From 37fb26a403ca8b88f5300755238239d9c120b522 Mon Sep 17 00:00:00 2001 From: PixelDots Date: Sat, 30 Sep 2023 08:42:42 -0500 Subject: [PATCH 1/3] Added Modifier-only keybinding support --- src/config/key_bindings.rs | 13 ++++-- src/config/types.rs | 13 ++++-- src/input/mod.rs | 61 +++++++++++++++++++++++---- src/shell/layout/tiling/grabs/swap.rs | 4 +- 4 files changed, 73 insertions(+), 18 deletions(-) diff --git a/src/config/key_bindings.rs b/src/config/key_bindings.rs index 4ad89f6a..1eba1f7a 100644 --- a/src/config/key_bindings.rs +++ b/src/config/key_bindings.rs @@ -90,11 +90,11 @@ pub struct KeyPattern { pub modifiers: KeyModifiers, /// The actual key, that was pressed #[serde(deserialize_with = "deserialize_Keysym")] - pub key: u32, + pub key: Option, } impl KeyPattern { - pub fn new(modifiers: impl Into, key: u32) -> KeyPattern { + pub fn new(modifiers: impl Into, key: Option) -> KeyPattern { KeyPattern { modifiers: modifiers.into(), key, @@ -117,7 +117,12 @@ impl ToString for KeyPattern { if self.modifiers.shift { result += "Shift+"; } - result += &keysym_get_name(self.key); + + if let Some(key) = self.key { + result += &keysym_get_name(key); + } else { + result.remove(result.len() - 1); + } result } } @@ -176,7 +181,7 @@ fn insert_binding( for key in keys { let pattern = KeyPattern { modifiers: modifiers.clone(), - key, + key: Some(key), }; if !key_bindings.contains_key(&pattern) { key_bindings.insert(pattern, action.clone()); diff --git a/src/config/types.rs b/src/config/types.rs index 349dc216..33a96c50 100644 --- a/src/config/types.rs +++ b/src/config/types.rs @@ -56,13 +56,18 @@ where } #[allow(non_snake_case)] -pub fn deserialize_Keysym<'de, D>(deserializer: D) -> Result +pub fn deserialize_Keysym<'de, D>(deserializer: D) -> Result, D::Error> where D: serde::Deserializer<'de>, { use serde::de::{Error, Unexpected}; - let name = String::deserialize(deserializer)?; + let name: Option = Option::deserialize(deserializer)?; + if name.is_none() { + return Ok(None); + } + + let name = name.unwrap(); //let name = format!("KEY_{}", code); match xkb::keysym_from_name(&name, xkb::KEYSYM_NO_FLAGS) { KeySyms::KEY_NoSymbol => match xkb::keysym_from_name(&name, xkb::KEYSYM_CASE_INSENSITIVE) { @@ -76,9 +81,9 @@ where name, xkb::keysym_get_name(x) ); - Ok(x) + Ok(Some(x)) } }, - x => Ok(x), + x => Ok(Some(x)), } } diff --git a/src/input/mod.rs b/src/input/mod.rs index fd4db964..b9210e8d 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -67,6 +67,8 @@ pub struct SeatId(pub usize); pub struct ActiveOutput(pub RefCell); #[derive(Default)] pub struct SupressedKeys(RefCell)>>); +#[derive(Default, Debug)] +pub struct ModifiersShortcutQueue(RefCell>); #[derive(Default)] pub struct Devices(RefCell>>); @@ -107,6 +109,28 @@ impl SupressedKeys { } } +impl ModifiersShortcutQueue { + pub fn set(&self, binding: KeyPattern) { + let mut set = self.0.borrow_mut(); + *set = Some(binding); + } + + pub fn take(&self, binding: &KeyPattern) -> bool { + let mut set = self.0.borrow_mut(); + if set.is_some() && set.as_ref().unwrap() == binding { + *set = None; + true + } else { + false + } + } + + pub fn clear(&self) { + let mut set = self.0.borrow_mut(); + *set = None; + } +} + impl Devices { fn add_device(&self, device: &D) -> Vec { let id = device.id(); @@ -152,6 +176,7 @@ pub fn add_seat( userdata.insert_if_missing(SeatId::default); userdata.insert_if_missing(Devices::default); userdata.insert_if_missing(SupressedKeys::default); + userdata.insert_if_missing(ModifiersShortcutQueue::default); userdata.insert_if_missing(SeatMoveGrabState::default); userdata.insert_if_missing(CursorState::default); userdata.insert_if_missing(|| ActiveOutput(RefCell::new(output.clone()))); @@ -283,7 +308,7 @@ impl State { || (action_pattern.modifiers.alt && !modifiers.alt) || (action_pattern.modifiers.logo && !modifiers.logo) || (action_pattern.modifiers.shift && !modifiers.shift) - || (handle.raw_syms().contains(&action_pattern.key) && state == KeyState::Released) + || (action_pattern.key.is_some() && handle.raw_syms().contains(&action_pattern.key.unwrap()) && state == KeyState::Released) { data.common.shell.set_overview_mode(None, data.common.event_loop_handle.clone()); @@ -344,8 +369,8 @@ impl State { if let (ResizeMode::Started(action_pattern, _, _), _) = data.common.shell.resize_mode() { - if state == KeyState::Released - && handle.raw_syms().contains(&action_pattern.key) + if action_pattern.key.is_some() && state == KeyState::Released + && handle.raw_syms().contains(&action_pattern.key.unwrap()) { data.common.shell.set_resize_mode(None, &data.common.config, data.common.event_loop_handle.clone()); } else if action_pattern.modifiers != *modifiers { @@ -390,7 +415,7 @@ impl State { let action = Action::_ResizingInternal(direction, edge, state); let key_pattern = KeyPattern { modifiers: modifiers.clone().into(), - key: handle.raw_code(), + key: Some(handle.raw_code()), }; if state == KeyState::Released { @@ -412,7 +437,7 @@ impl State { }).ok() } else { None }; - userdata + userdata .get::() .unwrap() .add(&handle, token); @@ -472,14 +497,30 @@ impl State { } // handle the rest of the global shortcuts + let mut can_clear_modifiers_shortcut = true; if !shortcuts_inhibited { + let modifiers_queue = userdata.get::().unwrap(); for (binding, action) in data.common.config.static_conf.key_bindings.iter() { - if state == KeyState::Pressed - && binding.modifiers == *modifiers - && handle.raw_syms().contains(&binding.key) + let modifiers_bypass = binding.key.is_none() + && state == KeyState::Released + && binding.modifiers != *modifiers + && modifiers_queue.take(binding); + + if !modifiers_bypass && binding.key.is_none() && state == KeyState::Pressed && binding.modifiers == *modifiers { + modifiers_queue.set(binding.clone()); + can_clear_modifiers_shortcut = false; + } + + if ( + binding.key.is_some() + && state == KeyState::Pressed + && handle.raw_syms().contains(&binding.key.unwrap()) + && binding.modifiers == *modifiers + ) || modifiers_bypass { + modifiers_queue.clear(); userdata .get::() .unwrap() @@ -492,6 +533,10 @@ impl State { } } + if can_clear_modifiers_shortcut { + userdata.get::().unwrap().clear(); + } + // keys are passed through to apps FilterResult::Forward }, diff --git a/src/shell/layout/tiling/grabs/swap.rs b/src/shell/layout/tiling/grabs/swap.rs index 4272d86d..162fe8fc 100644 --- a/src/shell/layout/tiling/grabs/swap.rs +++ b/src/shell/layout/tiling/grabs/swap.rs @@ -62,7 +62,7 @@ impl KeyboardGrab for SwapWindowGrab { (pattern.key, *direction) }) .collect::>(); - let Some(direction) = syms.iter().find_map(|sym| focus_bindings.iter().find_map(|(key, direction)| (sym == key).then_some(*direction))) else { return }; + let Some(direction) = syms.iter().find_map(|sym| focus_bindings.iter().find_map(|(key, direction)| (key.is_some() && sym == key.as_ref().unwrap()).then_some(*direction))) else { return }; data.handle_action( Action::Focus(direction), @@ -71,7 +71,7 @@ impl KeyboardGrab for SwapWindowGrab { time, KeyPattern { modifiers: modifiers.map(Into::into).unwrap_or_default(), - key: keycode, + key: Some(keycode), }, None, ); From 805db26ac145b8c6a07c8a2828cbb946d7a166d6 Mon Sep 17 00:00:00 2001 From: PixelDots Date: Sat, 30 Sep 2023 08:50:49 -0500 Subject: [PATCH 2/3] Update `config.ron` `Super` now to open Launcher --- config.ron | 138 +++++++++++++++++++++++++++-------------------------- 1 file changed, 70 insertions(+), 68 deletions(-) diff --git a/config.ron b/config.ron index 2a34d462..e00ec3b8 100644 --- a/config.ron +++ b/config.ron @@ -1,86 +1,88 @@ ( key_bindings: { - (modifiers: [Super, Shift], key: "Escape"): Terminate, - (modifiers: [Super], key: "Escape"): Debug, - (modifiers: [Super], key: "q"): Close, + (modifiers: [Super, Shift], key: Some("Escape")): Terminate, + (modifiers: [Super], key: Some("Escape")): Debug, + (modifiers: [Super], key: Some("q")): Close, - (modifiers: [Super], key: "1"): Workspace(1), - (modifiers: [Super], key: "2"): Workspace(2), - (modifiers: [Super], key: "3"): Workspace(3), - (modifiers: [Super], key: "4"): Workspace(4), - (modifiers: [Super], key: "5"): Workspace(5), - (modifiers: [Super], key: "6"): Workspace(6), - (modifiers: [Super], key: "7"): Workspace(7), - (modifiers: [Super], key: "8"): Workspace(8), - (modifiers: [Super], key: "9"): Workspace(9), - (modifiers: [Super], key: "0"): LastWorkspace, - (modifiers: [Super, Shift], key: "1"): MoveToWorkspace(1), - (modifiers: [Super, Shift], key: "2"): MoveToWorkspace(2), - (modifiers: [Super, Shift], key: "3"): MoveToWorkspace(3), - (modifiers: [Super, Shift], key: "4"): MoveToWorkspace(4), - (modifiers: [Super, Shift], key: "5"): MoveToWorkspace(5), - (modifiers: [Super, Shift], key: "6"): MoveToWorkspace(6), - (modifiers: [Super, Shift], key: "7"): MoveToWorkspace(7), - (modifiers: [Super, Shift], key: "8"): MoveToWorkspace(8), - (modifiers: [Super, Shift], key: "9"): MoveToWorkspace(9), - (modifiers: [Super, Shift], key: "0"): MoveToLastWorkspace, + (modifiers: [Super], key: Some("1")): Workspace(1), + (modifiers: [Super], key: Some("2")): Workspace(2), + (modifiers: [Super], key: Some("3")): Workspace(3), + (modifiers: [Super], key: Some("4")): Workspace(4), + (modifiers: [Super], key: Some("5")): Workspace(5), + (modifiers: [Super], key: Some("6")): Workspace(6), + (modifiers: [Super], key: Some("7")): Workspace(7), + (modifiers: [Super], key: Some("8")): Workspace(8), + (modifiers: [Super], key: Some("9")): Workspace(9), + (modifiers: [Super], key: Some("0")): LastWorkspace, + (modifiers: [Super, Shift], key: Some("1")): MoveToWorkspace(1), + (modifiers: [Super, Shift], key: Some("2")): MoveToWorkspace(2), + (modifiers: [Super, Shift], key: Some("3")): MoveToWorkspace(3), + (modifiers: [Super, Shift], key: Some("4")): MoveToWorkspace(4), + (modifiers: [Super, Shift], key: Some("5")): MoveToWorkspace(5), + (modifiers: [Super, Shift], key: Some("6")): MoveToWorkspace(6), + (modifiers: [Super, Shift], key: Some("7")): MoveToWorkspace(7), + (modifiers: [Super, Shift], key: Some("8")): MoveToWorkspace(8), + (modifiers: [Super, Shift], key: Some("9")): MoveToWorkspace(9), + (modifiers: [Super, Shift], key: Some("0")): MoveToLastWorkspace, - (modifiers: [Super, Ctrl, Alt], key: "Down"): MoveToNextOutput, - (modifiers: [Super, Ctrl, Alt], key: "Up"): MoveToPreviousOutput, - (modifiers: [Super, Ctrl, Alt], key: "j"): MoveToNextOutput, - (modifiers: [Super, Ctrl, Alt], key: "k"): MoveToPreviousOutput, + (modifiers: [Super, Ctrl, Alt], key: Some("Down")): MoveToNextOutput, + (modifiers: [Super, Ctrl, Alt], key: Some("Up")): MoveToPreviousOutput, + (modifiers: [Super, Ctrl, Alt], key: Some("j")): MoveToNextOutput, + (modifiers: [Super, Ctrl, Alt], key: Some("k")): MoveToPreviousOutput, - (modifiers: [Super], key: "Period"): NextOutput, - (modifiers: [Super], key: "Comma"): PreviousOutput, - (modifiers: [Super, Shift], key: "Period"): MoveToNextOutput, - (modifiers: [Super, Shift], key: "Comma"): MoveToPreviousOutput, + (modifiers: [Super], key: Some("Period")): NextOutput, + (modifiers: [Super], key: Some("Comma")): PreviousOutput, + (modifiers: [Super, Shift], key: Some("Period")): MoveToNextOutput, + (modifiers: [Super, Shift], key: Some("Comma")): MoveToPreviousOutput, - (modifiers: [Super], key: "Left"): Focus(Left), - (modifiers: [Super], key: "Right"): Focus(Right), - (modifiers: [Super], key: "Up"): Focus(Up), - (modifiers: [Super], key: "Down"): Focus(Down), - (modifiers: [Super], key: "h"): Focus(Left), - (modifiers: [Super], key: "j"): Focus(Down), - (modifiers: [Super], key: "k"): Focus(Up), - (modifiers: [Super], key: "l"): Focus(Right), - (modifiers: [Super], key: "u"): Focus(Out), - (modifiers: [Super], key: "i"): Focus(In), + (modifiers: [Super], key: Some("Left")): Focus(Left), + (modifiers: [Super], key: Some("Right")): Focus(Right), + (modifiers: [Super], key: Some("Up")): Focus(Up), + (modifiers: [Super], key: Some("Down")): Focus(Down), + (modifiers: [Super], key: Some("h")): Focus(Left), + (modifiers: [Super], key: Some("j")): Focus(Down), + (modifiers: [Super], key: Some("k")): Focus(Up), + (modifiers: [Super], key: Some("l")): Focus(Right), + (modifiers: [Super], key: Some("u")): Focus(Out), + (modifiers: [Super], key: Some("i")): Focus(In), - (modifiers: [Super, Shift], key: "Left"): Move(Left), - (modifiers: [Super, Shift], key: "Right"): Move(Right), - (modifiers: [Super, Shift], key: "Up"): Move(Up), - (modifiers: [Super, Shift], key: "Down"): Move(Down), - (modifiers: [Super, Shift], key: "h"): Move(Left), - (modifiers: [Super, Shift], key: "j"): Move(Down), - (modifiers: [Super, Shift], key: "k"): Move(Up), - (modifiers: [Super, Shift], key: "l"): Move(Right), + (modifiers: [Super, Shift], key: Some("Left")): Move(Left), + (modifiers: [Super, Shift], key: Some("Right")): Move(Right), + (modifiers: [Super, Shift], key: Some("Up")): Move(Up), + (modifiers: [Super, Shift], key: Some("Down")): Move(Down), + (modifiers: [Super, Shift], key: Some("h")): Move(Left), + (modifiers: [Super, Shift], key: Some("j")): Move(Down), + (modifiers: [Super, Shift], key: Some("k")): Move(Up), + (modifiers: [Super, Shift], key: Some("l")): Move(Right), - (modifiers: [Super], key: "o"): ToggleOrientation, - (modifiers: [Super], key: "s"): ToggleStacking, - (modifiers: [Super], key: "y"): ToggleTiling, - (modifiers: [Super], key: "g"): ToggleWindowFloating, - (modifiers: [Super], key: "x"): SwapWindow, + (modifiers: [Super], key: Some("o")): ToggleOrientation, + (modifiers: [Super], key: Some("s")): ToggleStacking, + (modifiers: [Super], key: Some("y")): ToggleTiling, + (modifiers: [Super], key: Some("g")): ToggleWindowFloating, + (modifiers: [Super], key: Some("x")): SwapWindow, - (modifiers: [Super], key: "m"): Maximize, - (modifiers: [Super], key: "r"): Resizing(Outwards), - (modifiers: [Super, Shift], key: "r"): Resizing(Inwards), + (modifiers: [Super], key: Some("m")): Maximize, + (modifiers: [Super], key: Some("r")): Resizing(Outwards), + (modifiers: [Super, Shift], key: Some("r")): Resizing(Inwards), //TODO: ability to select default web browser - (modifiers: [Super], key: "b"): Spawn("firefox"), + (modifiers: [Super], key: Some("b")): Spawn("firefox"), //TODO: ability to select default file browser - (modifiers: [Super], key: "f"): Spawn("nautilus"), + (modifiers: [Super], key: Some("f")): Spawn("nautilus"), //TODO: ability to select default terminal - (modifiers: [Super], key: "t"): Spawn("gnome-terminal"), + (modifiers: [Super], key: Some("t")): Spawn("gnome-terminal"), - (modifiers: [Super], key: "a"): Spawn("busctl --user call com.system76.CosmicAppLibrary /com/system76/CosmicAppLibrary com.system76.CosmicAppLibrary Toggle"), - (modifiers: [Super], key: "w"): Spawn("busctl --user call com.system76.CosmicWorkspaces /com/system76/CosmicWorkspaces com.system76.CosmicWorkspaces Toggle"), - (modifiers: [Super], key: "slash"): Spawn("busctl --user call com.system76.CosmicLauncher /com/system76/CosmicLauncher com.system76.CosmicLauncher Toggle"), + (modifiers: [Super], key: Some("a")): Spawn("busctl --user call com.system76.CosmicAppLibrary /com/system76/CosmicAppLibrary com.system76.CosmicAppLibrary Toggle"), + (modifiers: [Super], key: Some("w")): Spawn("busctl --user call com.system76.CosmicWorkspaces /com/system76/CosmicWorkspaces com.system76.CosmicWorkspaces Toggle"), + (modifiers: [Super], key: Some("slash")): Spawn("busctl --user call com.system76.CosmicLauncher /com/system76/CosmicLauncher com.system76.CosmicLauncher Toggle"), + (modifiers: [Super], key: None): Spawn("busctl --user call com.system76.CosmicLauncher /com/system76/CosmicLauncher com.system76.CosmicLauncher Toggle"), - (modifiers: [], key: "XF86AudioRaiseVolume"): Spawn("amixer sset Master 5%+"), - (modifiers: [], key: "XF86AudioLowerVolume"): Spawn("amixer sset Master 5%-"), - (modifiers: [], key: "XF86AudioMute"): Spawn("amixer sset Master toggle"), - (modifiers: [], key: "XF86MonBrightnessUp"): Spawn("busctl --user call com.system76.CosmicSettingsDaemon /com/system76/CosmicSettingsDaemon com.system76.CosmicSettingsDaemon IncreaseDisplayBrightness"), - (modifiers: [], key: "XF86MonBrightnessDown"): Spawn("busctl --user call com.system76.CosmicSettingsDaemon /com/system76/CosmicSettingsDaemon com.system76.CosmicSettingsDaemon DecreaseDisplayBrightness"), + + (modifiers: [], key: Some("XF86AudioRaiseVolume")): Spawn("amixer sset Master 5%+"), + (modifiers: [], key: Some("XF86AudioLowerVolume")): Spawn("amixer sset Master 5%-"), + (modifiers: [], key: Some("XF86AudioMute")): Spawn("amixer sset Master toggle"), + (modifiers: [], key: Some("XF86MonBrightnessUp")): Spawn("busctl --user call com.system76.CosmicSettingsDaemon /com/system76/CosmicSettingsDaemon com.system76.CosmicSettingsDaemon IncreaseDisplayBrightness"), + (modifiers: [], key: Some("XF86MonBrightnessDown")): Spawn("busctl --user call com.system76.CosmicSettingsDaemon /com/system76/CosmicSettingsDaemon com.system76.CosmicSettingsDaemon DecreaseDisplayBrightness"), }, workspace_mode: OutputBound, workspace_amount: Dynamic, From c60f7071bb07c051e0dfe03845ba9277b4da9853 Mon Sep 17 00:00:00 2001 From: PixelDots Date: Mon, 2 Oct 2023 13:03:40 -0500 Subject: [PATCH 3/3] deserialize string or default to none for config.ron Cleanup config.ron --- config.ron | 141 ++++++++++++++++++------------------- src/config/key_bindings.rs | 2 +- src/config/types.rs | 7 +- 3 files changed, 72 insertions(+), 78 deletions(-) diff --git a/config.ron b/config.ron index e00ec3b8..451dcecd 100644 --- a/config.ron +++ b/config.ron @@ -1,91 +1,90 @@ ( key_bindings: { - (modifiers: [Super, Shift], key: Some("Escape")): Terminate, - (modifiers: [Super], key: Some("Escape")): Debug, - (modifiers: [Super], key: Some("q")): Close, + (modifiers: [Super, Shift], key: "Escape"): Terminate, + (modifiers: [Super], key: "Escape"): Debug, + (modifiers: [Super], key: "q"): Close, - (modifiers: [Super], key: Some("1")): Workspace(1), - (modifiers: [Super], key: Some("2")): Workspace(2), - (modifiers: [Super], key: Some("3")): Workspace(3), - (modifiers: [Super], key: Some("4")): Workspace(4), - (modifiers: [Super], key: Some("5")): Workspace(5), - (modifiers: [Super], key: Some("6")): Workspace(6), - (modifiers: [Super], key: Some("7")): Workspace(7), - (modifiers: [Super], key: Some("8")): Workspace(8), - (modifiers: [Super], key: Some("9")): Workspace(9), - (modifiers: [Super], key: Some("0")): LastWorkspace, - (modifiers: [Super, Shift], key: Some("1")): MoveToWorkspace(1), - (modifiers: [Super, Shift], key: Some("2")): MoveToWorkspace(2), - (modifiers: [Super, Shift], key: Some("3")): MoveToWorkspace(3), - (modifiers: [Super, Shift], key: Some("4")): MoveToWorkspace(4), - (modifiers: [Super, Shift], key: Some("5")): MoveToWorkspace(5), - (modifiers: [Super, Shift], key: Some("6")): MoveToWorkspace(6), - (modifiers: [Super, Shift], key: Some("7")): MoveToWorkspace(7), - (modifiers: [Super, Shift], key: Some("8")): MoveToWorkspace(8), - (modifiers: [Super, Shift], key: Some("9")): MoveToWorkspace(9), - (modifiers: [Super, Shift], key: Some("0")): MoveToLastWorkspace, + (modifiers: [Super], key: "1"): Workspace(1), + (modifiers: [Super], key: "2"): Workspace(2), + (modifiers: [Super], key: "3"): Workspace(3), + (modifiers: [Super], key: "4"): Workspace(4), + (modifiers: [Super], key: "5"): Workspace(5), + (modifiers: [Super], key: "6"): Workspace(6), + (modifiers: [Super], key: "7"): Workspace(7), + (modifiers: [Super], key: "8"): Workspace(8), + (modifiers: [Super], key: "9"): Workspace(9), + (modifiers: [Super], key: "0"): LastWorkspace, + (modifiers: [Super, Shift], key: "1"): MoveToWorkspace(1), + (modifiers: [Super, Shift], key: "2"): MoveToWorkspace(2), + (modifiers: [Super, Shift], key: "3"): MoveToWorkspace(3), + (modifiers: [Super, Shift], key: "4"): MoveToWorkspace(4), + (modifiers: [Super, Shift], key: "5"): MoveToWorkspace(5), + (modifiers: [Super, Shift], key: "6"): MoveToWorkspace(6), + (modifiers: [Super, Shift], key: "7"): MoveToWorkspace(7), + (modifiers: [Super, Shift], key: "8"): MoveToWorkspace(8), + (modifiers: [Super, Shift], key: "9"): MoveToWorkspace(9), + (modifiers: [Super, Shift], key: "0"): MoveToLastWorkspace, - (modifiers: [Super, Ctrl, Alt], key: Some("Down")): MoveToNextOutput, - (modifiers: [Super, Ctrl, Alt], key: Some("Up")): MoveToPreviousOutput, - (modifiers: [Super, Ctrl, Alt], key: Some("j")): MoveToNextOutput, - (modifiers: [Super, Ctrl, Alt], key: Some("k")): MoveToPreviousOutput, + (modifiers: [Super, Ctrl, Alt], key: "Down"): MoveToNextOutput, + (modifiers: [Super, Ctrl, Alt], key: "Up"): MoveToPreviousOutput, + (modifiers: [Super, Ctrl, Alt], key: "j"): MoveToNextOutput, + (modifiers: [Super, Ctrl, Alt], key: "k"): MoveToPreviousOutput, - (modifiers: [Super], key: Some("Period")): NextOutput, - (modifiers: [Super], key: Some("Comma")): PreviousOutput, - (modifiers: [Super, Shift], key: Some("Period")): MoveToNextOutput, - (modifiers: [Super, Shift], key: Some("Comma")): MoveToPreviousOutput, + (modifiers: [Super], key: "Period"): NextOutput, + (modifiers: [Super], key: "Comma"): PreviousOutput, + (modifiers: [Super, Shift], key: "Period"): MoveToNextOutput, + (modifiers: [Super, Shift], key: "Comma"): MoveToPreviousOutput, - (modifiers: [Super], key: Some("Left")): Focus(Left), - (modifiers: [Super], key: Some("Right")): Focus(Right), - (modifiers: [Super], key: Some("Up")): Focus(Up), - (modifiers: [Super], key: Some("Down")): Focus(Down), - (modifiers: [Super], key: Some("h")): Focus(Left), - (modifiers: [Super], key: Some("j")): Focus(Down), - (modifiers: [Super], key: Some("k")): Focus(Up), - (modifiers: [Super], key: Some("l")): Focus(Right), - (modifiers: [Super], key: Some("u")): Focus(Out), - (modifiers: [Super], key: Some("i")): Focus(In), + (modifiers: [Super], key: "Left"): Focus(Left), + (modifiers: [Super], key: "Right"): Focus(Right), + (modifiers: [Super], key: "Up"): Focus(Up), + (modifiers: [Super], key: "Down"): Focus(Down), + (modifiers: [Super], key: "h"): Focus(Left), + (modifiers: [Super], key: "j"): Focus(Down), + (modifiers: [Super], key: "k"): Focus(Up), + (modifiers: [Super], key: "l"): Focus(Right), + (modifiers: [Super], key: "u"): Focus(Out), + (modifiers: [Super], key: "i"): Focus(In), - (modifiers: [Super, Shift], key: Some("Left")): Move(Left), - (modifiers: [Super, Shift], key: Some("Right")): Move(Right), - (modifiers: [Super, Shift], key: Some("Up")): Move(Up), - (modifiers: [Super, Shift], key: Some("Down")): Move(Down), - (modifiers: [Super, Shift], key: Some("h")): Move(Left), - (modifiers: [Super, Shift], key: Some("j")): Move(Down), - (modifiers: [Super, Shift], key: Some("k")): Move(Up), - (modifiers: [Super, Shift], key: Some("l")): Move(Right), + (modifiers: [Super, Shift], key: "Left"): Move(Left), + (modifiers: [Super, Shift], key: "Right"): Move(Right), + (modifiers: [Super, Shift], key: "Up"): Move(Up), + (modifiers: [Super, Shift], key: "Down"): Move(Down), + (modifiers: [Super, Shift], key: "h"): Move(Left), + (modifiers: [Super, Shift], key: "j"): Move(Down), + (modifiers: [Super, Shift], key: "k"): Move(Up), + (modifiers: [Super, Shift], key: "l"): Move(Right), - (modifiers: [Super], key: Some("o")): ToggleOrientation, - (modifiers: [Super], key: Some("s")): ToggleStacking, - (modifiers: [Super], key: Some("y")): ToggleTiling, - (modifiers: [Super], key: Some("g")): ToggleWindowFloating, - (modifiers: [Super], key: Some("x")): SwapWindow, + (modifiers: [Super], key: "o"): ToggleOrientation, + (modifiers: [Super], key: "s"): ToggleStacking, + (modifiers: [Super], key: "y"): ToggleTiling, + (modifiers: [Super], key: "g"): ToggleWindowFloating, + (modifiers: [Super], key: "x"): SwapWindow, - (modifiers: [Super], key: Some("m")): Maximize, - (modifiers: [Super], key: Some("r")): Resizing(Outwards), - (modifiers: [Super, Shift], key: Some("r")): Resizing(Inwards), + (modifiers: [Super], key: "m"): Maximize, + (modifiers: [Super], key: "r"): Resizing(Outwards), + (modifiers: [Super, Shift], key: "r"): Resizing(Inwards), //TODO: ability to select default web browser - (modifiers: [Super], key: Some("b")): Spawn("firefox"), + (modifiers: [Super], key: "b"): Spawn("firefox"), //TODO: ability to select default file browser - (modifiers: [Super], key: Some("f")): Spawn("nautilus"), + (modifiers: [Super], key: "f"): Spawn("nautilus"), //TODO: ability to select default terminal - (modifiers: [Super], key: Some("t")): Spawn("gnome-terminal"), + (modifiers: [Super], key: "t"): Spawn("gnome-terminal"), - (modifiers: [Super], key: Some("a")): Spawn("busctl --user call com.system76.CosmicAppLibrary /com/system76/CosmicAppLibrary com.system76.CosmicAppLibrary Toggle"), - (modifiers: [Super], key: Some("w")): Spawn("busctl --user call com.system76.CosmicWorkspaces /com/system76/CosmicWorkspaces com.system76.CosmicWorkspaces Toggle"), - (modifiers: [Super], key: Some("slash")): Spawn("busctl --user call com.system76.CosmicLauncher /com/system76/CosmicLauncher com.system76.CosmicLauncher Toggle"), - (modifiers: [Super], key: None): Spawn("busctl --user call com.system76.CosmicLauncher /com/system76/CosmicLauncher com.system76.CosmicLauncher Toggle"), + (modifiers: [Super], key: "a"): Spawn("busctl --user call com.system76.CosmicAppLibrary /com/system76/CosmicAppLibrary com.system76.CosmicAppLibrary Toggle"), + (modifiers: [Super], key: "w"): Spawn("busctl --user call com.system76.CosmicWorkspaces /com/system76/CosmicWorkspaces com.system76.CosmicWorkspaces Toggle"), + (modifiers: [Super], key: "slash"): Spawn("busctl --user call com.system76.CosmicLauncher /com/system76/CosmicLauncher com.system76.CosmicLauncher Toggle"), + (modifiers: [Super]): Spawn("busctl --user call com.system76.CosmicLauncher /com/system76/CosmicLauncher com.system76.CosmicLauncher Toggle"), - - (modifiers: [], key: Some("XF86AudioRaiseVolume")): Spawn("amixer sset Master 5%+"), - (modifiers: [], key: Some("XF86AudioLowerVolume")): Spawn("amixer sset Master 5%-"), - (modifiers: [], key: Some("XF86AudioMute")): Spawn("amixer sset Master toggle"), - (modifiers: [], key: Some("XF86MonBrightnessUp")): Spawn("busctl --user call com.system76.CosmicSettingsDaemon /com/system76/CosmicSettingsDaemon com.system76.CosmicSettingsDaemon IncreaseDisplayBrightness"), - (modifiers: [], key: Some("XF86MonBrightnessDown")): Spawn("busctl --user call com.system76.CosmicSettingsDaemon /com/system76/CosmicSettingsDaemon com.system76.CosmicSettingsDaemon DecreaseDisplayBrightness"), + (modifiers: [], key: "XF86AudioRaiseVolume"): Spawn("amixer sset Master 5%+"), + (modifiers: [], key: "XF86AudioLowerVolume"): Spawn("amixer sset Master 5%-"), + (modifiers: [], key: "XF86AudioMute"): Spawn("amixer sset Master toggle"), + (modifiers: [], key: "XF86MonBrightnessUp"): Spawn("busctl --user call com.system76.CosmicSettingsDaemon /com/system76/CosmicSettingsDaemon com.system76.CosmicSettingsDaemon IncreaseDisplayBrightness"), + (modifiers: [], key: "XF86MonBrightnessDown"): Spawn("busctl --user call com.system76.CosmicSettingsDaemon /com/system76/CosmicSettingsDaemon com.system76.CosmicSettingsDaemon DecreaseDisplayBrightness"), }, workspace_mode: OutputBound, workspace_amount: Dynamic, workspace_layout: Vertical, tiling_enabled: false, -) +) \ No newline at end of file diff --git a/src/config/key_bindings.rs b/src/config/key_bindings.rs index 1eba1f7a..985d4b8f 100644 --- a/src/config/key_bindings.rs +++ b/src/config/key_bindings.rs @@ -89,7 +89,7 @@ pub struct KeyPattern { #[serde(deserialize_with = "deserialize_KeyModifiers")] pub modifiers: KeyModifiers, /// The actual key, that was pressed - #[serde(deserialize_with = "deserialize_Keysym")] + #[serde(deserialize_with = "deserialize_Keysym", default)] pub key: Option, } diff --git a/src/config/types.rs b/src/config/types.rs index 33a96c50..03fa4eb7 100644 --- a/src/config/types.rs +++ b/src/config/types.rs @@ -62,12 +62,7 @@ where { use serde::de::{Error, Unexpected}; - let name: Option = Option::deserialize(deserializer)?; - if name.is_none() { - return Ok(None); - } - - let name = name.unwrap(); + let name = String::deserialize(deserializer)?; //let name = format!("KEY_{}", code); match xkb::keysym_from_name(&name, xkb::KEYSYM_NO_FLAGS) { KeySyms::KEY_NoSymbol => match xkb::keysym_from_name(&name, xkb::KEYSYM_CASE_INSENSITIVE) {