From eaaa937be89803b1ba2ae84caf17be4d7adf2b50 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sat, 30 Mar 2024 23:17:23 +0000 Subject: [PATCH 01/39] chore: correct comment --- src/popup.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/popup.rs b/src/popup.rs index cb1a536..1f24248 100644 --- a/src/popup.rs +++ b/src/popup.rs @@ -216,7 +216,7 @@ impl Popup { } } - /// Hides the popover + /// Hides the popup pub fn hide(&self) { *self.current_widget.borrow_mut() = None; self.window.hide(); From 99eb560cea89687d7899a74be016c641d94640f9 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sat, 30 Mar 2024 23:17:32 +0000 Subject: [PATCH 02/39] build: update universal-config --- Cargo.lock | 131 ++++++++++++++++++++++++++++++----------------------- Cargo.toml | 2 +- 2 files changed, 75 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6d55ff..7fe2027 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -283,12 +283,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - [[package]] name = "base64" version = "0.21.0" @@ -306,6 +300,9 @@ name = "bitflags" version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +dependencies = [ + "serde", +] [[package]] name = "block-buffer" @@ -1236,7 +1233,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72793962ceece3863c2965d7f10c8786323b17c7adea75a515809fa20ab799a5" dependencies = [ "heck 0.4.1", - "proc-macro-crate 2.0.1", + "proc-macro-crate 2.0.0", "proc-macro-error", "proc-macro2", "quote 1.0.35", @@ -1356,19 +1353,13 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap 2.2.6", + "indexmap", "slab", "tokio", "tokio-util", "tracing", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "hashbrown" version = "0.14.1" @@ -1592,16 +1583,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", -] - [[package]] name = "indexmap" version = "2.2.6" @@ -1609,7 +1590,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown 0.14.1", + "hashbrown", + "serde", ] [[package]] @@ -1674,7 +1656,7 @@ dependencies = [ "gtk", "gtk-layer-shell", "hyprland", - "indexmap 2.2.6", + "indexmap", "libpulse-binding", "mpd-utils", "mpris", @@ -1752,11 +1734,12 @@ checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "libcorn" -version = "0.9.0" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07283e36c1e48784b5e24e27fd4f6deabd83ebfa05648316dcead505ecbab40f" +checksum = "48ada41708c215eb095c72db1ca41913c347f75d382f2fc9e8d1017a22b7671e" dependencies = [ "cfg-if", + "indexmap", "pest", "pest_derive", "serde", @@ -2375,11 +2358,10 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "2.0.1" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97dc5fea232fc28d2f597b37c4876b348a40e33f3b02cc975c8d006d78d94b1a" +checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" dependencies = [ - "toml_datetime", "toml_edit 0.20.2", ] @@ -2577,7 +2559,7 @@ version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d66674f2b6fb864665eea7a3c1ac4e3dfacd2fda83cf6f935a612e01b0e3338" dependencies = [ - "base64 0.21.0", + "base64", "bytes", "encoding_rs", "futures-core", @@ -2615,13 +2597,14 @@ dependencies = [ [[package]] name = "ron" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "300a51053b1cb55c80b7a9fde4120726ddf25ca241a1cbb926626f62fb136bff" +checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" dependencies = [ - "base64 0.13.1", - "bitflags 1.3.2", + "base64", + "bitflags 2.4.0", "serde", + "serde_derive", ] [[package]] @@ -2672,7 +2655,7 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64 0.21.0", + "base64", ] [[package]] @@ -2774,9 +2757,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" dependencies = [ "itoa", "ryu", @@ -2796,9 +2779,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" dependencies = [ "serde", ] @@ -2817,11 +2800,11 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.21" +version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9d684e3ec7de3bf5466b32bd75303ac16f0736426e5a4e0d6e489559ce1249c" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap 1.9.3", + "indexmap", "itoa", "ryu", "serde", @@ -3105,7 +3088,7 @@ dependencies = [ "cfg-expr", "heck 0.4.1", "pkg-config", - "toml", + "toml 0.7.6", "version-compare", ] @@ -3283,10 +3266,22 @@ dependencies = [ ] [[package]] -name = "toml_datetime" -version = "0.6.3" +name = "toml" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.22.9", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" dependencies = [ "serde", ] @@ -3297,11 +3292,11 @@ version = "0.19.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" dependencies = [ - "indexmap 2.2.6", + "indexmap", "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.5.10", ] [[package]] @@ -3310,9 +3305,22 @@ version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" dependencies = [ - "indexmap 2.2.6", + "indexmap", "toml_datetime", - "winnow", + "winnow 0.5.10", +] + +[[package]] +name = "toml_edit" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow 0.6.5", ] [[package]] @@ -3496,9 +3504,9 @@ checksum = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" [[package]] name = "universal-config" -version = "0.4.3" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e41ae277cedae5c3a4d6dbe5d7ad5068cdbcd9e7005de28996cada89c28c776" +checksum = "6b01452126ed3a29e5d54cc9f036c541c2ceeb152fb9234fef8a1fc3054b26ca" dependencies = [ "dirs", "libcorn", @@ -3507,15 +3515,15 @@ dependencies = [ "serde_json", "serde_yaml", "thiserror", - "toml", + "toml 0.8.12", "tracing", ] [[package]] name = "unsafe-libyaml" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" [[package]] name = "upower_dbus" @@ -4054,6 +4062,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.50.0" diff --git a/Cargo.toml b/Cargo.toml index 23ab177..7a9570b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -104,7 +104,7 @@ wayland-protocols-wlr = { version = "0.2.0", features = ["client"] } smithay-client-toolkit = { version = "0.18.1", default-features = false, features = [ "calloop", ] } -universal-config = { version = "0.4.3", default_features = false } +universal-config = { version = "0.5.0", default_features = false } ctrlc = "3.4.2" cfg-if = "1.0.0" From bb02a21d0efcad07ba0598a38ff56abfc7c06107 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sat, 30 Mar 2024 23:24:30 +0000 Subject: [PATCH 03/39] docs(compiling): add missing notifications feature flag --- docs/Compiling.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/Compiling.md b/docs/Compiling.md index 30c69df..f7eeb93 100644 --- a/docs/Compiling.md +++ b/docs/Compiling.md @@ -84,6 +84,7 @@ cargo build --release --no-default-features \ | music+all | Enables the `music` module with support for all player types. | | music+mpris | Enables the `music` module with MPRIS support. | | music+mpd | Enables the `music` module with MPD support. | +| notifications | Enables the `notiications` module. | | sys_info | Enables the `sys_info` module. | | tray | Enables the `tray` module. | | upower | Enables the `upower` module. | From 42ae9156458ab4c224f6ca155fc715f9fae44e3f Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sat, 30 Mar 2024 23:31:28 +0000 Subject: [PATCH 04/39] chore(nix): add missing libpulseaudio to shell --- shell.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/shell.nix b/shell.nix index d8dda7b..66f6b9d 100644 --- a/shell.nix +++ b/shell.nix @@ -9,6 +9,7 @@ pkgs.mkShell { gtk-layer-shell gcc openssl + libpulseaudio ]; nativeBuildInputs = with pkgs; [ From 30417e06feeda5bd1f2d9b40bf916399c78c3c5f Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sun, 31 Mar 2024 22:55:39 +0100 Subject: [PATCH 05/39] build(nix): fix naersk build broken when using non-default features Fixes #520 --- nix/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/default.nix b/nix/default.nix index f5d680a..bf01e68 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -73,7 +73,7 @@ in then builder.buildPackage (basePkg // { - cargoOptions = old: old ++ flags; + cargoBuildOptions = old: old ++ flags; }) else if builderName == "crane" then From df7cd1e36437a4f56c62ea70a1a08a01111eed79 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 1 Apr 2024 00:55:04 +0000 Subject: [PATCH 06/39] flake.lock: Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'crane': 'github:ipetkov/crane/2c94ff9a6fbeb9f3ea0107f28688edbe9c81deaa?narHash=sha256-jX%2BB1VGHT0ruHHL5RwS8L21R6miBn4B6s9iVyUJsJJY%3D' (2024-02-24) → 'github:ipetkov/crane/ada0fb4dcce4561acb1eb17c59b7306d9d4a95f3?narHash=sha256-LEg6/dmEFxx6Ygti5DO9MOhGNpyB7zdxdWtzv/FCTXk%3D' (2024-03-29) • Updated input 'naersk/nixpkgs': 'github:NixOS/nixpkgs/ebe6e807793e7c9cc59cf81225fdee1a03413811?narHash=sha256-lKdtMbhnBNU1lr978T%2BwEYet3sfIXXgyiDZNEgx8CV8%3D' (2024-02-29) → 'github:NixOS/nixpkgs/807c549feabce7eddbf259dbdcec9e0600a0660d?narHash=sha256-9slQ609YqT9bT/MNX9%2B5k5jltL9zgpn36DpFB7TkttM%3D' (2024-03-29) • Updated input 'nixpkgs': 'github:nixos/nixpkgs/9099616b93301d5cf84274b184a3a5ec69e94e08?narHash=sha256-HofykKuisObPUfj0E9CJVfaMhawXkYx3G8UIFR/XQ38%3D' (2024-02-28) → 'github:nixos/nixpkgs/d8fe5e6c92d0d190646fb9f1056741a229980089?narHash=sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk%3D' (2024-03-29) • Updated input 'rust-overlay': 'github:oxalica/rust-overlay/72fa0217f76020ad3aeb2dd9dd72490905b23b6f?narHash=sha256-0oYeE5VkhnPA7YBl%2B0Utq2cYoHcfsEhSGwraCa27Vs8%3D' (2024-02-29) → 'github:oxalica/rust-overlay/f258266af947599e8069df1c2e933189270f143a?narHash=sha256-EJ03x3N9ihhonAttkaCrqxb0djDq3URCuDpmVPbNZhA%3D' (2024-03-31) --- flake.lock | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/flake.lock b/flake.lock index 47e5ffa..3a3b651 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1708794349, - "narHash": "sha256-jX+B1VGHT0ruHHL5RwS8L21R6miBn4B6s9iVyUJsJJY=", + "lastModified": 1711681752, + "narHash": "sha256-LEg6/dmEFxx6Ygti5DO9MOhGNpyB7zdxdWtzv/FCTXk=", "owner": "ipetkov", "repo": "crane", - "rev": "2c94ff9a6fbeb9f3ea0107f28688edbe9c81deaa", + "rev": "ada0fb4dcce4561acb1eb17c59b7306d9d4a95f3", "type": "github" }, "original": { @@ -58,11 +58,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1709200309, - "narHash": "sha256-lKdtMbhnBNU1lr978T+wEYet3sfIXXgyiDZNEgx8CV8=", + "lastModified": 1711715736, + "narHash": "sha256-9slQ609YqT9bT/MNX9+5k5jltL9zgpn36DpFB7TkttM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ebe6e807793e7c9cc59cf81225fdee1a03413811", + "rev": "807c549feabce7eddbf259dbdcec9e0600a0660d", "type": "github" }, "original": { @@ -72,11 +72,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1709150264, - "narHash": "sha256-HofykKuisObPUfj0E9CJVfaMhawXkYx3G8UIFR/XQ38=", + "lastModified": 1711703276, + "narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=", "owner": "nixos", "repo": "nixpkgs", - "rev": "9099616b93301d5cf84274b184a3a5ec69e94e08", + "rev": "d8fe5e6c92d0d190646fb9f1056741a229980089", "type": "github" }, "original": { @@ -102,11 +102,11 @@ ] }, "locked": { - "lastModified": 1709172595, - "narHash": "sha256-0oYeE5VkhnPA7YBl+0Utq2cYoHcfsEhSGwraCa27Vs8=", + "lastModified": 1711851236, + "narHash": "sha256-EJ03x3N9ihhonAttkaCrqxb0djDq3URCuDpmVPbNZhA=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "72fa0217f76020ad3aeb2dd9dd72490905b23b6f", + "rev": "f258266af947599e8069df1c2e933189270f143a", "type": "github" }, "original": { From 994f4a4a123452607dd591e1e358ec218a3cb5ae Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Thu, 14 Mar 2024 22:35:33 +0000 Subject: [PATCH 07/39] feat: ability to add custom modules instead native modules Resolves #131 --- docs/modules/Custom.md | 14 +- src/bar.rs | 53 +---- src/config/mod.rs | 46 ++++ src/ipc/server.rs | 4 +- src/macros.rs | 28 +++ src/modules/clipboard.rs | 9 +- src/modules/clock.rs | 14 +- src/modules/custom/mod.rs | 64 +++++- src/modules/focused.rs | 6 +- src/modules/label.rs | 6 +- src/modules/launcher/mod.rs | 9 +- src/modules/mod.rs | 394 +++++++++++++++++++++++++---------- src/modules/music/mod.rs | 9 +- src/modules/notifications.rs | 6 +- src/modules/script.rs | 6 +- src/modules/sysinfo.rs | 6 +- src/modules/tray/mod.rs | 6 +- src/modules/upower.rs | 9 +- src/modules/volume.rs | 14 +- src/modules/workspaces.rs | 6 +- src/popup.rs | 40 ++-- 21 files changed, 497 insertions(+), 252 deletions(-) diff --git a/docs/modules/Custom.md b/docs/modules/Custom.md index 298e0a3..041b484 100644 --- a/docs/modules/Custom.md +++ b/docs/modules/Custom.md @@ -1,6 +1,11 @@ -Allows you to compose custom modules consisting of multiple widgets, including popups. +Allows you to compose custom modules consisting of multiple modules and widgets, including popups. Labels can display dynamic content from scripts, and buttons can interact with the bar or execute commands on click. +The module provides a set of utility widgets, such as containers, labels and buttons. +In addition to these, you can also add any native module. +Paired with the other custom modules such as Cairo, +this provides a powerful declarative interface for constructing your own interfaces. + If you only intend to run a single script, prefer the [script](script) module, or [label](label) if you only need a single text label. @@ -13,6 +18,11 @@ or [label](label) if you only need a single text label. This module can be quite fiddly to configure as you effectively have to build a tree of widgets by hand. It is well worth looking at the examples. +| Name | Type | Default | Description | +|---------|------------------------|------------|------------------------------------------| +| `bar` | `(Module or Widget)[]` | `[]` | Modules and widgets to add to the bar. | +| `popup` | `(Module or Widget)[]` | `null` | Modules and widgets to add to the popup. | + ### `Widget` There are many widget types, each with their own config options. @@ -36,7 +46,7 @@ A container to place nested widgets inside. | Name | Type | Default | Description | |---------------|------------------------------------------------------------|----------------|-------------------------------------------------------------------| | `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Whether child widgets should be horizontally or vertically added. | -| `widgets` | `Widget[]` | `[]` | List of widgets to add to this box. | +| `widgets` | `(Module or Widget)[]` | `[]` | List of widgets to add to this box. | #### Label diff --git a/src/bar.rs b/src/bar.rs index d91e0fc..4363806 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -1,7 +1,5 @@ use crate::config::{BarConfig, BarPosition, MarginConfig, ModuleConfig}; -use crate::modules::{ - create_module, set_widget_identifiers, wrap_widget, ModuleInfo, ModuleLocation, -}; +use crate::modules::{BarModuleFactory, ModuleInfo, ModuleLocation}; use crate::popup::Popup; use crate::Ironbar; use color_eyre::Result; @@ -350,55 +348,10 @@ fn add_modules( ironbar: &Rc, popup: &Rc, ) -> Result<()> { - let orientation = info.bar_position.orientation(); - - macro_rules! add_module { - ($module:expr, $id:expr) => {{ - let common = $module.common.take().expect("common config to exist"); - let widget_parts = create_module( - *$module, - $id, - ironbar.clone(), - common.name.clone(), - &info, - &Rc::clone(&popup), - )?; - set_widget_identifiers(&widget_parts, &common); - - let container = wrap_widget(&widget_parts.widget, common, orientation); - content.add(&container); - }}; - } + let module_factory = BarModuleFactory::new(ironbar.clone(), popup.clone()).into(); for config in modules { - let id = Ironbar::unique_id(); - match config { - #[cfg(feature = "clipboard")] - ModuleConfig::Clipboard(mut module) => add_module!(module, id), - #[cfg(feature = "clock")] - ModuleConfig::Clock(mut module) => add_module!(module, id), - ModuleConfig::Custom(mut module) => add_module!(module, id), - #[cfg(feature = "focused")] - ModuleConfig::Focused(mut module) => add_module!(module, id), - ModuleConfig::Label(mut module) => add_module!(module, id), - #[cfg(feature = "launcher")] - ModuleConfig::Launcher(mut module) => add_module!(module, id), - #[cfg(feature = "music")] - ModuleConfig::Music(mut module) => add_module!(module, id), - #[cfg(feature = "notifications")] - ModuleConfig::Notifications(mut module) => add_module!(module, id), - ModuleConfig::Script(mut module) => add_module!(module, id), - #[cfg(feature = "sys_info")] - ModuleConfig::SysInfo(mut module) => add_module!(module, id), - #[cfg(feature = "tray")] - ModuleConfig::Tray(mut module) => add_module!(module, id), - #[cfg(feature = "upower")] - ModuleConfig::Upower(mut module) => add_module!(module, id), - #[cfg(feature = "volume")] - ModuleConfig::Volume(mut module) => add_module!(module, id), - #[cfg(feature = "workspaces")] - ModuleConfig::Workspaces(mut module) => add_module!(module, id), - } + config.create(&module_factory, content, info)?; } Ok(()) diff --git a/src/config/mod.rs b/src/config/mod.rs index a20572b..52fcb8d 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -27,7 +27,10 @@ use crate::modules::upower::UpowerModule; use crate::modules::volume::VolumeModule; #[cfg(feature = "workspaces")] use crate::modules::workspaces::WorkspacesModule; + +use crate::modules::{AnyModuleFactory, ModuleFactory, ModuleInfo}; use cfg_if::cfg_if; +use color_eyre::Result; use serde::Deserialize; use std::collections::HashMap; @@ -64,6 +67,49 @@ pub enum ModuleConfig { Workspaces(Box), } +impl ModuleConfig { + pub fn create( + self, + module_factory: &AnyModuleFactory, + container: >k::Box, + info: &ModuleInfo, + ) -> Result<()> { + macro_rules! create { + ($module:expr) => { + module_factory.create(*$module, container, info) + }; + } + + match self { + #[cfg(feature = "clipboard")] + Self::Clipboard(module) => create!(module), + #[cfg(feature = "clock")] + Self::Clock(module) => create!(module), + Self::Custom(module) => create!(module), + #[cfg(feature = "focused")] + Self::Focused(module) => create!(module), + Self::Label(module) => create!(module), + #[cfg(feature = "launcher")] + Self::Launcher(module) => create!(module), + #[cfg(feature = "music")] + Self::Music(module) => create!(module), + #[cfg(feature = "notifications")] + Self::Notifications(module) => create!(module), + Self::Script(module) => create!(module), + #[cfg(feature = "sys_info")] + Self::SysInfo(module) => create!(module), + #[cfg(feature = "tray")] + Self::Tray(module) => create!(module), + #[cfg(feature = "upower")] + Self::Upower(module) => create!(module), + #[cfg(feature = "volume")] + Self::Volume(module) => create!(module), + #[cfg(feature = "workspaces")] + Self::Workspaces(module) => create!(module), + } + } +} + #[derive(Debug, Deserialize, Clone)] pub enum BarEntryConfig { Single(BarConfig), diff --git a/src/ipc/server.rs b/src/ipc/server.rs index 931a4fa..776efe1 100644 --- a/src/ipc/server.rs +++ b/src/ipc/server.rs @@ -172,7 +172,7 @@ impl Ipc { popup.hide(); let data = popup - .cache + .container_cache .borrow() .iter() .find(|(_, value)| value.name == name) @@ -209,7 +209,7 @@ impl Ipc { popup.hide(); let data = popup - .cache + .container_cache .borrow() .iter() .find(|(_, value)| value.name == name) diff --git a/src/macros.rs b/src/macros.rs index e5fd195..cabc8a0 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,3 +1,31 @@ +/// Provides implementations of methods required by the `Module` trait +/// which cannot be included as part of the trait. +/// +/// This removes the need to add the same boilerplate method definitions +/// to every module implementation. +/// +/// # Usage: +/// +/// ```rs +/// impl Module for ClockModule { +/// type SendMessage = DateTime; +/// type ReceiveMessage = (); +/// +/// module_impl!("clock"); +/// } +#[macro_export] +macro_rules! module_impl { + ($name:literal) => { + fn name() -> &'static str { + $name + } + + fn take_common(&mut self) -> $crate::config::CommonConfig { + self.common.take().expect("common config to exist") + } + }; +} + /// Sends a message on an asynchronous `Sender` using `send()` /// Panics if the message cannot be sent. /// diff --git a/src/modules/clipboard.rs b/src/modules/clipboard.rs index 9749df6..6d53e40 100644 --- a/src/modules/clipboard.rs +++ b/src/modules/clipboard.rs @@ -5,7 +5,7 @@ use crate::image::new_icon_button; use crate::modules::{ Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, PopupButton, WidgetContext, }; -use crate::{glib_recv, spawn, try_send}; +use crate::{glib_recv, module_impl, spawn, try_send}; use glib::Propagation; use gtk::gdk_pixbuf::Pixbuf; use gtk::gio::{Cancellable, MemoryInputStream}; @@ -65,9 +65,7 @@ impl Module