view: Store modstate on keypress event

Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
This commit is contained in:
Quentin Glidic 2016-02-23 12:52:35 +01:00
parent 990914d20f
commit 590e61b417
3 changed files with 29 additions and 27 deletions

View File

@ -110,7 +110,7 @@ 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, xcb_key_press_event_t *ev, char *pad, int pad_len, xkb_keysym_t key ); int textbox_keypress ( textbox *tb, char *pad, int pad_len, unsigned int modstate, xkb_keysym_t key );
/** /**
* @param tb Handle to the textbox * @param tb Handle to the textbox

View File

@ -533,7 +533,7 @@ 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, xcb_key_press_event_t *ev, char *pad, int pad_len, xkb_keysym_t key ) int textbox_keypress ( textbox *tb, char *pad, int pad_len, unsigned int modstate, xkb_keysym_t key )
{ {
if ( !( tb->flags & TB_EDITABLE ) ) { if ( !( tb->flags & TB_EDITABLE ) ) {
return 0; return 0;
@ -542,67 +542,67 @@ int textbox_keypress ( textbox *tb, xcb_key_press_event_t *ev, char *pad, int pa
tb->blink = 2; tb->blink = 2;
if ( key != XKB_KEY_NoSymbol ) { if ( key != XKB_KEY_NoSymbol ) {
// Left or Ctrl-b // Left or Ctrl-b
if ( abe_test_action ( MOVE_CHAR_BACK, ev->state, key ) ) { if ( abe_test_action ( MOVE_CHAR_BACK, modstate, key ) ) {
textbox_cursor_dec ( tb ); textbox_cursor_dec ( tb );
return 2; return 2;
} }
// Right or Ctrl-F // Right or Ctrl-F
else if ( abe_test_action ( MOVE_CHAR_FORWARD, ev->state, key ) ) { else if ( abe_test_action ( MOVE_CHAR_FORWARD, modstate, key ) ) {
textbox_cursor_inc ( tb ); textbox_cursor_inc ( tb );
return 2; return 2;
} }
// Ctrl-U: Kill from the beginning to the end of the line. // Ctrl-U: Kill from the beginning to the end of the line.
else if ( abe_test_action ( CLEAR_LINE, ev->state, key ) ) { else if ( abe_test_action ( CLEAR_LINE, modstate, key ) ) {
textbox_text ( tb, "" ); textbox_text ( tb, "" );
return 1; return 1;
} }
// Ctrl-A // Ctrl-A
else if ( abe_test_action ( MOVE_FRONT, ev->state, key ) ) { else if ( abe_test_action ( MOVE_FRONT, modstate, key ) ) {
textbox_cursor ( tb, 0 ); textbox_cursor ( tb, 0 );
return 2; return 2;
} }
// Ctrl-E // Ctrl-E
else if ( abe_test_action ( MOVE_END, ev->state, key ) ) { else if ( abe_test_action ( MOVE_END, modstate, key ) ) {
textbox_cursor_end ( tb ); textbox_cursor_end ( tb );
return 2; return 2;
} }
// Ctrl-Alt-h // Ctrl-Alt-h
else if ( abe_test_action ( REMOVE_WORD_BACK, ev->state, key ) ) { else if ( abe_test_action ( REMOVE_WORD_BACK, modstate, key ) ) {
textbox_cursor_bkspc_word ( tb ); textbox_cursor_bkspc_word ( tb );
return 1; return 1;
} }
// Ctrl-Alt-d // Ctrl-Alt-d
else if ( abe_test_action ( REMOVE_WORD_FORWARD, ev->state, key ) ) { else if ( abe_test_action ( REMOVE_WORD_FORWARD, modstate, key ) ) {
textbox_cursor_del_word ( tb ); textbox_cursor_del_word ( tb );
return 1; return 1;
} // Delete or Ctrl-D } // Delete or Ctrl-D
else if ( abe_test_action ( REMOVE_CHAR_FORWARD, ev->state, key ) ) { else if ( abe_test_action ( REMOVE_CHAR_FORWARD, modstate, key ) ) {
textbox_cursor_del ( tb ); textbox_cursor_del ( tb );
return 1; return 1;
} }
// Alt-B // Alt-B
else if ( abe_test_action ( MOVE_WORD_BACK, ev->state, key ) ) { else if ( abe_test_action ( MOVE_WORD_BACK, modstate, key ) ) {
textbox_cursor_dec_word ( tb ); textbox_cursor_dec_word ( tb );
return 2; return 2;
} }
// Alt-F // Alt-F
else if ( abe_test_action ( MOVE_WORD_FORWARD, ev->state, key ) ) { else if ( abe_test_action ( MOVE_WORD_FORWARD, modstate, key ) ) {
textbox_cursor_inc_word ( tb ); textbox_cursor_inc_word ( tb );
return 2; return 2;
} }
// BackSpace, Ctrl-h // BackSpace, Ctrl-h
else if ( abe_test_action ( REMOVE_CHAR_BACK, ev->state, key ) ) { else if ( abe_test_action ( REMOVE_CHAR_BACK, modstate, key ) ) {
textbox_cursor_bkspc ( tb ); textbox_cursor_bkspc ( tb );
return 1; return 1;
} }
else if ( abe_test_action ( ACCEPT_CUSTOM, ev->state, key ) ) { else if ( abe_test_action ( ACCEPT_CUSTOM, modstate, key ) ) {
return -2; return -2;
} }
else if ( abe_test_action ( ACCEPT_ENTRY_CONTINUE, ev->state, key ) ) { else if ( abe_test_action ( ACCEPT_ENTRY_CONTINUE, modstate, key ) ) {
return -3; return -3;
} }
else if ( abe_test_action ( ACCEPT_ENTRY, ev->state, key ) ) { else if ( abe_test_action ( ACCEPT_ENTRY, modstate, key ) ) {
return -1; return -1;
} }
} }

View File

@ -1328,41 +1328,43 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t
len = xkb_state_key_get_utf8 ( xkb->state, xkpe->detail, pad, sizeof ( pad ) ); len = xkb_state_key_get_utf8 ( xkb->state, xkpe->detail, pad, sizeof ( pad ) );
} }
unsigned int modstate = xkpe->state;
if ( key != XKB_KEY_NoSymbol ) { if ( key != XKB_KEY_NoSymbol ) {
// Handling of paste // Handling of paste
if ( abe_test_action ( PASTE_PRIMARY, xkpe->state, key ) ) { if ( abe_test_action ( PASTE_PRIMARY, modstate, key ) ) {
XConvertSelection ( display, XA_PRIMARY, netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window, CurrentTime ); XConvertSelection ( display, XA_PRIMARY, netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window, CurrentTime );
} }
else if ( abe_test_action ( PASTE_SECONDARY, xkpe->state, key ) ) { else if ( abe_test_action ( PASTE_SECONDARY, modstate, key ) ) {
XConvertSelection ( display, netatoms[CLIPBOARD], netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window, XConvertSelection ( display, netatoms[CLIPBOARD], netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window,
CurrentTime ); CurrentTime );
} }
if ( abe_test_action ( SCREENSHOT, xkpe->state, key ) ) { if ( abe_test_action ( SCREENSHOT, modstate, key ) ) {
menu_capture_screenshot ( ); menu_capture_screenshot ( );
break; break;
} }
if ( abe_test_action ( TOGGLE_SORT, xkpe->state, key ) ) { if ( abe_test_action ( TOGGLE_SORT, modstate, key ) ) {
config.levenshtein_sort = !config.levenshtein_sort; config.levenshtein_sort = !config.levenshtein_sort;
state->refilter = TRUE; state->refilter = TRUE;
state->update = TRUE; state->update = TRUE;
textbox_text ( state->case_indicator, get_matching_state () ); textbox_text ( state->case_indicator, get_matching_state () );
break; break;
} }
else if ( abe_test_action ( MODE_PREVIOUS, xkpe->state, key ) ) { else if ( abe_test_action ( MODE_PREVIOUS, modstate, key ) ) {
state->retv = MENU_PREVIOUS; state->retv = MENU_PREVIOUS;
( state->selected_line ) = 0; ( state->selected_line ) = 0;
state->quit = TRUE; state->quit = TRUE;
break; break;
} }
// Menu navigation. // Menu navigation.
else if ( abe_test_action ( MODE_NEXT, xkpe->state, key ) ) { else if ( abe_test_action ( MODE_NEXT, modstate, key ) ) {
state->retv = MENU_NEXT; state->retv = MENU_NEXT;
( state->selected_line ) = 0; ( state->selected_line ) = 0;
state->quit = TRUE; state->quit = TRUE;
break; break;
} }
// Toggle case sensitivity. // Toggle case sensitivity.
else if ( abe_test_action ( TOGGLE_CASE_SENSITIVITY, xkpe->state, key ) ) { else if ( abe_test_action ( TOGGLE_CASE_SENSITIVITY, modstate, key ) ) {
config.case_sensitive = !config.case_sensitive; config.case_sensitive = !config.case_sensitive;
( state->selected_line ) = 0; ( state->selected_line ) = 0;
state->refilter = TRUE; state->refilter = TRUE;
@ -1371,7 +1373,7 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t
break; break;
} }
// Special delete entry command. // Special delete entry command.
else if ( abe_test_action ( DELETE_ENTRY, xkpe->state, key ) ) { else if ( abe_test_action ( DELETE_ENTRY, modstate, key ) ) {
if ( state->selected < state->filtered_lines ) { if ( state->selected < state->filtered_lines ) {
( state->selected_line ) = state->line_map[state->selected]; ( state->selected_line ) = state->line_map[state->selected];
state->retv = MENU_ENTRY_DELETE; state->retv = MENU_ENTRY_DELETE;
@ -1380,7 +1382,7 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t
} }
} }
for ( unsigned int a = CUSTOM_1; a <= CUSTOM_19; a++ ) { for ( unsigned int a = CUSTOM_1; a <= CUSTOM_19; a++ ) {
if ( abe_test_action ( a, xkpe->state, key ) ) { if ( abe_test_action ( a, modstate, key ) ) {
state->selected_line = UINT32_MAX; state->selected_line = UINT32_MAX;
if ( state->selected < state->filtered_lines ) { if ( state->selected < state->filtered_lines ) {
( state->selected_line ) = state->line_map[state->selected]; ( state->selected_line ) = state->line_map[state->selected];
@ -1390,7 +1392,7 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t
break; break;
} }
} }
if ( rofi_view_keyboard_navigation ( state, key, xkpe->state ) ) { if ( rofi_view_keyboard_navigation ( state, key, modstate ) ) {
break; break;
} }
} }
@ -1400,7 +1402,7 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t
break; break;
} }
int rc = textbox_keypress ( state->text, xkpe, pad, len, key ); int rc = textbox_keypress ( state->text, pad, len, modstate, key );
// Row is accepted. // Row is accepted.
if ( rc < 0 ) { if ( rc < 0 ) {
int shift = ( ( xkpe->state & ShiftMask ) == ShiftMask ); int shift = ( ( xkpe->state & ShiftMask ) == ShiftMask );