[gimp] app: move the entire get-coords API from GimpDisplayShell to GimpDeviceInfo



commit 5af05cce0b2b48b8db5274850bad400a37614ff8
Author: Michael Natterer <mitch gimp org>
Date:   Tue Feb 16 13:00:46 2010 +0100

    app: move the entire get-coords API from GimpDisplayShell to GimpDeviceInfo
    
    because GimpDeviceInfo will soon apply curves to the axes. Also change
    everything to speak in terms of GimpDeviceInfo instead of GdkDevice.

 app/display/gimpdisplayshell-autoscroll.c |   12 ++-
 app/display/gimpdisplayshell-callbacks.c  |   56 +++++----
 app/display/gimpdisplayshell-coords.c     |  135 ---------------------
 app/display/gimpdisplayshell-coords.h     |   18 ---
 app/widgets/Makefile.am                   |    2 +
 app/widgets/gimpdeviceinfo-coords.c       |  186 +++++++++++++++++++++++++++++
 app/widgets/gimpdeviceinfo-coords.h       |   43 +++++++
 app/widgets/gimpdevices.c                 |   58 +++++-----
 app/widgets/gimpdevices.h                 |   28 ++--
 app/widgets/gimpdevicestatus.c            |    5 +-
 app/widgets/gimpdevicestatus.h            |   14 +-
 11 files changed, 324 insertions(+), 233 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-autoscroll.c b/app/display/gimpdisplayshell-autoscroll.c
index 5084e21..71f2bce 100644
--- a/app/display/gimpdisplayshell-autoscroll.c
+++ b/app/display/gimpdisplayshell-autoscroll.c
@@ -21,10 +21,12 @@
 
 #include "display-types.h"
 
+#include "widgets/gimpdeviceinfo.h"
+#include "widgets/gimpdeviceinfo-coords.h"
+
 #include "gimpdisplay.h"
 #include "gimpdisplayshell.h"
 #include "gimpdisplayshell-autoscroll.h"
-#include "gimpdisplayshell-coords.h"
 #include "gimpdisplayshell-scroll.h"
 #include "gimpdisplayshell-transform.h"
 
