From 46cbaca5e08a5be8945486d007c0f7315d10b351 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Mon, 1 Apr 2024 01:30:19 +0100 Subject: [PATCH] feat: option to disable module popup --- docs/Configuration guide.md | 1 + src/config/common.rs | 1 + src/modules/mod.rs | 32 +++++++++++++++++++------------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/docs/Configuration guide.md b/docs/Configuration guide.md index c269106..7caeaf5 100644 --- a/docs/Configuration guide.md +++ b/docs/Configuration guide.md @@ -332,6 +332,7 @@ For information on the `Script` type, and embedding scripts in strings, see [her | `show_if` | [Dynamic Boolean](dynamic-values#dynamic-boolean) | `null` | Polls the script to check its exit code. If exit code is zero, the module is shown. For other codes, it is hidden. | | `transition_type` | `slide_start` or `slide_end` or `crossfade` or `none` | `slide_start` | The transition animation to use when showing/hiding the widget. | | `transition_duration` | `integer` | `250` | The length of the transition animation to use when showing/hiding the widget. | +| `disable_popup` | `boolean` | `false` | Prevents the popup from opening on-click for this widget. | #### Appearance diff --git a/src/config/common.rs b/src/config/common.rs index 3e3cc85..fd207cf 100644 --- a/src/config/common.rs +++ b/src/config/common.rs @@ -27,6 +27,7 @@ pub struct CommonConfig { pub on_mouse_exit: Option, pub tooltip: Option, + pub disable_popup: bool, } #[derive(Debug, Deserialize, Clone)] diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 580aac8..f768f61 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -314,7 +314,7 @@ pub trait ModuleFactory { .register_content(id, instance_name, popup_content); } - self.setup_receiver(tx, ui_rx, module_name, id); + self.setup_receiver(tx, ui_rx, module_name, id, common.disable_popup); module_parts.setup_identifiers(&common); @@ -334,6 +334,7 @@ pub trait ModuleFactory { rx: mpsc::Receiver>, name: &'static str, id: usize, + disable_popup: bool, ) where TSend: Debug + Clone + Send + 'static; @@ -360,6 +361,7 @@ impl ModuleFactory for BarModuleFactory { rx: mpsc::Receiver>, name: &'static str, id: usize, + disable_popup: bool, ) where TSend: Debug + Clone + Send + 'static, { @@ -369,7 +371,7 @@ impl ModuleFactory for BarModuleFactory { ModuleUpdateEvent::Update(update) => { send!(tx, update); } - ModuleUpdateEvent::TogglePopup(button_id) => { + ModuleUpdateEvent::TogglePopup(button_id) if !disable_popup => { debug!("Toggling popup for {} [#{}] (button id: {button_id})", name, id); if popup.is_visible() && popup.current_widget().unwrap_or_default() == id { popup.hide(); @@ -377,22 +379,23 @@ impl ModuleFactory for BarModuleFactory { popup.show(id, button_id); } } - ModuleUpdateEvent::OpenPopup(button_id) => { + ModuleUpdateEvent::OpenPopup(button_id) if !disable_popup => { debug!("Opening popup for {} [#{}] (button id: {button_id})", name, id); popup.hide(); popup.show(id, button_id); } #[cfg(feature = "launcher")] - ModuleUpdateEvent::OpenPopupAt(geometry) => { + ModuleUpdateEvent::OpenPopupAt(geometry) if !disable_popup => { debug!("Opening popup for {} [#{}]", name, id); popup.hide(); popup.show_at(id, geometry); } - ModuleUpdateEvent::ClosePopup => { + ModuleUpdateEvent::ClosePopup if !disable_popup => { debug!("Closing popup for {} [#{}]", name, id); popup.hide(); - } + }, + _ => {} } }); } @@ -430,6 +433,7 @@ impl ModuleFactory for PopupModuleFactory { rx: mpsc::Receiver>, name: &'static str, id: usize, + disable_popup: bool, ) where TSend: Debug + Clone + Send + 'static, { @@ -440,7 +444,7 @@ impl ModuleFactory for PopupModuleFactory { ModuleUpdateEvent::Update(update) => { send!(tx, update); } - ModuleUpdateEvent::TogglePopup(_) => { + ModuleUpdateEvent::TogglePopup(_) if !disable_popup => { debug!("Toggling popup for {} [#{}] (button id: {button_id})", name, id); if popup.is_visible() && popup.current_widget().unwrap_or_default() == id { popup.hide(); @@ -448,22 +452,23 @@ impl ModuleFactory for PopupModuleFactory { popup.show(id, button_id); } } - ModuleUpdateEvent::OpenPopup(_) => { + ModuleUpdateEvent::OpenPopup(_) if !disable_popup => { debug!("Opening popup for {} [#{}] (button id: {button_id})", name, id); popup.hide(); popup.show(id, button_id); } #[cfg(feature = "launcher")] - ModuleUpdateEvent::OpenPopupAt(geometry) => { + ModuleUpdateEvent::OpenPopupAt(geometry) if !disable_popup => { debug!("Opening popup for {} [#{}]", name, id); popup.hide(); popup.show_at(id, geometry); } - ModuleUpdateEvent::ClosePopup => { + ModuleUpdateEvent::ClosePopup if !disable_popup => { debug!("Closing popup for {} [#{}]", name, id); popup.hide(); - } + }, + _ => {} } }); } @@ -490,12 +495,13 @@ impl ModuleFactory for AnyModuleFactory { rx: mpsc::Receiver>, name: &'static str, id: usize, + disable_popup: bool, ) where TSend: Debug + Clone + Send + 'static, { match self { - AnyModuleFactory::Bar(bar) => bar.setup_receiver(tx, rx, name, id), - AnyModuleFactory::Popup(popup) => popup.setup_receiver(tx, rx, name, id), + AnyModuleFactory::Bar(bar) => bar.setup_receiver(tx, rx, name, id, disable_popup), + AnyModuleFactory::Popup(popup) => popup.setup_receiver(tx, rx, name, id, disable_popup), } }