[evince] libdocument: Add ev_document_misc_get_pointer_position()



commit 5da7fad37c878a9581b314c21258f5aa140a51cd
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Sun Dec 4 12:45:02 2011 +0100

    libdocument: Add ev_document_misc_get_pointer_position()
    
    Helper function to get the pointer position to replace
    gtk_widget_get_pointer() that is now deprecated.

 libdocument/ev-document-misc.c |   33 +++++++++++++++++++++++++++++++++
 libdocument/ev-document-misc.h |    4 ++++
 2 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/libdocument/ev-document-misc.c b/libdocument/ev-document-misc.c
index 01676b5..f165a11 100644
--- a/libdocument/ev-document-misc.c
+++ b/libdocument/ev-document-misc.c
@@ -356,3 +356,36 @@ ev_document_misc_format_date (GTime utime)
 
 	return g_locale_to_utf8 (s, -1, NULL, NULL, NULL);
 }
+
+void
+ev_document_misc_get_pointer_position (GtkWidget *widget,
+                                       gint      *x,
+                                       gint      *y)
+{
+        GdkDeviceManager *device_manager;
+        GdkDevice        *device_pointer;
+        GdkRectangle      allocation;
+
+        if (x)
+                *x = -1;
+        if (y)
+                *y = -1;
+
+        if (!gtk_widget_get_realized (widget))
+                return;
+
+        device_manager = gdk_display_get_device_manager (gtk_widget_get_display (widget));
+        device_pointer = gdk_device_manager_get_client_pointer (device_manager);
+        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;
+}
diff --git a/libdocument/ev-document-misc.h b/libdocument/ev-document-misc.h
index dfce2e2..4c550e7 100644
--- a/libdocument/ev-document-misc.h
+++ b/libdocument/ev-document-misc.h
@@ -62,6 +62,10 @@ gdouble          ev_document_misc_get_screen_dpi (GdkScreen *screen);
 
 gchar           *ev_document_misc_format_date (GTime utime);
 
+void             ev_document_misc_get_pointer_position (GtkWidget *widget,
+							gint      *x,
+							gint      *y);
+
 G_END_DECLS
 
 #endif /* EV_DOCUMENT_MISC_H */



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