Ignore:
File:
1 edited

Legend:

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

    rc9927c66 r5d380b6  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3838#include <mem.h>
    3939#include <stdlib.h>
     40#include <str.h>
    4041#include "../private/display.h"
    4142#include "../private/params.h"
     
    6869                dsname = SERVICE_NAME_DISPLAY;
    6970
    70         rc = loc_service_get_id(dsname, &display_svc, IPC_FLAG_BLOCKING);
     71        rc = loc_service_get_id(dsname, &display_svc, 0);
    7172        if (rc != EOK) {
    7273                free(display);
     
    7576
    7677        display->sess = loc_service_connect(display_svc, INTERFACE_DISPLAY,
    77             IPC_FLAG_BLOCKING);
     78            0);
    7879        if (display->sess == NULL) {
    7980                free(display);
     
    147148{
    148149        memset(params, 0, sizeof(*params));
     150        params->caption = "";
    149151}
    150152
     
    162164{
    163165        display_window_t *window;
    164         async_exch_t *exch;
    165         aid_t req;
    166         ipc_call_t answer;
    167         errno_t rc;
     166        display_wnd_params_enc_t eparams;
     167        async_exch_t *exch;
     168        aid_t req;
     169        ipc_call_t answer;
     170        errno_t rc;
     171
     172        /* Encode the parameters for transport */
     173        eparams.rect = params->rect;
     174        eparams.caption_size = str_size(params->caption);
     175        eparams.min_size = params->min_size;
     176        eparams.pos = params->pos;
     177        eparams.flags = params->flags;
     178        eparams.idev_id = params->idev_id;
    168179
    169180        window = calloc(1, sizeof(display_window_t));
     
    173184        exch = async_exchange_begin(display->sess);
    174185        req = async_send_0(exch, DISPLAY_WINDOW_CREATE, &answer);
    175         rc = async_data_write_start(exch, params, sizeof (display_wnd_params_t));
     186
     187        /* Write fixed fields */
     188        rc = async_data_write_start(exch, &eparams,
     189            sizeof (display_wnd_params_enc_t));
     190        if (rc != EOK) {
     191                async_exchange_end(exch);
     192                async_forget(req);
     193                free(window);
     194                return rc;
     195        }
     196
     197        /* Write caption */
     198        rc = async_data_write_start(exch, params->caption,
     199            eparams.caption_size);
    176200        async_exchange_end(exch);
    177201        if (rc != EOK) {
     
    261285 * @param window Window
    262286 * @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);
     287 * @param pos_id Positioning device ID
     288 * @return EOK on success or an error code
     289 */
     290errno_t display_window_move_req(display_window_t *window, gfx_coord2_t *pos,
     291    sysarg_t pos_id)
     292{
     293        async_exch_t *exch;
     294        aid_t req;
     295        ipc_call_t answer;
     296        errno_t rc;
     297
     298        exch = async_exchange_begin(window->display->sess);
     299        req = async_send_2(exch, DISPLAY_WINDOW_MOVE_REQ, window->id,
     300            pos_id, &answer);
    274301        rc = async_data_write_start(exch, (void *)pos, sizeof (gfx_coord2_t));
    275302        async_exchange_end(exch);
     
    350377}
    351378
     379/** Get display window maximized rectangle.
     380 *
     381 * Get the rectangle to which a window would be maximized.
     382 *
     383 * @param window Window
     384 * @param rect Place to store maximized rectangle
     385 * @return EOK on success or an error code
     386 */
     387errno_t display_window_get_max_rect(display_window_t *window, gfx_rect_t *rect)
     388{
     389        async_exch_t *exch;
     390        aid_t req;
     391        ipc_call_t answer;
     392        errno_t rc;
     393
     394        exch = async_exchange_begin(window->display->sess);
     395        req = async_send_1(exch, DISPLAY_WINDOW_GET_MAX_RECT, window->id,
     396            &answer);
     397        rc = async_data_read_start(exch, rect, sizeof (gfx_rect_t));
     398        async_exchange_end(exch);
     399        if (rc != EOK) {
     400                async_forget(req);
     401                return rc;
     402        }
     403
     404        async_wait_for(req, &rc);
     405        if (rc != EOK)
     406                return rc;
     407
     408        return EOK;
     409}
     410
    352411/** Request a window resize.
    353412 *
     
    359418 * @param rsztype Resize type (which part of window frame is being dragged)
    360419 * @param pos Position in the window where the button was pressed
     420 * @param pos_id Positioning device ID
    361421 * @return EOK on success or an error code
    362422 */
    363423errno_t display_window_resize_req(display_window_t *window,
    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);
     424    display_wnd_rsztype_t rsztype, gfx_coord2_t *pos, sysarg_t pos_id)
     425{
     426        async_exch_t *exch;
     427        aid_t req;
     428        ipc_call_t answer;
     429        errno_t rc;
     430
     431        exch = async_exchange_begin(window->display->sess);
     432        req = async_send_3(exch, DISPLAY_WINDOW_RESIZE_REQ, window->id,
     433            (sysarg_t) rsztype, pos_id, &answer);
    374434        rc = async_data_write_start(exch, (void *)pos, sizeof (gfx_coord2_t));
    375435        async_exchange_end(exch);
     
    455515}
    456516
     517/** Minimize window.
     518 *
     519 * @param window Window
     520 * @return EOK on success or an error code
     521 */
     522errno_t display_window_minimize(display_window_t *window)
     523{
     524        async_exch_t *exch;
     525        errno_t rc;
     526
     527        exch = async_exchange_begin(window->display->sess);
     528        rc = async_req_1_0(exch, DISPLAY_WINDOW_MINIMIZE, window->id);
     529        async_exchange_end(exch);
     530
     531        return rc;
     532}
     533
     534/** Maximize window.
     535 *
     536 * @param window Window
     537 * @return EOK on success or an error code
     538 */
     539errno_t display_window_maximize(display_window_t *window)
     540{
     541        async_exch_t *exch;
     542        errno_t rc;
     543
     544        exch = async_exchange_begin(window->display->sess);
     545        rc = async_req_1_0(exch, DISPLAY_WINDOW_MAXIMIZE, window->id);
     546        async_exchange_end(exch);
     547
     548        return rc;
     549}
     550
     551/** Unmaximize window.
     552 *
     553 * @param window Window
     554 * @return EOK on success or an error code
     555 */
     556errno_t display_window_unmaximize(display_window_t *window)
     557{
     558        async_exch_t *exch;
     559        errno_t rc;
     560
     561        exch = async_exchange_begin(window->display->sess);
     562        rc = async_req_1_0(exch, DISPLAY_WINDOW_UNMAXIMIZE, window->id);
     563        async_exchange_end(exch);
     564
     565        return rc;
     566}
     567
    457568/** Set window cursor.
    458569 *
     
    474585            cursor);
    475586        async_exchange_end(exch);
     587        return rc;
     588}
     589
     590/** Set display window caption.
     591 *
     592 * @param window Window
     593 * @param caption New caption
     594 * @return EOK on success or an error code
     595 */
     596errno_t display_window_set_caption(display_window_t *window,
     597    const char *caption)
     598{
     599        async_exch_t *exch;
     600        aid_t req;
     601        ipc_call_t answer;
     602        size_t cap_size;
     603        errno_t rc;
     604
     605        cap_size = str_size(caption);
     606
     607        exch = async_exchange_begin(window->display->sess);
     608        req = async_send_1(exch, DISPLAY_WINDOW_SET_CAPTION, window->id,
     609            &answer);
     610
     611        /* Write caption */
     612        rc = async_data_write_start(exch, caption, cap_size);
     613        async_exchange_end(exch);
     614        if (rc != EOK) {
     615                async_forget(req);
     616                return rc;
     617        }
     618
     619        async_wait_for(req, &rc);
    476620        return rc;
    477621}
     
    577721                case wev_focus:
    578722                        if (window->cb != NULL && window->cb->focus_event != NULL) {
    579                                 window->cb->focus_event(window->cb_arg);
     723                                window->cb->focus_event(window->cb_arg,
     724                                    event.ev.focus.nfocus);
    580725                        }
    581726                        break;
     
    600745                case wev_unfocus:
    601746                        if (window->cb != NULL && window->cb->unfocus_event != NULL) {
    602                                 window->cb->unfocus_event(window->cb_arg);
     747                                window->cb->unfocus_event(window->cb_arg,
     748                                    event.ev.unfocus.nfocus);
    603749                        }
    604750                        break;
Note: See TracChangeset for help on using the changeset viewer.