Changeset 1e4a937 in mainline
- Timestamp:
- 2020-03-09T11:03:58Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e022819
- Parents:
- a2e104e
- git-author:
- Jiri Svoboda <jiri@…> (2020-03-08 10:02:08)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-03-09 11:03:58)
- Location:
- uspace/lib
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/display/include/disp_srv.h
ra2e104e r1e4a937 41 41 #include "display/wndparams.h" 42 42 #include "types/display/event.h" 43 #include "types/display/wndresize.h" 43 44 44 45 typedef struct display_ops display_ops_t; … … 55 56 errno_t (*window_destroy)(void *, sysarg_t); 56 57 errno_t (*window_move_req)(void *, sysarg_t, gfx_coord2_t *); 58 errno_t (*window_resize_req)(void *, sysarg_t, display_wnd_rsztype_t, 59 gfx_coord2_t *); 57 60 errno_t (*window_resize)(void *, sysarg_t, gfx_coord2_t *, gfx_rect_t *); 58 61 errno_t (*get_event)(void *, sysarg_t *, display_wnd_ev_t *); -
uspace/lib/display/include/display.h
ra2e104e r1e4a937 41 41 #include <stdbool.h> 42 42 #include "display/wndparams.h" 43 #include "display/wndresize.h" 43 44 #include "types/display.h" 44 45 … … 50 51 extern errno_t display_window_get_gc(display_window_t *, gfx_context_t **); 51 52 extern errno_t display_window_move_req(display_window_t *, gfx_coord2_t *); 53 extern errno_t display_window_resize_req(display_window_t *, 54 display_wnd_rsztype_t, gfx_coord2_t *); 52 55 extern errno_t display_window_resize(display_window_t *, 53 56 gfx_coord2_t *, gfx_rect_t *); -
uspace/lib/display/include/ipc/display.h
ra2e104e r1e4a937 44 44 DISPLAY_WINDOW_MOVE_REQ, 45 45 DISPLAY_WINDOW_RESIZE, 46 DISPLAY_WINDOW_RESIZE_REQ, 46 47 DISPLAY_GET_EVENT 47 48 } display_request_t; -
uspace/lib/display/src/disp_srv.c
ra2e104e r1e4a937 37 37 #include <disp_srv.h> 38 38 #include <display/event.h> 39 #include <display/wndresize.h> 39 40 #include <errno.h> 40 41 #include <io/log.h> … … 147 148 } 148 149 150 static void display_window_resize_req_srv(display_srv_t *srv, ipc_call_t *icall) 151 { 152 sysarg_t wnd_id; 153 ipc_call_t call; 154 display_wnd_rsztype_t rsztype; 155 gfx_coord2_t pos; 156 size_t size; 157 errno_t rc; 158 159 wnd_id = ipc_get_arg1(icall); 160 rsztype = (display_wnd_rsztype_t) ipc_get_arg2(icall); 161 162 if (!async_data_write_receive(&call, &size)) { 163 async_answer_0(&call, EREFUSED); 164 async_answer_0(icall, EREFUSED); 165 return; 166 } 167 168 if (size != sizeof(gfx_coord2_t)) { 169 async_answer_0(&call, EINVAL); 170 async_answer_0(icall, EINVAL); 171 return; 172 } 173 174 rc = async_data_write_finalize(&call, &pos, size); 175 if (rc != EOK) { 176 async_answer_0(&call, rc); 177 async_answer_0(icall, rc); 178 return; 179 } 180 181 if (srv->ops->window_resize_req == NULL) { 182 async_answer_0(icall, ENOTSUP); 183 return; 184 } 185 186 rc = srv->ops->window_resize_req(srv->arg, wnd_id, rsztype, &pos); 187 async_answer_0(icall, rc); 188 } 189 149 190 static void display_window_resize_srv(display_srv_t *srv, ipc_call_t *icall) 150 191 { … … 256 297 case DISPLAY_WINDOW_MOVE_REQ: 257 298 display_window_move_req_srv(srv, &call); 299 break; 300 case DISPLAY_WINDOW_RESIZE_REQ: 301 display_window_resize_req_srv(srv, &call); 258 302 break; 259 303 case DISPLAY_WINDOW_RESIZE: -
uspace/lib/display/src/display.c
ra2e104e r1e4a937 251 251 * 252 252 * @param window Window 253 * @param pos Position in the window where the button was pressed 253 254 * @return EOK on success or an error code 254 255 */ … … 262 263 exch = async_exchange_begin(window->display->sess); 263 264 req = async_send_1(exch, DISPLAY_WINDOW_MOVE_REQ, window->id, &answer); 265 rc = async_data_write_start(exch, (void *)pos, sizeof (gfx_coord2_t)); 266 async_exchange_end(exch); 267 if (rc != EOK) { 268 async_forget(req); 269 return rc; 270 } 271 272 async_wait_for(req, &rc); 273 if (rc != EOK) 274 return rc; 275 276 return EOK; 277 } 278 279 /** Request a window resize. 280 * 281 * Request the display service to initiate a user window resize operation 282 * (i.e. let the user resize the window). Used when the client detects 283 * mouse press on the window frame or such. 284 * 285 * @param window Window 286 * @param rsztype Resize type (which part of window frame is being dragged) 287 * @param pos Position in the window where the button was pressed 288 * @return EOK on success or an error code 289 */ 290 errno_t display_window_resize_req(display_window_t *window, 291 display_wnd_rsztype_t rsztype, gfx_coord2_t *pos) 292 { 293 async_exch_t *exch; 294 aid_t req; 295 ipc_call_t answer; 296 errno_t rc; 297 298 exch = async_exchange_begin(window->display->sess); 299 req = async_send_2(exch, DISPLAY_WINDOW_RESIZE_REQ, window->id, 300 (sysarg_t) rsztype, &answer); 264 301 rc = async_data_write_start(exch, (void *)pos, sizeof (gfx_coord2_t)); 265 302 async_exchange_end(exch); -
uspace/lib/display/test/display.c
ra2e104e r1e4a937 57 57 static errno_t test_window_destroy(void *, sysarg_t); 58 58 static errno_t test_window_move_req(void *, sysarg_t, gfx_coord2_t *); 59 static errno_t test_window_resize_req(void *, sysarg_t, display_wnd_rsztype_t, 60 gfx_coord2_t *); 59 61 static errno_t test_window_resize(void *, sysarg_t, gfx_coord2_t *, 60 62 gfx_rect_t *); … … 67 69 .window_destroy = test_window_destroy, 68 70 .window_move_req = test_window_move_req, 71 .window_resize_req = test_window_resize_req, 69 72 .window_resize = test_window_resize, 70 73 .get_event = test_get_event … … 100 103 sysarg_t move_req_wnd_id; 101 104 gfx_coord2_t move_req_pos; 105 106 bool window_resize_req_called; 107 sysarg_t resize_req_wnd_id; 108 display_wnd_rsztype_t resize_req_rsztype; 109 gfx_coord2_t resize_req_pos; 102 110 103 111 bool window_resize_called; … … 410 418 } 411 419 420 /** display_window_resize_req() with server returning error response works. */ 421 PCUT_TEST(window_resize_req_failure) 422 { 423 errno_t rc; 424 service_id_t sid; 425 display_t *disp = NULL; 426 display_wnd_params_t params; 427 display_window_t *wnd; 428 test_response_t resp; 429 display_wnd_rsztype_t rsztype; 430 gfx_coord2_t pos; 431 432 async_set_fallback_port_handler(test_display_conn, &resp); 433 434 // FIXME This causes this test to be non-reentrant! 435 rc = loc_server_register(test_display_server); 436 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 437 438 rc = loc_service_register(test_display_svc, &sid); 439 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 440 441 rc = display_open(test_display_svc, &disp); 442 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 443 PCUT_ASSERT_NOT_NULL(disp); 444 445 resp.rc = EOK; 446 display_wnd_params_init(¶ms); 447 params.rect.p0.x = 0; 448 params.rect.p0.y = 0; 449 params.rect.p0.x = 100; 450 params.rect.p0.y = 100; 451 452 rc = display_window_create(disp, ¶ms, &test_display_wnd_cb, 453 (void *) &resp, &wnd); 454 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 455 PCUT_ASSERT_NOT_NULL(wnd); 456 457 resp.rc = EIO; 458 resp.window_resize_req_called = false; 459 460 rsztype = display_wr_top_right; 461 pos.x = 42; 462 pos.y = 43; 463 464 rc = display_window_resize_req(wnd, rsztype, &pos); 465 PCUT_ASSERT_TRUE(resp.window_resize_req_called); 466 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 467 PCUT_ASSERT_INT_EQUALS(rsztype, resp.resize_req_rsztype); 468 PCUT_ASSERT_INT_EQUALS(wnd->id, resp.resize_req_wnd_id); 469 PCUT_ASSERT_INT_EQUALS(pos.x, resp.resize_req_pos.x); 470 PCUT_ASSERT_INT_EQUALS(pos.y, resp.resize_req_pos.y); 471 472 display_window_destroy(wnd); 473 display_close(disp); 474 rc = loc_service_unregister(sid); 475 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 476 } 477 478 /** display_window_resize_req() with server returning success response works. */ 479 PCUT_TEST(window_resize_req_success) 480 { 481 errno_t rc; 482 service_id_t sid; 483 display_t *disp = NULL; 484 display_wnd_params_t params; 485 display_window_t *wnd; 486 test_response_t resp; 487 display_wnd_rsztype_t rsztype; 488 gfx_coord2_t pos; 489 490 async_set_fallback_port_handler(test_display_conn, &resp); 491 492 // FIXME This causes this test to be non-reentrant! 493 rc = loc_server_register(test_display_server); 494 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 495 496 rc = loc_service_register(test_display_svc, &sid); 497 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 498 499 rc = display_open(test_display_svc, &disp); 500 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 501 PCUT_ASSERT_NOT_NULL(disp); 502 503 resp.rc = EOK; 504 display_wnd_params_init(¶ms); 505 params.rect.p0.x = 0; 506 params.rect.p0.y = 0; 507 params.rect.p0.x = 100; 508 params.rect.p0.y = 100; 509 510 rc = display_window_create(disp, ¶ms, &test_display_wnd_cb, 511 (void *) &resp, &wnd); 512 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 513 PCUT_ASSERT_NOT_NULL(wnd); 514 515 resp.rc = EOK; 516 resp.window_resize_req_called = false; 517 518 rsztype = display_wr_top_right; 519 pos.x = 42; 520 pos.y = 43; 521 522 rc = display_window_resize_req(wnd, rsztype, &pos); 523 PCUT_ASSERT_TRUE(resp.window_resize_req_called); 524 PCUT_ASSERT_ERRNO_VAL(resp.rc, rc); 525 PCUT_ASSERT_INT_EQUALS(rsztype, resp.resize_req_rsztype); 526 PCUT_ASSERT_INT_EQUALS(wnd->id, resp.resize_req_wnd_id); 527 PCUT_ASSERT_INT_EQUALS(pos.x, resp.resize_req_pos.x); 528 PCUT_ASSERT_INT_EQUALS(pos.y, resp.resize_req_pos.y); 529 530 display_window_destroy(wnd); 531 display_close(disp); 532 rc = loc_service_unregister(sid); 533 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 534 } 535 412 536 /** display_window_resize() with server returning error response works. */ 413 537 PCUT_TEST(window_resize_failure) … … 1140 1264 } 1141 1265 1266 static errno_t test_window_resize_req(void *arg, sysarg_t wnd_id, 1267 display_wnd_rsztype_t rsztype, gfx_coord2_t *pos) 1268 { 1269 test_response_t *resp = (test_response_t *) arg; 1270 1271 resp->window_resize_req_called = true; 1272 resp->resize_req_rsztype = rsztype; 1273 resp->resize_req_wnd_id = wnd_id; 1274 resp->resize_req_pos = *pos; 1275 return resp->rc; 1276 } 1277 1142 1278 static errno_t test_window_resize(void *arg, sysarg_t wnd_id, 1143 1279 gfx_coord2_t *offs, gfx_rect_t *nrect) -
uspace/lib/gui/window.c
ra2e104e r1e4a937 293 293 (event.hpos >= width - border_thickness - close_thickness); 294 294 295 if (top && left && allowed_button) { 296 window_grab_flags_t flags = GF_EMPTY; 297 flags |= GF_MOVE_X; 298 flags |= GF_MOVE_Y; 299 flags |= btn_left ? GF_RESIZE_X : GF_SCALE_X; 300 flags |= btn_left ? GF_RESIZE_Y : GF_SCALE_Y; 301 //win_grab(widget->window->osess, event.pos_id, flags); 302 } else if (bottom && left && allowed_button) { 303 window_grab_flags_t flags = GF_EMPTY; 304 flags |= GF_MOVE_X; 305 flags |= btn_left ? GF_RESIZE_X : GF_SCALE_X; 306 flags |= btn_left ? GF_RESIZE_Y : GF_SCALE_Y; 307 //win_grab(widget->window->osess, event.pos_id, flags); 308 } else if (bottom && right && allowed_button) { 309 window_grab_flags_t flags = GF_EMPTY; 310 flags |= btn_left ? GF_RESIZE_X : GF_SCALE_X; 311 flags |= btn_left ? GF_RESIZE_Y : GF_SCALE_Y; 312 //win_grab(widget->window->osess, event.pos_id, flags); 295 pos.x = event.hpos; 296 pos.y = event.vpos; 297 298 if (top && left && btn_left) { 299 (void) display_window_resize_req(widget->window->dwindow, 300 display_wr_top_left, &pos); 301 } else if (bottom && left && btn_left) { 302 (void) display_window_resize_req(widget->window->dwindow, 303 display_wr_bottom_left, &pos); 304 } else if (bottom && right && btn_left) { 305 (void) display_window_resize_req(widget->window->dwindow, 306 display_wr_bottom_right, &pos); 313 307 } else if (top && right && allowed_button) { 314 window_grab_flags_t flags = GF_EMPTY; 315 flags |= GF_MOVE_Y; 316 flags |= btn_left ? GF_RESIZE_X : GF_SCALE_X; 317 flags |= btn_left ? GF_RESIZE_Y : GF_SCALE_Y; 318 //win_grab(widget->window->osess, event.pos_id, flags); 319 } else if (top && allowed_button) { 320 window_grab_flags_t flags = GF_EMPTY; 321 flags |= GF_MOVE_Y; 322 flags |= btn_left ? GF_RESIZE_Y : GF_SCALE_Y; 323 //win_grab(widget->window->osess, event.pos_id, flags); 324 } else if (left && allowed_button) { 325 window_grab_flags_t flags = GF_EMPTY; 326 flags |= GF_MOVE_X; 327 flags |= btn_left ? GF_RESIZE_X : GF_SCALE_X; 328 //win_grab(widget->window->osess, event.pos_id, flags); 329 } else if (bottom && allowed_button) { 330 window_grab_flags_t flags = GF_EMPTY; 331 flags |= btn_left ? GF_RESIZE_Y : GF_SCALE_Y; 332 //win_grab(widget->window->osess, event.pos_id, flags); 333 } else if (right && allowed_button) { 334 window_grab_flags_t flags = GF_EMPTY; 335 flags |= btn_left ? GF_RESIZE_X : GF_SCALE_X; 336 //win_grab(widget->window->osess, event.pos_id, flags); 308 (void) display_window_resize_req(widget->window->dwindow, 309 display_wr_top_right, &pos); 310 } else if (top && btn_left) { 311 (void) display_window_resize_req(widget->window->dwindow, 312 display_wr_top, &pos); 313 } else if (left && btn_left) { 314 (void) display_window_resize_req(widget->window->dwindow, 315 display_wr_bottom, &pos); 316 } else if (bottom && btn_left) { 317 (void) display_window_resize_req(widget->window->dwindow, 318 display_wr_bottom, &pos); 319 } else if (right && btn_left) { 320 (void) display_window_resize_req(widget->window->dwindow, 321 display_wr_bottom, &pos); 337 322 } else if (close && btn_left) { 338 323 window_close(widget->window); 339 324 } else if (header && btn_left) { 340 window_grab_flags_t flags = GF_EMPTY;341 flags |= GF_MOVE_X;342 flags |= GF_MOVE_Y;343 pos.x = event.hpos;344 pos.y = event.vpos;345 325 (void) display_window_move_req(widget->window->dwindow, 346 326 &pos);
Note:
See TracChangeset
for help on using the changeset viewer.