From 97f41faf093280079f8cf409ee8604869964b9d9 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sun, 9 Jan 2022 04:32:57 +0000 Subject: [PATCH] Make caps lock work on Haiku * src/haiku_support.cc (map_caps): (map_caps_shift): New functions. (DispatchMessage): Map keys with the appropriate map if caps lock is on. --- src/haiku_support.cc | 48 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 47a6af92f61..03d5dad7699 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -178,6 +178,40 @@ map_shift (uint32_t kc, uint32_t *ch) key_map_lock.Unlock (); } +static void +map_caps (uint32_t kc, uint32_t *ch) +{ + if (!key_map_lock.Lock ()) + gui_abort ("Failed to lock keymap"); + if (!key_map) + get_key_map (&key_map, &key_chars); + if (!key_map) + return; + if (kc >= 128) + return; + + int32_t m = key_map->caps_map[kc]; + map_key (key_chars, m, ch); + key_map_lock.Unlock (); +} + +static void +map_caps_shift (uint32_t kc, uint32_t *ch) +{ + if (!key_map_lock.Lock ()) + gui_abort ("Failed to lock keymap"); + if (!key_map) + get_key_map (&key_map, &key_chars); + if (!key_map) + return; + if (kc >= 128) + return; + + int32_t m = key_map->caps_shift_map[kc]; + map_key (key_chars, m, ch); + key_map_lock.Unlock (); +} + static void map_normal (uint32_t kc, uint32_t *ch) { @@ -605,9 +639,19 @@ public: BUnicodeChar::FromUTF8 (msg->GetString ("bytes")); if ((mods & B_SHIFT_KEY) && rq.kc >= 0) - map_shift (rq.kc, &rq.unraw_mb_char); + { + if (mods & B_CAPS_LOCK) + map_caps_shift (rq.kc, &rq.unraw_mb_char); + else + map_shift (rq.kc, &rq.unraw_mb_char); + } else if (rq.kc >= 0) - map_normal (rq.kc, &rq.unraw_mb_char); + { + if (mods & B_CAPS_LOCK) + map_caps (rq.kc, &rq.unraw_mb_char); + else + map_normal (rq.kc, &rq.unraw_mb_char); + } haiku_write (msg->what == B_KEY_DOWN ? KEY_DOWN : KEY_UP, &rq); } -- 2.39.2