Skip to content

Commit

Permalink
Implement xdg_activation_v1
Browse files Browse the repository at this point in the history
Fixes #30.
  • Loading branch information
pcc authored and YaLTeR committed Jun 10, 2024
1 parent a55e385 commit bc3d6ca
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ use smithay::wayland::session_lock::{
LockSurface, SessionLockHandler, SessionLockManagerState, SessionLocker,
};
use smithay::wayland::tablet_manager::TabletSeatHandler;
use smithay::wayland::xdg_activation::{
XdgActivationHandler, XdgActivationState, XdgActivationToken, XdgActivationTokenData,
};
use smithay::{
delegate_cursor_shape, delegate_data_control, delegate_data_device, delegate_dmabuf,
delegate_drm_lease, delegate_idle_inhibit, delegate_idle_notify, delegate_input_method_manager,
delegate_output, delegate_pointer_constraints, delegate_pointer_gestures,
delegate_presentation, delegate_primary_selection, delegate_relative_pointer, delegate_seat,
delegate_security_context, delegate_session_lock, delegate_tablet_manager,
delegate_text_input_manager, delegate_viewporter, delegate_virtual_keyboard_manager,
delegate_xdg_activation,
};

use crate::niri::{ClientState, State};
Expand Down Expand Up @@ -498,3 +502,40 @@ impl GammaControlHandler for State {
}
}
delegate_gamma_control!(State);

impl XdgActivationHandler for State {
fn activation_state(&mut self) -> &mut XdgActivationState {
&mut self.niri.activation_state
}

fn token_created(&mut self, _token: XdgActivationToken, data: XdgActivationTokenData) -> bool {
// Only tokens that were created while the application has keyboard focus are valid.
let Some((serial, seat)) = data.serial else {
return false;
};
let Some(seat) = Seat::<State>::from_resource(&seat) else {
return false;
};

let keyboard = seat.get_keyboard().unwrap();
return keyboard
.last_enter()
.map(|last_enter| serial.is_no_older_than(&last_enter))
.unwrap_or(false);
}

fn request_activation(
&mut self,
_token: XdgActivationToken,
token_data: XdgActivationTokenData,
surface: WlSurface,
) {
if token_data.timestamp.elapsed().as_secs() < 10 {
if let Some((mapped, _)) = self.niri.layout.find_window_and_output(&surface) {
let window = mapped.window.clone();
self.niri.layout.activate_window(&window);
}
}
}
}
delegate_xdg_activation!(State);
4 changes: 4 additions & 0 deletions src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ use smithay::wayland::tablet_manager::TabletManagerState;
use smithay::wayland::text_input::TextInputManagerState;
use smithay::wayland::viewporter::ViewporterState;
use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState;
use smithay::wayland::xdg_activation::XdgActivationState;
use smithay::wayland::xdg_foreign::XdgForeignState;

use crate::backend::tty::SurfaceDmabufFeedback;
Expand Down Expand Up @@ -217,6 +218,7 @@ pub struct Niri {
pub presentation_state: PresentationState,
pub security_context_state: SecurityContextState,
pub gamma_control_manager_state: GammaControlManagerState,
pub activation_state: XdgActivationState,

pub seat: Seat<State>,
/// Scancodes of the keys to suppress.
Expand Down Expand Up @@ -1369,6 +1371,7 @@ impl Niri {
GammaControlManagerState::new::<State, _>(&display_handle, move |client| {
is_tty && !client.get_data::<ClientState>().unwrap().restricted
});
let activation_state = XdgActivationState::new::<State>(&display_handle);

let mut seat: Seat<State> = seat_state.new_wl_seat(&display_handle, backend.seat_name());
seat.add_keyboard(
Expand Down Expand Up @@ -1527,6 +1530,7 @@ impl Niri {
presentation_state,
security_context_state,
gamma_control_manager_state,
activation_state,

seat,
keyboard_focus: KeyboardFocus::Layout { surface: None },
Expand Down

0 comments on commit bc3d6ca

Please sign in to comment.