1*4882a593SmuzhiyunFrom 8501bfbe04f89db1a2c7c87c09654d3d0966c7bd Mon Sep 17 00:00:00 2001
2*4882a593SmuzhiyunFrom: Jeffy Chen <jeffy.chen@rock-chips.com>
3*4882a593SmuzhiyunDate: Wed, 27 Feb 2019 17:06:58 +0800
4*4882a593SmuzhiyunSubject: [PATCH 07/79] HACK: xdg-shell: Support setting window position
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunSet window position when .set_window_geometry() called with size 0x0.
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunSigned-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
9*4882a593Smuzhiyun---
10*4882a593Smuzhiyun desktop-shell/shell.c                         |  6 ++++++
11*4882a593Smuzhiyun include/libweston-desktop/libweston-desktop.h |  3 +++
12*4882a593Smuzhiyun include/libweston/libweston.h                 |  2 ++
13*4882a593Smuzhiyun libweston-desktop/surface.c                   | 10 ++++++++++
14*4882a593Smuzhiyun libweston-desktop/xdg-shell.c                 | 10 ++++++++++
15*4882a593Smuzhiyun libweston/compositor.c                        |  2 ++
16*4882a593Smuzhiyun 6 files changed, 33 insertions(+)
17*4882a593Smuzhiyun
18*4882a593Smuzhiyundiff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
19*4882a593Smuzhiyunindex 63e1431..3c71192 100644
20*4882a593Smuzhiyun--- a/desktop-shell/shell.c
21*4882a593Smuzhiyun+++ b/desktop-shell/shell.c
22*4882a593Smuzhiyun@@ -4243,6 +4243,12 @@ weston_view_set_initial_position(struct weston_view *view,
23*4882a593Smuzhiyun 	struct weston_seat *seat;
24*4882a593Smuzhiyun 	pixman_rectangle32_t area;
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun+	if (view->has_position) {
27*4882a593Smuzhiyun+		weston_view_set_position(view,
28*4882a593Smuzhiyun+					 view->geometry.x, view->geometry.y);
29*4882a593Smuzhiyun+		return;
30*4882a593Smuzhiyun+	}
31*4882a593Smuzhiyun+
32*4882a593Smuzhiyun 	/* As a heuristic place the new window on the same output as the
33*4882a593Smuzhiyun 	 * pointer. Falling back to the output containing 0, 0.
34*4882a593Smuzhiyun 	 *
35*4882a593Smuzhiyundiff --git a/include/libweston-desktop/libweston-desktop.h b/include/libweston-desktop/libweston-desktop.h
36*4882a593Smuzhiyunindex 3e7ac73..6b54d3a 100644
37*4882a593Smuzhiyun--- a/include/libweston-desktop/libweston-desktop.h
38*4882a593Smuzhiyun+++ b/include/libweston-desktop/libweston-desktop.h
39*4882a593Smuzhiyun@@ -163,6 +163,9 @@ void
40*4882a593Smuzhiyun weston_desktop_surface_set_size(struct weston_desktop_surface *surface,
41*4882a593Smuzhiyun 				int32_t width, int32_t height);
42*4882a593Smuzhiyun void
43*4882a593Smuzhiyun+weston_desktop_surface_set_position(struct weston_desktop_surface *surface,
44*4882a593Smuzhiyun+				    int32_t x, int32_t y);
45*4882a593Smuzhiyun+void
46*4882a593Smuzhiyun weston_desktop_surface_close(struct weston_desktop_surface *surface);
47*4882a593Smuzhiyun void
48*4882a593Smuzhiyun weston_desktop_surface_add_metadata_listener(struct weston_desktop_surface *surface,
49*4882a593Smuzhiyundiff --git a/include/libweston/libweston.h b/include/libweston/libweston.h
50*4882a593Smuzhiyunindex d99dc76..bfa7e36 100644
51*4882a593Smuzhiyun--- a/include/libweston/libweston.h
52*4882a593Smuzhiyun+++ b/include/libweston/libweston.h
53*4882a593Smuzhiyun@@ -1326,6 +1326,8 @@ struct weston_view {
54*4882a593Smuzhiyun 		pixman_region32_t scissor; /* always a simple rect */
55*4882a593Smuzhiyun 	} geometry;
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun+	bool has_position;
58*4882a593Smuzhiyun+
59*4882a593Smuzhiyun 	/* State derived from geometry state, read-only.
60*4882a593Smuzhiyun 	 * This is updated by weston_view_update_transform().
61*4882a593Smuzhiyun 	 */
62*4882a593Smuzhiyundiff --git a/libweston-desktop/surface.c b/libweston-desktop/surface.c
63*4882a593Smuzhiyunindex 433f08a..21ff080 100644
64*4882a593Smuzhiyun--- a/libweston-desktop/surface.c
65*4882a593Smuzhiyun+++ b/libweston-desktop/surface.c
66*4882a593Smuzhiyun@@ -685,6 +685,16 @@ weston_desktop_surface_get_min_size(struct weston_desktop_surface *surface)
67*4882a593Smuzhiyun 						     surface->implementation_data);
68*4882a593Smuzhiyun }
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun+void
71*4882a593Smuzhiyun+weston_desktop_surface_set_position(struct weston_desktop_surface *surface,
72*4882a593Smuzhiyun+				    int32_t x, int32_t y)
73*4882a593Smuzhiyun+{
74*4882a593Smuzhiyun+	struct weston_desktop_view *view;
75*4882a593Smuzhiyun+
76*4882a593Smuzhiyun+	wl_list_for_each(view, &surface->view_list, link)
77*4882a593Smuzhiyun+		weston_view_set_position(view->view, x, y);
78*4882a593Smuzhiyun+}
79*4882a593Smuzhiyun+
80*4882a593Smuzhiyun void
81*4882a593Smuzhiyun weston_desktop_surface_set_title(struct weston_desktop_surface *surface,
82*4882a593Smuzhiyun 				 const char *title)
83*4882a593Smuzhiyundiff --git a/libweston-desktop/xdg-shell.c b/libweston-desktop/xdg-shell.c
84*4882a593Smuzhiyunindex 6cbf55e..a0161f6 100644
85*4882a593Smuzhiyun--- a/libweston-desktop/xdg-shell.c
86*4882a593Smuzhiyun+++ b/libweston-desktop/xdg-shell.c
87*4882a593Smuzhiyun@@ -1266,6 +1266,16 @@ weston_desktop_xdg_surface_protocol_set_window_geometry(struct wl_client *wl_cli
88*4882a593Smuzhiyun 	struct weston_desktop_xdg_surface *surface =
89*4882a593Smuzhiyun 		weston_desktop_surface_get_implementation_data(dsurface);
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun+	/* HACK: For setting window position */
92*4882a593Smuzhiyun+	if (!width && !height) {
93*4882a593Smuzhiyun+		struct weston_desktop_xdg_toplevel *toplevel =
94*4882a593Smuzhiyun+			weston_desktop_surface_get_implementation_data(dsurface);
95*4882a593Smuzhiyun+		if (!toplevel->current.state.fullscreen &&
96*4882a593Smuzhiyun+		    !toplevel->current.state.maximized)
97*4882a593Smuzhiyun+			weston_desktop_surface_set_position(dsurface, x, y);
98*4882a593Smuzhiyun+		return;
99*4882a593Smuzhiyun+	}
100*4882a593Smuzhiyun+
101*4882a593Smuzhiyun 	if (!weston_desktop_xdg_surface_check_role(surface))
102*4882a593Smuzhiyun 		return;
103*4882a593Smuzhiyun
104*4882a593Smuzhiyundiff --git a/libweston/compositor.c b/libweston/compositor.c
105*4882a593Smuzhiyunindex bfb4c0f..70d7127 100644
106*4882a593Smuzhiyun--- a/libweston/compositor.c
107*4882a593Smuzhiyun+++ b/libweston/compositor.c
108*4882a593Smuzhiyun@@ -1792,6 +1792,8 @@ weston_surface_damage(struct weston_surface *surface)
109*4882a593Smuzhiyun WL_EXPORT void
110*4882a593Smuzhiyun weston_view_set_position(struct weston_view *view, float x, float y)
111*4882a593Smuzhiyun {
112*4882a593Smuzhiyun+	view->has_position = true;
113*4882a593Smuzhiyun+
114*4882a593Smuzhiyun 	if (view->geometry.x == x && view->geometry.y == y)
115*4882a593Smuzhiyun 		return;
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun--
118*4882a593Smuzhiyun2.20.1
119*4882a593Smuzhiyun
120