From 379ac88a5a506ff7668fc9e8ded58a9f3f110a82 Mon Sep 17 00:00:00 2001 From: Richard Acayan Date: Thu, 25 Jul 2024 18:20:00 -0400 Subject: [PATCH] wayland: dispatcher: move overriding visibility manager to root D-Bus support is large, and should have an option to be excluded. Move the struct implementing D-Bus support from the dispatcher to the main file, so it can be replaced with a stub. --- src/main.rs | 17 ++++++++++++++++- src/wayland/dispatcher.rs | 36 +++++++----------------------------- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7aaf5b1..d5c5746 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,21 @@ use std::sync::Arc; use std::time::Instant; use tokio::task; use wayland_client::globals; +use zbus::InterfaceRef; + +pub struct VisibilityManager(InterfaceRef>); + +impl VisibilityManager { + pub fn set_visible(&self, visible: bool) + { + let osk = self.0.clone(); + + task::spawn(async move { + let osk = osk.get().await; + osk.set_visible(visible).await; + }); + } +} #[tokio::main(flavor = "current_thread")] async fn main() @@ -48,7 +63,7 @@ async fn main() let gfx = dispatcher.graphics(); let osk = OSK0::start(&conn_zbus, gfx, conn_wl.clone()).await; match osk { - Ok(k) => dispatcher.set_osk(k), + Ok(k) => dispatcher.set_osk(VisibilityManager(k)), Err(e) => eprintln!("warn: bind to sm.puri.OSK0 failed: {}", e), } diff --git a/src/wayland/dispatcher.rs b/src/wayland/dispatcher.rs index 43bb02d..6d1cbb5 100644 --- a/src/wayland/dispatcher.rs +++ b/src/wayland/dispatcher.rs @@ -3,11 +3,11 @@ * Copyright (c) 2024, Richard Acayan. All rights reserved. */ +use crate::VisibilityManager; use crate::core::Button; use crate::core::Display; use crate::core::Graphics; use crate::core::Layout; -use crate::dbus::osk::OSK0; use crate::wayland::Seat; use crate::wayland::Surface; use crate::wayland::VirtualKeyboard; @@ -24,7 +24,6 @@ use crate::wayland::virtual_keyboard_unstable_v1::zwp_virtual_keyboard_v1; use std::io::Error; use std::sync::Arc; use std::sync::Mutex; -use tokio::task; use wayland_client::Connection; use wayland_client::Dispatch; use wayland_client::Proxy; @@ -41,12 +40,11 @@ use wayland_client::protocol::wl_shm; use wayland_client::protocol::wl_shm_pool; use wayland_client::protocol::wl_surface; use wayland_client::protocol::wl_touch; -use zbus::InterfaceRef; pub struct Dispatcher { seat: Seat, VirtualKeyboard, Self>, gfx: Arc>>>, - osk: Option>>, + osk: Option, } impl Dispatcher { @@ -103,13 +101,15 @@ impl Dispatcher { self.seat.button() } + #[allow(dead_code)] #[inline(always)] pub fn graphics(&self) -> Arc>>> { self.gfx.clone() } - pub fn set_osk(&mut self, osk: InterfaceRef>) + #[allow(dead_code)] + pub fn set_osk(&mut self, osk: VisibilityManager) { self.osk = Some(osk); } @@ -122,18 +122,7 @@ impl Dispatcher { fn show(&self) { match &self.osk { - Some(osk) => { - /* - * Clone the reference from the struct so it can be given to the - * spawned task. - */ - let osk = osk.clone(); - - task::spawn(async move { - let osk = osk.get().await; - osk.set_visible(true).await; - }); - }, + Some(osk) => osk.set_visible(true), None => { let mut gfx = self.gfx.lock().unwrap(); gfx.display_mut().show(); @@ -144,18 +133,7 @@ impl Dispatcher { fn hide(&self) { match &self.osk { - Some(osk) => { - /* - * Clone the reference from the struct so it can be given to the - * spawned task. - */ - let osk = osk.clone(); - - task::spawn(async move { - let osk = osk.get().await; - osk.set_visible(false).await; - }); - }, + Some(osk) => osk.set_visible(false), None => { let mut gfx = self.gfx.lock().unwrap(); gfx.display_mut().hide();