core: add meta key

Some applications have features (like typing Unicode codepoints in foot)
that can only be used with key presses. Add a Meta key to allow the user
to always send a keypress.
This commit is contained in:
Richard Acayan 2024-09-04 21:31:04 -04:00
parent 0ebf6a8d5b
commit f3ba955ae4
3 changed files with 28 additions and 6 deletions

View file

@ -56,7 +56,8 @@ pub const MOD_SHIFT: usize = 1;
pub const MOD_CTRL: usize = 2;
pub const MOD_ALT: usize = 3;
pub const MOD_FN: usize = 4;
pub const MODIFIERS_MAX: usize = 4;
pub const MOD_META: usize = 5;
pub const MODIFIERS_MAX: usize = 5;
#[derive(Clone)]
struct KeyValue(Keysym, String);
@ -417,6 +418,7 @@ impl Part {
Keysym::Control_L => MOD_CTRL,
Keysym::Alt_L => MOD_ALT,
Keysym::XF86_Fn => MOD_FN,
Keysym::Meta_L => MOD_META,
_ => 0,
}
}
@ -501,7 +503,7 @@ pub struct Layout {
text_supp: bool,
}
const KEYSYMS: [(&str, Keysym, &str); 20] = [
const KEYSYMS: [(&str, Keysym, &str); 21] = [
("\\#", Keysym::numbersign, "#"),
("\\?", Keysym::question, "?"),
("\\@", Keysym::at, "@"),
@ -517,6 +519,7 @@ const KEYSYMS: [(&str, Keysym, &str); 20] = [
("fn", Keysym::XF86_Fn, "Fn"),
("left", Keysym::Left, ""),
("loc alt", Keysym::Alt_L, "Alt"),
("loc meta", Keysym::Meta_L, "Meta"),
("right", Keysym::Right, ""),
("shift", Keysym::Shift_L, ""),
("space", Keysym::space, " "),
@ -533,6 +536,20 @@ impl Layout {
}
}
/*
* Check if the modifier can be emitted as a key event.
*
* Modifiers that modify the key values (e.g. the Fn key and any accents)
* should usually not be emitted as key events to applications, and their
* only purpose is to modify the key values. The Meta modifier should also
* be inhibited from emitting a key event, because its purpose is to make
* every key value emit a key press.
*/
pub fn is_pressable_modifier(modifier: usize) -> bool
{
!Self::is_keysym_modifier(modifier) && modifier != MOD_META
}
pub fn is_label_modifier(modifier: usize) -> bool
{
// Shift does not change the keysym used for input, but changes the
@ -547,6 +564,7 @@ impl Layout {
MOD_CTRL => Keysym::Control_L,
MOD_ALT => Keysym::Alt_L,
MOD_FN => Keysym::XF86_Fn,
MOD_META => Keysym::Meta_L,
_ => Keysym::NoSymbol,
}
}