PatchworkOS  c9fea19
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/io.h>
12#include <sys/kbd.h>
13#include <sys/mouse.h>
14
15#if defined(__cplusplus)
16extern "C"
17{
18#endif
19
20/**
21 * @brief Desktop Window Manager Events
22 * @defgroup libpatchwork_events Events
23 * @ingroup libpatchwork
24 *
25 * @{
26 */
27
28/**
29 * @brief Report flags.
30 *
31 * Used to specify what information changed in a report event.
32 */
33typedef enum
34{
36 REPORT_RECT = 1 << 0,
39 REPORT_NAME = 1 << 3,
41
42/**
43 * @brief Action type.
44 *
45 * Used to specify the type of an action event.
46 */
54
55/**
56 * @brief Event type.
57 *
58 * Used to identify the type of an event.
59 *
60 * Events are divided into 4 categories:
61 * - Standard events (0-127): Sent by the DWM to ONLY the display or surface that the event is targeted at, sent by
62 * default.
63 * - Global events (128-255): Sent by the DWM to all displays, not sent by default.
64 * - Library events (256-511): Sent by the libpatchwork library to elements using the library, cant be subscribed to or
65 * unsubscribed from.
66 * - Internal Library events (512-1023): Used internally by libpatchwork, should not be used by programs.
67 * - User events (1024-65535): Defined by individual programs, cant be subscribed to or unsubscribed from.
68 *
69 * @todo Global events are a security mess, when per-process namespaces stabilize we should consider if this could be
70 * done better.
71 */
73
74/**
75 * @brief Event bitmask type.
76 *
77 * Used to decide what events will be received by a display, only applicable to events sent by the DWM.
78 * By default events 0-127 inclusive are received (the first uint64_t is by default UINT64_MAX)
79 */
81
82#define EVENT_SCREEN_INFO 0
83#define EVENT_SURFACE_NEW 1
84#define EVENT_KBD 2
85#define EVENT_MOUSE 3
86#define EVENT_TIMER 4
87#define EVENT_CURSOR_ENTER 5
88#define EVENT_CURSOR_LEAVE 6
89#define EVENT_REPORT 7
90
91#define EVENT_GLOBAL_ATTACH 128
92#define EVENT_GLOBAL_DETACH 129
93#define EVENT_GLOBAL_REPORT 130
94#define EVENT_GLOBAL_KBD 131
95#define EVENT_GLOBAL_MOUSE 132
96
97#define DWM_MAX_EVENT 256
98
99#define EVENT_LIB_INIT 256
100#define EVENT_LIB_DEINIT 257
101#define EVENT_LIB_REDRAW 258
102#define EVENT_LIB_ACTION 259
103#define EVENT_LIB_QUIT 260
104#define EVENT_LIB_FORCE_ACTION 261
105
106#define EVENT_LIB_INTERNAL_WAKE 512
107
108#define EVENT_USER_START 1024
109#define EVENT_USER_END 65535
110
111/**
112 * @brief Screen Info event.
113 *
114 * Sent as the response to the `CMD_SCREEN_INFO` command.
115 */
121
122/**
123 * @brief Surface New event.
124 *
125 * Sent as the response to the `CMD_SURFACE_NEW` command.
126 */
127typedef struct
128{
129 key_t shmemKey; ///< Key that can be `claim()`ed to access the surface's shared memory.
131
132/**
133 * @brief Keyboard event.
134 *
135 * Sent when a key is pressed or released.
136 */
144
145/**
146 * @brief Mouse event.
147 *
148 * Sent when the mouse is moved or a button is pressed or released.
149 */
159
160/**
161 * @brief Cursor Enter event.
162 *
163 * Sent when the cursor enters a surface.
164 */
166
167/**
168 * @brief Cursor Leave event.
169 *
170 * Sent when the cursor leaves a surface.
171 */
173
174/**
175 * @brief Report event.
176 *
177 * Sent when a surface's information changes.
178 */
184
185/**
186 * @brief Global Attach event.
187 *
188 * Sent when a display attaches to the DWM.
189 */
194
195/**
196 * @brief Global Detach event.
197 *
198 * Sent when a display detaches from the DWM.
199 */
204
205/**
206 * @brief Global Report event.
207 *
208 * Sent when any surface's information changes.
209 */
211
212/**
213 * @brief Global Keyboard event.
214 *
215 * Sent when a key is pressed or released regardless of which display is focused.
216 */
218
219/**
220 * @brief Global Mouse event.
221 *
222 * Sent when the mouse is moved or a button is pressed or released regardless of which display is focused or where
223 * the cursor is.
224 */
226
227/**
228 * @brief Library Redraw event.
229 *
230 * Sent to an element when it should redraw itself.
231 */
232typedef struct
233{
235 bool shouldPropagate; ///< Whether the redraw event should be propagated to child elements.
237
238/**
239 * @brief Library Action event.
240 *
241 * Sent to an element when an action occurs, for example a button element being clicked.
242 */
248
249/**
250 * @brief Library Force Action event.
251 *
252 * Sent to an element to force it to act as if an action occurred.
253 */
259
260/**
261 * @brief Maximum size of event data.
262 */
263#define EVENT_MAX_DATA 128
264
265/**
266 * @brief Event structure.
267 *
268 * Represents an event sent by the DWM or libpatchwork.
269 */
293
294#ifdef static_assert
295static_assert(sizeof(event_t) == 144, "invalid event_t size");
296#endif
297
298/** @} */
299
300#if defined(__cplusplus)
301}
302#endif
303
304#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:172
event_mouse_t event_global_mouse_t
Global Mouse event.
Definition event.h:225
report_flags_t
Report flags.
Definition event.h:34
#define EVENT_MAX_DATA
Maximum size of event data.
Definition event.h:263
uint64_t event_bitmask_t[4]
Event bitmask type.
Definition event.h:80
event_report_t event_global_report_t
Global Report event.
Definition event.h:210
action_type_t
Action type.
Definition event.h:48
uint16_t event_type_t
Event type.
Definition event.h:72
event_mouse_t event_cursor_enter_t
Cursor Enter event.
Definition event.h:165
event_kbd_t event_global_kbd_t
Global Keyboard event.
Definition event.h:217
@ REPORT_NONE
Definition event.h:35
@ REPORT_IS_FOCUSED
Definition event.h:38
@ REPORT_NAME
Definition event.h:39
@ REPORT_IS_VISIBLE
Definition event.h:37
@ REPORT_RECT
Definition event.h:36
@ ACTION_PRESS
Definition event.h:51
@ ACTION_RELEASE
Definition event.h:50
@ ACTION_CANCEL
Definition event.h:52
@ ACTION_NONE
Definition event.h:49
uint64_t surface_id_t
Definition surface.h:53
keycode_t
Keyboard keycode type.
Definition kbd.h:27
kbd_mods_t
Keyboard modifiers type.
Definition kbd.h:297
kbd_event_type_t
Keyboard event type.
Definition kbd.h:286
mouse_buttons_t
Mouse buttons enum.
Definition mouse.h:31
__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:191
surface_info_t info
Definition event.h:192
Global Detach event.
Definition event.h:201
surface_info_t info
Definition event.h:202
Keyboard event.
Definition event.h:138
kbd_mods_t mods
Definition event.h:140
kbd_event_type_t type
Definition event.h:139
keycode_t code
Definition event.h:141
char ascii
Definition event.h:142
Library Action event.
Definition event.h:244
action_type_t type
Definition event.h:246
element_id_t source
Definition event.h:245
Library Force Action event.
Definition event.h:255
action_type_t action
Definition event.h:257
element_id_t dest
Definition event.h:256
Library Redraw event.
Definition event.h:233
bool shouldPropagate
Whether the redraw event should be propagated to child elements.
Definition event.h:235
element_id_t id
Definition event.h:234
Mouse event.
Definition event.h:151
point_t screenPos
Definition event.h:156
point_t delta
Definition event.h:157
mouse_buttons_t pressed
Definition event.h:153
mouse_buttons_t held
Definition event.h:152
point_t pos
Definition event.h:155
mouse_buttons_t released
Definition event.h:154
Report event.
Definition event.h:180
surface_info_t info
Definition event.h:182
report_flags_t flags
Definition event.h:181
Screen Info event.
Definition event.h:117
uint64_t width
Definition event.h:118
uint64_t height
Definition event.h:119
Surface New event.
Definition event.h:128
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
surface_id_t target
Definition event.h:273
event_global_detach_t globalDetach
Definition event.h:283
event_lib_action_t libAction
Definition event.h:288
event_global_mouse_t globalMouse
Definition event.h:286
event_kbd_t kbd
Definition event.h:277
event_lib_redraw_t libRedraw
Definition event.h:287
event_report_t report
Definition event.h:281
event_surface_new_t surfaceNew
Definition event.h:276
event_cursor_leave_t cursorLeave
Definition event.h:280
event_cursor_enter_t cursorEnter
Definition event.h:279
event_type_t type
Definition event.h:272
event_global_attach_t globalAttach
Definition event.h:282
event_mouse_t mouse
Definition event.h:278
event_lib_force_action_t libForceAction
Definition event.h:289
event_global_report_t globalReport
Definition event.h:284
event_global_kbd_t globalKbd
Definition event.h:285
event_screen_info_t screenInfo
Definition event.h:275
Key type.
Definition io.h:454