Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset cf32dbd in mainline


Ignore:
Timestamp:
2019-11-29T19:38:25Z (12 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
fd777a2
Parents:
38e5f36c
Message:

Introduce window focus, housed in a seat object

Location:
uspace/srv/hid/display
Files:
3 added
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/client.c

    r38e5f36c rcf32dbd  
    3939#include "client.h"
    4040#include "display.h"
     41#include "seat.h"
    4142#include "window.h"
    4243
     
    112113void ds_client_remove_window(ds_window_t *wnd)
    113114{
     115        ds_seat_t *seat;
     116
     117        /* Make sure window is no longer focused in any seat */
     118        seat = ds_display_first_seat(wnd->client->display);
     119        while (seat != NULL) {
     120                ds_seat_evac_focus(seat, wnd);
     121                seat = ds_display_next_seat(seat);
     122        }
     123
    114124        list_remove(&wnd->lwindows);
    115125        wnd->client = NULL;
  • uspace/srv/hid/display/client.h

    r38e5f36c rcf32dbd  
    3737#define CLIENT_H
    3838
     39#include <errno.h>
     40#include <io/kbd_event.h>
    3941#include "types/display/client.h"
    4042#include "types/display/display.h"
  • uspace/srv/hid/display/display.c

    r38e5f36c rcf32dbd  
    3939#include <stdlib.h>
    4040#include "client.h"
     41#include "seat.h"
    4142#include "window.h"
    4243#include "display.h"
     
    5960        disp->gc = gc;
    6061        disp->next_wnd_id = 1;
     62        list_initialize(&disp->seats);
    6163        *rdisp = disp;
    6264        return EOK;
     
    7072{
    7173        assert(list_empty(&disp->clients));
     74        assert(list_empty(&disp->seats));
    7275        free(disp);
    7376}
     
    7679 *
    7780 * @param disp Display
    78  * @param client client
     81 * @param client Client
    7982 */
    8083void ds_display_add_client(ds_display_t *disp, ds_client_t *client)
     
    8992/** Remove client from display.
    9093 *
    91  * @param client client
     94 * @param client Client
    9295 */
    9396void ds_display_remove_client(ds_client_t *client)
     
    160163}
    161164
     165/** Post keyboard event to a display.
     166 *
     167 * The event is routed to the correct window by first determining the
     168 * seat the keyboard device belongs to and then the event is sent to the
     169 * window focused by that seat.
     170 *
     171 * @param display Display
     172 * @param event Event
     173 */
    162174errno_t ds_display_post_kbd_event(ds_display_t *display, kbd_event_t *event)
    163175{
    164         ds_client_t *client;
    165         ds_window_t *wnd;
    166 
    167         // XXX Correctly determine destination window
    168 
    169         client = ds_display_first_client(display);
    170         if (client == NULL)
     176        ds_seat_t *seat;
     177
     178        // TODO Determine which seat the event belongs to
     179        seat = ds_display_first_seat(display);
     180        if (seat == NULL)
    171181                return EOK;
    172182
    173         wnd = ds_client_first_window(client);
    174         if (wnd == NULL)
    175                 return EOK;
    176 
    177         return ds_client_post_kbd_event(client, wnd, event);
     183        return ds_seat_post_kbd_event(seat, event);
     184}
     185
     186/** Add seat to display.
     187 *
     188 * @param disp Display
     189 * @param seat Seat
     190 */
     191void ds_display_add_seat(ds_display_t *disp, ds_seat_t *seat)
     192{
     193        assert(seat->display == NULL);
     194        assert(!link_used(&seat->lseats));
     195
     196        seat->display = disp;
     197        list_append(&seat->lseats, &disp->seats);
     198}
     199
     200/** Remove seat from display.
     201 *
     202 * @param seat Seat
     203 */
     204void ds_display_remove_seat(ds_seat_t *seat)
     205{
     206        list_remove(&seat->lseats);
     207        seat->display = NULL;
     208}
     209
     210/** Get first seat in display.
     211 *
     212 * @param disp Display
     213 * @return First seat or @c NULL if there is none
     214 */
     215ds_seat_t *ds_display_first_seat(ds_display_t *disp)
     216{
     217        link_t *link = list_first(&disp->seats);
     218
     219        if (link == NULL)
     220                return NULL;
     221
     222        return list_get_instance(link, ds_seat_t, lseats);
     223}
     224
     225/** Get next seat in display.
     226 *
     227 * @param seat Current seat
     228 * @return Next seat or @c NULL if there is none
     229 */
     230ds_seat_t *ds_display_next_seat(ds_seat_t *seat)
     231{
     232        link_t *link = list_next(&seat->lseats, &seat->display->seats);
     233
     234        if (link == NULL)
     235                return NULL;
     236
     237        return list_get_instance(link, ds_seat_t, lseats);
    178238}
    179239
  • uspace/srv/hid/display/display.h

    r38e5f36c rcf32dbd  
    4242#include "types/display/client.h"
    4343#include "types/display/display.h"
     44#include "types/display/seat.h"
    4445
    4546extern errno_t ds_display_create(gfx_context_t *, ds_display_t **);
     
    5152extern ds_window_t *ds_display_find_window(ds_display_t *, ds_wnd_id_t);
    5253extern errno_t ds_display_post_kbd_event(ds_display_t *, kbd_event_t *);
     54extern void ds_display_add_seat(ds_display_t *, ds_seat_t *);
     55extern void ds_display_remove_seat(ds_seat_t *);
     56extern ds_seat_t *ds_display_first_seat(ds_display_t *);
     57extern ds_seat_t *ds_display_next_seat(ds_seat_t *);
    5358
    5459#endif
  • uspace/srv/hid/display/dsops.c

    r38e5f36c rcf32dbd  
    3838#include <io/log.h>
    3939#include "client.h"
     40#include "display.h"
     41#include "dsops.h"
     42#include "seat.h"
    4043#include "window.h"
    41 #include "dsops.h"
    4244
    4345static errno_t disp_window_create(void *, sysarg_t *);
     
    5557        errno_t rc;
    5658        ds_client_t *client = (ds_client_t *) arg;
     59        ds_seat_t *seat;
    5760        ds_window_t *wnd;
    5861
     
    6972        wnd->dpos.x = ((wnd->id - 1) & 1) * 400;
    7073        wnd->dpos.y = ((wnd->id - 1) & 2) / 2 * 300;
     74
     75        /*
     76         * XXX This should be performed by window manager. It needs to determine
     77         * whether the new window should get focus and which seat should
     78         * focus on it.
     79         */
     80        seat = ds_display_first_seat(client->display);
     81        ds_seat_set_focus(seat, wnd);
    7182
    7283        *rwnd_id = wnd->id;
  • uspace/srv/hid/display/main.c

    r38e5f36c rcf32dbd  
    5050#include "main.h"
    5151#include "output.h"
     52#include "seat.h"
    5253#include "window.h"
    5354
     
    7879{
    7980        ds_display_t *disp = NULL;
     81        ds_seat_t *seat = NULL;
    8082        gfx_context_t *gc = NULL;
    8183        errno_t rc;
     
    8486
    8587        rc = ds_display_create(NULL, &disp);
     88        if (rc != EOK)
     89                goto error;
     90
     91        rc = ds_seat_create(disp, &seat);
    8692        if (rc != EOK)
    8793                goto error;
     
    121127        if (gc != NULL)
    122128                gfx_context_delete(gc);
     129        if (seat != NULL)
     130                ds_seat_destroy(seat);
    123131        if (disp != NULL)
    124132                ds_display_destroy(disp);
  • uspace/srv/hid/display/meson.build

    r38e5f36c rcf32dbd  
    3535        'main.c',
    3636        'output.c',
     37        'seat.c',
    3738        'window.c',
    3839)
     
    4142        'client.c',
    4243        'display.c',
     44        'seat.c',
    4345        'window.c',
    4446        'test/client.c',
  • uspace/srv/hid/display/test/display.c

    r38e5f36c rcf32dbd  
    3434#include "../client.h"
    3535#include "../display.h"
     36#include "../seat.h"
    3637#include "../window.h"
    3738
     
    130131}
    131132
     133/** Basic seat operation. */
     134PCUT_TEST(display_seat)
     135{
     136        ds_display_t *disp;
     137        ds_seat_t *seat;
     138        ds_seat_t *s0, *s1;
     139        errno_t rc;
     140
     141        rc = ds_display_create(NULL, &disp);
     142        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     143
     144        rc = ds_seat_create(disp, &seat);
     145        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     146
     147        s0 = ds_display_first_seat(disp);
     148        PCUT_ASSERT_EQUALS(s0, seat);
     149
     150        s1 = ds_display_next_seat(s0);
     151        PCUT_ASSERT_NULL(s1);
     152
     153        ds_seat_destroy(seat);
     154        ds_display_destroy(disp);
     155}
     156
    132157/** Test ds_display_post_kbd_event(). */
    133158PCUT_TEST(display_post_kbd_event)
    134159{
    135160        ds_display_t *disp;
     161        ds_seat_t *seat;
    136162        ds_client_t *client;
    137163        ds_window_t *wnd;
     
    141167
    142168        rc = ds_display_create(NULL, &disp);
     169        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     170
     171        rc = ds_seat_create(disp, &seat);
    143172        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    144173
     
    162191        ds_window_destroy(wnd);
    163192        ds_client_destroy(client);
     193        ds_seat_destroy(seat);
    164194        ds_display_destroy(disp);
    165195}
  • uspace/srv/hid/display/types/display/display.h

    r38e5f36c rcf32dbd  
    5959        /** Input service */
    6060        input_t *input;
     61
     62        /** Seats (of ds_seat_t) */
     63        list_t seats;
    6164} ds_display_t;
    6265
  • uspace/srv/hid/display/window.h

    r38e5f36c rcf32dbd  
    3737#define WINDOW_H
    3838
    39 #include <display/event.h>
    4039#include <errno.h>
    4140#include <types/gfx/context.h>
Note: See TracChangeset for help on using the changeset viewer.