1 From 6ab4713d3eba589aa1f39eee2b48c81906d7ba87 Mon Sep 17 00:00:00 2001
2 From: Marius Vlad <marius.vlad@collabora.com>
3 Date: Tue, 16 Aug 2022 13:34:19 +0300
4 Subject: [PATCH] libweston/desktop/xdg-shell: Add tiled orientation states
6 With the help of a newly introduced function, weston_desktop_surface_set_orientation(),
7 this patch adds missing tiled states from the xdg-shell protocol.
8 The orientation state is passed on as a bitmask enumeration flag, which the
9 shell can set, allowing multiple tiling states at once.
11 These new states are incorporated the same way as the others, retaining
12 the set state, but also avoiding sending new configure events if nothing
13 changed since previously acked data.
15 Upstream-Status: Pending
17 Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
18 (cherry-picked from 37a3025d893def991dec59587d17672aa3bf967a)
20 Note that this was actually ported because libweston-desktop is not
21 embedded into libweston and the structure changed in upstream.
23 include/libweston-desktop/libweston-desktop.h | 11 ++++++
24 libweston-desktop/internal.h | 2 +
25 libweston-desktop/surface.c | 10 +++++
26 libweston-desktop/xdg-shell.c | 38 +++++++++++++++++++
27 4 files changed, 61 insertions(+)
29 diff --git a/include/libweston-desktop/libweston-desktop.h b/include/libweston-desktop/libweston-desktop.h
30 index 3e7ac73..c296d16 100644
31 --- a/include/libweston-desktop/libweston-desktop.h
32 +++ b/include/libweston-desktop/libweston-desktop.h
33 @@ -44,6 +44,14 @@ enum weston_desktop_surface_edge {
34 WESTON_DESKTOP_SURFACE_EDGE_BOTTOM_RIGHT = 10,
37 +enum weston_top_level_tiled_orientation {
38 + WESTON_TOP_LEVEL_TILED_ORIENTATION_NONE = 0 << 0,
39 + WESTON_TOP_LEVEL_TILED_ORIENTATION_LEFT = 1 << 1,
40 + WESTON_TOP_LEVEL_TILED_ORIENTATION_RIGHT = 1 << 2,
41 + WESTON_TOP_LEVEL_TILED_ORIENTATION_TOP = 1 << 3,
42 + WESTON_TOP_LEVEL_TILED_ORIENTATION_BOTTOM = 1 << 4,
45 struct weston_desktop;
46 struct weston_desktop_client;
47 struct weston_desktop_surface;
48 @@ -163,6 +171,9 @@ void
49 weston_desktop_surface_set_size(struct weston_desktop_surface *surface,
50 int32_t width, int32_t height);
52 +weston_desktop_surface_set_orientation(struct weston_desktop_surface *surface,
53 + enum weston_top_level_tiled_orientation tile_orientation);
55 weston_desktop_surface_close(struct weston_desktop_surface *surface);
57 weston_desktop_surface_add_metadata_listener(struct weston_desktop_surface *surface,
58 diff --git a/libweston-desktop/internal.h b/libweston-desktop/internal.h
59 index 2606d27..8afdede 100644
60 --- a/libweston-desktop/internal.h
61 +++ b/libweston-desktop/internal.h
62 @@ -100,6 +100,8 @@ struct weston_desktop_surface_implementation {
63 void *user_data, bool resizing);
64 void (*set_size)(struct weston_desktop_surface *surface,
65 void *user_data, int32_t width, int32_t height);
66 + void (*set_orientation)(struct weston_desktop_surface *surface,
67 + void *user_data, enum weston_top_level_tiled_orientation tiled_orientation);
68 void (*committed)(struct weston_desktop_surface *surface, void *user_data,
69 int32_t sx, int32_t sy);
70 void (*update_position)(struct weston_desktop_surface *surface,
71 diff --git a/libweston-desktop/surface.c b/libweston-desktop/surface.c
72 index 433f08a..6b3f4ae 100644
73 --- a/libweston-desktop/surface.c
74 +++ b/libweston-desktop/surface.c
75 @@ -506,6 +506,16 @@ weston_desktop_surface_set_size(struct weston_desktop_surface *surface, int32_t
80 +weston_desktop_surface_set_orientation(struct weston_desktop_surface *surface,
81 + enum weston_top_level_tiled_orientation tile_orientation)
83 + if (surface->implementation->set_orientation != NULL)
84 + surface->implementation->set_orientation(surface,
85 + surface->implementation_data,
90 weston_desktop_surface_close(struct weston_desktop_surface *surface)
92 diff --git a/libweston-desktop/xdg-shell.c b/libweston-desktop/xdg-shell.c
93 index ff76c39..1e49147 100644
94 --- a/libweston-desktop/xdg-shell.c
95 +++ b/libweston-desktop/xdg-shell.c
96 @@ -94,6 +94,7 @@ struct weston_desktop_xdg_toplevel_state {
100 + uint32_t tiled_orientation;
103 struct weston_desktop_xdg_toplevel_configure {
104 @@ -624,6 +625,29 @@ weston_desktop_xdg_toplevel_send_configure(struct weston_desktop_xdg_toplevel *t
105 s = wl_array_add(&states, sizeof(uint32_t));
106 *s = XDG_TOPLEVEL_STATE_ACTIVATED;
108 + if (toplevel->pending.state.tiled_orientation &
109 + WESTON_TOP_LEVEL_TILED_ORIENTATION_LEFT) {
110 + s = wl_array_add(&states, sizeof(uint32_t));
111 + *s = XDG_TOPLEVEL_STATE_TILED_LEFT;
114 + if (toplevel->pending.state.tiled_orientation &
115 + WESTON_TOP_LEVEL_TILED_ORIENTATION_RIGHT) {
116 + s = wl_array_add(&states, sizeof(uint32_t));
117 + *s = XDG_TOPLEVEL_STATE_TILED_RIGHT;
120 + if (toplevel->pending.state.tiled_orientation &
121 + WESTON_TOP_LEVEL_TILED_ORIENTATION_TOP) {
122 + s = wl_array_add(&states, sizeof(uint32_t));
123 + *s = XDG_TOPLEVEL_STATE_TILED_TOP;
126 + if (toplevel->pending.state.tiled_orientation &
127 + WESTON_TOP_LEVEL_TILED_ORIENTATION_BOTTOM) {
128 + s = wl_array_add(&states, sizeof(uint32_t));
129 + *s = XDG_TOPLEVEL_STATE_TILED_BOTTOM;
132 xdg_toplevel_send_configure(toplevel->resource,
133 toplevel->pending.size.width,
134 @@ -686,6 +710,16 @@ weston_desktop_xdg_toplevel_set_size(struct weston_desktop_surface *dsurface,
135 weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
139 +weston_desktop_xdg_toplevel_set_orientation(struct weston_desktop_surface *surface, void *user_data,
140 + enum weston_top_level_tiled_orientation tiled_orientation)
142 + struct weston_desktop_xdg_toplevel *toplevel = user_data;
144 + toplevel->pending.state.tiled_orientation = tiled_orientation;
145 + weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
149 weston_desktop_xdg_toplevel_committed(struct weston_desktop_xdg_toplevel *toplevel,
150 int32_t sx, int32_t sy)
151 @@ -1096,6 +1130,9 @@ weston_desktop_xdg_toplevel_state_compare(struct weston_desktop_xdg_toplevel *to
153 if (toplevel->pending.state.resizing != configured.state.resizing)
155 + if (toplevel->pending.state.tiled_orientation !=
156 + configured.state.tiled_orientation)
159 if (toplevel->pending.size.width == configured.size.width &&
160 toplevel->pending.size.height == configured.size.height)
161 @@ -1440,6 +1477,7 @@ static const struct weston_desktop_surface_implementation weston_desktop_xdg_sur
162 .set_resizing = weston_desktop_xdg_toplevel_set_resizing,
163 .set_activated = weston_desktop_xdg_toplevel_set_activated,
164 .set_size = weston_desktop_xdg_toplevel_set_size,
165 + .set_orientation = weston_desktop_xdg_toplevel_set_orientation,
167 .get_maximized = weston_desktop_xdg_toplevel_get_maximized,
168 .get_fullscreen = weston_desktop_xdg_toplevel_get_fullscreen,