niri
Clone
https://git.tahinli.com/Tahinli/niri.git
0 watching·0 forks·Rust·GPL-3.0·12.1 MiB·055a94d·Ivan Molodetskikh·1 year ago·2247 commits
| 1 | use std::cmp::min; |
| 2 | use std::collections::HashMap; |
| 3 | use std::fmt; |
| 4 | use std::fmt::Write as _; |
| 5 | use std::os::unix::net::UnixStream; |
| 6 | use std::sync::atomic::{AtomicBool, Ordering}; |
| 7 | use std::sync::Arc; |
| 8 | use std::time::Duration; |
| 9 | |
| 10 | use calloop::EventLoop; |
| 11 | use calloop_wayland_source::WaylandSource; |
| 12 | use single_pixel_buffer::v1::client::wp_single_pixel_buffer_manager_v1::WpSinglePixelBufferManagerV1; |
| 13 | use smithay::reexports::wayland_protocols::wp::single_pixel_buffer; |
| 14 | use smithay::reexports::wayland_protocols::wp::viewporter::client::wp_viewport::WpViewport; |
| 15 | use smithay::reexports::wayland_protocols::wp::viewporter::client::wp_viewporter::WpViewporter; |
| 16 | use smithay::reexports::wayland_protocols::xdg::shell::client::xdg_surface::{self, XdgSurface}; |
| 17 | use smithay::reexports::wayland_protocols::xdg::shell::client::xdg_toplevel::{self, XdgToplevel}; |
| 18 | use smithay::reexports::wayland_protocols::xdg::shell::client::xdg_wm_base::{self, XdgWmBase}; |
| 19 | use smithay::reexports::wayland_protocols_wlr::layer_shell::v1::client::zwlr_layer_shell_v1::{ |
| 20 | self, ZwlrLayerShellV1, |
| 21 | }; |
| 22 | use smithay::reexports::wayland_protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::{ |
| 23 | self, ZwlrLayerSurfaceV1, |
| 24 | }; |
| 25 | use wayland_backend::client::Backend; |
| 26 | use wayland_client::globals::Global; |
| 27 | use wayland_client::protocol::wl_buffer::{self, WlBuffer}; |
| 28 | use wayland_client::protocol::wl_callback::{self, WlCallback}; |
| 29 | use wayland_client::protocol::wl_compositor::WlCompositor; |
| 30 | use wayland_client::protocol::wl_display::WlDisplay; |
| 31 | use wayland_client::protocol::wl_output::{self, WlOutput}; |
| 32 | use wayland_client::protocol::wl_registry::{self, WlRegistry}; |
| 33 | use wayland_client::protocol::wl_surface::{self, WlSurface}; |
| 34 | use wayland_client::{Connection, Dispatch, Proxy as _, QueueHandle}; |
| 35 | |
| 36 | use crate::utils::id::IdCounter; |
| 37 | |
| 38 | pub struct Client { |
| 39 | pub id: ClientId, |
| 40 | pub event_loop: EventLoop<'static, State>, |
| 41 | pub connection: Connection, |
| 42 | pub qh: QueueHandle<State>, |
| 43 | pub display: WlDisplay, |
| 44 | pub state: State, |
| 45 | } |
| 46 | |
| 47 | pub struct State { |
| 48 | pub qh: QueueHandle<State>, |
| 49 | |
| 50 | pub globals: Vec<Global>, |
| 51 | pub outputs: HashMap<WlOutput, String>, |
| 52 | |
| 53 | pub compositor: Option<WlCompositor>, |
| 54 | pub xdg_wm_base: Option<XdgWmBase>, |
| 55 | pub layer_shell: Option<ZwlrLayerShellV1>, |
| 56 | pub spbm: Option<WpSinglePixelBufferManagerV1>, |
| 57 | pub viewporter: Option<WpViewporter>, |
| 58 | |
| 59 | pub windows: Vec<Window>, |
| 60 | pub layers: Vec<LayerSurface>, |
| 61 | } |
| 62 | |
| 63 | pub struct Window { |
| 64 | pub qh: QueueHandle<State>, |
| 65 | pub spbm: WpSinglePixelBufferManagerV1, |
| 66 | |
| 67 | pub surface: WlSurface, |
| 68 | pub xdg_surface: XdgSurface, |
| 69 | pub xdg_toplevel: XdgToplevel, |
| 70 | pub viewport: WpViewport, |
| 71 | pub pending_configure: Configure, |
| 72 | pub configures_received: Vec<(u32, Configure)>, |
| 73 | pub close_requested: bool, |
| 74 | |
| 75 | pub configures_looked_at: usize, |
| 76 | } |
| 77 | |
| 78 | pub struct LayerSurface { |
| 79 | pub qh: QueueHandle<State>, |
| 80 | pub spbm: WpSinglePixelBufferManagerV1, |
| 81 | |
| 82 | pub surface: WlSurface, |
| 83 | pub layer_surface: ZwlrLayerSurfaceV1, |
| 84 | pub viewport: WpViewport, |
| 85 | pub configures_received: Vec<(u32, LayerConfigure)>, |
| 86 | pub close_requested: bool, |
| 87 | |
| 88 | pub configures_looked_at: usize, |
| 89 | } |
| 90 | |
| 91 | #[derive(Debug, Clone, Default)] |
| 92 | pub struct Configure { |
| 93 | pub size: (i32, i32), |
| 94 | pub bounds: Option<(i32, i32)>, |
| 95 | pub states: Vec<xdg_toplevel::State>, |
| 96 | } |
| 97 | |
| 98 | #[derive(Debug, Clone, Copy)] |
| 99 | pub struct LayerConfigure { |
| 100 | pub size: (u32, u32), |
| 101 | } |
| 102 | |
| 103 | #[derive(Clone, Copy, Default)] |
| 104 | pub struct LayerMargin { |
| 105 | pub top: i32, |
| 106 | pub right: i32, |
| 107 | pub bottom: i32, |
| 108 | pub left: i32, |
| 109 | } |
| 110 | |
| 111 | #[derive(Clone, Copy, Default)] |
| 112 | pub struct LayerConfigureProps { |
| 113 | pub size: Option<(u32, u32)>, |
| 114 | pub anchor: Option<zwlr_layer_surface_v1::Anchor>, |
| 115 | pub exclusive_zone: Option<i32>, |
| 116 | pub margin: Option<LayerMargin>, |
| 117 | pub kb_interactivity: Option<zwlr_layer_surface_v1::KeyboardInteractivity>, |
| 118 | pub layer: Option<zwlr_layer_shell_v1::Layer>, |
| 119 | pub exclusive_edge: Option<zwlr_layer_surface_v1::Anchor>, |
| 120 | } |
| 121 | |
| 122 | #[derive(Default)] |
| 123 | pub struct SyncData { |
| 124 | pub done: AtomicBool, |
| 125 | } |
| 126 | |
| 127 | static CLIENT_ID_COUNTER: IdCounter = IdCounter::new(); |
| 128 | |
| 129 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 130 | pub struct ClientId(u64); |
| 131 | |
| 132 | impl ClientId { |
| 133 | fn next() -> ClientId { |
| 134 | ClientId(CLIENT_ID_COUNTER.next()) |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | impl fmt::Display for Configure { |
| 139 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 140 | write!(f, "size: {} × {}, ", self.size.0, self.size.1)?; |
| 141 | if let Some(bounds) = self.bounds { |
| 142 | write!(f, "bounds: {} × {}, ", bounds.0, bounds.1)?; |
| 143 | } else { |
| 144 | write!(f, "bounds: none, ")?; |
| 145 | } |
| 146 | write!(f, "states: {:?}", self.states)?; |
| 147 | Ok(()) |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | impl fmt::Display for LayerConfigure { |
| 152 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 153 | write!(f, "size: {} × {}", self.size.0, self.size.1)?; |
| 154 | Ok(()) |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | impl Client { |
| 159 | pub fn new(stream: UnixStream) -> Self { |
| 160 | let id = ClientId::next(); |
| 161 | |
| 162 | let event_loop = EventLoop::try_new().unwrap(); |
| 163 | let backend = Backend::connect(stream).unwrap(); |
| 164 | let connection = Connection::from_backend(backend); |
| 165 | let queue = connection.new_event_queue(); |
| 166 | let qh = queue.handle(); |
| 167 | WaylandSource::new(connection.clone(), queue) |
| 168 | .insert(event_loop.handle()) |
| 169 | .unwrap(); |
| 170 | |
| 171 | let display = connection.display(); |
| 172 | let _registry = display.get_registry(&qh, ()); |
| 173 | connection.flush().unwrap(); |
| 174 | |
| 175 | let state = State { |
| 176 | qh: qh.clone(), |
| 177 | globals: Vec::new(), |
| 178 | outputs: HashMap::new(), |
| 179 | compositor: None, |
| 180 | xdg_wm_base: None, |
| 181 | layer_shell: None, |
| 182 | spbm: None, |
| 183 | viewporter: None, |
| 184 | windows: Vec::new(), |
| 185 | layers: Vec::new(), |
| 186 | }; |
| 187 | |
| 188 | Self { |
| 189 | id, |
| 190 | event_loop, |
| 191 | connection, |
| 192 | qh, |
| 193 | display, |
| 194 | state, |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | pub fn dispatch(&mut self) { |
| 199 | self.event_loop |
| 200 | .dispatch(Duration::ZERO, &mut self.state) |
| 201 | .unwrap(); |
| 202 | } |
| 203 | |
| 204 | pub fn send_sync(&self) -> Arc<SyncData> { |
| 205 | let data = Arc::new(SyncData::default()); |
| 206 | self.display.sync(&self.qh, data.clone()); |
| 207 | self.connection.flush().unwrap(); |
| 208 | data |
| 209 | } |
| 210 | |
| 211 | pub fn create_window(&mut self) -> &mut Window { |
| 212 | self.state.create_window() |
| 213 | } |
| 214 | |
| 215 | pub fn window(&mut self, surface: &WlSurface) -> &mut Window { |
| 216 | self.state.window(surface) |
| 217 | } |
| 218 | |
| 219 | pub fn create_layer( |
| 220 | &mut self, |
| 221 | output: Option<&WlOutput>, |
| 222 | layer: zwlr_layer_shell_v1::Layer, |
| 223 | namespace: &str, |
| 224 | ) -> &mut LayerSurface { |
| 225 | self.state.create_layer(output, layer, namespace.to_owned()) |
| 226 | } |
| 227 | |
| 228 | pub fn layer(&mut self, surface: &WlSurface) -> &mut LayerSurface { |
| 229 | self.state.layer(surface) |
| 230 | } |
| 231 | |
| 232 | pub fn output(&mut self, name: &str) -> WlOutput { |
| 233 | self.state |
| 234 | .outputs |
| 235 | .iter() |
| 236 | .find(|(_, v)| *v == name) |
| 237 | .unwrap() |
| 238 | .0 |
| 239 | .clone() |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | impl State { |
| 244 | pub fn create_window(&mut self) -> &mut Window { |
| 245 | let compositor = self.compositor.as_ref().unwrap(); |
| 246 | let xdg_wm_base = self.xdg_wm_base.as_ref().unwrap(); |
| 247 | let viewporter = self.viewporter.as_ref().unwrap(); |
| 248 | |
| 249 | let surface = compositor.create_surface(&self.qh, ()); |
| 250 | let xdg_surface = xdg_wm_base.get_xdg_surface(&surface, &self.qh, ()); |
| 251 | let xdg_toplevel = xdg_surface.get_toplevel(&self.qh, ()); |
| 252 | let viewport = viewporter.get_viewport(&surface, &self.qh, ()); |
| 253 | |
| 254 | let window = Window { |
| 255 | qh: self.qh.clone(), |
| 256 | spbm: self.spbm.clone().unwrap(), |
| 257 | |
| 258 | surface, |
| 259 | xdg_surface, |
| 260 | xdg_toplevel, |
| 261 | viewport, |
| 262 | pending_configure: Configure::default(), |
| 263 | configures_received: Vec::new(), |
| 264 | close_requested: false, |
| 265 | |
| 266 | configures_looked_at: 0, |
| 267 | }; |
| 268 | |
| 269 | self.windows.push(window); |
| 270 | self.windows.last_mut().unwrap() |
| 271 | } |
| 272 | |
| 273 | pub fn window(&mut self, surface: &WlSurface) -> &mut Window { |
| 274 | self.windows |
| 275 | .iter_mut() |
| 276 | .find(|w| w.surface == *surface) |
| 277 | .unwrap() |
| 278 | } |
| 279 | |
| 280 | pub fn create_layer( |
| 281 | &mut self, |
| 282 | output: Option<&WlOutput>, |
| 283 | layer: zwlr_layer_shell_v1::Layer, |
| 284 | namespace: String, |
| 285 | ) -> &mut LayerSurface { |
| 286 | let compositor = self.compositor.as_ref().unwrap(); |
| 287 | let layer_shell = self.layer_shell.as_ref().unwrap(); |
| 288 | let viewporter = self.viewporter.as_ref().unwrap(); |
| 289 | |
| 290 | let surface = compositor.create_surface(&self.qh, ()); |
| 291 | let layer_surface = |
| 292 | layer_shell.get_layer_surface(&surface, output, layer, namespace, &self.qh, ()); |
| 293 | let viewport = viewporter.get_viewport(&surface, &self.qh, ()); |
| 294 | |
| 295 | let layer_surface = LayerSurface { |
| 296 | qh: self.qh.clone(), |
| 297 | spbm: self.spbm.clone().unwrap(), |
| 298 | |
| 299 | surface, |
| 300 | layer_surface, |
| 301 | viewport, |
| 302 | configures_received: Vec::new(), |
| 303 | close_requested: false, |
| 304 | |
| 305 | configures_looked_at: 0, |
| 306 | }; |
| 307 | |
| 308 | self.layers.push(layer_surface); |
| 309 | self.layers.last_mut().unwrap() |
| 310 | } |
| 311 | |
| 312 | pub fn layer(&mut self, surface: &WlSurface) -> &mut LayerSurface { |
| 313 | self.layers |
| 314 | .iter_mut() |
| 315 | .find(|w| w.surface == *surface) |
| 316 | .unwrap() |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | impl Window { |
| 321 | pub fn commit(&self) { |
| 322 | self.surface.commit(); |
| 323 | } |
| 324 | |
| 325 | pub fn ack_last(&self) { |
| 326 | let serial = self.configures_received.last().unwrap().0; |
| 327 | self.xdg_surface.ack_configure(serial); |
| 328 | } |
| 329 | |
| 330 | pub fn ack_last_and_commit(&self) { |
| 331 | self.ack_last(); |
| 332 | self.commit(); |
| 333 | } |
| 334 | |
| 335 | pub fn attach_new_buffer(&self) { |
| 336 | let buffer = self.spbm.create_u32_rgba_buffer(0, 0, 0, 0, &self.qh, ()); |
| 337 | self.surface.attach(Some(&buffer), 0, 0); |
| 338 | } |
| 339 | |
| 340 | pub fn set_size(&self, w: u16, h: u16) { |
| 341 | self.viewport.set_destination(i32::from(w), i32::from(h)); |
| 342 | } |
| 343 | |
| 344 | pub fn set_fullscreen(&self, output: Option<&WlOutput>) { |
| 345 | self.xdg_toplevel.set_fullscreen(output); |
| 346 | } |
| 347 | |
| 348 | pub fn unset_fullscreen(&self) { |
| 349 | self.xdg_toplevel.unset_fullscreen(); |
| 350 | } |
| 351 | |
| 352 | pub fn set_parent(&self, parent: Option<&XdgToplevel>) { |
| 353 | self.xdg_toplevel.set_parent(parent); |
| 354 | } |
| 355 | |
| 356 | pub fn set_title(&self, title: &str) { |
| 357 | self.xdg_toplevel.set_title(title.to_owned()); |
| 358 | } |
| 359 | |
| 360 | pub fn recent_configures(&mut self) -> impl Iterator<Item = &Configure> { |
| 361 | let start = self.configures_looked_at; |
| 362 | self.configures_looked_at = self.configures_received.len(); |
| 363 | self.configures_received[start..].iter().map(|(_, c)| c) |
| 364 | } |
| 365 | |
| 366 | pub fn format_recent_configures(&mut self) -> String { |
| 367 | let mut buf = String::new(); |
| 368 | for configure in self.recent_configures() { |
| 369 | if !buf.is_empty() { |
| 370 | buf.push('\n'); |
| 371 | } |
| 372 | write!(buf, "{configure}").unwrap(); |
| 373 | } |
| 374 | buf |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | impl LayerSurface { |
| 379 | pub fn commit(&self) { |
| 380 | self.surface.commit(); |
| 381 | } |
| 382 | |
| 383 | pub fn ack_last(&self) { |
| 384 | let serial = self.configures_received.last().unwrap().0; |
| 385 | self.layer_surface.ack_configure(serial); |
| 386 | } |
| 387 | |
| 388 | pub fn ack_last_and_commit(&self) { |
| 389 | self.ack_last(); |
| 390 | self.commit(); |
| 391 | } |
| 392 | |
| 393 | pub fn set_configure_props(&self, props: LayerConfigureProps) { |
| 394 | let LayerConfigureProps { |
| 395 | size, |
| 396 | anchor, |
| 397 | exclusive_zone, |
| 398 | margin, |
| 399 | kb_interactivity, |
| 400 | layer, |
| 401 | exclusive_edge, |
| 402 | } = props; |
| 403 | |
| 404 | if let Some(x) = size { |
| 405 | self.layer_surface.set_size(x.0, x.1); |
| 406 | } |
| 407 | if let Some(x) = anchor { |
| 408 | self.layer_surface.set_anchor(x); |
| 409 | } |
| 410 | if let Some(x) = exclusive_zone { |
| 411 | self.layer_surface.set_exclusive_zone(x); |
| 412 | } |
| 413 | if let Some(x) = margin { |
| 414 | self.layer_surface |
| 415 | .set_margin(x.top, x.right, x.bottom, x.left); |
| 416 | } |
| 417 | if let Some(x) = kb_interactivity { |
| 418 | self.layer_surface.set_keyboard_interactivity(x); |
| 419 | } |
| 420 | if let Some(x) = layer { |
| 421 | self.layer_surface.set_layer(x); |
| 422 | } |
| 423 | if let Some(x) = exclusive_edge { |
| 424 | self.layer_surface.set_exclusive_edge(x); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | pub fn attach_new_buffer(&self) { |
| 429 | let buffer = self.spbm.create_u32_rgba_buffer(0, 0, 0, 0, &self.qh, ()); |
| 430 | self.surface.attach(Some(&buffer), 0, 0); |
| 431 | } |
| 432 | |
| 433 | pub fn set_size(&self, w: u16, h: u16) { |
| 434 | self.viewport.set_destination(i32::from(w), i32::from(h)); |
| 435 | } |
| 436 | |
| 437 | pub fn recent_configures(&mut self) -> impl Iterator<Item = &LayerConfigure> { |
| 438 | let start = self.configures_looked_at; |
| 439 | self.configures_looked_at = self.configures_received.len(); |
| 440 | self.configures_received[start..].iter().map(|(_, c)| c) |
| 441 | } |
| 442 | |
| 443 | pub fn format_recent_configures(&mut self) -> String { |
| 444 | let mut buf = String::new(); |
| 445 | for configure in self.recent_configures() { |
| 446 | if !buf.is_empty() { |
| 447 | buf.push('\n'); |
| 448 | } |
| 449 | write!(buf, "{configure}").unwrap(); |
| 450 | } |
| 451 | buf |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | impl Dispatch<WlCallback, Arc<SyncData>> for State { |
| 456 | fn event( |
| 457 | _state: &mut Self, |
| 458 | _proxy: &WlCallback, |
| 459 | event: <WlCallback as wayland_client::Proxy>::Event, |
| 460 | data: &Arc<SyncData>, |
| 461 | _conn: &Connection, |
| 462 | _qhandle: &QueueHandle<Self>, |
| 463 | ) { |
| 464 | match event { |
| 465 | wl_callback::Event::Done { .. } => data.done.store(true, Ordering::Relaxed), |
| 466 | _ => unreachable!(), |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | impl Dispatch<WlRegistry, ()> for State { |
| 472 | fn event( |
| 473 | state: &mut Self, |
| 474 | registry: &WlRegistry, |
| 475 | event: <WlRegistry as wayland_client::Proxy>::Event, |
| 476 | _data: &(), |
| 477 | _conn: &Connection, |
| 478 | qh: &QueueHandle<Self>, |
| 479 | ) { |
| 480 | match event { |
| 481 | wl_registry::Event::Global { |
| 482 | name, |
| 483 | interface, |
| 484 | version, |
| 485 | } => { |
| 486 | if interface == WlCompositor::interface().name { |
| 487 | let version = min(version, WlCompositor::interface().version); |
| 488 | state.compositor = Some(registry.bind(name, version, qh, ())); |
| 489 | } else if interface == XdgWmBase::interface().name { |
| 490 | let version = min(version, XdgWmBase::interface().version); |
| 491 | state.xdg_wm_base = Some(registry.bind(name, version, qh, ())); |
| 492 | } else if interface == ZwlrLayerShellV1::interface().name { |
| 493 | let version = min(version, ZwlrLayerShellV1::interface().version); |
| 494 | state.layer_shell = Some(registry.bind(name, version, qh, ())); |
| 495 | } else if interface == WpSinglePixelBufferManagerV1::interface().name { |
| 496 | let version = min(version, WpSinglePixelBufferManagerV1::interface().version); |
| 497 | state.spbm = Some(registry.bind(name, version, qh, ())); |
| 498 | } else if interface == WpViewporter::interface().name { |
| 499 | let version = min(version, WpViewporter::interface().version); |
| 500 | state.viewporter = Some(registry.bind(name, version, qh, ())); |
| 501 | } else if interface == WlOutput::interface().name { |
| 502 | let version = min(version, WlOutput::interface().version); |
| 503 | let output = registry.bind(name, version, qh, ()); |
| 504 | state.outputs.insert(output, String::new()); |
| 505 | } |
| 506 | |
| 507 | let global = Global { |
| 508 | name, |
| 509 | interface, |
| 510 | version, |
| 511 | }; |
| 512 | state.globals.push(global); |
| 513 | } |
| 514 | wl_registry::Event::GlobalRemove { .. } => (), |
| 515 | _ => unreachable!(), |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | impl Dispatch<WlOutput, ()> for State { |
| 521 | fn event( |
| 522 | state: &mut Self, |
| 523 | output: &WlOutput, |
| 524 | event: <WlOutput as wayland_client::Proxy>::Event, |
| 525 | _data: &(), |
| 526 | _conn: &Connection, |
| 527 | _qhandle: &QueueHandle<Self>, |
| 528 | ) { |
| 529 | match event { |
| 530 | wl_output::Event::Geometry { .. } => (), |
| 531 | wl_output::Event::Mode { .. } => (), |
| 532 | wl_output::Event::Done => (), |
| 533 | wl_output::Event::Scale { .. } => (), |
| 534 | wl_output::Event::Name { name } => { |
| 535 | *state.outputs.get_mut(output).unwrap() = name; |
| 536 | } |
| 537 | wl_output::Event::Description { .. } => (), |
| 538 | _ => unreachable!(), |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | impl Dispatch<WlCompositor, ()> for State { |
| 544 | fn event( |
| 545 | _state: &mut Self, |
| 546 | _proxy: &WlCompositor, |
| 547 | _event: <WlCompositor as wayland_client::Proxy>::Event, |
| 548 | _data: &(), |
| 549 | _conn: &Connection, |
| 550 | _qhandle: &QueueHandle<Self>, |
| 551 | ) { |
| 552 | unreachable!() |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | impl Dispatch<XdgWmBase, ()> for State { |
| 557 | fn event( |
| 558 | _state: &mut Self, |
| 559 | xdg_wm_base: &XdgWmBase, |
| 560 | event: <XdgWmBase as wayland_client::Proxy>::Event, |
| 561 | _data: &(), |
| 562 | _conn: &Connection, |
| 563 | _qhandle: &QueueHandle<Self>, |
| 564 | ) { |
| 565 | match event { |
| 566 | xdg_wm_base::Event::Ping { serial } => { |
| 567 | xdg_wm_base.pong(serial); |
| 568 | } |
| 569 | _ => unreachable!(), |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | impl Dispatch<ZwlrLayerShellV1, ()> for State { |
| 575 | fn event( |
| 576 | _state: &mut Self, |
| 577 | _proxy: &ZwlrLayerShellV1, |
| 578 | _event: <ZwlrLayerShellV1 as wayland_client::Proxy>::Event, |
| 579 | _data: &(), |
| 580 | _conn: &Connection, |
| 581 | _qhandle: &QueueHandle<Self>, |
| 582 | ) { |
| 583 | unreachable!() |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | impl Dispatch<WlSurface, ()> for State { |
| 588 | fn event( |
| 589 | _state: &mut Self, |
| 590 | _proxy: &WlSurface, |
| 591 | event: <WlSurface as wayland_client::Proxy>::Event, |
| 592 | _data: &(), |
| 593 | _conn: &Connection, |
| 594 | _qhandle: &QueueHandle<Self>, |
| 595 | ) { |
| 596 | match event { |
| 597 | wl_surface::Event::Enter { .. } => (), |
| 598 | wl_surface::Event::Leave { .. } => (), |
| 599 | wl_surface::Event::PreferredBufferScale { .. } => (), |
| 600 | wl_surface::Event::PreferredBufferTransform { .. } => (), |
| 601 | _ => unreachable!(), |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | impl Dispatch<XdgSurface, ()> for State { |
| 607 | fn event( |
| 608 | state: &mut Self, |
| 609 | xdg_surface: &XdgSurface, |
| 610 | event: <XdgSurface as wayland_client::Proxy>::Event, |
| 611 | _data: &(), |
| 612 | _conn: &Connection, |
| 613 | _qhandle: &QueueHandle<Self>, |
| 614 | ) { |
| 615 | match event { |
| 616 | xdg_surface::Event::Configure { serial } => { |
| 617 | let window = state |
| 618 | .windows |
| 619 | .iter_mut() |
| 620 | .find(|w| w.xdg_surface == *xdg_surface) |
| 621 | .unwrap(); |
| 622 | let configure = window.pending_configure.clone(); |
| 623 | window.configures_received.push((serial, configure)); |
| 624 | } |
| 625 | _ => unreachable!(), |
| 626 | } |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | impl Dispatch<XdgToplevel, ()> for State { |
| 631 | fn event( |
| 632 | state: &mut Self, |
| 633 | xdg_toplevel: &XdgToplevel, |
| 634 | event: <XdgToplevel as wayland_client::Proxy>::Event, |
| 635 | _data: &(), |
| 636 | _conn: &Connection, |
| 637 | _qhandle: &QueueHandle<Self>, |
| 638 | ) { |
| 639 | let window = state |
| 640 | .windows |
| 641 | .iter_mut() |
| 642 | .find(|w| w.xdg_toplevel == *xdg_toplevel) |
| 643 | .unwrap(); |
| 644 | |
| 645 | match event { |
| 646 | xdg_toplevel::Event::Configure { |
| 647 | width, |
| 648 | height, |
| 649 | states, |
| 650 | } => { |
| 651 | let configure = &mut window.pending_configure; |
| 652 | configure.size = (width, height); |
| 653 | configure.states = states |
| 654 | .chunks_exact(4) |
| 655 | .flat_map(TryInto::<[u8; 4]>::try_into) |
| 656 | .map(u32::from_ne_bytes) |
| 657 | .flat_map(xdg_toplevel::State::try_from) |
| 658 | .collect(); |
| 659 | } |
| 660 | xdg_toplevel::Event::Close => { |
| 661 | window.close_requested = true; |
| 662 | } |
| 663 | xdg_toplevel::Event::ConfigureBounds { width, height } => { |
| 664 | window.pending_configure.bounds = Some((width, height)); |
| 665 | } |
| 666 | xdg_toplevel::Event::WmCapabilities { .. } => (), |
| 667 | _ => unreachable!(), |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | impl Dispatch<ZwlrLayerSurfaceV1, ()> for State { |
| 673 | fn event( |
| 674 | state: &mut Self, |
| 675 | layer_surface: &ZwlrLayerSurfaceV1, |
| 676 | event: <ZwlrLayerSurfaceV1 as wayland_client::Proxy>::Event, |
| 677 | _data: &(), |
| 678 | _conn: &Connection, |
| 679 | _qhandle: &QueueHandle<Self>, |
| 680 | ) { |
| 681 | let layer_surface = state |
| 682 | .layers |
| 683 | .iter_mut() |
| 684 | .find(|w| w.layer_surface == *layer_surface) |
| 685 | .unwrap(); |
| 686 | |
| 687 | match event { |
| 688 | zwlr_layer_surface_v1::Event::Configure { |
| 689 | serial, |
| 690 | width, |
| 691 | height, |
| 692 | } => { |
| 693 | let configure = LayerConfigure { |
| 694 | size: (width, height), |
| 695 | }; |
| 696 | layer_surface.configures_received.push((serial, configure)); |
| 697 | } |
| 698 | zwlr_layer_surface_v1::Event::Closed => layer_surface.close_requested = true, |
| 699 | _ => unreachable!(), |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | impl Dispatch<WlBuffer, ()> for State { |
| 705 | fn event( |
| 706 | _state: &mut Self, |
| 707 | _proxy: &WlBuffer, |
| 708 | event: <WlBuffer as wayland_client::Proxy>::Event, |
| 709 | _data: &(), |
| 710 | _conn: &Connection, |
| 711 | _qhandle: &QueueHandle<Self>, |
| 712 | ) { |
| 713 | match event { |
| 714 | wl_buffer::Event::Release => (), |
| 715 | _ => unreachable!(), |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | impl Dispatch<WpSinglePixelBufferManagerV1, ()> for State { |
| 721 | fn event( |
| 722 | _state: &mut Self, |
| 723 | _proxy: &WpSinglePixelBufferManagerV1, |
| 724 | _event: <WpSinglePixelBufferManagerV1 as wayland_client::Proxy>::Event, |
| 725 | _data: &(), |
| 726 | _conn: &Connection, |
| 727 | _qhandle: &QueueHandle<Self>, |
| 728 | ) { |
| 729 | unreachable!() |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | impl Dispatch<WpViewporter, ()> for State { |
| 734 | fn event( |
| 735 | _state: &mut Self, |
| 736 | _proxy: &WpViewporter, |
| 737 | _event: <WpViewporter as wayland_client::Proxy>::Event, |
| 738 | _data: &(), |
| 739 | _conn: &Connection, |
| 740 | _qhandle: &QueueHandle<Self>, |
| 741 | ) { |
| 742 | unreachable!() |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | impl Dispatch<WpViewport, ()> for State { |
| 747 | fn event( |
| 748 | _state: &mut Self, |
| 749 | _proxy: &WpViewport, |
| 750 | _event: <WpViewport as wayland_client::Proxy>::Event, |
| 751 | _data: &(), |
| 752 | _conn: &Connection, |
| 753 | _qhandle: &QueueHandle<Self>, |
| 754 | ) { |
| 755 | unreachable!() |
| 756 | } |
| 757 | } |