]> Pileus Git - ~andy/gtk/blobdiff - gdk/x11/gdkinput-x11.c
Remove selection for DeviceButtonRelease, we no longer need it now that
[~andy/gtk] / gdk / x11 / gdkinput-x11.c
index 770c9b874a18f29f8532c6bf77f880fe074db0f4..b53e5cc7a8ce1a767edee296dc35150bc0f786b2 100644 (file)
 #include "gdkinternals.h"
 #include "gdkx.h"
 #include "gdk.h"               /* For gdk_error_trap_push()/pop() */
+#include "gdkdisplay-x11.h"
 
 #include <string.h>
 
 /* Forward declarations */
-static GdkDevicePrivate *gdk_input_device_new(XDeviceInfo *device, 
-                                             gint include_core);
-static void gdk_input_translate_coordinates(GdkDevicePrivate *gdkdev,
-                                           GdkInputWindow   *input_window,
-                                           gint             *axis_data,
-                                           gdouble          *axis_out,
-                                           gdouble          *x_out,
-                                           gdouble          *y_out);
-static guint gdk_input_translate_state(guint state, guint device_state);
-
-/* Global variables */
+static GdkDevicePrivate *gdk_input_device_new            (GdkDisplay       *display,
+                                                         XDeviceInfo      *device,
+                                                         gint              include_core);
+static void              gdk_input_translate_coordinates (GdkDevicePrivate *gdkdev,
+                                                         GdkInputWindow   *input_window,
+                                                         gint             *axis_data,
+                                                         gdouble          *axis_out,
+                                                         gdouble          *x_out,
+                                                         gdouble          *y_out);
+static guint             gdk_input_translate_state       (guint             state,
+                                                         guint             device_state);
 
 GdkDevicePrivate *
