add dbus osk and session support

The D-Bus interfaces used by Phosh are org.gnome.SessionManager for
recovering critical services from crashes and sm.puri.OSK0 for manual
on-screen keyboard activation. Add support for them.
This commit is contained in:
Richard Acayan 2024-07-24 22:39:16 -04:00
parent 397323b582
commit 4fd0c82997
6 changed files with 283 additions and 30 deletions

View file

@ -7,6 +7,7 @@ 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;
@ -23,6 +24,7 @@ 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;
@ -39,10 +41,12 @@ 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>>>,
}
impl Dispatcher {
@ -89,6 +93,7 @@ impl Dispatcher {
Ok(Dispatcher {
seat,
gfx,
osk: None,
})
}
@ -98,6 +103,17 @@ impl Dispatcher {
self.seat.button()
}
#[inline(always)]
pub fn graphics(&self) -> Arc<Mutex<Graphics<Surface<Self>>>>
{
self.gfx.clone()
}
pub fn set_osk(&mut self, osk: InterfaceRef<OSK0<Self>>)
{
self.osk = Some(osk);
}
pub fn dispatch_timers(&mut self)
{
self.seat.button_mut().dispatch_timers();
@ -105,14 +121,46 @@ impl Dispatcher {
fn show(&self)
{
let mut gfx = self.gfx.lock().unwrap();
gfx.display_mut().show();
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;
});
},
None => {
let mut gfx = self.gfx.lock().unwrap();
gfx.display_mut().show();
},
}
}
fn hide(&self)
{
let mut gfx = self.gfx.lock().unwrap();
gfx.display_mut().hide();
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;
});
},
None => {
let mut gfx = self.gfx.lock().unwrap();
gfx.display_mut().hide();
},
}
}
}