mirror of
https://github.com/davatorium/rofi.git
synced 2025-07-31 21:59:25 -04:00
Avoid loosing keyboard press events when they arrive to quickly.
* Do not absorb events, but loop over them.
This commit is contained in:
parent
112e2c2bc5
commit
7e6241226e
1 changed files with 95 additions and 93 deletions
188
source/rofi.c
188
source/rofi.c
|
@ -82,7 +82,7 @@ unsigned int NumlockMask = 0;
|
||||||
Display *display = NULL;
|
Display *display = NULL;
|
||||||
char *display_str = NULL;
|
char *display_str = NULL;
|
||||||
|
|
||||||
static int ( *xerror )( Display *, XErrorEvent * );
|
static int ( *xerror )( Display *, XErrorEvent * );
|
||||||
|
|
||||||
#define ATOM_ENUM( x ) x
|
#define ATOM_ENUM( x ) x
|
||||||
#define ATOM_CHAR( x ) # x
|
#define ATOM_CHAR( x ) # x
|
||||||
|
@ -1696,111 +1696,113 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom
|
||||||
}
|
}
|
||||||
// Key press event.
|
// Key press event.
|
||||||
else if ( ev.type == KeyPress ) {
|
else if ( ev.type == KeyPress ) {
|
||||||
while ( XCheckTypedEvent ( display, KeyPress, &ev ) ) {
|
do {
|
||||||
;
|
// while ( XCheckTypedEvent ( display, KeyPress, &ev ) ) {
|
||||||
}
|
// ;
|
||||||
|
// }
|
||||||
|
|
||||||
if ( time ) {
|
if ( time ) {
|
||||||
*time = ev.xkey.time;
|
*time = ev.xkey.time;
|
||||||
}
|
|
||||||
|
|
||||||
KeySym key = XkbKeycodeToKeysym ( display, ev.xkey.keycode, 0, 0 );
|
|
||||||
|
|
||||||
// Handling of paste
|
|
||||||
if ( ( ( ( ev.xkey.state & ControlMask ) == ControlMask ) && key == XK_v ) ) {
|
|
||||||
XConvertSelection ( display, ( ev.xkey.state & ShiftMask ) ?
|
|
||||||
XA_PRIMARY : netatoms[CLIPBOARD],
|
|
||||||
netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window, CurrentTime );
|
|
||||||
}
|
|
||||||
else if ( key == XK_Insert ) {
|
|
||||||
XConvertSelection ( display, ( ev.xkey.state & ShiftMask ) ?
|
|
||||||
XA_PRIMARY : netatoms[CLIPBOARD],
|
|
||||||
netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window, CurrentTime );
|
|
||||||
}
|
|
||||||
else if ( ( ( ev.xkey.state & ControlMask ) == ControlMask ) && key == XK_slash ) {
|
|
||||||
state.retv = MENU_PREVIOUS;
|
|
||||||
*( state.selected_line ) = 0;
|
|
||||||
state.quit = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Menu navigation.
|
|
||||||
else if ( ( ( ev.xkey.state & ShiftMask ) == ShiftMask ) &&
|
|
||||||
key == XK_slash ) {
|
|
||||||
state.retv = MENU_NEXT;
|
|
||||||
*( state.selected_line ) = 0;
|
|
||||||
state.quit = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Toggle case sensitivity.
|
|
||||||
else if ( key == XK_grave || key == XK_dead_grave ) {
|
|
||||||
config.case_sensitive = !config.case_sensitive;
|
|
||||||
*( state.selected_line ) = 0;
|
|
||||||
state.refilter = TRUE;
|
|
||||||
state.update = TRUE;
|
|
||||||
if ( config.case_sensitive ) {
|
|
||||||
textbox_show ( state.case_indicator );
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
textbox_hide ( state.case_indicator );
|
KeySym key = XkbKeycodeToKeysym ( display, ev.xkey.keycode, 0, 0 );
|
||||||
|
|
||||||
|
// Handling of paste
|
||||||
|
if ( ( ( ( ev.xkey.state & ControlMask ) == ControlMask ) && key == XK_v ) ) {
|
||||||
|
XConvertSelection ( display, ( ev.xkey.state & ShiftMask ) ?
|
||||||
|
XA_PRIMARY : netatoms[CLIPBOARD],
|
||||||
|
netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window, CurrentTime );
|
||||||
}
|
}
|
||||||
}
|
else if ( key == XK_Insert ) {
|
||||||
// Switcher short-cut
|
XConvertSelection ( display, ( ev.xkey.state & ShiftMask ) ?
|
||||||
else if ( ( ( ev.xkey.state & Mod1Mask ) == Mod1Mask ) &&
|
XA_PRIMARY : netatoms[CLIPBOARD],
|
||||||
key >= XK_1 && key <= XK_9 ) {
|
netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window, CurrentTime );
|
||||||
*( state.selected_line ) = ( key - XK_1 );
|
}
|
||||||
state.retv = MENU_QUICK_SWITCH;
|
else if ( ( ( ev.xkey.state & ControlMask ) == ControlMask ) && key == XK_slash ) {
|
||||||
state.quit = TRUE;
|
state.retv = MENU_PREVIOUS;
|
||||||
break;
|
*( state.selected_line ) = 0;
|
||||||
}
|
|
||||||
// Special delete entry command.
|
|
||||||
else if ( ( ( ev.xkey.state & ShiftMask ) == ShiftMask ) &&
|
|
||||||
key == XK_Delete ) {
|
|
||||||
if ( state.filtered[state.selected] != NULL ) {
|
|
||||||
*( state.selected_line ) = state.line_map[state.selected];
|
|
||||||
state.retv = MENU_ENTRY_DELETE;
|
|
||||||
state.quit = TRUE;
|
state.quit = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
// Menu navigation.
|
||||||
else{
|
else if ( ( ( ev.xkey.state & ShiftMask ) == ShiftMask ) &&
|
||||||
int rc = textbox_keypress ( state.text, &ev );
|
key == XK_slash ) {
|
||||||
// Row is accepted.
|
state.retv = MENU_NEXT;
|
||||||
if ( rc < 0 ) {
|
*( state.selected_line ) = 0;
|
||||||
if ( shift != NULL ) {
|
state.quit = TRUE;
|
||||||
( *shift ) = ( ( ev.xkey.state & ShiftMask ) == ShiftMask );
|
break;
|
||||||
|
}
|
||||||
|
// Toggle case sensitivity.
|
||||||
|
else if ( key == XK_grave || key == XK_dead_grave ) {
|
||||||
|
config.case_sensitive = !config.case_sensitive;
|
||||||
|
*( state.selected_line ) = 0;
|
||||||
|
state.refilter = TRUE;
|
||||||
|
state.update = TRUE;
|
||||||
|
if ( config.case_sensitive ) {
|
||||||
|
textbox_show ( state.case_indicator );
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
// If a valid item is selected, return that..
|
textbox_hide ( state.case_indicator );
|
||||||
if ( state.selected < state.filtered_lines && state.filtered[state.selected] != NULL ) {
|
}
|
||||||
|
}
|
||||||
|
// Switcher short-cut
|
||||||
|
else if ( ( ( ev.xkey.state & Mod1Mask ) == Mod1Mask ) &&
|
||||||
|
key >= XK_1 && key <= XK_9 ) {
|
||||||
|
*( state.selected_line ) = ( key - XK_1 );
|
||||||
|
state.retv = MENU_QUICK_SWITCH;
|
||||||
|
state.quit = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Special delete entry command.
|
||||||
|
else if ( ( ( ev.xkey.state & ShiftMask ) == ShiftMask ) &&
|
||||||
|
key == XK_Delete ) {
|
||||||
|
if ( state.filtered[state.selected] != NULL ) {
|
||||||
*( state.selected_line ) = state.line_map[state.selected];
|
*( state.selected_line ) = state.line_map[state.selected];
|
||||||
if ( strlen ( state.text->text ) > 0 && rc == -2 ) {
|
state.retv = MENU_ENTRY_DELETE;
|
||||||
|
state.quit = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
int rc = textbox_keypress ( state.text, &ev );
|
||||||
|
// Row is accepted.
|
||||||
|
if ( rc < 0 ) {
|
||||||
|
if ( shift != NULL ) {
|
||||||
|
( *shift ) = ( ( ev.xkey.state & ShiftMask ) == ShiftMask );
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a valid item is selected, return that..
|
||||||
|
if ( state.selected < state.filtered_lines && state.filtered[state.selected] != NULL ) {
|
||||||
|
*( state.selected_line ) = state.line_map[state.selected];
|
||||||
|
if ( strlen ( state.text->text ) > 0 && rc == -2 ) {
|
||||||
|
state.retv = MENU_CUSTOM_INPUT;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
state.retv = MENU_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( strlen ( state.text->text ) > 0 ) {
|
||||||
state.retv = MENU_CUSTOM_INPUT;
|
state.retv = MENU_CUSTOM_INPUT;
|
||||||
}
|
}
|
||||||
else {
|
else{
|
||||||
state.retv = MENU_OK;
|
// Nothing entered and nothing selected.
|
||||||
|
state.retv = MENU_CANCEL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if ( strlen ( state.text->text ) > 0 ) {
|
|
||||||
state.retv = MENU_CUSTOM_INPUT;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
// Nothing entered and nothing selected.
|
|
||||||
state.retv = MENU_CANCEL;
|
|
||||||
}
|
|
||||||
|
|
||||||
state.quit = TRUE;
|
state.quit = TRUE;
|
||||||
|
}
|
||||||
|
// Key press is handled by entry box.
|
||||||
|
else if ( rc > 0 ) {
|
||||||
|
state.refilter = TRUE;
|
||||||
|
state.update = TRUE;
|
||||||
|
}
|
||||||
|
// Other keys.
|
||||||
|
else{
|
||||||
|
// unhandled key
|
||||||
|
menu_keyboard_navigation ( &state, key, ev.xkey.state );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Key press is handled by entry box.
|
} while ( XCheckTypedEvent ( display, KeyPress, &ev ) );
|
||||||
else if ( rc > 0 ) {
|
|
||||||
state.refilter = TRUE;
|
|
||||||
state.update = TRUE;
|
|
||||||
}
|
|
||||||
// Other keys.
|
|
||||||
else{
|
|
||||||
// unhandled key
|
|
||||||
menu_keyboard_navigation ( &state, key, ev.xkey.state );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue