Explorar el Código

ignore arrowkey presses for cancelling selection.

naelstrof hace 7 años
padre
commit
dcb9364586
Se han modificado 2 ficheros con 16 adiciones y 0 borrados
  1. 13
    0
      src/keyboard.cpp
  2. 3
    0
      src/keyboard.hpp

+ 13
- 0
src/keyboard.cpp Ver fichero

@@ -15,6 +15,9 @@ bool slop::Keyboard::getKey( KeySym key ) {
15 15
     }
16 16
 }
17 17
 
18
+// This returns if a key is currently pressed.
19
+// Ignores arrow key presses specifically so users can
20
+// adjust their selection.
18 21
 bool slop::Keyboard::anyKeyDown() {
19 22
     return keyDown;
20 23
 }
@@ -22,6 +25,16 @@ bool slop::Keyboard::anyKeyDown() {
22 25
 void slop::Keyboard::update() {
23 26
     char keys[32];
24 27
     XQueryKeymap( x11->display, keys );
28
+    // We first delete the arrow key buttons from the mapping.
29
+    // 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 ) );
25 38
     keyDown = false;
26 39
     for ( int i=0;i<32;i++ ) {
27 40
         if ( deltaState[i] == keys[i] ) {

+ 3
- 0
src/keyboard.hpp Ver fichero

@@ -21,6 +21,9 @@
21 21
 #ifndef N_KEYBOARD_H_
22 22
 #define N_KEYBOARD_H_
23 23
 
24
+#define XK_MISCELLANY
25
+#include <X11/keysymdef.h>
26
+
24 27
 #include "x.hpp"
25 28
 
26 29
 namespace slop {