From 39331e5fbb970e66c3746b39b26601ff479323f1 Mon Sep 17 00:00:00 2001 From: imawizard <1701648+imawizard@users.noreply.github.com> Date: Tue, 30 Jul 2024 12:07:39 +0200 Subject: [PATCH 1/4] feat: Add `focusWorkspaceByWindow: "same-monitor"` (#30) Works the same as `focusWorkspaceByWindow: true`, but keeps the current monitor active, instead of switching to the workspace's last active monitor. --- lib/miguru/miguru.ahk | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/miguru/miguru.ahk b/lib/miguru/miguru.ahk index 2ef8d7c..c3e234a 100644 --- a/lib/miguru/miguru.ahk +++ b/lib/miguru/miguru.ahk @@ -147,7 +147,7 @@ class MiguruWM extends WMEvents { ExpectInSet(o, "mouseFollowsFocus", true, false) ExpectInSet(o, "followWindowToWorkspace", true, false) ExpectInSet(o, "followWindowToMonitor", true, false) - ExpectInSet(o, "focusWorkspaceByWindow", true, false) + ExpectInSet(o, "focusWorkspaceByWindow", true, false, "same-monitor") ExpectFunc(o, "showPopup") ExpectType(o, "focusIndicator", Object) ExpectType(o, "delays", Object) @@ -532,7 +532,8 @@ class MiguruWM extends WMEvents { ws := getWorkspace() if this._opts.focusWorkspaceByWindow { - if !req.HasProp("monitor") { + if !req.HasProp("monitor") + && this._opts.focusWorkspaceByWindow != "same-monitor" { monitor := this.activeWsMonitors.Get(ws.Index, "") if monitor { ws := this._workspaces[monitor, ws.Index] From 703caa1c99b2bcc9812ecfc275a53d38c5978b88 Mon Sep 17 00:00:00 2001 From: imawizard Date: Wed, 10 Apr 2024 18:48:40 +0200 Subject: [PATCH 2/4] feat: Add config for which window to focus on close TODO: fenster verschwinden z.B. auch bei send-to-monitor When the active window was closed, this setting decides which window is then to be focused (so kind of like the opposite of tilingInsertion). --- lib/miguru/miguru.ahk | 26 +++++++++++++++++++++++--- lib/miguru/workspaces.ahk | 6 ++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/miguru/miguru.ahk b/lib/miguru/miguru.ahk index c3e234a..2f4739f 100644 --- a/lib/miguru/miguru.ahk +++ b/lib/miguru/miguru.ahk @@ -68,6 +68,7 @@ class MiguruWM extends WMEvents { tilingMinWidth: 500, tilingMinHeight: 500, tilingInsertion: "last", + focusAfterClose: "previous", floatingAlwaysOnTop: false, focusFollowsMouse: false, @@ -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) @@ -566,6 +573,7 @@ class MiguruWM extends WMEvents { if !window { return } + ;; TODO: focusAfterClose next := window.workspace.Remove(hwnd) ws.AddIfNew(hwnd) ws.ActiveWindow := hwnd @@ -1070,9 +1078,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) @@ -1123,6 +1142,7 @@ class MiguruWM extends WMEvents { window := this._managed[hwnd] if !this._pinned.Has(hwnd) { + ;; TODO: focusAfterClose window.workspace.Remove(hwnd) } else { this._removePinnedWindow(hwnd, window) diff --git a/lib/miguru/workspaces.ahk b/lib/miguru/workspaces.ahk index 04ecc7b..c462610 100644 --- a/lib/miguru/workspaces.ahk +++ b/lib/miguru/workspaces.ahk @@ -362,6 +362,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: From 90ac3be58a4447d52dcfa54b900ca810e9101fac Mon Sep 17 00:00:00 2001 From: imawizard Date: Wed, 10 Apr 2024 18:51:25 +0200 Subject: [PATCH 3/4] fix: Possibly still treat as active after hide-close sequence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There seem to be cases where – when closing e.g. an active explorer window – a "hidden" event occurs first, then a "focus" event according to z-order and eventually a "destroyed" event. Because of the focus-switch in between the destroyed window is not the active one anymore and no window is actively set as the new active one with respects to focusAfterClose. This commit adds remembering a hidden window if it was active, and in case said window gets closed within a specific duration after being hidden, it'll be treated as a regular close event of the active window. --- lib/miguru/miguru.ahk | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/miguru/miguru.ahk b/lib/miguru/miguru.ahk index 2f4739f..0650673 100644 --- a/lib/miguru/miguru.ahk +++ b/lib/miguru/miguru.ahk @@ -97,6 +97,7 @@ class MiguruWM extends WMEvents { sendMonitorRetile: 100, pinnedWindowFocused: 100, onDisplayChange: 1000, + hideCloseSequence: 200, }, }, opts) @@ -112,6 +113,7 @@ class MiguruWM extends WMEvents { this._delayed := Timeouts() this._maybeActiveWindow := "" + this._maybeClosed := {hwnd: 0, ticks: 0} this._focusIndicator.SetMonitorList(this._monitors) windowTracking := GetSpiInt(SPI_GETACTIVEWINDOWTRACKING) @@ -1072,14 +1074,9 @@ class MiguruWM extends WMEvents { window := this._managed.Delete(hwnd) if !this._pinned.Has(hwnd) { - ;; FIXME: There seems to be cases where – when closing e.g. an - ;; explorer window – a "hidden" event occurs first, then a "focus" - ;; event according to z-order and lastly a "destroyed" event. - ;; 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. ws := window.workspace - if ws.ActiveWindow == hwnd { + if ws.ActiveWindow == hwnd || this._maybeClosed.hwnd == hwnd + && A_TickCount - this._maybeClosed.ticks <= this._delays.hideCloseSequence { wasActive := true next := ws.GetWindow(this._opts.focusAfterClose, hwnd) } else { @@ -1131,7 +1128,15 @@ class MiguruWM extends WMEvents { return } + window := this._managed[hwnd] + if wait { + if window.workspace.ActiveWindow == hwnd { + this._maybeClosed := { + hwnd: hwnd, + ticks: A_TickCount, + } + } this._delayed.Replace( this._hide.Bind(this, event, hwnd, false), this._delays.windowHidden, @@ -1140,7 +1145,6 @@ class MiguruWM extends WMEvents { return } - window := this._managed[hwnd] if !this._pinned.Has(hwnd) { ;; TODO: focusAfterClose window.workspace.Remove(hwnd) From 1c7552b6981ee3af7c5f857affbed625cd2f5e3c Mon Sep 17 00:00:00 2001 From: imawizard Date: Tue, 30 Jul 2024 13:12:18 +0200 Subject: [PATCH 4/4] x --- lib/miguru/miguru.ahk | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/miguru/miguru.ahk b/lib/miguru/miguru.ahk index 0650673..9fbe1ec 100644 --- a/lib/miguru/miguru.ahk +++ b/lib/miguru/miguru.ahk @@ -1084,7 +1084,10 @@ class MiguruWM extends WMEvents { } ws.Remove(hwnd) if wasActive { - if ws.Index == this.activeWsIdx { + if next == hwnd { + warn("!!!KACKEEEEEEEEEE") + } else if ws.Index == this.activeWsIdx { + warn(">>>> focus {}", WinInfo(next)) this._focusWindow(next, false) } else { ws.ActiveWindow := next @@ -1136,6 +1139,8 @@ class MiguruWM extends WMEvents { hwnd: hwnd, ticks: A_TickCount, } + debug(() => ["Active window might have been closed {}", + WinInfo(hwnd)]) } this._delayed.Replace( this._hide.Bind(this, event, hwnd, false),