2 * Copyright (c) 2024 Jiri Svoboda
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
36 #include <congfx/console.h>
39 #include <gfx/bitmap.h>
40 #include <gfx/context.h>
41 #include <gfx/cursor.h>
42 #include <gfx/render.h>
43 #include <io/kbd_event.h>
44 #include <io/pos_event.h>
46 #include <memgfx/memgc.h>
48 #include <ui/control.h>
49 #include <ui/menubar.h>
51 #include <ui/menuentry.h>
52 #include <ui/resource.h>
54 #include <ui/wdecor.h>
55 #include <ui/window.h>
56 #include "../private/control.h"
57 #include "../private/dummygc.h"
58 #include "../private/resource.h"
59 #include "../private/ui.h"
60 #include "../private/wdecor.h"
61 #include "../private/window.h"
63 static void dwnd_close_event(void *);
64 static void dwnd_focus_event(void *, unsigned);
65 static void dwnd_kbd_event(void *, kbd_event_t
*);
66 static void dwnd_pos_event(void *, pos_event_t
*);
67 static void dwnd_resize_event(void *, gfx_rect_t
*);
68 static void dwnd_unfocus_event(void *, unsigned);
70 static display_wnd_cb_t dwnd_cb
= {
71 .close_event
= dwnd_close_event
,
72 .focus_event
= dwnd_focus_event
,
73 .kbd_event
= dwnd_kbd_event
,
74 .pos_event
= dwnd_pos_event
,
75 .resize_event
= dwnd_resize_event
,
76 .unfocus_event
= dwnd_unfocus_event
79 static void wd_sysmenu_open(ui_wdecor_t
*, void *, sysarg_t
);
80 static void wd_sysmenu_left(ui_wdecor_t
*, void *, sysarg_t
);
81 static void wd_sysmenu_right(ui_wdecor_t
*, void *, sysarg_t
);
82 static void wd_sysmenu_accel(ui_wdecor_t
*, void *, char32_t
, sysarg_t
);
83 static void wd_minimize(ui_wdecor_t
*, void *);
84 static void wd_maximize(ui_wdecor_t
*, void *);
85 static void wd_unmaximize(ui_wdecor_t
*, void *);
86 static void wd_close(ui_wdecor_t
*, void *);
87 static void wd_move(ui_wdecor_t
*, void *, gfx_coord2_t
*, sysarg_t
);
88 static void wd_resize(ui_wdecor_t
*, void *, ui_wdecor_rsztype_t
,
89 gfx_coord2_t
*, sysarg_t
);
90 static void wd_set_cursor(ui_wdecor_t
*, void *, ui_stock_cursor_t
);
92 static ui_wdecor_cb_t wdecor_cb
= {
93 .sysmenu_open
= wd_sysmenu_open
,
94 .sysmenu_left
= wd_sysmenu_left
,
95 .sysmenu_right
= wd_sysmenu_right
,
96 .sysmenu_accel
= wd_sysmenu_accel
,
97 .minimize
= wd_minimize
,
98 .maximize
= wd_maximize
,
99 .unmaximize
= wd_unmaximize
,
103 .set_cursor
= wd_set_cursor
106 static void wnd_sysmenu_left(ui_menu_t
*, void *, sysarg_t
);
107 static void wnd_sysmenu_right(ui_menu_t
*, void *, sysarg_t
);
108 static void wnd_sysmenu_close_req(ui_menu_t
*, void *);
109 static void wnd_sysmenu_press_accel(ui_menu_t
*, void *, char32_t
, sysarg_t
);
111 static ui_menu_cb_t wnd_sysmenu_cb
= {
112 .left
= wnd_sysmenu_left
,
113 .right
= wnd_sysmenu_right
,
114 .close_req
= wnd_sysmenu_close_req
,
115 .press_accel
= wnd_sysmenu_press_accel
118 static void wnd_sysmenu_erestore(ui_menu_entry_t
*, void *);
119 static void wnd_sysmenu_eminimize(ui_menu_entry_t
*, void *);
120 static void wnd_sysmenu_emaximize(ui_menu_entry_t
*, void *);
121 static void wnd_sysmenu_eclose(ui_menu_entry_t
*, void *);
123 static void ui_window_invalidate(void *, gfx_rect_t
*);
124 static void ui_window_update(void *);
125 static errno_t
ui_window_cursor_get_pos(void *, gfx_coord2_t
*);
126 static errno_t
ui_window_cursor_set_pos(void *, gfx_coord2_t
*);
127 static errno_t
ui_window_cursor_set_visible(void *, bool);
129 /** Window memory GC callbacks */
130 static mem_gc_cb_t ui_window_mem_gc_cb
= {
131 .invalidate
= ui_window_invalidate
,
132 .update
= ui_window_update
,
133 .cursor_get_pos
= ui_window_cursor_get_pos
,
134 .cursor_set_pos
= ui_window_cursor_set_pos
,
135 .cursor_set_visible
= ui_window_cursor_set_visible
138 static void ui_window_app_invalidate(void *, gfx_rect_t
*);
139 static void ui_window_app_update(void *);
141 /** Application area memory GC callbacks */
142 static mem_gc_cb_t ui_window_app_mem_gc_cb
= {
143 .invalidate
= ui_window_app_invalidate
,
144 .update
= ui_window_app_update
147 static void ui_window_expose_cb(void *);
149 /** Initialize window parameters structure.
151 * Window parameters structure must always be initialized using this function
152 * first. By default, the window will be decorated. To get a non-decorated
153 * window, one needs to clear ui_wds_decorated
154 * (e.g. params->style &= ~ui_wds_decorated).
156 * @param params Window parameters structure
158 void ui_wnd_params_init(ui_wnd_params_t
*params
)
160 memset(params
, 0, sizeof(ui_wnd_params_t
));
162 /* Make window decorated by default. */
163 params
->style
= ui_wds_decorated
;
166 /** Compute where window should be placed on the screen.
168 * This only applies to windows that do not use default placement or
169 * if we are running in full-screen mode.
171 * @param window Window
172 * @param drect Display rectangle
173 * @param params Window parameters
174 * @param pos Place to store position of top-left corner
176 static void ui_window_place(ui_window_t
*window
, gfx_rect_t
*drect
,
177 ui_wnd_params_t
*params
, gfx_coord2_t
*pos
)
180 gfx_coord2_t below_pos
;
181 gfx_rect_t below_rect
;
183 assert(params
->placement
!= ui_wnd_place_default
||
184 ui_is_fullscreen(window
->ui
));
189 switch (params
->placement
) {
190 case ui_wnd_place_default
:
191 case ui_wnd_place_center
:
192 assert(params
->placement
!= ui_wnd_place_default
||
193 ui_is_fullscreen(window
->ui
));
195 gfx_rect_dims(¶ms
->rect
, &dims
);
196 pos
->x
= (drect
->p0
.x
+ drect
->p1
.x
) / 2 - dims
.x
/ 2;
197 pos
->y
= (drect
->p0
.y
+ drect
->p1
.y
) / 2 - dims
.y
/ 2;
199 case ui_wnd_place_top_left
:
200 case ui_wnd_place_full_screen
:
201 pos
->x
= drect
->p0
.x
- params
->rect
.p0
.x
;
202 pos
->y
= drect
->p0
.y
- params
->rect
.p0
.y
;
204 case ui_wnd_place_top_right
:
205 pos
->x
= drect
->p1
.x
- params
->rect
.p1
.x
;
206 pos
->y
= drect
->p0
.y
- params
->rect
.p0
.y
;
208 case ui_wnd_place_bottom_left
:
209 pos
->x
= drect
->p0
.x
- params
->rect
.p0
.x
;
210 pos
->y
= drect
->p1
.y
- params
->rect
.p1
.y
;
212 case ui_wnd_place_bottom_right
:
213 pos
->x
= drect
->p1
.x
- params
->rect
.p1
.x
;
214 pos
->y
= drect
->p1
.y
- params
->rect
.p1
.y
;
216 case ui_wnd_place_popup
:
217 /* Compute rectangle when placed below */
218 below_pos
.x
= params
->prect
.p0
.x
;
219 below_pos
.y
= params
->prect
.p1
.y
;
220 gfx_rect_translate(&below_pos
, ¶ms
->rect
, &below_rect
);
222 /* Does below_rect fit within the display? */
223 if (gfx_rect_is_inside(&below_rect
, drect
)) {
224 /* Place popup window below parent rectangle */
225 pos
->x
= params
->prect
.p0
.x
- params
->rect
.p0
.x
;
226 pos
->y
= params
->prect
.p1
.y
- params
->rect
.p0
.y
;
228 /* Place popup window above parent rectangle */
229 pos
->x
= params
->prect
.p0
.x
;
230 pos
->y
= params
->prect
.p0
.y
-
231 (params
->rect
.p1
.y
- params
->rect
.p0
.y
);
237 /** Create window's system menu.
239 * @param window Window
240 * @return EOK on success or an error code
242 static errno_t
ui_window_sysmenu_create(ui_window_t
*window
)
245 ui_menu_entry_t
*mrestore
;
246 ui_menu_entry_t
*mmin
;
247 ui_menu_entry_t
*mmax
;
248 ui_menu_entry_t
*msep
;
249 ui_menu_entry_t
*mclose
;
251 rc
= ui_menu_create(window
, &window
->sysmenu
);
255 ui_menu_set_cb(window
->sysmenu
, &wnd_sysmenu_cb
, (void *)window
);
257 rc
= ui_menu_entry_create(window
->sysmenu
, "~R~estore",
262 if (!window
->wdecor
->maximized
)
263 ui_menu_entry_set_disabled(mrestore
, true);
265 ui_menu_entry_set_cb(mrestore
, wnd_sysmenu_erestore
, (void *)window
);
267 rc
= ui_menu_entry_create(window
->sysmenu
, "Mi~n~imize",
272 if ((window
->wdecor
->style
& ui_wds_minimize_btn
) == 0)
273 ui_menu_entry_set_disabled(mmin
, true);
275 ui_menu_entry_set_cb(mmin
, wnd_sysmenu_eminimize
, (void *)window
);
277 rc
= ui_menu_entry_create(window
->sysmenu
, "Ma~x~imize",
282 if ((window
->wdecor
->style
& ui_wds_maximize_btn
) == 0 ||
283 window
->wdecor
->maximized
)
284 ui_menu_entry_set_disabled(mmax
, true);
286 ui_menu_entry_set_cb(mmax
, wnd_sysmenu_emaximize
, (void *)window
);
288 rc
= ui_menu_entry_sep_create(window
->sysmenu
, &msep
);
292 rc
= ui_menu_entry_create(window
->sysmenu
, "~C~lose", "Alt-F4",
297 if ((window
->wdecor
->style
& ui_wds_close_btn
) == 0)
298 ui_menu_entry_set_disabled(mclose
, true);
300 ui_menu_entry_set_cb(mclose
, wnd_sysmenu_eclose
, (void *)window
);
302 window
->sysmenu_restore
= mrestore
;
303 window
->sysmenu_minimize
= mmin
;
304 window
->sysmenu_maximize
= mmax
;
311 /** Create new window.
313 * @param ui User interface
314 * @param params Window parameters
315 * @param rwindow Place to store pointer to new window
316 * @return EOK on success or an error code
318 errno_t
ui_window_create(ui_t
*ui
, ui_wnd_params_t
*params
,
319 ui_window_t
**rwindow
)
322 ui_window_t
*pwindow
= NULL
;
324 gfx_coord2_t scr_dims
;
325 display_wnd_params_t dparams
;
326 gfx_context_t
*gc
= NULL
;
327 ui_resource_t
*res
= NULL
;
328 ui_wdecor_t
*wdecor
= NULL
;
329 dummy_gc_t
*dgc
= NULL
;
330 gfx_bitmap_params_t bparams
;
331 gfx_bitmap_alloc_t alloc
;
332 gfx_bitmap_t
*bmp
= NULL
;
334 mem_gc_t
*memgc
= NULL
;
335 xlate_gc_t
*xgc
= NULL
;
338 window
= calloc(1, sizeof(ui_window_t
));
344 display_wnd_params_init(&dparams
);
345 dparams
.rect
= params
->rect
;
346 dparams
.caption
= params
->caption
;
347 dparams
.min_size
= params
->min_size
;
350 * If idev_id is not specified, use the UI default (probably
351 * obtained from display specification. This creates the
352 * main window in the seat specified on the command line.
354 if (params
->idev_id
!= 0)
355 dparams
.idev_id
= params
->idev_id
;
357 dparams
.idev_id
= ui
->idev_id
;
359 if ((params
->flags
& ui_wndf_popup
) != 0)
360 dparams
.flags
|= wndf_popup
;
361 if ((params
->flags
& ui_wndf_nofocus
) != 0)
362 dparams
.flags
|= wndf_nofocus
;
363 if ((params
->flags
& ui_wndf_topmost
) != 0)
364 dparams
.flags
|= wndf_topmost
;
365 if ((params
->flags
& ui_wndf_system
) != 0)
366 dparams
.flags
|= wndf_system
;
367 if ((params
->flags
& ui_wndf_avoid
) != 0)
368 dparams
.flags
|= wndf_avoid
;
370 if (ui
->display
!= NULL
) {
371 if (params
->placement
!= ui_wnd_place_default
) {
372 rc
= display_get_info(ui
->display
, &info
);
377 if (params
->placement
== ui_wnd_place_full_screen
) {
378 /* Make window the size of the screen */
379 gfx_rect_dims(&info
.rect
, &scr_dims
);
380 gfx_coord2_add(&dparams
.rect
.p0
, &scr_dims
,
384 if (params
->placement
!= ui_wnd_place_default
) {
385 /* Set initial display window position */
386 ui_window_place(window
, &info
.rect
, params
,
389 dparams
.flags
|= wndf_setpos
;
392 rc
= display_window_create(ui
->display
, &dparams
, &dwnd_cb
,
393 (void *) window
, &window
->dwindow
);
397 rc
= display_window_get_gc(window
->dwindow
, &gc
);
400 } else if (ui
->console
!= NULL
) {
401 gc
= console_gc_get_ctx(ui
->cgc
);
403 if (params
->placement
== ui_wnd_place_full_screen
) {
404 /* Make window the size of the screen */
405 gfx_rect_dims(&ui
->rect
, &scr_dims
);
406 gfx_coord2_add(&dparams
.rect
.p0
, &scr_dims
,
408 (void) console_set_caption(ui
->console
,
412 /* Needed for unit tests */
413 rc
= dummygc_create(&dgc
);
417 gc
= dummygc_get_ctx(dgc
);
420 #ifdef CONFIG_UI_CS_RENDER
421 /* Create window bitmap */
422 gfx_bitmap_params_init(&bparams
);
423 #ifndef CONFIG_WIN_DOUBLE_BUF
424 /* Console does not support direct output */
425 if (ui
->display
!= NULL
)
426 bparams
.flags
|= bmpf_direct_output
;
429 /* Move rectangle so that top-left corner is 0,0 */
430 gfx_rect_rtranslate(&dparams
.rect
.p0
, &dparams
.rect
, &bparams
.rect
);
432 rc
= gfx_bitmap_create(gc
, &bparams
, NULL
, &bmp
);
436 /* Create memory GC */
437 rc
= gfx_bitmap_get_alloc(bmp
, &alloc
);
439 gfx_bitmap_destroy(window
->app_bmp
);
443 rc
= mem_gc_create(&bparams
.rect
, &alloc
, &ui_window_mem_gc_cb
,
444 (void *) window
, &memgc
);
446 gfx_bitmap_destroy(window
->app_bmp
);
452 window
->gc
= mem_gc_get_ctx(memgc
);
456 /* Server-side rendering */
458 /* Full-screen mode? */
459 if (ui
->display
== NULL
) {
460 /* Create translating GC to translate window contents */
463 rc
= xlate_gc_create(&off
, gc
, &xgc
);
468 window
->gc
= xlate_gc_get_ctx(xgc
);
474 (void) ui_window_mem_gc_cb
;
478 if (ui
->display
== NULL
) {
479 ui_window_place(window
, &ui
->rect
, params
, &window
->dpos
);
481 if (window
->xgc
!= NULL
)
482 xlate_gc_set_off(window
->xgc
, &window
->dpos
);
485 rc
= ui_resource_create(window
->gc
, ui_is_textmode(ui
), &res
);
489 rc
= ui_wdecor_create(res
, params
->caption
, params
->style
, &wdecor
);
493 ui_wdecor_set_rect(wdecor
, &dparams
.rect
);
494 ui_wdecor_set_cb(wdecor
, &wdecor_cb
, (void *) window
);
495 ui_wdecor_paint(wdecor
);
497 ui_resource_set_expose_cb(res
, ui_window_expose_cb
, (void *) window
);
499 window
->rect
= dparams
.rect
;
501 window
->wdecor
= wdecor
;
502 window
->cursor
= ui_curs_arrow
;
503 window
->placement
= params
->placement
;
505 rc
= ui_window_sysmenu_create(window
);
511 if (ui_is_fullscreen(ui
))
512 pwindow
= ui_window_get_active(ui
);
514 list_append(&window
->lwindows
, &ui
->windows
);
516 if (ui_is_fullscreen(ui
)) {
517 /* Send unfocus event to previously active window */
519 ui_window_send_unfocus(pwindow
, 0);
525 ui_wdecor_destroy(wdecor
);
527 ui_resource_destroy(res
);
529 mem_gc_delete(memgc
);
531 xlate_gc_delete(xgc
);
533 gfx_bitmap_destroy(bmp
);
535 dummygc_destroy(dgc
);
542 * @param window Window or @c NULL
544 void ui_window_destroy(ui_window_t
*window
)
547 ui_window_t
*nwindow
;
554 list_remove(&window
->lwindows
);
555 ui_control_destroy(window
->control
);
556 ui_menu_destroy(window
->sysmenu
);
557 ui_wdecor_destroy(window
->wdecor
);
558 ui_resource_destroy(window
->res
);
559 if (window
->app_mgc
!= NULL
)
560 mem_gc_delete(window
->app_mgc
);
561 if (window
->app_bmp
!= NULL
)
562 gfx_bitmap_destroy(window
->app_bmp
);
563 if (window
->mgc
!= NULL
) {
564 mem_gc_delete(window
->mgc
);
567 if (window
->bmp
!= NULL
)
568 gfx_bitmap_destroy(window
->bmp
);
569 if (window
->dwindow
!= NULL
)
570 display_window_destroy(window
->dwindow
);
572 /* Need to repaint if windows are emulated */
573 if (ui_is_fullscreen(ui
)) {
575 /* Send focus event to newly active window */
576 nwindow
= ui_window_get_active(ui
);
578 ui_window_send_focus(nwindow
, 0);
581 if (ui
->console
!= NULL
&&
582 window
->placement
== ui_wnd_place_full_screen
) {
583 (void) console_set_caption(ui
->console
, "");
589 /** Add control to window.
591 * Only one control can be added to a window. If more than one control
592 * is added, the results are undefined.
594 * @param window Window
595 * @param control Control
597 void ui_window_add(ui_window_t
*window
, ui_control_t
*control
)
599 assert(window
->control
== NULL
);
601 window
->control
= control
;
602 control
->elemp
= (void *) window
;
605 /** Remove control from window.
607 * @param window Window
608 * @param control Control
610 void ui_window_remove(ui_window_t
*window
, ui_control_t
*control
)
612 assert(window
->control
== control
);
613 assert((ui_window_t
*) control
->elemp
== window
);
615 window
->control
= NULL
;
616 control
->elemp
= NULL
;
619 /** Get active window (only valid in fullscreen mode).
621 * @param ui User interface
622 * @return Active window
624 ui_window_t
*ui_window_get_active(ui_t
*ui
)
628 link
= list_last(&ui
->windows
);
632 return list_get_instance(link
, ui_window_t
, lwindows
);
635 /** Resize or (un)maximize window.
637 * @param window Window
638 * @param rect Rectangle
639 * @param scop Size change operation
641 * @return EOK on success or an error code
643 errno_t
ui_window_size_change(ui_window_t
*window
, gfx_rect_t
*rect
,
649 gfx_bitmap_t
*app_bmp
= NULL
;
650 gfx_bitmap_t
*win_bmp
= NULL
;
651 gfx_bitmap_params_t app_params
;
652 gfx_bitmap_params_t win_params
;
653 gfx_bitmap_alloc_t app_alloc
;
654 gfx_bitmap_alloc_t win_alloc
;
658 * Move rect so that p0=0,0 - keep window's coordinate system origin
659 * locked to top-left corner of the window.
662 gfx_rect_rtranslate(&offs
, rect
, &nrect
);
664 /* mgc != NULL iff client-side rendering */
665 if (window
->mgc
!= NULL
) {
666 #ifdef CONFIG_WIN_DOUBLE_BUF
668 * Create new window bitmap in advance. If direct mapping,
669 * will need do it after resizing the window.
671 assert(window
->bmp
!= NULL
);
672 gfx_bitmap_params_init(&win_params
);
673 win_params
.rect
= nrect
;
675 rc
= gfx_bitmap_create(window
->realgc
, &win_params
, NULL
,
680 rc
= gfx_bitmap_get_alloc(win_bmp
, &win_alloc
);
686 /* Application area GC? */
687 if (window
->app_gc
!= NULL
) {
688 /* Resize application bitmap */
689 assert(window
->app_bmp
!= NULL
);
691 gfx_bitmap_params_init(&app_params
);
694 * The bitmap will have the same dimensions as the
695 * application rectangle, but start at 0,0.
697 ui_wdecor_app_from_rect(window
->wdecor
->style
, &nrect
, &arect
);
698 gfx_rect_rtranslate(&arect
.p0
, &arect
, &app_params
.rect
);
700 rc
= gfx_bitmap_create(window
->gc
, &app_params
, NULL
,
705 rc
= gfx_bitmap_get_alloc(app_bmp
, &app_alloc
);
710 /* dwindow can be NULL in case of unit tests or fullscreen mode */
711 if (window
->dwindow
!= NULL
) {
714 rc
= display_window_resize(window
->dwindow
, &offs
,
719 case ui_wsc_maximize
:
720 rc
= display_window_maximize(window
->dwindow
);
724 case ui_wsc_unmaximize
:
725 rc
= display_window_unmaximize(window
->dwindow
);
732 /* Client side rendering? */
733 if (window
->mgc
!= NULL
) {
734 #ifndef CONFIG_WIN_DOUBLE_BUF
735 /* Window is resized, now we can map the window bitmap again */
736 gfx_bitmap_params_init(&win_params
);
737 win_params
.flags
|= bmpf_direct_output
;
738 win_params
.rect
= nrect
;
740 rc
= gfx_bitmap_create(window
->realgc
, &win_params
, NULL
,
745 rc
= gfx_bitmap_get_alloc(win_bmp
, &win_alloc
);
749 mem_gc_retarget(window
->mgc
, &win_params
.rect
, &win_alloc
);
751 gfx_bitmap_destroy(window
->bmp
);
752 window
->bmp
= win_bmp
;
755 window
->rect
= nrect
;
756 ui_wdecor_set_rect(window
->wdecor
, &nrect
);
757 ui_wdecor_paint(window
->wdecor
);
758 gfx_update(window
->gc
);
760 /* Application area GC? */
761 if (window
->app_gc
!= NULL
) {
762 mem_gc_retarget(window
->app_mgc
, &app_params
.rect
, &app_alloc
);
764 gfx_bitmap_destroy(window
->app_bmp
);
765 window
->app_bmp
= app_bmp
;
771 gfx_bitmap_destroy(app_bmp
);
773 gfx_bitmap_destroy(win_bmp
);
777 /** Resize/move window.
779 * Resize window to the dimensions of @a rect. If @a rect.p0 is not 0,0,
780 * the top-left corner of the window will move on the screen accordingly.
782 * @param window Window
783 * @param rect Rectangle
785 * @return EOK on success or an error code
787 errno_t
ui_window_resize(ui_window_t
*window
, gfx_rect_t
*rect
)
789 return ui_window_size_change(window
, rect
, ui_wsc_resize
);
792 /** Set window callbacks.
794 * @param window Window
795 * @param cb Window callbacks
796 * @param arg Callback argument
798 void ui_window_set_cb(ui_window_t
*window
, ui_window_cb_t
*cb
, void *arg
)
804 /** Change window caption.
806 * @param window Window
807 * @param caption New caption
809 * @return EOK on success or an error code
811 errno_t
ui_window_set_caption(ui_window_t
*window
, const char *caption
)
815 /* Set console caption if fullscreen window on console */
816 if (window
->ui
->console
!= NULL
&& window
->placement
==
817 ui_wnd_place_full_screen
) {
818 rc
= console_set_caption(window
->ui
->console
, caption
);
823 /* Set display window caption if running on display service */
824 if (window
->dwindow
!= NULL
) {
825 rc
= display_window_set_caption(window
->dwindow
, caption
);
830 return ui_wdecor_set_caption(window
->wdecor
, caption
);
833 /** Get window's containing UI.
835 * @param window Window
836 * @return Containing UI
838 ui_t
*ui_window_get_ui(ui_window_t
*window
)
843 /** Get UI resource from window.
845 * @param window Window
846 * @return UI resource
848 ui_resource_t
*ui_window_get_res(ui_window_t
*window
)
855 * @param window Window
856 * @return GC (relative to window)
858 gfx_context_t
*ui_window_get_gc(ui_window_t
*window
)
863 /** Get window position.
865 * @param window Window
866 * @param pos Place to store position
867 * @return EOK on success or an error code
869 errno_t
ui_window_get_pos(ui_window_t
*window
, gfx_coord2_t
*pos
)
873 if (window
->dwindow
!= NULL
) {
874 rc
= display_window_get_pos(window
->dwindow
, pos
);
884 /** Get window application area GC
886 * @param window Window
887 * @param rgc Place to store GC (relative to application area)
888 * @return EOK on success or an error code
890 errno_t
ui_window_get_app_gc(ui_window_t
*window
, gfx_context_t
**rgc
)
892 gfx_bitmap_params_t params
;
893 gfx_bitmap_alloc_t alloc
;
898 if (window
->app_gc
== NULL
) {
899 assert(window
->app_bmp
== NULL
);
901 gfx_bitmap_params_init(¶ms
);
904 * The bitmap will have the same dimensions as the
905 * application rectangle, but start at 0,0.
907 ui_window_get_app_rect(window
, &rect
);
908 gfx_rect_rtranslate(&rect
.p0
, &rect
, ¶ms
.rect
);
910 rc
= gfx_bitmap_create(window
->gc
, ¶ms
, NULL
,
915 rc
= gfx_bitmap_get_alloc(window
->app_bmp
, &alloc
);
917 gfx_bitmap_destroy(window
->app_bmp
);
921 rc
= mem_gc_create(¶ms
.rect
, &alloc
,
922 &ui_window_app_mem_gc_cb
, (void *) window
, &memgc
);
924 gfx_bitmap_destroy(window
->app_bmp
);
928 window
->app_mgc
= memgc
;
929 window
->app_gc
= mem_gc_get_ctx(memgc
);
932 *rgc
= window
->app_gc
;
936 /** Get window application rectangle
938 * @param window Window
939 * @param rect Place to store application rectangle
941 void ui_window_get_app_rect(ui_window_t
*window
, gfx_rect_t
*rect
)
943 ui_wdecor_geom_t geom
;
945 ui_wdecor_get_geom(window
->wdecor
, &geom
);
946 *rect
= geom
.app_area_rect
;
949 /** Set cursor when pointer is hovering over a control.
951 * @param window Window
952 * @param cursor Cursor
954 void ui_window_set_ctl_cursor(ui_window_t
*window
, ui_stock_cursor_t cursor
)
956 display_stock_cursor_t dcursor
;
958 dcursor
= wnd_dcursor_from_cursor(cursor
);
960 if (window
->dwindow
!= NULL
)
961 (void) display_window_set_cursor(window
->dwindow
, dcursor
);
966 * @param window Window
967 * @return EOK on success or an error code
969 errno_t
ui_window_paint(ui_window_t
*window
)
971 return ui_window_send_paint(window
);
974 /** Handle window close event. */
975 static void dwnd_close_event(void *arg
)
977 ui_window_t
*window
= (ui_window_t
*) arg
;
978 ui_t
*ui
= window
->ui
;
981 ui_window_send_close(window
);
985 /** Handle window focus event. */
986 static void dwnd_focus_event(void *arg
, unsigned nfocus
)
988 ui_window_t
*window
= (ui_window_t
*) arg
;
989 ui_t
*ui
= window
->ui
;
994 if (window
->wdecor
!= NULL
) {
995 ui_wdecor_set_active(window
->wdecor
, true);
996 ui_wdecor_paint(window
->wdecor
);
999 ui_window_send_focus(window
, nfocus
);
1003 /** Handle window keyboard event */
1004 static void dwnd_kbd_event(void *arg
, kbd_event_t
*kbd_event
)
1006 ui_window_t
*window
= (ui_window_t
*) arg
;
1007 ui_t
*ui
= window
->ui
;
1010 ui_window_send_kbd(window
, kbd_event
);
1014 /** Handle window position event */
1015 static void dwnd_pos_event(void *arg
, pos_event_t
*event
)
1017 ui_window_t
*window
= (ui_window_t
*) arg
;
1018 ui_t
*ui
= window
->ui
;
1021 /* Make sure we don't process events until fully initialized */
1022 if (window
->wdecor
== NULL
)
1027 claim
= ui_wdecor_pos_event(window
->wdecor
, event
);
1028 if (claim
== ui_claimed
) {
1033 ui_window_send_pos(window
, event
);
1037 /** Handle window resize event */
1038 static void dwnd_resize_event(void *arg
, gfx_rect_t
*rect
)
1040 ui_window_t
*window
= (ui_window_t
*) arg
;
1041 ui_t
*ui
= window
->ui
;
1043 /* Make sure we don't process events until fully initialized */
1044 if (window
->wdecor
== NULL
)
1047 if ((window
->wdecor
->style
& ui_wds_resizable
) == 0)
1051 (void) ui_window_resize(window
, rect
);
1052 ui_window_send_resize(window
);
1056 /** Handle window unfocus event. */
1057 static void dwnd_unfocus_event(void *arg
, unsigned nfocus
)
1059 ui_window_t
*window
= (ui_window_t
*) arg
;
1060 ui_t
*ui
= window
->ui
;
1064 if (window
->wdecor
!= NULL
&& nfocus
== 0) {
1065 ui_wdecor_set_active(window
->wdecor
, false);
1066 ui_wdecor_paint(window
->wdecor
);
1069 ui_window_send_unfocus(window
, nfocus
);
1073 /** Window decoration requested opening of system menu.
1075 * @param wdecor Window decoration
1076 * @param arg Argument (window)
1077 * @param idev_id Input device ID
1079 static void wd_sysmenu_open(ui_wdecor_t
*wdecor
, void *arg
, sysarg_t idev_id
)
1081 ui_window_t
*window
= (ui_window_t
*) arg
;
1083 ui_window_send_sysmenu(window
, idev_id
);
1086 /** Window decoration requested moving left from system menu handle.
1088 * @param wdecor Window decoration
1089 * @param arg Argument (window)
1090 * @param idev_id Input device ID
1092 static void wd_sysmenu_left(ui_wdecor_t
*wdecor
, void *arg
, sysarg_t idev_id
)
1094 ui_window_t
*window
= (ui_window_t
*) arg
;
1096 if (window
->mbar
!= NULL
) {
1097 ui_wdecor_sysmenu_hdl_set_active(window
->wdecor
, false);
1098 ui_menu_close(window
->sysmenu
);
1099 ui_menu_bar_select_last(window
->mbar
, false, idev_id
);
1103 /** Window decoration requested moving right from system menu handle.
1105 * @param wdecor Window decoration
1106 * @param arg Argument (window)
1107 * @param idev_id Input device ID
1109 static void wd_sysmenu_right(ui_wdecor_t
*wdecor
, void *arg
, sysarg_t idev_id
)
1111 ui_window_t
*window
= (ui_window_t
*) arg
;
1113 if (window
->mbar
!= NULL
) {
1114 ui_wdecor_sysmenu_hdl_set_active(window
->wdecor
, false);
1115 ui_menu_close(window
->sysmenu
);
1116 ui_menu_bar_select_first(window
->mbar
, false, idev_id
);
1120 /** Window decoration detected accelerator press from system menu handle.
1122 * @param wdecor Window decoration
1123 * @param arg Argument (window)
1124 * @param c Accelerator key
1125 * @param idev_id Input device ID
1127 static void wd_sysmenu_accel(ui_wdecor_t
*wdecor
, void *arg
, char32_t c
,
1130 ui_window_t
*window
= (ui_window_t
*) arg
;
1132 if (window
->mbar
!= NULL
) {
1133 ui_wdecor_sysmenu_hdl_set_active(window
->wdecor
, false);
1134 ui_menu_close(window
->sysmenu
);
1135 ui_menu_bar_press_accel(window
->mbar
, c
, idev_id
);
1139 /** Window decoration requested window minimization.
1141 * @param wdecor Window decoration
1142 * @param arg Argument (window)
1144 static void wd_minimize(ui_wdecor_t
*wdecor
, void *arg
)
1146 ui_window_t
*window
= (ui_window_t
*) arg
;
1148 ui_window_send_minimize(window
);
1151 /** Window decoration requested window maximization.
1153 * @param wdecor Window decoration
1154 * @param arg Argument (window)
1156 static void wd_maximize(ui_wdecor_t
*wdecor
, void *arg
)
1158 ui_window_t
*window
= (ui_window_t
*) arg
;
1160 ui_window_send_maximize(window
);
1163 /** Window decoration requested window unmaximization.
1165 * @param wdecor Window decoration
1166 * @param arg Argument (window)
1168 static void wd_unmaximize(ui_wdecor_t
*wdecor
, void *arg
)
1170 ui_window_t
*window
= (ui_window_t
*) arg
;
1172 ui_window_send_unmaximize(window
);
1175 /** Window decoration requested window closure.
1177 * @param wdecor Window decoration
1178 * @param arg Argument (window)
1180 static void wd_close(ui_wdecor_t
*wdecor
, void *arg
)
1182 ui_window_t
*window
= (ui_window_t
*) arg
;
1184 ui_window_send_close(window
);
1187 /** Window decoration requested window move.
1189 * @param wdecor Window decoration
1190 * @param arg Argument (window)
1191 * @param pos Position where the title bar was pressed
1192 * @param pos_id Positioning device ID
1194 static void wd_move(ui_wdecor_t
*wdecor
, void *arg
, gfx_coord2_t
*pos
,
1197 ui_window_t
*window
= (ui_window_t
*) arg
;
1199 if (window
->dwindow
!= NULL
)
1200 (void) display_window_move_req(window
->dwindow
, pos
, pos_id
);
1203 /** Window decoration requested window resize.
1205 * @param wdecor Window decoration
1206 * @param arg Argument (window)
1207 * @param rsztype Resize type
1208 * @param pos Position where the button was pressed
1209 * @param pos_id Positioning device ID
1211 static void wd_resize(ui_wdecor_t
*wdecor
, void *arg
,
1212 ui_wdecor_rsztype_t rsztype
, gfx_coord2_t
*pos
, sysarg_t pos_id
)
1214 ui_window_t
*window
= (ui_window_t
*) arg
;
1216 if (window
->dwindow
!= NULL
) {
1217 (void) display_window_resize_req(window
->dwindow
,
1218 (display_wnd_rsztype_t
) rsztype
, // Same constants in the enums
1223 /** Get display stock cursor from UI stock cursor.
1225 * @param cursor UI stock cursor
1226 * @return Display stock cursor
1228 display_stock_cursor_t
wnd_dcursor_from_cursor(ui_stock_cursor_t cursor
)
1230 display_stock_cursor_t dcursor
;
1232 dcursor
= dcurs_arrow
;
1236 dcursor
= dcurs_arrow
;
1238 case ui_curs_size_ud
:
1239 dcursor
= dcurs_size_ud
;
1241 case ui_curs_size_lr
:
1242 dcursor
= dcurs_size_lr
;
1244 case ui_curs_size_uldr
:
1245 dcursor
= dcurs_size_uldr
;
1247 case ui_curs_size_urdl
:
1248 dcursor
= dcurs_size_urdl
;
1251 dcursor
= dcurs_ibeam
;
1258 /** Window decoration requested changing cursor.
1260 * @param wdecor Window decoration
1261 * @param arg Argument (window)
1262 * @param cursor Cursor to set
1264 static void wd_set_cursor(ui_wdecor_t
*wdecor
, void *arg
,
1265 ui_stock_cursor_t cursor
)
1267 ui_window_t
*window
= (ui_window_t
*) arg
;
1268 display_stock_cursor_t dcursor
;
1270 if (cursor
== window
->cursor
)
1273 dcursor
= wnd_dcursor_from_cursor(cursor
);
1275 if (window
->dwindow
!= NULL
)
1276 (void) display_window_set_cursor(window
->dwindow
, dcursor
);
1278 window
->cursor
= cursor
;
1281 /** Send window sysmenu event.
1283 * @param window Window
1284 * @parma idev_id Input device ID
1286 void ui_window_send_sysmenu(ui_window_t
*window
, sysarg_t idev_id
)
1288 if (window
->cb
!= NULL
&& window
->cb
->sysmenu
!= NULL
)
1289 window
->cb
->sysmenu(window
, window
->arg
, idev_id
);
1291 ui_window_def_sysmenu(window
, idev_id
);
1294 /** Send window minimize event.
1296 * @param window Window
1298 void ui_window_send_minimize(ui_window_t
*window
)
1300 if (window
->cb
!= NULL
&& window
->cb
->minimize
!= NULL
)
1301 window
->cb
->minimize(window
, window
->arg
);
1303 ui_window_def_minimize(window
);
1306 /** Send window maximize event.
1308 * @param window Window
1310 void ui_window_send_maximize(ui_window_t
*window
)
1312 if (window
->cb
!= NULL
&& window
->cb
->maximize
!= NULL
)
1313 window
->cb
->maximize(window
, window
->arg
);
1315 ui_window_def_maximize(window
);
1318 /** Send window unmaximize event.
1320 * @param window Window
1322 void ui_window_send_unmaximize(ui_window_t
*window
)
1324 if (window
->cb
!= NULL
&& window
->cb
->unmaximize
!= NULL
)
1325 window
->cb
->unmaximize(window
, window
->arg
);
1327 ui_window_def_unmaximize(window
);
1330 /** Send window close event.
1332 * @param window Window
1334 void ui_window_send_close(ui_window_t
*window
)
1336 if (window
->cb
!= NULL
&& window
->cb
->close
!= NULL
)
1337 window
->cb
->close(window
, window
->arg
);
1340 /** Send window focus event.
1342 * @param window Window
1343 * @param nfocus New number of foci
1345 void ui_window_send_focus(ui_window_t
*window
, unsigned nfocus
)
1347 if (window
->cb
!= NULL
&& window
->cb
->focus
!= NULL
)
1348 window
->cb
->focus(window
, window
->arg
, nfocus
);
1351 /** Send window keyboard event.
1353 * @param window Window
1355 void ui_window_send_kbd(ui_window_t
*window
, kbd_event_t
*kbd
)
1357 if (window
->cb
!= NULL
&& window
->cb
->kbd
!= NULL
)
1358 window
->cb
->kbd(window
, window
->arg
, kbd
);
1360 ui_window_def_kbd(window
, kbd
);
1363 /** Send window paint event.
1365 * @param window Window
1367 errno_t
ui_window_send_paint(ui_window_t
*window
)
1369 if (window
->cb
!= NULL
&& window
->cb
->paint
!= NULL
)
1370 return window
->cb
->paint(window
, window
->arg
);
1372 return ui_window_def_paint(window
);
1375 /** Send window position event.
1377 * @param window Window
1379 void ui_window_send_pos(ui_window_t
*window
, pos_event_t
*pos
)
1381 if (window
->cb
!= NULL
&& window
->cb
->pos
!= NULL
)
1382 window
->cb
->pos(window
, window
->arg
, pos
);
1384 ui_window_def_pos(window
, pos
);
1387 /** Send window unfocus event.
1389 * @param window Window
1390 * @param nfocus Number of remaining foci
1392 void ui_window_send_unfocus(ui_window_t
*window
, unsigned nfocus
)
1394 if (window
->cb
!= NULL
&& window
->cb
->unfocus
!= NULL
)
1395 window
->cb
->unfocus(window
, window
->arg
, nfocus
);
1397 return ui_window_def_unfocus(window
, nfocus
);
1400 /** Send window resize event.
1402 * @param window Window
1404 void ui_window_send_resize(ui_window_t
*window
)
1406 if (window
->cb
!= NULL
&& window
->cb
->resize
!= NULL
)
1407 window
->cb
->resize(window
, window
->arg
);
1409 return ui_window_def_resize(window
);
1412 /** Default window sysmenu routine.
1414 * @param window Window
1415 * @param idev_id Input device ID
1416 * @return EOK on success or an error code
1418 errno_t
ui_window_def_sysmenu(ui_window_t
*window
, sysarg_t idev_id
)
1421 ui_wdecor_geom_t geom
;
1423 if (ui_menu_is_open(window
->sysmenu
)) {
1424 ui_menu_close(window
->sysmenu
);
1426 ui_wdecor_get_geom(window
->wdecor
, &geom
);
1428 rc
= ui_menu_open(window
->sysmenu
, &geom
.title_bar_rect
,
1439 /** Default window minimize routine.
1441 * @param window Window
1442 * @return EOK on success or an error code
1444 errno_t
ui_window_def_minimize(ui_window_t
*window
)
1448 if (window
->dwindow
!= NULL
) {
1449 rc
= display_window_minimize(window
->dwindow
);
1459 /** Default window maximize routine.
1461 * @param window Window
1462 * @return EOK on success or an error code
1464 errno_t
ui_window_def_maximize(ui_window_t
*window
)
1467 gfx_rect_t old_rect
;
1470 old_rect
= window
->rect
;
1472 if (window
->dwindow
!= NULL
) {
1473 rc
= display_window_get_max_rect(window
->dwindow
, &rect
);
1477 rect
= window
->ui
->rect
;
1480 ui_wdecor_set_maximized(window
->wdecor
, true);
1481 ui_menu_entry_set_disabled(window
->sysmenu_restore
, false);
1482 ui_menu_entry_set_disabled(window
->sysmenu_maximize
, true);
1484 rc
= ui_window_size_change(window
, &rect
, ui_wsc_maximize
);
1486 ui_wdecor_set_maximized(window
->wdecor
, false);
1490 window
->normal_rect
= old_rect
;
1491 (void) ui_window_paint(window
);
1495 /** Default window unmaximize routine.
1497 * @param window Window
1498 * @return EOK on success or an error code
1500 errno_t
ui_window_def_unmaximize(ui_window_t
*window
)
1504 ui_wdecor_set_maximized(window
->wdecor
, false);
1505 ui_menu_entry_set_disabled(window
->sysmenu_restore
, true);
1506 ui_menu_entry_set_disabled(window
->sysmenu_maximize
, false);
1508 rc
= ui_window_size_change(window
, &window
->normal_rect
,
1511 ui_wdecor_set_maximized(window
->wdecor
, true);
1512 printf("ui_window_size_change->error\n");
1516 (void) ui_window_paint(window
);
1520 /** Default window keyboard event routine.
1522 * @param window Window
1523 * @return ui_claimed iff event was claimed
1525 ui_evclaim_t
ui_window_def_kbd(ui_window_t
*window
, kbd_event_t
*kbd
)
1529 if (window
->control
!= NULL
)
1530 claim
= ui_control_kbd_event(window
->control
, kbd
);
1532 claim
= ui_unclaimed
;
1534 if (claim
== ui_unclaimed
)
1535 return ui_wdecor_kbd_event(window
->wdecor
, kbd
);
1537 return ui_unclaimed
;
1540 /** Default window paint routine.
1542 * @param window Window
1543 * @return EOK on success or an error code
1545 errno_t
ui_window_def_paint(ui_window_t
*window
)
1547 gfx_rect_t app_rect
;
1550 rc
= gfx_set_color(window
->gc
, window
->res
->wnd_face_color
);
1554 ui_window_get_app_rect(window
, &app_rect
);
1556 rc
= gfx_fill_rect(window
->gc
, &app_rect
);
1560 if (window
->control
!= NULL
)
1561 return ui_control_paint(window
->control
);
1563 rc
= gfx_update(window
->res
->gc
);
1570 /** Default window position event routine.
1572 * @param window Window
1574 void ui_window_def_pos(ui_window_t
*window
, pos_event_t
*pos
)
1576 if (window
->control
!= NULL
)
1577 ui_control_pos_event(window
->control
, pos
);
1580 /** Default window unfocus routine.
1582 * @param window Window
1583 * @param nfocus Number of remaining foci
1584 * @return EOK on success or an error code
1586 void ui_window_def_unfocus(ui_window_t
*window
, unsigned nfocus
)
1588 if (window
->control
!= NULL
)
1589 ui_control_unfocus(window
->control
, nfocus
);
1592 /** Default window resize routine.
1594 * @param window Window
1595 * @return EOK on success or an error code
1597 void ui_window_def_resize(ui_window_t
*window
)
1599 ui_window_paint(window
);
1602 /** Handle system menu left event.
1604 * @param sysmenu System menu
1605 * @param arg Argument (ui_window_t *)
1606 * @param idev_id Input device ID
1608 static void wnd_sysmenu_left(ui_menu_t
*sysmenu
, void *arg
, sysarg_t idev_id
)
1610 ui_window_t
*window
= (ui_window_t
*)arg
;
1612 if (window
->mbar
!= NULL
) {
1613 ui_wdecor_sysmenu_hdl_set_active(window
->wdecor
, false);
1614 ui_menu_close(sysmenu
);
1615 ui_menu_bar_select_last(window
->mbar
, true, idev_id
);
1619 /** Handle system menu right event.
1621 * @param sysmenu System menu
1622 * @param arg Argument (ui_window_t *)
1623 * @param idev_id Input device ID
1625 static void wnd_sysmenu_right(ui_menu_t
*sysmenu
, void *arg
, sysarg_t idev_id
)
1627 ui_window_t
*window
= (ui_window_t
*)arg
;
1629 if (window
->mbar
!= NULL
) {
1630 ui_wdecor_sysmenu_hdl_set_active(window
->wdecor
, false);
1631 ui_menu_close(sysmenu
);
1632 ui_menu_bar_select_first(window
->mbar
, true, idev_id
);
1636 /** Handle system menu close request event.
1638 * @param sysmenu System menu
1639 * @param arg Argument (ui_window_t *)
1640 * @param idev_id Input device ID
1642 static void wnd_sysmenu_close_req(ui_menu_t
*sysmenu
, void *arg
)
1644 ui_window_t
*window
= (ui_window_t
*)arg
;
1646 ui_wdecor_sysmenu_hdl_set_active(window
->wdecor
, false);
1647 ui_menu_close(sysmenu
);
1650 /** Handle system menu Restore entry activation.
1652 * @param mentry Menu entry
1653 * @param arg Argument (ui_window_t *)
1655 static void wnd_sysmenu_erestore(ui_menu_entry_t
*mentry
, void *arg
)
1657 ui_window_t
*window
= (ui_window_t
*)arg
;
1659 ui_window_send_unmaximize(window
);
1662 /** Handle system menu Minimize entry activation.
1664 * @param mentry Menu entry
1665 * @param arg Argument (ui_window_t *)
1667 static void wnd_sysmenu_eminimize(ui_menu_entry_t
*mentry
, void *arg
)
1669 ui_window_t
*window
= (ui_window_t
*)arg
;
1671 ui_window_send_minimize(window
);
1674 /** Handle system menu Maximize entry activation.
1676 * @param mentry Menu entry
1677 * @param arg Argument (ui_window_t *)
1679 static void wnd_sysmenu_emaximize(ui_menu_entry_t
*mentry
, void *arg
)
1681 ui_window_t
*window
= (ui_window_t
*)arg
;
1683 ui_window_send_maximize(window
);
1686 /** Handle system menu Close entry activation.
1688 * @param mentry Menu entry
1689 * @param arg Argument (ui_window_t *)
1691 static void wnd_sysmenu_eclose(ui_menu_entry_t
*mentry
, void *arg
)
1693 ui_window_t
*window
= (ui_window_t
*)arg
;
1695 ui_window_send_close(window
);
1698 /** Handle system menu press accelerator key event.
1700 * @param sysmenu System menu
1701 * @param arg Argument (ui_window_t *)
1702 * @param idev_id Input device ID
1704 static void wnd_sysmenu_press_accel(ui_menu_t
*sysmenu
, void *arg
,
1705 char32_t c
, sysarg_t idev_id
)
1713 /** Window invalidate callback
1715 * @param arg Argument (ui_window_t *)
1716 * @param rect Rectangle to update
1718 static void ui_window_invalidate(void *arg
, gfx_rect_t
*rect
)
1720 ui_window_t
*window
= (ui_window_t
*) arg
;
1723 gfx_rect_envelope(&window
->dirty_rect
, rect
, &env
);
1724 window
->dirty_rect
= env
;
1727 /** Window update callback
1729 * @param arg Argument (ui_window_t *)
1731 static void ui_window_update(void *arg
)
1733 ui_window_t
*window
= (ui_window_t
*) arg
;
1735 if (!gfx_rect_is_empty(&window
->dirty_rect
)) {
1736 (void) gfx_bitmap_render(window
->bmp
, &window
->dirty_rect
,
1740 window
->dirty_rect
.p0
.x
= 0;
1741 window
->dirty_rect
.p0
.y
= 0;
1742 window
->dirty_rect
.p1
.x
= 0;
1743 window
->dirty_rect
.p1
.y
= 0;
1746 /** Window cursor get position callback
1748 * @param arg Argument (ui_window_t *)
1749 * @param pos Place to store position
1751 static errno_t
ui_window_cursor_get_pos(void *arg
, gfx_coord2_t
*pos
)
1753 ui_window_t
*window
= (ui_window_t
*) arg
;
1757 rc
= gfx_cursor_get_pos(window
->realgc
, &cpos
);
1761 pos
->x
= cpos
.x
- window
->dpos
.x
;
1762 pos
->y
= cpos
.y
- window
->dpos
.y
;
1766 /** Window cursor set position callback
1768 * @param arg Argument (ui_window_t *)
1769 * @param pos New position
1771 static errno_t
ui_window_cursor_set_pos(void *arg
, gfx_coord2_t
*pos
)
1773 ui_window_t
*window
= (ui_window_t
*) arg
;
1776 cpos
.x
= pos
->x
+ window
->dpos
.x
;
1777 cpos
.y
= pos
->y
+ window
->dpos
.y
;
1779 return gfx_cursor_set_pos(window
->realgc
, &cpos
);
1782 /** Window cursor set visibility callback
1784 * @param arg Argument (ui_window_t *)
1785 * @param visible @c true iff cursor is to be made visible
1787 static errno_t
ui_window_cursor_set_visible(void *arg
, bool visible
)
1789 ui_window_t
*window
= (ui_window_t
*) arg
;
1791 return gfx_cursor_set_visible(window
->realgc
, visible
);
1794 /** Application area invalidate callback
1796 * @param arg Argument (ui_window_t *)
1797 * @param rect Rectangle to update
1799 static void ui_window_app_invalidate(void *arg
, gfx_rect_t
*rect
)
1801 ui_window_t
*window
= (ui_window_t
*) arg
;
1804 ui_window_get_app_rect(window
, &arect
);
1806 /* Render bitmap rectangle inside the application area */
1807 (void) gfx_bitmap_render(window
->app_bmp
, rect
, &arect
.p0
);
1809 * TODO Update applications to call gfx_update(), then
1810 * we can defer update to ui_window_app_update().
1812 (void) gfx_update(window
->res
->gc
);
1815 /** Application area update callback
1817 * @param arg Argument (ui_window_t *)
1819 static void ui_window_app_update(void *arg
)
1821 ui_window_t
*window
= (ui_window_t
*) arg
;
1824 * Not used since display is updated immediately
1825 * in ui_window_app_invalidate
1830 /** Window expose callback. */
1831 static void ui_window_expose_cb(void *arg
)
1833 ui_window_t
*window
= (ui_window_t
*) arg
;
1835 ui_window_paint(window
);