20
849
Fork
You've already forked fuzzel
83

WIP: Add --preview-selection, alt approach #593

Closed
markstos wants to merge 3 commits from markstos/fuzzel:preview-selection-alt into master
pull from: markstos/fuzzel:preview-selection-alt
merge into: dnkl:master
dnkl:master
dnkl:gnome-support
dnkl:releases/1.14
dnkl:issue-319-window-switching
dnkl:issue-561-nord-theme-only
dnkl:resvg-filtering-take-2
dnkl:resvg-filtering
dnkl:releases/1.13
dnkl:rehanzo-dont-ignore-execute-648
dnkl:keybinds-overwrite
dnkl:issue-561-refresh-theme
dnkl:ci-automated-testing
dnkl:reenable-legacy-icons
dnkl:releases/1.12
dnkl:test-coverage-for-fzf-caching
dnkl:releases/1.11
dnkl:releases/1.10
dnkl:releases/1.9
dnkl:releases/1.8
dnkl:releases/1.7
dnkl:releases/1.6
dnkl:releases/1.5
dnkl:releases/1.4
dnkl:releases/1.3
dnkl:releases/1.2
dnkl:releases/1.1
dnkl:releases/1.0
Collaborator
Copy link

Implements feature without duplicate KEEP_RUNNING code from #496. Also adds docs, completions and Changelog entry.

Implements feature without duplicate KEEP_RUNNING code from #496. Also adds docs, completions and Changelog entry.
First-time contributor
Copy link

Nice! I tried this with my setup from #496 and it looks good.

Nice! I tried this with my setup from https://codeberg.org/dnkl/fuzzel/pulls/496 and it looks good.
dnkl left a comment
Copy link

This is slightly better, but unfortunately breaks in subtle ways if there are multiple seats enabled/active (for example, XDG activation token retrieval is likely to fail, meaning the launched application cannot be activated/focused properly by the compositor).

How about a third approach, where we:

  • Add a boolean parameter to execute_selected(), telling it whether it's a "preview" or not (and thus whether it should set wayl->status, or leave it as is)
  • Break out the if (preview_selection) ... logic to a separate function
  • Call this function from wayland.c, similar to how the first PR implemented this feature.

The function could have an early exit:

if (!(conf->dmenu.enabled && conf->dmenu.preview_selection))
 return;
execute_selected(..., preview=true);

That way, we don't have to check if preview_selection has been enabled in every single place the selection is updated.

This is slightly better, but unfortunately breaks in subtle ways if there are multiple seats enabled/active (for example, XDG activation token retrieval is likely to fail, meaning the launched application cannot be activated/focused properly by the compositor). How about a third approach, where we: * Add a boolean parameter to `execute_selected()`, telling it whether it's a "preview" or not (and thus whether it should set `wayl->status`, or leave it as is) * Break out the `if (preview_selection) ...` logic to a separate function * Call this function from `wayland.c`, similar to how the first PR implemented this feature. The function could have an early exit: ```c if (!(conf->dmenu.enabled && conf->dmenu.preview_selection)) return; execute_selected(..., preview=true); ``` That way, we don't have to check if preview_selection has been enabled in every single place the selection is updated.
Author
Collaborator
Copy link

@dnkl Check out the latest commit to see if it's more like what you had mind.

@dnkl Check out the latest commit to see if it's more like what you had mind.
Owner
Copy link

@markstos yeah, something like that. Now all that remains is removing the callback mechanism, and calling preview() directly from wayland.c (this is necessary to keep supporting multi-seat).

@markstos yeah, something like that. Now all that remains is removing the callback mechanism, and calling `preview()` directly from `wayland.c` (this is necessary to keep supporting multi-seat).
Contributor
Copy link

fuzzel will produce an output each time selection changes

This is little misleading since it won't trigger when selection is changed by the query

> fuzzel will produce an output each time selection changes This is little misleading since it won't trigger when selection is changed by the query
Contributor
Copy link

Also, it doesn't trigger on initial selection. So to "preview" initial selection user would have to to up or down and back.

Also, it doesn't trigger on initial selection. So to "preview" initial selection user would have to to up or down and back.
markstos force-pushed preview-selection-alt from bd06a0f25b
Some checks are pending
ci/woodpecker/pr/woodpecker Pipeline is pending approval
builds.sr.ht/freebsd-x64 Job completed
to d3663fb9dd
Some checks reported errors
ci/woodpecker/pr/woodpecker Pipeline is pending approval
builds.sr.ht/freebsd-x64 Job failed
2025年06月30日 21:10:48 +02:00
Compare
Author
Collaborator
Copy link

Ready for re-testing. Here's what to test:

