Changes in uspace/lib/display/src/display.c [4ac11ff:8279aab] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/display/src/display.c
r4ac11ff r8279aab 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 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" … … 68 69 dsname = SERVICE_NAME_DISPLAY; 69 70 70 rc = loc_service_get_id(dsname, &display_svc, IPC_FLAG_BLOCKING);71 rc = loc_service_get_id(dsname, &display_svc, 0); 71 72 if (rc != EOK) { 72 73 free(display); … … 75 76 76 77 display->sess = loc_service_connect(display_svc, INTERFACE_DISPLAY, 77 IPC_FLAG_BLOCKING);78 0); 78 79 if (display->sess == NULL) { 79 80 free(display); … … 137 138 } 138 139 140 /* 141 * Lock display. 142 * 143 * While display is locked, display event handlers will not be called. 144 * 145 * @param display Display 146 */ 147 void display_lock(display_t *display) 148 { 149 fibril_mutex_lock(&display->lock); 150 } 151 152 /* 153 * Unlock display. 154 * 155 * @param display Display 156 */ 157 void display_unlock(display_t *display) 158 { 159 fibril_mutex_unlock(&display->lock); 160 } 161 139 162 /** Initialize window parameters structure. 140 163 * … … 147 170 { 148 171 memset(params, 0, sizeof(*params)); 172 params->caption = ""; 149 173 } 150 174 … … 162 186 { 163 187 display_window_t *window; 164 async_exch_t *exch; 165 aid_t req; 166 ipc_call_t answer; 167 errno_t rc; 188 display_wnd_params_enc_t eparams; 189 async_exch_t *exch; 190 aid_t req; 191 ipc_call_t answer; 192 errno_t rc; 193 194 /* Encode the parameters for transport */ 195 eparams.rect = params->rect; 196 eparams.caption_size = str_size(params->caption); 197 eparams.min_size = params->min_size; 198 eparams.pos = params->pos; 199 eparams.flags = params->flags; 200 eparams.idev_id = params->idev_id; 168 201 169 202 window = calloc(1, sizeof(display_window_t)); … … 173 206 exch = async_exchange_begin(display->sess); 174 207 req = async_send_0(exch, DISPLAY_WINDOW_CREATE, &answer); 175 rc = async_data_write_start(exch, params, sizeof (display_wnd_params_t)); 208 209 /* Write fixed fields */ 210 rc = async_data_write_start(exch, &eparams, 211 sizeof (display_wnd_params_enc_t)); 212 if (rc != EOK) { 213 async_exchange_end(exch); 214 async_forget(req); 215 free(window); 216 return rc; 217 } 218 219 /* Write caption */ 220 rc = async_data_write_start(exch, params->caption, 221 eparams.caption_size); 176 222 async_exchange_end(exch); 177 223 if (rc != EOK) { … … 261 307 * @param window Window 262 308 * @param pos Position in the window where the button was pressed 263 * @return EOK on success or an error code 264 */ 265 errno_t display_window_move_req(display_window_t *window, gfx_coord2_t *pos) 266 { 267 async_exch_t *exch; 268 aid_t req; 269 ipc_call_t answer; 270 errno_t rc; 271 272 exch = async_exchange_begin(window->display->sess); 273 req = async_send_1(exch, DISPLAY_WINDOW_MOVE_REQ, window->id, &answer); 309 * @param pos_id Positioning device ID 310 * @return EOK on success or an error code 311 */ 312 errno_t display_window_move_req(display_window_t *window, gfx_coord2_t *pos, 313 sysarg_t pos_id) 314 { 315 async_exch_t *exch; 316 aid_t req; 317 ipc_call_t answer; 318 errno_t rc; 319 320 exch = async_exchange_begin(window->display->sess); 321 req = async_send_2(exch, DISPLAY_WINDOW_MOVE_REQ, window->id, 322 pos_id, &answer); 274 323 rc = async_data_write_start(exch, (void *)pos, sizeof (gfx_coord2_t)); 275 324 async_exchange_end(exch); … … 319 368 } 320 369 370 /** Get display window position. 371 * 372 * Get display window position on the display. 373 * 374 * @param window Window 375 * @param dpos Place to store position 376 * @return EOK on success or an error code 377 */ 378 errno_t display_window_get_pos(display_window_t *window, gfx_coord2_t *dpos) 379 { 380 async_exch_t *exch; 381 aid_t req; 382 ipc_call_t answer; 383 errno_t rc; 384 385 exch = async_exchange_begin(window->display->sess); 386 req = async_send_1(exch, DISPLAY_WINDOW_GET_POS, window->id, &answer); 387 rc = async_data_read_start(exch, dpos, sizeof (gfx_coord2_t)); 388 async_exchange_end(exch); 389 if (rc != EOK) { 390 async_forget(req); 391 return rc; 392 } 393 394 async_wait_for(req, &rc); 395 if (rc != EOK) 396 return rc; 397 398 return EOK; 399 } 400 401 /** Get display window maximized rectangle. 402 * 403 * Get the rectangle to which a window would be maximized. 404 * 405 * @param window Window 406 * @param rect Place to store maximized rectangle 407 * @return EOK on success or an error code 408 */ 409 errno_t display_window_get_max_rect(display_window_t *window, gfx_rect_t *rect) 410 { 411 async_exch_t *exch; 412 aid_t req; 413 ipc_call_t answer; 414 errno_t rc; 415 416 exch = async_exchange_begin(window->display->sess); 417 req = async_send_1(exch, DISPLAY_WINDOW_GET_MAX_RECT, window->id, 418 &answer); 419 rc = async_data_read_start(exch, rect, sizeof (gfx_rect_t)); 420 async_exchange_end(exch); 421 if (rc != EOK) { 422 async_forget(req); 423 return rc; 424 } 425 426 async_wait_for(req, &rc); 427 if (rc != EOK) 428 return rc; 429 430 return EOK; 431 } 432 321 433 /** Request a window resize. 322 434 * … … 328 440 * @param rsztype Resize type (which part of window frame is being dragged) 329 441 * @param pos Position in the window where the button was pressed 442 * @param pos_id Positioning device ID 330 443 * @return EOK on success or an error code 331 444 */ 332 445 errno_t display_window_resize_req(display_window_t *window, 333 display_wnd_rsztype_t rsztype, gfx_coord2_t *pos )334 { 335 async_exch_t *exch; 336 aid_t req; 337 ipc_call_t answer; 338 errno_t rc; 339 340 exch = async_exchange_begin(window->display->sess); 341 req = async_send_ 2(exch, DISPLAY_WINDOW_RESIZE_REQ, window->id,342 (sysarg_t) rsztype, &answer);446 display_wnd_rsztype_t rsztype, gfx_coord2_t *pos, sysarg_t pos_id) 447 { 448 async_exch_t *exch; 449 aid_t req; 450 ipc_call_t answer; 451 errno_t rc; 452 453 exch = async_exchange_begin(window->display->sess); 454 req = async_send_3(exch, DISPLAY_WINDOW_RESIZE_REQ, window->id, 455 (sysarg_t) rsztype, pos_id, &answer); 343 456 rc = async_data_write_start(exch, (void *)pos, sizeof (gfx_coord2_t)); 344 457 async_exchange_end(exch); … … 424 537 } 425 538 539 /** Minimize window. 540 * 541 * @param window Window 542 * @return EOK on success or an error code 543 */ 544 errno_t display_window_minimize(display_window_t *window) 545 { 546 async_exch_t *exch; 547 errno_t rc; 548 549 exch = async_exchange_begin(window->display->sess); 550 rc = async_req_1_0(exch, DISPLAY_WINDOW_MINIMIZE, window->id); 551 async_exchange_end(exch); 552 553 return rc; 554 } 555 556 /** Maximize window. 557 * 558 * @param window Window 559 * @return EOK on success or an error code 560 */ 561 errno_t display_window_maximize(display_window_t *window) 562 { 563 async_exch_t *exch; 564 errno_t rc; 565 566 exch = async_exchange_begin(window->display->sess); 567 rc = async_req_1_0(exch, DISPLAY_WINDOW_MAXIMIZE, window->id); 568 async_exchange_end(exch); 569 570 return rc; 571 } 572 573 /** Unmaximize window. 574 * 575 * @param window Window 576 * @return EOK on success or an error code 577 */ 578 errno_t display_window_unmaximize(display_window_t *window) 579 { 580 async_exch_t *exch; 581 errno_t rc; 582 583 exch = async_exchange_begin(window->display->sess); 584 rc = async_req_1_0(exch, DISPLAY_WINDOW_UNMAXIMIZE, window->id); 585 async_exchange_end(exch); 586 587 return rc; 588 } 589 426 590 /** Set window cursor. 427 591 * … … 443 607 cursor); 444 608 async_exchange_end(exch); 609 return rc; 610 } 611 612 /** Set display window caption. 613 * 614 * @param window Window 615 * @param caption New caption 616 * @return EOK on success or an error code 617 */ 618 errno_t display_window_set_caption(display_window_t *window, 619 const char *caption) 620 { 621 async_exch_t *exch; 622 aid_t req; 623 ipc_call_t answer; 624 size_t cap_size; 625 errno_t rc; 626 627 cap_size = str_size(caption); 628 629 exch = async_exchange_begin(window->display->sess); 630 req = async_send_1(exch, DISPLAY_WINDOW_SET_CAPTION, window->id, 631 &answer); 632 633 /* Write caption */ 634 rc = async_data_write_start(exch, caption, cap_size); 635 async_exchange_end(exch); 636 if (rc != EOK) { 637 async_forget(req); 638 return rc; 639 } 640 641 async_wait_for(req, &rc); 445 642 return rc; 446 643 } … … 525 722 display_wnd_ev_t event; 526 723 724 display_lock(display); 725 527 726 while (true) { 528 fibril_mutex_lock(&display->lock);529 530 727 if (display->sess != NULL) 531 728 rc = display_get_event(display, &window, &event); 532 729 else 533 730 rc = ENOENT; 534 535 fibril_mutex_unlock(&display->lock);536 731 537 732 if (rc != EOK) … … 546 741 case wev_focus: 547 742 if (window->cb != NULL && window->cb->focus_event != NULL) { 548 window->cb->focus_event(window->cb_arg); 743 window->cb->focus_event(window->cb_arg, 744 event.ev.focus.nfocus); 549 745 } 550 746 break; … … 569 765 case wev_unfocus: 570 766 if (window->cb != NULL && window->cb->unfocus_event != NULL) { 571 window->cb->unfocus_event(window->cb_arg); 767 window->cb->unfocus_event(window->cb_arg, 768 event.ev.unfocus.nfocus); 572 769 } 573 770 break; … … 575 772 } 576 773 774 display_unlock(display); 577 775 async_answer_0(icall, EOK); 578 776 }
Note:
See TracChangeset
for help on using the changeset viewer.