From 2add312c5c7bf2c5012053c26586e9067edd96e2 Mon Sep 17 00:00:00 2001 From: Chris <1828125+digitallyserviced@users.noreply.github.com> Date: Fri, 7 May 2021 10:54:24 -0400 Subject: [PATCH] Allow VoidSymbol keycode to be seen by wezterm (#759) * allow voidsymbol for key code * update docs, cleanup * cleanup and fmt of files * remove unnecessary inputs --- config/src/keys.rs | 1 + docs/config/keys.md | 26 +++++++++++++++++++++++++- wezterm-gui/src/termwindow/keyevent.rs | 1 + wezterm-input-types/src/lib.rs | 1 + window/src/os/xkeysyms.rs | 2 ++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/config/src/keys.rs b/config/src/keys.rs index b2f6b886a..6ccbe9fc6 100644 --- a/config/src/keys.rs +++ b/config/src/keys.rs @@ -66,6 +66,7 @@ fn make_map() -> HashMap { RightAlt, Pause, CapsLock, + VoidSymbol, PageUp, PageDown, End, diff --git a/docs/config/keys.md b/docs/config/keys.md index 43eae1c5f..90e255668 100644 --- a/docs/config/keys.md +++ b/docs/config/keys.md @@ -219,7 +219,7 @@ all of these are meaningful on all platforms: `Hyper`, `Super`, `Meta`, `Cancel`, `Backspace`, `Tab`, `Clear`, `Enter`, `Shift`, `Escape`, `LeftShift`, `RightShift`, `Control`, `LeftControl`, `RightControl`, `Alt`, `LeftAlt`, `RightAlt`, `Menu`, `LeftMenu`, `RightMenu`, -`Pause`, `CapsLock`, `PageUp`, `PageDown`, `End`, `Home`, `LeftArrow`, +`Pause`, `CapsLock`, `VoidSymbol`, `PageUp`, `PageDown`, `End`, `Home`, `LeftArrow`, `RightArrow`, `UpArrow`, `DownArrow`, `Select`, `Print`, `Execute`, `PrintScreen`, `Insert`, `Delete`, `Help`, `LeftWindows`, `RightWindows`, `Applications`, `Sleep`, `Numpad0`, `Numpad1`, `Numpad2`, `Numpad3`, @@ -244,6 +244,10 @@ Possible Modifier labels are: * `SHIFT` - The shift key. Left and right are equivalent. * `ALT`, `OPT`, `META` - these are all equivalent: on macOS the `Option` key, on other systems the `Alt` or `Meta` key. Left and right are equivalent. + * `VoidSymbol` - This keycode is emitted in special cases where the original + function of the key has been removed. Such as in Linux and using `setxkbmap`. + `setxkbmap -option caps:none`. The `CapsLock` will no longer function as + before in all applications, instead emitting `VoidSymbol`. You can combine modifiers using the `|` symbol (eg: `"CMD|CTRL"`). @@ -283,6 +287,26 @@ return { } ``` +If you decide to change certain keys on the keyboard to `VoidSymbol` (like `CapsLock`), +then you can utilize it as a `LEADER` or any other part of key bindings. The +following example now uses `VoidSymbol` and uses `CapsLock` as a `LEADER` +without it affecting the shift / capital state as long as you have +`setxkbmap -option caps:none` configured. + +```lua +local wezterm = require 'wezterm'; + +return { + -- timeout_milliseconds defaults to 1000 and can be omitted + -- for this example use `setxkbmap -option caps:none` in your terminal. + leader = { key="VoidSymbol", mods="", timeout_milliseconds=1000 }, + keys = { + {key="|", mods="LEADER", action=wezterm.action{SplitHorizontal={domain="CurrentPaneDomain"}}}, + {key="-", mods="LEADER", action=wezterm.action{SplitVertical={domain="CurrentPaneDomain"}}}, + } +} +``` + ### Using Raw/Scan Codes for key bindings In some cases it is desirable to assign keys based on their diff --git a/wezterm-gui/src/termwindow/keyevent.rs b/wezterm-gui/src/termwindow/keyevent.rs index a4efe6386..3da1e39bf 100644 --- a/wezterm-gui/src/termwindow/keyevent.rs +++ b/wezterm-gui/src/termwindow/keyevent.rs @@ -300,6 +300,7 @@ impl super::TermWindow { WK::RightAlt => KC::RightAlt, WK::Pause => KC::Pause, WK::CapsLock => KC::CapsLock, + WK::VoidSymbol => return Key::None, WK::Select => KC::Select, WK::Print => KC::Print, WK::Execute => KC::Execute, diff --git a/wezterm-input-types/src/lib.rs b/wezterm-input-types/src/lib.rs index bafbfb6d9..1242d54f9 100644 --- a/wezterm-input-types/src/lib.rs +++ b/wezterm-input-types/src/lib.rs @@ -40,6 +40,7 @@ pub enum KeyCode { RightAlt, Pause, CapsLock, + VoidSymbol, PageUp, PageDown, End, diff --git a/window/src/os/xkeysyms.rs b/window/src/os/xkeysyms.rs index 2b10fbd9a..ce1dcaada 100644 --- a/window/src/os/xkeysyms.rs +++ b/window/src/os/xkeysyms.rs @@ -82,6 +82,8 @@ pub fn keysym_to_keycode(keysym: u32) -> Option { KEY_Menu => KeyCode::Applications, KEY_Help => KeyCode::Help, + KEY_VoidSymbol => KeyCode::VoidSymbol, + i @ KEY_F1..=KEY_F12 => KeyCode::Function((1 + i - KEY_F1) as u8), // numeric and function keypad keys