mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
view: Split keypress handling to an helper function
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
This commit is contained in:
parent
73584a377e
commit
0d899f1bbd
1 changed files with 44 additions and 42 deletions
|
@ -1318,39 +1318,8 @@ void rofi_view_finalize ( RofiViewState *state )
|
|||
}
|
||||
}
|
||||
|
||||
static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t *ev, xkb_stuff *xkb )
|
||||
static void rofi_view_handle_keypress ( RofiViewState *state, xkb_stuff *xkb, xcb_key_press_event_t *xkpe )
|
||||
{
|
||||
switch ( ev->response_type & ~0x80 )
|
||||
{
|
||||
case XCB_FOCUS_IN:
|
||||
if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == 0 ) {
|
||||
take_keyboard ( CacheState.main_window );
|
||||
}
|
||||
break;
|
||||
case XCB_FOCUS_OUT:
|
||||
if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == 0 ) {
|
||||
release_keyboard ( );
|
||||
}
|
||||
break;
|
||||
case XCB_MOTION_NOTIFY:
|
||||
{
|
||||
xcb_motion_notify_event_t *xme = (xcb_motion_notify_event_t *) ev;
|
||||
if ( xme->event_x >= state->scrollbar->widget.x && xme->event_x < ( state->scrollbar->widget.x + state->scrollbar->widget.w ) ) {
|
||||
state->selected = scrollbar_clicked ( state->scrollbar, xme->event_y );
|
||||
state->update = TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case XCB_BUTTON_PRESS:
|
||||
rofi_view_mouse_navigation ( state, (xcb_button_press_event_t *) ev );
|
||||
break;
|
||||
// Paste event.
|
||||
case XCB_SELECTION_NOTIFY:
|
||||
rofi_view_paste ( state, (xcb_selection_notify_event_t *) ev );
|
||||
break;
|
||||
case XCB_KEY_PRESS:
|
||||
{
|
||||
xcb_key_press_event_t *xkpe = (xcb_key_press_event_t *) ev;
|
||||
xcb_keysym_t key;
|
||||
char pad[32];
|
||||
int len = 0;
|
||||
|
@ -1375,7 +1344,7 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t
|
|||
break;
|
||||
}
|
||||
if ( ( key == XKB_KEY_NoSymbol ) && ( len == 0 ) ) {
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1400,27 +1369,27 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t
|
|||
}
|
||||
if ( abe_test_action ( SCREENSHOT, modstate, key ) ) {
|
||||
menu_capture_screenshot ( );
|
||||
break;
|
||||
return;
|
||||
}
|
||||
if ( abe_test_action ( TOGGLE_SORT, modstate, key ) ) {
|
||||
config.levenshtein_sort = !config.levenshtein_sort;
|
||||
state->refilter = TRUE;
|
||||
state->update = TRUE;
|
||||
textbox_text ( state->case_indicator, get_matching_state () );
|
||||
break;
|
||||
return;
|
||||
}
|
||||
else if ( abe_test_action ( MODE_PREVIOUS, modstate, key ) ) {
|
||||
state->retv = MENU_PREVIOUS;
|
||||
( state->selected_line ) = 0;
|
||||
state->quit = TRUE;
|
||||
break;
|
||||
return;
|
||||
}
|
||||
// Menu navigation.
|
||||
else if ( abe_test_action ( MODE_NEXT, modstate, key ) ) {
|
||||
state->retv = MENU_NEXT;
|
||||
( state->selected_line ) = 0;
|
||||
state->quit = TRUE;
|
||||
break;
|
||||
return;
|
||||
}
|
||||
// Toggle case sensitivity.
|
||||
else if ( abe_test_action ( TOGGLE_CASE_SENSITIVITY, modstate, key ) ) {
|
||||
|
@ -1429,7 +1398,7 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t
|
|||
state->refilter = TRUE;
|
||||
state->update = TRUE;
|
||||
textbox_text ( state->case_indicator, get_matching_state () );
|
||||
break;
|
||||
return;
|
||||
}
|
||||
// Special delete entry command.
|
||||
else if ( abe_test_action ( DELETE_ENTRY, modstate, key ) ) {
|
||||
|
@ -1437,7 +1406,7 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t
|
|||
( state->selected_line ) = state->line_map[state->selected];
|
||||
state->retv = MENU_ENTRY_DELETE;
|
||||
state->quit = TRUE;
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
for ( unsigned int a = CUSTOM_1; a <= CUSTOM_19; a++ ) {
|
||||
|
@ -1448,17 +1417,17 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t
|
|||
}
|
||||
state->retv = MENU_QUICK_SWITCH | ( ( a - CUSTOM_1 ) & MENU_LOWER_MASK );
|
||||
state->quit = TRUE;
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ( rofi_view_keyboard_navigation ( state, key, modstate ) ) {
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
{
|
||||
// Skip if we detected key before.
|
||||
if ( state->quit ) {
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
int rc = textbox_keypress ( state->text, pad, len, modstate, key );
|
||||
|
@ -1490,8 +1459,41 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t
|
|||
state->update = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t *ev, xkb_stuff *xkb )
|
||||
{
|
||||
switch ( ev->response_type & ~0x80 )
|
||||
{
|
||||
case XCB_FOCUS_IN:
|
||||
if ( ( state->menu_flags & MENU_NORMAL_WINDOW ) == 0 ) {
|
||||
take_keyboard ( CacheState.main_window );
|
||||
}
|
||||
break;
|
||||
case XCB_FOCUS_OUT:
|
||||
if ( ( state->menu_flags & MENU_NORMAL_WINDOW ) == 0 ) {
|
||||
release_keyboard ( );
|
||||
}
|
||||
break;
|
||||
case XCB_MOTION_NOTIFY:
|
||||
{
|
||||
xcb_motion_notify_event_t *xme = (xcb_motion_notify_event_t *) ev;
|
||||
if ( xme->event_x >= state->scrollbar->widget.x && xme->event_x < ( state->scrollbar->widget.x + state->scrollbar->widget.w ) ) {
|
||||
state->selected = scrollbar_clicked ( state->scrollbar, xme->event_y );
|
||||
state->update = TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case XCB_BUTTON_PRESS:
|
||||
rofi_view_mouse_navigation ( state, (xcb_button_press_event_t *) ev );
|
||||
break;
|
||||
// Paste event.
|
||||
case XCB_SELECTION_NOTIFY:
|
||||
rofi_view_paste ( state, (xcb_selection_notify_event_t *) ev );
|
||||
break;
|
||||
case XCB_KEY_PRESS:
|
||||
rofi_view_handle_keypress ( state, xkb, (xcb_key_press_event_t *) ev );
|
||||
break;
|
||||
}
|
||||
// Update if requested.
|
||||
if ( state->refilter ) {
|
||||
|
|
Loading…
Reference in a new issue