1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-01 18:51:04 +02:00

refactor: move most of the horrible add_module macro content into proper functions

This commit is contained in:
Jake Stanger 2022-12-04 23:23:22 +00:00
parent 490f3f3f65
commit 2c1b2924d4
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
15 changed files with 317 additions and 344 deletions

View file

@ -22,7 +22,7 @@ pub struct ClockModule {
format: String,
#[serde(flatten)]
pub common: CommonConfig,
pub common: Option<CommonConfig>,
}
fn default_format() -> String {
@ -33,6 +33,10 @@ impl Module<Button> for ClockModule {
type SendMessage = DateTime<Local>;
type ReceiveMessage = ();
fn name() -> &'static str {
"clock"
}
fn spawn_controller(
&self,
_info: &ModuleInfo,

View file

@ -21,7 +21,7 @@ pub struct CustomModule {
popup: Option<Vec<Widget>>,
#[serde(flatten)]
pub common: CommonConfig,
pub common: Option<CommonConfig>,
}
/// Attempts to parse an `Orientation` from `String`
@ -168,6 +168,10 @@ impl Module<gtk::Box> for CustomModule {
type SendMessage = ();
type ReceiveMessage = ExecEvent;
fn name() -> &'static str {
"custom"
}
fn spawn_controller(
&self,
_info: &ModuleInfo,

View file

@ -26,7 +26,7 @@ pub struct FocusedModule {
icon_theme: Option<String>,
#[serde(flatten)]
pub common: CommonConfig,
pub common: Option<CommonConfig>,
}
const fn default_icon_size() -> i32 {
@ -37,6 +37,10 @@ impl Module<gtk::Box> for FocusedModule {
type SendMessage = (String, String);
type ReceiveMessage = ();
fn name() -> &'static str {
"focused"
}
fn spawn_controller(
&self,
_info: &ModuleInfo,

View file

@ -36,7 +36,7 @@ pub struct LauncherModule {
icon_theme: Option<String>,
#[serde(flatten)]
pub common: CommonConfig,
pub common: Option<CommonConfig>,
}
#[derive(Debug, Clone)]
@ -78,6 +78,10 @@ impl Module<gtk::Box> for LauncherModule {
type SendMessage = LauncherUpdate;
type ReceiveMessage = ItemEvent;
fn name() -> &'static str {
"launcher"
}
fn spawn_controller(
&self,
_info: &ModuleInfo,

View file

@ -17,7 +17,6 @@ pub mod workspaces;
use crate::config::BarPosition;
use crate::popup::ButtonGeometry;
use color_eyre::Result;
use derive_builder::Builder;
use glib::IsA;
use gtk::gdk::Monitor;
use gtk::{Application, Widget};
@ -29,15 +28,12 @@ pub enum ModuleLocation {
Center,
Right,
}
#[derive(Builder)]
pub struct ModuleInfo<'a> {
pub app: &'a Application,
pub location: ModuleLocation,
pub bar_position: BarPosition,
pub monitor: &'a Monitor,
pub output_name: &'a str,
pub module_name: &'a str,
}
#[derive(Debug)]
@ -73,6 +69,8 @@ where
type SendMessage;
type ReceiveMessage;
fn name() -> &'static str;
fn spawn_controller(
&self,
info: &ModuleInfo,

View file

@ -68,7 +68,7 @@ pub struct MpdModule {
music_dir: PathBuf,
#[serde(flatten)]
pub common: CommonConfig,
pub common: Option<CommonConfig>,
}
fn default_socket() -> String {
@ -128,6 +128,10 @@ impl Module<Button> for MpdModule {
type SendMessage = Option<SongUpdate>;
type ReceiveMessage = PlayerCommand;
fn name() -> &'static str {
"mpd"
}
fn spawn_controller(
&self,
_info: &ModuleInfo,

View file

@ -21,7 +21,7 @@ pub struct ScriptModule {
interval: u64,
#[serde(flatten)]
pub common: CommonConfig,
pub common: Option<CommonConfig>,
}
/// `Mode::Poll`
@ -48,6 +48,10 @@ impl Module<Label> for ScriptModule {
type SendMessage = String;
type ReceiveMessage = ();
fn name() -> &'static str {
"script"
}
fn spawn_controller(
&self,
_info: &ModuleInfo,

View file

@ -22,7 +22,7 @@ pub struct SysInfoModule {
interval: Interval,
#[serde(flatten)]
pub common: CommonConfig,
pub common: Option<CommonConfig>,
}
#[derive(Debug, Deserialize, Copy, Clone)]
@ -116,6 +116,10 @@ impl Module<gtk::Box> for SysInfoModule {
type SendMessage = HashMap<String, String>;
type ReceiveMessage = ();
fn name() -> &'static str {
"sysinfo"
}
fn spawn_controller(
&self,
_info: &ModuleInfo,

View file

@ -17,7 +17,7 @@ use tokio::sync::mpsc::{Receiver, Sender};
#[derive(Debug, Deserialize, Clone)]
pub struct TrayModule {
#[serde(flatten)]
pub common: CommonConfig,
pub common: Option<CommonConfig>,
}
/// Gets a GTK `Image` component
@ -92,6 +92,10 @@ impl Module<MenuBar> for TrayModule {
type SendMessage = NotifierItemMessage;
type ReceiveMessage = NotifierItemCommand;
fn name() -> &'static str {
"tray"
}
fn spawn_controller(
&self,
_info: &ModuleInfo,

View file

@ -22,7 +22,7 @@ pub struct WorkspacesModule {
all_monitors: bool,
#[serde(flatten)]
pub common: CommonConfig,
pub common: Option<CommonConfig>,
}
#[derive(Clone, Debug)]
@ -65,6 +65,10 @@ impl Module<gtk::Box> for WorkspacesModule {
type SendMessage = WorkspaceUpdate;
type ReceiveMessage = String;
fn name() -> &'static str {
"workspaces"
}
fn spawn_controller(
&self,
info: &ModuleInfo,