mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
window: Make custom action run a command on the window
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
This commit is contained in:
parent
3bd41b9a41
commit
db4f087487
6 changed files with 60 additions and 4 deletions
|
@ -66,6 +66,8 @@ Settings config = {
|
||||||
.run_list_command = "",
|
.run_list_command = "",
|
||||||
/** Command executed when running application in terminal */
|
/** Command executed when running application in terminal */
|
||||||
.run_shell_command = "{terminal} -e {cmd}",
|
.run_shell_command = "{terminal} -e {cmd}",
|
||||||
|
/** Command executed on accep-entry-custom for window modus */
|
||||||
|
.window_command = "xkill -id {window}",
|
||||||
/**
|
/**
|
||||||
* Location of the window.
|
* Location of the window.
|
||||||
* Enumeration indicating location or gravity of window.
|
* Enumeration indicating location or gravity of window.
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
[ -filter *filter* ]
|
[ -filter *filter* ]
|
||||||
[ -ssh-client *client* ]
|
[ -ssh-client *client* ]
|
||||||
[ -ssh-command *command* ]
|
[ -ssh-command *command* ]
|
||||||
|
[ -window-command *command* ]
|
||||||
[ -disable-history ]
|
[ -disable-history ]
|
||||||
[ -levenshtein-sort ]
|
[ -levenshtein-sort ]
|
||||||
[ -case-sensitive ]
|
[ -case-sensitive ]
|
||||||
|
@ -448,6 +449,13 @@ If set, use an external tool to generate list of executable commands. Uses 'run-
|
||||||
|
|
||||||
Default: *""*
|
Default: *""*
|
||||||
|
|
||||||
|
`-window-command` *cmd*
|
||||||
|
|
||||||
|
Set command to execute on selected window for custom action.
|
||||||
|
See *PATTERN*.
|
||||||
|
|
||||||
|
Default: *"xkill -id {window}"*
|
||||||
|
|
||||||
### Combi settings
|
### Combi settings
|
||||||
|
|
||||||
`-combi-modi` *mode1,mode2*
|
`-combi-modi` *mode1,mode2*
|
||||||
|
@ -713,11 +721,13 @@ A keybinding starting with `!` will act when all keys have been released.
|
||||||
|
|
||||||
Show a list of all the windows and allow switching between them.
|
Show a list of all the windows and allow switching between them.
|
||||||
Pressing the `delete-entry` binding (`shift-delete`) will kill the window.
|
Pressing the `delete-entry` binding (`shift-delete`) will kill the window.
|
||||||
|
Pressing the `accept-custom` binding (`control-enter` or `shift-enter`) will run a command on the window.
|
||||||
|
|
||||||
### WindowCD
|
### WindowCD
|
||||||
|
|
||||||
Shows a list of the windows on the current desktop and allows switching between them.
|
Shows a list of the windows on the current desktop and allows switching between them.
|
||||||
Pressing the `delete-entry` binding (`shift-delete`) will kill the window.
|
Pressing the `delete-entry` binding (`shift-delete`) will kill the window.
|
||||||
|
Pressing the `accept-custom` binding (`control-enter` or `shift-enter`) will run a command on the window.
|
||||||
|
|
||||||
### Run
|
### Run
|
||||||
|
|
||||||
|
|
15
doc/rofi.1
15
doc/rofi.1
|
@ -7,7 +7,7 @@
|
||||||
\fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement
|
\fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement
|
||||||
.
|
.
|
||||||
.SH "SYNOPSIS"
|
.SH "SYNOPSIS"
|
||||||
\fBrofi\fR [ \-width \fIpct_scr\fR ] [ \-lines \fIlines\fR ] [ \-columns \fIcolumns\fR ] [ \-font \fIpangofont\fR ] [ \-terminal \fIterminal\fR ] [ \-location \fIposition\fR ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fR ] [ \-opacity \fIopacity%\fR ] [ \-display \fIdisplay\fR ] [ \-bw \fIwidth\fR ] [ \-dmenu [ \-p \fIprompt\fR ] [ \-sep \fIseparator\fR ] [ \-l \fIselected line\fR ] [ \-mesg ] [ \-select ] [ \-input \fIinput\fR ] ] [ \-filter \fIfilter\fR ] [ \-ssh\-client \fIclient\fR ] [ \-ssh\-command \fIcommand\fR ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-case\-sensitive ] [ \-show \fImode\fR ] [ \-modi \fImode1,mode2\fR ] [ \-eh \fIelement height\fR ] [ \-lazy\-filter\-limit \fIlimit\fR ] [ \-e \fImessage\fR] [ \-a \fIrow\fR ] [ \-u \fIrow\fR ] [ \-pid \fIpath\fR ] [ \-now ] [ \-rnow ] [ \-snow ] [ \-version ] [ \-help ] [ \-dump\-xresources ] [ \-dump\-xresources\-theme ] [ \-auto\-select ] [ \-parse\-hosts ] [ \-no\-parse\-known\-hosts ] [ \-combi\-modi \fImode1,mode2\fR ] [ \-normal\-window ] [ \-fake\-transparency ] [ \-glob ] [ \-regex ] [ \-tokenize ] [ \-threads \fInum\fR ] [ \-config \fIfilename\fR ]
|
\fBrofi\fR [ \-width \fIpct_scr\fR ] [ \-lines \fIlines\fR ] [ \-columns \fIcolumns\fR ] [ \-font \fIpangofont\fR ] [ \-terminal \fIterminal\fR ] [ \-location \fIposition\fR ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fR ] [ \-opacity \fIopacity%\fR ] [ \-display \fIdisplay\fR ] [ \-bw \fIwidth\fR ] [ \-dmenu [ \-p \fIprompt\fR ] [ \-sep \fIseparator\fR ] [ \-l \fIselected line\fR ] [ \-mesg ] [ \-select ] [ \-input \fIinput\fR ] ] [ \-filter \fIfilter\fR ] [ \-ssh\-client \fIclient\fR ] [ \-ssh\-command \fIcommand\fR ] [ \-window\-command \fIcommand\fR ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-case\-sensitive ] [ \-show \fImode\fR ] [ \-modi \fImode1,mode2\fR ] [ \-eh \fIelement height\fR ] [ \-lazy\-filter\-limit \fIlimit\fR ] [ \-e \fImessage\fR] [ \-a \fIrow\fR ] [ \-u \fIrow\fR ] [ \-pid \fIpath\fR ] [ \-now ] [ \-rnow ] [ \-snow ] [ \-version ] [ \-help ] [ \-dump\-xresources ] [ \-dump\-xresources\-theme ] [ \-auto\-select ] [ \-parse\-hosts ] [ \-no\-parse\-known\-hosts ] [ \-combi\-modi \fImode1,mode2\fR ] [ \-normal\-window ] [ \-fake\-transparency ] [ \-glob ] [ \-regex ] [ \-tokenize ] [ \-threads \fInum\fR ] [ \-config \fIfilename\fR ]
|
||||||
.
|
.
|
||||||
.SH "DESCRIPTION"
|
.SH "DESCRIPTION"
|
||||||
\fBrofi\fR is an X11 popup window switcher, run dialog, dmenu replacement and more\. It focuses on being fast to use and have minimal distraction\. It supports keyboard and mouse navigation, type to filter, tokenized search and more\.
|
\fBrofi\fR is an X11 popup window switcher, run dialog, dmenu replacement and more\. It focuses on being fast to use and have minimal distraction\. It supports keyboard and mouse navigation, type to filter, tokenized search and more\.
|
||||||
|
@ -728,6 +728,15 @@ If set, use an external tool to generate list of executable commands\. Uses \'ru
|
||||||
.P
|
.P
|
||||||
Default: \fI""\fR
|
Default: \fI""\fR
|
||||||
.
|
.
|
||||||
|
.P
|
||||||
|
\fB\-window\-command\fR \fIcmd\fR
|
||||||
|
.
|
||||||
|
.P
|
||||||
|
Set command to execute on selected window for custom action\. See \fIPATTERN\fR\.
|
||||||
|
.
|
||||||
|
.P
|
||||||
|
Default: \fI"xkill \-id {window}"\fR
|
||||||
|
.
|
||||||
.SS "Combi settings"
|
.SS "Combi settings"
|
||||||
\fB\-combi\-modi\fR \fImode1,mode2\fR
|
\fB\-combi\-modi\fR \fImode1,mode2\fR
|
||||||
.
|
.
|
||||||
|
@ -1166,10 +1175,10 @@ A keybinding starting with \fB!\fR will act when all keys have been released\.
|
||||||
.SH "Available Modi"
|
.SH "Available Modi"
|
||||||
.
|
.
|
||||||
.SS "Window"
|
.SS "Window"
|
||||||
Show a list of all the windows and allow switching between them\. Pressing the \fBdelete\-entry\fR binding (\fBshift\-delete\fR) will kill the window\.
|
Show a list of all the windows and allow switching between them\. Pressing the \fBdelete\-entry\fR binding (\fBshift\-delete\fR) will kill the window\. Pressing the \fBaccept\-custom\fR binding (\fBcontrol\-enter\fR or \fBshift\-enter\fR) will run a command on the window\.
|
||||||
.
|
.
|
||||||
.SS "WindowCD"
|
.SS "WindowCD"
|
||||||
Shows a list of the windows on the current desktop and allows switching between them\. Pressing the \fBdelete\-entry\fR binding (\fBshift\-delete\fR) will kill the window\.
|
Shows a list of the windows on the current desktop and allows switching between them\. Pressing the \fBdelete\-entry\fR binding (\fBshift\-delete\fR) will kill the window\. Pressing the \fBaccept\-custom\fR binding (\fBcontrol\-enter\fR or \fBshift\-enter\fR) will run a command on the window\.
|
||||||
.
|
.
|
||||||
.SS "Run"
|
.SS "Run"
|
||||||
Shows a list of executables in \fB$PATH\fR and can launch them (optional in a terminal)\. Pressing the \fBaccept\-custom\fR binding (\fBcontrol\-enter\fR or \fBshift\-enter\fR) will run the command in a terminal\.
|
Shows a list of executables in \fB$PATH\fR and can launch them (optional in a terminal)\. Pressing the \fBaccept\-custom\fR binding (\fBcontrol\-enter\fR or \fBshift\-enter\fR) will run the command in a terminal\.
|
||||||
|
|
|
@ -71,6 +71,8 @@ typedef struct
|
||||||
char * run_shell_command;
|
char * run_shell_command;
|
||||||
/** Command for listing executables */
|
/** Command for listing executables */
|
||||||
char * run_list_command;
|
char * run_list_command;
|
||||||
|
/** Command for window */
|
||||||
|
char * window_command;
|
||||||
|
|
||||||
/** Windows location/gravity */
|
/** Windows location/gravity */
|
||||||
WindowLocation location;
|
WindowLocation location;
|
||||||
|
|
|
@ -526,6 +526,34 @@ static int window_mode_init_cd ( Mode *sw )
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int act_on_window ( xcb_window_t window )
|
||||||
|
{
|
||||||
|
int retv = TRUE;
|
||||||
|
char **args = NULL;
|
||||||
|
int argc = 0;
|
||||||
|
char window_str[100]; /* We are probably safe here */
|
||||||
|
|
||||||
|
g_snprintf(window_str, sizeof window_str, "%d", window);
|
||||||
|
|
||||||
|
helper_parse_setup ( config.window_command, &args, &argc, "{window}", window_str, NULL );
|
||||||
|
|
||||||
|
GError *error = NULL;
|
||||||
|
g_spawn_async ( NULL, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error );
|
||||||
|
if ( error != NULL ) {
|
||||||
|
char *msg = g_strdup_printf ( "Failed to execute action for window: '%s'\nError: '%s'", window_str, error->message );
|
||||||
|
rofi_view_error_dialog ( msg, FALSE );
|
||||||
|
g_free ( msg );
|
||||||
|
// print error.
|
||||||
|
g_error_free ( error );
|
||||||
|
retv = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Free the args list.
|
||||||
|
g_strfreev ( args );
|
||||||
|
return retv;
|
||||||
|
}
|
||||||
|
|
||||||
static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **input,
|
static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **input,
|
||||||
unsigned int selected_line )
|
unsigned int selected_line )
|
||||||
{
|
{
|
||||||
|
@ -541,7 +569,10 @@ static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **i
|
||||||
retv = ( mretv & MENU_LOWER_MASK );
|
retv = ( mretv & MENU_LOWER_MASK );
|
||||||
}
|
}
|
||||||
else if ( ( mretv & ( MENU_OK ) ) && rmpd->cmd_list[selected_line] ) {
|
else if ( ( mretv & ( MENU_OK ) ) && rmpd->cmd_list[selected_line] ) {
|
||||||
if ( rmpd->config_i3_mode ) {
|
if ( mretv & MENU_CUSTOM_ACTION ) {
|
||||||
|
act_on_window ( rmpd->ids->array[selected_line] );
|
||||||
|
}
|
||||||
|
else if ( rmpd->config_i3_mode ) {
|
||||||
// Hack for i3.
|
// Hack for i3.
|
||||||
i3_support_focus_window ( rmpd->ids->array[selected_line] );
|
i3_support_focus_window ( rmpd->ids->array[selected_line] );
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,6 +116,8 @@ static XrmOption xrmOptions[] = {
|
||||||
"Command to get extra run targets" },
|
"Command to get extra run targets" },
|
||||||
{ xrm_String, "run-shell-command", { .str = &config.run_shell_command }, NULL,
|
{ xrm_String, "run-shell-command", { .str = &config.run_shell_command }, NULL,
|
||||||
"Run command to execute that runs in shell" },
|
"Run command to execute that runs in shell" },
|
||||||
|
{ xrm_String, "window-command", { .str = &config.window_command }, NULL,
|
||||||
|
"Command executed on accep-entry-custom for window modus" },
|
||||||
|
|
||||||
{ xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL,
|
{ xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL,
|
||||||
"Disable history in run/ssh" },
|
"Disable history in run/ssh" },
|
||||||
|
|
Loading…
Reference in a new issue