| 1 | /*
|
|---|
| 2 | * Copyright (c) 2024 Jiri Svoboda
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup display
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /**
|
|---|
| 33 | * @file Display server display
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #include <errno.h>
|
|---|
| 37 | #include <gfx/bitmap.h>
|
|---|
| 38 | #include <gfx/context.h>
|
|---|
| 39 | #include <gfx/render.h>
|
|---|
| 40 | #include <io/log.h>
|
|---|
| 41 | #include <memgfx/memgc.h>
|
|---|
| 42 | #include <stdlib.h>
|
|---|
| 43 | #include <str.h>
|
|---|
| 44 | #include "client.h"
|
|---|
| 45 | #include "clonegc.h"
|
|---|
| 46 | #include "cursimg.h"
|
|---|
| 47 | #include "cursor.h"
|
|---|
| 48 | #include "display.h"
|
|---|
| 49 | #include "idevcfg.h"
|
|---|
| 50 | #include "seat.h"
|
|---|
| 51 | #include "window.h"
|
|---|
| 52 | #include "wmclient.h"
|
|---|
| 53 |
|
|---|
| 54 | static gfx_context_t *ds_display_get_unbuf_gc(ds_display_t *);
|
|---|
| 55 | static void ds_display_invalidate_cb(void *, gfx_rect_t *);
|
|---|
| 56 | static void ds_display_update_cb(void *);
|
|---|
| 57 |
|
|---|
| 58 | static mem_gc_cb_t ds_display_mem_gc_cb = {
|
|---|
| 59 | .invalidate = ds_display_invalidate_cb,
|
|---|
| 60 | .update = ds_display_update_cb
|
|---|
| 61 | };
|
|---|
| 62 |
|
|---|
| 63 | /** Create display.
|
|---|
| 64 | *
|
|---|
| 65 | * @param gc Graphics context for displaying output
|
|---|
| 66 | * @param flags Display flags
|
|---|
| 67 | * @param rdisp Place to store pointer to new display.
|
|---|
| 68 | * @return EOK on success, ENOMEM if out of memory
|
|---|
| 69 | */
|
|---|
| 70 | errno_t ds_display_create(gfx_context_t *gc, ds_display_flags_t flags,
|
|---|
| 71 | ds_display_t **rdisp)
|
|---|
| 72 | {
|
|---|
| 73 | ds_display_t *disp;
|
|---|
| 74 | ds_cursor_t *cursor;
|
|---|
| 75 | int i;
|
|---|
| 76 | errno_t rc;
|
|---|
| 77 |
|
|---|
| 78 | disp = calloc(1, sizeof(ds_display_t));
|
|---|
| 79 | if (disp == NULL)
|
|---|
| 80 | return ENOMEM;
|
|---|
| 81 |
|
|---|
| 82 | rc = gfx_color_new_rgb_i16(0x8000, 0xc800, 0xffff, &disp->bg_color);
|
|---|
| 83 | if (rc != EOK) {
|
|---|
| 84 | free(disp);
|
|---|
| 85 | return ENOMEM;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | list_initialize(&disp->cursors);
|
|---|
| 89 |
|
|---|
| 90 | for (i = 0; i < dcurs_limit; i++) {
|
|---|
| 91 | rc = ds_cursor_create(disp, &ds_cursimg[i].rect,
|
|---|
| 92 | ds_cursimg[i].image, &cursor);
|
|---|
| 93 | if (rc != EOK)
|
|---|
| 94 | goto error;
|
|---|
| 95 |
|
|---|
| 96 | disp->cursor[i] = cursor;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | fibril_mutex_initialize(&disp->lock);
|
|---|
| 100 | list_initialize(&disp->clients);
|
|---|
| 101 | list_initialize(&disp->wmclients);
|
|---|
| 102 | list_initialize(&disp->cfgclients);
|
|---|
| 103 | disp->next_wnd_id = 1;
|
|---|
| 104 | disp->next_seat_id = 1;
|
|---|
| 105 | list_initialize(&disp->ddevs);
|
|---|
| 106 | list_initialize(&disp->idevcfgs);
|
|---|
| 107 | list_initialize(&disp->seats);
|
|---|
| 108 | list_initialize(&disp->windows);
|
|---|
| 109 | disp->flags = flags;
|
|---|
| 110 | *rdisp = disp;
|
|---|
| 111 | return EOK;
|
|---|
| 112 | error:
|
|---|
| 113 | ds_display_destroy(disp);
|
|---|
| 114 | return rc;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | /** Destroy display.
|
|---|
| 118 | *
|
|---|
| 119 | * @param disp Display
|
|---|
| 120 | */
|
|---|
| 121 | void ds_display_destroy(ds_display_t *disp)
|
|---|
| 122 | {
|
|---|
| 123 | int i;
|
|---|
| 124 |
|
|---|
| 125 | assert(list_empty(&disp->clients));
|
|---|
| 126 | assert(list_empty(&disp->wmclients));
|
|---|
| 127 | assert(list_empty(&disp->cfgclients));
|
|---|
| 128 | assert(list_empty(&disp->seats));
|
|---|
| 129 | assert(list_empty(&disp->ddevs));
|
|---|
| 130 | assert(list_empty(&disp->idevcfgs));
|
|---|
| 131 | assert(list_empty(&disp->seats));
|
|---|
| 132 | assert(list_empty(&disp->windows));
|
|---|
| 133 |
|
|---|
| 134 | /* Destroy cursors */
|
|---|
| 135 | for (i = 0; i < dcurs_limit; i++) {
|
|---|
| 136 | ds_cursor_destroy(disp->cursor[i]);
|
|---|
| 137 | disp->cursor[i] = NULL;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | gfx_color_delete(disp->bg_color);
|
|---|
| 141 | free(disp);
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | /** Load display configuration from SIF file.
|
|---|
| 145 | *
|
|---|
| 146 | * @param display Display
|
|---|
| 147 | * @param cfgpath Configuration file path
|
|---|
| 148 | *
|
|---|
| 149 | * @return EOK on success or an error code
|
|---|
| 150 | */
|
|---|
| 151 | errno_t ds_display_load_cfg(ds_display_t *display, const char *cfgpath)
|
|---|
| 152 | {
|
|---|
| 153 | sif_doc_t *doc = NULL;
|
|---|
| 154 | sif_node_t *rnode;
|
|---|
| 155 | sif_node_t *ndisplay;
|
|---|
| 156 | sif_node_t *nseats;
|
|---|
| 157 | sif_node_t *nseat;
|
|---|
| 158 | ds_seat_t *seat;
|
|---|
| 159 | sif_node_t *nidevcfgs;
|
|---|
| 160 | sif_node_t *nidevcfg;
|
|---|
| 161 | const char *ntype;
|
|---|
| 162 | ds_idevcfg_t *idevcfg;
|
|---|
| 163 | errno_t rc;
|
|---|
| 164 |
|
|---|
| 165 | rc = sif_load(cfgpath, &doc);
|
|---|
| 166 | if (rc != EOK)
|
|---|
| 167 | goto error;
|
|---|
| 168 |
|
|---|
| 169 | rnode = sif_get_root(doc);
|
|---|
| 170 | ndisplay = sif_node_first_child(rnode);
|
|---|
| 171 | ntype = sif_node_get_type(ndisplay);
|
|---|
| 172 | if (str_cmp(ntype, "display") != 0) {
|
|---|
| 173 | rc = EIO;
|
|---|
| 174 | goto error;
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | nseats = sif_node_first_child(ndisplay);
|
|---|
| 178 | ntype = sif_node_get_type(nseats);
|
|---|
| 179 | if (str_cmp(ntype, "seats") != 0) {
|
|---|
| 180 | rc = EIO;
|
|---|
| 181 | goto error;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | /* Load individual seats */
|
|---|
| 185 | nseat = sif_node_first_child(nseats);
|
|---|
| 186 | while (nseat != NULL) {
|
|---|
| 187 | ntype = sif_node_get_type(nseat);
|
|---|
| 188 | if (str_cmp(ntype, "seat") != 0) {
|
|---|
| 189 | rc = EIO;
|
|---|
| 190 | goto error;
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | rc = ds_seat_load(display, nseat, &seat);
|
|---|
| 194 | if (rc != EOK)
|
|---|
| 195 | goto error;
|
|---|
| 196 |
|
|---|
| 197 | (void)seat;
|
|---|
| 198 | nseat = sif_node_next_child(nseat);
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | nidevcfgs = sif_node_next_child(nseats);
|
|---|
| 202 | ntype = sif_node_get_type(nidevcfgs);
|
|---|
| 203 | if (str_cmp(ntype, "idevcfgs") != 0) {
|
|---|
| 204 | rc = EIO;
|
|---|
| 205 | goto error;
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | /* Load individual input device configuration entries */
|
|---|
| 209 | nidevcfg = sif_node_first_child(nidevcfgs);
|
|---|
| 210 | while (nidevcfg != NULL) {
|
|---|
| 211 | ntype = sif_node_get_type(nidevcfg);
|
|---|
| 212 | if (str_cmp(ntype, "idevcfg") != 0) {
|
|---|
| 213 | rc = EIO;
|
|---|
| 214 | goto error;
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | rc = ds_idevcfg_load(display, nidevcfg, &idevcfg);
|
|---|
| 218 | if (rc != EOK)
|
|---|
| 219 | goto error;
|
|---|
| 220 |
|
|---|
| 221 | (void)idevcfg;
|
|---|
| 222 | nidevcfg = sif_node_next_child(nidevcfg);
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | sif_delete(doc);
|
|---|
| 226 | return EOK;
|
|---|
| 227 | error:
|
|---|
| 228 | if (doc != NULL)
|
|---|
| 229 | sif_delete(doc);
|
|---|
| 230 |
|
|---|
| 231 | seat = ds_display_first_seat(display);
|
|---|
| 232 | while (seat != NULL) {
|
|---|
| 233 | ds_seat_destroy(seat);
|
|---|
| 234 | seat = ds_display_first_seat(display);
|
|---|
| 235 | }
|
|---|
| 236 | return rc;
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | /** Save display configuration to SIF file.
|
|---|
| 240 | *
|
|---|
| 241 | * @param display Display
|
|---|
| 242 | * @param cfgpath Configuration file path
|
|---|
| 243 | *
|
|---|
| 244 | * @return EOK on success or an error code
|
|---|
| 245 | */
|
|---|
| 246 | errno_t ds_display_save_cfg(ds_display_t *display, const char *cfgpath)
|
|---|
| 247 | {
|
|---|
| 248 | sif_doc_t *doc = NULL;
|
|---|
| 249 | sif_node_t *rnode;
|
|---|
| 250 | sif_node_t *ndisplay;
|
|---|
| 251 | sif_node_t *nseats;
|
|---|
| 252 | sif_node_t *nseat;
|
|---|
| 253 | ds_seat_t *seat;
|
|---|
| 254 | sif_node_t *nidevcfgs;
|
|---|
| 255 | sif_node_t *nidevcfg;
|
|---|
| 256 | ds_idevcfg_t *idevcfg;
|
|---|
| 257 | errno_t rc;
|
|---|
| 258 |
|
|---|
| 259 | rc = sif_new(&doc);
|
|---|
| 260 | if (rc != EOK)
|
|---|
| 261 | goto error;
|
|---|
| 262 |
|
|---|
| 263 | rnode = sif_get_root(doc);
|
|---|
| 264 | rc = sif_node_append_child(rnode, "display", &ndisplay);
|
|---|
| 265 | if (rc != EOK)
|
|---|
| 266 | goto error;
|
|---|
| 267 |
|
|---|
| 268 | rc = sif_node_append_child(ndisplay, "seats", &nseats);
|
|---|
| 269 | if (rc != EOK)
|
|---|
| 270 | goto error;
|
|---|
| 271 |
|
|---|
| 272 | /* Save individual seats */
|
|---|
| 273 | seat = ds_display_first_seat(display);
|
|---|
| 274 | while (seat != NULL) {
|
|---|
| 275 | rc = sif_node_append_child(nseats, "seat", &nseat);
|
|---|
| 276 | if (rc != EOK)
|
|---|
| 277 | goto error;
|
|---|
| 278 |
|
|---|
| 279 | rc = ds_seat_save(seat, nseat);
|
|---|
| 280 | if (rc != EOK)
|
|---|
| 281 | goto error;
|
|---|
| 282 |
|
|---|
| 283 | seat = ds_display_next_seat(seat);
|
|---|
| 284 | }
|
|---|
| 285 |
|
|---|
| 286 | rc = sif_node_append_child(ndisplay, "idevcfgs", &nidevcfgs);
|
|---|
| 287 | if (rc != EOK)
|
|---|
| 288 | goto error;
|
|---|
| 289 |
|
|---|
| 290 | /* Save individual input device configuration entries */
|
|---|
| 291 | idevcfg = ds_display_first_idevcfg(display);
|
|---|
| 292 | while (idevcfg != NULL) {
|
|---|
| 293 | rc = sif_node_append_child(nidevcfgs, "idevcfg", &nidevcfg);
|
|---|
| 294 | if (rc != EOK)
|
|---|
| 295 | goto error;
|
|---|
| 296 |
|
|---|
| 297 | rc = ds_idevcfg_save(idevcfg, nidevcfg);
|
|---|
| 298 | if (rc != EOK)
|
|---|
| 299 | goto error;
|
|---|
| 300 |
|
|---|
| 301 | idevcfg = ds_display_next_idevcfg(idevcfg);
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 304 | rc = sif_save(doc, cfgpath);
|
|---|
| 305 | if (rc != EOK)
|
|---|
| 306 | goto error;
|
|---|
| 307 |
|
|---|
| 308 | sif_delete(doc);
|
|---|
| 309 | return EOK;
|
|---|
| 310 | error:
|
|---|
| 311 | if (doc != NULL)
|
|---|
| 312 | sif_delete(doc);
|
|---|
| 313 | return rc;
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 | /** Lock display.
|
|---|
| 317 | *
|
|---|
| 318 | * This should be called in any thread that wishes to access the display
|
|---|
| 319 | * or its child objects (e.g. windows).
|
|---|
| 320 | *
|
|---|
| 321 | * @param disp Display
|
|---|
| 322 | */
|
|---|
| 323 | void ds_display_lock(ds_display_t *disp)
|
|---|
| 324 | {
|
|---|
| 325 | fibril_mutex_lock(&disp->lock);
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | /** Unlock display.
|
|---|
| 329 | *
|
|---|
| 330 | * @param disp Display
|
|---|
| 331 | */
|
|---|
| 332 | void ds_display_unlock(ds_display_t *disp)
|
|---|
| 333 | {
|
|---|
| 334 | fibril_mutex_unlock(&disp->lock);
|
|---|
| 335 | }
|
|---|
| 336 |
|
|---|
| 337 | /** Get display information.
|
|---|
| 338 | *
|
|---|
| 339 | * @param disp Display
|
|---|
| 340 | */
|
|---|
| 341 | void ds_display_get_info(ds_display_t *disp, display_info_t *info)
|
|---|
| 342 | {
|
|---|
| 343 | info->rect = disp->rect;
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | /** Add client to display.
|
|---|
| 347 | *
|
|---|
| 348 | * @param disp Display
|
|---|
| 349 | * @param client Client
|
|---|
| 350 | */
|
|---|
| 351 | void ds_display_add_client(ds_display_t *disp, ds_client_t *client)
|
|---|
| 352 | {
|
|---|
| 353 | assert(client->display == NULL);
|
|---|
| 354 | assert(!link_used(&client->lclients));
|
|---|
| 355 |
|
|---|
| 356 | client->display = disp;
|
|---|
| 357 | list_append(&client->lclients, &disp->clients);
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 | /** Remove client from display.
|
|---|
| 361 | *
|
|---|
| 362 | * @param client Client
|
|---|
| 363 | */
|
|---|
| 364 | void ds_display_remove_client(ds_client_t *client)
|
|---|
| 365 | {
|
|---|
| 366 | list_remove(&client->lclients);
|
|---|
| 367 | client->display = NULL;
|
|---|
| 368 | }
|
|---|
| 369 |
|
|---|
| 370 | /** Get first client in display.
|
|---|
| 371 | *
|
|---|
| 372 | * @param disp Display
|
|---|
| 373 | * @return First client or @c NULL if there is none
|
|---|
| 374 | */
|
|---|
| 375 | ds_client_t *ds_display_first_client(ds_display_t *disp)
|
|---|
| 376 | {
|
|---|
| 377 | link_t *link = list_first(&disp->clients);
|
|---|
| 378 |
|
|---|
| 379 | if (link == NULL)
|
|---|
| 380 | return NULL;
|
|---|
| 381 |
|
|---|
| 382 | return list_get_instance(link, ds_client_t, lclients);
|
|---|
| 383 | }
|
|---|
| 384 |
|
|---|
| 385 | /** Get next client in display.
|
|---|
| 386 | *
|
|---|
| 387 | * @param client Current client
|
|---|
| 388 | * @return Next client or @c NULL if there is none
|
|---|
| 389 | */
|
|---|
| 390 | ds_client_t *ds_display_next_client(ds_client_t *client)
|
|---|
| 391 | {
|
|---|
| 392 | link_t *link = list_next(&client->lclients, &client->display->clients);
|
|---|
| 393 |
|
|---|
| 394 | if (link == NULL)
|
|---|
| 395 | return NULL;
|
|---|
| 396 |
|
|---|
| 397 | return list_get_instance(link, ds_client_t, lclients);
|
|---|
| 398 | }
|
|---|
| 399 |
|
|---|
| 400 | /** Add WM client to display.
|
|---|
| 401 | *
|
|---|
| 402 | * @param disp Display
|
|---|
| 403 | * @param wmclient WM client
|
|---|
| 404 | */
|
|---|
| 405 | void ds_display_add_wmclient(ds_display_t *disp, ds_wmclient_t *wmclient)
|
|---|
| 406 | {
|
|---|
| 407 | assert(wmclient->display == NULL);
|
|---|
| 408 | assert(!link_used(&wmclient->lwmclients));
|
|---|
| 409 |
|
|---|
| 410 | wmclient->display = disp;
|
|---|
| 411 | list_append(&wmclient->lwmclients, &disp->wmclients);
|
|---|
| 412 | }
|
|---|
| 413 |
|
|---|
| 414 | /** Remove WM client from display.
|
|---|
| 415 | *
|
|---|
| 416 | * @param wmclient WM client
|
|---|
| 417 | */
|
|---|
| 418 | void ds_display_remove_wmclient(ds_wmclient_t *wmclient)
|
|---|
| 419 | {
|
|---|
| 420 | list_remove(&wmclient->lwmclients);
|
|---|
| 421 | wmclient->display = NULL;
|
|---|
| 422 | }
|
|---|
| 423 |
|
|---|
| 424 | /** Add CFG client to display.
|
|---|
| 425 | *
|
|---|
| 426 | * @param disp Display
|
|---|
| 427 | * @param cfgclient CFG client
|
|---|
| 428 | */
|
|---|
| 429 | void ds_display_add_cfgclient(ds_display_t *disp, ds_cfgclient_t *cfgclient)
|
|---|
| 430 | {
|
|---|
| 431 | assert(cfgclient->display == NULL);
|
|---|
| 432 | assert(!link_used(&cfgclient->lcfgclients));
|
|---|
| 433 |
|
|---|
| 434 | cfgclient->display = disp;
|
|---|
| 435 | list_append(&cfgclient->lcfgclients, &disp->cfgclients);
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 | /** Remove CFG client from display.
|
|---|
| 439 | *
|
|---|
| 440 | * @param cfgclient CFG client
|
|---|
| 441 | */
|
|---|
| 442 | void ds_display_remove_cfgclient(ds_cfgclient_t *cfgclient)
|
|---|
| 443 | {
|
|---|
| 444 | list_remove(&cfgclient->lcfgclients);
|
|---|
| 445 | cfgclient->display = NULL;
|
|---|
| 446 | }
|
|---|
| 447 |
|
|---|
| 448 | /** Get first WM client in display.
|
|---|
| 449 | *
|
|---|
| 450 | * @param disp Display
|
|---|
| 451 | * @return First WM client or @c NULL if there is none
|
|---|
| 452 | */
|
|---|
| 453 | ds_wmclient_t *ds_display_first_wmclient(ds_display_t *disp)
|
|---|
| 454 | {
|
|---|
| 455 | link_t *link = list_first(&disp->wmclients);
|
|---|
| 456 |
|
|---|
| 457 | if (link == NULL)
|
|---|
| 458 | return NULL;
|
|---|
| 459 |
|
|---|
| 460 | return list_get_instance(link, ds_wmclient_t, lwmclients);
|
|---|
| 461 | }
|
|---|
| 462 |
|
|---|
| 463 | /** Get next WM client in display.
|
|---|
| 464 | *
|
|---|
| 465 | * @param wmclient Current WM client
|
|---|
| 466 | * @return Next WM client or @c NULL if there is none
|
|---|
| 467 | */
|
|---|
| 468 | ds_wmclient_t *ds_display_next_wmclient(ds_wmclient_t *wmclient)
|
|---|
| 469 | {
|
|---|
| 470 | link_t *link = list_next(&wmclient->lwmclients,
|
|---|
| 471 | &wmclient->display->wmclients);
|
|---|
| 472 |
|
|---|
| 473 | if (link == NULL)
|
|---|
| 474 | return NULL;
|
|---|
| 475 |
|
|---|
| 476 | return list_get_instance(link, ds_wmclient_t, lwmclients);
|
|---|
| 477 | }
|
|---|
| 478 |
|
|---|
| 479 | /** Find window in all clients by ID.
|
|---|
| 480 | *
|
|---|
| 481 | * XXX This is just a hack needed to match GC connection to a window,
|
|---|
| 482 | * as we don't have a good safe way to pass the GC endpoint to our client
|
|---|
| 483 | * on demand.
|
|---|
| 484 | *
|
|---|
| 485 | * @param display Display
|
|---|
| 486 | * @param id Window ID
|
|---|
| 487 | */
|
|---|
| 488 | ds_window_t *ds_display_find_window(ds_display_t *display, ds_wnd_id_t id)
|
|---|
| 489 | {
|
|---|
| 490 | ds_client_t *client;
|
|---|
| 491 | ds_window_t *wnd;
|
|---|
| 492 |
|
|---|
| 493 | client = ds_display_first_client(display);
|
|---|
| 494 | while (client != NULL) {
|
|---|
| 495 | wnd = ds_client_find_window(client, id);
|
|---|
| 496 | if (wnd != NULL)
|
|---|
| 497 | return wnd;
|
|---|
| 498 |
|
|---|
| 499 | client = ds_display_next_client(client);
|
|---|
| 500 | }
|
|---|
| 501 |
|
|---|
| 502 | return NULL;
|
|---|
| 503 | }
|
|---|
| 504 |
|
|---|
| 505 | /** Find window by display position.
|
|---|
| 506 | *
|
|---|
| 507 | * @param display Display
|
|---|
| 508 | * @param pos Display position
|
|---|
| 509 | */
|
|---|
| 510 | ds_window_t *ds_display_window_by_pos(ds_display_t *display, gfx_coord2_t *pos)
|
|---|
| 511 | {
|
|---|
| 512 | ds_window_t *wnd;
|
|---|
| 513 | gfx_rect_t drect;
|
|---|
| 514 |
|
|---|
| 515 | wnd = ds_display_first_window(display);
|
|---|
| 516 | while (wnd != NULL) {
|
|---|
| 517 | /* Window bounding rectangle on display */
|
|---|
| 518 | gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
|
|---|
| 519 |
|
|---|
| 520 | if (gfx_pix_inside_rect(pos, &drect) &&
|
|---|
| 521 | ds_window_is_visible(wnd))
|
|---|
| 522 | return wnd;
|
|---|
| 523 |
|
|---|
| 524 | wnd = ds_display_next_window(wnd);
|
|---|
| 525 | }
|
|---|
| 526 |
|
|---|
| 527 | return NULL;
|
|---|
| 528 | }
|
|---|
| 529 |
|
|---|
| 530 | /** Add window to window list.
|
|---|
| 531 | *
|
|---|
| 532 | * Topmost windows are enlisted before any other window. Non-topmost
|
|---|
| 533 | * windows are enlisted before any other non-topmost window.
|
|---|
| 534 | *
|
|---|
| 535 | * @param display Display
|
|---|
| 536 | * @param wnd Window
|
|---|
| 537 | */
|
|---|
| 538 | void ds_display_enlist_window(ds_display_t *display, ds_window_t *wnd)
|
|---|
| 539 | {
|
|---|
| 540 | ds_window_t *w;
|
|---|
| 541 |
|
|---|
| 542 | assert(wnd->display == display);
|
|---|
| 543 | assert(!link_used(&wnd->ldwindows));
|
|---|
| 544 |
|
|---|
| 545 | if ((wnd->flags & wndf_topmost) == 0) {
|
|---|
| 546 | /* Find the first non-topmost window */
|
|---|
| 547 | w = ds_display_first_window(display);
|
|---|
| 548 | while (w != NULL && (w->flags & wndf_topmost) != 0)
|
|---|
| 549 | w = ds_display_next_window(w);
|
|---|
| 550 |
|
|---|
| 551 | if (w != NULL)
|
|---|
| 552 | list_insert_before(&wnd->ldwindows, &w->ldwindows);
|
|---|
| 553 | else
|
|---|
| 554 | list_append(&wnd->ldwindows, &display->windows);
|
|---|
| 555 | } else {
|
|---|
| 556 | /* Insert at the beginning */
|
|---|
| 557 | list_prepend(&wnd->ldwindows, &display->windows);
|
|---|
| 558 | }
|
|---|
| 559 |
|
|---|
| 560 | }
|
|---|
| 561 |
|
|---|
| 562 | /** Add window to display.
|
|---|
| 563 | *
|
|---|
| 564 | * @param display Display
|
|---|
| 565 | * @param wnd Window
|
|---|
| 566 | */
|
|---|
| 567 | void ds_display_add_window(ds_display_t *display, ds_window_t *wnd)
|
|---|
| 568 | {
|
|---|
| 569 | ds_wmclient_t *wmclient;
|
|---|
| 570 |
|
|---|
| 571 | assert(wnd->display == NULL);
|
|---|
| 572 | assert(!link_used(&wnd->ldwindows));
|
|---|
| 573 |
|
|---|
| 574 | wnd->display = display;
|
|---|
| 575 | ds_display_enlist_window(display, wnd);
|
|---|
| 576 |
|
|---|
| 577 | /* Notify window managers about the new window */
|
|---|
| 578 | wmclient = ds_display_first_wmclient(display);
|
|---|
| 579 | while (wmclient != NULL) {
|
|---|
| 580 | ds_wmclient_post_wnd_added_event(wmclient, wnd->id);
|
|---|
| 581 | wmclient = ds_display_next_wmclient(wmclient);
|
|---|
| 582 | }
|
|---|
| 583 | }
|
|---|
| 584 |
|
|---|
| 585 | /** Remove window from display.
|
|---|
| 586 | *
|
|---|
| 587 | * @param wnd Window
|
|---|
| 588 | */
|
|---|
| 589 | void ds_display_remove_window(ds_window_t *wnd)
|
|---|
| 590 | {
|
|---|
| 591 | ds_wmclient_t *wmclient;
|
|---|
| 592 | ds_display_t *display;
|
|---|
| 593 |
|
|---|
| 594 | display = wnd->display;
|
|---|
| 595 |
|
|---|
| 596 | list_remove(&wnd->ldwindows);
|
|---|
| 597 | wnd->display = NULL;
|
|---|
| 598 |
|
|---|
| 599 | /* Notify window managers about the removed window */
|
|---|
| 600 | wmclient = ds_display_first_wmclient(display);
|
|---|
| 601 | while (wmclient != NULL) {
|
|---|
| 602 | ds_wmclient_post_wnd_removed_event(wmclient, wnd->id);
|
|---|
| 603 | wmclient = ds_display_next_wmclient(wmclient);
|
|---|
| 604 | }
|
|---|
| 605 | }
|
|---|
| 606 |
|
|---|
| 607 | /** Move window to top.
|
|---|
| 608 | *
|
|---|
| 609 | * @param display Display
|
|---|
| 610 | * @param wnd Window
|
|---|
| 611 | */
|
|---|
| 612 | void ds_display_window_to_top(ds_window_t *wnd)
|
|---|
| 613 | {
|
|---|
| 614 | assert(wnd->display != NULL);
|
|---|
| 615 | assert(link_used(&wnd->ldwindows));
|
|---|
| 616 |
|
|---|
| 617 | list_remove(&wnd->ldwindows);
|
|---|
| 618 | ds_display_enlist_window(wnd->display, wnd);
|
|---|
| 619 | }
|
|---|
| 620 |
|
|---|
| 621 | /** Get first window in display.
|
|---|
| 622 | *
|
|---|
| 623 | * @param display Display
|
|---|
| 624 | * @return First window or @c NULL if there is none
|
|---|
| 625 | */
|
|---|
| 626 | ds_window_t *ds_display_first_window(ds_display_t *display)
|
|---|
| 627 | {
|
|---|
| 628 | link_t *link = list_first(&display->windows);
|
|---|
| 629 |
|
|---|
| 630 | if (link == NULL)
|
|---|
| 631 | return NULL;
|
|---|
| 632 |
|
|---|
| 633 | return list_get_instance(link, ds_window_t, ldwindows);
|
|---|
| 634 | }
|
|---|
| 635 |
|
|---|
| 636 | /** Get last window in display.
|
|---|
| 637 | *
|
|---|
| 638 | * @param display Display
|
|---|
| 639 | * @return Last window or @c NULL if there is none
|
|---|
| 640 | */
|
|---|
| 641 | ds_window_t *ds_display_last_window(ds_display_t *display)
|
|---|
| 642 | {
|
|---|
| 643 | link_t *link = list_last(&display->windows);
|
|---|
| 644 |
|
|---|
| 645 | if (link == NULL)
|
|---|
| 646 | return NULL;
|
|---|
| 647 |
|
|---|
| 648 | return list_get_instance(link, ds_window_t, ldwindows);
|
|---|
| 649 | }
|
|---|
| 650 |
|
|---|
| 651 | /** Get next window in client.
|
|---|
| 652 | *
|
|---|
| 653 | * @param wnd Current window
|
|---|
| 654 | * @return Next window or @c NULL if there is none
|
|---|
| 655 | */
|
|---|
| 656 | ds_window_t *ds_display_next_window(ds_window_t *wnd)
|
|---|
| 657 | {
|
|---|
| 658 | link_t *link = list_next(&wnd->ldwindows, &wnd->display->windows);
|
|---|
| 659 |
|
|---|
| 660 | if (link == NULL)
|
|---|
| 661 | return NULL;
|
|---|
| 662 |
|
|---|
| 663 | return list_get_instance(link, ds_window_t, ldwindows);
|
|---|
| 664 | }
|
|---|
| 665 |
|
|---|
| 666 | /** Get previous window in client.
|
|---|
| 667 | *
|
|---|
| 668 | * @param wnd Current window
|
|---|
| 669 | * @return Previous window or @c NULL if there is none
|
|---|
| 670 | */
|
|---|
| 671 | ds_window_t *ds_display_prev_window(ds_window_t *wnd)
|
|---|
| 672 | {
|
|---|
| 673 | link_t *link = list_prev(&wnd->ldwindows, &wnd->display->windows);
|
|---|
| 674 |
|
|---|
| 675 | if (link == NULL)
|
|---|
| 676 | return NULL;
|
|---|
| 677 |
|
|---|
| 678 | return list_get_instance(link, ds_window_t, ldwindows);
|
|---|
| 679 | }
|
|---|
| 680 |
|
|---|
| 681 | /** Post keyboard event to a display.
|
|---|
| 682 | *
|
|---|
| 683 | * The event is routed to the correct window by first determining the
|
|---|
| 684 | * seat the keyboard device belongs to and then the event is sent to the
|
|---|
| 685 | * window focused by that seat.
|
|---|
| 686 | *
|
|---|
| 687 | * @param display Display
|
|---|
| 688 | * @param event Event
|
|---|
| 689 | */
|
|---|
| 690 | errno_t ds_display_post_kbd_event(ds_display_t *display, kbd_event_t *event)
|
|---|
| 691 | {
|
|---|
| 692 | ds_seat_t *seat;
|
|---|
| 693 |
|
|---|
| 694 | /* Determine which seat the event belongs to */
|
|---|
| 695 | seat = ds_display_seat_by_idev(display, event->kbd_id);
|
|---|
| 696 | if (seat == NULL)
|
|---|
| 697 | return EOK;
|
|---|
| 698 |
|
|---|
| 699 | return ds_seat_post_kbd_event(seat, event);
|
|---|
| 700 | }
|
|---|
| 701 |
|
|---|
| 702 | /** Post position event to a display.
|
|---|
| 703 | *
|
|---|
| 704 | * @param display Display
|
|---|
| 705 | * @param event Event
|
|---|
| 706 | */
|
|---|
| 707 | errno_t ds_display_post_ptd_event(ds_display_t *display, ptd_event_t *event)
|
|---|
| 708 | {
|
|---|
| 709 | ds_seat_t *seat;
|
|---|
| 710 |
|
|---|
| 711 | /* Determine which seat the event belongs to */
|
|---|
| 712 | seat = ds_display_seat_by_idev(display, event->pos_id);
|
|---|
| 713 | if (seat == NULL)
|
|---|
| 714 | return EOK;
|
|---|
| 715 |
|
|---|
| 716 | return ds_seat_post_ptd_event(seat, event);
|
|---|
| 717 | }
|
|---|
| 718 |
|
|---|
| 719 | /** Add seat to display.
|
|---|
| 720 | *
|
|---|
| 721 | * @param disp Display
|
|---|
| 722 | * @param seat Seat
|
|---|
| 723 | */
|
|---|
| 724 | void ds_display_add_seat(ds_display_t *disp, ds_seat_t *seat)
|
|---|
| 725 | {
|
|---|
| 726 | assert(seat->display == NULL);
|
|---|
| 727 | assert(!link_used(&seat->lseats));
|
|---|
| 728 |
|
|---|
| 729 | seat->display = disp;
|
|---|
| 730 | seat->id = disp->next_seat_id++;
|
|---|
| 731 | list_append(&seat->lseats, &disp->seats);
|
|---|
| 732 | }
|
|---|
| 733 |
|
|---|
| 734 | /** Remove seat from display.
|
|---|
| 735 | *
|
|---|
| 736 | * @param seat Seat
|
|---|
| 737 | */
|
|---|
| 738 | void ds_display_remove_seat(ds_seat_t *seat)
|
|---|
| 739 | {
|
|---|
| 740 | list_remove(&seat->lseats);
|
|---|
| 741 | seat->display = NULL;
|
|---|
| 742 | }
|
|---|
| 743 |
|
|---|
| 744 | /** Get first seat in display.
|
|---|
| 745 | *
|
|---|
| 746 | * @param disp Display
|
|---|
| 747 | * @return First seat or @c NULL if there is none
|
|---|
| 748 | */
|
|---|
| 749 | ds_seat_t *ds_display_first_seat(ds_display_t *disp)
|
|---|
| 750 | {
|
|---|
| 751 | link_t *link = list_first(&disp->seats);
|
|---|
| 752 |
|
|---|
| 753 | if (link == NULL)
|
|---|
| 754 | return NULL;
|
|---|
| 755 |
|
|---|
| 756 | return list_get_instance(link, ds_seat_t, lseats);
|
|---|
| 757 | }
|
|---|
| 758 |
|
|---|
| 759 | /** Get next seat in display.
|
|---|
| 760 | *
|
|---|
| 761 | * @param seat Current seat
|
|---|
| 762 | * @return Next seat or @c NULL if there is none
|
|---|
| 763 | */
|
|---|
| 764 | ds_seat_t *ds_display_next_seat(ds_seat_t *seat)
|
|---|
| 765 | {
|
|---|
| 766 | link_t *link = list_next(&seat->lseats, &seat->display->seats);
|
|---|
| 767 |
|
|---|
| 768 | if (link == NULL)
|
|---|
| 769 | return NULL;
|
|---|
| 770 |
|
|---|
| 771 | return list_get_instance(link, ds_seat_t, lseats);
|
|---|
| 772 | }
|
|---|
| 773 |
|
|---|
| 774 | /** Get default seat in display.
|
|---|
| 775 | *
|
|---|
| 776 | * @param disp Display
|
|---|
| 777 | * @return First seat or @c NULL if there is none
|
|---|
| 778 | */
|
|---|
| 779 | ds_seat_t *ds_display_default_seat(ds_display_t *disp)
|
|---|
| 780 | {
|
|---|
| 781 | /* XXX Probably not the best solution */
|
|---|
| 782 | return ds_display_first_seat(disp);
|
|---|
| 783 | }
|
|---|
| 784 |
|
|---|
| 785 | /** Find seat by ID.
|
|---|
| 786 | *
|
|---|
| 787 | * @param display Display
|
|---|
| 788 | * @param id Seat ID
|
|---|
| 789 | */
|
|---|
| 790 | ds_seat_t *ds_display_find_seat(ds_display_t *display, ds_seat_id_t id)
|
|---|
| 791 | {
|
|---|
| 792 | ds_seat_t *seat;
|
|---|
| 793 |
|
|---|
| 794 | seat = ds_display_first_seat(display);
|
|---|
| 795 | while (seat != NULL) {
|
|---|
| 796 | if (seat->id == id)
|
|---|
| 797 | return seat;
|
|---|
| 798 |
|
|---|
| 799 | seat = ds_display_next_seat(seat);
|
|---|
| 800 | }
|
|---|
| 801 |
|
|---|
| 802 | return NULL;
|
|---|
| 803 | }
|
|---|
| 804 |
|
|---|
| 805 | /** Get seat which owns the specified input device.
|
|---|
| 806 | *
|
|---|
| 807 | * @param disp Display
|
|---|
| 808 | * @param idev_id Input device ID
|
|---|
| 809 | * @return Seat which owns device with ID @a idev_id or @c NULL if not found
|
|---|
| 810 | */
|
|---|
| 811 | ds_seat_t *ds_display_seat_by_idev(ds_display_t *disp, ds_idev_id_t idev_id)
|
|---|
| 812 | {
|
|---|
| 813 | ds_idevcfg_t *idevcfg;
|
|---|
| 814 |
|
|---|
| 815 | /*
|
|---|
| 816 | * Find input device configuration entry that maps this input device
|
|---|
| 817 | * to a seat.
|
|---|
| 818 | */
|
|---|
| 819 | idevcfg = ds_display_first_idevcfg(disp);
|
|---|
| 820 | while (idevcfg != NULL) {
|
|---|
| 821 | if (idevcfg->svc_id == idev_id)
|
|---|
| 822 | return idevcfg->seat;
|
|---|
| 823 |
|
|---|
| 824 | idevcfg = ds_display_next_idevcfg(idevcfg);
|
|---|
| 825 | }
|
|---|
| 826 |
|
|---|
| 827 | /* If none was found, return the default seat */
|
|---|
| 828 | return ds_display_default_seat(disp);
|
|---|
| 829 | }
|
|---|
| 830 |
|
|---|
| 831 | /** Allocate back buffer for display.
|
|---|
| 832 | *
|
|---|
| 833 | * @param disp Display
|
|---|
| 834 | * @return EOK on success or if no back buffer is required, otherwise
|
|---|
| 835 | * an error code.
|
|---|
| 836 | */
|
|---|
| 837 | static errno_t ds_display_alloc_backbuf(ds_display_t *disp)
|
|---|
| 838 | {
|
|---|
| 839 | gfx_context_t *ugc;
|
|---|
| 840 | gfx_bitmap_params_t params;
|
|---|
| 841 | gfx_bitmap_alloc_t alloc;
|
|---|
| 842 | errno_t rc;
|
|---|
| 843 |
|
|---|
| 844 | /* Allocate backbuffer */
|
|---|
| 845 | if ((disp->flags & df_disp_double_buf) == 0) {
|
|---|
| 846 | /* Not double buffering. Nothing to do. */
|
|---|
| 847 | return EOK;
|
|---|
| 848 | }
|
|---|
| 849 |
|
|---|
| 850 | ugc = ds_display_get_unbuf_gc(disp);
|
|---|
| 851 |
|
|---|
| 852 | gfx_bitmap_params_init(¶ms);
|
|---|
| 853 | params.rect = disp->rect;
|
|---|
| 854 |
|
|---|
| 855 | rc = gfx_bitmap_create(ugc, ¶ms, NULL,
|
|---|
| 856 | &disp->backbuf);
|
|---|
| 857 | if (rc != EOK)
|
|---|
| 858 | goto error;
|
|---|
| 859 |
|
|---|
| 860 | rc = gfx_bitmap_get_alloc(disp->backbuf, &alloc);
|
|---|
| 861 | if (rc != EOK)
|
|---|
| 862 | goto error;
|
|---|
| 863 |
|
|---|
| 864 | rc = mem_gc_create(&disp->rect, &alloc, &ds_display_mem_gc_cb,
|
|---|
| 865 | (void *) disp, &disp->bbgc);
|
|---|
| 866 | if (rc != EOK)
|
|---|
| 867 | goto error;
|
|---|
| 868 |
|
|---|
| 869 | disp->dirty_rect.p0.x = 0;
|
|---|
| 870 | disp->dirty_rect.p0.y = 0;
|
|---|
| 871 | disp->dirty_rect.p1.x = 0;
|
|---|
| 872 | disp->dirty_rect.p1.y = 0;
|
|---|
| 873 |
|
|---|
| 874 | return EOK;
|
|---|
| 875 | error:
|
|---|
| 876 | if (disp->backbuf != NULL) {
|
|---|
| 877 | gfx_bitmap_destroy(disp->backbuf);
|
|---|
| 878 | disp->backbuf = NULL;
|
|---|
| 879 | }
|
|---|
| 880 |
|
|---|
| 881 | return rc;
|
|---|
| 882 | }
|
|---|
| 883 |
|
|---|
| 884 | /** Add display device to display.
|
|---|
| 885 | *
|
|---|
| 886 | * @param disp Display
|
|---|
| 887 | * @param ddev Display device
|
|---|
| 888 | * @return EOK on success, or an error code
|
|---|
| 889 | */
|
|---|
| 890 | errno_t ds_display_add_ddev(ds_display_t *disp, ds_ddev_t *ddev)
|
|---|
| 891 | {
|
|---|
| 892 | errno_t rc;
|
|---|
| 893 | gfx_rect_t old_disp_rect;
|
|---|
| 894 |
|
|---|
| 895 | assert(ddev->display == NULL);
|
|---|
| 896 | assert(!link_used(&ddev->lddevs));
|
|---|
| 897 |
|
|---|
| 898 | old_disp_rect = disp->rect;
|
|---|
| 899 |
|
|---|
| 900 | ddev->display = disp;
|
|---|
| 901 | list_append(&ddev->lddevs, &disp->ddevs);
|
|---|
| 902 |
|
|---|
| 903 | /* First display device */
|
|---|
| 904 | if (gfx_rect_is_empty(&disp->rect)) {
|
|---|
| 905 | /* Set screen dimensions */
|
|---|
| 906 | disp->rect = ddev->info.rect;
|
|---|
| 907 |
|
|---|
| 908 | /* Create cloning GC */
|
|---|
| 909 | rc = ds_clonegc_create(ddev->gc, &disp->fbgc);
|
|---|
| 910 | if (rc != EOK)
|
|---|
| 911 | goto error;
|
|---|
| 912 |
|
|---|
| 913 | /* Allocate backbuffer */
|
|---|
| 914 | rc = ds_display_alloc_backbuf(disp);
|
|---|
| 915 | if (rc != EOK) {
|
|---|
| 916 | ds_clonegc_delete(disp->fbgc);
|
|---|
| 917 | disp->fbgc = NULL;
|
|---|
| 918 | goto error;
|
|---|
| 919 | }
|
|---|
| 920 | } else {
|
|---|
| 921 | /* Add new output device to cloning GC */
|
|---|
| 922 | rc = ds_clonegc_add_output(disp->fbgc, ddev->gc);
|
|---|
| 923 | if (rc != EOK)
|
|---|
| 924 | goto error;
|
|---|
| 925 | }
|
|---|
| 926 |
|
|---|
| 927 | ds_display_update_max_rect(disp);
|
|---|
| 928 |
|
|---|
| 929 | return EOK;
|
|---|
| 930 | error:
|
|---|
| 931 | disp->rect = old_disp_rect;
|
|---|
| 932 | list_remove(&ddev->lddevs);
|
|---|
| 933 | return rc;
|
|---|
| 934 | }
|
|---|
| 935 |
|
|---|
| 936 | /** Remove display device from display.
|
|---|
| 937 | *
|
|---|
| 938 | * @param ddev Display device
|
|---|
| 939 | */
|
|---|
| 940 | void ds_display_remove_ddev(ds_ddev_t *ddev)
|
|---|
| 941 | {
|
|---|
| 942 | list_remove(&ddev->lddevs);
|
|---|
| 943 | ddev->display = NULL;
|
|---|
| 944 | }
|
|---|
| 945 |
|
|---|
| 946 | /** Get first display device in display.
|
|---|
| 947 | *
|
|---|
| 948 | * @param disp Display
|
|---|
| 949 | * @return First display device or @c NULL if there is none
|
|---|
| 950 | */
|
|---|
| 951 | ds_ddev_t *ds_display_first_ddev(ds_display_t *disp)
|
|---|
| 952 | {
|
|---|
| 953 | link_t *link = list_first(&disp->ddevs);
|
|---|
| 954 |
|
|---|
| 955 | if (link == NULL)
|
|---|
| 956 | return NULL;
|
|---|
| 957 |
|
|---|
| 958 | return list_get_instance(link, ds_ddev_t, lddevs);
|
|---|
| 959 | }
|
|---|
| 960 |
|
|---|
| 961 | /** Get next display device in display.
|
|---|
| 962 | *
|
|---|
| 963 | * @param ddev Current display device
|
|---|
| 964 | * @return Next display device or @c NULL if there is none
|
|---|
| 965 | */
|
|---|
| 966 | ds_ddev_t *ds_display_next_ddev(ds_ddev_t *ddev)
|
|---|
| 967 | {
|
|---|
| 968 | link_t *link = list_next(&ddev->lddevs, &ddev->display->ddevs);
|
|---|
| 969 |
|
|---|
| 970 | if (link == NULL)
|
|---|
| 971 | return NULL;
|
|---|
| 972 |
|
|---|
| 973 | return list_get_instance(link, ds_ddev_t, lddevs);
|
|---|
| 974 | }
|
|---|
| 975 |
|
|---|
| 976 | /** Add input device configuration entry to display.
|
|---|
| 977 | *
|
|---|
| 978 | * @param disp Display
|
|---|
| 979 | * @param idevcfg Input device configuration
|
|---|
| 980 | */
|
|---|
| 981 | void ds_display_add_idevcfg(ds_display_t *disp, ds_idevcfg_t *idevcfg)
|
|---|
| 982 | {
|
|---|
| 983 | assert(idevcfg->display == NULL);
|
|---|
| 984 | assert(!link_used(&idevcfg->ldispidcfgs));
|
|---|
| 985 |
|
|---|
| 986 | idevcfg->display = disp;
|
|---|
| 987 | list_append(&idevcfg->ldispidcfgs, &disp->idevcfgs);
|
|---|
| 988 | }
|
|---|
| 989 |
|
|---|
| 990 | /** Remove input device configuration entry from display.
|
|---|
| 991 | *
|
|---|
| 992 | * @param idevcfg Input device configuration entry
|
|---|
| 993 | */
|
|---|
| 994 | void ds_display_remove_idevcfg(ds_idevcfg_t *idevcfg)
|
|---|
| 995 | {
|
|---|
| 996 | list_remove(&idevcfg->ldispidcfgs);
|
|---|
| 997 | idevcfg->display = NULL;
|
|---|
| 998 | }
|
|---|
| 999 |
|
|---|
| 1000 | /** Get first input device configuration entry in display.
|
|---|
| 1001 | *
|
|---|
| 1002 | * @param disp Display
|
|---|
| 1003 | * @return First input device configuration entry or @c NULL if there is none
|
|---|
| 1004 | */
|
|---|
| 1005 | ds_idevcfg_t *ds_display_first_idevcfg(ds_display_t *disp)
|
|---|
| 1006 | {
|
|---|
| 1007 | link_t *link = list_first(&disp->idevcfgs);
|
|---|
| 1008 |
|
|---|
| 1009 | if (link == NULL)
|
|---|
| 1010 | return NULL;
|
|---|
| 1011 |
|
|---|
| 1012 | return list_get_instance(link, ds_idevcfg_t, ldispidcfgs);
|
|---|
| 1013 | }
|
|---|
| 1014 |
|
|---|
| 1015 | /** Get next input device configuration entry in display.
|
|---|
| 1016 | *
|
|---|
| 1017 | * @param idevcfg Current input device configuration entry
|
|---|
| 1018 | * @return Next input device configuration entry or @c NULL if there is none
|
|---|
| 1019 | */
|
|---|
| 1020 | ds_idevcfg_t *ds_display_next_idevcfg(ds_idevcfg_t *idevcfg)
|
|---|
| 1021 | {
|
|---|
| 1022 | link_t *link = list_next(&idevcfg->ldispidcfgs, &idevcfg->display->idevcfgs);
|
|---|
| 1023 |
|
|---|
| 1024 | if (link == NULL)
|
|---|
| 1025 | return NULL;
|
|---|
| 1026 |
|
|---|
| 1027 | return list_get_instance(link, ds_idevcfg_t, ldispidcfgs);
|
|---|
| 1028 | }
|
|---|
| 1029 |
|
|---|
| 1030 | /** Add cursor to display.
|
|---|
| 1031 | *
|
|---|
| 1032 | * @param display Display
|
|---|
| 1033 | * @param cursor Cursor
|
|---|
| 1034 | */
|
|---|
| 1035 | void ds_display_add_cursor(ds_display_t *display, ds_cursor_t *cursor)
|
|---|
| 1036 | {
|
|---|
| 1037 | assert(cursor->display == NULL);
|
|---|
| 1038 | assert(!link_used(&cursor->ldisplay));
|
|---|
| 1039 |
|
|---|
| 1040 | cursor->display = display;
|
|---|
| 1041 | list_prepend(&cursor->ldisplay, &display->cursors);
|
|---|
| 1042 | }
|
|---|
| 1043 |
|
|---|
| 1044 | /** Remove cursor from display.
|
|---|
| 1045 | *
|
|---|
| 1046 | * @param cursor Cursor
|
|---|
| 1047 | */
|
|---|
| 1048 | void ds_display_remove_cursor(ds_cursor_t *cursor)
|
|---|
| 1049 | {
|
|---|
| 1050 | list_remove(&cursor->ldisplay);
|
|---|
| 1051 | cursor->display = NULL;
|
|---|
| 1052 | }
|
|---|
| 1053 |
|
|---|
| 1054 | /** Update display maximize rectangle.
|
|---|
| 1055 | *
|
|---|
| 1056 | * Recalculate the maximize rectangle (the rectangle used for maximized
|
|---|
| 1057 | * windows).
|
|---|
| 1058 | *
|
|---|
| 1059 | * @param display Display
|
|---|
| 1060 | */
|
|---|
| 1061 | void ds_display_update_max_rect(ds_display_t *display)
|
|---|
| 1062 | {
|
|---|
| 1063 | ds_window_t *wnd;
|
|---|
| 1064 | gfx_rect_t max_rect;
|
|---|
| 1065 | gfx_rect_t drect;
|
|---|
| 1066 |
|
|---|
| 1067 | /* Start with the entire display */
|
|---|
| 1068 | max_rect = display->rect;
|
|---|
| 1069 |
|
|---|
| 1070 | wnd = ds_display_first_window(display);
|
|---|
| 1071 | while (wnd != NULL) {
|
|---|
| 1072 | /* Should maximized windows avoid this window? */
|
|---|
| 1073 | if ((wnd->flags & wndf_avoid) != 0) {
|
|---|
| 1074 | /* Window bounding rectangle on display */
|
|---|
| 1075 | gfx_rect_translate(&wnd->dpos, &wnd->rect, &drect);
|
|---|
| 1076 |
|
|---|
| 1077 | /* Crop maximized rectangle */
|
|---|
| 1078 | ds_display_crop_max_rect(&drect, &max_rect);
|
|---|
| 1079 | }
|
|---|
| 1080 |
|
|---|
| 1081 | wnd = ds_display_next_window(wnd);
|
|---|
| 1082 | }
|
|---|
| 1083 |
|
|---|
| 1084 | /* Update the maximize rectangle */
|
|---|
| 1085 | display->max_rect = max_rect;
|
|---|
| 1086 | }
|
|---|
| 1087 |
|
|---|
| 1088 | /** Crop maximize rectangle.
|
|---|
| 1089 | *
|
|---|
| 1090 | * Use the avoid rectangle @a arect to crop off maximization rectangle
|
|---|
| 1091 | * @a mrect. If @a arect covers the top, bottom, left or right part
|
|---|
| 1092 | * of @a mrect, it will be cropped off. Otherwise there will be
|
|---|
| 1093 | * no effect.
|
|---|
| 1094 | *
|
|---|
| 1095 | * @param arect Avoid rectangle
|
|---|
| 1096 | * @param mrect Maximize rectangle to be modified
|
|---|
| 1097 | */
|
|---|
| 1098 | void ds_display_crop_max_rect(gfx_rect_t *arect, gfx_rect_t *mrect)
|
|---|
| 1099 | {
|
|---|
| 1100 | if (arect->p0.x == mrect->p0.x && arect->p0.y == mrect->p0.y &&
|
|---|
| 1101 | arect->p1.x == mrect->p1.x) {
|
|---|
| 1102 | /* Cropp off top part */
|
|---|
| 1103 | mrect->p0.y = arect->p1.y;
|
|---|
| 1104 | } else if (arect->p0.x == mrect->p0.x && arect->p1.x == mrect->p1.x &&
|
|---|
| 1105 | arect->p1.y == mrect->p1.y) {
|
|---|
| 1106 | /* Cropp off bottom part */
|
|---|
| 1107 | mrect->p1.y = arect->p0.y;
|
|---|
| 1108 | } else if (arect->p0.x == mrect->p0.x && arect->p0.y == mrect->p0.y &&
|
|---|
| 1109 | arect->p1.y == mrect->p1.y) {
|
|---|
| 1110 | /* Cropp off left part */
|
|---|
| 1111 | mrect->p0.x = arect->p1.x;
|
|---|
| 1112 | } else if (arect->p0.y == mrect->p0.y && arect->p1.x == mrect->p1.x &&
|
|---|
| 1113 | arect->p1.y == mrect->p1.y) {
|
|---|
| 1114 | /* Cropp off right part */
|
|---|
| 1115 | mrect->p1.x = arect->p0.x;
|
|---|
| 1116 | }
|
|---|
| 1117 | }
|
|---|
| 1118 |
|
|---|
| 1119 | /** Get unbuffered GC.
|
|---|
| 1120 | *
|
|---|
| 1121 | * Get the display's (unbuffered) graphic context. If the display
|
|---|
| 1122 | * is double-buffered, this returns GC of the front buffer. If the display
|
|---|
| 1123 | * is unbuffered, this is the same as @c ds_display_get_gc().
|
|---|
| 1124 | *
|
|---|
| 1125 | * @param display Display
|
|---|
| 1126 | * @return Unbuffered GC
|
|---|
| 1127 | */
|
|---|
| 1128 | static gfx_context_t *ds_display_get_unbuf_gc(ds_display_t *display)
|
|---|
| 1129 | {
|
|---|
| 1130 | /* In case of unit tests */
|
|---|
| 1131 | if (display->fbgc == NULL)
|
|---|
| 1132 | return NULL;
|
|---|
| 1133 |
|
|---|
| 1134 | return ds_clonegc_get_ctx(display->fbgc);
|
|---|
| 1135 | }
|
|---|
| 1136 |
|
|---|
| 1137 | /** Get display GC.
|
|---|
| 1138 | *
|
|---|
| 1139 | * Get the graphic context used to paint the display. This is to be used
|
|---|
| 1140 | * for all display server paint operations.
|
|---|
| 1141 | *
|
|---|
| 1142 | * @param display Display
|
|---|
| 1143 | * @return Graphic context for painting to the display
|
|---|
| 1144 | */
|
|---|
| 1145 | gfx_context_t *ds_display_get_gc(ds_display_t *display)
|
|---|
| 1146 | {
|
|---|
| 1147 | if ((display->flags & df_disp_double_buf) != 0)
|
|---|
| 1148 | return mem_gc_get_ctx(display->bbgc);
|
|---|
| 1149 | else
|
|---|
| 1150 | return ds_display_get_unbuf_gc(display);
|
|---|
| 1151 | }
|
|---|
| 1152 |
|
|---|
| 1153 | /** Paint display background.
|
|---|
| 1154 | *
|
|---|
| 1155 | * @param display Display
|
|---|
| 1156 | * @param rect Bounding rectangle or @c NULL to repaint entire display
|
|---|
| 1157 | */
|
|---|
| 1158 | errno_t ds_display_paint_bg(ds_display_t *disp, gfx_rect_t *rect)
|
|---|
| 1159 | {
|
|---|
| 1160 | gfx_rect_t crect;
|
|---|
| 1161 | gfx_context_t *gc;
|
|---|
| 1162 | errno_t rc;
|
|---|
| 1163 |
|
|---|
| 1164 | if (rect != NULL)
|
|---|
| 1165 | gfx_rect_clip(&disp->rect, rect, &crect);
|
|---|
| 1166 | else
|
|---|
| 1167 | crect = disp->rect;
|
|---|
| 1168 |
|
|---|
| 1169 | gc = ds_display_get_gc(disp);
|
|---|
| 1170 | if (gc == NULL)
|
|---|
| 1171 | return EOK;
|
|---|
| 1172 |
|
|---|
| 1173 | rc = gfx_set_color(gc, disp->bg_color);
|
|---|
| 1174 | if (rc != EOK)
|
|---|
| 1175 | return rc;
|
|---|
| 1176 |
|
|---|
| 1177 | return gfx_fill_rect(gc, &crect);
|
|---|
| 1178 | }
|
|---|
| 1179 |
|
|---|
| 1180 | /** Update front buffer from back buffer.
|
|---|
| 1181 | *
|
|---|
| 1182 | * If the display is not double-buffered, no action is taken.
|
|---|
| 1183 | *
|
|---|
| 1184 | * @param disp Display
|
|---|
| 1185 | * @return EOK on success, or an error code
|
|---|
| 1186 | */
|
|---|
| 1187 | static errno_t ds_display_update(ds_display_t *disp)
|
|---|
| 1188 | {
|
|---|
| 1189 | errno_t rc;
|
|---|
| 1190 |
|
|---|
| 1191 | if (disp->backbuf == NULL) {
|
|---|
| 1192 | /* Not double-buffered, nothing to do. */
|
|---|
| 1193 | return EOK;
|
|---|
| 1194 | }
|
|---|
| 1195 |
|
|---|
| 1196 | rc = gfx_bitmap_render(disp->backbuf, &disp->dirty_rect, NULL);
|
|---|
| 1197 | if (rc != EOK)
|
|---|
| 1198 | return rc;
|
|---|
| 1199 |
|
|---|
| 1200 | disp->dirty_rect.p0.x = 0;
|
|---|
| 1201 | disp->dirty_rect.p0.y = 0;
|
|---|
| 1202 | disp->dirty_rect.p1.x = 0;
|
|---|
| 1203 | disp->dirty_rect.p1.y = 0;
|
|---|
| 1204 |
|
|---|
| 1205 | return EOK;
|
|---|
| 1206 | }
|
|---|
| 1207 |
|
|---|
| 1208 | /** Paint display.
|
|---|
| 1209 | *
|
|---|
| 1210 | * @param display Display
|
|---|
| 1211 | * @param rect Bounding rectangle or @c NULL to repaint entire display
|
|---|
| 1212 | */
|
|---|
| 1213 | errno_t ds_display_paint(ds_display_t *disp, gfx_rect_t *rect)
|
|---|
| 1214 | {
|
|---|
| 1215 | errno_t rc;
|
|---|
| 1216 | ds_window_t *wnd;
|
|---|
| 1217 | ds_seat_t *seat;
|
|---|
| 1218 |
|
|---|
| 1219 | /* Paint background */
|
|---|
| 1220 | rc = ds_display_paint_bg(disp, rect);
|
|---|
| 1221 | if (rc != EOK)
|
|---|
| 1222 | return rc;
|
|---|
| 1223 |
|
|---|
| 1224 | /* Paint windows bottom to top */
|
|---|
| 1225 | wnd = ds_display_last_window(disp);
|
|---|
| 1226 | while (wnd != NULL) {
|
|---|
| 1227 | rc = ds_window_paint(wnd, rect);
|
|---|
| 1228 | if (rc != EOK)
|
|---|
| 1229 | return rc;
|
|---|
| 1230 |
|
|---|
| 1231 | wnd = ds_display_prev_window(wnd);
|
|---|
| 1232 | }
|
|---|
| 1233 |
|
|---|
| 1234 | /* Paint window previews for windows being resized or moved */
|
|---|
| 1235 | wnd = ds_display_last_window(disp);
|
|---|
| 1236 | while (wnd != NULL) {
|
|---|
| 1237 | rc = ds_window_paint_preview(wnd, rect);
|
|---|
| 1238 | if (rc != EOK)
|
|---|
| 1239 | return rc;
|
|---|
| 1240 |
|
|---|
| 1241 | wnd = ds_display_prev_window(wnd);
|
|---|
| 1242 | }
|
|---|
| 1243 |
|
|---|
| 1244 | /* Paint pointers */
|
|---|
| 1245 | seat = ds_display_first_seat(disp);
|
|---|
| 1246 | while (seat != NULL) {
|
|---|
| 1247 | rc = ds_seat_paint_pointer(seat, rect);
|
|---|
| 1248 | if (rc != EOK)
|
|---|
| 1249 | return rc;
|
|---|
| 1250 |
|
|---|
| 1251 | seat = ds_display_next_seat(seat);
|
|---|
| 1252 | }
|
|---|
| 1253 |
|
|---|
| 1254 | return ds_display_update(disp);
|
|---|
| 1255 | }
|
|---|
| 1256 |
|
|---|
| 1257 | /** Display invalidate callback.
|
|---|
| 1258 | *
|
|---|
| 1259 | * Called by backbuffer memory GC when something is rendered into it.
|
|---|
| 1260 | * Updates the display's dirty rectangle.
|
|---|
| 1261 | *
|
|---|
| 1262 | * @param arg Argument (display cast as void *)
|
|---|
| 1263 | * @param rect Rectangle to update
|
|---|
| 1264 | */
|
|---|
| 1265 | static void ds_display_invalidate_cb(void *arg, gfx_rect_t *rect)
|
|---|
| 1266 | {
|
|---|
| 1267 | ds_display_t *disp = (ds_display_t *) arg;
|
|---|
| 1268 | gfx_rect_t env;
|
|---|
| 1269 |
|
|---|
| 1270 | gfx_rect_envelope(&disp->dirty_rect, rect, &env);
|
|---|
| 1271 | disp->dirty_rect = env;
|
|---|
| 1272 | }
|
|---|
| 1273 |
|
|---|
| 1274 | /** Display update callback.
|
|---|
| 1275 | *
|
|---|
| 1276 | * @param arg Argument (display cast as void *)
|
|---|
| 1277 | */
|
|---|
| 1278 | static void ds_display_update_cb(void *arg)
|
|---|
| 1279 | {
|
|---|
| 1280 | ds_display_t *disp = (ds_display_t *) arg;
|
|---|
| 1281 |
|
|---|
| 1282 | (void) disp;
|
|---|
| 1283 | }
|
|---|
| 1284 |
|
|---|
| 1285 | /** @}
|
|---|
| 1286 | */
|
|---|