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.
This commit is contained in:
parent
15c9402b99
commit
379ac88a5a
2 changed files with 23 additions and 30 deletions
17
src/main.rs
17
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<OSK0<Dispatcher>>);
|
||||
|
||||
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),
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Surface<Self>, VirtualKeyboard, Self>,
|
||||
gfx: Arc<Mutex<Graphics<Surface<Self>>>>,
|
||||
osk: Option<InterfaceRef<OSK0<Self>>>,
|
||||
osk: Option<VisibilityManager>,
|
||||
}
|
||||
|
||||
impl Dispatcher {
|
||||
|
|
@ -103,13 +101,15 @@ impl Dispatcher {
|
|||
self.seat.button()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[inline(always)]
|
||||
pub fn graphics(&self) -> Arc<Mutex<Graphics<Surface<Self>>>>
|
||||
{
|
||||
self.gfx.clone()
|
||||
}
|
||||
|
||||
pub fn set_osk(&mut self, osk: InterfaceRef<OSK0<Self>>)
|
||||
#[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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue