Skip to content

Commit

Permalink
Fix handling of pixmaps for GTK3
Browse files Browse the repository at this point in the history
  • Loading branch information
zturtleman committed Nov 13, 2024
1 parent a063e20 commit 48d97bd
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/country-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ struct pixmap* get_pixmap_for_country(int id) {
return NULL;
}

#ifdef GUI_GTK2
gdk_pixbuf_render_pixmap_and_mask(pix->pixbuf,&pix->pix,&pix->mask,255);
#endif

g_free (filename);

Expand All @@ -236,8 +238,10 @@ struct pixmap* get_pixmap_for_country_with_fallback(int id) {
flags[0].pixbuf = gdk_pixbuf_new_from_xpm_data( (const char **)noflag_xpm);
if (!flags[0].pixbuf)
flags[0].pixbuf = GINT_TO_POINTER(-1);
#ifdef GUI_GTK2
else
gdk_pixbuf_render_pixmap_and_mask(flags[0].pixbuf,&flags[0].pix,&flags[0].mask,255);
#endif
}
return &flags[0];
}
Expand Down
4 changes: 4 additions & 0 deletions src/loadpixmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,15 @@ struct pixmap* load_pixmap_as_pixmap (GtkWidget* widget, const gchar* filename,
debug(4, "loading gdk_pixbuf from file: %s", found_filename);
}

#ifdef GUI_GTK2
if (pix->pixbuf) {
gdk_pixbuf_render_pixmap_and_mask (pix->pixbuf, &pix->pix, &pix->mask, 255);
}

