Changes in uspace/lib/display/src/display.c [8279aab:c9927c66] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/display/src/display.c
r8279aab rc9927c66 1 1 /* 2 * Copyright (c) 202 5Jiri Svoboda2 * Copyright (c) 2021 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 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; 164 async_exch_t *exch; 165 aid_t req; 166 ipc_call_t answer; 167 errno_t rc; 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) 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); 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); 323 274 rc = async_data_write_start(exch, (void *)pos, sizeof (gfx_coord2_t)); 324 275 async_exchange_end(exch); … … 399 350 } 400 351 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 352 /** Request a window resize. 434 353 * … … 440 359 * @param rsztype Resize type (which part of window frame is being dragged) 441 360 * @param pos Position in the window where the button was pressed 442 * @param pos_id Positioning device ID443 361 * @return EOK on success or an error code 444 362 */ 445 363 errno_t display_window_resize_req(display_window_t *window, 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);364 display_wnd_rsztype_t rsztype, gfx_coord2_t *pos) 365 { 366 async_exch_t *exch; 367 aid_t req; 368 ipc_call_t answer; 369 errno_t rc; 370 371 exch = async_exchange_begin(window->display->sess); 372 req = async_send_2(exch, DISPLAY_WINDOW_RESIZE_REQ, window->id, 373 (sysarg_t) rsztype, &answer); 456 374 rc = async_data_write_start(exch, (void *)pos, sizeof (gfx_coord2_t)); 457 375 async_exchange_end(exch); … … 537 455 } 538 456 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 457 /** Set window cursor. 591 458 * … … 607 474 cursor); 608 475 async_exchange_end(exch); 609 return rc;610 }611 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 476 return rc; 643 477 } … … 722 556 display_wnd_ev_t event; 723 557 724 display_lock(display);725 726 558 while (true) { 559 fibril_mutex_lock(&display->lock); 560 727 561 if (display->sess != NULL) 728 562 rc = display_get_event(display, &window, &event); 729 563 else 730 564 rc = ENOENT; 565 566 fibril_mutex_unlock(&display->lock); 731 567 732 568 if (rc != EOK) … … 741 577 case wev_focus: 742 578 if (window->cb != NULL && window->cb->focus_event != NULL) { 743 window->cb->focus_event(window->cb_arg, 744 event.ev.focus.nfocus); 579 window->cb->focus_event(window->cb_arg); 745 580 } 746 581 break; … … 765 600 case wev_unfocus: 766 601 if (window->cb != NULL && window->cb->unfocus_event != NULL) { 767 window->cb->unfocus_event(window->cb_arg, 768 event.ev.unfocus.nfocus); 602 window->cb->unfocus_event(window->cb_arg); 769 603 } 770 604 break; … … 772 606 } 773 607 774 display_unlock(display);775 608 async_answer_0(icall, EOK); 776 609 }
Note:
See TracChangeset
for help on using the changeset viewer.