Ignore:
File:
1 edited

Legend:

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

    rd9d6f29 r1215db9  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4545#include "cursimg.h"
    4646#include "cursor.h"
    47 #include "display.h"
    4847#include "seat.h"
    4948#include "window.h"
    50 #include "wmclient.h"
     49#include "display.h"
    5150
    5251static gfx_context_t *ds_display_get_unbuf_gc(ds_display_t *);
     
    9796        fibril_mutex_initialize(&disp->lock);
    9897        list_initialize(&disp->clients);
    99         list_initialize(&disp->wmclients);
    10098        disp->next_wnd_id = 1;
    10199        list_initialize(&disp->ddevs);
     
    116114void ds_display_destroy(ds_display_t *disp)
    117115{
    118         int i;
    119 
    120116        assert(list_empty(&disp->clients));
    121         assert(list_empty(&disp->wmclients));
    122117        assert(list_empty(&disp->seats));
    123         assert(list_empty(&disp->ddevs));
    124         assert(list_empty(&disp->seats));
    125         assert(list_empty(&disp->windows));
    126 
    127         /* Destroy cursors */
    128         for (i = 0; i < dcurs_limit; i++) {
    129                 ds_cursor_destroy(disp->cursor[i]);
    130                 disp->cursor[i] = NULL;
    131         }
    132 
     118        /* XXX destroy cursors */
    133119        gfx_color_delete(disp->bg_color);
    134120        free(disp);
     
    217203
    218204        return list_get_instance(link, ds_client_t, lclients);
    219 }
    220 
    221 /** Add WM client to display.
    222  *
    223  * @param disp Display
    224  * @param wmclient WM client
    225  */
    226 void ds_display_add_wmclient(ds_display_t *disp, ds_wmclient_t *wmclient)
    227 {
    228         assert(wmclient->display == NULL);
    229         assert(!link_used(&wmclient->lwmclients));
    230 
    231         wmclient->display = disp;
    232         list_append(&wmclient->lwmclients, &disp->wmclients);
    233 }
    234 
    235 /** Remove WM client from display.
    236  *
    237  * @param wmclient WM client
    238  */
    239 void ds_display_remove_wmclient(ds_wmclient_t *wmclient)
    240 {
    241         list_remove(&wmclient->lwmclients);
    242         wmclient->display = NULL;
    243 }
    244 
    245 /** Get first WM client in display.
    246  *
    247  * @param disp Display
    248  * @return First WM client or @c NULL if there is none
    249  */
    250 ds_wmclient_t *ds_display_first_wmclient(ds_display_t *disp)
    251 {
    252         link_t *link = list_first(&disp->wmclients);
    253 
    254         if (link == NULL)
    255                 return NULL;
    256 
    257         return list_get_instance(link, ds_wmclient_t, lwmclients);
    258 }
    259 
    260 /** Get next WM client in display.
    261  *
    262  * @param wmclient Current WM client
    263  * @return Next WM client or @c NULL if there is none
    264  */
    265 ds_wmclient_t *ds_display_next_wmclient(ds_wmclient_t *wmclient)
    266 {
    267         link_t *link = list_next(&wmclient->lwmclients,
    268             &wmclient->display->wmclients);
    269 
    270         if (link == NULL)
    271                 return NULL;
    272 
    273         return list_get_instance(link, ds_wmclient_t, lwmclients);
    274205}
    275206
     
    315246                gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
    316247
    317                 if (gfx_pix_inside_rect(pos, &drect) &&
    318                     ds_window_is_visible(wnd))
     248                if (gfx_pix_inside_rect(pos, &drect))
    319249                        return wnd;
    320250
     
    325255}
    326256
    327 /** Add window to window list.
    328  *
    329  * Topmost windows are enlisted before any other window. Non-topmost
    330  * windows are enlisted before any other non-topmost window.
     257/** Add window to display.
    331258 *
    332259 * @param display Display
    333260 * @param wnd Window
    334261 */
    335 void ds_display_enlist_window(ds_display_t *display, ds_window_t *wnd)
    336 {
    337         ds_window_t *w;
    338 
    339         assert(wnd->display == display);
    340         assert(!link_used(&wnd->ldwindows));
    341 
    342         if ((wnd->flags & wndf_topmost) == 0) {
    343                 /* Find the first non-topmost window */
    344                 w = ds_display_first_window(display);
    345                 while (w != NULL && (w->flags & wndf_topmost) != 0)
    346                         w = ds_display_next_window(w);
    347 
    348                 if (w != NULL)
    349                         list_insert_before(&wnd->ldwindows, &w->ldwindows);
    350                 else
    351                         list_append(&wnd->ldwindows, &display->windows);
    352         } else {
    353                 /* Insert at the beginning */
    354                 list_prepend(&wnd->ldwindows, &display->windows);
    355         }
    356 
    357 }
    358 
    359 /** Add window to display.
    360  *
    361  * @param display Display
    362  * @param wnd Window
    363  */
    364262void ds_display_add_window(ds_display_t *display, ds_window_t *wnd)
    365263{
    366         ds_wmclient_t *wmclient;
    367 
    368264        assert(wnd->display == NULL);
    369265        assert(!link_used(&wnd->ldwindows));
    370266
    371267        wnd->display = display;
    372         ds_display_enlist_window(display, wnd);
    373 
    374         /* Notify window managers about the new window */
    375         wmclient = ds_display_first_wmclient(display);
    376         while (wmclient != NULL) {
    377                 ds_wmclient_post_wnd_added_event(wmclient, wnd->id);
    378                 wmclient = ds_display_next_wmclient(wmclient);
    379         }
     268        list_prepend(&wnd->ldwindows, &display->windows);
    380269}
    381270
     
    386275void ds_display_remove_window(ds_window_t *wnd)
    387276{
    388         ds_wmclient_t *wmclient;
    389         ds_display_t *display;
    390 
    391         display = wnd->display;
    392 
    393277        list_remove(&wnd->ldwindows);
    394278        wnd->display = NULL;
    395 
    396         /* Notify window managers about the removed window */
    397         wmclient = ds_display_first_wmclient(display);
    398         while (wmclient != NULL) {
    399                 ds_wmclient_post_wnd_removed_event(wmclient, wnd->id);
    400                 wmclient = ds_display_next_wmclient(wmclient);
    401         }
    402 }
    403 
    404 /** Move window to top.
    405  *
    406  * @param display Display
    407  * @param wnd Window
    408  */
    409 void ds_display_window_to_top(ds_window_t *wnd)
    410 {
    411         assert(wnd->display != NULL);
    412         assert(link_used(&wnd->ldwindows));
    413 
    414         list_remove(&wnd->ldwindows);
    415         ds_display_enlist_window(wnd->display, wnd);
    416279}
    417280
     
    489352        ds_seat_t *seat;
    490353
    491         /* Determine which seat the event belongs to */
    492         seat = ds_display_seat_by_idev(display, event->kbd_id);
     354        // TODO Determine which seat the event belongs to
     355        seat = ds_display_first_seat(display);
    493356        if (seat == NULL)
    494357                return EOK;
     
    506369        ds_seat_t *seat;
    507370
    508         /* Determine which seat the event belongs to */
    509         seat = ds_display_seat_by_idev(display, event->pos_id);
     371        // TODO Determine which seat the event belongs to
     372        seat = ds_display_first_seat(display);
    510373        if (seat == NULL)
    511374                return EOK;
     
    566429
    567430        return list_get_instance(link, ds_seat_t, lseats);
    568 }
    569 
    570 /** Get seat which owns the specified input device.
    571  *
    572  * @param disp Display
    573  * @param idev_id Input device ID
    574  * @return Seat which owns device with ID @a idev_id or @c NULL if not found
    575  */
    576 ds_seat_t *ds_display_seat_by_idev(ds_display_t *disp, ds_idev_id_t idev_id)
    577 {
    578         // TODO Multi-seat
    579         (void) idev_id;
    580 
    581         return ds_display_first_seat(disp);
    582431}
    583432
     
    644493{
    645494        errno_t rc;
    646         gfx_rect_t old_disp_rect;
    647495
    648496        assert(ddev->display == NULL);
    649497        assert(!link_used(&ddev->lddevs));
    650 
    651         old_disp_rect = disp->rect;
    652498
    653499        ddev->display = disp;
     
    661507                /* Create cloning GC */
    662508                rc = ds_clonegc_create(ddev->gc, &disp->fbgc);
    663                 if (rc != EOK)
    664                         goto error;
     509                if (rc != EOK) {
     510                        // XXX Remove output
     511                        return ENOMEM;
     512                }
    665513
    666514                /* Allocate backbuffer */
    667515                rc = ds_display_alloc_backbuf(disp);
    668516                if (rc != EOK) {
    669                         ds_clonegc_delete(disp->fbgc);
    670                         disp->fbgc = NULL;
     517                        // XXX Remove output
     518                        // XXX Delete clone GC
    671519                        goto error;
    672520                }
     
    678526        }
    679527
    680         ds_display_update_max_rect(disp);
    681 
    682528        return EOK;
    683529error:
    684         disp->rect = old_disp_rect;
     530        disp->rect.p0.x = 0;
     531        disp->rect.p0.y = 0;
     532        disp->rect.p1.x = 0;
     533        disp->rect.p1.y = 0;
    685534        list_remove(&ddev->lddevs);
    686535        return rc;
     
    749598        list_remove(&cursor->ldisplay);
    750599        cursor->display = NULL;
    751 }
    752 
    753 /** Update display maximize rectangle.
    754  *
    755  * Recalculate the maximize rectangle (the rectangle used for maximized
    756  * windows).
    757  *
    758  * @param display Display
    759  */
    760 void ds_display_update_max_rect(ds_display_t *display)
    761 {
    762         ds_window_t *wnd;
    763         gfx_rect_t max_rect;
    764         gfx_rect_t drect;
    765 
    766         /* Start with the entire display */
    767         max_rect = display->rect;
    768 
    769         wnd = ds_display_first_window(display);
    770         while (wnd != NULL) {
    771                 /* Should maximized windows avoid this window? */
    772                 if ((wnd->flags & wndf_avoid) != 0) {
    773                         /* Window bounding rectangle on display */
    774                         gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
    775 
    776                         /* Crop maximized rectangle */
    777                         ds_display_crop_max_rect(&drect, &max_rect);
    778                 }
    779 
    780                 wnd = ds_display_next_window(wnd);
    781         }
    782 
    783         /* Update the maximize rectangle */
    784         display->max_rect = max_rect;
    785 }
    786 
    787 /** Crop maximize rectangle.
    788  *
    789  * Use the avoid rectangle @a arect to crop off maximization rectangle
    790  * @a mrect. If @a arect covers the top, bottom, left or right part
    791  * of @a mrect, it will be cropped off. Otherwise there will be
    792  * no effect.
    793  *
    794  * @param arect Avoid rectangle
    795  * @param mrect Maximize rectangle to be modified
    796  */
    797 void ds_display_crop_max_rect(gfx_rect_t *arect, gfx_rect_t *mrect)
    798 {
    799         if (arect->p0.x == mrect->p0.x && arect->p0.y == mrect->p0.y &&
    800             arect->p1.x == mrect->p1.x) {
    801                 /* Cropp off top part */
    802                 mrect->p0.y = arect->p1.y;
    803         } else if (arect->p0.x == mrect->p0.x && arect->p1.x == mrect->p1.x &&
    804             arect->p1.y == mrect->p1.y) {
    805                 /* Cropp off bottom part */
    806                 mrect->p1.y = arect->p0.y;
    807         } else if (arect->p0.x == mrect->p0.x && arect->p0.y == mrect->p0.y &&
    808             arect->p1.y == mrect->p1.y) {
    809                 /* Cropp off left part */
    810                 mrect->p0.x = arect->p1.x;
    811         } else if (arect->p0.y == mrect->p0.y && arect->p1.x == mrect->p1.x &&
    812             arect->p1.y == mrect->p1.y) {
    813                 /* Cropp off right part */
    814                 mrect->p1.x = arect->p0.x;
    815         }
    816600}
    817601
Note: See TracChangeset for help on using the changeset viewer.