refactor: decouple NativeWindowViews and GlobalMenuBarX11 (#47117)

The GlobalMenuBar used to hold a raw_ptr reference to its NativeWindow;
but since it doesn't use it & only wants the gfx::AcceleratedWidget info,
let's remove the NativeWindowViews reference.

AFAICT, GlobalMenuBarX11::window_ has never been used

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2025-05-15 19:38:44 -05:00 committed by GitHub
parent f9bcea3bfc
commit af31ce0135
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 10 deletions

View file

@ -1397,7 +1397,8 @@ void NativeWindowViews::SetMenu(ElectronMenuModel* menu_model) {
.supports_global_application_menus;
if (can_use_global_menus && ShouldUseGlobalMenuBar()) {
if (!global_menu_bar_)
global_menu_bar_ = std::make_unique<GlobalMenuBarX11>(this);
global_menu_bar_ =
std::make_unique<GlobalMenuBarX11>(GetAcceleratedWidget());
if (global_menu_bar_->IsServerStarted()) {
root_view_.RegisterAcceleratorsWithFocusManager(menu_model);
global_menu_bar_->SetMenu(menu_model);

View file

@ -9,7 +9,6 @@
#include "base/functional/bind.h"
#include "base/strings/utf_string_conversions.h"
#include "shell/browser/native_window_views.h"
#include "shell/browser/ui/electron_menu_model.h"
#include "shell/browser/ui/views/global_menu_bar_registrar_x11.h"
#include "third_party/abseil-cpp/absl/strings/str_format.h"
@ -173,10 +172,8 @@ std::string GetMenuModelStatus(ElectronMenuModel* model) {
} // namespace
GlobalMenuBarX11::GlobalMenuBarX11(NativeWindowViews* window)
: window_(window),
xwindow_(static_cast<x11::Window>(
window_->GetNativeWindow()->GetHost()->GetAcceleratedWidget())) {
GlobalMenuBarX11::GlobalMenuBarX11(gfx::AcceleratedWidget accelerated_widget)
: xwindow_(static_cast<x11::Window>(accelerated_widget)) {
EnsureMethodsLoaded();
if (server_new)
InitServer(xwindow_);

View file

@ -22,8 +22,6 @@ class Accelerator;
namespace electron {
class NativeWindowViews;
// Controls the Mac style menu bar on Unity.
//
// Unity has an Apple-like menu bar at the top of the screen that changes
@ -37,7 +35,7 @@ class NativeWindowViews;
// from menu models instead, and it is also per-window specific.
class GlobalMenuBarX11 {
public:
explicit GlobalMenuBarX11(NativeWindowViews* window);
explicit GlobalMenuBarX11(gfx::AcceleratedWidget accelerated_widget);
virtual ~GlobalMenuBarX11();
// disable copy
@ -68,7 +66,6 @@ class GlobalMenuBarX11 {
void OnItemActivated(DbusmenuMenuitem* item, unsigned int timestamp);
void OnSubMenuShow(DbusmenuMenuitem* item);
raw_ptr<NativeWindowViews> window_;
x11::Window xwindow_;
raw_ptr<DbusmenuServer> server_ = nullptr;