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

Merge branch 'master' into feat/volume-icon

This commit is contained in:
Reinout Meliesie 2024-06-30 18:15:15 +02:00
commit 9ea49202b3
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
55 changed files with 1161 additions and 556 deletions

View file

@ -16,6 +16,7 @@ use tracing::trace;
/// see [here](script).
/// For information on styling, please see the [styling guide](styling-guide).
#[derive(Debug, Default, Deserialize, Clone)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct CommonConfig {
/// Sets the unique widget name,
/// allowing you to target it in CSS using `#name`.
@ -160,6 +161,7 @@ pub struct CommonConfig {
#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum TransitionType {
None,
Crossfade,
@ -169,6 +171,7 @@ pub enum TransitionType {
#[derive(Debug, Default, Deserialize, Clone, Copy)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum ModuleOrientation {
#[default]
#[serde(alias = "h")]

View file

@ -35,6 +35,37 @@ impl<'de> Deserialize<'de> for MonitorConfig {
}
}
pub fn deserialize_layer<'de, D>(deserializer: D) -> Result<gtk_layer_shell::Layer, D::Error>
where
D: serde::Deserializer<'de>,
{
use gtk_layer_shell::Layer;
let value = Option::<String>::deserialize(deserializer)?;
value
.map(|v| match v.as_str() {
"background" => Ok(Layer::Background),
"bottom" => Ok(Layer::Bottom),
"top" => Ok(Layer::Top),
"overlay" => Ok(Layer::Overlay),
_ => Err(serde::de::Error::custom("invalid value for orientation")),
})
.unwrap_or(Ok(Layer::Top))
}
#[cfg(feature = "schema")]
pub fn schema_layer(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
use schemars::JsonSchema;
let mut schema: schemars::schema::SchemaObject = <String>::json_schema(gen).into();
schema.enum_values = Some(vec![
"background".into(),
"bottom".into(),
"top".into(),
"overlay".into(),
]);
schema.into()
}
impl BarPosition {
/// Gets the orientation the bar and widgets should use
/// based on this position.

View file

@ -38,11 +38,15 @@ use color_eyre::Result;
use serde::Deserialize;
use std::collections::HashMap;
#[cfg(feature = "schema")]
use schemars::JsonSchema;
pub use self::common::{CommonConfig, ModuleOrientation, TransitionType};
pub use self::truncate::TruncateMode;
#[derive(Debug, Deserialize, Clone)]
#[serde(tag = "type", rename_all = "snake_case")]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
pub enum ModuleConfig {
#[cfg(feature = "cairo")]
Cairo(Box<CairoModule>),
@ -123,6 +127,7 @@ impl ModuleConfig {
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
pub enum MonitorConfig {
Single(BarConfig),
Multiple(Vec<BarConfig>),
@ -130,6 +135,7 @@ pub enum MonitorConfig {
#[derive(Debug, Deserialize, Copy, Clone, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
pub enum BarPosition {
Top,
Bottom,
@ -144,6 +150,7 @@ impl Default for BarPosition {
}
#[derive(Debug, Default, Deserialize, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
pub struct MarginConfig {
#[serde(default)]
pub bottom: i32,
@ -162,6 +169,7 @@ pub struct MarginConfig {
/// depending on your [use-case](#2-pick-your-use-case).
///
#[derive(Debug, Deserialize, Clone)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
pub struct BarConfig {
/// A unique identifier for the bar, used for controlling it over IPC.
/// If not set, uses a generated integer suffix.
@ -214,6 +222,36 @@ pub struct BarConfig {
#[serde(default)]
pub margin: MarginConfig,
/// The layer-shell layer to place the bar on.
///
/// Taken from the
/// [wlr_layer_shell](https://wayland.app/protocols/wlr-layer-shell-unstable-v1#zwlr_layer_shell_v1:enum:layer) definition:
///
/// > These values indicate which layers a surface can be rendered in.
/// > They are ordered by z depth, bottom-most first.
/// > Traditional shell surfaces will typically be rendered between the bottom and top layers.
/// > Fullscreen shell surfaces are typically rendered at the top layer.
/// > Multiple surfaces can share a single layer, and ordering within a single layer is undefined.
///
/// **Valid options**: `background`, `bottom`, `top`, `overlay`
/// <br>
/// **Default**: `top`
#[serde(
default = "default_layer",
deserialize_with = "r#impl::deserialize_layer"
)]
#[cfg_attr(feature = "schema", schemars(schema_with = "r#impl::schema_layer"))]
pub layer: gtk_layer_shell::Layer,
/// Whether the bar should reserve an exclusive zone around it.
///
/// When true, this prevents windows from rendering in the same space
/// as the bar, causing them to shift.
///
/// **Default**: `true` unless `start_hidden` is set.
#[serde(default)]
pub exclusive_zone: Option<bool>,
/// The size of the gap in pixels
/// between the bar and the popup window.
///
@ -280,9 +318,11 @@ impl Default for BarConfig {
Self {
position: BarPosition::default(),
height: default_bar_height(),
margin: MarginConfig::default(),
name: None,
layer: default_layer(),
exclusive_zone: None,
height: default_bar_height(),
start_hidden: None,
autohide: None,
icon_theme: None,
@ -298,6 +338,7 @@ impl Default for BarConfig {
}
#[derive(Debug, Deserialize, Clone, Default)]
#[cfg_attr(feature = "schema", derive(JsonSchema))]
pub struct Config {
/// A map of [ironvar](ironvar) keys and values
/// to initialize Ironbar with on startup.
@ -337,6 +378,10 @@ pub struct Config {
pub monitors: Option<HashMap<String, MonitorConfig>>,
}
const fn default_layer() -> gtk_layer_shell::Layer {
gtk_layer_shell::Layer::Top
}
const fn default_bar_height() -> i32 {
42
}

View file

@ -4,6 +4,7 @@ use serde::Deserialize;
#[derive(Debug, Deserialize, Clone, Copy)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum EllipsizeMode {
Start,
Middle,
@ -28,6 +29,7 @@ impl From<EllipsizeMode> for GtkEllipsizeMode {
///
#[derive(Debug, Deserialize, Clone, Copy)]
#[serde(untagged)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum TruncateMode {
/// Auto mode lets GTK decide when to ellipsize.
///