1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

[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";
}
```
This commit is contained in:
Dave Davenport 2021-06-30 14:12:09 +02:00
parent c1cd4540a4
commit 0c304524fb
5 changed files with 71 additions and 35 deletions

View file

@ -1370,14 +1370,13 @@ This is a textbox widget. The displayed string can be set with \fB\fCstr\fR\&.
.IP \(bu 2
\fB\fCicon\fR:
This is an icon widget. The displayed icon can be set with \fB\fCfilename\fR and size with \fB\fCsize\fR\&.
If the property \fB\fCaction\fR is set, it acts as a button.
\fB\fCaction\fR can be set to a keybinding name and completes that action. (see rofi \-show keys for a list).
.IP \(bu 2
\fB\fCbutton\fR:
This is a textbox widget that can have a 'clickable' action.
The \fB\fCaction\fR can be set to:
\fB\fCok\fR accept entry.
\fB\fCcustom\fR accept custom input.
\fB\fCok|alternate\fR: accept entry and launch alternate action (for run launch in terminal).
\fB\fCcustom|alternate\fR: accept custom input and launch alternate action.
\fB\fCkeybinding\fR: accepts a keybinging name and completes that action. (see rofi \-show keys for a list).
.RE

View file

@ -848,13 +848,12 @@ There are several special widgets that can be used by prefixing the name of the
This is a textbox widget. The displayed string can be set with `str`.
* `icon`:
This is an icon widget. The displayed icon can be set with `filename` and size with `size`.
If the property `action` is set, it acts as a button.
`action` can be set to a keybinding name and completes that action. (see rofi -show keys for a list).
* `button`:
This is a textbox widget that can have a 'clickable' action.
The `action` can be set to:
`ok` accept entry.
`custom` accept custom input.
`ok|alternate`: accept entry and launch alternate action (for run launch in terminal).
`custom|alternate`: accept custom input and launch alternate action.
`keybinding`: accepts a keybinging name and completes that action. (see rofi -show keys for a list).
To specify children, set the `children`
property (this always happens on the `box` child, see example below):

View file

@ -1179,15 +1179,18 @@ configuration {
directory: "/some/directory";
/**
* Sorting method. Can be set to:
* - "name"
* - "mtime" (modification time)
* - "atime" (access time)
* - "ctime" (change time)
* \- "name"
* \- "mtime" (modification time)
* \- "atime" (access time)
* \- "ctime" (change time)
*/
sorting-method: "name";
sorting\-method: "name";
}
}
.fi
.RE
.SS Other
.PP
\fB\fC\-drun\-use\-desktop\-cache\fR

View file

@ -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;
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;
}
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;
}
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 );

View file

@ -44,7 +44,33 @@ window {
y-offset: -15.5em;
children: [ inputbar, message, wrapper-mode-switcher, listview ];
children: [ inputbar, message, wrapper-mode-switcher, listview , pagerbox ];
}
pagerbox {
expand: false;
orientation: horizontal;
children: [ icon-left, pad, icon-right ];
}
pad {
expand: true;
}
icon-left {
expand: false;
filename: "go-previous";
size: 24;
vertical-align: 0.5;
action: "kb-page-prev";
}
icon-right {
expand: false;
filename: "go-next";
size: 24;
vertical-align: 0.5;
action: "kb-page-next";
}
@ -191,9 +217,23 @@ wrapper {
border: 2px;
border-radius: 5px;
padding: 4px;
children: [ icon-k, entry ];
children: [ icon-k, entry, icon-paste];
spacing: 0.5em;
}
button-paste {
expand: false;
str: "gtk-paste";
size: 24;
vertical-align: 0.5;
action: "kb-cancel";
}
icon-paste {
expand: false;
filename: "gtk-paste";
size: 24;
vertical-align: 0.5;
action: "kb-primary-paste";
}
icon-k {
expand: false;
filename: "input-keyboard";