From 5fefb950b3a1de2c8c8e2cbfecf4ed3790ecffef Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 27 Oct 2019 11:46:18 +0100 Subject: fdm: use the FDM's poll loop --- meson.build | 1 + 1 file changed, 1 insertion(+) (limited to 'meson.build') diff --git a/meson.build b/meson.build index 22987aa4..590f5f8f 100644 --- a/meson.build +++ b/meson.build @@ -68,6 +68,7 @@ executable( 'config.c', 'config.h', 'commands.c', 'commands.h', 'csi.c', 'csi.h', + 'fdm.c', 'fdm.h', 'font.c', 'font.h', 'grid.c', 'grid.h', 'input.c', 'input.h', -- cgit v1.3 From 0120c57ed5a8189508d315e4c650f54572a935a1 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 27 Oct 2019 13:06:39 +0100 Subject: wayland: move wayland struct definitions to a separate file --- meson.build | 1 + terminal.h | 69 +------------------------------------------------------- wayland.h | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 68 deletions(-) create mode 100644 wayland.h (limited to 'meson.build') diff --git a/meson.build b/meson.build index 590f5f8f..62fceb6e 100644 --- a/meson.build +++ b/meson.build @@ -84,6 +84,7 @@ executable( 'tokenize.c', 'tokenize.h', 'tllist.h', 'vt.c', 'vt.h', + 'wayland.h', wl_proto_src + wl_proto_headers, version, dependencies: [threads, math, freetype, fontconfig, pixman, wayland_client, wayland_cursor, xkb], install: true) diff --git a/terminal.h b/terminal.h index 71f190cc..e1756632 100644 --- a/terminal.h +++ b/terminal.h @@ -15,78 +15,11 @@ #include "font.h" #include "tllist.h" +#include "wayland.h" #define likely(c) __builtin_expect(!!(c), 1) #define unlikely(c) __builtin_expect(!!(c), 0) -struct monitor { - struct terminal *term; - struct wl_output *output; - struct zxdg_output_v1 *xdg; - char *name; - - int x; - int y; - - int width_mm; - int height_mm; - - int width_px; - int height_px; - - int scale; - float refresh; -}; - -struct wl_window { - struct wl_surface *surface; - struct xdg_wm_base *shell; - struct xdg_surface *xdg_surface; - struct xdg_toplevel *xdg_toplevel; - - struct zxdg_decoration_manager_v1 *xdg_decoration_manager; - struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration; - - /* Scrollback search */ - struct wl_surface *search_surface; - struct wl_subsurface *search_sub_surface; - - tll(const struct monitor *) on_outputs; /* Outputs we're mapped on */ -}; - -struct wayland { - struct wl_display *display; - struct wl_registry *registry; - struct wl_compositor *compositor; - struct wl_subcompositor *sub_compositor; - struct wl_shm *shm; - - struct wl_seat *seat; - struct wl_keyboard *keyboard; - struct zxdg_output_manager_v1 *xdg_output_manager; - - /* Clipboard */ - struct wl_data_device_manager *data_device_manager; - struct wl_data_device *data_device; - struct zwp_primary_selection_device_manager_v1 *primary_selection_device_manager; - struct zwp_primary_selection_device_v1 *primary_selection_device; - - /* Cursor */ - struct { - struct wl_pointer *pointer; - uint32_t serial; - - struct wl_surface *surface; - struct wl_cursor_theme *theme; - struct wl_cursor *cursor; - int size; - char *theme_name; - } pointer; - - bool have_argb8888; - tll(struct monitor) monitors; /* All available outputs */ -}; - struct rgb { float r, g, b; }; /* diff --git a/wayland.h b/wayland.h new file mode 100644 index 00000000..970cb8cf --- /dev/null +++ b/wayland.h @@ -0,0 +1,74 @@ +#pragma once + +#include +#include + +#include "tllist.h" + +struct monitor { + struct terminal *term; + struct wl_output *output; + struct zxdg_output_v1 *xdg; + char *name; + + int x; + int y; + + int width_mm; + int height_mm; + + int width_px; + int height_px; + + int scale; + float refresh; +}; + +struct wl_window { + struct wl_surface *surface; + struct xdg_wm_base *shell; + struct xdg_surface *xdg_surface; + struct xdg_toplevel *xdg_toplevel; + + struct zxdg_decoration_manager_v1 *xdg_decoration_manager; + struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration; + + /* Scrollback search */ + struct wl_surface *search_surface; + struct wl_subsurface *search_sub_surface; + + tll(const struct monitor *) on_outputs; /* Outputs we're mapped on */ +}; + +struct wayland { + struct wl_display *display; + struct wl_registry *registry; + struct wl_compositor *compositor; + struct wl_subcompositor *sub_compositor; + struct wl_shm *shm; + + struct wl_seat *seat; + struct wl_keyboard *keyboard; + struct zxdg_output_manager_v1 *xdg_output_manager; + + /* Clipboard */ + struct wl_data_device_manager *data_device_manager; + struct wl_data_device *data_device; + struct zwp_primary_selection_device_manager_v1 *primary_selection_device_manager; + struct zwp_primary_selection_device_v1 *primary_selection_device; + + /* Cursor */ + struct { + struct wl_pointer *pointer; + uint32_t serial; + + struct wl_surface *surface; + struct wl_cursor_theme *theme; + struct wl_cursor *cursor; + int size; + char *theme_name; + } pointer; + + bool have_argb8888; + tll(struct monitor) monitors; /* All available outputs */ +}; -- cgit v1.3 From 942ff566a2e8f9f4dc866b74ba10bce838a0d606 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 27 Oct 2019 15:57:23 +0100 Subject: wayland: implement wayl_destroy() --- main.c | 62 +++++++++++---------------------------------------------- meson.build | 2 +- wayland.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ wayland.h | 7 +++++++ 4 files changed, 85 insertions(+), 52 deletions(-) create mode 100644 wayland.c (limited to 'meson.build') diff --git a/main.c b/main.c index 78a70fe4..7487705f 100644 --- a/main.c +++ b/main.c @@ -1152,47 +1152,26 @@ out: shm_fini(); tll_free(term.window.on_outputs); - tll_foreach(term.wl.monitors, it) { - free(it->item.name); - if (it->item.xdg != NULL) - zxdg_output_v1_destroy(it->item.xdg); - if (it->item.output != NULL) - wl_output_destroy(it->item.output); - tll_remove(term.wl.monitors, it); - } - - if (term.wl.xdg_output_manager != NULL) - zxdg_output_manager_v1_destroy(term.wl.xdg_output_manager); - - free(term.wl.pointer.theme_name); - if (term.wl.pointer.theme != NULL) - wl_cursor_theme_destroy(term.wl.pointer.theme); - if (term.wl.pointer.pointer != NULL) - wl_pointer_destroy(term.wl.pointer.pointer); - if (term.wl.pointer.surface != NULL) - wl_surface_destroy(term.wl.pointer.surface); - if (term.wl.keyboard != NULL) - wl_keyboard_destroy(term.wl.keyboard); if (term.selection.clipboard.data_source != NULL) wl_data_source_destroy(term.selection.clipboard.data_source); if (term.selection.clipboard.data_offer != NULL) wl_data_offer_destroy(term.selection.clipboard.data_offer); free(term.selection.clipboard.text); - if (term.wl.data_device != NULL) - wl_data_device_destroy(term.wl.data_device); - if (term.wl.data_device_manager != NULL) - wl_data_device_manager_destroy(term.wl.data_device_manager); if (term.selection.primary.data_source != NULL) zwp_primary_selection_source_v1_destroy(term.selection.primary.data_source); if (term.selection.primary.data_offer != NULL) zwp_primary_selection_offer_v1_destroy(term.selection.primary.data_offer); free(term.selection.primary.text); - if (term.wl.primary_selection_device != NULL) - zwp_primary_selection_device_v1_destroy(term.wl.primary_selection_device); - if (term.wl.primary_selection_device_manager != NULL) - zwp_primary_selection_device_manager_v1_destroy(term.wl.primary_selection_device_manager); - if (term.wl.seat != NULL) - wl_seat_destroy(term.wl.seat); + 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); if (term.window.search_sub_surface != NULL) wl_subsurface_destroy(term.window.search_sub_surface); if (term.window.search_surface != NULL) @@ -1211,26 +1190,7 @@ out: xdg_wm_base_destroy(term.window.shell); if (term.window.surface != NULL) wl_surface_destroy(term.window.surface); - if (term.wl.shm != NULL) - wl_shm_destroy(term.wl.shm); - if (term.wl.sub_compositor != NULL) - wl_subcompositor_destroy(term.wl.sub_compositor); - if (term.wl.compositor != NULL) - wl_compositor_destroy(term.wl.compositor); - if (term.wl.registry != NULL) - wl_registry_destroy(term.wl.registry); - if (term.wl.display != NULL) - wl_display_disconnect(term.wl.display); - 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); + wayl_destroy(&term.wl); free(term.vt.osc.data); for (int row = 0; row < term.normal.num_rows; row++) diff --git a/meson.build b/meson.build index 62fceb6e..da91ff91 100644 --- a/meson.build +++ b/meson.build @@ -84,7 +84,7 @@ executable( 'tokenize.c', 'tokenize.h', 'tllist.h', 'vt.c', 'vt.h', - 'wayland.h', + 'wayland.c', 'wayland.h', wl_proto_src + wl_proto_headers, version, dependencies: [threads, math, freetype, fontconfig, pixman, wayland_client, wayland_cursor, xkb], install: true) diff --git a/wayland.c b/wayland.c new file mode 100644 index 00000000..4a8ad23f --- /dev/null +++ b/wayland.c @@ -0,0 +1,66 @@ +#include "wayland.h" + +#include +#include +#include +#include + +#include +#include + +#define LOG_MODULE "wayland" +#define LOG_ENABLE_DBG 0 +#include "log.h" + +#include "tllist.h" + +void +wayl_init(struct wayland *wayl) +{ +} + +void +wayl_destroy(struct wayland *wayl) +{ + tll_foreach(wayl->monitors, it) { + free(it->item.name); + if (it->item.xdg != NULL) + zxdg_output_v1_destroy(it->item.xdg); + if (it->item.output != NULL) + wl_output_destroy(it->item.output); + tll_remove(wayl->monitors, it); + } + + if (wayl->xdg_output_manager != NULL) + zxdg_output_manager_v1_destroy(wayl->xdg_output_manager); + + free(wayl->pointer.theme_name); + if (wayl->pointer.theme != NULL) + wl_cursor_theme_destroy(wayl->pointer.theme); + if (wayl->pointer.pointer != NULL) + wl_pointer_destroy(wayl->pointer.pointer); + if (wayl->pointer.surface != NULL) + wl_surface_destroy(wayl->pointer.surface); + if (wayl->keyboard != NULL) + wl_keyboard_destroy(wayl->keyboard); + if (wayl->data_device != NULL) + wl_data_device_destroy(wayl->data_device); + if (wayl->data_device_manager != NULL) + wl_data_device_manager_destroy(wayl->data_device_manager); + if (wayl->primary_selection_device != NULL) + zwp_primary_selection_device_v1_destroy(wayl->primary_selection_device); + if (wayl->primary_selection_device_manager != NULL) + zwp_primary_selection_device_manager_v1_destroy(wayl->primary_selection_device_manager); + if (wayl->seat != NULL) + wl_seat_destroy(wayl->seat); + if (wayl->shm != NULL) + wl_shm_destroy(wayl->shm); + if (wayl->sub_compositor != NULL) + wl_subcompositor_destroy(wayl->sub_compositor); + if (wayl->compositor != NULL) + wl_compositor_destroy(wayl->compositor); + if (wayl->registry != NULL) + wl_registry_destroy(wayl->registry); + if (wayl->display != NULL) + wl_display_disconnect(wayl->display); +} diff --git a/wayland.h b/wayland.h index 970cb8cf..81d622fe 100644 --- a/wayland.h +++ b/wayland.h @@ -3,6 +3,9 @@ #include #include +#include +#include + #include "tllist.h" struct monitor { @@ -72,3 +75,7 @@ struct wayland { bool have_argb8888; tll(struct monitor) monitors; /* All available outputs */ }; + +/* TODO: return allocated pointer */ +void wayl_init(struct wayland *wayl); +void wayl_destroy(struct wayland *wayl); -- cgit v1.3 From 061bbd704961b17419fd69344af6268487abb926 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 27 Oct 2019 16:21:19 +0100 Subject: kbd: break out XKB kbd struct to a separate file --- kbd.c | 18 ++++++++++++++++++ kbd.h | 35 +++++++++++++++++++++++++++++++++++ main.c | 13 +------------ meson.build | 1 + terminal.h | 33 +-------------------------------- 5 files changed, 56 insertions(+), 44 deletions(-) create mode 100644 kbd.c create mode 100644 kbd.h (limited to 'meson.build') 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 }; -- cgit v1.3 From c9455d5f211616ce3750e58a472e1b5a4251b8be Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 27 Oct 2019 17:07:44 +0100 Subject: kbd: move into wayland --- input.c | 136 ++++++++++++++++++++++++++++++------------------------------ kbd.c | 18 -------- kbd.h | 35 ---------------- main.c | 31 +++++++------- meson.build | 1 - search.c | 16 +++---- selection.c | 2 +- terminal.c | 6 +-- terminal.h | 2 - wayland.c | 11 +++++ wayland.h | 38 +++++++++++++++-- 11 files changed, 141 insertions(+), 155 deletions(-) delete mode 100644 kbd.c delete mode 100644 kbd.h (limited to 'meson.build') diff --git a/input.c b/input.c index 00397974..975923a3 100644 --- a/input.c +++ b/input.c @@ -35,45 +35,45 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, char *map_str = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); /* TODO: free old context + keymap */ - if (term->kbd.xkb_compose_state != NULL) { - xkb_compose_state_unref(term->kbd.xkb_compose_state); - term->kbd.xkb_compose_state = NULL; + if (term->wl.kbd.xkb_compose_state != NULL) { + xkb_compose_state_unref(term->wl.kbd.xkb_compose_state); + term->wl.kbd.xkb_compose_state = NULL; } - if (term->kbd.xkb_compose_table != NULL) { - xkb_compose_table_unref(term->kbd.xkb_compose_table); - term->kbd.xkb_compose_table = NULL; + if (term->wl.kbd.xkb_compose_table != NULL) { + xkb_compose_table_unref(term->wl.kbd.xkb_compose_table); + term->wl.kbd.xkb_compose_table = NULL; } - if (term->kbd.xkb_keymap != NULL) { - xkb_keymap_unref(term->kbd.xkb_keymap); - term->kbd.xkb_keymap = NULL; + if (term->wl.kbd.xkb_keymap != NULL) { + xkb_keymap_unref(term->wl.kbd.xkb_keymap); + term->wl.kbd.xkb_keymap = NULL; } - if (term->kbd.xkb_state != NULL) { - xkb_state_unref(term->kbd.xkb_state); - term->kbd.xkb_state = NULL; + if (term->wl.kbd.xkb_state != NULL) { + xkb_state_unref(term->wl.kbd.xkb_state); + term->wl.kbd.xkb_state = NULL; } - if (term->kbd.xkb != NULL) { - xkb_context_unref(term->kbd.xkb); - term->kbd.xkb = NULL; + if (term->wl.kbd.xkb != NULL) { + xkb_context_unref(term->wl.kbd.xkb); + term->wl.kbd.xkb = NULL; } - term->kbd.xkb = xkb_context_new(XKB_CONTEXT_NO_FLAGS); - term->kbd.xkb_keymap = xkb_keymap_new_from_string( - term->kbd.xkb, map_str, XKB_KEYMAP_FORMAT_TEXT_V1, + term->wl.kbd.xkb = xkb_context_new(XKB_CONTEXT_NO_FLAGS); + term->wl.kbd.xkb_keymap = xkb_keymap_new_from_string( + term->wl.kbd.xkb, map_str, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); /* TODO: initialize in enter? */ - term->kbd.xkb_state = xkb_state_new(term->kbd.xkb_keymap); + term->wl.kbd.xkb_state = xkb_state_new(term->wl.kbd.xkb_keymap); - term->kbd.mod_shift = xkb_keymap_mod_get_index(term->kbd.xkb_keymap, "Shift"); - term->kbd.mod_alt = xkb_keymap_mod_get_index(term->kbd.xkb_keymap, "Mod1") ; - term->kbd.mod_ctrl = xkb_keymap_mod_get_index(term->kbd.xkb_keymap, "Control"); - term->kbd.mod_meta = xkb_keymap_mod_get_index(term->kbd.xkb_keymap, "Mod4"); + term->wl.kbd.mod_shift = xkb_keymap_mod_get_index(term->wl.kbd.xkb_keymap, "Shift"); + term->wl.kbd.mod_alt = xkb_keymap_mod_get_index(term->wl.kbd.xkb_keymap, "Mod1") ; + term->wl.kbd.mod_ctrl = xkb_keymap_mod_get_index(term->wl.kbd.xkb_keymap, "Control"); + term->wl.kbd.mod_meta = xkb_keymap_mod_get_index(term->wl.kbd.xkb_keymap, "Mod4"); /* Compose (dead keys) */ - term->kbd.xkb_compose_table = xkb_compose_table_new_from_locale( - term->kbd.xkb, setlocale(LC_CTYPE, NULL), XKB_COMPOSE_COMPILE_NO_FLAGS); - term->kbd.xkb_compose_state = xkb_compose_state_new( - term->kbd.xkb_compose_table, XKB_COMPOSE_STATE_NO_FLAGS); + term->wl.kbd.xkb_compose_table = xkb_compose_table_new_from_locale( + term->wl.kbd.xkb, setlocale(LC_CTYPE, NULL), XKB_COMPOSE_COMPILE_NO_FLAGS); + term->wl.kbd.xkb_compose_state = xkb_compose_state_new( + term->wl.kbd.xkb_compose_table, XKB_COMPOSE_STATE_NO_FLAGS); munmap(map_str, size); close(fd); @@ -91,12 +91,12 @@ keyboard_enter(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, static bool start_repeater(struct terminal *term, uint32_t key) { - if (term->kbd.repeat.dont_re_repeat) + if (term->wl.kbd.repeat.dont_re_repeat) return true; struct itimerspec t = { - .it_value = {.tv_sec = 0, .tv_nsec = term->kbd.repeat.delay * 1000000}, - .it_interval = {.tv_sec = 0, .tv_nsec = 1000000000 / term->kbd.repeat.rate}, + .it_value = {.tv_sec = 0, .tv_nsec = term->wl.kbd.repeat.delay * 1000000}, + .it_interval = {.tv_sec = 0, .tv_nsec = 1000000000 / term->wl.kbd.repeat.rate}, }; if (t.it_value.tv_nsec >= 1000000000) { @@ -107,22 +107,22 @@ start_repeater(struct terminal *term, uint32_t key) t.it_interval.tv_sec += t.it_interval.tv_nsec / 1000000000; t.it_interval.tv_nsec %= 1000000000; } - if (timerfd_settime(term->kbd.repeat.fd, 0, &t, NULL) < 0) { + if (timerfd_settime(term->wl.kbd.repeat.fd, 0, &t, NULL) < 0) { LOG_ERRNO("failed to arm keyboard repeat timer"); return false; } - term->kbd.repeat.key = key; + term->wl.kbd.repeat.key = key; return true; } static bool stop_repeater(struct terminal *term, uint32_t key) { - if (key != -1 && key != term->kbd.repeat.key) + if (key != -1 && key != term->wl.kbd.repeat.key) return true; - if (timerfd_settime(term->kbd.repeat.fd, 0, &(struct itimerspec){{0}}, NULL) < 0) { + if (timerfd_settime(term->wl.kbd.repeat.fd, 0, &(struct itimerspec){{0}}, NULL) < 0) { LOG_ERRNO("failed to disarm keyboard repeat timer"); return false; } @@ -146,10 +146,10 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, { struct terminal *term = data; - const xkb_mod_mask_t ctrl = 1 << term->kbd.mod_ctrl; - const xkb_mod_mask_t alt = 1 << term->kbd.mod_alt; - const xkb_mod_mask_t shift = 1 << term->kbd.mod_shift; - const xkb_mod_mask_t meta = 1 << term->kbd.mod_meta; + const xkb_mod_mask_t ctrl = 1 << term->wl.kbd.mod_ctrl; + const xkb_mod_mask_t alt = 1 << term->wl.kbd.mod_alt; + const xkb_mod_mask_t shift = 1 << term->wl.kbd.mod_shift; + const xkb_mod_mask_t meta = 1 << term->wl.kbd.mod_meta; if (state == XKB_KEY_UP) { stop_repeater(term, key); @@ -157,7 +157,7 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, } key += 8; - xkb_keysym_t sym = xkb_state_key_get_one_sym(term->kbd.xkb_state, key); + xkb_keysym_t sym = xkb_state_key_get_one_sym(term->wl.kbd.xkb_state, key); #if 0 char foo[100]; @@ -165,16 +165,16 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, LOG_INFO("%s", foo); #endif - xkb_compose_state_feed(term->kbd.xkb_compose_state, sym); + xkb_compose_state_feed(term->wl.kbd.xkb_compose_state, sym); enum xkb_compose_status compose_status = xkb_compose_state_get_status( - term->kbd.xkb_compose_state); + term->wl.kbd.xkb_compose_state); if (compose_status == XKB_COMPOSE_COMPOSING) return; xkb_mod_mask_t mods = xkb_state_serialize_mods( - term->kbd.xkb_state, XKB_STATE_MODS_DEPRESSED); - //xkb_mod_mask_t consumed = xkb_state_key_get_consumed_mods(term->kbd.xkb_state, key); + term->wl.kbd.xkb_state, XKB_STATE_MODS_DEPRESSED); + //xkb_mod_mask_t consumed = xkb_state_key_get_consumed_mods(term->wl.kbd.xkb_state, key); xkb_mod_mask_t consumed = 0x0; xkb_mod_mask_t significant = ctrl | alt | shift | meta; xkb_mod_mask_t effective_mods = mods & ~consumed & significant; @@ -188,7 +188,7 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, #if 0 for (size_t i = 0; i < 32; i++) { if (mods & (1 << i)) { - LOG_INFO("%s", xkb_keymap_mod_get_name(term->kbd.xkb_keymap, i)); + LOG_INFO("%s", xkb_keymap_mod_get_name(term->wl.kbd.xkb_keymap, i)); } } #endif @@ -200,10 +200,10 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, bool found_map = false; enum modifier keymap_mods = MOD_NONE; - keymap_mods |= term->kbd.shift ? MOD_SHIFT : MOD_NONE; - keymap_mods |= term->kbd.alt ? MOD_ALT : MOD_NONE; - keymap_mods |= term->kbd.ctrl ? MOD_CTRL : MOD_NONE; - keymap_mods |= term->kbd.meta ? MOD_META : MOD_NONE; + keymap_mods |= term->wl.kbd.shift ? MOD_SHIFT : MOD_NONE; + keymap_mods |= term->wl.kbd.alt ? MOD_ALT : MOD_NONE; + keymap_mods |= term->wl.kbd.ctrl ? MOD_CTRL : MOD_NONE; + keymap_mods |= term->wl.kbd.meta ? MOD_META : MOD_NONE; if (effective_mods == shift) { if (sym == XKB_KEY_Page_Up) { @@ -268,11 +268,11 @@ keyboard_key(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, if (compose_status == XKB_COMPOSE_COMPOSED) { count = xkb_compose_state_get_utf8( - term->kbd.xkb_compose_state, (char *)buf, sizeof(buf)); - xkb_compose_state_reset(term->kbd.xkb_compose_state); + term->wl.kbd.xkb_compose_state, (char *)buf, sizeof(buf)); + xkb_compose_state_reset(term->wl.kbd.xkb_compose_state); } else { count = xkb_state_key_get_utf8( - term->kbd.xkb_state, key, (char *)buf, sizeof(buf)); + term->wl.kbd.xkb_state, key, (char *)buf, sizeof(buf)); } if (count > 0) { @@ -338,17 +338,17 @@ keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, mods_depressed, mods_latched, mods_locked, group); xkb_state_update_mask( - term->kbd.xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group); + term->wl.kbd.xkb_state, mods_depressed, mods_latched, mods_locked, 0, 0, group); /* Update state of modifiers we're interrested in for e.g mouse events */ - term->kbd.shift = xkb_state_mod_index_is_active( - term->kbd.xkb_state, term->kbd.mod_shift, XKB_STATE_MODS_DEPRESSED); - term->kbd.alt = xkb_state_mod_index_is_active( - term->kbd.xkb_state, term->kbd.mod_alt, XKB_STATE_MODS_DEPRESSED); - term->kbd.ctrl = xkb_state_mod_index_is_active( - term->kbd.xkb_state, term->kbd.mod_ctrl, XKB_STATE_MODS_DEPRESSED); - term->kbd.meta = xkb_state_mod_index_is_active( - term->kbd.xkb_state, term->kbd.mod_meta, XKB_STATE_MODS_DEPRESSED); + term->wl.kbd.shift = xkb_state_mod_index_is_active( + term->wl.kbd.xkb_state, term->wl.kbd.mod_shift, XKB_STATE_MODS_DEPRESSED); + term->wl.kbd.alt = xkb_state_mod_index_is_active( + term->wl.kbd.xkb_state, term->wl.kbd.mod_alt, XKB_STATE_MODS_DEPRESSED); + term->wl.kbd.ctrl = xkb_state_mod_index_is_active( + term->wl.kbd.xkb_state, term->wl.kbd.mod_ctrl, XKB_STATE_MODS_DEPRESSED); + term->wl.kbd.meta = xkb_state_mod_index_is_active( + term->wl.kbd.xkb_state, term->wl.kbd.mod_meta, XKB_STATE_MODS_DEPRESSED); } static void @@ -357,8 +357,8 @@ keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard, { struct terminal *term = data; LOG_DBG("keyboard repeat: rate=%d, delay=%d", rate, delay); - term->kbd.repeat.rate = rate; - term->kbd.repeat.delay = delay; + term->wl.kbd.repeat.rate = rate; + term->wl.kbd.repeat.delay = delay; } const struct wl_keyboard_listener keyboard_listener = { @@ -430,7 +430,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, term_mouse_motion( term, term->mouse.button, term->mouse.row, term->mouse.col, - term->kbd.shift, term->kbd.alt, term->kbd.ctrl); + term->wl.kbd.shift, term->wl.kbd.alt, term->wl.kbd.ctrl); } static void @@ -467,7 +467,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, case 2: selection_mark_word(term, term->mouse.col, term->mouse.row, - term->kbd.ctrl, serial); + term->wl.kbd.ctrl, serial); break; case 3: @@ -484,7 +484,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, term->mouse.last_button = button; term->mouse.last_time = now; term_mouse_down(term, button, term->mouse.row, term->mouse.col, - term->kbd.shift, term->kbd.alt, term->kbd.ctrl); + term->wl.kbd.shift, term->wl.kbd.alt, term->wl.kbd.ctrl); break; } @@ -496,7 +496,7 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, term->mouse.button = 0; /* For motion events */ term_mouse_up(term, button, term->mouse.row, term->mouse.col, - term->kbd.shift, term->kbd.alt, term->kbd.ctrl); + term->wl.kbd.shift, term->wl.kbd.alt, term->wl.kbd.ctrl); break; } } @@ -520,7 +520,7 @@ mouse_scroll(struct terminal *term, int amount) */ xkb_keycode_t key = xkb_keymap_key_by_name( - term->kbd.xkb_keymap, button == BTN_BACK ? "UP" : "DOWN"); + term->wl.kbd.xkb_keymap, button == BTN_BACK ? "UP" : "DOWN"); for (int i = 0; i < amount; i++) keyboard_key(term, NULL, term->input_serial, 0, key - 8, XKB_KEY_DOWN); @@ -528,7 +528,7 @@ mouse_scroll(struct terminal *term, int amount) } else { for (int i = 0; i < amount; i++) term_mouse_down(term, button, term->mouse.row, term->mouse.col, - term->kbd.shift, term->kbd.alt, term->kbd.ctrl); + term->wl.kbd.shift, term->wl.kbd.alt, term->wl.kbd.ctrl); scrollback(term, amount); } diff --git a/kbd.c b/kbd.c deleted file mode 100644 index c38e77ba..00000000 --- a/kbd.c +++ /dev/null @@ -1,18 +0,0 @@ -#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 deleted file mode 100644 index 06de5b50..00000000 --- a/kbd.h +++ /dev/null @@ -1,35 +0,0 @@ -#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 7c8de292..90f9ef2a 100644 --- a/main.c +++ b/main.c @@ -492,7 +492,7 @@ fdm_repeat(struct fdm *fdm, int fd, int events, void *data) struct terminal *term = data; uint64_t expiration_count; ssize_t ret = read( - term->kbd.repeat.fd, &expiration_count, sizeof(expiration_count)); + term->wl.kbd.repeat.fd, &expiration_count, sizeof(expiration_count)); if (ret < 0) { if (errno == EAGAIN) @@ -502,10 +502,10 @@ fdm_repeat(struct fdm *fdm, int fd, int events, void *data) return false; } - term->kbd.repeat.dont_re_repeat = true; + term->wl.kbd.repeat.dont_re_repeat = true; for (size_t i = 0; i < expiration_count; i++) - input_repeat(term, term->kbd.repeat.key); - term->kbd.repeat.dont_re_repeat = false; + input_repeat(term, term->wl.kbd.repeat.key); + term->wl.kbd.repeat.dont_re_repeat = false; return true; } @@ -742,11 +742,6 @@ main(int argc, char *const *argv) //.background = conf.colors.bg }, }, - .kbd = { - .repeat = { - .fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC | TFD_NONBLOCK), - }, - }, .colors = { .default_fg = conf.colors.fg, .default_bg = conf.colors.bg, @@ -788,6 +783,13 @@ main(int argc, char *const *argv) .normal = {.damage = tll_init(), .scroll_damage = tll_init()}, .alt = {.damage = tll_init(), .scroll_damage = tll_init()}, .grid = &term.normal, + .wl = { + .kbd = { + .repeat = { + .fd = timerfd_create(CLOCK_BOOTTIME, TFD_CLOEXEC | TFD_NONBLOCK), + }, + }, + }, .render = { .scrollback_lines = conf.scrollback_lines, .workers = { @@ -833,7 +835,7 @@ main(int argc, char *const *argv) goto out; } - if (term.flash.fd == -1 || term.blink.fd == -1 || term.kbd.repeat.fd == -1) { + if (term.flash.fd == -1 || term.blink.fd == -1 || term.wl.kbd.repeat.fd == -1) { LOG_ERR("failed to create timers"); goto out; } @@ -1108,7 +1110,7 @@ main(int argc, char *const *argv) fdm_add(fdm, wl_display_get_fd(term.wl.display), EPOLLIN, &fdm_wayl, &term); fdm_add(fdm, term.ptmx, EPOLLIN, &fdm_ptmx, &term); - fdm_add(fdm, term.kbd.repeat.fd, EPOLLIN, &fdm_repeat, &term); + fdm_add(fdm, term.wl.kbd.repeat.fd, EPOLLIN, &fdm_repeat, &term); fdm_add(fdm, term.flash.fd, EPOLLIN, &fdm_flash, &term); fdm_add(fdm, term.blink.fd, EPOLLIN, &fdm_blink, &term); fdm_add(fdm, term.delayed_render_timer.lower_fd, EPOLLIN, &fdm_delayed_render, &term); @@ -1127,7 +1129,7 @@ out: if (fdm != NULL) { fdm_del(fdm, wl_display_get_fd(term.wl.display)); fdm_del(fdm, term.ptmx); - fdm_del(fdm, term.kbd.repeat.fd); + fdm_del(fdm, term.wl.kbd.repeat.fd); fdm_del(fdm, term.flash.fd); fdm_del(fdm, term.blink.fd); fdm_del(fdm, term.delayed_render_timer.lower_fd); @@ -1150,7 +1152,6 @@ out: shm_fini(); - kbd_destroy(&term.kbd); wayl_win_destroy(&term.window); wayl_destroy(&term.wl); @@ -1174,8 +1175,8 @@ out: close(term.flash.fd); if (term.blink.fd != -1) close(term.blink.fd); - if (term.kbd.repeat.fd != -1) - close(term.kbd.repeat.fd); + if (term.wl.kbd.repeat.fd != -1) + close(term.wl.kbd.repeat.fd); if (term.ptmx != -1) close(term.ptmx); diff --git a/meson.build b/meson.build index cc6bc7f4..da91ff91 100644 --- a/meson.build +++ b/meson.build @@ -72,7 +72,6 @@ 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/search.c b/search.c index 59ac0152..e9da3770 100644 --- a/search.c +++ b/search.c @@ -294,13 +294,13 @@ search_input(struct terminal *term, uint32_t key, xkb_keysym_t sym, xkb_mod_mask { LOG_DBG("search: input: sym=%d/0x%x, mods=0x%08x", sym, sym, mods); - const xkb_mod_mask_t ctrl = 1 << term->kbd.mod_ctrl; - const xkb_mod_mask_t alt = 1 << term->kbd.mod_alt; - //const xkb_mod_mask_t shift = 1 << term->kbd.mod_shift; - //const xkb_mod_mask_t meta = 1 << term->kbd.mod_meta; + const xkb_mod_mask_t ctrl = 1 << term->wl.kbd.mod_ctrl; + const xkb_mod_mask_t alt = 1 << term->wl.kbd.mod_alt; + //const xkb_mod_mask_t shift = 1 << term->wl.kbd.mod_shift; + //const xkb_mod_mask_t meta = 1 << term->wl.kbd.mod_meta; enum xkb_compose_status compose_status = xkb_compose_state_get_status( - term->kbd.xkb_compose_state); + term->wl.kbd.xkb_compose_state); /* Cancel search */ if ((mods == 0 && sym == XKB_KEY_Escape) || @@ -449,11 +449,11 @@ search_input(struct terminal *term, uint32_t key, xkb_keysym_t sym, xkb_mod_mask if (compose_status == XKB_COMPOSE_COMPOSED) { count = xkb_compose_state_get_utf8( - term->kbd.xkb_compose_state, (char *)buf, sizeof(buf)); - xkb_compose_state_reset(term->kbd.xkb_compose_state); + term->wl.kbd.xkb_compose_state, (char *)buf, sizeof(buf)); + xkb_compose_state_reset(term->wl.kbd.xkb_compose_state); } else { count = xkb_state_key_get_utf8( - term->kbd.xkb_state, key, (char *)buf, sizeof(buf)); + term->wl.kbd.xkb_state, key, (char *)buf, sizeof(buf)); } const char *src = (const char *)buf; diff --git a/selection.c b/selection.c index e53ace8b..33875e94 100644 --- a/selection.c +++ b/selection.c @@ -22,7 +22,7 @@ selection_enabled(const struct terminal *term) { return term->mouse_tracking == MOUSE_NONE || - term->kbd.shift || + term->wl.kbd.shift || term->is_searching; } diff --git a/terminal.c b/terminal.c index 95a60682..ada701cc 100644 --- a/terminal.c +++ b/terminal.c @@ -480,7 +480,7 @@ void term_mouse_down(struct terminal *term, int button, int row, int col, bool shift, bool alt, bool ctrl) { - if (term->kbd.shift) { + if (term->wl.kbd.shift) { /* "raw" mouse mode */ return; } @@ -513,7 +513,7 @@ void term_mouse_up(struct terminal *term, int button, int row, int col, bool shift, bool alt, bool ctrl) { - if (term->kbd.shift) { + if (term->wl.kbd.shift) { /* "raw" mouse mode */ return; } @@ -551,7 +551,7 @@ void term_mouse_motion(struct terminal *term, int button, int row, int col, bool shift, bool alt, bool ctrl) { - if (term->kbd.shift) { + if (term->wl.kbd.shift) { /* "raw" mouse mode */ return; } diff --git a/terminal.h b/terminal.h index 7ee45ca7..cd8d7768 100644 --- a/terminal.h +++ b/terminal.h @@ -11,7 +11,6 @@ #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) @@ -176,7 +175,6 @@ struct terminal { } blink; struct vt vt; - struct kbd kbd; int scale; int width; /* pixels */ diff --git a/wayland.c b/wayland.c index 96ba3641..e6701de6 100644 --- a/wayland.c +++ b/wayland.c @@ -34,6 +34,17 @@ wayl_destroy(struct wayland *wayl) if (wayl->xdg_output_manager != NULL) zxdg_output_manager_v1_destroy(wayl->xdg_output_manager); + if (wayl->kbd.xkb_compose_state != NULL) + xkb_compose_state_unref(wayl->kbd.xkb_compose_state); + if (wayl->kbd.xkb_compose_table != NULL) + xkb_compose_table_unref(wayl->kbd.xkb_compose_table); + if (wayl->kbd.xkb_keymap != NULL) + xkb_keymap_unref(wayl->kbd.xkb_keymap); + if (wayl->kbd.xkb_state != NULL) + xkb_state_unref(wayl->kbd.xkb_state); + if (wayl->kbd.xkb != NULL) + xkb_context_unref(wayl->kbd.xkb); + if (wayl->clipboard.data_source != NULL) wl_data_source_destroy(wayl->clipboard.data_source); if (wayl->clipboard.data_offer != NULL) diff --git a/wayland.h b/wayland.h index 1b680b2c..643d5ac5 100644 --- a/wayland.h +++ b/wayland.h @@ -5,6 +5,7 @@ #include #include +#include #include "tllist.h" @@ -27,6 +28,33 @@ struct monitor { float refresh; }; +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; +}; + struct wl_clipboard { struct wl_data_source *data_source; struct wl_data_offer *data_offer; @@ -70,12 +98,18 @@ struct wayland { struct wl_keyboard *keyboard; struct zxdg_output_manager_v1 *xdg_output_manager; + /* Keyboard */ + struct kbd kbd; + /* Clipboard */ struct wl_data_device_manager *data_device_manager; struct wl_data_device *data_device; struct zwp_primary_selection_device_manager_v1 *primary_selection_device_manager; struct zwp_primary_selection_device_v1 *primary_selection_device; + struct wl_clipboard clipboard; + struct wl_primary primary; + /* Cursor */ struct { struct wl_pointer *pointer; @@ -88,10 +122,6 @@ struct wayland { char *theme_name; } pointer; - /* Clipboard */ - struct wl_clipboard clipboard; - struct wl_primary primary; - bool have_argb8888; tll(struct monitor) monitors; /* All available outputs */ }; -- cgit v1.3