echo -e 'first\nsecond' | ./pkg/fuzzel/usr/bin/fuzzel --preview-selection --minimal-lines --dmenu --width 10

  • Test initial selection
  • Test changing selection by filtering
  • Test that the same selection is not repeated. Only output when selection when changes.
  • Test selecting by arrow keys
  • Test final selection is still emited.
Ready for re-testing. Here's what to test: echo -e 'first\nsecond' | ./pkg/fuzzel/usr/bin/fuzzel --preview-selection --minimal-lines --dmenu --width 10 - Test initial selection - Test changing selection by filtering - Test that the same selection is not repeated. Only output when selection when changes. - Test selecting by arrow keys - Test final selection is still emited.
Owner
Copy link

This currently fails to build:

../../wayland.c: In function ‘wl_touch_up’:
../../wayland.c:1288:21: error: too few arguments to function ‘execute_selected’; expected 4, have 3
 1288 | execute_selected(seat, false, -1);
 | ^~~~~~~~~~~~~~~~
../../wayland.c:575:1: note: declared here
 575 | execute_selected(struct seat *seat, bool as_is, int custom_success_exit_code, bool preview)
 | ^~~~~~~~~~~~~~~~

(also seen in the CI)

This currently fails to build: ``` ../../wayland.c: In function ‘wl_touch_up’: ../../wayland.c:1288:21: error: too few arguments to function ‘execute_selected’; expected 4, have 3 1288 | execute_selected(seat, false, -1); | ^~~~~~~~~~~~~~~~ ../../wayland.c:575:1: note: declared here 575 | execute_selected(struct seat *seat, bool as_is, int custom_success_exit_code, bool preview) | ^~~~~~~~~~~~~~~~ ``` (also seen in the CI)
markstos force-pushed preview-selection-alt from d3663fb9dd
Some checks reported errors
ci/woodpecker/pr/woodpecker Pipeline is pending approval
builds.sr.ht/freebsd-x64 Job failed
to b49f023bfe
Some checks are pending
ci/woodpecker/pr/woodpecker Pipeline is pending approval
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pull_request_closed/woodpecker Pipeline is pending approval
2025年07月01日 13:42:58 +02:00
Compare
Author
Collaborator
Copy link

Looks like a bad rebase/merge caused a build failure. Fixed now.

Looks like a bad rebase/merge caused a build failure. Fixed now.
markstos changed title from (削除) Add --preview-selection, alt approach (削除ここまで) to WIP: Add --preview-selection, alt approach 2025年07月01日 14:00:08 +02:00
Author
Collaborator
Copy link

Converting this back to a draft because I'm not sure the UX here is the best for handling previews. There's an alternate way to think about it over this issue request:

#428 (comment)

Instead of emitting the selection to STDOUT, we could instead directly call a command with it. That eliminates the need to use some wrapper script to handle the selections, and keeps STDOUT used exclusively for the final output. Ex:

## If {selection} is not present, we pass it as arg to this command
--selection-cmd=imv
## Or if {selection} is present, we assume this is a command with arguments
--selection-cmd=/bin/imv {selection}

Waiting now to gather some feedback before considering a change of course.

Converting this back to a draft because I'm not sure the UX here is the best for handling previews. There's an alternate way to think about it over this issue request: https://codeberg.org/dnkl/fuzzel/issues/428#issuecomment-5674559 Instead of emitting the selection to STDOUT, we could instead directly call a command with it. That eliminates the need to use some wrapper script to handle the selections, and keeps STDOUT used exclusively for the final output. Ex: ``` ## If {selection} is not present, we pass it as arg to this command --selection-cmd=imv ## Or if {selection} is present, we assume this is a command with arguments --selection-cmd=/bin/imv {selection} ``` Waiting now to gather some feedback before considering a change of course.
Contributor
Copy link

For current approach:

  • initial selection
  • changing selection by filtering
  • that the same selection is not repeated. Only output when selection when changes.
  • selecting by arrow keys
  • final selection is still emited.

changing selection by filtering repro:

  1. initial: "first" printed
  2. query "s": "second" printed
  3. query "" (empty): first is selected but NOT printed
  4. submit: "first" printed
For current approach: - initial selection ✅ - changing selection by filtering ❌ - that the same selection is not repeated. Only output when selection when changes. ✅ - selecting by arrow keys ✅ - final selection is still emited. ✅ changing selection by filtering repro: 1. initial: "first" printed 2. query "s": "second" printed 3. query "" (empty): first is selected but _NOT_ printed 4. submit: "first" printed
Contributor
Copy link

