1 #if !defined(HIKARI_SERVER_H)
2 #define HIKARI_SERVER_H
3
4 #include <wayland-server-core.h>
5 #include <wayland-util.h>
6
7 #ifdef HAVE_VIRTUAL_INPUT
8 #include <wlr/types/wlr_virtual_keyboard_v1.h>
9 #include <wlr/types/wlr_virtual_pointer_v1.h>
10 #endif
11
12 #include <hikari/configuration.h>
13 #include <hikari/cursor.h>
14 #include <hikari/dnd_mode.h>
15 #include <hikari/group_assign_mode.h>
16 #include <hikari/indicator.h>
17 #include <hikari/input_grab_mode.h>
18 #include <hikari/layout_select_mode.h>
19 #include <hikari/lock_mode.h>
20 #include <hikari/mark_assign_mode.h>
21 #include <hikari/mark_select_mode.h>
22 #include <hikari/move_mode.h>
23 #include <hikari/normal_mode.h>
24 #include <hikari/resize_mode.h>
25 #include <hikari/sheet_assign_mode.h>
26 #include <hikari/workspace.h>
27
28 #ifdef HAVE_LAYERSHELL
29 #include <hikari/layer_shell.h>
30 #endif
31
32 struct wlr_input_device;
33
34 struct hikari_output;
35 struct hikari_group;
36
37 struct hikari_server {
38 bool cycling;
39 #ifndef NDEBUG
40 bool track_damage;
41 #endif
42
43 const char *socket;
44 char *config_path;
45
46 struct wl_event_source *shutdown_timer;
47
48 struct hikari_indicator indicator;
49
50 struct wl_display *display;
51 struct wl_event_loop *event_loop;
52 struct wlr_backend *backend;
53 struct wlr_renderer *renderer;
54 struct wlr_xdg_output_manager_v1 *output_manager;
55 struct wlr_data_device_manager *data_device_manager;
56
57 struct wlr_backend *noop_backend;
58 struct hikari_output *noop_output;
59
60 struct wl_listener new_output;
61 struct wl_listener new_input;
62 struct wl_listener new_xdg_surface;
63 struct wl_listener request_set_primary_selection;
64 struct wl_listener request_set_selection;
65 struct wl_listener output_layout_change;
66 struct wl_listener new_decoration;
67 struct wl_listener new_toplevel_decoration;
68 struct wl_listener request_start_drag;
69 struct wl_listener start_drag;
70
71 #ifdef HAVE_LAYERSHELL
72 struct wl_listener new_layer_shell_surface;
73 #endif
74
75 #ifdef HAVE_XWAYLAND
76 struct wl_listener new_xwayland_surface;
77
78 struct wlr_xwayland *xwayland;
79 #endif
80
81 #ifdef HAVE_VIRTUAL_INPUT
82 struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard;
83 struct wl_listener new_virtual_keyboard;
84
85 struct wlr_virtual_pointer_manager_v1 *virtual_pointer;
86 struct wl_listener new_virtual_pointer;
87 #endif
88
89 struct wlr_compositor *compositor;
90 struct wlr_server_decoration_manager *decoration_manager;
91 struct wlr_xdg_decoration_manager_v1 *xdg_decoration_manager;
92
93 struct wlr_xdg_shell *xdg_shell;
94 struct wlr_layer_shell_v1 *layer_shell;
95
96 struct wlr_output_layout *output_layout;
97 struct wlr_seat *seat;
98
99 struct hikari_workspace *workspace;
100
101 struct hikari_cursor cursor;
102
103 struct wl_list pointers;
104 struct wl_list keyboards;
105 struct wl_list switches;
106 struct wl_list outputs;
107
108 struct wl_list groups;
109 struct wl_list visible_groups;
110 struct wl_list visible_views;
111
112 struct hikari_mode *mode;
113
114 struct hikari_group_assign_mode group_assign_mode;
115 struct hikari_input_grab_mode input_grab_mode;
116 struct hikari_layout_select_mode layout_select_mode;
117 struct hikari_lock_mode lock_mode;
118 struct hikari_mark_assign_mode mark_assign_mode;
119 struct hikari_mark_select_mode mark_select_mode;
120 struct hikari_move_mode move_mode;
121 struct hikari_normal_mode normal_mode;
122 struct hikari_resize_mode resize_mode;
123 struct hikari_sheet_assign_mode sheet_assign_mode;
124 struct hikari_dnd_mode dnd_mode;
125
126 struct {
127 uint32_t modifiers;
128 bool mod_released;
129 bool mod_changed;
130 bool mod_pressed;
131 } keyboard_state;
132 };
133
134 extern struct hikari_server hikari_server;
135
136 static inline bool
hikari_server_is_indicating(void)137 hikari_server_is_indicating(void)
138 {
139 return hikari_server.keyboard_state.mod_pressed;
140 }
141
142 static inline bool
hikari_server_is_cycling(void)143 hikari_server_is_cycling(void)
144 {
145 return hikari_server.cycling;
146 }
147
148 static inline void
hikari_server_set_cycling(void)149 hikari_server_set_cycling(void)
150 {
151 hikari_server.cycling = true;
152 }
153
154 static inline void
hikari_server_unset_cycling(void)155 hikari_server_unset_cycling(void)
156 {
157 hikari_server.cycling = false;
158 }
159
160 void
161 hikari_server_migrate_focus_view(
162 struct hikari_output *output, double lx, double ly, bool center);
163
164 void
165 hikari_server_prepare_privileged(void);
166
167 void
168 hikari_server_start(char *config_path, char *autostart);
169
170 struct hikari_node *
171 hikari_server_node_at(double x,
172 double y,
173 struct wlr_surface **surface,
174 struct hikari_workspace **workspace,
175 double *sx,
176 double *sy);
177
178 void
179 hikari_server_stop();
180
181 void
182 hikari_server_terminate(void *arg);
183
184 void
185 hikari_server_cursor_focus(void);
186
187 void
188 hikari_server_lock(void *arg);
189
190 void
191 hikari_server_reload(void *arg);
192
193 void
194 hikari_server_execute_command(void *arg);
195
196 struct hikari_group *
197 hikari_server_find_group(const char *group_name);
198
199 struct hikari_group *
200 hikari_server_find_or_create_group(const char *group_name);
201
202 #define SHEET_ACTIONS(n) \
203 static inline void hikari_server_display_sheet_##n(void *arg) \
204 { \
205 hikari_workspace_display_sheet_##n(hikari_server.workspace); \
206 } \
207 \
208 static inline void hikari_server_pin_view_to_sheet_##n(void *arg) \
209 { \
210 hikari_workspace_pin_view_to_sheet_##n(hikari_server.workspace); \
211 }
212
213 SHEET_ACTIONS(0)
214 SHEET_ACTIONS(1)
215 SHEET_ACTIONS(2)
216 SHEET_ACTIONS(3)
217 SHEET_ACTIONS(4)
218 SHEET_ACTIONS(5)
219 SHEET_ACTIONS(6)
220 SHEET_ACTIONS(7)
221 SHEET_ACTIONS(8)
222 SHEET_ACTIONS(9)
223 SHEET_ACTIONS(alternate)
224 SHEET_ACTIONS(current)
225 SHEET_ACTIONS(next)
226 SHEET_ACTIONS(prev)
227 #undef SHEET_ACTIONS
228
229 void
230 hikari_server_move_view_up(void *arg);
231
232 void
233 hikari_server_move_view_down(void *arg);
234
235 void
236 hikari_server_move_view_left(void *arg);
237
238 void
239 hikari_server_move_view_right(void *arg);
240
241 #define MOVE(pos) \
242 static inline void hikari_server_move_view_##pos(void *arg) \
243 { \
244 hikari_workspace_move_view_##pos(hikari_server.workspace); \
245 }
246
247 MOVE(bottom_left)
248 MOVE(bottom_middle)
249 MOVE(bottom_right)
250 MOVE(center_left)
251 MOVE(center)
252 MOVE(center_right)
253 MOVE(top_left)
254 MOVE(top_middle)
255 MOVE(top_right)
256 #undef MOVE
257
258 void
259 hikari_server_increase_view_size_up(void *arg);
260
261 void
262 hikari_server_decrease_view_size_down(void *arg);
263
264 void
265 hikari_server_increase_view_size_left(void *arg);
266
267 void
268 hikari_server_decrease_view_size_right(void *arg);
269
270 #define STEP hikari_configuration->step
271 static inline void
hikari_server_decrease_view_size_up(void * arg)272 hikari_server_decrease_view_size_up(void *arg)
273 {
274 hikari_workspace_move_resize_view(hikari_server.workspace, 0, 0, 0, -STEP);
275 }
276
277 static inline void
hikari_server_increase_view_size_down(void * arg)278 hikari_server_increase_view_size_down(void *arg)
279 {
280 hikari_workspace_move_resize_view(hikari_server.workspace, 0, 0, 0, STEP);
281 }
282
283 static inline void
hikari_server_decrease_view_size_left(void * arg)284 hikari_server_decrease_view_size_left(void *arg)
285 {
286 hikari_workspace_move_resize_view(hikari_server.workspace, 0, 0, -STEP, 0);
287 }
288
289 static inline void
hikari_server_increase_view_size_right(void * arg)290 hikari_server_increase_view_size_right(void *arg)
291 {
292 hikari_workspace_move_resize_view(hikari_server.workspace, 0, 0, STEP, 0);
293 }
294 #undef STEP
295
296 static inline void
hikari_server_snap_view_up(void * arg)297 hikari_server_snap_view_up(void *arg)
298 {
299 hikari_workspace_snap_view_up(hikari_server.workspace);
300 }
301
302 static inline void
hikari_server_snap_view_down(void * arg)303 hikari_server_snap_view_down(void *arg)
304 {
305 hikari_workspace_snap_view_down(hikari_server.workspace);
306 }
307
308 static inline void
hikari_server_snap_view_left(void * arg)309 hikari_server_snap_view_left(void *arg)
310 {
311 hikari_workspace_snap_view_left(hikari_server.workspace);
312 }
313
314 static inline void
hikari_server_snap_view_right(void * arg)315 hikari_server_snap_view_right(void *arg)
316 {
317 hikari_workspace_snap_view_right(hikari_server.workspace);
318 }
319
320 #define CYCLE_ACTION(n) void hikari_server_cycle_##n(void *arg);
321
322 CYCLE_ACTION(first_group_view)
CYCLE_ACTION(last_group_view)323 CYCLE_ACTION(last_group_view)
324 CYCLE_ACTION(next_group_view)
325 CYCLE_ACTION(prev_group_view)
326 CYCLE_ACTION(next_layout_view)
327 CYCLE_ACTION(prev_layout_view)
328 CYCLE_ACTION(first_layout_view)
329 CYCLE_ACTION(last_layout_view)
330 CYCLE_ACTION(next_group)
331 CYCLE_ACTION(prev_group)
332 CYCLE_ACTION(next_view)
333 CYCLE_ACTION(prev_view)
334 CYCLE_ACTION(next_workspace)
335 CYCLE_ACTION(prev_workspace)
336 #undef CYCLE_ACTION
337
338 #define WORKSPACE_ACTION(name) \
339 static inline void hikari_server_##name(void *arg) \
340 { \
341 hikari_workspace_##name(hikari_server.workspace); \
342 }
343
344 WORKSPACE_ACTION(toggle_view_vertical_maximize)
345 WORKSPACE_ACTION(toggle_view_horizontal_maximize)
346 WORKSPACE_ACTION(toggle_view_full_maximize)
347 WORKSPACE_ACTION(toggle_view_floating)
348 WORKSPACE_ACTION(toggle_view_invisible)
349 WORKSPACE_ACTION(toggle_view_public)
350 WORKSPACE_ACTION(only_view)
351 WORKSPACE_ACTION(only_group)
352 WORKSPACE_ACTION(hide_view)
353 WORKSPACE_ACTION(hide_group)
354 WORKSPACE_ACTION(sheet_show_group)
355 WORKSPACE_ACTION(raise_view)
356 WORKSPACE_ACTION(raise_group)
357 WORKSPACE_ACTION(lower_view)
358 WORKSPACE_ACTION(lower_group)
359 WORKSPACE_ACTION(show_invisible_sheet_views)
360 WORKSPACE_ACTION(reset_view_geometry)
361 WORKSPACE_ACTION(quit_view)
362 WORKSPACE_ACTION(exchange_next_view)
363 WORKSPACE_ACTION(exchange_prev_view)
364 WORKSPACE_ACTION(exchange_main_layout_view)
365 WORKSPACE_ACTION(switch_to_next_inhabited_sheet)
366 WORKSPACE_ACTION(switch_to_prev_inhabited_sheet)
367 WORKSPACE_ACTION(show_all_sheet_views)
368 WORKSPACE_ACTION(show_all)
369 WORKSPACE_ACTION(show_group)
370 WORKSPACE_ACTION(show_invisible)
371 WORKSPACE_ACTION(clear)
372 #undef WORKSPACE_ACTION
373
374 static inline void
375 hikari_server_clear_workspace(void *arg)
376 {
377 hikari_workspace_clear(hikari_server.workspace);
378 }
379
380 #define MODE(name) \
381 void hikari_server_enter_##name##_mode(void *arg); \
382 \
383 static inline bool hikari_server_in_##name##_mode(void) \
384 { \
385 return hikari_server.mode == \
386 (struct hikari_mode *)&hikari_server.name##_mode; \
387 }
388
389 MODE(group_assign)
390 MODE(input_grab)
391 MODE(layout_select)
392 MODE(lock)
393 MODE(mark_assign)
394 MODE(mark_select)
395 MODE(move)
396 MODE(normal)
397 MODE(resize)
398 MODE(sheet_assign)
399
400 void
401 hikari_server_enter_mark_select_switch_mode(void *arg);
402 #undef MODE
403
404 void
405 hikari_server_reset_sheet_layout(void *arg);
406
407 void
408 hikari_server_layout_restack_append(void *arg);
409
410 void
411 hikari_server_layout_restack_prepend(void *arg);
412
413 void
414 hikari_server_layout_sheet(void *arg);
415
416 void
417 hikari_server_session_change_vt(void *arg);
418
419 void
420 hikari_server_show_mark(void *arg);
421
422 void
423 hikari_server_switch_to_mark(void *arg);
424
425 #ifndef NDEBUG
426 void
427 hikari_server_toggle_damage_tracking(void *arg);
428 #endif
429
430 #endif
431