Ignore:
File:
1 edited

Legend:

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

    rededdc4 r5877de74  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2022 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4444#include <memgfx/memgc.h>
    4545#include <stdlib.h>
    46 #include <str.h>
    47 #include <wndmgt.h>
    4846#include "client.h"
    4947#include "display.h"
    5048#include "seat.h"
    5149#include "window.h"
    52 #include "wmclient.h"
    5350
    5451static void ds_window_invalidate_cb(void *, gfx_rect_t *);
     
    6764 * @param client Client owning the window
    6865 * @param params Window parameters
    69  * @param rwnd Place to store pointer to new window.
     66 * @param rgc Place to store pointer to new GC.
    7067 *
    7168 * @return EOK on success or an error code
    7269 */
    7370errno_t ds_window_create(ds_client_t *client, display_wnd_params_t *params,
    74     ds_window_t **rwnd)
     71    ds_window_t **rgc)
    7572{
    7673        ds_window_t *wnd = NULL;
     
    8481        wnd = calloc(1, sizeof(ds_window_t));
    8582        if (wnd == NULL) {
    86                 rc = ENOMEM;
    87                 goto error;
    88         }
    89 
    90         wnd->caption = str_dup(params->caption);
    91         if (wnd->caption == NULL) {
    9283                rc = ENOMEM;
    9384                goto error;
     
    142133        }
    143134
    144         // TODO Multi-seat: which seat should own the new window?
    145135        seat = ds_display_first_seat(client->display);
    146136
     
    150140                ds_seat_set_focus(seat, wnd);
    151141
    152         if ((params->flags & wndf_avoid) != 0)
    153                 ds_display_update_max_rect(wnd->display);
    154 
    155142        (void) ds_display_paint(wnd->display, NULL);
    156143
    157         *rwnd = wnd;
     144        *rgc = wnd;
    158145        return EOK;
    159146error:
     
    165152                if (wnd->bitmap != NULL)
    166153                        gfx_bitmap_destroy(wnd->bitmap);
    167                 if (wnd->caption != NULL)
    168                         free(wnd->caption);
    169154                free(wnd);
    170155        }
     
    182167
    183168        disp = wnd->display;
    184 
    185         ds_window_unfocus(wnd);
    186169
    187170        ds_client_remove_window(wnd);
    188171        ds_display_remove_window(wnd);
    189172
    190         if ((wnd->flags & wndf_avoid) != 0)
    191                 ds_display_update_max_rect(disp);
    192 
    193173        mem_gc_delete(wnd->mgc);
    194174
     
    196176                gfx_bitmap_destroy(wnd->bitmap);
    197177
    198         free(wnd->caption);
    199178        free(wnd);
    200179
     
    208187void ds_window_bring_to_top(ds_window_t *wnd)
    209188{
    210         ds_display_window_to_top(wnd);
     189        ds_display_t *disp = wnd->display;
     190
     191        ds_display_remove_window(wnd);
     192        ds_display_add_window(disp, wnd);
    211193        (void) ds_display_paint(wnd->display, NULL);
    212194}
     
    220202{
    221203        return wnd->gc;
    222 }
    223 
    224 /** Determine if window is visible.
    225  *
    226  * @param wnd Window
    227  * @return @c true iff window is visible
    228  */
    229 bool ds_window_is_visible(ds_window_t *wnd)
    230 {
    231         return (wnd->flags & wndf_minimized) == 0;
    232204}
    233205
     
    244216        gfx_rect_t crect;
    245217
    246         log_msg(LOG_DEFAULT, LVL_DEBUG2, "ds_window_paint");
    247 
    248         /* Skip painting the window if not visible */
    249         if (!ds_window_is_visible(wnd))
    250                 return EOK;
     218        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_paint");
    251219
    252220        if (rect != NULL) {
     
    393361        bool newr;
    394362
    395         log_msg(LOG_DEFAULT, LVL_DEBUG2, "ds_window_repaint_preview");
     363        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_repaint_preview");
    396364
    397365        /*
     
    491459        gfx_rect_t old_rect;
    492460
    493         log_msg(LOG_DEFAULT, LVL_DEBUG2, "ds_window_update_move (%d, %d)",
     461        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_move (%d, %d)",
    494462            (int) pos->x, (int) pos->y);
    495463
     
    528496        wnd->preview_rect = wnd->rect;
    529497
    530         // TODO Multi-seat: need client to tell us which seat started the resize!
     498        // XXX Need client to tell us which seat started the resize!
    531499        seat = ds_display_first_seat(wnd->display);
    532500        ctype = display_cursor_from_wrsz(rsztype);
     
    559527        ds_client_post_resize_event(wnd->client, wnd, &nrect);
    560528
    561         // TODO Multi-seat: Need to know which seat started the resize!
     529        // XXX Need to know which seat started the resize!
    562530        seat = ds_display_first_seat(wnd->display);
    563531        ds_seat_set_wm_cursor(seat, NULL);
     
    577545        gfx_rect_t old_rect;
    578546
    579         log_msg(LOG_DEFAULT, LVL_DEBUG2, "ds_window_update_resize (%d, %d)",
     547        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_update_resize (%d, %d)",
    580548            (int) pos->x, (int) pos->y);
    581549
     
    626594        bool inside;
    627595
    628         log_msg(LOG_DEFAULT, LVL_DEBUG2,
     596        log_msg(LOG_DEFAULT, LVL_DEBUG,
    629597            "ds_window_post_pos_event type=%d pos=%d,%d", event->type,
    630598            (int) event->hpos, (int) event->vpos);
     
    680648errno_t ds_window_post_focus_event(ds_window_t *wnd)
    681649{
    682         errno_t rc;
    683         ds_wmclient_t *wmclient;
    684 
    685650        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_post_focus_event");
    686651
    687         rc = ds_client_post_focus_event(wnd->client, wnd);
    688         if (rc != EOK)
    689                 return rc;
    690 
    691         /* Increase focus counter */
    692         ++wnd->nfocus;
    693 
    694         /* Notify window managers about window information change */
    695         wmclient = ds_display_first_wmclient(wnd->display);
    696         while (wmclient != NULL) {
    697                 ds_wmclient_post_wnd_changed_event(wmclient, wnd->id);
    698                 wmclient = ds_display_next_wmclient(wmclient);
    699         }
    700 
    701         return EOK;
     652        return ds_client_post_focus_event(wnd->client, wnd);
    702653}
    703654
     
    709660errno_t ds_window_post_unfocus_event(ds_window_t *wnd)
    710661{
    711         errno_t rc;
    712         ds_wmclient_t *wmclient;
    713 
    714662        log_msg(LOG_DEFAULT, LVL_DEBUG, "ds_window_post_unfocus_event");
    715663
    716         rc = ds_client_post_unfocus_event(wnd->client, wnd);
    717         if (rc != EOK)
    718                 return rc;
    719 
    720         /* Decrease focus counter */
    721         --wnd->nfocus;
    722 
    723         /* Notify window managers about window information change */
    724         wmclient = ds_display_first_wmclient(wnd->display);
    725         while (wmclient != NULL) {
    726                 ds_wmclient_post_wnd_changed_event(wmclient, wnd->id);
    727                 wmclient = ds_display_next_wmclient(wmclient);
    728         }
    729 
    730         return EOK;
     664        return ds_client_post_unfocus_event(wnd->client, wnd);
    731665}
    732666
     
    774708void ds_window_get_max_rect(ds_window_t *wnd, gfx_rect_t *rect)
    775709{
    776         *rect = wnd->display->max_rect;
     710        *rect = wnd->display->rect;
    777711}
    778712
     
    851785        wnd->rect = *nrect;
    852786
    853         if ((wnd->flags & wndf_avoid) != 0)
    854                 ds_display_update_max_rect(wnd->display);
    855 
    856         (void) ds_display_paint(wnd->display, NULL);
    857         return EOK;
    858 }
    859 
    860 /** Minimize window.
    861  *
    862  * @param wnd Window
    863  * @return EOK on success or an error code
    864  */
    865 errno_t ds_window_minimize(ds_window_t *wnd)
    866 {
    867         /* If already minimized, do nothing and return success. */
    868         if ((wnd->flags & wndf_minimized) != 0)
    869                 return EOK;
    870 
    871         ds_window_unfocus(wnd);
    872 
    873         wnd->flags |= wndf_minimized;
    874         (void) ds_display_paint(wnd->display, NULL);
    875         return EOK;
    876 }
    877 
    878 /** Unminimize window.
    879  *
    880  * @param wnd Window
    881  * @return EOK on success or an error code
    882  */
    883 errno_t ds_window_unminimize(ds_window_t *wnd)
    884 {
    885         /* If not minimized, do nothing and return success. */
    886         if ((wnd->flags & wndf_minimized) == 0)
    887                 return EOK;
    888 
    889         wnd->flags &= ~wndf_minimized;
    890787        (void) ds_display_paint(wnd->display, NULL);
    891788        return EOK;
     
    1005902 *
    1006903 * @param wnd Window
    1007  * @param cursor New cursor
    1008904 * @return EOK on success, EINVAL if @a cursor is invalid
    1009905 */
     
    1019915}
    1020916
    1021 /** Set window caption.
    1022  *
    1023  * @param wnd Window
    1024  * @param caption New caption
    1025  *
    1026  * @return EOK on success, EINVAL if @a cursor is invalid
    1027  */
    1028 errno_t ds_window_set_caption(ds_window_t *wnd, const char *caption)
    1029 {
    1030         char *dcaption;
    1031         ds_wmclient_t *wmclient;
    1032 
    1033         dcaption = str_dup(caption);
    1034         if (dcaption == NULL)
    1035                 return ENOMEM;
    1036 
    1037         free(wnd->caption);
    1038         wnd->caption = dcaption;
    1039 
    1040         /* Notify window managers about window information change */
    1041         wmclient = ds_display_first_wmclient(wnd->display);
    1042         while (wmclient != NULL) {
    1043                 ds_wmclient_post_wnd_changed_event(wmclient, wnd->id);
    1044                 wmclient = ds_display_next_wmclient(wmclient);
    1045         }
    1046 
    1047         return EOK;
    1048 }
    1049 
    1050 /** Find alternate window with the allowed flags.
    1051  *
    1052  * An alternate window is a *different* window that is preferably previous
    1053  * in the display order and only has the @a allowed flags.
    1054  *
    1055  * @param wnd Window
    1056  * @param allowed_flags Bitmask of flags that the window is allowed to have
    1057  *
    1058  * @return Alternate window matching the criteria or @c NULL if there is none
    1059  */
    1060 ds_window_t *ds_window_find_alt(ds_window_t *wnd,
    1061     display_wnd_flags_t allowed_flags)
    1062 {
    1063         ds_window_t *nwnd;
    1064 
    1065         /* Try preceding windows in display order */
    1066         nwnd = ds_display_prev_window(wnd);
    1067         while (nwnd != NULL && (nwnd->flags & ~allowed_flags) != 0) {
    1068                 nwnd = ds_display_prev_window(nwnd);
    1069         }
    1070 
    1071         /* Do we already have a matching window? */
    1072         if (nwnd != NULL && (nwnd->flags & ~allowed_flags) == 0) {
    1073                 return nwnd;
    1074         }
    1075 
    1076         /* Try succeeding windows in display order */
    1077         nwnd = ds_display_last_window(wnd->display);
    1078         while (nwnd != NULL && nwnd != wnd &&
    1079             (nwnd->flags & ~allowed_flags) != 0) {
    1080                 nwnd = ds_display_prev_window(nwnd);
    1081         }
    1082 
    1083         if (nwnd == wnd)
    1084                 return NULL;
    1085 
    1086         return nwnd;
    1087 }
    1088 
    1089 /** Remove focus from window.
    1090  *
    1091  * Used to switch focus to another window when closing or minimizing window.
    1092  *
    1093  * @param wnd Window
    1094  */
    1095 void ds_window_unfocus(ds_window_t *wnd)
    1096 {
    1097         ds_seat_t *seat;
    1098 
    1099         /* Make sure window is no longer focused in any seat */
    1100         seat = ds_display_first_seat(wnd->display);
    1101         while (seat != NULL) {
    1102                 ds_seat_unfocus_wnd(seat, wnd);
    1103                 seat = ds_display_next_seat(seat);
    1104         }
    1105 }
    1106 
    1107917/** Window memory GC invalidate callback.
    1108918 *
Note: See TracChangeset for help on using the changeset viewer.