Fix issue #275: don't try to do move cursor when nothing is shown.

This commit is contained in:
Qball Cow 2015-11-20 11:43:22 +01:00
parent 264e9e5b0e
commit 1bd231bc3d
4 changed files with 30 additions and 7 deletions

View File

@ -419,6 +419,10 @@ static void menu_calculate_window_and_element_width ( MenuState *state, workarea
*/
inline static void menu_nav_page_next ( MenuState *state )
{
// If no lines, do nothing.
if ( state->filtered_lines == 0 ) {
return;
}
state->selected += ( state->max_elements );
if ( state->selected >= state->filtered_lines ) {
state->selected = state->filtered_lines - 1;
@ -451,6 +455,10 @@ inline static void menu_nav_page_prev ( MenuState * state )
*/
inline static void menu_nav_right ( MenuState *state )
{
// If no lines, do nothing.
if ( state->filtered_lines == 0 ) {
return;
}
if ( ( state->selected + state->max_rows ) < state->filtered_lines ) {
state->selected += state->max_rows;
state->update = TRUE;
@ -508,6 +516,10 @@ inline static void menu_nav_up ( MenuState *state )
*/
inline static void menu_nav_down ( MenuState *state )
{
// If no lines, do nothing.
if ( state->filtered_lines == 0 ) {
return;
}
state->selected = state->selected < state->filtered_lines - 1 ? MIN ( state->filtered_lines - 1, state->selected + 1 ) : 0;
state->update = TRUE;
}
@ -528,6 +540,10 @@ inline static void menu_nav_first ( MenuState * state )
*/
inline static void menu_nav_last ( MenuState * state )
{
// If no lines, do nothing.
if ( state->filtered_lines == 0 ) {
return;
}
state->selected = state->filtered_lines - 1;
state->update = TRUE;
}
@ -830,8 +846,12 @@ static void menu_refilter ( MenuState *state )
}
state->filtered_lines = state->num_lines;
}
state->selected = MIN ( state->selected, state->filtered_lines - 1 );
if ( state->filtered_lines > 0 ) {
state->selected = MIN ( state->selected, state->filtered_lines - 1 );
}
else {
state->selected = 0;
}
if ( config.auto_select == TRUE && state->filtered_lines == 1 && state->num_lines > 1 ) {
*( state->selected_line ) = state->line_map[state->selected];
@ -1510,7 +1530,7 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select
}
// This is needed for letting the Input Method handle combined keys.
// E.g. `e into è
if ( XFilterEvent ( &ev, main_window) ) {
if ( XFilterEvent ( &ev, main_window ) ) {
continue;
}

View File

@ -575,7 +575,8 @@ int textbox_keypress ( textbox *tb, XIC xic, XEvent *ev )
}
// Filter When alt/ctrl/etc is pressed do not accept the character.
// Ignore others (numlock, shift,..).
else if ( !iscntrl ( *pad ) && 0 == ( ev->xkey.state & ~( ModeSwitchMask | NumlockMask | ( 1 << 12 ) | ( 1 << 13 ) | ShiftMask | LockMask ) ) ) {
else if ( !iscntrl ( *pad ) && 0 ==
( ev->xkey.state & ~( ModeSwitchMask | NumlockMask | ( 1 << 12 ) | ( 1 << 13 ) | ShiftMask | LockMask ) ) ) {
textbox_insert ( tb, tb->cursor, pad );
textbox_cursor_inc ( tb );
return 1;

View File

@ -57,8 +57,8 @@
Atom netatoms[NUM_NETATOMS];
const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) };
// Mask indicating num-lock.
unsigned int NumlockMask = 0;
unsigned int ModeSwitchMask = 0;
unsigned int NumlockMask = 0;
unsigned int ModeSwitchMask = 0;
extern Colormap map;
@ -370,7 +370,7 @@ static void x11_figure_out_numlock_mask ( Display *display )
{
XModifierKeymap *modmap = XGetModifierMapping ( display );
KeyCode kc = XKeysymToKeycode ( display, XK_Num_Lock );
KeyCode kc_ms = XKeysymToKeycode ( display, XK_Mode_switch);
KeyCode kc_ms = XKeysymToKeycode ( display, XK_Mode_switch );
for ( int i = 0; i < 8; i++ ) {
for ( int j = 0; j < ( int ) modmap->max_keypermod; j++ ) {
if ( modmap->modifiermap[i * modmap->max_keypermod + j] == kc ) {

View File

@ -14,6 +14,8 @@ sleep 0.4
xdotool key 'e'
sleep 0.4
xdotool key End
sleep 0.4
xdotool key Return
# Get result, kill xvfb
wait ${RPID}