Gaps in Windows....

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
almworkcivil53
Posts: 3
Joined: 14 Sep 2023, 03:29

Gaps in Windows....

Post by almworkcivil53 » 14 Sep 2023, 04:22

Dear AHK Team

Assalamulaiaum...

Hopping for your good health and safety....

I use a AHKv2 script, on windows 11, for setting up and arranging windows on my desktop screen(one monitor only). The script is stated at the end of the thread for your reference.

Please note the following snapshot with issues.
snap shot with issues.png
snap shot with issues.png (272.71 KiB) Viewed 918 times
To explain the issue, as you can see, there are gaps among the windows.

I would request anyone to kindly point out the issues, and guide me about the script, so that these gaps among the windows can removed.
A solution script would be a great help in this regard.

Just a History for reference. Using the same script with AHKv1(with minor modifications) in windows 7, there was no problem. As per my understanding, this is due to the borders of windows, which get modified during win7 to win11 transition.

Code: Select all

<^<!Numpad5::      ;first select window then press LCtrl+LAlt+5 to move active window to centre
{
WinMove (A_ScreenWidth/6), (A_ScreenHeight/6), (A_ScreenWidth*2/3), (A_ScreenHeight*2/3), "A"
return
}

<^<!Numpad4::       ;first select window then press LCtrl+LAlt+4 to move active window to left
{
WinMove 0, 0, (A_ScreenWidth*0.500), (A_ScreenHeight*1.00), "A"
return
}

<^<!Numpad6::       ;first select window then press LCtrl+LAlt+6 to move active window to right
{
WinMove (A_ScreenWidth*0.500), 0, (A_ScreenWidth*0.500), (A_ScreenHeight*1.00), "A"
return
}

<^<!Numpad8::       ;first select window then press LCtrl+LAlt+8 to move active window to top
{
WinMove 0, 0, (A_ScreenWidth), (A_ScreenHeight/2), "A"
return
}

<^<!Numpad2::       ;first select window then press LCtrl+LAlt+2 to move active window to bottom
{
WinMove 0, (A_ScreenHeight/2), (A_ScreenWidth), (A_ScreenHeight/2), "A"
return
}

<^<!Numpad7::        ;first select window then press LCtrl+LAlt+7 to move active window to left top
{
WinMove 0, 0, (A_ScreenWidth/2), (A_ScreenHeight/2), "A"
return
}

<^<!Numpad1::        ;first select window then press LCtrl+LAlt+1 to move active window to left bottom
{
WinMove 0, (A_ScreenHeight/2), (A_ScreenWidth/2), (A_ScreenHeight/2), "A"
return
}

<^<!Numpad9::         ;first select window then press LCtrl+LAlt+9 to move active window to right top
{
WinMove (A_ScreenWidth/2), 0, (A_ScreenWidth/2), (A_ScreenHeight/2), "A"
return
}

<^<!Numpad3::          ;first select window then press LCtrl+LAlt+3 to move active window to right top
{
WinMove (A_ScreenWidth/2), (A_ScreenHeight/2), (A_ScreenWidth/2), (A_ScreenHeight/2), "A"
return
}

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Gaps in Windows....

Post by mikeyww » 14 Sep 2023, 08:04

Welcome to this AutoHotkey forum!

There are other posts about this-- essentially, the actual window width might not be exactly how it appears on the screen; a Windows phenomenon probably relating to rendering of window borders. I'm not sure whether a real solution was posted; may depend on specific Windows theme being used, though I'm not sure. Could search the forum to learn more. I imagine that a solution is possible, since window snapping is possible, etc.

User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: Gaps in Windows....

Post by boiler » 14 Sep 2023, 08:32


User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Gaps in Windows....

Post by FanaticGuru » 14 Sep 2023, 13:13

almworkcivil53 wrote:
14 Sep 2023, 04:22
As per my understanding, this is due to the borders of windows, which get modified during win7 to win11 transition.

Newer versions of Windows added a translucent drop shadow effect to windows. This effect is achieved by making the GUI (the area humans think of as the window) smaller and leaving room for this drop shadow effect at the edges of windows. Your example picture is showing windows touching by their true dimensions of the outer most limits of their graphical effects.

So now windows have an offset to deal with this translucent border around the GUI of windows. Hopefully WinGetPosEx will help you sort this translucent border out.

Also, when dealing with AHK GUI this problem can arise because similar commands can give different results because one is assuming the window size and position with the drop shadow and the other is without.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

ludamo
Posts: 44
Joined: 25 Mar 2015, 02:21

Re: Gaps in Windows....

Post by ludamo » 14 Sep 2023, 20:08

Depending on whether you want to change a registry value, you might also look at a program called Winaero Tweaker and the Customize Window Borders section where you can reduce the Border padding at will (for Win 10 at least).

almworkcivil53
Posts: 3
Joined: 14 Sep 2023, 03:29

Re: Gaps in Windows....

Post by almworkcivil53 » 14 Sep 2023, 23:58

Dear AHK Team

Much Thanks for your value able support and guidance in this regards.

As I already mentioned, that using the same script on windows & with AHKv1, was OK.

Can any tell me how much in pixels that gap is, for one window? I can use Mathematics to incorporate it in my script.

Again I much grateful for your time and efforts in this regards.


Yours Sincerely

almworkcivil53

User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: Gaps in Windows....

Post by boiler » 15 Sep 2023, 00:07

Use WinGetPos and WinGetPosEx and calculate the differences.

ntepa
Posts: 439
Joined: 19 Oct 2022, 20:52

Re: Gaps in Windows....

Post by ntepa » 15 Sep 2023, 03:01

