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