summaryrefslogtreecommitdiff
path: root/capplets/common/theme-thumbnail.c
diff options
context:
space:
mode:
authormonsta <[email protected]>2016-12-02 00:45:36 +0300
committermonsta <[email protected]>2016-12-02 00:50:14 +0300
commit0c27d18ab5efb721a2f02549767016c81fc6ce2c (patch)
tree76b7b89cface072e011a3757a833e9090bab44f2 /capplets/common/theme-thumbnail.c
parent1aa83d45ebf9599c6d4d3f47211c3961282e98f0 (diff)
downloadmate-control-center-0c27d18ab5efb721a2f02549767016c81fc6ce2c.tar.bz2
mate-control-center-0c27d18ab5efb721a2f02549767016c81fc6ce2c.tar.xz
move to GTK+3 (>= 3.14), drop GTK+2 code and --with-gtk build option
and require libmatekbd, libmate-desktop, marco, m-s-d >= 1.17
Diffstat (limited to 'capplets/common/theme-thumbnail.c')
-rw-r--r--capplets/common/theme-thumbnail.c149
1 files changed, 5 insertions, 144 deletions
diff --git a/capplets/common/theme-thumbnail.c b/capplets/common/theme-thumbnail.c
index 775b460c..2b11d01f 100644
--- a/capplets/common/theme-thumbnail.c
+++ b/capplets/common/theme-thumbnail.c
@@ -19,14 +19,6 @@
#include "gtkrc-utils.h"
#include "capplet-util.h"
-#if !GTK_CHECK_VERSION (3, 0, 0)
-#define gtk_widget_get_preferred_size(x,y,z) gtk_widget_size_request(x,y)
-#endif
-
-#if GTK_CHECK_VERSION (3, 0, 0)
-#define GdkRegion cairo_region_t
-#define gdk_region_destroy cairo_region_destroy
-#endif
typedef struct {
gboolean set;
@@ -97,48 +89,8 @@ static int pipe_from_factory_fd[2];
#define MARCO_THUMBNAIL_WIDTH 120
#define MARCO_THUMBNAIL_HEIGHT 60
-/* This draw the thumbnail of gtk
- */
-#if !GTK_CHECK_VERSION (3, 0, 0)
-static GdkPixmap *
-draw_window_on_pixbuf(GtkWidget* widget)
-{
- GdkVisual* visual;
- GdkPixmap* pixmap;
- GtkStyle* style;
- GdkScreen* screen = gdk_screen_get_default();
- GdkWindow* window;
- gint width, height;
-
- gtk_widget_ensure_style(widget);
-
- style = gtk_widget_get_style(widget);
-
- g_assert(style);
- g_assert(style->font_desc);
-
- gtk_window_get_size(GTK_WINDOW(widget), &width, &height);
-
- 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));
-
- window = gtk_widget_get_window(widget);
- gdk_window_redirect_to_drawable(window, pixmap, 0, 0, 0, 0, width, height);
- 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);
-
- gtk_widget_hide(widget);
-
- return pixmap;
-}
-#endif
-
-static void pixbuf_apply_mask_region(GdkPixbuf* pixbuf, GdkRegion* region)
+static void pixbuf_apply_mask_region(GdkPixbuf* pixbuf, cairo_region_t* region)
{
gint nchannels, rowstride, w, h;
guchar *pixels, *p;
@@ -158,11 +110,7 @@ static void pixbuf_apply_mask_region(GdkPixbuf* pixbuf, GdkRegion* region)
for (w = 0; w < gdk_pixbuf_get_width (pixbuf); ++w)
for (h = 0; h < gdk_pixbuf_get_height (pixbuf); ++h)
{
-#if GTK_CHECK_VERSION (3, 0, 0)
if (!cairo_region_contains_point (region, w, h))
-#else
- if (!gdk_region_point_in (region, w, h))
-#endif
{
p = pixels + h * rowstride + w * nchannels;
if (G_BYTE_ORDER == G_BIG_ENDIAN)
@@ -201,11 +149,7 @@ create_folder_icon (char *icon_theme_name)
if (folder_icon_info != NULL)
{
folder_icon = gtk_icon_info_load_icon (folder_icon_info, NULL);
-#if GTK_CHECK_VERSION (3, 8, 0)
g_object_unref (folder_icon_info);
-#else
- gtk_icon_info_free (folder_icon_info);
-#endif
}
if (folder_icon == NULL)
@@ -236,14 +180,11 @@ create_meta_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
GtkRequisition requisition;
GtkAllocation allocation;
GtkAllocation vbox_allocation;
-#if !GTK_CHECK_VERSION (3, 0, 0)
- GdkPixmap *pixmap;
-#endif
MetaFrameFlags flags;
MetaTheme *theme;
GdkPixbuf *pixbuf, *icon;
int icon_width, icon_height;
- GdkRegion *region;
+ cairo_region_t *region;
g_object_set (gtk_settings_get_default (),
"gtk-theme-name", (char *) theme_thumbnail_data->control_theme_name->data,
@@ -272,36 +213,19 @@ 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
- vbox = gtk_vbox_new (FALSE, 6);
-#endif
gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
gtk_container_add (GTK_CONTAINER (preview), vbox);
align = gtk_alignment_new (0, 0, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 0);
stock_button = gtk_button_new_from_stock (GTK_STOCK_OPEN);
gtk_container_add (GTK_CONTAINER (align), stock_button);
-#if GTK_CHECK_VERSION (3, 0, 0)
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-#else
- box = gtk_hbox_new (FALSE, 0);
-#endif
gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, FALSE, 0);
checkbox = gtk_check_button_new ();
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), TRUE);
@@ -325,18 +249,11 @@ create_meta_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
gtk_widget_size_allocate (window, &allocation);
gtk_widget_get_preferred_size (window, &requisition, NULL);
-#if GTK_CHECK_VERSION (3, 0, 0)
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);
-
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, META_THUMBNAIL_SIZE, META_THUMBNAIL_SIZE);
- gdk_pixbuf_get_from_drawable (pixbuf, pixmap, NULL, 0, 0, 0, 0, META_THUMBNAIL_SIZE, META_THUMBNAIL_SIZE);
-#endif
gtk_widget_get_allocation (vbox, &vbox_allocation);
@@ -351,14 +268,11 @@ create_meta_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
region = meta_preview_get_clip_region (META_PREVIEW (preview),
META_THUMBNAIL_SIZE, META_THUMBNAIL_SIZE);
pixbuf_apply_mask_region (pixbuf, region);
- gdk_region_destroy (region);
+ cairo_region_destroy (region);
g_object_unref (icon);
gtk_widget_destroy (window);
meta_theme_free (theme);
-#if !GTK_CHECK_VERSION (3, 0, 0)
- g_object_unref (pixmap);
-#endif
return pixbuf;
}
@@ -370,9 +284,6 @@ create_gtk_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
GtkWidget *window, *vbox, *box, *stock_button, *checkbox, *radio;
GtkRequisition requisition;
GtkAllocation allocation;
-#if !GTK_CHECK_VERSION (3, 0, 0)
- GdkPixmap *pixmap;
-#endif
GdkPixbuf *pixbuf, *retval;
gint width, height;
@@ -381,23 +292,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);
-#else
- vbox = gtk_vbox_new (FALSE, 0);
-#endif
gtk_container_add (GTK_CONTAINER (window), vbox);
-#if GTK_CHECK_VERSION (3, 0, 0)
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-#else
- box = gtk_hbox_new (FALSE, 6);
-#endif
gtk_container_set_border_width (GTK_CONTAINER (box), 6);
gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, FALSE, 0);
stock_button = gtk_button_new_from_stock (GTK_STOCK_OPEN);
@@ -408,9 +307,7 @@ 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)));
@@ -420,7 +317,6 @@ 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;
@@ -432,18 +328,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)
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);
-
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
- gdk_pixbuf_get_from_drawable (pixbuf, pixmap, NULL, 0, 0, 0, 0, width, height);
-#endif
retval = gdk_pixbuf_scale_simple (pixbuf,
GTK_THUMBNAIL_SIZE,
@@ -451,9 +340,6 @@ create_gtk_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
GDK_INTERP_BILINEAR);
g_object_unref (pixbuf);
gtk_widget_destroy (window);
-#if !GTK_CHECK_VERSION (3, 0, 0)
- g_object_unref (pixmap);
-#endif
return retval;
}
@@ -466,11 +352,8 @@ create_marco_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
MetaTheme *theme;
GtkRequisition requisition;
GtkAllocation allocation;
-#if !GTK_CHECK_VERSION (3, 0, 0)
- GdkPixmap *pixmap;
-#endif
GdkPixbuf *pixbuf, *retval;
- GdkRegion *region;
+ cairo_region_t *region;
theme = meta_theme_load ((char *) theme_thumbnail_data->wm_theme_name->data, NULL);
if (theme == NULL)
@@ -486,11 +369,7 @@ 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 ();
@@ -502,15 +381,7 @@ 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;
@@ -520,23 +391,16 @@ create_marco_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
gtk_widget_size_allocate (window, &allocation);
gtk_widget_get_preferred_size (window, &requisition, NULL);
-#if GTK_CHECK_VERSION (3, 0, 0)
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);
-
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, (int) MARCO_THUMBNAIL_WIDTH * 1.2, (int) MARCO_THUMBNAIL_HEIGHT * 1.2);
- gdk_pixbuf_get_from_drawable (pixbuf, pixmap, NULL, 0, 0, 0, 0, (int) MARCO_THUMBNAIL_WIDTH * 1.2, (int) MARCO_THUMBNAIL_HEIGHT * 1.2);
-#endif
region = meta_preview_get_clip_region (META_PREVIEW (preview),
MARCO_THUMBNAIL_WIDTH * 1.2, MARCO_THUMBNAIL_HEIGHT * 1.2);
pixbuf_apply_mask_region (pixbuf, region);
- gdk_region_destroy (region);
+ cairo_region_destroy (region);
retval = gdk_pixbuf_scale_simple (pixbuf,
@@ -547,9 +411,6 @@ create_marco_theme_pixbuf (ThemeThumbnailData *theme_thumbnail_data)
gtk_widget_destroy (window);
meta_theme_free (theme);
-#if !GTK_CHECK_VERSION (3, 0, 0)
- g_object_unref (pixmap);
-#endif
return retval;
}