Changeset 7cc30e9 in mainline
- Timestamp:
- 2022-10-24T17:50:46Z (2 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 913add60
- Parents:
- 7a05d924
- Location:
- uspace
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/gfxdemo/gfxdemo.c
r7a05d924 r7cc30e9 1069 1069 params.rect.p1.x = 400; 1070 1070 params.rect.p1.y = 300; 1071 params.caption = "GFX Demo"; 1071 1072 1072 1073 rc = display_window_create(display, ¶ms, &wnd_cb, NULL, &window); -
uspace/lib/display/include/disp_srv.h
r7a05d924 r7cc30e9 67 67 errno_t (*window_unmaximize)(void *, sysarg_t); 68 68 errno_t (*window_set_cursor)(void *, sysarg_t, display_stock_cursor_t); 69 errno_t (*window_set_caption)(void *, sysarg_t, const char *); 69 70 errno_t (*get_event)(void *, sysarg_t *, display_wnd_ev_t *); 70 71 errno_t (*get_info)(void *, display_info_t *); -
uspace/lib/display/include/display.h
r7a05d924 r7cc30e9 66 66 extern errno_t display_window_set_cursor(display_window_t *, 67 67 display_stock_cursor_t); 68 extern errno_t display_window_set_caption(display_window_t *, const char *); 68 69 69 70 #endif -
uspace/lib/display/include/ipc/display.h
r7a05d924 r7cc30e9 50 50 DISPLAY_WINDOW_RESIZE_REQ, 51 51 DISPLAY_WINDOW_SET_CURSOR, 52 DISPLAY_WINDOW_SET_CAPTION, 52 53 DISPLAY_WINDOW_UNMAXIMIZE, 53 54 DISPLAY_GET_EVENT, -
uspace/lib/display/include/types/display/wndparams.h
r7a05d924 r7cc30e9 58 58 /** Bounding rectangle */ 59 59 gfx_rect_t rect; 60 /** Window caption */ 61 const char *caption; 60 62 /** Minimum size (when being resized) */ 61 63 gfx_coord2_t min_size; -
uspace/lib/display/private/params.h
r7a05d924 r7cc30e9 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 46 46 } display_wnd_resize_t; 47 47 48 /** Display window parameters encoded for transport 49 * 50 * This omits variable-length fields (window caption). 51 */ 52 typedef struct { 53 /** Bounding rectangle */ 54 gfx_rect_t rect; 55 /** Window caption size in bytes */ 56 size_t caption_size; 57 /** Minimum size (when being resized) */ 58 gfx_coord2_t min_size; 59 /** Initial position (if flag wndf_setpos is set) */ 60 gfx_coord2_t pos; 61 /** Flags */ 62 display_wnd_flags_t flags; 63 } display_wnd_params_enc_t; 64 48 65 #endif 49 66 -
uspace/lib/display/src/disp_srv.c
r7a05d924 r7cc30e9 63 63 sysarg_t wnd_id; 64 64 ipc_call_t call; 65 display_wnd_params_enc_t eparams; 65 66 display_wnd_params_t params; 67 char *caption; 66 68 size_t size; 67 69 errno_t rc; … … 73 75 } 74 76 75 if (size != sizeof(display_wnd_params_t)) { 76 async_answer_0(&call, EINVAL); 77 async_answer_0(icall, EINVAL); 78 return; 79 } 80 81 rc = async_data_write_finalize(&call, ¶ms, size); 82 if (rc != EOK) { 77 if (size != sizeof(display_wnd_params_enc_t)) { 78 async_answer_0(&call, EINVAL); 79 async_answer_0(icall, EINVAL); 80 return; 81 } 82 83 rc = async_data_write_finalize(&call, &eparams, size); 84 if (rc != EOK) { 85 async_answer_0(&call, rc); 86 async_answer_0(icall, rc); 87 return; 88 } 89 90 caption = calloc(eparams.caption_size + 1, 1); 91 if (caption == NULL) { 92 async_answer_0(icall, ENOMEM); 93 return; 94 } 95 96 if (!async_data_write_receive(&call, &size)) { 97 free(caption); 98 async_answer_0(&call, EREFUSED); 99 async_answer_0(icall, EREFUSED); 100 return; 101 } 102 103 if (size != eparams.caption_size) { 104 free(caption); 105 async_answer_0(&call, EINVAL); 106 async_answer_0(icall, EINVAL); 107 return; 108 } 109 110 rc = async_data_write_finalize(&call, caption, eparams.caption_size); 111 if (rc != EOK) { 112 free(caption); 83 113 async_answer_0(&call, rc); 84 114 async_answer_0(icall, rc); … … 87 117 88 118 if (srv->ops->window_create == NULL) { 89 async_answer_0(icall, ENOTSUP); 90 return; 91 } 119 free(caption); 120 async_answer_0(icall, ENOTSUP); 121 return; 122 } 123 124 /* Decode the parameters from transport */ 125 params.rect = eparams.rect; 126 params.caption = caption; 127 params.min_size = eparams.min_size; 128 params.pos = eparams.pos; 129 params.flags = eparams.flags; 92 130 93 131 rc = srv->ops->window_create(srv->arg, ¶ms, &wnd_id); … … 401 439 rc = srv->ops->window_set_cursor(srv->arg, wnd_id, cursor); 402 440 async_answer_0(icall, rc); 441 } 442 443 static void display_window_set_caption_srv(display_srv_t *srv, 444 ipc_call_t *icall) 445 { 446 sysarg_t wnd_id; 447 ipc_call_t call; 448 char *caption; 449 size_t size; 450 errno_t rc; 451 452 wnd_id = ipc_get_arg1(icall); 453 454 if (!async_data_write_receive(&call, &size)) { 455 async_answer_0(&call, EREFUSED); 456 async_answer_0(icall, EREFUSED); 457 return; 458 } 459 460 caption = calloc(size + 1, 1); 461 if (caption == NULL) { 462 async_answer_0(&call, ENOMEM); 463 async_answer_0(icall, ENOMEM); 464 return; 465 } 466 467 rc = async_data_write_finalize(&call, caption, size); 468 if (rc != EOK) { 469 free(caption); 470 async_answer_0(&call, rc); 471 async_answer_0(icall, rc); 472 return; 473 } 474 475 if (srv->ops->window_set_caption == NULL) { 476 free(caption); 477 async_answer_0(icall, ENOTSUP); 478 return; 479 } 480 481 rc = srv->ops->window_set_caption(srv->arg, wnd_id, caption); 482 async_answer_0(icall, rc); 483 free(caption); 403 484 } 404 485 … … 538 619 case DISPLAY_WINDOW_SET_CURSOR: 539 620 display_window_set_cursor_srv(srv, &call); 621 break; 622 case DISPLAY_WINDOW_SET_CAPTION: 623 display_window_set_caption_srv(srv, &call); 540 624 break; 541 625 case DISPLAY_GET_EVENT: -
uspace/lib/display/src/display.c
r7a05d924 r7cc30e9 38 38 #include <mem.h> 39 39 #include <stdlib.h> 40 #include <str.h> 40 41 #include "../private/display.h" 41 42 #include "../private/params.h" … … 147 148 { 148 149 memset(params, 0, sizeof(*params)); 150 params->caption = ""; 149 151 } 150 152 … … 162 164 { 163 165 display_window_t *window; 164 async_exch_t *exch; 165 aid_t req; 166 ipc_call_t answer; 167 errno_t rc; 166 display_wnd_params_enc_t eparams; 167 async_exch_t *exch; 168 aid_t req; 169 ipc_call_t answer; 170 errno_t rc; 171 172 /* Encode the parameters for transport */ 173 eparams.rect = params->rect; 174 eparams.caption_size = str_size(params->caption); 175 eparams.min_size = params->min_size; 176 eparams.pos = params->pos; 177 eparams.flags = params->flags; 168 178 169 179 window = calloc(1, sizeof(display_window_t)); … … 173 183 exch = async_exchange_begin(display->sess); 174 184 req = async_send_0(exch, DISPLAY_WINDOW_CREATE, &answer); 175 rc = async_data_write_start(exch, params, sizeof (display_wnd_params_t)); 185 186 /* Write fixed fields */ 187 rc = async_data_write_start(exch, &eparams, 188 sizeof (display_wnd_params_enc_t)); 189 if (rc != EOK) { 190 async_exchange_end(exch); 191 async_forget(req); 192 free(window); 193 return rc; 194 } 195 196 /* Write caption */ 197 rc = async_data_write_start(exch, params->caption, 198 eparams.caption_size); 176 199 async_exchange_end(exch); 177 200 if (rc != EOK) { … … 540 563 cursor); 541 564 async_exchange_end(exch); 565 return rc; 566 } 567 568 /** Set display window caption. 569 * 570 * @param window Window 571 * @param caption New caption 572 * @return EOK on success or an error code 573 */ 574 errno_t display_window_set_caption(display_window_t *window, 575 const char *caption) 576 { 577 async_exch_t *exch; 578 aid_t req; 579 ipc_call_t answer; 580 size_t cap_size; 581 errno_t rc; 582 583 cap_size = str_size(caption); 584 585 exch = async_exchange_begin(window->display->sess); 586 req = async_send_1(exch, DISPLAY_WINDOW_SET_CAPTION, window->id, 587 &answer); 588 589 /* Write caption */ 590 rc = async_data_write_start(exch, caption, cap_size); 591 async_exchange_end(exch); 592 if (rc != EOK) { 593 async_forget(req); 594 return rc; 595 } 596 597 async_wait_for(req, &rc); 542 598 return rc; 543 599 } -
uspace/lib/display/test/display.c
r7a05d924 r7cc30e9 38 38 #include <loc.h> 39 39 #include <pcut/pcut.h> 40 #include <str.h> 40 41 #include "../private/display.h" 41 42 … … 68 69 static errno_t test_window_unmaximize(void *, sysarg_t); 69 70 static errno_t test_window_set_cursor(void *, sysarg_t, display_stock_cursor_t); 71 static errno_t test_window_set_caption(void *, sysarg_t, const char *); 70 72 static errno_t test_get_event(void *, sysarg_t *, display_wnd_ev_t *); 71 73 static errno_t test_get_info(void *, display_info_t *); … … 85 87 .window_unmaximize = test_window_unmaximize, 86 88 .window_set_cursor = test_window_set_cursor, 89 .window_set_caption = test_window_set_caption, 87 90 .get_event = test_get_event, 88 91 .get_info = test_get_info … … 148 151 sysarg_t set_cursor_wnd_id; 149 152 display_stock_cursor_t set_cursor_cursor; 153 154 bool window_set_caption_called; 155 sysarg_t set_caption_wnd_id; 156 char *set_caption_caption; 150 157 151 158 bool get_event_called; … … 1240 1247 PCUT_ASSERT_INT_EQUALS(dcurs_size_ud, resp.set_cursor_cursor); 1241 1248 1249 display_window_destroy(wnd); 1250 display_close(disp); 1251 rc = loc_service_unregister(sid); 1252 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1253 } 1254 1255 /** display_window_set_caption() with server returning error response works. */ 1256 PCUT_TEST(window_set_caption_failure) 1257 { 1258 errno_t rc; 1259 service_id_t sid; 1260 display_t *disp = NULL; 1261 display_wnd_params_t params; 1262 display_window_t *wnd; 1263 const char *caption; 1264 test_response_t resp; 1265 1266 async_set_fallback_port_handler(test_display_conn, &resp); 1267 1268 // FIXME This causes this test to be non-reentrant! 1269 rc = loc_server_register(test_display_server); 1270 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1271 1272 rc = loc_service_register(test_display_svc, &sid); 1273 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1274 1275 rc = display_open(test_display_svc, &disp); 1276 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1277 PCUT_ASSERT_NOT_NULL(disp); 1278 1279 resp.rc = EOK; 1280 display_wnd_params_init(¶ms); 1281 params.rect.p0.x = 0; 1282 params.rect.p0.y = 0; 1283 params.rect.p0.x = 100; 1284 params.rect.p0.y = 100; 1285 1286 rc = display_window_create(disp, ¶ms, &test_display_wnd_cb, 1287 (void *) &resp, &wnd); 1288 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1289 PCUT_ASSERT_NOT_NULL(wnd); 1290 1291 caption = "Hello"; 1292 1293 resp.rc = EIO; 1294 resp.window_set_caption_called = false; 1295 1296 rc = display_window_set_caption(wnd, caption); 1297 PCUT_ASSERT_INT_EQUALS(wnd->id, resp.set_caption_wnd_id); 1298 PCUT_ASSERT_TRUE(resp.window_set_caption_called); 1299 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 1300 PCUT_ASSERT_INT_EQUALS(0, str_cmp(caption, resp.set_caption_caption)); 1301 1302 //free(resp.set_caption_caption); 1303 display_window_destroy(wnd); 1304 display_close(disp); 1305 rc = loc_service_unregister(sid); 1306 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1307 } 1308 1309 /** display_window_set_caption() with server returning success response works. */ 1310 PCUT_TEST(window_set_caption_success) 1311 { 1312 errno_t rc; 1313 service_id_t sid; 1314 display_t *disp = NULL; 1315 display_wnd_params_t params; 1316 display_window_t *wnd; 1317 const char *caption; 1318 test_response_t resp; 1319 1320 async_set_fallback_port_handler(test_display_conn, &resp); 1321 1322 // FIXME This causes this test to be non-reentrant! 1323 rc = loc_server_register(test_display_server); 1324 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1325 1326 rc = loc_service_register(test_display_svc, &sid); 1327 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1328 1329 rc = display_open(test_display_svc, &disp); 1330 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1331 PCUT_ASSERT_NOT_NULL(disp); 1332 1333 resp.rc = EOK; 1334 display_wnd_params_init(¶ms); 1335 params.rect.p0.x = 0; 1336 params.rect.p0.y = 0; 1337 params.rect.p0.x = 100; 1338 params.rect.p0.y = 100; 1339 1340 rc = display_window_create(disp, ¶ms, &test_display_wnd_cb, 1341 (void *) &resp, &wnd); 1342 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 1343 PCUT_ASSERT_NOT_NULL(wnd); 1344 1345 caption = "Hello"; 1346 1347 resp.rc = EOK; 1348 resp.window_set_caption_called = false; 1349 1350 rc = display_window_set_caption(wnd, caption); 1351 PCUT_ASSERT_INT_EQUALS(wnd->id, resp.set_caption_wnd_id); 1352 PCUT_ASSERT_TRUE(resp.window_set_caption_called); 1353 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 1354 PCUT_ASSERT_INT_EQUALS(0, str_cmp(caption, resp.set_caption_caption)); 1355 1356 //free(resp.set_caption_caption); 1242 1357 display_window_destroy(wnd); 1243 1358 display_close(disp); … … 2018 2133 } 2019 2134 2135 static errno_t test_window_set_caption(void *arg, sysarg_t wnd_id, 2136 const char *caption) 2137 { 2138 test_response_t *resp = (test_response_t *) arg; 2139 2140 resp->window_set_caption_called = true; 2141 resp->set_caption_wnd_id = wnd_id; 2142 resp->set_caption_caption = str_dup(caption); 2143 2144 return resp->rc; 2145 } 2146 2020 2147 static errno_t test_get_event(void *arg, sysarg_t *wnd_id, 2021 2148 display_wnd_ev_t *event) -
uspace/lib/ui/src/window.c
r7a05d924 r7cc30e9 222 222 display_wnd_params_init(&dparams); 223 223 dparams.rect = params->rect; 224 dparams.caption = params->caption; 224 225 /* Only allow making the window larger */ 225 226 gfx_rect_dims(¶ms->rect, &dparams.min_size); … … 651 652 errno_t ui_window_set_caption(ui_window_t *window, const char *caption) 652 653 { 654 errno_t rc; 655 656 /* Set console caption if fullscreen window on console */ 657 if (window->ui->console != NULL && window->placement == 658 ui_wnd_place_full_screen) { 659 rc = console_set_caption(window->ui->console, caption); 660 if (rc != EOK) 661 return rc; 662 } 663 664 /* Set display window caption if running on display service */ 665 if (window->dwindow != NULL) { 666 rc = display_window_set_caption(window->dwindow, caption); 667 if (rc != EOK) 668 return rc; 669 } 670 653 671 return ui_wdecor_set_caption(window->wdecor, caption); 654 672 } -
uspace/srv/hid/display/dsops.c
r7a05d924 r7cc30e9 57 57 static errno_t disp_window_unmaximize(void *, sysarg_t); 58 58 static errno_t disp_window_set_cursor(void *, sysarg_t, display_stock_cursor_t); 59 static errno_t disp_window_set_caption(void *, sysarg_t, const char *); 59 60 static errno_t disp_get_event(void *, sysarg_t *, display_wnd_ev_t *); 60 61 static errno_t disp_get_info(void *, display_info_t *); … … 72 73 .window_unmaximize = disp_window_unmaximize, 73 74 .window_set_cursor = disp_window_set_cursor, 75 .window_set_caption = disp_window_set_caption, 74 76 .get_event = disp_get_event, 75 77 .get_info = disp_get_info … … 306 308 } 307 309 310 static errno_t disp_window_set_caption(void *arg, sysarg_t wnd_id, 311 const char *caption) 312 { 313 ds_client_t *client = (ds_client_t *) arg; 314 ds_window_t *wnd; 315 errno_t rc; 316 317 ds_display_lock(client->display); 318 319 wnd = ds_client_find_window(client, wnd_id); 320 if (wnd == NULL) { 321 ds_display_unlock(client->display); 322 return ENOENT; 323 } 324 325 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_set_caption()"); 326 rc = ds_window_set_caption(wnd, caption); 327 ds_display_unlock(client->display); 328 return rc; 329 } 330 308 331 static errno_t disp_get_event(void *arg, sysarg_t *wnd_id, 309 332 display_wnd_ev_t *event) -
uspace/srv/hid/display/test/window.c
r7a05d924 r7cc30e9 851 851 } 852 852 853 /** Test ds_window_set_caption() */ 854 PCUT_TEST(window_set_caption) 855 { 856 gfx_context_t *gc; 857 ds_display_t *disp; 858 ds_client_t *client; 859 ds_seat_t *seat; 860 ds_window_t *wnd; 861 display_wnd_params_t params; 862 errno_t rc; 863 864 rc = gfx_context_new(&dummy_ops, NULL, &gc); 865 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 866 867 rc = ds_display_create(gc, df_none, &disp); 868 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 869 870 rc = ds_client_create(disp, NULL, NULL, &client); 871 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 872 873 rc = ds_seat_create(disp, &seat); 874 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 875 876 display_wnd_params_init(¶ms); 877 params.rect.p0.x = params.rect.p0.y = 0; 878 params.rect.p1.x = params.rect.p1.y = 1; 879 880 rc = ds_window_create(client, ¶ms, &wnd); 881 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 882 883 PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor); 884 885 rc = ds_window_set_caption(wnd, "Hello"); 886 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 887 PCUT_ASSERT_INT_EQUALS(0, str_cmp("Hello", wnd->caption)); 888 889 ds_window_destroy(wnd); 890 ds_seat_destroy(seat); 891 ds_client_destroy(client); 892 ds_display_destroy(disp); 893 } 894 853 895 static errno_t dummy_set_color(void *arg, gfx_color_t *color) 854 896 { -
uspace/srv/hid/display/types/display/window.h
r7a05d924 r7cc30e9 105 105 /** Window resize type (if state is dsw_resizing) */ 106 106 display_wnd_rsztype_t rsztype; 107 /** Window caption */ 108 char *caption; 107 109 } ds_window_t; 108 110 -
uspace/srv/hid/display/window.c
r7a05d924 r7cc30e9 44 44 #include <memgfx/memgc.h> 45 45 #include <stdlib.h> 46 #include <str.h> 46 47 #include "client.h" 47 48 #include "display.h" … … 81 82 wnd = calloc(1, sizeof(ds_window_t)); 82 83 if (wnd == NULL) { 84 rc = ENOMEM; 85 goto error; 86 } 87 88 wnd->caption = str_dup(params->caption); 89 if (wnd->caption == NULL) { 83 90 rc = ENOMEM; 84 91 goto error; … … 152 159 if (wnd->bitmap != NULL) 153 160 gfx_bitmap_destroy(wnd->bitmap); 161 if (wnd->caption != NULL) 162 free(wnd->caption); 154 163 free(wnd); 155 164 } … … 176 185 gfx_bitmap_destroy(wnd->bitmap); 177 186 187 free(wnd->caption); 178 188 free(wnd); 179 189 … … 902 912 * 903 913 * @param wnd Window 914 * @param cursor New cursor 904 915 * @return EOK on success, EINVAL if @a cursor is invalid 905 916 */ … … 915 926 } 916 927 928 /** Set window caption. 929 * 930 * @param wnd Window 931 * @param caption New caption 932 * 933 * @return EOK on success, EINVAL if @a cursor is invalid 934 */ 935 errno_t ds_window_set_caption(ds_window_t *wnd, const char *caption) 936 { 937 char *dcaption; 938 939 dcaption = str_dup(caption); 940 if (dcaption == NULL) 941 return ENOMEM; 942 943 free(wnd->caption); 944 wnd->caption = dcaption; 945 946 return EOK; 947 } 948 917 949 /** Window memory GC invalidate callback. 918 950 * -
uspace/srv/hid/display/window.h
r7a05d924 r7cc30e9 73 73 gfx_rect_t *); 74 74 extern errno_t ds_window_set_cursor(ds_window_t *, display_stock_cursor_t); 75 extern errno_t ds_window_set_caption(ds_window_t *, const char *); 75 76 76 77 #endif -
uspace/srv/hid/display/wmops.c
r7a05d924 r7cc30e9 98 98 wndmgt_window_info_t **rinfo) 99 99 { 100 101 /* ds_client_t *client = (ds_client_t *) arg; 100 ds_display_t *disp = (ds_display_t *)arg; 102 101 ds_window_t *wnd; 103 104 ds_display_lock(client->display);105 106 wnd = ds_client_find_window(client, wnd_id);107 if (wnd == NULL) {108 ds_display_unlock(client->display);109 return ENOENT;110 }111 112 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_pos()");113 ds_window_get_pos(wnd, pos);114 ds_display_unlock(client->display);115 return EOK;*/116 102 wndmgt_window_info_t *info; 117 103 118 104 log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_get_window_info()"); 105 106 wnd = ds_display_find_window(disp, wnd_id); 107 if (wnd == NULL) 108 return ENOENT; 119 109 120 110 info = calloc(1, sizeof(wndmgt_window_info_t)); … … 122 112 return ENOMEM; 123 113 124 info->caption = str_dup( "Hello");114 info->caption = str_dup(wnd->caption); 125 115 if (info->caption == NULL) { 126 116 free(info);
Note:
See TracChangeset
for help on using the changeset viewer.