Implement keyboard shortcut inhibit protocol
TODO: restrict what apps can call this in some way.
This commit is contained in:
parent
7b670afc36
commit
0f726cf16b
4 changed files with 60 additions and 11 deletions
|
|
@ -20,7 +20,10 @@ use smithay::{
|
|||
output::Output,
|
||||
reexports::wayland_server::{protocol::wl_surface::WlSurface, DisplayHandle},
|
||||
utils::{Buffer, Logical, Point, Rectangle, Size, SERIAL_COUNTER},
|
||||
wayland::shell::wlr_layer::Layer as WlrLayer,
|
||||
wayland::{
|
||||
keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitorSeat,
|
||||
shell::wlr_layer::Layer as WlrLayer,
|
||||
},
|
||||
};
|
||||
|
||||
use std::{cell::RefCell, collections::HashMap};
|
||||
|
|
@ -173,6 +176,19 @@ impl State {
|
|||
|
||||
let device = event.device();
|
||||
for seat in self.common.seats.clone().iter() {
|
||||
let current_output = active_output(seat, &self.common);
|
||||
let workspace = self.common.shell.active_space_mut(¤t_output);
|
||||
let shortcuts_inhibited = workspace
|
||||
.focus_stack(seat)
|
||||
.last()
|
||||
.and_then(|window| {
|
||||
seat.keyboard_shortcuts_inhibitor_for_surface(
|
||||
&window.toplevel().wl_surface(),
|
||||
)
|
||||
})
|
||||
.map(|inhibitor| inhibitor.is_active())
|
||||
.unwrap_or(false);
|
||||
|
||||
let userdata = seat.user_data();
|
||||
let devices = userdata.get::<Devices>().unwrap();
|
||||
if devices.has_device(&device) {
|
||||
|
|
@ -249,15 +265,22 @@ impl State {
|
|||
}
|
||||
|
||||
// here we can handle global shortcuts and the like
|
||||
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)
|
||||
if !shortcuts_inhibited {
|
||||
for (binding, action) in
|
||||
data.common.config.static_conf.key_bindings.iter()
|
||||
{
|
||||
userdata.get::<SupressedKeys>().unwrap().add(&handle);
|
||||
return FilterResult::Intercept(Some(action.clone()));
|
||||
if state == KeyState::Pressed
|
||||
&& binding.modifiers == *modifiers
|
||||
&& handle.raw_syms().contains(&binding.key)
|
||||
{
|
||||
userdata
|
||||
.get::<SupressedKeys>()
|
||||
.unwrap()
|
||||
.add(&handle);
|
||||
return FilterResult::Intercept(Some(
|
||||
action.clone(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ use smithay::{
|
|||
utils::{Buffer, Size},
|
||||
wayland::{
|
||||
compositor::CompositorState, data_device::DataDeviceState, dmabuf::DmabufState,
|
||||
output::OutputManagerState, primary_selection::PrimarySelectionState, shm::ShmState,
|
||||
viewporter::ViewporterState,
|
||||
keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitState, output::OutputManagerState,
|
||||
primary_selection::PrimarySelectionState, shm::ShmState, viewporter::ViewporterState,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -86,6 +86,7 @@ pub struct Common {
|
|||
pub data_device_state: DataDeviceState,
|
||||
pub dmabuf_state: DmabufState,
|
||||
pub export_dmabuf_state: ExportDmabufState,
|
||||
pub keyboard_shortcuts_inhibit_state: KeyboardShortcutsInhibitState,
|
||||
pub output_state: OutputManagerState,
|
||||
pub output_configuration_state: OutputConfigurationState<State>,
|
||||
pub primary_selection_state: PrimarySelectionState,
|
||||
|
|
@ -301,6 +302,7 @@ impl State {
|
|||
//|client| client.get_data::<ClientState>().unwrap().privileged,
|
||||
|_| true,
|
||||
);
|
||||
let keyboard_shortcuts_inhibit_state = KeyboardShortcutsInhibitState::new::<Self>(dh);
|
||||
let output_state = OutputManagerState::new_with_xdg_output::<Self>(dh);
|
||||
let output_configuration_state = OutputConfigurationState::new(dh, |_| true);
|
||||
let primary_selection_state = PrimarySelectionState::new::<Self, _>(dh, None);
|
||||
|
|
@ -355,6 +357,7 @@ impl State {
|
|||
export_dmabuf_state,
|
||||
shm_state,
|
||||
seat_state,
|
||||
keyboard_shortcuts_inhibit_state,
|
||||
output_state,
|
||||
output_configuration_state,
|
||||
primary_selection_state,
|
||||
|
|
|
|||
22
src/wayland/handlers/keyboard_shortcuts_inhibit.rs
Normal file
22
src/wayland/handlers/keyboard_shortcuts_inhibit.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::state::State;
|
||||
use smithay::{
|
||||
delegate_keyboard_shortcuts_inhibit,
|
||||
wayland::keyboard_shortcuts_inhibit::{
|
||||
KeyboardShortcutsInhibitHandler, KeyboardShortcutsInhibitState, KeyboardShortcutsInhibitor,
|
||||
},
|
||||
};
|
||||
|
||||
impl KeyboardShortcutsInhibitHandler for State {
|
||||
fn keyboard_shortcuts_inhibit_state(&mut self) -> &mut KeyboardShortcutsInhibitState {
|
||||
&mut self.common.keyboard_shortcuts_inhibit_state
|
||||
}
|
||||
|
||||
fn new_inhibitor(&mut self, inhibitor: KeyboardShortcutsInhibitor) {
|
||||
// TODO: Restrict what apps can inhibit shortcuts
|
||||
inhibitor.activate();
|
||||
}
|
||||
}
|
||||
|
||||
delegate_keyboard_shortcuts_inhibit!(State);
|
||||
|
|
@ -5,6 +5,7 @@ pub mod compositor;
|
|||
pub mod data_device;
|
||||
pub mod dmabuf;
|
||||
pub mod export_dmabuf;
|
||||
pub mod keyboard_shortcuts_inhibit;
|
||||
pub mod layer_shell;
|
||||
pub mod output;
|
||||
pub mod output_configuration;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue