kbd: move into wayland

This commit is contained in:
Daniel Eklöf 2019-10-27 17:07:44 +01:00
parent 061bbd7049
commit c9455d5f21
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
11 changed files with 141 additions and 155 deletions

136
input.c
View file

@ -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);
}

18
kbd.c
View file

@ -1,18 +0,0 @@
#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);
}

35
kbd.h
View file

@ -1,35 +0,0 @@
#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);

31
main.c
View file

@ -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);

View file

@ -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',

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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 */

View file

@ -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)

View file

@ -5,6 +5,7 @@
#include <wayland-client.h>
#include <primary-selection-unstable-v1.h>
#include <xkbcommon/xkbcommon.h>
#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 */
};