Cycle through window positions on a grid system of your design, inspired by the gTile extension for Gnome.
I created this to streamline workflow on a 21:9 ultra-widescreen display where I like to organize windows as 25%, 50%, 25% so my main task is in the center. Halves, thirds, and quarters are also useful. Perhaps this will be helpful for you as well!
Works for me with AutoHotKey (AHK) 1.1.30
-
Format: grid size, top left corner tile, bottom right corner tile
-
Coordinate origin: The tile at
0:0
always corresponds to the top left, no matter the grid size. In a6x4
grid5:3
is the bottom right tile -
Format examples:
2x2 0:1 0:1
or6x4 0:2 3:3, 0:0 3:3, 3x2 0:0 1:1
for multiple cyclable presets -
Grid size format variants can either reuse the last grid format (e.g
6x4 0:2 3:3, 0:0 3:3
) or define a new grid (e.g6x4 0:2 3:3, 8x6 0:0 3:3
)
Note: Above explanation is borrowed directly from gTile
WindowGrid.CycleWindowPosition
accepts parameters:
WinTitle
is any AHK WinTitle query, e.g.A
is the current active windowPositions
is a string of window locations to advance on each invocation, in a cyle. Syntax is described above in Grid FormatCondition*
any number of AHK Func objects can be suppled. These filter and sort the entries established inPositions
to achieve dynamic functionality, e.g.- Remove locations that are below a minimum width
- Reverse the order of positions to allow forward and backward cycles
- etc.
See example.ahk
for more.
Ctrl+Alt+2
^!2::WindowGrid.CycleWindowPosition("A", "2x1 0:0, 4x1 1:0 2:0, 2x1 1:1")
Ctrl+Alt+3, Shift reverses direction of cycle
^!3::
+^!3::WindowGrid.CycleWindowPosition("A"
, "3x1 0:0, 1:0, 2:0,"
. "3x2 0:0, 0:1, 1:0, 1:1, 2:0, 2:1"
, WindowGrid.MinimumWidth
, WindowGrid.Toggle("+", WindowGrid.Reversed))
Ctrl+Alt+0
^!0::
SnapApplicationWindows() {
; notepad.exe in top left
WindowGrid.CycleWindowPosition("ahk_exe notepad.exe", "4x3 0:0")
; winver.exe in center third
WindowGrid.CycleWindowPosition("ahk_exe winver.exe", "3x3 1:1")
}
- gTile Gnome shell extension offers similar functionality
- MacOS has lots of options. I use Rectangle with success, but it is not as flexible
- AHK methods similar to AdvancedWindowSnap and its forks
- Uses WinGetPosEx to calculate true window dimensions (Aero/DWM makes this a nontrivial task with each major Windows release)
- Uses
GetMonitorIndexForWindow
, which seems to be widely permuted on the AHK forums and GitHub