1 #ifndef _SWAY_OUTPUT_H
2 #define _SWAY_OUTPUT_H
3 #include <time.h>
4 #include <unistd.h>
5 #include <wayland-server-core.h>
6 #include <wlr/types/wlr_box.h>
7 #include <wlr/types/wlr_output.h>
8 #include "config.h"
9 #include "sway/tree/node.h"
10 #include "sway/tree/view.h"
11 
12 struct sway_server;
13 struct sway_container;
14 
15 struct sway_output_state {
16 	list_t *workspaces;
17 	struct sway_workspace *active_workspace;
18 };
19 
20 struct sway_output {
21 	struct sway_node node;
22 	struct wlr_output *wlr_output;
23 	struct sway_server *server;
24 	struct wl_list link;
25 
26 	struct wl_list layers[4]; // sway_layer_surface::link
27 	struct wlr_box usable_area;
28 
29 	struct timespec last_frame;
30 	struct wlr_output_damage *damage;
31 
32 	int lx, ly; // layout coords
33 	int width, height; // transformed buffer size
34 	enum wl_output_subpixel detected_subpixel;
35 	enum scale_filter_mode scale_filter;
36 	// last applied mode when the output is DPMS'ed
37 	struct wlr_output_mode *current_mode;
38 
39 	bool enabling, enabled;
40 	list_t *workspaces;
41 
42 	struct sway_output_state current;
43 
44 	struct wl_listener destroy;
45 	struct wl_listener mode;
46 	struct wl_listener transform;
47 	struct wl_listener scale;
48 	struct wl_listener present;
49 	struct wl_listener damage_destroy;
50 	struct wl_listener damage_frame;
51 
52 	struct {
53 		struct wl_signal destroy;
54 	} events;
55 
56 	struct timespec last_presentation;
57 	uint32_t refresh_nsec;
58 	int max_render_time; // In milliseconds
59 	struct wl_event_source *repaint_timer;
60 };
61 
62 struct sway_output *output_create(struct wlr_output *wlr_output);
63 
64 void output_destroy(struct sway_output *output);
65 
66 void output_begin_destroy(struct sway_output *output);
67 
68 struct sway_output *output_from_wlr_output(struct wlr_output *output);
69 
70 struct sway_output *output_get_in_direction(struct sway_output *reference,
71 		enum wlr_direction direction);
72 
73 void output_add_workspace(struct sway_output *output,
74 		struct sway_workspace *workspace);
75 
76 typedef void (*sway_surface_iterator_func_t)(struct sway_output *output, struct sway_view *view,
77 	struct wlr_surface *surface, struct wlr_box *box, float rotation,
78 	void *user_data);
79 
80 void output_damage_whole(struct sway_output *output);
81 
82 void output_damage_surface(struct sway_output *output, double ox, double oy,
83 	struct wlr_surface *surface, bool whole);
84 
85 void output_damage_from_view(struct sway_output *output,
86 	struct sway_view *view);
87 
88 void output_damage_box(struct sway_output *output, struct wlr_box *box);
89 
90 void output_damage_whole_container(struct sway_output *output,
91 	struct sway_container *con);
92 
93 // this ONLY includes the enabled outputs
94 struct sway_output *output_by_name_or_id(const char *name_or_id);
95 
96 // this includes all the outputs, including disabled ones
97 struct sway_output *all_output_by_name_or_id(const char *name_or_id);
98 
99 void output_sort_workspaces(struct sway_output *output);
100 
101 void output_enable(struct sway_output *output);
102 
103 void output_disable(struct sway_output *output);
104 
105 bool output_has_opaque_overlay_layer_surface(struct sway_output *output);
106 
107 struct sway_workspace *output_get_active_workspace(struct sway_output *output);
108 
109 void output_render(struct sway_output *output, struct timespec *when,
110 	pixman_region32_t *damage);
111 
112 void output_surface_for_each_surface(struct sway_output *output,
113 		struct wlr_surface *surface, double ox, double oy,
114 		sway_surface_iterator_func_t iterator, void *user_data);
115 
116 void output_view_for_each_surface(struct sway_output *output,
117 	struct sway_view *view, sway_surface_iterator_func_t iterator,
118 	void *user_data);
119 
120 void output_view_for_each_popup(struct sway_output *output,
121 		struct sway_view *view, sway_surface_iterator_func_t iterator,
122 		void *user_data);
123 
124 void output_layer_for_each_surface(struct sway_output *output,
125 	struct wl_list *layer_surfaces, sway_surface_iterator_func_t iterator,
126 	void *user_data);
127 
128 void output_layer_for_each_surface_toplevel(struct sway_output *output,
129 	struct wl_list *layer_surfaces, sway_surface_iterator_func_t iterator,
130 	void *user_data);
131 
132 void output_layer_for_each_surface_popup(struct sway_output *output,
133 	struct wl_list *layer_surfaces, sway_surface_iterator_func_t iterator,
134 	void *user_data);
135 
136 #if HAVE_XWAYLAND
137 void output_unmanaged_for_each_surface(struct sway_output *output,
138 	struct wl_list *unmanaged, sway_surface_iterator_func_t iterator,
139 	void *user_data);
140 #endif
141 
142 void output_drag_icons_for_each_surface(struct sway_output *output,
143 	struct wl_list *drag_icons, sway_surface_iterator_func_t iterator,
144 	void *user_data);
145 
146 void output_for_each_workspace(struct sway_output *output,
147 		void (*f)(struct sway_workspace *ws, void *data), void *data);
148 
149 void output_for_each_container(struct sway_output *output,
150 		void (*f)(struct sway_container *con, void *data), void *data);
151 
152 struct sway_workspace *output_find_workspace(struct sway_output *output,
153 		bool (*test)(struct sway_workspace *ws, void *data), void *data);
154 
155 struct sway_container *output_find_container(struct sway_output *output,
156 		bool (*test)(struct sway_container *con, void *data), void *data);
157 
158 void output_get_box(struct sway_output *output, struct wlr_box *box);
159 
160 enum sway_container_layout output_get_default_layout(
161 		struct sway_output *output);
162 
163 void render_rect(struct sway_output *output,
164 		pixman_region32_t *output_damage, const struct wlr_box *_box,
165 		float color[static 4]);
166 
167 void premultiply_alpha(float color[4], float opacity);
168 
169 void scale_box(struct wlr_box *box, float scale);
170 
171 enum wlr_direction opposite_direction(enum wlr_direction d);
172 
173 void handle_output_layout_change(struct wl_listener *listener, void *data);
174 
175 void handle_output_manager_apply(struct wl_listener *listener, void *data);
176 
177 void handle_output_manager_test(struct wl_listener *listener, void *data);
178 
179 void handle_output_power_manager_set_mode(struct wl_listener *listener,
180 	void *data);
181 
182 #endif
183