diff options
-rw-r--r-- | mate-screenshot/src/screenshot-dialog.c | 35 | ||||
-rw-r--r-- | mate-screenshot/src/screenshot-utils.c | 50 |
2 files changed, 70 insertions, 15 deletions
diff --git a/mate-screenshot/src/screenshot-dialog.c b/mate-screenshot/src/screenshot-dialog.c index 5f5fd098..6e71ebf8 100644 --- a/mate-screenshot/src/screenshot-dialog.c +++ b/mate-screenshot/src/screenshot-dialog.c @@ -64,20 +64,32 @@ on_toplevel_key_press_event (GtkWidget *widget, return FALSE; } -static void #if GTK_CHECK_VERSION (3, 0, 0) -on_preview_draw (GtkWidget *drawing_area, cairo_t *cr, gpointer data) +static void +on_preview_draw (GtkWidget *drawing_area, + cairo_t *cr, + gpointer data) +{ + ScreenshotDialog *dialog = data; + GtkStyleContext *context; + + context = gtk_widget_get_style_context (drawing_area); + gtk_style_context_save (context); + + gtk_style_context_set_state (context, gtk_widget_get_state_flags (drawing_area)); + gtk_render_icon (context, cr, dialog->preview_image, 0, 0); + + gtk_style_context_restore (context); +} + #else +static void on_preview_expose_event (GtkWidget *drawing_area, GdkEventExpose *event, gpointer data) -#endif { ScreenshotDialog *dialog = data; GdkPixbuf *pixbuf = NULL; gboolean free_pixbuf = FALSE; -#if !GTK_CHECK_VERSION (3, 0, 0) cairo_t *cr; -#endif - /* Stolen from GtkImage. I really should just make the drawing area an * image some day */ if (gtk_widget_get_state (drawing_area) != GTK_STATE_NORMAL) @@ -101,24 +113,19 @@ on_preview_expose_event (GtkWidget *drawing_area, GdkEventExpose *event, gpointe } else { - pixbuf = g_object_ref (dialog->preview_image); + pixbuf = g_object_ref (dialog->preview_image); } - -#if !GTK_CHECK_VERSION (3, 0, 0) + cr = gdk_cairo_create (gtk_widget_get_window (drawing_area)); gdk_cairo_region (cr, event->region); cairo_clip (cr); -#endif - gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); cairo_paint (cr); - -#if !GTK_CHECK_VERSION (3, 0, 0) cairo_destroy (cr); -#endif g_object_unref (pixbuf); } +#endif static gboolean on_preview_button_press_event (GtkWidget *drawing_area, diff --git a/mate-screenshot/src/screenshot-utils.c b/mate-screenshot/src/screenshot-utils.c index 9d5d8af7..0efd43b8 100644 --- a/mate-screenshot/src/screenshot-utils.c +++ b/mate-screenshot/src/screenshot-utils.c @@ -500,6 +500,11 @@ void screenshot_select_area_async (SelectAreaCallback callback) { GdkCursor *cursor; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkDeviceManager *manager; + GdkDevice *pointer, *keyboard; + GdkGrabStatus res; +#endif select_area_filter_data data; GdkRectangle *rectangle; CallbackData *cb_data; @@ -521,6 +526,39 @@ screenshot_select_area_async (SelectAreaCallback callback) cursor = gdk_cursor_new (GDK_CROSSHAIR); +#if GTK_CHECK_VERSION (3, 0, 0) + 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; + } + + 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_device_ungrab (pointer, GDK_CURRENT_TIME); + g_object_unref (cursor); + goto out; + } + +#else + 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, @@ -537,14 +575,24 @@ screenshot_select_area_async (SelectAreaCallback callback) goto out; } +#endif + gtk_main (); +#if GTK_CHECK_VERSION (3, 0, 0) + + gdk_device_ungrab (keyboard, GDK_CURRENT_TIME); + gdk_device_ungrab (pointer, GDK_CURRENT_TIME); + +#else + gdk_keyboard_ungrab (GDK_CURRENT_TIME); gdk_pointer_ungrab (GDK_CURRENT_TIME); +#endif + gtk_widget_destroy (data.window); gdk_cursor_unref (cursor); - gdk_flush (); out: |