use slint::PhysicalSize;
use smithay_client_toolkit::{
compositor::CompositorHandler,
output::{OutputHandler, OutputState},
reexports::client::{
Connection, QueueHandle,
protocol::{wl_output, wl_seat, wl_surface},
},
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
seat::{Capability, SeatHandler, SeatState, pointer::PointerData},
session_lock::{
SessionLock, SessionLockHandler, SessionLockSurface, SessionLockSurfaceConfigure,
},
shm::{Shm, ShmHandler, slot::Buffer},
};
use tracing::info;
use crate::{slint_adapter::SpellSkiaWinAdapter, wayland_adapter::lock::SpellLock};
impl ProvidesRegistryState for SpellLock {
fn registry(&mut self) -> &mut RegistryState {
&mut self.registry_state
}
registry_handlers![OutputState, SeatState];
}
impl ShmHandler for SpellLock {
fn shm_state(&mut self) -> &mut Shm {
&mut self.shm
}
}
impl OutputHandler for SpellLock {
fn output_state(&mut self) -> &mut OutputState {
&mut self.output_state
}
fn new_output(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_output: wl_output::WlOutput,
) {
info!("New output source added");
}
fn update_output(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_output: wl_output::WlOutput,
) {
info!("Updated output source");
}
fn output_destroyed(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_output: wl_output::WlOutput,
) {
info!("Output is destroyed");
}
}
impl CompositorHandler for SpellLock {
fn scale_factor_changed(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_new_factor: i32,
) {
info!("Scale factor changed");
}
fn transform_changed(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_new_transform: wl_output::Transform,
) {
info!("Compositor transformation changed");
}
fn frame(
&mut self,
_conn: &Connection,
qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_time: u32,
) {
self.converter_lock(qh);
}
fn surface_enter(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
info!("Surface entered");
}
fn surface_leave(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
info!("Surface left");
}
}
impl SessionLockHandler for SpellLock {
fn locked(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, _session_lock: SessionLock) {
info!("Session is locked");
}
fn finished(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_session_lock: SessionLock,
) {
info!("Session could not be locked");
self.is_locked = true;
}
fn configure(
&mut self,
_conn: &Connection,
qh: &QueueHandle<Self>,
_surface: SessionLockSurface,
_configure: SessionLockSurfaceConfigure,
_serial: u32,
) {
self.converter_lock(qh);
}
}
impl SeatHandler for SpellLock {
fn seat_state(&mut self) -> &mut SeatState {
&mut self.seat_state
}
fn new_seat(&mut self, _: &Connection, _: &QueueHandle<Self>, _: wl_seat::WlSeat) {}
fn new_capability(
&mut self,
_conn: &Connection,
qh: &QueueHandle<Self>,
seat: wl_seat::WlSeat,
capability: Capability,
) {
if capability == Capability::Keyboard && self.keyboard_state.is_none() {
info!("Setting keyboard capability");
let keyboard = self
.seat_state
.get_keyboard(qh, &seat, None)
.expect("Failed to create keyboard");
self.keyboard_state = Some(keyboard);
}
if capability == Capability::Touch && self.touch_state.is_none() {
info!("Setting touch Capability");
let touch = self
.seat_state
.get_touch(qh, &seat)
.expect("Failed to create touch");
self.touch_state = Some(touch);
}
if capability == Capability::Pointer && self.pointer_state.pointer.is_none() {
info!("Setting pointer capability");
let pointer = self
.seat_state
.get_pointer(qh, &seat)
.expect("Failed to create pointer");
let pointer_data = PointerData::new(seat);
self.pointer_state.pointer = Some(pointer);
self.pointer_state.pointer_data = Some(pointer_data);
}
}
fn remove_capability(
&mut self,
_conn: &Connection,
_: &QueueHandle<Self>,
_: wl_seat::WlSeat,
capability: Capability,
) {
if capability == Capability::Keyboard && self.keyboard_state.is_some() {
info!("Unsettting keyboard capability");
self.keyboard_state.take().unwrap().release();
}
if capability == Capability::Pointer && self.pointer_state.pointer.is_some() {
info!("Unsetting pointer capability");
self.pointer_state.pointer.take().unwrap().release();
}
if capability == Capability::Touch && self.touch_state.is_some() {
info!("Unsetting pointer capability");
self.touch_state.take().unwrap().release();
}
}
fn remove_seat(&mut self, _: &Connection, _: &QueueHandle<Self>, _: wl_seat::WlSeat) {}
}
pub struct SpellSlintLock {
pub(crate) adapters: Vec<std::rc::Rc<SpellSkiaWinAdapter>>,
pub(crate) size: Vec<PhysicalSize>,
pub(crate) wayland_buffer: Vec<Buffer>,
}