diff --git a/docs/modules/Sys-Info.md b/docs/modules/Sys-Info.md index 232c802..d2aeddc 100644 --- a/docs/modules/Sys-Info.md +++ b/docs/modules/Sys-Info.md @@ -19,6 +19,8 @@ Pango markup is supported. | `interval.temps` | `integer` | `5` | Seconds between refreshing temperature data | | `interval.disks` | `integer` | `5` | Seconds between refreshing disk data | | `interval.network` | `integer` | `5` | Seconds between refreshing network data | +| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the labels. | +| `direction` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | How the labels are laid out (not the rotation of an individual label). |
JSON diff --git a/src/config/common.rs b/src/config/common.rs index bc8ba20..25a8944 100644 --- a/src/config/common.rs +++ b/src/config/common.rs @@ -40,9 +40,10 @@ pub enum TransitionType { SlideEnd, } -#[derive(Debug, Deserialize, Clone)] +#[derive(Debug, Default, Deserialize, Clone, Copy)] #[serde(rename_all = "snake_case")] pub enum ModuleOrientation { + #[default] #[serde(alias = "h")] Horizontal, #[serde(alias = "v")] @@ -50,10 +51,10 @@ pub enum ModuleOrientation { } impl ModuleOrientation { - pub const fn to_angle(&self) -> f64 { + pub const fn to_angle(self) -> f64 { match self { Self::Horizontal => 0.0, - Self::Vertical => 90.0 + Self::Vertical => 90.0, } } } @@ -61,18 +62,12 @@ impl ModuleOrientation { impl From for Orientation { fn from(o: ModuleOrientation) -> Self { match o { - ModuleOrientation::Horizontal => Orientation::Horizontal, - ModuleOrientation::Vertical => Orientation::Vertical + ModuleOrientation::Horizontal => Self::Horizontal, + ModuleOrientation::Vertical => Self::Vertical, } } } -impl Default for ModuleOrientation { - fn default() -> Self { - ModuleOrientation::Horizontal - } -} - impl TransitionType { pub const fn to_revealer_transition_type( &self, diff --git a/src/modules/custom/box.rs b/src/modules/custom/box.rs index bfdb28a..dca848a 100644 --- a/src/modules/custom/box.rs +++ b/src/modules/custom/box.rs @@ -2,7 +2,7 @@ use super::{CustomWidget, CustomWidgetContext}; use crate::build; use crate::config::ModuleOrientation; use crate::modules::custom::WidgetConfig; -use gtk::{prelude::*, Orientation}; +use gtk::prelude::*; use serde::Deserialize; #[derive(Debug, Deserialize, Clone)] @@ -20,9 +20,7 @@ impl CustomWidget for BoxWidget { let container = build!(self, Self::Widget); if let Some(orientation) = self.orientation { - container.set_orientation( - Orientation::from(orientation), - ); + container.set_orientation(orientation.into()); } if let Some(widgets) = self.widgets { diff --git a/src/modules/custom/button.rs b/src/modules/custom/button.rs index 7b152f3..199420d 100644 --- a/src/modules/custom/button.rs +++ b/src/modules/custom/button.rs @@ -39,9 +39,7 @@ impl CustomWidget for ButtonWidget { let label = Label::new(None); label.set_use_markup(true); - label.set_angle( - self.orientation.to_angle(), - ); + label.set_angle(self.orientation.to_angle()); button.add(&label); diff --git a/src/modules/custom/label.rs b/src/modules/custom/label.rs index aab2859..ca551c8 100644 --- a/src/modules/custom/label.rs +++ b/src/modules/custom/label.rs @@ -23,9 +23,7 @@ impl CustomWidget for LabelWidget { fn into_widget(self, _context: CustomWidgetContext) -> Self::Widget { let label = build!(self, Self::Widget); - label.set_angle( - self.orientation.to_angle(), - ); + label.set_angle(self.orientation.to_angle()); label.set_use_markup(true); diff --git a/src/modules/custom/mod.rs b/src/modules/custom/mod.rs index a0b198c..dc54e83 100644 --- a/src/modules/custom/mod.rs +++ b/src/modules/custom/mod.rs @@ -18,7 +18,7 @@ use crate::modules::{ }; use crate::script::Script; use crate::{module_impl, send_async, spawn}; -use color_eyre::{Report, Result}; +use color_eyre::Result; use gtk::prelude::*; use gtk::{Button, IconTheme, Orientation}; use serde::Deserialize; diff --git a/src/modules/custom/progress.rs b/src/modules/custom/progress.rs index cfbb510..16f46f8 100644 --- a/src/modules/custom/progress.rs +++ b/src/modules/custom/progress.rs @@ -1,5 +1,4 @@ use gtk::prelude::*; -use gtk::Orientation; use gtk::ProgressBar; use serde::Deserialize; use tokio::sync::mpsc; @@ -36,9 +35,7 @@ impl CustomWidget for ProgressWidget { fn into_widget(self, context: CustomWidgetContext) -> Self::Widget { let progress = build!(self, Self::Widget); - progress.set_orientation( - Orientation::from(self.orientation), - ); + progress.set_orientation(self.orientation.into()); if let Some(length) = self.length { set_length(&progress, length, context.bar_orientation); diff --git a/src/modules/custom/slider.rs b/src/modules/custom/slider.rs index 0426039..6bb3634 100644 --- a/src/modules/custom/slider.rs +++ b/src/modules/custom/slider.rs @@ -1,5 +1,4 @@ use glib::Propagation; -use gtk::Orientation; use std::cell::Cell; use std::ops::Neg; @@ -48,9 +47,7 @@ impl CustomWidget for SliderWidget { fn into_widget(self, context: CustomWidgetContext) -> Self::Widget { let scale = build!(self, Self::Widget); - scale.set_orientation( - Orientation::from(self.orientation), - ); + scale.set_orientation(self.orientation.into()); if let Some(length) = self.length { set_length(&scale, length, context.bar_orientation); diff --git a/src/modules/sysinfo.rs b/src/modules/sysinfo.rs index c6a9f66..4b0966f 100644 --- a/src/modules/sysinfo.rs +++ b/src/modules/sysinfo.rs @@ -1,4 +1,4 @@ -use crate::config::CommonConfig; +use crate::config::{CommonConfig, ModuleOrientation}; use crate::gtk_helpers::IronbarGtkExt; use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext}; use crate::{glib_recv, module_impl, send_async, spawn}; @@ -21,6 +21,11 @@ pub struct SysInfoModule { #[serde(default = "Interval::default")] interval: Interval, + #[serde(default)] + orientation: ModuleOrientation, + + direction: Option, + #[serde(flatten)] pub common: Option, } @@ -182,11 +187,16 @@ impl Module for SysInfoModule { fn into_widget( self, context: WidgetContext, - info: &ModuleInfo, + _info: &ModuleInfo, ) -> Result> { let re = Regex::new(r"\{([^}]+)}")?; - let container = gtk::Box::new(info.bar_position.orientation(), 10); + let layout = match self.direction { + Some(orientation) => orientation, + None => self.orientation, + }; + + let container = gtk::Box::new(layout.into(), 10); let mut labels = Vec::new(); @@ -194,7 +204,7 @@ impl Module for SysInfoModule { let label = Label::builder().label(format).use_markup(true).build(); label.add_class("item"); - label.set_angle(info.bar_position.get_angle()); + label.set_angle(self.orientation.to_angle()); container.add(&label); labels.push(label); diff --git a/test-configs/orientation.yaml b/test-configs/orientation.yaml index 93594c8..8aefd7a 100644 --- a/test-configs/orientation.yaml +++ b/test-configs/orientation.yaml @@ -1,4 +1,4 @@ -position: "left" +position: "bottom" start: - type: clock format: "%H:%M" @@ -79,4 +79,39 @@ start: - type: slider value: "echo 50" length: 100 - orientation: v \ No newline at end of file + orientation: v + - type: sys_info + format: + - ' {cpu_percent}%' + - ' {memory_used} / {memory_total} GB ({memory_percent}%)' + - '󰥔 {uptime}' + interval: + cpu: 1 + disks: 300 + memory: 30 + networks: 3 + temps: 5 + - type: sys_info + orientation: vertical + format: + - ' {cpu_percent}%' + - ' {memory_used} / {memory_total} GB ({memory_percent}%)' + - '󰥔 {uptime}' + interval: + cpu: 1 + disks: 300 + memory: 30 + networks: 3 + temps: 5 + - type: sys_info + layout: vertical + format: + - ' {cpu_percent}%' + - ' {memory_used} / {memory_total} GB ({memory_percent}%)' + - '󰥔 {uptime}' + interval: + cpu: 1 + disks: 300 + memory: 30 + networks: 3 + temps: 5 \ No newline at end of file