PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
window.h
Go to the documentation of this file.
1#ifndef PATCHWORK_WIN_H
2#define PATCHWORK_WIN_H 1
3
4#include "display.h"
5#include "pixel.h"
6#include "procedure.h"
7#include "surface.h"
8
9#if defined(__cplusplus)
10extern "C"
11{
12#endif
13
14/**
15 * @brief Window.
16 * @defgroup libpatchwork_window Window
17 * @ingroup libpatchwork
18 *
19 * A window represents a rectangular area on the screen that can display content and receive user input, this includes
20 * panels, cursors, wallpapers and normal application windows. It can be considered to be the client side implementation
21 * of the Desktop Window Managers surfaces.
22 *
23 * If `WINDOW_DECO` flag is set, the window will have decorations (titlebar, close/minimize buttons, etc) which will
24 * serve as the root element with the client element as a child. This client element is then what the application will
25 * draw to and receive events from.
26 *
27 * The window system is NOT thread safe, it is the responsibility of the application to ensure that windows are only
28 * accessed from a single thread at a time.
29 *
30 * @{
31 */
32
33/**
34 * @brief Opaque window structure.
35 * @struct window_t
36 */
37typedef struct window window_t;
38
39/**
40 * @brief Window flags.
41 * @enum window_flags_t
42 */
43typedef enum window_flags
44{
46 WINDOW_DECO = 1 << 0, ///< Enable decorations (titlebar, close/minimize buttons, etc).
47 WINDOW_RESIZABLE = 1 << 1, ///< Allows `window_move()` to resize the window. @todo Implement resize handles.
48 WINDOW_NO_CONTROLS = 1 << 2 ///< Disable controls (close/minimize buttons), only applies if `WINDOW_DECO` is set.
50
51/**
52 * @brief Allocate and initialize a new window.
53 *
54 * @param disp The connection to the DWM.
55 * @param name The name of the window.
56 * @param rect The rectangle defining the position and size of the window.
57 * @param type The type of surface to create, (e.g., panels, cursors, wallpapers, normal windows, etc).
58 * @param flags The window flags.
59 * @param procedure The procedure for the window's client element.
60 * @param private Private data to associate with the window's client element.
61 * @return On success, the new window. On failure, returns `NULL` and `errno` is set.
62 */
63window_t* window_new(display_t* disp, const char* name, const rect_t* rect, surface_type_t type, window_flags_t flags,
64 procedure_t procedure, void* private);
65
66/**
67 * @brief Free a window.
68 *
69 * @param win The window to free.
70 */
71void window_free(window_t* win);
72
73/**
74 * @brief Get the window's rectangle in screen coordinates.
75 *
76 * Equivalent to `RECT_INIT_DIM(x, y, width, height)`.
77 *
78 * @param win The window.
79 * @return The window's rectangle.
80 */
82
83/**
84 * @brief Get the window's rectangle in local coordinates.
85 *
86 * Equivalent to `RECT_INIT_DIM(0, 0, width, height)`.
87 *
88 * @param win The window.
89 * @return The window's local rectangle.
90 */
92
93/**
94 * @brief Get the display associated with the window.
95 *
96 * @param win The window.
97 * @return The display.
98 */
100
101/**
102 * @brief Get the surface ID of the window.
103 *
104 * @param win The window.
105 * @return The surface ID or `SURFACE_ID_NONE` if `win` is `NULL`.
106 */
108
109/**
110 * @brief Get the surface type of the window.
111 *
112 * @param win The window.
113 * @return The surface type or `SURFACE_NONE` if `win` is `NULL`.
114 */
116
117/**
118 * @brief Get the client element of the window.
119 *
120 * The client element is the window element that applications should draw to and receive events from, if the window has
121 * decorations this will be the child of the deco element, otherwise it will be the root element.
122 *
123 * @param win The window.
124 * @return The client element.
125 */
127
128/**
129 * @brief Move and/or resize the window.
130 *
131 * @param win The window.
132 * @param rect The new screen rectangle for the window.
133 * @return On success, `0`. On failure, `ERR` and `errno` is set.
134 */
135uint64_t window_move(window_t* win, const rect_t* rect);
136
137/**
138 * @brief Set the window timer.
139 *
140 * When the timer fires an event of type `EVENT_TIMER` will be sent to the window's procedure.
141 *
142 * @param win The window.
143 * @param flags The timer flags.
144 * @param timeout The timer timeout in clock ticks, or `CLOCKS_NEVER` to disable the timer. Setting a new timer will
145 * overide the previous timer if one is set.
146 * @return On success, `0`. On failure, `ERR` and `errno` is set.
147 */
149
150/**
151 * @brief Invalidate a rectangle of the window.
152 *
153 * This is used to notify the DWM of the change not to redraw the specified rectangle.
154 *
155 * The changes will be flushed to the DWM when `window_invalidate_flush()` is called.
156 *
157 * @param win The window.
158 * @param rect The rectangle to invalidate, in local coordinates.
159 */
160void window_invalidate(window_t* win, const rect_t* rect);
161
162/**
163 * @brief Flush invalidated rectangles to the DWM.
164 *
165 * This will push a command to the display to notify the DWM of all previously invalidated rectangles.
166 *
167 * In order for the DWM to actually redraw the invalidated region, the commands must be flushed to the DWM using
168 * `display_cmds_flush()`.
169 *
170 * @param win The window.
171 * @return On success, `0`. On failure, `ERR` and `errno` is set.
172 */
174
175/**
176 * @brief Dispatch an event to the window's elements.
177 *
178 * Most events will be sent to the root element, which will then propagate the event to its children.
179 *
180 * Some events will be handled specially, for example `EVENT_LIB_FORCE_ACTION` will be sent directly to the specified
181 * element.
182 *
183 * @param win The window.
184 * @param event The event to dispatch.
185 * @return The result of the window procedure.
186 */
187uint64_t window_dispatch(window_t* win, const event_t* event);
188
189/**
190 * @brief Set the focus to the window.
191 *
192 * Causes the window to be moved to the front and to, for example, receive keyboard input.
193 *
194 * @param win The window.
195 * @return On success, `0`. On failure, `ERR` and `errno` is set.
196 */
198
199/**
200 * @brief Set the visibility of the window.
201 *
202 * Windows are invisible by default, so they must be made visible after creation to be seen.
203 *
204 * Will also dispatch all currently pending `EVENT_LIB_REDRAW` events for the window.
205 *
206 * @param win The window.
207 * @param isVisible Whether the window should be visible.
208 * @return On success, `0`. On failure, `ERR` and `errno` is set.
209 */
210uint64_t window_set_visible(window_t* win, bool isVisible);
211
212/** @} */
213
214#if defined(__cplusplus)
215}
216#endif
217
218#endif
timer_flags_t
Definition cmd.h:75
surface_type_t
Surface types.
Definition surface.h:33
uint64_t surface_id_t
Definition surface.h:53
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
rect_t window_content_rect(window_t *win)
Get the window's rectangle in local coordinates.
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_NONE
Definition window.h:45
@ WINDOW_RESIZABLE
Allows window_move() to resize the window.
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
__UINT64_TYPE__ clock_t
A nanosecond time.
Definition clock_t.h:13
static const path_flag_t flags[]
Definition path.c:42
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
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
Opaque display structure.
Definition internal.h:61
Opaque element structure.
Definition internal.h:23
Event structure.
Definition event.h:271
Definition rect.h:13
Opaque window structure.
Definition internal.h:44