add layer option, fixes #43

This commit is contained in:
Alexander Mohr 2025-05-28 15:45:37 +02:00
parent 79e8ac0a36
commit 01802fe84e
2 changed files with 44 additions and 4 deletions

View file

@ -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<Self, Self::Err> {
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<bool>,
#[clap(long = "dynamic-lines")]
dynamic_lines: Option<bool>, // todo support this
layer: Option<String>, // todo support this
#[clap(long = "layer")]
layer: Option<Layer>,
copy_exec: Option<String>, // todo support this
#[clap(long = "single_click")]
single_click: Option<bool>, // 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 {

View file

@ -485,6 +485,17 @@ fn modifiers_from_mask(mask: gdk4::ModifierType) -> HashSet<Modifier> {
modifiers
}
impl From<config::Layer> 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<T, P>(
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);