swc

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

commit 67856a4d6df781a69bb66f16b95410a3dee17f53
parent dd0b21656eb7b19e8e6f454ab0de4284998d47f5
Author: Michael Forney <mforney@mforney.org>
Date:   Thu,  7 Aug 2014 00:22:32 -0700

Split swc_window_set_geometry into swc_window_set_{position,size}

Diffstat:
Mlibswc/shell_surface.c | 65++++++++++++++++++++++++++++++++---------------------------------
Mlibswc/swc.h | 23++++++++++++++++++++---
Mlibswc/window.c | 29++++++++++++++++++++++++-----
Mlibswc/window.h | 4++--
Mlibswc/xwm.c | 29++++++++++++++++++++---------
5 files changed, 98 insertions(+), 52 deletions(-)

diff --git a/libswc/shell_surface.c b/libswc/shell_surface.c @@ -43,6 +43,33 @@ struct shell_surface struct wl_listener surface_destroy_listener; }; +static void configure(struct window * window, uint32_t width, uint32_t height) +{ + struct shell_surface * shell_surface + = wl_container_of(window, shell_surface, window); + + wl_shell_surface_send_configure(shell_surface->resource, + WL_SHELL_SURFACE_RESIZE_NONE, + width, height); +} + +static void close(struct window * window) +{ + struct shell_surface * shell_surface + = wl_container_of(window, shell_surface, window); + struct wl_client * client; + pid_t pid; + + client = wl_resource_get_client(shell_surface->resource); + wl_client_get_credentials(client, &pid, NULL, NULL); + kill(pid, SIGTERM); +} + +static const struct window_impl window_impl = { + .configure = &configure, + .close = &close, +}; + static void pong(struct wl_client * client, struct wl_resource * resource, uint32_t serial) { @@ -184,34 +211,6 @@ static const struct wl_shell_surface_interface shell_surface_implementation = { .set_class = &set_class }; -static void configure(struct window * window, - const struct swc_rectangle * geometry) -{ - struct shell_surface * shell_surface - = wl_container_of(window, shell_surface, window); - - wl_shell_surface_send_configure(shell_surface->resource, - WL_SHELL_SURFACE_RESIZE_NONE, - geometry->width, geometry->height); -} - -static void close(struct window * window) -{ - struct shell_surface * shell_surface - = wl_container_of(window, shell_surface, window); - struct wl_client * client; - pid_t pid; - - client = wl_resource_get_client(shell_surface->resource); - wl_client_get_credentials(client, &pid, NULL, NULL); - kill(pid, SIGTERM); -} - -static const struct window_impl shell_window_impl = { - .configure = &configure, - .close = &close, -}; - static void handle_surface_destroy(struct wl_listener * listener, void * data) { struct shell_surface * shell_surface @@ -244,15 +243,15 @@ struct shell_surface * shell_surface_new(struct wl_client * client, uint32_t id, if (!shell_surface->resource) goto error1; - window_initialize(&shell_surface->window, &shell_window_impl, surface); - shell_surface->surface_destroy_listener.notify = &handle_surface_destroy; - wl_resource_add_destroy_listener(surface->resource, - &shell_surface->surface_destroy_listener); - wl_resource_set_implementation(shell_surface->resource, &shell_surface_implementation, shell_surface, &destroy_shell_surface); + window_initialize(&shell_surface->window, &window_impl, surface); + shell_surface->surface_destroy_listener.notify = &handle_surface_destroy; + wl_resource_add_destroy_listener(surface->resource, + &shell_surface->surface_destroy_listener); + return shell_surface; error1: diff --git a/libswc/swc.h b/libswc/swc.h @@ -125,10 +125,27 @@ void swc_window_hide(struct swc_window * window); void swc_window_focus(struct swc_window * window); /** - * Set the window's geometry. + * Set the window's position. * - * The geometry's coordinates refer to the actual contents of the window, and - * should be adjusted for the border size. + * The x and y coordinates refer to the top-left corner of the actual contents + * of the window and should be adjusted for the border size. + */ +void swc_window_set_position(struct swc_window * window, int32_t x, int32_t y); + +/** + * Set the window's size. + * + * The width and height refer to the dimension of the actual contents of the + * window and should be adjusted for the border size. + */ +void swc_window_set_size(struct swc_window * window, + uint32_t width, uint32_t height); + +/** + * Set the window's size and position. + * + * This is a convenience function that is equivalent to calling + * swc_window_set_size and then swc_window_set_position. */ void swc_window_set_geometry(struct swc_window * window, const struct swc_rectangle * geometry); diff --git a/libswc/window.c b/libswc/window.c @@ -98,15 +98,34 @@ void swc_window_focus(struct swc_window * base) } EXPORT -void swc_window_set_geometry(struct swc_window * base, - const struct swc_rectangle * geometry) +void swc_window_set_position(struct swc_window * base, int32_t x, int32_t y) +{ + struct window * window = INTERNAL(base); + struct swc_rectangle * geometry = &window->view->base.geometry; + + if (x == geometry->x && y == geometry->y) + return; + + if (window->impl->move) + window->impl->move(window, x, y); + view_move(&window->view->base, x, y); +} + +EXPORT +void swc_window_set_size(struct swc_window * base, + uint32_t width, uint32_t height) { struct window * window = INTERNAL(base); - if (window->impl->configure) - window->impl->configure(window, geometry); + window->impl->configure(window, width, height); +} - view_move(&window->view->base, geometry->x, geometry->y); +EXPORT +void swc_window_set_geometry(struct swc_window * window, + const struct swc_rectangle * geometry) +{ + swc_window_set_size(window, geometry->width, geometry->height); + swc_window_set_position(window, geometry->x, geometry->y); } EXPORT diff --git a/libswc/window.h b/libswc/window.h @@ -57,8 +57,8 @@ struct window struct window_impl { - void (* configure)(struct window * window, - const struct swc_rectangle * geometry); + void (* move)(struct window * window, int32_t x, int32_t y); + void (* configure)(struct window * window, uint32_t width, uint32_t height); void (* focus)(struct window * window); void (* unfocus)(struct window * window); void (* close)(struct window * window); diff --git a/libswc/xwm.c b/libswc/xwm.c @@ -151,19 +151,29 @@ static struct xwl_window * find_window_by_surface_id(struct wl_list * list, return NULL; } -static void configure(struct window * window, - const struct swc_rectangle * geometry) +static void move(struct window * window, int32_t x, int32_t y) { - uint32_t mask, values[4]; + uint32_t mask, values[2]; struct xwl_window * xwl_window = wl_container_of(window, xwl_window, window); - mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y - | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT; - values[0] = geometry->x; - values[1] = geometry->y; - values[2] = geometry->width; - values[3] = geometry->height; + mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y; + values[0] = x; + values[1] = y; + + xcb_configure_window(xwm.connection, xwl_window->id, mask, values); + xcb_flush(xwm.connection); +} + +static void configure(struct window * window, uint32_t width, uint32_t height) +{ + uint32_t mask, values[2]; + struct xwl_window * xwl_window + = wl_container_of(window, xwl_window, window); + + mask = XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT; + values[0] = width; + values[1] = height; xcb_configure_window(xwm.connection, xwl_window->id, mask, values); xcb_flush(xwm.connection); @@ -225,6 +235,7 @@ static void close(struct window * window) } static const struct window_impl xwl_window_handler = { + .move = &move, .configure = &configure, .focus = &focus, .unfocus = &unfocus,