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

Merge pull request #530 from ClaireNeveu/master

feat: Add orientation support for clock, button, label, and sys_info
This commit is contained in:
Jake Stanger 2024-04-06 17:21:02 +01:00 committed by GitHub
commit 9a71c693ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 272 additions and 40 deletions

View file

@ -13,6 +13,7 @@ Clicking on the widget opens a popup with the time and a calendar.
| `format` | `string` | `%d/%m/%Y %H:%M` | Date/time format string. Pango markup is supported. | | `format` | `string` | `%d/%m/%Y %H:%M` | Date/time format string. Pango markup is supported. |
| `format_popup` | `string` | `%H:%M:%S` | Date/time format string to display in the popup header. Pango markup is supported. | | `format_popup` | `string` | `%H:%M:%S` | Date/time format string to display in the popup header. Pango markup is supported. |
| `locale` | `string` | `$LC_TIME` or `$LANG` or `'POSIX'` | Locale to use (eg `en_GB`). Defaults to the system language (reading from env var). | | `locale` | `string` | `$LC_TIME` or `$LANG` or `'POSIX'` | Locale to use (eg `en_GB`). Defaults to the system language (reading from env var). |
| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the time on the clock button. |
> Detail on available tokens can be found here: <https://docs.rs/chrono/latest/chrono/format/strftime/index.html> > Detail on available tokens can be found here: <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>

View file

