Skip to content

Commit 6b61553

Browse files
author
Soham Dasgupta
committed
feat: add quarter layouts
1 parent c58f22d commit 6b61553

File tree

4 files changed

+195
-22
lines changed

4 files changed

+195
-22
lines changed

CHANGELOG.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,28 @@
22

33
### Features
44

5-
- Add toast message on layout change
6-
- Add INI file based shortcut configuration
7-
- The monitor detection mechanism now only checks if more than 50% of the window is inside the monitor to take effect.
5+
#### Layouts -
86

9-
## v0.1.0 (2023-09-16)
7+
- Added Center
8+
- Added Center 1920 x 1080
9+
- Added Center Half
10+
- Added Center Two Third
11+
- Added First Third
12+
- Added Center Third
13+
- Added Last Third
14+
- Added Top Left Sixth
15+
- Added Bottom Left Sixth
16+
- Added Top Right Sixth
17+
- Added Bottom Right Sixth
18+
- Added Top Center Sixth
19+
- Added Bottom Center Sixth
20+
- Added Top Left
21+
- Added Top Right
22+
- Added Bottom Left
23+
- Added Bottom Right
1024

11-
### Features
25+
#### Settings -
1226

13-
- Add Center
14-
- Add Center 1920 x 1080
15-
- Add Center Half
16-
- Add Center Two Third
17-
- Add First Third
18-
- Add Center Third
19-
- Add Last Third
20-
- Add Top Left Sixth
21-
- Add Bottom Left Sixth
22-
- Add Top Right Sixth
23-
- Add Bottom Right Sixth
24-
- Add Top Center Sixth
25-
- Add Bottom Center Sixth
27+
- Added toast message on layout change
28+
- Added INI file based shortcut configuration
29+
- The monitor detection mechanism now only checks if more than 50% of the window is inside the monitor to take effect.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ Here are the shortcuts available in Polygon.
4848
| :construction: | | Bottom Half |
4949
| :construction: | | First Two Thirds |
5050
| :construction: | | Last Two Thirds |
51-
| :construction: | | Top Left |
52-
| :construction: | | Top Right |
53-
| :construction: | | Bottom Left |
54-
| :construction: | | Bottom Right |
51+
| :white_check_mark: | <kbd>CTRL</kbd>+<kbd>WIN</kbd>+<kbd>U</kbd> | Top Left |
52+
| :white_check_mark: | <kbd>CTRL</kbd>+<kbd>WIN</kbd>+<kbd>I</kbd> | Top Right |
53+
| :white_check_mark: | <kbd>CTRL</kbd>+<kbd>WIN</kbd>+<kbd>J</kbd> | Bottom Left |
54+
| :white_check_mark: | <kbd>CTRL</kbd>+<kbd>WIN</kbd>+<kbd>K</kbd> | Bottom Right |
5555
| :construction: | | First Fourth |
5656
| :construction: | | Second Fourth |
5757
| :construction: | | Third Fourth |

