From 9706acaa44e85acbd2c5329d69fedc76ac86307f Mon Sep 17 00:00:00 2001 From: Jeffy Chen Date: Wed, 27 Apr 2022 18:05:28 +0800 Subject: [PATCH 12/74] 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 | 46 +++++++++++++++-------------------- 5 files changed, 75 insertions(+), 30 deletions(-) diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c index fb53069..56c3976 100644 --- a/clients/desktop-shell.c +++ b/clients/desktop-shell.c @@ -134,6 +134,8 @@ struct output { int y; struct panel *panel; struct background *background; + + struct desktop *desktop; }; struct panel_launcher { @@ -1266,10 +1268,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) @@ -1339,6 +1358,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 d7eb422..e946b4a 100644 --- a/compositor/main.c +++ b/compositor/main.c @@ -3297,6 +3297,7 @@ wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data) struct weston_log_subscriber *logger = NULL; struct weston_log_subscriber *flight_rec = NULL; sigset_t mask; + char *buf; bool wait_for_debugger = false; struct wl_protocol_logger *protologger = NULL; @@ -3438,6 +3439,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 3c71192..15c148f 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -1490,7 +1490,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); @@ -3091,6 +3091,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, @@ -3106,10 +3118,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 be2514a..c6ba508 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -1057,6 +1057,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 @@ -1184,6 +1190,8 @@ struct weston_compositor { struct weston_log_scope *timeline; struct content_protection *content_protection; + + enum weston_output_flow output_flow; }; struct weston_buffer { @@ -2158,6 +2166,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 f36ec9b..e184349 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -255,10 +255,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 */ @@ -269,7 +265,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; @@ -285,14 +280,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); } @@ -6044,27 +6038,26 @@ weston_head_get_destroy_listener(struct weston_head *head, return wl_signal_get(&head->destroy_signal, notify); } -/* 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; - - if (!delta_width) - return; + int x, y, next_x, next_y; + 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_move(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_move(output, x, y); } } @@ -6174,6 +6167,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; @@ -6201,8 +6196,6 @@ weston_output_move(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); @@ -6423,7 +6416,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); @@ -6497,7 +6490,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) { @@ -6765,7 +6758,6 @@ weston_output_enable(struct weston_output *output) output->x = x; output->y = y; - output->dirty = 1; output->original_scale = output->scale; wl_signal_init(&output->frame_signal); -- 2.20.1