swc

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

commit 65451401706ebc379a285ce8c900e1c5e36dc807
parent 24d8954d9b2a06af540a908b7a61f64c90ee3c83
Author: Michael Forney <mforney@mforney.org>
Date:   Wed, 26 Feb 2014 19:06:50 -0800

Rename input_focus -> input to add other common input stuff

Diffstat:
Alibswc/input.c | 149+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Alibswc/input.h | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dlibswc/input_focus.c | 149-------------------------------------------------------------------------------
Dlibswc/input_focus.h | 77-----------------------------------------------------------------------------
Mlibswc/keyboard.h | 2+-
Mlibswc/local.mk | 2+-
Mlibswc/pointer.h | 2+-
7 files changed, 233 insertions(+), 229 deletions(-)

diff --git a/libswc/input.c b/libswc/input.c @@ -0,0 +1,149 @@ +/* swc: input.c + * + * Copyright (c) 2013, 2014 Michael Forney + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "input.h" +#include "compositor.h" +#include "event.h" +#include "surface.h" +#include "util.h" + +static inline void focus(struct input_focus * input_focus, + struct compositor_view * view) +{ + struct wl_resource * resource = NULL; + + if (view) + { + struct wl_client * client; + + client = wl_resource_get_client(view->surface->resource); + resource = wl_resource_find_for_client(&input_focus->resources, client); + + wl_signal_add(&view->destroy_signal, + &input_focus->view_destroy_listener); + + if (resource) + input_focus->handler->enter(input_focus->handler, resource, view); + } + + input_focus->view = view; + input_focus->resource = resource; +} + +static inline void unfocus(struct input_focus * input_focus) +{ + if (input_focus->view) + wl_list_remove(&input_focus->view_destroy_listener.link); + + if (input_focus->resource) + { + input_focus->handler->leave(input_focus->handler, input_focus->resource, + input_focus->view); + } +} + +static void handle_focus_view_destroy(struct wl_listener * listener, + void * data) +{ + struct input_focus * input_focus + = CONTAINER_OF(listener, typeof(*input_focus), view_destroy_listener); + + input_focus->resource = NULL; + input_focus->view = NULL; +} + +bool input_focus_initialize(struct input_focus * input_focus, + struct input_focus_handler * handler) +{ + input_focus->resource = NULL; + input_focus->view = NULL; + input_focus->view_destroy_listener.notify = &handle_focus_view_destroy; + input_focus->handler = handler; + + wl_list_init(&input_focus->resources); + wl_signal_init(&input_focus->event_signal); + + return true; +} + +void input_focus_finalize(struct input_focus * input_focus) +{ + /* XXX: Destroy resources? */ +} + +void input_focus_add_resource(struct input_focus * input_focus, + struct wl_resource * resource) +{ + /* If this new input resource corresponds to our focus, set it as our + * focus. */ + if (input_focus->view) + { + struct wl_client * client, * surface_client; + + client = wl_resource_get_client(resource); + surface_client = wl_resource_get_client + (input_focus->view->surface->resource); + + if (client == surface_client) + { + input_focus->handler->enter(input_focus->handler, resource, + input_focus->view); + input_focus->resource = resource; + } + } + + wl_list_insert(&input_focus->resources, wl_resource_get_link(resource)); +} + +void input_focus_remove_resource(struct input_focus * input_focus, + struct wl_resource * resource) +{ + if (resource == input_focus->resource) + input_focus->resource = NULL; + + swc_remove_resource(resource); +} + +void input_focus_set(struct input_focus * input_focus, + struct compositor_view * view) +{ + struct input_focus_event_data data; + + if (view == input_focus->view) + return; + + data.old = input_focus->view; + data.new = view; + + /* Unfocus previously focused view. */ + unfocus(input_focus); + + /* Focus new view, if given. */ + focus(input_focus, view); + + swc_send_event(&input_focus->event_signal, INPUT_FOCUS_EVENT_CHANGED, + &data); + + return; +} + diff --git a/libswc/input.h b/libswc/input.h @@ -0,0 +1,81 @@ +/* swc: input.h + * + * Copyright (c) 2013, 2014 Michael Forney + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef SWC_INPUT_H +#define SWC_INPUT_H + +#include <stdbool.h> +#include <wayland-server.h> + +/* Focus {{{ */ + +enum +{ + INPUT_FOCUS_EVENT_CHANGED +}; + +struct input_focus_event_data +{ + struct compositor_view * old, * new; +}; + +struct input_focus_handler +{ + void (* enter)(struct input_focus_handler * handler, + struct wl_resource * resource, + struct compositor_view * view); + void (* leave)(struct input_focus_handler * handler, + struct wl_resource * resource, + struct compositor_view * view); +}; + +struct input_focus +{ + struct wl_resource * resource; + struct compositor_view * view; + struct wl_listener view_destroy_listener; + + struct input_focus_handler * handler; + struct wl_list resources; + + struct wl_signal event_signal; +}; + +bool input_focus_initialize(struct input_focus * input_focus, + struct input_focus_handler * input_handler); + +void input_focus_finalize(struct input_focus * input_focus); + +void input_focus_add_resource(struct input_focus * input_focus, + struct wl_resource * resource); + +void input_focus_remove_resource(struct input_focus * input_focus, + struct wl_resource * resource); + +void input_focus_set(struct input_focus * input_focus, + struct compositor_view * view); + +/* }}} */ + +#endif + diff --git a/libswc/input_focus.c b/libswc/input_focus.c @@ -1,149 +0,0 @@ -/* swc: input_focus.c - * - * Copyright (c) 2013, 2014 Michael Forney - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "input_focus.h" -#include "compositor.h" -#include "event.h" -#include "surface.h" -#include "util.h" - -static inline void focus(struct input_focus * input_focus, - struct compositor_view * view) -{ - struct wl_resource * resource = NULL; - - if (view) - { - struct wl_client * client; - - client = wl_resource_get_client(view->surface->resource); - resource = wl_resource_find_for_client(&input_focus->resources, client); - - wl_signal_add(&view->destroy_signal, - &input_focus->view_destroy_listener); - - if (resource) - input_focus->handler->enter(input_focus->handler, resource, view); - } - - input_focus->view = view; - input_focus->resource = resource; -} - -static inline void unfocus(struct input_focus * input_focus) -{ - if (input_focus->view) - wl_list_remove(&input_focus->view_destroy_listener.link); - - if (input_focus->resource) - { - input_focus->handler->leave(input_focus->handler, input_focus->resource, - input_focus->view); - } -} - -static void handle_focus_view_destroy(struct wl_listener * listener, - void * data) -{ - struct input_focus * input_focus - = CONTAINER_OF(listener, typeof(*input_focus), view_destroy_listener); - - input_focus->resource = NULL; - input_focus->view = NULL; -} - -bool input_focus_initialize(struct input_focus * input_focus, - struct input_focus_handler * handler) -{ - input_focus->resource = NULL; - input_focus->view = NULL; - input_focus->view_destroy_listener.notify = &handle_focus_view_destroy; - input_focus->handler = handler; - - wl_list_init(&input_focus->resources); - wl_signal_init(&input_focus->event_signal); - - return true; -} - -void input_focus_finalize(struct input_focus * input_focus) -{ - /* XXX: Destroy resources? */ -} - -void input_focus_add_resource(struct input_focus * input_focus, - struct wl_resource * resource) -{ - /* If this new input resource corresponds to our focus, set it as our - * focus. */ - if (input_focus->view) - { - struct wl_client * client, * surface_client; - - client = wl_resource_get_client(resource); - surface_client = wl_resource_get_client - (input_focus->view->surface->resource); - - if (client == surface_client) - { - input_focus->handler->enter(input_focus->handler, resource, - input_focus->view); - input_focus->resource = resource; - } - } - - wl_list_insert(&input_focus->resources, wl_resource_get_link(resource)); -} - -void input_focus_remove_resource(struct input_focus * input_focus, - struct wl_resource * resource) -{ - if (resource == input_focus->resource) - input_focus->resource = NULL; - - swc_remove_resource(resource); -} - -void input_focus_set(struct input_focus * input_focus, - struct compositor_view * view) -{ - struct input_focus_event_data data; - - if (view == input_focus->view) - return; - - data.old = input_focus->view; - data.new = view; - - /* Unfocus previously focused view. */ - unfocus(input_focus); - - /* Focus new view, if given. */ - focus(input_focus, view); - - swc_send_event(&input_focus->event_signal, INPUT_FOCUS_EVENT_CHANGED, - &data); - - return; -} - diff --git a/libswc/input_focus.h b/libswc/input_focus.h @@ -1,77 +0,0 @@ -/* swc: input_focus.h - * - * Copyright (c) 2013, 2014 Michael Forney - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef SWC_INPUT_FOCUS_H -#define SWC_INPUT_FOCUS_H - -#include <stdbool.h> -#include <wayland-server.h> - -enum -{ - INPUT_FOCUS_EVENT_CHANGED -}; - -struct input_focus_event_data -{ - struct compositor_view * old, * new; -}; - -struct input_focus_handler -{ - void (* enter)(struct input_focus_handler * handler, - struct wl_resource * resource, - struct compositor_view * view); - void (* leave)(struct input_focus_handler * handler, - struct wl_resource * resource, - struct compositor_view * view); -}; - -struct input_focus -{ - struct wl_resource * resource; - struct compositor_view * view; - struct wl_listener view_destroy_listener; - - struct input_focus_handler * handler; - struct wl_list resources; - - struct wl_signal event_signal; -}; - -bool input_focus_initialize(struct input_focus * input_focus, - struct input_focus_handler * input_handler); - -void input_focus_finalize(struct input_focus * input_focus); - -void input_focus_add_resource(struct input_focus * input_focus, - struct wl_resource * resource); - -void input_focus_remove_resource(struct input_focus * input_focus, - struct wl_resource * resource); - -void input_focus_set(struct input_focus * input_focus, - struct compositor_view * view); - -#endif - diff --git a/libswc/keyboard.h b/libswc/keyboard.h @@ -24,7 +24,7 @@ #ifndef SWC_KEYBOARD_H #define SWC_KEYBOARD_H -#include "input_focus.h" +#include "input.h" #include "surface.h" #include "xkb.h" diff --git a/libswc/local.mk b/libswc/local.mk @@ -37,7 +37,7 @@ SWC_SOURCES = \ libswc/drm.c \ libswc/evdev_device.c \ libswc/framebuffer_plane.c \ - libswc/input_focus.c \ + libswc/input.c \ libswc/keyboard.c \ libswc/launch.c \ libswc/mode.c \ diff --git a/libswc/pointer.h b/libswc/pointer.h @@ -24,7 +24,7 @@ #ifndef SWC_POINTER_H #define SWC_POINTER_H -#include "input_focus.h" +#include "input.h" #include "surface.h" #include "view.h"