PatchworkOS
Loading...
Searching...
No Matches
window.c
Go to the documentation of this file.
3#define __STDC_WANT_LIB_EXT1__ 1
4#include "internal.h"
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9
10#define WINDOW_CLIENT_ELEM_ID (UINT64_MAX)
11#define WINDOW_DECO_ELEM_ID (UINT64_MAX - 1)
12#define WINDOW_DECO_CLOSE_BUTTON_ID (UINT64_MAX - 2)
13#define WINDOW_DECO_MINIMIZE_BUTTON_ID (UINT64_MAX - 3)
14
15#define WINDOW_DECO_CLOSE_BUTTON_INDEX 0
16#define WINDOW_DECO_MINIMIZE_BUTTON_INDEX 1
17#define WINDOW_DECO_BUTTON_AMOUNT 2
18
28
29static void window_deco_titlebar_rect(window_t* win, element_t* elem, rect_t* rect)
30{
31 (void)win; // Unused
32
33 rect_t contentRect = element_get_content_rect(elem);
34 const theme_t* theme = element_get_theme(elem);
35
36 *rect = (rect_t){
39 .right = RECT_WIDTH(&contentRect) - theme->frameSize - theme->smallPadding,
40 .bottom = theme->frameSize + theme->titlebarSize,
41 };
42}
43
44static void window_deco_button_rect(window_t* win, element_t* elem, rect_t* rect, uint64_t index)
45{
46 window_deco_titlebar_rect(win, elem, rect);
47 RECT_SHRINK(rect, element_get_theme(elem)->frameSize);
48 uint64_t size = (rect->bottom - rect->top);
49 rect->right -= size * index;
50 rect->left = rect->right - size;
51}
52
54{
55 deco_private_t* private = element_get_private(elem);
56 const theme_t* theme = element_get_theme(elem);
57
58 rect_t titlebar;
59 window_deco_titlebar_rect(win, elem, &titlebar);
60
62 RECT_SHRINK(&titlebar, theme->frameSize);
63 if (private->isFocused)
64 {
67 }
68 else
69 {
72 }
73
74 titlebar.left += theme->bigPadding;
75 titlebar.right -= theme->panelSize; // Space for buttons
77}
78
79static void window_deco_handle_dragging(window_t* win, element_t* elem, const event_mouse_t* event)
80{
81 deco_private_t* private = element_get_private(elem);
82
83 rect_t titlebarWithoutButtons;
84 window_deco_titlebar_rect(win, elem, &titlebarWithoutButtons);
85 if (!(win->flags & WINDOW_NO_CONTROLS))
86 {
87 rect_t lastButton;
88 window_deco_button_rect(win, elem, &lastButton, WINDOW_DECO_BUTTON_AMOUNT - 1);
89 titlebarWithoutButtons.right = lastButton.left;
90 }
91
92 if (private->isDragging)
93 {
94 if (event->held & MOUSE_LEFT)
95 {
96 rect_t rect = RECT_INIT_DIM(event->screenPos.x - private->dragOffset.x,
97 event->screenPos.y - private->dragOffset.y, RECT_WIDTH(&win->rect), RECT_HEIGHT(&win->rect));
98 window_move(win, &rect);
99 }
100 else
101 {
102 private->isDragging = false;
103 }
104 }
105 else if (RECT_CONTAINS_POINT(&titlebarWithoutButtons, &event->pos) && (event->pressed & MOUSE_LEFT))
106 {
107 private->dragOffset =
108 (point_t){.x = event->screenPos.x - win->rect.left, .y = event->screenPos.y - win->rect.top};
109 private->isDragging = true;
110 }
111}
112
114{
115 const theme_t* theme = element_get_theme(elem);
116 element_t* closeButton = NULL;
117 element_t* minimizeButton = NULL;
118
119 rect_t closeRect;
121 closeButton = button_new(elem, WINDOW_DECO_CLOSE_BUTTON_ID, &closeRect, "", ELEMENT_NO_OUTLINE);
122 if (closeButton == NULL)
123 {
124 goto error;
125 }
126
127 rect_t minimizeRect;
129 minimizeButton = button_new(elem, WINDOW_DECO_MINIMIZE_BUTTON_ID, &minimizeRect, "", ELEMENT_NO_OUTLINE);
130 if (minimizeButton == NULL)
131 {
132 goto error;
133 }
134
135 private->closeIcon = image_new(window_get_display(win), theme->iconClose);
136 if (private->closeIcon == NULL)
137 {
138 goto error;
139 }
140
141 private->minimizeIcon = image_new(window_get_display(win), theme->iconMinimize);
142 if (private->minimizeIcon == NULL)
143 {
144 goto error;
145 }
146
147 element_set_image(closeButton, private->closeIcon);
148 element_set_image(minimizeButton, private->minimizeIcon);
149
150 return 0;
151
152error:
153 if (private->minimizeIcon != NULL)
154 {
155 image_free(private->minimizeIcon);
156 }
157 if (private->closeIcon != NULL)
158 {
159 image_free(private->closeIcon);
160 }
161 if (closeButton != NULL)
162 {
163 element_free(closeButton);
164 }
165 if (minimizeButton != NULL)
166 {
167 element_free(minimizeButton);
168 }
169 return ERR;
170}
171
173{
174 deco_private_t* private = malloc(sizeof(deco_private_t));
175 if (private == NULL)
176 {
177 return ERR;
178 }
179 private->isFocused = false;
180 private->isVisible = true;
181 private->isDragging = false;
182 private->minimizeIcon = NULL;
183 private->closeIcon = NULL;
184
185 if (!(win->flags & WINDOW_NO_CONTROLS))
186 {
187 if (window_deco_init_controls(win, elem, private) == ERR)
188 {
189 free(private);
190 return ERR;
191 }
192 }
193
194 element_set_private(elem, private);
195 return 0;
196}
197
198static void window_deco_free(element_t* elem)
199{
200 deco_private_t* private = element_get_private(elem);
201 if (private != NULL)
202 {
203 if (private->closeIcon != NULL)
204 {
205 image_free(private->closeIcon);
206 }
207 if (private->minimizeIcon != NULL)
208 {
209 image_free(private->minimizeIcon);
210 }
211 free(private);
212 }
213}
214
215static void window_deco_redraw(window_t* win, element_t* elem)
216{
217 const theme_t* theme = element_get_theme(elem);
218 rect_t rect = element_get_content_rect(elem);
219
220 drawable_t draw;
221 element_draw_begin(elem, &draw);
222
224 RECT_SHRINK(&rect, theme->frameSize);
225 draw_rect(&draw, &rect, theme->deco.backgroundNormal);
226
227 window_deco_draw_titlebar(win, elem, &draw);
228
229 element_draw_end(elem, &draw);
230}
231
232static void window_deco_action(window_t* win, const levent_action_t* action)
233{
234 if (action->type != ACTION_RELEASE)
235 {
236 return;
237 }
238
239 switch (action->source)
240 {
242 display_push(win->disp, win->surface, LEVENT_QUIT, NULL, 0);
243 break;
245 display_set_is_visible(win->disp, win->surface, false);
246 break;
247 }
248}
249
250static void window_deco_report(window_t* win, element_t* elem, const event_report_t* report)
251{
252 if (!(report->flags & REPORT_IS_FOCUSED))
253 {
254 return;
255 }
256
257 deco_private_t* private = element_get_private(elem);
258 private->isFocused = report->info.flags & SURFACE_FOCUSED;
259 private->isVisible = report->info.flags & SURFACE_VISIBLE;
260
261 drawable_t draw;
262 element_draw_begin(elem, &draw);
263 window_deco_draw_titlebar(win, elem, &draw);
264 element_draw_end(elem, &draw);
265}
266
267static uint64_t window_deco_procedure(window_t* win, element_t* elem, const event_t* event)
268{
269 switch (event->type)
270 {
271 case LEVENT_INIT:
272 return window_deco_init(win, elem);
273
274 case LEVENT_DEINIT:
275 window_deco_free(elem);
276 break;
277
278 case LEVENT_REDRAW:
279 window_deco_redraw(win, elem);
280 break;
281
282 case LEVENT_ACTION:
283 window_deco_action(win, &event->lAction);
284 break;
285
286 case EVENT_REPORT:
287 window_deco_report(win, elem, &event->report);
288 break;
289
290 case EVENT_MOUSE:
291 window_deco_handle_dragging(win, elem, &event->mouse);
292 break;
293
294 default:
295 break;
296 }
297
298 return 0;
299}
300
301window_t* window_new(display_t* disp, const char* name, const rect_t* rect, surface_type_t type, window_flags_t flags,
302 procedure_t procedure, void* private)
303{
304 if (disp == NULL || name == NULL || rect == NULL || procedure == NULL || strnlen_s(name, MAX_NAME + 1) >= MAX_NAME)
305 {
306 errno = EINVAL;
307 return NULL;
308 }
309
310 window_t* win = malloc(sizeof(window_t));
311 if (win == NULL)
312 {
313 errno = ENOMEM;
314 return NULL;
315 }
316 list_entry_init(&win->entry);
317 win->disp = disp;
318 strcpy(win->name, name);
319 win->rect = (rect_t){0};
320 win->invalidRect = (rect_t){0};
321 win->type = type;
322 win->flags = flags;
323 win->buffer = NULL;
324 win->root = NULL;
325 win->clientElement = NULL;
326
327 const theme_t* theme = theme_global_get();
328 if (flags & WINDOW_DECO)
329 {
330 // Expand window to fit decorations
331 win->rect.left = rect->left - theme->frameSize;
332 win->rect.top = rect->top - theme->frameSize - theme->titlebarSize;
333 win->rect.right = rect->right + theme->frameSize;
334 win->rect.bottom = rect->bottom + theme->frameSize;
335 }
336 else
337 {
338 win->rect = *rect;
339 }
340
342 if (cmd == NULL)
343 {
344 free(win);
345 return NULL;
346 }
347 cmd->type = win->type;
348 cmd->rect = win->rect;
349 strcpy(cmd->name, win->name);
350 display_cmds_flush(disp);
351 event_t event;
352 if (display_wait(disp, &event, EVENT_SURFACE_NEW) == ERR)
353 {
354 window_free(win);
355 return NULL;
356 }
357 win->surface = event.target;
358
359 fd_t shmem = claim(&event.surfaceNew.shmemKey);
360 if (shmem == ERR)
361 {
362 window_free(win);
363 return NULL;
364 }
365 win->buffer =
366 mmap(shmem, NULL, RECT_WIDTH(&win->rect) * RECT_HEIGHT(&win->rect) * sizeof(pixel_t), PROT_READ | PROT_WRITE);
367 close(shmem);
368 if (win->buffer == NULL)
369 {
370 window_free(win);
371 return NULL;
372 }
373
374 mtx_lock(&disp->mutex);
375 list_push(&disp->windows, &win->entry);
376 mtx_unlock(&disp->mutex);
377
378 rect_t rootRect = RECT_INIT_DIM(0, 0, RECT_WIDTH(&win->rect), RECT_HEIGHT(&win->rect));
379 if (flags & WINDOW_DECO)
380 {
381 win->root =
383 if (win->root == NULL)
384 {
385 window_free(win);
386 return NULL;
387 }
388
391
392 win->clientElement =
393 element_new(win->root, WINDOW_CLIENT_ELEM_ID, &clientRect, "client", ELEMENT_NONE, procedure, private);
394 if (win->clientElement == NULL)
395 {
396 window_free(win);
397 return NULL;
398 }
399 }
400 else
401 {
402 win->clientElement =
403 element_new_root(win, WINDOW_CLIENT_ELEM_ID, &rootRect, "client", ELEMENT_NONE, procedure, private);
404 if (win->clientElement == NULL)
405 {
406 window_free(win);
407 return NULL;
408 }
409 win->root = win->clientElement;
410 }
411
412 return win;
413}
414
416{
417 if (win == NULL)
418 {
419 return;
420 }
421
422 if (win->root != NULL)
423 {
424 element_free(win->root);
425 }
426
427 if (win->buffer != NULL)
428 {
429 munmap(win->buffer, RECT_WIDTH(&win->rect) * RECT_HEIGHT(&win->rect) * sizeof(pixel_t));
430 }
431
433 if (cmd == NULL)
434 {
435 abort();
436 }
437 cmd->target = win->surface;
439
440 mtx_lock(&win->disp->mutex);
441 list_remove(&win->disp->windows, &win->entry);
442 mtx_unlock(&win->disp->mutex);
443
444 free(win);
445}
446
448{
449 if (win == NULL)
450 {
451 return (rect_t){0};
452 }
453
454 return win->rect;
455}
456
458{
459 if (win == NULL)
460 {
461 return (rect_t){0};
462 }
463
464 return RECT_INIT_DIM(0, 0, RECT_WIDTH(&win->rect), RECT_HEIGHT(&win->rect));
465}
466
468{
469 if (win == NULL)
470 {
471 return NULL;
472 }
473
474 return win->disp;
475}
476
478{
479 if (win == NULL)
480 {
481 return SURFACE_ID_NONE;
482 }
483
484 return win->surface;
485}
486
488{
489 if (win == NULL)
490 {
491 return SURFACE_NONE;
492 }
493
494 return win->type;
495}
496
498{
499 if (win == NULL)
500 {
501 return NULL;
502 }
503
504 return win->clientElement;
505}
506
508{
509 if (win == NULL || rect == NULL)
510 {
511 errno = EINVAL;
512 return ERR;
513 }
514
515 bool hasSizeChanged = RECT_WIDTH(&win->rect) != RECT_WIDTH(rect) || RECT_HEIGHT(&win->rect) != RECT_HEIGHT(rect);
516 if (hasSizeChanged && !(win->flags & WINDOW_RESIZABLE))
517 {
518 errno = EPERM;
519 return ERR;
520 }
521
523 if (cmd == NULL)
524 {
525 return ERR;
526 }
527 cmd->target = win->surface;
528 cmd->rect = *rect;
530 return 0;
531}
532
534{
535 if (win == NULL)
536 {
537 errno = EINVAL;
538 return ERR;
539 }
540
542 if (cmd == NULL)
543 {
544 return ERR;
545 }
546 cmd->target = win->surface;
547 cmd->flags = flags;
548 cmd->timeout = timeout;
550 return 0;
551}
552
553void window_invalidate(window_t* win, const rect_t* rect)
554{
555 if (win == NULL || rect == NULL)
556 {
557 return;
558 }
559
560 if (RECT_AREA(&win->invalidRect) == 0)
561 {
562 win->invalidRect = *rect;
563 }
564 else
565 {
567 }
568}
569
571{
572 if (win == NULL)
573 {
574 errno = EINVAL;
575 return ERR;
576 }
577
578 if (RECT_AREA(&win->invalidRect) == 0)
579 {
580 return 0;
581 }
582
585 if (cmd == NULL)
586 {
587 return ERR;
588 }
589
590 cmd->target = win->surface;
591 cmd->invalidRect = win->invalidRect;
593
594 win->invalidRect = (rect_t){0};
595 return 0;
596}
597
599{
600 if (win == NULL || event == NULL)
601 {
602 errno = EINVAL;
603 return ERR;
604 }
605
606 switch (event->type)
607 {
608 case LEVENT_REDRAW:
609 {
610 element_t* elem = element_find(win->root, event->lRedraw.id);
611 if (elem == NULL)
612 {
613 return ERR;
614 }
615
616 if (element_dispatch(elem, event) == ERR)
617 {
618 return ERR;
619 }
620 }
621 break;
623 {
624 element_t* elem = element_find(win->root, event->lForceAction.dest);
625 if (elem == NULL)
626 {
627 return ERR;
628 }
629
630 if (element_dispatch(elem, event) == ERR)
631 {
632 return ERR;
633 }
634 }
635 break;
636 case EVENT_REPORT:
637 {
638 if (event->report.flags & REPORT_RECT)
639 {
640 rect_t newRect = event->report.info.rect;
641
642 if (RECT_WIDTH(&win->rect) != RECT_WIDTH(&newRect) || RECT_HEIGHT(&win->rect) != RECT_HEIGHT(&newRect))
643 {
644 levent_redraw_t event;
645 event.id = win->root->id;
646 event.shouldPropagate = true;
647 display_push(win->disp, win->surface, LEVENT_REDRAW, &event, sizeof(levent_redraw_t));
648 }
649
650 win->rect = newRect;
651 }
652
653 if (element_dispatch(win->root, event) == ERR)
654 {
655 return ERR;
656 }
657 }
658 break;
659 default:
660 {
661 if (element_dispatch(win->root, event) == ERR)
662 {
663 return ERR;
664 }
665 }
666 break;
667 }
668
670 return 0;
671}
672
674{
675 if (win == NULL)
676 {
677 errno = EINVAL;
678 return ERR;
679 }
680
682 if (cmd == NULL)
683 {
684 return ERR;
685 }
686 cmd->isGlobal = false;
687 cmd->target = win->surface;
689 return 0;
690}
691
693{
694 if (win == NULL)
695 {
696 errno = EINVAL;
697 return ERR;
698 }
699
701 {
702 return ERR;
703 }
704
707 if (cmd == NULL)
708 {
709 return ERR;
710 }
711 cmd->isGlobal = false;
712 cmd->target = win->surface;
713 cmd->isVisible = isVisible;
715 return 0;
716}
#define MAX_NAME
Maximum length of names.
Definition MAX_NAME.h:11
@ CMD_SURFACE_TIMER_SET
Definition cmd.h:28
@ CMD_SURFACE_MOVE
Definition cmd.h:27
@ CMD_SURFACE_NEW
Definition cmd.h:25
@ CMD_SURFACE_VISIBLE_SET
Definition cmd.h:31
@ CMD_SURFACE_FREE
Definition cmd.h:26
@ CMD_SURFACE_FOCUS_SET
Definition cmd.h:30
@ CMD_SURFACE_INVALIDATE
Definition cmd.h:29
timer_flags_t
Definition cmd.h:75
element_t * element_new_root(window_t *win, element_id_t id, const rect_t *rect, const char *text, element_flags_t flags, procedure_t procedure, void *private)
Definition element.c:76
void * display_cmd_alloc(display_t *disp, cmd_type_t type, uint64_t size)
Allocate a section of the displays command buffer.
Definition display.c:173
void display_cmds_flush(display_t *disp)
Flush the display's command buffer.
Definition display.c:198
void display_push(display_t *disp, surface_id_t target, event_type_t type, void *data, uint64_t size)
Push an event to the display's internal event queue.
Definition display.c:349
uint64_t display_wait(display_t *disp, event_t *event, event_type_t expected)
Wait for the display to receive an event of the expected type.
Definition display.c:367
uint64_t display_dispatch_pending(display_t *disp, event_type_t type, surface_id_t target)
Dispatch all events currently in the display's internal event queue of a specific type and target.
Definition display.c:472
uint64_t display_set_is_visible(display_t *disp, surface_id_t id, bool isVisible)
Set the visibility of a surface.
Definition display.c:588
void draw_gradient(drawable_t *draw, const rect_t *rect, pixel_t start, pixel_t end, direction_t direction, bool shouldAddNoise)
Draw a gradient filled rectangle.
Definition drawable.c:382
void draw_rect(drawable_t *draw, const rect_t *rect, pixel_t pixel)
Draw a filled rectangle.
Definition drawable.c:7
void draw_text(drawable_t *draw, const rect_t *rect, const font_t *font, align_t xAlign, align_t yAlign, pixel_t pixel, const char *text)
Draw text to a drawable.
Definition drawable.c:669
void draw_frame(drawable_t *draw, const rect_t *rect, uint64_t width, pixel_t foreground, pixel_t background)
Draw a skeuomorphic frame.
Definition drawable.c:204
@ ALIGN_MIN
Definition drawable.h:51
@ ALIGN_CENTER
Definition drawable.h:49
@ DIRECTION_HORIZONTAL
Definition drawable.h:61
void element_set_image(element_t *elem, image_t *image)
Set the image of an element.
Definition element.c:381
void element_set_private(element_t *elem, void *private)
Set private data for an element.
Definition element.c:163
element_t * element_find(element_t *elem, element_id_t id)
Find a child element by its ID.
Definition element.c:134
theme_t * element_get_theme(element_t *elem)
Get the theme of an element.
Definition element.c:401
#define ELEMENT_NO_OUTLINE
Definition element.h:47
uint64_t element_dispatch(element_t *elem, const event_t *event)
Dispatch an event to an element.
Definition element.c:476
void element_draw_end(element_t *elem, drawable_t *draw)
End drawing to an element.
Definition element.c:427
element_t * element_new(element_t *parent, element_id_t id, const rect_t *rect, const char *text, element_flags_t flags, procedure_t procedure, void *private)
Allocate and initialize a new element.
Definition element.c:48
#define ELEMENT_NONE
Definition element.h:43
rect_t element_get_content_rect(element_t *elem)
Get the element's rectangle in local coordinates.
Definition element.c:213
void element_draw_begin(element_t *elem, drawable_t *draw)
Begin drawing to an element.
Definition element.c:411
void element_free(element_t *elem)
Deinitialize and free an element and all its children.
Definition element.c:113
void * element_get_private(element_t *elem)
Get private data for an element.
Definition element.c:173
#define LEVENT_QUIT
Definition event.h:103
#define LEVENT_FORCE_ACTION
Definition event.h:104
#define EVENT_MOUSE
Definition event.h:85
#define LEVENT_DEINIT
Definition event.h:100
#define LEVENT_REDRAW
Definition event.h:101
#define EVENT_SURFACE_NEW
Definition event.h:83
#define LEVENT_INIT
Definition event.h:99
#define LEVENT_ACTION
Definition event.h:102
#define EVENT_REPORT
Definition event.h:89
@ REPORT_IS_FOCUSED
Definition event.h:38
@ REPORT_RECT
Definition event.h:36
@ ACTION_RELEASE
Definition event.h:50
#define SURFACE_ID_NONE
Definition surface.h:54
surface_type_t
Surface types.
Definition surface.h:33
uint64_t surface_id_t
Definition surface.h:53
@ SURFACE_NONE
Definition surface.h:34
@ SURFACE_VISIBLE
Definition surface.h:49
@ SURFACE_FOCUSED
Definition surface.h:50
theme_t * theme_global_get(void)
Get the global theme.
Definition theme.c:97
element_t * button_new(element_t *parent, element_id_t id, const rect_t *rect, const char *text, element_flags_t flags)
Create a new button element.
Definition button.c:308
uint64_t window_set_visible(window_t *win, bool isVisible)
Set the visibility of the window.
Definition window.c:692
rect_t window_get_rect(window_t *win)
Get the window's rectangle in screen coordinates.
Definition window.c:447
uint64_t window_move(window_t *win, const rect_t *rect)
Move and/or resize the window.
Definition window.c:507
uint64_t window_set_focus(window_t *win)
Set the focus to the window.
Definition window.c:673
surface_id_t window_get_id(window_t *win)
Get the surface ID of the window.
Definition window.c:477
window_flags_t
Window flags.
Definition window.h:44
uint64_t window_invalidate_flush(window_t *win)
Flush invalidated rectangles to the DWM.
Definition window.c:570
surface_type_t window_get_type(window_t *win)
Get the surface type of the window.
Definition window.c:487
uint64_t window_set_timer(window_t *win, timer_flags_t flags, clock_t timeout)
Set the window timer.
Definition window.c:533
uint64_t window_dispatch(window_t *win, const event_t *event)
Dispatch an event to the window's elements.
Definition window.c:598
window_t * window_new(display_t *disp, const char *name, const rect_t *rect, surface_type_t type, window_flags_t flags, procedure_t procedure, void *private)
Allocate and initialize a new window.
Definition window.c:301
element_t * window_get_client_element(window_t *win)
Get the client element of the window.
Definition window.c:497
void window_free(window_t *win)
Free a window.
Definition window.c:415
display_t * window_get_display(window_t *win)
Get the display associated with the window.
Definition window.c:467
void window_invalidate(window_t *win, const rect_t *rect)
Invalidate a rectangle of the window.
Definition window.c:553
@ WINDOW_RESIZABLE
Allows window_move() to resize the window. TODO: Implement resize handles.
Definition window.h:47
@ WINDOW_NO_CONTROLS
Disable controls (close/minimize buttons), only applies if WINDOW_DECO is set.
Definition window.h:48
@ WINDOW_DECO
Enable decorations (titlebar, close/minimize buttons, etc).
Definition window.h:46
#define EINVAL
Invalid argument.
Definition errno.h:142
#define ENOMEM
Out of memory.
Definition errno.h:92
#define errno
Error number variable.
Definition errno.h:27
#define EPERM
Operation not permitted.
Definition errno.h:37
fd_t claim(key_t *key)
System call for claiming a shared file descriptor.
Definition claim.c:6
uint64_t close(fd_t fd)
System call for closing files.
Definition close.c:9
static void list_remove(list_t *list, list_entry_t *entry)
Removes a list entry from its current list.
Definition list.h:317
static void list_push(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list.
Definition list.h:345
static void list_entry_init(list_entry_t *entry)
Initializes a list entry.
Definition list.h:184
@ MOUSE_LEFT
Left mouse button.
Definition mouse.h:35
void * mmap(fd_t fd, void *address, uint64_t length, prot_t prot)
System call to map memory from a file.
Definition mmap.c:6
uint64_t munmap(void *address, uint64_t length)
System call to unmap mapped memory.
Definition munmap.c:6
@ PROT_READ
Memory can be read from.
Definition proc.h:172
@ PROT_WRITE
Memory can be written to.
Definition proc.h:173
#define NULL
Pointer error value.
Definition NULL.h:23
#define ERR
Integer error value.
Definition ERR.h:17
__UINT64_TYPE__ fd_t
A file descriptor.
Definition fd_t.h:12
__UINT64_TYPE__ clock_t
A nanosecond time.
Definition clock_t.h:13
void image_free(image_t *image)
Definition image.c:74
image_t * image_new(display_t *disp, const char *path)
Definition image.c:27
uint32_t pixel_t
Definition pixel.h:11
uint64_t(* procedure_t)(window_t *, element_t *, const event_t *)
Definition procedure.h:15
static uint64_t procedure(window_t *win, element_t *elem, const event_t *event)
Definition main.c:46
#define RECT_SHRINK(rect, margin)
Definition rect.h:81
#define RECT_AREA(rect)
Definition rect.h:40
#define RECT_INIT_DIM(x, y, width, height)
Definition rect.h:32
#define RECT_INIT(left, top, right, bottom)
Definition rect.h:26
#define RECT_HEIGHT(rect)
Definition rect.h:39
#define RECT_WIDTH(rect)
Definition rect.h:38
#define RECT_EXPAND_TO_CONTAIN(rect, other)
Definition rect.h:44
#define RECT_CONTAINS_POINT(rect, point)
Definition rect.h:61
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
_PUBLIC void * malloc(size_t size)
Definition malloc.c:5
_PUBLIC _NORETURN void abort(void)
Definition abort.c:7
_PUBLIC void free(void *ptr)
Definition free.c:11
_PUBLIC char * strcpy(char *_RESTRICT s1, const char *_RESTRICT s2)
Definition strcpy.c:3
size_t strnlen_s(const char *s, size_t maxsize)
Definition strnlen_s.c:4
surface_id_t target
Definition cmd.h:99
surface_id_t target
Definition cmd.h:64
surface_id_t target
Definition cmd.h:91
surface_id_t target
Definition cmd.h:70
rect_t rect
Definition cmd.h:71
char name[MAX_NAME]
Definition cmd.h:58
rect_t rect
Definition cmd.h:57
surface_type_t type
Definition cmd.h:56
surface_id_t target
Definition cmd.h:83
timer_flags_t flags
Definition cmd.h:84
surface_id_t target
Definition cmd.h:106
bool isFocused
Definition window.c:21
bool isVisible
Definition window.c:22
point_t dragOffset
Definition window.c:24
image_t * closeIcon
Definition window.c:25
image_t * minimizeIcon
Definition window.c:26
bool isDragging
Definition window.c:23
Opaque display structure.
Definition internal.h:61
mtx_t mutex
Definition internal.h:73
list_t windows
Definition internal.h:69
Drawable structure.
Definition drawable.h:35
Opaque element structure.
Definition internal.h:23
element_id_t id
Definition internal.h:27
Mouse event.
Definition event.h:151
point_t screenPos
Definition event.h:156
mouse_buttons_t pressed
Definition event.h:153
mouse_buttons_t held
Definition event.h:152
point_t pos
Definition event.h:155
Report event.
Definition event.h:180
surface_info_t info
Definition event.h:182
report_flags_t flags
Definition event.h:181
key_t shmemKey
Key that can be claim()ed to access the surface's shared memory.
Definition event.h:129
Event structure.
Definition event.h:271
event_report_t report
Definition event.h:281
levent_force_action_t lForceAction
Definition event.h:289
event_surface_new_t surfaceNew
Definition event.h:276
event_type_t type
Definition event.h:272
levent_action_t lAction
Definition event.h:288
event_mouse_t mouse
Definition event.h:278
levent_redraw_t lRedraw
Definition event.h:287
Library Action event.
Definition event.h:244
action_type_t type
Definition event.h:246
element_id_t source
Definition event.h:245
element_id_t dest
Definition event.h:256
Library Redraw event.
Definition event.h:233
element_id_t id
Definition event.h:234
int64_t y
Definition point.h:14
int64_t x
Definition point.h:13
Definition rect.h:13
int32_t bottom
Definition rect.h:17
int32_t top
Definition rect.h:15
int32_t right
Definition rect.h:16
int32_t left
Definition rect.h:14
surface_flags_t flags
Definition surface.h:61
pixel_t backgroundNormal
Definition theme.h:35
pixel_t backgroundSelectedEnd
Definition theme.h:37
pixel_t highlight
Definition theme.h:45
pixel_t backgroundUnselectedEnd
Definition theme.h:39
pixel_t backgroundUnselectedStart
Definition theme.h:38
pixel_t foregroundNormal
Definition theme.h:40
pixel_t shadow
Definition theme.h:46
pixel_t backgroundSelectedStart
Definition theme.h:36
Theme structure.
Definition theme.h:71
int64_t smallPadding
Definition theme.h:88
char iconMinimize[MAX_PATH]
Definition theme.h:82
theme_color_set_t deco
Definition theme.h:76
int64_t panelSize
Definition theme.h:86
int64_t titlebarSize
Definition theme.h:85
int64_t frameSize
Definition theme.h:83
char iconClose[MAX_PATH]
Definition theme.h:81
int64_t bigPadding
Definition theme.h:87
Opaque window structure.
Definition internal.h:44
list_entry_t entry
Definition internal.h:45
rect_t rect
Definition internal.h:48
rect_t invalidRect
Definition internal.h:49
char name[MAX_NAME]
Definition internal.h:47
window_flags_t flags
Definition internal.h:51
element_t * root
Definition internal.h:54
surface_type_t type
Definition internal.h:50
pixel_t * buffer
Definition internal.h:53
surface_id_t surface
Definition internal.h:52
element_t * clientElement
Definition internal.h:55
display_t * disp
Definition internal.h:46
static theme_t theme
Definition theme.c:12
_PUBLIC int mtx_lock(mtx_t *mtx)
Definition mtx_lock.c:11
_PUBLIC int mtx_unlock(mtx_t *mtx)
Definition mtx_unlock.c:10
static uint64_t window_deco_init(window_t *win, element_t *elem)
Definition window.c:172
#define WINDOW_DECO_BUTTON_AMOUNT
Definition window.c:17
#define WINDOW_DECO_CLOSE_BUTTON_ID
Definition window.c:12
static void window_deco_handle_dragging(window_t *win, element_t *elem, const event_mouse_t *event)
Definition window.c:79
rect_t window_get_local_rect(window_t *win)
Definition window.c:457
static void window_deco_titlebar_rect(window_t *win, element_t *elem, rect_t *rect)
Definition window.c:29
#define WINDOW_DECO_MINIMIZE_BUTTON_ID
Definition window.c:13
static void window_deco_draw_titlebar(window_t *win, element_t *elem, drawable_t *draw)
Definition window.c:53
#define WINDOW_CLIENT_ELEM_ID
Definition window.c:10
#define WINDOW_DECO_MINIMIZE_BUTTON_INDEX
Definition window.c:16
static void window_deco_redraw(window_t *win, element_t *elem)
Definition window.c:215
static void window_deco_button_rect(window_t *win, element_t *elem, rect_t *rect, uint64_t index)
Definition window.c:44
static uint64_t window_deco_procedure(window_t *win, element_t *elem, const event_t *event)
Definition window.c:267
#define WINDOW_DECO_CLOSE_BUTTON_INDEX
Definition window.c:15
static void window_deco_report(window_t *win, element_t *elem, const event_report_t *report)
Definition window.c:250
#define WINDOW_DECO_ELEM_ID
Definition window.c:11
static void window_deco_free(element_t *elem)
Definition window.c:198
static uint64_t window_deco_init_controls(window_t *win, element_t *elem, deco_private_t *private)
Definition window.c:113
static void window_deco_action(window_t *win, const levent_action_t *action)
Definition window.c:232