1From 8501bfbe04f89db1a2c7c87c09654d3d0966c7bd 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 07/79] 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 |  3 +++
12 include/libweston/libweston.h                 |  2 ++
13 libweston-desktop/surface.c                   | 10 ++++++++++
14 libweston-desktop/xdg-shell.c                 | 10 ++++++++++
15 libweston/compositor.c                        |  2 ++
16 6 files changed, 33 insertions(+)
17
18diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
19index 63e1431..3c71192 100644
20--- a/desktop-shell/shell.c
21+++ b/desktop-shell/shell.c
22@@ -4243,6 +4243,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 3e7ac73..6b54d3a 100644
37--- a/include/libweston-desktop/libweston-desktop.h
38+++ b/include/libweston-desktop/libweston-desktop.h
39@@ -163,6 +163,9 @@ void
40 weston_desktop_surface_set_size(struct weston_desktop_surface *surface,
41 				int32_t width, int32_t height);
42 void
43+weston_desktop_surface_set_position(struct weston_desktop_surface *surface,
44+				    int32_t x, int32_t y);
45+void
46 weston_desktop_surface_close(struct weston_desktop_surface *surface);
47 void
48 weston_desktop_surface_add_metadata_listener(struct weston_desktop_surface *surface,
49diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h
50index d99dc76..bfa7e36 100644
51--- a/include/libweston/libweston.h
52+++ b/include/libweston/libweston.h
53@@ -1326,6 +1326,8 @@ struct weston_view {
54 		pixman_region32_t scissor; /* always a simple rect */
55 	} geometry;
56
57+	bool has_position;
58+
59 	/* State derived from geometry state, read-only.
60 	 * This is updated by weston_view_update_transform().
61 	 */
62diff --git a/libweston-desktop/surface.c b/libweston-desktop/surface.c
63index 433f08a..21ff080 100644
64--- a/libweston-desktop/surface.c
65+++ b/libweston-desktop/surface.c
66@@ -685,6 +685,16 @@ weston_desktop_surface_get_min_size(struct weston_desktop_surface *surface)
67 						     surface->implementation_data);
68 }
69
70+void
71+weston_desktop_surface_set_position(struct weston_desktop_surface *surface,
72+				    int32_t x, int32_t y)
73+{
74+	struct weston_desktop_view *view;
75+
76+	wl_list_for_each(view, &surface->view_list, link)
77+		weston_view_set_position(view->view, x, y);
78+}
79+
80 void
81 weston_desktop_surface_set_title(struct weston_desktop_surface *surface,
82 				 const char *title)
83diff --git a/libweston-desktop/xdg-shell.c b/libweston-desktop/xdg-shell.c
84index 6cbf55e..a0161f6 100644
85--- a/libweston-desktop/xdg-shell.c
86+++ b/libweston-desktop/xdg-shell.c
87@@ -1266,6 +1266,16 @@ weston_desktop_xdg_surface_protocol_set_window_geometry(struct wl_client *wl_cli
88 	struct weston_desktop_xdg_surface *surface =
89 		weston_desktop_surface_get_implementation_data(dsurface);
90
91+	/* HACK: For setting window position */
92+	if (!width && !height) {
93+		struct weston_desktop_xdg_toplevel *toplevel =
94+			weston_desktop_surface_get_implementation_data(dsurface);
95+		if (!toplevel->current.state.fullscreen &&
96+		    !toplevel->current.state.maximized)
97+			weston_desktop_surface_set_position(dsurface, x, y);
98+		return;
99+	}
100+
101 	if (!weston_desktop_xdg_surface_check_role(surface))
102 		return;
103
104diff --git a/libweston/compositor.c b/libweston/compositor.c
105index bfb4c0f..70d7127 100644
106--- a/libweston/compositor.c
107+++ b/libweston/compositor.c
108@@ -1792,6 +1792,8 @@ weston_surface_damage(struct weston_surface *surface)
109 WL_EXPORT void
110 weston_view_set_position(struct weston_view *view, float x, float y)
111 {
112+	view->has_position = true;
113+
114 	if (view->geometry.x == x && view->geometry.y == y)
115 		return;
116
117--
1182.20.1
119
120