xref: /OK3568_Linux_fs/buildroot/package/weston/0013-Support-setting-output-flow-direction.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1From b342bc6139ea8a765084eacfc0ca365561fcdd30 Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Wed, 27 Apr 2022 18:05:28 +0800
4Subject: [PATCH 13/93] Support setting output flow direction
5
6Set env "WESTON_OUTPUT_FLOW" to change output flow direction:
7horizontal:
8  Place outputs horizontal.
9vertical:
10  Place outputs vertical.
11same-as:
12  Place outputs at (0,0).
13
14Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
15---
16 clients/desktop-shell.c       | 20 +++++++++++++++
17 compositor/main.c             | 11 ++++++++
18 desktop-shell/shell.c         | 17 ++++++++++---
19 include/libweston/libweston.h | 11 ++++++++
20 libweston/compositor.c        | 48 +++++++++++++++--------------------
21 5 files changed, 77 insertions(+), 30 deletions(-)
22
23diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
24index b450a01..6eb9775 100644
25--- a/clients/desktop-shell.c
26+++ b/clients/desktop-shell.c
27@@ -135,6 +135,8 @@ struct output {
28 	int y;
29 	struct panel *panel;
30 	struct background *background;
31+
32+	struct desktop *desktop;
33 };
34
35 struct panel_launcher {
36@@ -1227,10 +1229,27 @@ output_handle_geometry(void *data,
37                        int transform)
38 {
39 	struct output *output = data;
40+	struct desktop *desktop = output->desktop;
41+	struct wl_surface *surface;
42
43 	output->x = x;
44 	output->y = y;
45
46+	if (y && output->panel) {
47+		/* HACK: Re-set the panel to destroy it */
48+		surface = window_get_wl_surface(output->panel->window);
49+		weston_desktop_shell_set_panel(desktop->shell,
50+					       output->output, surface);
51+	}
52+
53+	if (!y && desktop->want_panel && !output->panel) {
54+		/* based on output_init() */
55+		output->panel = panel_create(desktop, output);
56+		surface = window_get_wl_surface(output->panel->window);
57+		weston_desktop_shell_set_panel(desktop->shell,
58+					       output->output, surface);
59+	}
60+
61 	if (output->panel)
62 		window_set_buffer_transform(output->panel->window, transform);
63 	if (output->background)
64@@ -1300,6 +1319,7 @@ create_output(struct desktop *desktop, uint32_t id)
65 	if (!output)
66 		return;
67
68+	output->desktop = desktop;
69 	output->output =
70 		display_bind(desktop->display, id, &wl_output_interface, 2);
71 	output->server_output_id = id;
72diff --git a/compositor/main.c b/compositor/main.c
73index 631355e..57a52b6 100644
74--- a/compositor/main.c
75+++ b/compositor/main.c
76@@ -3546,6 +3546,7 @@ wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
77 	struct weston_log_subscriber *flight_rec = NULL;
78 	sigset_t mask;
79 	struct sigaction action;
80+	char *buf;
81
82 	bool wait_for_debugger = false;
83 	struct wl_protocol_logger *protologger = NULL;
84@@ -3699,6 +3700,16 @@ wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
85 		goto out;
86 	}
87
88+	wet.compositor->output_flow = WESTON_OUTPUT_FLOW_HORIZONTAL;
89+
90+	buf = getenv("WESTON_OUTPUT_FLOW");
91+	if (buf) {
92+		if (!strcmp(buf, "vertical"))
93+			wet.compositor->output_flow = WESTON_OUTPUT_FLOW_VERTICAL;
94+		else if (!strcmp(buf, "same-as"))
95+			wet.compositor->output_flow = WESTON_OUTPUT_FLOW_SAME_AS;
96+	}
97+
98 	protocol_scope =
99 		weston_log_ctx_add_log_scope(log_ctx, "proto",
100 					     "Wayland protocol dump for all clients.\n",
101diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
102index 7363ee3..79e20ad 100644
103--- a/desktop-shell/shell.c
104+++ b/desktop-shell/shell.c
105@@ -1020,7 +1020,7 @@ constrain_position(struct weston_move_grab *move, int *cx, int *cy)
106 	y = wl_fixed_to_int(pointer->y + move->dy);
107
108 	if (shsurf->shell->panel_position ==
109-	    WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP) {
110+	    WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP && !surface->output->y) {
111 		get_output_work_area(shsurf->shell, surface->output, &area);
112 		geometry =
113 			weston_desktop_surface_get_geometry(shsurf->desktop_surface);
114@@ -2658,6 +2658,18 @@ desktop_shell_set_panel(struct wl_client *client,
115 		wl_resource_get_user_data(surface_resource);
116 	struct weston_view *view, *next;
117 	struct shell_output *sh_output;
118+	struct weston_output *output;
119+
120+	output = weston_head_from_resource(output_resource)->output;
121+	sh_output = find_shell_output_from_weston_output(shell, output);
122+
123+	if (surface == sh_output->panel_surface) {
124+		/* HACK: Re-set to destroy output panel */
125+		weston_desktop_shell_send_configure(resource, 0,
126+						    surface_resource,
127+						    0, 0);
128+		return;
129+	}
130
131 	if (surface->committed) {
132 		wl_resource_post_error(surface_resource,
133@@ -2673,10 +2685,9 @@ desktop_shell_set_panel(struct wl_client *client,
134 	surface->committed = panel_committed;
135 	surface->committed_private = shell;
136 	weston_surface_set_label_func(surface, panel_get_label);
137-	surface->output = weston_head_from_resource(output_resource)->output;
138+	surface->output = output;
139 	weston_view_set_output(view, surface->output);
140
141-	sh_output = find_shell_output_from_weston_output(shell, surface->output);
142 	if (sh_output->panel_surface) {
143 		/* The output already has a panel, tell our helper
144 		 * there is no need for another one. */
145diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h
146index a3a23bc..103c293 100644
147--- a/include/libweston/libweston.h
148+++ b/include/libweston/libweston.h
149@@ -1184,6 +1184,12 @@ struct weston_color_manager;
150 struct weston_dmabuf_feedback;
151 struct weston_dmabuf_feedback_format_table;
152
153+enum weston_output_flow {
154+	WESTON_OUTPUT_FLOW_HORIZONTAL,
155+	WESTON_OUTPUT_FLOW_VERTICAL,
156+	WESTON_OUTPUT_FLOW_SAME_AS,
157+};
158+
159 /** Main object, container-like structure which aggregates all other objects.
160  *
161  * \ingroup compositor
162@@ -1317,6 +1323,8 @@ struct weston_compositor {
163 	/* One-time warning about a view appearing in the layer list when it
164 	 * or its surface are not mapped. */
165 	bool warned_about_unmapped_surface_or_view;
166+
167+	enum weston_output_flow output_flow;
168 };
169
170 struct weston_solid_buffer_values {
171@@ -2347,6 +2355,9 @@ struct weston_color_profile *
172 weston_compositor_load_icc_file(struct weston_compositor *compositor,
173 				const char *path);
174
175+void
176+weston_compositor_reflow_outputs(struct weston_compositor *compositor);
177+
178 #ifdef  __cplusplus
179 }
180 #endif
181diff --git a/libweston/compositor.c b/libweston/compositor.c
182index 55751a7..23316ef 100644
183--- a/libweston/compositor.c
184+++ b/libweston/compositor.c
185@@ -258,10 +258,6 @@ weston_mode_switch_finish(struct weston_output *output,
186 					       mode_changed, scale_changed);
187 }
188
189-static void
190-weston_compositor_reflow_outputs(struct weston_compositor *compositor,
191-				struct weston_output *resized_output, int delta_width);
192-
193 /**
194  * \ingroup output
195  */
196@@ -272,7 +268,6 @@ weston_output_mode_set_native(struct weston_output *output,
197 {
198 	int ret;
199 	int mode_changed = 0, scale_changed = 0;
200-	int32_t old_width;
201
202 	if (!output->switch_mode)
203 		return -1;
204@@ -288,14 +283,13 @@ weston_output_mode_set_native(struct weston_output *output,
205 		}
206 	}
207
208-	old_width = output->width;
209 	output->native_mode = mode;
210 	output->native_scale = scale;
211
212 	weston_mode_switch_finish(output, mode_changed, scale_changed);
213
214 	if (mode_changed || scale_changed) {
215-		weston_compositor_reflow_outputs(output->compositor, output, output->width - old_width);
216+		weston_compositor_reflow_outputs(output->compositor);
217
218 		wl_signal_emit(&output->compositor->output_resized_signal, output);
219 	}
220@@ -6468,30 +6462,29 @@ weston_head_get_destroy_listener(struct weston_head *head,
221 static void
222 weston_output_set_position(struct weston_output *output, int x, int y);
223
224-/* Move other outputs when one is resized so the space remains contiguous. */
225-static void
226-weston_compositor_reflow_outputs(struct weston_compositor *compositor,
227-				struct weston_output *resized_output, int delta_width)
228+WL_EXPORT void
229+weston_compositor_reflow_outputs(struct weston_compositor *compositor)
230 {
231 	struct weston_output *output;
232-	bool start_resizing = false;
233+	int x, y, next_x, next_y;
234
235 	if (compositor->output_flow_dirty)
236 		return;
237
238-	if (!delta_width)
239-		return;
240-
241+	next_x = next_y = 0;
242 	wl_list_for_each(output, &compositor->output_list, link) {
243-		if (output == resized_output) {
244-			start_resizing = true;
245+		if (output->destroying)
246 			continue;
247-		}
248
249-		if (start_resizing) {
250-			weston_output_set_position(output, output->x + delta_width, output->y);
251-			output->dirty = 1;
252-		}
253+		x = next_x;
254+		y = next_y;
255+
256+		if (compositor->output_flow == WESTON_OUTPUT_FLOW_HORIZONTAL)
257+			next_x += output->width;
258+		else if (compositor->output_flow == WESTON_OUTPUT_FLOW_VERTICAL)
259+			next_y += output->height;
260+
261+		weston_output_set_position(output, x, y);
262 	}
263 }
264
265@@ -6583,6 +6576,8 @@ weston_output_transform_scale_init(struct weston_output *output, uint32_t transf
266 static void
267 weston_output_init_geometry(struct weston_output *output, int x, int y)
268 {
269+	output->dirty = 1;
270+
271 	output->x = x;
272 	output->y = y;
273
274@@ -6616,8 +6611,6 @@ weston_output_set_position(struct weston_output *output, int x, int y)
275
276 	weston_output_init_geometry(output, x, y);
277
278-	output->dirty = 1;
279-
280 	/* Move views on this output. */
281 	wl_signal_emit(&output->compositor->output_moved_signal, output);
282
283@@ -6909,7 +6902,7 @@ weston_compositor_remove_output(struct weston_output *output)
284
285 	weston_presentation_feedback_discard_list(&output->feedback_list);
286
287-	weston_compositor_reflow_outputs(compositor, output, -output->width);
288+	weston_compositor_reflow_outputs(compositor);
289
290 	wl_list_remove(&output->link);
291 	wl_list_insert(compositor->pending_output_list.prev, &output->link);
292@@ -6983,7 +6976,7 @@ weston_output_set_transform(struct weston_output *output,
293
294 	weston_output_init_geometry(output, output->x, output->y);
295
296-	output->dirty = 1;
297+	weston_compositor_reflow_outputs(output->compositor);
298
299 	/* Notify clients of the change for output transform. */
300 	wl_list_for_each(head, &output->head_list, output_link) {
301@@ -7346,7 +7339,6 @@ weston_output_enable(struct weston_output *output)
302 	/* Make sure we have a transform set */
303 	assert(output->transform != UINT32_MAX);
304
305-	output->dirty = 1;
306 	output->original_scale = output->scale;
307
308 	wl_signal_init(&output->frame_signal);
309@@ -7385,6 +7377,8 @@ weston_output_enable(struct weston_output *output)
310 		   output->name, head_names);
311 	free(head_names);
312
313+	weston_compositor_reflow_outputs(output->compositor);
314+
315 	return 0;
316 }
317
318--
3192.20.1
320
321