1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-04-19 19:34:24 +02:00

feat: Add orientation and direction support for sys info

This commit is contained in:
Claire Neveu 2024-04-05 13:28:47 -04:00
parent 70b2c592b2
commit 44be58594b
10 changed files with 66 additions and 36 deletions

View file

@ -19,6 +19,8 @@ Pango markup is supported.
| `interval.temps` | `integer` | `5` | Seconds between refreshing temperature data | | `interval.temps` | `integer` | `5` | Seconds between refreshing temperature data |
| `interval.disks` | `integer` | `5` | Seconds between refreshing disk data | | `interval.disks` | `integer` | `5` | Seconds between refreshing disk data |
| `interval.network` | `integer` | `5` | Seconds between refreshing network 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). |
<details> <details>
<summary>JSON</summary> <summary>JSON</summary>

View file

@ -40,9 +40,10 @@ pub enum TransitionType {
SlideEnd, SlideEnd,
} }
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Default, Deserialize, Clone, Copy)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum ModuleOrientation { pub enum ModuleOrientation {
#[default]
#[serde(alias = "h")] #[serde(alias = "h")]
Horizontal, Horizontal,
#[serde(alias = "v")] #[serde(alias = "v")]
@ -50,10 +51,10 @@ pub enum ModuleOrientation {
} }
impl ModuleOrientation { impl ModuleOrientation {
pub const fn to_angle(&self) -> f64 { pub const fn to_angle(self) -> f64 {
match self { match self {
Self::Horizontal => 0.0, Self::Horizontal => 0.0,
Self::Vertical => 90.0 Self::Vertical => 90.0,
} }
} }
} }
@ -61,18 +62,12 @@ impl ModuleOrientation {
impl From<ModuleOrientation> for Orientation { impl From<ModuleOrientation> for Orientation {
fn from(o: ModuleOrientation) -> Self { fn from(o: ModuleOrientation) -> Self {
match o { match o {
ModuleOrientation::Horizontal => Orientation::Horizontal, ModuleOrientation::Horizontal => Self::Horizontal,
ModuleOrientation::Vertical => Orientation::Vertical ModuleOrientation::Vertical => Self::Vertical,
} }
} }
} }
impl Default for ModuleOrientation {
fn default() -> Self {
ModuleOrientation::Horizontal
}
}
impl TransitionType { impl TransitionType {
pub const fn to_revealer_transition_type( pub const fn to_revealer_transition_type(
&self, &self,

View file

@ -2,7 +2,7 @@ use super::{CustomWidget, CustomWidgetContext};
use crate::build; use crate::build;
use crate::config::ModuleOrientation; use crate::config::ModuleOrientation;
use crate::modules::custom::WidgetConfig; use crate::modules::custom::WidgetConfig;
use gtk::{prelude::*, Orientation}; use gtk::prelude::*;
use serde::Deserialize; use serde::Deserialize;
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]
@ -20,9 +20,7 @@ impl CustomWidget for BoxWidget {
let container = build!(self, Self::Widget); let container = build!(self, Self::Widget);
if let Some(orientation) = self.orientation { if let Some(orientation) = self.orientation {
container.set_orientation( container.set_orientation(orientation.into());
Orientation::from(orientation),
);
} }
if let Some(widgets) = self.widgets { if let Some(widgets) = self.widgets {

View file

@ -39,9 +39,7 @@ impl CustomWidget for ButtonWidget {
let label = Label::new(None); let label = Label::new(None);
label.set_use_markup(true); label.set_use_markup(true);
label.set_angle( label.set_angle(self.orientation.to_angle());
self.orientation.to_angle(),
);
button.add(&label); button.add(&label);

View file

@ -23,9 +23,7 @@ impl CustomWidget for LabelWidget {
fn into_widget(self, _context: CustomWidgetContext) -> Self::Widget { fn into_widget(self, _context: CustomWidgetContext) -> Self::Widget {
let label = build!(self, Self::Widget); let label = build!(self, Self::Widget);
label.set_angle( label.set_angle(self.orientation.to_angle());
self.orientation.to_angle(),
);
label.set_use_markup(true); label.set_use_markup(true);

View file

@ -18,7 +18,7 @@ use crate::modules::{
}; };
use crate::script::Script; use crate::script::Script;
use crate::{module_impl, send_async, spawn}; use crate::{module_impl, send_async, spawn};
use color_eyre::{Report, Result}; use color_eyre::Result;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::{Button, IconTheme, Orientation}; use gtk::{Button, IconTheme, Orientation};
use serde::Deserialize; use serde::Deserialize;

View file

@ -1,5 +1,4 @@
use gtk::prelude::*; use gtk::prelude::*;
use gtk::Orientation;
use gtk::ProgressBar; use gtk::ProgressBar;
use serde::Deserialize; use serde::Deserialize;
use tokio::sync::mpsc; use tokio::sync::mpsc;
@ -36,9 +35,7 @@ impl CustomWidget for ProgressWidget {
fn into_widget(self, context: CustomWidgetContext) -> Self::Widget { fn into_widget(self, context: CustomWidgetContext) -> Self::Widget {
let progress = build!(self, Self::Widget); let progress = build!(self, Self::Widget);
progress.set_orientation( progress.set_orientation(self.orientation.into());
Orientation::from(self.orientation),
);
if let Some(length) = self.length { if let Some(length) = self.length {
set_length(&progress, length, context.bar_orientation); set_length(&progress, length, context.bar_orientation);

View file

@ -1,5 +1,4 @@
use glib::Propagation; use glib::Propagation;
use gtk::Orientation;
use std::cell::Cell; use std::cell::Cell;
use std::ops::Neg; use std::ops::Neg;
@ -48,9 +47,7 @@ impl CustomWidget for SliderWidget {
fn into_widget(self, context: CustomWidgetContext) -> Self::Widget { fn into_widget(self, context: CustomWidgetContext) -> Self::Widget {
let scale = build!(self, Self::Widget); let scale = build!(self, Self::Widget);
scale.set_orientation( scale.set_orientation(self.orientation.into());
Orientation::from(self.orientation),
);
if let Some(length) = self.length { if let Some(length) = self.length {
set_length(&scale, length, context.bar_orientation); set_length(&scale, length, context.bar_orientation);

View file

@ -1,4 +1,4 @@
use crate::config::CommonConfig; use crate::config::{CommonConfig, ModuleOrientation};
use crate::gtk_helpers::IronbarGtkExt; use crate::gtk_helpers::IronbarGtkExt;
use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext}; use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext};
use crate::{glib_recv, module_impl, send_async, spawn}; use crate::{glib_recv, module_impl, send_async, spawn};
@ -21,6 +21,11 @@ pub struct SysInfoModule {
#[serde(default = "Interval::default")] #[serde(default = "Interval::default")]
interval: Interval, interval: Interval,
#[serde(default)]
orientation: ModuleOrientation,
direction: Option<ModuleOrientation>,
#[serde(flatten)] #[serde(flatten)]
pub common: Option<CommonConfig>, pub common: Option<CommonConfig>,
} }
@ -182,11 +187,16 @@ impl Module<gtk::Box> for SysInfoModule {
fn into_widget( fn into_widget(
self, self,
context: WidgetContext<Self::SendMessage, Self::ReceiveMessage>, context: WidgetContext<Self::SendMessage, Self::ReceiveMessage>,
info: &ModuleInfo, _info: &ModuleInfo,
) -> Result<ModuleParts<gtk::Box>> { ) -> Result<ModuleParts<gtk::Box>> {
let re = Regex::new(r"\{([^}]+)}")?; 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(); let mut labels = Vec::new();
@ -194,7 +204,7 @@ impl Module<gtk::Box> for SysInfoModule {
let label = Label::builder().label(format).use_markup(true).build(); let label = Label::builder().label(format).use_markup(true).build();
label.add_class("item"); label.add_class("item");
label.set_angle(info.bar_position.get_angle()); label.set_angle(self.orientation.to_angle());
container.add(&label); container.add(&label);
labels.push(label); labels.push(label);

View file

@ -1,4 +1,4 @@
position: "left" position: "bottom"
start: start:
- type: clock - type: clock
format: "%H:%M" format: "%H:%M"
@ -79,4 +79,39 @@ start:
- type: slider - type: slider
value: "echo 50" value: "echo 50"
length: 100 length: 100
orientation: v 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