Skip to content

Commit

Permalink
feat: Add orientation and layout support for sys info
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaireNeveu committed Apr 5, 2024
1 parent 54fb99e commit 6aa7455
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/modules/Sys-Info.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
| `layout` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | How the labels are laid out (not the rotation of an individual label). |

<details>
<summary>JSON</summary>
Expand Down
2 changes: 1 addition & 1 deletion src/config/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub enum TransitionType {
SlideEnd,
}

#[derive(Debug, Deserialize, Clone)]
#[derive(Debug, Deserialize, Clone, Copy)]
#[serde(rename_all = "snake_case")]
pub enum ModuleOrientation {
#[serde(alias = "h")]
Expand Down
18 changes: 14 additions & 4 deletions src/modules/sysinfo.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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};
use color_eyre::Result;
use gtk::prelude::*;
use gtk::{prelude::*, Orientation};
use gtk::Label;
use regex::{Captures, Regex};
use serde::Deserialize;
Expand All @@ -21,6 +21,11 @@ pub struct SysInfoModule {
#[serde(default = "Interval::default")]
interval: Interval,

#[serde(default)]
orientation: ModuleOrientation,

layout: Option<ModuleOrientation>,

#[serde(flatten)]
pub common: Option<CommonConfig>,
}
Expand Down Expand Up @@ -186,15 +191,20 @@ impl Module<gtk::Box> for SysInfoModule {
) -> Result<ModuleParts<gtk::Box>> {
let re = Regex::new(r"\{([^}]+)}")?;

let container = gtk::Box::new(info.bar_position.orientation(), 10);
let layout = match self.layout {
Some(orientation) => orientation,
None => self.orientation,
};

let container = gtk::Box::new(Orientation::from(layout), 10);

let mut labels = Vec::new();

for format in &self.format {
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);
Expand Down
39 changes: 37 additions & 2 deletions test-configs/orientation.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
position: "left"
position: "bottom"
start:
- type: clock
format: "%H:%M"
Expand Down Expand Up @@ -79,4 +79,39 @@ start:
- type: slider
value: "echo 50"
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

0 comments on commit 6aa7455

Please sign in to comment.