Add config for loading keybindings

This commit is contained in:
Victoria Brekenfeld 2022-03-28 23:45:30 +02:00
parent 4796832521
commit aab52b502c
7 changed files with 367 additions and 63 deletions

View file

@ -1,9 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-only
use crate::state::Common;
use smithay::{backend::input::KeyState, wayland::seat::keysyms};
use crate::{config::Action, state::Common};
use smithay::{
backend::input::{Device, DeviceCapability, InputBackend, InputEvent},
backend::input::{Device, DeviceCapability, InputBackend, InputEvent, KeyState},
desktop::{layer_map_for_output, Space, WindowSurfaceType},
reexports::wayland_server::{protocol::wl_surface::WlSurface, Display},
utils::{Logical, Point},
@ -213,66 +212,8 @@ impl Common {
return FilterResult::Intercept(());
}
// here we can handle global shortcuts and the like
if modifiers.logo
&& handle.raw_syms().contains(&keysyms::KEY_Return)
&& state == KeyState::Pressed
{
if let Err(err) = std::process::Command::new("gnome-terminal")
.env("WAYLAND_DISPLAY", &self.socket)
.spawn()
{
slog_scope::warn!("Failed to spawn terminal: {}", err);
}
userdata.get::<SupressedKeys>().unwrap().add(&handle);
return FilterResult::Intercept(());
}
if modifiers.logo
&& handle
.raw_syms()
.iter()
.any(|sym| *sym >= keysyms::KEY_0 && *sym <= keysyms::KEY_9)
&& state == KeyState::Pressed
{
let current_output = active_output(seat, &self);
let key_num = handle
.raw_syms()
.iter()
.find(|sym| {
**sym >= keysyms::KEY_0 && **sym <= keysyms::KEY_9
})
.unwrap()
- keysyms::KEY_0;
let workspace = match key_num {
0 => 9,
x => x - 1,
};
self.shell.activate(&current_output, workspace as usize);
userdata.get::<SupressedKeys>().unwrap().add(&handle);
return FilterResult::Intercept(());
}
if modifiers.logo
&& modifiers.shift
&& handle.raw_syms().contains(&keysyms::KEY_Escape)
&& state == KeyState::Pressed
{
self.should_stop = true;
}
#[cfg(feature = "debug")]
{
self.egui.modifiers = modifiers.clone();
if self.seats.iter().position(|x| x == seat).unwrap() == 0
&& modifiers.logo
&& handle.raw_syms().contains(&keysyms::KEY_Escape)
&& state == KeyState::Pressed
{
self.egui.active = !self.egui.active;
userdata.get::<SupressedKeys>().unwrap().add(&handle);
return FilterResult::Intercept(());
}
if self.seats.iter().position(|x| x == seat).unwrap() == 0
&& self.egui.active
{
@ -295,6 +236,73 @@ impl Common {
}
}
// here we can handle global shortcuts and the like
for (binding, action) in self.config.key_bindings.iter() {
if state == KeyState::Pressed
&& binding.modifiers == *modifiers
&& handle.raw_syms().contains(&binding.key)
{
match action {
Action::Terminate => {
userdata
.get::<SupressedKeys>()
.unwrap()
.add(&handle);
self.should_stop = true;
return FilterResult::Intercept(());
}
#[cfg(feature = "debug")]
Action::Debug => {
self.egui.active = !self.egui.active;
userdata
.get::<SupressedKeys>()
.unwrap()
.add(&handle);
return FilterResult::Intercept(());
}
#[cfg(not(feature = "debug"))]
Action::Debug => slog_scope::info!(
"Debug overlay not included in this version"
),
Action::Close => { /* TODO */ }
Action::Workspace(key_num) => {
let current_output = active_output(seat, &self);
let workspace = match key_num {
0 => 9,
x => x - 1,
};
self.shell
.activate(&current_output, workspace as usize);
userdata
.get::<SupressedKeys>()
.unwrap()
.add(&handle);
return FilterResult::Intercept(());
}
Action::MoveToWorkspace(num) => { /* TODO */ }
Action::Focus(focus) => match focus {
_ => { /* TODO */ }
},
Action::Spawn(command) => {
if let Err(err) =
std::process::Command::new("/bin/sh")
.arg("-c")
.arg(command)
.env("WAYLAND_DISPLAY", &self.socket)
.spawn()
{
slog_scope::warn!("Failed to spawn: {}", err);
}
userdata
.get::<SupressedKeys>()
.unwrap()
.add(&handle);
return FilterResult::Intercept(());
}
}
}
}
FilterResult::Forward
},
);