1 #ifndef _SWAY_SERVER_H
2 #define _SWAY_SERVER_H
3 #include <stdbool.h>
4 #include <wayland-server-core.h>
5 #include <wlr/backend.h>
6 #include <wlr/backend/session.h>
7 #include <wlr/render/wlr_renderer.h>
8 #include <wlr/types/wlr_compositor.h>
9 #include <wlr/types/wlr_data_device.h>
10 #include <wlr/types/wlr_input_method_v2.h>
11 #include <wlr/types/wlr_foreign_toplevel_management_v1.h>
12 #include <wlr/types/wlr_layer_shell_v1.h>
13 #include <wlr/types/wlr_output_management_v1.h>
14 #include <wlr/types/wlr_output_power_management_v1.h>
15 #include <wlr/types/wlr_presentation_time.h>
16 #include <wlr/types/wlr_relative_pointer_v1.h>
17 #include <wlr/types/wlr_server_decoration.h>
18 #include <wlr/types/wlr_text_input_v3.h>
19 #include <wlr/types/wlr_xdg_shell.h>
20 #include "config.h"
21 #include "list.h"
22 #if HAVE_XWAYLAND
23 #include "sway/xwayland.h"
24 #endif
25 
26 struct sway_server {
27 	struct wl_display *wl_display;
28 	struct wl_event_loop *wl_event_loop;
29 	const char *socket;
30 
31 	struct wlr_backend *backend;
32 	struct wlr_backend *noop_backend;
33 	// secondary headless backend used for creating virtual outputs on-the-fly
34 	struct wlr_backend *headless_backend;
35 
36 	struct wlr_compositor *compositor;
37 	struct wl_listener compositor_new_surface;
38 
39 	struct wlr_data_device_manager *data_device_manager;
40 
41 	struct sway_input_manager *input;
42 
43 	struct wl_listener new_output;
44 	struct wl_listener output_layout_change;
45 
46 	struct wlr_idle *idle;
47 	struct sway_idle_inhibit_manager_v1 *idle_inhibit_manager_v1;
48 
49 	struct wlr_layer_shell_v1 *layer_shell;
50 	struct wl_listener layer_shell_surface;
51 
52 	struct wlr_xdg_shell *xdg_shell;
53 	struct wl_listener xdg_shell_surface;
54 
55 	struct wlr_tablet_manager_v2 *tablet_v2;
56 
57 #if HAVE_XWAYLAND
58 	struct sway_xwayland xwayland;
59 	struct wl_listener xwayland_surface;
60 	struct wl_listener xwayland_ready;
61 #endif
62 
63 	struct wlr_relative_pointer_manager_v1 *relative_pointer_manager;
64 
65 	struct wlr_server_decoration_manager *server_decoration_manager;
66 	struct wl_listener server_decoration;
67 	struct wl_list decorations; // sway_server_decoration::link
68 
69 	struct wlr_xdg_decoration_manager_v1 *xdg_decoration_manager;
70 	struct wl_listener xdg_decoration;
71 	struct wl_list xdg_decorations; // sway_xdg_decoration::link
72 
73 	struct wlr_presentation *presentation;
74 
75 	struct wlr_pointer_constraints_v1 *pointer_constraints;
76 	struct wl_listener pointer_constraint;
77 
78 	struct wlr_output_manager_v1 *output_manager_v1;
79 	struct wl_listener output_manager_apply;
80 	struct wl_listener output_manager_test;
81 
82 	struct wlr_output_power_manager_v1 *output_power_manager_v1;
83 	struct wl_listener output_power_manager_set_mode;
84 	struct wlr_input_method_manager_v2 *input_method;
85 	struct wlr_text_input_manager_v3 *text_input;
86 	struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager;
87 
88 	size_t txn_timeout_ms;
89 	list_t *transactions;
90 	list_t *dirty_nodes;
91 };
92 
93 extern struct sway_server server;
94 
95 struct sway_debug {
96 	bool noatomic;         // Ignore atomic layout updates
97 	bool txn_timings;      // Log verbose messages about transactions
98 	bool txn_wait;         // Always wait for the timeout before applying
99 
100 	enum {
101 		DAMAGE_DEFAULT,    // Default behaviour
102 		DAMAGE_HIGHLIGHT,  // Highlight regions of the screen being damaged
103 		DAMAGE_RERENDER,   // Render the full output when any damage occurs
104 	} damage;
105 };
106 
107 extern struct sway_debug debug;
108 
109 /* Prepares an unprivileged server_init by performing all privileged operations in advance */
110 bool server_privileged_prepare(struct sway_server *server);
111 bool server_init(struct sway_server *server);
112 void server_fini(struct sway_server *server);
113 bool server_start(struct sway_server *server);
114 void server_run(struct sway_server *server);
115 
116 void handle_compositor_new_surface(struct wl_listener *listener, void *data);
117 void handle_new_output(struct wl_listener *listener, void *data);
118 
119 void handle_idle_inhibitor_v1(struct wl_listener *listener, void *data);
120 void handle_layer_shell_surface(struct wl_listener *listener, void *data);
121 void handle_xdg_shell_surface(struct wl_listener *listener, void *data);
122 #if HAVE_XWAYLAND
123 void handle_xwayland_surface(struct wl_listener *listener, void *data);
124 #endif
125 void handle_server_decoration(struct wl_listener *listener, void *data);
126 void handle_xdg_decoration(struct wl_listener *listener, void *data);
127 void handle_pointer_constraint(struct wl_listener *listener, void *data);
128 
129 #endif
130