Changeset 6baab83 in mainline
- Timestamp:
- 2021-05-27T17:00:30Z (3 years ago)
- Children:
- b4b4dafe
- Parents:
- f2416ec3
- Location:
- uspace
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/display/include/disp_srv.h
rf2416ec3 r6baab83 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 61 61 gfx_coord2_t *); 62 62 errno_t (*window_move)(void *, sysarg_t, gfx_coord2_t *); 63 errno_t (*window_get_pos)(void *, sysarg_t, gfx_coord2_t *); 63 64 errno_t (*window_resize)(void *, sysarg_t, gfx_coord2_t *, gfx_rect_t *); 64 65 errno_t (*window_set_cursor)(void *, sysarg_t, display_stock_cursor_t); -
uspace/lib/display/include/display.h
rf2416ec3 r6baab83 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 58 58 display_wnd_rsztype_t, gfx_coord2_t *); 59 59 extern errno_t display_window_move(display_window_t *, gfx_coord2_t *); 60 extern errno_t display_window_get_pos(display_window_t *, gfx_coord2_t *); 60 61 extern errno_t display_window_resize(display_window_t *, 61 62 gfx_coord2_t *, gfx_rect_t *); -
uspace/lib/display/include/ipc/display.h
rf2416ec3 r6baab83 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 44 44 DISPLAY_WINDOW_MOVE, 45 45 DISPLAY_WINDOW_MOVE_REQ, 46 DISPLAY_WINDOW_GET_POS, 46 47 DISPLAY_WINDOW_RESIZE, 47 48 DISPLAY_WINDOW_RESIZE_REQ, -
uspace/lib/display/src/disp_srv.c
rf2416ec3 r6baab83 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 187 187 } 188 188 189 static void display_window_get_pos_srv(display_srv_t *srv, ipc_call_t *icall) 190 { 191 sysarg_t wnd_id; 192 ipc_call_t call; 193 gfx_coord2_t dpos; 194 size_t size; 195 errno_t rc; 196 197 wnd_id = ipc_get_arg1(icall); 198 199 if (srv->ops->window_get_pos == NULL) { 200 async_answer_0(icall, ENOTSUP); 201 return; 202 } 203 204 if (!async_data_read_receive(&call, &size)) { 205 async_answer_0(icall, EREFUSED); 206 return; 207 } 208 209 rc = srv->ops->window_get_pos(srv->arg, wnd_id, &dpos); 210 if (rc != EOK) { 211 async_answer_0(&call, rc); 212 async_answer_0(icall, rc); 213 return; 214 } 215 216 if (size != sizeof(gfx_coord2_t)) { 217 async_answer_0(&call, EINVAL); 218 async_answer_0(icall, EINVAL); 219 return; 220 } 221 222 rc = async_data_read_finalize(&call, &dpos, size); 223 if (rc != EOK) { 224 async_answer_0(&call, rc); 225 async_answer_0(icall, rc); 226 return; 227 } 228 229 async_answer_0(icall, EOK); 230 } 231 189 232 static void display_window_resize_req_srv(display_srv_t *srv, ipc_call_t *icall) 190 233 { … … 398 441 case DISPLAY_WINDOW_MOVE: 399 442 display_window_move_srv(srv, &call); 443 break; 444 case DISPLAY_WINDOW_GET_POS: 445 display_window_get_pos_srv(srv, &call); 400 446 break; 401 447 case DISPLAY_WINDOW_RESIZE_REQ: -
uspace/lib/display/src/display.c
rf2416ec3 r6baab83 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 319 319 } 320 320 321 /** Get display window position. 322 * 323 * Get display window position on the display. 324 * 325 * @param window Window 326 * @param dpos Place to store position 327 * @return EOK on success or an error code 328 */ 329 errno_t display_window_get_pos(display_window_t *window, gfx_coord2_t *dpos) 330 { 331 async_exch_t *exch; 332 aid_t req; 333 ipc_call_t answer; 334 errno_t rc; 335 336 exch = async_exchange_begin(window->display->sess); 337 req = async_send_1(exch, DISPLAY_WINDOW_GET_POS, window->id, &answer); 338 rc = async_data_read_start(exch, dpos, sizeof (gfx_coord2_t)); 339 async_exchange_end(exch); 340 if (rc != EOK) { 341 async_forget(req); 342 return rc; 343 } 344 345 async_wait_for(req, &rc); 346 if (rc != EOK) 347 return rc; 348 349 return EOK; 350 } 351 321 352 /** Request a window resize. 322 353 * -
uspace/lib/display/test/display.c
rf2416ec3 r6baab83 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 59 59 static errno_t test_window_move_req(void *, sysarg_t, gfx_coord2_t *); 60 60 static errno_t test_window_move(void *, sysarg_t, gfx_coord2_t *); 61 static errno_t test_window_get_pos(void *, sysarg_t, gfx_coord2_t *); 61 62 static errno_t test_window_resize_req(void *, sysarg_t, display_wnd_rsztype_t, 62 63 gfx_coord2_t *); … … 74 75 .window_move_req = test_window_move_req, 75 76 .window_move = test_window_move, 77 .window_get_pos = test_window_get_pos, 76 78 .window_resize_req = test_window_resize_req, 77 79 .window_resize = test_window_resize, … … 115 117 sysarg_t move_wnd_id; 116 118 gfx_coord2_t move_dpos; 119 120 bool window_get_pos_called; 121 sysarg_t get_pos_wnd_id; 122 gfx_coord2_t get_pos_rpos; 117 123 118 124 bool window_resize_req_called; … … 556 562 } 557 563 564 /** display_window_get_pos() with server returning error response works. */ 565 PCUT_TEST(window_get_pos_failure) 566 { 567 errno_t rc; 568 service_id_t sid; 569 display_t *disp = NULL; 570 display_wnd_params_t params; 571 display_window_t *wnd; 572 gfx_coord2_t dpos; 573 test_response_t resp; 574 575 async_set_fallback_port_handler(test_display_conn, &resp); 576 577 // FIXME This causes this test to be non-reentrant! 578 rc = loc_server_register(test_display_server); 579 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 580 581 rc = loc_service_register(test_display_svc, &sid); 582 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 583 584 rc = display_open(test_display_svc, &disp); 585 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 586 PCUT_ASSERT_NOT_NULL(disp); 587 588 resp.rc = EOK; 589 display_wnd_params_init(¶ms); 590 params.rect.p0.x = 0; 591 params.rect.p0.y = 0; 592 params.rect.p0.x = 100; 593 params.rect.p0.y = 100; 594 595 rc = display_window_create(disp, ¶ms, &test_display_wnd_cb, 596 (void *) &resp, &wnd); 597 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 598 PCUT_ASSERT_NOT_NULL(wnd); 599 600 resp.rc = EIO; 601 resp.window_get_pos_called = false; 602 603 dpos.x = 0; 604 dpos.y = 0; 605 606 rc = display_window_get_pos(wnd, &dpos); 607 PCUT_ASSERT_TRUE(resp.window_get_pos_called); 608 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 609 PCUT_ASSERT_INT_EQUALS(wnd->id, resp.get_pos_wnd_id); 610 PCUT_ASSERT_INT_EQUALS(0, dpos.x); 611 PCUT_ASSERT_INT_EQUALS(0, dpos.y); 612 613 display_window_destroy(wnd); 614 display_close(disp); 615 rc = loc_service_unregister(sid); 616 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 617 } 618 619 /** display_window_get_pos() with server returning success response works. */ 620 PCUT_TEST(window_get_pos_success) 621 { 622 errno_t rc; 623 service_id_t sid; 624 display_t *disp = NULL; 625 display_wnd_params_t params; 626 display_window_t *wnd; 627 gfx_coord2_t dpos; 628 test_response_t resp; 629 630 async_set_fallback_port_handler(test_display_conn, &resp); 631 632 // FIXME This causes this test to be non-reentrant! 633 rc = loc_server_register(test_display_server); 634 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 635 636 rc = loc_service_register(test_display_svc, &sid); 637 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 638 639 rc = display_open(test_display_svc, &disp); 640 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 641 PCUT_ASSERT_NOT_NULL(disp); 642 643 resp.rc = EOK; 644 display_wnd_params_init(¶ms); 645 params.rect.p0.x = 0; 646 params.rect.p0.y = 0; 647 params.rect.p0.x = 100; 648 params.rect.p0.y = 100; 649 650 rc = display_window_create(disp, ¶ms, &test_display_wnd_cb, 651 (void *) &resp, &wnd); 652 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 653 PCUT_ASSERT_NOT_NULL(wnd); 654 655 resp.rc = EOK; 656 resp.window_get_pos_called = false; 657 resp.get_pos_rpos.x = 11; 658 resp.get_pos_rpos.y = 12; 659 660 dpos.x = 0; 661 dpos.y = 0; 662 663 rc = display_window_get_pos(wnd, &dpos); 664 PCUT_ASSERT_TRUE(resp.window_get_pos_called); 665 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 666 PCUT_ASSERT_INT_EQUALS(wnd->id, resp.get_pos_wnd_id); 667 PCUT_ASSERT_INT_EQUALS(resp.get_pos_rpos.x, dpos.x); 668 PCUT_ASSERT_INT_EQUALS(resp.get_pos_rpos.y, dpos.y); 669 670 display_window_destroy(wnd); 671 display_close(disp); 672 rc = loc_service_unregister(sid); 673 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 674 } 675 558 676 /** display_window_resize_req() with server returning error response works. */ 559 677 PCUT_TEST(window_resize_req_failure) … … 937 1055 resp.rc = ENOMEM; 938 1056 rc = display_window_get_gc(wnd, &gc); 939 /* async_connect_me_to() does not return specific error */ 940 PCUT_ASSERT_ERRNO_VAL(EIO, rc); 1057 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 941 1058 PCUT_ASSERT_NULL(gc); 942 1059 … … 1589 1706 } 1590 1707 1708 static errno_t test_window_get_pos(void *arg, sysarg_t wnd_id, gfx_coord2_t *dpos) 1709 { 1710 test_response_t *resp = (test_response_t *) arg; 1711 1712 resp->window_get_pos_called = true; 1713 resp->get_pos_wnd_id = wnd_id; 1714 1715 if (resp->rc == EOK) 1716 *dpos = resp->get_pos_rpos; 1717 1718 return resp->rc; 1719 } 1720 1591 1721 static errno_t test_window_resize_req(void *arg, sysarg_t wnd_id, 1592 1722 display_wnd_rsztype_t rsztype, gfx_coord2_t *pos) -
uspace/lib/ui/include/types/ui/window.h
rf2416ec3 r6baab83 58 58 ui_wnd_place_bottom_right, 59 59 /** Place window accross the entire screen */ 60 ui_wnd_place_full_screen 60 ui_wnd_place_full_screen, 61 /** Place window as a popup window adjacent to rectangle */ 62 ui_wnd_place_popup 61 63 } ui_wnd_placement_t; 62 64 … … 71 73 /** Window placement */ 72 74 ui_wnd_placement_t placement; 75 /** Parent rectangle for popup windows */ 76 gfx_rect_t prect; 73 77 } ui_wnd_params_t; 74 78 -
uspace/lib/ui/include/ui/window.h
rf2416ec3 r6baab83 57 57 extern ui_resource_t *ui_window_get_res(ui_window_t *); 58 58 extern gfx_context_t *ui_window_get_gc(ui_window_t *); 59 extern errno_t ui_window_get_pos(ui_window_t *, gfx_coord2_t *); 59 60 extern errno_t ui_window_get_app_gc(ui_window_t *, gfx_context_t **); 60 61 extern void ui_window_get_app_rect(ui_window_t *, gfx_rect_t *); -
uspace/lib/ui/src/menu.c
rf2416ec3 r6baab83 245 245 ui_popup_params_init(¶ms); 246 246 params.rect = geom.outer_rect; 247 params.place = *prect; 247 248 248 249 rc = ui_popup_create(menu->mbar->ui, menu->mbar->window, ¶ms, -
uspace/lib/ui/src/popup.c
rf2416ec3 r6baab83 78 78 ui_window_t *window = NULL; 79 79 ui_wnd_params_t wparams; 80 gfx_coord2_t parent_pos; 80 81 errno_t rc; 81 82 … … 83 84 if (popup == NULL) 84 85 return ENOMEM; 86 87 rc = ui_window_get_pos(parent, &parent_pos); 88 if (rc != EOK) 89 goto error; 85 90 86 91 ui_wnd_params_init(&wparams); … … 88 93 wparams.caption = ""; 89 94 wparams.style &= ~ui_wds_decorated; 95 wparams.placement = ui_wnd_place_popup; 96 97 /* Compute position of parent rectangle relative to the screen */ 98 gfx_rect_translate(&parent_pos, ¶ms->place, &wparams.prect); 90 99 91 100 rc = ui_window_create(ui, &wparams, &window); -
uspace/lib/ui/src/window.c
rf2416ec3 r6baab83 109 109 } 110 110 111 static errno_t ui_window_place(ui_window_t *window, display_t *display, 112 display_info_t *info, ui_wnd_params_t *params) 113 { 114 gfx_coord2_t pos; 115 errno_t rc; 116 117 assert(params->placement != ui_wnd_place_default); 118 119 pos.x = 0; 120 pos.y = 0; 121 switch (params->placement) { 122 case ui_wnd_place_default: 123 assert(false); 124 case ui_wnd_place_top_left: 125 case ui_wnd_place_full_screen: 126 pos.x = info->rect.p0.x - params->rect.p0.x; 127 pos.y = info->rect.p0.y - params->rect.p0.y; 128 break; 129 case ui_wnd_place_top_right: 130 pos.x = info->rect.p1.x - params->rect.p1.x; 131 pos.y = info->rect.p0.y - params->rect.p0.y; 132 break; 133 case ui_wnd_place_bottom_left: 134 pos.x = info->rect.p0.x - params->rect.p0.x; 135 pos.y = info->rect.p1.y - params->rect.p1.y; 136 break; 137 case ui_wnd_place_bottom_right: 138 pos.x = info->rect.p1.x - params->rect.p1.x; 139 pos.y = info->rect.p1.y - params->rect.p1.y; 140 break; 141 case ui_wnd_place_popup: 142 /* Place popup window below parent rectangle */ 143 pos.x = params->prect.p0.x; 144 pos.y = params->prect.p1.y; 145 break; 146 } 147 148 rc = display_window_move(window->dwindow, &pos); 149 if (rc != EOK) 150 goto error; 151 152 return EOK; 153 error: 154 return rc; 155 } 156 111 157 /** Create new window. 112 158 * … … 121 167 ui_window_t *window; 122 168 display_info_t info; 123 gfx_coord2_t pos;124 169 gfx_coord2_t scr_dims; 125 170 display_wnd_params_t dparams; 126 display_window_t *dwindow = NULL;127 171 gfx_context_t *gc = NULL; 128 172 ui_resource_t *res = NULL; … … 159 203 160 204 rc = display_window_create(ui->display, &dparams, &dwnd_cb, 161 (void *) window, & dwindow);205 (void *) window, &window->dwindow); 162 206 if (rc != EOK) 163 207 goto error; 164 208 165 209 if (params->placement != ui_wnd_place_default) { 166 pos.x = 0; 167 pos.y = 0; 168 169 switch (params->placement) { 170 case ui_wnd_place_default: 171 assert(false); 172 case ui_wnd_place_top_left: 173 case ui_wnd_place_full_screen: 174 pos.x = info.rect.p0.x - params->rect.p0.x; 175 pos.y = info.rect.p0.y - params->rect.p0.y; 176 break; 177 case ui_wnd_place_top_right: 178 pos.x = info.rect.p1.x - params->rect.p1.x; 179 pos.y = info.rect.p0.y - params->rect.p0.y; 180 break; 181 case ui_wnd_place_bottom_left: 182 pos.x = info.rect.p0.x - params->rect.p0.x; 183 pos.y = info.rect.p1.y - params->rect.p1.y; 184 break; 185 case ui_wnd_place_bottom_right: 186 pos.x = info.rect.p1.x - params->rect.p1.x; 187 pos.y = info.rect.p1.y - params->rect.p1.y; 188 break; 189 } 190 191 rc = display_window_move(dwindow, &pos); 210 rc = ui_window_place(window, ui->display, &info, 211 params); 192 212 if (rc != EOK) 193 213 goto error; 194 214 } 195 215 196 rc = display_window_get_gc( dwindow, &gc);216 rc = display_window_get_gc(window->dwindow, &gc); 197 217 if (rc != EOK) 198 218 goto error; … … 265 285 266 286 window->ui = ui; 267 window->dwindow = dwindow;268 287 window->rect = dparams.rect; 269 288 … … 286 305 if (dgc != NULL) 287 306 dummygc_destroy(dgc); 288 if (dwindow != NULL)289 display_window_destroy(dwindow);290 307 free(window); 291 308 return rc; … … 536 553 { 537 554 return window->gc; 555 } 556 557 /** Get window position. 558 * 559 * @param window Window 560 * @param pos Place to store position 561 * @return EOK on success or an error code 562 */ 563 errno_t ui_window_get_pos(ui_window_t *window, gfx_coord2_t *pos) 564 { 565 errno_t rc; 566 567 if (window->dwindow != NULL) { 568 rc = display_window_get_pos(window->dwindow, pos); 569 if (rc != EOK) 570 return rc; 571 } else { 572 pos->x = 0; 573 pos->y = 0; 574 } 575 576 return EOK; 538 577 } 539 578 -
uspace/srv/hid/display/dsops.c
rf2416ec3 r6baab83 48 48 static errno_t disp_window_move_req(void *, sysarg_t, gfx_coord2_t *); 49 49 static errno_t disp_window_move(void *, sysarg_t, gfx_coord2_t *); 50 static errno_t disp_window_get_pos(void *, sysarg_t, gfx_coord2_t *); 50 51 static errno_t disp_window_resize_req(void *, sysarg_t, 51 52 display_wnd_rsztype_t, gfx_coord2_t *); … … 61 62 .window_move_req = disp_window_move_req, 62 63 .window_move = disp_window_move, 64 .window_get_pos = disp_window_get_pos, 63 65 .window_resize_req = disp_window_resize_req, 64 66 .window_resize = disp_window_resize, … … 162 164 } 163 165 166 static errno_t disp_window_get_pos(void *arg, sysarg_t wnd_id, 167 gfx_coord2_t *pos) 168 { 169 ds_client_t *client = (ds_client_t *) arg; 170 ds_window_t *wnd; 171 172 ds_display_lock(client->display); 173 174 wnd = ds_client_find_window(client, wnd_id); 175 if (wnd == NULL) { 176 ds_display_unlock(client->display); 177 return ENOENT; 178 } 179 180 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_pos()"); 181 ds_window_get_pos(wnd, pos); 182 ds_display_unlock(client->display); 183 return EOK; 184 } 185 164 186 static errno_t disp_window_resize_req(void *arg, sysarg_t wnd_id, 165 187 display_wnd_rsztype_t rsztype, gfx_coord2_t *pos) -
uspace/srv/hid/display/window.c
rf2416ec3 r6baab83 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 658 658 } 659 659 660 /** Get window position. 661 * 662 * @param wnd Window 663 */ 664 void ds_window_get_pos(ds_window_t *wnd, gfx_coord2_t *dpos) 665 { 666 *dpos = wnd->dpos; 667 } 668 660 669 /** Start resizing a window, detected by client. 661 670 * -
uspace/srv/hid/display/window.h
rf2416ec3 r6baab83 63 63 extern void ds_window_move_req(ds_window_t *, gfx_coord2_t *); 64 64 extern void ds_window_move(ds_window_t *, gfx_coord2_t *); 65 extern void ds_window_get_pos(ds_window_t *, gfx_coord2_t *); 65 66 extern void ds_window_resize_req(ds_window_t *, display_wnd_rsztype_t, 66 67 gfx_coord2_t *);
Note:
See TracChangeset
for help on using the changeset viewer.