Skip to content

Cycle through window positions via hotkeys in Windows

Notifications You must be signed in to change notification settings

jdleslie/AHK-WindowGrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

AHK-WindowGrid

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

Grid Format

  • 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 a 6x4 grid 5:3 is the bottom right tile

  • Format examples: 2x2 0:1 0:1 or 6x4 0:2 3:3, 0:0 3:3, 3x2 0:0 1:1 for multiple cyclable presets

    gTile Preset specification illustrated

  • 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.g 6x4 0:2 3:3, 8x6 0:0 3:3)

Note: Above explanation is borrowed directly from gTile

Examples

WindowGrid.CycleWindowPosition accepts parameters:

  • WinTitle is any AHK WinTitle query, e.g. A is the current active window
  • Positions is a string of window locations to advance on each invocation, in a cyle. Syntax is described above in Grid Format
  • Condition* any number of AHK Func objects can be suppled. These filter and sort the entries established in Positions to achieve dynamic functionality, e.g.
    1. Remove locations that are below a minimum width
    2. Reverse the order of positions to allow forward and backward cycles
    3. etc.

See example.ahk for more.

Active Window snaps to 1/2 width, full height

Ctrl+Alt+2

^!2::WindowGrid.CycleWindowPosition("A", "2x1 0:0, 4x1 1:0 2:0, 2x1 1:1")

Active window snaps to 1/3 width, half and full height

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))

Align preset windows, if they exist, to known locations

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")
	}

References

  • 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

About

Cycle through window positions via hotkeys in Windows

Resources

Stars

Watchers

Forks

Releases

No releases published