1From 5141e382c9e3bb58fb10c932d6ddafa4570dfa05 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 12/79] 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 | 46 +++++++++++++++-------------------- 21 5 files changed, 75 insertions(+), 30 deletions(-) 22 23diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c 24index fb53069..56c3976 100644 25--- a/clients/desktop-shell.c 26+++ b/clients/desktop-shell.c 27@@ -134,6 +134,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@@ -1266,10 +1268,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@@ -1339,6 +1358,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 d7eb422..e946b4a 100644 74--- a/compositor/main.c 75+++ b/compositor/main.c 76@@ -3297,6 +3297,7 @@ wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data) 77 struct weston_log_subscriber *logger = NULL; 78 struct weston_log_subscriber *flight_rec = NULL; 79 sigset_t mask; 80+ char *buf; 81 82 bool wait_for_debugger = false; 83 struct wl_protocol_logger *protologger = NULL; 84@@ -3438,6 +3439,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 3c71192..15c148f 100644 103--- a/desktop-shell/shell.c 104+++ b/desktop-shell/shell.c 105@@ -1490,7 +1490,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@@ -3091,6 +3091,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@@ -3106,10 +3118,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 be2514a..c6ba508 100644 147--- a/include/libweston/libweston.h 148+++ b/include/libweston/libweston.h 149@@ -1057,6 +1057,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@@ -1184,6 +1190,8 @@ struct weston_compositor { 163 struct weston_log_scope *timeline; 164 165 struct content_protection *content_protection; 166+ 167+ enum weston_output_flow output_flow; 168 }; 169 170 struct weston_buffer { 171@@ -2158,6 +2166,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 f36ec9b..e184349 100644 183--- a/libweston/compositor.c 184+++ b/libweston/compositor.c 185@@ -255,10 +255,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@@ -269,7 +265,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@@ -285,14 +280,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@@ -6044,27 +6038,26 @@ weston_head_get_destroy_listener(struct weston_head *head, 221 return wl_signal_get(&head->destroy_signal, notify); 222 } 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- 234- if (!delta_width) 235- return; 236+ int x, y, next_x, next_y; 237 238+ next_x = next_y = 0; 239 wl_list_for_each(output, &compositor->output_list, link) { 240- if (output == resized_output) { 241- start_resizing = true; 242+ if (output->destroying) 243 continue; 244- } 245 246- if (start_resizing) { 247- weston_output_move(output, output->x + delta_width, output->y); 248- output->dirty = 1; 249- } 250+ x = next_x; 251+ y = next_y; 252+ 253+ if (compositor->output_flow == WESTON_OUTPUT_FLOW_HORIZONTAL) 254+ next_x += output->width; 255+ else if (compositor->output_flow == WESTON_OUTPUT_FLOW_VERTICAL) 256+ next_y += output->height; 257+ 258+ weston_output_move(output, x, y); 259 } 260 } 261 262@@ -6174,6 +6167,8 @@ weston_output_transform_scale_init(struct weston_output *output, uint32_t transf 263 static void 264 weston_output_init_geometry(struct weston_output *output, int x, int y) 265 { 266+ output->dirty = 1; 267+ 268 output->x = x; 269 output->y = y; 270 271@@ -6201,8 +6196,6 @@ weston_output_move(struct weston_output *output, int x, int y) 272 273 weston_output_init_geometry(output, x, y); 274 275- output->dirty = 1; 276- 277 /* Move views on this output. */ 278 wl_signal_emit(&output->compositor->output_moved_signal, output); 279 280@@ -6423,7 +6416,7 @@ weston_compositor_remove_output(struct weston_output *output) 281 282 weston_presentation_feedback_discard_list(&output->feedback_list); 283 284- weston_compositor_reflow_outputs(compositor, output, -output->width); 285+ weston_compositor_reflow_outputs(compositor); 286 287 wl_list_remove(&output->link); 288 wl_list_insert(compositor->pending_output_list.prev, &output->link); 289@@ -6497,7 +6490,7 @@ weston_output_set_transform(struct weston_output *output, 290 291 weston_output_init_geometry(output, output->x, output->y); 292 293- output->dirty = 1; 294+ weston_compositor_reflow_outputs(output->compositor); 295 296 /* Notify clients of the change for output transform. */ 297 wl_list_for_each(head, &output->head_list, output_link) { 298@@ -6765,7 +6758,6 @@ weston_output_enable(struct weston_output *output) 299 300 output->x = x; 301 output->y = y; 302- output->dirty = 1; 303 output->original_scale = output->scale; 304 305 wl_signal_init(&output->frame_signal); 306-- 3072.20.1 308 309