Skip to content

Commit

Permalink
fix: šŸ› always operate on a fresh window from Wnck. trying to minimizeā€¦
Browse files Browse the repository at this point in the history
ā€¦ segfaults. related to #1
  • Loading branch information
folke committed Jun 2, 2020
1 parent b9f282a commit c8a6bb0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
4 changes: 4 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 21 additions & 5 deletions src/dock-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
32 changes: 12 additions & 20 deletions src/dock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,42 +35,34 @@ 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<number>(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()
if (!this.items.has(xid)) {
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<number>(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<string, DockItem>()
Expand Down

0 comments on commit c8a6bb0

Please sign in to comment.