improve dmenu style, fix config loading issues

This commit is contained in:
Alexander Mohr 2025-05-25 00:59:18 +02:00
parent eafd962276
commit 818cc41aac
7 changed files with 29 additions and 14 deletions

View file

@ -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

View file

@ -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%"

View file

@ -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%"

View file

@ -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%"

View file

@ -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<bool>,
/// If set, the given amount tof lines will be shown
#[clap(short = 'L', long = "lines")]
lines: Option<i32>, // todo support this
lines: Option<i32>,
/// Additional space to add to the window when `lines` is used.
#[clap(long = "line-additional-space")]
lines_additional_space: Option<i32>,
#[clap(short = 'w', long = "columns")]
columns: Option<u32>,
@ -342,7 +346,7 @@ pub struct Config {
#[clap(long = "hide-search")]
hide_search: Option<bool>,
#[clap(long = "dynamic-lines")]
dynamic_lines: bool, // todo support this
dynamic_lines: Option<bool>, // todo support this
layer: Option<String>, // todo support this
copy_exec: Option<String>, // 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<i32> {
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<Config, Error> {
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}")))?;

View file

@ -1176,13 +1176,11 @@ fn window_show_resize<T: Clone + 'static>(config: &Config, ui: &Rc<UiElements<T>
// 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<T: Clone + 'static + Send>(
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);

View file

@ -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() {