Skip to content

Commit f76e33b

Browse files
author
Soham Dasgupta
committed
feat: improve toast and restore window before positioning
1 parent 255b483 commit f76e33b

File tree

2 files changed

+49
-32
lines changed

2 files changed

+49
-32
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## [v0.5.0](https://github.com/thesobercoder/polygon/compare/v0.4.0...v0.5.0) (2023-11-21)
2+
3+
### Bugs
4+
5+
- Improve toast display on quickly switching layout
6+
- Restore the window first before positioning
7+
18
## [v0.4.0](https://github.com/thesobercoder/polygon/compare/v0.3.0...v0.4.0) (2023-11-20)
29

310
### Features

polygon.ahk

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
;-- Ahk2Exe properties
77
;@Ahk2Exe-SetName Polygon
8-
;@Ahk2Exe-SetVersion 0.4.0
8+
;@Ahk2Exe-SetVersion 0.5.0
99
;@Ahk2Exe-SetCompanyName Soham Dasgupta
1010
;@Ahk2Exe-SetDescription A window manager for Windows 10/11 powered by AutoHotkey
1111

1212
;-- Globals
13-
global APP_VERSION := "0.4.0"
13+
global APP_VERSION := "0.5.0"
1414
global APP_VERSION_NAME := "v" . APP_VERSION
1515
global APP_NAME := "Polygon"
1616
global APP_REPO_OWNER := "thesobercoder"
@@ -92,9 +92,9 @@ Toast(Message, r, l, t, b) {
9292
title := APP_NAME . " 08ab0337-daeb-4b9c-b01d-11fbc97e1dcb"
9393
hWnd := WinExist(title)
9494
if (hWnd > 0)
95-
return
95+
WinClose(hWnd)
9696
toastGui := Gui()
97-
toastGui.Opt("+ToolWindow -Caption +AlwaysOnTop +Disabled")
97+
toastGui.Opt("+ToolWindow -Caption +AlwaysOnTop +Disabled +E0x20")
9898
toastGui.BackColor := "000000"
9999
toastGui.SetFont("cFFFFFF S18", "Verdana")
100100
toastGui.add("Text", "Center X0 Y90 W278 H210", Message)
@@ -104,10 +104,14 @@ Toast(Message, r, l, t, b) {
104104
WinSetExStyle(32, title)
105105
Loop 60
106106
{
107+
hWnd := WinExist(title)
108+
if (hWnd < 1)
109+
break
110+
107111
if (A_Index = 1)
108112
{
109-
WinSetTransparent(120, title)
110-
Sleep(1000)
113+
WinSetTransparent(120, hWnd)
114+
Sleep(100)
111115
}
112116
else if (A_Index = 60)
113117
{
@@ -117,7 +121,7 @@ Toast(Message, r, l, t, b) {
117121
else
118122
{
119123
TransFade := 120 - A_Index * 2
120-
WinSetTransparent(TransFade, title)
124+
WinSetTransparent(TransFade, hWnd)
121125
Sleep(1)
122126
}
123127
}
@@ -227,7 +231,7 @@ Center(*) {
227231
centerX := Ceil(((l + r) - (ofl + ofr)) / 2)
228232
centerY := Ceil(((t + b) - (ofb + oft)) / 2)
229233
;-- Move the active window to the center of the current monitor
230-
WinMove(centerX - w / 2, centerY - h / 2, w + ofl + ofr, h + oft + ofb, hWnd)
234+
WinMoveEx(centerX - w / 2, centerY - h / 2, w + ofl + ofr, h + oft + ofb, hWnd)
231235
;-- Show layout toast
232236
Toast("Center", r, l, t, b)
233237
}
@@ -242,7 +246,7 @@ CenterHD(*) {
242246
centerX := Ceil(((l + r) - (ofl + ofr)) / 2)
243247
centerY := Ceil(((t + b) - (ofb + oft)) / 2)
244248
;-- Move the active window to the center of the current monitor with desired size
245-
WinMove(Ceil(centerX - rw / 2), Ceil(centerY - rh / 2), rw + ofl + ofr, rh + oft + ofb, hWnd)
249+
WinMoveEx(Ceil(centerX - rw / 2), Ceil(centerY - rh / 2), rw + ofl + ofr, rh + oft + ofb, hWnd)
246250
;-- Show layout toast
247251
Toast("Center HD", r, l, t, b)
248252
}
@@ -255,7 +259,7 @@ CenterHalf(*) {
255259
;-- Calculate the horizontal position for centering
256260
CenterX := (l - ofl) + Ceil(((r - ofr) - (l - ofl)) / 2) - Ceil(HalfWidth / 2)
257261
;-- Set the window position to the center half of the monitor
258-
WinMove(CenterX, t - oft, HalfWidth + ofl + ofr, (b - t) + oft + ofb, hWnd)
262+
WinMoveEx(CenterX, t - oft, HalfWidth + ofl + ofr, (b - t) + oft + ofb, hWnd)
259263
;-- Show layout toast
260264
Toast("Center Half", r, l, t, b)
261265
}
@@ -268,7 +272,7 @@ CenterTwoThird(*) {
268272
;-- Calculate horizontal position for centering
269273
CenterX := (l - ofl) + Ceil(((r - ofr) - (l - ofl)) / 2) - Ceil(TwoThirdWidth / 2)
270274
;-- Set window position to center two third width
271-
WinMove(CenterX, t - oft, TwoThirdWidth + ofl + ofr, (b - t) + oft + ofb, hWnd)
275+
WinMoveEx(CenterX, t - oft, TwoThirdWidth + ofl + ofr, (b - t) + oft + ofb, hWnd)
272276
;-- Show layout toast
273277
Toast("Center Two Third", r, l, t, b)
274278
}
@@ -279,7 +283,7 @@ FirstThird(*) {
279283
;-- Calculate the width of one third of the monitor
280284
OneThirdWidth := Ceil((r - l) / 3)
281285
;-- Set the window position to the left one third of the monitor
282-
WinMove(l - ofl, t - oft, OneThirdWidth + ofr + ofl, (b - t) + oft + ofb, hWnd)
286+
WinMoveEx(l - ofl, t - oft, OneThirdWidth + ofr + ofl, (b - t) + oft + ofb, hWnd)
283287
;-- Show layout toast
284288
Toast("First Third", r, l, t, b)
285289
}
@@ -292,7 +296,7 @@ CenterThird(*) {
292296
;-- Calculate the horizontal position for centering
293297
CenterX := (l - ofl) + Ceil(((r - ofr) - (l - ofl)) / 2) - Ceil(OneThirdWidth / 2)
294298
;-- Set the window position to the center one third of the monitor
295-
WinMove(CenterX, t - oft, OneThirdWidth + ofl + ofr, (b - t) + oft + ofb, hWnd)
299+
WinMoveEx(CenterX, t - oft, OneThirdWidth + ofl + ofr, (b - t) + oft + ofb, hWnd)
296300
;-- Show layout toast
297301
Toast("Center Third", r, l, t, b)
298302
}
@@ -305,7 +309,7 @@ LastThird(*) {
305309
;-- Calculate horizontal position for right aligning
306310
RightX := (r - ofr) - OneThirdWidth
307311
;-- Set window position to right one third of monitor
308-
WinMove(RightX, t - oft, OneThirdWidth + ofl + ofr, (b - t) + oft + ofb, hWnd)
312+
WinMoveEx(RightX, t - oft, OneThirdWidth + ofl + ofr, (b - t) + oft + ofb, hWnd)
309313
;-- Show layout toast
310314
Toast("Last Third", r, l, t, b)
311315
}
@@ -316,7 +320,7 @@ TopLeftSixth(*) {
316320
;-- Calculate the width of one third of the monitor
317321
OneThirdWidth := Ceil((r - l) / 3)
318322
;-- Set the window position to the left one third of the monitor and top half of it
319-
WinMove(l - ofl, t - oft, OneThirdWidth + ofl + ofb, Ceil((b - t) / 2) + oft + ofb, hWnd)
323+
WinMoveEx(l - ofl, t - oft, OneThirdWidth + ofl + ofb, Ceil((b - t) / 2) + oft + ofb, hWnd)
320324
;-- Show layout toast
321325
Toast("Top Left Sixth", r, l, t, b)
322326
}
@@ -327,7 +331,7 @@ BottomLeftSixth(*) {
327331
;-- Calculate the width of one third of the monitor
328332
OneThirdWidth := Ceil((r - l) / 3)
329333
;-- Set the window position to left one third of monitor and bottom half of it
330-
WinMove(l - ofl, Ceil(b - (b - t) / 2), OneThirdWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
334+
WinMoveEx(l - ofl, Ceil(b - (b - t) / 2), OneThirdWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
331335
;-- Show layout toast
332336
Toast("Bottom Left Sixth", r, l, t, b)
333337
}
@@ -340,7 +344,7 @@ TopRightSixth(*) {
340344
;-- Calculate horizontal position for right aligning
341345
RightX := (r - ofr) - OneThirdWidth
342346
;-- Set window position to right one third of monitor and top half of it.
343-
WinMove(RightX, t - oft, OneThirdWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
347+
WinMoveEx(RightX, t - oft, OneThirdWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
344348
;-- Show layout toast
345349
Toast("Top Right Sixth", r, l, t, b)
346350
}
@@ -353,7 +357,7 @@ BottomRightSixth(*) {
353357
;-- Calculate horizontal position for right aligning
354358
RightX := (r - ofr) - OneThirdWidth
355359
;-- Set window position to right one third of monitor and bottom half of it
356-
WinMove(RightX, Ceil(b - (b - t) / 2), OneThirdWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
360+
WinMoveEx(RightX, Ceil(b - (b - t) / 2), OneThirdWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
357361
;-- Show layout toast
358362
Toast("Bottom Right Sixth", r, l, t, b)
359363
}
@@ -366,7 +370,7 @@ TopCenterSixth(*) {
366370
;-- Calculate the horizontal position for centering
367371
CenterX := (l - ofl) + Ceil(((r - ofr) - (l - ofl)) / 2) - Ceil(OneThirdWidth / 2)
368372
;-- Set the window position to top center one sixth of the monitor
369-
WinMove(CenterX, t - oft, OneThirdWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
373+
WinMoveEx(CenterX, t - oft, OneThirdWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
370374
;-- Show layout toast
371375
Toast("Top Center Sixth", r, l, t, b)
372376
}
@@ -379,7 +383,7 @@ BottomCenterSixth(*) {
379383
;-- Calculate the horizontal position for centering
380384
CenterX := (l - ofl) + Ceil(((r - ofr) - (l - ofl)) / 2) - Ceil(OneThirdWidth / 2)
381385
;-- Set the window position to bottom center one sixth of the monitor
382-
WinMove(CenterX, Ceil(b - (b - t) / 2), OneThirdWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
386+
WinMoveEx(CenterX, Ceil(b - (b - t) / 2), OneThirdWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
383387
;-- Show layout toast
384388
Toast("Bottom Center Sixth", r, l, t, b)
385389
}
@@ -390,7 +394,7 @@ LeftHalf(*) {
390394
;-- Calculate the width of half of the monitor
391395
HalfWidth := Ceil((r - l) / 2)
392396
;-- Set the window position to the left half of the monitor
393-
WinMove(l - ofl, t - oft, HalfWidth + ofl + ofr, (b - t) + oft + ofb, hWnd)
397+
WinMoveEx(l - ofl, t - oft, HalfWidth + ofl + ofr, (b - t) + oft + ofb, hWnd)
394398
;-- Show layout toast
395399
Toast("Left Half", r, l, t, b)
396400
}
@@ -403,7 +407,7 @@ RightHalf(*) {
403407
;-- Calculate horizontal position for right aligning
404408
RightX := (r - ofr) - HalfWidth
405409
;-- Set the window position to the right half of the monitor
406-
WinMove(RightX, t - oft, HalfWidth + ofl + ofr, (b - t) + oft + ofb, hWnd)
410+
WinMoveEx(RightX, t - oft, HalfWidth + ofl + ofr, (b - t) + oft + ofb, hWnd)
407411
;-- Show layout toast
408412
Toast("Right Half", r, l, t, b)
409413
}
@@ -414,7 +418,7 @@ TopLeft(*) {
414418
;-- Calculate the width as half of the monitor
415419
HalfWidth := Ceil((r - l) / 2)
416420
;-- Set the window position to the left half of the monitor and top half of it
417-
WinMove(l - ofl, t - oft, HalfWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
421+
WinMoveEx(l - ofl, t - oft, HalfWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
418422
;-- Show layout toast
419423
Toast("Top Left", r, l, t, b)
420424
}
@@ -427,7 +431,7 @@ TopRight(*) {
427431
;-- Calculate horizontal position for right aligning
428432
RightX := (r - ofr) - HalfWidth
429433
;-- Set the window position to start from the middle of the monitor and extend to the very right edge
430-
WinMove(RightX, t - oft, r - l - HalfWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
434+
WinMoveEx(RightX, t - oft, r - l - HalfWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
431435
;-- Show layout toast
432436
Toast("Top Right", r, l, t, b)
433437
}
@@ -440,7 +444,7 @@ BottomLeft(*) {
440444
;-- Calculate the height of half of the monitor
441445
HalfHeight := Ceil((b - t) / 2)
442446
;-- Set the window position to left one third of monitor and bottom half of it
443-
WinMove(l - ofl, Ceil(b - (b - t) / 2), HalfWidth + ofl + ofr, HalfHeight + oft + ofb, hWnd)
447+
WinMoveEx(l - ofl, Ceil(b - (b - t) / 2), HalfWidth + ofl + ofr, HalfHeight + oft + ofb, hWnd)
444448
;-- Show layout toast
445449
Toast("Bottom Left", r, l, t, b)
446450
}
@@ -453,7 +457,7 @@ BottomRight(*) {
453457
;-- Calculate horizontal position for right aligning
454458
RightX := (r - ofr) - HalfWidth
455459
;-- Set the window position to the right half of the monitor and bottom half of it
456-
WinMove(RightX, Ceil(b - (b - t) / 2), HalfWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
460+
WinMoveEx(RightX, Ceil(b - (b - t) / 2), HalfWidth + ofl + ofr, Ceil((b - t) / 2) + oft + ofb, hWnd)
457461
;-- Show layout toast
458462
Toast("Bottom Right", r, l, t, b)
459463
}
@@ -464,7 +468,7 @@ TopHalf(*) {
464468
;-- Calculate the height of half of the monitor
465469
HalfHeight := Ceil((b - t) / 2)
466470
;-- Set the window position to the left half of the monitor and top half of it
467-
WinMove(l - ofl, t - oft, Ceil((r - l)) + ofl + ofr, HalfHeight + oft + ofb, hWnd)
471+
WinMoveEx(l - ofl, t - oft, Ceil((r - l)) + ofl + ofr, HalfHeight + oft + ofb, hWnd)
468472
;-- Show layout toast
469473
Toast("Top Half", r, l, t, b)
470474
}
@@ -475,7 +479,7 @@ BottomHalf(*) {
475479
;-- Calculate the height of half of the monitor
476480
HalfHeight := Ceil((b - t) / 2)
477481
;-- Set the window position to the left half of the monitor and top half of it
478-
WinMove(l - ofl, Ceil(b - (b - t) / 2), Ceil((r - l)) + ofl + ofr, HalfHeight + oft + ofb, hWnd)
482+
WinMoveEx(l - ofl, Ceil(b - (b - t) / 2), Ceil((r - l)) + ofl + ofr, HalfHeight + oft + ofb, hWnd)
479483
;-- Show layout toast
480484
Toast("Bottom Half", r, l, t, b)
481485
}
@@ -486,7 +490,7 @@ FirstFourth(*) {
486490
;-- Calculate the width of one fourth of the monitor
487491
OneFourthWidth := Ceil((r - l) / 4)
488492
;-- Set the window position to the left one fourth of the monitor
489-
WinMove(l - ofl, t - oft, OneFourthWidth + ofr + ofl, (b - t) + oft + ofb, hWnd)
493+
WinMoveEx(l - ofl, t - oft, OneFourthWidth + ofr + ofl, (b - t) + oft + ofb, hWnd)
490494
;-- Show layout toast
491495
Toast("First Fourth", r, l, t, b)
492496
}
@@ -497,7 +501,7 @@ SecondFourth(*) {
497501
; Calculate the width of one-fourth of the monitor
498502
OneFourthWidth := Ceil((r - l) / 4)
499503
; Set the window position to the left one-fourth of the monitor
500-
WinMove(l - ofl + OneFourthWidth, t - oft, OneFourthWidth + ofr + ofl, (b - t) + oft + ofb, hWnd)
504+
WinMoveEx(l - ofl + OneFourthWidth, t - oft, OneFourthWidth + ofr + ofl, (b - t) + oft + ofb, hWnd)
501505
; Show layout toast
502506
Toast("Second Fourth", r, l, t, b)
503507
}
@@ -508,7 +512,7 @@ ThirdFourth(*) {
508512
; Calculate the width of one-fourth of the monitor
509513
OneFourthWidth := Ceil((r - l) / 4)
510514
; Set the window position to the right one-fourth of the monitor
511-
WinMove(l - ofl + 2 * OneFourthWidth, t - oft, OneFourthWidth + ofr + ofl, (b - t) + oft + ofb, hWnd)
515+
WinMoveEx(l - ofl + 2 * OneFourthWidth, t - oft, OneFourthWidth + ofr + ofl, (b - t) + oft + ofb, hWnd)
512516
; Show layout toast
513517
Toast("Third Fourth", r, l, t, b)
514518
}
@@ -519,11 +523,17 @@ LastFourth(*) {
519523
;-- Calculate the width of one fourth of the monitor
520524
OneFourthWidth := Ceil((r - l) / 4)
521525
;-- Set the window position to the right one fourth of the monitor
522-
WinMove(r - OneFourthWidth - ofr, t - oft, OneFourthWidth + ofr + ofl, (b - t) + oft + ofb, hWnd)
526+
WinMoveEx(r - OneFourthWidth - ofr, t - oft, OneFourthWidth + ofr + ofl, (b - t) + oft + ofb, hWnd)
523527
;-- Show layout toast
524528
Toast("Last Fourth", r, l, t, b)
525529
}
526530
}
531+
WinMoveEx(X := 0, Y := 0, Width := 0, Height := 0, hWnd := 0) {
532+
;-- Restore the window before moving
533+
WinRestore(hWnd)
534+
;-- Move the window to the desired position and dimension
535+
WinMove(X, Y, Width, Height, hWnd)
536+
}
527537
GetWindowRectEx(&hWindow := 0, &winX := 0, &winY := 0, &winW := 0, &winH := 0, &winOffsetLeft := 0, &winOffsetRight := 0, &winOffsetTop := 0, &winOffsetBottom := 0, &monRight := 0, &monLeft := 0, &monTop := 0, &monBottom := 0) {
528538
;-- Get the handle of the active window
529539
hWindow := WinExist("A")

0 commit comments

Comments
 (0)