ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

Desperate app request - restore window positions after wake from sleep scrambles

<< < (3/13) > >>

mouser:
Let me get skwire to upload the tool he wrote for me to WM_DISPLAYCHANGE events and log monitor positions, it's what we used to try to figure out what was going on..

Let me try to describe my setup:

I have 4 monitors.  My pc never sleeps or hibernates, but the monitors to go to sleep and turn off after about 30 minutes.  So when I wake up after 8 hours, and first come to the pc, that is when windows move all over the place.  Presumably because one or more of the monitors does not wake up in time.

Importantly: The movement of windows seems NOT to happen when the monitors first go to sleep.. it happens only at the time of waking up(!)
It seems at wake up time is when windows gets confused.

Here is what we saw one day when looking at the WM_DISPLAYCHANGE events:

The situation after a few hours of sleep:


--- Code: Text ---Hourly check...2017-05-10 09:52:44 AM ------------------------------ Monitor Count:  4Primary Monitor:        1 Monitor:        #1Name:   \\.\DISPLAY1Res:    2560 x 1440Left:   0 (0 working)Top:    0 (0 working)Right:  2560 (2560 working)Bottom: 1440 (1410 working) Monitor:        #2Name:   \\.\DISPLAY5Res:    2560 x 1440Left:   2560 (2560 working)Top:    0 (0 working)Right:  5120 (5120 working)Bottom: 1440 (1410 working) Monitor:        #3Name:   \\.\DISPLAY6Res:    1440 x 2560Left:   -1440 (-1440 working)Top:    -601 (-601 working)Right:  0 (0 working)Bottom: 1959 (1929 working) Monitor:        #4Name:   \\.\DISPLAY2Res:    1920 x 1080Left:   -3360 (-3360 working)Top:    180 (180 working)Right:  -1440 (-1440 working)Bottom: 1260 (1260 working)
Everything is fine at this point.. but here is what happens when i press keyboard and "wake up" the monitors:


--- Code: Text ---WM_DISPLAYCHANGE event...2017-05-10 10:02:05 AM ------------------------------ Monitor Count:  3Primary Monitor:        1 Monitor:        #1Name:   \\.\DISPLAY1Res:    1920 x 1080Left:   0 (0 working)Top:    0 (0 working)Right:  1920 (2560 working)Bottom: 1080 (1410 working) Monitor:        #2Name:   \\.\DISPLAY5Res:    2560 x 1440Left:   2560 (2560 working)Top:    0 (0 working)Right:  5120 (5120 working)Bottom: 1440 (1410 working) Monitor:        #3Name:   \\.\DISPLAY6Res:    1440 x 2560Left:   -1440 (-1440 working)Top:    -601 (-601 working)Right:  0 (0 working)Bottom: 1959 (1929 working)

Note that it has actually "lost" one of my monitors at this point.. And even more frustrating, another WM_DISPLAYCHANGE event is *NOT* sent when it eventually sees it a few seconds later..


SO I am guessing that the procedure will have to look something like this:

1. Save windows positions occasionally.
2. When a WM_DISPLAYCHANGE event occurs, do NOT assume it is a correct thing.. Instead, use it to start a timer, which will RECHECK monitor situation after a few seconds.
3. After the delay has passed and the monitors come back, get current real monitor locations and restore any windows locations that have changed.


So I can think of a few ways a program could work that would make me happy, perhaps the simplest would be something like this:
a) let me tell the program when my monitors are in there "normal" configuration (ie just select a menu operation).
b) when the monitors are in this state, the program can save windows locations periodically -- or in fact since we know that the OS doesn't actually have any problem while the monitors are asleep, you could simply save window positions ONCE, when the monitors fall asleep]
c) when you get a WM_DISPLAYCHANGE message, set a timer that has you check monitor configurations occasionally, and WAIT UNTIL THE "GOOD" (normal) monitor configuration comes back
d) that is when the windows should be restored.

Step C is the key part -- you are essentially detecting a WM_DISPLAYCHANGE message as a "signal" that the monitors are in an UNSTABLE state that is likely to bounce around for the next few seconds, and cannot be trusted.  This is where MS Windows messes up windows positions.  So then the key is to just WAIT until the monitors come back to their "normal" configuration (and don't assume you will get a WM_DISPLAYCHANGE message when they do, you just have to wait a few seconds and/or check their state).  Then when the monitors are back to "normal" the window positions can be restored.

Does that make sense?

skrommel:
Try the latest version. I added monitor sleep detection, and logs power events to log.txt.

mouser:
Ideally once the basic operations were working, one could experiment with ways to reduce unneeded operations and cpu usage..  That is, it would be nice if one could find ways to only have to save window positions once right before the problem (which might be possible if one could get a signal that happened when monitors fall asleep, or only once after the computer has been idle for at least monitor-sleep-time, say 30 minutes), so that window positions would not have to be saved frequently during normal pc use.

And another tweak would be to eventually not use my suggestion of the user specifying when the monitors are in the the "normal" configuration, perhaps by this same mechanism -- by assuming that when you do your one-time save of window positions after some long idle time (or after monitor sleep time), then THAT is the normal configuration, and updating what you consider the normal configuration when the monitors fall asleep...

Again both ideas are based on my observation that the problem happens at the time that the monitors WAKE UP from being asleep -- not when they fall asleep.

mouser:
And needless to say, your application would have other uses besides saving my sanity -- i'm sure there are people that would like to be able to save and restore window positions manually to help them with different tasks.  But let's leave those people for later -- I am the one in need of saving at the moment :)

mouser:
Try the latest version. I added monitor sleep detection, and logs power events to log.txt.
--- End quote ---

Will do.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version