diff options
Diffstat (limited to 'libdocument/ev-document-misc.c')
-rw-r--r-- | libdocument/ev-document-misc.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/libdocument/ev-document-misc.c b/libdocument/ev-document-misc.c index a695c050..a0ba4785 100644 --- a/libdocument/ev-document-misc.c +++ b/libdocument/ev-document-misc.c @@ -425,3 +425,48 @@ ev_document_misc_format_date (GTime utime) return g_locale_to_utf8 (s, -1, NULL, NULL, NULL); } + +#if GTK_CHECK_VERSION(3, 0, 0) +void +ev_document_misc_get_pointer_position (GtkWidget *widget, + gint *x, + gint *y) +{ +#if GTK_CHECK_VERSION (3, 20, 0) + GdkSeat *seat; +#else + GdkDeviceManager *device_manager; +#endif + GdkDevice *device_pointer; + GdkRectangle allocation; + + if (x) + *x = -1; + if (y) + *y = -1; + + if (!gtk_widget_get_realized (widget)) + return; + +#if GTK_CHECK_VERSION(3, 20, 0) + seat = gdk_display_get_default_seat (gtk_widget_get_display (widget)); + device_pointer = gdk_seat_get_pointer (seat); +#else + device_manager = gdk_display_get_device_manager (gtk_widget_get_display (widget)); + device_pointer = gdk_device_manager_get_client_pointer (device_manager); +#endif + gdk_window_get_device_position (gtk_widget_get_window (widget), + device_pointer, + x, y, NULL); + + if (gtk_widget_get_has_window (widget)) + return; + + gtk_widget_get_allocation (widget, &allocation); + if (x) + *x -= allocation.x; + if (y) + *y -= allocation.y; +} +#endif + |