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

feat: ability to set bar layer and exclusive zone

This commit is contained in:
Jake Stanger 2024-06-13 21:42:40 +01:00
parent c28de8d902
commit aa45396062
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
7 changed files with 145 additions and 36 deletions

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

@ -216,6 +216,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.
///
@ -282,9 +312,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,
@ -340,6 +372,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
}