@@ -22,22 +22,43 @@ bool slop::Keyboard::anyKeyDown() {
2222 return keyDown;
2323}
2424
25+ void slop::Keyboard::zeroKey ( char keys[32 ], KeySym key ) {
26+ KeyCode keycode = XKeysymToKeycode ( x11->display , key );
27+ keys[ keycode / 8 ] = keys[ keycode / 8 ] & ~( 1 << ( keycode % 8 ) );
28+ }
29+
2530void slop::Keyboard::update () {
2631 char keys[32 ];
2732 XQueryKeymap ( x11->display , keys );
2833 // We first delete the arrow key buttons from the mapping.
2934 // This allows the user to press the arrow keys without triggering anyKeyDown
30- KeyCode keycode = XKeysymToKeycode ( x11->display , XK_Left );
31- keys[ keycode / 8 ] = keys[ keycode / 8 ] & ~( 1 << ( keycode % 8 ) );
32- keycode = XKeysymToKeycode ( x11->display , XK_Right );
33- keys[ keycode / 8 ] = keys[ keycode / 8 ] & ~( 1 << ( keycode % 8 ) );
34- keycode = XKeysymToKeycode ( x11->display , XK_Up );
35- keys[ keycode / 8 ] = keys[ keycode / 8 ] & ~( 1 << ( keycode % 8 ) );
36- keycode = XKeysymToKeycode ( x11->display , XK_Down );
37- keys[ keycode / 8 ] = keys[ keycode / 8 ] & ~( 1 << ( keycode % 8 ) );
35+ zeroKey (keys, XK_Left);
36+ zeroKey (keys, XK_Right);
37+ zeroKey (keys, XK_Up);
38+ zeroKey (keys, XK_Down);
3839 // Also deleting Space for move operation
39- keycode = XKeysymToKeycode ( x11->display , XK_space );
40- keys[ keycode / 8 ] = keys[ keycode / 8 ] & ~( 1 << ( keycode % 8 ) );
40+ zeroKey (keys, XK_space);
41+
42+ if ( mouseKeys ) {
43+ zeroKey (keys, XK_KP_0);
44+ zeroKey (keys, XK_KP_1);
45+ zeroKey (keys, XK_KP_2);
46+ zeroKey (keys, XK_KP_3);
47+ zeroKey (keys, XK_KP_4);
48+ zeroKey (keys, XK_KP_5);
49+ zeroKey (keys, XK_KP_6);
50+ zeroKey (keys, XK_KP_7);
51+ zeroKey (keys, XK_KP_8);
52+ zeroKey (keys, XK_KP_9);
53+ zeroKey (keys, XK_KP_Add);
54+ zeroKey (keys, XK_KP_Subtract);
55+ zeroKey (keys, XK_KP_Multiply);
56+ zeroKey (keys, XK_KP_Divide);
57+ zeroKey (keys, XK_KP_Insert);
58+ zeroKey (keys, XK_KP_Delete);
59+ zeroKey (keys, XK_KP_Decimal);
60+ }
61+
4162 keyDown = false ;
4263 for ( int i=0 ;i<32 ;i++ ) {
4364 if ( deltaState[i] == keys[i] ) {
@@ -69,6 +90,18 @@ slop::Keyboard::Keyboard( X11* x11 ) {
6990 if ( err != GrabSuccess ) {
7091 // throw std::runtime_error( "Couldn't grab the keyboard after 10 tries." );
7192 }
93+
94+ // Ignore any failures while checking for Mouse Keys
95+ XkbDescPtr xkb = XkbGetKeyboard ( x11->display , XkbControlsMask, XkbUseCoreKbd );
96+ if ( xkb != 0 ) {
97+ Status status = XkbGetControls ( x11->display , XkbAllControlsMask, xkb );
98+ if ( status == Success ) {
99+ mouseKeys = xkb->ctrls ->enabled_ctrls & XkbMouseKeysMask;
100+ XkbFreeControls ( xkb, XkbAllControlsMask, true );
101+ }
102+ XkbFreeKeyboard ( xkb, XkbControlsMask, true );
103+ }
104+
72105 XQueryKeymap ( x11->display , deltaState );
73106 keyDown = false ;
74107}
0 commit comments