diff --git a/README.md b/README.md index 4c25093..8827bf9 100644 --- a/README.md +++ b/README.md @@ -26,11 +26,12 @@ I recently started using [bspwm](https://github.com/baskerville/bspwm) as my mai * rules to define custom icons * clicking on a group cycles through the windows in that group * right click to get a popup with all open windows in that group -* supports custom wm **unhide** commands +* supports custom wm **hide** and **unhide** commands ```ini # Example for bspwm: unhideCommand = bspc node {window} -g hidden=off -f + hideCommand=bspc node {window} -g hidden=on -f ``` ## 📦 Installation @@ -85,6 +86,7 @@ activeWorkspaceOnly=false showHidden=true showVisible=true unhideCommand=bspc node {window} -g hidden=off -f +hideCommand=bspc node {window} -g hidden=on -f #Rules for custom icons matching the class::instance of windows #icon-name=string to be part of class::instance diff --git a/config/settings.ini b/config/settings.ini index c615548..64e69a7 100644 --- a/config/settings.ini +++ b/config/settings.ini @@ -18,6 +18,7 @@ activeWorkspaceOnly=false showHidden=true showVisible=true unhideCommand=bspc node {window} -g hidden=off -f +hideCommand=bspc node {window} -g hidden=on -f #Rules for custom icons matching the class::instance of windows #icon-name=string to be part of class::instance diff --git a/src/config.ts b/src/config.ts index 063c628..2cb5d9b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -19,6 +19,7 @@ const defaults = { showHidden: true, showVisible: true, unhideCommand: "bspc node {window} -g hidden=off -f", + hideCommand: "bspc node {window} -g hidden=on -f", }, icons: { "google-agenda": "calendar.google.com", diff --git a/src/dock-item.ts b/src/dock-item.ts index 07d81bb..2cb6c4f 100644 --- a/src/dock-item.ts +++ b/src/dock-item.ts @@ -76,20 +76,25 @@ export class DockItem { const activeId = this.window.get_screen().get_active_window()?.get_xid() const group = this.getGroupWindows() - // Cycle though existing windows, if active window is part of group - for (let g = 0; g < group.length; g++) { - if (group[g].get_xid() == activeId) { - if (g === group.length - 1) { - this.activate(group[0]) - } else this.activate(group[g + 1]) - return + if (group.length > 1) { + // Cycle though existing windows, if active window is part of group + for (let g = 0; g < group.length; g++) { + if (group[g].get_xid() == activeId) { + if (g === group.length - 1) { + this.activate(group[0]) + } else this.activate(group[g + 1]) + return + } } } - this.activate() + this.activate(this.window, true) } - activate(window = this.window) { + activate(window: Wnck.Window, toggle = false) { + log(`activate: ${toggle}`) const timestamp = new Date().getTime() / 1000 + + // Unhide the window if it's minimized / hidden if (this.isHidden(window)) { if (config.settings.behavior.unhideCommand) { const unhide = config.settings.behavior.unhideCommand.replace( @@ -99,8 +104,26 @@ export class DockItem { log(`[unhide] ${unhide}`) GLib.spawn_command_line_async(unhide) } + window.activate(timestamp) + } + // Toggle it if it's the only one in the group and if it's the active window + else if ( + toggle && + window.get_screen().get_active_window()?.get_xid() == window.get_xid() + ) { + log("minimizing") + window.minimize() + if (config.settings.behavior.hideCommand) { + const hide = config.settings.behavior.hideCommand.replace( + "{window}", + `${window.get_xid()}` + ) + log(`[hide] ${hide}`) + GLib.spawn_command_line_async(hide) + } } - window.activate(timestamp) + // Else, just show it + else window.activate(timestamp) } isHidden(window = this.window) { @@ -172,7 +195,7 @@ export class DockItem { ) ) menuItem.connect("activate", () => { - item.activate() + item.activate(item.window, true) }) this.menu.append(menuItem)