davatorium / rofi

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

Ability to *replace* the list in combi mode via a script #1934

Open schaefsteven opened 9 months ago

schaefsteven commented 9 months ago

Before opening a feature request

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

Scripts that return new options (such as confirmation dialogs) do not replace the entire list of options in combi mode. They only replace their own options.

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

I have tested and looked for a solution and can not find any.

Who will benefit from it?

Users who wish to have a lot of functionality in combi mode, which reduces the need to remember multiple keyboard shortcuts

Rofi version (rofi -v)

1.7.3

Configuration

https://gist.github.com/schaefsteven/3ebbe2a001ecebed7af23cdd36eeffe4

Additional information

If a script returns new options to rofi, rofi (in single-mode operation) replaces the current list of options with the new list. In combi mode, the other modi's options remain in the list.

In my case, I have combi mode with drun and a Power Management script, which asks for confirmation before executing its commands, but the confirmation options appear at the end of the options list (off the screen), which is not the desired function.

schaefsteven commented 9 months ago

Note: one workaround for this is to run a new instance of rofi instead of returning new items to the existing instance. However this makes the code of the script much more clunky (the first instance calls your script again, which needs to parse the argument, and then run rofi, running your script a third time with another more different argument), causes the window to blink closed for a moment (not a big deal, but still worth mentioning), and just overall feels like the wrong answer.

DaveDavenport commented 9 months ago

I don't understand this request.. You want want to combine the lists of multiple modes, this is what combi mode does and what you indicate it does, but also not?

It sounds more liike you do not want to use combi mode, but open multiple modes at the same time (under one keybinding), something rofi can do.

schaefsteven commented 9 months ago

I don't understand this request.. You want want to combine the lists of multiple modes, this is what combi mode does and what you indicate it does, but also not?

Yes, when I call Rofi with my key bind, I want it to show multiple modes, but then when I use that list to call the option from one of my modes, I want what that mode returns to be the only thing listed.

I guess I don't really understand the use case of combi mode with its current implementation when calling a mode/script that returns more options. Why would I call a mode to get more options, but then choose something else entirely? That would be like driving to the Pizza shop but then not buying a pizza and instead leaving, going to the laundry mat, and doing my laundry.

It sounds more liike you do not want to use combi mode, but open multiple modes at the same time (under one keybinding), something rofi can do.

I don't know what you mean by open multiple modes at the same time. Can you point me towards documentation that explains this?

I know what I'm trying to describe is a bit convoluted, so let me demonstrate the current behavior and the desired behavior:

Current Behavior:

Action: Start Rofi in combi mode

Rofi Displays: ++++++++++++++ drun Firefox drun Chrome drun Spotify drun Thunar drun Blender ++++++++++++++

Action: Type in Shut and select the option Shut Down

Rofi Displays: ++++++++++++++ drun Firefox drun Chrome drun Spotify drun Thunar drun Blender ++++++++++++++ (down at the bottom of the list, two new items exist: Yes, shut down, and No, cancel. but I have to type in "yes" or tab all the way down there to select them)

Desired Behavior:

Action: Start Rofi in combi mode

Rofi Displays: ++++++++++++++ drun Firefox drun Chrome drun Spotify drun Thunar drun Blender ++++++++++++++

Action: Type in Shut and select the option Shut Down

Rofi Displays: ++++++++++++++ Are you sure? Yes, Shut Down. Are you sure? No, Cancel ++++++++++++++

DaveDavenport commented 9 months ago

I guess I don't really understand the use case of combi mode with its current implementation

I use it to combine window and drun.. so if I open rofi type in 'firefox' it either switches to open instance, otherwise launches it. This is what it was designed for.

when calling a mode/script that returns more options. Why would I call a mode to get more options, but then choose something else entirely? That would be like driving to the Pizza shop but then not buying a pizza and instead leaving, going to the laundry mat, and doing my laundry.

It all depends on the use-case, there is more then just one. I also think that is not a very honest/good analogy. You are not going to the pizza shop and next to the laundromat.. You are going to the combined shop that sells both pizza as do your laundry (hence it is called combi (short for combined)). But given your explanation below I think I understand what you are trying to say.

I don't know what you mean by open multiple modes at the same time. Can you point me towards documentation that explains this?

Its the default setup, it is shown in the video/screenshots on the github page, etc.

You can open 3 views:

rofi -show window -modes 'window,drun,ssh'

and then use the appropriate keybindings (or mouse) to switch between them.

You see the windows rofi-2024-01-10-1756-00000

then hit the key:

rofi-2024-01-10-1805-00001

(I've typed some in to hide some info as I did not feel like grabbing gimp to blur)

Thanks for the explanation, that makes it a lot more clear how you (intend) to use it. This is indeed currently not possible.. When combi mode was written, script mode did not exists. Rofi is build in a way that modes are very standalone, combi mode has no idea what each mode does, it just proxies the information through. Neither does a mode know what the UI is doing, it just presents lists. So without adding more information leakage, supporting your use-case would break other use-cases (like my preferred way of using rofi, where I close windows and launch stuff in one run .).

This could be fixed in a nice way, patch(es) are welcome.

schaefsteven commented 9 months ago

This is indeed currently not possible.. When combi mode was written, script mode did not exists.

That makes sense.

Rofi is build in a way that modes are very standalone, combi mode has no idea what each mode does, it just proxies the information through.

My first inclination for how to implement this would be with a Mode Option. Similarly to how a mode option can be used to change the prompt, we could have a mode option that tells combi mode "clear everything else out of your list, only display what I'm giving you." IIRC though, I don't think combi mode responds to any Mode Options currently. I'm not sure if there is a reason why it can't be parsing them.

DaveDavenport commented 9 months ago

IIRC though, I don't think combi mode responds to any Mode Options currently. I'm not sure if there is a reason why it can't be parsing them.

I am not completely sure what you mean with 'Mode Option'. I don't want to make a wrong assumption and cause confusion because we are talking past eachother.

I'm not sure if there is a reason why it can't be parsing them.

I am not sure what Mode Options are.. but combi mode has a very limited interface to the combined modes that is proxies to it own mode interface.

( See f.e. here on how a mode looks https://davatorium.github.io/rofi/guides/Plugins/2017-04-19-rofi-140-sneak-preview-plugins/)

schaefsteven commented 9 months ago

I am not sure what Mode Options are

https://github.com/davatorium/rofi/blob/1.7.3/doc/rofi-script.5.markdown#passing-mode-options

DaveDavenport commented 9 months ago

aah, I was thinking more at the C level 'mode' structure and interface, that is why I linked some example mode. (I don't really use script mode myself )

Most of those are really limited to script mode/dmenu. With the current abstraction those fields are completely hidden from combi. Some of them are handled internally to the mode others are exposed via the above interface and passed along without knowledge. (urgent/active/markup maps to get_value() , prompt to name, etc.) Combi mode parsing 'mode options' from a script mode is not something possible.

I currently do not have time to add new features to rofi, I hope somebody is willing to pick this up and make a decent implementation for this.

In the current implementation, combi has no knowledge about what type of mode it runs, and a mode has no knowledge if it is rofi calling it directly or proxied via combi mode. This abstraction is something I don't want to break. A solution to this problem should take this abstraction into account.