2003-01-27 Padraig O'Briain <padraig.obriain@sun.com
[platform/core/uifw/at-spi2-atk.git] / registryd / deviceeventcontroller.c
index 8849dba..9171c5b 100644 (file)
@@ -32,6 +32,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <stdio.h>
+#include <sys/time.h>
 #include <bonobo/bonobo-exception.h>
 
 #include <X11/Xlib.h>
@@ -105,7 +106,6 @@ typedef struct {
   int xkb_base_error_code;
   unsigned int xkb_latch_mask;
   unsigned int pending_xkb_mod_relatch_mask;
-  KeyCode *shift_keycodes;
   XkbDescPtr xkb_desc;
 } DEControllerPrivateData;
 
@@ -144,51 +144,6 @@ keycode_for_keysym (long keysym)
   return XKeysymToKeycode (spi_get_display (), (KeySym) keysym);
 }
 
-#define SPI_DEC_MAX_SHIFT_KEYSYMS 15
-static long _shift_keysyms[SPI_DEC_MAX_SHIFT_KEYSYMS] = 
-                                {XK_Shift_L, XK_Shift_R,
-                                XK_Control_L, XK_Control_R,
-                                XK_Caps_Lock, XK_Shift_Lock,
-                                XK_Alt_L, XK_Alt_R,
-                                XK_Meta_L, XK_Meta_R, 
-                                XK_Super_L, XK_Super_R,
-                                XK_Hyper_L, XK_Hyper_R,
-                                0};
-
-static gboolean
-spi_keycodes_contain (KeyCode keycodes[], KeyCode keycode)
-{
-  int i = 0;
-
-  if (keycode)
-    {
-      while (i < SPI_DEC_MAX_SHIFT_KEYSYMS)
-       {
-         if (keycodes[i] == keycode) 
-           return TRUE;
-         ++i;
-       }
-    }
-  return FALSE;
-}
-
-static void
-spi_dec_init_keycode_list (SpiDEController *controller)
-{
-  DEControllerPrivateData *priv = 
-    g_object_get_qdata (G_OBJECT (controller), spi_dec_private_quark);
-  KeyCode keycode;
-  int i;
-  priv->shift_keycodes = g_malloc (sizeof (KeyCode) * 
-                                  SPI_DEC_MAX_SHIFT_KEYSYMS);
-  for (i = 0; _shift_keysyms[i] != 0; ++i)
-    { 
-      keycode = keycode_for_keysym (_shift_keysyms [i]);
-      priv->shift_keycodes [i] = keycode;
-    }
-  priv->shift_keycodes [i] = 0; /* terminate the list */
-}
-
 static DEControllerGrabMask *
 spi_grab_mask_clone (DEControllerGrabMask *grab_mask)
 {
@@ -236,8 +191,6 @@ spi_dec_set_unlatch_pending (SpiDEController *controller, unsigned mask)
   priv->pending_xkb_mod_relatch_mask |= priv->xkb_latch_mask; 
 }
  
-static gint poll_count = 0;
-
 static gboolean
 spi_dec_button_update_and_emit (SpiDEController *controller, 
                                guint mask_return)
@@ -294,13 +247,13 @@ spi_dec_button_update_and_emit (SpiDEController *controller,
          is_down = True;
        } 
       else if (!(mask_return & Button4Mask) &&
-              (mouse_mask_state & Button1Mask)) 
+              (mouse_mask_state & Button4Mask)) 
        {
          mouse_mask_state &= ~Button4Mask;
          button_number = 4;
        } 
       else if ((mask_return & Button4Mask) &&
-              !(mouse_mask_state & Button1Mask)) 
+              !(mouse_mask_state & Button4Mask)) 
        {
          mouse_mask_state |= Button4Mask;
          button_number = 4;
@@ -373,7 +326,6 @@ spi_dec_mouse_check (SpiDEController *controller,
   Accessibility_Event e;
   CORBA_Environment ev;
   int win_x_return,win_y_return;
-  int poll_count_modulus = 10;
   unsigned int mask_return;
   Window root_return, child_return;
   Display *display = spi_get_display ();
@@ -395,20 +347,17 @@ spi_dec_mouse_check (SpiDEController *controller,
       while (spi_dec_button_update_and_emit (controller, mask_return));
     }
 
-  if (poll_count++ == poll_count_modulus) {
-    poll_count = 0;
-    e.type = "mouse:abs";  
-    e.source = BONOBO_OBJREF (controller->registry->desktop);
-    e.detail1 = *x;
-    e.detail2 = *y;
-    spi_init_any_nil (&e.any_data);
-    CORBA_exception_init (&ev);
-    Accessibility_Registry_notifyEvent (BONOBO_OBJREF (controller->registry),
-                                       &e,
-                                       &ev);
-  }
   if (*x != last_mouse_pos->x || *y != last_mouse_pos->y) 
     {
+      e.type = "mouse:abs";  
+      e.source = BONOBO_OBJREF (controller->registry->desktop);
+      e.detail1 = *x;
+      e.detail2 = *y;
+      spi_init_any_nil (&e.any_data);
+      CORBA_exception_init (&ev);
+      Accessibility_Registry_notifyEvent (BONOBO_OBJREF (controller->registry),
+                                         &e,
+                                         &ev);
       e.type = "mouse:rel";  
       e.source = BONOBO_OBJREF (controller->registry->desktop);
       e.detail1 = *x - last_mouse_pos->x;
@@ -1888,26 +1837,6 @@ impl_generate_keyboard_event (PortableServer_Servant           servant,
     {
       DBG (-1, g_warning ("Error emitting keystroke"));
     }
-
-  /* now we must determine whether this keystroke is expected 
-   * to delatch XKB. This is a bit of a hack :-( */
-  priv =  g_object_get_qdata (G_OBJECT (controller), spi_dec_private_quark);
-  if (!priv->shift_keycodes) 
-    spi_dec_init_keycode_list (controller);
-  if (!spi_keycodes_contain (priv->shift_keycodes, key_synth_code)) 
-    {
-      priv->pending_xkb_mod_relatch_mask = 0;
-      priv->xkb_latch_mask = 0;
-      fprintf (stderr, "resetting the relatch masks.\n");
-    }
-  else
-    {
-      int x, y;
-      gboolean moved;
-      priv->pending_xkb_mod_relatch_mask = 
-       spi_dec_mouse_check (controller, &x, &y, &moved);
-      fprintf (stderr, "preparing to relatch %x\n");
-    }
 }
 
 /* Accessibility::DEController::generateMouseEvent */
@@ -2032,20 +1961,12 @@ spi_device_event_controller_init (SpiDEController *device_event_controller)
   device_event_controller->mouse_listeners = NULL;
   device_event_controller->keygrabs_list   = NULL;
 
-  /*
-   * TODO: fixme, this module makes the foolish assumptions that
-   * registryd uses the same display as the apps, and that the
-   * DISPLAY environment variable is set.
-   */
-  gdk_init (NULL, NULL);
-  
   private = g_new0 (DEControllerPrivateData, 1);
   gettimeofday (&private->last_press_time, NULL);
   gettimeofday (&private->last_release_time, NULL);
   g_object_set_qdata (G_OBJECT (device_event_controller),
                      spi_dec_private_quark,
                      private);
-  private->shift_keycodes = NULL;
   spi_controller_register_with_devices (device_event_controller);
 }