Commit 8ee01678 authored by Joe Downing's avatar Joe Downing Committed by Commit Bot

Center the disconnect windows on screen when auto-hide is enabled

This change is a result of our discussions with the privacy folks.
The old behavior was to center the disconnect window along the
x-axis and dock it just above the taskbar.  The change is to now
position the dialog near the center of the y-axis as well to
maximize the chances of a local user seeing the disconnect window
before it auto-hides.

This change also fixes a bug where I was setting the position after
animating the window so it would appear to jump when being reshown.

BUG=882926

Change-Id: I3e923937f10f24c3e719f311380a98b77644e866
Reviewed-on: https://chromium-review.googlesource.com/1220029Reviewed-by: default avatarJamie Walch <jamiewalch@chromium.org>
Commit-Queue: Joe Downing <joedow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590434}
parent c4f92dd3
......@@ -78,7 +78,9 @@ class DisconnectWindowWin : public HostWindow {
// Returns |control| rectangle in the dialog coordinates.
bool GetControlRect(HWND control, RECT* rect);
// Trys to position the dialog window above the taskbar.
// Positions the dialog window based on the current auto-hide state.
// If auto-hide is enabled, the window is displayed near the center of the
// display, otherwise it is displayed just above the taskbar.
void SetDialogPosition();
// Applies localization string and resizes the dialog.
......@@ -345,6 +347,9 @@ void DisconnectWindowWin::ShowDialog() {
if (!was_auto_hidden_)
return;
// Make sure the dialog is fully visible when it is reshown.
SetDialogPosition();
if (!AnimateWindow(hwnd_, kAnimationDurationMs, AW_BLEND)) {
PLOG(ERROR) << "AnimateWindow() failed to show dialog: ";
ShowWindow(hwnd_, SW_SHOW);
......@@ -354,9 +359,6 @@ void DisconnectWindowWin::ShowDialog() {
client_session_control_->DisconnectSession(protocol::OK);
}
was_auto_hidden_ = false;
// Make sure the dialog is fully visible when it is reshown.
SetDialogPosition();
}
void DisconnectWindowWin::HideDialog() {
......@@ -416,15 +418,27 @@ void DisconnectWindowWin::SetDialogPosition() {
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_, nullptr, left, top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
if (!GetMonitorInfo(monitor, &monitor_info) ||
!GetWindowRect(hwnd_, &window_rect)) {
return;
}
int window_width = window_rect.right - window_rect.left;
int window_height = window_rect.bottom - window_rect.top;
// Default settings will display the window above the taskbar and centered
// along the x axis.
int top = monitor_info.rcWork.bottom - window_height;
int left =
(monitor_info.rcWork.right + monitor_info.rcWork.left - window_width) / 2;
// Adjust the top value if the window is in auto-hide mode. We adjust the
// position to make the dialog a bit more obtrusive so that a local user will
// notice it before it auto-hides.
if (local_input_monitor_)
top = top * 0.7;
SetWindowPos(hwnd_, nullptr, left, top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
bool DisconnectWindowWin::SetStrings() {
......
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