7498f55
--- plib-1.8.4/src/pw/pwX11.cxx.key	2006-10-05 19:56:42.000000000 +0200
7498f55
+++ plib-1.8.4/src/pw/pwX11.cxx	2006-10-05 20:04:19.000000000 +0200
7498f55
@@ -117,11 +117,19 @@
7498f55
 static XTextProperty *titlePropertyPtr = NULL;
7498f55
 
7498f55
 static bool autoRepeat = false ;
7498f55
+static bool haveFocus = false ;
7498f55
 
7498f55
 static void getEvents ();
7498f55
 
7498f55
 void pwSetAutoRepeatKey ( bool enable )
7498f55
 {
7498f55
+  if ( (autoRepeat != enable) && haveFocus )
7498f55
+  {
7498f55
+    if ( enable )
7498f55
+      XAutoRepeatOn ( currDisplay ) ;
7498f55
+    else
7498f55
+      XAutoRepeatOff ( currDisplay ) ;
7498f55
+  }
7498f55
   autoRepeat = enable ;
7498f55
 }
7498f55
 
7498f55
@@ -351,7 +359,7 @@
7498f55
                        KeyPressMask        | KeyReleaseMask       |
7498f55
 		       EnterWindowMask     | LeaveWindowMask      |
7498f55
                        PointerMotionMask   | ButtonMotionMask     |
7498f55
-                       VisibilityChangeMask ;
7498f55
+                       VisibilityChangeMask| FocusChangeMask;
7498f55
 
7498f55
   attribs.background_pixmap = None ;
7498f55
   attribs.background_pixel  = 0    ;
7498f55
@@ -405,6 +413,10 @@
7498f55
   XMapWindow       ( currDisplay, wmWindow ) ;
7498f55
   glXMakeCurrent   ( currDisplay, currHandle, currContext ) ;
7498f55
 
7498f55
+  haveFocus = true;
7498f55
+  if (!autoRepeat)
7498f55
+    XAutoRepeatOff ( currDisplay ) ;
7498f55
+
7498f55
   pwSetCursor ( PW_CURSOR_LEFT ) ;
7498f55
 
7498f55
 #ifdef GL_MULTISAMPLE_FILTER_HINT_NV
7498f55
@@ -717,8 +729,6 @@
7498f55
 
7498f55
 static void getEvents ()
7498f55
 {
7498f55
-  bool repeating = false ;
7498f55
-  char keyflags [ 32 ] ;
7498f55
   XEvent event ;
7498f55
 
7498f55
   insideCallback = true ;
7498f55
@@ -770,6 +780,18 @@
7498f55
           (*mpCB) ( event.xmotion.x, event.xmotion.y ) ;
7498f55
         break ;
7498f55
 
7498f55
+      case FocusIn:
7498f55
+        if ( !haveFocus && !autoRepeat )
7498f55
+          XAutoRepeatOff ( currDisplay ) ;
7498f55
+        haveFocus = true;
7498f55
+        break;
7498f55
+
7498f55
+      case FocusOut:
7498f55
+        if ( haveFocus && !autoRepeat )
7498f55
+          XAutoRepeatOn ( currDisplay ) ;
7498f55
+        haveFocus = false;
7498f55
+        break;
7498f55
+
7498f55
       case ButtonRelease   :
7498f55
         updown = PW_UP ;
7498f55
         /* FALLTHROUGH */
7498f55
@@ -792,23 +814,9 @@
7498f55
 
7498f55
       case KeyRelease      :
7498f55
         updown = PW_UP ;
7498f55
-
7498f55
-        XQueryKeymap ( currDisplay, keyflags ) ;
7498f55
-
7498f55
-        repeating = ( ( keyflags [ event.xkey.keycode >> 3 ] &
7498f55
-                          ( 1 << ( event.xkey.keycode & 7 ) ) ) != 0 ) ;
7498f55
-
7498f55
         /* FALLTHROUGH */
7498f55
 
7498f55
       case KeyPress        :
7498f55
-        /*
7498f55
-          Only generate a key up callback if the key is actually up
7498f55
-          and not repeating.
7498f55
-        */
7498f55
-
7498f55
-        if ( ! autoRepeat && repeating )
7498f55
-          break ;
7498f55
-
7498f55
         XComposeStatus composeStatus ;
7498f55
         char           asciiCode [ 32 ] ;
7498f55
         KeySym         keySym ;
7498f55
@@ -1021,10 +1029,14 @@
7498f55
   if ( fsWindow != None )
7498f55
     pwSetWindowed ( ) ;
7498f55
 
7498f55
+  if ( haveFocus && !autoRepeat )
7498f55
+    XAutoRepeatOn ( currDisplay ) ;
7498f55
+
7498f55
   glXDestroyContext ( currDisplay, currContext ) ;
7498f55
   XDestroyWindow    ( currDisplay, currHandle  ) ;
7498f55
   XDestroyWindow    ( currDisplay, wmWindow    ) ;
7498f55
   XCloseDisplay     ( currDisplay ) ;
7498f55
+  haveFocus = false;
7498f55
   currDisplay = NULL;
7498f55
 }
7498f55