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