diff --git a/doc/rofi-theme.5.markdown b/doc/rofi-theme.5.markdown index 2ded95f66..0e19014fb 100644 --- a/doc/rofi-theme.5.markdown +++ b/doc/rofi-theme.5.markdown @@ -1322,6 +1322,20 @@ icon-paste { } ``` +Alternatively, the property `exec` can be set to be a command such as a program or shell script instead of `action`. The optional property `exit-after-command` (default **false**) can be set so Rofi exits upon completion of that command. + +For example, the following configuration would create an icon widget that, when clicked, opens an XTerm session and closes Rofi: + +```css +icon-xterm { + expand: false; + filename: "/usr/share/pixmaps/mini.xterm_48x48.xpm"; + size: 24; + exec: "xterm"; + exit-after-command: true; +} +``` + #### button This is a textbox widget that can have a 'clickable' action. The `action` can @@ -1337,6 +1351,18 @@ button-paste { } ``` +As with icon widgets, the button widget can alternatively be set to run a command when clicked with the `exec` property and Rofi can be set to exit upon the command's completion by setting the `exit-after-command` property to **true**. + +```css +button-xterm { + expand: false; + content: "Launch XTerm"; + vertical-align: 0.5; + exec: "xterm"; + exit-after-command: true; +} +``` + #### Children To specify children, set the `children` diff --git a/source/view.c b/source/view.c index 50fd42afa..edbb9c69c 100644 --- a/source/view.c +++ b/source/view.c @@ -1552,6 +1552,9 @@ WidgetTriggerActionResult textbox_button_trigger_action( switch (action) { case MOUSE_CLICK_DOWN: { const char *type = rofi_theme_get_string(wid, "action", NULL); + const char *command = rofi_theme_get_string(wid, "exec", NULL); + const int exit_after = rofi_theme_get_boolean(wid, "exit-after-command", FALSE); + if (type) { if (state->list_view) { (state->selected_line) = @@ -1565,6 +1568,12 @@ WidgetTriggerActionResult textbox_button_trigger_action( } state->skip_absorb = TRUE; return WIDGET_TRIGGER_ACTION_RESULT_HANDLED; + } else if (command) { + if (helper_execute_command(NULL, command, FALSE, NULL)) { + if (exit_after) { + rofi_quit_main_loop(); + } + } } } case MOUSE_CLICK_UP: @@ -1790,7 +1799,8 @@ static void rofi_view_add_widget(RofiViewState *state, widget *parent_widget, icon *t = icon_create(parent_widget, name); /* small hack to make it clickable */ const char *type = rofi_theme_get_string(WIDGET(t), "action", NULL); - if (type) { + const char *command = rofi_theme_get_string(WIDGET(t), "exec", NULL); + if (type || command) { WIDGET(t)->type = WIDGET_TYPE_EDITBOX; } box_add((box *)parent_widget, WIDGET(t), TRUE);