add switch-mode option to the script mode#2196
add switch-mode option to the script mode#2196DaveDavenport merged 6 commits intodavatorium:nextfrom tmoron:next
Conversation
|
What is the use-case for this patch? |
|
I want to create a kind of submenu system in the launcher, where different prefixes trigger different modes or actions. For example, typing d would switch to drun, typing c would switch to calc, and other prefixes could be used to start Firefox with a search or open a bookmark. |
source/modes/script.c
Outdated
| int16_t switch_mode; | ||
| } ScriptModePrivateData; | ||
|
|
||
| extern unsigned int curr_mode; |
There was a problem hiding this comment.
I am not a big fan of this 'bypass' of the mode API.
I need to remember exactly how it works, Maybe we can use MENU_QUICK_SWITCH structure.
I think if you return the mode number from the _result function it should switch to that mode..
There was a problem hiding this comment.
See process_result in rofi.c
There was a problem hiding this comment.
yes, returning the id of the mode does switch to that mode,that's what I had initially. but this method doesn't clear the input and the next mode starts with the previous mode's input. So if I start drun with "d" in script, drun mode will be started with a d already entered. I avoided adding a clear in the default switch to prevent breaking other behavior.
There was a problem hiding this comment.
free and set *input to NULL?
There was a problem hiding this comment.
oh, I didn't notice that, yes that's a much better approach. i'll make a new commit
There was a problem hiding this comment.
great! I had to look, as it been a long time since I touched this part of the code.
source/modes/script.c
Outdated
| // store them as they might be different on next executor and reset. | ||
| gboolean keep_filter = rmpd->keep_filter; | ||
| gboolean keep_selection = rmpd->keep_selection; | ||
| RofiViewState *state = rofi_view_get_active(); |
There was a problem hiding this comment.
I think this one is not needed anymore.
source/modes/script.c
Outdated
| } | ||
| } | ||
|
|
||
| if (state && rmpd->switch_mode >= 0) { |
There was a problem hiding this comment.
state check is not needed anymore?
|
Thanks. |
|
thank you ! |

Added an option to switch modes from a script.
Usage :
this switches to the drun mode