For "--selection-cmd" approach, this is how fzf does it (--bind='focus:execute-silent:COMMAND). I just started learning advanced uses of fzf like a week ago so can't say much about which approach would be better for fuzzel.

For "--selection-cmd" approach, this is how fzf does it (`--bind='focus:execute-silent:COMMAND`). I just started learning advanced uses of fzf like a week ago so can't say much about which approach would be better for fuzzel.
Author
Collaborator
Copy link

I like to align with other projects where it makes sense, so thanks for the fzf reference. fzf supports a very complex combination of many events triggers and actions. I'm not sure we'll want to implement all those, but it does look like a flexible and extensible system without adding an explosion of options. So maybe should adopt their --bind syntax, even if we only have a minimal number of triggers and actions now.

I like to align with other projects where it makes sense, so thanks for the `fzf` reference. fzf supports a very complex combination of many events triggers and actions. I'm not sure we'll want to implement all those, but it does look like a flexible and extensible system without adding an explosion of options. So maybe should adopt their `--bind` syntax, even if we only have a minimal number of triggers and actions now.
markstos changed title from (削除) WIP: Add --preview-selection, alt approach (削除ここまで) to WIP: Add --preview-selection, alt approach 2025年07月02日 23:03:40 +02:00
Owner
Copy link

I think having a way to define a custom command to execute for previews is a much better approach than printing to stdout. It always bothered me that there were no obvious way to distinguish previews from the final, selected item, other that "it's the last printed item before fuzzel exited". But if you want to do something different for that item (and more importantly, not doing whatever you do to preview items), you couldn't really do that.

As for how to implement it, I'm open for suggestions. I'm not sure it makes sense to implement a complex bind syntax when we don't have any other actions to bind. Perhaps go with a simple preview-command for now? It can always be converted to something else in the future.

I think having a way to define a custom command to execute for previews is a much better approach than printing to stdout. It always bothered me that there were no obvious way to distinguish previews from the final, selected item, other that "it's the last printed item before fuzzel exited". But if you want to do something different for that item (and more importantly, **not** doing whatever you do to preview items), you couldn't really do that. As for how to implement it, I'm open for suggestions. I'm not sure it makes sense to implement a complex bind syntax when we don't have any other actions to bind. Perhaps go with a simple `preview-command` for now? It can always be converted to something else in the future.
Author
Collaborator
Copy link

I think having a way to define a custom command to execute for previews is a much better approach than printing to stdout.

Having considered the the options, I agree.

I'm not sure it makes sense to implement a complex bind syntax when we don't have any other actions to bind.

I also agree. Although fzf does that, I just don't see Fuzzel adding so many "hooks" for external actions like that.

Perhaps go with a simple --preview-command for now? It can always be converted to something else in the future.

Yes, but what about adopting the naming convention of JavaScript events, where they name event handles like "onFocus", "onMouseOver" and so forth. On this case, perhaps:

--on-select-command

This both clarifies that it's an command triggered by an event also sets a precedent for other other event handler commands would be named if we were to add any more.

> I think having a way to define a custom command to execute for previews is a much better approach than printing to stdout. Having considered the the options, I agree. > I'm not sure it makes sense to implement a complex bind syntax when we don't have any other actions to bind. I also agree. Although fzf does that, I just don't see Fuzzel adding so many "hooks" for external actions like that. > Perhaps go with a simple `--preview-command` for now? It can always be converted to something else in the future. Yes, but what about adopting the naming convention of JavaScript events, where they name event handles like "onFocus", "onMouseOver" and so forth. On this case, perhaps: ``` --on-select-command ``` This both clarifies that it's an command triggered by an event also sets a precedent for other other event handler commands would be named if we were to add any more.
Owner
Copy link

On this case, perhaps:

--on-select-command

Sounds good to me :)

> On this case, perhaps: > ``` > --on-select-command > ``` Sounds good to me :)
Author
Collaborator
Copy link

The color picking tool maybe a related user, but needs more testing to understand how it works.

https://github.com/tom-gora/gmenu

The color picking tool maybe a related user, but needs more testing to understand how it works. https://github.com/tom-gora/gmenu
Author
Collaborator
Copy link

Because we are going to change the implementation significantly and because this already conflicts so badly, I'm going to close this PR, and we'll try again later with --on-selection-cmd.

Because we are going to change the implementation significantly and because this already conflicts so badly, I'm going to close this PR, and we'll try again later with `--on-selection-cmd`.
markstos closed this pull request 2025年08月22日 20:49:00 +02:00
Some checks are pending
ci/woodpecker/pr/woodpecker Pipeline is pending approval
builds.sr.ht/freebsd-x64 Job completed
ci/woodpecker/pull_request_closed/woodpecker Pipeline is pending approval

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dnkl/fuzzel!593
Reference in a new issue
dnkl/fuzzel
No description provided.
Delete branch "markstos/fuzzel:preview-selection-alt"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?