I added the function WinMoveEx to move windows with offset correction:

Code: Select all

#Requires autohotkey v2.0

<^<!Numpad5::      ;first select window then press LCtrl+LAlt+5 to move active window to centre
{
WinMoveEx (A_ScreenWidth/6), (A_ScreenHeight/6), (A_ScreenWidth*2/3), (A_ScreenHeight*2/3), "A"
return
}

<^<!Numpad4::       ;first select window then press LCtrl+LAlt+4 to move active window to left
{
WinMoveEx 0, 0, (A_ScreenWidth*0.500), (A_ScreenHeight*1.00), "A"
return
}

<^<!Numpad6::       ;first select window then press LCtrl+LAlt+6 to move active window to right
{
WinMoveEx (A_ScreenWidth*0.500), 0, (A_ScreenWidth*0.500), (A_ScreenHeight*1.00), "A"
return
}

<^<!Numpad8::       ;first select window then press LCtrl+LAlt+8 to move active window to top
{
WinMoveEx 0, 0, (A_ScreenWidth), (A_ScreenHeight/2), "A"
return
}

<^<!Numpad2::       ;first select window then press LCtrl+LAlt+2 to move active window to bottom
{
WinMoveEx 0, (A_ScreenHeight/2), (A_ScreenWidth), (A_ScreenHeight/2), "A"
return
}

<^<!Numpad7::        ;first select window then press LCtrl+LAlt+7 to move active window to left top
{
WinMoveEx 0, 0, (A_ScreenWidth/2), (A_ScreenHeight/2), "A"
return
}

<^<!Numpad1::        ;first select window then press LCtrl+LAlt+1 to move active window to left bottom
{
WinMoveEx 0, (A_ScreenHeight/2), (A_ScreenWidth/2), (A_ScreenHeight/2), "A"
return
}

<^<!Numpad9::         ;first select window then press LCtrl+LAlt+9 to move active window to right top
{
WinMoveEx (A_ScreenWidth/2), 0, (A_ScreenWidth/2), (A_ScreenHeight/2), "A"
return
}

<^<!Numpad3::          ;first select window then press LCtrl+LAlt+3 to move active window to right bottom
{
WinMoveEx (A_ScreenWidth/2), (A_ScreenHeight/2), (A_ScreenWidth/2), (A_ScreenHeight/2), "A"
return
}

WinGetPosEx(&X?, &Y?, &W?, &H?, hwnd*) {
    static DWMWA_EXTENDED_FRAME_BOUNDS := 9
    hwnd := WinExist(hwnd*)
    DllCall("dwmapi\DwmGetWindowAttribute"
            , "ptr" , hwnd
            , "uint", DWMWA_EXTENDED_FRAME_BOUNDS
            , "ptr" , RECT := Buffer(16, 0)
            , "uint", RECT.size
            , "uint")
    X := NumGet(RECT, 0, "int")
    Y := NumGet(RECT, 4, "int")
    W := NumGet(RECT, 8, "int") - X
    H := NumGet(RECT, 12, "int") - Y
}

WinMoveEx(X?, Y?, W?, H?, hwnd*) {
    hwnd := WinExist(hwnd*)
    ; compare pos and get offset
    WinGetPosEx(&fX, &fY, &fW, &fH, hwnd)
    WinGetPos(&wX, &wY, &wW, &wH, hwnd)
    xDiff := fX - wX
    hDiff := wH - fH
    pixel := 1
    ; new X, Y, W, H with offset corrected.
    IsSet(X) && nX := X - xDiff - pixel
    IsSet(Y) && nY := Y - pixel
    IsSet(W) && nW := W + (xDiff + pixel) * 2
    IsSet(H) && nH := H + hDiff + (pixel * 2)
    WinMove(nX?, nY?, nW?, nH?, hwnd?)
}

User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Gaps in Windows....

Post by FanaticGuru » 15 Sep 2023, 15:47

almworkcivil53 wrote:
14 Sep 2023, 23:58
Can any tell me how much in pixels that gap is, for one window? I can use Mathematics to incorporate it in my script.

It is not a specific amount as it varies based on things like resolution. But Windows provides a way to retrieve this gap size as shown by others in this thread.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

almworkcivil53
Posts: 3
Joined: 14 Sep 2023, 03:29

Re: Gaps in Windows....

Post by almworkcivil53 » 17 Sep 2023, 14:05

Dear AHK Team

Assalamualiqum....Brothers and Sisters.

Much Thanks @ntepa , @boiler , @mikeyww , @FanaticGuru For your support in this regards....

The Solution proposed by all and implemented by @ntepa is working flawlessly.....I pray for all of your family and friends to have a happy and better life....

As per my understanding the script is doing the following steps(just a brief explanation)

1. Custom function WinGetPosEx gets the extended/correct size of window frame.
2 The difference of output of WinGetPosEx with output of WinGetPos gives,

xDiff = horizontal difference
hDiff = vertical difference

3. Custom function WinMoveEx combines step 2 and add the differences to the values i.e.
X Y W and H.

4.Hence, the Gap between Windows is gone for Good.

Much Clever and Indeed, understandable.... :)

Much Thanks Again @ntepa, for doing the scripting work for me.... :)

My issue is resolved, I consider this thread closed, however anyone can use the details and the information shared here as reference development work.

Yours Sincerely
almworkcivil53

User avatar
chupocro
Posts: 8
Joined: 03 Nov 2023, 20:53

Re: Gaps in Windows....

Post by chupocro » 05 Nov 2023, 14:57

I tested that script but it wasn't pixel perfect with every window. Here I posted the script which was pixel perfect with every window I tested.

Post Reply

Return to “Ask for Help (v2)”