Repository navigation
release: 0.3.1 — abas sem vão entre elas, queda do dock ao fechar janelas #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5b3747d
43b0109
0504cf3
5ab88ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)) | ||
|
Comment on lines
+1578
to
+1580
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the painted tab path for overlap hit testing. With classic tabs and overlap 14, a point five pixels left of an inactive tab's right edge and two pixels above its base remains inside its painted path. This cutoff instead selects the next slot. Active-tab rectangle precedence also ignores transparent corners. Test the actual paths in paint precedence order so clicks select the visible tab. (raw.githubusercontent.com)
|
||
| continue; | ||
| } | ||
| found = (int)i; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.