Commit 29e5f8c8 authored by Cosimo Cecchi's avatar Cosimo Cecchi

screenshot: don't use deprecated GDK api

Use GdkDevice and GdkDeviceManager instead of the deprecated pointer GDK
API.
parent def86f59
......@@ -218,9 +218,12 @@ emit_select_callback_in_idle (gpointer user_data)
void
screenshot_select_area_async (SelectAreaCallback callback)
{
GdkCursor *cursor;
GdkCursor *cursor;
select_area_filter_data data;
CallbackData *cb_data;
GdkDeviceManager *manager;
GdkDevice *pointer, *keyboard;
GdkGrabStatus res;
data.rect.x = 0;
data.rect.y = 0;
......@@ -238,27 +241,39 @@ screenshot_select_area_async (SelectAreaCallback callback)
g_signal_connect (data.window, "motion-notify-event", G_CALLBACK (select_area_motion_notify), &data);
cursor = gdk_cursor_new (GDK_CROSSHAIR);
if (gdk_pointer_grab (gtk_widget_get_window (data.window), FALSE,
GDK_POINTER_MOTION_MASK|GDK_BUTTON_PRESS_MASK|GDK_BUTTON_RELEASE_MASK,
NULL, cursor,
GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS)
manager = gdk_display_get_device_manager (gdk_display_get_default ());
pointer = gdk_device_manager_get_client_pointer (manager);
keyboard = gdk_device_get_associated_device (pointer);
res = gdk_device_grab (pointer, gtk_widget_get_window (data.window),
GDK_OWNERSHIP_NONE, FALSE,
GDK_POINTER_MOTION_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK,
cursor, GDK_CURRENT_TIME);
if (res != GDK_GRAB_SUCCESS)
{
g_object_unref (cursor);
goto out;
}
if (gdk_keyboard_grab (gtk_widget_get_window (data.window), FALSE, GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS)
res = gdk_device_grab (keyboard, gtk_widget_get_window (data.window),
GDK_OWNERSHIP_NONE, FALSE,
GDK_KEY_PRESS_MASK |
GDK_KEY_RELEASE_MASK,
NULL, GDK_CURRENT_TIME);
if (res != GDK_GRAB_SUCCESS)
{
gdk_pointer_ungrab (GDK_CURRENT_TIME);
gdk_cursor_unref (cursor);
gdk_device_ungrab (pointer, GDK_CURRENT_TIME);
g_object_unref (cursor);
goto out;
}
gtk_main ();
gdk_keyboard_ungrab (GDK_CURRENT_TIME);
gdk_pointer_ungrab (GDK_CURRENT_TIME);
gdk_device_ungrab (pointer, GDK_CURRENT_TIME);
gdk_device_ungrab (keyboard, GDK_CURRENT_TIME);
gtk_widget_destroy (data.window);
g_object_unref (cursor);
......
......@@ -119,14 +119,18 @@ GdkWindow *
screenshot_find_current_window ()
{
GdkWindow *current_window;
GdkDeviceManager *manager;
GdkDevice *device;
current_window = screenshot_find_active_window ();
manager = gdk_display_get_device_manager (gdk_display_get_default ());
device = gdk_device_manager_get_client_pointer (manager);
/* If there's no active window, we fall back to returning the
* window that the cursor is in.
*/
if (!current_window)
current_window = gdk_window_at_pointer (NULL, NULL);
current_window = gdk_device_get_window_at_position (device, NULL, NULL);
if (current_window)
{
......@@ -507,13 +511,20 @@ screenshot_get_pixbuf_fallback (GdkWindow *window,
if (cursor_pixbuf != NULL)
{
GdkDeviceManager *manager;
GdkDevice *device;
GdkRectangle rect;
gint cx, cy, xhot, yhot;
manager = gdk_display_get_device_manager (gdk_display_get_default ());
device = gdk_device_manager_get_client_pointer (manager);
if (wm_window != NULL)
gdk_window_get_pointer (wm_window, &cx, &cy, NULL);
gdk_window_get_device_position (wm_window, device,
&cx, &cy, NULL);
else
gdk_window_get_pointer (window, &cx, &cy, NULL);
gdk_window_get_device_position (window, device,
&cx, &cy, NULL);
sscanf (gdk_pixbuf_get_option (cursor_pixbuf, "x_hot"), "%d", &xhot);
sscanf (gdk_pixbuf_get_option (cursor_pixbuf, "y_hot"), "%d", &yhot);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment