~tsdh/swayr#45: 
Support "index mode" for more beautiful menus

In pickers the window ID is only there for Swayr's benefit-- it is visual clutter for the user, but there's a way to remove it.

A number of pickers support an "index mode" that returns the index of the item selected rather than the text selected. The feature exists for tools like swayr to build more attractive menus. It would be used like this:

  1. Swayr's config is set to use index mode
  2. Swayr holds an array in memory of all the window IDS.
  3. Swayr sends the list of lines to display to the picker in index mode without displaying the window ID.
  4. The picker sends back the index of the line selected (0-indexed).
  5. Swayr uses the index to lookup the window ID in the in-memory array.

Here's the syntax to use the feature in some common pickers:

  • fuzzel --dmenu --index
  • rofi -dmenu -format i
  • dmenu --index

Bemenu and wofi don't seem to support this option.

The current behavior can remain as option for pickers without index mode.

Status
RESOLVED IMPLEMENTED
Submitter
~markstos
Assigned to
No-one
Submitted
a month ago
Updated
a month ago
Labels
enhancement swayr

~tsdh a month ago

No, thank you. I don't think it's worth it to add so much complexity for a few reasons.

  1. As you say, it's only supported by few pickers whereas the current variant is the absolute minimum requirement one can have with a picker and therefore works with all of them.
  2. It provides a likely way to shot yourself in the foot, i.e., the new setting menu.index_mode would need to be in sync with menu.args. That is, if and only if you want to use this new index-mode with fuzzel, you need to make sure that "--index" is in menu.args.
  3. Being able to omit the {id} (the so-called con id in sway parlance) in formats doesn't strike me as important. Depending on the picker you use, you might be able to make that text invisible, e.g., using pango markup with wofi.
  4. You can already omit the {id} in your formats and it will be fine except in the edge case where you have many windows of the same application with the same title on the same workspace. But that would be problematic with your approach, too, in that the user cannot distinguish between those windows.

What could work without any complex changes was dynamically adding some sequence number to what's displayed in the picker only in the case that multiple candidates have the very same display string. For example, say you have 3 foot terminal windows with the same title ~, those would be displayed in the picker as:

  • ~ -- foot
  • ~ -- foot 2
  • ~ -- foot 3

Would that be fine, too?

~markstos a month ago

Thanks for the reply.

Your suggestion to include an ID only when necessary to uniquely identify a window would also be welcome and would address the goal in most cases.

Good idea!

~tsdh REPORTED IMPLEMENTED a month ago

Tassilo Horn referenced this ticket in commit d74355b.

~tsdh a month ago

I've implemented that, please test.

Note that it doesn't add the sway con ID to uniquify textually identical choices but just an increasing number. The reason is that the switcher function is generic: it might be used to choose a window, a swayr command, a swaymsg command, or something else. The list of items to choose from just have to implement a certain trait which is very simple but doesn't allow poking in the details of each concrete type.

~markstos a month ago

I have tested this, and can't confirm that it is working as intended. I used this window format and then tried the window switcher:

window_format = "{app_name:{:<11.11}} “{title:{:<60.60}...}” on {workspace_name:{:<13.13}}\u0000icon\u001f{app_icon}"

I then carefully made sure I was using the newly built binaries and restarted the swayrd service.

I launched two fish shells in terminals on the same workspace and confirmed that they had the same string displayed my picker, Fuzzel-- I expected one of the entries to have the unique string added to them, but neither one did.

~tsdh IMPLEMENTED IMPLEMENTED a month ago

Tassilo Horn referenced this ticket in commit f03a0fb.

~tsdh a month ago*

Ah, indeed, one thing I missed is that when the display string ends in this \0icon... thingy, then the uniquifying number has to go before the icon escape sequence. Should be fixed now.

~markstos a month ago

Tested to work now. Thanks!

Register here or Log in to comment, or comment via email.