1From 467e75739f3afddeaa1c3208fd029e36a34c7fc0 Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Wed, 27 Feb 2019 17:06:58 +0800
4Subject: [PATCH 08/93] HACK: xdg-shell: Support setting window position
5
6Set window position when .set_window_geometry() called with size 0x0.
7
8Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
9---
10 desktop-shell/shell.c                         |  6 ++++++
11 include/libweston-desktop/libweston-desktop.h |  4 ++++
12 include/libweston/libweston.h                 |  2 ++
13 libweston/compositor.c                        |  2 ++
14 libweston/desktop/surface.c                   | 10 ++++++++++
15 libweston/desktop/xdg-shell.c                 | 10 ++++++++++
16 6 files changed, 34 insertions(+)
17
18diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
19index 9da08ae..7363ee3 100644
20--- a/desktop-shell/shell.c
21+++ b/desktop-shell/shell.c
22@@ -3821,6 +3821,12 @@ weston_view_set_initial_position(struct weston_view *view,
23 	struct weston_seat *seat;
24 	pixman_rectangle32_t area;
25
26+	if (view->has_position) {
27+		weston_view_set_position(view,
28+					 view->geometry.x, view->geometry.y);
29+		return;
30+	}
31+
32 	/* As a heuristic place the new window on the same output as the
33 	 * pointer. Falling back to the output containing 0, 0.
34 	 *
35diff --git a/include/libweston-desktop/libweston-desktop.h b/include/libweston-desktop/libweston-desktop.h
36index 3536935..09e00c6 100644
37--- a/include/libweston-desktop/libweston-desktop.h
38+++ b/include/libweston-desktop/libweston-desktop.h
39@@ -176,6 +176,10 @@ weston_desktop_surface_set_size(struct weston_desktop_surface *surface,
40 void
41 weston_desktop_surface_set_orientation(struct weston_desktop_surface *surface,
42 				       enum weston_top_level_tiled_orientation tile_orientation);
43+
44+void
45+weston_desktop_surface_set_position(struct weston_desktop_surface *surface,
46+				    int32_t x, int32_t y);
47 void
48 weston_desktop_surface_close(struct weston_desktop_surface *surface);
49 void
50diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h
51index 7382dd2..89c5feb 100644
52--- a/include/libweston/libweston.h
53+++ b/include/libweston/libweston.h
54@@ -1489,6 +1489,8 @@ struct weston_view {
55 		pixman_region32_t scissor; /* always a simple rect */
56 	} geometry;
57
58+	bool has_position;
59+
60 	/* State derived from geometry state, read-only.
61 	 * This is updated by weston_view_update_transform().
62 	 */
63diff --git a/libweston/compositor.c b/libweston/compositor.c
64index e166911..caec3e2 100644
65--- a/libweston/compositor.c
66+++ b/libweston/compositor.c
67@@ -1810,6 +1810,8 @@ weston_surface_damage(struct weston_surface *surface)
68 WL_EXPORT void
69 weston_view_set_position(struct weston_view *view, float x, float y)
70 {
71+	view->has_position = true;
72+
73 	if (view->geometry.x == x && view->geometry.y == y)
74 		return;
75
76diff --git a/libweston/desktop/surface.c b/libweston/desktop/surface.c
77index 6b3f4ae..54e493c 100644
78--- a/libweston/desktop/surface.c
79+++ b/libweston/desktop/surface.c
80@@ -695,6 +695,16 @@ weston_desktop_surface_get_min_size(struct weston_desktop_surface *surface)
81 						     surface->implementation_data);
82 }
83
84+void
85+weston_desktop_surface_set_position(struct weston_desktop_surface *surface,
86+				    int32_t x, int32_t y)
87+{
88+	struct weston_desktop_view *view;
89+
90+	wl_list_for_each(view, &surface->view_list, link)
91+		weston_view_set_position(view->view, x, y);
92+}
93+
94 void
95 weston_desktop_surface_set_title(struct weston_desktop_surface *surface,
96 				 const char *title)
97diff --git a/libweston/desktop/xdg-shell.c b/libweston/desktop/xdg-shell.c
98index ca9862c..636dc29 100644
99--- a/libweston/desktop/xdg-shell.c
100+++ b/libweston/desktop/xdg-shell.c
101@@ -1342,6 +1342,16 @@ weston_desktop_xdg_surface_protocol_set_window_geometry(struct wl_client *wl_cli
102 	struct weston_desktop_xdg_surface *surface =
103 		weston_desktop_surface_get_implementation_data(dsurface);
104
105+	/* HACK: For setting window position */
106+	if (!width && !height) {
107+		struct weston_desktop_xdg_toplevel *toplevel =
108+			weston_desktop_surface_get_implementation_data(dsurface);
109+		if (!toplevel->current.state.fullscreen &&
110+		    !toplevel->current.state.maximized)
111+			weston_desktop_surface_set_position(dsurface, x, y);
112+		return;
113+	}
114+
115 	if (!weston_desktop_xdg_surface_check_role(surface))
116 		return;
117
118--
1192.20.1
120
121