2019-04-10 13:22:06 +00:00
|
|
|
use std::cell::RefCell;
|
2021-06-29 15:30:48 +00:00
|
|
|
use std::sync::Mutex;
|
2019-04-10 13:22:06 +00:00
|
|
|
|
2018-10-02 21:37:24 +00:00
|
|
|
use smithay::{
|
2021-07-31 18:21:07 +00:00
|
|
|
reexports::{
|
|
|
|
wayland_protocols::xdg_shell::server::xdg_toplevel,
|
|
|
|
wayland_server::protocol::wl_surface::{self, WlSurface},
|
|
|
|
},
|
2021-07-05 17:21:15 +00:00
|
|
|
utils::{Logical, Point, Rectangle},
|
2018-10-02 21:37:24 +00:00
|
|
|
wayland::{
|
2021-06-23 07:43:53 +00:00
|
|
|
compositor::{with_states, with_surface_tree_downward, SubsurfaceCachedState, TraversalAction},
|
2018-10-02 21:37:24 +00:00
|
|
|
shell::{
|
2021-06-23 07:43:53 +00:00
|
|
|
legacy::ShellSurface,
|
2021-07-30 16:15:15 +00:00
|
|
|
wlr_layer::Layer,
|
2021-06-29 15:30:48 +00:00
|
|
|
xdg::{PopupSurface, SurfaceCachedState, ToplevelSurface, XdgPopupSurfaceRoleAttributes},
|
2018-10-02 21:37:24 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2017-09-22 12:56:59 +00:00
|
|
|
|
2020-02-03 12:55:48 +00:00
|
|
|
use crate::shell::SurfaceData;
|
2021-01-04 08:46:59 +00:00
|
|
|
#[cfg(feature = "xwayland")]
|
|
|
|
use crate::xwayland::X11Surface;
|
2020-02-03 12:55:48 +00:00
|
|
|
|
2021-07-30 16:15:15 +00:00
|
|
|
mod layer_map;
|
|
|
|
pub use layer_map::{LayerMap, LayerSurface};
|
|
|
|
|
2021-07-01 21:07:07 +00:00
|
|
|
#[derive(Clone, PartialEq)]
|
2021-06-23 07:43:53 +00:00
|
|
|
pub enum Kind {
|
|
|
|
Xdg(ToplevelSurface),
|
|
|
|
Wl(ShellSurface),
|
2021-01-04 08:46:59 +00:00
|
|
|
#[cfg(feature = "xwayland")]
|
|
|
|
X11(X11Surface),
|
2018-04-23 09:40:41 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 07:43:53 +00:00
|
|
|
impl Kind {
|
2018-04-23 09:40:41 +00:00
|
|
|
pub fn alive(&self) -> bool {
|
|
|
|
match *self {
|
|
|
|
Kind::Xdg(ref t) => t.alive(),
|
|
|
|
Kind::Wl(ref t) => t.alive(),
|
2021-01-04 08:46:59 +00:00
|
|
|
#[cfg(feature = "xwayland")]
|
|
|
|
Kind::X11(ref t) => t.alive(),
|
2018-04-23 09:40:41 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-23 18:01:28 +00:00
|
|
|
|
2019-02-22 21:50:46 +00:00
|
|
|
pub fn get_surface(&self) -> Option<&wl_surface::WlSurface> {
|
2018-04-23 09:40:41 +00:00
|
|
|
match *self {
|
|
|
|
Kind::Xdg(ref t) => t.get_surface(),
|
|
|
|
Kind::Wl(ref t) => t.get_surface(),
|
2021-01-04 08:46:59 +00:00
|
|
|
#[cfg(feature = "xwayland")]
|
|
|
|
Kind::X11(ref t) => t.get_surface(),
|
2018-04-23 09:40:41 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-01 15:25:50 +00:00
|
|
|
|
2021-06-27 01:47:04 +00:00
|
|
|
/// Activate/Deactivate this window
|
|
|
|
pub fn set_activated(&self, active: bool) {
|
2021-06-23 20:52:49 +00:00
|
|
|
if let Kind::Xdg(ref t) = self {
|
|
|
|
let changed = t.with_pending_state(|state| {
|
|
|
|
if active {
|
|
|
|
state.states.set(xdg_toplevel::State::Activated)
|
|
|
|
} else {
|
|
|
|
state.states.unset(xdg_toplevel::State::Activated)
|
2021-06-27 01:47:04 +00:00
|
|
|
}
|
2021-06-23 20:52:49 +00:00
|
|
|
});
|
|
|
|
if let Ok(true) = changed {
|
|
|
|
t.send_configure();
|
2021-06-27 01:47:04 +00:00
|
|
|
}
|
2021-06-23 20:52:49 +00:00
|
|
|
}
|
2021-06-27 01:47:04 +00:00
|
|
|
}
|
2018-04-23 09:40:41 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 07:43:53 +00:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum PopupKind {
|
|
|
|
Xdg(PopupSurface),
|
2021-06-15 21:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 07:43:53 +00:00
|
|
|
impl PopupKind {
|
2021-06-29 15:30:48 +00:00
|
|
|
fn alive(&self) -> bool {
|
2021-06-15 21:32:02 +00:00
|
|
|
match *self {
|
|
|
|
PopupKind::Xdg(ref t) => t.alive(),
|
|
|
|
}
|
|
|
|
}
|
2021-06-23 18:01:28 +00:00
|
|
|
|
2021-06-15 21:32:02 +00:00
|
|
|
pub fn get_surface(&self) -> Option<&wl_surface::WlSurface> {
|
|
|
|
match *self {
|
|
|
|
PopupKind::Xdg(ref t) => t.get_surface(),
|
|
|
|
}
|
|
|
|
}
|
2021-06-29 15:30:48 +00:00
|
|
|
|
|
|
|
fn parent(&self) -> Option<wl_surface::WlSurface> {
|
|
|
|
let wl_surface = match self.get_surface() {
|
|
|
|
Some(s) => s,
|
|
|
|
None => return None,
|
|
|
|
};
|
|
|
|
with_states(wl_surface, |states| {
|
|
|
|
states
|
|
|
|
.data_map
|
|
|
|
.get::<Mutex<XdgPopupSurfaceRoleAttributes>>()
|
|
|
|
.unwrap()
|
|
|
|
.lock()
|
|
|
|
.unwrap()
|
|
|
|
.parent
|
|
|
|
.clone()
|
|
|
|
})
|
|
|
|
.ok()
|
|
|
|
.flatten()
|
|
|
|
}
|
|
|
|
|
2021-07-05 17:21:15 +00:00
|
|
|
pub fn location(&self) -> Point<i32, Logical> {
|
2021-06-29 15:30:48 +00:00
|
|
|
let wl_surface = match self.get_surface() {
|
|
|
|
Some(s) => s,
|
2021-07-05 17:21:15 +00:00
|
|
|
None => return (0, 0).into(),
|
2021-06-29 15:30:48 +00:00
|
|
|
};
|
2021-07-05 17:21:15 +00:00
|
|
|
with_states(wl_surface, |states| {
|
2021-06-29 15:30:48 +00:00
|
|
|
states
|
|
|
|
.data_map
|
|
|
|
.get::<Mutex<XdgPopupSurfaceRoleAttributes>>()
|
|
|
|
.unwrap()
|
|
|
|
.lock()
|
|
|
|
.unwrap()
|
|
|
|
.current
|
|
|
|
.geometry
|
|
|
|
})
|
2021-07-05 17:21:15 +00:00
|
|
|
.unwrap_or_default()
|
|
|
|
.loc
|
2021-06-29 15:30:48 +00:00
|
|
|
}
|
2021-06-15 21:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 07:43:53 +00:00
|
|
|
struct Window {
|
2021-07-05 17:21:15 +00:00
|
|
|
location: Point<i32, Logical>,
|
2020-02-03 09:10:36 +00:00
|
|
|
/// A bounding box over this window and its children.
|
2020-01-22 03:57:45 +00:00
|
|
|
///
|
2020-02-03 09:10:36 +00:00
|
|
|
/// Used for the fast path of the check in `matching`, and as the fall-back for the window
|
|
|
|
/// geometry if that's not set explicitly.
|
2021-07-05 17:21:15 +00:00
|
|
|
bbox: Rectangle<i32, Logical>,
|
2021-06-23 07:43:53 +00:00
|
|
|
toplevel: Kind,
|
2017-09-22 12:56:59 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 07:43:53 +00:00
|
|
|
impl Window {
|
2020-01-22 03:58:41 +00:00
|
|
|
/// Finds the topmost surface under this point if any and returns it together with the location of this
|
|
|
|
/// surface.
|
2021-07-05 17:21:15 +00:00
|
|
|
fn matching(&self, point: Point<f64, Logical>) -> Option<(wl_surface::WlSurface, Point<i32, Logical>)> {
|
|
|
|
if !self.bbox.to_f64().contains(point) {
|
2017-09-22 12:56:59 +00:00
|
|
|
return None;
|
|
|
|
}
|
|
|
|
// need to check more carefully
|
2019-04-10 13:22:06 +00:00
|
|
|
let found = RefCell::new(None);
|
2017-09-22 12:56:59 +00:00
|
|
|
if let Some(wl_surface) = self.toplevel.get_surface() {
|
2021-06-23 07:43:53 +00:00
|
|
|
with_surface_tree_downward(
|
2017-09-22 12:56:59 +00:00
|
|
|
wl_surface,
|
|
|
|
self.location,
|
2021-07-05 17:21:15 +00:00
|
|
|
|wl_surface, states, location| {
|
|
|
|
let mut location = *location;
|
2021-06-23 07:43:53 +00:00
|
|
|
let data = states.data_map.get::<RefCell<SurfaceData>>();
|
2020-02-03 12:55:48 +00:00
|
|
|
|
2021-06-23 07:43:53 +00:00
|
|
|
if states.role == Some("subsurface") {
|
|
|
|
let current = states.cached_state.current::<SubsurfaceCachedState>();
|
2021-07-05 17:21:15 +00:00
|
|
|
location += current.location;
|
2017-09-22 12:56:59 +00:00
|
|
|
}
|
2020-01-22 04:00:37 +00:00
|
|
|
|
2021-06-23 07:43:53 +00:00
|
|
|
let contains_the_point = data
|
|
|
|
.map(|data| {
|
|
|
|
data.borrow()
|
2021-07-05 17:21:15 +00:00
|
|
|
.contains_point(&*states.cached_state.current(), point - location.to_f64())
|
2021-06-23 07:43:53 +00:00
|
|
|
})
|
|
|
|
.unwrap_or(false);
|
|
|
|
if contains_the_point {
|
2021-07-05 17:21:15 +00:00
|
|
|
*found.borrow_mut() = Some((wl_surface.clone(), location));
|
2020-01-22 04:00:37 +00:00
|
|
|
}
|
|
|
|
|
2021-07-05 17:21:15 +00:00
|
|
|
TraversalAction::DoChildren(location)
|
2017-09-22 12:56:59 +00:00
|
|
|
},
|
2021-06-23 07:43:53 +00:00
|
|
|
|_, _, _| {},
|
|
|
|
|_, _, _| {
|
2019-04-10 13:22:06 +00:00
|
|
|
// only continue if the point is not found
|
|
|
|
found.borrow().is_none()
|
|
|
|
},
|
2017-09-22 12:56:59 +00:00
|
|
|
);
|
|
|
|
}
|
2019-04-10 13:22:06 +00:00
|
|
|
found.into_inner()
|
2017-09-22 12:56:59 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 07:43:53 +00:00
|
|
|
fn self_update(&mut self) {
|
2021-07-05 17:21:15 +00:00
|
|
|
let mut bounding_box = Rectangle::from_loc_and_size(self.location, (0, 0));
|
2017-09-22 12:56:59 +00:00
|
|
|
if let Some(wl_surface) = self.toplevel.get_surface() {
|
2021-06-23 07:43:53 +00:00
|
|
|
with_surface_tree_downward(
|
2017-09-22 12:56:59 +00:00
|
|
|
wl_surface,
|
2021-07-05 17:21:15 +00:00
|
|
|
self.location,
|
|
|
|
|_, states, &loc| {
|
|
|
|
let mut loc = loc;
|
2021-06-23 07:43:53 +00:00
|
|
|
let data = states.data_map.get::<RefCell<SurfaceData>>();
|
2020-02-03 12:55:48 +00:00
|
|
|
|
2021-07-05 17:21:15 +00:00
|
|
|
if let Some(size) = data.and_then(|d| d.borrow().size()) {
|
2021-06-23 07:43:53 +00:00
|
|
|
if states.role == Some("subsurface") {
|
|
|
|
let current = states.cached_state.current::<SubsurfaceCachedState>();
|
2021-07-05 17:21:15 +00:00
|
|
|
loc += current.location;
|
2017-09-22 12:56:59 +00:00
|
|
|
}
|
2020-02-03 12:16:00 +00:00
|
|
|
|
|
|
|
// Update the bounding box.
|
2021-07-05 17:21:15 +00:00
|
|
|
bounding_box = bounding_box.merge(Rectangle::from_loc_and_size(loc, size));
|
2020-02-03 12:16:00 +00:00
|
|
|
|
2021-07-05 17:21:15 +00:00
|
|
|
TraversalAction::DoChildren(loc)
|
2017-09-22 12:56:59 +00:00
|
|
|
} else {
|
2020-02-03 12:16:00 +00:00
|
|
|
// If the parent surface is unmapped, then the child surfaces are hidden as
|
|
|
|
// well, no need to consider them here.
|
2017-09-22 12:56:59 +00:00
|
|
|
TraversalAction::SkipChildren
|
|
|
|
}
|
|
|
|
},
|
2021-06-23 07:43:53 +00:00
|
|
|
|_, _, _| {},
|
|
|
|
|_, _, _| true,
|
2017-09-22 12:56:59 +00:00
|
|
|
);
|
|
|
|
}
|
2021-07-05 17:21:15 +00:00
|
|
|
self.bbox = bounding_box;
|
2017-09-22 12:56:59 +00:00
|
|
|
}
|
2020-02-03 13:23:04 +00:00
|
|
|
|
|
|
|
/// Returns the geometry of this window.
|
2021-07-05 17:21:15 +00:00
|
|
|
pub fn geometry(&self) -> Rectangle<i32, Logical> {
|
2020-02-03 13:23:04 +00:00
|
|
|
// It's the set geometry with the full bounding box as the fallback.
|
2021-06-23 07:43:53 +00:00
|
|
|
with_states(self.toplevel.get_surface().unwrap(), |states| {
|
|
|
|
states.cached_state.current::<SurfaceCachedState>().geometry
|
|
|
|
})
|
|
|
|
.unwrap()
|
|
|
|
.unwrap_or(self.bbox)
|
2020-02-03 13:23:04 +00:00
|
|
|
}
|
2020-04-21 17:42:03 +00:00
|
|
|
|
|
|
|
/// Sends the frame callback to all the subsurfaces in this
|
|
|
|
/// window that requested it
|
2021-06-23 07:43:53 +00:00
|
|
|
pub fn send_frame(&self, time: u32) {
|
2020-04-21 17:42:03 +00:00
|
|
|
if let Some(wl_surface) = self.toplevel.get_surface() {
|
2021-06-23 07:43:53 +00:00
|
|
|
with_surface_tree_downward(
|
2020-04-21 17:42:03 +00:00
|
|
|
wl_surface,
|
|
|
|
(),
|
2021-06-23 07:43:53 +00:00
|
|
|
|_, _, &()| TraversalAction::DoChildren(()),
|
|
|
|
|_, states, &()| {
|
2020-04-21 17:42:03 +00:00
|
|
|
// the surface may not have any user_data if it is a subsurface and has not
|
|
|
|
// yet been commited
|
2021-06-23 07:43:53 +00:00
|
|
|
SurfaceData::send_frame(&mut *states.cached_state.current(), time)
|
2020-04-21 17:42:03 +00:00
|
|
|
},
|
2021-06-23 07:43:53 +00:00
|
|
|
|_, _, &()| true,
|
2020-04-21 17:42:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-09-22 12:56:59 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 07:43:53 +00:00
|
|
|
pub struct Popup {
|
|
|
|
popup: PopupKind,
|
2021-06-15 21:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 14:27:12 +00:00
|
|
|
#[derive(Default)]
|
2021-06-23 07:43:53 +00:00
|
|
|
pub struct WindowMap {
|
|
|
|
windows: Vec<Window>,
|
|
|
|
popups: Vec<Popup>,
|
2021-07-30 16:15:15 +00:00
|
|
|
|
|
|
|
pub layers: LayerMap,
|
2017-09-22 12:56:59 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 07:43:53 +00:00
|
|
|
impl WindowMap {
|
2021-07-05 17:21:15 +00:00
|
|
|
pub fn insert(&mut self, toplevel: Kind, location: Point<i32, Logical>) {
|
2017-09-22 12:56:59 +00:00
|
|
|
let mut window = Window {
|
2018-06-27 12:04:29 +00:00
|
|
|
location,
|
2020-02-03 09:10:36 +00:00
|
|
|
bbox: Rectangle::default(),
|
2018-06-27 12:04:29 +00:00
|
|
|
toplevel,
|
2017-09-22 12:56:59 +00:00
|
|
|
};
|
2021-06-23 07:43:53 +00:00
|
|
|
window.self_update();
|
2017-09-22 12:56:59 +00:00
|
|
|
self.windows.insert(0, window);
|
|
|
|
}
|
|
|
|
|
2021-07-11 08:05:27 +00:00
|
|
|
pub fn windows(&self) -> impl Iterator<Item = Kind> + '_ {
|
|
|
|
self.windows.iter().map(|w| w.toplevel.clone())
|
|
|
|
}
|
|
|
|
|
2021-06-23 07:43:53 +00:00
|
|
|
pub fn insert_popup(&mut self, popup: PopupKind) {
|
2021-06-15 21:32:02 +00:00
|
|
|
let popup = Popup { popup };
|
|
|
|
self.popups.push(popup);
|
|
|
|
}
|
|
|
|
|
2021-07-05 17:21:15 +00:00
|
|
|
pub fn get_surface_under(
|
|
|
|
&self,
|
|
|
|
point: Point<f64, Logical>,
|
|
|
|
) -> Option<(wl_surface::WlSurface, Point<i32, Logical>)> {
|
2021-07-30 16:15:15 +00:00
|
|
|
if let Some(res) = self.layers.get_surface_under(&Layer::Overlay, point) {
|
|
|
|
return Some(res);
|
|
|
|
}
|
|
|
|
if let Some(res) = self.layers.get_surface_under(&Layer::Top, point) {
|
|
|
|
return Some(res);
|
|
|
|
}
|
|
|
|
|
2017-09-22 12:56:59 +00:00
|
|
|
for w in &self.windows {
|
2021-06-23 07:43:53 +00:00
|
|
|
if let Some(surface) = w.matching(point) {
|
2017-09-22 12:56:59 +00:00
|
|
|
return Some(surface);
|
|
|
|
}
|
|
|
|
}
|
2021-07-30 16:15:15 +00:00
|
|
|
|
|
|
|
if let Some(res) = self.layers.get_surface_under(&Layer::Bottom, point) {
|
|
|
|
return Some(res);
|
|
|
|
}
|
|
|
|
if let Some(res) = self.layers.get_surface_under(&Layer::Background, point) {
|
|
|
|
return Some(res);
|
|
|
|
}
|
|
|
|
|
2017-09-22 12:56:59 +00:00
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2021-07-31 18:21:07 +00:00
|
|
|
pub fn bring_surface_to_top(&mut self, surface: &WlSurface) {
|
|
|
|
let found = self.windows.iter().enumerate().find(|(_, w)| {
|
|
|
|
if let Some(s) = w.toplevel.get_surface() {
|
|
|
|
s.as_ref().equals(surface.as_ref())
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if let Some((i, _)) = 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-07 21:30:38 +00:00
|
|
|
pub fn get_surface_and_bring_to_top(
|
2018-04-22 09:58:39 +00:00
|
|
|
&mut self,
|
2021-07-05 17:21:15 +00:00
|
|
|
point: Point<f64, Logical>,
|
|
|
|
) -> Option<(wl_surface::WlSurface, Point<i32, Logical>)> {
|
2017-09-22 12:56:59 +00:00
|
|
|
let mut found = None;
|
|
|
|
for (i, w) in self.windows.iter().enumerate() {
|
2021-06-23 07:43:53 +00:00
|
|
|
if let Some(surface) = w.matching(point) {
|
2017-09-22 12:56:59 +00:00
|
|
|
found = Some((i, surface));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some((i, surface)) = found {
|
|
|
|
let winner = self.windows.remove(i);
|
2021-06-27 01:47:04 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2017-09-22 12:56:59 +00:00
|
|
|
self.windows.insert(0, winner);
|
|
|
|
Some(surface)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_windows_from_bottom_to_top<Func>(&self, mut f: Func)
|
|
|
|
where
|
2021-07-05 17:21:15 +00:00
|
|
|
Func: FnMut(&Kind, Point<i32, Logical>, &Rectangle<i32, Logical>),
|
2017-09-22 12:56:59 +00:00
|
|
|
{
|
|
|
|
for w in self.windows.iter().rev() {
|
2020-06-07 21:11:27 +00:00
|
|
|
f(&w.toplevel, w.location, &w.bbox)
|
2017-09-22 12:56:59 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-29 15:30:48 +00:00
|
|
|
pub fn with_child_popups<Func>(&self, base: &wl_surface::WlSurface, mut f: Func)
|
|
|
|
where
|
|
|
|
Func: FnMut(&PopupKind),
|
|
|
|
{
|
|
|
|
for w in self
|
|
|
|
.popups
|
|
|
|
.iter()
|
|
|
|
.rev()
|
|
|
|
.filter(move |w| w.popup.parent().as_ref() == Some(base))
|
|
|
|
{
|
|
|
|
f(&w.popup)
|
|
|
|
}
|
|
|
|
}
|
2017-09-22 12:56:59 +00:00
|
|
|
|
|
|
|
pub fn refresh(&mut self) {
|
|
|
|
self.windows.retain(|w| w.toplevel.alive());
|
2021-06-15 21:32:02 +00:00
|
|
|
self.popups.retain(|p| p.popup.alive());
|
2021-07-30 16:15:15 +00:00
|
|
|
self.layers.refresh();
|
2018-06-27 12:04:29 +00:00
|
|
|
for w in &mut self.windows {
|
2021-06-23 07:43:53 +00:00
|
|
|
w.self_update();
|
2017-09-22 12:56:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-08 05:43:32 +00:00
|
|
|
/// Refreshes the state of the toplevel, if it exists.
|
2021-06-23 07:43:53 +00:00
|
|
|
pub fn refresh_toplevel(&mut self, toplevel: &Kind) {
|
2021-07-01 21:07:07 +00:00
|
|
|
if let Some(w) = self.windows.iter_mut().find(|w| &w.toplevel == toplevel) {
|
2021-06-23 07:43:53 +00:00
|
|
|
w.self_update();
|
2020-02-08 05:43:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 12:56:59 +00:00
|
|
|
pub fn clear(&mut self) {
|
|
|
|
self.windows.clear();
|
|
|
|
}
|
2020-02-01 15:30:01 +00:00
|
|
|
|
2020-02-08 05:39:27 +00:00
|
|
|
/// Finds the toplevel corresponding to the given `WlSurface`.
|
2021-06-23 07:43:53 +00:00
|
|
|
pub fn find(&self, surface: &wl_surface::WlSurface) -> Option<Kind> {
|
2020-02-08 05:39:27 +00:00
|
|
|
self.windows.iter().find_map(|w| {
|
|
|
|
if w.toplevel
|
|
|
|
.get_surface()
|
|
|
|
.map(|s| s.as_ref().equals(surface.as_ref()))
|
|
|
|
.unwrap_or(false)
|
|
|
|
{
|
|
|
|
Some(w.toplevel.clone())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2021-06-15 21:32:02 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-06-29 15:30:48 +00:00
|
|
|
/// Finds the popup corresponding to the given `WlSurface`.
|
2021-06-23 07:43:53 +00:00
|
|
|
pub fn find_popup(&self, surface: &wl_surface::WlSurface) -> Option<PopupKind> {
|
2021-06-15 21:32:02 +00:00
|
|
|
self.popups.iter().find_map(|p| {
|
|
|
|
if p.popup
|
|
|
|
.get_surface()
|
|
|
|
.map(|s| s.as_ref().equals(surface.as_ref()))
|
|
|
|
.unwrap_or(false)
|
|
|
|
{
|
|
|
|
Some(p.popup.clone())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2020-02-08 05:39:27 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-02-01 15:30:01 +00:00
|
|
|
/// Returns the location of the toplevel, if it exists.
|
2021-07-05 17:21:15 +00:00
|
|
|
pub fn location(&self, toplevel: &Kind) -> Option<Point<i32, Logical>> {
|
2020-02-01 15:30:01 +00:00
|
|
|
self.windows
|
|
|
|
.iter()
|
2021-07-01 21:07:07 +00:00
|
|
|
.find(|w| &w.toplevel == toplevel)
|
2020-02-01 15:30:01 +00:00
|
|
|
.map(|w| w.location)
|
|
|
|
}
|
2020-02-01 15:30:13 +00:00
|
|
|
|
|
|
|
/// Sets the location of the toplevel, if it exists.
|
2021-07-05 17:21:15 +00:00
|
|
|
pub fn set_location(&mut self, toplevel: &Kind, location: Point<i32, Logical>) {
|
2021-07-01 21:07:07 +00:00
|
|
|
if let Some(w) = self.windows.iter_mut().find(|w| &w.toplevel == toplevel) {
|
2020-02-01 15:30:13 +00:00
|
|
|
w.location = location;
|
2021-06-23 07:43:53 +00:00
|
|
|
w.self_update();
|
2020-02-01 15:30:13 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-03 13:23:04 +00:00
|
|
|
|
|
|
|
/// Returns the geometry of the toplevel, if it exists.
|
2021-07-05 17:21:15 +00:00
|
|
|
pub fn geometry(&self, toplevel: &Kind) -> Option<Rectangle<i32, Logical>> {
|
2020-02-03 13:23:04 +00:00
|
|
|
self.windows
|
|
|
|
.iter()
|
2021-07-01 21:07:07 +00:00
|
|
|
.find(|w| &w.toplevel == toplevel)
|
2021-06-23 07:43:53 +00:00
|
|
|
.map(|w| w.geometry())
|
2020-02-03 13:23:04 +00:00
|
|
|
}
|
2020-04-21 17:42:03 +00:00
|
|
|
|
2020-10-10 18:01:18 +00:00
|
|
|
pub fn send_frames(&self, time: u32) {
|
2020-04-21 17:42:03 +00:00
|
|
|
for window in &self.windows {
|
2021-06-23 07:43:53 +00:00
|
|
|
window.send_frame(time);
|
2020-04-21 17:42:03 +00:00
|
|
|
}
|
2021-07-30 16:15:15 +00:00
|
|
|
self.layers.send_frames(time);
|
2020-04-21 17:42:03 +00:00
|
|
|
}
|
2017-09-22 12:56:59 +00:00
|
|
|
}
|