swc

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

commit 88d98cd12ac855de4d6819d84901ee2cfa9876d8
parent baf362d7c2c700e79bc3a66650910e9e2c094f88
Author: Michael Forney <mforney@mforney.org>
Date:   Mon, 25 Nov 2013 03:01:54 -0800

binding.{c,h} -> bindings.{c,h}

Diffstat:
Mlibswc/Makefile.local | 2+-
Dlibswc/binding.c | 110-------------------------------------------------------------------------------
Dlibswc/binding.h | 37-------------------------------------
Alibswc/bindings.c | 110+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Alibswc/bindings.h | 37+++++++++++++++++++++++++++++++++++++
Mlibswc/compositor.c | 1-
Mlibswc/swc.c | 2+-
7 files changed, 149 insertions(+), 150 deletions(-)

diff --git a/libswc/Makefile.local b/libswc/Makefile.local @@ -59,7 +59,7 @@ SWC_SOURCES += \ libswc/window.c \ libswc/shell.c \ libswc/shell_surface.c \ - libswc/binding.c + libswc/bindings.c SWC_STATIC_OBJECTS = $(SWC_SOURCES:%.c=%.o) SWC_SHARED_OBJECTS = $(SWC_SOURCES:%.c=%.lo) diff --git a/libswc/binding.c b/libswc/binding.c @@ -1,110 +0,0 @@ -/* swc: swc/binding.c - * - * Copyright (c) 2013 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 "swc.h" -#include "binding.h" -#include "keyboard.h" -#include "util.h" - -#include <wayland-util.h> - -struct binding -{ - uint32_t value; - uint32_t modifiers; - swc_binding_handler_t handler; - void * data; -}; - -static struct wl_array key_bindings; - -static bool handle_key(struct swc_keyboard * keyboard, uint32_t time, - uint32_t key, uint32_t state) -{ - struct binding * binding; - - if (state == WL_KEYBOARD_KEY_STATE_PRESSED) - { - xkb_layout_index_t layout; - const xkb_keysym_t * keysyms; - int num_keysyms; - - /* XKB key codes are offset by 8 */ - key += 8; - - layout = xkb_state_key_get_layout(keyboard->xkb.state, key); - - /* XXX: Maybe someone might want to register a key binding for a - * keysym with a different shift-level? */ - num_keysyms = xkb_keymap_key_get_syms_by_level - (keyboard->xkb.keymap.map, key, layout, 0, &keysyms); - - if (num_keysyms == 1) - { - wl_array_for_each(binding, &key_bindings) - { - if (binding->value == keysyms[0] - && (binding->modifiers == keyboard->modifiers - || binding->modifiers == SWC_MOD_ANY)) - { - binding->handler(time, keysyms[0], binding->data); - printf("\t-> handled\n"); - return true; - } - } - } - } - - return false; -} - -static const struct swc_keyboard_handler binding_handler = { - .key = &handle_key, -}; -const struct swc_keyboard_handler * swc_binding_handler = &binding_handler; - -bool swc_bindings_initialize() -{ - wl_array_init(&key_bindings); - - return true; -} - -void swc_bindings_finalize() -{ - wl_array_release(&key_bindings); -} - -EXPORT -void swc_add_key_binding(uint32_t modifiers, uint32_t value, - swc_binding_handler_t handler, void * data) -{ - struct binding * binding; - - binding = wl_array_add(&key_bindings, sizeof *binding); - binding->value = value; - binding->modifiers = modifiers; - binding->handler = handler; - binding->data = data; -} - diff --git a/libswc/binding.h b/libswc/binding.h @@ -1,37 +0,0 @@ -/* swc: libswc/binding.h - * - * Copyright (c) 2013 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_BINDING_H -#define SWC_BINDING_H - -#include <stdbool.h> - -struct swc_keyboard_handler; - -extern const struct swc_keyboard_handler * swc_binding_handler; - -bool swc_bindings_initialize(); -void swc_bindings_finalize(); - -#endif - diff --git a/libswc/bindings.c b/libswc/bindings.c @@ -0,0 +1,110 @@ +/* swc: swc/bindings.c + * + * Copyright (c) 2013 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 "swc.h" +#include "bindings.h" +#include "keyboard.h" +#include "util.h" + +#include <wayland-util.h> + +struct binding +{ + uint32_t value; + uint32_t modifiers; + swc_binding_handler_t handler; + void * data; +}; + +static struct wl_array key_bindings; + +static bool handle_key(struct swc_keyboard * keyboard, uint32_t time, + uint32_t key, uint32_t state) +{ + struct binding * binding; + + if (state == WL_KEYBOARD_KEY_STATE_PRESSED) + { + xkb_layout_index_t layout; + const xkb_keysym_t * keysyms; + int num_keysyms; + + /* XKB key codes are offset by 8 */ + key += 8; + + layout = xkb_state_key_get_layout(keyboard->xkb.state, key); + + /* XXX: Maybe someone might want to register a key binding for a + * keysym with a different shift-level? */ + num_keysyms = xkb_keymap_key_get_syms_by_level + (keyboard->xkb.keymap.map, key, layout, 0, &keysyms); + + if (num_keysyms == 1) + { + wl_array_for_each(binding, &key_bindings) + { + if (binding->value == keysyms[0] + && (binding->modifiers == keyboard->modifiers + || binding->modifiers == SWC_MOD_ANY)) + { + binding->handler(time, keysyms[0], binding->data); + printf("\t-> handled\n"); + return true; + } + } + } + } + + return false; +} + +static const struct swc_keyboard_handler binding_handler = { + .key = &handle_key, +}; +const struct swc_keyboard_handler * swc_binding_handler = &binding_handler; + +bool swc_bindings_initialize() +{ + wl_array_init(&key_bindings); + + return true; +} + +void swc_bindings_finalize() +{ + wl_array_release(&key_bindings); +} + +EXPORT +void swc_add_key_binding(uint32_t modifiers, uint32_t value, + swc_binding_handler_t handler, void * data) +{ + struct binding * binding; + + binding = wl_array_add(&key_bindings, sizeof *binding); + binding->value = value; + binding->modifiers = modifiers; + binding->handler = handler; + binding->data = data; +} + diff --git a/libswc/bindings.h b/libswc/bindings.h @@ -0,0 +1,37 @@ +/* swc: libswc/bindings.h + * + * Copyright (c) 2013 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_BINDINGS_H +#define SWC_BINDINGS_H + +#include <stdbool.h> + +struct swc_keyboard_handler; + +extern const struct swc_keyboard_handler * swc_binding_handler; + +bool swc_bindings_initialize(); +void swc_bindings_finalize(); + +#endif + diff --git a/libswc/compositor.c b/libswc/compositor.c @@ -1,5 +1,4 @@ #include "swc.h" -#include "binding.h" #include "compositor.h" #include "compositor_surface.h" #include "cursor_surface.h" diff --git a/libswc/swc.c b/libswc/swc.c @@ -22,7 +22,7 @@ */ #include "swc.h" -#include "binding.h" +#include "bindings.h" #include "compositor.h" #include "internal.h" #include "shell.h"