Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable system maximization for frameless windows except if transparent #28207

Merged
merged 6 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/api/frameless-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ win.show()
blur effect to the content below the window (i.e. other applications open on
the user's system).
* The window will not be transparent when DevTools is opened.
* On Windows operating systems, transparent windows will not work when DWM is
* On Windows operating systems,
* transparent windows will not work when DWM is
disabled.
* transparent windows can not be maximized using the Windows system menu or by double clicking the title bar. The reasoning behind this can be seen on [this pull request](https://github.com/electron/electron/pull/28207).
* On Linux, users have to put `--enable-transparent-visuals --disable-gpu` in
the command line to disable GPU and allow ARGB to make transparent window,
this is caused by an upstream bug that [alpha channel doesn't work on some
Expand Down
27 changes: 14 additions & 13 deletions shell/browser/native_window_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ void NativeWindowViews::Maximize() {

void NativeWindowViews::Unmaximize() {
#if defined(OS_WIN)
if (!(::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE) & WS_THICKFRAME)) {
if (transparent()) {
SetBounds(restore_bounds_, false);
return;
}
Expand All @@ -540,21 +540,22 @@ void NativeWindowViews::Unmaximize() {
}

bool NativeWindowViews::IsMaximized() {
// For window without WS_THICKFRAME style, we can not call IsMaximized().
// This path will be used for transparent windows as well.

if (widget()->IsMaximized()) {
return true;
} else {
#if defined(OS_WIN)
if (!(::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE) & WS_THICKFRAME)) {
// Compare the size of the window with the size of the display
auto display = display::Screen::GetScreen()->GetDisplayNearestWindow(
GetNativeWindow());
// Maximized if the window is the same dimensions and placement as the
// display
return GetBounds() == display.work_area();
}
if (transparent()) {
// Compare the size of the window with the size of the display
auto display = display::Screen::GetScreen()->GetDisplayNearestWindow(
GetNativeWindow());
// Maximized if the window is the same dimensions and placement as the
// display
return GetBounds() == display.work_area();
}
#endif

return widget()->IsMaximized();
return false;
}
}

void NativeWindowViews::Minimize() {
Expand Down
29 changes: 26 additions & 3 deletions shell/browser/native_window_views_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ std::set<NativeWindowViews*> NativeWindowViews::forwarding_windows_;
HHOOK NativeWindowViews::mouse_hook_ = NULL;

void NativeWindowViews::Maximize() {
// Only use Maximize() when window has WS_THICKFRAME style
if (::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE) & WS_THICKFRAME) {
// Only use Maximize() when window is NOT transparent style
if (!transparent()) {
if (IsVisible())
widget()->Maximize();
else
Expand Down Expand Up @@ -324,8 +324,31 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
GET_Y_LPARAM(l_param), &prevent_default);
return prevent_default;
}
default:
case WM_SYSCOMMAND: {
// Mask is needed to account for double clicking title bar to maximize
WPARAM max_mask = 0xFFF0;
if (transparent() && ((w_param & max_mask) == SC_MAXIMIZE)) {
return true;
}
return false;
}
case WM_INITMENU: {
// This is handling the scenario where the menu might get triggered by the
// user doing "alt + space" resulting in system maximization and restore
// being used on transparent windows when that does not work.
if (transparent()) {
HMENU menu = GetSystemMenu(GetAcceleratedWidget(), false);
EnableMenuItem(menu, SC_MAXIMIZE,
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
EnableMenuItem(menu, SC_RESTORE,
MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
return true;
}
return false;
}
default: {
return false;
}
}
}

Expand Down