linuxOS_AP06/buildroot/package/weston/0020-Support-setting-output-flow-direction.patch
2025-06-03 12:28:32 +08:00

291 lines
8.9 KiB
Diff

From c407d1125d0710055bf6cdb0fc359724b73e4b4a Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Wed, 27 Apr 2022 18:05:28 +0800
Subject: [PATCH 20/98] 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 <jeffy.chen@rock-chips.com>
---
clients/desktop-shell.c | 20 ++++++++++++++
desktop-shell/shell.c | 14 +++++++++-
frontend/main.c | 11 ++++++++
include/libweston/libweston.h | 11 ++++++++
libweston/compositor.c | 50 ++++++++++++++++++-----------------
5 files changed, 81 insertions(+), 25 deletions(-)
diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index 9e7863f54..f50097976 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -136,6 +136,8 @@ struct output {
int y;
struct panel *panel;
struct background *background;
+
+ struct desktop *desktop;
};
struct panel_launcher {
@@ -1283,10 +1285,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)
@@ -1356,6 +1375,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/desktop-shell/shell.c b/desktop-shell/shell.c
index a1238f07d..38ddb4aa6 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -1060,7 +1060,7 @@ constrain_position(struct weston_move_grab *move)
c = weston_coord_global_add(pointer->pos, move->delta);
if (shsurf->shell->panel_position ==
- WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP) {
+ WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP && !surface->output->pos.c.y) {
get_output_work_area(shsurf->shell, surface->output, &area);
geometry =
weston_desktop_surface_get_geometry(shsurf->desktop_surface);
@@ -2928,6 +2928,18 @@ desktop_shell_set_panel(struct wl_client *client,
wl_resource_get_user_data(surface_resource);
struct shell_output *sh_output;
struct weston_head *head = weston_head_from_resource(output_resource);
+ 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,
diff --git a/frontend/main.c b/frontend/main.c
index 3b6481d1e..3220629e4 100644
--- a/frontend/main.c
+++ b/frontend/main.c
@@ -4447,6 +4447,7 @@ wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
void *wet_xwl = NULL;
sigset_t mask;
struct sigaction action;
+ char *buf;
bool wait_for_debugger = false;
struct wl_protocol_logger *protologger = NULL;
@@ -4612,6 +4613,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/include/libweston/libweston.h b/include/libweston/libweston.h
index 731eb57c9..77b44baa2 100644
--- a/include/libweston/libweston.h
+++ b/include/libweston/libweston.h
@@ -1473,6 +1473,12 @@ struct weston_dmabuf_feedback;
struct weston_dmabuf_feedback_format_table;
struct weston_renderer;
+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
@@ -1626,6 +1632,8 @@ struct weston_compositor {
struct wl_global *weston_capture_v1;
struct wl_signal ask_auth;
} output_capture;
+
+ enum weston_output_flow output_flow;
};
struct weston_solid_buffer_values {
@@ -2836,6 +2844,9 @@ int
weston_output_mode_set_native(struct weston_output *output,
struct weston_mode *mode,
int32_t scale);
+
+void
+weston_compositor_reflow_outputs(struct weston_compositor *compositor);
#ifdef __cplusplus
}
#endif
diff --git a/libweston/compositor.c b/libweston/compositor.c
index cf56e4dd1..419d834a1 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -521,10 +521,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);
-
/** Set up the native mode for an output
*
* \param output The weston_output object
@@ -565,7 +561,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;
@@ -581,14 +576,13 @@ weston_output_mode_set_native(struct weston_output *output,
}
}
- old_width = output->width;
weston_output_copy_native_mode(output, 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);
}
@@ -7283,32 +7277,36 @@ 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;
+ int 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;
+ struct weston_coord_global pos;
+
+ if (output->destroying || output->mirror_of)
continue;
- }
- if (start_resizing) {
- struct weston_coord_global pos = output->pos;
+ pos.c = weston_coord(next_x, next_y);
+ weston_output_set_position(output, pos);
- pos.c.x += delta_width;
- weston_output_set_position(output, pos);
- }
+ 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;
+ }
+
+ wl_list_for_each(output, &compositor->output_list, link) {
+ if (!output->mirror_of)
+ continue;
+
+ weston_output_set_position(output, output->mirror_of->pos);
}
}
@@ -7707,7 +7705,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);
@@ -7786,6 +7784,8 @@ weston_output_set_transform(struct weston_output *output,
weston_output_update_matrix(output);
+ weston_compositor_reflow_outputs(output->compositor);
+
/* Notify clients of the change for output transform. */
wl_list_for_each(head, &output->head_list, output_link) {
wl_resource_for_each(resource, &head->resource_list) {
@@ -8330,6 +8330,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