PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
event.h
Go to the documentation of this file.
1#ifndef PATCHWORK_EVENT_H
2#define PATCHWORK_EVENT_H 1
3
4#include "element_id.h"
5#include "point.h"
6#include "rect.h"
7#include "surface.h"
8
9#include <assert.h>
10#include <stdint.h>
11#include <sys/fs.h>
12#include <sys/kbd.h>
13
14#if defined(__cplusplus)
15extern "C"
16{
17#endif
18
19/**
20 * @brief Desktop Window Manager Events
21 * @defgroup libpatchwork_events Events
22 * @ingroup libpatchwork
23 *
24 * @{
25 */
26
27/**
28 * @brief Report flags.
29 *
30 * Used to specify what information changed in a report event.
31 */
32typedef enum
33{
35 REPORT_RECT = 1 << 0,
38 REPORT_NAME = 1 << 3,
40
41/**
42 * @brief Action type.
43 *
44 * Used to specify the type of an action event.
45 */
53
54/**
55 * @brief Event type.
56 *
57 * Used to identify the type of an event.
58 *
59 * Events are divided into 4 categories:
60 * - Standard events (0-127): Sent by the DWM to ONLY the display or surface that the event is targeted at, sent by
61 * default.
62 * - Global events (128-255): Sent by the DWM to all displays, not sent by default.
63 * - Library events (256-511): Sent by the libpatchwork library to elements using the library, cant be subscribed to or
64 * unsubscribed from.
65 * - Internal Library events (512-1023): Used internally by libpatchwork, should not be used by programs.
66 * - User events (1024-65535): Defined by individual programs, cant be subscribed to or unsubscribed from.
67 *
68 * @todo Global events are a security mess, when per-process namespaces stabilize we should consider if this could be
69 * done better.
70 */
72
73/**
74 * @brief Event bitmask type.
75 *
76 * Used to decide what events will be received by a display, only applicable to events sent by the DWM.
77 * By default events 0-127 inclusive are received (the first uint64_t is by default UINT64_MAX)
78 */
80
81#define EVENT_SCREEN_INFO 0
82#define EVENT_SURFACE_NEW 1
83#define EVENT_KBD 2
84#define EVENT_MOUSE 3
85#define EVENT_TIMER 4
86#define EVENT_CURSOR_ENTER 5
87#define EVENT_CURSOR_LEAVE 6
88#define EVENT_REPORT 7
89
90#define EVENT_GLOBAL_ATTACH 128
91#define EVENT_GLOBAL_DETACH 129
92#define EVENT_GLOBAL_REPORT 130
93#define EVENT_GLOBAL_KBD 131
94#define EVENT_GLOBAL_MOUSE 132
95
96#define DWM_MAX_EVENT 256
97
98#define EVENT_LIB_INIT 256
99#define EVENT_LIB_DEINIT 257
100#define EVENT_LIB_REDRAW 258
101#define EVENT_LIB_ACTION 259
102#define EVENT_LIB_QUIT 260
103#define EVENT_LIB_FORCE_ACTION 261
104
105#define EVENT_LIB_INTERNAL_WAKE 512
106
107#define EVENT_USER_START 1024
108#define EVENT_USER_END 65535
109
110/**
111 * @brief Screen Info event.
112 *
113 * Sent as the response to the `CMD_SCREEN_INFO` command.
114 */
120
121/**
122 * @brief Surface New event.
123 *
124 * Sent as the response to the `CMD_SURFACE_NEW` command.
125 */
126typedef struct
127{
128 char shmemKey[KEY_128BIT]; ///< Key that can be `claim()`ed to access the surface's shared memory.
130
131/**
132 * @brief Keyboard event type.
133 *
134 */
135typedef enum
136{
137 KBD_PRESS = 0, ///< Key press event
138 KBD_RELEASE = 1 ///< Key release event
140
141/**
142 * @brief Keyboard modifiers type.
143 *
144 */
145typedef enum
146{
147 KBD_MOD_NONE = 0, ///< No modifier
148 KBD_MOD_CAPS = 1 << 0, ///< Caps Lock modifier
149 KBD_MOD_SHIFT = 1 << 1, ///< Shift modifier
150 KBD_MOD_CTRL = 1 << 2, ///< Control modifier
151 KBD_MOD_ALT = 1 << 3, ///< Alt modifier
152 KBD_MOD_SUPER = 1 << 4, ///< Super (Windows/Command) modifier
153} kbd_mods_t;
154
155/**
156 * @brief Keyboard event.
157 *
158 * Sent when a key is pressed or released.
159 */
167
168/**
169 * @brief Mouse buttons enum.
170 *
171 */
172typedef enum
173{
174 MOUSE_NONE = 0, ///< None
175 MOUSE_LEFT = (1 << 1), ///< Left mouse button
176 MOUSE_RIGHT = (1 << 2), ///< Right mouse button
177 MOUSE_MIDDLE = (1 << 3), ///< Middle mouse button
179
180/**
181 * @brief Mouse event.
182 *
183 * Sent when the mouse is moved or a button is pressed or released.
184 */
194
195/**
196 * @brief Cursor Enter event.
197 *
198 * Sent when the cursor enters a surface.
199 */
201
202/**
203 * @brief Cursor Leave event.
204 *
205 * Sent when the cursor leaves a surface.
206 */
208
209/**
210 * @brief Report event.
211 *
212 * Sent when a surface's information changes.
213 */
219
220/**
221 * @brief Global Attach event.
222 *
223 * Sent when a display attaches to the DWM.
224 */
229
230/**
231 * @brief Global Detach event.
232 *
233 * Sent when a display detaches from the DWM.
234 */
239
240/**
241 * @brief Global Report event.
242 *
243 * Sent when any surface's information changes.
244 */
246
247/**
248 * @brief Global Keyboard event.
249 *
250 * Sent when a key is pressed or released regardless of which display is focused.
251 */
253
254/**
255 * @brief Global Mouse event.
256 *
257 * Sent when the mouse is moved or a button is pressed or released regardless of which display is focused or where
258 * the cursor is.
259 */
261
262/**
263 * @brief Library Redraw event.
264 *
265 * Sent to an element when it should redraw itself.
266 */
267typedef struct
268{
270 bool shouldPropagate; ///< Whether the redraw event should be propagated to child elements.
272
273/**
274 * @brief Library Action event.
275 *
276 * Sent to an element when an action occurs, for example a button element being clicked.
277 */
283
284/**
285 * @brief Library Force Action event.
286 *
287 * Sent to an element to force it to act as if an action occurred.
288 */
294
295/**
296 * @brief Maximum size of event data.
297 */
298#define EVENT_MAX_DATA 128
299
300/**
301 * @brief Event structure.
302 *
303 * Represents an event sent by the DWM or libpatchwork.
304 */
328
329#ifdef static_assert
330static_assert(sizeof(event_t) == 144, "invalid event_t size");
331#endif
332
333/** @} */
334
335#if defined(__cplusplus)
336}
337#endif
338
339#endif
uint64_t element_id_t
Element identifier type.
Definition element_id.h:23
event_mouse_t event_cursor_leave_t
Cursor Leave event.
Definition event.h:207
event_mouse_t event_global_mouse_t
Global Mouse event.
Definition event.h:260
report_flags_t
Report flags.
Definition event.h:33
#define EVENT_MAX_DATA
Maximum size of event data.
Definition event.h:298
kbd_mods_t
Keyboard modifiers type.
Definition event.h:146
uint64_t event_bitmask_t[4]
Event bitmask type.
Definition event.h:79
event_report_t event_global_report_t
Global Report event.
Definition event.h:245
kbd_event_type_t
Keyboard event type.
Definition event.h:136
action_type_t
Action type.
Definition event.h:47
uint16_t event_type_t
Event type.
Definition event.h:71
event_mouse_t event_cursor_enter_t
Cursor Enter event.
Definition event.h:200
event_kbd_t event_global_kbd_t
Global Keyboard event.
Definition event.h:252
mouse_buttons_t
Mouse buttons enum.
Definition event.h:173
@ REPORT_NONE
Definition event.h:34
@ REPORT_IS_FOCUSED
Definition event.h:37
@ REPORT_NAME
Definition event.h:38
@ REPORT_IS_VISIBLE
Definition event.h:36
@ REPORT_RECT
Definition event.h:35
@ KBD_MOD_SUPER
Super (Windows/Command) modifier.
Definition event.h:152
@ KBD_MOD_CAPS
Caps Lock modifier.
Definition event.h:148
@ KBD_MOD_NONE
No modifier.
Definition event.h:147
@ KBD_MOD_CTRL
Control modifier.
Definition event.h:150
@ KBD_MOD_ALT
Alt modifier.
Definition event.h:151
@ KBD_MOD_SHIFT
Shift modifier.
Definition event.h:149
@ KBD_RELEASE
Key release event.
Definition event.h:138
@ KBD_PRESS
Key press event.
Definition event.h:137
@ ACTION_PRESS
Definition event.h:50
@ ACTION_RELEASE
Definition event.h:49
@ ACTION_CANCEL
Definition event.h:51
@ ACTION_NONE
Definition event.h:48
@ MOUSE_RIGHT
Right mouse button.
Definition event.h:176
@ MOUSE_NONE
None.
Definition event.h:174
@ MOUSE_MIDDLE
Middle mouse button.
Definition event.h:177
@ MOUSE_LEFT
Left mouse button.
Definition event.h:175
uint64_t surface_id_t
Definition surface.h:53
#define KEY_128BIT
The size of a buffer needed to hold a 128-bit key.
Definition fs.h:520
keycode_t
Keyboard keycode type.
Definition kbd.h:29
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
__UINT16_TYPE__ uint16_t
Definition stdint.h:13
Global Attach event.
Definition event.h:226
surface_info_t info
Definition event.h:227
Global Detach event.
Definition event.h:236
surface_info_t info
Definition event.h:237
Keyboard event.
Definition event.h:161
kbd_mods_t mods
Definition event.h:163
kbd_event_type_t type
Definition event.h:162
keycode_t code
Definition event.h:164
char ascii
Definition event.h:165
Library Action event.
Definition event.h:279
action_type_t type
Definition event.h:281
element_id_t source
Definition event.h:280
Library Force Action event.
Definition event.h:290
action_type_t action
Definition event.h:292
element_id_t dest
Definition event.h:291
Library Redraw event.
Definition event.h:268
bool shouldPropagate
Whether the redraw event should be propagated to child elements.
Definition event.h:270
element_id_t id
Definition event.h:269
Mouse event.
Definition event.h:186
point_t screenPos
Definition event.h:191
point_t delta
Definition event.h:192
mouse_buttons_t pressed
Definition event.h:188
mouse_buttons_t held
Definition event.h:187
point_t pos
Definition event.h:190
mouse_buttons_t released
Definition event.h:189
Report event.
Definition event.h:215
surface_info_t info
Definition event.h:217
report_flags_t flags
Definition event.h:216
Screen Info event.
Definition event.h:116
uint64_t width
Definition event.h:117
uint64_t height
Definition event.h:118
Surface New event.
Definition event.h:127
Event structure.
Definition event.h:306
surface_id_t target
Definition event.h:308
event_global_detach_t globalDetach
Definition event.h:318
event_lib_action_t libAction
Definition event.h:323
event_global_mouse_t globalMouse
Definition event.h:321
event_kbd_t kbd
Definition event.h:312
event_lib_redraw_t libRedraw
Definition event.h:322
event_report_t report
Definition event.h:316
event_surface_new_t surfaceNew
Definition event.h:311
event_cursor_leave_t cursorLeave
Definition event.h:315
event_cursor_enter_t cursorEnter
Definition event.h:314
event_type_t type
Definition event.h:307
event_global_attach_t globalAttach
Definition event.h:317
event_mouse_t mouse
Definition event.h:313
event_lib_force_action_t libForceAction
Definition event.h:324
event_global_report_t globalReport
Definition event.h:319
event_global_kbd_t globalKbd
Definition event.h:320
event_screen_info_t screenInfo
Definition event.h:310