summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Gorodnichev <[email protected]>2015-09-22 13:08:35 +0300
committermonsta <[email protected]>2016-01-28 16:32:26 +0300
commit0fe0004f21832032602920d9c6f1074c1c3d9089 (patch)
treea508d1224194af9b6d2b6ac8fd122d0794baf416
parenta216984f5db59375d906fbf1b4f9ca7b4b0b3cc3 (diff)
downloadmate-control-center-0fe0004f21832032602920d9c6f1074c1c3d9089.tar.bz2
mate-control-center-0fe0004f21832032602920d9c6f1074c1c3d9089.tar.xz
use offscreen windows for previews
gtk 2.20+ provides offscreen window. use them for previews note by @monsta: commit is patched to leave the current GTK+2 code as is because offscreen windows don't work properly there for some reason...
-rw-r--r--capplets/common/theme-thumbnail.c71
1 files changed, 46 insertions, 25 deletions
diff --git a/capplets/common/theme-thumbnail.c b/capplets/common/theme-thumbnail.c
index 4376ef0f..f66a05ec 100644
--- a/capplets/common/theme-thumbnail.c
+++ b/capplets/common/theme-thumbnail.c
@@ -94,16 +94,12 @@ static int pipe_from_factory_fd[2];
/* This draw the thumbnail of gtk
*/
-#if GTK_CHECK_VERSION (3, 0, 0)
-static void draw_window_on_pixbuf(GtkWidget* widget, GdkPixbuf* pixbuf)
-#else
-static GdkPixmap* draw_window_on_pixbuf(GtkWidget* widget)
-#endif
-{
#if !GTK_CHECK_VERSION (3, 0, 0)
+static GdkPixmap *
+draw_window_on_pixbuf(GtkWidget* widget)
+{
GdkVisual* visual;
GdkPixmap* pixmap;
-#endif
GtkStyle* style;
GdkScreen* screen = gdk_screen_get_default();
GdkWindow* window;
@@ -118,41 +114,32 @@ static GdkPixmap* draw_window_on_pixbuf(GtkWidget* widget)
gtk_window_get_size(GTK_WINDOW(widget), &width, &height);
-#if !GTK_CHECK_VERSION (3, 0, 0)
visual = gtk_widget_get_visual(widget);
pixmap = gdk_pixmap_new(NULL, width, height, gdk_visual_get_depth (visual));
gdk_drawable_set_colormap(GDK_DRAWABLE(pixmap), gtk_widget_get_colormap(widget));
-#endif
window = gtk_widget_get_window(widget);
/* This is a hack for the default resize grip on Ubuntu.
* We need to add a --enable-ubuntu for this.
- * Resize grip is also default with GTK3.
+ * Resize grip is also default with GTK3.
*/
-#if defined(UBUNTU) || GTK_CHECK_VERSION (3, 0, 0)
+#if defined(UBUNTU)
gtk_window_set_has_resize_grip(GTK_WINDOW(widget), FALSE);
#endif
-#if !GTK_CHECK_VERSION (3, 0, 0)
gdk_window_redirect_to_drawable(window, pixmap, 0, 0, 0, 0, width, height);
-#endif
gdk_window_set_override_redirect(window, TRUE);
gtk_window_move(GTK_WINDOW(widget), gdk_screen_get_width(screen), gdk_screen_get_height(screen));
gtk_widget_show(widget);
gdk_window_process_updates(window, TRUE);
-#if GTK_CHECK_VERSION (3, 0, 0)
- pixbuf = gdk_pixbuf_get_from_window (window, 0, 0, width, height);
-#endif
-
gtk_widget_hide(widget);
-#if !GTK_CHECK_VERSION (3, 0, 0)
return pixmap;
-#endif
}
+#endif
static void pixbuf_apply_mask_region(GdkPixbuf* pixbuf, GdkRegion* region)
{
@@ -288,11 +275,20 @@ create_meta_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
META_FRAME_ALLOWS_SHADE |
META_FRAME_ALLOWS_MOVE;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ window = gtk_offscreen_window_new ();
+#else
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+#endif
preview = meta_preview_new ();
gtk_container_add (GTK_CONTAINER (window), preview);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_widget_show_all (window);
+#else
gtk_widget_realize (window);
gtk_widget_realize (preview);
+#endif
+
#if GTK_CHECK_VERSION (3, 0, 0)
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
#else
@@ -333,8 +329,11 @@ create_meta_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
gtk_widget_get_preferred_size (window, &requisition, NULL);
#if GTK_CHECK_VERSION (3, 0, 0)
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, META_THUMBNAIL_SIZE, META_THUMBNAIL_SIZE);
- draw_window_on_pixbuf (window, pixbuf);
+ gtk_widget_queue_draw (window);
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
+ pixbuf = gtk_offscreen_window_get_pixbuf (GTK_OFFSCREEN_WINDOW (window));
#else
pixmap = draw_window_on_pixbuf (window);
@@ -385,7 +384,11 @@ create_gtk_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
"gtk-color-scheme", (char *) theme_thumbnail_data->gtk_color_scheme->data,
NULL);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ window = gtk_offscreen_window_new ();
+#else
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+#endif
#if GTK_CHECK_VERSION (3, 0, 0)
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
@@ -408,6 +411,9 @@ create_gtk_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
radio = gtk_radio_button_new_from_widget (NULL);
gtk_box_pack_start (GTK_BOX (box), radio, FALSE, FALSE, 0);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_widget_show_all (window);
+#else
gtk_widget_show_all (vbox);
gtk_widget_realize (stock_button);
gtk_widget_realize (gtk_bin_get_child (GTK_BIN (stock_button)));
@@ -417,6 +423,7 @@ create_gtk_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
gtk_widget_map (gtk_bin_get_child (GTK_BIN (stock_button)));
gtk_widget_map (checkbox);
gtk_widget_map (radio);
+#endif
gtk_widget_get_preferred_size (window, &requisition, NULL);
allocation.x = 0;
@@ -429,8 +436,11 @@ create_gtk_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
gtk_window_get_size (GTK_WINDOW (window), &width, &height);
#if GTK_CHECK_VERSION (3, 0, 0)
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
- draw_window_on_pixbuf (window, pixbuf);
+ gtk_widget_queue_draw (window);
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
+ pixbuf = gtk_offscreen_window_get_pixbuf (GTK_OFFSCREEN_WINDOW (window));
#else
pixmap = draw_window_on_pixbuf (window);
@@ -479,7 +489,11 @@ create_marco_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
META_FRAME_ALLOWS_SHADE |
META_FRAME_ALLOWS_MOVE;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ window = gtk_offscreen_window_new ();
+#else
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+#endif
gtk_window_set_default_size (GTK_WINDOW (window), (int) MARCO_THUMBNAIL_WIDTH * 1.2, (int) MARCO_THUMBNAIL_HEIGHT * 1.2);
preview = meta_preview_new ();
@@ -491,11 +505,15 @@ create_marco_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
dummy = gtk_label_new ("");
gtk_container_add (GTK_CONTAINER (preview), dummy);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_widget_show_all (window);
+#else
gtk_widget_realize (window);
gtk_widget_realize (preview);
gtk_widget_realize (dummy);
gtk_widget_show_all (preview);
gtk_widget_map (dummy);
+#endif
gtk_widget_get_preferred_size (window, &requisition, NULL);
allocation.x = 0;
@@ -506,8 +524,11 @@ create_marco_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
gtk_widget_get_preferred_size (window, &requisition, NULL);
#if GTK_CHECK_VERSION (3, 0, 0)
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, (int) MARCO_THUMBNAIL_WIDTH * 1.2, (int) MARCO_THUMBNAIL_HEIGHT * 1.2);
- draw_window_on_pixbuf (window, pixbuf);
+ gtk_widget_queue_draw (window);
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
+ pixbuf = gtk_offscreen_window_get_pixbuf (GTK_OFFSCREEN_WINDOW (window));
#else
pixmap = draw_window_on_pixbuf (window);