cosmic-comp/src/wayland/handlers/toplevel_management.rs

63 lines
1.9 KiB
Rust
Raw Normal View History

2022-07-18 21:26:02 +02:00
// SPDX-License-Identifier: GPL-3.0-only
use smithay::{
desktop::{Kind, Window},
2022-08-31 13:01:23 +02:00
input::Seat,
2022-07-18 21:26:02 +02:00
reexports::wayland_server::DisplayHandle,
};
use crate::{
utils::prelude::*,
wayland::protocols::toplevel_management::{
delegate_toplevel_management, ToplevelManagementHandler, ToplevelManagementState,
},
};
impl ToplevelManagementHandler for State {
fn toplevel_management_state(&mut self) -> &mut ToplevelManagementState {
&mut self.common.shell.toplevel_management_state
}
2022-08-31 13:01:23 +02:00
fn activate(&mut self, _dh: &DisplayHandle, window: &Window, seat: Option<Seat<Self>>) {
2022-09-28 12:01:29 +02:00
for output in self
2022-08-30 13:28:36 +02:00
.common
.shell
2022-09-28 12:01:29 +02:00
.outputs()
.cloned()
.collect::<Vec<_>>()
.iter()
2022-08-30 13:28:36 +02:00
{
2022-09-28 12:01:29 +02:00
let maybe = self
.common
.shell
.workspaces
.spaces_for_output(output)
.enumerate()
.find(|(_, w)| w.windows().any(|w| &w == window));
if let Some((idx, workspace)) = maybe {
let seat = seat.unwrap_or(self.common.last_active_seat().clone());
let mapped = workspace
.mapped()
.find(|m| m.windows().any(|(w, _)| &w == window))
.unwrap()
.clone();
std::mem::drop(workspace);
self.common.shell.activate(&output, idx as usize);
mapped.focus_window(window);
Common::set_focus(self, Some(&mapped.clone().into()), &seat, None);
return;
2022-07-18 21:26:02 +02:00
}
}
}
fn close(&mut self, _dh: &DisplayHandle, window: &Window) {
#[allow(irrefutable_let_patterns)]
if let Kind::Xdg(xdg) = &window.toplevel() {
xdg.send_close();
}
}
}
delegate_toplevel_management!(State);