Changeset 35cffea in mainline for uspace/srv/hid/display


Ignore:
Timestamp:
2022-05-19T08:02:31Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ad698f4
Parents:
fd05ea6
git-author:
Jiri Svoboda <jiri@…> (2022-05-18 17:02:12)
git-committer:
Jiri Svoboda <jiri@…> (2022-05-19 08:02:31)
Message:

Maximizing/unmaximizing a window

Location:
uspace/srv/hid/display
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/dsops.c

    rfd05ea6 r35cffea  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4949static errno_t disp_window_move(void *, sysarg_t, gfx_coord2_t *);
    5050static errno_t disp_window_get_pos(void *, sysarg_t, gfx_coord2_t *);
     51static errno_t disp_window_get_max_rect(void *, sysarg_t, gfx_rect_t *);
    5152static errno_t disp_window_resize_req(void *, sysarg_t,
    5253    display_wnd_rsztype_t, gfx_coord2_t *);
    5354static errno_t disp_window_resize(void *, sysarg_t, gfx_coord2_t *,
    5455    gfx_rect_t *);
     56static errno_t disp_window_maximize(void *, sysarg_t);
     57static errno_t disp_window_unmaximize(void *, sysarg_t);
    5558static errno_t disp_window_set_cursor(void *, sysarg_t, display_stock_cursor_t);
    5659static errno_t disp_get_event(void *, sysarg_t *, display_wnd_ev_t *);
     
    6366        .window_move = disp_window_move,
    6467        .window_get_pos = disp_window_get_pos,
     68        .window_get_max_rect = disp_window_get_max_rect,
    6569        .window_resize_req = disp_window_resize_req,
    6670        .window_resize = disp_window_resize,
     71        .window_maximize = disp_window_maximize,
     72        .window_unmaximize = disp_window_unmaximize,
    6773        .window_set_cursor = disp_window_set_cursor,
    6874        .get_event = disp_get_event,
     
    175181}
    176182
     183static errno_t disp_window_get_max_rect(void *arg, sysarg_t wnd_id,
     184    gfx_rect_t *rect)
     185{
     186        ds_client_t *client = (ds_client_t *) arg;
     187        ds_window_t *wnd;
     188
     189        ds_display_lock(client->display);
     190
     191        wnd = ds_client_find_window(client, wnd_id);
     192        if (wnd == NULL) {
     193                ds_display_unlock(client->display);
     194                return ENOENT;
     195        }
     196
     197        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_max_rect()");
     198        ds_window_get_max_rect(wnd, rect);
     199        ds_display_unlock(client->display);
     200        return EOK;
     201}
     202
    177203static errno_t disp_window_resize_req(void *arg, sysarg_t wnd_id,
    178204    display_wnd_rsztype_t rsztype, gfx_coord2_t *pos)
     
    219245}
    220246
     247static errno_t disp_window_maximize(void *arg, sysarg_t wnd_id)
     248{
     249        ds_client_t *client = (ds_client_t *) arg;
     250        ds_window_t *wnd;
     251        errno_t rc;
     252
     253        ds_display_lock(client->display);
     254
     255        wnd = ds_client_find_window(client, wnd_id);
     256        if (wnd == NULL) {
     257                ds_display_unlock(client->display);
     258                return ENOENT;
     259        }
     260
     261        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_maximize()");
     262        rc = ds_window_maximize(wnd);
     263        ds_display_unlock(client->display);
     264        return rc;
     265}
     266
     267static errno_t disp_window_unmaximize(void *arg, sysarg_t wnd_id)
     268{
     269        ds_client_t *client = (ds_client_t *) arg;
     270        ds_window_t *wnd;
     271        errno_t rc;
     272
     273        ds_display_lock(client->display);
     274
     275        wnd = ds_client_find_window(client, wnd_id);
     276        if (wnd == NULL) {
     277                ds_display_unlock(client->display);
     278                return ENOENT;
     279        }
     280
     281        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_unmaximize()");
     282        rc = ds_window_unmaximize(wnd);
     283        ds_display_unlock(client->display);
     284        return rc;
     285}
     286
    221287static errno_t disp_window_set_cursor(void *arg, sysarg_t wnd_id,
    222288    display_stock_cursor_t cursor)
  • uspace/srv/hid/display/test/window.c

    rfd05ea6 r35cffea  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    9999}
    100100
     101/** Test ds_window_get_pos(). */
     102PCUT_TEST(get_pos)
     103{
     104        ds_display_t *disp;
     105        ds_client_t *client;
     106        ds_seat_t *seat;
     107        ds_window_t *wnd;
     108        display_wnd_params_t params;
     109        gfx_coord2_t pos;
     110        errno_t rc;
     111
     112        rc = ds_display_create(NULL, df_none, &disp);
     113        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     114
     115        rc = ds_client_create(disp, NULL, NULL, &client);
     116        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     117
     118        rc = ds_seat_create(disp, &seat);
     119        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     120
     121        display_wnd_params_init(&params);
     122        params.rect.p0.x = params.rect.p0.y = 0;
     123        params.rect.p1.x = params.rect.p1.y = 10;
     124
     125        rc = ds_window_create(client, &params, &wnd);
     126        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     127
     128        wnd->dpos.x = 100;
     129        wnd->dpos.y = 100;
     130
     131        ds_window_get_pos(wnd, &pos);
     132
     133        PCUT_ASSERT_INT_EQUALS(100, pos.x);
     134        PCUT_ASSERT_INT_EQUALS(100, pos.y);
     135
     136        ds_window_destroy(wnd);
     137        ds_seat_destroy(seat);
     138        ds_client_destroy(client);
     139        ds_display_destroy(disp);
     140}
     141
     142/** Test ds_window_get_max_rect(). */
     143PCUT_TEST(get_max_rect)
     144{
     145        ds_display_t *disp;
     146        ds_client_t *client;
     147        ds_seat_t *seat;
     148        ds_window_t *wnd;
     149        display_wnd_params_t params;
     150        gfx_rect_t rect;
     151        errno_t rc;
     152
     153        rc = ds_display_create(NULL, df_none, &disp);
     154        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     155
     156        rc = ds_client_create(disp, NULL, NULL, &client);
     157        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     158
     159        rc = ds_seat_create(disp, &seat);
     160        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     161
     162        display_wnd_params_init(&params);
     163        params.rect.p0.x = params.rect.p0.y = 0;
     164        params.rect.p1.x = params.rect.p1.y = 10;
     165
     166        rc = ds_window_create(client, &params, &wnd);
     167        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     168
     169        wnd->dpos.x = 100;
     170        wnd->dpos.y = 100;
     171
     172        ds_window_get_max_rect(wnd, &rect);
     173
     174        PCUT_ASSERT_INT_EQUALS(disp->rect.p0.x, rect.p0.x);
     175        PCUT_ASSERT_INT_EQUALS(disp->rect.p0.y, rect.p0.y);
     176        PCUT_ASSERT_INT_EQUALS(disp->rect.p1.x, rect.p1.x);
     177        PCUT_ASSERT_INT_EQUALS(disp->rect.p1.y, rect.p1.y);
     178
     179        ds_window_destroy(wnd);
     180        ds_seat_destroy(seat);
     181        ds_client_destroy(client);
     182        ds_display_destroy(disp);
     183}
     184
     185/** Test ds_window_maximize(). */
     186PCUT_TEST(window_maximize)
     187{
     188        ds_display_t *disp;
     189        ds_client_t *client;
     190        ds_seat_t *seat;
     191        ds_window_t *wnd;
     192        display_wnd_params_t params;
     193        errno_t rc;
     194
     195        rc = ds_display_create(NULL, df_none, &disp);
     196        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     197
     198        rc = ds_client_create(disp, NULL, NULL, &client);
     199        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     200
     201        rc = ds_seat_create(disp, &seat);
     202        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     203
     204        display_wnd_params_init(&params);
     205        params.rect.p0.x = params.rect.p0.y = 0;
     206        params.rect.p1.x = params.rect.p1.y = 10;
     207
     208        rc = ds_window_create(client, &params, &wnd);
     209        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     210
     211        wnd->dpos.x = 100;
     212        wnd->dpos.y = 100;
     213
     214        rc = ds_window_maximize(wnd);
     215        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     216
     217        PCUT_ASSERT_INT_EQUALS(wndf_maximized, wnd->flags & wndf_maximized);
     218
     219        ds_window_destroy(wnd);
     220        ds_seat_destroy(seat);
     221        ds_client_destroy(client);
     222        ds_display_destroy(disp);
     223}
     224
     225/** Test ds_window_unmaximize(). */
     226PCUT_TEST(window_unmaximize)
     227{
     228        ds_display_t *disp;
     229        ds_client_t *client;
     230        ds_seat_t *seat;
     231        ds_window_t *wnd;
     232        display_wnd_params_t params;
     233        errno_t rc;
     234
     235        rc = ds_display_create(NULL, df_none, &disp);
     236        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     237
     238        rc = ds_client_create(disp, NULL, NULL, &client);
     239        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     240
     241        rc = ds_seat_create(disp, &seat);
     242        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     243
     244        display_wnd_params_init(&params);
     245        params.rect.p0.x = params.rect.p0.y = 0;
     246        params.rect.p1.x = params.rect.p1.y = 10;
     247
     248        rc = ds_window_create(client, &params, &wnd);
     249        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     250
     251        wnd->dpos.x = 100;
     252        wnd->dpos.y = 100;
     253
     254        rc = ds_window_maximize(wnd);
     255        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     256
     257        rc = ds_window_unmaximize(wnd);
     258        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     259
     260        PCUT_ASSERT_INT_EQUALS(0, wnd->flags & wndf_maximized);
     261
     262        ds_window_destroy(wnd);
     263        ds_seat_destroy(seat);
     264        ds_client_destroy(client);
     265        ds_display_destroy(disp);
     266}
     267
    101268/** Test ds_window_get_ctx(). */
    102269PCUT_TEST(window_get_ctx)
  • uspace/srv/hid/display/types/display/window.h

    rfd05ea6 r35cffea  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    7979        /** Minimum size */
    8080        gfx_coord2_t min_size;
     81        /** Normal rectangle (when not maximized or minimized) */
     82        gfx_rect_t normal_rect;
     83        /** Normal display position (when not maximized or minimized) */
     84        gfx_coord2_t normal_dpos;
    8185        /** Window ID */
    8286        ds_wnd_id_t id;
  • uspace/srv/hid/display/window.c

    rfd05ea6 r35cffea  
    11/*
    2  * Copyright (c) 2021 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    580580 * @param wnd Window
    581581 * @param event Position event
     582 *
     583 * @return EOK on success or an error code
    582584 */
    583585errno_t ds_window_post_pos_event(ds_window_t *wnd, pos_event_t *event)
     
    597599        inside = gfx_pix_inside_rect(&pos, &drect);
    598600
    599         if (event->type == POS_PRESS && event->btn_num == 2 && inside) {
     601        if (event->type == POS_PRESS && event->btn_num == 2 && inside &&
     602            (wnd->flags & wndf_maximized) == 0) {
    600603                ds_window_start_move(wnd, &pos);
    601604                return EOK;
     
    637640 *
    638641 * @param wnd Window
     642 * @return EOK on success or an error code
    639643 */
    640644errno_t ds_window_post_focus_event(ds_window_t *wnd)
     
    648652 *
    649653 * @param wnd Window
     654 * @return EOK on success or an error code
    650655 */
    651656errno_t ds_window_post_unfocus_event(ds_window_t *wnd)
     
    691696{
    692697        *dpos = wnd->dpos;
     698}
     699
     700/** Get maximized window rectangle.
     701 *
     702 * @param wnd Window
     703 */
     704void ds_window_get_max_rect(ds_window_t *wnd, gfx_rect_t *rect)
     705{
     706        *rect = wnd->display->rect;
    693707}
    694708
     
    716730 *
    717731 * @param wnd Window
     732 * @return EOK on success or an error code
    718733 */
    719734errno_t ds_window_resize(ds_window_t *wnd, gfx_coord2_t *offs,
     
    770785}
    771786
     787/** Maximize window.
     788 *
     789 * @param wnd Window
     790 * @return EOK on success or an error code
     791 */
     792errno_t ds_window_maximize(ds_window_t *wnd)
     793{
     794        gfx_coord2_t old_dpos;
     795        gfx_rect_t old_rect;
     796        gfx_coord2_t offs;
     797        gfx_rect_t max_rect;
     798        gfx_rect_t nrect;
     799        errno_t rc;
     800
     801        /* If already maximized, do nothing and return success. */
     802        if ((wnd->flags & wndf_maximized) != 0)
     803                return EOK;
     804
     805        /* Remember the old window rectangle and display position */
     806        old_rect = wnd->rect;
     807        old_dpos = wnd->dpos;
     808
     809        ds_window_get_max_rect(wnd, &max_rect);
     810
     811        /* Keep window contents on the same position on the screen */
     812        offs.x = max_rect.p0.x - wnd->dpos.x;
     813        offs.y = max_rect.p0.y - wnd->dpos.y;
     814
     815        /* Maximized window's coordinates will start at 0,0 */
     816        gfx_rect_rtranslate(&max_rect.p0, &max_rect, &nrect);
     817
     818        rc = ds_window_resize(wnd, &offs, &nrect);
     819        if (rc != EOK)
     820                return rc;
     821
     822        /* Set window flags, remember normal rectangle */
     823        wnd->flags |= wndf_maximized;
     824        wnd->normal_rect = old_rect;
     825        wnd->normal_dpos = old_dpos;
     826
     827        return EOK;
     828}
     829
     830/** Unmaximize window.
     831 *
     832 * @param wnd Window
     833 * @return EOK on success or an error code
     834 */
     835errno_t ds_window_unmaximize(ds_window_t *wnd)
     836{
     837        gfx_coord2_t offs;
     838        errno_t rc;
     839
     840        /* If not maximized, do nothing and return success. */
     841        if ((wnd->flags & wndf_maximized) == 0)
     842                return EOK;
     843
     844        /* Keep window contents on the same position on the screen */
     845        offs.x = wnd->normal_dpos.x - wnd->dpos.x;
     846        offs.y = wnd->normal_dpos.y - wnd->dpos.y;
     847
     848        rc = ds_window_resize(wnd, &offs, &wnd->normal_rect);
     849        if (rc != EOK)
     850                return rc;
     851
     852        /* Set window flags, remember normal rectangle */
     853        wnd->flags &= ~wndf_maximized;
     854
     855        return EOK;
     856}
     857
    772858/** Compute new window rectangle after resize operation.
    773859 *
  • uspace/srv/hid/display/window.h

    rfd05ea6 r35cffea  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6464extern void ds_window_move(ds_window_t *, gfx_coord2_t *);
    6565extern void ds_window_get_pos(ds_window_t *, gfx_coord2_t *);
     66extern void ds_window_get_max_rect(ds_window_t *, gfx_rect_t *);
    6667extern void ds_window_resize_req(ds_window_t *, display_wnd_rsztype_t,
    6768    gfx_coord2_t *);
    6869extern errno_t ds_window_resize(ds_window_t *, gfx_coord2_t *, gfx_rect_t *);
     70extern errno_t ds_window_maximize(ds_window_t *);
     71extern errno_t ds_window_unmaximize(ds_window_t *);
    6972extern void ds_window_calc_resize(ds_window_t *, gfx_coord2_t *,
    7073    gfx_rect_t *);
Note: See TracChangeset for help on using the changeset viewer.