Changeset a2e104e in mainline for uspace/srv/hid/display
- Timestamp:
- 2020-03-05T11:23:41Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1e4a937
- Parents:
- 338d0935
- git-author:
- Jiri Svoboda <jiri@…> (2020-03-04 19:23:29)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-03-05 11:23:41)
- Location:
- uspace/srv/hid/display
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/display/dsops.c
r338d0935 ra2e104e 46 46 static errno_t disp_window_create(void *, display_wnd_params_t *, sysarg_t *); 47 47 static errno_t disp_window_destroy(void *, sysarg_t); 48 static errno_t disp_window_move_req(void *, sysarg_t, gfx_coord2_t *); 48 49 static errno_t disp_window_resize(void *, sysarg_t, gfx_coord2_t *, 49 50 gfx_rect_t *); … … 53 54 .window_create = disp_window_create, 54 55 .window_destroy = disp_window_destroy, 56 .window_move_req = disp_window_move_req, 55 57 .window_resize = disp_window_resize, 56 58 .get_event = disp_get_event … … 102 104 } 103 105 106 static errno_t disp_window_move_req(void *arg, sysarg_t wnd_id, 107 gfx_coord2_t *pos) 108 { 109 ds_client_t *client = (ds_client_t *) arg; 110 ds_window_t *wnd; 111 112 wnd = ds_client_find_window(client, wnd_id); 113 if (wnd == NULL) 114 return ENOENT; 115 116 log_msg(LVL_NOTE, LVL_DEBUG, "disp_window_move_req()"); 117 ds_window_move_req(wnd, pos); 118 return EOK; 119 } 120 104 121 static errno_t disp_window_resize(void *arg, sysarg_t wnd_id, 105 122 gfx_coord2_t *offs, gfx_rect_t *nbound) -
uspace/srv/hid/display/test/window.c
r338d0935 ra2e104e 201 201 PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state); 202 202 203 wnd->dpos.x = 10; 204 wnd->dpos.y = 10; 205 203 206 event.type = POS_PRESS; 207 event.btn_num = 2; 204 208 event.hpos = 10; 205 209 event.vpos = 10; … … 216 220 217 221 PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state); 218 PCUT_ASSERT_INT_EQUALS( wnd->dpos.x, 1);219 PCUT_ASSERT_INT_EQUALS( wnd->dpos.y, 2);222 PCUT_ASSERT_INT_EQUALS(11, wnd->dpos.x); 223 PCUT_ASSERT_INT_EQUALS(12, wnd->dpos.y); 220 224 221 225 event.type = POS_RELEASE; … … 227 231 228 232 PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state); 229 PCUT_ASSERT_INT_EQUALS(wnd->dpos.x, 3); 230 PCUT_ASSERT_INT_EQUALS(wnd->dpos.y, 4); 233 PCUT_ASSERT_INT_EQUALS(13, wnd->dpos.x); 234 PCUT_ASSERT_INT_EQUALS(14, wnd->dpos.y); 235 236 ds_window_destroy(wnd); 237 ds_client_destroy(client); 238 ds_display_destroy(disp); 239 } 240 241 /** Test ds_window_move_req() */ 242 PCUT_TEST(window_move_req) 243 { 244 gfx_context_t *gc; 245 ds_display_t *disp; 246 ds_client_t *client; 247 ds_window_t *wnd; 248 display_wnd_params_t params; 249 gfx_coord2_t pos; 250 errno_t rc; 251 252 rc = gfx_context_new(&dummy_ops, NULL, &gc); 253 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 254 255 rc = ds_display_create(gc, &disp); 256 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 257 258 rc = ds_client_create(disp, NULL, NULL, &client); 259 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 260 261 display_wnd_params_init(¶ms); 262 params.rect.p0.x = params.rect.p0.y = 0; 263 params.rect.p1.x = params.rect.p1.y = 1; 264 265 rc = ds_window_create(client, ¶ms, &wnd); 266 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 267 268 PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state); 269 270 pos.x = 42; 271 pos.y = 43; 272 ds_window_move_req(wnd, &pos); 273 274 PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state); 275 PCUT_ASSERT_INT_EQUALS(pos.x, wnd->orig_pos.x); 276 PCUT_ASSERT_INT_EQUALS(pos.y, wnd->orig_pos.y); 231 277 232 278 ds_window_destroy(wnd); -
uspace/srv/hid/display/window.c
r338d0935 ra2e104e 436 436 } 437 437 438 /** Start moving a window, detected by client. 439 * 440 * @param wnd Window 441 * @param pos Position where the pointer was when the move started 442 * relative to the window 443 * @param event Button press event 444 */ 445 void ds_window_move_req(ds_window_t *wnd, gfx_coord2_t *pos) 446 { 447 log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_move_req (%d, %d)", 448 (int) pos->x, (int) pos->y); 449 450 if (wnd->state != dsw_idle) 451 return; 452 453 gfx_coord2_add(&wnd->dpos, pos, &wnd->orig_pos); 454 wnd->state = dsw_moving; 455 } 456 438 457 /** Start moving a window by mouse drag. 439 458 * … … 446 465 (int) event->hpos, (int) event->vpos); 447 466 448 assert(wnd->state == dsw_idle); 467 if (wnd->state != dsw_idle) 468 return; 449 469 450 470 wnd->orig_pos.x = event->hpos; … … 467 487 (int) event->hpos, (int) event->vpos); 468 488 469 assert(wnd->state == dsw_moving); 489 if (wnd->state != dsw_moving) 490 return; 491 470 492 pos.x = event->hpos; 471 493 pos.y = event->vpos; … … 497 519 (int) event->hpos, (int) event->vpos); 498 520 521 if (wnd->state != dsw_moving) 522 return; 523 499 524 gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect); 500 525 … … 505 530 } 506 531 507 assert(wnd->state == dsw_moving);508 532 pos.x = event->hpos; 509 533 pos.y = event->vpos; … … 559 583 { 560 584 pos_event_t tevent; 585 gfx_coord2_t pos; 586 gfx_rect_t drect; 587 bool inside; 561 588 562 589 log_msg(LOG_DEFAULT, LVL_DEBUG, … … 564 591 (int) event->hpos, (int) event->vpos); 565 592 566 if (event->type == POS_PRESS) { 567 if (wnd->state == dsw_idle) 568 ds_window_start_move(wnd, event); 569 } 570 571 if (event->type == POS_RELEASE) { 572 if (wnd->state == dsw_moving) 573 ds_window_finish_move(wnd, event); 574 } 575 576 if (event->type == POS_UPDATE) { 577 if (wnd->state == dsw_moving) 578 ds_window_update_move(wnd, event); 579 } 593 pos.x = event->hpos; 594 pos.y = event->vpos; 595 gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect); 596 inside = gfx_pix_inside_rect(&pos, &drect); 597 598 if (event->type == POS_PRESS && event->btn_num == 2 && inside) 599 ds_window_start_move(wnd, event); 600 601 if (event->type == POS_RELEASE) 602 ds_window_finish_move(wnd, event); 603 604 if (event->type == POS_UPDATE) 605 ds_window_update_move(wnd, event); 580 606 581 607 /* Transform event coordinates to window-local */ -
uspace/srv/hid/display/window.h
r338d0935 ra2e104e 58 58 extern errno_t ds_window_post_focus_event(ds_window_t *); 59 59 extern errno_t ds_window_post_unfocus_event(ds_window_t *); 60 extern void ds_window_move_req(ds_window_t *wnd, gfx_coord2_t *); 60 61 61 62 #endif
Note:
See TracChangeset
for help on using the changeset viewer.