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

Remember window size #41

Closed
ibrumby opened this issue Apr 11, 2020 · 11 comments
Closed

Remember window size #41

ibrumby opened this issue Apr 11, 2020 · 11 comments

Comments

@ibrumby
Copy link

ibrumby commented Apr 11, 2020

Every time I launch Ciderpress it creates a window that is 3820 pixels wide on my monitor. So the first thing I have to do is reduce the width of the window. It would be nice if it remembered the window size.

@fadden
Copy link
Owner

fadden commented Jul 23, 2020

I'm passing rectDefault to the window creation function, which is documented thusly:

Pass this static CRect as a parameter when creating a window to allow Windows to choose the window's initial size and position.

On my system, Windows chooses to make it larger than I would like, though not full screen. I think there used to be a time when Windows would remember what you did automatically, but as of at least Win7 that is no longer the case.

The window size is set before preferences are loaded, which means I can't simply save a preference and use it later.

I think the correct approach is to use GetWindowPlacement and SetWindowPlacement. I actually use these in SourceGen, with a WindowPlacement class that makes native calls into user32.dll and serializes the result. It outputs a blob of values (3 ints, 2 points, 1 rect) that would need to be stored in the Registry, since that's where CP's settings live.

Simply restoring the previous X/Y position and size is problematic on multi-monitor systems, since the external monitors frequently go away. Anything that is placed substantially off-screen needs to be relocated and perhaps resized, or you might not be able to see the window or grab its title bar. The window placement calls are expected to deal with that.

@fadden
Copy link
Owner

fadden commented Apr 11, 2021

I finally got around to digging into this a little more. MFC's CWinAppEx class, from which CiderPress inherits, has an EnableLoadWindowPlacement() feature, and a LoadWindowPlacement() method that you can override to modify the position. Apparently these are supposed to save and restore the app's window size and position in the registry, but as far as I can tell these do absolutely nothing whatsoever now.

So that might be part of why it no longer behaves the way it used to.

The key moment for picking a size seems to be MainWindow::PreCreateWindow(), which receives a CREATESTRUCT from the operating system (or whatever app launched it). The position and width/height values are being set to CW_USEDEFAULT, which is documented:

If nWidth is CW_USEDEFAULT, the system selects a default width and height for the window; the default width extends from the initial x-coordinates to the right edge of the screen; the default height extends from the initial y-coordinate to the top of the icon area.

I can trivially set a fixed size like this:

diff --git a/app/Main.cpp b/app/Main.cpp
index b74b9a6..8e65acc 100644
--- a/app/Main.cpp
+++ b/app/Main.cpp
@@ -311,6 +311,8 @@ BOOL MainWindow::PreCreateWindow(CREATESTRUCT& cs)
     BOOL res = CFrameWnd::PreCreateWindow(cs);

     cs.dwExStyle &= ~(WS_EX_CLIENTEDGE);
+    cs.cx = 1150;
+    cs.cy = 800;

Not ideal, but seems more pleasant than the current behavior. The window's position is still determined by the OS, so it shouldn't end up off screen. Potentially slightly awkward for somebody running at 1024x768; I could try to limit the size based on the screen metrics of the primary or current monitor (with these calls), though I don't know if that's a real concern in this century.

fadden added a commit that referenced this issue Apr 19, 2021
Windows is currently creating the main window at near-maximal size.
It used to remember the size and placement, but no longer does.

As a workaround, the initial size is set to 1150x800, which is large
enough to show all columns without scrolling even with very wide
pathnames.  With some effort this could be modified to respect the
maximum size of the monitor on which it will be displayed, so that
anyone still running at 1024x768 won't be in a bad place.

Ideally it would remember the previous size and position.  See
issue #41 for discussion.
@fadden
Copy link
Owner

fadden commented Apr 19, 2021

Above workaround published in v4.0.5-d2.

@Keatah
Copy link

Keatah commented Apr 24, 2021

Ciderpress now opens full screen and then spreads half-way across my 2nd monitor. Reverting back to v4.0.5-d1, as that version works correctly.

@fadden
Copy link
Owner

fadden commented Apr 24, 2021

@Keatah Can you provide some additional details?

  • What OS are you running?
  • What resolution is your primary display configured for?
  • What does "works correctly" mean... how big does the window usually become? Was it previously maximized?

The change should force the window to be 1150x800, so unless you're running on a tiny system I'm at a bit of a loss. Anything that would help me reproduce your circumstances would be helpful.

@Keatah
Copy link

Keatah commented Apr 29, 2021

Yes, we're running at smaller resolutions. Some as small as 1024x768. Otherwise 1280x1024, 1600x1200. Not popular resolutions in today's world, I understand..

It seems ok at 1920x1200 or 1920x1080.

I wouldn't worry about it too much. Is it possible to have CP remember the previous size and position?

Win10 and sometimes WinXP.

@fadden
Copy link
Owner

fadden commented May 10, 2021

Version 4.0.5 was released without the fixed-size behavior (i.e. same as v4.0.5-d1). FWIW, this is the last version that will run on WinXP.

Version 4.1.0-d1 saves and restores the main window placement: https://github.com/fadden/ciderpress/releases/tag/v4.1.0-d1

@fadden fadden closed this as completed May 10, 2021
@ibrumby
Copy link
Author

ibrumby commented May 10, 2021

It's almost perfect now. If I try and align the window with the top-left of my screen however it tends to reset to default size.

I think I must be moving the window to -1 xpos or -1 ypos, but visually it looks like the window is completely on screen rather than offscreen. This triggers the "offscreen" code path and resets it.

It would be better if it just moved x pos, y pos to 0,0 and kept width and height intact in this scenario. But it's still a major improvement on the old version.

@fadden
Copy link
Owner

fadden commented May 10, 2021

Whoops, that's my fault. It's punting if any of the values are < 0. Easy to fix.

@fadden fadden reopened this May 10, 2021
fadden added a commit that referenced this issue May 10, 2021
It's okay to have the window off the top/left edge of the primary
display, but CiderPress was rejecting the values and reverting to
default placement.

(for issue #41)
@fadden
Copy link
Owner

fadden commented May 11, 2021

This should work better: https://github.com/fadden/ciderpress/releases/tag/v4.1.0-d2

@fadden fadden closed this as completed May 11, 2021
@ibrumby
Copy link
Author

ibrumby commented May 11, 2021

Works great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants