-
Notifications
You must be signed in to change notification settings - Fork 601
fixes initial placement, move and size issues #498
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,6 +99,42 @@ LPCWSTR cef_main_window::GetBracketsWindowTitleText() | |
| return szTitle; | ||
| } | ||
|
|
||
| void cef_main_window::EnsureWindowRectVisibility(int& left, int& top, int& width, int& height) | ||
| { | ||
| // don't check if we're already letting | ||
| // Windows determine the window placement | ||
| if (left == CW_USEDEFAULT && | ||
| top == CW_USEDEFAULT && | ||
| width == CW_USEDEFAULT && | ||
| height == CW_USEDEFAULT) { | ||
| return; | ||
| } | ||
|
|
||
| // The virtual display is the bounding rect of all monitors | ||
| // see http://msdn.microsoft.com/en-us/library/dd162729(v=vs.85).aspx | ||
|
|
||
| int xScreen = ::GetSystemMetrics(SM_XVIRTUALSCREEN); | ||
| int yScreen = ::GetSystemMetrics(SM_YVIRTUALSCREEN); | ||
| int cxScreen = ::GetSystemMetrics(SM_CXVIRTUALSCREEN); | ||
| int cyScreen = ::GetSystemMetrics(SM_CYVIRTUALSCREEN); | ||
|
|
||
| // Make sure the window fits inside the virtual screen. | ||
| // If it doesn't then we let windows decide the window placement | ||
| if (left < xScreen || | ||
| top < yScreen || | ||
| left + width > xScreen + cxScreen || | ||
| top + height > yScreen + cyScreen) { | ||
|
|
||
| // something was off-screen so reposition | ||
| // to the default window placement | ||
| left = CW_USEDEFAULT; | ||
| top = CW_USEDEFAULT; | ||
| width = CW_USEDEFAULT; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can original width and height be maintained? i.e. only set left and top to default?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, this has to work for both the maximized size / placement and the restored size / placement otherwise you run into that odd case so, IMO, it's better to just let the OS decide initial placement and then let the user move it wherever they want. This eliminates incorrectly computing the placement or placing the window on a secondary monitor (in the case they have more than 2 monitors and disconnect one or rearrange monitors.) |
||
| height = CW_USEDEFAULT; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // Create Method. Call this to create a cef_main_window instance | ||
| BOOL cef_main_window::Create() | ||
| { | ||
|
|
@@ -108,10 +144,14 @@ BOOL cef_main_window::Create() | |
| int top = CW_USEDEFAULT; | ||
| int width = CW_USEDEFAULT; | ||
| int height = CW_USEDEFAULT; | ||
|
|
||
| int showCmd = SW_SHOW; | ||
|
|
||
| LoadWindowRestoreRect(left, top, width, height, showCmd); | ||
|
|
||
| // make sure the window is visible | ||
| EnsureWindowRectVisibility(left, top, width, height); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested this with multiple monitors only so please test with a single monitor. I tested this by changing various registry values to make sure that when the restore coordinates were offscreen that brackets let Windows figure out where to place the window. Tested Maximized windows to ensure that the restored placement was correct. I also tested that, if the restored size was off screen, Windows figures out where to place the window when it is restored. For reference: #144
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, I tested stretching the app across to monitors to ensure that would work. The origin #144 implementation would constrain it to a single monitor. |
||
|
|
||
| DWORD styles = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_EX_COMPOSITED; | ||
|
|
||
| if (showCmd == SW_MAXIMIZE) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calling this was something that needed to be added whenever the app is moved or resized