diff options
author | Jess VanDerwalker <washu@sonic.net> | 2012-08-12 23:20:56 -0700 |
---|---|---|
committer | Jess VanDerwalker <washu@sonic.net> | 2012-08-29 09:15:52 -0700 |
commit | 5a22ae5f3732c146e4b30232e18373d16f42501c (patch) | |
tree | 17cb2e02adeb283c0357dbc8e258b98c5c00cad7 | |
parent | c91cbdc819e0849673233d27a2e8cbbde0797edb (diff) |
libxcwm: keyboard.h/.c created for keymapping functions.
Created keyboard.h/.c which contain functions for setting keyboard
mapping and modifier mapping. Added these files to the build process.
Signed-off-by: Jess VanDerwalker <washu@sonic.net>
Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
-rw-r--r-- | include/Makefile.am | 4 | ||||
-rw-r--r-- | include/xcwm/keyboard.h | 73 | ||||
-rw-r--r-- | include/xcwm/xcwm.h | 1 | ||||
-rw-r--r-- | src/libxcwm/Makefile.am | 3 | ||||
-rw-r--r-- | src/libxcwm/keyboard.c | 83 |
5 files changed, 162 insertions, 2 deletions
diff --git a/include/Makefile.am b/include/Makefile.am index fc89bd6..9014ed9 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -7,5 +7,7 @@ xcwminclude_HEADERS = \ xcwm/window.h \ xcwm/event.h \ xcwm/image.h \ - xcwm/input.h + xcwm/input.h \ + xcwm/keyboard.h + diff --git a/include/xcwm/keyboard.h b/include/xcwm/keyboard.h new file mode 100644 index 0000000..a7b97ca --- /dev/null +++ b/include/xcwm/keyboard.h @@ -0,0 +1,73 @@ +/* Copyright (c) 2012 Apple Inc + * + * xcwm/event.h + * + * 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 _XCWM_KEYBOARD_H_ +#define _XCWM_KEYBOARD_H_ + +#ifndef __XCWM_INDIRECT__ +#error "Please #include <xcwm/xcwm.h> instead of this file directly." +#endif + +#include <xcb/xcb.h> + +/** + * Typedefs for keysym and keycode data type. + * + * FIXME: Should we be doing this? It does keep user from having to + * include xcb.h directly in their code, but perhaps there is a better + * way. + * + */ +typedef xcb_keysym_t xcwm_keysym_t; +typedef xcb_keycode_t xcwm_keycode_t; + +/** + * Set the keyboard mappping with the given map. + * @param context The context to update mapping on. + * @param num_keycodes The number of keycodes being updated. + * @param first_keycode The first keycode value being updated. + * @param keysyms_per_keycode The number of keysym values per unique keycode. + * @param keyMap The new keymap. + */ +void +xcwm_keyboard_set_mapping (xcwm_context_t *context, + uint8_t num_keycodes, + xcwm_keycode_t first_keycode, + uint8_t keysyms_per_keycode, + xcwm_keysym_t *keyMap); + +/** + * Set the modifier mapping with the given map. + * @param context The context to update mapping on. + * @param keycodes_per_modifier The number of keycodes allowed for + * each modifier. + * @param modMap The modifier keymap. + */ +void +xcwm_keyboard_set_modifier_map (xcwm_context_t *context, + uint8_t keycodes_per_modifier, + xcwm_keycode_t *modMap); + +#endif /* _XCWM_KEYBOARD_H_ */ diff --git a/include/xcwm/xcwm.h b/include/xcwm/xcwm.h index cd037a6..fdba2e9 100644 --- a/include/xcwm/xcwm.h +++ b/include/xcwm/xcwm.h @@ -35,5 +35,6 @@ #include <xcwm/event.h> #include <xcwm/input.h> #include <xcwm/image.h> +#include <xcwm/keyboard.h> #endif /* _XCWM_XCWM_H_ */ diff --git a/src/libxcwm/Makefile.am b/src/libxcwm/Makefile.am index 134945c..19bf3aa 100644 --- a/src/libxcwm/Makefile.am +++ b/src/libxcwm/Makefile.am @@ -16,4 +16,5 @@ libxcwm_la_SOURCES = \ util.c \ image.c \ input.c \ - atoms.c + atoms.c \ + keyboard.c diff --git a/src/libxcwm/keyboard.c b/src/libxcwm/keyboard.c new file mode 100644 index 0000000..61185a6 --- /dev/null +++ b/src/libxcwm/keyboard.c @@ -0,0 +1,83 @@ +/* Copyright (c) 2012 Jess VanDerwalker <jvanderw@freedesktop.org> + * + * keyboard.c + * + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <xcb/xcb.h> +#include <xcwm/xcwm.h> +#include <stdlib.h> +#include <stdio.h> + +void +xcwm_keyboard_set_mapping (xcwm_context_t *context, + uint8_t num_keycodes, + xcwm_keycode_t first_keycode, + uint8_t keysyms_per_keycode, + xcwm_keysym_t *keyMap) +{ + + xcb_void_cookie_t cookie; + xcb_generic_error_t *error; + + cookie = xcb_change_keyboard_mapping_checked(context->conn, + num_keycodes, + first_keycode, + keysyms_per_keycode, + keyMap); + + error = xcb_request_check(context->conn, cookie); + if (error) { + fprintf(stderr, "ERROR: Failed to change keyboard mapping"); + fprintf(stderr, "\nError code: %d\n", error->error_code); + } + + xcb_flush(context->conn); +} + +void +xcwm_keyboard_set_modifier_map (xcwm_context_t *context, + uint8_t keycodes_per_modifier, + xcwm_keycode_t *modMap) +{ + + xcb_set_modifier_mapping_cookie_t map_cookie; + xcb_set_modifier_mapping_reply_t *map_reply; + xcb_generic_error_t *error; + + /* Set the modifier mapping */ + map_cookie = xcb_set_modifier_mapping(context->conn, + keycodes_per_modifier, + modMap); + map_reply = xcb_set_modifier_mapping_reply(context->conn, + map_cookie, &error); + if (error) { + fprintf(stderr, "ERROR: Failed to change keyboard modifier mapping"); + fprintf(stderr, "\nError code: %d\n", error->error_code); + } + free(map_reply); + xcb_flush(context->conn); +} |