Last active
May 21, 2019 10:45
-
-
Save FunkMonkey/df5c93d8ac216db52e7c to your computer and use it in GitHub Desktop.
Window Set Iterator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. | |
; #Warn ; Enable warnings to assist with detecting common errors. | |
SendMode Input ; Recommended for new scripts due to its superior speed and reliability. | |
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. | |
; ATTENTION: requires Autohotkey_L | |
; TODO: changing currentWindowSet via hotkey | |
; ====================================== | |
; Code | |
; ====================================== | |
#WinActivateForce ; prevent flashing of taskbar buttons | |
windowSets := {} | |
currentWindowSet := 1 | |
indexOf(array, item) { | |
for index, value in array { | |
if(value == item) | |
return index | |
} | |
return 0 | |
} | |
insertIntoWindowSet(set, winId) { | |
; find duplicates | |
index := indexOf(set, winId) | |
if( index != 0) { | |
return | |
} | |
set.insert(winId) | |
} | |
removeFromWindowSet(set, winId) { | |
; find it | |
index := indexOf(set, winId) | |
if( index != 0) { | |
set.Remove(index) | |
} | |
} | |
getOrCreateSet(setIndex) { | |
global windowSets | |
set := windowSets[setIndex] | |
if( !set ) { | |
set := [] | |
windowSets[setIndex] := set | |
} | |
return set | |
} | |
showWindow(winID) { | |
WinActivate, ahk_id %winID% | |
} | |
nextWindowInSet(set, currWinID) { | |
if( set.MaxIndex() == 0) { | |
return | |
} | |
index := indexOf(set, currWinID) | |
if ( index == 0 || index + 1 > set.MaxIndex()) | |
showWindow(set[1]) | |
else | |
showWindow(set[index + 1]) | |
} | |
previousWindowInSet(set, currWinID) { | |
if( set.MaxIndex() == 0) { | |
return | |
} | |
index := indexOf(set, currWinID) | |
if ( index == 0 || index - 1 < 1) | |
showWindow(set[set.MaxIndex()]) | |
else | |
showWindow(set[1]) | |
} | |
; ====================================== | |
; Hotkeys | |
; ====================================== | |
^#a:: | |
WinGet, activeWindowID, ID, A | |
set := getOrCreateSet(currentWindowSet) | |
insertIntoWindowSet(set, activeWindowID) | |
return | |
^#s:: | |
WinGet, activeWindowID, ID, A | |
set := getOrCreateSet(currentWindowSet) | |
removeFromWindowSet(set, activeWindowID) | |
return | |
^#Right:: | |
WinGet, activeWindowID, ID, A | |
set := getOrCreateSet(currentWindowSet) | |
nextWindowInSet(set, activeWindowID) | |
return | |
^#Left:: | |
WinGet, activeWindowID, ID, A | |
set := getOrCreateSet(currentWindowSet) | |
nextWindowInSet(set, activeWindowID) | |
return |
hi, i created a version with close a window bug fix
also changed the key combination to alt+shift from ctrl+super
https://gist.github.com/saim-doruklu/844bcd127d3d88a4732e6f2af1b112cd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is still a bug, when you close a window that has been added to the list. This will prevent cycling. Gonna fix that soon.
Also: It was build in a way, that multiple window sets are possible. Any ideas, how window set switching should work? Cycling through window sets or having a hotkey for each set?