diff options
author | Dave Davenport <qball@gmpclient.org> | 2021-06-30 14:12:09 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2021-06-30 14:12:09 +0200 |
commit | 0c304524fb49e641d3da1a86a39f654cf162ca49 (patch) | |
tree | 20dfdac21d02b61d0bad2a992af5368b9f80b93e /source | |
parent | c1cd4540a44b17409933148bb22e98db38a41306 (diff) |
[Icon|Button] Make action available on icon and use keyb name.
You can now bind a key-binding on mouse click to icons and buttons by setting
"action" property.
For example:
```css
icon-paste {
expand: false;
filename: "gtk-paste";
size: 24;
vertical-align: 0.5;
action: "kb-primary-paste";
}
```
Diffstat (limited to 'source')
-rw-r--r-- | source/view.c | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/source/view.c b/source/view.c index 479c5254..3259ed56 100644 --- a/source/view.c +++ b/source/view.c @@ -1722,27 +1722,16 @@ static WidgetTriggerActionResult textbox_button_trigger_action ( widget *wid, Mo { case MOUSE_CLICK_DOWN: { - const char * type = rofi_theme_get_string ( wid, "action", "ok" ); - ( state->selected_line ) = state->line_map[listview_get_selected ( state->list_view )]; - if ( strcmp ( type, "ok" ) == 0 ) { - state->retv = MENU_OK; - } - else if ( strcmp ( type, "ok|alternate" ) == 0 ) { - state->retv = MENU_CUSTOM_ACTION | MENU_OK; - } - else if ( strcmp ( type, "custom" ) ) { - state->retv = MENU_CUSTOM_INPUT; - } - else if ( strcmp ( type, "custom|alternate" ) == 0 ) { - state->retv = MENU_CUSTOM_ACTION | MENU_CUSTOM_INPUT; - } - else { - g_warning ( "Invalid action specified." ); - return WIDGET_TRIGGER_ACTION_RESULT_IGNORED; + const char * type = rofi_theme_get_string ( wid, "action", NULL ); + if ( type ) { + ( state->selected_line ) = state->line_map[listview_get_selected ( state->list_view )]; + guint id = key_binding_get_action_from_name(type); + if ( id != UINT32_MAX ) { + rofi_view_trigger_global_action ( id ); + } + state->skip_absorb = TRUE; + return WIDGET_TRIGGER_ACTION_RESULT_HANDLED; } - state->quit = TRUE; - state->skip_absorb = TRUE; - return WIDGET_TRIGGER_ACTION_RESULT_HANDLED; } case MOUSE_CLICK_UP: case MOUSE_DCLICK_DOWN: @@ -1939,7 +1928,13 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget, } else if ( g_ascii_strncasecmp ( name, "icon", 4 ) == 0 ) { 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 ) { + WIDGET(t)->type = WIDGET_TYPE_EDITBOX; + } box_add ( (box *) parent_widget, WIDGET ( t ), TRUE ); + widget_set_trigger_action_handler ( WIDGET ( t ), textbox_button_trigger_action, state ); } else { wid = (widget *) box_create ( parent_widget, name, ROFI_ORIENTATION_VERTICAL ); |