From c5ef072cffec6e97777ae66f1ee8edaaf7a7d84d Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Wed, 1 Feb 2023 17:32:45 +0200 Subject: add position config option --- README.md | 1 + src/config.rs | 19 +++++++++++++++++++ src/state.rs | 6 ++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 58ae821..eabc5c8 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ tags_padding = 25 blocks_r = 6 blocks_overlap = 0 command = "i3status-rs" +position = "top" hide_inactive_tags = true invert_touchpad_scrolling = true show_layout_name = false diff --git a/src/config.rs b/src/config.rs index a20f60e..9770858 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,4 +1,5 @@ use crate::color::Color; +use crate::protocol::zwlr_layer_surface_v1; use anyhow::{Context, Result}; use dirs_next::config_dir; use pangocairo::pango::FontDescription; @@ -33,6 +34,7 @@ pub struct Config { // command pub command: Option, // misc + pub position: Position, pub hide_inactive_tags: bool, pub invert_touchpad_scrolling: bool, pub show_layout_name: bool, @@ -61,6 +63,7 @@ impl Default for Config { blocks_r: 0.0, blocks_overlap: 0.0, command: None, + position: Position::Top, hide_inactive_tags: true, invert_touchpad_scrolling: true, show_layout_name: true, @@ -92,6 +95,22 @@ impl Config { } } +#[derive(Deserialize, Debug, Clone, Copy)] +#[serde(rename_all = "lowercase")] +pub enum Position { + Top, + Bottom, +} + +impl From for zwlr_layer_surface_v1::Anchor { + fn from(position: Position) -> Self { + match position { + Position::Top => Self::Top | Self::Left | Self::Right, + Position::Bottom => Self::Bottom | Self::Left | Self::Right, + } + } +} + #[derive(Debug)] pub struct Font(pub FontDescription); diff --git a/src/state.rs b/src/state.rs index c283678..6844e56 100644 --- a/src/state.rs +++ b/src/state.rs @@ -155,18 +155,16 @@ impl State { let surface = self.wl_compositor.create_surface(conn); - use zwlr_layer_shell_v1::Layer; - use zwlr_layer_surface_v1::Anchor; let layer_surface = self.layer_shell.get_layer_surface_with_cb( conn, surface, output, - Layer::Top, + zwlr_layer_shell_v1::Layer::Top, wayrs_client::cstr!("i3bar-river").into(), layer_surface_cb, ); layer_surface.set_size(conn, 0, self.shared_state.config.height); - layer_surface.set_anchor(conn, Anchor::Top | Anchor::Left | Anchor::Right); // Top + Left + Right + layer_surface.set_anchor(conn, self.shared_state.config.position.into()); // Top + Left + Right layer_surface.set_exclusive_zone(conn, self.shared_state.config.height as i32 + 5); // TODO: make the margin configurable // Note: layer_surface is commited when we receive the scale factor of this output -- cgit v1.3.1