From b342bc6139ea8a765084eacfc0ca365561fcdd30 Mon Sep 17 00:00:00 2001 From: Jeffy Chen Date: Wed, 27 Apr 2022 18:05:28 +0800 Subject: [PATCH 13/93] Support setting output flow direction Set env "WESTON_OUTPUT_FLOW" to change output flow direction: horizontal: Place outputs horizontal. vertical: Place outputs vertical. same-as: Place outputs at (0,0). Signed-off-by: Jeffy Chen --- clients/desktop-shell.c | 20 +++++++++++++++ compositor/main.c | 11 ++++++++ desktop-shell/shell.c | 17 ++++++++++--- include/libweston/libweston.h | 11 ++++++++ libweston/compositor.c | 48 +++++++++++++++-------------------- 5 files changed, 77 insertions(+), 30 deletions(-) diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c index b450a01..6eb9775 100644 --- a/clients/desktop-shell.c +++ b/clients/desktop-shell.c @@ -135,6 +135,8 @@ struct output { int y; struct panel *panel; struct background *background; + + struct desktop *desktop; }; struct panel_launcher { @@ -1227,10 +1229,27 @@ output_handle_geometry(void *data, int transform) { struct output *output = data; + struct desktop *desktop = output->desktop; + struct wl_surface *surface; output->x = x; output->y = y; + if (y && output->panel) { + /* HACK: Re-set the panel to destroy it */ + surface = window_get_wl_surface(output->panel->window); + weston_desktop_shell_set_panel(desktop->shell, + output->output, surface); + } + + if (!y && desktop->want_panel && !output->panel) { + /* based on output_init() */ + output->panel = panel_create(desktop, output); + surface = window_get_wl_surface(output->panel->window); + weston_desktop_shell_set_panel(desktop->shell, + output->output, surface); + } + if (output->panel) window_set_buffer_transform(output->panel->window, transform); if (output->background) @@ -1300,6 +1319,7 @@ create_output(struct desktop *desktop, uint32_t id) if (!output) return; + output->desktop = desktop; output->output = display_bind(desktop->display, id, &wl_output_interface, 2); output->server_output_id = id; diff --git a/compositor/main.c b/compositor/main.c index 631355e..57a52b6 100644 --- a/compositor/main.c +++ b/compositor/main.c @@ -3546,6 +3546,7 @@ wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data) struct weston_log_subscriber *flight_rec = NULL; sigset_t mask; struct sigaction action; + char *buf; bool wait_for_debugger = false; struct wl_protocol_logger *protologger = NULL; @@ -3699,6 +3700,16 @@ wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data) goto out; } + wet.compositor->output_flow = WESTON_OUTPUT_FLOW_HORIZONTAL; + + buf = getenv("WESTON_OUTPUT_FLOW"); + if (buf) { + if (!strcmp(buf, "vertical")) + wet.compositor->output_flow = WESTON_OUTPUT_FLOW_VERTICAL; + else if (!strcmp(buf, "same-as")) + wet.compositor->output_flow = WESTON_OUTPUT_FLOW_SAME_AS; + } + protocol_scope = weston_log_ctx_add_log_scope(log_ctx, "proto", "Wayland protocol dump for all clients.\n", diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index 7363ee3..79e20ad 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -1020,7 +1020,7 @@ constrain_position(struct weston_move_grab *move, int *cx, int *cy) y = wl_fixed_to_int(pointer->y + move->dy); if (shsurf->shell->panel_position == - WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP) { + WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP && !surface->output->y) { get_output_work_area(shsurf->shell, surface->output, &area); geometry = weston_desktop_surface_get_geometry(shsurf->desktop_surface); @@ -2658,6 +2658,18 @@ desktop_shell_set_panel(struct wl_client *client, wl_resource_get_user_data(surface_resource); struct weston_view *view, *next; struct shell_output *sh_output; + struct weston_output *output; + + output = weston_head_from_resource(output_resource)->output; + sh_output = find_shell_output_from_weston_output(shell, output); + + if (surface == sh_output->panel_surface) { + /* HACK: Re-set to destroy output panel */ + weston_desktop_shell_send_configure(resource, 0, + surface_resource, + 0, 0); + return; + } if (surface->committed) { wl_resource_post_error(surface_resource, @@ -2673,10 +2685,9 @@ desktop_shell_set_panel(struct wl_client *client, surface->committed = panel_committed; surface->committed_private = shell; weston_surface_set_label_func(surface, panel_get_label); - surface->output = weston_head_from_resource(output_resource)->output; + surface->output = output; weston_view_set_output(view, surface->output); - sh_output = find_shell_output_from_weston_output(shell, surface->output); if (sh_output->panel_surface) { /* The output already has a panel, tell our helper * there is no need for another one. */ diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index a3a23bc..103c293 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -1184,6 +1184,12 @@ struct weston_color_manager; struct weston_dmabuf_feedback; struct weston_dmabuf_feedback_format_table; +enum weston_output_flow { + WESTON_OUTPUT_FLOW_HORIZONTAL, + WESTON_OUTPUT_FLOW_VERTICAL, + WESTON_OUTPUT_FLOW_SAME_AS, +}; + /** Main object, container-like structure which aggregates all other objects. * * \ingroup compositor @@ -1317,6 +1323,8 @@ struct weston_compositor { /* One-time warning about a view appearing in the layer list when it * or its surface are not mapped. */ bool warned_about_unmapped_surface_or_view; + + enum weston_output_flow output_flow; }; struct weston_solid_buffer_values { @@ -2347,6 +2355,9 @@ struct weston_color_profile * weston_compositor_load_icc_file(struct weston_compositor *compositor, const char *path); +void +weston_compositor_reflow_outputs(struct weston_compositor *compositor); + #ifdef __cplusplus } #endif diff --git a/libweston/compositor.c b/libweston/compositor.c index 55751a7..23316ef 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -258,10 +258,6 @@ weston_mode_switch_finish(struct weston_output *output, mode_changed, scale_changed); } -static void -weston_compositor_reflow_outputs(struct weston_compositor *compositor, - struct weston_output *resized_output, int delta_width); - /** * \ingroup output */ @@ -272,7 +268,6 @@ weston_output_mode_set_native(struct weston_output *output, { int ret; int mode_changed = 0, scale_changed = 0; - int32_t old_width; if (!output->switch_mode) return -1; @@ -288,14 +283,13 @@ weston_output_mode_set_native(struct weston_output *output, } } - old_width = output->width; output->native_mode = mode; output->native_scale = scale; weston_mode_switch_finish(output, mode_changed, scale_changed); if (mode_changed || scale_changed) { - weston_compositor_reflow_outputs(output->compositor, output, output->width - old_width); + weston_compositor_reflow_outputs(output->compositor); wl_signal_emit(&output->compositor->output_resized_signal, output); } @@ -6468,30 +6462,29 @@ weston_head_get_destroy_listener(struct weston_head *head, static void weston_output_set_position(struct weston_output *output, int x, int y); -/* Move other outputs when one is resized so the space remains contiguous. */ -static void -weston_compositor_reflow_outputs(struct weston_compositor *compositor, - struct weston_output *resized_output, int delta_width) +WL_EXPORT void +weston_compositor_reflow_outputs(struct weston_compositor *compositor) { struct weston_output *output; - bool start_resizing = false; + int x, y, next_x, next_y; if (compositor->output_flow_dirty) return; - if (!delta_width) - return; - + next_x = next_y = 0; wl_list_for_each(output, &compositor->output_list, link) { - if (output == resized_output) { - start_resizing = true; + if (output->destroying) continue; - } - if (start_resizing) { - weston_output_set_position(output, output->x + delta_width, output->y); - output->dirty = 1; - } + x = next_x; + y = next_y; + + if (compositor->output_flow == WESTON_OUTPUT_FLOW_HORIZONTAL) + next_x += output->width; + else if (compositor->output_flow == WESTON_OUTPUT_FLOW_VERTICAL) + next_y += output->height; + + weston_output_set_position(output, x, y); } } @@ -6583,6 +6576,8 @@ weston_output_transform_scale_init(struct weston_output *output, uint32_t transf static void weston_output_init_geometry(struct weston_output *output, int x, int y) { + output->dirty = 1; + output->x = x; output->y = y; @@ -6616,8 +6611,6 @@ weston_output_set_position(struct weston_output *output, int x, int y) weston_output_init_geometry(output, x, y); - output->dirty = 1; - /* Move views on this output. */ wl_signal_emit(&output->compositor->output_moved_signal, output); @@ -6909,7 +6902,7 @@ weston_compositor_remove_output(struct weston_output *output) weston_presentation_feedback_discard_list(&output->feedback_list); - weston_compositor_reflow_outputs(compositor, output, -output->width); + weston_compositor_reflow_outputs(compositor); wl_list_remove(&output->link); wl_list_insert(compositor->pending_output_list.prev, &output->link); @@ -6983,7 +6976,7 @@ weston_output_set_transform(struct weston_output *output, weston_output_init_geometry(output, output->x, output->y); - output->dirty = 1; + weston_compositor_reflow_outputs(output->compositor); /* Notify clients of the change for output transform. */ wl_list_for_each(head, &output->head_list, output_link) { @@ -7346,7 +7339,6 @@ weston_output_enable(struct weston_output *output) /* Make sure we have a transform set */ assert(output->transform != UINT32_MAX); - output->dirty = 1; output->original_scale = output->scale; wl_signal_init(&output->frame_signal); @@ -7385,6 +7377,8 @@ weston_output_enable(struct weston_output *output) output->name, head_names); free(head_names); + weston_compositor_reflow_outputs(output->compositor); + return 0; } -- 2.20.1