diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-10-27 15:21:19 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-10-27 15:21:19 +0000 |
| commit | 061bbd704961b17419fd69344af6268487abb926 (patch) | |
| tree | dbcd298ccffd325fb97e3deaee5d151df55f4bf8 | |
| parent | wayland: move clipboard/primary structs into the wayland struct (diff) | |
kbd: break out XKB kbd struct to a separate file
| -rw-r--r-- | kbd.c | 18 | ||||
| -rw-r--r-- | kbd.h | 35 | ||||
| -rw-r--r-- | main.c | 13 | ||||
| -rw-r--r-- | meson.build | 1 | ||||
| -rw-r--r-- | terminal.h | 33 |
5 files changed, 56 insertions, 44 deletions
@@ -0,0 +1,18 @@ +#include "kbd.h" + +#include <xkbcommon/xkbcommon-compose.h> + +void +kbd_destroy(struct kbd *kbd) +{ + if (kbd->xkb_compose_state != NULL) + xkb_compose_state_unref(kbd->xkb_compose_state); + if (kbd->xkb_compose_table != NULL) + xkb_compose_table_unref(kbd->xkb_compose_table); + if (kbd->xkb_keymap != NULL) + xkb_keymap_unref(kbd->xkb_keymap); + if (kbd->xkb_state != NULL) + xkb_state_unref(kbd->xkb_state); + if (kbd->xkb != NULL) + xkb_context_unref(kbd->xkb); +} @@ -0,0 +1,35 @@ +#pragma once + +#include <stdint.h> +#include <stdbool.h> + +#include <xkbcommon/xkbcommon.h> + +struct kbd { + struct xkb_context *xkb; + struct xkb_keymap *xkb_keymap; + struct xkb_state *xkb_state; + struct xkb_compose_table *xkb_compose_table; + struct xkb_compose_state *xkb_compose_state; + struct { + int fd; + + bool dont_re_repeat; + int32_t delay; + int32_t rate; + uint32_t key; + } repeat; + + xkb_mod_index_t mod_shift; + xkb_mod_index_t mod_alt; + xkb_mod_index_t mod_ctrl; + xkb_mod_index_t mod_meta; + + /* Enabled modifiers */ + bool shift; + bool alt; + bool ctrl; + bool meta; +}; + +void kbd_destroy(struct kbd *kbd); @@ -21,7 +21,6 @@ #include <wayland-client.h> #include <wayland-cursor.h> #include <xdg-shell.h> -#include <xkbcommon/xkbcommon-compose.h> #include <xdg-output-unstable-v1.h> #include <xdg-decoration-unstable-v1.h> @@ -1151,17 +1150,7 @@ out: shm_fini(); - if (term.kbd.xkb_compose_state != NULL) - xkb_compose_state_unref(term.kbd.xkb_compose_state); - if (term.kbd.xkb_compose_table != NULL) - xkb_compose_table_unref(term.kbd.xkb_compose_table); - if (term.kbd.xkb_keymap != NULL) - xkb_keymap_unref(term.kbd.xkb_keymap); - if (term.kbd.xkb_state != NULL) - xkb_state_unref(term.kbd.xkb_state); - if (term.kbd.xkb != NULL) - xkb_context_unref(term.kbd.xkb); - + kbd_destroy(&term.kbd); wayl_win_destroy(&term.window); wayl_destroy(&term.wl); diff --git a/meson.build b/meson.build index da91ff91..cc6bc7f4 100644 --- a/meson.build +++ b/meson.build @@ -72,6 +72,7 @@ executable( 'font.c', 'font.h', 'grid.c', 'grid.h', 'input.c', 'input.h', + 'kbd.c', 'kbd.h', 'log.c', 'log.h', 'main.c', 'osc.c', 'osc.h', @@ -8,14 +8,10 @@ #include <threads.h> #include <semaphore.h> -#include <wayland-client.h> -#include <primary-selection-unstable-v1.h> -#include <xkbcommon/xkbcommon.h> -#include <xkbcommon/xkbcommon-keysyms.h> - #include "font.h" #include "tllist.h" #include "wayland.h" +#include "kbd.h" #define likely(c) __builtin_expect(!!(c), 1) #define unlikely(c) __builtin_expect(!!(c), 0) @@ -123,33 +119,6 @@ struct vt { struct attributes saved_attrs; }; -struct kbd { - struct xkb_context *xkb; - struct xkb_keymap *xkb_keymap; - struct xkb_state *xkb_state; - struct xkb_compose_table *xkb_compose_table; - struct xkb_compose_state *xkb_compose_state; - struct { - int fd; - - bool dont_re_repeat; - int32_t delay; - int32_t rate; - uint32_t key; - } repeat; - - xkb_mod_index_t mod_shift; - xkb_mod_index_t mod_alt; - xkb_mod_index_t mod_ctrl; - xkb_mod_index_t mod_meta; - - /* Enabled modifiers */ - bool shift; - bool alt; - bool ctrl; - bool meta; -}; - enum cursor_keys { CURSOR_KEYS_DONTCARE, CURSOR_KEYS_NORMAL, CURSOR_KEYS_APPLICATION}; enum keypad_keys { KEYPAD_DONTCARE, KEYPAD_NUMERICAL, KEYPAD_APPLICATION }; enum charset { CHARSET_ASCII, CHARSET_GRAPHIC }; |
