commit acdd686
Michael Forney
·
2014-02-17 09:28:20 +0000 UTC
parent 19ac923
window: Setup for interactive moving and resizing
6 files changed,
+205,
-7
+15,
-6
1@@ -33,12 +33,6 @@
2 #include <assert.h>
3 #include <wld/wld.h>
4
5-struct button_press
6-{
7- uint32_t value;
8- struct pointer_handler * handler;
9-};
10-
11 static void enter(struct input_focus_handler * handler,
12 struct wl_resource * resource, struct swc_surface * surface)
13 {
14@@ -379,6 +373,20 @@ struct wl_resource * pointer_bind(struct pointer * pointer,
15 return client_resource;
16 }
17
18+struct button_press * pointer_get_button_press(struct pointer * pointer,
19+ uint32_t serial)
20+{
21+ struct button_press * button;
22+
23+ wl_array_for_each(button, &pointer->buttons)
24+ {
25+ if (button->serial == serial)
26+ return button;
27+ }
28+
29+ return NULL;
30+}
31+
32 void pointer_handle_button(struct pointer * pointer, uint32_t time,
33 uint32_t value, uint32_t state)
34 {
35@@ -414,6 +422,7 @@ void pointer_handle_button(struct pointer * pointer, uint32_t time,
36 {
37 button = wl_array_add(&pointer->buttons, sizeof *button);
38 button->value = value;
39+ button->serial = serial;
40 button->handler = handler;
41 break;
42 }
+10,
-0
1@@ -31,6 +31,13 @@
2 #include <wayland-server.h>
3 #include <pixman.h>
4
5+struct button_press
6+{
7+ uint32_t value;
8+ uint32_t serial;
9+ struct pointer_handler * handler;
10+};
11+
12 struct pointer_handler
13 {
14 bool (* motion)(struct pointer_handler * handler, uint32_t time,
15@@ -79,6 +86,9 @@ void pointer_set_focus(struct pointer * pointer, struct swc_surface * surface);
16 void pointer_set_region(struct pointer * pointer, pixman_region32_t * region);
17 void pointer_set_cursor(struct pointer * pointer, uint32_t id);
18
19+struct button_press * pointer_get_button_press(struct pointer * pointer,
20+ uint32_t serial);
21+
22 struct wl_resource * pointer_bind(struct pointer * pointer,
23 struct wl_client * client, uint32_t id);
24 void pointer_handle_button(struct pointer * pointer, uint32_t time,
+19,
-1
1@@ -23,8 +23,10 @@
2
3 #include "shell_surface.h"
4 #include "compositor.h"
5-#include "swc.h"
6+#include "internal.h"
7+#include "seat.h"
8 #include "surface.h"
9+#include "swc.h"
10 #include "util.h"
11 #include "view.h"
12 #include "window.h"
13@@ -57,12 +59,28 @@ static void pong(struct wl_client * client, struct wl_resource * resource,
14 static void move(struct wl_client * client, struct wl_resource * resource,
15 struct wl_resource * seat_resource, uint32_t serial)
16 {
17+ struct swc_shell_surface * shell_surface
18+ = wl_resource_get_user_data(resource);
19+ struct button_press * button;
20+
21+ if (!(button = pointer_get_button_press(swc.seat->pointer, serial)))
22+ return;
23+
24+ window_begin_interactive_move(&shell_surface->window, button);
25 }
26
27 static void resize(struct wl_client * client, struct wl_resource * resource,
28 struct wl_resource * seat_resource, uint32_t serial,
29 uint32_t edges)
30 {
31+ struct swc_shell_surface * shell_surface
32+ = wl_resource_get_user_data(resource);
33+ struct button_press * button;
34+
35+ if (!(button = pointer_get_button_press(swc.seat->pointer, serial)))
36+ return;
37+
38+ window_begin_interactive_resize(&shell_surface->window, edges, button);
39 }
40
41 static void set_toplevel(struct wl_client * client,
+29,
-0
1@@ -137,6 +137,35 @@ void swc_window_set_geometry(struct swc_window * window,
2 void swc_window_set_border(struct swc_window * window,
3 uint32_t color, uint32_t width);
4
5+/**
6+ * Begin an interactive move of the specified window.
7+ */
8+void swc_window_begin_move(struct swc_window * window);
9+
10+/**
11+ * End an interactive move of the specified window.
12+ */
13+void swc_window_end_move(struct swc_window * window);
14+
15+enum
16+{
17+ SWC_WINDOW_EDGE_AUTO = 0,
18+ SWC_WINDOW_EDGE_TOP = (1 << 0),
19+ SWC_WINDOW_EDGE_BOTTOM = (1 << 1),
20+ SWC_WINDOW_EDGE_LEFT = (1 << 2),
21+ SWC_WINDOW_EDGE_RIGHT = (1 << 3)
22+};
23+
24+/**
25+ * Begin an interactive resize of the specified window.
26+ */
27+void swc_window_begin_resize(struct swc_window * window, uint32_t edges);
28+
29+/**
30+ * End an interactive resize of the specified window.
31+ */
32+void swc_window_end_resize(struct swc_window * window);
33+
34 /* }}} */
35
36 /* Screens {{{ */
+109,
-0
1@@ -112,6 +112,107 @@ void swc_window_set_border(struct swc_window * window,
2 compositor_view_set_border_width(view, border_width);
3 }
4
5+static inline void window_begin_interaction
6+ (struct window * window, struct window_pointer_interaction * interaction,
7+ struct button_press * button)
8+{
9+ if (button)
10+ {
11+ interaction->original_handler = button->handler;
12+ button->handler = &interaction->handler;
13+ }
14+ else
15+ interaction->original_handler = NULL;
16+
17+ wl_list_insert(&swc.seat->pointer->handlers, &interaction->handler.link);
18+}
19+
20+void window_begin_interactive_move(struct window * window,
21+ struct button_press * button)
22+{
23+ window_begin_interaction(window, &window->move.interaction, button);
24+}
25+
26+void window_begin_interactive_resize(struct window * window, uint32_t edges,
27+ struct button_press * button)
28+{
29+ window_begin_interaction(window, &window->resize.interaction, button);
30+
31+ if (!edges)
32+ {
33+ /* TODO: Calculate edges to use */
34+ }
35+
36+ window->resize.edges = edges;
37+}
38+
39+EXPORT
40+void swc_window_begin_move(struct swc_window * base)
41+{
42+ struct window * window = (struct window *) base;
43+
44+ window_begin_interactive_move(window, NULL);
45+}
46+
47+EXPORT
48+void swc_window_end_move(struct swc_window * base)
49+{
50+ struct window * window = (struct window *) base;
51+
52+ wl_list_remove(&window->move.interaction.handler.link);
53+}
54+
55+EXPORT
56+void swc_window_begin_resize(struct swc_window * base, uint32_t edges)
57+{
58+ struct window * window = (struct window *) base;
59+
60+ window_begin_interactive_resize(window, edges, NULL);
61+}
62+
63+EXPORT
64+void swc_window_end_resize(struct swc_window * base)
65+{
66+ struct window * window = (struct window *) base;
67+
68+ wl_list_remove(&window->resize.interaction.handler.link);
69+}
70+
71+static bool move_motion(struct pointer_handler * handler, uint32_t time,
72+ wl_fixed_t fx, wl_fixed_t fy)
73+{
74+ /* TODO: Implement interactive moving */
75+
76+ return true;
77+}
78+
79+static bool resize_motion(struct pointer_handler * handler, uint32_t time,
80+ wl_fixed_t fx, wl_fixed_t fy)
81+{
82+ /* TODO: Implement interactive resizing */
83+
84+ return true;
85+}
86+
87+static bool handle_button(struct pointer_handler * handler, uint32_t time,
88+ uint32_t button, uint32_t state)
89+{
90+ struct window_pointer_interaction * interaction
91+ = CONTAINER_OF(handler, typeof(*interaction), handler);
92+
93+ if (state != WL_POINTER_BUTTON_STATE_RELEASED
94+ || !interaction->original_handler)
95+ {
96+ return false;
97+ }
98+
99+ interaction->original_handler->button
100+ (interaction->original_handler, time, button, state);
101+ wl_list_remove(&handler->link);
102+
103+ return true;
104+}
105+
106 bool window_initialize(struct window * window, const struct window_impl * impl,
107 struct swc_surface * surface)
108 {
109@@ -128,6 +229,14 @@ bool window_initialize(struct window * window, const struct window_impl * impl,
110
111 window->surface = surface;
112 window->impl = impl;
113+ window->move.interaction.handler = (struct pointer_handler) {
114+ .motion = &move_motion,
115+ .button = &handle_button
116+ };
117+ window->resize.interaction.handler = (struct pointer_handler) {
118+ .motion = &resize_motion,
119+ .button = &handle_button
120+ };
121
122 surface->window = window;
123
+23,
-0
1@@ -25,10 +25,16 @@
2 #define SWC_WINDOW_H
3
4 #include "swc.h"
5+#include "pointer.h"
6
7 #include <stdint.h>
8 #include <wayland-server.h>
9
10+struct window_pointer_interaction
11+{
12+ struct pointer_handler handler, * original_handler;
13+};
14+
15 struct window
16 {
17 struct swc_window base;
18@@ -36,6 +42,17 @@ struct window
19
20 struct swc_surface * surface;
21 struct swc_view * view;
22+
23+ struct
24+ {
25+ struct window_pointer_interaction interaction;
26+ } move;
27+
28+ struct
29+ {
30+ struct window_pointer_interaction interaction;
31+ uint32_t edges;
32+ } resize;
33 };
34
35 struct window_impl
36@@ -61,5 +78,11 @@ void window_set_state(struct window * window, uint32_t state);
37
38 void window_set_parent(struct window * window, struct window * parent);
39
40+void window_begin_interactive_move(struct window * window,
41+ struct button_press * button);
42+
43+void window_begin_interactive_resize(struct window * window, uint32_t edges,
44+ struct button_press * button);
45+
46 #endif
47