Issue #268, Filter out mode switch key.

This commit is contained in:
Dave Davenport 2015-11-20 08:40:24 +01:00
parent 922aa5f946
commit 5f7694fc62
2 changed files with 7 additions and 1 deletions

View File

@ -45,6 +45,7 @@
// Use this so we can ignore numlock mask.
// TODO: maybe use something smarter here..
extern unsigned int NumlockMask;
extern unsigned int ModeSwitchMask;
/**
* Font + font color cache.
@ -574,7 +575,7 @@ 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 & ~( 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

@ -58,6 +58,7 @@ Atom netatoms[NUM_NETATOMS];
const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) };
// Mask indicating num-lock.
unsigned int NumlockMask = 0;
unsigned int ModeSwitchMask = 0;
extern Colormap map;
@ -369,11 +370,15 @@ 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);
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 ) {
NumlockMask = ( 1 << i );
}
if ( modmap->modifiermap[i * modmap->max_keypermod + j] == kc_ms ) {
ModeSwitchMask = ( 1 << i );
}
}
}
XFreeModifiermap ( modmap );