Changeset 8d1bcd7 in mainline
- Timestamp:
- 2023-09-26T20:26:55Z (16 months ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5afc1aa
- Parents:
- ed1a948
- Location:
- uspace/lib/ui
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/include/types/ui/wdecor.h
red1a948 r8d1bcd7 84 84 /** Window decoration callbacks */ 85 85 typedef struct ui_wdecor_cb { 86 void (*sysmenu)(ui_wdecor_t *, void *, sysarg_t); 86 void (*sysmenu_open)(ui_wdecor_t *, void *, sysarg_t); 87 void (*sysmenu_left)(ui_wdecor_t *, void *, sysarg_t); 88 void (*sysmenu_right)(ui_wdecor_t *, void *, sysarg_t); 89 void (*sysmenu_accel)(ui_wdecor_t *, void *, char32_t, sysarg_t); 87 90 void (*minimize)(ui_wdecor_t *, void *); 88 91 void (*maximize)(ui_wdecor_t *, void *); -
uspace/lib/ui/include/ui/menubar.h
red1a948 r8d1bcd7 61 61 extern void ui_menu_bar_activate(ui_menu_bar_t *); 62 62 extern void ui_menu_bar_deactivate(ui_menu_bar_t *); 63 extern void ui_menu_bar_select_first(ui_menu_bar_t *, bool, sysarg_t); 64 extern void ui_menu_bar_select_last(ui_menu_bar_t *, bool, sysarg_t); 63 65 64 66 #endif -
uspace/lib/ui/private/menubar.h
red1a948 r8d1bcd7 67 67 68 68 extern void ui_menu_bar_select(ui_menu_bar_t *, ui_menu_dd_t *, bool, sysarg_t); 69 extern void ui_menu_bar_select_sysmenu(ui_menu_bar_t *, sysarg_t); 69 70 extern void ui_menu_bar_left(ui_menu_bar_t *, sysarg_t); 70 71 extern void ui_menu_bar_right(ui_menu_bar_t *, sysarg_t); -
uspace/lib/ui/private/wdecor.h
red1a948 r8d1bcd7 99 99 } ui_wdecor_geom_t; 100 100 101 extern void ui_wdecor_sysmenu(ui_wdecor_t *, sysarg_t); 101 extern void ui_wdecor_sysmenu_open(ui_wdecor_t *, sysarg_t); 102 extern void ui_wdecor_sysmenu_left(ui_wdecor_t *, sysarg_t); 103 extern void ui_wdecor_sysmenu_right(ui_wdecor_t *, sysarg_t); 104 extern void ui_wdecor_sysmenu_accel(ui_wdecor_t *, char32_t, sysarg_t); 102 105 extern void ui_wdecor_minimize(ui_wdecor_t *); 103 106 extern void ui_wdecor_maximize(ui_wdecor_t *); -
uspace/lib/ui/private/window.h
red1a948 r8d1bcd7 102 102 /** System menu maximize entry */ 103 103 struct ui_menu_entry *sysmenu_maximize; 104 /** Menu bar */ 105 struct ui_menu_bar *mbar; 104 106 /** Top-level control in the application area */ 105 107 struct ui_control *control; -
uspace/lib/ui/src/menubar.c
red1a948 r8d1bcd7 48 48 #include <ui/menubar.h> 49 49 #include <ui/menudd.h> 50 #include <ui/wdecor.h> 50 51 #include <ui/window.h> 51 52 #include "../private/menubar.h" 52 53 #include "../private/resource.h" 54 #include "../private/wdecor.h" 55 #include "../private/window.h" 53 56 54 57 enum { … … 97 100 mbar->window = window; 98 101 list_initialize(&mbar->menudds); 102 103 if (window->mbar == NULL) 104 window->mbar = mbar; 105 99 106 *rmbar = mbar; 100 107 return EOK; … … 111 118 if (mbar == NULL) 112 119 return; 120 121 if (mbar->window->mbar == mbar) 122 mbar->window->mbar = NULL; 113 123 114 124 /* Destroy menu drop-downs */ … … 277 287 (void) ui_menu_dd_open(mbar->selected, &rect, idev_id); 278 288 } 279 } 289 290 mbar->active = true; 291 } else { 292 mbar->active = false; 293 } 294 } 295 296 void ui_menu_bar_select_first(ui_menu_bar_t *mbar, bool openup, 297 sysarg_t idev_id) 298 { 299 ui_menu_dd_t *mdd; 300 301 mdd = ui_menu_dd_first(mbar); 302 ui_menu_bar_select(mbar, mdd, openup, idev_id); 303 } 304 305 void ui_menu_bar_select_last(ui_menu_bar_t *mbar, bool openup, 306 sysarg_t idev_id) 307 { 308 ui_menu_dd_t *mdd; 309 310 mdd = ui_menu_dd_last(mbar); 311 ui_menu_bar_select(mbar, mdd, openup, idev_id); 312 } 313 314 void ui_menu_bar_select_sysmenu(ui_menu_bar_t *mbar, sysarg_t idev_id) 315 { 316 bool was_open; 317 318 ui_wdecor_sysmenu_hdl_set_active(mbar->window->wdecor, true); 319 was_open = mbar->selected != NULL && 320 ui_menu_dd_is_open(mbar->selected); 321 322 if (was_open) 323 ui_window_send_sysmenu(mbar->window, idev_id); 280 324 } 281 325 … … 296 340 297 341 nmdd = ui_menu_dd_prev(mbar->selected); 298 if (nmdd == NULL) 299 nmdd = ui_menu_dd_last(mbar); 342 if (nmdd == NULL) { 343 if ((mbar->window->wdecor->style & ui_wds_sysmenu_hdl) != 0) { 344 ui_menu_bar_select_sysmenu(mbar, idev_id); 345 } else { 346 nmdd = ui_menu_dd_last(mbar); 347 } 348 } 300 349 301 350 if (nmdd != mbar->selected) … … 319 368 320 369 nmdd = ui_menu_dd_next(mbar->selected); 321 if (nmdd == NULL) 322 nmdd = ui_menu_dd_first(mbar); 370 if (nmdd == NULL) { 371 if ((mbar->window->wdecor->style & ui_wds_sysmenu_hdl) != 0) { 372 ui_menu_bar_select_sysmenu(mbar, idev_id); 373 } else { 374 nmdd = ui_menu_dd_first(mbar); 375 } 376 } 323 377 324 378 if (nmdd != mbar->selected) … … 551 605 } 552 606 607 /** Deactivate menu bar. 608 * 609 * @param mbar Menu bar 610 */ 553 611 void ui_menu_bar_deactivate(ui_menu_bar_t *mbar) 554 612 { 555 613 ui_menu_bar_select(mbar, NULL, false, 0); 556 mbar->active = false;557 614 } 558 615 -
uspace/lib/ui/src/wdecor.c
red1a948 r8d1bcd7 406 406 ui_wdecor_get_geom(wdecor, &geom); 407 407 (void) ui_wdecor_sysmenu_hdl_paint(wdecor, &geom.sysmenu_hdl_rect); 408 (void) gfx_update(wdecor->res->gc); 408 409 } 409 410 … … 540 541 } 541 542 542 /** Send decoration sysmenu event.543 /** Send decoration sysmenu open event. 543 544 * 544 545 * @param wdecor Window decoration 545 546 * @param idev_id Input device ID 546 547 */ 547 void ui_wdecor_sysmenu(ui_wdecor_t *wdecor, sysarg_t idev_id) 548 { 549 if (wdecor->cb != NULL && wdecor->cb->sysmenu != NULL) 550 wdecor->cb->sysmenu(wdecor, wdecor->arg, idev_id); 548 void ui_wdecor_sysmenu_open(ui_wdecor_t *wdecor, sysarg_t idev_id) 549 { 550 if (wdecor->cb != NULL && wdecor->cb->sysmenu_open != NULL) 551 wdecor->cb->sysmenu_open(wdecor, wdecor->arg, idev_id); 552 } 553 554 /** Send decoration sysmenu left event. 555 * 556 * @param wdecor Window decoration 557 * @param idev_id Input device ID 558 */ 559 void ui_wdecor_sysmenu_left(ui_wdecor_t *wdecor, sysarg_t idev_id) 560 { 561 if (wdecor->cb != NULL && wdecor->cb->sysmenu_left != NULL) 562 wdecor->cb->sysmenu_left(wdecor, wdecor->arg, idev_id); 563 } 564 565 /** Send decoration sysmenu right event. 566 * 567 * @param wdecor Window decoration 568 * @param idev_id Input device ID 569 */ 570 void ui_wdecor_sysmenu_right(ui_wdecor_t *wdecor, sysarg_t idev_id) 571 { 572 if (wdecor->cb != NULL && wdecor->cb->sysmenu_right != NULL) 573 wdecor->cb->sysmenu_right(wdecor, wdecor->arg, idev_id); 574 } 575 576 /** Send decoration sysmenu accelerator event. 577 * 578 * @param wdecor Window decoration 579 * @param c Accelerator character 580 * @param idev_id Input device ID 581 */ 582 void ui_wdecor_sysmenu_accel(ui_wdecor_t *wdecor, char32_t c, sysarg_t idev_id) 583 { 584 if (wdecor->cb != NULL && wdecor->cb->sysmenu_right != NULL) 585 wdecor->cb->sysmenu_accel(wdecor, wdecor->arg, c, idev_id); 551 586 } 552 587 … … 986 1021 ui_evclaim_t ui_wdecor_kbd_event(ui_wdecor_t *wdecor, kbd_event_t *event) 987 1022 { 988 (void)wdecor;989 990 1023 if (event->type == KEY_PRESS && (event->mods & (KM_CTRL | KM_ALT | 991 1024 KM_SHIFT)) == 0) { 992 if (event->key == KC_F 9) {1025 if (event->key == KC_F10) { 993 1026 ui_wdecor_sysmenu_hdl_set_active(wdecor, true); 994 ui_wdecor_sysmenu(wdecor, event->kbd_id); 1027 ui_wdecor_sysmenu_open(wdecor, event->kbd_id); 1028 return ui_claimed; 1029 } 1030 } 1031 1032 /* System menu handle events (if active) */ 1033 if (event->type == KEY_PRESS && (event->mods & (KM_CTRL | KM_ALT | 1034 KM_SHIFT)) == 0 && wdecor->sysmenu_hdl_active) { 1035 switch (event->key) { 1036 case KC_ESCAPE: 1037 ui_wdecor_sysmenu_hdl_set_active(wdecor, false); 1038 return ui_claimed; 1039 case KC_LEFT: 1040 ui_wdecor_sysmenu_left(wdecor, event->kbd_id); 1041 return ui_claimed; 1042 case KC_RIGHT: 1043 ui_wdecor_sysmenu_right(wdecor, event->kbd_id); 1044 return ui_claimed; 1045 case KC_DOWN: 1046 ui_wdecor_sysmenu_open(wdecor, event->kbd_id); 1047 return ui_claimed; 1048 default: 1049 break; 1050 } 1051 1052 if (event->c != '\0') { 1053 /* Could be an accelerator key */ 1054 ui_wdecor_sysmenu_accel(wdecor, event->c, 1055 event->kbd_id); 995 1056 } 996 1057 } … … 1050 1111 gfx_pix_inside_rect(&pos, &geom.sysmenu_hdl_rect)) { 1051 1112 ui_wdecor_sysmenu_hdl_set_active(wdecor, true); 1052 ui_wdecor_sysmenu (wdecor, event->pos_id);1113 ui_wdecor_sysmenu_open(wdecor, event->pos_id); 1053 1114 return ui_claimed; 1054 1115 } -
uspace/lib/ui/src/window.c
red1a948 r8d1bcd7 47 47 #include <stdlib.h> 48 48 #include <ui/control.h> 49 #include <ui/menubar.h> 49 50 #include <ui/menu.h> 50 51 #include <ui/menuentry.h> … … 76 77 }; 77 78 78 static void wd_sysmenu(ui_wdecor_t *, void *, sysarg_t); 79 static void wd_sysmenu_open(ui_wdecor_t *, void *, sysarg_t); 80 static void wd_sysmenu_left(ui_wdecor_t *, void *, sysarg_t); 81 static void wd_sysmenu_right(ui_wdecor_t *, void *, sysarg_t); 82 static void wd_sysmenu_accel(ui_wdecor_t *, void *, char32_t, sysarg_t); 79 83 static void wd_minimize(ui_wdecor_t *, void *); 80 84 static void wd_maximize(ui_wdecor_t *, void *); … … 87 91 88 92 static ui_wdecor_cb_t wdecor_cb = { 89 .sysmenu = wd_sysmenu, 93 .sysmenu_open = wd_sysmenu_open, 94 .sysmenu_left = wd_sysmenu_left, 95 .sysmenu_right = wd_sysmenu_right, 96 .sysmenu_accel = wd_sysmenu_accel, 90 97 .minimize = wd_minimize, 91 98 .maximize = wd_maximize, … … 1036 1043 * @param idev_id Input device ID 1037 1044 */ 1038 static void wd_sysmenu (ui_wdecor_t *wdecor, void *arg, sysarg_t idev_id)1045 static void wd_sysmenu_open(ui_wdecor_t *wdecor, void *arg, sysarg_t idev_id) 1039 1046 { 1040 1047 ui_window_t *window = (ui_window_t *) arg; 1041 1048 1042 1049 ui_window_send_sysmenu(window, idev_id); 1050 } 1051 1052 /** Window decoration requested moving left from system menu handle. 1053 * 1054 * @param wdecor Window decoration 1055 * @param arg Argument (window) 1056 * @param idev_id Input device ID 1057 */ 1058 static void wd_sysmenu_left(ui_wdecor_t *wdecor, void *arg, sysarg_t idev_id) 1059 { 1060 ui_window_t *window = (ui_window_t *) arg; 1061 1062 if (window->mbar != NULL) { 1063 ui_menu_bar_select_last(window->mbar, false, idev_id); 1064 ui_wdecor_sysmenu_hdl_set_active(window->wdecor, false); 1065 } 1066 } 1067 1068 /** Window decoration requested moving right from system menu handle. 1069 * 1070 * @param wdecor Window decoration 1071 * @param arg Argument (window) 1072 * @param idev_id Input device ID 1073 */ 1074 static void wd_sysmenu_right(ui_wdecor_t *wdecor, void *arg, sysarg_t idev_id) 1075 { 1076 ui_window_t *window = (ui_window_t *) arg; 1077 1078 if (window->mbar != NULL) { 1079 ui_menu_bar_select_first(window->mbar, false, idev_id); 1080 ui_wdecor_sysmenu_hdl_set_active(window->wdecor, false); 1081 } 1082 } 1083 1084 /** Window decoration detected accelerator press from system menu handle. 1085 * 1086 * @param wdecor Window decoration 1087 * @param arg Argument (window) 1088 * @param c Accelerator key 1089 * @param idev_id Input device ID 1090 */ 1091 static void wd_sysmenu_accel(ui_wdecor_t *wdecor, void *arg, char32_t c, 1092 sysarg_t idev_id) 1093 { 1094 ui_window_t *window = (ui_window_t *) arg; 1095 1096 if (window->mbar != NULL) { 1097 ui_menu_bar_press_accel(window->mbar, c, idev_id); 1098 ui_wdecor_sysmenu_hdl_set_active(window->wdecor, false); 1099 } 1043 1100 } 1044 1101 … … 1491 1548 static void wnd_sysmenu_left(ui_menu_t *sysmenu, void *arg, sysarg_t idev_id) 1492 1549 { 1550 ui_window_t *window = (ui_window_t *)arg; 1551 1493 1552 (void)sysmenu; 1494 (void)arg; 1495 (void)idev_id; 1553 1554 if (window->mbar != NULL) 1555 ui_menu_bar_select_last(window->mbar, true, idev_id); 1496 1556 } 1497 1557 … … 1504 1564 static void wnd_sysmenu_right(ui_menu_t *sysmenu, void *arg, sysarg_t idev_id) 1505 1565 { 1566 ui_window_t *window = (ui_window_t *)arg; 1567 1506 1568 (void)sysmenu; 1507 (void)arg; 1508 (void)idev_id; 1569 1570 if (window->mbar != NULL) 1571 ui_menu_bar_select_first(window->mbar, true, idev_id); 1509 1572 } 1510 1573 -
uspace/lib/ui/test/menubar.c
red1a948 r8d1bcd7 37 37 #include <ui/window.h> 38 38 #include "../private/menubar.h" 39 #include "../private/wdecor.h" 40 #include "../private/window.h" 39 41 40 42 PCUT_INIT; … … 45 47 PCUT_TEST(create_destroy) 46 48 { 47 ui_menu_bar_t *mbar = NULL; 48 errno_t rc; 49 50 rc = ui_menu_bar_create(NULL, NULL, &mbar); 51 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 52 PCUT_ASSERT_NOT_NULL(mbar); 53 54 ui_menu_bar_destroy(mbar); 49 ui_t *ui = NULL; 50 ui_window_t *window = NULL; 51 ui_wnd_params_t params; 52 ui_menu_bar_t *mbar = NULL; 53 errno_t rc; 54 55 rc = ui_create_disp(NULL, &ui); 56 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 57 58 ui_wnd_params_init(¶ms); 59 params.caption = "Hello"; 60 61 rc = ui_window_create(ui, ¶ms, &window); 62 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 63 PCUT_ASSERT_NOT_NULL(window); 64 65 rc = ui_menu_bar_create(ui, window, &mbar); 66 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 67 PCUT_ASSERT_NOT_NULL(mbar); 68 69 ui_menu_bar_destroy(mbar); 70 ui_window_destroy(window); 71 ui_destroy(ui); 55 72 } 56 73 … … 64 81 PCUT_TEST(ctl) 65 82 { 83 ui_t *ui = NULL; 84 ui_window_t *window = NULL; 85 ui_wnd_params_t params; 66 86 ui_menu_bar_t *mbar = NULL; 67 87 ui_control_t *control; 68 88 errno_t rc; 69 89 70 rc = ui_menu_bar_create(NULL, NULL, &mbar); 90 rc = ui_create_disp(NULL, &ui); 91 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 92 93 ui_wnd_params_init(¶ms); 94 params.caption = "Hello"; 95 96 rc = ui_window_create(ui, ¶ms, &window); 97 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 98 PCUT_ASSERT_NOT_NULL(window); 99 100 rc = ui_menu_bar_create(ui, window, &mbar); 71 101 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 72 102 PCUT_ASSERT_NOT_NULL(mbar); … … 76 106 77 107 ui_control_destroy(control); 108 ui_window_destroy(window); 109 ui_destroy(ui); 78 110 } 79 111 … … 344 376 } 345 377 378 /** ui_menu_bar_select_first/last() selects first/last drop-down */ 379 PCUT_TEST(select_first_last) 380 { 381 ui_t *ui = NULL; 382 ui_window_t *window = NULL; 383 ui_wnd_params_t params; 384 ui_menu_bar_t *mbar = NULL; 385 ui_menu_dd_t *mdd1 = NULL; 386 ui_menu_dd_t *mdd2 = NULL; 387 errno_t rc; 388 389 rc = ui_create_disp(NULL, &ui); 390 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 391 392 ui_wnd_params_init(¶ms); 393 params.caption = "Hello"; 394 395 rc = ui_window_create(ui, ¶ms, &window); 396 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 397 PCUT_ASSERT_NOT_NULL(window); 398 399 rc = ui_menu_bar_create(ui, window, &mbar); 400 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 401 PCUT_ASSERT_NOT_NULL(mbar); 402 403 rc = ui_menu_dd_create(mbar, "Test 1", &mdd1, NULL); 404 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 405 PCUT_ASSERT_NOT_NULL(mdd1); 406 407 rc = ui_menu_dd_create(mbar, "Test 2", &mdd2, NULL); 408 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 409 PCUT_ASSERT_NOT_NULL(mdd2); 410 411 ui_menu_bar_select_first(mbar, true, 0); 412 PCUT_ASSERT_EQUALS(mdd1, mbar->selected); 413 414 ui_menu_bar_select_last(mbar, true, 0); 415 PCUT_ASSERT_EQUALS(mdd2, mbar->selected); 416 417 ui_menu_bar_destroy(mbar); 418 ui_window_destroy(window); 419 ui_destroy(ui); 420 } 421 422 /** ui_menu_bar_select_sysmenu() activates system menu */ 423 PCUT_TEST(select_sysmenu) 424 { 425 ui_t *ui = NULL; 426 ui_window_t *window = NULL; 427 ui_wnd_params_t params; 428 ui_menu_bar_t *mbar = NULL; 429 ui_menu_dd_t *mdd1 = NULL; 430 ui_menu_dd_t *mdd2 = NULL; 431 errno_t rc; 432 433 rc = ui_create_disp(NULL, &ui); 434 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 435 436 ui_wnd_params_init(¶ms); 437 params.caption = "Hello"; 438 439 rc = ui_window_create(ui, ¶ms, &window); 440 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 441 PCUT_ASSERT_NOT_NULL(window); 442 443 rc = ui_menu_bar_create(ui, window, &mbar); 444 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 445 PCUT_ASSERT_NOT_NULL(mbar); 446 447 rc = ui_menu_dd_create(mbar, "Test 1", &mdd1, NULL); 448 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 449 PCUT_ASSERT_NOT_NULL(mdd1); 450 451 rc = ui_menu_dd_create(mbar, "Test 2", &mdd2, NULL); 452 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 453 PCUT_ASSERT_NOT_NULL(mdd2); 454 455 ui_menu_bar_select_sysmenu(mbar, 0); 456 PCUT_ASSERT_TRUE(window->wdecor->sysmenu_hdl_active); 457 458 ui_menu_bar_destroy(mbar); 459 ui_window_destroy(window); 460 ui_destroy(ui); 461 } 462 346 463 /** ui_menu_bar_activate() activates/deactivates menu bar */ 347 464 PCUT_TEST(activate_deactivate) -
uspace/lib/ui/test/menudd.c
red1a948 r8d1bcd7 48 48 PCUT_TEST(create_destroy) 49 49 { 50 ui_t *ui = NULL; 51 ui_window_t *window = NULL; 52 ui_wnd_params_t params; 50 53 ui_menu_bar_t *mbar = NULL; 51 54 ui_menu_dd_t *mdd = NULL; … … 53 56 errno_t rc; 54 57 55 rc = ui_menu_bar_create(NULL, NULL, &mbar); 58 rc = ui_create_disp(NULL, &ui); 59 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 60 61 ui_wnd_params_init(¶ms); 62 params.caption = "Hello"; 63 64 rc = ui_window_create(ui, ¶ms, &window); 65 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 66 PCUT_ASSERT_NOT_NULL(window); 67 68 rc = ui_menu_bar_create(ui, window, &mbar); 56 69 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 57 70 … … 68 81 ui_menu_dd_destroy(mdd); 69 82 ui_menu_bar_destroy(mbar); 83 ui_window_destroy(window); 84 ui_destroy(ui); 70 85 } 71 86 -
uspace/lib/ui/test/wdecor.c
red1a948 r8d1bcd7 62 62 }; 63 63 64 static void test_wdecor_sysmenu(ui_wdecor_t *, void *, sysarg_t); 64 static void test_wdecor_sysmenu_open(ui_wdecor_t *, void *, sysarg_t); 65 static void test_wdecor_sysmenu_left(ui_wdecor_t *, void *, sysarg_t); 66 static void test_wdecor_sysmenu_right(ui_wdecor_t *, void *, sysarg_t); 67 static void test_wdecor_sysmenu_accel(ui_wdecor_t *, void *, char32_t, 68 sysarg_t); 65 69 static void test_wdecor_minimize(ui_wdecor_t *, void *); 66 70 static void test_wdecor_maximize(ui_wdecor_t *, void *); … … 73 77 74 78 static ui_wdecor_cb_t test_wdecor_cb = { 75 .sysmenu = test_wdecor_sysmenu, 79 .sysmenu_open = test_wdecor_sysmenu_open, 80 .sysmenu_left = test_wdecor_sysmenu_left, 81 .sysmenu_right = test_wdecor_sysmenu_right, 82 .sysmenu_accel = test_wdecor_sysmenu_accel, 76 83 .minimize = test_wdecor_minimize, 77 84 .maximize = test_wdecor_maximize, … … 104 111 105 112 typedef struct { 106 bool sysmenu; 113 bool sysmenu_open; 114 bool sysmenu_left; 115 bool sysmenu_right; 116 bool sysmenu_accel; 107 117 bool minimize; 108 118 bool maximize; … … 113 123 sysarg_t pos_id; 114 124 sysarg_t idev_id; 125 char32_t accel; 115 126 bool resize; 116 127 ui_wdecor_rsztype_t rsztype; … … 312 323 } 313 324 314 /** Test ui_wdecor_sysmenu () */315 PCUT_TEST(sysmenu )325 /** Test ui_wdecor_sysmenu_open() */ 326 PCUT_TEST(sysmenu_open) 316 327 { 317 328 errno_t rc; … … 322 333 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 323 334 324 /* Sysmenu callback with no callbacks set */325 ui_wdecor_sysmenu (wdecor, 42);326 327 /* Sysmenu callback with sysmenu callback not implemented */335 /* Sysmenu open callback with no callbacks set */ 336 ui_wdecor_sysmenu_open(wdecor, 42); 337 338 /* Sysmenu open callback with sysmenu callback not implemented */ 328 339 ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL); 329 ui_wdecor_sysmenu (wdecor, 42);330 331 /* Sysmenu callback with real callback set */332 resp.sysmenu = false;340 ui_wdecor_sysmenu_open(wdecor, 42); 341 342 /* Sysmenu open callback with real callback set */ 343 resp.sysmenu_open = false; 333 344 resp.idev_id = 0; 334 345 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp); 335 ui_wdecor_sysmenu(wdecor, 42); 336 PCUT_ASSERT_TRUE(resp.sysmenu); 346 ui_wdecor_sysmenu_open(wdecor, 42); 347 PCUT_ASSERT_TRUE(resp.sysmenu_open); 348 PCUT_ASSERT_INT_EQUALS(42, resp.idev_id); 349 350 ui_wdecor_destroy(wdecor); 351 } 352 353 /** Test ui_wdecor_sysmenu_left() */ 354 PCUT_TEST(sysmenu_left) 355 { 356 errno_t rc; 357 ui_wdecor_t *wdecor; 358 test_cb_resp_t resp; 359 360 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 361 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 362 363 /* Sysmenu left callback with no callbacks set */ 364 ui_wdecor_sysmenu_left(wdecor, 42); 365 366 /* Sysmenu left callback with sysmenu callback not implemented */ 367 ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL); 368 ui_wdecor_sysmenu_left(wdecor, 42); 369 370 /* Sysmenu left callback with real callback set */ 371 resp.sysmenu_left = false; 372 resp.idev_id = 0; 373 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp); 374 ui_wdecor_sysmenu_left(wdecor, 42); 375 PCUT_ASSERT_TRUE(resp.sysmenu_left); 376 PCUT_ASSERT_INT_EQUALS(42, resp.idev_id); 377 378 ui_wdecor_destroy(wdecor); 379 } 380 381 /** Test ui_wdecor_sysmenu_right() */ 382 PCUT_TEST(sysmenu_right) 383 { 384 errno_t rc; 385 ui_wdecor_t *wdecor; 386 test_cb_resp_t resp; 387 388 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 389 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 390 391 /* Sysmenu right callback with no callbacks set */ 392 ui_wdecor_sysmenu_right(wdecor, 42); 393 394 /* Sysmenu right callback with sysmenu callback not implemented */ 395 ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL); 396 ui_wdecor_sysmenu_right(wdecor, 42); 397 398 /* Sysmenu right callback with real callback set */ 399 resp.sysmenu_right = false; 400 resp.idev_id = 0; 401 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp); 402 ui_wdecor_sysmenu_right(wdecor, 42); 403 PCUT_ASSERT_TRUE(resp.sysmenu_right); 404 PCUT_ASSERT_INT_EQUALS(42, resp.idev_id); 405 406 ui_wdecor_destroy(wdecor); 407 } 408 409 /** Test ui_wdecor_sysmenu_accel() */ 410 PCUT_TEST(sysmenu_accel) 411 { 412 errno_t rc; 413 ui_wdecor_t *wdecor; 414 test_cb_resp_t resp; 415 416 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 417 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 418 419 /* Sysmenu accelerator callback with no callbacks set */ 420 ui_wdecor_sysmenu_accel(wdecor, 'a', 42); 421 422 /* Sysmenu accelerator callback with sysmenu callback not implemented */ 423 ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL); 424 ui_wdecor_sysmenu_accel(wdecor, 'a', 42); 425 426 /* Sysmenu accelerator callback with real callback set */ 427 resp.sysmenu_accel = false; 428 resp.idev_id = 0; 429 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp); 430 ui_wdecor_sysmenu_accel(wdecor, 'a', 42); 431 PCUT_ASSERT_TRUE(resp.sysmenu_accel); 432 PCUT_ASSERT_INT_EQUALS('a', resp.accel); 337 433 PCUT_ASSERT_INT_EQUALS(42, resp.idev_id); 338 434 … … 649 745 } 650 746 651 /** Pressing F9 generates sysmenu event */ 652 PCUT_TEST(kbd_f9_sysmenu) 747 /** Pressing F10 generates sysmenu event. 748 * 749 * Note that in a window with menu bar the menu bar would claim F10 750 * so it would never be delivered to window decoration. 751 */ 752 PCUT_TEST(kbd_f10_sysmenu) 653 753 { 654 754 errno_t rc; … … 681 781 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp); 682 782 683 resp.move = false; 684 resp.pos.x = 0; 685 resp.pos.y = 0; 783 resp.sysmenu_open = false; 686 784 687 785 event.type = KEY_PRESS; 688 786 event.mods = 0; 689 event.key = KC_F 9;787 event.key = KC_F10; 690 788 event.kbd_id = 42; 691 789 ui_wdecor_kbd_event(wdecor, &event); 692 790 693 PCUT_ASSERT_TRUE(resp.sysmenu); 791 PCUT_ASSERT_TRUE(resp.sysmenu_open); 792 PCUT_ASSERT_INT_EQUALS(event.kbd_id, resp.idev_id); 793 794 ui_wdecor_destroy(wdecor); 795 ui_resource_destroy(resource); 796 797 rc = gfx_context_delete(gc); 798 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 799 } 800 801 /** Down key with active sysmenu handle generates sysmenu open event */ 802 PCUT_TEST(kbd_down_sysmenu) 803 { 804 errno_t rc; 805 gfx_rect_t rect; 806 kbd_event_t event; 807 gfx_context_t *gc = NULL; 808 test_gc_t tgc; 809 test_cb_resp_t resp; 810 ui_resource_t *resource = NULL; 811 ui_wdecor_t *wdecor; 812 813 memset(&tgc, 0, sizeof(tgc)); 814 rc = gfx_context_new(&ops, &tgc, &gc); 815 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 816 817 rc = ui_resource_create(gc, false, &resource); 818 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 819 PCUT_ASSERT_NOT_NULL(resource); 820 821 rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor); 822 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 823 824 rect.p0.x = 10; 825 rect.p0.y = 20; 826 rect.p1.x = 100; 827 rect.p1.y = 200; 828 829 ui_wdecor_set_rect(wdecor, &rect); 830 831 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp); 832 833 ui_wdecor_sysmenu_hdl_set_active(wdecor, true); 834 835 resp.sysmenu_open = false; 836 837 event.type = KEY_PRESS; 838 event.mods = 0; 839 event.key = KC_DOWN; 840 event.kbd_id = 42; 841 ui_wdecor_kbd_event(wdecor, &event); 842 843 PCUT_ASSERT_TRUE(resp.sysmenu_open); 844 PCUT_ASSERT_INT_EQUALS(event.kbd_id, resp.idev_id); 845 846 ui_wdecor_destroy(wdecor); 847 ui_resource_destroy(resource); 848 849 rc = gfx_context_delete(gc); 850 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 851 } 852 853 /** Left key with active sysmenu handle generates sysmenu left event */ 854 PCUT_TEST(kbd_left_sysmenu) 855 { 856 errno_t rc; 857 gfx_rect_t rect; 858 kbd_event_t event; 859 gfx_context_t *gc = NULL; 860 test_gc_t tgc; 861 test_cb_resp_t resp; 862 ui_resource_t *resource = NULL; 863 ui_wdecor_t *wdecor; 864 865 memset(&tgc, 0, sizeof(tgc)); 866 rc = gfx_context_new(&ops, &tgc, &gc); 867 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 868 869 rc = ui_resource_create(gc, false, &resource); 870 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 871 PCUT_ASSERT_NOT_NULL(resource); 872 873 rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor); 874 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 875 876 rect.p0.x = 10; 877 rect.p0.y = 20; 878 rect.p1.x = 100; 879 rect.p1.y = 200; 880 881 ui_wdecor_set_rect(wdecor, &rect); 882 883 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp); 884 885 ui_wdecor_sysmenu_hdl_set_active(wdecor, true); 886 887 resp.sysmenu_left = false; 888 889 event.type = KEY_PRESS; 890 event.mods = 0; 891 event.key = KC_LEFT; 892 event.kbd_id = 42; 893 ui_wdecor_kbd_event(wdecor, &event); 894 895 PCUT_ASSERT_TRUE(resp.sysmenu_left); 896 PCUT_ASSERT_INT_EQUALS(event.kbd_id, resp.idev_id); 897 898 ui_wdecor_destroy(wdecor); 899 ui_resource_destroy(resource); 900 901 rc = gfx_context_delete(gc); 902 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 903 } 904 905 /** Right key with active sysmenu handle generates sysmenu right event */ 906 PCUT_TEST(kbd_right_sysmenu) 907 { 908 errno_t rc; 909 gfx_rect_t rect; 910 kbd_event_t event; 911 gfx_context_t *gc = NULL; 912 test_gc_t tgc; 913 test_cb_resp_t resp; 914 ui_resource_t *resource = NULL; 915 ui_wdecor_t *wdecor; 916 917 memset(&tgc, 0, sizeof(tgc)); 918 rc = gfx_context_new(&ops, &tgc, &gc); 919 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 920 921 rc = ui_resource_create(gc, false, &resource); 922 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 923 PCUT_ASSERT_NOT_NULL(resource); 924 925 rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor); 926 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 927 928 rect.p0.x = 10; 929 rect.p0.y = 20; 930 rect.p1.x = 100; 931 rect.p1.y = 200; 932 933 ui_wdecor_set_rect(wdecor, &rect); 934 935 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp); 936 937 ui_wdecor_sysmenu_hdl_set_active(wdecor, true); 938 939 resp.sysmenu_right = false; 940 941 event.type = KEY_PRESS; 942 event.mods = 0; 943 event.key = KC_RIGHT; 944 event.kbd_id = 42; 945 ui_wdecor_kbd_event(wdecor, &event); 946 947 PCUT_ASSERT_TRUE(resp.sysmenu_right); 948 PCUT_ASSERT_INT_EQUALS(event.kbd_id, resp.idev_id); 949 950 ui_wdecor_destroy(wdecor); 951 ui_resource_destroy(resource); 952 953 rc = gfx_context_delete(gc); 954 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 955 } 956 957 /** Character key with active sysmenu handle generates sysmenu accel event */ 958 PCUT_TEST(kbd_accel_sysmenu) 959 { 960 errno_t rc; 961 gfx_rect_t rect; 962 kbd_event_t event; 963 gfx_context_t *gc = NULL; 964 test_gc_t tgc; 965 test_cb_resp_t resp; 966 ui_resource_t *resource = NULL; 967 ui_wdecor_t *wdecor; 968 969 memset(&tgc, 0, sizeof(tgc)); 970 rc = gfx_context_new(&ops, &tgc, &gc); 971 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 972 973 rc = ui_resource_create(gc, false, &resource); 974 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 975 PCUT_ASSERT_NOT_NULL(resource); 976 977 rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor); 978 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 979 980 rect.p0.x = 10; 981 rect.p0.y = 20; 982 rect.p1.x = 100; 983 rect.p1.y = 200; 984 985 ui_wdecor_set_rect(wdecor, &rect); 986 987 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp); 988 989 ui_wdecor_sysmenu_hdl_set_active(wdecor, true); 990 991 resp.sysmenu_accel = false; 992 993 event.type = KEY_PRESS; 994 event.mods = 0; 995 event.key = KC_A; 996 event.c = 'a'; 997 event.kbd_id = 42; 998 ui_wdecor_kbd_event(wdecor, &event); 999 1000 PCUT_ASSERT_TRUE(resp.sysmenu_accel); 1001 PCUT_ASSERT_INT_EQUALS(event.c, resp.accel); 694 1002 PCUT_ASSERT_INT_EQUALS(event.kbd_id, resp.idev_id); 695 1003 … … 1341 1649 } 1342 1650 1343 static void test_wdecor_sysmenu (ui_wdecor_t *wdecor, void *arg,1651 static void test_wdecor_sysmenu_open(ui_wdecor_t *wdecor, void *arg, 1344 1652 sysarg_t idev_id) 1345 1653 { 1346 1654 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 1347 1655 1348 resp->sysmenu = true; 1656 resp->sysmenu_open = true; 1657 resp->idev_id = idev_id; 1658 } 1659 1660 static void test_wdecor_sysmenu_left(ui_wdecor_t *wdecor, void *arg, 1661 sysarg_t idev_id) 1662 { 1663 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 1664 1665 resp->sysmenu_left = true; 1666 resp->idev_id = idev_id; 1667 } 1668 1669 static void test_wdecor_sysmenu_right(ui_wdecor_t *wdecor, void *arg, 1670 sysarg_t idev_id) 1671 { 1672 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 1673 1674 resp->sysmenu_right = true; 1675 resp->idev_id = idev_id; 1676 } 1677 1678 static void test_wdecor_sysmenu_accel(ui_wdecor_t *wdecor, void *arg, 1679 char32_t accel, sysarg_t idev_id) 1680 { 1681 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 1682 1683 resp->sysmenu_accel = true; 1684 resp->accel = accel; 1349 1685 resp->idev_id = idev_id; 1350 1686 }
Note:
See TracChangeset
for help on using the changeset viewer.