if (pix->pixbuf == NULL || pix->pix == NULL) {
#else
if (pix->pixbuf == NULL) {
#endif
// translator: %s = file name
xqf_warning (_("Error loading pixmap file: %s"), found_filename?found_filename:filename);
g_free (found_filename);
Expand Down
22 changes: 22 additions & 0 deletions src/pixmaps.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ void free_pixmap (struct pixmap *pixmap) {
g_object_unref (G_OBJECT (pixmap->pixbuf));
pixmap->pixbuf = NULL;
}
#ifdef GUI_GTK2
if (pixmap->pix) {
gdk_pixmap_unref (pixmap->pix);
pixmap->pix = NULL;
Expand All @@ -129,6 +130,7 @@ void free_pixmap (struct pixmap *pixmap) {
gdk_bitmap_unref (pixmap->mask);
pixmap->mask = NULL;
}
#endif
}


Expand All @@ -137,11 +139,15 @@ static void create_pixmap (GtkWidget *widget, const char* file, struct pixmap *p

if (!pix->pixbuf) {
pix->pixbuf = error_pix.pixbuf;
#ifdef GUI_GTK2
pix->pix = error_pix.pix;
pix->mask = error_pix.mask;
#endif
g_object_ref (G_OBJECT (pix->pixbuf));
#ifdef GUI_GTK2
gdk_pixmap_ref(pix->pix);
gdk_bitmap_ref(pix->mask);
#endif
}
}

Expand Down Expand Up @@ -218,7 +224,9 @@ struct pixmap* cat_pixmaps (GtkWidget *window, struct pixmap *dest, struct pixma
gdk_pixbuf_copy_area (s1->pixbuf, 0, 0, w1, h1, dest->pixbuf, 0, 0);
gdk_pixbuf_copy_area (s2->pixbuf, 0, 0, w2, h2, dest->pixbuf, w1, 0);

#ifdef GUI_GTK2
gdk_pixbuf_render_pixmap_and_mask (dest->pixbuf, &dest->pix, &dest->mask, 255);
#endif

return dest;
}
Expand Down Expand Up @@ -316,7 +324,9 @@ void ensure_buddy_pix (GtkWidget *window, int n) {
gdk_pixbuf_composite (buddy_pix[4].pixbuf, dest->pixbuf, 0, 0, width, height, 0, 0, 1.0, 1.0, GDK_INTERP_NEAREST, 255);
}

#ifdef GUI_GTK2
gdk_pixbuf_render_pixmap_and_mask (dest->pixbuf, &dest->pix, &dest->mask, 255);
#endif
}


Expand Down Expand Up @@ -346,7 +356,9 @@ void two_colors_pixmap (GdkWindow *window, int width, int height, GdkColor *top,

g_object_unref (G_OBJECT (half_pixbuf));

#ifdef GUI_GTK2
gdk_pixbuf_render_pixmap_and_mask (dest->pixbuf, &dest->pix, &dest->mask, 255);
#endif
}


Expand All @@ -360,8 +372,10 @@ void create_server_pixmap (GtkWidget *window, struct pixmap *stype, int n, struc
gboolean pixmap_cache_lookup (GSList *cache, struct pixmap *pix, unsigned key) {
struct cached_pixmap *cp;
GdkPixbuf *res_pixbuf = NULL;
#ifdef GUI_GTK2
GdkPixmap *res_pix = NULL;
GdkBitmap *res_mask = NULL;
#endif

if (!pix)
return FALSE;
Expand All @@ -371,8 +385,10 @@ gboolean pixmap_cache_lookup (GSList *cache, struct pixmap *pix, unsigned key) {
if (cp->key == key) {
cp->weight += 2;
res_pixbuf = cp->pixbuf;
#ifdef GUI_GTK2
res_pix = cp->pix;
res_mask = cp->mask;
#endif
break;
}
cache = cache->next;
Expand All @@ -382,13 +398,15 @@ gboolean pixmap_cache_lookup (GSList *cache, struct pixmap *pix, unsigned key) {
if (res_pixbuf)
g_object_ref (G_OBJECT (res_pixbuf));

#ifdef GUI_GTK2
pix->pix = res_pix;
if (res_pix)
gdk_pixmap_ref (res_pix);

pix->mask = res_mask;
if (res_mask)
gdk_bitmap_ref (res_mask);
#endif

return (pix->pixbuf != NULL);
}
Expand All @@ -403,12 +421,14 @@ void pixmap_cache_add (GSList **cache, struct pixmap *pix, unsigned key) {
cp->pixbuf = pix->pixbuf;
g_object_ref (G_OBJECT (cp->pixbuf));

#ifdef GUI_GTK2
cp->pix = pix->pix;
gdk_pixmap_ref (cp->pix);

cp->mask = pix->mask;
if (cp->mask)
gdk_bitmap_ref (cp->mask);
#endif

cp->key = key;
cp->weight = 10;
Expand All @@ -427,10 +447,12 @@ static int cached_pixmap_cmp (const struct cached_pixmap *a,
static void free_cached_pixmap (struct cached_pixmap *cp) {

g_object_unref (G_OBJECT (cp->pixbuf));
#ifdef GUI_GTK2
gdk_pixmap_unref (cp->pix);

if (cp->mask)
gdk_bitmap_unref (cp->mask);
#endif

g_free (cp);
}
Expand Down
7 changes: 7 additions & 0 deletions src/pixmaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,25 @@

#include <gtk/gtk.h>

#ifdef GUI_GTK3
#include <gdk-pixbuf/gdk-pixbuf.h>
#endif

struct pixmap {
GdkPixbuf *pixbuf;
#ifdef GUI_GTK2
GdkPixmap *pix;
GdkBitmap *mask;
#endif
};

struct cached_pixmap {
unsigned key;
GdkPixbuf *pixbuf;
#ifdef GUI_GTK2
GdkPixmap *pix;
GdkBitmap *mask;
#endif
int weight;
};

Expand Down
6 changes: 6 additions & 0 deletions src/skin.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,22 +402,28 @@ static gushort convert_color (unsigned c) {


void allocate_quake_player_colors (GdkWindow *window) {
#ifdef GUI_GTK2
GdkColormap *colormap;
#endif
int i, j;

if (!pcolors_allocated) {
#ifdef GUI_GTK2
colormap = gdk_drawable_get_colormap (GDK_DRAWABLE (window));
#endif

for (i = 0; i < 14; i++) {
j = (i<8)? 11 : 15 - 11;
pcolors[i].pixel = 0;
pcolors[i].red = convert_color (quake_pallete [(i*16 + j)*3 + 0]);
pcolors[i].green = convert_color (quake_pallete [(i*16 + j)*3 + 1]);
pcolors[i].blue = convert_color (quake_pallete [(i*16 + j)*3 + 2]);
#ifdef GUI_GTK2
if (!gdk_colormap_alloc_color (colormap, &pcolors[i], FALSE, TRUE)) {
g_warning ("unable to allocate color: ( %d %d %d )",
pcolors[i].red, pcolors[i].green, pcolors[i].blue);
}
#endif
}
pcolors_allocated = TRUE;
}
Expand Down
2 changes: 2 additions & 0 deletions src/srv-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ static void get_server_pixmap (GtkWidget *window, struct server *s, GSList **cac

if (!s || !window || !buddy_pix[1].pixbuf) {
pix->pixbuf = NULL;
#ifdef GUI_GTK2
pix->pix = NULL;
pix->mask = NULL;
#endif
return;
}

Expand Down

0 comments on commit 48d97bd

Please sign in to comment.