swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit acdd6869316bd9d00320ae4f9222d9551057b5cf
parent 19ac923129bcb96df9616845ff5708b9fdfbe600
Author: Michael Forney <mforney@mforney.org>
Date:   Mon, 17 Feb 2014 01:28:20 -0800

window: Setup for interactive moving and resizing

Diffstat:
Mlibswc/pointer.c | 21+++++++++++++++------
Mlibswc/pointer.h | 10++++++++++
Mlibswc/shell_surface.c | 20+++++++++++++++++++-
Mlibswc/swc.h | 29+++++++++++++++++++++++++++++
Mlibswc/window.c | 109+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mlibswc/window.h | 23+++++++++++++++++++++++
6 files changed, 205 insertions(+), 7 deletions(-)

diff --git a/libswc/pointer.c b/libswc/pointer.c @@ -33,12 +33,6 @@ #include <assert.h> #include <wld/wld.h> -struct button_press -{ - uint32_t value; - struct pointer_handler * handler; -}; - static void enter(struct input_focus_handler * handler, struct wl_resource * resource, struct swc_surface * surface) { @@ -379,6 +373,20 @@ struct wl_resource * pointer_bind(struct pointer * pointer, return client_resource; } +struct button_press * pointer_get_button_press(struct pointer * pointer, + uint32_t serial) +{ + struct button_press * button; + + wl_array_for_each(button, &pointer->buttons) + { + if (button->serial == serial) + return button; + } + + return NULL; +} + void pointer_handle_button(struct pointer * pointer, uint32_t time, uint32_t value, uint32_t state) { @@ -414,6 +422,7 @@ void pointer_handle_button(struct pointer * pointer, uint32_t time, { button = wl_array_add(&pointer->buttons, sizeof *button); button->value = value; + button->serial = serial; button->handler = handler; break; } diff --git a/libswc/pointer.h b/libswc/pointer.h @@ -31,6 +31,13 @@ #include <wayland-server.h> #include <pixman.h> +struct button_press +{ + uint32_t value; + uint32_t serial; + struct pointer_handler * handler; +}; + struct pointer_handler { bool (* motion)(struct pointer_handler * handler, uint32_t time, @@ -79,6 +86,9 @@ void pointer_set_focus(struct pointer * pointer, struct swc_surface * surface); void pointer_set_region(struct pointer * pointer, pixman_region32_t * region); void pointer_set_cursor(struct pointer * pointer, uint32_t id); +struct button_press * pointer_get_button_press(struct pointer * pointer, + uint32_t serial); + struct wl_resource * pointer_bind(struct pointer * pointer, struct wl_client * client, uint32_t id); void pointer_handle_button(struct pointer * pointer, uint32_t time, diff --git a/libswc/shell_surface.c b/libswc/shell_surface.c @@ -23,8 +23,10 @@ #include "shell_surface.h" #include "compositor.h" -#include "swc.h" +#include "internal.h" +#include "seat.h" #include "surface.h" +#include "swc.h" #include "util.h" #include "view.h" #include "window.h" @@ -57,12 +59,28 @@ static void pong(struct wl_client * client, struct wl_resource * resource, static void move(struct wl_client * client, struct wl_resource * resource, struct wl_resource * seat_resource, uint32_t serial) { + struct swc_shell_surface * shell_surface + = wl_resource_get_user_data(resource); + struct button_press * button; + + if (!(button = pointer_get_button_press(swc.seat->pointer, serial))) + return; + + window_begin_interactive_move(&shell_surface->window, button); } static void resize(struct wl_client * client, struct wl_resource * resource, struct wl_resource * seat_resource, uint32_t serial, uint32_t edges) { + struct swc_shell_surface * shell_surface + = wl_resource_get_user_data(resource); + struct button_press * button; + + if (!(button = pointer_get_button_press(swc.seat->pointer, serial))) + return; + + window_begin_interactive_resize(&shell_surface->window, edges, button); } static void set_toplevel(struct wl_client * client, diff --git a/libswc/swc.h b/libswc/swc.h @@ -137,6 +137,35 @@ void swc_window_set_geometry(struct swc_window * window, void swc_window_set_border(struct swc_window * window, uint32_t color, uint32_t width); +/** + * Begin an interactive move of the specified window. + */ +void swc_window_begin_move(struct swc_window * window); + +/** + * End an interactive move of the specified window. + */ +void swc_window_end_move(struct swc_window * window); + +enum +{ + SWC_WINDOW_EDGE_AUTO = 0, + SWC_WINDOW_EDGE_TOP = (1 << 0), + SWC_WINDOW_EDGE_BOTTOM = (1 << 1), + SWC_WINDOW_EDGE_LEFT = (1 << 2), + SWC_WINDOW_EDGE_RIGHT = (1 << 3) +}; + +/** + * Begin an interactive resize of the specified window. + */ +void swc_window_begin_resize(struct swc_window * window, uint32_t edges); + +/** + * End an interactive resize of the specified window. + */ +void swc_window_end_resize(struct swc_window * window); + /* }}} */ /* Screens {{{ */ diff --git a/libswc/window.c b/libswc/window.c @@ -112,6 +112,107 @@ void swc_window_set_border(struct swc_window * window, compositor_view_set_border_width(view, border_width); } +static inline void window_begin_interaction + (struct window * window, struct window_pointer_interaction * interaction, + struct button_press * button) +{ + if (button) + { + interaction->original_handler = button->handler; + button->handler = &interaction->handler; + } + else + interaction->original_handler = NULL; + + wl_list_insert(&swc.seat->pointer->handlers, &interaction->handler.link); +} + +void window_begin_interactive_move(struct window * window, + struct button_press * button) +{ + window_begin_interaction(window, &window->move.interaction, button); +} + +void window_begin_interactive_resize(struct window * window, uint32_t edges, + struct button_press * button) +{ + window_begin_interaction(window, &window->resize.interaction, button); + + if (!edges) + { + /* TODO: Calculate edges to use */ + } + + window->resize.edges = edges; +} + +EXPORT +void swc_window_begin_move(struct swc_window * base) +{ + struct window * window = (struct window *) base; + + window_begin_interactive_move(window, NULL); +} + +EXPORT +void swc_window_end_move(struct swc_window * base) +{ + struct window * window = (struct window *) base; + + wl_list_remove(&window->move.interaction.handler.link); +} + +EXPORT +void swc_window_begin_resize(struct swc_window * base, uint32_t edges) +{ + struct window * window = (struct window *) base; + + window_begin_interactive_resize(window, edges, NULL); +} + +EXPORT +void swc_window_end_resize(struct swc_window * base) +{ + struct window * window = (struct window *) base; + + wl_list_remove(&window->resize.interaction.handler.link); +} + +static bool move_motion(struct pointer_handler * handler, uint32_t time, + wl_fixed_t fx, wl_fixed_t fy) +{ + /* TODO: Implement interactive moving */ + + return true; +} + +static bool resize_motion(struct pointer_handler * handler, uint32_t time, + wl_fixed_t fx, wl_fixed_t fy) +{ + /* TODO: Implement interactive resizing */ + + return true; +} + +static bool handle_button(struct pointer_handler * handler, uint32_t time, + uint32_t button, uint32_t state) +{ + struct window_pointer_interaction * interaction + = CONTAINER_OF(handler, typeof(*interaction), handler); + + if (state != WL_POINTER_BUTTON_STATE_RELEASED + || !interaction->original_handler) + { + return false; + } + + interaction->original_handler->button + (interaction->original_handler, time, button, state); + wl_list_remove(&handler->link); + + return true; +} + bool window_initialize(struct window * window, const struct window_impl * impl, struct swc_surface * surface) { @@ -128,6 +229,14 @@ bool window_initialize(struct window * window, const struct window_impl * impl, window->surface = surface; window->impl = impl; + window->move.interaction.handler = (struct pointer_handler) { + .motion = &move_motion, + .button = &handle_button + }; + window->resize.interaction.handler = (struct pointer_handler) { + .motion = &resize_motion, + .button = &handle_button + }; surface->window = window; diff --git a/libswc/window.h b/libswc/window.h @@ -25,10 +25,16 @@ #define SWC_WINDOW_H #include "swc.h" +#include "pointer.h" #include <stdint.h> #include <wayland-server.h> +struct window_pointer_interaction +{ + struct pointer_handler handler, * original_handler; +}; + struct window { struct swc_window base; @@ -36,6 +42,17 @@ struct window struct swc_surface * surface; struct swc_view * view; + + struct + { + struct window_pointer_interaction interaction; + } move; + + struct + { + struct window_pointer_interaction interaction; + uint32_t edges; + } resize; }; struct window_impl @@ -61,5 +78,11 @@ void window_set_state(struct window * window, uint32_t state); void window_set_parent(struct window * window, struct window * parent); +void window_begin_interactive_move(struct window * window, + struct button_press * button); + +void window_begin_interactive_resize(struct window * window, uint32_t edges, + struct button_press * button); + #endif