Send ALL keyboard shortcuts

Using keyboard-shortcut-inhibit-unstable-v1.xml we can inhibit shortcuts
for the server and send those to the client as well.
This commit is contained in:
Ferdinand Schober
2022-09-20 08:24:44 +02:00
parent 2d72259d8e
commit 76261ad24a
2 changed files with 50 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
port = 42069
[client.left] [client.left]
host_name = "rubinium" host_name = "rubinium"
ip = "192.168.2.182" ip = "192.168.2.182"

View File

@@ -10,6 +10,10 @@ use std::{
use wayland_protocols::wp::{ use wayland_protocols::wp::{
pointer_constraints::zv1::client::{zwp_locked_pointer_v1, zwp_pointer_constraints_v1}, pointer_constraints::zv1::client::{zwp_locked_pointer_v1, zwp_pointer_constraints_v1},
relative_pointer::zv1::client::{zwp_relative_pointer_manager_v1, zwp_relative_pointer_v1}, relative_pointer::zv1::client::{zwp_relative_pointer_manager_v1, zwp_relative_pointer_v1},
keyboard_shortcuts_inhibit::zv1::client::{
zwp_keyboard_shortcuts_inhibit_manager_v1,
zwp_keyboard_shortcuts_inhibitor_v1,
},
}; };
use wayland_protocols_wlr::layer_shell::v1::client::{ use wayland_protocols_wlr::layer_shell::v1::client::{
@@ -38,7 +42,10 @@ struct App {
rel_pointer_manager: Option<zwp_relative_pointer_manager_v1::ZwpRelativePointerManagerV1>, rel_pointer_manager: Option<zwp_relative_pointer_manager_v1::ZwpRelativePointerManagerV1>,
pointer_lock: Option<zwp_locked_pointer_v1::ZwpLockedPointerV1>, pointer_lock: Option<zwp_locked_pointer_v1::ZwpLockedPointerV1>,
rel_pointer: Option<zwp_relative_pointer_v1::ZwpRelativePointerV1>, rel_pointer: Option<zwp_relative_pointer_v1::ZwpRelativePointerV1>,
shortcut_inhibit_manager: Option<zwp_keyboard_shortcuts_inhibit_manager_v1::ZwpKeyboardShortcutsInhibitManagerV1>,
shortcut_inhibitor: Option<zwp_keyboard_shortcuts_inhibitor_v1::ZwpKeyboardShortcutsInhibitorV1>,
connection: protocol::Connection, connection: protocol::Connection,
seat: Option<wl_seat::WlSeat>,
} }
fn main() { fn main() {
@@ -69,6 +76,9 @@ fn main() {
pointer_lock: None, pointer_lock: None,
rel_pointer: None, rel_pointer: None,
connection, connection,
shortcut_inhibit_manager: None,
shortcut_inhibitor: None,
seat: None,
}; };
// use roundtrip to process this event synchronously // use roundtrip to process this event synchronously
@@ -146,7 +156,7 @@ impl Dispatch<wl_registry::WlRegistry, ()> for App {
app.buffer = Some(buffer); app.buffer = Some(buffer);
} }
"wl_seat" => { "wl_seat" => {
registry.bind::<wl_seat::WlSeat, _, _>(name, 8, qh, ()); app.seat = Some(registry.bind::<wl_seat::WlSeat, _, _>(name, 8, qh, ()));
} }
"zwp_pointer_constraints_v1" => { "zwp_pointer_constraints_v1" => {
app.pointer_constraints = Some( app.pointer_constraints = Some(
@@ -174,6 +184,11 @@ impl Dispatch<wl_registry::WlRegistry, ()> for App {
4, &qh, (), 4, &qh, (),
)); ));
} }
"zwp_keyboard_shortcuts_inhibit_manager_v1" => {
app.shortcut_inhibit_manager = Some(registry.bind::<zwp_keyboard_shortcuts_inhibit_manager_v1::ZwpKeyboardShortcutsInhibitManagerV1, _, _>(
name, 1, &qh, (),
));
}
_ => {} _ => {}
} }
} }
@@ -307,6 +322,13 @@ impl Dispatch<wl_pointer::WlPointer, ()> for App {
.get_relative_pointer(pointer, qh, ()), .get_relative_pointer(pointer, qh, ()),
); );
} }
if app.shortcut_inhibitor.is_none() {
app.shortcut_inhibitor = Some(app.shortcut_inhibit_manager.as_ref().unwrap().inhibit_shortcuts(
app.surface.as_ref().unwrap(),
app.seat.as_ref().unwrap(),
qh, (),
));
}
} }
wl_pointer::Event::Leave {..} => { wl_pointer::Event::Leave {..} => {
if let Some(s) = app.layer_surface.as_ref() { if let Some(s) = app.layer_surface.as_ref() {
@@ -349,6 +371,10 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for App {
rel_pointer.destroy(); rel_pointer.destroy();
app.rel_pointer = None; app.rel_pointer = None;
} }
if let Some(shortcut_inhibitor) = app.shortcut_inhibitor.as_ref() {
shortcut_inhibitor.destroy();
app.shortcut_inhibitor = None;
}
} else { } else {
app.connection.send_event(event); app.connection.send_event(event);
} }
@@ -465,3 +491,25 @@ impl Dispatch<wl_region::WlRegion, ()> for App {
_: &QueueHandle<Self>, _: &QueueHandle<Self>,
) { } ) { }
} }
impl Dispatch<zwp_keyboard_shortcuts_inhibit_manager_v1::ZwpKeyboardShortcutsInhibitManagerV1, ()> for App {
fn event(
_: &mut Self,
_: &zwp_keyboard_shortcuts_inhibit_manager_v1::ZwpKeyboardShortcutsInhibitManagerV1,
_: <zwp_keyboard_shortcuts_inhibit_manager_v1::ZwpKeyboardShortcutsInhibitManagerV1 as wayland_client::Proxy>::Event,
_: &(),
_: &Connection,
_: &QueueHandle<Self>,
) { }
}
impl Dispatch<zwp_keyboard_shortcuts_inhibitor_v1::ZwpKeyboardShortcutsInhibitorV1, ()> for App {
fn event(
_: &mut Self,
_: &zwp_keyboard_shortcuts_inhibitor_v1::ZwpKeyboardShortcutsInhibitorV1,
_: <zwp_keyboard_shortcuts_inhibitor_v1::ZwpKeyboardShortcutsInhibitorV1 as wayland_client::Proxy>::Event,
_: &(),
_: &Connection,
_: &QueueHandle<Self>,
) { }
}