summaryrefslogtreecommitdiff
path: root/src/output.rs
diff options
context:
space:
mode:
authorMaxVerevkin <maxxverrr@gmail.com>2023-08-03 13:56:14 +0300
committerMaxVerevkin <maxxverrr@gmail.com>2023-08-03 13:56:14 +0300
commite36c1aaff019b2d4633763ddf191aa2192cba4c4 (patch)
tree4632ade2c318dd8cbf63668ebdc50a681811044c /src/output.rs
parent8ceaa7cf022564d8e0d92602724d465eaf388258 (diff)
downloadi3bar-mango-e36c1aaff019b2d4633763ddf191aa2192cba4c4.tar.gz
refactor wl_output stuff into its own mod, require wl_output v4 (for name)
Diffstat (limited to 'src/output.rs')
-rw-r--r--src/output.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/output.rs b/src/output.rs
new file mode 100644
index 0000000..9e1b78c
--- /dev/null
+++ b/src/output.rs
@@ -0,0 +1,54 @@
+use wayrs_client::global::{Global, GlobalExt};
+use wayrs_client::protocol::*;
+use wayrs_client::Connection;
+
+use crate::state::State;
+
+pub struct Output {
+ pub wl: WlOutput,
+ pub reg_name: u32,
+ pub scale: u32,
+}
+
+impl Output {
+ pub fn bind(conn: &mut Connection<State>, global: &Global) -> Self {
+ Self {
+ wl: global
+ .bind_with_cb(conn, 4, wl_output_cb)
+ .expect("could not bind wl_output"),
+ reg_name: global.name,
+ scale: 1,
+ }
+ }
+
+ pub fn destroy(self, conn: &mut Connection<State>) {
+ self.wl.release(conn);
+ }
+}
+
+fn wl_output_cb(
+ conn: &mut Connection<State>,
+ state: &mut State,
+ output: WlOutput,
+ event: wl_output::Event,
+) {
+ match event {
+ wl_output::Event::Name(name) => {
+ let i = state
+ .pending_outputs
+ .iter()
+ .position(|o| o.wl == output)
+ .unwrap();
+ let output = state.pending_outputs.swap_remove(i);
+ state.register_output(conn, output, name.to_str().expect("invalid output name"));
+ }
+ wl_output::Event::Scale(scale) => {
+ if let Some(bar) = state.bars.iter_mut().find(|bar| bar.output.wl == output) {
+ bar.scale = scale as u32;
+ } else if let Some(output) = state.pending_outputs.iter_mut().find(|o| o.wl == output) {
+ output.scale = scale as u32;
+ }
+ }
+ _ => (),
+ }
+}