Commit 1bb2cf69 authored by wez@chromium.org's avatar wez@chromium.org

Reposition the Disconnect dialog when work area dimensions change.

This prevents the Disconnect dialog from becoming hidden by the Windows task bar, or falling off-screen when the display resolution is made smaller.

BUG=129907,129835


Review URL: https://chromiumcodereview.appspot.com/10825251

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151313 0039d316-1c4b-4281-b951-d872f2087c98
parent 3419fa77
...@@ -27,8 +27,13 @@ ...@@ -27,8 +27,13 @@
// SimpleHost: simple_host_process.cc // SimpleHost: simple_host_process.cc
extern HMODULE g_hModule; extern HMODULE g_hModule;
namespace {
const int DISCONNECT_HOTKEY_ID = 1000; const int DISCONNECT_HOTKEY_ID = 1000;
const int kWindowBorderRadius = 14; const int kWindowBorderRadius = 14;
const wchar_t kShellTrayWindowName[] = L"Shell_TrayWnd";
} // namespace anonymous
namespace remoting { namespace remoting {
...@@ -51,6 +56,7 @@ private: ...@@ -51,6 +56,7 @@ private:
void ShutdownHost(); void ShutdownHost();
void EndDialog(); void EndDialog();
void SetStrings(const UiStrings& strings, const std::string& username); void SetStrings(const UiStrings& strings, const std::string& username);
void SetDialogPosition();
DisconnectCallback disconnect_callback_; DisconnectCallback disconnect_callback_;
HWND hwnd_; HWND hwnd_;
...@@ -109,6 +115,17 @@ BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT msg, ...@@ -109,6 +115,17 @@ BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT msg,
hwnd_ = NULL; hwnd_ = NULL;
return TRUE; return TRUE;
// Ensure the dialog stays visible if the work area dimensions change.
case WM_SETTINGCHANGE:
if (wParam == SPI_SETWORKAREA)
SetDialogPosition();
return TRUE;
// Ensure the dialog stays visible if the display dimensions change.
case WM_DISPLAYCHANGE:
SetDialogPosition();
return TRUE;
// Handle the disconnect hot-key. // Handle the disconnect hot-key.
case WM_HOTKEY: case WM_HOTKEY:
EndDialog(); EndDialog();
...@@ -121,21 +138,20 @@ BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT msg, ...@@ -121,21 +138,20 @@ BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT msg,
SetWindowLong(hwnd, DWL_MSGRESULT, HTCAPTION); SetWindowLong(hwnd, DWL_MSGRESULT, HTCAPTION);
return TRUE; return TRUE;
case WM_PAINT: case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd_, &ps);
RECT rect;
GetClientRect(hwnd_, &rect);
{ {
PAINTSTRUCT ps; base::win::ScopedSelectObject border(hdc, border_pen_);
HDC hdc = BeginPaint(hwnd_, &ps); base::win::ScopedSelectObject brush(hdc, GetStockObject(NULL_BRUSH));
RECT rect; RoundRect(hdc, rect.left, rect.top, rect.right - 1, rect.bottom - 1,
GetClientRect(hwnd_, &rect); kWindowBorderRadius, kWindowBorderRadius);
{
base::win::ScopedSelectObject border(hdc, border_pen_);
base::win::ScopedSelectObject brush(hdc, GetStockObject(NULL_BRUSH));
RoundRect(hdc, rect.left, rect.top, rect.right - 1, rect.bottom - 1,
kWindowBorderRadius, kWindowBorderRadius);
}
EndPaint(hwnd_, &ps);
return TRUE;
} }
EndPaint(hwnd_, &ps);
return TRUE;
}
} }
return FALSE; return FALSE;
} }
...@@ -182,22 +198,7 @@ void DisconnectWindowWin::Show(ChromotingHost* host, ...@@ -182,22 +198,7 @@ void DisconnectWindowWin::Show(ChromotingHost* host,
} }
SetStrings(host->ui_strings(), username); SetStrings(host->ui_strings(), username);
SetDialogPosition();
// Try to center the window above the task-bar. If that fails, use the
// primary monitor. If that fails (very unlikely), use the default position.
HWND taskbar = FindWindow(L"Shell_TrayWnd", NULL);
HMONITOR monitor = MonitorFromWindow(taskbar, MONITOR_DEFAULTTOPRIMARY);
MONITORINFO monitor_info = {sizeof(monitor_info)};
RECT window_rect;
if (GetMonitorInfo(monitor, &monitor_info) &&
GetWindowRect(hwnd_, &window_rect)) {
int window_width = window_rect.right - window_rect.left;
int window_height = window_rect.bottom - window_rect.top;
int top = monitor_info.rcWork.bottom - window_height;
int left = (monitor_info.rcWork.right + monitor_info.rcWork.left -
window_width) / 2;
SetWindowPos(hwnd_, NULL, left, top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
ShowWindow(hwnd_, SW_SHOW); ShowWindow(hwnd_, SW_SHOW);
} }
...@@ -273,6 +274,24 @@ void DisconnectWindowWin::SetStrings(const UiStrings& strings, ...@@ -273,6 +274,24 @@ void DisconnectWindowWin::SetStrings(const UiStrings& strings,
SetWindowRgn(hwnd_, rgn, TRUE); SetWindowRgn(hwnd_, rgn, TRUE);
} }
void DisconnectWindowWin::SetDialogPosition() {
// Try to center the window above the task-bar. If that fails, use the
// primary monitor. If that fails (very unlikely), use the default position.
HWND taskbar = FindWindow(kShellTrayWindowName, NULL);
HMONITOR monitor = MonitorFromWindow(taskbar, MONITOR_DEFAULTTOPRIMARY);
MONITORINFO monitor_info = {sizeof(monitor_info)};
RECT window_rect;
if (GetMonitorInfo(monitor, &monitor_info) &&
GetWindowRect(hwnd_, &window_rect)) {
int window_width = window_rect.right - window_rect.left;
int window_height = window_rect.bottom - window_rect.top;
int top = monitor_info.rcWork.bottom - window_height;
int left = (monitor_info.rcWork.right + monitor_info.rcWork.left -
window_width) / 2;
SetWindowPos(hwnd_, NULL, left, top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
}
void DisconnectWindowWin::Hide() { void DisconnectWindowWin::Hide() {
EndDialog(); EndDialog();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment