diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d07e28..7b71c5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ 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.1 — 2026-11-14 + +- Abas sem os "triângulos" de papel de parede entre elas: as abas vizinhas + se sobrepõem por uma inclinação (a da esquerda na frente, como abas de + pasta), nos estilos clássico e tiles. Lado a lado, as laterais inclinadas + deixavam um vão em V entre cada duas abas. O clique segue o que está + desenhado na frente. +- Corrigida a queda do dock (SIGSEGV em `g_str_hash` dentro do desenho) + quando uma janela sumia ou trocava de `WM_CLASS` enquanto o dock se + redesenhava, por exemplo ao abrir e fechar o instalador na ISO live: a + janela era liberada antes de o dock refazer seus grupos. Agora o + rastreador só a libera depois do aviso (`tests/test-windows.c`). + ## 0.3.0 — 2026-11-11 - Controlador: novo visual, um painel de instrumentos OPENSTEP. O diff --git a/meson.build b/meson.build index bfcd4ed..d138523 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.0', + version: '0.3.1', 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 609e481..00d41cc 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.0 +pkgver=0.3.1 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 53595e9..0aefda6 100644 --- a/src/backend/btd-windows.c +++ b/src/backend/btd-windows.c @@ -21,12 +21,29 @@ window_free(BtdWindow *w) g_free(w); } +/* + * A window that goes away (destroyed, unmapped, now skip-taskbar...) leaves + * the table at once, but the dock hears about it only in emit_idle(), at a + * lower priority than GTK's redraws; its groups keep pointing to the window + * until then, and a frame drawn in between (the launch feedback redraws + * continuously) read the freed strings - a crash in g_str_hash under the + * draw handler when the installer window closed. The window is kept until + * after the changed callback. + */ +static void +window_retire(BtdWindow *w) +{ + g_ptr_array_add(w->tracker->retired, w); + btd_window_tracker_queue_changed(w->tracker); +} + void btd_window_tracker_init_base(BtdWindowTracker *t, const char *name, guint caps) { t->name = name; t->caps = caps; - t->windows = g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, (GDestroyNotify)window_free); + t->windows = g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, (GDestroyNotify)window_retire); + t->retired = g_ptr_array_new_with_free_func((GDestroyNotify)window_free); } BtdWindow * @@ -35,6 +52,7 @@ btd_window_new(BtdWindowTracker *t, guint64 id) BtdWindow *w = g_new0(BtdWindow, 1); w->id = id; w->serial = ++t->next_serial; + w->tracker = t; g_hash_table_insert(t->windows, &w->id, w); return w; } @@ -57,6 +75,7 @@ emit_idle(gpointer data) t->idle_id = 0; if (t->changed) t->changed(t, t->changed_data); + g_ptr_array_set_size(t->retired, 0); return G_SOURCE_REMOVE; } @@ -134,8 +153,9 @@ btd_window_tracker_free(BtdWindowTracker *t) t->changed = NULL; if (t->destroy) t->destroy(t); + g_hash_table_unref(t->windows); /* retires them all */ if (t->idle_id) g_source_remove(t->idle_id); - g_hash_table_unref(t->windows); + g_ptr_array_unref(t->retired); g_free(t); } diff --git a/src/backend/btd-windows.h b/src/backend/btd-windows.h index 827919d..9a07431 100644 --- a/src/backend/btd-windows.h +++ b/src/backend/btd-windows.h @@ -56,6 +56,7 @@ typedef struct { int monitor_hint; /* monitor of the window centre, -1 unknown */ char *desktop_id; /* resolved by the dock, cached */ gboolean resolved; + struct _BtdWindowTracker *tracker; } BtdWindow; typedef struct _BtdWindowTracker BtdWindowTracker; @@ -70,6 +71,9 @@ struct _BtdWindowTracker { BtdWindowsChangedFunc changed; gpointer changed_data; guint idle_id; + /* Windows taken out of the table, freed only after the changed callback: + * until then the dock's groups still point to them. */ + GPtrArray *retired; void (*activate)(BtdWindowTracker *t, BtdWindow *w, guint32 time); void (*minimize)(BtdWindowTracker *t, BtdWindow *w); diff --git a/src/ui/btd-dock.c b/src/ui/btd-dock.c index d5514f9..b0242ea 100644 --- a/src/ui/btd-dock.c +++ b/src/ui/btd-dock.c @@ -833,15 +833,27 @@ btd_dock_relayout(BtdDock *dock) width = dock->fill_width; add_slot(dock, SLOT_TRASH, width - PAD - 2 - dock->cell_w, ty, dock->cell_w, dock->cell_h, -1); int tab_y = dir == BTD_TAB_UP ? dock->shadow : dock->shelf_h; - add_slot(dock, SLOT_HIDE, 0, tab_y, dock->stub_w, dock->tab_h, -1); + /* Neighbouring tabs overlap by one slope, the left one in front (drawn + * right to left), like folder tabs: side by side, their sloped sides + * left a V-shaped notch between every two tabs that showed the desktop + * (triangles of wallpaper between General, Developer and Documents). + * Classic trapezoids also have rounded top corners (4 px): overlapping + * by the slope plus that radius closes the notch they leave at the top. */ + int e = 0; + if (dock->prefs.style == BTD_STYLE_TILES) + e = (int)BTD_TAB_SLOPE; + else if (dock->prefs.style == BTD_STYLE_CLASSIC) + e = (int)ceil(BTD_BETA_SLANT * dock->tab_h / 28.0) + 4; + dock->tab_overlap = e; + add_slot(dock, SLOT_HIDE, 0, tab_y, dock->stub_w + e, dock->tab_h, -1); int tabs_w = width - 2 * dock->stub_w; x = dock->stub_w; for (guint i = 0; i < n_tabs; i++) { int w = (int)((guint64)tabs_w * (i + 1) / n_tabs) - (int)((guint64)tabs_w * i / n_tabs); - add_slot(dock, SLOT_TAB, x, tab_y, w, dock->tab_h, (int)i); + add_slot(dock, SLOT_TAB, x - e, tab_y, w + 2 * e, dock->tab_h, (int)i); x += w; } - add_slot(dock, SLOT_ADD_TAB, width - dock->stub_w, tab_y, dock->stub_w, dock->tab_h, -1); + add_slot(dock, SLOT_ADD_TAB, width - dock->stub_w - e, tab_y, dock->stub_w + e, dock->tab_h, -1); dock->tabs_end = width; dock->width = width; int full_h = dock->shadow + dock->tab_h + dock->shelf_h; @@ -1355,8 +1367,9 @@ draw_tab_slot(BtdDock *dock, cairo_t *cr, Slot *s, gboolean active, gboolean hig if (l) { int lw, lh; pango_layout_get_pixel_size(l, &lw, &lh); - if (lw > s->rect.width - 2 * BTD_BETA_SLANT - 8) { - pango_layout_set_width(l, (int)(s->rect.width - 2 * BTD_BETA_SLANT - 8) * PANGO_SCALE); + int room = s->rect.width - 2 * dock->tab_overlap - 2 * (int)BTD_BETA_SLANT - 8; + if (lw > room) { + pango_layout_set_width(l, MAX(1, room) * PANGO_SCALE); pango_layout_set_ellipsize(l, PANGO_ELLIPSIZE_END); } } @@ -1370,11 +1383,14 @@ draw_tab_slot(BtdDock *dock, cairo_t *cr, Slot *s, gboolean active, gboolean hig if (l) g_object_unref(l); double cy = s->rect.y + s->rect.height / 2.0 + (dir == BTD_TAB_UP ? 1 : -1); + /* The end slots reach tab_overlap px under their neighbour tab: the + * glyph stays centred on the stub itself, where nothing covers it. */ if (s->kind == SLOT_HIDE) - btd_draw_arrow_glyph(cr, p, s->rect.x + s->rect.width / 2.0 - 2, cy, MIN(16, s->rect.height - 8), + btd_draw_arrow_glyph(cr, p, s->rect.x + dock->stub_w / 2.0 - 2, cy, MIN(16, s->rect.height - 8), dock->prefs.edge == BTD_EDGE_BOTTOM); else if (s->kind == SLOT_ADD_TAB) - btd_draw_document_glyph(cr, p, s->rect.x + s->rect.width / 2.0 + 3, cy, MIN(16, s->rect.height - 9)); + btd_draw_document_glyph(cr, p, s->rect.x + dock->tab_overlap + dock->stub_w / 2.0 + 3, cy, + MIN(16, s->rect.height - 9)); } /* X11 with a compositor: the parts of the window outside the drawing area @@ -1535,20 +1551,33 @@ on_draw(GtkWidget *widget, cairo_t *cr, gpointer data) /* ---- input ---------------------------------------------------------------- */ +static gboolean +is_tab_row(SlotKind kind) +{ + return kind == SLOT_TAB || kind == SLOT_HIDE || kind == SLOT_ADD_TAB; +} + +static gboolean +slot_is_tab(BtdDock *dock, const Slot *s, BtdTab *tab) +{ + return s->kind == SLOT_TAB && btd_model_get_tab(dock->model, (guint)s->index) == tab; +} + static int slot_at(BtdDock *dock, double x, double y) { - /* tabs overlap: the active tab and right-most visible tab win */ + /* Tabs overlap (tab_overlap): what is drawn in front wins, the active + * tab, else the left one up to the middle of its slope. */ int found = -1; + BtdTab *active = btd_model_get_active_tab(dock->model); for (guint i = 0; i < dock->slots->len; i++) { Slot *s = &g_array_index(dock->slots, Slot, i); if (x >= s->rect.x && x < s->rect.x + s->rect.width && y >= s->rect.y && y < s->rect.y + s->rect.height) { - if (s->kind == SLOT_TAB && found >= 0) { - BtdTab *tab = btd_model_get_tab(dock->model, (guint)s->index); + if (found >= 0 && is_tab_row(s->kind)) { Slot *prev = &g_array_index(dock->slots, Slot, found); - /* inside the overlapping slope, prefer the active tab, else the left one */ - if (prev->kind == SLOT_TAB && tab != btd_model_get_active_tab(dock->model) && - x < prev->rect.x + prev->rect.width - BTD_TAB_SLOPE * 0.5) + if (is_tab_row(prev->kind) && !slot_is_tab(dock, s, active) && + (slot_is_tab(dock, prev, active) || + x < prev->rect.x + prev->rect.width - dock->tab_overlap * 0.5)) continue; } found = (int)i; diff --git a/src/ui/btd-dock.h b/src/ui/btd-dock.h index e603864..f07f8bb 100644 --- a/src/ui/btd-dock.h +++ b/src/ui/btd-dock.h @@ -71,6 +71,7 @@ struct _BtdDock { int width, height; int tile, tab_h, shelf_y, shelf_h, shadow; int cell_w, cell_h, label_h, stub_w; + int tab_overlap; /* px each tab of the row reaches under its neighbours */ int fill_width; /* width given by the compositor (Wayland, full width) */ int tabs_end; /* x after the last tab */ GdkRectangle active_tab_rect; diff --git a/src/ui/btd-draw.h b/src/ui/btd-draw.h index e6790a1..5cf17f3 100644 --- a/src/ui/btd-draw.h +++ b/src/ui/btd-draw.h @@ -68,7 +68,7 @@ PangoFontDescription *btd_font_new(gboolean bold, double px); /* OPENSTEP 4.0 beta look (style classic): marble textures, trapezoid tabs * that are wider at the base, with rounded top corners, a lit left edge and a - * dark right edge; the gaps between them show the desktop. */ + * dark right edge; neighbouring tabs overlap (btd-dock.c, tab_overlap). */ #define BTD_BETA_SLANT 10.0 cairo_pattern_t *btd_marble_pattern(double r, double g, double b, double amplitude, guint seed); void btd_beta_tab_path(cairo_t *cr, double x, double y, double w, double h, BtdTabDirection dir, diff --git a/tests/meson.build b/tests/meson.build index 3ec6504..80867cc 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -16,6 +16,15 @@ foreach t : ['model', 'config', 'desktop', 'coexist', 'launch', 'wmattrs', 'geom test(t, exe, env: test_env, protocol: 'tap', args: ['--tap']) endforeach +# O rastreador de janelas, sem X11 nem Wayland: uma janela que sai da tabela +# só é liberada depois do aviso ao dock. +if get_option('dock') + exe = executable('test-windows', 'test-windows.c', '../src/backend/btd-windows.c', + dependencies: [core_dep, dependency('gtk+-3.0')], + include_directories: include_directories('../src/backend')) + test('windows', exe, env: test_env, protocol: 'tap', args: ['--tap']) +endif + # O controlador (dockapp), sem X11: ordem das setas, regiões, preferências, # --set e os arquivos do menu do wlmaker. if get_option('dock') and get_option('dockapp') and have_dockapp diff --git a/tests/test-windows.c b/tests/test-windows.c new file mode 100644 index 0000000..5f85c2f --- /dev/null +++ b/tests/test-windows.c @@ -0,0 +1,69 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * The window tracker keeps a window that left the table alive until the + * changed callback has run: the dock's groups point to it until then, and a + * frame drawn in between used to read freed memory (crash in g_str_hash + * under the draw handler). + */ +#include "btd-windows.h" + +typedef struct { + int calls; + guint listed; + gboolean retired_readable; +} Seen; + +static BtdWindow *retired_window; + +static void +on_changed(BtdWindowTracker *t, gpointer data) +{ + Seen *seen = data; + seen->calls++; + GList *l = btd_window_tracker_list(t); + seen->listed = g_list_length(l); + g_list_free(l); + /* the window that left is not listed, but still intact for the groups + * built before this callback */ + seen->retired_readable = retired_window && g_strcmp0(retired_window->wm_class, "calamares") == 0; +} + +static void +test_window_outlives_removal_until_changed(void) +{ + BtdWindowTracker *t = g_new0(BtdWindowTracker, 1); + btd_window_tracker_init_base(t, "test", 0); + Seen seen = { 0 }; + btd_window_tracker_set_changed_func(t, on_changed, &seen); + + BtdWindow *keep = btd_window_new(t, 1); + btd_window_set_string(&keep->wm_class, "xterm", NULL); + BtdWindow *gone = btd_window_new(t, 2); + btd_window_set_string(&gone->wm_class, "calamares", NULL); + retired_window = gone; + + guint64 id = 2; + g_hash_table_remove(t->windows, &id); /* destroyed, or WM_CLASS re-read */ + g_assert_cmpuint(g_hash_table_size(t->windows), ==, 1); + g_assert_cmpuint(t->retired->len, ==, 1); + g_assert_cmpstr(gone->wm_class, ==, "calamares"); /* a redraw now is safe */ + g_assert_cmpuint(t->idle_id, !=, 0); /* the dock will be told */ + + while (t->idle_id) + g_main_context_iteration(NULL, TRUE); + g_assert_cmpint(seen.calls, ==, 1); + g_assert_cmpuint(seen.listed, ==, 1); + g_assert_true(seen.retired_readable); + g_assert_cmpuint(t->retired->len, ==, 0); /* freed after the callback */ + retired_window = NULL; + + btd_window_tracker_free(t); +} + +int +main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + g_test_add_func("/windows/outlives-removal-until-changed", test_window_outlives_removal_until_changed); + return g_test_run(); +}