6
6
7
7
#include " base/win/windows_version.h"
8
8
#include " shell/browser/ui/views/win_frame_view.h"
9
- #include " ui/base/win/hwnd_metrics.h"
10
9
#include " ui/base/win/shell.h"
11
- #include " ui/display/win/screen_win.h"
12
- #include " ui/views/win/hwnd_util.h"
13
10
14
11
namespace electron {
15
12
@@ -41,23 +38,25 @@ bool ElectronDesktopWindowTreeHostWin::HasNativeFrame() const {
41
38
// Since we never use chromium's titlebar implementation, we can just say
42
39
// that we use a native titlebar. This will disable the repaint locking when
43
40
// DWM composition is disabled.
41
+ // See also https://github.com/electron/electron/issues/1821.
44
42
return !ui::win::IsAeroGlassEnabled ();
45
43
}
46
44
47
45
bool ElectronDesktopWindowTreeHostWin::GetDwmFrameInsetsInPixels (
48
46
gfx::Insets* insets) const {
47
+ // Set DWMFrameInsets to prevent maximized frameless window from bleeding
48
+ // into other monitors.
49
49
if (IsMaximized () && !native_window_view_->has_frame ()) {
50
- HMONITOR monitor = ::MonitorFromWindow (
51
- native_window_view_->GetAcceleratedWidget (), MONITOR_DEFAULTTONEAREST);
52
- int frame_height = display::win::ScreenWin::GetSystemMetricsForMonitor (
53
- monitor, SM_CYSIZEFRAME) +
54
- display::win::ScreenWin::GetSystemMetricsForMonitor (
55
- monitor, SM_CXPADDEDBORDER);
56
- int frame_size = base::win::GetVersion () < base::win::Version::WIN8
57
- ? display::win::ScreenWin::GetSystemMetricsForMonitor (
58
- monitor, SM_CXSIZEFRAME)
59
- : 0 ;
60
- insets->Set (frame_height, frame_size, frame_size, frame_size);
50
+ // This would be equivalent to calling:
51
+ // DwmExtendFrameIntoClientArea({0, 0, 0, 0});
52
+ //
53
+ // which means do not extend window frame into client area. It is almost
54
+ // a no-op, but it can tell Windows to not extend the window frame to be
55
+ // larger than current workspace.
56
+ //
57
+ // See also:
58
+ // https://devblogs.microsoft.com/oldnewthing/20150304-00/?p=44543
59
+ *insets = gfx::Insets ();
61
60
return true ;
62
61
}
63
62
return false ;
@@ -66,24 +65,20 @@ bool ElectronDesktopWindowTreeHostWin::GetDwmFrameInsetsInPixels(
66
65
bool ElectronDesktopWindowTreeHostWin::GetClientAreaInsets (
67
66
gfx::Insets* insets,
68
67
HMONITOR monitor) const {
68
+ // Windows by deafult extends the maximized window slightly larger than
69
+ // current workspace, for frameless window since the standard frame has been
70
+ // removed, the client area would then be drew outside current workspace.
71
+ //
72
+ // Indenting the client area can fix this behavior.
69
73
if (IsMaximized () && !native_window_view_->has_frame ()) {
70
- if (base::win::GetVersion () < base::win::Version::WIN8) {
71
- // This tells Windows that most of the window is a client area, meaning
72
- // Chrome will draw it. Windows still fills in the glass bits because of
73
- // the // DwmExtendFrameIntoClientArea call in |UpdateDWMFrame|.
74
- // Without this 1 pixel offset on the right and bottom:
75
- // * windows paint in a more standard way, and
76
- // * we get weird black bars at the top when maximized in multiple
77
- // monitor configurations.
78
- int border_thickness = 1 ;
79
- insets->Set (0 , 0 , border_thickness, border_thickness);
80
- } else {
81
- const int frame_thickness = ui::GetFrameThickness (monitor);
82
- // Reduce the Windows non-client border size because we extend the border
83
- // into our client area in UpdateDWMFrame(). The top inset must be 0 or
84
- // else Windows will draw a full native titlebar outside the client area.
85
- insets->Set (0 , frame_thickness, frame_thickness, frame_thickness);
86
- }
74
+ // The insets would be eventually passed to WM_NCCALCSIZE, which takes
75
+ // the metrics under the DPI of _main_ monitor instead of current moniotr.
76
+ //
77
+ // Please make sure you tested maximized frameless window under multiple
78
+ // monitors with different DPIs before changing this code.
79
+ const int thickness = ::GetSystemMetrics (SM_CXSIZEFRAME) +
80
+ ::GetSystemMetrics (SM_CXPADDEDBORDER);
81
+ insets->Set (thickness, thickness, thickness, thickness);
87
82
return true ;
88
83
}
89
84
return false ;
0 commit comments