Window Positions wrong with Aero-Snap

Posted by Steve on Thu 28 Aug 2014 02:33 AM — 7 posts, 26,534 views.

#0
GetMainWindowPosition/GetWorldWindowPosition report the window sizes incorrectly when using the 'Aero Snap' windows feature.

Steps to reproduce:
1 - Set the window and world window to some size.
2 - Use GetMainWindowPosition/GetWorldWindowPosition and notice that the sizes are reported correctly.
3 - Use 'Aero-Snap' (windowsKey+arrowKey) to snap the window to one side of the screen (MUSHClient will take up exactly half of the monitor).
4 - Use GetMainWindowPosition/GetWorldWindowPosition and notice that the sizes are still reported as the old sizes.

MUSHClient version 4.84, Windows 7 64-bit.
Australia Forum Administrator #1
Some investigating reveals that the problem is (probably) that the GetWindowPlacement function which I am using to find the window's position (placement) appears to remember the original position before using Aero Snap. Presumably this is so it can snap back later.

Now one suggested solution is to use GetWindowRect instead, which reports the current rectangle. So far, so good. That works (not that I have tested yet on Windows 7, I am still using XP).

However there is an issue if you minimize the window. Check these figures out, using the amended code:

Normal:


"top"=59
"height"=991
"left"=152
"width"=1345


Minimized:


"top"=-32000
"height"=31
"left"=-32000
"width"=160


The claimed sizes when minimized are wrong (or different, anyway). With the original code it "remembers" the size so it would report the same size whether minimized or not.

Now I don't know for sure if that would bother you, or indeed other scripters who may be relying on the current behaviour.
#2
Reported sizes when minimized are irrelevant in my case, but it is a good point that the change could affect others who rely on the current behavior. This isn't really a big deal to me, but a solution would be nice. I don't know how you feel about polluting up the API with a workaround function like "GetMainWindowPositionAero" or something to that effect. Maybe an additional function parameter that has a default value on the existing function.
Amended on Thu 28 Aug 2014 06:29 AM by Steve
Australia Forum Administrator #3
Well how about this? I am happier to make a change if its impact will be minimal (and there are possibly scripts around that use the current code, for whom the authors have gone dormant).

Let's assume you are using Lua. With Lua you can have optional arguments. We could pass down an argument which, if true, reports the "real" position and if false (the default) has the existing behaviour.
#4
I am indeed using Lua and would be ok with your proposal.
Australia Forum Administrator #5
Modified in version 4.95.

https://github.com/nickgammon/mushclient/commit/4eb9166
Amended on Thu 28 Aug 2014 11:33 PM by Nick Gammon
Australia Forum Administrator #6
Version 4.95 now available.

http://www.gammon.com.au/forum/?id=12633