[AD] fix for auto repeat in X version

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


This patch fixes auto repeating in X version, it turns off auto repeat
for display connection when keyboard is installed and restores
previous state of auto repeat state when keyboard is shutdown.

There is one problem with this patch.  Pause key starts to auto repeat
when pressed once, but it might be the problem for all ports of
Allegro that use software auto repeat mode.


diff -ruN old/allegro-3.9.30/src/x/xkeybd.c new/allegro-3.9.30/src/x/xkeybd.c
--- old/allegro-3.9.30/src/x/xkeybd.c	Mon Dec 20 06:39:28 1999
+++ new/allegro-3.9.30/src/x/xkeybd.c	Fri Jan  7 11:31:03 2000
@@ -28,6 +28,9 @@
 static void _xwin_keydrv_set_rate(int delay, int rate);
 
 
+static int _xwin_keydrv_auto_repeat_state = 1;
+
+
 static KEYBOARD_DRIVER keyboard_xwin =
 {
    KEYBOARD_XWINDOWS,
@@ -34,7 +34,7 @@
    empty_string,
    empty_string,
    "X-Windows keyboard",
-   FALSE,
+   TRUE,
    _xwin_keydrv_init,
    _xwin_keydrv_exit,
    NULL,
@@ -72,10 +75,6 @@
  */
 static void _xwin_keydrv_set_rate(int delay, int rate)
 {
-   if ((delay == 0) && (rate == 0))
-      _xwin_auto_repeat_off();
-   else
-      _xwin_auto_repeat_on();
 }
 
 
@@ -147,6 +146,8 @@
    _xwin_init_keyboard_tables();
    _xwin_keydrv_set_leds(_key_shifts);
 
+   _xwin_keydrv_auto_repeat_state = _xwin_set_auto_repeat(FALSE);
+
    DISABLE();
 
    _xwin_keyboard_interrupt = _xwin_keydrv_handler;
@@ -165,6 +166,8 @@
 static void _xwin_keydrv_exit(void)
 {
    DISABLE();
+
+   _xwin_set_auto_repeat(_xwin_keydrv_auto_repeat_state);
 
    _xwin_keyboard_interrupt = 0;
    _xwin_keyboard_focused = 0;
diff -ruN old/allegro-3.9.30/src/x/xwin.c new/allegro-3.9.30/src/x/xwin.c
--- old/allegro-3.9.30/src/x/xwin.c	Mon Dec 20 06:39:28 1999
+++ new/allegro-3.9.30/src/x/xwin.c	Fri Jan  7 11:30:10 2000
@@ -179,8 +179,7 @@
 static void _xwin_private_change_keyboard_control(int led, int on);
 static int _xwin_private_get_pointer_mapping(unsigned char map[], int nmap);
 static void _xwin_private_init_keyboard_tables(void);
-static void _xwin_private_auto_repeat_on(void);
-static void _xwin_private_auto_repeat_off(void);
+static int _xwin_private_set_auto_repeat(int on);
 
 #ifdef ALLEGRO_XWINDOWS_WITH_XF86DGA
 static BITMAP *_xdga_private_create_screen(GFX_DRIVER *drv, int w, int h,
@@ -2475,38 +2474,33 @@
 
 
 
-/* _xwin_auto_repeat_on:
- *  Wrapper for XAutoRepeatOn.
+/* _xwin_set_auto_repeat:
+ *  Set auto repeat mode, return previous state of auto repeat.
  */
-static void _xwin_private_auto_repeat_on(void)
+static int _xwin_private_set_auto_repeat(int on)
 {
-   if (_xwin.display != 0)
-      XAutoRepeatOn(_xwin.display);
-}
-
-void _xwin_auto_repeat_on(void)
-{
-   DISABLE();
-   _xwin_private_auto_repeat_on();
-   ENABLE();
-}
+   XKeyboardState state;
 
+   if (_xwin.display == 0)
+      return TRUE;
 
+   XGetKeyboardControl(_xwin.display, &state);
 
-/* _xwin_auto_repeat_off:
- *  Wrapper for XAutoRepeatOff.
- */
-static void _xwin_private_auto_repeat_off(void)
-{
-   if (_xwin.display != 0)
+   if (on != 0)
+      XAutoRepeatOn(_xwin.display);
+   else
       XAutoRepeatOff(_xwin.display);
+
+   return ((state.global_auto_repeat == AutoRepeatModeOn) ? TRUE : FALSE);
 }
 
-void _xwin_auto_repeat_off(void)
+int _xwin_set_auto_repeat(int on)
 {
+   int state;
    DISABLE();
-   _xwin_private_auto_repeat_off();
+   state = _xwin_private_set_auto_repeat(on);
    ENABLE();
+   return state;
 }
 
 
diff -ruN old/allegro-3.9.30/src/x/xwin.h new/allegro-3.9.30/src/x/xwin.h
--- old/allegro-3.9.30/src/x/xwin.h	Mon Dec 20 06:39:28 1999
+++ new/allegro-3.9.30/src/x/xwin.h	Fri Jan  7 11:24:43 2000
@@ -47,8 +47,7 @@
    AL_FUNC(void, _xwin_change_keyboard_control, (int led, int on));
    AL_FUNC(int, _xwin_get_pointer_mapping, (unsigned char map[], int nmap));
    AL_FUNC(void, _xwin_init_keyboard_tables, (void));
-   AL_FUNC(void, _xwin_auto_repeat_on, (void));
-   AL_FUNC(void, _xwin_auto_repeat_off, (void));
+   AL_FUNC(int, _xwin_set_auto_repeat, (int on));
 
    AL_FUNC(BITMAP*, _xdga_create_screen, (GFX_DRIVER *drv, int w, int h,
 					  int vw, int vh, int depth, int fullscr));


-- 
Michael Bukin



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/