feat: runtime configurable keybindings

This commit is contained in:
Michael Aaron Murphy 2024-04-03 16:02:27 +02:00 committed by Michael Murphy
parent 62afa4cf61
commit 553c49b42b
25 changed files with 674 additions and 829 deletions

View file

@ -1,7 +1,8 @@
use cosmic_settings_config::shortcuts::Action;
use smithay::{input::pointer::MotionEvent, utils::SERIAL_COUNTER, wayland::seat::WaylandFocus};
use crate::{
config::{Action, StaticConfig},
config::Config,
fl,
shell::{
element::{CosmicMapped, CosmicWindow},
@ -93,7 +94,7 @@ pub fn tab_items(
stack: &CosmicMapped,
tab: &CosmicSurface,
is_tiled: bool,
config: &StaticConfig,
config: &Config,
) -> impl Iterator<Item = Item> {
let unstack_clone_stack = stack.clone();
let unstack_clone_tab = tab.clone();
@ -145,7 +146,7 @@ pub fn tab_items(
Item::new(fl!("window-menu-close"), move |_handle| {
close_clone.close();
})
.shortcut(config.get_shortcut_for_action(&Action::Close)),
.shortcut(config.shortcut_for_action(&Action::Close)),
]
.into_iter()
}
@ -157,7 +158,7 @@ pub fn window_items(
is_sticky: bool,
tiling_enabled: bool,
possible_resizes: ResizeEdge,
config: &StaticConfig,
config: &Config,
) -> impl Iterator<Item = Item> {
let minimize_clone = window.clone();
let maximize_clone = window.clone();
@ -181,7 +182,7 @@ pub fn window_items(
let mapped = stack_clone.clone();
let _ = handle.insert_idle(move |state| toggle_stacking(state, &mapped));
})
.shortcut(config.get_shortcut_for_action(&Action::ToggleStacking)),
.shortcut(config.shortcut_for_action(&Action::ToggleStacking)),
),
is_stacked.then_some(
Item::new(fl!("window-menu-unstack-all"), move |handle| {
@ -190,7 +191,7 @@ pub fn window_items(
toggle_stacking(state, &mapped);
});
})
.shortcut(config.get_shortcut_for_action(&Action::ToggleStacking)),
.shortcut(config.shortcut_for_action(&Action::ToggleStacking)),
),
Some(Item::Separator),
Some(
@ -205,7 +206,7 @@ pub fn window_items(
.minimize_request(&mapped);
});
})
.shortcut(config.get_shortcut_for_action(&Action::Minimize)),
.shortcut(config.shortcut_for_action(&Action::Minimize)),
),
Some(
Item::new(fl!("window-menu-maximize"), move |handle| {
@ -216,7 +217,7 @@ pub fn window_items(
shell.maximize_toggle(&mapped, &seat);
});
})
.shortcut(config.get_shortcut_for_action(&Action::Maximize))
.shortcut(config.shortcut_for_action(&Action::Maximize))
.toggled(window.is_maximized(false)),
),
(tiling_enabled && !is_sticky).then_some(
@ -230,7 +231,7 @@ pub fn window_items(
}
});
})
.shortcut(config.get_shortcut_for_action(&Action::ToggleWindowFloating))
.shortcut(config.shortcut_for_action(&Action::ToggleWindowFloating))
.toggled(!is_tiled),
),
Some(Item::Separator),
@ -410,7 +411,7 @@ pub fn window_items(
let mapped = move_prev_clone.clone();
let _ = handle.insert_idle(move |state| move_prev_workspace(state, &mapped));
})
.shortcut(config.get_shortcut_for_action(&Action::MoveToPreviousWorkspace))
.shortcut(config.shortcut_for_action(&Action::MoveToPreviousWorkspace))
.disabled(is_sticky),
),
Some(
@ -418,7 +419,7 @@ pub fn window_items(
let mapped = move_next_clone.clone();
let _ = handle.insert_idle(move |state| move_next_workspace(state, &mapped));
})
.shortcut(config.get_shortcut_for_action(&Action::MoveToNextWorkspace))
.shortcut(config.shortcut_for_action(&Action::MoveToNextWorkspace))
.disabled(is_sticky),
),
Some(Item::Separator),
@ -445,7 +446,7 @@ pub fn window_items(
Item::new(fl!("window-menu-close"), move |_handle| {
close_clone.send_close();
})
.shortcut(config.get_shortcut_for_action(&Action::Close)),
.shortcut(config.shortcut_for_action(&Action::Close)),
)
},
]

View file

@ -1,3 +1,4 @@
use cosmic_settings_config::shortcuts;
use smithay::{
input::{
pointer::{
@ -106,6 +107,36 @@ impl ResizeEdge {
}
}
impl From<shortcuts::action::ResizeEdge> for ResizeEdge {
fn from(edge: shortcuts::action::ResizeEdge) -> Self {
match edge {
shortcuts::action::ResizeEdge::Bottom => ResizeEdge::BOTTOM,
shortcuts::action::ResizeEdge::BottomLeft => ResizeEdge::BOTTOM_LEFT,
shortcuts::action::ResizeEdge::BottomRight => ResizeEdge::BOTTOM_RIGHT,
shortcuts::action::ResizeEdge::Left => ResizeEdge::LEFT,
shortcuts::action::ResizeEdge::Right => ResizeEdge::RIGHT,
shortcuts::action::ResizeEdge::Top => ResizeEdge::TOP,
shortcuts::action::ResizeEdge::TopLeft => ResizeEdge::TOP_LEFT,
shortcuts::action::ResizeEdge::TopRight => ResizeEdge::TOP_RIGHT,
}
}
}
impl Into<shortcuts::action::ResizeEdge> for ResizeEdge {
fn into(self) -> shortcuts::action::ResizeEdge {
match self {
ResizeEdge::BOTTOM => shortcuts::action::ResizeEdge::Bottom,
ResizeEdge::BOTTOM_LEFT => shortcuts::action::ResizeEdge::BottomLeft,
ResizeEdge::BOTTOM_RIGHT => shortcuts::action::ResizeEdge::BottomRight,
ResizeEdge::LEFT => shortcuts::action::ResizeEdge::Left,
ResizeEdge::RIGHT => shortcuts::action::ResizeEdge::Right,
ResizeEdge::TOP => shortcuts::action::ResizeEdge::Top,
ResizeEdge::TOP_LEFT => shortcuts::action::ResizeEdge::TopLeft,
_ => shortcuts::action::ResizeEdge::TopRight,
}
}
}
impl From<xdg_toplevel::ResizeEdge> for ResizeEdge {
#[inline]
fn from(x: xdg_toplevel::ResizeEdge) -> Self {

View file

@ -863,7 +863,8 @@ impl Drop for MoveGrab {
state,
Some((
target,
position.as_logical().to_f64() - window.geometry().loc.to_f64() + offset,
position.as_logical().to_f64() - window.geometry().loc.to_f64()
+ offset,
)),
&MotionEvent {
location: pointer.current_location(),