Changeset f7fb2b21 in mainline
- Timestamp:
- 2020-02-10T19:01:42Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b43edabe
- Parents:
- 287688f
- Location:
- uspace
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/display/include/types/display.h
r287688f rf7fb2b21 39 39 #include <fibril_synch.h> 40 40 #include <io/kbd_event.h> 41 #include <io/pos_event.h> 41 42 #include <stdint.h> 42 43 … … 58 59 typedef struct { 59 60 void (*kbd_event)(void *, kbd_event_t *); 61 void (*pos_event)(void *, pos_event_t *); 60 62 } display_wnd_cb_t; 61 63 -
uspace/lib/display/include/types/display/event.h
r287688f rf7fb2b21 37 37 38 38 #include <io/kbd_event.h> 39 #include <io/pos_event.h> 40 41 typedef enum { 42 wev_kbd, 43 wev_pos 44 } display_wnd_ev_type_t; 39 45 40 46 typedef struct { 41 kbd_event_t kbd_event; 47 display_wnd_ev_type_t etype; 48 union { 49 kbd_event_t kbd; 50 pos_event_t pos; 51 } ev; 42 52 } display_wnd_ev_t; 43 53 -
uspace/lib/display/src/display.c
r287688f rf7fb2b21 295 295 break; 296 296 297 if (window->cb != NULL && window->cb->kbd_event != NULL) 298 window->cb->kbd_event(window->cb_arg, &event.kbd_event); 297 switch (event.etype) { 298 case wev_kbd: 299 if (window->cb != NULL && window->cb->kbd_event != NULL) { 300 window->cb->kbd_event(window->cb_arg, 301 &event.ev.kbd); 302 } 303 break; 304 case wev_pos: 305 if (window->cb != NULL && window->cb->pos_event != NULL) { 306 window->cb->pos_event(window->cb_arg, 307 &event.ev.pos); 308 } 309 break; 310 } 299 311 } 300 312 -
uspace/lib/display/test/display.c
r287688f rf7fb2b21 48 48 static void test_display_conn(ipc_call_t *, void *); 49 49 static void test_kbd_event(void *, kbd_event_t *); 50 static void test_pos_event(void *, pos_event_t *); 50 51 51 52 static errno_t test_window_create(void *, display_wnd_params_t *, sysarg_t *); … … 62 63 63 64 static display_wnd_cb_t test_display_wnd_cb = { 64 .kbd_event = test_kbd_event 65 .kbd_event = test_kbd_event, 66 .pos_event = test_pos_event 65 67 }; 66 68 … … 84 86 bool set_color_called; 85 87 bool kbd_event_called; 86 fibril_condvar_t kbd_event_cv; 87 fibril_mutex_t kbd_event_lock; 88 bool pos_event_called; 89 fibril_condvar_t event_cv; 90 fibril_mutex_t event_lock; 88 91 display_srv_t *srv; 89 92 } test_response_t; … … 392 395 display_window_t *wnd; 393 396 test_response_t resp; 394 gfx_context_t *gc;395 397 396 398 async_set_fallback_port_handler(test_display_conn, &resp); … … 421 423 PCUT_ASSERT_NOT_NULL(wnd); 422 424 423 gc = NULL;424 rc = display_window_get_gc(wnd, &gc);425 PCUT_ASSERT_ERRNO_VAL(EOK, rc);426 PCUT_ASSERT_NOT_NULL(gc);427 428 425 resp.event_cnt = 1; 429 resp.event.kbd_event.type = KEY_PRESS; 430 resp.event.kbd_event.key = KC_ENTER; 431 resp.event.kbd_event.mods = 0; 432 resp.event.kbd_event.c = L'\0'; 426 resp.event.etype = wev_kbd; 427 resp.event.ev.kbd.type = KEY_PRESS; 428 resp.event.ev.kbd.key = KC_ENTER; 429 resp.event.ev.kbd.mods = 0; 430 resp.event.ev.kbd.c = L'\0'; 433 431 resp.wnd_id = wnd->id; 434 432 resp.kbd_event_called = false; 435 fibril_mutex_initialize(&resp. kbd_event_lock);436 fibril_condvar_initialize(&resp. kbd_event_cv);433 fibril_mutex_initialize(&resp.event_lock); 434 fibril_condvar_initialize(&resp.event_cv); 437 435 display_srv_ev_pending(resp.srv); 438 436 439 437 /* Wait for the event handler to be called. */ 440 fibril_mutex_lock(&resp. kbd_event_lock);438 fibril_mutex_lock(&resp.event_lock); 441 439 while (!resp.kbd_event_called) { 442 fibril_condvar_wait(&resp. kbd_event_cv, &resp.kbd_event_lock);440 fibril_condvar_wait(&resp.event_cv, &resp.event_lock); 443 441 } 444 fibril_mutex_unlock(&resp. kbd_event_lock);442 fibril_mutex_unlock(&resp.event_lock); 445 443 446 444 /* Verify that the event was delivered correctly */ 447 PCUT_ASSERT_EQUALS(resp.event.kbd_event.type, 448 resp.revent.kbd_event.type); 449 PCUT_ASSERT_EQUALS(resp.event.kbd_event.key, 450 resp.revent.kbd_event.key); 451 PCUT_ASSERT_EQUALS(resp.event.kbd_event.mods, 452 resp.revent.kbd_event.mods); 453 PCUT_ASSERT_EQUALS(resp.event.kbd_event.c, 454 resp.revent.kbd_event.c); 445 PCUT_ASSERT_EQUALS(resp.event.etype, 446 resp.revent.etype); 447 PCUT_ASSERT_EQUALS(resp.event.ev.kbd.type, 448 resp.revent.ev.kbd.type); 449 PCUT_ASSERT_EQUALS(resp.event.ev.kbd.key, 450 resp.revent.ev.kbd.key); 451 PCUT_ASSERT_EQUALS(resp.event.ev.kbd.mods, 452 resp.revent.ev.kbd.mods); 453 PCUT_ASSERT_EQUALS(resp.event.ev.kbd.c, 454 resp.revent.ev.kbd.c); 455 456 rc = display_window_destroy(wnd); 457 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 458 459 display_close(disp); 460 461 rc = loc_service_unregister(sid); 462 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 463 } 464 465 /** Position event can be delivered from server to client callback function */ 466 PCUT_TEST(pos_event_deliver) 467 { 468 errno_t rc; 469 service_id_t sid; 470 display_t *disp = NULL; 471 display_wnd_params_t params; 472 display_window_t *wnd; 473 test_response_t resp; 474 475 async_set_fallback_port_handler(test_display_conn, &resp); 476 477 // FIXME This causes this test to be non-reentrant! 478 rc = loc_server_register(test_display_server); 479 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 480 481 rc = loc_service_register(test_display_svc, &sid); 482 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 483 484 rc = display_open(test_display_svc, &disp); 485 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 486 PCUT_ASSERT_NOT_NULL(disp); 487 PCUT_ASSERT_NOT_NULL(resp.srv); 488 489 wnd = NULL; 490 resp.rc = EOK; 491 display_wnd_params_init(¶ms); 492 params.rect.p0.x = 0; 493 params.rect.p0.y = 0; 494 params.rect.p0.x = 100; 495 params.rect.p0.y = 100; 496 497 rc = display_window_create(disp, ¶ms, &test_display_wnd_cb, 498 (void *) &resp, &wnd); 499 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 500 PCUT_ASSERT_NOT_NULL(wnd); 501 502 resp.event_cnt = 1; 503 resp.event.etype = wev_pos; 504 resp.event.ev.pos.type = POS_PRESS; 505 resp.event.ev.pos.btn_num = 1; 506 resp.event.ev.pos.hpos = 2; 507 resp.event.ev.pos.vpos = 3; 508 resp.wnd_id = wnd->id; 509 resp.pos_event_called = false; 510 fibril_mutex_initialize(&resp.event_lock); 511 fibril_condvar_initialize(&resp.event_cv); 512 display_srv_ev_pending(resp.srv); 513 514 /* Wait for the event handler to be called. */ 515 fibril_mutex_lock(&resp.event_lock); 516 while (!resp.pos_event_called) { 517 fibril_condvar_wait(&resp.event_cv, &resp.event_lock); 518 } 519 fibril_mutex_unlock(&resp.event_lock); 520 521 /* Verify that the event was delivered correctly */ 522 PCUT_ASSERT_EQUALS(resp.event.etype, 523 resp.revent.etype); 524 PCUT_ASSERT_EQUALS(resp.event.ev.pos.type, 525 resp.revent.ev.pos.type); 526 PCUT_ASSERT_EQUALS(resp.event.ev.pos.btn_num, 527 resp.revent.ev.pos.btn_num); 528 PCUT_ASSERT_EQUALS(resp.event.ev.pos.hpos, 529 resp.revent.ev.pos.hpos); 530 PCUT_ASSERT_EQUALS(resp.event.ev.pos.vpos, 531 resp.revent.ev.pos.vpos); 455 532 456 533 rc = display_window_destroy(wnd); … … 514 591 test_response_t *resp = (test_response_t *) arg; 515 592 516 resp->revent.kbd_event = *event; 517 518 fibril_mutex_lock(&resp->kbd_event_lock); 593 resp->revent.etype = wev_kbd; 594 resp->revent.ev.kbd = *event; 595 596 fibril_mutex_lock(&resp->event_lock); 519 597 resp->kbd_event_called = true; 520 fibril_condvar_broadcast(&resp->kbd_event_cv); 521 fibril_mutex_unlock(&resp->kbd_event_lock); 598 fibril_condvar_broadcast(&resp->event_cv); 599 fibril_mutex_unlock(&resp->event_lock); 600 } 601 602 static void test_pos_event(void *arg, pos_event_t *event) 603 { 604 test_response_t *resp = (test_response_t *) arg; 605 606 resp->revent.etype = wev_pos; 607 resp->revent.ev.pos = *event; 608 609 fibril_mutex_lock(&resp->event_lock); 610 resp->pos_event_called = true; 611 fibril_condvar_broadcast(&resp->event_cv); 612 fibril_mutex_unlock(&resp->event_lock); 522 613 } 523 614 -
uspace/lib/gui/window.c
r287688f rf7fb2b21 84 84 85 85 static void window_kbd_event(void *, kbd_event_t *); 86 static void window_pos_event(void *, pos_event_t *); 86 87 87 88 static display_wnd_cb_t window_cb = { 88 .kbd_event = window_kbd_event 89 .kbd_event = window_kbd_event, 90 .pos_event = window_pos_event 89 91 }; 90 92 … … 815 817 } 816 818 819 static void window_pos_event(void *arg, pos_event_t *pevent) 820 { 821 window_t *win = (window_t *) arg; 822 window_event_t *event; 823 824 event = (window_event_t *) calloc(1, sizeof(window_event_t)); 825 if (event == NULL) 826 return; 827 828 link_initialize(&event->link); 829 event->type = ET_POSITION_EVENT; 830 event->data.pos = *pevent; 831 prodcons_produce(&win->events, &event->link); 832 } 833 817 834 /** @} 818 835 */ -
uspace/srv/hid/display/client.c
r287688f rf7fb2b21 221 221 222 222 wevent->window = ewindow; 223 wevent->event.kbd_event = *event; 223 wevent->event.etype = wev_kbd; 224 wevent->event.ev.kbd = *event; 224 225 list_append(&wevent->levents, &client->events); 225 226 … … 231 232 } 232 233 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 */ 242 errno_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 233 264 /** @} 234 265 */ -
uspace/srv/hid/display/client.h
r287688f rf7fb2b21 39 39 #include <errno.h> 40 40 #include <io/kbd_event.h> 41 #include <io/pos_event.h> 41 42 #include "types/display/client.h" 42 43 #include "types/display/display.h" … … 54 55 extern errno_t ds_client_post_kbd_event(ds_client_t *, ds_window_t *, 55 56 kbd_event_t *); 57 extern errno_t ds_client_post_pos_event(ds_client_t *, ds_window_t *, 58 pos_event_t *); 56 59 57 60 #endif -
uspace/srv/hid/display/test/client.c
r287688f rf7fb2b21 206 206 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 207 207 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(). */ 223 PCUT_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(¶ms); 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, ¶ms, &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); 212 268 213 269 rc = ds_client_get_event(client, &rwindow, &revent); -
uspace/srv/hid/display/test/display.c
r287688f rf7fb2b21 377 377 w1->dpos.y = 400; 378 378 379 PCUT_ASSERT_FALSE(called_cb);380 381 379 ds_seat_set_focus(seat, w0); 382 380 … … 386 384 rc = ds_display_post_ptd_event(disp, &event); 387 385 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 388 PCUT_ASSERT_FALSE(called_cb);389 386 390 387 event.type = PTD_PRESS; … … 392 389 rc = ds_display_post_ptd_event(disp, &event); 393 390 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 394 PCUT_ASSERT_FALSE(called_cb);395 391 396 392 PCUT_ASSERT_EQUALS(w1, seat->focus); … … 400 396 rc = ds_display_post_ptd_event(disp, &event); 401 397 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 402 PCUT_ASSERT_FALSE(called_cb);403 398 404 399 event.type = PTD_MOVE; … … 407 402 rc = ds_display_post_ptd_event(disp, &event); 408 403 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 409 PCUT_ASSERT_FALSE(called_cb);410 404 411 405 event.type = PTD_PRESS; … … 413 407 rc = ds_display_post_ptd_event(disp, &event); 414 408 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 415 PCUT_ASSERT_FALSE(called_cb);416 409 417 410 PCUT_ASSERT_EQUALS(w0, seat->focus); -
uspace/srv/hid/display/test/seat.c
r287688f rf7fb2b21 232 232 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 233 233 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); 238 239 239 240 rc = ds_client_get_event(client, &rwindow, &revent); -
uspace/srv/hid/display/window.c
r287688f rf7fb2b21 489 489 errno_t ds_window_post_pos_event(ds_window_t *wnd, pos_event_t *event) 490 490 { 491 pos_event_t tevent; 492 491 493 log_msg(LOG_DEFAULT, LVL_DEBUG, 492 494 "ds_window_post_pos_event type=%d pos=%d,%d\n", event->type, … … 508 510 } 509 511 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); 511 518 } 512 519
Note:
See TracChangeset
for help on using the changeset viewer.