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: Frameless window shows frame while opening #35351

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
1 change: 1 addition & 0 deletions patches/chromium/.patches
Expand Up @@ -134,3 +134,4 @@ cherry-pick-60d8559e150a.patch
cherry-pick-54a7927b19f9.patch
cherry-pick-bd9724c9fe63.patch
cherry-pick-c643d18a078d.patch
feat_add_set_can_resize_mutator.patch
27 changes: 27 additions & 0 deletions patches/chromium/feat_add_set_can_resize_mutator.patch
@@ -0,0 +1,27 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com>
Date: Tue, 2 Aug 2022 09:30:36 -0700
Subject: feat: Add set_can_resize mutator

Adds a set_can_resize mutator to WidgetDelegate that
doesn't emit the OnSizeConstraintsChanged event.
This way, we can call set_can_resize from Electron before
the widget is initialized to set the value earlier,
and in turn, avoid showing a frame at startup
for frameless applications.

diff --git a/ui/views/widget/widget_delegate.h b/ui/views/widget/widget_delegate.h
index 3375d6c3629235413362c4ed3d8c5a0eb53e23cd..8f4002ef6f5aa9b2cd8c1c911806772518d71f4b 100644
--- a/ui/views/widget/widget_delegate.h
+++ b/ui/views/widget/widget_delegate.h
@@ -328,6 +328,10 @@ class VIEWS_EXPORT WidgetDelegate {
// be cycled through with keyboard focus.
virtual void GetAccessiblePanes(std::vector<View*>* panes) {}

+ // A setter for the can_resize parameter that doesn't
+ // emit any events.
+ void set_can_resize(bool can_resize) { params_.can_resize = can_resize; }
+
// Setters for data parameters of the WidgetDelegate. If you use these
// setters, there is no need to override the corresponding virtual getters.
void SetAccessibleRole(ax::mojom::Role role);
17 changes: 17 additions & 0 deletions shell/browser/native_window_views.cc
Expand Up @@ -281,7 +281,24 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
new ElectronDesktopWindowTreeHostLinux(this, native_widget);
#endif

// Ref https://github.com/electron/electron/issues/30760
// Set the can_resize param before initializing the widget.
// When resizable_ is true, this causes the WS_THICKFRAME style
// to be passed into CreateWindowEx and SetWindowLong calls in
// WindowImpl::Init and HwndMessageHandler::SizeConstraintsChanged
// respectively. As a result, the Windows 7 frame doesn't show,
// but it isn't clear why this is the case.
// When resizable_ is false, WS_THICKFRAME is not passed into the
// SetWindowLong call, so the Windows 7 frame still shows.
// One workaround would be to call set_can_resize(true) here,
// and then move the SetCanResize(resizable_) call after the
// SetWindowLong call around line 365, but that's a much larger change.
set_can_resize(true);
widget()->Init(std::move(params));

// When the workaround above is not needed anymore, only this
// call should be necessary.
// With the workaround in place, this call doesn't do anything.
SetCanResize(resizable_);

bool fullscreen = false;
Expand Down