feat(keyboard): add "swap with control" for caps lock key

This commit is contained in:
Daniel Fox Franke 2026-04-20 09:12:52 -04:00 committed by GitHub
parent 2b7fd9b8e2
commit d0fa882596
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -48,6 +48,7 @@ static CAPS_LOCK_OPTIONS: &[(&str, &str)] = &[
("Backspace", "caps:backspace"), ("Backspace", "caps:backspace"),
("Super", "caps:super"), ("Super", "caps:super"),
("Control", "caps:ctrl_modifier"), ("Control", "caps:ctrl_modifier"),
("Swap with Control", "ctrl:swapcaps"),
]; ];
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -151,11 +152,11 @@ impl SpecialKey {
} }
} }
pub fn prefix(self) -> &'static str { pub fn prefixes(self) -> &'static [&'static str] {
match self { match self {
Self::Compose => "compose:", Self::Compose => &["compose:"],
Self::AlternateCharacters => "lv3:", Self::AlternateCharacters => &["lv3:"],
Self::CapsLock => "caps:", Self::CapsLock => &["caps:", "ctrl:"],
} }
} }
} }
@ -508,10 +509,10 @@ impl Page {
Message::SpecialCharacterSelect(id) => { Message::SpecialCharacterSelect(id) => {
if let Some(Context::SpecialCharacter(special_key)) = self.context { if let Some(Context::SpecialCharacter(special_key)) = self.context {
let options = self.xkb.options.as_deref().unwrap_or_default(); let options = self.xkb.options.as_deref().unwrap_or_default();
let prefix = special_key.prefix(); let prefixes = special_key.prefixes();
let new_options = options let new_options = options
.split(',') .split(',')
.filter(|x| !x.starts_with(prefix)) .filter(|x| !prefixes.iter().any(|prefix| x.starts_with(prefix)))
.chain(id) .chain(id)
.join(","); .join(",");
@ -607,13 +608,13 @@ impl Page {
SpecialKey::AlternateCharacters => (ALTERNATE_CHARACTER_OPTIONS, None), SpecialKey::AlternateCharacters => (ALTERNATE_CHARACTER_OPTIONS, None),
SpecialKey::CapsLock => (CAPS_LOCK_OPTIONS, None), SpecialKey::CapsLock => (CAPS_LOCK_OPTIONS, None),
}; };
let prefix = special_key.prefix(); let prefixes = special_key.prefixes();
let current = self let current = self
.xkb .xkb
.options .options
.iter() .iter()
.flat_map(|x| x.split(',')) .flat_map(|x| x.split(','))
.find(|x| x.starts_with(prefix)); .find(|x| prefixes.iter().any(|prefix| x.starts_with(prefix)));
// TODO layout default // TODO layout default