commit 1bb790d
Michael Forney
·
2014-10-01 04:55:49 +0000 UTC
parent 98a3a36
Add support for atomic moves and resizes
6 files changed,
+73,
-3
+2,
-0
1@@ -51,6 +51,8 @@ static void configure(struct window * window, uint32_t width, uint32_t height)
2 wl_shell_surface_send_configure(shell_surface->resource,
3 WL_SHELL_SURFACE_RESIZE_NONE,
4 width, height);
5+ /* wl_shell does not support acknowledging configures. */
6+ window->configure.acknowledged = true;
7 }
8
9 static void close(struct window * window)
+2,
-0
1@@ -60,6 +60,7 @@ void view_finalize(struct view * view)
2 int view_attach(struct view * view, struct wld_buffer * buffer)
3 {
4 int ret;
5+ struct view_handler * handler;
6
7 if ((ret = view->impl->attach(view, buffer)) < 0)
8 return ret;
9@@ -71,6 +72,7 @@ int view_attach(struct view * view, struct wld_buffer * buffer)
10 wld_buffer_reference(buffer);
11
12 view->buffer = buffer;
13+ HANDLE(view, handler, attach);
14
15 return 0;
16 }
+2,
-0
1@@ -71,6 +71,8 @@ struct view_handler_impl
2 {
3 /* Called when the view has displayed the next frame. */
4 void (* frame)(struct view_handler * handler, uint32_t time);
5+ /* Called when a new buffer is attached to the view. */
6+ void (* attach)(struct view_handler * handler);
7 /* Called after the view's position changes. */
8 void (* move)(struct view_handler * handler);
9 /* Called after the view's size changes. */
+57,
-3
1@@ -95,6 +95,18 @@ static void end_interaction(struct window_pointer_interaction * interaction)
2 wl_list_remove(&interaction->handler.link);
3 }
4
5+static void flush(struct window * window)
6+{
7+ if (window->move.pending)
8+ {
9+ if (window->impl->move)
10+ window->impl->move(window, window->move.x, window->move.y);
11+
12+ view_move(&window->view->base, window->move.x, window->move.y);
13+ window->move.pending = false;
14+ }
15+}
16+
17 EXPORT
18 void swc_window_set_handler(struct swc_window * base,
19 const struct swc_window_handler * handler,
20@@ -153,6 +165,10 @@ void swc_window_set_stacked(struct swc_window * base)
21 {
22 struct window * window = INTERNAL(base);
23
24+ flush(window);
25+ window->configure.pending = false;
26+ window->configure.width = 0;
27+ window->configure.height = 0;
28 if (window->impl->set_mode)
29 window->impl->set_mode(window, WINDOW_MODE_STACKED);
30 window->mode = WINDOW_MODE_STACKED;
31@@ -190,11 +206,18 @@ void swc_window_set_position(struct swc_window * base, int32_t x, int32_t y)
32 struct swc_rectangle * geometry = &window->view->base.geometry;
33
34 if (x == geometry->x && y == geometry->y)
35+ {
36+ window->move.pending = false;
37 return;
38+ }
39+
40+ window->move.x = x;
41+ window->move.y = y;
42+ window->move.pending = true;
43
44- if (window->impl->move)
45- window->impl->move(window, x, y);
46- view_move(&window->view->base, x, y);
47+ /* If we don't have a configure pending, perform the move now. */
48+ if (!window->configure.pending)
49+ flush(window);
50 }
51
52 EXPORT
53@@ -202,8 +225,25 @@ void swc_window_set_size(struct swc_window * base,
54 uint32_t width, uint32_t height)
55 {
56 struct window * window = INTERNAL(base);
57+ struct swc_rectangle * geometry = &window->view->base.geometry;
58+
59+ if ((window->configure.pending
60+ && width == window->configure.width
61+ && height == window->configure.height)
62+ || (!window->configure.pending
63+ && width == geometry->width && height == geometry->height))
64+ {
65+ return;
66+ }
67
68 window->impl->configure(window, width, height);
69+
70+ if (window->mode == WINDOW_MODE_TILED)
71+ {
72+ window->configure.width = width;
73+ window->configure.height = height;
74+ window->configure.pending = true;
75+ }
76 }
77
78 EXPORT
79@@ -301,6 +341,15 @@ static bool handle_button(struct pointer_handler * handler, uint32_t time,
80 return true;
81 }
82
83+static void handle_attach(struct view_handler * handler)
84+{
85+ struct window * window = wl_container_of(handler, window, view_handler);
86+
87+ if (window->configure.acknowledged)
88+ flush(window);
89+ window->configure.pending = false;
90+}
91+
92 static void handle_resize(struct view_handler * handler,
93 uint32_t old_width, uint32_t old_height)
94 {
95@@ -322,6 +371,7 @@ static void handle_resize(struct view_handler * handler,
96 }
97
98 static const struct view_handler_impl view_handler_impl = {
99+ .attach = &handle_attach,
100 .resize = &handle_resize,
101 };
102
103@@ -343,11 +393,15 @@ bool window_initialize(struct window * window, const struct window_impl * impl,
104 window->view->window = window;
105 window->managed = false;
106 window->mode = WINDOW_MODE_STACKED;
107+ window->move.pending = false;
108 window->move.interaction.active = false;
109 window->move.interaction.handler = (struct pointer_handler) {
110 .motion = &move_motion,
111 .button = &handle_button
112 };
113+ window->configure.pending = false;
114+ window->configure.width = 0;
115+ window->configure.height = 0;
116 window->resize.interaction.active = false;
117 window->resize.interaction.handler = (struct pointer_handler) {
118 .motion = &resize_motion,
+9,
-0
1@@ -60,6 +60,9 @@ struct window
2 {
3 struct window_pointer_interaction interaction;
4 struct { int32_t x, y; } offset;
5+
6+ bool pending;
7+ int32_t x, y;
8 } move;
9
10 struct
11@@ -68,6 +71,12 @@ struct window
12 struct { int32_t x, y; } offset;
13 uint32_t edges;
14 } resize;
15+
16+ struct
17+ {
18+ bool pending, acknowledged;
19+ uint32_t width, height;
20+ } configure;
21 };
22
23 struct window_impl
+1,
-0
1@@ -175,6 +175,7 @@ static void configure(struct window * window, uint32_t width, uint32_t height)
2 values[0] = width;
3 values[1] = height;
4
5+ window->configure.acknowledged = true;
6 xcb_configure_window(xwm.connection, xwl_window->id, mask, values);
7 xcb_flush(xwm.connection);
8 }