diff --git a/src/main.rs b/src/main.rs index e7ac9c3..f26e39d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,63 +1,5 @@ -mod clock; - -use clock::ClockApp; -use smithay_client_toolkit::{ - compositor::CompositorState, - output::OutputState, - registry::RegistryState, - shell::{ - wlr_layer::{Anchor, KeyboardInteractivity, Layer, LayerShell}, - WaylandSurface, - }, - shm::Shm, -}; -use wayland_client::globals::registry_queue_init; -use wayland_client::Connection; +mod ui; fn main() -> Result<(), Box> { - let conn = Connection::connect_to_env()?; - let (globals, mut event_queue) = registry_queue_init(&conn)?; - let qh = event_queue.handle(); - - let mut app = ClockApp { - registry_state: RegistryState::new(&globals), - output_state: OutputState::new(&globals, &qh), - compositor_state: CompositorState::bind(&globals, &qh)?, - shm_state: Shm::bind(&globals, &qh)?, - layer_shell: LayerShell::bind(&globals, &qh)?, - - pool: None, - width: 400, - height: 200, - layer_surface: None, - configured: false, - }; - - // Create the layer surface - let surface = app.compositor_state.create_surface(&qh); - let layer_surface = app.layer_shell.create_layer_surface( - &qh, - surface, - Layer::Top, - Some("clock"), - None, - ); - - layer_surface.set_anchor(Anchor::TOP | Anchor::LEFT | Anchor::RIGHT); - layer_surface.set_size(app.width, app.height); - layer_surface.set_exclusive_zone(app.height as i32); - layer_surface.set_keyboard_interactivity(KeyboardInteractivity::None); - layer_surface.commit(); - - app.layer_surface = Some(layer_surface); - - loop { - event_queue.blocking_dispatch(&mut app)?; - - if app.configured { - app.draw(&qh)?; - // Sleep briefly to reduce CPU usage - std::thread::sleep(std::time::Duration::from_millis(500)); - } - } + ui::run() } diff --git a/src/clock.rs b/src/ui/clock.rs similarity index 100% rename from src/clock.rs rename to src/ui/clock.rs diff --git a/src/ui/mod.rs b/src/ui/mod.rs new file mode 100644 index 0000000..664810c --- /dev/null +++ b/src/ui/mod.rs @@ -0,0 +1,4 @@ +mod clock; +mod ui; + +pub use ui::run; diff --git a/src/ui/ui.rs b/src/ui/ui.rs new file mode 100644 index 0000000..8d7f0cf --- /dev/null +++ b/src/ui/ui.rs @@ -0,0 +1,61 @@ +use super::clock::ClockApp; +use smithay_client_toolkit::{ + compositor::CompositorState, + output::OutputState, + registry::RegistryState, + shell::{ + wlr_layer::{Anchor, KeyboardInteractivity, Layer, LayerShell}, + WaylandSurface, + }, + shm::Shm, +}; +use wayland_client::globals::registry_queue_init; +use wayland_client::Connection; + +pub fn run() -> Result<(), Box> { + let conn = Connection::connect_to_env()?; + let (globals, mut event_queue) = registry_queue_init(&conn)?; + let qh = event_queue.handle(); + + let mut app = ClockApp { + registry_state: RegistryState::new(&globals), + output_state: OutputState::new(&globals, &qh), + compositor_state: CompositorState::bind(&globals, &qh)?, + shm_state: Shm::bind(&globals, &qh)?, + layer_shell: LayerShell::bind(&globals, &qh)?, + + pool: None, + width: 400, + height: 200, + layer_surface: None, + configured: false, + }; + + // Create the layer surface + let surface = app.compositor_state.create_surface(&qh); + let layer_surface = app.layer_shell.create_layer_surface( + &qh, + surface, + Layer::Top, + Some("clock"), + None, + ); + + layer_surface.set_anchor(Anchor::TOP | Anchor::LEFT | Anchor::RIGHT); + layer_surface.set_size(app.width, app.height); + layer_surface.set_exclusive_zone(app.height as i32); + layer_surface.set_keyboard_interactivity(KeyboardInteractivity::None); + layer_surface.commit(); + + app.layer_surface = Some(layer_surface); + + loop { + event_queue.blocking_dispatch(&mut app)?; + + if app.configured { + app.draw(&qh)?; + // Sleep briefly to reduce CPU usage + std::thread::sleep(std::time::Duration::from_millis(500)); + } + } +}