Skip to content

Commit

Permalink
feat: Add config for what window to focus on close
Browse files Browse the repository at this point in the history
  • Loading branch information
imawizard committed Apr 22, 2024
1 parent b3bf740 commit 88d8fec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/miguru/miguru.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class MiguruWM extends WMEvents {
tilingMinWidth: 500,
tilingMinHeight: 500,
tilingInsertion: "last",
focusAfterClose: "previous",
floatingAlwaysOnTop: false,

focusFollowsMouse: false,
Expand Down Expand Up @@ -142,6 +143,12 @@ class MiguruWM extends WMEvents {
"first",
"last",
)
ExpectInSet(o, "focusAfterClose",
"previous",
"next",
"first",
"last",
)
ExpectInSet(o, "floatingAlwaysOnTop", true, false)
ExpectInSet(o, "focusFollowsMouse", true, false)
ExpectInSet(o, "mouseFollowsFocus", true, false)
Expand Down Expand Up @@ -1069,9 +1076,20 @@ class MiguruWM extends WMEvents {
;; Because of the focus-switch the destroyed window is not the
;; active one anymore and Remove() won't return a window that were
;; to be activated.
next := window.workspace.Remove(hwnd)
if next && window.workspace.Index == this.activeWsIdx {
this._focusWindow(next, false)
ws := window.workspace
if ws.ActiveWindow == hwnd {
wasActive := true
next := ws.GetWindow(this._opts.focusAfterClose, hwnd)
} else {
wasActive := false
}
ws.Remove(hwnd)
if wasActive {
if ws.Index == this.activeWsIdx {
this._focusWindow(next, false)
} else {
ws.ActiveWindow := next
}
}
} else {
this._unpinWindow(hwnd, window)
Expand Down
6 changes: 6 additions & 0 deletions lib/miguru/workspaces.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ class WorkspaceList {
return this._nextWindow(hwnd)
case "previous":
return this._previousWindow(hwnd)
case "first":
return this._tiled.First ? this._tiled.First.data
: this._floating.Get(1, "")
case "last":
first := this._tiled.First ? this._tiled.First.data : ""
return this._previousWindow(first)
case "":
return hwnd
default:
Expand Down

0 comments on commit 88d8fec

Please sign in to comment.