aboutsummaryrefslogtreecommitdiff
path: root/swt.c
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2023-04-11 09:09:03 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2023-04-11 09:09:03 +0200
commitb9b5d5ae2be24d41f3cbd71b9b30338afdb132ee (patch)
treefa7732a6e823ed61d1a9a0e17e7935c978e184d2 /swt.c
parent76440f53fd9529525e286224e11e918d1e05baf5 (diff)
add ctrl-sequences and custom kmap
Diffstat (limited to 'swt.c')
-rw-r--r--swt.c60
1 files changed, 53 insertions, 7 deletions
diff --git a/swt.c b/swt.c
index b43b43d..60d9e9a 100644
--- a/swt.c
+++ b/swt.c
@@ -55,6 +55,8 @@ static void setup();
static void cleanup();
static void run();
static void usage();
+static int matchmod(uint32_t mask, uint32_t mod);
+static char *kmap();
static void buffer_release(void *data, struct wl_buffer *buffer);
static void draw_frame();
static void commit_surface();
@@ -370,13 +372,13 @@ toplevel_configure(void *data, struct xdg_toplevel *toplevel, int32_t width, int
}
win.canvas = create_drw(client.shm, win.width, win.height);
+ draw_frame();
ttywidth = (win.width - 2 * borderpx) / win.fontcache->box.width;
ttyheight = (win.height - 2 * borderpx) / win.fontcache->box.height;
ttywidth = MAX(ttywidth, 1);
ttyheight = MAX(ttyheight, 1);
tresize(ttywidth, ttyheight);
ttyresize(ttywidth, ttyheight);
- draw_frame();
}
}
@@ -488,21 +490,27 @@ keyboard_modifiers(void *data, struct wl_keyboard *keybaord, uint32_t serial, ui
{
xkb_state_update_mask(client.kb.state, depressed, latched, locked, 0, 0, group);
- client.kb.event.mods.alt = xkb_state_mod_name_is_active(
+ client.kb.event.mod = 0;
+ client.kb.event.mod |= xkb_state_mod_name_is_active(
client.kb.state,
XKB_MOD_NAME_ALT,
XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED
- );
- client.kb.event.mods.ctrl = xkb_state_mod_name_is_active(
+ ) * KEY_MOD_ALT;
+ client.kb.event.mod = xkb_state_mod_name_is_active(
client.kb.state,
XKB_MOD_NAME_CTRL,
XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED
- );
- client.kb.event.mods.shift = xkb_state_mod_name_is_active(
+ ) * KEY_MOD_CTRL;
+ client.kb.event.mod |= xkb_state_mod_name_is_active(
client.kb.state,
XKB_MOD_NAME_SHIFT,
XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED
- );
+ ) * KEY_MOD_SHIFT;
+ client.kb.event.mod |= xkb_state_mod_name_is_active(
+ client.kb.state,
+ XKB_MOD_NAME_LOGO,
+ XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED
+ ) * KEY_MOD_LOGO;
}
@@ -518,14 +526,52 @@ keyboard_repeat_info(void *data, struct wl_keyboard *keyboard, int32_t rate, int
}
+int
+matchmod(uint32_t mask, uint32_t mod)
+{
+ return mask == KEY_MOD_ANY || mask == mod;
+}
+
+
+char *
+kmap()
+{
+ Key *kp;
+
+ for (kp = key; kp < key + LEN(key); kp++) {
+ if (kp->k != client.kb.event.sym)
+ continue;
+
+ if (!matchmod(kp->mask, client.kb.event.mod))
+ continue;
+
+ return kp->s;
+ }
+
+ return 0;
+}
+
+
void
handle_keyboard_event()
{
char buf[9] = { 0 };
+ char *customkey;
int len;
+ char c;
if (client.kb.event.state == WL_KEYBOARD_KEY_STATE_PRESSED) {
+ if ((customkey = kmap())) {
+ ttywrite(customkey, strlen(customkey), 1);
+ return;
+ }
+
if ((len = xkb_keysym_to_utf8(client.kb.event.sym, buf, 8))) {
+ if (client.kb.event.mod & KEY_MOD_CTRL) {
+ xkb_keysym_to_utf8(xkb_keysym_to_lower(client.kb.event.sym), buf, 8);
+ buf[0] -= 'a' - 1;
+ }
+
ttywrite(buf, strlen(buf), 1);
}
}