Changes in uspace/lib/display/src/display.c [8279aab:4ac11ff] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/display/src/display.c
r8279aab r4ac11ff 1 1 /* 2 * Copyright (c) 20 25Jiri Svoboda2 * Copyright (c) 2019 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 38 38 #include <mem.h> 39 39 #include <stdlib.h> 40 #include <str.h>41 40 #include "../private/display.h" 42 41 #include "../private/params.h" … … 69 68 dsname = SERVICE_NAME_DISPLAY; 70 69 71 rc = loc_service_get_id(dsname, &display_svc, 0);70 rc = loc_service_get_id(dsname, &display_svc, IPC_FLAG_BLOCKING); 72 71 if (rc != EOK) { 73 72 free(display); … … 76 75 77 76 display->sess = loc_service_connect(display_svc, INTERFACE_DISPLAY, 78 0);77 IPC_FLAG_BLOCKING); 79 78 if (display->sess == NULL) { 80 79 free(display); … … 138 137 } 139 138 140 /*141 * Lock display.142 *143 * While display is locked, display event handlers will not be called.144 *145 * @param display Display146 */147 void display_lock(display_t *display)148 {149 fibril_mutex_lock(&display->lock);150 }151 152 /*153 * Unlock display.154 *155 * @param display Display156 */157 void display_unlock(display_t *display)158 {159 fibril_mutex_unlock(&display->lock);160 }161 162 139 /** Initialize window parameters structure. 163 140 * … … 170 147 { 171 148 memset(params, 0, sizeof(*params)); 172 params->caption = "";173 149 } 174 150 … … 186 162 { 187 163 display_window_t *window; 188 display_wnd_params_enc_t eparams;189 164 async_exch_t *exch; 190 165 aid_t req; 191 166 ipc_call_t answer; 192 167 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;201 168 202 169 window = calloc(1, sizeof(display_window_t)); … … 206 173 exch = async_exchange_begin(display->sess); 207 174 req = async_send_0(exch, DISPLAY_WINDOW_CREATE, &answer); 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); 175 rc = async_data_write_start(exch, params, sizeof (display_wnd_params_t)); 222 176 async_exchange_end(exch); 223 177 if (rc != EOK) { … … 307 261 * @param window Window 308 262 * @param pos Position in the window where the button was pressed 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) 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) 314 266 { 315 267 async_exch_t *exch; … … 319 271 320 272 exch = async_exchange_begin(window->display->sess); 321 req = async_send_2(exch, DISPLAY_WINDOW_MOVE_REQ, window->id, 322 pos_id, &answer); 273 req = async_send_1(exch, DISPLAY_WINDOW_MOVE_REQ, window->id, &answer); 323 274 rc = async_data_write_start(exch, (void *)pos, sizeof (gfx_coord2_t)); 324 275 async_exchange_end(exch); … … 368 319 } 369 320 370 /** Get display window position.371 *372 * Get display window position on the display.373 *374 * @param window Window375 * @param dpos Place to store position376 * @return EOK on success or an error code377 */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 Window406 * @param rect Place to store maximized rectangle407 * @return EOK on success or an error code408 */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 433 321 /** Request a window resize. 434 322 * … … 440 328 * @param rsztype Resize type (which part of window frame is being dragged) 441 329 * @param pos Position in the window where the button was pressed 442 * @param pos_id Positioning device ID443 330 * @return EOK on success or an error code 444 331 */ 445 332 errno_t display_window_resize_req(display_window_t *window, 446 display_wnd_rsztype_t rsztype, gfx_coord2_t *pos , sysarg_t pos_id)333 display_wnd_rsztype_t rsztype, gfx_coord2_t *pos) 447 334 { 448 335 async_exch_t *exch; … … 452 339 453 340 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);341 req = async_send_2(exch, DISPLAY_WINDOW_RESIZE_REQ, window->id, 342 (sysarg_t) rsztype, &answer); 456 343 rc = async_data_write_start(exch, (void *)pos, sizeof (gfx_coord2_t)); 457 344 async_exchange_end(exch); … … 537 424 } 538 425 539 /** Minimize window.540 *541 * @param window Window542 * @return EOK on success or an error code543 */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 Window559 * @return EOK on success or an error code560 */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 Window576 * @return EOK on success or an error code577 */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 590 426 /** Set window cursor. 591 427 * … … 610 446 } 611 447 612 /** Set display window caption.613 *614 * @param window Window615 * @param caption New caption616 * @return EOK on success or an error code617 */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);642 return rc;643 }644 645 448 /** Get display event. 646 449 * … … 722 525 display_wnd_ev_t event; 723 526 724 display_lock(display);725 726 527 while (true) { 528 fibril_mutex_lock(&display->lock); 529 727 530 if (display->sess != NULL) 728 531 rc = display_get_event(display, &window, &event); 729 532 else 730 533 rc = ENOENT; 534 535 fibril_mutex_unlock(&display->lock); 731 536 732 537 if (rc != EOK) … … 741 546 case wev_focus: 742 547 if (window->cb != NULL && window->cb->focus_event != NULL) { 743 window->cb->focus_event(window->cb_arg, 744 event.ev.focus.nfocus); 548 window->cb->focus_event(window->cb_arg); 745 549 } 746 550 break; … … 765 569 case wev_unfocus: 766 570 if (window->cb != NULL && window->cb->unfocus_event != NULL) { 767 window->cb->unfocus_event(window->cb_arg, 768 event.ev.unfocus.nfocus); 571 window->cb->unfocus_event(window->cb_arg); 769 572 } 770 573 break; … … 772 575 } 773 576 774 display_unlock(display);775 577 async_answer_0(icall, EOK); 776 578 }
Note:
See TracChangeset
for help on using the changeset viewer.