@ -57,6 +57,7 @@ A text label. Pango markup is supported.
| Name | Type | Default | Description | | Name | Type | Default | Description |
|---------|-------------------------------------------------|---------|---------------------------------------------------------------------| |---------|-------------------------------------------------|---------|---------------------------------------------------------------------|
| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. | | `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. |
| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the label. |
#### Button #### Button
@ -69,6 +70,7 @@ A clickable button, which can run a command when clicked.
| `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. Ignored if `widgets` is set. | | `label` | [Dynamic String](dynamic-values#dynamic-string) | `null` | Widget text label. Pango markup and embedded scripts are supported. Ignored if `widgets` is set. |
| `widgets` | `(Module or Widget)[]` | `[]` | List of modules/widgets to add to this button. | | `widgets` | `(Module or Widget)[]` | `[]` | List of modules/widgets to add to this button. |
| `on_click` | `string [command]` | `null` | Command to execute. More on this [below](#commands). | | `on_click` | `string [command]` | `null` | Command to execute. More on this [below](#commands). |
| `orientation` | `'horizontal'` or `'vertical'` (shorthand: `'h'` or `'v'`) | `'horizontal'` | Orientation of the button. |
#### Image #### Image

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,6 +40,34 @@ pub enum TransitionType {
SlideEnd, SlideEnd,
} }
#[derive(Debug, Default, Deserialize, Clone, Copy)]
#[serde(rename_all = "snake_case")]
pub enum ModuleOrientation {
#[default]
#[serde(alias = "h")]
Horizontal,
#[serde(alias = "v")]
Vertical,
}
impl ModuleOrientation {
pub const fn to_angle(self) -> f64 {
match self {
Self::Horizontal => 0.0,
Self::Vertical => 90.0,
}
}
}
impl From<ModuleOrientation> for Orientation {
fn from(o: ModuleOrientation) -> Self {
match o {
ModuleOrientation::Horizontal => Self::Horizontal,
ModuleOrientation::Vertical => Self::Vertical,
}
}
}
impl TransitionType { impl TransitionType {
pub const fn to_revealer_transition_type( pub const fn to_revealer_transition_type(
&self, &self,

View file

@ -34,7 +34,7 @@ use color_eyre::Result;
use serde::Deserialize; use serde::Deserialize;
use std::collections::HashMap; use std::collections::HashMap;
pub use self::common::{CommonConfig, TransitionType}; pub use self::common::{CommonConfig, ModuleOrientation, TransitionType};
pub use self::truncate::TruncateMode; pub use self::truncate::TruncateMode;
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]

View file

@ -8,7 +8,7 @@ use serde::Deserialize;
use tokio::sync::{broadcast, mpsc}; use tokio::sync::{broadcast, mpsc};
use tokio::time::sleep; use tokio::time::sleep;
use crate::config::CommonConfig; use crate::config::{CommonConfig, ModuleOrientation};
use crate::gtk_helpers::IronbarGtkExt; use crate::gtk_helpers::IronbarGtkExt;
use crate::modules::{ use crate::modules::{
Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, PopupButton, WidgetContext, Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, PopupButton, WidgetContext,
@ -31,6 +31,9 @@ pub struct ClockModule {
#[serde(default = "default_locale")] #[serde(default = "default_locale")]
locale: String, locale: String,
#[serde(default)]
orientation: ModuleOrientation,
#[serde(flatten)] #[serde(flatten)]
pub common: Option<CommonConfig>, pub common: Option<CommonConfig>,
} }
@ -41,6 +44,7 @@ impl Default for ClockModule {
format: default_format(), format: default_format(),
format_popup: default_popup_format(), format_popup: default_popup_format(),
locale: default_locale(), locale: default_locale(),
orientation: ModuleOrientation::Horizontal,
common: Some(CommonConfig::default()), common: Some(CommonConfig::default()),
} }
} }
@ -98,7 +102,7 @@ impl Module<Button> for ClockModule {
) -> Result<ModuleParts<Button>> { ) -> Result<ModuleParts<Button>> {
let button = Button::new(); let button = Button::new();
let label = Label::builder() let label = Label::builder()
.angle(info.bar_position.get_angle()) .angle(self.orientation.to_angle())
.use_markup(true) .use_markup(true)
.build(); .build();
button.add(&label); button.add(&label);

View file

@ -1,15 +1,15 @@
use super::{try_get_orientation, CustomWidget, CustomWidgetContext}; use super::{CustomWidget, CustomWidgetContext};
use crate::build; use crate::build;
use crate::config::ModuleOrientation;
use crate::modules::custom::WidgetConfig; use crate::modules::custom::WidgetConfig;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::Orientation;
use serde::Deserialize; use serde::Deserialize;
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]
pub struct BoxWidget { pub struct BoxWidget {
name: Option<String>, name: Option<String>,
class: Option<String>, class: Option<String>,
orientation: Option<String>, orientation: Option<ModuleOrientation>,
widgets: Option<Vec<WidgetConfig>>, widgets: Option<Vec<WidgetConfig>>,
} }
@ -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());
try_get_orientation(&orientation).unwrap_or(Orientation::Horizontal),
);
} }
if let Some(widgets) = self.widgets { if let Some(widgets) = self.widgets {

View file

@ -2,6 +2,7 @@ use gtk::prelude::*;
use gtk::{Button, Label, Orientation}; use gtk::{Button, Label, Orientation};
use serde::Deserialize; use serde::Deserialize;
use crate::config::ModuleOrientation;
use crate::dynamic_value::dynamic_string; use crate::dynamic_value::dynamic_string;
use crate::modules::PopupButton; use crate::modules::PopupButton;
use crate::{build, try_send}; use crate::{build, try_send};
@ -15,6 +16,8 @@ pub struct ButtonWidget {
label: Option<String>, label: Option<String>,
on_click: Option<String>, on_click: Option<String>,
widgets: Option<Vec<WidgetConfig>>, widgets: Option<Vec<WidgetConfig>>,
#[serde(default)]
orientation: ModuleOrientation,
} }
impl CustomWidget for ButtonWidget { impl CustomWidget for ButtonWidget {
@ -35,6 +38,9 @@ impl CustomWidget for ButtonWidget {
} else if let Some(text) = self.label { } else if let Some(text) = self.label {
let label = Label::new(None); let label = Label::new(None);
label.set_use_markup(true); label.set_use_markup(true);
label.set_angle(self.orientation.to_angle());
button.add(&label); button.add(&label);
dynamic_string(&text, move |string| { dynamic_string(&text, move |string| {

View file

@ -3,6 +3,7 @@ use gtk::Label;
use serde::Deserialize; use serde::Deserialize;
use crate::build; use crate::build;
use crate::config::ModuleOrientation;
use crate::dynamic_value::dynamic_string; use crate::dynamic_value::dynamic_string;
use super::{CustomWidget, CustomWidgetContext}; use super::{CustomWidget, CustomWidgetContext};
@ -12,6 +13,8 @@ pub struct LabelWidget {
name: Option<String>, name: Option<String>,
class: Option<String>, class: Option<String>,
label: String, label: String,
#[serde(default)]
orientation: ModuleOrientation,
} }
impl CustomWidget for LabelWidget { impl CustomWidget for LabelWidget {
@ -20,6 +23,8 @@ 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(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;
@ -113,17 +113,6 @@ pub fn set_length<W: WidgetExt>(widget: &W, length: i32, bar_orientation: Orient
}; };
} }
/// Attempts to parse an `Orientation` from `String`.
/// Will accept `horizontal`, `vertical`, `h` or `v`.
/// Ignores case.
fn try_get_orientation(orientation: &str) -> Result<Orientation> {
match orientation.to_lowercase().as_str() {
"horizontal" | "h" => Ok(Orientation::Horizontal),
"vertical" | "v" => Ok(Orientation::Vertical),
_ => Err(Report::msg("Invalid orientation string in config")),
}
}
impl WidgetOrModule { impl WidgetOrModule {
fn add_to(self, parent: &gtk::Box, context: &CustomWidgetContext, common: CommonConfig) { fn add_to(self, parent: &gtk::Box, context: &CustomWidgetContext, common: CommonConfig) {
match self { match self {

View file

@ -4,18 +4,20 @@ use serde::Deserialize;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tracing::error; use tracing::error;
use crate::config::ModuleOrientation;
use crate::dynamic_value::dynamic_string; use crate::dynamic_value::dynamic_string;
use crate::modules::custom::set_length; use crate::modules::custom::set_length;
use crate::script::{OutputStream, Script, ScriptInput}; use crate::script::{OutputStream, Script, ScriptInput};
use crate::{build, glib_recv_mpsc, spawn, try_send}; use crate::{build, glib_recv_mpsc, spawn, try_send};
use super::{try_get_orientation, CustomWidget, CustomWidgetContext}; use super::{CustomWidget, CustomWidgetContext};
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]
pub struct ProgressWidget { pub struct ProgressWidget {
name: Option<String>, name: Option<String>,
class: Option<String>, class: Option<String>,
orientation: Option<String>, #[serde(default)]
orientation: ModuleOrientation,
label: Option<String>, label: Option<String>,
value: Option<ScriptInput>, value: Option<ScriptInput>,
#[serde(default = "default_max")] #[serde(default = "default_max")]
@ -33,11 +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);
if let Some(orientation) = self.orientation { progress.set_orientation(self.orientation.into());
progress.set_orientation(
try_get_orientation(&orientation).unwrap_or(context.bar_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

@ -8,17 +8,19 @@ use serde::Deserialize;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tracing::error; use tracing::error;
use crate::config::ModuleOrientation;
use crate::modules::custom::set_length; use crate::modules::custom::set_length;
use crate::script::{OutputStream, Script, ScriptInput}; use crate::script::{OutputStream, Script, ScriptInput};
use crate::{build, glib_recv_mpsc, spawn, try_send}; use crate::{build, glib_recv_mpsc, spawn, try_send};
use super::{try_get_orientation, CustomWidget, CustomWidgetContext, ExecEvent}; use super::{CustomWidget, CustomWidgetContext, ExecEvent};
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]
pub struct SliderWidget { pub struct SliderWidget {
name: Option<String>, name: Option<String>,
class: Option<String>, class: Option<String>,
orientation: Option<String>, #[serde(default)]
orientation: ModuleOrientation,
value: Option<ScriptInput>, value: Option<ScriptInput>,
on_change: Option<String>, on_change: Option<String>,
#[serde(default = "default_min")] #[serde(default = "default_min")]
@ -45,11 +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);
if let Some(orientation) = self.orientation { scale.set_orientation(self.orientation.into());
scale.set_orientation(
try_get_orientation(&orientation).unwrap_or(context.bar_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

@ -181,7 +181,6 @@ impl Module<gtk::Button> for UpowerModule {
try_send!(tx, ModuleUpdateEvent::TogglePopup(button.popup_id())); try_send!(tx, ModuleUpdateEvent::TogglePopup(button.popup_id()));
}); });
label.set_angle(info.bar_position.get_angle());
let format = self.format.clone(); let format = self.format.clone();
let rx = context.subscribe(); let rx = context.subscribe();

View file

@ -0,0 +1,192 @@
{
position = "bottom"
start = [
{
type = "clock"
format = "%H:%M"
}
{
type = "clock"
format = "%H:%M"
orientation = "horizontal"
}
{
type = "clock"
format = "%H:%M"
orientation = "h"
}
{
type = "clock"
format = "%H:%M"
orientation = "vertical"
}
{
type = "clock"
format = "%H:%M"
orientation = "v"
}
{
type = "custom"
bar = [
{
type = "label"
label = "label"
}
{
type = "label"
label = "label"
orientation = "horizontal"
}
{
type = "label"
label = "label"
orientation = "h"
}
{
type = "label"
label = "label"
orientation = "vertical"
}
{
type = "label"
label = "label"
orientation = "v"
}
]
}
{
type = "custom"
bar = [
{
type = "button"
label = "label"
}
{
type = "button"
label = "label"
orientation = "horizontal"
}
{
type = "button"
label = "label"
orientation = "h"
}
{
type = "button"
label = "label"
orientation = "vertical"
}
{
type = "button"
label = "label"
orientation = "v"
}
]
}
{
type = "custom"
bar = [
{
type = "progress"
value = "echo 50"
}
{
type = "progress"
value = "echo 50"
orientation = "horizontal"
}
{
type = "progress"
value = "echo 50"
orientation = "h"
}
{
type = "progress"
value = "echo 50"
orientation = "vertical"
}
{
type = "progress"
value = "echo 50"
orientation = "v"
}
]
}
{
type = "custom"
bar = [
{
type = "slider"
value = "echo 50"
length = 100
}
{
type = "slider"
value = "echo 50"
length = 100
orientation = "horizontal"
}
{
type = "slider"
value = "echo 50"
length = 100
orientation = "h"
}
{
type = "slider"
value = "echo 50"
length = 100
orientation = "vertical"
}
{
type = "slider"
value = "echo 50"
length = 100
orientation = "v"
}
]
}
{
type = "sys_info"
interval.memory = 30
interval.cpu = 1
interval.temps = 5
interval.disks = 300
interval.networks = 3
format = [
" {cpu_percent}%"
" {memory_used} / {memory_total} GB ({memory_percent}%)"
"󰥔 {uptime}"
]
}
{
type = "sys_info"
orientation = "vertical"
interval.memory = 30
interval.cpu = 1
interval.temps = 5
interval.disks = 300
interval.networks = 3
format = [
" {cpu_percent}%"
" {memory_used} / {memory_total} GB ({memory_percent}%)"
"󰥔 {uptime}"
]
}
{
type = "sys_info"
layout = "vertical"
interval.memory = 30
interval.cpu = 1
interval.temps = 5
interval.disks = 300
interval.networks = 3
format = [
" {cpu_percent}%"
" {memory_used} / {memory_total} GB ({memory_percent}%)"
"󰥔 {uptime}"
]
}
]
}