Merge branch 'master' into primary
This commit is contained in:
commit
5b2bbe84cb
21 changed files with 2064 additions and 1382 deletions
|
|
@ -1,4 +1,7 @@
|
|||
use cosmic::iced::keyboard::{KeyCode, Modifiers};
|
||||
use cosmic::{
|
||||
iced::keyboard::{Key, Modifiers},
|
||||
iced_core::keyboard::key::Named,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{collections::HashMap, fmt};
|
||||
|
||||
|
|
@ -15,12 +18,12 @@ pub enum Modifier {
|
|||
#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
|
||||
pub struct KeyBind {
|
||||
pub modifiers: Vec<Modifier>,
|
||||
pub key_code: KeyCode,
|
||||
pub key: Key,
|
||||
}
|
||||
|
||||
impl KeyBind {
|
||||
pub fn matches(&self, modifiers: Modifiers, key_code: KeyCode) -> bool {
|
||||
self.key_code == key_code
|
||||
pub fn matches(&self, modifiers: Modifiers, key: &Key) -> bool {
|
||||
key == &self.key
|
||||
&& modifiers.logo() == self.modifiers.contains(&Modifier::Super)
|
||||
&& modifiers.control() == self.modifiers.contains(&Modifier::Ctrl)
|
||||
&& modifiers.alt() == self.modifiers.contains(&Modifier::Alt)
|
||||
|
|
@ -33,7 +36,11 @@ impl fmt::Display for KeyBind {
|
|||
for modifier in self.modifiers.iter() {
|
||||
write!(f, "{:?} + ", modifier)?;
|
||||
}
|
||||
write!(f, "{:?}", self.key_code)
|
||||
match &self.key {
|
||||
Key::Character(c) => write!(f, "{}", c.to_uppercase()),
|
||||
Key::Named(named) => write!(f, "{:?}", named),
|
||||
other => write!(f, "{:?}", other),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -42,11 +49,11 @@ pub fn key_binds() -> HashMap<KeyBind, Action> {
|
|||
let mut key_binds = HashMap::new();
|
||||
|
||||
macro_rules! bind {
|
||||
([$($modifier:ident),+ $(,)?], $key_code:ident, $action:ident) => {{
|
||||
([$($modifier:ident),+ $(,)?], $key:expr, $action:ident) => {{
|
||||
key_binds.insert(
|
||||
KeyBind {
|
||||
modifiers: vec![$(Modifier::$modifier),+],
|
||||
key_code: KeyCode::$key_code,
|
||||
key: $key,
|
||||
},
|
||||
Action::$action,
|
||||
);
|
||||
|
|
@ -54,52 +61,56 @@ pub fn key_binds() -> HashMap<KeyBind, Action> {
|
|||
}
|
||||
|
||||
// Standard key bindings
|
||||
bind!([Ctrl, Shift], A, SelectAll);
|
||||
bind!([Ctrl, Shift], C, Copy);
|
||||
bind!([Ctrl, Shift], F, Find);
|
||||
bind!([Ctrl, Shift], N, WindowNew);
|
||||
bind!([Ctrl, Shift], Q, WindowClose);
|
||||
bind!([Ctrl, Shift], T, TabNew);
|
||||
bind!([Ctrl, Shift], V, Paste);
|
||||
bind!([Shift], Insert, PastePrimary);
|
||||
bind!([Ctrl, Shift], W, TabClose);
|
||||
bind!([Ctrl, Shift], Key::Character("A".into()), SelectAll);
|
||||
bind!([Ctrl, Shift], Key::Character("C".into()), Copy);
|
||||
bind!([Ctrl, Shift], Key::Character("F".into()), Find);
|
||||
bind!([Ctrl, Shift], Key::Character("N".into()), WindowNew);
|
||||
bind!([Ctrl, Shift], Key::Character("Q".into()), WindowClose);
|
||||
bind!([Ctrl, Shift], Key::Character("T".into()), TabNew);
|
||||
bind!([Ctrl, Shift], Key::Character("V".into()), Paste);
|
||||
bind!([Shift], Key::Named(Named::Insert), PastePrimary);
|
||||
bind!([Ctrl, Shift], Key::Character("W".into()), TabClose);
|
||||
|
||||
// Ctrl+Alt+D splits horizontally, Ctrl+Alt+R splits vertically, Ctrl+Shift+X maximizes split
|
||||
//TODO: Adjust bindings as desired by UX
|
||||
bind!([Ctrl, Alt], D, PaneSplitHorizontal);
|
||||
bind!([Ctrl, Alt], R, PaneSplitVertical);
|
||||
bind!([Ctrl, Shift], X, PaneToggleMaximized);
|
||||
bind!([Ctrl, Alt], Key::Character("d".into()), PaneSplitHorizontal);
|
||||
bind!([Ctrl, Alt], Key::Character("r".into()), PaneSplitVertical);
|
||||
bind!(
|
||||
[Ctrl, Shift],
|
||||
Key::Character("X".into()),
|
||||
PaneToggleMaximized
|
||||
);
|
||||
|
||||
// Ctrl+Tab and Ctrl+Shift+Tab cycle through tabs
|
||||
// Ctrl+Tab is not a special key for terminals and is free to use
|
||||
bind!([Ctrl], Tab, TabNext);
|
||||
bind!([Ctrl, Shift], Tab, TabPrev);
|
||||
bind!([Ctrl], Key::Named(Named::Tab), TabNext);
|
||||
bind!([Ctrl, Shift], Key::Named(Named::Tab), TabPrev);
|
||||
|
||||
// Ctrl+Shift+# activates tabs by index
|
||||
bind!([Ctrl, Shift], Key1, TabActivate0);
|
||||
bind!([Ctrl, Shift], Key2, TabActivate1);
|
||||
bind!([Ctrl, Shift], Key3, TabActivate2);
|
||||
bind!([Ctrl, Shift], Key4, TabActivate3);
|
||||
bind!([Ctrl, Shift], Key5, TabActivate4);
|
||||
bind!([Ctrl, Shift], Key6, TabActivate5);
|
||||
bind!([Ctrl, Shift], Key7, TabActivate6);
|
||||
bind!([Ctrl, Shift], Key8, TabActivate7);
|
||||
bind!([Ctrl, Shift], Key9, TabActivate8);
|
||||
bind!([Ctrl, Shift], Key::Character("!".into()), TabActivate0);
|
||||
bind!([Ctrl, Shift], Key::Character("@".into()), TabActivate1);
|
||||
bind!([Ctrl, Shift], Key::Character("#".into()), TabActivate2);
|
||||
bind!([Ctrl, Shift], Key::Character("$".into()), TabActivate3);
|
||||
bind!([Ctrl, Shift], Key::Character("%".into()), TabActivate4);
|
||||
bind!([Ctrl, Shift], Key::Character("^".into()), TabActivate5);
|
||||
bind!([Ctrl, Shift], Key::Character("&".into()), TabActivate6);
|
||||
bind!([Ctrl, Shift], Key::Character("*".into()), TabActivate7);
|
||||
bind!([Ctrl, Shift], Key::Character("(".into()), TabActivate8);
|
||||
|
||||
// Ctrl+0, Ctrl+-, and Ctrl+= are not special keys for terminals and are free to use
|
||||
bind!([Ctrl], Key0, ZoomReset);
|
||||
bind!([Ctrl], Minus, ZoomOut);
|
||||
bind!([Ctrl], Equals, ZoomIn);
|
||||
bind!([Ctrl], Key::Character("0".into()), ZoomReset);
|
||||
bind!([Ctrl], Key::Character("-".into()), ZoomOut);
|
||||
bind!([Ctrl], Key::Character("=".into()), ZoomIn);
|
||||
|
||||
// Ctrl+Arrows and Ctrl+HJKL move between splits
|
||||
bind!([Ctrl, Shift], Left, PaneFocusLeft);
|
||||
bind!([Ctrl, Shift], H, PaneFocusLeft);
|
||||
bind!([Ctrl, Shift], Down, PaneFocusDown);
|
||||
bind!([Ctrl, Shift], J, PaneFocusDown);
|
||||
bind!([Ctrl, Shift], Up, PaneFocusUp);
|
||||
bind!([Ctrl, Shift], K, PaneFocusUp);
|
||||
bind!([Ctrl, Shift], Right, PaneFocusRight);
|
||||
bind!([Ctrl, Shift], L, PaneFocusRight);
|
||||
bind!([Ctrl, Shift], Key::Named(Named::ArrowLeft), PaneFocusLeft);
|
||||
bind!([Ctrl, Shift], Key::Character("H".into()), PaneFocusLeft);
|
||||
bind!([Ctrl, Shift], Key::Named(Named::ArrowDown), PaneFocusDown);
|
||||
bind!([Ctrl, Shift], Key::Character("J".into()), PaneFocusDown);
|
||||
bind!([Ctrl, Shift], Key::Named(Named::ArrowUp), PaneFocusUp);
|
||||
bind!([Ctrl, Shift], Key::Character("K".into()), PaneFocusUp);
|
||||
bind!([Ctrl, Shift], Key::Named(Named::ArrowRight), PaneFocusRight);
|
||||
bind!([Ctrl, Shift], Key::Character("L".into()), PaneFocusRight);
|
||||
|
||||
key_binds
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue