diff --git a/worf/src/lib/config.rs b/worf/src/lib/config.rs index f3f94d5..cd3b86c 100644 --- a/worf/src/lib/config.rs +++ b/worf/src/lib/config.rs @@ -89,6 +89,28 @@ pub enum Mode { Emoji, } +#[derive(Clone, Debug, Serialize, Deserialize)] +pub enum Layer { + Background, + Bottom, + Top, + Overlay +} + +impl FromStr for Layer { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "Background" => Ok(Layer::Background), + "Bottom" => Ok(Layer::Bottom), + "Top" => Ok(Layer::Top), + "Overlay" => Ok(Layer::Overlay), + _ => Err(format!("{s} is not a valid layer.")), + } + } +} + #[derive(Debug, Error)] pub enum ArgsError { #[error("input is not valid {0}")] @@ -344,9 +366,13 @@ pub struct Config { /// If set to `true` the search field willOption<> be hidden. #[clap(long = "hide-search")] hide_search: Option, + #[clap(long = "dynamic-lines")] dynamic_lines: Option, // todo support this - layer: Option, // todo support this + + #[clap(long = "layer")] + layer: Option, + copy_exec: Option, // todo support this #[clap(long = "single_click")] single_click: Option, // todo support this @@ -579,6 +605,11 @@ impl Config { pub fn version(&self) -> bool { self.version } + + #[must_use] + pub fn layer(&self) -> Layer { + self.layer.clone().unwrap_or(Layer::Top) + } } fn default_false() -> bool { diff --git a/worf/src/lib/gui.rs b/worf/src/lib/gui.rs index 9b8155e..77b383a 100644 --- a/worf/src/lib/gui.rs +++ b/worf/src/lib/gui.rs @@ -485,6 +485,17 @@ fn modifiers_from_mask(mask: gdk4::ModifierType) -> HashSet { modifiers } +impl From for gtk4_layer_shell::Layer{ + fn from(value: config::Layer) -> Self { + match value { + config::Layer::Background => gtk4_layer_shell::Layer::Background, + config::Layer::Bottom => gtk4_layer_shell::Layer::Bottom, + config::Layer::Top => gtk4_layer_shell::Layer::Top, + config::Layer::Overlay => gtk4_layer_shell::Layer::Overlay, + } + } +} + #[derive(Clone, PartialEq, Debug)] pub struct KeyBinding { pub key: Key, @@ -674,9 +685,7 @@ fn build_ui( if !config.normal_window() { // Initialize the window as a layer ui_elements.window.init_layer_shell(); - ui_elements - .window - .set_layer(gtk4_layer_shell::Layer::Overlay); + ui_elements.window.set_layer(config.layer().into()); ui_elements .window .set_keyboard_mode(KeyboardMode::Exclusive);