Changeset f7fb2b21 in mainline for uspace/srv/hid/display


Ignore:
Timestamp:
2020-02-10T19:01:42Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b43edabe
Parents:
287688f2
Message:

Propagate position event to display clients

Location:
uspace/srv/hid/display
Files:
6 edited

Legend:

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

    r287688f2 rf7fb2b21  
    221221
    222222        wevent->window = ewindow;
    223         wevent->event.kbd_event = *event;
     223        wevent->event.etype = wev_kbd;
     224        wevent->event.ev.kbd = *event;
    224225        list_append(&wevent->levents, &client->events);
    225226
     
    231232}
    232233
     234/** Post position event to the client's message queue.
     235 *
     236 * @param client Client
     237 * @param ewindow Window that the message is targetted to
     238 * @param event Event
     239 *
     240 * @return EOK on success or an error code
     241 */
     242errno_t ds_client_post_pos_event(ds_client_t *client, ds_window_t *ewindow,
     243    pos_event_t *event)
     244{
     245        ds_window_ev_t *wevent;
     246
     247        wevent = calloc(1, sizeof(ds_window_ev_t));
     248        if (wevent == NULL)
     249                return ENOMEM;
     250
     251        wevent->window = ewindow;
     252        wevent->event.etype = wev_pos;
     253        wevent->event.ev.pos = *event;
     254        list_append(&wevent->levents, &client->events);
     255
     256        /* Notify the client */
     257        // TODO Do not send more than once until client drains the queue
     258        if (client->cb != NULL && client->cb->ev_pending != NULL)
     259                client->cb->ev_pending(client->cb_arg);
     260
     261        return EOK;
     262}
     263
    233264/** @}
    234265 */
  • uspace/srv/hid/display/client.h

    r287688f2 rf7fb2b21  
    3939#include <errno.h>
    4040#include <io/kbd_event.h>
     41#include <io/pos_event.h>
    4142#include "types/display/client.h"
    4243#include "types/display/display.h"
     
    5455extern errno_t ds_client_post_kbd_event(ds_client_t *, ds_window_t *,
    5556    kbd_event_t *);
     57extern errno_t ds_client_post_pos_event(ds_client_t *, ds_window_t *,
     58    pos_event_t *);
    5659
    5760#endif
  • uspace/srv/hid/display/test/client.c

    r287688f2 rf7fb2b21  
    206206        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    207207        PCUT_ASSERT_EQUALS(wnd, rwindow);
    208         PCUT_ASSERT_EQUALS(event.type, revent.kbd_event.type);
    209         PCUT_ASSERT_EQUALS(event.key, revent.kbd_event.key);
    210         PCUT_ASSERT_EQUALS(event.mods, revent.kbd_event.mods);
    211         PCUT_ASSERT_EQUALS(event.c, revent.kbd_event.c);
     208        PCUT_ASSERT_EQUALS(wev_kbd, revent.etype);
     209        PCUT_ASSERT_EQUALS(event.type, revent.ev.kbd.type);
     210        PCUT_ASSERT_EQUALS(event.key, revent.ev.kbd.key);
     211        PCUT_ASSERT_EQUALS(event.mods, revent.ev.kbd.mods);
     212        PCUT_ASSERT_EQUALS(event.c, revent.ev.kbd.c);
     213
     214        rc = ds_client_get_event(client, &rwindow, &revent);
     215        PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
     216
     217        ds_window_destroy(wnd);
     218        ds_client_destroy(client);
     219        ds_display_destroy(disp);
     220}
     221
     222/** Test ds_client_get_event(), ds_client_post_pos_event(). */
     223PCUT_TEST(client_get_post_pos_event)
     224{
     225        ds_display_t *disp;
     226        ds_client_t *client;
     227        ds_window_t *wnd;
     228        display_wnd_params_t params;
     229        pos_event_t event;
     230        ds_window_t *rwindow;
     231        display_wnd_ev_t revent;
     232        bool called_cb = NULL;
     233        errno_t rc;
     234
     235        rc = ds_display_create(NULL, &disp);
     236        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     237
     238        rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
     239        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     240
     241        display_wnd_params_init(&params);
     242        params.rect.p0.x = params.rect.p0.y = 0;
     243        params.rect.p1.x = params.rect.p1.y = 1;
     244
     245        rc = ds_window_create(client, &params, &wnd);
     246        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     247
     248        event.type = POS_PRESS;
     249        event.hpos = 1;
     250        event.vpos = 2;
     251
     252        PCUT_ASSERT_FALSE(called_cb);
     253
     254        rc = ds_client_get_event(client, &rwindow, &revent);
     255        PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
     256
     257        rc = ds_client_post_pos_event(client, wnd, &event);
     258        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     259        PCUT_ASSERT_TRUE(called_cb);
     260
     261        rc = ds_client_get_event(client, &rwindow, &revent);
     262        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     263        PCUT_ASSERT_EQUALS(wnd, rwindow);
     264        PCUT_ASSERT_EQUALS(wev_pos, revent.etype);
     265        PCUT_ASSERT_EQUALS(event.type, revent.ev.pos.type);
     266        PCUT_ASSERT_EQUALS(event.hpos, revent.ev.pos.hpos);
     267        PCUT_ASSERT_EQUALS(event.vpos, revent.ev.pos.vpos);
    212268
    213269        rc = ds_client_get_event(client, &rwindow, &revent);
  • uspace/srv/hid/display/test/display.c

    r287688f2 rf7fb2b21  
    377377        w1->dpos.y = 400;
    378378
    379         PCUT_ASSERT_FALSE(called_cb);
    380 
    381379        ds_seat_set_focus(seat, w0);
    382380
     
    386384        rc = ds_display_post_ptd_event(disp, &event);
    387385        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    388         PCUT_ASSERT_FALSE(called_cb);
    389386
    390387        event.type = PTD_PRESS;
     
    392389        rc = ds_display_post_ptd_event(disp, &event);
    393390        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    394         PCUT_ASSERT_FALSE(called_cb);
    395391
    396392        PCUT_ASSERT_EQUALS(w1, seat->focus);
     
    400396        rc = ds_display_post_ptd_event(disp, &event);
    401397        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    402         PCUT_ASSERT_FALSE(called_cb);
    403398
    404399        event.type = PTD_MOVE;
     
    407402        rc = ds_display_post_ptd_event(disp, &event);
    408403        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    409         PCUT_ASSERT_FALSE(called_cb);
    410404
    411405        event.type = PTD_PRESS;
     
    413407        rc = ds_display_post_ptd_event(disp, &event);
    414408        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    415         PCUT_ASSERT_FALSE(called_cb);
    416409
    417410        PCUT_ASSERT_EQUALS(w0, seat->focus);
  • uspace/srv/hid/display/test/seat.c

    r287688f2 rf7fb2b21  
    232232        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    233233        PCUT_ASSERT_EQUALS(wnd, rwindow);
    234         PCUT_ASSERT_EQUALS(event.type, revent.kbd_event.type);
    235         PCUT_ASSERT_EQUALS(event.key, revent.kbd_event.key);
    236         PCUT_ASSERT_EQUALS(event.mods, revent.kbd_event.mods);
    237         PCUT_ASSERT_EQUALS(event.c, revent.kbd_event.c);
     234        PCUT_ASSERT_EQUALS(wev_kbd, revent.etype);
     235        PCUT_ASSERT_EQUALS(event.type, revent.ev.kbd.type);
     236        PCUT_ASSERT_EQUALS(event.key, revent.ev.kbd.key);
     237        PCUT_ASSERT_EQUALS(event.mods, revent.ev.kbd.mods);
     238        PCUT_ASSERT_EQUALS(event.c, revent.ev.kbd.c);
    238239
    239240        rc = ds_client_get_event(client, &rwindow, &revent);
  • uspace/srv/hid/display/window.c

    r287688f2 rf7fb2b21  
    489489errno_t ds_window_post_pos_event(ds_window_t *wnd, pos_event_t *event)
    490490{
     491        pos_event_t tevent;
     492
    491493        log_msg(LOG_DEFAULT, LVL_DEBUG,
    492494            "ds_window_post_pos_event type=%d pos=%d,%d\n", event->type,
     
    508510        }
    509511
    510         return EOK;
     512        /* Transform event coordinates to window-local */
     513        tevent = *event;
     514        tevent.hpos -= wnd->dpos.x;
     515        tevent.vpos -= wnd->dpos.y;
     516
     517        return ds_client_post_pos_event(wnd->client, wnd, &tevent);
    511518}
    512519
Note: See TracChangeset for help on using the changeset viewer.