Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/display/src/display.c

    r8279aab r4ac11ff  
    11/*
    2  * Copyright (c) 2025 Jiri Svoboda
     2 * Copyright (c) 2019 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3838#include <mem.h>
    3939#include <stdlib.h>
    40 #include <str.h>
    4140#include "../private/display.h"
    4241#include "../private/params.h"
     
    6968                dsname = SERVICE_NAME_DISPLAY;
    7069
    71         rc = loc_service_get_id(dsname, &display_svc, 0);
     70        rc = loc_service_get_id(dsname, &display_svc, IPC_FLAG_BLOCKING);
    7271        if (rc != EOK) {
    7372                free(display);
     
    7675
    7776        display->sess = loc_service_connect(display_svc, INTERFACE_DISPLAY,
    78             0);
     77            IPC_FLAG_BLOCKING);
    7978        if (display->sess == NULL) {
    8079                free(display);
     
    138137}
    139138
    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 
    162139/** Initialize window parameters structure.
    163140 *
     
    170147{
    171148        memset(params, 0, sizeof(*params));
    172         params->caption = "";
    173149}
    174150
     
    186162{
    187163        display_window_t *window;
    188         display_wnd_params_enc_t eparams;
    189164        async_exch_t *exch;
    190165        aid_t req;
    191166        ipc_call_t answer;
    192167        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;
    201168
    202169        window = calloc(1, sizeof(display_window_t));
     
    206173        exch = async_exchange_begin(display->sess);
    207174        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));
    222176        async_exchange_end(exch);
    223177        if (rc != EOK) {
     
    307261 * @param window Window
    308262 * @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 */
     265errno_t display_window_move_req(display_window_t *window, gfx_coord2_t *pos)
    314266{
    315267        async_exch_t *exch;
     
    319271
    320272        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);
    323274        rc = async_data_write_start(exch, (void *)pos, sizeof (gfx_coord2_t));
    324275        async_exchange_end(exch);
     
    368319}
    369320
    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 
    433321/** Request a window resize.
    434322 *
     
    440328 * @param rsztype Resize type (which part of window frame is being dragged)
    441329 * @param pos Position in the window where the button was pressed
    442  * @param pos_id Positioning device ID
    443330 * @return EOK on success or an error code
    444331 */
    445332errno_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)
    447334{
    448335        async_exch_t *exch;
     
    452339
    453340        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);
    456343        rc = async_data_write_start(exch, (void *)pos, sizeof (gfx_coord2_t));
    457344        async_exchange_end(exch);
     
    537424}
    538425
    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 
    590426/** Set window cursor.
    591427 *
     
    610446}
    611447
    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);
    642         return rc;
    643 }
    644 
    645448/** Get display event.
    646449 *
     
    722525        display_wnd_ev_t event;
    723526
    724         display_lock(display);
    725 
    726527        while (true) {
     528                fibril_mutex_lock(&display->lock);
     529
    727530                if (display->sess != NULL)
    728531                        rc = display_get_event(display, &window, &event);
    729532                else
    730533                        rc = ENOENT;
     534
     535                fibril_mutex_unlock(&display->lock);
    731536
    732537                if (rc != EOK)
     
    741546                case wev_focus:
    742547                        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);
    745549                        }
    746550                        break;
     
    765569                case wev_unfocus:
    766570                        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);
    769572                        }
    770573                        break;
     
    772575        }
    773576
    774         display_unlock(display);
    775577        async_answer_0(icall, EOK);
    776578}
Note: See TracChangeset for help on using the changeset viewer.