PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
display.h
Go to the documentation of this file.
1#ifndef PATCHWORK_DISPLAY_H
2#define PATCHWORK_DISPLAY_H 1
3
4#include "cmd.h"
5#include "event.h"
6#include "rect.h"
7
8#include <stdbool.h>
9#include <stdint.h>
10#include <sys/proc.h>
11
12#if defined(__cplusplus)
13extern "C"
14{
15#endif
16
17/**
18 * @brief Display connection.
19 * @defgroup libpatchwork_display Display Connection
20 * @ingroup libpatchwork
21 *
22 * A display represents a connection to the Desktop Window Manager (DWM).
23 *
24 * @{
25 */
26
27/**
28 * @brief Opaque display structure.
29 * @struct display_t
30 */
31typedef struct display display_t;
32
33/**
34 * @brief Create a new display connection.
35 *
36 * @return On success, a The display connection. On failure, `NULL` and `errno` is set.
37 */
39
40/**
41 * @brief Free a display connection.
42 *
43 * @param disp The display connection.
44 */
45void display_free(display_t* disp);
46
47/**
48 * @brief Check if the display connection is still connected.
49 *
50 * @param disp The display connection.
51 * @return `true` if connected, `false` otherwise.
52 */
54
55/**
56 * @brief Disconnect the display connection.
57 *
58 * After calling this function, the display connection will be marked as disconnected and no further commands or
59 * events will be processed.
60 *
61 * Will not free the display connection, use `display_free()` for that.
62 *
63 * @param disp The display connection.
64 */
66
67/**
68 * @brief Allocate a section of the displays command buffer.
69 *
70 * The display batches commands together in its command buffer, where each command is prefixed with a `cmd_header_t` and
71 * has a variable size.
72 *
73 * @param disp The display connection.
74 * @param type Type of command to allocate.
75 * @param size Size of the command data to allocate.
76 * @return Pointer to the allocated command data, or `NULL` on failure and `errno` is set.
77 */
78void* display_cmd_alloc(display_t* disp, cmd_type_t type, uint64_t size);
79
80/**
81 * @brief Flush the display's command buffer.
82 *
83 * This will send all queued commands to the DWM.
84 *
85 * @param disp The display connection.
86 */
88
89/**
90 * @brief Retrieve the next event from the display connection.
91 *
92 * @param disp The display connection.
93 * @param event Output pointer to store the retrieved event.
94 * @param timeout Maximum time to wait for an event, if `CLOCKS_NEVER` will wait indefinitely.
95 * @return On success, `0`. On failure, `ERR` and `errno` is set.
96 */
97uint64_t display_next(display_t* disp, event_t* event, clock_t timeout);
98
99/**
100 * @brief Poll the display connection for events together with other file descriptors.
101 *
102 * @param disp The display connection.
103 * @param fds Array of file descriptors to poll alongside the display connection.
104 * @param nfds Number of file descriptors in the array.
105 * @param timeout Maximum time to wait for an event, if `CLOCKS_NEVER` will wait indefinitely.
106 * @return On success, number of file descriptors with events (not including the display connection). On failure,
107 * returns `ERR` and `errno` is set.
108 */
109uint64_t display_poll(display_t* disp, pollfd_t* fds, uint64_t nfds, clock_t timeout);
110
111/**
112 * @brief Push an event to the display's internal event queue.
113 *
114 * This will not send the event to the DWM, instead it will be stored in the display's internal event queue and can be
115 * retrieved using `display_next()`.
116 *
117 * @param disp The display connection.
118 * @param target Target surface ID for the event.
119 * @param type Type of event.
120 * @param data Pointer to the event data, can be `NULL` if `size` is `0`.
121 * @param size Size of the event data, must be less than `EVENT_MAX_DATA`.
122 */
123void display_push(display_t* disp, surface_id_t target, event_type_t type, void* data, uint64_t size);
124
125/**
126 * @brief Wait for the display to receive an event of the expected type.
127 *
128 * This function will block until an event of the expected type is received.
129 *
130 * Any other events received while waiting will be pushed back to the display's internal event queue.
131 *
132 * @param disp The display connection.
133 * @param event Output pointer to store the retrieved event.
134 * @param expected The expected event type to wait for.
135 * @return On success, `0`. On failure, `ERR` and `errno` is set.
136 */
137uint64_t display_wait(display_t* disp, event_t* event, event_type_t expected);
138
139/**
140 * @brief Emit an event to a target surface.
141 *
142 * This function will construct an event and dispatch it to the target surface.
143 *
144 * @param disp The display connection.
145 * @param target Target surface ID for the event, if `SURFACE_ID_NONE` the event is sent to all surfaces.
146 * @param type Type of event.
147 * @param data Pointer to the event data, can be `NULL` if `size` is `0`.
148 * @param size Size of the event data, must be less than `EVENT_MAX_DATA`.
149 * @return On success, `0`. On failure, `ERR` and `errno` is set.
150 */
151uint64_t display_emit(display_t* disp, surface_id_t target, event_type_t type, void* data, uint64_t size);
152
153/**
154 * @brief Dispatch an event to the appropriate surface.
155 *
156 * Will flush the display's command buffer after dispatching the event.
157 *
158 * @param disp The display connection.
159 * @param event The event to dispatch.
160 * @return On success, `0`. On failure, `ERR` and `errno` is set.
161 */
162uint64_t display_dispatch(display_t* disp, const event_t* event);
163
164/**
165 * @brief Dispatch all events currently in the display's internal event queue of a specific type and target.
166 *
167 * @param disp The display connection.
168 * @param type The event type to check for.
169 * @param target The target surface ID for the events, if `SURFACE_ID_NONE` all events are dispatched.
170 * @return On success, `0`. On failure, `ERR` and `errno` is set.
171 */
173
174/**
175 * @brief Subscribe to events of a specific type.
176 *
177 * Should only be used for events sent by the DWM.
178 *
179 * @param disp The display connection.
180 * @param type The event type to subscribe to.
181 */
183
184/**
185 * @brief Unsubscribe from events of a specific type.
186 *
187 * Should only be used for events sent by the DWM.
188 *
189 * @param disp The display connection.
190 * @param type The event type to unsubscribe from.
191 */
193
194/**
195 * @brief Get information about a surface.
196 *
197 * Uses a `CMD_SURFACE_REPORT` command to request information about the specified surface from the DWM.
198 *
199 * @param disp The display connection.
200 * @param id The surface ID to query.
201 * @param info Output pointer to store the surface information.
202 * @return On success, `0`. On failure, `ERR` and `errno` is set.
203 */
205
206/**
207 * @brief Set the focus to a surface.
208 *
209 * Can apply to any surface, not just ones owned by the client.
210 *
211 * @param disp The display connection.
212 * @param id The surface ID to set focus to.
213 */
215
216/**
217 * @brief Set the visibility of a surface.
218 *
219 * Can apply to any surface, not just ones owned by the client.
220 *
221 * @param disp The display connection.
222 * @param id The surface ID to set visibility for.
223 * @param isVisible Whether the surface should be visible.
224 */
225uint64_t display_set_is_visible(display_t* disp, surface_id_t id, bool isVisible);
226
227/**
228 * @brief Get the rectangle of a screen.
229 *
230 * @param disp The display connection.
231 * @param rect Output pointer to store the rectangle of the screen.
232 * @param index Index of the screen to query, only `0` is supported currently.
233 * @return On success, `0`. On failure, `ERR` and `errno` is set.
234 */
236
237/** @} */
238
239#if defined(__cplusplus)
240}
241#endif
242
243#endif
cmd_type_t
Definition cmd.h:23
static fd_t data
Definition dwm.c:21
void display_disconnect(display_t *disp)
Disconnect the display connection.
Definition display.c:159
uint64_t display_poll(display_t *disp, pollfd_t *fds, uint64_t nfds, clock_t timeout)
Poll the display connection for events together with other file descriptors.
Definition display.c:266
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:171
uint64_t display_next(display_t *disp, event_t *event, clock_t timeout)
Retrieve the next event from the display connection.
Definition display.c:211
uint64_t display_unsubscribe(display_t *disp, event_type_t type)
Unsubscribe from events of a specific type.
Definition display.c:498
void display_cmds_flush(display_t *disp)
Flush the display's command buffer.
Definition display.c:196
uint64_t display_dispatch(display_t *disp, const event_t *event)
Dispatch an event to the appropriate surface.
Definition display.c:410
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:321
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:339
uint64_t display_get_screen(display_t *disp, rect_t *rect, uint64_t index)
Get the rectangle of a screen.
Definition display.c:573
void display_free(display_t *disp)
Free a display connection.
Definition display.c:111
uint64_t display_set_focus(display_t *disp, surface_id_t id)
Set the focus to a surface.
Definition display.c:544
bool display_is_connected(display_t *disp)
Check if the display connection is still connected.
Definition display.c:146
uint64_t display_emit(display_t *disp, surface_id_t target, event_type_t type, void *data, uint64_t size)
Emit an event to a target surface.
Definition display.c:389
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:442
display_t * display_new(void)
Create a new display connection.
Definition display.c:46
uint64_t display_get_surface_info(display_t *disp, surface_id_t id, surface_info_t *info)
Get information about a surface.
Definition display.c:517
uint64_t display_subscribe(display_t *disp, event_type_t type)
Subscribe to events of a specific type.
Definition display.c:479
uint64_t display_set_is_visible(display_t *disp, surface_id_t id, bool isVisible)
Set the visibility of a surface.
Definition display.c:558
uint16_t event_type_t
Event type.
Definition event.h:71
uint64_t surface_id_t
Definition surface.h:53
__UINT64_TYPE__ clock_t
A nanosecond time.
Definition clock_t.h:13
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
Opaque display structure.
Definition internal.h:68
Event structure.
Definition event.h:306
Poll file descriptor structure.
Definition fs.h:305
Definition rect.h:13