Changeset 35cffea in mainline for uspace/srv/hid/display/window.c


Ignore:
Timestamp:
2022-05-19T08:02:31Z (2 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 *
Note: See TracChangeset for help on using the changeset viewer.