From 36239479392dc47403583720180773aadb38aa12 Mon Sep 17 00:00:00 2001 From: Poly Date: Sun, 27 Jun 2021 03:47:04 +0200 Subject: [PATCH] [Anvil] XDG activate support --- anvil/src/window_map.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/anvil/src/window_map.rs b/anvil/src/window_map.rs index c4a72c5..06e8095 100644 --- a/anvil/src/window_map.rs +++ b/anvil/src/window_map.rs @@ -1,7 +1,7 @@ use std::cell::RefCell; use smithay::{ - reexports::wayland_server::protocol::wl_surface, + reexports::{wayland_protocols::xdg_shell::server::xdg_toplevel, wayland_server::protocol::wl_surface}, utils::Rectangle, wayland::{ compositor::{with_states, with_surface_tree_downward, SubsurfaceCachedState, TraversalAction}, @@ -52,6 +52,25 @@ impl Kind { _ => false, } } + + /// Activate/Deactivate this window + pub fn set_activated(&self, active: bool) { + match *self { + Kind::Xdg(ref t) => { + let changed = t.with_pending_state(|state| { + if active { + state.states.set(xdg_toplevel::State::Activated) + } else { + state.states.unset(xdg_toplevel::State::Activated) + } + }); + if let Ok(true) = changed { + t.send_configure(); + } + } + _ => {} + }; + } } #[derive(Clone)] @@ -252,6 +271,15 @@ impl WindowMap { } if let Some((i, surface)) = found { let winner = self.windows.remove(i); + + // Take activation away from all the windows + for window in self.windows.iter() { + window.toplevel.set_activated(false); + } + + // Give activation to our winner + winner.toplevel.set_activated(true); + self.windows.insert(0, winner); Some(surface) } else {