Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<p align="center">
<a href="https://github.com/big-windowmaker/tabbed-dock/actions/workflows/ci.yml"><img src="https://github.com/big-windowmaker/tabbed-dock/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
<img src="https://img.shields.io/badge/vers%C3%A3o-0.3.2-informational" alt="Versão 0.3.2">
<img src="https://img.shields.io/badge/vers%C3%A3o-0.3.3-informational" alt="Versão 0.3.3">
<img src="https://img.shields.io/badge/licen%C3%A7a-GPL--2.0--or--later-blue" alt="Licença GPL-2.0-or-later">
<img src="https://img.shields.io/badge/sess%C3%B5es-X11%20%7C%20Wayland-555" alt="X11 e Wayland">
</p>
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -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'])
Expand Down
2 changes: 1 addition & 1 deletion pkgbuild/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions src/backend/btd-windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 5 additions & 0 deletions src/backend/btd-windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
83 changes: 83 additions & 0 deletions src/backend/btd-x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
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)
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
37 changes: 26 additions & 11 deletions src/ui/btd-appicons.c
Original file line number Diff line number Diff line change
Expand Up @@ -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-<key>.png. */
static char *
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/ui/btd-dock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
54 changes: 54 additions & 0 deletions src/ui/btd-icons.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions src/ui/btd-icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "btd-desktop.h"
#include "btd-model.h"
#include "btd-windows.h"

G_BEGIN_DECLS

Expand All @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading