diff options
author | raveit65 <[email protected]> | 2016-08-07 13:03:17 +0200 |
---|---|---|
committer | raveit65 <[email protected]> | 2016-09-01 08:21:55 +0200 |
commit | 5b0b7091d7f3338df67064ea057a9ce49e47608a (patch) | |
tree | bb90a63dba3f14b89fd17c74b5e8b6d2b143b32c | |
parent | bc2bda8c7e60627677c701aa20ef5998e32ce42c (diff) | |
download | mate-utils-5b0b7091d7f3338df67064ea057a9ce49e47608a.tar.bz2 mate-utils-5b0b7091d7f3338df67064ea057a9ce49e47608a.tar.xz |
GTK+-3 screenshot-dialog: Avoid resizing the preview too much
Relying on configure events to resize the preview makes us do more
work than necessary and, in particular, gtk+ sometimes sends us phony
configure events sized 1x1 which make us hit a pretty CPU intensive
resize operation in gdk-pixbuf.
Instead, we can avoid all that by creating the preview pixbuf lazily
on the draw handler using the actual allocated widget size.
https://bugzilla.gnome.org/show_bug.cgi?id=768087
taken from:
https://git.gnome.org/browse/gnome-screenshot/commit/?id=c21823b
-rw-r--r-- | mate-screenshot/src/screenshot-dialog.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/mate-screenshot/src/screenshot-dialog.c b/mate-screenshot/src/screenshot-dialog.c index fd9f12e4..2886458a 100644 --- a/mate-screenshot/src/screenshot-dialog.c +++ b/mate-screenshot/src/screenshot-dialog.c @@ -72,6 +72,21 @@ on_preview_draw (GtkWidget *drawing_area, { ScreenshotDialog *dialog = data; GtkStyleContext *context; + int width, height; + + width = gtk_widget_get_allocated_width (drawing_area); + height = gtk_widget_get_allocated_height (drawing_area); + + if (!dialog->preview_image || + gdk_pixbuf_get_width (dialog->preview_image) != width || + gdk_pixbuf_get_height (dialog->preview_image) != height) + { + g_clear_object (&dialog->preview_image); + dialog->preview_image = gdk_pixbuf_scale_simple (dialog->screenshot, + width, + height, + GDK_INTERP_BILINEAR); + } context = gtk_widget_get_style_context (drawing_area); gtk_style_context_save (context); @@ -153,6 +168,7 @@ on_preview_button_release_event (GtkWidget *drawing_area, return FALSE; } +#if !GTK_CHECK_VERSION (3, 0, 0) static void on_preview_configure_event (GtkWidget *drawing_area, GdkEventConfigure *event, @@ -168,6 +184,7 @@ on_preview_configure_event (GtkWidget *drawing_area, event->height, GDK_INTERP_BILINEAR); } +#endif static void drag_data_get (GtkWidget *widget, @@ -299,7 +316,9 @@ screenshot_dialog_new (GdkPixbuf *screenshot, #endif g_signal_connect (preview_darea, "button_press_event", G_CALLBACK (on_preview_button_press_event), dialog); g_signal_connect (preview_darea, "button_release_event", G_CALLBACK (on_preview_button_release_event), dialog); +#if !GTK_CHECK_VERSION (3, 0, 0) g_signal_connect (preview_darea, "configure_event", G_CALLBACK (on_preview_configure_event), dialog); +#endif if (take_window_shot) gtk_frame_set_shadow_type (GTK_FRAME (aspect_frame), GTK_SHADOW_NONE); |