From c8a6bb0ef7dc6b881fa622c2b817afe036c008e9 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 3 Jun 2020 01:25:05 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20always=20operate=20on=20a?= =?UTF-8?q?=20fresh=20window=20from=20Wnck.=20trying=20to=20minimize=20seg?= =?UTF-8?q?faults.=20related=20to=20#1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO | 4 ++++ src/dock-item.ts | 26 +++++++++++++++++++++----- src/dock.ts | 32 ++++++++++++-------------------- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/TODO b/TODO index 03e1761..c205138 100644 --- a/TODO +++ b/TODO @@ -2,3 +2,7 @@ Todo: ☐ Hide Dock when no toolbar windows ☐ Check for segfaults. Possibly write auto restart script + ☐ Check why dock sometimes doesn't render initially + When cycling though windows, jump to the ones in the current workspace first + Wrong geometry when initially loaded in Xorg + Clicking app to activate feels slow. probably animations etc diff --git a/src/dock-item.ts b/src/dock-item.ts index ece4775..c4aed96 100644 --- a/src/dock-item.ts +++ b/src/dock-item.ts @@ -10,8 +10,12 @@ export class DockItem { name: string tooltip = "" - constructor(public window: Wnck.Window, public horizontal: boolean) { - this.name = window.get_class_instance_name() + constructor( + public screen: Wnck.Screen, + public xid: number, + public horizontal: boolean + ) { + this.name = this.window.get_class_instance_name().slice() this.update() this.window.connect("icon-changed", () => { @@ -26,6 +30,18 @@ export class DockItem { this.button.connect("clicked", () => this.activate()) } + get window() { + for (const w of this.screen.get_windows_stacked()) { + if (w.get_xid() == this.xid) return w + } + + const error = new Error( + `Wnck.Window ${this.xid} for ${this.name} no longer exists` + ) + logError(error) + throw error + } + getGroupWindows() { const group = this.getGroupKey() return this.window @@ -96,9 +112,9 @@ export class DockItem { Gtk.IconLookupFlags.FORCE_SIZE ) } else { - icon = this.window - .get_icon() - .scale_simple( + icon = icon.copy() + if (icon) + icon = icon.scale_simple( config.settings.appearance.iconSize, config.settings.appearance.iconSize, GdkPixbuf.InterpType.BILINEAR diff --git a/src/dock.ts b/src/dock.ts index 438629a..38db474 100644 --- a/src/dock.ts +++ b/src/dock.ts @@ -35,19 +35,21 @@ export class Dock { // this.toolbar.connect("remove", () => this.toolbar.check_resize()) } - getWorkspaceXids(windows: Wnck.Window[]) { - const activeWorkspace = this.screen.get_active_workspace() - return new Set( - windows - .filter((w) => w.is_on_workspace(activeWorkspace)) - .map((x) => x.get_xid()) - ) - } - update() { + // this.screen.force_update() const windows = this.screen.get_windows() if (!windows) return log("No Windows!") + // Remove closed windows + const xids = new Set(windows.map((x) => x.get_xid())) + for (const [xid, item] of this.items.entries()) { + if (!xids.has(xid)) { + log(`- ${item.name}`) + this.items.delete(xid) + this.toolbar.remove(item.button) + } + } + // Add opened windows windows.forEach((window) => { const xid = window.get_xid() @@ -55,22 +57,12 @@ export class Dock { window.connect("geometry-changed", () => this.toolbar.check_resize()) window.connect("workspace-changed", () => this.update()) log(`+ ${window.get_class_instance_name()}`) - const item = new DockItem(window, this.horizontal) + const item = new DockItem(this.screen, xid, this.horizontal) this.toolbar.add(item.button) this.items.set(xid, item) } }) - // Remove closed windows - const xids = new Set(windows.map((x) => x.get_xid())) - for (const [xid, item] of this.items.entries()) { - if (!xids.has(xid)) { - log(`- ${item.window.get_class_instance_name()}`) - this.items.delete(xid) - this.toolbar.remove(item.button) - } - } - // Update window state const workspace = this.screen.get_active_workspace() const groups = new Map()