summaryrefslogtreecommitdiff
path: root/gdk/gdkdevice.c
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2013-07-03 11:52:58 +0200
committerAlexander Larsson <alexl@redhat.com>2013-07-03 14:39:25 +0200
commite8b38fedbd8961df4aaaa75b122a06ddc68e75f2 (patch)
treef8543ff9715a6f480e1bc645268844455ed3df2e /gdk/gdkdevice.c
parent867ba1df27b9ed27d2d3ed6d43b536484635da18 (diff)
downloadgtk+-e8b38fedbd8961df4aaaa75b122a06ddc68e75f2.tar.gz
gdk: Convert mouse position to doubles, add new getters
We've long had double precision mouse coordinates on wayland (e.g. when rotating a window) but with the new scaling we even have it on X (and, its also in Xinput2), so convert all the internal mouse/device position getters to use doubles and add new accessors for the public APIs that take doubles instead of ints.
Diffstat (limited to 'gdk/gdkdevice.c')
-rw-r--r--gdk/gdkdevice.c131
1 files changed, 99 insertions, 32 deletions
diff --git a/gdk/gdkdevice.c b/gdk/gdkdevice.c
index 3147d9e6a0..ced0976ec9 100644
--- a/gdk/gdkdevice.c
+++ b/gdk/gdkdevice.c
@@ -24,6 +24,9 @@
#include "gdkinternals.h"
#include "gdkintl.h"
+/* for the use of round() */
+#include "fallback-c89.c"
+
/**
* SECTION:gdkdevice
* @Short_description: Object representing an input device
@@ -406,28 +409,28 @@ gdk_device_get_state (GdkDevice *device,
}
/**
- * gdk_device_get_position:
+ * gdk_device_get_position_double:
* @device: pointer device to query status about.
* @screen: (out) (transfer none) (allow-none): location to store the #GdkScreen
* the @device is on, or %NULL.
* @x: (out) (allow-none): location to store root window X coordinate of @device, or %NULL.
* @y: (out) (allow-none): location to store root window Y coordinate of @device, or %NULL.
*
- * Gets the current location of @device. As a slave device
+ * Gets the current location of @device in double precision. As a slave device
* coordinates are those of its master pointer, This function
* may not be called on devices of type %GDK_DEVICE_TYPE_SLAVE,
* unless there is an ongoing grab on them, see gdk_device_grab().
*
- * Since: 3.0
+ * Since: 3.10
**/
void
-gdk_device_get_position (GdkDevice *device,
- GdkScreen **screen,
- gint *x,
- gint *y)
+gdk_device_get_position_double (GdkDevice *device,
+ GdkScreen **screen,
+ gdouble *x,
+ gdouble *y)
{
GdkDisplay *display;
- gint tmp_x, tmp_y;
+ gdouble tmp_x, tmp_y;
GdkScreen *default_screen;
GdkWindow *root;
@@ -456,15 +459,47 @@ gdk_device_get_position (GdkDevice *device,
}
/**
- * gdk_device_get_window_at_position:
+ * gdk_device_get_position:
+ * @device: pointer device to query status about.
+ * @screen: (out) (transfer none) (allow-none): location to store the #GdkScreen
+ * the @device is on, or %NULL.
+ * @x: (out) (allow-none): location to store root window X coordinate of @device, or %NULL.
+ * @y: (out) (allow-none): location to store root window Y coordinate of @device, or %NULL.
+ *
+ * Gets the current location of @device. As a slave device
+ * coordinates are those of its master pointer, This function
+ * may not be called on devices of type %GDK_DEVICE_TYPE_SLAVE,
+ * unless there is an ongoing grab on them, see gdk_device_grab().
+ *
+ * Since: 3.0
+ **/
+void
+gdk_device_get_position (GdkDevice *device,
+ GdkScreen **screen,
+ gint *x,
+ gint *y)
+{
+ gdouble tmp_x, tmp_y;
+
+ gdk_device_get_position_double (device, screen, &tmp_x, &tmp_y);
+ if (x)
+ *x = round (tmp_x);
+ if (y)
+ *y = round (tmp_y);
+}
+
+
+/**
+ * gdk_device_get_window_at_position_double:
* @device: pointer #GdkDevice to query info to.
* @win_x: (out) (allow-none): return location for the X coordinate of the device location,
* relative to the window origin, or %NULL.
* @win_y: (out) (allow-none): return location for the Y coordinate of the device location,
* relative to the window origin, or %NULL.
*
- * Obtains the window underneath @device, returning the location of the device in @win_x and @win_y. Returns
- * %NULL if the window tree under @device is not known to GDK (for example, belongs to another application).
+ * Obtains the window underneath @device, returning the location of the device in @win_x and @win_y in
+ * double precision. Returns %NULL if the window tree under @device is not known to GDK (for example,
+ * belongs to another application).
*
* As a slave device coordinates are those of its master pointer, This
* function may not be called on devices of type %GDK_DEVICE_TYPE_SLAVE,
@@ -475,11 +510,11 @@ gdk_device_get_position (GdkDevice *device,
* Since: 3.0
**/
GdkWindow *
-gdk_device_get_window_at_position (GdkDevice *device,
- gint *win_x,
- gint *win_y)
+gdk_device_get_window_at_position_double (GdkDevice *device,
+ gdouble *win_x,
+ gdouble *win_y)
{
- gint tmp_x, tmp_y;
+ gdouble tmp_x, tmp_y;
GdkWindow *window;
g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
@@ -492,15 +527,9 @@ gdk_device_get_window_at_position (GdkDevice *device,
/* This might need corrections, as the native window returned
may contain client side children */
if (window)
- {
- double xx, yy;
-
- window = _gdk_window_find_descendant_at (window,
- tmp_x, tmp_y,
- &xx, &yy);
- tmp_x = floor (xx + 0.5);
- tmp_y = floor (yy + 0.5);
- }
+ window = _gdk_window_find_descendant_at (window,
+ tmp_x, tmp_y,
+ &tmp_x, &tmp_y);
if (win_x)
*win_x = tmp_x;
@@ -511,6 +540,44 @@ gdk_device_get_window_at_position (GdkDevice *device,
}
/**
+ * gdk_device_get_window_at_position:
+ * @device: pointer #GdkDevice to query info to.
+ * @win_x: (out) (allow-none): return location for the X coordinate of the device location,
+ * relative to the window origin, or %NULL.
+ * @win_y: (out) (allow-none): return location for the Y coordinate of the device location,
+ * relative to the window origin, or %NULL.
+ *
+ * Obtains the window underneath @device, returning the location of the device in @win_x and @win_y. Returns
+ * %NULL if the window tree under @device is not known to GDK (for example, belongs to another application).
+ *
+ * As a slave device coordinates are those of its master pointer, This
+ * function may not be called on devices of type %GDK_DEVICE_TYPE_SLAVE,
+ * unless there is an ongoing grab on them, see gdk_device_grab().
+ *
+ * Returns: (transfer none): the #GdkWindow under the device position, or %NULL.
+ *
+ * Since: 3.0
+ **/
+GdkWindow *
+gdk_device_get_window_at_position (GdkDevice *device,
+ gint *win_x,
+ gint *win_y)
+{
+ gdouble tmp_x, tmp_y;
+ GdkWindow *window;
+
+ window =
+ gdk_device_get_window_at_position_double (device, &tmp_x, &tmp_y);
+
+ if (win_x)
+ *win_x = round (tmp_x);
+ if (win_y)
+ *win_y = round (tmp_y);
+
+ return window;
+}
+
+/**
* gdk_device_get_history: (skip)
* @device: a #GdkDevice
* @window: the window with respect to which which the event coordinates will be reported
@@ -1535,8 +1602,8 @@ _gdk_device_translate_window_coord (GdkDevice *device,
gboolean
_gdk_device_translate_screen_coord (GdkDevice *device,
GdkWindow *window,
- gint window_root_x,
- gint window_root_y,
+ gdouble window_root_x,
+ gdouble window_root_y,
guint index_,
gdouble value,
gdouble *axis_value)
@@ -1616,10 +1683,10 @@ _gdk_device_query_state (GdkDevice *device,
GdkWindow *window,
GdkWindow **root_window,
GdkWindow **child_window,
- gint *root_x,
- gint *root_y,
- gint *win_x,
- gint *win_y,
+ gdouble *root_x,
+ gdouble *root_y,
+ gdouble *win_x,
+ gdouble *win_y,
GdkModifierType *mask)
{
GDK_DEVICE_GET_CLASS (device)->query_state (device,
@@ -1635,8 +1702,8 @@ _gdk_device_query_state (GdkDevice *device,
GdkWindow *
_gdk_device_window_at_position (GdkDevice *device,
- gint *win_x,
- gint *win_y,
+ gdouble *win_x,
+ gdouble *win_y,
GdkModifierType *mask,
gboolean get_toplevel)
{