diff --git a/Cargo.toml b/Cargo.toml index 374d6c4..b396ede 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,3 +24,11 @@ zbus = { version = "4.4.0", default-features = false, features = ["tokio"] } [build-dependencies] bindgen = "0.69.4" + +[[bin]] +name = "ufkbd-gnome" +path = "src/ufkbd_gnome.rs" + +[[bin]] +name = "ufkbd-wl" +path = "src/ufkbd_wl.rs" diff --git a/src/main.rs b/src/ufkbd_gnome.rs similarity index 100% rename from src/main.rs rename to src/ufkbd_gnome.rs diff --git a/src/ufkbd_wl.rs b/src/ufkbd_wl.rs new file mode 100644 index 0000000..a053a80 --- /dev/null +++ b/src/ufkbd_wl.rs @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Copyright (c) 2024, Richard Acayan. All rights reserved. + */ + +mod core; +mod wayland; + +use crate::core::Layout; +use crate::wayland::Dispatcher; +use polling::Event; +use polling::Events; +use polling::Poller; +use std::path::Path; +use std::time::Instant; +use wayland_client::globals; + +pub struct VisibilityManager(); + +impl VisibilityManager { + pub fn set_visible(&self, _visible: bool) + { + unreachable!(); + } +} + +fn main() +{ + let conn = wayland_client::Connection::connect_to_env().unwrap(); + + let (globals, mut queue) = globals::registry_queue_init::(&conn) + .expect("Registry required"); + + let layouts = Path::new("/usr/share/unfettered-keyboard/layouts"); + let layout = Layout::load(layouts, "latn_qwerty_us.xml") + .expect("Layout should be loadable"); + let mut dispatcher = Dispatcher::new(layout, queue.handle(), &globals).unwrap(); + + let wl_evt = Event::readable(0); + + let mut events = Events::new(); + let poller = Poller::new().unwrap(); + + loop { + conn.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(); + } +}