davatorium / rofi

Rofi: A window switcher, application launcher and dmenu replacement
https://davatorium.github.io/rofi/
Other
12.95k stars 608 forks source link

[REQUEST] Custom order of window list. #1965

Open arakis opened 5 months ago

arakis commented 5 months ago

Before opening a feature request

What is the user problem or growth opportunity you want to see solved?

I would like to have a custom order in the window list, specifically a MRU (Most Recently Used) list.

I already have an i3 IPC listener that tracks the MRU list. Now, I would like to pass the window IDs to Rofi, for example via a command like -window-ids 123,124,125,126. If a window ID is invalid, it should be ignored. If a window ID is missing, the rendering should be skipped - with this latter behavior, you also have control over whether the windows are workspace, screen, or otherwise scoped.

Another approach could be to add a sort script: Pass all entries as standard input to a script, and that script returns a list of indexes as standard output. In this case, the standard input should contain some metadata, like window IDs.

I have also considered using script mode or dmenu mode. However, I'm not sure how complicated it would be to track all icons of the active windows, retrieve the path of the icon files, and pass them to the script mode - and this process would have to be very efficient, of course.

How do you know that this problem exists today? Why is this important?

In i3, the order of the windows depends on the container layout.

Who will benefit from it?

Everybody who wishes a MRU based list.

Rofi version (rofi -v)

1.7.5

Configuration

-

Additional information

No response

DaveDavenport commented 5 months ago

Can't you implement this easily using script mode and i3's ipc? I wonder if we can help with the icon for an application in a way. (looking up icon for window class would be easy, I wonder if we can implement something to fetch icon for window id).

arakis commented 5 months ago

Implementing via script mode and IPC would work, but as you said, I need an efficient and safe way to show the icons.

arakis commented 5 months ago

By the way, I also see that the original window list has some additional features/columns: Workspace number, and separate columns for Process name and Window Title.

So, it might be challenging to mimic this list one-to-one, solely for custom order.

arakis commented 5 months ago

There might be another issue with script mode: it can be quite slow, especially when running in notebook power-saving mode.

#!/usr/bin/env bash

# https://gist.github.com/Atreyagaurav/2b70bb997fa5eff45c924e86095080e8

$(jq -r '.scripts | .["'$(jq -r '.scripts|keys[]' \
                             ~/.config/rofi/scripts/custom-menu.json \
                              | rofi -dmenu)'"] |.script' \
     ~/.config/rofi/scripts/custom-menu.json)
{
  "bgcolor": "black",
  "scripts": {
    "rdp-arakis": {
      "name": "RDP Arakis",
      "script": "/home/sebastian/.scripts/launch-rdp-arakis.sh",
      "tooltip": "RDP Arakis"
    }
  }
}

When launching the aforementioned script, rofi will be displayed immediately - but it can take up to 2 seconds until the list is filled (in this case, a single entry), when in power save mode. When plugged into power, the list will be filled immediately.

In contrast to the window list: This mode will always be rendered immediately, without noticing any delay, regardless of the power mode.

For a window switcher, any delay will kill the user experience.

So, passing the order of window-id's via command line may still be the most performant way.

lbonn commented 5 months ago

@arakis this may interest you: https://github.com/lbonn/i3-focus-last, it uses dmenu mode.

I am also working on a rofi plugin version (in the repo as well) which mostly works but still needs a bit of polish.

DaveDavenport commented 5 months ago

supprising that in power saving mode it is so slow.. I wonder why and if it has something to do with rofi's async loading in dmenu.

btw the above is not script mode? but dmenu mode. there is a (slight) difference.

DaveDavenport commented 5 months ago
~/.config/rofi/scripts/custom-menu.json

I am confused by this, rofi does not support json menus. That directory should have script mode scripts.

arakis commented 5 months ago

You're right, rofi does not support json. It's just an input file for the jq tool. See https://gist.github.com/Atreyagaurav/2b70bb997fa5eff45c924e86095080e8

DaveDavenport commented 5 months ago

That directory is already 'used' by rofi to auto-load mode scripts. You might want to avoid using that.