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