From f46e8708645a6971965f294bbbb9f9f520a516d6 Mon Sep 17 00:00:00 2001 From: Nova Date: Sun, 22 Jan 2023 02:38:40 -0500 Subject: [PATCH] refactor(wayland): remove SeatData wrapper --- src/wayland/panel_item.rs | 4 +- src/wayland/seat.rs | 88 +++++++++++++++++---------------------- src/wayland/state.rs | 2 +- 3 files changed, 41 insertions(+), 53 deletions(-) diff --git a/src/wayland/panel_item.rs b/src/wayland/panel_item.rs index 81b2a60..6ea2cd7 100644 --- a/src/wayland/panel_item.rs +++ b/src/wayland/panel_item.rs @@ -111,14 +111,14 @@ pub struct PanelItem { client_credentials: Option, toplevel: WlWeak, pub cursor: Mutex>>, - seat_data: SeatData, + seat_data: Arc, } impl PanelItem { pub fn create( toplevel: XdgToplevel, wl_surface: WlSurface, client_credentials: Option, - seat_data: SeatData, + seat_data: Arc, ) -> (Arc, Arc) { debug!(?toplevel, ?client_credentials, "Create panel item"); let node = Arc::new(Node::create( diff --git a/src/wayland/seat.rs b/src/wayland/seat.rs index 0483942..ab0a7d0 100644 --- a/src/wayland/seat.rs +++ b/src/wayland/seat.rs @@ -32,42 +32,12 @@ use smithay::{ }; use std::{ collections::VecDeque, - ops::Deref, sync::{Arc, Weak}, time::{Duration, Instant}, }; use tracing::{debug, warn}; use xkbcommon::xkb::{self, Keymap}; -#[derive(Clone)] -pub struct SeatData(Arc); -impl SeatData { - pub fn new(dh: &DisplayHandle, client: ClientId) -> Self { - let seat_data = SeatData(Arc::new(SeatDataInner { - client, - global_id: OnceCell::new(), - panels: Mutex::new(FxHashMap::default()), - pointer: OnceCell::new(), - keyboard: OnceCell::new(), - touch: OnceCell::new(), - })); - - seat_data - .global_id - .set(dh.create_global::(7, seat_data.clone())) - .unwrap(); - - seat_data - } -} -impl Deref for SeatData { - type Target = SeatDataInner; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - pub struct KeyboardInfo { keymap: KeymapFile, state: xkb::State, @@ -160,7 +130,7 @@ impl PanelInfo { keyboard_info: None, } } - pub fn set_pointer_active(&mut self, seat_data: &SeatDataInner, active: bool) { + pub fn set_pointer_active(&mut self, seat_data: &SeatData, active: bool) { if active && self.pointer_queue.is_none() { self.pointer_queue.replace(Default::default()); } @@ -248,7 +218,7 @@ impl PanelInfo { locked } - pub fn set_keyboard_active(&mut self, seat_data: &SeatDataInner, active: bool) { + pub fn set_keyboard_active(&mut self, seat_data: &SeatData, active: bool) { if active && self.keyboard_queue.is_none() { self.keyboard_queue.replace(Default::default()); } @@ -294,7 +264,7 @@ impl PanelInfo { } } -pub struct SeatDataInner { +pub struct SeatData { client: ClientId, global_id: OnceCell, panels: Mutex>, @@ -302,7 +272,25 @@ pub struct SeatDataInner { keyboard: OnceCell<(WlKeyboard, Mutex>)>, touch: OnceCell, } -impl SeatDataInner { +impl SeatData { + pub fn new(dh: &DisplayHandle, client: ClientId) -> Arc { + let seat_data = Arc::new(SeatData { + client, + global_id: OnceCell::new(), + panels: Mutex::new(FxHashMap::default()), + pointer: OnceCell::new(), + keyboard: OnceCell::new(), + touch: OnceCell::new(), + }); + + seat_data + .global_id + .set(dh.create_global::(7, seat_data.clone())) + .unwrap(); + + seat_data + } + // pub fn set_focus(&self, toplevel: &WlSurface, focus: &WlSurface) { // if let Some(panel_info) = self.panels.lock().get_mut(&toplevel.id()) { // panel_info.focus = focus.downgrade(); @@ -445,7 +433,7 @@ impl SeatDataInner { } } } -impl Drop for SeatDataInner { +impl Drop for SeatData { fn drop(&mut self) { let id = self.global_id.take().unwrap(); let _ = task::new(|| "global destroy queue garbage collection", async move { @@ -454,13 +442,13 @@ impl Drop for SeatDataInner { } } -impl GlobalDispatch for WaylandState { +impl GlobalDispatch, WaylandState> for WaylandState { fn bind( _state: &mut WaylandState, _handle: &DisplayHandle, _client: &Client, resource: New, - data: &SeatData, + data: &Arc, data_init: &mut DataInit<'_, WaylandState>, ) { let resource = data_init.init(resource, data.clone()); @@ -472,33 +460,33 @@ impl GlobalDispatch for WaylandState { resource.capabilities(Capability::Pointer | Capability::Keyboard); } - fn can_view(client: Client, data: &SeatData) -> bool { - client.id() == data.0.client + fn can_view(client: Client, data: &Arc) -> bool { + client.id() == data.client } } -impl Dispatch for WaylandState { +impl Dispatch, WaylandState> for WaylandState { fn request( _state: &mut WaylandState, _client: &Client, _resource: &WlSeat, request: wl_seat::Request, - data: &SeatData, + data: &Arc, _dh: &DisplayHandle, data_init: &mut DataInit<'_, WaylandState>, ) { match request { wl_seat::Request::GetPointer { id } => { let pointer = data_init.init(id, data.clone()); - let _ = data.0.pointer.set((pointer, Mutex::new(None))); + let _ = data.pointer.set((pointer, Mutex::new(None))); } wl_seat::Request::GetKeyboard { id } => { let keyboard = data_init.init(id, data.clone()); keyboard.repeat_info(0, 0); - let _ = data.0.keyboard.set((keyboard, Mutex::new(None))); + let _ = data.keyboard.set((keyboard, Mutex::new(None))); } wl_seat::Request::GetTouch { id } => { - let _ = data.0.touch.set(data_init.init(id, data.clone())); + let _ = data.touch.set(data_init.init(id, data.clone())); } wl_seat::Request::Release => (), _ => unreachable!(), @@ -509,13 +497,13 @@ impl Dispatch for WaylandState { pub struct Cursor { pub hotspot: Vector2, } -impl Dispatch for WaylandState { +impl Dispatch, WaylandState> for WaylandState { fn request( state: &mut WaylandState, _client: &Client, _resource: &WlPointer, request: wl_pointer::Request, - seat_data: &SeatData, + seat_data: &Arc, dh: &DisplayHandle, _data_init: &mut DataInit<'_, WaylandState>, ) { @@ -557,13 +545,13 @@ impl Dispatch for WaylandState { } } -impl Dispatch for WaylandState { +impl Dispatch, WaylandState> for WaylandState { fn request( _state: &mut WaylandState, _client: &Client, _resource: &WlKeyboard, request: ::Request, - _data: &SeatData, + _data: &Arc, _dh: &DisplayHandle, _data_init: &mut DataInit<'_, WaylandState>, ) { @@ -574,13 +562,13 @@ impl Dispatch for WaylandState { } } -impl Dispatch for WaylandState { +impl Dispatch, WaylandState> for WaylandState { fn request( _state: &mut WaylandState, _client: &Client, _resource: &WlTouch, request: ::Request, - _data: &SeatData, + _data: &Arc, _dh: &DisplayHandle, _data_init: &mut DataInit<'_, WaylandState>, ) { diff --git a/src/wayland/state.rs b/src/wayland/state.rs index d3f3b86..dad1a40 100644 --- a/src/wayland/state.rs +++ b/src/wayland/state.rs @@ -61,7 +61,7 @@ pub struct WaylandState { pub dmabuf_global: DmabufGlobal, pub pending_dmabufs: Vec, pub output: Output, - pub seats: FxHashMap, + pub seats: FxHashMap>, } impl WaylandState {