From e1d6b8b038b5ae5c6c130a016ef358bc3b2648a3 Mon Sep 17 00:00:00 2001 From: Ben Allred Date: Wed, 6 Jan 2016 18:55:43 -0700 Subject: [PATCH] Maintain snap position when moving across monitors (Win+Shift+Left/Right) --- Modules/SettingsGui.ahk | 2 +- Modules/Snapper.ahk | 16 +++++++++++++++- SnapX.ahk | 35 ++++++++++++++++++++++++----------- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Modules/SettingsGui.ahk b/Modules/SettingsGui.ahk index ef78b71..231f230 100644 --- a/Modules/SettingsGui.ahk +++ b/Modules/SettingsGui.ahk @@ -78,7 +78,7 @@ class SettingsGui GuiControlGet, checkForUpdates, Settings:, SettingsGui_CheckForUpdates this.settings.horizontalSections := horizontalSections - this.settings.verticalSections := verticalSections + this.settings.verticalSections := verticalSections this.settings.runOnStartup := runOnStartup this.settings.checkForUpdates := checkForUpdates diff --git a/Modules/Snapper.ahk b/Modules/Snapper.ahk index 7f49213..1551207 100644 --- a/Modules/Snapper.ahk +++ b/Modules/Snapper.ahk @@ -73,6 +73,20 @@ debug.write(" action: minimize") widthFactor := mon.workarea.w / this.settings.horizontalSections heightFactor := mon.workarea.h / this.settings.verticalSections + ; state: restored + if (!window.snapped) + { + ; action: nothing + if (!(horizontalDirection || horizontalSize || verticalDirection || verticalSize)) + { + return + } + ; action: anything + ; or state: snapped + ; action: nothing (need to resnap for some reason) + ; (continue) + } + ; state: minimized if (minMaxState < 0) { @@ -163,7 +177,7 @@ debug.write(" action: restore unsnapped") } ; action: all -debug.write(" action: " (horizontalDirection ? "move horizontal" : horizontalSize ? "resize horizontal" : verticalDirection ? "move vertical" : verticalSize ? "resize vertical" : "what?")) +debug.write(" action: " (horizontalDirection ? "move horizontal" : horizontalSize ? "resize horizontal" : verticalDirection ? "move vertical" : verticalSize ? "resize vertical" : "snap")) this.LastOperation := Operation.Moved window.grid.left := window.grid.left + horizontalDirection window.grid.left := window.grid.left + (horizontalSize < 0 && window.grid.left != 0 && window.grid.left + window.grid.width >= this.settings.horizontalSections ? 1 : 0) ; keep right edge attached to monitor edge if shrinking diff --git a/SnapX.ahk b/SnapX.ahk index ada3cf5..5ad3655 100644 --- a/SnapX.ahk +++ b/SnapX.ahk @@ -83,14 +83,27 @@ snapper := new Snapper(settings) #MaxThreadsBuffer On -#Left::snapper.moveWindow(-1, 0, 0, 0) -#!Left::snapper.moveWindow(-1, 0, 0, 0) -#Right::snapper.moveWindow(1, 0, 0, 0) -#!Right::snapper.moveWindow(1, 0, 0, 0) -#!Up::snapper.moveWindow(0, 0, -1, 0) -#!Down::snapper.moveWindow(0, 0, 1, 0) - -#Up::snapper.moveWindow(0, 1, 0, 0) -#Down::snapper.moveWindow(0, -1, 0, 0) -#PgUp::snapper.moveWindow(0, 0, 0, 1) -#PgDn::snapper.moveWindow(0, 0, 0, -1) \ No newline at end of file +; horizontal sizing and direction +#Left::snapper.moveWindow(-1, 0, 0, 0) ; move left +#!Left::snapper.moveWindow(-1, 0, 0, 0) ; move left +#Right::snapper.moveWindow(1, 0, 0, 0) ; move right +#!Right::snapper.moveWindow(1, 0, 0, 0) ; move right +#Up::snapper.moveWindow(0, 1, 0, 0) ; increase width +#Down::snapper.moveWindow(0, -1, 0, 0) ; decrease width + +; vertical sizing and direction +#!Up::snapper.moveWindow(0, 0, -1, 0) ; move up +#!Down::snapper.moveWindow(0, 0, 1, 0) ; move down +#PgUp::snapper.moveWindow(0, 0, 0, 1) ; size height toward top +#PgDn::snapper.moveWindow(0, 0, 0, -1) ; size height toward bottom + +; movement between multiple monitors +; sleep allows time for Windows to do the movement to the new monitor before we re-snap according to the new monitor's width/height +~#+Left:: + Sleep, 10 + snapper.moveWindow(0, 0, 0, 0) + return +~#+Right:: + Sleep, 10 + snapper.moveWindow(0, 0, 0, 0) + return \ No newline at end of file