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 Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
16 (cherry-picked from 37a3025d893def991dec59587d17672aa3bf967a)
18 Note that this was actually ported because libweston-desktop is not
19 embedded into libweston and the structure changed in upstream.
21 include/libweston-desktop/libweston-desktop.h | 11 ++++++
22 libweston-desktop/internal.h | 2 +
23 libweston-desktop/surface.c | 10 +++++
24 libweston-desktop/xdg-shell.c | 38 +++++++++++++++++++
25 4 files changed, 61 insertions(+)
27 diff --git a/include/libweston-desktop/libweston-desktop.h b/include/libweston-desktop/libweston-desktop.h
28 index 3e7ac73..c296d16 100644
29 --- a/include/libweston-desktop/libweston-desktop.h
30 +++ b/include/libweston-desktop/libweston-desktop.h
31 @@ -44,6 +44,14 @@ enum weston_desktop_surface_edge {
32 WESTON_DESKTOP_SURFACE_EDGE_BOTTOM_RIGHT = 10,
35 +enum weston_top_level_tiled_orientation {
36 + WESTON_TOP_LEVEL_TILED_ORIENTATION_NONE = 0 << 0,
37 + WESTON_TOP_LEVEL_TILED_ORIENTATION_LEFT = 1 << 1,
38 + WESTON_TOP_LEVEL_TILED_ORIENTATION_RIGHT = 1 << 2,
39 + WESTON_TOP_LEVEL_TILED_ORIENTATION_TOP = 1 << 3,
40 + WESTON_TOP_LEVEL_TILED_ORIENTATION_BOTTOM = 1 << 4,
43 struct weston_desktop;
44 struct weston_desktop_client;
45 struct weston_desktop_surface;
46 @@ -163,6 +171,9 @@ void
47 weston_desktop_surface_set_size(struct weston_desktop_surface *surface,
48 int32_t width, int32_t height);
50 +weston_desktop_surface_set_orientation(struct weston_desktop_surface *surface,
51 + enum weston_top_level_tiled_orientation tile_orientation);
53 weston_desktop_surface_close(struct weston_desktop_surface *surface);
55 weston_desktop_surface_add_metadata_listener(struct weston_desktop_surface *surface,
56 diff --git a/libweston-desktop/internal.h b/libweston-desktop/internal.h
57 index 2606d27..8afdede 100644
58 --- a/libweston-desktop/internal.h
59 +++ b/libweston-desktop/internal.h
60 @@ -100,6 +100,8 @@ struct weston_desktop_surface_implementation {
61 void *user_data, bool resizing);
62 void (*set_size)(struct weston_desktop_surface *surface,
63 void *user_data, int32_t width, int32_t height);
64 + void (*set_orientation)(struct weston_desktop_surface *surface,
65 + void *user_data, enum weston_top_level_tiled_orientation tiled_orientation);
66 void (*committed)(struct weston_desktop_surface *surface, void *user_data,
67 int32_t sx, int32_t sy);
68 void (*update_position)(struct weston_desktop_surface *surface,
69 diff --git a/libweston-desktop/surface.c b/libweston-desktop/surface.c
70 index 433f08a..6b3f4ae 100644
71 --- a/libweston-desktop/surface.c
72 +++ b/libweston-desktop/surface.c
73 @@ -506,6 +506,16 @@ weston_desktop_surface_set_size(struct weston_desktop_surface *surface, int32_t
78 +weston_desktop_surface_set_orientation(struct weston_desktop_surface *surface,
79 + enum weston_top_level_tiled_orientation tile_orientation)
81 + if (surface->implementation->set_orientation != NULL)
82 + surface->implementation->set_orientation(surface,
83 + surface->implementation_data,
88 weston_desktop_surface_close(struct weston_desktop_surface *surface)
90 diff --git a/libweston-desktop/xdg-shell.c b/libweston-desktop/xdg-shell.c
91 index ff76c39..1e49147 100644
92 --- a/libweston-desktop/xdg-shell.c
93 +++ b/libweston-desktop/xdg-shell.c
94 @@ -94,6 +94,7 @@ struct weston_desktop_xdg_toplevel_state {
98 + uint32_t tiled_orientation;
101 struct weston_desktop_xdg_toplevel_configure {
102 @@ -624,6 +625,29 @@ weston_desktop_xdg_toplevel_send_configure(struct weston_desktop_xdg_toplevel *t
103 s = wl_array_add(&states, sizeof(uint32_t));
104 *s = XDG_TOPLEVEL_STATE_ACTIVATED;
106 + if (toplevel->pending.state.tiled_orientation &
107 + WESTON_TOP_LEVEL_TILED_ORIENTATION_LEFT) {
108 + s = wl_array_add(&states, sizeof(uint32_t));
109 + *s = XDG_TOPLEVEL_STATE_TILED_LEFT;
112 + if (toplevel->pending.state.tiled_orientation &
113 + WESTON_TOP_LEVEL_TILED_ORIENTATION_RIGHT) {
114 + s = wl_array_add(&states, sizeof(uint32_t));
115 + *s = XDG_TOPLEVEL_STATE_TILED_RIGHT;
118 + if (toplevel->pending.state.tiled_orientation &
119 + WESTON_TOP_LEVEL_TILED_ORIENTATION_TOP) {
120 + s = wl_array_add(&states, sizeof(uint32_t));
121 + *s = XDG_TOPLEVEL_STATE_TILED_TOP;
124 + if (toplevel->pending.state.tiled_orientation &
125 + WESTON_TOP_LEVEL_TILED_ORIENTATION_BOTTOM) {
126 + s = wl_array_add(&states, sizeof(uint32_t));
127 + *s = XDG_TOPLEVEL_STATE_TILED_BOTTOM;
130 xdg_toplevel_send_configure(toplevel->resource,
131 toplevel->pending.size.width,
132 @@ -686,6 +710,16 @@ weston_desktop_xdg_toplevel_set_size(struct weston_desktop_surface *dsurface,
133 weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
137 +weston_desktop_xdg_toplevel_set_orientation(struct weston_desktop_surface *surface, void *user_data,
138 + enum weston_top_level_tiled_orientation tiled_orientation)
140 + struct weston_desktop_xdg_toplevel *toplevel = user_data;
142 + toplevel->pending.state.tiled_orientation = tiled_orientation;
143 + weston_desktop_xdg_surface_schedule_configure(&toplevel->base);
147 weston_desktop_xdg_toplevel_committed(struct weston_desktop_xdg_toplevel *toplevel,
148 int32_t sx, int32_t sy)
149 @@ -1096,6 +1130,9 @@ weston_desktop_xdg_toplevel_state_compare(struct weston_desktop_xdg_toplevel *to
151 if (toplevel->pending.state.resizing != configured.state.resizing)
153 + if (toplevel->pending.state.tiled_orientation !=
154 + configured.state.tiled_orientation)
157 if (toplevel->pending.size.width == configured.size.width &&
158 toplevel->pending.size.height == configured.size.height)
159 @@ -1440,6 +1477,7 @@ static const struct weston_desktop_surface_implementation weston_desktop_xdg_sur
160 .set_resizing = weston_desktop_xdg_toplevel_set_resizing,
161 .set_activated = weston_desktop_xdg_toplevel_set_activated,
162 .set_size = weston_desktop_xdg_toplevel_set_size,
163 + .set_orientation = weston_desktop_xdg_toplevel_set_orientation,
165 .get_maximized = weston_desktop_xdg_toplevel_get_maximized,
166 .get_fullscreen = weston_desktop_xdg_toplevel_get_fullscreen,