swc

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

commit 195c797ba43e1ec5d8bf2f25f58e792f786a9846
parent 1b3cdbc4139f78a5f6e657786dae3353b7ffb41a
Author: Michael Forney <mforney@mforney.org>
Date:   Thu, 30 Jan 2014 02:11:29 -0800

window: Reserve swc_ for external API

Diffstat:
Mlibswc/shell_surface.c | 21+++++++++------------
Mlibswc/surface.h | 2+-
Mlibswc/swc.c | 2+-
Mlibswc/window.c | 83+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mlibswc/window.h | 35+++++++++++++++++------------------
Mlibswc/xwm.c | 24+++++++++++-------------
6 files changed, 80 insertions(+), 87 deletions(-)

diff --git a/libswc/shell_surface.c b/libswc/shell_surface.c @@ -33,7 +33,7 @@ struct swc_shell_surface { - struct swc_window_internal window; + struct window window; struct wl_resource * resource; struct wl_listener surface_destroy_listener; @@ -75,8 +75,7 @@ static void set_toplevel(struct wl_client * client, return; shell_surface->type = SHELL_SURFACE_TYPE_TOPLEVEL; - swc_window_set_state(&shell_surface->window.base, - SWC_WINDOW_STATE_TOPLEVEL); + window_set_state(&shell_surface->window, SWC_WINDOW_STATE_TOPLEVEL); } static void set_transient(struct wl_client * client, @@ -132,7 +131,7 @@ static void set_title(struct wl_client * client, struct wl_resource * resource, struct swc_shell_surface * shell_surface = wl_resource_get_user_data(resource); - swc_window_set_title(&shell_surface->window.base, title, -1); + window_set_title(&shell_surface->window, title, -1); } static void set_class(struct wl_client * client, struct wl_resource * resource, @@ -141,7 +140,7 @@ static void set_class(struct wl_client * client, struct wl_resource * resource, struct swc_shell_surface * shell_surface = wl_resource_get_user_data(resource); - swc_window_set_class(&shell_surface->window.base, class); + window_set_class(&shell_surface->window, class); } static const struct wl_shell_surface_interface shell_surface_implementation = { @@ -157,18 +156,18 @@ static const struct wl_shell_surface_interface shell_surface_implementation = { .set_class = &set_class }; -static void configure(struct swc_window * window, +static void configure(struct window * window, const struct swc_rectangle * geometry) { struct swc_shell_surface * shell_surface - = CONTAINER_OF(window, typeof(*shell_surface), window.base); + = CONTAINER_OF(window, typeof(*shell_surface), window); wl_shell_surface_send_configure(shell_surface->resource, WL_SHELL_SURFACE_RESIZE_NONE, geometry->width, geometry->height); } -static const struct swc_window_impl shell_window_impl = { +static const struct window_impl shell_window_impl = { .configure = &configure }; @@ -185,7 +184,7 @@ static void destroy_shell_surface(struct wl_resource * resource) struct swc_shell_surface * shell_surface = wl_resource_get_user_data(resource); - swc_window_finalize(&shell_surface->window.base); + window_finalize(&shell_surface->window); free(shell_surface); } @@ -199,14 +198,12 @@ struct swc_shell_surface * swc_shell_surface_new if (!shell_surface) goto error0; + window_initialize(&shell_surface->window, &shell_window_impl, surface); shell_surface->type = SHELL_SURFACE_TYPE_UNSPECIFIED; shell_surface->surface_destroy_listener.notify = &handle_surface_destroy; wl_resource_add_destroy_listener(surface->resource, &shell_surface->surface_destroy_listener); - swc_window_initialize(&shell_surface->window.base, - &shell_window_impl, surface); - shell_surface->resource = wl_resource_create (client, &wl_shell_surface_interface, 1, id); diff --git a/libswc/surface.h b/libswc/surface.h @@ -67,7 +67,7 @@ struct swc_surface int32_t x, y; } pending; - struct swc_window * window; + struct window * window; struct swc_view * view; struct wl_listener view_listener; diff --git a/libswc/swc.c b/libswc/swc.c @@ -67,7 +67,7 @@ static void setup_compositor() &swc.bindings->keyboard_handler->link); swc.seat->pointer->handler = swc.compositor->pointer_handler; wl_signal_add(&swc.seat->pointer->focus.event_signal, - swc_window_enter_listener); + &window_enter_listener); /* Calculate pointer region */ pixman_region32_init(&pointer_region); diff --git a/libswc/window.c b/libswc/window.c @@ -34,13 +34,13 @@ #include <stdlib.h> #include <string.h> -#define INTERNAL(window) ((struct swc_window_internal *) (window)) +#define INTERNAL(w) ((struct window *) (w)) static void handle_window_enter(struct wl_listener * listener, void * data) { struct swc_event * event = data; struct swc_input_focus_event_data * event_data = event->data; - struct swc_window * window; + struct window * window; if (event->type != SWC_INPUT_FOCUS_EVENT_CHANGED) return; @@ -48,13 +48,12 @@ static void handle_window_enter(struct wl_listener * listener, void * data) if (!event_data->new || !(window = event_data->new->window)) return; - swc_send_event(&window->event_signal, SWC_WINDOW_ENTERED, NULL); + swc_send_event(&window->base.event_signal, SWC_WINDOW_ENTERED, NULL); } -static struct wl_listener window_enter_listener = { +struct wl_listener window_enter_listener = { .notify = &handle_window_enter }; -struct wl_listener * swc_window_enter_listener = &window_enter_listener; EXPORT void swc_window_show(struct swc_window * window) @@ -69,8 +68,9 @@ void swc_window_hide(struct swc_window * window) } EXPORT -void swc_window_focus(struct swc_window * window) +void swc_window_focus(struct swc_window * base) { + struct window * window = INTERNAL(base); struct swc_surface * new_focus = window ? INTERNAL(window)->surface : NULL, * old_focus = swc.seat->keyboard->focus.surface; @@ -78,27 +78,28 @@ void swc_window_focus(struct swc_window * window) * focus to either NULL, or a window with a different implementation, set * the focus of the previous focus window's implementation to NULL. */ if (old_focus && old_focus->window - && !(window && INTERNAL(window)->impl - == INTERNAL(old_focus->window)->impl) + && !(window && window->impl == INTERNAL(old_focus->window)->impl) && INTERNAL(old_focus->window)->impl->focus) { INTERNAL(old_focus->window)->impl->focus(NULL); } - if (window && INTERNAL(window)->impl->focus) - INTERNAL(window)->impl->focus(window); + if (window && window->impl->focus) + window->impl->focus(window); swc_keyboard_set_focus(swc.seat->keyboard, new_focus); } EXPORT -void swc_window_set_geometry(struct swc_window * window, +void swc_window_set_geometry(struct swc_window * base, const struct swc_rectangle * geometry) { - if (INTERNAL(window)->impl->configure) - INTERNAL(window)->impl->configure(window, geometry); + struct window * window = INTERNAL(base); - swc_view_move(INTERNAL(window)->surface->view, geometry->x, geometry->y); + if (window->impl->configure) + window->impl->configure(window, geometry); + + swc_view_move(window->surface->view, geometry->x, geometry->y); } EXPORT @@ -111,56 +112,54 @@ void swc_window_set_border(struct swc_window * window, swc_compositor_surface_set_border_width(surface, border_width); } -bool swc_window_initialize(struct swc_window * window, - const struct swc_window_impl * impl, - struct swc_surface * surface) +bool window_initialize(struct window * window, const struct window_impl * impl, + struct swc_surface * surface) { DEBUG("Initializing window, %p\n", window); - window->title = NULL; - window->class = NULL; - window->state = SWC_WINDOW_STATE_WITHDRAWN; - wl_signal_init(&window->event_signal); - INTERNAL(window)->surface = surface; - INTERNAL(window)->impl = impl; + window->base.title = NULL; + window->base.class = NULL; + window->base.state = SWC_WINDOW_STATE_WITHDRAWN; + wl_signal_init(&window->base.event_signal); + window->surface = surface; + window->impl = impl; surface->window = window; swc_compositor_add_surface(surface); - swc.manager->new_window(window); + swc.manager->new_window(&window->base); return true; } -void swc_window_finalize(struct swc_window * window) +void window_finalize(struct window * window) { DEBUG("Finalizing window, %p\n", window); - swc_send_event(&window->event_signal, SWC_WINDOW_DESTROYED, NULL); - swc_compositor_remove_surface(INTERNAL(window)->surface); - INTERNAL(window)->surface->window = NULL; - free(window->title); - free(window->class); + swc_send_event(&window->base.event_signal, SWC_WINDOW_DESTROYED, NULL); + swc_compositor_remove_surface(window->surface); + window->surface->window = NULL; + free(window->base.title); + free(window->base.class); } -void swc_window_set_title(struct swc_window * window, - const char * title, size_t length) +void window_set_title(struct window * window, const char * title, size_t length) { - free(window->title); - window->title = strndup(title, length); - swc_send_event(&window->event_signal, SWC_WINDOW_TITLE_CHANGED, NULL); + free(window->base.title); + window->base.title = strndup(title, length); + swc_send_event(&window->base.event_signal, SWC_WINDOW_TITLE_CHANGED, NULL); } -void swc_window_set_class(struct swc_window * window, const char * class) +void window_set_class(struct window * window, const char * class) { - free(window->class); - window->class = strdup(class); - swc_send_event(&window->event_signal, SWC_WINDOW_CLASS_CHANGED, NULL); + free(window->base.class); + window->base.class = strdup(class); + swc_send_event(&window->base.event_signal, SWC_WINDOW_CLASS_CHANGED, NULL); } -void swc_window_set_state(struct swc_window * window, uint32_t state) +void window_set_state(struct window * window, uint32_t state) { - window->state = state; - swc_send_event(&window->event_signal, SWC_WINDOW_STATE_CHANGED, NULL); + window->base.state = state; + swc_send_event(&window->base.event_signal, SWC_WINDOW_STATE_CHANGED, NULL); } diff --git a/libswc/window.h b/libswc/window.h @@ -29,35 +29,34 @@ #include <stdint.h> #include <wayland-server.h> -struct swc_window_impl -{ - void (* configure)(struct swc_window * window, - const struct swc_rectangle * geometry); - void (* focus)(struct swc_window * window); -}; - -struct swc_window_internal +struct window { struct swc_window base; struct swc_surface * surface; - const struct swc_window_impl * impl; + const struct window_impl * impl; +}; + +struct window_impl +{ + void (* configure)(struct window * window, + const struct swc_rectangle * geometry); + void (* focus)(struct window * window); }; -extern struct wl_listener * swc_window_enter_listener; +extern struct wl_listener window_enter_listener; -bool swc_window_initialize(struct swc_window * window, - const struct swc_window_impl * impl, - struct swc_surface * surface); +bool window_initialize(struct window * window, const struct window_impl * impl, + struct swc_surface * surface); -void swc_window_finalize(struct swc_window * window); +void window_finalize(struct window * window); -void swc_window_set_title(struct swc_window * window, - const char * title, size_t length); +void window_set_title(struct window * window, + const char * title, size_t length); -void swc_window_set_class(struct swc_window * window, const char * class); +void window_set_class(struct window * window, const char * class); -void swc_window_set_state(struct swc_window * window, uint32_t state); +void window_set_state(struct window * window, uint32_t state); #endif diff --git a/libswc/xwm.c b/libswc/xwm.c @@ -37,7 +37,7 @@ struct xwl_window { xcb_window_t id; - struct swc_window_internal window; + struct window window; struct wl_listener surface_destroy_listener; }; @@ -66,8 +66,8 @@ static void update_name(struct xwl_window * xwl_window) xcb_ewmh_get_wm_name_reply(&xwm.ewmh, wm_name_cookie, &wm_name_reply, NULL); - swc_window_set_title(&xwl_window->window.base, - wm_name_reply.strings, wm_name_reply.strings_len); + window_set_title(&xwl_window->window, + wm_name_reply.strings, wm_name_reply.strings_len); xcb_ewmh_get_utf8_strings_reply_wipe(&wm_name_reply); } @@ -265,12 +265,12 @@ void swc_xwm_finalize() xcb_disconnect(xwm.connection); } -static void configure(struct swc_window * window, +static void configure(struct window * window, const struct swc_rectangle * geometry) { uint32_t mask, values[4]; struct xwl_window * xwl_window - = CONTAINER_OF(window, typeof(*xwl_window), window.base); + = CONTAINER_OF(window, typeof(*xwl_window), window); mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT; @@ -283,10 +283,10 @@ static void configure(struct swc_window * window, xcb_flush(xwm.connection); } -static void focus(struct swc_window * window) +static void focus(struct window * window) { xcb_window_t id = window ? CONTAINER_OF(window, struct xwl_window, - window.base)->id + window)->id : XCB_NONE; xcb_set_input_focus(xwm.connection, XCB_INPUT_FOCUS_NONE, @@ -294,7 +294,7 @@ static void focus(struct swc_window * window) xcb_flush(xwm.connection); } -static const struct swc_window_impl xwl_window_handler = { +static const struct window_impl xwl_window_handler = { .configure = &configure, .focus = &focus }; @@ -305,7 +305,7 @@ static void handle_surface_destroy(struct wl_listener * listener, void * data) struct xwl_window * xwl_window = CONTAINER_OF(listener, typeof(*xwl_window), surface_destroy_listener); - swc_window_finalize(&xwl_window->window.base); + window_finalize(&xwl_window->window); free(xwl_window); wl_array_for_each(entry, &xwm.windows) @@ -333,12 +333,11 @@ void swc_xwm_manage_window(xcb_window_t id, struct swc_surface * surface) geometry_cookie = xcb_get_geometry(xwm.connection, id); + window_initialize(&xwl_window->window, &xwl_window_handler, surface); xwl_window->id = id; xwl_window->surface_destroy_listener.notify = &handle_surface_destroy; wl_resource_add_destroy_listener(surface->resource, &xwl_window->surface_destroy_listener); - swc_window_initialize(&xwl_window->window.base, - &xwl_window_handler, surface); entry->xwl_window = xwl_window; @@ -363,8 +362,7 @@ void swc_xwm_manage_window(xcb_window_t id, struct swc_surface * surface) xcb_configure_window(xwm.connection, id, mask, values); update_name(xwl_window); - swc_window_set_state(&xwl_window->window.base, - SWC_WINDOW_STATE_TOPLEVEL); + window_set_state(&xwl_window->window, SWC_WINDOW_STATE_TOPLEVEL); } }