From fcd33136c8001e1af6c6c06768e9ee03071bac12 Mon Sep 17 00:00:00 2001 From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com> Date: Tue, 2 Aug 2022 09:51:27 -0700 Subject: [PATCH 1/6] fix: Frameless window shows frame while opening --- patches/chromium/.patches | 2 + .../feat_add_set_can_resize_mutator.patch | 42 +++++++++++++++++++ shell/browser/native_window_views.cc | 6 +++ 3 files changed, 50 insertions(+) create mode 100644 patches/chromium/feat_add_set_can_resize_mutator.patch diff --git a/patches/chromium/.patches b/patches/chromium/.patches index 37cda2f133e14..decf73ebeba20 100644 --- a/patches/chromium/.patches +++ b/patches/chromium/.patches @@ -134,3 +134,5 @@ cherry-pick-60d8559e150a.patch cherry-pick-54a7927b19f9.patch cherry-pick-bd9724c9fe63.patch cherry-pick-c643d18a078d.patch +add_electron_deps_to_license_credits_file.patch +feat_add_set_can_resize_mutator.patch diff --git a/patches/chromium/feat_add_set_can_resize_mutator.patch b/patches/chromium/feat_add_set_can_resize_mutator.patch new file mode 100644 index 0000000000000..bbb1129c258bc --- /dev/null +++ b/patches/chromium/feat_add_set_can_resize_mutator.patch @@ -0,0 +1,42 @@ +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.cc b/ui/views/widget/widget_delegate.cc +index 6d58e740b5693c0f70eecce88593851f43c5d020..41a233a3c7a5bbf88fa13bd43ec607fda53cd7de 100644 +--- a/ui/views/widget/widget_delegate.cc ++++ b/ui/views/widget/widget_delegate.cc +@@ -299,6 +299,10 @@ bool WidgetDelegate::ShouldDescendIntoChildForEventHandling( + return true; + } + ++void WidgetDelegate::set_can_resize(bool can_resize) { ++ params_.can_resize = can_resize; ++} ++ + void WidgetDelegate::SetAccessibleRole(ax::mojom::Role role) { + params_.accessible_role = role; + } +diff --git a/ui/views/widget/widget_delegate.h b/ui/views/widget/widget_delegate.h +index 431d19f2543a9011de76b941982603ff98afa041..301b13d08cc87006535acd3770f6d7d0ef6d8459 100644 +--- a/ui/views/widget/widget_delegate.h ++++ b/ui/views/widget/widget_delegate.h +@@ -323,6 +323,10 @@ class VIEWS_EXPORT WidgetDelegate { + // be cycled through with keyboard focus. + virtual void GetAccessiblePanes(std::vector* panes) {} + ++ // A setter for the can_resize parameter that doesn't ++ // emit any events. ++ void set_can_resize(bool 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); diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 51ccfef8c689f..8b74c3ab0758d 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -281,7 +281,13 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options, new ElectronDesktopWindowTreeHostLinux(this, native_widget); #endif + // We want to set the can_resize param before initializing + // the widget, but we want to do it without emitting any events. + set_can_resize(resizable_); widget()->Init(std::move(params)); + + // Now that the widget is initialized, use the + // regular SetCanResize so that events can be emitted if needed. SetCanResize(resizable_); bool fullscreen = false; From 750f35df585256cf7a403a3d84bddbbbe0e5a940 Mon Sep 17 00:00:00 2001 From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com> Date: Fri, 12 Aug 2022 13:52:19 -0700 Subject: [PATCH 2/6] Clarify comments --- shell/browser/native_window_views.cc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 8b74c3ab0758d..0f1496b23c2af 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -281,13 +281,23 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options, new ElectronDesktopWindowTreeHostLinux(this, native_widget); #endif - // We want to set the can_resize param before initializing - // the widget, but we want to do it without emitting any events. - set_can_resize(resizable_); + // 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 either + // 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)); - // Now that the widget is initialized, use the - // regular SetCanResize so that events can be emitted if needed. + // 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; From 50776e97945721101f0eff422aa96b6e012d4cce Mon Sep 17 00:00:00 2001 From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com> Date: Fri, 12 Aug 2022 13:59:59 -0700 Subject: [PATCH 3/6] Inline setter --- .../feat_add_set_can_resize_mutator.patch | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/patches/chromium/feat_add_set_can_resize_mutator.patch b/patches/chromium/feat_add_set_can_resize_mutator.patch index bbb1129c258bc..5b2adba9ecd49 100644 --- a/patches/chromium/feat_add_set_can_resize_mutator.patch +++ b/patches/chromium/feat_add_set_can_resize_mutator.patch @@ -10,23 +10,8 @@ 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.cc b/ui/views/widget/widget_delegate.cc -index 6d58e740b5693c0f70eecce88593851f43c5d020..41a233a3c7a5bbf88fa13bd43ec607fda53cd7de 100644 ---- a/ui/views/widget/widget_delegate.cc -+++ b/ui/views/widget/widget_delegate.cc -@@ -299,6 +299,10 @@ bool WidgetDelegate::ShouldDescendIntoChildForEventHandling( - return true; - } - -+void WidgetDelegate::set_can_resize(bool can_resize) { -+ params_.can_resize = can_resize; -+} -+ - void WidgetDelegate::SetAccessibleRole(ax::mojom::Role role) { - params_.accessible_role = role; - } diff --git a/ui/views/widget/widget_delegate.h b/ui/views/widget/widget_delegate.h -index 431d19f2543a9011de76b941982603ff98afa041..301b13d08cc87006535acd3770f6d7d0ef6d8459 100644 +index 431d19f2543a9011de76b941982603ff98afa041..32e07e0c9686e6942a40c4d4775a03068cfd33b5 100644 --- a/ui/views/widget/widget_delegate.h +++ b/ui/views/widget/widget_delegate.h @@ -323,6 +323,10 @@ class VIEWS_EXPORT WidgetDelegate { @@ -35,7 +20,7 @@ index 431d19f2543a9011de76b941982603ff98afa041..301b13d08cc87006535acd3770f6d7d0 + // A setter for the can_resize parameter that doesn't + // emit any events. -+ void set_can_resize(bool can_resize); ++ 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. From b0e088790fe1cb5006433654855198aaf6049bd9 Mon Sep 17 00:00:00 2001 From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com> Date: Mon, 15 Aug 2022 09:50:54 -0700 Subject: [PATCH 4/6] Edit comment --- shell/browser/native_window_views.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 0f1496b23c2af..26a377e041477 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -281,17 +281,18 @@ 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 either - // 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. + // 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)); From 2e0eba2743accc27f3156731871c14cb856afcc1 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Tue, 16 Aug 2022 14:31:27 -0700 Subject: [PATCH 5/6] Update .patches --- patches/chromium/.patches | 1 - 1 file changed, 1 deletion(-) diff --git a/patches/chromium/.patches b/patches/chromium/.patches index decf73ebeba20..08ca41ab56fd1 100644 --- a/patches/chromium/.patches +++ b/patches/chromium/.patches @@ -134,5 +134,4 @@ cherry-pick-60d8559e150a.patch cherry-pick-54a7927b19f9.patch cherry-pick-bd9724c9fe63.patch cherry-pick-c643d18a078d.patch -add_electron_deps_to_license_credits_file.patch feat_add_set_can_resize_mutator.patch From 221205deda3b051aa4be052408e244281e13b6d0 Mon Sep 17 00:00:00 2001 From: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Date: Tue, 16 Aug 2022 21:43:57 +0000 Subject: [PATCH 6/6] chore: update patches --- patches/chromium/feat_add_set_can_resize_mutator.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patches/chromium/feat_add_set_can_resize_mutator.patch b/patches/chromium/feat_add_set_can_resize_mutator.patch index 5b2adba9ecd49..6fd8a960658a8 100644 --- a/patches/chromium/feat_add_set_can_resize_mutator.patch +++ b/patches/chromium/feat_add_set_can_resize_mutator.patch @@ -11,10 +11,10 @@ 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 431d19f2543a9011de76b941982603ff98afa041..32e07e0c9686e6942a40c4d4775a03068cfd33b5 100644 +index 3375d6c3629235413362c4ed3d8c5a0eb53e23cd..8f4002ef6f5aa9b2cd8c1c911806772518d71f4b 100644 --- a/ui/views/widget/widget_delegate.h +++ b/ui/views/widget/widget_delegate.h -@@ -323,6 +323,10 @@ class VIEWS_EXPORT WidgetDelegate { +@@ -328,6 +328,10 @@ class VIEWS_EXPORT WidgetDelegate { // be cycled through with keyboard focus. virtual void GetAccessiblePanes(std::vector* panes) {}