polygon.ahk

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ global APP_SHORTCUT_TOPCENTERSIXTH := IniRead(APP_INI_FILE, APP_INI_SECTION_SHOR
2727
global APP_SHORTCUT_BOTTOMCENTERSIXTH := IniRead(APP_INI_FILE, APP_INI_SECTION_SHORTCUT, "BottomCenterSixth", "^#m")
2828
global APP_SHORTCUT_LEFTHALF := IniRead(APP_INI_FILE, APP_INI_SECTION_SHORTCUT, "LeftHalf", "^#[")
2929
global APP_SHORTCUT_RIGHTHALF := IniRead(APP_INI_FILE, APP_INI_SECTION_SHORTCUT, "RightHalf", "^#]")
30+
global APP_SHORTCUT_TOPLEFT := IniRead(APP_INI_FILE, APP_INI_SECTION_SHORTCUT, "TopLeft", "^#u")
31+
global APP_SHORTCUT_TOPRIGHT := IniRead(APP_INI_FILE, APP_INI_SECTION_SHORTCUT, "TopRight", "^#i")
32+
global APP_SHORTCUT_BOTTOMLEFT := IniRead(APP_INI_FILE, APP_INI_SECTION_SHORTCUT, "BottomLeft", "^#j")
33+
global APP_SHORTCUT_BOTTOMRIGHT := IniRead(APP_INI_FILE, APP_INI_SECTION_SHORTCUT, "BottomRight", "^#k")
3034

3135
;--Tooltip
3236
A_IconTip := APP_NAME
@@ -132,6 +136,10 @@ Hotkey(APP_SHORTCUT_TOPCENTERSIXTH, TopCenterSixth)
132136
Hotkey(APP_SHORTCUT_BOTTOMCENTERSIXTH, BottomCenterSixth)
133137
Hotkey(APP_SHORTCUT_LEFTHALF, LeftHalf)
134138
Hotkey(APP_SHORTCUT_RIGHTHALF, RightHalf)
139+
Hotkey(APP_SHORTCUT_TOPLEFT, TopLeft)
140+
Hotkey(APP_SHORTCUT_TOPRIGHT, TopRight)
141+
Hotkey(APP_SHORTCUT_BOTTOMLEFT, BottomLeft)
142+
Hotkey(APP_SHORTCUT_BOTTOMRIGHT, BottomRight)
135143

136144
Center(*)
137145
{
@@ -721,6 +729,163 @@ RightHalf(*)
721729
}
722730
}
723731

