]> Pileus Git - ~andy/gtk/blobdiff - gdk/x11/gdkinput-x11.c
Merges from gtk-1-2
[~andy/gtk] / gdk / x11 / gdkinput-x11.c
index dfe161fd719f28464f7dca81d0af65e9e1b8d238..eb6d57295b4a24dcf152117aae56d46f6c6fb7b3 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-#if defined(XINPUT_GXI) || defined(XINPUT_XFREE)
+/*
+ * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
+#include "gdkinputprivate.h"
+#include "gdkx.h"
 
 /* Forward declarations */
-static void gdk_input_get_root_relative_geometry (Display *dpy, Window w, 
-                                                 int *x_ret, int *y_ret,
-                                                 int *width_ret, 
-                                                 int *height_ret);
 static GdkDevicePrivate *gdk_input_device_new(XDeviceInfo *device, 
                                              gint include_core);
-static void gdk_input_common_find_events(GdkWindow *window,
-                                        GdkDevicePrivate *gdkdev,
-                                        gint mask,
-                                        XEventClass *classes,
-                                        int *num_classes);
-static void gdk_input_common_select_events(GdkWindow *window,
-                                          GdkDevicePrivate *gdkdev);
 static void gdk_input_translate_coordinates(GdkDevicePrivate *gdkdev,
                                            GdkInputWindow *input_window,
                                            gint *axis_data,
@@ -40,34 +37,21 @@ static void gdk_input_translate_coordinates(GdkDevicePrivate *gdkdev,
                                            gdouble *pressure,
                                            gdouble *xtilt, gdouble *ytilt);
 static guint gdk_input_translate_state(guint state, guint device_state);
-static gint gdk_input_common_init(gint include_core);
-static gint  gdk_input_common_other_event (GdkEvent *event, 
-                                          XEvent *xevent, 
-                                          GdkInputWindow *input_window,
-                                          GdkDevicePrivate *gdkdev);
-static void gdk_input_common_set_axes (guint32 deviceid, GdkAxisUse *axes);
-static GdkTimeCoord * gdk_input_common_motion_events (GdkWindow *window,
-                                                     guint32 deviceid,
-                                                     guint32 start,
-                                                     guint32 stop,
-                                                     gint *nevents_return);
-static void  gdk_input_common_get_pointer     (GdkWindow       *window,
-                                              guint32     deviceid,
-                                              gdouble         *x,
-                                              gdouble         *y,
-                                              gdouble         *pressure,
-                                              gdouble         *xtilt,
-                                              gdouble         *ytilt,
-                                              GdkModifierType *mask);
-
-#define GDK_MAX_DEVICE_CLASSES 13
+void  gdk_input_common_get_pointer     (GdkWindow       *window,
+                                       guint32    deviceid,
+                                       gdouble         *x,
+                                       gdouble         *y,
+                                       gdouble         *pressure,
+                                       gdouble         *xtilt,
+                                       gdouble         *ytilt,
+                                       GdkModifierType *mask);
 
 /* Global variables */
 
 static gint gdk_input_root_width;
 static gint gdk_input_root_height;
 
-static void
+void
 gdk_input_get_root_relative_geometry(Display *dpy, Window w, int *x_ret, int *y_ret,
                               int *width_ret, int *height_ret)
 {
@@ -186,7 +170,7 @@ gdk_input_device_new(XDeviceInfo *device, gint include_core)
          if ((xki->min_keycode == 8) && (xki->max_keycode == 32))
            {
              gdkdev->info.num_keys = 32;
-             gdkdev->min_keycode = 0;
+             gdkdev->min_keycode = 1;
            }
          else
            {
@@ -294,7 +278,7 @@ gdk_input_device_new(XDeviceInfo *device, gint include_core)
   return gdkdev;
 }
 
-static void
+void
 gdk_input_common_find_events(GdkWindow *window,
                             GdkDevicePrivate *gdkdev,
                             gint mask,
@@ -396,7 +380,7 @@ gdk_input_common_find_events(GdkWindow *window,
   *num_classes = i;
 }
 
-static void
+void
 gdk_input_common_select_events(GdkWindow *window,
                               GdkDevicePrivate *gdkdev)
 {
@@ -436,22 +420,24 @@ gdk_input_common_init(gint include_core)
   for (loop = 0; loop < num_extensions &&
         (strcmp(extensions[loop], "XInputExtension") != 0); loop++);
   XFreeExtensionList(extensions);
-  if (loop == num_extensions)  /* XInput extension not found */
-    return FALSE;
+  gdk_input_devices = NULL;
+  if (loop < num_extensions)
+    {
+      /* XInput extension found */
 
-  gdk_input_devices = 0;
-  devices = XListInputDevices(display, &num_devices);
+      devices = XListInputDevices(display, &num_devices);
   
-  for(loop=0; loop<num_devices; loop++)
-    {
-      GdkDevicePrivate *gdkdev = gdk_input_device_new(&devices[loop],
+      for(loop=0; loop<num_devices; loop++)
+       {
+         GdkDevicePrivate *gdkdev = gdk_input_device_new(&devices[loop],
                                                      include_core);
-      if (gdkdev)
-       gdk_input_devices = g_list_append(gdk_input_devices, gdkdev);
+         if (gdkdev)
+           gdk_input_devices = g_list_append(gdk_input_devices, gdkdev);
+       }
+      XFreeDeviceList(devices);
     }
-  XFreeDeviceList(devices);
 
-  gdk_input_devices = g_list_append (gdk_input_devices, &gdk_input_core_info);
+  gdk_input_devices = g_list_append (gdk_input_devices, (gpointer)&gdk_input_core_info);
 
   return TRUE;
 }
@@ -463,14 +449,14 @@ gdk_input_translate_coordinates (GdkDevicePrivate *gdkdev,
                                 gdouble *x, gdouble *y, gdouble *pressure,
                                 gdouble *xtilt, gdouble *ytilt)
 {
-  GdkWindowPrivate *win_priv;
+  GdkDrawablePrivate *drawable_priv;
 
   int x_axis, y_axis, pressure_axis, xtilt_axis, ytilt_axis;
 
   double device_width, device_height;
   double x_offset, y_offset, x_scale, y_scale;
 
-  win_priv = (GdkWindowPrivate *) input_window->window;
+  drawable_priv = (GdkDrawablePrivate *) input_window->window;
 
   x_axis = gdkdev->axis_for_use[GDK_AXIS_X];
   y_axis = gdkdev->axis_for_use[GDK_AXIS_Y];
@@ -496,26 +482,26 @@ gdk_input_translate_coordinates (GdkDevicePrivate *gdkdev,
       double device_aspect = (device_height*gdkdev->axes[y_axis].resolution) /
        (device_width*gdkdev->axes[x_axis].resolution);
 
-      if (device_aspect * win_priv->width >= win_priv->height)
+      if (device_aspect * drawable_priv->width >= drawable_priv->height)
        {
          /* device taller than window */
-         x_scale = win_priv->width / device_width;
+         x_scale = drawable_priv->width / device_width;
          y_scale = (x_scale * gdkdev->axes[x_axis].resolution)
            / gdkdev->axes[y_axis].resolution;
 
          x_offset = 0;
          y_offset = -(device_height * y_scale - 
-                              win_priv->height)/2;
+                              drawable_priv->height)/2;
        }
       else
        {
          /* window taller than device */
-         y_scale = win_priv->height / device_height;
+         y_scale = drawable_priv->height / device_height;
          x_scale = (y_scale * gdkdev->axes[y_axis].resolution)
            / gdkdev->axes[x_axis].resolution;
 
          y_offset = 0;
-         x_offset = - (device_width * x_scale - win_priv->width)/2;
+         x_offset = - (device_width * x_scale - drawable_priv->width)/2;
        }
     }
   
@@ -572,10 +558,11 @@ gdk_input_translate_state(guint state, guint device_state)
   return device_state | (state & 0xFF);
 }
 
-static gint 
-gdk_input_common_other_event (GdkEvent *event, 
-                             XEvent *xevent, 
-                             GdkInputWindow *input_window,
+
+gint 
+gdk_input_common_other_event (GdkEvent         *event,
+                             XEvent           *xevent,
+                             GdkInputWindow   *input_window,
                              GdkDevicePrivate *gdkdev)
 {
   if ((xevent->type == gdkdev->buttonpress_type) ||
@@ -727,7 +714,7 @@ gdk_input_common_other_event (GdkEvent *event,
   return -1;                   /* wasn't one of our event types */
 }
 
-static void
+void
 gdk_input_common_set_axes (guint32 deviceid, GdkAxisUse *axes)
 {
   int i;
@@ -746,10 +733,11 @@ gdk_input_common_set_axes (guint32 deviceid, GdkAxisUse *axes)
     }
 }
 
-void gdk_input_common_set_key (guint32 deviceid,
-                              guint   index,
-                              guint   keyval,
-                              GdkModifierType modifiers)
+void 
+gdk_input_common_set_key (guint32 deviceid,
+                         guint   index,
+                         guint   keyval,
+                         GdkModifierType modifiers)
 {
   GdkDevicePrivate *gdkdev = gdk_input_find_device(deviceid);
   
@@ -761,7 +749,7 @@ void gdk_input_common_set_key (guint32 deviceid,
   gdkdev->info.keys[index].modifiers = modifiers;
 }
 
-static GdkTimeCoord *
+GdkTimeCoord *
 gdk_input_common_motion_events (GdkWindow *window,
                                guint32 deviceid,
                                guint32 start,
@@ -810,7 +798,7 @@ gdk_input_common_motion_events (GdkWindow *window,
     return NULL;
 }
 
-static void 
+void 
 gdk_input_common_get_pointer     (GdkWindow       *window,
                                  guint32          deviceid,
                                  gdouble         *x,
@@ -877,7 +865,6 @@ gdk_input_common_get_pointer     (GdkWindow       *window,
            }
          input_class = (XInputClass *)(((char *)input_class)+input_class->length);
        }
+      XFreeDeviceState (state);
     }
 }
-
-#endif