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:
parent
397323b582
commit
4fd0c82997
6 changed files with 283 additions and 30 deletions
79
src/main.rs
79
src/main.rs
|
|
@ -4,23 +4,29 @@
|
|||
*/
|
||||
|
||||
mod core;
|
||||
mod dbus;
|
||||
mod wayland;
|
||||
|
||||
use crate::core::Layout;
|
||||
use crate::dbus::session;
|
||||
use crate::dbus::osk::OSK0;
|
||||
use crate::wayland::Dispatcher;
|
||||
use polling::Event;
|
||||
use polling::Events;
|
||||
use polling::Poller;
|
||||
use std::future::pending;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use wayland_client::Connection;
|
||||
use tokio::task;
|
||||
use wayland_client::globals;
|
||||
|
||||
fn main()
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main()
|
||||
{
|
||||
let conn = Connection::connect_to_env().unwrap();
|
||||
let conn_wl = wayland_client::Connection::connect_to_env().unwrap();
|
||||
|
||||
let (globals, mut queue) = globals::registry_queue_init::<Dispatcher>(&conn)
|
||||
let (globals, mut queue) = globals::registry_queue_init::<Dispatcher>(&conn_wl)
|
||||
.expect("Registry required");
|
||||
|
||||
let layouts = Path::new("/usr/share/unfettered-keyboard/layouts");
|
||||
|
|
@ -29,29 +35,50 @@ fn main()
|
|||
let mut dispatcher = Dispatcher::new(layout, queue.handle(), &globals).unwrap();
|
||||
|
||||
let wl_evt = Event::readable(0);
|
||||
let poller = Poller::new().unwrap();
|
||||
let mut events = Events::new();
|
||||
|
||||
loop {
|
||||
queue.flush().unwrap();
|
||||
let conn_zbus = zbus::Connection::session().await.unwrap();
|
||||
|
||||
let guard = queue.prepare_read().unwrap();
|
||||
let fd = guard.connection_fd();
|
||||
let timer = dispatcher.button().next_time().map(|t| t - Instant::now());
|
||||
|
||||
unsafe {
|
||||
poller.add(&fd, wl_evt).unwrap();
|
||||
}
|
||||
|
||||
events.clear();
|
||||
poller.wait(&mut events, timer).unwrap();
|
||||
poller.delete(fd).unwrap();
|
||||
|
||||
if !events.is_empty() {
|
||||
guard.read().unwrap();
|
||||
queue.dispatch_pending(&mut dispatcher).unwrap();
|
||||
}
|
||||
|
||||
dispatcher.dispatch_timers();
|
||||
let res = session::register(&conn_zbus).await;
|
||||
if let Err(e) = res {
|
||||
eprintln!("warn: GNOME session registration failed: {}", e);
|
||||
}
|
||||
|
||||
let conn_wl = Arc::new(conn_wl);
|
||||
|
||||
let gfx = dispatcher.graphics();
|
||||
let osk = OSK0::start(&conn_zbus, gfx, conn_wl.clone()).await;
|
||||
match osk {
|
||||
Ok(k) => dispatcher.set_osk(k),
|
||||
Err(e) => eprintln!("warn: bind to sm.puri.OSK0 failed: {}", e),
|
||||
}
|
||||
|
||||
let mut events = Events::new();
|
||||
let poller = Poller::new().unwrap();
|
||||
|
||||
task::spawn_blocking(move || {
|
||||
loop {
|
||||
conn_wl.flush().unwrap();
|
||||
|
||||
let guard = queue.prepare_read().unwrap();
|
||||
let fd = guard.connection_fd();
|
||||
let timer = dispatcher.button().next_time().map(|t| t - Instant::now());
|
||||
|
||||
unsafe {
|
||||
poller.add(&fd, wl_evt).unwrap();
|
||||
}
|
||||
|
||||
events.clear();
|
||||
poller.wait(&mut events, timer).unwrap();
|
||||
poller.delete(fd).unwrap();
|
||||
|
||||
if !events.is_empty() {
|
||||
guard.read().unwrap();
|
||||
queue.dispatch_pending(&mut dispatcher).unwrap();
|
||||
}
|
||||
|
||||
dispatcher.dispatch_timers();
|
||||
}
|
||||
});
|
||||
|
||||
pending::<()>().await;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue