2.34.0
[platform/upstream/at-spi2-core.git] / registryd / deviceeventcontroller-x11.c
index 2e26f17..df16bd8 100644 (file)
@@ -6,19 +6,19 @@
  * Copyright 2001, 2002 Ximian, Inc.
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 /* deviceeventcontroller-x11.c: X-specific DeviceEventController support */
 #define XK_LATIN1
 #include <X11/keysymdef.h>
 
-#ifdef HAVE_XEVIE
-#include <X11/Xproto.h>
-#include <X11/X.h>
-#include <X11/extensions/Xevie.h>
-#endif /* HAVE_XEVIE */
-
 #include <glib.h>
 
 #include <dbus/dbus.h>
@@ -65,9 +59,6 @@
 
 #include "introspection.h"
 
-KeySym ucs2keysym (long ucs);
-long keysym2ucs(KeySym keysym); 
-
 static void spi_dec_x11_emit_modifier_event (SpiDEController *controller,
                             guint prev_mask,
                             guint current_mask);
@@ -149,6 +140,14 @@ keysym_mod_mask (KeySym keysym, KeyCode keycode)
                 (sym_rtn == keysym)) {
                retval = Mod3Mask;
        }
+       else if (XkbLookupKeySym (display, keycode, Mod4Mask, &mods_rtn, &sym_rtn) &&
+                (sym_rtn == keysym)) {
+               retval = Mod4Mask;
+       }
+       else if (XkbLookupKeySym (display, keycode, Mod5Mask, &mods_rtn, &sym_rtn) &&
+                (sym_rtn == keysym)) {
+               retval = Mod5Mask;
+       }
        else if (XkbLookupKeySym (display, keycode, 
                                  ShiftMask | Mod2Mask, &mods_rtn, &sym_rtn) &&
                 (sym_rtn == keysym)) {
@@ -164,6 +163,11 @@ keysym_mod_mask (KeySym keysym, KeyCode keycode)
                 (sym_rtn == keysym)) {
                retval = (Mod4Mask | ShiftMask);
        }
+       else if (XkbLookupKeySym (display, keycode,
+                                 ShiftMask | Mod5Mask, &mods_rtn, &sym_rtn) &&
+                (sym_rtn == keysym)) {
+               retval = (Mod5Mask | ShiftMask);
+       }
        else
                retval = 0xFFFF;
        return retval;
@@ -240,6 +244,7 @@ spi_dec_x11_get_keycode (SpiDEController *controller,
                         * Long-term fix is to extend the X keymap here instead of replace entries.
                         */
                        priv->reserved_reset_timeout = g_timeout_add (500, spi_dec_reset_reserved, priv);
+                       g_source_set_name_by_id (priv->reserved_reset_timeout, "[at-spi2-core] spi_dec_reset_reserved");
                }               
                if (modmask)
                        *modmask = 0;
