iced-yoda/winit/src/platform_specific/wayland/handlers/shell/layer.rs

131 lines
3.8 KiB
Rust

use crate::platform_specific::wayland::{
event_loop::state::{SctkState, receive_frame},
sctk_event::{LayerSurfaceEventVariant, SctkEvent},
};
use cctk::sctk::{
delegate_layer,
reexports::client::Proxy,
shell::{
WaylandSurface,
wlr_layer::{Anchor, KeyboardInteractivity, LayerShellHandler},
},
};
use std::fmt::Debug;
use winit::dpi::LogicalSize;
impl LayerShellHandler for SctkState {
fn closed(
&mut self,
_conn: &cctk::sctk::reexports::client::Connection,
_qh: &cctk::sctk::reexports::client::QueueHandle<Self>,
layer: &cctk::sctk::shell::wlr_layer::LayerSurface,
) {
let layer = match self.layer_surfaces.iter().position(|s| {
s.surface.wl_surface().id() == layer.wl_surface().id()
}) {
Some(w) => self.layer_surfaces.remove(w),
None => return,
};
if let Some(id) = self.id_map.remove(&layer.surface.wl_surface().id()) {
if let Some(blurred) = self.blur_surfaces.remove(&id) {
blurred.destroy();
}
_ = self.corner_radii.remove(&id);
_ = self.destroyed.insert(id);
}
self.sctk_events.push(SctkEvent::LayerSurfaceEvent {
variant: LayerSurfaceEventVariant::Done,
id: layer.surface.wl_surface().clone(),
})
// TODO popup cleanup
}
fn configure(
&mut self,
_conn: &cctk::sctk::reexports::client::Connection,
_qh: &cctk::sctk::reexports::client::QueueHandle<Self>,
layer: &cctk::sctk::shell::wlr_layer::LayerSurface,
mut configure: cctk::sctk::shell::wlr_layer::LayerSurfaceConfigure,
_serial: u32,
) {
let layer =
match self.layer_surfaces.iter_mut().find(|s| {
s.surface.wl_surface().id() == layer.wl_surface().id()
}) {
Some(l) => l,
None => return,
};
let first = layer.last_configure.is_none();
let common = layer.common.lock().unwrap();
let requested_size = common.requested_size;
drop(common);
configure.new_size.0 = if let Some(w) = requested_size.0 {
w
} else {
configure.new_size.0.max(1)
};
configure.new_size.1 = if let Some(h) = requested_size.1 {
h
} else {
configure.new_size.1.max(1)
};
layer.update_viewport(configure.new_size.0, configure.new_size.1);
_ = layer.last_configure.replace(configure.clone());
let mut common = layer.common.lock().unwrap();
common.size =
LogicalSize::new(configure.new_size.0, configure.new_size.1);
drop(common);
let wl_surface = layer.surface.wl_surface().clone();
receive_frame(&mut self.frame_status, &wl_surface);
self.request_redraw(&wl_surface);
self.sctk_events.push(SctkEvent::LayerSurfaceEvent {
variant: LayerSurfaceEventVariant::Configure(
configure,
wl_surface.clone(),
first,
),
id: wl_surface,
});
}
}
delegate_layer!(SctkState);
#[allow(dead_code)]
/// A request to SCTK window from Winit window.
#[derive(Debug, Clone)]
pub enum LayerSurfaceRequest {
/// Set fullscreen.
///
/// Passing `None` will set it on the current monitor.
Size(LogicalSize<u32>),
/// Unset fullscreen.
UnsetFullscreen,
/// Show cursor for the certain window or not.
ShowCursor(bool),
/// Set anchor
Anchor(Anchor),
/// Set margin
ExclusiveZone(i32),
/// Set margin
Margin(u32),
/// Passthrough mouse input to underlying windows.
KeyboardInteractivity(KeyboardInteractivity),
/// Redraw was requested.
Redraw,
/// Window should be closed.
Close,
}