diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1d413c5..491a0b5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,16 @@ Formato livre, uma seção por versão; datas no fuso de Brasília. O pacote
`big-wm-tabbed-dock` usa `epoch=1` desde 0.2.0 (antes, vinha no big-wm com
versão por data).
+## 0.3.3 — 2026-11-27
+
+- Aplicativo aberto sem `.desktop` (zenity, um script, um jogo, um
+ programa do Wine) aparecia com o ícone genérico "exec", enquanto o
+ appicon do Window Maker ao lado mostrava o dele. Agora vem primeiro um
+ ícone do tema com o nome da janela (app ID, classe ou instância do
+ `WM_CLASS`, também em minúsculas, ou o programa) e, no X11, o ícone da
+ própria janela (`_NET_WM_ICON`). No Wayland vale o do tema (o protocolo
+ não traz os pixels). Teste `tests/test-icons.c`.
+
## 0.3.2 — 2026-11-20
- Aplicativo instalado com o dock já rodando: a janela aberta aparecia sem
diff --git a/README.md b/README.md
index b7c57d9..c138539 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@
-
+
diff --git a/meson.build b/meson.build
index 99ca850..267619b 100644
--- a/meson.build
+++ b/meson.build
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-or-later
project('big-wm-tabbed-dock', 'c',
- version: '0.3.2',
+ version: '0.3.3',
license: 'GPL-2.0-or-later',
meson_version: '>= 0.62',
default_options: ['c_std=gnu11', 'warning_level=2', 'buildtype=debugoptimized', 'b_ndebug=if-release'])
diff --git a/pkgbuild/PKGBUILD b/pkgbuild/PKGBUILD
index a70311b..9df9242 100644
--- a/pkgbuild/PKGBUILD
+++ b/pkgbuild/PKGBUILD
@@ -11,7 +11,7 @@
# TABBED_DOCK_SOURCE="git+file://$PWD/.." makepkg
pkgname=big-wm-tabbed-dock
epoch=1
-pkgver=0.3.2
+pkgver=0.3.3
pkgrel=1
pkgdesc="Big WindowMaker: dock horizontal com abas (X11 e Wayland), inspirado no OPENSTEP 4.0 beta, e seu controlador no Dock"
arch=('x86_64')
diff --git a/src/backend/btd-windows.c b/src/backend/btd-windows.c
index 0aefda6..c49af3a 100644
--- a/src/backend/btd-windows.c
+++ b/src/backend/btd-windows.c
@@ -18,6 +18,8 @@ window_free(BtdWindow *w)
g_free(w->launched_desktop_file);
g_free(w->exe);
g_free(w->desktop_id);
+ if (w->icon)
+ cairo_surface_destroy(w->icon);
g_free(w);
}
diff --git a/src/backend/btd-windows.h b/src/backend/btd-windows.h
index 9a07431..4ea9929 100644
--- a/src/backend/btd-windows.h
+++ b/src/backend/btd-windows.h
@@ -55,6 +55,11 @@ typedef struct {
gboolean has_geometry;
int monitor_hint; /* monitor of the window centre, -1 unknown */
char *desktop_id; /* resolved by the dock, cached */
+ /* X11: the window's own icon (_NET_WM_ICON, the size closest above
+ * 64 px), for an application with no .desktop; NULL when it has none
+ * (and always on Wayland). icon_serial is unique to each icon read. */
+ cairo_surface_t *icon;
+ guint icon_serial;
gboolean resolved;
struct _BtdWindowTracker *tracker;
} BtdWindow;
diff --git a/src/backend/btd-x11.c b/src/backend/btd-x11.c
index c774060..0b21cc1 100644
--- a/src/backend/btd-x11.c
+++ b/src/backend/btd-x11.c
@@ -34,6 +34,7 @@ enum {
A_NET_WM_STATE_FULLSCREEN,
A_NET_WM_STATE_MAXIMIZED_VERT,
A_NET_WM_STATE_MAXIMIZED_HORZ,
+ A_NET_WM_ICON,
A_COUNT
};
@@ -43,6 +44,7 @@ static const char *atom_names[A_COUNT] = {
"_NET_WM_WINDOW_TYPE_DIALOG", "_NET_WM_NAME", "UTF8_STRING", "WM_STATE", "_NET_WM_PID",
"_GTK_APPLICATION_ID", "_NET_CLOSE_WINDOW", "WM_CHANGE_STATE",
"_NET_WM_STATE_FULLSCREEN", "_NET_WM_STATE_MAXIMIZED_VERT", "_NET_WM_STATE_MAXIMIZED_HORZ",
+ "_NET_WM_ICON",
};
typedef struct {
@@ -239,6 +241,84 @@ update_geometry(X11Tracker *x, BtdWindow *bw)
return TRUE;
}
+/* The window's own icon (_NET_WM_ICON: width, height and ARGB pixels, one
+ * per CARDINAL, for each size it offers). Window Maker draws the appicon of
+ * an application with no .desktop from it; the dock does the same instead of
+ * the generic icon. Takes the smallest size of at least 64 px, else the
+ * largest. TRUE when it changed. */
+#define MAX_ICON_SIDE 512
+static gboolean
+update_icon(X11Tracker *x, BtdWindow *bw)
+{
+ Atom type;
+ int format;
+ unsigned long n = 0, after;
+ unsigned char *raw = NULL;
+ cairo_surface_t *icon = NULL;
+ gdk_x11_display_error_trap_push(x->gdk_display);
+ int status = XGetWindowProperty(x->dpy, (Window)bw->id, x->atoms[A_NET_WM_ICON], 0,
+ 2 + MAX_ICON_SIDE * MAX_ICON_SIDE * 4, False, XA_CARDINAL, &type, &format, &n,
+ &after, &raw);
+ if (!gdk_x11_display_error_trap_pop(x->gdk_display) && status == Success && raw && type == XA_CARDINAL &&
+ format == 32) {
+ /* format 32 arrives as an array of long (64-bit on x86_64) */
+ const unsigned long *d = (const unsigned long *)raw;
+ unsigned long best = n, best_w = 0, best_h = 0;
+ for (unsigned long i = 0; i + 2 <= n;) {
+ unsigned long w = d[i], h = d[i + 1];
+ /* an incomplete record ends the list (w, h <= n: no overflow) */
+ if (w == 0 || h == 0 || w > n || h > n || w * h > n - i - 2)
+ break;
+ if (w > MAX_ICON_SIDE || h > MAX_ICON_SIDE) {
+ i += 2 + w * h; /* complete but too big: the next size */
+ continue;
+ }
+ gboolean better = best == n || (best_w < 64 ? w > best_w : (w >= 64 && w < best_w));
+ if (better) {
+ best = i;
+ best_w = w;
+ best_h = h;
+ }
+ i += 2 + w * h;
+ }
+ if (best < n)
+ icon = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, (int)best_w, (int)best_h);
+ if (icon && cairo_surface_status(icon) != CAIRO_STATUS_SUCCESS) {
+ /* no memory: keep the icon the window had */
+ cairo_surface_destroy(icon);
+ XFree(raw);
+ return FALSE;
+ }
+ if (icon) {
+ unsigned char *dst = cairo_image_surface_get_data(icon);
+ int stride = cairo_image_surface_get_stride(icon);
+ cairo_surface_flush(icon);
+ for (unsigned long yy = 0; yy < best_h; yy++) {
+ guint32 *row = (guint32 *)(dst + yy * (unsigned long)stride);
+ for (unsigned long xx = 0; xx < best_w; xx++) {
+ guint32 v = (guint32)d[best + 2 + yy * best_w + xx];
+ guint32 a = v >> 24, r = (v >> 16) & 0xff, g = (v >> 8) & 0xff, b = v & 0xff;
+ /* cairo wants premultiplied alpha */
+ row[xx] = a << 24 | (r * a / 255) << 16 | (g * a / 255) << 8 | (b * a / 255);
+ }
+ }
+ cairo_surface_mark_dirty(icon);
+ }
+ }
+ if (raw)
+ XFree(raw);
+ if (!icon && !bw->icon)
+ return FALSE;
+ if (bw->icon)
+ cairo_surface_destroy(bw->icon);
+ bw->icon = icon;
+ /* unique across windows: X reuses window ids, and the icon cache is
+ * keyed by id and serial */
+ static guint icon_serial;
+ bw->icon_serial = ++icon_serial;
+ return TRUE;
+}
+
static BtdWindow *
add_window(X11Tracker *x, Window w)
{
@@ -269,6 +349,7 @@ add_window(X11Tracker *x, Window w)
update_title(x, bw);
update_state(x, bw);
update_geometry(x, bw);
+ update_icon(x, bw);
bw->active = (Window)bw->id == x->active;
return bw;
}
@@ -422,6 +503,8 @@ event_filter(GdkXEvent *gxev, GdkEvent *event, gpointer data)
}
} else if (a == x->atoms[A_NET_WM_NAME] || a == XA_WM_NAME) {
changed = update_title(x, bw);
+ } else if (a == x->atoms[A_NET_WM_ICON]) {
+ changed = update_icon(x, bw);
} else if (a == XA_WM_CLASS || a == x->atoms[A_GTK_APPLICATION_ID]) {
/* re-read identity; the dock re-resolves the application */
g_hash_table_remove(x->base.windows, &id);
diff --git a/src/ui/btd-appicons.c b/src/ui/btd-appicons.c
index b425c04..7962daf 100644
--- a/src/ui/btd-appicons.c
+++ b/src/ui/btd-appicons.c
@@ -148,6 +148,7 @@ is_docked(Appicons *s, BtdWindow *w, const char *desktop_id)
}
static const char *icon_name(Appicons *s, AppIcon *a);
+static cairo_surface_t *app_icon(Appicons *s, AppIcon *a, int size, int scale);
/* File name of the PNG drawn for the application: big-wm-app-.png. */
static char *
@@ -164,16 +165,23 @@ icon_file_name(const char *key)
* where the Dock and the Clip find the icons of their launchers. Once per
* session and icon (a theme change draws it again on the next start). */
static gboolean
-write_icon_file(Appicons *s, const char *name, const char *icon)
-{
+write_icon_file(Appicons *s, const char *name, AppIcon *a)
+{
+ /* what was drawn: the icon name, or the windows' icon (no .desktop),
+ * which changes with the version of a window's own icon */
+ char *icon = g_strdup(icon_name(s, a));
+ if (!icon) {
+ guint serial = 0;
+ for (guint i = 0; i < a->windows->len && !serial; i++)
+ serial = ((BtdWindow *)a->windows->pdata[i])->icon_serial;
+ icon = g_strdup_printf("(windows:%u)", serial);
+ }
const char *done = g_hash_table_lookup(s->icon_files, name);
char *dir = g_build_filename(g_get_user_data_dir(), "wlmaker", "icons", NULL);
char *path = g_build_filename(dir, name, NULL);
gboolean ok = done && g_strcmp0(done, icon) == 0 && g_file_test(path, G_FILE_TEST_EXISTS);
if (!ok && g_mkdir_with_parents(dir, 0755) == 0) {
- cairo_surface_t *src = btd_icon_cache_lookup_name(s->icons, icon, LAUNCHER_ICON, 1);
- if (!src)
- src = btd_icon_cache_lookup_name(s->icons, "application-x-executable", LAUNCHER_ICON, 1);
+ cairo_surface_t *src = app_icon(s, a, LAUNCHER_ICON, 1);
if (src) {
/* As a plain ARGB image of the launcher's size. */
cairo_surface_t *img = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, LAUNCHER_ICON, LAUNCHER_ICON);
@@ -197,6 +205,7 @@ write_icon_file(Appicons *s, const char *name, const char *icon)
if (ok)
g_hash_table_insert(s->icon_files, g_strdup(name), g_strdup(icon));
}
+ g_free(icon);
g_free(path);
g_free(dir);
return ok;
@@ -280,7 +289,7 @@ publish(Appicons *s)
g_free(cmd);
}
char *name = icon_file_name(a->key);
- if (write_icon_file(s, name, icon_name(s, a))) {
+ if (write_icon_file(s, name, a)) {
g_string_append(out, " Icon = ");
plist_string(out, name);
g_string_append(out, ";\n");
@@ -381,8 +390,16 @@ icon_name(Appicons *s, AppIcon *a)
if (e->icon)
return e->icon;
}
- BtdWindow *w = a->windows->len ? a->windows->pdata[0] : NULL;
- return w && w->app_id ? w->app_id : "application-x-executable";
+ /* NULL: no .desktop icon; the windows' own (btd_icon_cache_lookup_windows) */
+ return NULL;
+}
+
+static cairo_surface_t *
+app_icon(Appicons *s, AppIcon *a, int size, int scale)
+{
+ const char *name = icon_name(s, a);
+ return name ? btd_icon_cache_lookup_name(s->icons, name, size, scale)
+ : btd_icon_cache_lookup_windows(s->icons, a->windows, size, scale);
}
static gboolean
@@ -403,9 +420,7 @@ on_draw(GtkWidget *widget, cairo_t *cr, gpointer data)
AppIcon *a = s->apps->pdata[i];
double x = i * TILE;
btd_draw_tile(cr, &s->palette, x, 0, TILE, FALSE, s->pressed == (int)i, s->hover == (int)i);
- cairo_surface_t *icon = btd_icon_cache_lookup_name(s->icons, icon_name(s, a), ICON, scale);
- if (!icon)
- icon = btd_icon_cache_lookup_name(s->icons, "application-x-executable", ICON, scale);
+ cairo_surface_t *icon = app_icon(s, a, ICON, scale);
if (icon) {
cairo_save(cr);
cairo_set_source_surface(cr, icon, x + (TILE - ICON) / 2.0, (TILE - ICON) / 2.0);
diff --git a/src/ui/btd-dock.c b/src/ui/btd-dock.c
index 4f0795d..e36d1f6 100644
--- a/src/ui/btd-dock.c
+++ b/src/ui/btd-dock.c
@@ -1316,7 +1316,9 @@ draw_cell(BtdDock *dock, cairo_t *cr, Slot *s, const BtdItem *item, AppGroup *gr
icon = btd_icon_cache_lookup_item(dock->icons, item, dock->index, icon_size, scale);
} else {
const BtdDesktopEntry *e = btd_desktop_index_lookup(dock->index, group->desktop_id);
- icon = btd_icon_cache_lookup_name(dock->icons, e ? e->icon : NULL, icon_size, scale);
+ /* no .desktop (or one without Icon=): what the windows say */
+ icon = e && e->icon ? btd_icon_cache_lookup_name(dock->icons, e->icon, icon_size, scale)
+ : btd_icon_cache_lookup_windows(dock->icons, group->windows, icon_size, scale);
}
double alpha = 1.0;
if (launching && dock->prefs.animations)
diff --git a/src/ui/btd-icons.c b/src/ui/btd-icons.c
index 1b68957..2e765b3 100644
--- a/src/ui/btd-icons.c
+++ b/src/ui/btd-icons.c
@@ -235,6 +235,60 @@ btd_icon_cache_lookup_name(BtdIconCache *c, const char *icon, int size, int scal
return lookup_or_load(c, icon && *icon ? icon : "application-x-executable", size, scale, NULL);
}
+/* The window's own pixels, scaled once to the icon size (cached per window
+ * and icon version). */
+static cairo_surface_t *
+window_pixels(BtdIconCache *c, const BtdWindow *w, int size, int scale)
+{
+ char *key = g_strdup_printf("window:%" G_GUINT64_FORMAT ":%u|%d|%d", w->id, w->icon_serial, size, scale);
+ cairo_surface_t *s = cache_get(c, key);
+ if (!s) {
+ int px = size * scale;
+ double iw = cairo_image_surface_get_width(w->icon), ih = cairo_image_surface_get_height(w->icon);
+ s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, px, px);
+ cairo_t *cr = cairo_create(s);
+ double k = MIN(px / iw, px / ih);
+ cairo_translate(cr, (px - iw * k) / 2, (px - ih * k) / 2);
+ cairo_scale(cr, k, k);
+ cairo_set_source_surface(cr, w->icon, 0, 0);
+ cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_GOOD);
+ cairo_paint(cr);
+ cairo_destroy(cr);
+ cairo_surface_set_device_scale(s, scale, scale);
+ cache_put(c, key, s);
+ }
+ g_free(key);
+ return s;
+}
+
+cairo_surface_t *
+btd_icon_cache_lookup_windows(BtdIconCache *c, GPtrArray *windows, int size, int scale)
+{
+ for (guint i = 0; windows && i < windows->len; i++) {
+ const BtdWindow *w = windows->pdata[i];
+ const char *names[] = { w->app_id, w->wm_class, w->wm_instance, w->exe };
+ for (guint k = 0; k < G_N_ELEMENTS(names); k++) {
+ if (!names[k] || !*names[k] || strchr(names[k], '/'))
+ continue;
+ char *lower = g_utf8_strdown(names[k], -1);
+ const char *found = gtk_icon_theme_has_icon(c->theme, names[k]) ? names[k]
+ : gtk_icon_theme_has_icon(c->theme, lower) ? lower
+ : NULL;
+ cairo_surface_t *s = found ? lookup_or_load(c, found, size, scale, NULL) : NULL;
+ g_free(lower);
+ if (s)
+ return s;
+ }
+ }
+ for (guint i = 0; windows && i < windows->len; i++) {
+ const BtdWindow *w = windows->pdata[i];
+ if (w->icon && cairo_surface_status(w->icon) == CAIRO_STATUS_SUCCESS &&
+ cairo_image_surface_get_width(w->icon) > 0)
+ return window_pixels(c, w, size, scale);
+ }
+ return btd_icon_cache_lookup_name(c, NULL, size, scale);
+}
+
cairo_surface_t *
btd_icon_cache_lookup_item(BtdIconCache *c, const BtdItem *item, BtdDesktopIndex *index, int size, int scale)
{
diff --git a/src/ui/btd-icons.h b/src/ui/btd-icons.h
index 3fd358d..b2261e8 100644
--- a/src/ui/btd-icons.h
+++ b/src/ui/btd-icons.h
@@ -12,6 +12,7 @@
#include "btd-desktop.h"
#include "btd-model.h"
+#include "btd-windows.h"
G_BEGIN_DECLS
@@ -27,6 +28,11 @@ guint btd_icon_cache_size(BtdIconCache *cache);
/* Returns a borrowed surface (valid until the next lookup may evict it;
* draw it immediately). Never NULL: falls back to a generic icon. */
cairo_surface_t *btd_icon_cache_lookup_name(BtdIconCache *cache, const char *icon, int size, int scale);
+/* Icon of running windows (BtdWindow *) with no .desktop icon: a theme icon
+ * named after the app ID, the WM_CLASS class or instance (also in lower
+ * case) or the program; else the window's own icon (X11 _NET_WM_ICON);
+ * else the generic icon. Never NULL; borrowed like the lookups above. */
+cairo_surface_t *btd_icon_cache_lookup_windows(BtdIconCache *cache, GPtrArray *windows, int size, int scale);
cairo_surface_t *btd_icon_cache_lookup_item(BtdIconCache *cache, const BtdItem *item, BtdDesktopIndex *index,
int size, int scale);
diff --git a/tests/meson.build b/tests/meson.build
index 80867cc..6353e3c 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -23,6 +23,12 @@ if get_option('dock')
dependencies: [core_dep, dependency('gtk+-3.0')],
include_directories: include_directories('../src/backend'))
test('windows', exe, env: test_env, protocol: 'tap', args: ['--tap'])
+ # Ícone de um aplicativo sem .desktop: tema pelo nome da janela, o ícone
+ # da própria janela (_NET_WM_ICON) ou o genérico.
+ exe = executable('test-icons', 'test-icons.c', '../src/ui/btd-icons.c', '../src/backend/btd-windows.c',
+ dependencies: [core_dep, dependency('gtk+-3.0'), dependency('librsvg-2.0')],
+ include_directories: include_directories('../src/ui', '../src/backend'))
+ test('icons', exe, env: test_env, protocol: 'tap', args: ['--tap'])
endif
# O controlador (dockapp), sem X11: ordem das setas, regiões, preferências,
diff --git a/tests/test-icons.c b/tests/test-icons.c
new file mode 100644
index 0000000..32a4857
--- /dev/null
+++ b/tests/test-icons.c
@@ -0,0 +1,142 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Icon of a running application with no .desktop (btd_icon_cache_lookup_windows):
+ * a theme icon named after the window (class in lower case here), else the
+ * window's own icon (X11 _NET_WM_ICON), else the generic icon. Before, every
+ * such application showed the generic "exec" icon in the dock.
+ */
+#include
+
+#include "btd-icons.h"
+
+#define SIZE 48
+
+static char *theme_dir;
+
+/* the colour at the centre of a drawn icon, as 0xRRGGBB (opaque pixels) */
+static guint32
+centre(cairo_surface_t *s)
+{
+ cairo_surface_flush(s);
+ int w = cairo_image_surface_get_width(s), h = cairo_image_surface_get_height(s);
+ const guint32 *px =
+ (const guint32 *)(cairo_image_surface_get_data(s) + (h / 2) * cairo_image_surface_get_stride(s));
+ return px[w / 2] & 0xFFFFFF;
+}
+
+static cairo_surface_t *
+square(double r, double g, double b, int side)
+{
+ cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, side, side);
+ cairo_t *cr = cairo_create(s);
+ cairo_set_source_rgb(cr, r, g, b);
+ cairo_paint(cr);
+ cairo_destroy(cr);
+ return s;
+}
+
+static BtdIconCache *
+make_cache(void)
+{
+ GtkIconTheme *theme = gtk_icon_theme_new();
+ gtk_icon_theme_set_search_path(theme, (const char *[]){ theme_dir }, 1);
+ gtk_icon_theme_set_custom_theme(theme, "teste");
+ BtdIconCache *c = btd_icon_cache_new(theme, BTD_ICON_CACHE_MAX);
+ g_object_unref(theme);
+ return c;
+}
+
+static void
+test_theme_icon_by_class(void)
+{
+ BtdIconCache *c = make_cache();
+ BtdWindow w = { .id = 1, .wm_class = "MinhaClasse", .wm_instance = "minha" };
+ GPtrArray *ws = g_ptr_array_new();
+ g_ptr_array_add(ws, &w);
+ /* "MinhaClasse" is not in the theme; "minhaclasse" (green) is */
+ g_assert_cmphex(centre(btd_icon_cache_lookup_windows(c, ws, SIZE, 1)), ==, 0x00FF00);
+ g_ptr_array_unref(ws);
+ btd_icon_cache_free(c);
+}
+
+static void
+test_window_own_icon(void)
+{
+ BtdIconCache *c = make_cache();
+ BtdWindow w = { .id = 2, .wm_class = "SemIcone", .icon = square(1, 0, 0, 16), .icon_serial = 7 };
+ GPtrArray *ws = g_ptr_array_new();
+ g_ptr_array_add(ws, &w);
+ cairo_surface_t *s = btd_icon_cache_lookup_windows(c, ws, SIZE, 2);
+ /* scaled to the icon size at the monitor scale */
+ g_assert_cmpint(cairo_image_surface_get_width(s), ==, SIZE * 2);
+ g_assert_cmphex(centre(s), ==, 0xFF0000);
+ /* a new icon on the same window is drawn again, not taken from the cache */
+ cairo_surface_destroy(w.icon);
+ w.icon = square(0, 0, 1, 16);
+ w.icon_serial = 8;
+ g_assert_cmphex(centre(btd_icon_cache_lookup_windows(c, ws, SIZE, 2)), ==, 0x0000FF);
+ cairo_surface_destroy(w.icon);
+ g_ptr_array_unref(ws);
+ btd_icon_cache_free(c);
+}
+
+static void
+test_nothing_falls_back_to_generic(void)
+{
+ BtdIconCache *c = make_cache();
+ BtdWindow w = { .id = 3, .app_id = "nada.por.aqui" };
+ GPtrArray *ws = g_ptr_array_new();
+ g_ptr_array_add(ws, &w);
+ cairo_surface_t *s = btd_icon_cache_lookup_windows(c, ws, SIZE, 1);
+ g_assert_nonnull(s);
+ g_assert_true(s == btd_icon_cache_lookup_name(c, NULL, SIZE, 1));
+ g_assert_cmphex(centre(s), ==, 0x808080);
+ g_ptr_array_unref(ws);
+ btd_icon_cache_free(c);
+}
+
+int
+main(int argc, char **argv)
+{
+ g_test_init(&argc, &argv, NULL);
+ theme_dir = g_dir_make_tmp("btd-icons-XXXXXX", NULL);
+ char *apps = g_build_filename(theme_dir, "teste", "48x48", "apps", NULL);
+ g_mkdir_with_parents(apps, 0700);
+ char *index = g_build_filename(theme_dir, "teste", "index.theme", NULL);
+ g_file_set_contents(index,
+ "[Icon Theme]\nName=teste\nDirectories=48x48/apps\n\n"
+ "[48x48/apps]\nSize=48\nType=Fixed\n",
+ -1, NULL);
+ char *png = g_build_filename(apps, "minhaclasse.png", NULL);
+ cairo_surface_t *green = square(0, 1, 0, 48);
+ cairo_surface_write_to_png(green, png);
+ cairo_surface_destroy(green);
+ /* the generic icon (gray), as every real theme has */
+ char *generic = g_build_filename(apps, "application-x-executable.png", NULL);
+ cairo_surface_t *gray = square(0.5, 0.5, 0.5, 48);
+ cairo_surface_write_to_png(gray, generic);
+ cairo_surface_destroy(gray);
+
+ g_test_add_func("/icons/theme-icon-by-class", test_theme_icon_by_class);
+ g_test_add_func("/icons/window-own-icon", test_window_own_icon);
+ g_test_add_func("/icons/nothing-generic", test_nothing_falls_back_to_generic);
+ int r = g_test_run();
+
+ g_unlink(png);
+ g_unlink(generic);
+ g_free(generic);
+ g_unlink(index);
+ g_rmdir(apps);
+ char *size_dir = g_path_get_dirname(apps);
+ g_rmdir(size_dir);
+ char *teste = g_path_get_dirname(size_dir);
+ g_rmdir(teste);
+ g_rmdir(theme_dir);
+ g_free(teste);
+ g_free(size_dir);
+ g_free(png);
+ g_free(index);
+ g_free(apps);
+ g_free(theme_dir);
+ return r;
+}