Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restoring positions after redocking does not work #10

Open
aronovgj opened this issue Nov 23, 2018 · 35 comments
Open

Restoring positions after redocking does not work #10

aronovgj opened this issue Nov 23, 2018 · 35 comments
Assignees
Labels
bug Something isn't working

Comments

@aronovgj
Copy link

  • After redocking window positions and sizes are restored to one monitor
  • All other monitors are empty
  • Reading the config again does not fix it
@manutalcual
Copy link
Owner

Reading the config will not solve anything now. The app is now different. But I have tested it and it is very strange that it doesn't works for you.
Could you be so gentle to run a special logging version to see your screen sizes and what the app is receiving in terms of internal Windows messages?

I don't have any Windows machine at home (I'm a Linux guy) and have to do this at work, but obviously I'm limited to my laptop and screens, and it works on mine so... I can't do more without help.

Thank you for your time and help!

@manutalcual manutalcual self-assigned this Nov 23, 2018
@aronovgj
Copy link
Author

Sure, just give me the link to the logging version.

@manutalcual
Copy link
Owner

manutalcual commented Nov 23, 2018

I've created a branch to solve this issue: I0010-restoring-positions-doesnt-work
You can find the logging binary there: bin

Sorry, I forgot to give instructions.

Just stop you current app, start this one in maximum screen size (two or more monitors), wait a second, undock, wait until you see the windows appear, dock and wait until windows are moved to their (theoretical) position (it should take a few seconds until Windows sends screen resolution change messages) and stop it. There should be a wm.log file: attach it here.

Again thank you for your help.

@aronovgj
Copy link
Author

wm.log

@manutalcual
Copy link
Owner

Well... I understand why it doesn't works for you. When you undock the screen size doesn't changes. I don't know why.

This is before undocking, 1920x1080

[../../src/window.hh:261] Receive WM_TIMER event.
[../../src/poshandler.cc:92] Getting current desktop windows.
[../../src/dev.hh:51] [dev] Screen: 1920, 1080

After undocking:

[../../src/window.hh:273] WM_DEVICECHAGE received!!!!
[../../src/window.hh:286] Message: DBT_DEVNODES_CHANGED
[../../src/window.hh:288] Screen size...
[../../src/dev.hh:51] [dev] Screen: 1920, 1080
[../../src/window.hh:290] New screen...
[../../src/dev.hh:51] [dev] Screen: 1920, 1080
[../../src/window.hh:292] Last screen...
[../../src/dev.hh:51] [dev] Screen: 1920, 1080

As you may see there is no resolution change: always 1920x1080.
I'm going to investigate this on Google to see if there is someone who has find this very problem before and why is it caused.

@aronovgj
Copy link
Author

Oh, this might me connected:

The screens are connected via a docking station.
The screen settings in Windows show all three screens as connected but when I open Intels graphics settings I only see one screen.
If I connect the screens directly with the laptop, without a docking station, I can see all screens in the windows settings and in the intel settings.

So you might need another way to access information about the screens.

@manutalcual
Copy link
Owner

Ok. I've found related windows info:

GetSystemMetrics(SM_CMONITORS) counts only visible display monitors. This is different from EnumDisplayMonitors, which enumerates both visible display monitors and invisible pseudo-monitors that are associated with mirroring drivers. An invisible pseudo-monitor is associated with a pseudo-device used to mirror application drawing for remoting or other purposes.

So I have to EnumDisplayMonitors and act upon that information.
Let me some time (hopefully not much) to generate a new version.

Meanwhile, could you try the new version connecting the screens without the docking station? (Just to confirm the problem, not to take as a solution.)

@aronovgj
Copy link
Author

aronovgj commented Nov 23, 2018

Edit: sorry, will reupload in a second
Sadly, did not work either...

@aronovgj
Copy link
Author

wm.log
Had to edit log due to containing sensitive information...

@manutalcual
Copy link
Owner

Ok, I've managed to reproduce the failure. I'm going to work on this. It may take some time as I can't work on this just now.

@manutalcual
Copy link
Owner

I've updated the loggin zip. Now it works in my laptop when:

  • undocking, re-docking
  • disabling one monitor through Windows "display settings"

Hope it works for you now. Tell me if it is OK or not.

@aronovgj
Copy link
Author

aronovgj commented Nov 23, 2018

Nope, sorry...

After undocking and redocking 2 monitors, still same behavior:

wm.log

Also I now cannot open desktop overview anymore (WIN+TAB)...
Restarting Explorer helped

@manutalcual
Copy link
Owner

I'm going to take the laptop at home and work on thins over the weekend.

@aronovgj
Copy link
Author

Well... I am not going to hold you off :)

But I'll be able to test again on monday.

@manutalcual
Copy link
Owner

manutalcual commented Nov 27, 2018

Another logging version uploaded. There should be no behavior changes, just more log. I've seen there are two ways to obtain the screen/s resolution. Let's check the second one.

@aronovgj
Copy link
Author

aronovgj commented Nov 28, 2018

This time most windows were restored (it took more time than in previous versions). Some windows were moved to other desktops and were not maximized. But they did not all stay on the same screen this time after redocking.

Could you please anonymize window names and app names in the next version? It takes quite some time to go through the logs and fix this.

@aronovgj
Copy link
Author

wm.log

@aronovgj
Copy link
Author

aronovgj commented Nov 28, 2018

wm.log

On second try it did not work again... All windows were restored to the same screen.

@manutalcual
Copy link
Owner

Yes. Sorry for the anonymization. I should have thought about that before asking for help. Sorry.

Looking into the logs, it seems the resolution is: width: 5760, height: 1080.
So the same resolution for every monitor: 1920x1080, but negative axis to position in different monitors:

