From 818cc41aace34a14b164d70d276df4ffad5818bb Mon Sep 17 00:00:00 2001 From: Alexander Mohr Date: Sun, 25 May 2025 00:59:18 +0200 Subject: [PATCH] improve dmenu style, fix config loading issues --- styles/dmenu/config.toml | 4 ++-- styles/emoji/config | 2 +- styles/fullscreen/config.toml | 2 +- styles/launcher/config.toml | 2 +- worf/src/lib/config.rs | 18 ++++++++++++++---- worf/src/lib/gui.rs | 6 ++---- worf/src/main.rs | 9 ++++++++- 7 files changed, 29 insertions(+), 14 deletions(-) diff --git a/styles/dmenu/config.toml b/styles/dmenu/config.toml index 4dbb0d9..ebd10ee 100644 --- a/styles/dmenu/config.toml +++ b/styles/dmenu/config.toml @@ -2,9 +2,9 @@ image_size=0 columns=999 allow_images=false orientation="Horizontal" -row_bow_orientation="Horizontal" +row_box_orientation="Horizontal" content_halign="Start" -height="0" width="100%" hide_scroll=true location=["Top"] +lines=1 diff --git a/styles/emoji/config b/styles/emoji/config index 217d52a..6bfec0b 100644 --- a/styles/emoji/config +++ b/styles/emoji/config @@ -1,7 +1,7 @@ image_size=64 columns=6 orientation="Vertical" -row_bow_orientation="Vertical" +row_box_orientation="Vertical" content_halign="Center" height="70%" width="60%" diff --git a/styles/fullscreen/config.toml b/styles/fullscreen/config.toml index 80bab36..c7c3564 100644 --- a/styles/fullscreen/config.toml +++ b/styles/fullscreen/config.toml @@ -1,7 +1,7 @@ image_size=64 columns=6 orientation="Vertical" -row_bow_orientation="Vertical" +row_box_orientation="Vertical" content_halign="Center" height="105%" width="100%" diff --git a/styles/launcher/config.toml b/styles/launcher/config.toml index bae4b84..b8471ad 100644 --- a/styles/launcher/config.toml +++ b/styles/launcher/config.toml @@ -1,7 +1,7 @@ image_size=64 columns=6 orientation="Vertical" -row_bow_orientation="Vertical" +row_box_orientation="Vertical" content_halign="Center" height="70%" width="60%" diff --git a/worf/src/lib/config.rs b/worf/src/lib/config.rs index 1a4cfa4..35a192c 100644 --- a/worf/src/lib/config.rs +++ b/worf/src/lib/config.rs @@ -57,7 +57,6 @@ pub enum CustomKeyHintLocation { } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] - pub enum KeyDetectionType { /// Raw keyboard value, might not be correct all layouts Code, @@ -282,8 +281,13 @@ pub struct Config { #[clap(short = 'a', long = "no-actions")] no_actions: Option, + /// If set, the given amount tof lines will be shown #[clap(short = 'L', long = "lines")] - lines: Option, // todo support this + lines: Option, + + /// Additional space to add to the window when `lines` is used. + #[clap(long = "line-additional-space")] + lines_additional_space: Option, #[clap(short = 'w', long = "columns")] columns: Option, @@ -342,7 +346,7 @@ pub struct Config { #[clap(long = "hide-search")] hide_search: Option, #[clap(long = "dynamic-lines")] - dynamic_lines: bool, // todo support this + dynamic_lines: Option, // todo support this layer: Option, // todo support this copy_exec: Option, // todo support this #[clap(long = "single_click")] @@ -472,7 +476,7 @@ impl Config { } #[must_use] - pub fn row_bow_orientation(&self) -> Orientation { + pub fn row_box_orientation(&self) -> Orientation { self.row_box_orientation.unwrap_or(Orientation::Horizontal) } @@ -566,6 +570,11 @@ impl Config { pub fn lines(&self) -> Option { self.lines } + + #[must_use] + pub fn lines_additional_space(&self) -> i32 { + self.lines_additional_space.unwrap_or(0) + } } fn default_false() -> bool { @@ -722,6 +731,7 @@ pub fn load_config(args_opt: Option<&Config>) -> Result { let config_path = conf_path(args_opt.as_ref().and_then(|c| c.cfg_path.as_ref())); match config_path { Ok(path) => { + log::debug!("loading config from {}", path.display()); let toml_content = fs::read_to_string(path).map_err(|e| Error::Io(format!("{e}")))?; let mut config: Config = toml::from_str(&toml_content).map_err(|e| Error::ParsingError(format!("{e}")))?; diff --git a/worf/src/lib/gui.rs b/worf/src/lib/gui.rs index 8d8f699..4c6428b 100644 --- a/worf/src/lib/gui.rs +++ b/worf/src/lib/gui.rs @@ -1176,13 +1176,11 @@ fn window_show_resize(config: &Config, ui: &Rc // todo fix this eventually properly, so baseline is always set and not only in 85% of cases. let height = if baseline > 0 { baseline - } else if config.allow_images() { - i32::from(config.image_size()) // wild guess that image makes the most part of the row ... } else { nat // for my configuration way bigger than baseline }; - Some((height_search + height) * lines) + Some((height_search + height) * lines + config.lines_additional_space()) } else { log::warn!("No widget for height calculation available"); Some(0) @@ -1330,7 +1328,7 @@ fn create_menu_row( row.set_halign(Align::Fill); row.set_widget_name("row"); - let row_box = gtk4::Box::new(meta.config.row_bow_orientation().into(), 0); + let row_box = gtk4::Box::new(meta.config.row_box_orientation().into(), 0); row_box.set_hexpand(true); row_box.set_vexpand(false); row_box.set_halign(Align::Fill); diff --git a/worf/src/main.rs b/worf/src/main.rs index ee0142d..9c5d6fa 100644 --- a/worf/src/main.rs +++ b/worf/src/main.rs @@ -11,8 +11,15 @@ fn main() -> anyhow::Result<()> { .init(); let args = config::parse_args(); - let config = config::load_config(Some(&args)).unwrap_or(args); + let config = config::load_config(Some(&args)); + let config = match config { + Ok(c) => c, + Err(e) => { + log::error!("error during config load, skipping it, {e}"); + args + } + }; fork_if_configured(&config); if let Some(show) = &config.show() {