-gdk_input_find_device (guint32 id)
+_gdk_input_find_device (GdkDisplay *display,
+                       guint32     id)
 {
-  GList *tmp_list = _gdk_input_devices;
+  GList *tmp_list = GDK_DISPLAY_X11 (display)->input_devices;
   GdkDevicePrivate *gdkdev;
   while (tmp_list)
     {
@@ -60,8 +62,8 @@ gdk_input_find_device (guint32 id)
 }
 
 void
-gdk_input_get_root_relative_geometry(Display *dpy, Window w, int *x_ret, int *y_ret,
-                                    int *width_ret, int *height_ret)
+_gdk_input_get_root_relative_geometry(Display *display, Window w, int *x_ret, int *y_ret,
+                                     int *width_ret, int *height_ret)
 {
   Window root, parent, child;
   Window *children;
@@ -70,13 +72,13 @@ gdk_input_get_root_relative_geometry(Display *dpy, Window w, int *x_ret, int *y_
   guint width, height;
   guint border_widthc, depthc;
    
-  XQueryTree (dpy, w, &root, &parent, &children, &nchildren);
+  XQueryTree (display, w, &root, &parent, &children, &nchildren);
   if (children)
     XFree(children);
   
-  XGetGeometry (dpy, w, &root, &x, &y, &width, &height, &border_widthc, &depthc);
+  XGetGeometry (display, w, &root, &x, &y, &width, &height, &border_widthc, &depthc);
 
-  XTranslateCoordinates (dpy, w, root, 0, 0, &x, &y, &child);
+  XTranslateCoordinates (display, w, root, 0, 0, &x, &y, &child);
  
   if (x_ret)
     *x_ret = x;
@@ -89,7 +91,9 @@ gdk_input_get_root_relative_geometry(Display *dpy, Window w, int *x_ret, int *y_
 }
 
 static GdkDevicePrivate *
-gdk_input_device_new (XDeviceInfo *device, gint include_core)
+gdk_input_device_new (GdkDisplay  *display,
+                     XDeviceInfo *device, 
+                     gint         include_core)
 {
   GdkDevicePrivate *gdkdev;
   gchar *tmp_name;
@@ -99,6 +103,8 @@ gdk_input_device_new (XDeviceInfo *device, gint include_core)
   gdkdev = g_object_new (GDK_TYPE_DEVICE, NULL);
 
   gdkdev->deviceid = device->id;
+  gdkdev->display = display;
+
   if (device->name[0])
     gdkdev->info.name = g_strdup (device->name);
  else
@@ -112,8 +118,7 @@ gdk_input_device_new (XDeviceInfo *device, gint include_core)
      could invite a very, very, long list... Lowercase name
      for comparison purposes */
 
-  tmp_name = g_strdup (gdkdev->info.name);
-  g_strdown (tmp_name);
+  tmp_name = g_ascii_strdown (gdkdev->info.name, -1);
   
   if (!strcmp (tmp_name, "pointer"))
     gdkdev->info.source = GDK_SOURCE_MOUSE;
@@ -218,7 +223,8 @@ gdk_input_device_new (XDeviceInfo *device, gint include_core)
   if (device->use != IsXPointer)
     {
       gdk_error_trap_push ();
-      gdkdev->xdevice = XOpenDevice(gdk_display, gdkdev->deviceid);
+      gdkdev->xdevice = XOpenDevice (GDK_DISPLAY_XDISPLAY (display),
+                                    gdkdev->deviceid);
 
       /* return NULL if device is not ready */
       if (gdk_error_trap_pop ())
@@ -251,19 +257,16 @@ gdk_input_device_new (XDeviceInfo *device, gint include_core)
 }
 
 void
-gdk_input_common_find_events(GdkWindow *window,
-                            GdkDevicePrivate *gdkdev,
-                            gint mask,
-                            XEventClass *classes,
-                            int *num_classes)
+_gdk_input_common_find_events(GdkWindow *window,
+                             GdkDevicePrivate *gdkdev,
+                             gint mask,
+                             XEventClass *classes,
+                             int *num_classes)
 {
   gint i;
   XEventClass class;
   
   i = 0;
-  /* We have to track press and release events in pairs to keep
-     track of button state correctly and implement grabbing for
-     the gxi support */
   if (mask & GDK_BUTTON_PRESS_MASK || mask & GDK_BUTTON_RELEASE_MASK)
     {
       DeviceButtonPress (gdkdev->xdevice, gdkdev->buttonpress_type,
@@ -273,10 +276,6 @@ gdk_input_common_find_events(GdkWindow *window,
       DeviceButtonPressGrab (gdkdev->xdevice, 0, class);
       if (class != 0)
          classes[i++] = class;
-      DeviceButtonRelease (gdkdev->xdevice, gdkdev->buttonrelease_type,
-                          class);
-      if (class != 0)
-         classes[i++] = class;
     }
   if (mask & GDK_POINTER_MOTION_MASK)
     {
@@ -353,57 +352,59 @@ gdk_input_common_find_events(GdkWindow *window,
 }
 
 void
-gdk_input_common_select_events(GdkWindow *window,
-                              GdkDevicePrivate *gdkdev)
+_gdk_input_common_select_events(GdkWindow *window,
+                               GdkDevicePrivate *gdkdev)
 {
   XEventClass classes[GDK_MAX_DEVICE_CLASSES];
   gint num_classes;
 
   if (gdkdev->info.mode == GDK_MODE_DISABLED)
-    gdk_input_common_find_events(window, gdkdev, 0, classes, &num_classes);
+    _gdk_input_common_find_events(window, gdkdev, 0, classes, &num_classes);
   else
-    gdk_input_common_find_events(window, gdkdev, 
-                                ((GdkWindowObject *)window)->extension_events,
-                                classes, &num_classes);
+    _gdk_input_common_find_events(window, gdkdev, 
+                                 ((GdkWindowObject *)window)->extension_events,
+                                 classes, &num_classes);
   
-  XSelectExtensionEvent (gdk_display,
-                        GDK_WINDOW_XWINDOW(window),
+  XSelectExtensionEvent (GDK_WINDOW_XDISPLAY (window),
+                        GDK_WINDOW_XWINDOW (window),
                         classes, num_classes);
 }
 
 gint 
-gdk_input_common_init(gint include_core)
+_gdk_input_common_init (GdkDisplay *display,
+                       gint        include_core)
 {
   char **extensions;
   XDeviceInfo   *devices;
   int num_devices;
   int num_extensions, loop;
-  Display *display = gdk_display;
+  GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
 
   /* Init XInput extension */
   
-  extensions = XListExtensions(display, &num_extensions);
+  extensions = XListExtensions(display_x11->xdisplay, &num_extensions);
   for (loop = 0; loop < num_extensions &&
         (strcmp(extensions[loop], "XInputExtension") != 0); loop++);
   XFreeExtensionList(extensions);
-  _gdk_input_devices = NULL;
+  display_x11->input_devices = NULL;
   if (loop < num_extensions)
     {
       /* XInput extension found */
 
-      devices = XListInputDevices(display, &num_devices);
+      devices = XListInputDevices(display_x11->xdisplay, &num_devices);
   
       for(loop=0; loop<num_devices; loop++)
        {
-         GdkDevicePrivate *gdkdev = gdk_input_device_new(&devices[loop],
-                                                     include_core);
+         GdkDevicePrivate *gdkdev = gdk_input_device_new(display,
+                                                         &devices[loop],
+                                                         include_core);
          if (gdkdev)
-           _gdk_input_devices = g_list_append(_gdk_input_devices, gdkdev);
+           display_x11->input_devices = g_list_append(display_x11->input_devices, gdkdev);
        }
       XFreeDeviceList(devices);
     }
 
-  _gdk_input_devices = g_list_append (_gdk_input_devices, _gdk_core_pointer);
+  display_x11->input_devices = g_list_append (display_x11->input_devices, display->core_pointer);
 
   return TRUE;
 }
@@ -448,8 +449,8 @@ gdk_input_translate_coordinates (GdkDevicePrivate *gdkdev,
 
   if (gdkdev->info.mode == GDK_MODE_SCREEN) 
     {
-      x_scale = gdk_screen_width() / device_width;
-      y_scale = gdk_screen_height() / device_height;
+      x_scale = gdk_screen_get_width (gdk_drawable_get_screen (input_window->window)) / device_width;
+      y_scale = gdk_screen_get_height (gdk_drawable_get_screen (input_window->window)) / device_height;
 
       x_offset = - input_window->root_x;
       y_offset = - input_window->root_y;
@@ -520,10 +521,10 @@ gdk_input_translate_state(guint state, guint device_state)
 
 
 gint 
-gdk_input_common_other_event (GdkEvent         *event,
-                             XEvent           *xevent,
-                             GdkInputWindow   *input_window,
-                             GdkDevicePrivate *gdkdev)
+_gdk_input_common_other_event (GdkEvent         *event,
+                              XEvent           *xevent,
+                              GdkInputWindow   *input_window,
+                              GdkDevicePrivate *gdkdev)
 {
   if ((xevent->type == gdkdev->buttonpress_type) ||
       (xevent->type == gdkdev->buttonrelease_type)) 
@@ -686,11 +687,11 @@ _gdk_device_get_history (GdkDevice         *device,
   gint i;
 
   gdkdev = (GdkDevicePrivate *)device;
-  input_window = gdk_input_window_find (window);
+  input_window = _gdk_input_window_find (window);
 
   g_return_val_if_fail (input_window != NULL, FALSE);
 
-  device_coords = XGetDeviceMotionEvents (gdk_display,
+  device_coords = XGetDeviceMotionEvents (GDK_WINDOW_XDISPLAY (window),
                                          gdkdev->xdevice,
                                          start, stop,
                                          n_events, &mode_return,
@@ -711,12 +712,7 @@ _gdk_device_get_history (GdkDevice         *device,
       return TRUE;
     }
   else
-    {
-      *events = NULL;
-      *n_events = 0;
-
-      return FALSE;
-    }
+    return FALSE;
 }
 
 void 
@@ -753,10 +749,11 @@ gdk_device_get_state (GdkDevice       *device,
        gdk_window_get_pointer (window, NULL, NULL, mask);
       
       gdkdev = (GdkDevicePrivate *)device;
-      input_window = gdk_input_window_find (window);
+      input_window = _gdk_input_window_find (window);
       g_return_if_fail (input_window != NULL);
 
-      state = XQueryDeviceState (gdk_display, gdkdev->xdevice);
+      state = XQueryDeviceState (GDK_WINDOW_XDISPLAY (window),
+                                gdkdev->xdevice);
       input_class = state->data;
       for (i=0; i<state->num_classes; i++)
        {