@@ -1026,8 +1031,10 @@ spi_dec_x11_synth_keycode_press (SpiDEController *controller,
 {
        unsigned int time = CurrentTime;
        unsigned int bounce_delay;
+#ifdef THIS_IS_BROKEN 
        unsigned int elapsed_msec;
        struct timeval tv;
+#endif
        DEControllerPrivateData *priv = controller->priv;
 
        spi_x_error_trap ();
@@ -1036,15 +1043,15 @@ spi_dec_x11_synth_keycode_press (SpiDEController *controller,
                bounce_delay = xkb_get_bouncekeys_delay (controller); 
                 if (bounce_delay)
                {
+#ifdef THIS_IS_BROKEN
                        gettimeofday (&tv, NULL);
                        elapsed_msec =
                                (tv.tv_sec - priv->last_release_time.tv_sec) * 1000
                                + (tv.tv_usec - priv->last_release_time.tv_usec) / 1000;
-#ifdef SPI_XKB_DEBUG                   
+# ifdef SPI_XKB_DEBUG
                        fprintf (stderr, "%d ms elapsed (%ld usec)\n", elapsed_msec,
                                 (long) (tv.tv_usec - priv->last_release_time.tv_usec));
-#endif
-#ifdef THIS_IS_BROKEN
+# endif
                        if (elapsed_msec < bounce_delay)
                                time = bounce_delay - elapsed_msec + 1;
 #else
@@ -1070,8 +1077,10 @@ spi_dec_x11_synth_keycode_release (SpiDEController *controller,
 {
        unsigned int time = CurrentTime;
        unsigned int slow_delay;
+#ifdef THIS_IS_BROKEN_DUNNO_WHY
        unsigned int elapsed_msec;
        struct timeval tv;
+#endif
        DEControllerPrivateData *priv = controller->priv;
 
        spi_x_error_trap ();
@@ -1080,15 +1089,15 @@ spi_dec_x11_synth_keycode_release (SpiDEController *controller,
                slow_delay = xkb_get_slowkeys_delay (controller);
                if (slow_delay)
                {
+#ifdef THIS_IS_BROKEN_DUNNO_WHY
                        gettimeofday (&tv, NULL);
                        elapsed_msec =
                                (tv.tv_sec - priv->last_press_time.tv_sec) * 1000
                                + (tv.tv_usec - priv->last_press_time.tv_usec) / 1000;
-#ifdef SPI_XKB_DEBUG                   
+# ifdef SPI_XKB_DEBUG
                        fprintf (stderr, "%d ms elapsed (%ld usec)\n", elapsed_msec,
                                 (long) (tv.tv_usec - priv->last_press_time.tv_usec));
-#endif
-#ifdef THIS_IS_BROKEN_DUNNO_WHY
+# endif
                        if (elapsed_msec < slow_delay)
                                time = slow_delay - elapsed_msec + 1;
 #else
@@ -1149,7 +1158,7 @@ spi_dec_x11_unlock_modifiers (SpiDEController *controller, unsigned modifiers)
 static KeySym
 keysym_for_unichar (SpiDEController *controller, gunichar unichar)
 {
-       return ucs2keysym ((long) unichar);
+       return (KeySym) ucs2keysym ((long) unichar);
 }
 
 static gboolean
@@ -1167,8 +1176,6 @@ spi_dec_x11_synth_keystring (SpiDEController *controller, guint synth_type, gint
        const gchar *c;
        KeySym keysym;
 
-       maxlen = strlen (keystring) + 1;
-       keysyms = g_new0 (KeySym, maxlen);
        if (!(keystring && *keystring && g_utf8_validate (keystring, -1, &c))) { 
                retval = FALSE;
        } 
@@ -1176,6 +1183,9 @@ spi_dec_x11_synth_keystring (SpiDEController *controller, guint synth_type, gint
 #ifdef SPI_DEBUG
                fprintf (stderr, "[keystring synthesis attempted on %s]\n", keystring);
 #endif
+               maxlen = strlen (keystring) + 1;
+               keysyms = g_new0 (KeySym, maxlen);
+
                while (keystring && (unichar = g_utf8_get_char (keystring))) {
                        char bytes[6];
                        gint mbytes;
@@ -1209,8 +1219,9 @@ spi_dec_x11_synth_keystring (SpiDEController *controller, guint synth_type, gint
                        }
                }
                XSynchronize (spi_get_display (), FALSE);
+
+               g_free (keysyms);
        }
-       g_free (keysyms);
 
        if (synth_type == Accessibility_KEY_SYM) {
                keysym = keycode;
@@ -1224,69 +1235,12 @@ spi_dec_x11_synth_keystring (SpiDEController *controller, guint synth_type, gint
        return retval;
 }
 
-#ifdef HAVE_XEVIE
-static Bool
-isEvent(Display *dpy, XEvent *event, char *arg)
-{
-   return TRUE;
-}
-
-static gboolean
-handle_io (GIOChannel *source,
-           GIOCondition condition,
-           gpointer data) 
-{
-  SpiDEController *controller = (SpiDEController *) data;
-    DEControllerPrivateData *priv = controller->priv;
-  gboolean is_consumed = FALSE;
-  XEvent ev;
-
-  while (XCheckIfEvent(priv->xevie_display, &ev, isEvent, NULL))
-    {
-      if (ev.type == KeyPress || ev.type == KeyRelease)
-        is_consumed = spi_device_event_controller_forward_key_event (controller, &ev);
-
-      if (! is_consumed)
-        XevieSendEvent(priv->xevie_display, &ev, XEVIE_UNMODIFIED);
-    }
-
-  return TRUE;
-}
-#endif /* HAVE_XEVIE */
-
 static void
 spi_dec_x11_init (SpiDEController *controller)
 {
   DEControllerPrivateData *priv = controller->priv;    
-  spi_events_init (spi_get_display());
-#ifdef HAVE_XEVIE
-  GIOChannel *ioc;
-  int fd;
-#endif /* HAVE_XEVIE */
 
   spi_events_init (spi_get_display ());
-#ifdef HAVE_XEVIE
-  priv->xevie_display = XOpenDisplay(NULL);
-
-  if (XevieStart(priv->xevie_display) == TRUE)
-    {
-#ifdef SPI_KEYEVENT_DEBUG
-      fprintf (stderr, "XevieStart() success \n");
-#endif
-      XevieSelectInput(priv->xevie_display, KeyPressMask | KeyReleaseMask);
-
-      fd = ConnectionNumber(priv->xevie_display);
-      ioc = g_io_channel_unix_new (fd);
-      g_io_add_watch (ioc, G_IO_IN | G_IO_HUP, handle_io, controller);
-      g_io_channel_unref (ioc);
-    }
-  else
-    {
-#ifdef SPI_KEYEVENT_DEBUG
-      fprintf (stderr, "XevieStart() failed, only one client is allowed to do event int exception\n");
-#endif
-    }
-#endif /* HAVE_XEVIE */
 
   gettimeofday (&priv->last_press_time, NULL);
   gettimeofday (&priv->last_release_time, NULL);
@@ -1300,22 +1254,13 @@ spi_dec_x11_init (SpiDEController *controller)
 static void
 spi_dec_x11_finalize (SpiDEController *controller)
 {
-               DEControllerPrivateData *priv = controller->priv;
+  DEControllerPrivateData *priv = controller->priv;
+
   /* disconnect any special listeners, get rid of outstanding keygrabs */
   XUngrabKey (spi_get_display (), AnyKey, AnyModifier, DefaultRootWindow (spi_get_display ()));
 
-#ifdef HAVE_XEVIE
-  if (priv->xevie_display != NULL)
-    {
-      XevieEnd(priv->xevie_display);
-#ifdef SPI_KEYEVENT_DEBUG
-      printf("XevieEnd(dpy) finished \n");
-#endif
-    }
-#endif
-
   if (priv->xkb_desc)
-  XkbFreeKeyboard (priv->xkb_desc, 0, True);
+    XkbFreeKeyboard (priv->xkb_desc, 0, True);
   /* TODO: Should free the keymap */
 }
 
@@ -1323,7 +1268,7 @@ static gboolean
 spi_device_event_controller_forward_key_event (SpiDEController *controller,
                                               const XEvent    *event)
 {
-               DEControllerPrivateData *priv = controller->priv;
+  DEControllerPrivateData *priv = controller->priv;
   Accessibility_DeviceEvent key_event;
   gboolean ret;
 
@@ -1376,6 +1321,7 @@ wait_for_release_event (XEvent          *event,
 {
   pressed_event = spi_keystroke_from_x_key_event ((XKeyEvent *) event);
   check_release_handler = g_timeout_add (CHECK_RELEASE_DELAY, check_release, &pressed_event);
+  g_source_set_name_by_id (check_release_handler, "[at-spi2-core] check_release");
 }
 
 static void