mirror of
https://github.com/davatorium/rofi.git
synced 2025-07-31 21:59:25 -04:00
textbox: Split keybinding and text handling
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
This commit is contained in:
parent
143acf622b
commit
5b0964ae32
3 changed files with 50 additions and 29 deletions
|
@ -109,7 +109,8 @@ void textbox_draw ( textbox *tb, cairo_t *draw );
|
||||||
*
|
*
|
||||||
* @returns if the key was handled (1), unhandled(0) or handled and return was pressed (-1)
|
* @returns if the key was handled (1), unhandled(0) or handled and return was pressed (-1)
|
||||||
*/
|
*/
|
||||||
int textbox_keypress ( textbox *tb, char *pad, int pad_len, unsigned int modstate, xkb_keysym_t key );
|
int textbox_keybinding ( textbox *tb, unsigned int modstate, xkb_keysym_t key );
|
||||||
|
int textbox_keypress ( textbox *tb, char *pad, int pad_len );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param tb Handle to the textbox
|
* @param tb Handle to the textbox
|
||||||
|
|
|
@ -525,14 +525,14 @@ static void textbox_cursor_del_word ( textbox *tb )
|
||||||
// 0 = unhandled
|
// 0 = unhandled
|
||||||
// 1 = handled
|
// 1 = handled
|
||||||
// -1 = handled and return pressed (finished)
|
// -1 = handled and return pressed (finished)
|
||||||
int textbox_keypress ( textbox *tb, char *pad, int pad_len, unsigned int modstate, xkb_keysym_t key )
|
int textbox_keybinding ( textbox *tb, unsigned int modstate, xkb_keysym_t key )
|
||||||
{
|
{
|
||||||
if ( !( tb->flags & TB_EDITABLE ) ) {
|
if ( !( tb->flags & TB_EDITABLE ) ) {
|
||||||
return 0;
|
g_return_val_if_reached(0);
|
||||||
}
|
}
|
||||||
int old_blink = tb->blink;
|
int old_blink = tb->blink;
|
||||||
tb->blink = 2;
|
tb->blink = 2;
|
||||||
if ( key != XKB_KEY_NoSymbol ) {
|
|
||||||
// Left or Ctrl-b
|
// Left or Ctrl-b
|
||||||
if ( abe_test_action ( MOVE_CHAR_BACK, modstate, key ) ) {
|
if ( abe_test_action ( MOVE_CHAR_BACK, modstate, key ) ) {
|
||||||
textbox_cursor_dec ( tb );
|
textbox_cursor_dec ( tb );
|
||||||
|
@ -594,7 +594,18 @@ int textbox_keypress ( textbox *tb, char *pad, int pad_len, unsigned int modstat
|
||||||
else if ( abe_test_action ( ACCEPT_ENTRY, modstate, key ) ) {
|
else if ( abe_test_action ( ACCEPT_ENTRY, modstate, key ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tb->blink = old_blink;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int textbox_keypress ( textbox *tb, char *pad, int pad_len )
|
||||||
|
{
|
||||||
|
if ( !( tb->flags & TB_EDITABLE ) ) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
int old_blink = tb->blink;
|
||||||
|
tb->blink = 2;
|
||||||
if ( pad_len > 0 ) {
|
if ( pad_len > 0 ) {
|
||||||
// Filter When alt/ctrl is pressed do not accept the character.
|
// Filter When alt/ctrl is pressed do not accept the character.
|
||||||
if ( !g_ascii_iscntrl ( *pad ) ) {
|
if ( !g_ascii_iscntrl ( *pad ) ) {
|
||||||
|
|
|
@ -1425,35 +1425,44 @@ static void rofi_view_handle_keypress ( RofiViewState *state, xkb_stuff *xkb, xc
|
||||||
if ( rofi_view_keyboard_navigation ( state, key, modstate ) ) {
|
if ( rofi_view_keyboard_navigation ( state, key, modstate ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int rc = textbox_keybinding ( state->text, modstate, key );
|
||||||
|
// Row is accepted.
|
||||||
|
if ( rc < 0 ) {
|
||||||
|
// If a valid item is selected, return that..
|
||||||
|
state->selected_line = UINT32_MAX;
|
||||||
|
if ( state->selected < state->filtered_lines ) {
|
||||||
|
( state->selected_line ) = state->line_map[state->selected];
|
||||||
|
state->retv = MENU_OK;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Nothing entered and nothing selected.
|
||||||
|
state->retv = MENU_CUSTOM_INPUT;
|
||||||
|
}
|
||||||
|
if ( rc == -2 ) {
|
||||||
|
state->retv |= MENU_CUSTOM_ACTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
state->quit = TRUE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Key press is handled by entry box.
|
||||||
|
else if ( rc == 1 ) {
|
||||||
|
state->refilter = TRUE;
|
||||||
|
state->update = TRUE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if ( rc == 2 ) {
|
||||||
|
// redraw.
|
||||||
|
state->update = TRUE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int rc = textbox_keypress ( state->text, pad, len, modstate, key );
|
if ( ( len > 0 ) && ( textbox_keypress ( state->text, pad, len ) ) ) {
|
||||||
// Row is accepted.
|
|
||||||
if ( rc < 0 ) {
|
|
||||||
// If a valid item is selected, return that..
|
|
||||||
state->selected_line = UINT32_MAX;
|
|
||||||
if ( state->selected < state->filtered_lines ) {
|
|
||||||
( state->selected_line ) = state->line_map[state->selected];
|
|
||||||
state->retv = MENU_OK;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
// Nothing entered and nothing selected.
|
|
||||||
state->retv = MENU_CUSTOM_INPUT;
|
|
||||||
}
|
|
||||||
if ( rc == -2 ) {
|
|
||||||
state->retv |= MENU_CUSTOM_ACTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
state->quit = TRUE;
|
|
||||||
}
|
|
||||||
// Key press is handled by entry box.
|
|
||||||
else if ( rc == 1 ) {
|
|
||||||
state->refilter = TRUE;
|
state->refilter = TRUE;
|
||||||
state->update = TRUE;
|
state->update = TRUE;
|
||||||
}
|
return;
|
||||||
else if ( rc == 2 ) {
|
|
||||||
// redraw.
|
|
||||||
state->update = TRUE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue