|
| 1 | +use wayland_client::{ |
| 2 | + globals::GlobalList, |
| 3 | + protocol::{wl_seat, wl_surface}, |
| 4 | + Connection, Dispatch, QueueHandle, |
| 5 | +}; |
| 6 | +use wayland_protocols::wp::keyboard_shortcuts_inhibit::zv1::client::{ |
| 7 | + zwp_keyboard_shortcuts_inhibit_manager_v1, zwp_keyboard_shortcuts_inhibitor_v1, |
| 8 | +}; |
| 9 | + |
| 10 | +use crate::{error::GlobalError, globals::GlobalData, registry::GlobalProxy}; |
| 11 | + |
| 12 | +#[derive(Debug)] |
| 13 | +pub struct ShortcutsInhibitState { |
| 14 | + shortcuts_inhibit_manager: GlobalProxy< |
| 15 | + zwp_keyboard_shortcuts_inhibit_manager_v1::ZwpKeyboardShortcutsInhibitManagerV1, |
| 16 | + >, |
| 17 | +} |
| 18 | + |
| 19 | +impl ShortcutsInhibitState { |
| 20 | + /// Bind `zwp_keyboard_shortcuts_inhibit_manager_v1` global, if it exists |
| 21 | + pub fn bind<D>(globals: &GlobalList, qh: &QueueHandle<D>) -> Self |
| 22 | + where |
| 23 | + D: Dispatch< |
| 24 | + zwp_keyboard_shortcuts_inhibit_manager_v1::ZwpKeyboardShortcutsInhibitManagerV1, |
| 25 | + GlobalData, |
| 26 | + > + 'static, |
| 27 | + { |
| 28 | + let shortcuts_inhibit_manager = GlobalProxy::from(globals.bind(qh, 1..=1, GlobalData)); |
| 29 | + Self { shortcuts_inhibit_manager } |
| 30 | + } |
| 31 | + |
| 32 | + /// Request that keyboard shortcuts are inhibited for surface on given seat. |
| 33 | + /// |
| 34 | + /// Raises protocol error if a shortcut inhibitor already exists for the seat and surface. |
| 35 | + pub fn inhibit_shortcuts<D>( |
| 36 | + &self, |
| 37 | + surface: &wl_surface::WlSurface, |
| 38 | + seat: &wl_seat::WlSeat, |
| 39 | + qh: &QueueHandle<D>, |
| 40 | + ) -> Result<zwp_keyboard_shortcuts_inhibitor_v1::ZwpKeyboardShortcutsInhibitorV1, GlobalError> |
| 41 | + where |
| 42 | + D: Dispatch< |
| 43 | + zwp_keyboard_shortcuts_inhibitor_v1::ZwpKeyboardShortcutsInhibitorV1, |
| 44 | + GlobalData, |
| 45 | + > + 'static, |
| 46 | + { |
| 47 | + Ok(self.shortcuts_inhibit_manager.get()?.inhibit_shortcuts(surface, seat, qh, GlobalData)) |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +pub trait ShortcutsInhibitHandler: Sized { |
| 52 | + fn active( |
| 53 | + &mut self, |
| 54 | + conn: &Connection, |
| 55 | + qh: &QueueHandle<Self>, |
| 56 | + shortcuts_inhibitor: &zwp_keyboard_shortcuts_inhibitor_v1::ZwpKeyboardShortcutsInhibitorV1, |
| 57 | + ); |
| 58 | + |
| 59 | + fn inactive( |
| 60 | + &mut self, |
| 61 | + conn: &Connection, |
| 62 | + qh: &QueueHandle<Self>, |
| 63 | + shortcuts_inhibitor: &zwp_keyboard_shortcuts_inhibitor_v1::ZwpKeyboardShortcutsInhibitorV1, |
| 64 | + ); |
| 65 | +} |
| 66 | + |
| 67 | +impl<D> |
| 68 | + Dispatch< |
| 69 | + zwp_keyboard_shortcuts_inhibit_manager_v1::ZwpKeyboardShortcutsInhibitManagerV1, |
| 70 | + GlobalData, |
| 71 | + D, |
| 72 | + > for ShortcutsInhibitState |
| 73 | +where |
| 74 | + D: Dispatch< |
| 75 | + zwp_keyboard_shortcuts_inhibit_manager_v1::ZwpKeyboardShortcutsInhibitManagerV1, |
| 76 | + GlobalData, |
| 77 | + >, |
| 78 | +{ |
| 79 | + fn event( |
| 80 | + _data: &mut D, |
| 81 | + _manager: &zwp_keyboard_shortcuts_inhibit_manager_v1::ZwpKeyboardShortcutsInhibitManagerV1, |
| 82 | + _event: zwp_keyboard_shortcuts_inhibit_manager_v1::Event, |
| 83 | + _: &GlobalData, |
| 84 | + _conn: &Connection, |
| 85 | + _qh: &QueueHandle<D>, |
| 86 | + ) { |
| 87 | + unreachable!() |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +impl<D> |
| 92 | + Dispatch<zwp_keyboard_shortcuts_inhibitor_v1::ZwpKeyboardShortcutsInhibitorV1, GlobalData, D> |
| 93 | + for ShortcutsInhibitState |
| 94 | +where |
| 95 | + D: Dispatch<zwp_keyboard_shortcuts_inhibitor_v1::ZwpKeyboardShortcutsInhibitorV1, GlobalData> |
| 96 | + + ShortcutsInhibitHandler, |
| 97 | +{ |
| 98 | + fn event( |
| 99 | + data: &mut D, |
| 100 | + inhibitor: &zwp_keyboard_shortcuts_inhibitor_v1::ZwpKeyboardShortcutsInhibitorV1, |
| 101 | + event: zwp_keyboard_shortcuts_inhibitor_v1::Event, |
| 102 | + _: &GlobalData, |
| 103 | + conn: &Connection, |
| 104 | + qh: &QueueHandle<D>, |
| 105 | + ) { |
| 106 | + match event { |
| 107 | + zwp_keyboard_shortcuts_inhibitor_v1::Event::Active => data.active(conn, qh, inhibitor), |
| 108 | + zwp_keyboard_shortcuts_inhibitor_v1::Event::Inactive => { |
| 109 | + data.inactive(conn, qh, inhibitor) |
| 110 | + } |
| 111 | + _ => unreachable!(), |
| 112 | + } |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +#[macro_export] |
| 117 | +macro_rules! delegate_shortcuts_inhibit { |
| 118 | + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { |
| 119 | + $crate::reexports::client::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ |
| 120 | + $crate::reexports::protocols::wp::keyboard_shortcuts_inhibit::zv1::client::zwp_keyboard_shortcuts_inhibit_manager_v1::ZwpKeyboardShortcutsInhibitManagerV1: $crate::globals::GlobalData |
| 121 | + ] => $crate::seat::shortcuts_inhibit::ShortcutsInhibitState); |
| 122 | + $crate::reexports::client::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ |
| 123 | + $crate::reexports::protocols::wp::keyboard_shortcuts_inhibit::zv1::client::zwp_keyboard_shortcuts_inhibitor_v1::ZwpKeyboardShortcutsInhibitorV1: $crate::globals::GlobalData |
| 124 | + ] => $crate::seat::shortcuts_inhibit::ShortcutsInhibitState); |
| 125 | + }; |
| 126 | +} |
0 commit comments