1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

[I1405] Allow action to be taken on input change. (#1420)

Fixes: #1405
This commit is contained in:
Dave Davenport 2021-09-02 09:55:31 +02:00 committed by GitHub
parent 3f5d82ff56
commit 4b3f6f6767
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 138 additions and 3 deletions

View file

@ -763,6 +763,34 @@ window {
.fi
.RE
.RS
.IP \(bu 2
Format: \fB\fCvar(PROPERTY NAME, DEFAULT)\fR
.RE
.PP
A reference can point to another reference. Currently, the maximum number of redirects is 20.
A property always refers to another property. It cannot be used for a subpart of the property.
.PP
Example:
.PP
.RS
.nf
window {
width: var( width, 30%);
}
.fi
.RE
.PP
If the property \fB\fCwidth\fR is set globally (\fB\fC*{}\fR) that value is used, if the property
\fB\fCwidth\fR is not set, the default value is used.
.SH Orientation
.RS
.IP \(bu 2
@ -816,6 +844,31 @@ The environment variable should be an alphanumeric string without white\-space.
.fi
.RE
.RS
.IP \(bu 2
Format: \fB\fCenv(ENVIRONMENT, default)\fR
.RE
.PP
This will parse the environment variable as the property value. (that then can be any of the above types).
The environment variable should be an alphanumeric string without white\-space.
If the environment value is not found, the default value is used.
.PP
.RS
.nf
window {
width: env(WIDTH, 40%);
}
.fi
.RE
.PP
If environment WIDTH is set, then that value is parsed, otherwise the default value (\fB\fC40%\fR).
.SH Inherit
.RS
.IP \(bu 2

View file

@ -1393,6 +1393,46 @@ To get a searchable list of key bindings, run \fB\fCrofi \-show keys\fR\&.
.PP
A key binding starting with \fB\fC!\fR will act when all keys have been released.
.PP
You can bind certain events to key\-actions:
.SS Timeout
.PP
You can configure an action to be taken when rofi has not been interacted
with for a certain amount of seconds. You can specify a keybinding to trigger
after X seconds.
.PP
.RS
.nf
configuration {
timeout {
delay: 15;
action: "kb\-cancel";
}
}
.fi
.RE
.SS Input change
.PP
When the input of the textbox changes:
.PP
.RS
.nf
configuration {
inputchange {
action: "kb\-row\-first";
}
}
.fi
.RE
.SH Available Modi
.SS window
.PP

View file

@ -838,6 +838,36 @@ To get a searchable list of key bindings, run `rofi -show keys`.
A key binding starting with `!` will act when all keys have been released.
You can bind certain events to key-actions:
### Timeout
You can configure an action to be taken when rofi has not been interacted
with for a certain amount of seconds. You can specify a keybinding to trigger
after X seconds.
```css
configuration {
timeout {
delay: 15;
action: "kb-cancel";
}
}
```
### Input change
When the input of the textbox changes:
```css
configuration {
inputchange {
action: "kb-row-first";
}
}
```
## Available Modi
### window

View file

@ -455,9 +455,9 @@ static gboolean rofi_view_reload_idle(G_GNUC_UNUSED gpointer data) {
CacheState.idle_timeout = 0;
return G_SOURCE_REMOVE;
}
static gboolean rofi_view_user_timeout(G_GNUC_UNUSED gpointer data) {
CacheState.user_timeout = 0;
ThemeWidget *wid = rofi_config_find_widget("timeout", NULL, TRUE);
static void rofi_view_take_action(const char *name) {
ThemeWidget *wid = rofi_config_find_widget(name, NULL, TRUE);
if (wid) {
/** Check string property */
Property *p = rofi_theme_find_property(wid, P_STRING, "action", TRUE);
@ -471,6 +471,10 @@ static gboolean rofi_view_user_timeout(G_GNUC_UNUSED gpointer data) {
}
}
}
}
static gboolean rofi_view_user_timeout(G_GNUC_UNUSED gpointer data) {
CacheState.user_timeout = 0;
rofi_view_take_action("timeout");
return G_SOURCE_REMOVE;
}
@ -1229,6 +1233,12 @@ void rofi_view_finalize(RofiViewState *state) {
}
}
/**
* This function should be called when the input of the entry is changed.
* TODO: Evaluate if this needs to be a 'signal' on textbox?
*/
static void rofi_view_input_changed() { rofi_view_take_action("inputchange"); }
static void rofi_view_trigger_global_action(KeyBindingAction action) {
RofiViewState *state = rofi_view_get_active();
switch (action) {
@ -1410,6 +1420,7 @@ static void rofi_view_trigger_global_action(KeyBindingAction action) {
if (rc == 1) {
// Entry changed.
state->refilter = TRUE;
rofi_view_input_changed();
} else if (rc == 2) {
// Movement.
}
@ -1499,6 +1510,7 @@ gboolean rofi_view_trigger_action(RofiViewState *state, BindingsScope scope,
void rofi_view_handle_text(RofiViewState *state, char *text) {
if (textbox_append_text(state->text, text, strlen(text))) {
state->refilter = TRUE;
rofi_view_input_changed();
}
}