From 568ebb0060577501d0877cb88abdbc8fbcd0b1fa Mon Sep 17 00:00:00 2001 From: Nova Date: Wed, 4 Jan 2023 07:25:22 -0500 Subject: [PATCH] feat(wayland): serial counter --- Cargo.toml | 1 + src/wayland/mod.rs | 3 +++ src/wayland/panel_item.rs | 20 ++++++++++---------- src/wayland/seat.rs | 3 ++- src/wayland/xdg_shell.rs | 9 +++++---- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 022f708..392b1a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ serde = { version = "1.0.145", features = ["derive"] } tracing = "0.1.37" tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } tracing-slog = "0.2.0" +global_counter = "0.2.2" [dependencies.stereokit] default-features = false diff --git a/src/wayland/mod.rs b/src/wayland/mod.rs index 55a56f9..a5a1837 100644 --- a/src/wayland/mod.rs +++ b/src/wayland/mod.rs @@ -12,6 +12,7 @@ mod xdg_shell; use self::{state::WaylandState, surface::CORE_SURFACES}; use crate::wayland::state::ClientState; use color_eyre::eyre::{ensure, Result}; +use global_counter::primitive::exact::CounterU32; use once_cell::sync::OnceCell; use parking_lot::Mutex; use slog::Drain; @@ -32,6 +33,8 @@ use tokio::{ }; use tracing::info; +pub static SERIAL_COUNTER: CounterU32 = CounterU32::new(0); + struct EGLRawHandles { display: *const c_void, config: *const c_void, diff --git a/src/wayland/panel_item.rs b/src/wayland/panel_item.rs index a1d05e7..6b2c190 100644 --- a/src/wayland/panel_item.rs +++ b/src/wayland/panel_item.rs @@ -2,6 +2,7 @@ use super::{ seat::{Cursor, KeyboardInfo, SeatData}, surface::CoreSurface, xdg_shell::{XdgSurfaceData, XdgToplevelData}, + SERIAL_COUNTER, }; use crate::{ core::{ @@ -26,7 +27,6 @@ use smithay::{ wayland_protocols::xdg::shell::server::xdg_toplevel::{ XdgToplevel, EVT_CONFIGURE_BOUNDS_SINCE, EVT_WM_CAPABILITIES_SINCE, }, - wayland_protocols_wlr::foreign_toplevel::v1::server::zwlr_foreign_toplevel_handle_v1::State, wayland_server::{ backend::Credentials, protocol::{ @@ -307,7 +307,7 @@ impl PanelItem { let Some(wl_surface) = core_surface.wl_surface() else { return Ok(()) }; let Some(pointer) = panel_item.seat_data.pointer() else { return Ok(()) }; - pointer.leave(0, &wl_surface); + pointer.leave(SERIAL_COUNTER.inc(), &wl_surface); *panel_item.seat_data.pointer_focus.lock() = None; pointer.frame(); core_surface.flush_clients(); @@ -334,11 +334,11 @@ impl PanelItem { .and_then(|surf| surf.upgrade().ok()) .filter(|surf| surf.id() != wl_surface.id()) { - pointer.leave(0, &old_surface); + pointer.leave(SERIAL_COUNTER.inc(), &old_surface); *pointer_focus = None; } if pointer_focus.is_none() { - pointer.enter(0, &wl_surface, position.x, position.y); + pointer.enter(SERIAL_COUNTER.inc(), &wl_surface, position.x, position.y); *pointer_focus = Some(wl_surface.downgrade()); } else { pointer.motion(0, position.x, position.y); @@ -359,7 +359,7 @@ impl PanelItem { let (button, state): (u32, u32) = deserialize(data)?; pointer.button( - 0, + SERIAL_COUNTER.inc(), 0, button, match state { @@ -462,7 +462,7 @@ impl PanelItem { let mut keyboard_info = panel_item.seat_data.keyboard_info.lock(); if keyboard_info.is_none() { - keyboard.enter(0, &wl_surface, vec![]); + keyboard.enter(SERIAL_COUNTER.inc(), &wl_surface, vec![]); keyboard.repeat_info(0, 0); } keyboard_info.replace(KeyboardInfo::new(keymap)); @@ -483,7 +483,7 @@ impl PanelItem { let mut keyboard_info = panel_item.seat_data.keyboard_info.lock(); if keyboard_info.is_some() { - keyboard.leave(0, &wl_surface); + keyboard.leave(SERIAL_COUNTER.inc(), &wl_surface); *keyboard_info = None; } @@ -534,7 +534,7 @@ impl PanelItem { } let size = info.size.unwrap_or(Vector2::from([0; 2])); xdg_toplevel.configure(size.x as i32, size.y as i32, info.states); - xdg_surface.configure(0); + xdg_surface.configure(SERIAL_COUNTER.inc()); Ok(()) } @@ -549,7 +549,7 @@ impl PanelItem { let Some(xdg_surface) = panel_item.toplevel_surface_data().and_then(|d| d.xdg_surface.upgrade().ok()) else { return Ok(()) }; xdg_toplevel.wm_capabilities(deserialize(data)?); - xdg_surface.configure(0); + xdg_surface.configure(SERIAL_COUNTER.inc()); Ok(()) } @@ -609,7 +609,7 @@ impl PanelItem { if focused_surface.id() == toplevel_surface.id() { let Some(pointer) = self.seat_data.pointer() else { return }; - pointer.leave(0, &toplevel_surface); + pointer.leave(SERIAL_COUNTER.inc(), &toplevel_surface); pointer.frame(); *self.seat_data.pointer_focus.lock() = None; } diff --git a/src/wayland/seat.rs b/src/wayland/seat.rs index 2cf1bfe..ad5b8b0 100644 --- a/src/wayland/seat.rs +++ b/src/wayland/seat.rs @@ -1,5 +1,6 @@ use super::{ panel_item::PanelItem, state::WaylandState, surface::CoreSurface, GLOBAL_DESTROY_QUEUE, + SERIAL_COUNTER, }; use color_eyre::eyre::Result; use mint::Vector2; @@ -66,7 +67,7 @@ impl KeyboardInfo { 0, ); } - keyboard.key(0, 0, key, wl_key_state); + keyboard.key(SERIAL_COUNTER.inc(), 0, key, wl_key_state); Ok(()) } } diff --git a/src/wayland/xdg_shell.rs b/src/wayland/xdg_shell.rs index 73ee135..7b968e4 100644 --- a/src/wayland/xdg_shell.rs +++ b/src/wayland/xdg_shell.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use super::{ panel_item::{PanelItem, RecommendedState, ToplevelState}, state::WaylandState, + SERIAL_COUNTER, }; use mint::Vector2; use parking_lot::Mutex; @@ -243,8 +244,8 @@ impl Dispatch for WaylandState { if toplevel.version() >= EVT_WM_CAPABILITIES_SINCE { toplevel.wm_capabilities(vec![]); } - toplevel.configure(0, 0, vec![]); - xdg_surface.configure(0); + toplevel.configure(0, 0, vec![1]); + xdg_surface.configure(SERIAL_COUNTER.inc()); let (node, item) = PanelItem::create( toplevel, @@ -264,8 +265,8 @@ impl Dispatch for WaylandState { data_init.init(id, ()); } xdg_surface::Request::SetWindowGeometry { - x: _, - y: _, + x, + y, width, height, } => {