window: Make custom action run a command on the window

Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
This commit is contained in:
Quentin Glidic 2016-05-12 11:31:06 +02:00
parent 3bd41b9a41
commit db4f087487
6 changed files with 60 additions and 4 deletions

View File

@ -66,6 +66,8 @@ Settings config = {
.run_list_command = "",
/** Command executed when running application in terminal */
.run_shell_command = "{terminal} -e {cmd}",
/** Command executed on accep-entry-custom for window modus */
.window_command = "xkill -id {window}",
/**
* Location of the window.
* Enumeration indicating location or gravity of window.

View File

@ -22,6 +22,7 @@
[ -filter *filter* ]
[ -ssh-client *client* ]
[ -ssh-command *command* ]
[ -window-command *command* ]
[ -disable-history ]
[ -levenshtein-sort ]
[ -case-sensitive ]
@ -448,6 +449,13 @@ If set, use an external tool to generate list of executable commands. Uses 'run-
Default: *""*
`-window-command` *cmd*
Set command to execute on selected window for custom action.
See *PATTERN*.
Default: *"xkill -id {window}"*
### Combi settings
`-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.
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
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 `accept-custom` binding (`control-enter` or `shift-enter`) will run a command on the window.
### Run

View File

@ -7,7 +7,7 @@
\fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement
.
.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"
\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
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"
\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"
.
.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"
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"
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\.

View File

@ -71,6 +71,8 @@ typedef struct
char * run_shell_command;
/** Command for listing executables */
char * run_list_command;
/** Command for window */
char * window_command;
/** Windows location/gravity */
WindowLocation location;

View File

@ -526,6 +526,34 @@ static int window_mode_init_cd ( Mode *sw )
}
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,
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 );
}
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.
i3_support_focus_window ( rmpd->ids->array[selected_line] );
}

View File

@ -116,6 +116,8 @@ static XrmOption xrmOptions[] = {
"Command to get extra run targets" },
{ xrm_String, "run-shell-command", { .str = &config.run_shell_command }, NULL,
"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,
"Disable history in run/ssh" },