-
Notifications
You must be signed in to change notification settings - Fork 614
fixes initial placement, move and size issues #498
Changes from 2 commits
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,60 @@ LPCWSTR cef_main_window::GetBracketsWindowTitleText() | |
return szTitle; | ||
} | ||
|
||
void cef_main_window::EnsureWindowRectVisibility(int& left, int& top, int& width, int& height, int showCmd) | ||
{ | ||
static const int kWindowFrameSize = 8; | ||
|
||
// 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 a copy, we need to adjust the comparison | ||
// if it's a maximized window because the OS move the | ||
// origin of the window by 8 pixes to releive the borders | ||
// from the monitor for legacy apps | ||
int xLeft = left; | ||
int xTop = top; | ||
int xWidth = width; | ||
int xHeight = height; | ||
|
||
if (showCmd == SW_MAXIMIZE) { | ||
xLeft += kWindowFrameSize; | ||
xTop += kWindowFrameSize; | ||
xWidth -= kWindowFrameSize * 2; | ||
xHeight -= kWindowFrameSize * 2; | ||
} | ||
|
||
// Make sure the window fits inside the virtual screen. | ||
// If it doesn't then we let windows decide the window placement | ||
if (xLeft < xScreen || | ||
xTop < yScreen || | ||
xLeft + xWidth > xScreen + cxScreen || | ||
xTop + xHeight > yScreen + cyScreen) { | ||
|
||
// something was off-screen so reposition | ||
// to the default window placement | ||
left = CW_USEDEFAULT; | ||
top = CW_USEDEFAULT; | ||
width = CW_USEDEFAULT; | ||
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? 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 +162,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, showCmd); | ||
|
||
DWORD styles = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_EX_COMPOSITED; | ||
|
||
if (showCmd == SW_MAXIMIZE) | ||
|
@@ -353,6 +411,30 @@ void cef_main_window::RestoreWindowPlacement(int showCmd) | |
GetRegistryInt(::kWindowPostionFolder, ::kPrefRestoreRight, NULL, (int&)wp.rcNormalPosition.right); | ||
GetRegistryInt(::kWindowPostionFolder, ::kPrefRestoreBottom, NULL, (int&)wp.rcNormalPosition.bottom); | ||
|
||
::NormalizeRect(wp.rcNormalPosition); | ||
|
||
int left = wp.rcNormalPosition.left; | ||
int top = wp.rcNormalPosition.top; | ||
int width = wp.rcNormalPosition.right - left; | ||
int height = wp.rcNormalPosition.bottom - top; | ||
|
||
EnsureWindowRectVisibility(left, top, width, height, SW_SHOWNORMAL); | ||
|
||
wp.rcNormalPosition.left = left; | ||
wp.rcNormalPosition.top = top; | ||
|
||
if (width != CW_USEDEFAULT) { | ||
wp.rcNormalPosition.right = wp.rcNormalPosition.left + width; | ||
} else { | ||
wp.rcNormalPosition.right = CW_USEDEFAULT; | ||
} | ||
|
||
if (height != CW_USEDEFAULT) { | ||
wp.rcNormalPosition.bottom = wp.rcNormalPosition.top + height; | ||
} else { | ||
wp.rcNormalPosition.bottom = CW_USEDEFAULT; | ||
} | ||
|
||
// This returns FALSE on failure but not sure what we could do in that case | ||
SetWindowPlacement(&wp); | ||
} | ||
|
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