Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions appshell/cef_host_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,20 @@ BOOL cef_host_window::HandleSize(BOOL bMinimize)
}
SetProp(L"WasMinimized", (HANDLE)bMinimize);
#endif
NotifyWindowMovedOrResized();
return FALSE;
}

void cef_host_window::NotifyWindowMovedOrResized()
{
if (GetBrowser() && GetBrowser()->GetHost()) {
GetBrowser()->GetHost()->NotifyMoveOrResizeStarted();
Copy link
Copy Markdown
Contributor Author

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

}
}

BOOL cef_host_window::HandleMoveOrMoving()
{
NotifyWindowMovedOrResized();
return FALSE;
}

Expand Down Expand Up @@ -198,6 +211,11 @@ LRESULT cef_host_window::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
if (HandleInitMenuPopup((HMENU)wParam))
return 0L;
break;
case WM_MOVING:
case WM_MOVE:
if (HandleMoveOrMoving())
return 0L;
break;
}


Expand Down
2 changes: 2 additions & 0 deletions appshell/cef_host_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ class cef_host_window : public cef_host_window_base
// Message Handlers
BOOL HandleInitMenuPopup(HMENU hMenuPopup);
BOOL HandleSize(BOOL bMinimize);
BOOL HandleMoveOrMoving();

// Command Implementation
BOOL DoCommand(UINT commandId, CefRefPtr<CommandCallback> callback = 0);
BOOL DoCommand(const CefString& commandString, CefRefPtr<CommandCallback> callback = 0);

// Implementation
virtual void DoRepaintClientArea();
void NotifyWindowMovedOrResized();

// Helper to get a command string from command id
CefString GetCommandString(UINT commandId);
Expand Down
40 changes: 40 additions & 0 deletions appshell/cef_main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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()
{
Expand All @@ -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);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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)
Expand Down
1 change: 1 addition & 0 deletions appshell/cef_main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class cef_main_window : public cef_host_window
void SaveWindowRestoreRect();
void LoadWindowRestoreRect(int& left, int& top, int& width, int& height, int& showCmd);
void RestoreWindowPlacement(int showCmd);
void EnsureWindowRectVisibility(int& left, int& top, int& width, int& height);

// Message Handlers
BOOL HandleEraseBackground(HDC hdc);
Expand Down