Changeset 1af103e in mainline
- Timestamp:
- 2023-09-13T17:29:07Z (16 months ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 61643c8
- Parents:
- 46bd63c9
- Location:
- uspace/lib/ui
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/include/types/ui/wdecor.h
r46bd63c9 r1af103e 38 38 39 39 #include <gfx/coord.h> 40 #include <types/common.h> 40 41 #include <types/ui/cursor.h> 41 42 … … 51 52 /** Window has a title bar */ 52 53 ui_wds_titlebar = 0x2, 54 /** Window has a system menu */ 55 ui_wds_sysmenu = 0x4, 53 56 /** Window has a minimize button */ 54 ui_wds_minimize_btn = 0x 4,57 ui_wds_minimize_btn = 0x8, 55 58 /** Window has a maximize button */ 56 ui_wds_maximize_btn = 0x 8,59 ui_wds_maximize_btn = 0x10, 57 60 /** Window has a close button */ 58 ui_wds_close_btn = 0x 10,61 ui_wds_close_btn = 0x20, 59 62 /** Window is resizable */ 60 ui_wds_resizable = 0x 20,63 ui_wds_resizable = 0x40, 61 64 /** Window is decorated (default decoration) */ 62 ui_wds_decorated = ui_wds_frame | ui_wds_titlebar | 65 ui_wds_decorated = ui_wds_frame | ui_wds_titlebar | ui_wds_sysmenu | 63 66 ui_wds_minimize_btn | ui_wds_close_btn 64 67 } ui_wdecor_style_t; … … 81 84 /** Window decoration callbacks */ 82 85 typedef struct ui_wdecor_cb { 86 void (*sysmenu)(ui_wdecor_t *, void *, sysarg_t); 83 87 void (*minimize)(ui_wdecor_t *, void *); 84 88 void (*maximize)(ui_wdecor_t *, void *); -
uspace/lib/ui/include/types/ui/window.h
r46bd63c9 r1af103e 40 40 #include <io/kbd_event.h> 41 41 #include <io/pos_event.h> 42 #include <types/common.h> 42 43 #include <types/ui/wdecor.h> 43 44 … … 95 96 /** Window callbacks */ 96 97 typedef struct ui_window_cb { 98 void (*sysmenu)(ui_window_t *, void *, sysarg_t); 97 99 void (*minimize)(ui_window_t *, void *); 98 100 void (*maximize)(ui_window_t *, void *); -
uspace/lib/ui/include/ui/wdecor.h
r46bd63c9 r1af103e 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 39 39 #include <errno.h> 40 40 #include <gfx/coord.h> 41 #include <io/kbd_event.h> 41 42 #include <io/pos_event.h> 42 43 #include <stdbool.h> … … 54 55 extern errno_t ui_wdecor_set_caption(ui_wdecor_t *, const char *); 55 56 extern errno_t ui_wdecor_paint(ui_wdecor_t *); 57 extern ui_evclaim_t ui_wdecor_kbd_event(ui_wdecor_t *, kbd_event_t *); 56 58 extern ui_evclaim_t ui_wdecor_pos_event(ui_wdecor_t *, pos_event_t *); 57 59 extern void ui_wdecor_rect_from_app(ui_wdecor_style_t, gfx_rect_t *, -
uspace/lib/ui/include/ui/window.h
r46bd63c9 r1af103e 42 42 #include <io/kbd_event.h> 43 43 #include <io/pos_event.h> 44 #include <types/common.h> 44 45 #include <types/ui/control.h> 45 46 #include <types/ui/ui.h> … … 65 66 extern void ui_window_set_ctl_cursor(ui_window_t *, ui_stock_cursor_t); 66 67 extern errno_t ui_window_paint(ui_window_t *); 68 extern errno_t ui_window_def_sysmenu(ui_window_t *, sysarg_t); 67 69 extern errno_t ui_window_def_minimize(ui_window_t *); 68 70 extern errno_t ui_window_def_maximize(ui_window_t *); -
uspace/lib/ui/private/wdecor.h
r46bd63c9 r1af103e 41 41 #include <io/pos_event.h> 42 42 #include <stdbool.h> 43 #include <types/common.h> 43 44 #include <types/ui/cursor.h> 44 45 #include <types/ui/wdecor.h> … … 94 95 } ui_wdecor_geom_t; 95 96 97 extern void ui_wdecor_sysmenu(ui_wdecor_t *, sysarg_t); 96 98 extern void ui_wdecor_minimize(ui_wdecor_t *); 97 99 extern void ui_wdecor_maximize(ui_wdecor_t *); -
uspace/lib/ui/private/window.h
r46bd63c9 r1af103e 47 47 #include <memgfx/memgc.h> 48 48 #include <memgfx/xlategc.h> 49 #include <types/common.h> 49 50 #include <types/ui/cursor.h> 50 51 #include <types/ui/window.h> … … 93 94 /** Window decoration */ 94 95 struct ui_wdecor *wdecor; 96 /** System menu */ 97 struct ui_menu *sysmenu; 95 98 /** Top-level control in the application area */ 96 99 struct ui_control *control; … … 112 115 113 116 extern display_stock_cursor_t wnd_dcursor_from_cursor(ui_stock_cursor_t); 117 extern void ui_window_send_sysmenu(ui_window_t *, sysarg_t); 114 118 extern void ui_window_send_minimize(ui_window_t *); 115 119 extern void ui_window_send_maximize(ui_window_t *); -
uspace/lib/ui/src/wdecor.c
r46bd63c9 r1af103e 421 421 } 422 422 423 /** Send decoration sysmenu event. 424 * 425 * @param wdecor Window decoration 426 * @param idev_id Input device ID 427 */ 428 void ui_wdecor_sysmenu(ui_wdecor_t *wdecor, sysarg_t idev_id) 429 { 430 if (wdecor->cb != NULL && wdecor->cb->sysmenu != NULL) 431 wdecor->cb->sysmenu(wdecor, wdecor->arg, idev_id); 432 } 433 423 434 /** Send decoration minimize event. 424 435 * … … 805 816 } 806 817 818 /** Handle window decoration keyboard event. 819 * 820 * @param wdecor Window decoration 821 * @param kbd_event Keyboard event 822 * @return @c ui_claimed iff event was claimed 823 */ 824 ui_evclaim_t ui_wdecor_kbd_event(ui_wdecor_t *wdecor, kbd_event_t *event) 825 { 826 (void)wdecor; 827 828 if (event->type == KEY_PRESS && (event->mods & (KM_CTRL | KM_ALT | 829 KM_SHIFT)) == 0) { 830 if (event->key == KC_F9) 831 ui_wdecor_sysmenu(wdecor, event->kbd_id); 832 } 833 834 return ui_unclaimed; 835 } 836 807 837 /** Handle window frame position event. 808 838 * -
uspace/lib/ui/src/window.c
r46bd63c9 r1af103e 47 47 #include <stdlib.h> 48 48 #include <ui/control.h> 49 #include <ui/menu.h> 50 #include <ui/menuentry.h> 49 51 #include <ui/resource.h> 50 52 #include <ui/ui.h> … … 74 76 }; 75 77 78 static void wd_sysmenu(ui_wdecor_t *, void *, sysarg_t); 76 79 static void wd_minimize(ui_wdecor_t *, void *); 77 80 static void wd_maximize(ui_wdecor_t *, void *); … … 84 87 85 88 static ui_wdecor_cb_t wdecor_cb = { 89 .sysmenu = wd_sysmenu, 86 90 .minimize = wd_minimize, 87 91 .maximize = wd_maximize, … … 92 96 .set_cursor = wd_set_cursor 93 97 }; 98 99 static void wnd_sysmenu_left(ui_menu_t *, void *, sysarg_t); 100 static void wnd_sysmenu_right(ui_menu_t *, void *, sysarg_t); 101 static void wnd_sysmenu_close_req(ui_menu_t *, void *); 102 static void wnd_sysmenu_press_accel(ui_menu_t *, void *, char32_t, sysarg_t); 103 104 static ui_menu_cb_t wnd_sysmenu_cb = { 105 .left = wnd_sysmenu_left, 106 .right = wnd_sysmenu_right, 107 .close_req = wnd_sysmenu_close_req, 108 .press_accel = wnd_sysmenu_press_accel 109 }; 110 111 static void wnd_sysmenu_eclose(ui_menu_entry_t *, void *); 94 112 95 113 static void ui_window_invalidate(void *, gfx_rect_t *); … … 417 435 list_remove(&window->lwindows); 418 436 ui_control_destroy(window->control); 437 ui_menu_destroy(window->sysmenu); 419 438 ui_wdecor_destroy(window->wdecor); 420 439 ui_resource_destroy(window->res); … … 929 948 } 930 949 950 /** Window decoration requested opening of system menu. 951 * 952 * @param wdecor Window decoration 953 * @param arg Argument (window) 954 * @param idev_id Input device ID 955 */ 956 static void wd_sysmenu(ui_wdecor_t *wdecor, void *arg, sysarg_t idev_id) 957 { 958 ui_window_t *window = (ui_window_t *) arg; 959 960 ui_window_send_sysmenu(window, idev_id); 961 } 962 931 963 /** Window decoration requested window minimization. 932 964 * … … 1070 1102 } 1071 1103 1104 /** Send window sysmenu event. 1105 * 1106 * @param window Window 1107 * @parma idev_id Input device ID 1108 */ 1109 void ui_window_send_sysmenu(ui_window_t *window, sysarg_t idev_id) 1110 { 1111 if (window->cb != NULL && window->cb->sysmenu != NULL) 1112 window->cb->sysmenu(window, window->arg, idev_id); 1113 else 1114 ui_window_def_sysmenu(window, idev_id); 1115 } 1116 1072 1117 /** Send window minimize event. 1073 1118 * … … 1174 1219 else 1175 1220 return ui_window_def_unfocus(window, nfocus); 1221 } 1222 1223 /** Default window sysmenu routine. 1224 * 1225 * @param window Window 1226 * @param idev_id Input device ID 1227 * @return EOK on success or an error code 1228 */ 1229 errno_t ui_window_def_sysmenu(ui_window_t *window, sysarg_t idev_id) 1230 { 1231 errno_t rc; 1232 ui_menu_entry_t *mclose; 1233 ui_wdecor_geom_t geom; 1234 1235 if (window->sysmenu == NULL) { 1236 rc = ui_menu_create(window, &window->sysmenu); 1237 if (rc != EOK) 1238 goto error; 1239 1240 ui_menu_set_cb(window->sysmenu, &wnd_sysmenu_cb, 1241 (void *)window); 1242 1243 rc = ui_menu_entry_create(window->sysmenu, "~C~lose", "Alt-F4", 1244 &mclose); 1245 if (rc != EOK) 1246 goto error; 1247 1248 ui_menu_entry_set_cb(mclose, wnd_sysmenu_eclose, 1249 (void *)window); 1250 } 1251 1252 if (ui_menu_is_open(window->sysmenu)) { 1253 ui_menu_close(window->sysmenu); 1254 } else { 1255 ui_wdecor_get_geom(window->wdecor, &geom); 1256 1257 rc = ui_menu_open(window->sysmenu, &geom.title_bar_rect, 1258 idev_id); 1259 if (rc != EOK) 1260 goto error; 1261 } 1262 1263 return EOK; 1264 error: 1265 return rc; 1176 1266 } 1177 1267 … … 1260 1350 ui_evclaim_t ui_window_def_kbd(ui_window_t *window, kbd_event_t *kbd) 1261 1351 { 1352 ui_evclaim_t claim; 1353 1262 1354 if (window->control != NULL) 1263 return ui_control_kbd_event(window->control, kbd); 1355 claim = ui_control_kbd_event(window->control, kbd); 1356 else 1357 claim = ui_unclaimed; 1358 1359 if (claim == ui_unclaimed) 1360 return ui_wdecor_kbd_event(window->wdecor, kbd); 1264 1361 1265 1362 return ui_unclaimed; … … 1316 1413 if (window->control != NULL) 1317 1414 ui_control_unfocus(window->control, nfocus); 1415 } 1416 1417 /** Handle system menu left event. 1418 * 1419 * @param sysmenu System menu 1420 * @param arg Argument (ui_window_t *) 1421 * @param idev_id Input device ID 1422 */ 1423 static void wnd_sysmenu_left(ui_menu_t *sysmenu, void *arg, sysarg_t idev_id) 1424 { 1425 (void)sysmenu; 1426 (void)arg; 1427 (void)idev_id; 1428 } 1429 1430 /** Handle system menu right event. 1431 * 1432 * @param sysmenu System menu 1433 * @param arg Argument (ui_window_t *) 1434 * @param idev_id Input device ID 1435 */ 1436 static void wnd_sysmenu_right(ui_menu_t *sysmenu, void *arg, sysarg_t idev_id) 1437 { 1438 (void)sysmenu; 1439 (void)arg; 1440 (void)idev_id; 1441 } 1442 1443 /** Handle system menu close request event. 1444 * 1445 * @param sysmenu System menu 1446 * @param arg Argument (ui_window_t *) 1447 * @param idev_id Input device ID 1448 */ 1449 static void wnd_sysmenu_close_req(ui_menu_t *sysmenu, void *arg) 1450 { 1451 (void)arg; 1452 1453 ui_menu_close(sysmenu); 1454 } 1455 1456 /** Handle system menu Close entry activation. 1457 * 1458 * @param mentry Menu entry 1459 * @param arg Argument (ui_window_t *) 1460 */ 1461 static void wnd_sysmenu_eclose(ui_menu_entry_t *mentry, void *arg) 1462 { 1463 ui_window_t *window = (ui_window_t *)arg; 1464 1465 ui_window_send_close(window); 1466 } 1467 1468 /** Handle system menu press accelerator key event. 1469 * 1470 * @param sysmenu System menu 1471 * @param arg Argument (ui_window_t *) 1472 * @param idev_id Input device ID 1473 */ 1474 static void wnd_sysmenu_press_accel(ui_menu_t *sysmenu, void *arg, 1475 char32_t c, sysarg_t idev_id) 1476 { 1477 (void)sysmenu; 1478 (void)arg; 1479 (void)c; 1480 (void)idev_id; 1318 1481 } 1319 1482 -
uspace/lib/ui/test/wdecor.c
r46bd63c9 r1af103e 62 62 }; 63 63 64 static void test_wdecor_sysmenu(ui_wdecor_t *, void *, sysarg_t); 64 65 static void test_wdecor_minimize(ui_wdecor_t *, void *); 65 66 static void test_wdecor_maximize(ui_wdecor_t *, void *); … … 72 73 73 74 static ui_wdecor_cb_t test_wdecor_cb = { 75 .sysmenu = test_wdecor_sysmenu, 74 76 .minimize = test_wdecor_minimize, 75 77 .maximize = test_wdecor_maximize, … … 102 104 103 105 typedef struct { 106 bool sysmenu; 104 107 bool minimize; 105 108 bool maximize; … … 109 112 gfx_coord2_t pos; 110 113 sysarg_t pos_id; 114 sysarg_t idev_id; 111 115 bool resize; 112 116 ui_wdecor_rsztype_t rsztype; … … 241 245 rc = gfx_context_delete(gc); 242 246 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 247 } 248 249 /** Test ui_wdecor_sysmenu() */ 250 PCUT_TEST(sysmenu) 251 { 252 errno_t rc; 253 ui_wdecor_t *wdecor; 254 test_cb_resp_t resp; 255 256 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 257 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 258 259 /* Sysmenu callback with no callbacks set */ 260 ui_wdecor_sysmenu(wdecor, 42); 261 262 /* Sysmenu callback with sysmenu callback not implemented */ 263 ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL); 264 ui_wdecor_sysmenu(wdecor, 42); 265 266 /* Sysmenu callback with real callback set */ 267 resp.sysmenu = false; 268 resp.idev_id = 0; 269 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp); 270 ui_wdecor_sysmenu(wdecor, 42); 271 PCUT_ASSERT_TRUE(resp.sysmenu); 272 PCUT_ASSERT_INT_EQUALS(42, resp.idev_id); 273 274 ui_wdecor_destroy(wdecor); 243 275 } 244 276 … … 544 576 PCUT_ASSERT_INT_EQUALS(event.hpos, resp.pos.x); 545 577 PCUT_ASSERT_INT_EQUALS(event.vpos, resp.pos.y); 578 579 ui_wdecor_destroy(wdecor); 580 ui_resource_destroy(resource); 581 582 rc = gfx_context_delete(gc); 583 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 584 } 585 586 /** Pressing F9 generates sysmenu event */ 587 PCUT_TEST(kbd_f9_sysmenu) 588 { 589 errno_t rc; 590 gfx_rect_t rect; 591 kbd_event_t event; 592 gfx_context_t *gc = NULL; 593 test_gc_t tgc; 594 test_cb_resp_t resp; 595 ui_resource_t *resource = NULL; 596 ui_wdecor_t *wdecor; 597 598 memset(&tgc, 0, sizeof(tgc)); 599 rc = gfx_context_new(&ops, &tgc, &gc); 600 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 601 602 rc = ui_resource_create(gc, false, &resource); 603 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 604 PCUT_ASSERT_NOT_NULL(resource); 605 606 rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor); 607 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 608 609 rect.p0.x = 10; 610 rect.p0.y = 20; 611 rect.p1.x = 100; 612 rect.p1.y = 200; 613 614 ui_wdecor_set_rect(wdecor, &rect); 615 616 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp); 617 618 resp.move = false; 619 resp.pos.x = 0; 620 resp.pos.y = 0; 621 622 event.type = KEY_PRESS; 623 event.mods = 0; 624 event.key = KC_F9; 625 event.kbd_id = 42; 626 ui_wdecor_kbd_event(wdecor, &event); 627 628 PCUT_ASSERT_TRUE(resp.sysmenu); 629 PCUT_ASSERT_INT_EQUALS(event.kbd_id, resp.idev_id); 546 630 547 631 ui_wdecor_destroy(wdecor); … … 1111 1195 } 1112 1196 1197 static void test_wdecor_sysmenu(ui_wdecor_t *wdecor, void *arg, 1198 sysarg_t idev_id) 1199 { 1200 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 1201 1202 resp->sysmenu = true; 1203 resp->idev_id = idev_id; 1204 } 1205 1113 1206 static void test_wdecor_minimize(ui_wdecor_t *wdecor, void *arg) 1114 1207 { -
uspace/lib/ui/test/window.c
r46bd63c9 r1af103e 45 45 PCUT_TEST_SUITE(window); 46 46 47 static void test_window_sysmenu(ui_window_t *, void *, sysarg_t); 47 48 static void test_window_minimize(ui_window_t *, void *); 48 49 static void test_window_maximize(ui_window_t *, void *); … … 56 57 57 58 static ui_window_cb_t test_window_cb = { 59 .sysmenu = test_window_sysmenu, 58 60 .minimize = test_window_minimize, 59 61 .maximize = test_window_maximize, … … 82 84 typedef struct { 83 85 errno_t rc; 86 bool sysmenu; 87 sysarg_t sysmenu_idev_id; 84 88 bool minimize; 85 89 bool maximize; … … 544 548 } 545 549 550 /** ui_window_send_sysmenu() calls sysmenu callback set via ui_window_set_cb() */ 551 PCUT_TEST(send_sysmenu) 552 { 553 errno_t rc; 554 ui_t *ui = NULL; 555 ui_wnd_params_t params; 556 ui_window_t *window = NULL; 557 test_cb_resp_t resp; 558 559 rc = ui_create_disp(NULL, &ui); 560 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 561 562 ui_wnd_params_init(¶ms); 563 params.caption = "Hello"; 564 565 rc = ui_window_create(ui, ¶ms, &window); 566 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 567 PCUT_ASSERT_NOT_NULL(window); 568 569 /* Sysmenu callback with no callbacks set */ 570 ui_window_send_sysmenu(window, 42); 571 572 /* Sysmenu callback with sysmenu callback not implemented */ 573 ui_window_set_cb(window, &dummy_window_cb, NULL); 574 ui_window_send_sysmenu(window, 42); 575 576 /* Sysmenu callback with real callback set */ 577 resp.sysmenu = false; 578 resp.sysmenu_idev_id = 0; 579 ui_window_set_cb(window, &test_window_cb, &resp); 580 ui_window_send_sysmenu(window, 42); 581 PCUT_ASSERT_TRUE(resp.sysmenu); 582 PCUT_ASSERT_INT_EQUALS(42, resp.sysmenu_idev_id); 583 584 ui_window_destroy(window); 585 ui_destroy(ui); 586 } 587 546 588 /** ui_window_send_minimize() calls minimize callback set via ui_window_set_cb() */ 547 589 PCUT_TEST(send_minimize) … … 894 936 } 895 937 938 static void test_window_sysmenu(ui_window_t *window, void *arg, sysarg_t idev_id) 939 { 940 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 941 942 resp->sysmenu = true; 943 resp->sysmenu_idev_id = idev_id; 944 } 945 896 946 static void test_window_minimize(ui_window_t *window, void *arg) 897 947 {
Note:
See TracChangeset
for help on using the changeset viewer.