diff --git a/kbd.c b/kbd.c new file mode 100644 index 00000000..c38e77ba --- /dev/null +++ b/kbd.c @@ -0,0 +1,18 @@ +#include "kbd.h" + +#include + +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); +} diff --git a/kbd.h b/kbd.h new file mode 100644 index 00000000..06de5b50 --- /dev/null +++ b/kbd.h @@ -0,0 +1,35 @@ +#pragma once + +#include +#include + +#include + +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); diff --git a/main.c b/main.c index 0bdfe69a..7c8de292 100644 --- a/main.c +++ b/main.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -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', diff --git a/terminal.h b/terminal.h index 999b72e0..7ee45ca7 100644 --- a/terminal.h +++ b/terminal.h @@ -8,14 +8,10 @@ #include #include -#include -#include -#include -#include - #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 };