summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bar.rs5
-rw-r--r--src/shared_state.rs8
-rw-r--r--src/state.rs34
-rw-r--r--src/wm_info_provider.rs30
-rw-r--r--src/wm_info_provider/dummy.rs9
-rw-r--r--src/wm_info_provider/hyprland.rs6
6 files changed, 45 insertions, 47 deletions
diff --git a/src/bar.rs b/src/bar.rs
index d616008..f8434ef 100644
--- a/src/bar.rs
+++ b/src/bar.rs
@@ -120,9 +120,8 @@ impl Bar {
_y: f64,
) -> anyhow::Result<()> {
if let Some(tag_id) = self.tags_btns.click(x) {
- if let Some(wm) = &mut ss.wm_info_provider {
- wm.click_on_tag(conn, self.output.wl, seat, *tag_id, button);
- }
+ ss.wm_info_provider
+ .click_on_tag(conn, self.output.wl, seat, *tag_id, button);
} else if let Some((name, instance)) = self.blocks_btns.click(x) {
if let Some(cmd) = &mut ss.status_cmd {
cmd.send_click_event(&i3bar_protocol::Event {
diff --git a/src/shared_state.rs b/src/shared_state.rs
index 50ab77a..1970c0c 100644
--- a/src/shared_state.rs
+++ b/src/shared_state.rs
@@ -12,15 +12,15 @@ pub struct SharedState {
pub config: Config,
pub status_cmd: Option<StatusCmd>,
pub blocks_cache: BlocksCache,
- pub wm_info_provider: Option<Box<dyn WmInfoProvider>>,
+ pub wm_info_provider: Box<dyn WmInfoProvider>,
}
impl SharedState {
pub fn get_river(&mut self) -> Option<&mut wm_info_provider::RiverInfoProvider> {
- self.wm_info_provider.as_mut()?.as_any().downcast_mut()
+ self.wm_info_provider.as_any().downcast_mut()
}
- pub fn get_hyprland(&mut self) -> Option<&mut wm_info_provider::Hyprland> {
- self.wm_info_provider.as_mut()?.as_any().downcast_mut()
+ pub fn get_hyprland(&mut self) -> Option<&mut wm_info_provider::HyprlandInfoProvider> {
+ self.wm_info_provider.as_any().downcast_mut()
}
}
diff --git a/src/state.rs b/src/state.rs
index 92bf834..6556298 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -81,9 +81,7 @@ impl State {
.ok();
let wm_info_provider = wm_info_provider::bind(conn, globals, &config.wm);
- if let Some(wm) = &wm_info_provider {
- wm.register(event_loop);
- }
+ wm_info_provider.register(event_loop);
let mut this = Self {
wl_compositor,
@@ -157,15 +155,11 @@ impl State {
return;
}
- if let Some(wm) = &mut self.shared_state.wm_info_provider {
- wm.new_ouput(conn, &output);
- }
+ self.shared_state.wm_info_provider.new_ouput(conn, &output);
let mut bar = Bar::new(conn, self, output);
- if let Some(wm) = &self.shared_state.wm_info_provider {
- bar.set_tags(wm.get_tags(&bar.output));
- }
+ bar.set_tags(self.shared_state.wm_info_provider.get_tags(&bar.output));
if !self.hidden {
bar.show(conn, &self.shared_state);
@@ -176,9 +170,9 @@ impl State {
pub fn drop_bar(&mut self, conn: &mut Connection<Self>, bar_index: usize) {
let bar = self.bars.swap_remove(bar_index);
- if let Some(wm) = &mut self.shared_state.wm_info_provider {
- wm.output_removed(conn, &bar.output);
- }
+ self.shared_state
+ .wm_info_provider
+ .output_removed(conn, &bar.output);
bar.destroy(conn);
}
@@ -215,31 +209,21 @@ impl State {
pub fn tags_updated(&mut self, conn: &mut Connection<Self>, output: Option<WlOutput>) {
self.for_each_bar(output, |bar, ss| {
- bar.set_tags(ss.wm_info_provider.as_mut().unwrap().get_tags(&bar.output));
+ bar.set_tags(ss.wm_info_provider.get_tags(&bar.output));
bar.request_frame(conn);
});
}
pub fn layout_name_updated(&mut self, conn: &mut Connection<Self>, output: Option<WlOutput>) {
self.for_each_bar(output, |bar, ss| {
- bar.set_layout_name(
- ss.wm_info_provider
- .as_mut()
- .unwrap()
- .get_layout_name(&bar.output),
- );
+ bar.set_layout_name(ss.wm_info_provider.get_layout_name(&bar.output));
bar.request_frame(conn);
});
}
pub fn mode_name_updated(&mut self, conn: &mut Connection<Self>, output: Option<WlOutput>) {
self.for_each_bar(output, |bar, ss| {
- bar.set_mode_name(
- ss.wm_info_provider
- .as_mut()
- .unwrap()
- .get_mode_name(&bar.output),
- );
+ bar.set_mode_name(ss.wm_info_provider.get_mode_name(&bar.output));
bar.request_frame(conn);
});
}
diff --git a/src/wm_info_provider.rs b/src/wm_info_provider.rs
index 25eef05..59e0511 100644
--- a/src/wm_info_provider.rs
+++ b/src/wm_info_provider.rs
@@ -10,6 +10,9 @@ use crate::pointer_btn::PointerBtn;
use crate::protocol::*;
use crate::state::State;
+mod dummy;
+pub use dummy::*;
+
mod river;
pub use river::*;
@@ -22,7 +25,9 @@ pub trait WmInfoProvider {
fn new_ouput(&mut self, _: &mut Connection<State>, _: &Output) {}
fn output_removed(&mut self, _: &mut Connection<State>, _: &Output) {}
- fn get_tags(&self, output: &Output) -> Vec<Tag>;
+ fn get_tags(&self, _: &Output) -> Vec<Tag> {
+ Vec::new()
+ }
fn get_layout_name(&self, _: &Output) -> Option<String> {
None
}
@@ -32,12 +37,13 @@ pub trait WmInfoProvider {
fn click_on_tag(
&mut self,
- conn: &mut Connection<State>,
- output: WlOutput,
- seat: WlSeat,
- tag_id: u32,
- btn: PointerBtn,
- );
+ _conn: &mut Connection<State>,
+ _output: WlOutput,
+ _seat: WlSeat,
+ _tag_id: u32,
+ _btn: PointerBtn,
+ ) {
+ }
fn as_any(&mut self) -> &mut dyn Any;
}
@@ -46,16 +52,16 @@ pub fn bind(
conn: &mut Connection<State>,
globals: &Globals,
config: &WmConfig,
-) -> Option<Box<dyn WmInfoProvider>> {
+) -> Box<dyn WmInfoProvider> {
if let Some(river) = RiverInfoProvider::bind(conn, globals, config) {
- return Some(Box::new(river));
+ return Box::new(river);
}
- if let Some(hyprland) = Hyprland::new() {
- return Some(Box::new(hyprland));
+ if let Some(hyprland) = HyprlandInfoProvider::new() {
+ return Box::new(hyprland);
}
- None
+ Box::new(DummyInfoProvider)
}
#[derive(Debug)]
diff --git a/src/wm_info_provider/dummy.rs b/src/wm_info_provider/dummy.rs
new file mode 100644
index 0000000..72903c7
--- /dev/null
+++ b/src/wm_info_provider/dummy.rs
@@ -0,0 +1,9 @@
+use super::*;
+
+pub struct DummyInfoProvider;
+
+impl WmInfoProvider for DummyInfoProvider {
+ fn as_any(&mut self) -> &mut dyn Any {
+ self
+ }
+}
diff --git a/src/wm_info_provider/hyprland.rs b/src/wm_info_provider/hyprland.rs
index 1233e66..c754806 100644
--- a/src/wm_info_provider/hyprland.rs
+++ b/src/wm_info_provider/hyprland.rs
@@ -10,13 +10,13 @@ use crate::event_loop::{self, EventLoop};
use crate::state::State;
use crate::utils::read_to_vec;
-pub struct Hyprland {
+pub struct HyprlandInfoProvider {
ipc: Ipc,
workspaces: Vec<IpcWorkspace>,
active_id: u32,
}
-impl Hyprland {
+impl HyprlandInfoProvider {
pub fn new() -> Option<Self> {
let his = std::env::var("HYPRLAND_INSTANCE_SIGNATURE").ok()?;
let ipc = Ipc::new(&his).ok()?;
@@ -28,7 +28,7 @@ impl Hyprland {
}
}
-impl WmInfoProvider for Hyprland {
+impl WmInfoProvider for HyprlandInfoProvider {
fn register(&self, event_loop: &mut EventLoop) {
event_loop.register_with_fd(self.ipc.sock2.as_raw_fd(), |ctx| {
match hyprland_cb(ctx.conn, ctx.state) {