Implement xdg_activation_v1
Browse files at this commitbc3d6cac805bde6a26232dfa75c37b18ca9ec743Parent: a55e3852 changed files +45 -0
- src/handlers/mod.rs +41 -0
- src/niri.rs +4 -0
src/handlers/mod.rsmodified+41 -0
| @@ -48,6 +48,9 @@ use smithay::wayland::session_lock::{ | |||
| 48 | LockSurface, SessionLockHandler, SessionLockManagerState, SessionLocker, | 48 | LockSurface, SessionLockHandler, SessionLockManagerState, SessionLocker, |
| 49 | }; | 49 | }; |
| 50 | use smithay::wayland::tablet_manager::TabletSeatHandler; | 50 | use smithay::wayland::tablet_manager::TabletSeatHandler; |
| 51 | +use smithay::wayland::xdg_activation::{ | ||
| 52 | + XdgActivationHandler, XdgActivationState, XdgActivationToken, XdgActivationTokenData, | ||
| 53 | +}; | ||
| 51 | use smithay::{ | 54 | use smithay::{ |
| 52 | delegate_cursor_shape, delegate_data_control, delegate_data_device, delegate_dmabuf, | 55 | delegate_cursor_shape, delegate_data_control, delegate_data_device, delegate_dmabuf, |
| 53 | delegate_drm_lease, delegate_idle_inhibit, delegate_idle_notify, delegate_input_method_manager, | 56 | delegate_drm_lease, delegate_idle_inhibit, delegate_idle_notify, delegate_input_method_manager, |
| @@ -55,6 +58,7 @@ use smithay::{ | |||
| 55 | delegate_presentation, delegate_primary_selection, delegate_relative_pointer, delegate_seat, | 58 | delegate_presentation, delegate_primary_selection, delegate_relative_pointer, delegate_seat, |
| 56 | delegate_security_context, delegate_session_lock, delegate_tablet_manager, | 59 | delegate_security_context, delegate_session_lock, delegate_tablet_manager, |
| 57 | delegate_text_input_manager, delegate_viewporter, delegate_virtual_keyboard_manager, | 60 | delegate_text_input_manager, delegate_viewporter, delegate_virtual_keyboard_manager, |
| 61 | + delegate_xdg_activation, | ||
| 58 | }; | 62 | }; |
| 59 | 63 | ||
| 60 | use crate::niri::{ClientState, State}; | 64 | use crate::niri::{ClientState, State}; |
| @@ -498,3 +502,40 @@ impl GammaControlHandler for State { | |||
| 498 | } | 502 | } |
| 499 | } | 503 | } |
| 500 | delegate_gamma_control!(State); | 504 | delegate_gamma_control!(State); |
| 505 | + | ||
| 506 | +impl XdgActivationHandler for State { | ||
| 507 | + fn activation_state(&mut self) -> &mut XdgActivationState { | ||
| 508 | + &mut self.niri.activation_state | ||
| 509 | + } | ||
| 510 | + | ||
| 511 | + fn token_created(&mut self, _token: XdgActivationToken, data: XdgActivationTokenData) -> bool { | ||
| 512 | + // Only tokens that were created while the application has keyboard focus are valid. | ||
| 513 | + let Some((serial, seat)) = data.serial else { | ||
| 514 | + return false; | ||
| 515 | + }; | ||
| 516 | + let Some(seat) = Seat::<State>::from_resource(&seat) else { | ||
| 517 | + return false; | ||
| 518 | + }; | ||
| 519 | + | ||
| 520 | + let keyboard = seat.get_keyboard().unwrap(); | ||
| 521 | + return keyboard | ||
| 522 | + .last_enter() | ||
| 523 | + .map(|last_enter| serial.is_no_older_than(&last_enter)) | ||
| 524 | + .unwrap_or(false); | ||
| 525 | + } | ||
| 526 | + | ||
| 527 | + fn request_activation( | ||
| 528 | + &mut self, | ||
| 529 | + _token: XdgActivationToken, | ||
| 530 | + token_data: XdgActivationTokenData, | ||
| 531 | + surface: WlSurface, | ||
| 532 | + ) { | ||
| 533 | + if token_data.timestamp.elapsed().as_secs() < 10 { | ||
| 534 | + if let Some((mapped, _)) = self.niri.layout.find_window_and_output(&surface) { | ||
| 535 | + let window = mapped.window.clone(); | ||
| 536 | + self.niri.layout.activate_window(&window); | ||
| 537 | + } | ||
| 538 | + } | ||
| 539 | + } | ||
| 540 | +} | ||
| 541 | +delegate_xdg_activation!(State); | ||
src/niri.rsmodified+4 -0
| @@ -90,6 +90,7 @@ use smithay::wayland::tablet_manager::TabletManagerState; | |||
| 90 | use smithay::wayland::text_input::TextInputManagerState; | 90 | use smithay::wayland::text_input::TextInputManagerState; |
| 91 | use smithay::wayland::viewporter::ViewporterState; | 91 | use smithay::wayland::viewporter::ViewporterState; |
| 92 | use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState; | 92 | use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState; |
| 93 | +use smithay::wayland::xdg_activation::XdgActivationState; | ||
| 93 | use smithay::wayland::xdg_foreign::XdgForeignState; | 94 | use smithay::wayland::xdg_foreign::XdgForeignState; |
| 94 | 95 | ||
| 95 | use crate::backend::tty::SurfaceDmabufFeedback; | 96 | use crate::backend::tty::SurfaceDmabufFeedback; |
| @@ -217,6 +218,7 @@ pub struct Niri { | |||
| 217 | pub presentation_state: PresentationState, | 218 | pub presentation_state: PresentationState, |
| 218 | pub security_context_state: SecurityContextState, | 219 | pub security_context_state: SecurityContextState, |
| 219 | pub gamma_control_manager_state: GammaControlManagerState, | 220 | pub gamma_control_manager_state: GammaControlManagerState, |
| 221 | + pub activation_state: XdgActivationState, | ||
| 220 | 222 | ||
| 221 | pub seat: Seat<State>, | 223 | pub seat: Seat<State>, |
| 222 | /// Scancodes of the keys to suppress. | 224 | /// Scancodes of the keys to suppress. |
| @@ -1369,6 +1371,7 @@ impl Niri { | |||
| 1369 | GammaControlManagerState::new::<State, _>(&display_handle, move |client| { | 1371 | GammaControlManagerState::new::<State, _>(&display_handle, move |client| { |
| 1370 | is_tty && !client.get_data::<ClientState>().unwrap().restricted | 1372 | is_tty && !client.get_data::<ClientState>().unwrap().restricted |
| 1371 | }); | 1373 | }); |
| 1374 | + let activation_state = XdgActivationState::new::<State>(&display_handle); | ||
| 1372 | 1375 | ||
| 1373 | let mut seat: Seat<State> = seat_state.new_wl_seat(&display_handle, backend.seat_name()); | 1376 | let mut seat: Seat<State> = seat_state.new_wl_seat(&display_handle, backend.seat_name()); |
| 1374 | seat.add_keyboard( | 1377 | seat.add_keyboard( |
| @@ -1527,6 +1530,7 @@ impl Niri { | |||
| 1527 | presentation_state, | 1530 | presentation_state, |
| 1528 | security_context_state, | 1531 | security_context_state, |
| 1529 | gamma_control_manager_state, | 1532 | gamma_control_manager_state, |
| 1533 | + activation_state, | ||
| 1530 | 1534 | ||
| 1531 | seat, | 1535 | seat, |
| 1532 | keyboard_focus: KeyboardFocus::Layout { surface: None }, | 1536 | keyboard_focus: KeyboardFocus::Layout { surface: None }, |