732+
TopLeft(*)
733+
{
734+
;-- Get the handle of the active window
735+
hWnd := WinExist("A")
736+
if (hWnd <= 0)
737+
return
738+
739+
;-- Get the number of monitors
740+
MonitorCount := MonitorGetCount()
741+
742+
;-- Get the dimensions of the current window
743+
WinGetPosEx(hWnd, &x, &y, &w, &h, &ofl, &oft, &ofr, &ofb)
744+
745+
;-- Loop through each monitor to find which one contains the active window
746+
Loop MonitorCount
747+
{
748+
;-- Get the dimensions of the current monitor
749+
MonitorGetWorkArea(A_Index, &l, &t, &r, &b)
750+
751+
;-- Check if the active window is within the current monitor
752+
if (CheckWindowWithinMonitor(x, y, w, h, ofl, ofr, oft, ofb, r, l, t, b))
753+
{
754+
;-- Calculate the width as half of the monitor
755+
HalfWidth := Ceil((r - l) / 2)
756+
757+
;-- Set the window position to the left half of the monitor and top half of it
758+
WinMove(l - ofl, t - oft, HalfWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
759+
760+
;-- Show layout toast
761+
Toast("Top Left", r, l, t, b)
762+
763+
;-- Exit the loop since we found the correct monitor
764+
break
765+
}
766+
}
767+
}
768+
769+
TopRight(*)
770+
{
771+
;-- Get the handle of the active window
772+
hWnd := WinExist("A")
773+
if (hWnd <= 0)
774+
return
775+
776+
;-- Get the number of monitors
777+
MonitorCount := MonitorGetCount()
778+
779+
;-- Get the dimensions of the current window
780+
WinGetPosEx(hWnd, &x, &y, &w, &h, &ofl, &oft, &ofr, &ofb)
781+
782+
;-- Loop through each monitor to find which one contains the active window
783+
Loop MonitorCount
784+
{
785+
;-- Get the dimensions of the current monitor
786+
MonitorGetWorkArea(A_Index, &l, &t, &r, &b)
787+
788+
;-- Check if the active window is within the current monitor
789+
if (CheckWindowWithinMonitor(x, y, w, h, ofl, ofr, oft, ofb, r, l, t, b))
790+
{
791+
;-- Calculate the width as half of the monitor
792+
HalfWidth := Ceil((r - l) / 2)
793+
794+
;-- Calculate horizontal position for right aligning
795+
RightX := (r - ofr) - HalfWidth
796+
797+
;-- Set the window position to start from the middle of the monitor and extend to the very right edge
798+
WinMove(RightX, t - oft, r - l - HalfWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
799+
800+
;-- Show layout toast
801+
Toast("Top Right", r, l, t, b)
802+
803+
;-- Exit the loop since we found the correct monitor
804+
break
805+
}
806+
}
807+
}
808+
809+
BottomLeft(*)
810+
{
811+
;-- Get the handle of the active window
812+
hWnd := WinExist("A")
813+
if (hWnd <= 0)
814+
return
815+
816+
;-- Get the number of monitors
817+
MonitorCount := MonitorGetCount()
818+
819+
;-- Get the dimensions of the current window
820+
WinGetPosEx(hWnd, &x, &y, &w, &h, &ofl, &oft, &ofr, &ofb)
821+
822+
;-- Loop through each monitor to find which one contains the active window
823+
Loop MonitorCount
824+
{
825+
;-- Get the dimensions of the current monitor
826+
MonitorGetWorkArea(A_Index, &l, &t, &r, &b)
827+
828+
;-- Check if the active window is within the current monitor
829+
if (CheckWindowWithinMonitor(x, y, w, h, ofl, ofr, oft, ofb, r, l, t, b))
830+
{
831+
;-- Calculate the width of half of the monitor
832+
HalfWidth := Ceil((r - l) / 2)
833+
834+
;-- Calculate the height of half of the monitor
835+
HalfHeight := Ceil((b - t) / 2)
836+
837+
;-- Set the window position to left one third of monitor and bottom half of it
838+
WinMove(l - ofl, Ceil(b - (b - t) / 2), HalfWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
839+
840+
;-- Show layout toast
841+
Toast("Bottom Left", r, l, t, b)
842+
843+
;-- Exit the loop since we found the correct monitor
844+
break
845+
}
846+
}
847+
}
848+
849+
BottomRight(*)
850+
{
851+
;-- Get the handle of the active window
852+
hWnd := WinExist("A")
853+
if (hWnd <= 0)
854+
return
855+
856+
;-- Get the number of monitors
857+
MonitorCount := MonitorGetCount()
858+
859+
;-- Get the dimensions of the current window
860+
WinGetPosEx(hWnd, &x, &y, &w, &h, &ofl, &oft, &ofr, &ofb)
861+
862+
;-- Loop through each monitor to find which one contains the active window
863+
Loop MonitorCount
864+
{
865+
;-- Get the dimensions of the current monitor
866+
MonitorGetWorkArea(A_Index, &l, &t, &r, &b)
867+
868+
;-- Check if the active window is within the current monitor
869+
if (CheckWindowWithinMonitor(x, y, w, h, ofl, ofr, oft, ofb, r, l, t, b))
870+
{
871+
;-- Calculate the width as half of the monitor
872+
HalfWidth := Ceil((r - l) / 2)
873+
874+
;-- Calculate horizontal position for right aligning
875+
RightX := (r - ofr) - HalfWidth
876+
877+
;-- Set the window position to the right half of the monitor and bottom half of it
878+
WinMove(RightX, Ceil(b - (b - t) / 2), HalfWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
879+
880+
;-- Show layout toast
881+
Toast("Bottom Right", r, l, t, b)
882+
883+
;-- Exit the loop since we found the correct monitor
884+
break
885+
}
886+
}
887+
}
888+
724889
CheckWindowWithinMonitor(winX, winY, winW, winH, winOffsetLeft, winOffsetRight, winOffsetTop, winOffsetBottom, monRight, monLeft, monTop, monBottom)
725890
{
726891
; Calculate the coordinates of the corners of the window

polygon.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ TopCenterSixth="^#n"
1414
BottomCenterSixth="^#m"
1515
LeftHalf="^#["
1616
RightHalf="^#]"
17+
TopLeft="^#u"
18+
TopRight="^#i"
19+
BottomLeft="^#j"
20+
BottomRight="^#k"
1721

1822
[Toast]
1923
Show=1

0 commit comments

Comments
 (0)