From c852847ffce6cec56371cc15f56a710631ec3c9b Mon Sep 17 00:00:00 2001 From: Alexander Mohr Date: Thu, 5 Jun 2025 19:57:22 +0200 Subject: [PATCH] support single click fixes #45 --- README.md | 10 +++++----- worf/src/lib/config.rs | 16 ++++++++++++++-- worf/src/lib/gui.rs | 5 ++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ba3b074..4c5ad1d 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,11 @@ Worf is yet another style launcher, heavily inspired by **wofi**, **rofi**, and Auto mode intelligently detects what you're trying to do! Use these prefixes for quick access: -| Prefix | Mode | Description | -|--------|------|-------------| -| `ssh` | SSH | Connect to servers (optional prefix) | -| `?` | Web Search | Search the web | -| `/`, `$`, `~` | Files | Browse filesystem | +| Prefix | Mode | Description | +|---------------|------------|--------------------------------------| +| `ssh` | SSH | Connect to servers (optional prefix) | +| `?` | Web Search | Search the web | +| `/`, `$`, `~` | Files | Browse filesystem | ![Demo](images/demo.gif) diff --git a/worf/src/lib/config.rs b/worf/src/lib/config.rs index 1b3a87b..9adaaa2 100644 --- a/worf/src/lib/config.rs +++ b/worf/src/lib/config.rs @@ -383,12 +383,19 @@ pub struct Config { #[clap(long = "dynamic-lines-limit")] dynamic_lines_limit: Option, + /// Defines the layer worf is running on. + /// Has no effect when normal window is used. + /// defaults to `Top` #[clap(long = "layer")] layer: Option, copy_exec: Option, // todo support this - #[clap(long = "single_click")] - single_click: Option, // todo support this + + /// If set to `true` single click instead of double click will select + /// Defaults to `false` + #[clap(long = "single-click")] + single_click: Option, + #[clap(long = "pre-display-exec")] pre_display_exec: Option, // todo support this @@ -452,6 +459,11 @@ impl Config { self.matching.unwrap_or(MatchMethod::Contains) } + #[must_use] + pub fn single_click(&self) -> bool { + self.single_click.unwrap_or(false) + } + #[must_use] pub fn fuzzy_min_score(&self) -> f64 { self.fuzzy_min_score.unwrap_or(0.0) diff --git a/worf/src/lib/gui.rs b/worf/src/lib/gui.rs index 677302b..069aa38 100644 --- a/worf/src/lib/gui.rs +++ b/worf/src/lib/gui.rs @@ -1490,8 +1490,11 @@ fn create_menu_row( let click = GestureClick::new(); click.set_button(gtk4::gdk::BUTTON_PRIMARY); + + let presses = if meta.config.single_click() { 1 } else { 2 }; + click.connect_pressed(move |_gesture, n_press, _x, _y| { - if n_press == 2 { + if n_press == presses { if let Err(e) = handle_selected_item( &click_ui, Rc::>::clone(&click_meta),