[../../src/poshandler.cc:74] Adding window with class 'rctrl_renwnd32': , top 0, left -1548, right -74, bottom 862

Plus, there is a moment when there is only 3 monitors attached, and it reports 4:

[../../src/window.hh:262] Receive WM_TIMER event.
[../../src/dev.cc:7] get_ennum_windows called
[../../src/dev.cc:7] get_ennum_windows called
[../../src/dev.cc:7] get_ennum_windows called
[../../src/dev.hh:64] Metrics: width: 5760, height: 1080, right: 1920, bottom: 1080, monitors: 4
[../../src/dev.hh:70] [dev] Screen: 1920, 1080 (mon 4)

When screen size increments (3mon. => 4) I get the new positions. This fourth monitor must be a virtual one to draw or prepare to draw windows on it. Then, when I get the positions they are already for one monitor:

[../../src/poshandler.cc:74] Adding window with class 'rctrl_renwnd32': , top 0, left 434, right 1908, bottom 862

As you can see, the position isn't negative anymore. It was left -1548, right -74.
So either Windows or the device driver is drawing window contents in a hidden memory buffer and after the draw, its bits are overwritten in the graphical card memory (or something in those lines.)

So I have to ignore the positions when... the system resolution is the same as the max resolution detected until now (5760x1080) and there are more monitors than there were when that resolution was first detected. Clearer: if I have 5760 with two monitors, I have to ignore positions when I have 5760 with three or more monitors.

Unfortunately I don't have a system doing those things with screen resolution and positioning, so I'm going to try several algorithms that may be activated by an app parameter to see if I can fix it.

@manutalcual
Copy link
Owner

I've uploaded a new version. It now takes in account not only the monitor count but also the virtual screen size (with all monitors.) I think this should work, so no parameters and one algorithm only.
Cross your fingers!
(Anonymized!)

@aronovgj
Copy link
Author

aronovgj commented Nov 28, 2018

Nope, sorry:
wm.log

All windows are restored to one screen

[../../src/poshandler.cc:154] Can't set window placement for last window. [../../src/common.hh:176] Error: Ungültiges Fensterhandle
Means invalid window handle

@aronovgj
Copy link
Author

aronovgj commented Nov 28, 2018

Also, to make sure that we are on the same page: I talk about Desktops and Screens.

  • By Screens I mean the actual monitor
  • By Desktops I mean the Windows 10 feature that they stole from Linux where you can have several desktops and switch between them via shortcuts so you effectively have for example
    3 monitors x 5 desktops = same space like having 15 monitors.

And there are two issues:

  1. Windows are restored to one screen
  2. Some windows change the desktop while being restored

We are currently trying to fix issue 1.
#9 is issue 2.

@manutalcual
Copy link
Owner

manutalcual commented Dec 7, 2018

Hi,
I didn't have much time last week to develop this.
Now I've changed the paradigm and taken another approach: I store in memory all windows in each desktop configuration. Before there was one desktop and I was trying to move around windows when the desktop resolution changed, but I was keeping one desktop configuration.
Now I keep every desktop configuration and store all window positions for each desktop configuration.
Its easier and in my computer it works like a charm.
It has the advantage that it will keep window positions even when only using the laptop. Great!

Now the difference with your machine: your machine gives the resolution changes before the dock or undock messages (which they aren't, BTW, I will receive that message when there is a network change (e.g. wired to wifi)) so I have to do everything in three steps. I've tested those steps and they work, again, in my computer.
Lets see if it works in yours!

Thank you.

@aronovgj
Copy link
Author

aronovgj commented Dec 7, 2018

Some windows were restored, some were not. Some windows changed desktops.

wm.log

I'll be on vacation for a month so you can take your time :D

@manutalcual
Copy link
Owner

Another try to solve the issue. It works like a charm for me.

@manutalcual manutalcual added the bug Something isn't working label Dec 18, 2018
@aronovgj
Copy link
Author

aronovgj commented Jan 9, 2019

Build from 5 days ago:
wm.log

Same old :(

@manutalcual
Copy link
Owner

Hey, welcome back!
I'm going to investigate.

@dokbua
Copy link

dokbua commented Jul 30, 2019

Just fell over this handy utility after I for god-knows-what time redocked my Win10-Thinkpad-Onelink+ and had to re-sort all my windows. Unfortunately it doesn't seem to work for me. I downloaded the bin, extracted and ran. Tried clicking around with the get/save/read buttons both before and after redocking (several times) but nothing seems to happen. Don't know if I am missing a crucial step? Pity though, it's a good idea!!

@manutalcual
Copy link
Owner

Hi,

Try branch restoring-positions-doesnt-works or something like that. In that branch you don't need to use the menu, all is done automatically (when it works.)
Unfortunately, Microsoft apps are more or less redundant to be handled by others, so they usually don't work.
And as a shame, I don't have enough time to investigate or develop further this tool. It works for me but it doesn't give anything else to me and I have to pay the bills. Sorry.

@dokbua
Copy link

dokbua commented Jul 31, 2019

Fair enough, I can understand that. No worries, I'll keep looking.

@hansharhoff
Copy link

The version in the I0010-restoring-positions-doesnt-work branch works for me. Perhaps this should be merged to master so that this is the version people find by default?

@manutalcual
Copy link
Owner

Yes. Absolutely.

@manutalcual
Copy link
Owner

Done.

@manutalcual
Copy link
Owner

And I'm glad it works for you man! I'm quite happy with it even when some windows (mostly MS) refuse to play fair.

@hansharhoff
Copy link

hansharhoff commented Nov 13, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants