Skip to content

Commit

Permalink
feat: ✨ toggle window if it's the only one in the group
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 4, 2020
1 parent ecf899f commit 11c3fe1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
45 changes: 34 additions & 11 deletions src/dock-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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) {
Expand Down Expand Up @@ -172,7 +195,7 @@ export class DockItem {
)
)
menuItem.connect("activate", () => {
item.activate()
item.activate(item.window, true)
})
this.menu.append(menuItem)

Expand Down

0 comments on commit 11c3fe1

Please sign in to comment.