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

textbox: Split keybinding and text handling

Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
This commit is contained in:
Quentin Glidic 2016-04-07 15:01:14 +02:00
parent 143acf622b
commit 5b0964ae32
3 changed files with 50 additions and 29 deletions

View file

@ -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)
*/
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

View file

@ -525,14 +525,14 @@ static void textbox_cursor_del_word ( textbox *tb )
// 0 = unhandled
// 1 = handled
// -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 ) ) {
return 0;
g_return_val_if_reached(0);
}
int old_blink = tb->blink;
tb->blink = 2;
if ( key != XKB_KEY_NoSymbol ) {
// Left or Ctrl-b
if ( abe_test_action ( MOVE_CHAR_BACK, modstate, key ) ) {
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 ) ) {
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 ) {
// Filter When alt/ctrl is pressed do not accept the character.
if ( !g_ascii_iscntrl ( *pad ) ) {

View file

@ -1425,35 +1425,44 @@ static void rofi_view_handle_keypress ( RofiViewState *state, xkb_stuff *xkb, xc
if ( rofi_view_keyboard_navigation ( state, key, modstate ) ) {
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 );
// 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 ) {
if ( ( len > 0 ) && ( textbox_keypress ( state->text, pad, len ) ) ) {
state->refilter = TRUE;
state->update = TRUE;
}
else if ( rc == 2 ) {
// redraw.
state->update = TRUE;
return;
}
}