spell_framework/wayland_adapter/lock/
wayland.rs1use slint::PhysicalSize;
2use smithay_client_toolkit::{
3 compositor::CompositorHandler,
4 output::{OutputHandler, OutputState},
5 reexports::client::{
6 Connection, QueueHandle,
7 protocol::{wl_output, wl_seat, wl_surface},
8 },
9 registry::{ProvidesRegistryState, RegistryState},
10 registry_handlers,
11 seat::{Capability, SeatHandler, SeatState, pointer::PointerData},
12 session_lock::{
13 SessionLock, SessionLockHandler, SessionLockSurface, SessionLockSurfaceConfigure,
14 },
15 shm::{Shm, ShmHandler, slot::Buffer},
16};
17use tracing::info;
18
19use crate::{slint_adapter::SpellSkiaWinAdapter, wayland_adapter::lock::SpellLock};
20
21impl ProvidesRegistryState for SpellLock {
22 fn registry(&mut self) -> &mut RegistryState {
23 &mut self.registry_state
24 }
25 registry_handlers![OutputState, SeatState];
26}
27
28impl ShmHandler for SpellLock {
29 fn shm_state(&mut self) -> &mut Shm {
30 &mut self.shm
31 }
32}
33
34impl OutputHandler for SpellLock {
35 fn output_state(&mut self) -> &mut OutputState {
36 &mut self.output_state
37 }
38
39 fn new_output(
40 &mut self,
41 _conn: &Connection,
42 _qh: &QueueHandle<Self>,
43 _output: wl_output::WlOutput,
44 ) {
45 info!("New output source added");
46 }
47
48 fn update_output(
49 &mut self,
50 _conn: &Connection,
51 _qh: &QueueHandle<Self>,
52 _output: wl_output::WlOutput,
53 ) {
54 info!("Updated output source");
55 }
56
57 fn output_destroyed(
58 &mut self,
59 _conn: &Connection,
60 _qh: &QueueHandle<Self>,
61 _output: wl_output::WlOutput,
62 ) {
63 info!("Output is destroyed");
64 }
65}
66
67impl CompositorHandler for SpellLock {
68 fn scale_factor_changed(
69 &mut self,
70 _conn: &Connection,
71 _qh: &QueueHandle<Self>,
72 _surface: &wl_surface::WlSurface,
73 _new_factor: i32,
74 ) {
75 info!("Scale factor changed");
76 }
77
78 fn transform_changed(
79 &mut self,
80 _conn: &Connection,
81 _qh: &QueueHandle<Self>,
82 _surface: &wl_surface::WlSurface,
83 _new_transform: wl_output::Transform,
84 ) {
85 info!("Compositor transformation changed");
86 }
87
88 fn frame(
89 &mut self,
90 _conn: &Connection,
91 qh: &QueueHandle<Self>,
92 _surface: &wl_surface::WlSurface,
93 _time: u32,
94 ) {
95 self.converter_lock(qh);
96 }
97
98 fn surface_enter(
99 &mut self,
100 _conn: &Connection,
101 _qh: &QueueHandle<Self>,
102 _surface: &wl_surface::WlSurface,
103 _output: &wl_output::WlOutput,
104 ) {
105 info!("Surface entered");
106 }
107
108 fn surface_leave(
109 &mut self,
110 _conn: &Connection,
111 _qh: &QueueHandle<Self>,
112 _surface: &wl_surface::WlSurface,
113 _output: &wl_output::WlOutput,
114 ) {
115 info!("Surface left");
116 }
117}
118
119impl SessionLockHandler for SpellLock {
120 fn locked(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, _session_lock: SessionLock) {
121 info!("Session is locked");
122 }
123
124 fn finished(
125 &mut self,
126 _conn: &Connection,
127 _qh: &QueueHandle<Self>,
128 _session_lock: SessionLock,
129 ) {
130 info!("Session could not be locked");
131 self.is_locked = true;
132 }
133 fn configure(
134 &mut self,
135 _conn: &Connection,
136 qh: &QueueHandle<Self>,
137 _surface: SessionLockSurface,
138 _configure: SessionLockSurfaceConfigure,
139 _serial: u32,
140 ) {
141 self.converter_lock(qh);
142 }
143}
144
145impl SeatHandler for SpellLock {
146 fn seat_state(&mut self) -> &mut SeatState {
147 &mut self.seat_state
148 }
149
150 fn new_seat(&mut self, _: &Connection, _: &QueueHandle<Self>, _: wl_seat::WlSeat) {}
151
152 fn new_capability(
153 &mut self,
154 _conn: &Connection,
155 qh: &QueueHandle<Self>,
156 seat: wl_seat::WlSeat,
157 capability: Capability,
158 ) {
159 if capability == Capability::Keyboard && self.keyboard_state.is_none() {
160 info!("Setting keyboard capability");
161 let keyboard = self
162 .seat_state
163 .get_keyboard(qh, &seat, None)
164 .expect("Failed to create keyboard");
165 self.keyboard_state = Some(keyboard);
166 }
167 if capability == Capability::Touch && self.touch_state.is_none() {
168 info!("Setting touch Capability");
169 let touch = self
170 .seat_state
171 .get_touch(qh, &seat)
172 .expect("Failed to create touch");
173 self.touch_state = Some(touch);
174 }
175 if capability == Capability::Pointer && self.pointer_state.pointer.is_none() {
176 info!("Setting pointer capability");
177 let pointer = self
178 .seat_state
179 .get_pointer(qh, &seat)
180 .expect("Failed to create pointer");
181 let pointer_data = PointerData::new(seat);
182 self.pointer_state.pointer = Some(pointer);
183 self.pointer_state.pointer_data = Some(pointer_data);
184 }
185 }
186
187 fn remove_capability(
188 &mut self,
189 _conn: &Connection,
190 _: &QueueHandle<Self>,
191 _: wl_seat::WlSeat,
192 capability: Capability,
193 ) {
194 if capability == Capability::Keyboard && self.keyboard_state.is_some() {
195 info!("Unsettting keyboard capability");
196 self.keyboard_state.take().unwrap().release();
197 }
198 if capability == Capability::Pointer && self.pointer_state.pointer.is_some() {
199 info!("Unsetting pointer capability");
200 self.pointer_state.pointer.take().unwrap().release();
201 }
202 if capability == Capability::Touch && self.touch_state.is_some() {
203 info!("Unsetting pointer capability");
204 self.touch_state.take().unwrap().release();
205 }
206 }
207
208 fn remove_seat(&mut self, _: &Connection, _: &QueueHandle<Self>, _: wl_seat::WlSeat) {}
209}
210
211pub struct SpellSlintLock {
213 pub(crate) adapters: Vec<std::rc::Rc<SpellSkiaWinAdapter>>,
214 pub(crate) size: Vec<PhysicalSize>,
215 pub(crate) wayland_buffer: Vec<Buffer>,
216}