Move UI to its own directory
This commit is contained in:
parent
89bcd620a6
commit
bdc1083b04
4 changed files with 67 additions and 60 deletions
62
src/main.rs
62
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<dyn std::error::Error>> {
|
||||
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()
|
||||
}
|
||||
|
|
|
|||
4
src/ui/mod.rs
Normal file
4
src/ui/mod.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
mod clock;
|
||||
mod ui;
|
||||
|
||||
pub use ui::run;
|
||||
61
src/ui/ui.rs
Normal file
61
src/ui/ui.rs
Normal file
|
|
@ -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<dyn std::error::Error>> {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue