diff options
author | Quentin Glidic <sardemff7+git@sardemff7.net> | 2016-05-12 11:31:06 +0200 |
---|---|---|
committer | Quentin Glidic <sardemff7+git@sardemff7.net> | 2016-05-12 11:31:12 +0200 |
commit | db4f08748741813e03aa83177be9825f6d068c00 (patch) | |
tree | 97d12f8f130799e00be74465a2379c01b426de73 /source | |
parent | 3bd41b9a419fcf01250d614d1e05c8a79576dcd8 (diff) |
window: Make custom action run a command on the window
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
Diffstat (limited to 'source')
-rw-r--r-- | source/dialogs/window.c | 33 | ||||
-rw-r--r-- | source/xrmoptions.c | 2 |
2 files changed, 34 insertions, 1 deletions
diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 2a9cedb0..5e5dd63e 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -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] ); } diff --git a/source/xrmoptions.c b/source/xrmoptions.c index d9d82b14..66a1494a 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -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" }, |