@@ -41,7 +43,7 @@
 typedef struct
 {
   GdkEventMotion  *mevent;
-  GdkDevice       *device;
+  GimpDeviceInfo  *device;
   guint32          time;
   GdkModifierType  state;
   guint            timeout_id;
@@ -70,7 +72,7 @@ gimp_display_shell_autoscroll_start (GimpDisplayShell *shell,
   info = g_slice_new0 (ScrollInfo);
 
   info->mevent     = mevent;
-  info->device     = mevent->device;
+  info->device     = gimp_device_info_get_by_device (mevent->device);
   info->time       = gdk_event_get_time ((GdkEvent *) mevent);
   info->state      = state;
   info->timeout_id = g_timeout_add (AUTOSCROLL_DT,
@@ -115,7 +117,9 @@ gimp_display_shell_autoscroll_timeout (gpointer data)
   gint              dx = 0;
   gint              dy = 0;
 
-  gimp_display_shell_get_device_coords (shell, info->device, &device_coords);
+  gimp_device_info_get_device_coords (info->device,
+                                      gtk_widget_get_window (shell->canvas),
+                                      &device_coords);
 
   if (device_coords.x < 0)
     dx = device_coords.x;
diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c
index c5da214..a3910d5 100644
--- a/app/display/gimpdisplayshell-callbacks.c
+++ b/app/display/gimpdisplayshell-callbacks.c
@@ -53,6 +53,8 @@
 #include "widgets/gimpcontrollers.h"
 #include "widgets/gimpcontrollerkeyboard.h"
 #include "widgets/gimpcontrollerwheel.h"
+#include "widgets/gimpdeviceinfo.h"
+#include "widgets/gimpdeviceinfo-coords.h"
 #include "widgets/gimpdevices.h"
 #include "widgets/gimpdialogfactory.h"
 #include "widgets/gimpuimanager.h"
@@ -402,11 +404,11 @@ gimp_display_shell_canvas_expose (GtkWidget        *widget,
 static void
 gimp_display_shell_check_device_cursor (GimpDisplayShell *shell)
 {
-  GdkDevice *current_device;
+  GimpDeviceInfo *current_device;
 
   current_device = gimp_devices_get_current (shell->display->gimp);
 
-  shell->draw_cursor = ! current_device->has_cursor;
+  shell->draw_cursor = ! gimp_device_info_has_cursor (current_device);
 }
 
 static void
@@ -458,9 +460,9 @@ gimp_display_shell_space_pressed (GimpDisplayShell *shell,
       {
         GimpCoords coords;
 
-        gimp_display_shell_get_device_coords (shell,
-                                              gimp_devices_get_current (gimp),
-                                              &coords);
+        gimp_device_info_get_device_coords (gimp_devices_get_current (gimp),
+                                            gtk_widget_get_window (shell->canvas),
+                                            &coords);
 
         gimp_display_shell_start_scrolling (shell, coords.x, coords.y);
 
@@ -647,12 +649,14 @@ gimp_display_shell_canvas_tool_events (GtkWidget        *canvas,
       device_changed = TRUE;
     }
 
-  gimp_display_shell_get_event_coords (shell, event,
-                                       gimp_devices_get_current (gimp),
-                                       &display_coords);
-  gimp_display_shell_get_event_state (shell, event,
-                                      gimp_devices_get_current (gimp),
-                                      &state);
+  gimp_device_info_get_event_coords (gimp_devices_get_current (gimp),
+                                     gtk_widget_get_window (shell->canvas),
+                                     event,
+                                     &display_coords);
+  gimp_device_info_get_event_state (gimp_devices_get_current (gimp),
+                                    gtk_widget_get_window (shell->canvas),
+                                    event,
+                                    &state);
   time = gdk_event_get_time (event);
 
   /*  GimpCoords passed to tools are ALWAYS in image coordinates  */
@@ -877,7 +881,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget        *canvas,
                  *  the wacom driver is known to report crappy hints
                  *  (#6901) --mitch
                  */
-                if (gimp_devices_get_current (gimp) ==
+                if (gimp_devices_get_current (gimp)->device ==
                     gdk_display_get_core_pointer (gdk_display))
                   {
                     event_mask |= GDK_POINTER_MOTION_HINT_MASK;
@@ -1252,12 +1256,16 @@ gimp_display_shell_canvas_tool_events (GtkWidget        *canvas,
 
         if (compressed_motion && ! shell->scrolling)
           {
-            GdkDevice *device = gimp_devices_get_current (gimp);
-
-            gimp_display_shell_get_event_coords (shell, compressed_motion,
-                                                 device, &display_coords);
-            gimp_display_shell_get_event_state (shell, compressed_motion,
-                                                device, &state);
+            GimpDeviceInfo *device = gimp_devices_get_current (gimp);
+
+            gimp_device_info_get_event_coords (device,
+                                               gtk_widget_get_window (shell->canvas),
+                                               compressed_motion,
+                                               &display_coords);
+            gimp_device_info_get_event_state (device,
+                                              gtk_widget_get_window (shell->canvas),
+                                              compressed_motion,
+                                              &state);
             time = gdk_event_get_time (event);
 
             /*  GimpCoords passed to tools are ALWAYS in image coordinates  */
@@ -1343,17 +1351,19 @@ gimp_display_shell_canvas_tool_events (GtkWidget        *canvas,
                                             &history_events,
                                             &n_history_events))
                   {
-                    gint i;
+                    GimpDeviceInfo *device;
+                    gint            i;
+
+                    device = gimp_device_info_get_by_device (mevent->device);
 
                     tool_manager_control_active (gimp, GIMP_TOOL_ACTION_PAUSE,
                                                  display);
 
                     for (i = 0; i < n_history_events; i++)
                       {
-                        gimp_display_shell_get_time_coords (shell,
-                                                            mevent->device,
-                                                            history_events[i],
-                                                            &display_coords);
+                        gimp_device_info_get_time_coords (device,
+                                                          history_events[i],
+                                                          &display_coords);
 
                         /*  GimpCoords passed to tools are ALWAYS in
                          *  image coordinates
diff --git a/app/display/gimpdisplayshell-coords.c b/app/display/gimpdisplayshell-coords.c
index 73e3e11..3617d02 100644
--- a/app/display/gimpdisplayshell-coords.c
+++ b/app/display/gimpdisplayshell-coords.c
@@ -42,141 +42,6 @@ static const GimpCoords default_coords = GIMP_COORDS_DEFAULT_VALUES;
 
 /*  public functions  */
 
-gboolean
-gimp_display_shell_get_event_coords (GimpDisplayShell *shell,
-                                     GdkEvent         *event,
-                                     GdkDevice        *device,
-                                     GimpCoords       *coords)
-{
-  gdouble x;
-
-  if (gdk_event_get_axis (event, GDK_AXIS_X, &x))
-    {
-      *coords = default_coords;
-
-      coords->x = x;
-      gdk_event_get_axis (event, GDK_AXIS_Y, &coords->y);
-
-      /*  CLAMP() the return value of each *_get_axis() call to be safe
-       *  against buggy XInput drivers.
-       */
-
-      if (gdk_event_get_axis (event, GDK_AXIS_PRESSURE, &coords->pressure))
-        coords->pressure = CLAMP (coords->pressure, GIMP_COORDS_MIN_PRESSURE,
-                                  GIMP_COORDS_MAX_PRESSURE);
-
-      if (gdk_event_get_axis (event, GDK_AXIS_XTILT, &coords->xtilt))
-        coords->xtilt = CLAMP (coords->xtilt, GIMP_COORDS_MIN_TILT,
-                               GIMP_COORDS_MAX_TILT);
-
-      if (gdk_event_get_axis (event, GDK_AXIS_YTILT, &coords->ytilt))
-        coords->ytilt = CLAMP (coords->ytilt, GIMP_COORDS_MIN_TILT,
-                               GIMP_COORDS_MAX_TILT);
-
-      if (gdk_event_get_axis (event, GDK_AXIS_WHEEL, &coords->wheel))
-        coords->wheel = CLAMP (coords->wheel, GIMP_COORDS_MIN_WHEEL,
-                               GIMP_COORDS_MAX_WHEEL);
-
-      return TRUE;
-    }
-
-  gimp_display_shell_get_device_coords (shell, device, coords);
-
-  return FALSE;
-}
-
-void
-gimp_display_shell_get_device_coords (GimpDisplayShell *shell,
-                                      GdkDevice        *device,
-                                      GimpCoords       *coords)
-{
-  gdouble axes[GDK_AXIS_LAST];
-
-  *coords = default_coords;
-
-  gdk_device_get_state (device, gtk_widget_get_window (shell->canvas),
-                        axes, NULL);
-
-  gdk_device_get_axis (device, axes, GDK_AXIS_X, &coords->x);
-  gdk_device_get_axis (device, axes, GDK_AXIS_Y, &coords->y);
-
-  /*  CLAMP() the return value of each *_get_axis() call to be safe
-   *  against buggy XInput drivers.
-   */
-
-  if (gdk_device_get_axis (device, axes, GDK_AXIS_PRESSURE, &coords->pressure))
-    coords->pressure = CLAMP (coords->pressure, GIMP_COORDS_MIN_PRESSURE,
-                              GIMP_COORDS_MAX_PRESSURE);
-
-  if (gdk_device_get_axis (device, axes, GDK_AXIS_XTILT, &coords->xtilt))
-    coords->xtilt = CLAMP (coords->xtilt, GIMP_COORDS_MIN_TILT,
-                           GIMP_COORDS_MAX_TILT);
-
-  if (gdk_device_get_axis (device, axes, GDK_AXIS_YTILT, &coords->ytilt))
-    coords->ytilt = CLAMP (coords->ytilt, GIMP_COORDS_MIN_TILT,
-                           GIMP_COORDS_MAX_TILT);
-
-  if (gdk_device_get_axis (device, axes, GDK_AXIS_WHEEL, &coords->wheel))
-    coords->wheel = CLAMP (coords->wheel, GIMP_COORDS_MIN_WHEEL,
-                           GIMP_COORDS_MAX_WHEEL);
-}
-
-void
-gimp_display_shell_get_time_coords (GimpDisplayShell *shell,
-                                    GdkDevice        *device,
-                                    GdkTimeCoord     *event,
-                                    GimpCoords       *coords)
-{
-  *coords = default_coords;
-
-  gdk_device_get_axis (device, event->axes, GDK_AXIS_X, &coords->x);
-  gdk_device_get_axis (device, event->axes, GDK_AXIS_Y, &coords->y);
-
-  /*  CLAMP() the return value of each *_get_axis() call to be safe
-   *  against buggy XInput drivers.
-   */
-
-  if (gdk_device_get_axis (device,
-                           event->axes, GDK_AXIS_PRESSURE, &coords->pressure))
-    coords->pressure = CLAMP (coords->pressure, GIMP_COORDS_MIN_PRESSURE,
-                              GIMP_COORDS_MAX_PRESSURE);
-
-  if (gdk_device_get_axis (device, event->axes, GDK_AXIS_XTILT, &coords->xtilt))
-    coords->xtilt = CLAMP (coords->xtilt, GIMP_COORDS_MIN_TILT,
-                           GIMP_COORDS_MAX_TILT);
-
-  if (gdk_device_get_axis (device, event->axes, GDK_AXIS_YTILT, &coords->ytilt))
-    coords->ytilt = CLAMP (coords->ytilt, GIMP_COORDS_MIN_TILT,
-                           GIMP_COORDS_MAX_TILT);
-
-  if (gdk_device_get_axis (device, event->axes, GDK_AXIS_WHEEL, &coords->wheel))
-    coords->wheel = CLAMP (coords->wheel, GIMP_COORDS_MIN_WHEEL,
-                           GIMP_COORDS_MAX_WHEEL);
-}
-
-gboolean
-gimp_display_shell_get_event_state (GimpDisplayShell *shell,
-                                    GdkEvent         *event,
-                                    GdkDevice        *device,
-                                    GdkModifierType  *state)
-{
-  if (gdk_event_get_state (event, state))
-    return TRUE;
-
-  gimp_display_shell_get_device_state (shell, device, state);
-
-  return FALSE;
-}
-
-void
-gimp_display_shell_get_device_state (GimpDisplayShell *shell,
-                                     GdkDevice        *device,
-                                     GdkModifierType  *state)
-{
-  gdk_device_get_state (device, gtk_widget_get_window (shell->canvas),
-                        NULL, state);
-}
-
 /**
  * gimp_display_shell_eval_event:
  * @shell:
diff --git a/app/display/gimpdisplayshell-coords.h b/app/display/gimpdisplayshell-coords.h
index 83a521e..30928fc 100644
--- a/app/display/gimpdisplayshell-coords.h
+++ b/app/display/gimpdisplayshell-coords.h
@@ -19,24 +19,6 @@
 #define __GIMP_DISPLAY_SHELL_COORDS_H__
 
 
-gboolean gimp_display_shell_get_event_coords   (GimpDisplayShell *shell,
-                                                GdkEvent         *event,
-                                                GdkDevice        *device,
-                                                GimpCoords       *coords);
-void     gimp_display_shell_get_device_coords  (GimpDisplayShell *shell,
-                                                GdkDevice        *device,
-                                                GimpCoords       *coords);
-void     gimp_display_shell_get_time_coords    (GimpDisplayShell *shell,
-                                                GdkDevice        *device,
-                                                GdkTimeCoord     *event,
-                                                GimpCoords       *coords);
-gboolean gimp_display_shell_get_event_state    (GimpDisplayShell *shell,
-                                                GdkEvent         *event,
-                                                GdkDevice        *device,
-                                                GdkModifierType  *state);
-void     gimp_display_shell_get_device_state   (GimpDisplayShell *shell,
-                                                GdkDevice        *device,
-                                                GdkModifierType  *state);
 gboolean gimp_display_shell_eval_event         (GimpDisplayShell *shell,
                                                 GimpCoords       *coords,
                                                 gdouble           inertia_factor,
diff --git a/app/widgets/Makefile.am b/app/widgets/Makefile.am
index b1b09ad..b5525f4 100644
--- a/app/widgets/Makefile.am
+++ b/app/widgets/Makefile.am
@@ -116,6 +116,8 @@ libappwidgets_a_sources = \
 	gimpdeviceeditor.h		\
 	gimpdeviceinfo.c		\
 	gimpdeviceinfo.h		\
+	gimpdeviceinfo-coords.c		\
+	gimpdeviceinfo-coords.h		\
 	gimpdeviceinfoeditor.c		\
 	gimpdeviceinfoeditor.h		\
 	gimpdevices.c			\
diff --git a/app/widgets/gimpdeviceinfo-coords.c b/app/widgets/gimpdeviceinfo-coords.c
new file mode 100644
index 0000000..b918b75
--- /dev/null
+++ b/app/widgets/gimpdeviceinfo-coords.c
@@ -0,0 +1,186 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+
+#include "widgets-types.h"
+
+#include "gimpdeviceinfo.h"
+#include "gimpdeviceinfo-coords.h"
+
+
+static const GimpCoords default_coords = GIMP_COORDS_DEFAULT_VALUES;
+
+
+/*  public functions  */
+
+gboolean
+gimp_device_info_get_event_coords (GimpDeviceInfo *info,
+                                   GdkWindow      *window,
+                                   GdkEvent       *event,
+                                   GimpCoords     *coords)
+{
+  gdouble x;
+
+  if (gdk_event_get_axis (event, GDK_AXIS_X, &x))
+    {
+      *coords = default_coords;
+
+      coords->x = x;
+      gdk_event_get_axis (event, GDK_AXIS_Y, &coords->y);
+
+      /*  CLAMP() the return value of each *_get_axis() call to be safe
+       *  against buggy XInput drivers.
+       */
+
+      if (gdk_event_get_axis (event, GDK_AXIS_PRESSURE, &coords->pressure))
+        coords->pressure = CLAMP (coords->pressure, GIMP_COORDS_MIN_PRESSURE,
+                                  GIMP_COORDS_MAX_PRESSURE);
+
+      if (gdk_event_get_axis (event, GDK_AXIS_XTILT, &coords->xtilt))
+        coords->xtilt = CLAMP (coords->xtilt, GIMP_COORDS_MIN_TILT,
+                               GIMP_COORDS_MAX_TILT);
+
+      if (gdk_event_get_axis (event, GDK_AXIS_YTILT, &coords->ytilt))
+        coords->ytilt = CLAMP (coords->ytilt, GIMP_COORDS_MIN_TILT,
+                               GIMP_COORDS_MAX_TILT);
+
+      if (gdk_event_get_axis (event, GDK_AXIS_WHEEL, &coords->wheel))
+        coords->wheel = CLAMP (coords->wheel, GIMP_COORDS_MIN_WHEEL,
+                               GIMP_COORDS_MAX_WHEEL);
+
+      return TRUE;
+    }
+
+  gimp_device_info_get_device_coords (info, window, coords);
+
+  return FALSE;
+}
+
+void
+gimp_device_info_get_device_coords (GimpDeviceInfo *info,
+                                    GdkWindow      *window,
+                                    GimpCoords     *coords)
+{
+  gdouble axes[GDK_AXIS_LAST];
+
+  *coords = default_coords;
+
+  gdk_device_get_state (info->device, window, axes, NULL);
+
+  gdk_device_get_axis (info->device, axes, GDK_AXIS_X, &coords->x);
+  gdk_device_get_axis (info->device, axes, GDK_AXIS_Y, &coords->y);
+
+  /*  CLAMP() the return value of each *_get_axis() call to be safe
+   *  against buggy XInput drivers.
+   */
+
+  if (gdk_device_get_axis (info->device,
+                           axes, GDK_AXIS_PRESSURE, &coords->pressure))
+    {
+      coords->pressure = CLAMP (coords->pressure, GIMP_COORDS_MIN_PRESSURE,
+                                GIMP_COORDS_MAX_PRESSURE);
+    }
+
+  if (gdk_device_get_axis (info->device,
+                           axes, GDK_AXIS_XTILT, &coords->xtilt))
+    {
+      coords->xtilt = CLAMP (coords->xtilt, GIMP_COORDS_MIN_TILT,
+                             GIMP_COORDS_MAX_TILT);
+    }
+
+  if (gdk_device_get_axis (info->device,
+                           axes, GDK_AXIS_YTILT, &coords->ytilt))
+    {
+      coords->ytilt = CLAMP (coords->ytilt, GIMP_COORDS_MIN_TILT,
+                             GIMP_COORDS_MAX_TILT);
+    }
+
+  if (gdk_device_get_axis (info->device,
+                           axes, GDK_AXIS_WHEEL, &coords->wheel))
+    {
+      coords->wheel = CLAMP (coords->wheel, GIMP_COORDS_MIN_WHEEL,
+                             GIMP_COORDS_MAX_WHEEL);
+    }
+}
+
+void
+gimp_device_info_get_time_coords (GimpDeviceInfo *info,
+                                  GdkTimeCoord   *event,
+                                  GimpCoords     *coords)
+{
+  *coords = default_coords;
+
+  gdk_device_get_axis (info->device, event->axes, GDK_AXIS_X, &coords->x);
+  gdk_device_get_axis (info->device, event->axes, GDK_AXIS_Y, &coords->y);
+
+  /*  CLAMP() the return value of each *_get_axis() call to be safe
+   *  against buggy XInput drivers.
+   */
+
+  if (gdk_device_get_axis (info->device,
+                           event->axes, GDK_AXIS_PRESSURE, &coords->pressure))
+    {
+      coords->pressure = CLAMP (coords->pressure, GIMP_COORDS_MIN_PRESSURE,
+                                GIMP_COORDS_MAX_PRESSURE);
+    }
+
+  if (gdk_device_get_axis (info->device,
+                           event->axes, GDK_AXIS_XTILT, &coords->xtilt))
+    {
+      coords->xtilt = CLAMP (coords->xtilt, GIMP_COORDS_MIN_TILT,
+                             GIMP_COORDS_MAX_TILT);
+    }
+
+  if (gdk_device_get_axis (info->device,
+                           event->axes, GDK_AXIS_YTILT, &coords->ytilt))
+    {
+      coords->ytilt = CLAMP (coords->ytilt, GIMP_COORDS_MIN_TILT,
+                             GIMP_COORDS_MAX_TILT);
+    }
+
+  if (gdk_device_get_axis (info->device,
+                           event->axes, GDK_AXIS_WHEEL, &coords->wheel))
+    {
+      coords->wheel = CLAMP (coords->wheel, GIMP_COORDS_MIN_WHEEL,
+                             GIMP_COORDS_MAX_WHEEL);
+    }
+}
+
+gboolean
+gimp_device_info_get_event_state (GimpDeviceInfo  *info,
+                                  GdkWindow       *window,
+                                  GdkEvent        *event,
+                                  GdkModifierType *state)
+{
+  if (gdk_event_get_state (event, state))
+    return TRUE;
+
+  gimp_device_info_get_device_state (info, window, state);
+
+  return FALSE;
+}
+
+void
+gimp_device_info_get_device_state (GimpDeviceInfo  *info,
+                                   GdkWindow       *window,
+                                   GdkModifierType *state)
+{
+  gdk_device_get_state (info->device, window, NULL, state);
+}
diff --git a/app/widgets/gimpdeviceinfo-coords.h b/app/widgets/gimpdeviceinfo-coords.h
new file mode 100644
index 0000000..fae6d23
--- /dev/null
+++ b/app/widgets/gimpdeviceinfo-coords.h
@@ -0,0 +1,43 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_DEVICE_INFO_COORDS_H__
+#define __GIMP_DEVICE_INFO_COORDS_H__
+
+
+gboolean gimp_device_info_get_event_coords   (GimpDeviceInfo  *info,
+                                              GdkWindow       *window,
+                                              GdkEvent        *event,
+                                              GimpCoords      *coords);
+void     gimp_device_info_get_device_coords  (GimpDeviceInfo  *info,
+                                              GdkWindow       *window,
+                                              GimpCoords      *coords);
+
+void     gimp_device_info_get_time_coords    (GimpDeviceInfo  *info,
+                                              GdkTimeCoord    *event,
+                                              GimpCoords      *coords);
+
+gboolean gimp_device_info_get_event_state    (GimpDeviceInfo  *info,
+                                              GdkWindow       *window,
+                                              GdkEvent        *event,
+                                              GdkModifierType *state);
+void     gimp_device_info_get_device_state   (GimpDeviceInfo  *info,
+                                              GdkWindow       *window,
+                                              GdkModifierType *state);
+
+
+#endif /* __GIMP_DEVICE_INFO_COORDS_H__ */
diff --git a/app/widgets/gimpdevices.c b/app/widgets/gimpdevices.c
index 361432f..23cc80e 100644
--- a/app/widgets/gimpdevices.c
+++ b/app/widgets/gimpdevices.c
@@ -58,7 +58,7 @@ struct _GimpDeviceManager
 {
   Gimp                   *gimp;
   GimpContainer          *device_info_list;
-  GdkDevice              *current_device;
+  GimpDeviceInfo         *current_device;
   GimpDeviceChangeNotify  change_notify;
   gboolean                devicerc_deleted;
 };
@@ -105,11 +105,8 @@ gimp_devices_init (Gimp                   *gimp,
                           GIMP_DEVICE_MANAGER_DATA_KEY, manager,
                           (GDestroyNotify) gimp_device_manager_free);
 
-  gdk_display = gdk_display_get_default ();
-
   manager->gimp             = gimp;
   manager->device_info_list = gimp_list_new (GIMP_TYPE_DEVICE_INFO, FALSE);
-  manager->current_device   = gdk_display_get_core_pointer (gdk_display);
   manager->change_notify    = change_notify;
 
   gimp_list_set_sort_func (GIMP_LIST (manager->device_info_list),
@@ -130,6 +127,11 @@ gimp_devices_init (Gimp                   *gimp,
   g_signal_connect (disp_manager, "display-opened",
                     G_CALLBACK (gimp_devices_display_opened),
                     manager);
+
+  gdk_display = gdk_display_get_default ();
+
+  manager->current_device =
+    gimp_device_info_get_by_device (gdk_display_get_core_pointer (gdk_display));
 }
 
 void
@@ -154,7 +156,6 @@ void
 gimp_devices_restore (Gimp *gimp)
 {
   GimpDeviceManager *manager;
-  GimpDeviceInfo    *device_info;
   GimpContext       *user_context;
   GList             *list;
   gchar             *filename;
@@ -199,13 +200,11 @@ gimp_devices_restore (Gimp *gimp)
 
   gimp_list_reverse (GIMP_LIST (manager->device_info_list));
 
-  device_info = gimp_device_info_get_by_device (manager->current_device);
-
-  g_return_if_fail (GIMP_IS_DEVICE_INFO (device_info));
-
-  gimp_context_copy_properties (GIMP_CONTEXT (device_info), user_context,
+  gimp_context_copy_properties (GIMP_CONTEXT (manager->current_device),
+                                user_context,
                                 GIMP_DEVICE_INFO_CONTEXT_MASK);
-  gimp_context_set_parent (GIMP_CONTEXT (device_info), user_context);
+  gimp_context_set_parent (GIMP_CONTEXT (manager->current_device),
+                           user_context);
 }
 
 void
@@ -293,7 +292,7 @@ gimp_devices_get_list (Gimp *gimp)
   return manager->device_info_list;
 }
 
-GdkDevice *
+GimpDeviceInfo *
 gimp_devices_get_current (Gimp *gimp)
 {
   GimpDeviceManager *manager;
@@ -308,30 +307,22 @@ gimp_devices_get_current (Gimp *gimp)
 }
 
 void
-gimp_devices_select_device (Gimp      *gimp,
-                            GdkDevice *new_device)
+gimp_devices_select_device (Gimp           *gimp,
+                            GimpDeviceInfo *new_device_info)
 {
   GimpDeviceManager *manager;
-  GimpDeviceInfo    *current_device_info;
-  GimpDeviceInfo    *new_device_info;
   GimpContext       *user_context;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
-  g_return_if_fail (GDK_IS_DEVICE (new_device));
+  g_return_if_fail (GIMP_IS_DEVICE_INFO (new_device_info));
 
   manager = gimp_device_manager_get (gimp);
 
   g_return_if_fail (manager != NULL);
 
-  current_device_info = gimp_device_info_get_by_device (manager->current_device);
-  new_device_info     = gimp_device_info_get_by_device (new_device);
-
-  g_return_if_fail (GIMP_IS_DEVICE_INFO (current_device_info));
-  g_return_if_fail (GIMP_IS_DEVICE_INFO (new_device_info));
-
-  gimp_context_set_parent (GIMP_CONTEXT (current_device_info), NULL);
+  gimp_context_set_parent (GIMP_CONTEXT (manager->current_device), NULL);
 
-  manager->current_device = new_device;
+  manager->current_device = new_device_info;
 
   user_context = gimp_get_user_context (gimp);
 
@@ -349,6 +340,7 @@ gimp_devices_check_change (Gimp     *gimp,
 {
   GimpDeviceManager *manager;
   GdkDevice         *device;
+  GimpDeviceInfo    *device_info;
   GtkWidget         *source;
 
   g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
@@ -391,13 +383,15 @@ gimp_devices_check_change (Gimp     *gimp,
       break;
 
     default:
-      device = manager->current_device;
+      device = manager->current_device->device;
       break;
     }
 
-  if (device != manager->current_device)
+  device_info = gimp_device_info_get_by_device (device);
+
+  if (device_info != manager->current_device)
     {
-      gimp_devices_select_device (gimp, device);
+      gimp_devices_select_device (gimp, device_info);
       return TRUE;
     }
 
@@ -495,5 +489,13 @@ gimp_devices_device_removed (GdkDisplay        *gdk_display,
   if (device_info)
     {
       gimp_device_info_set_device (device_info, NULL, NULL);
+
+      if (device_info == manager->current_device)
+        {
+          device      = gdk_display_get_core_pointer (gdk_display);
+          device_info = gimp_device_info_get_by_device (device);
+
+          gimp_devices_select_device (manager->gimp, device_info);
+        }
     }
 }
diff --git a/app/widgets/gimpdevices.h b/app/widgets/gimpdevices.h
index 833f96e..719a647 100644
--- a/app/widgets/gimpdevices.h
+++ b/app/widgets/gimpdevices.h
@@ -22,24 +22,24 @@
 typedef void (* GimpDeviceChangeNotify) (Gimp *gimp);
 
 
-void            gimp_devices_init          (Gimp                   *gimp,
-                                            GimpDeviceChangeNotify  callback);
-void            gimp_devices_exit          (Gimp                   *gimp);
+void             gimp_devices_init          (Gimp                   *gimp,
+                                             GimpDeviceChangeNotify  callback);
+void             gimp_devices_exit          (Gimp                   *gimp);
 
-void            gimp_devices_restore       (Gimp                   *gimp);
-void            gimp_devices_save          (Gimp                   *gimp,
-                                            gboolean                always_save);
+void             gimp_devices_restore       (Gimp                   *gimp);
+void             gimp_devices_save          (Gimp                   *gimp,
+                                             gboolean                always_save);
 
-gboolean        gimp_devices_clear         (Gimp                   *gimp,
-                                            GError                **error);
+gboolean         gimp_devices_clear         (Gimp                   *gimp,
+                                             GError                **error);
 
-GimpContainer * gimp_devices_get_list      (Gimp                   *gimp);
-GdkDevice     * gimp_devices_get_current   (Gimp                   *gimp);
+GimpContainer  * gimp_devices_get_list      (Gimp                   *gimp);
+GimpDeviceInfo * gimp_devices_get_current   (Gimp                   *gimp);
 
-gboolean        gimp_devices_check_change  (Gimp                   *gimp,
-                                            GdkEvent               *event);
-void            gimp_devices_select_device (Gimp                   *gimp,
-                                            GdkDevice              *device);
+gboolean         gimp_devices_check_change  (Gimp                   *gimp,
+                                             GdkEvent               *event);
+void             gimp_devices_select_device (Gimp                   *gimp,
+                                             GimpDeviceInfo         *info);
 
 
 #endif /* __GIMP_DEVICES_H__ */
diff --git a/app/widgets/gimpdevicestatus.c b/app/widgets/gimpdevicestatus.c
index e1c8bd3..7c91c79 100644
--- a/app/widgets/gimpdevicestatus.c
+++ b/app/widgets/gimpdevicestatus.c
@@ -415,12 +415,9 @@ gimp_device_status_update (GimpDeviceStatus *status)
   for (list = status->devices; list; list = list->next)
     {
       GimpDeviceStatusEntry *entry = list->data;
-      GdkDevice             *device;
-
-      device = gimp_device_info_get_device (entry->device_info, NULL);
 
       gtk_widget_set_visible (entry->arrow,
-                              device && device == status->current_device);
+                              entry->device_info == status->current_device);
     }
 }
 
diff --git a/app/widgets/gimpdevicestatus.h b/app/widgets/gimpdevicestatus.h
index 6b4c200..93060c4 100644
--- a/app/widgets/gimpdevicestatus.h
+++ b/app/widgets/gimpdevicestatus.h
@@ -38,17 +38,17 @@ typedef struct _GimpDeviceStatusClass GimpDeviceStatusClass;
 
 struct _GimpDeviceStatus
 {
-  GimpEditor  parent_instance;
+  GimpEditor      parent_instance;
 
-  Gimp       *gimp;
-  GdkDevice  *current_device;
+  Gimp           *gimp;
+  GimpDeviceInfo *current_device;
 
-  GList      *devices;
+  GList          *devices;
 
-  GtkWidget  *vbox;
+  GtkWidget      *vbox;
 
-  GtkWidget  *save_button;
-  GtkWidget  *edit_button;
+  GtkWidget      *save_button;
+  GtkWidget      *edit_button;
 };
 
 struct _GimpDeviceStatusClass



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]