--- electron/shell/browser/native_window_views.cc.orig 2026-06-29 20:35:15 UTC +++ electron/shell/browser/native_window_views.cc @@ -58,7 +58,7 @@ #include "ui/wm/core/shadow_types.h" #include "ui/wm/core/window_util.h" -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) #include "base/notimplemented.h" #include "shell/browser/browser.h" #include "shell/browser/linux/unity_service.h" @@ -288,7 +288,7 @@ NativeWindowViews::NativeWindowViews(const int32_t bas // If a client frame, we need to draw our own shadows. if (transparent() || has_client_frame()) params.opacity = InitParams::WindowOpacity::kTranslucent; -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) // Resize handles and shadows on frameless windows need translucent insets. if (!has_frame()) params.opacity = InitParams::WindowOpacity::kTranslucent; @@ -307,7 +307,7 @@ NativeWindowViews::NativeWindowViews(const int32_t bas params.parent = parent->GetNativeWindow(); params.native_widget = new ElectronDesktopNativeWidgetAura{this, widget()}; -#elif BUILDFLAG(IS_LINUX) +#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) // Set the WM_CLASS and XDG App ID to the same value // for best compatibility with both X11 and Wayland. const auto app_id = platform_util::GetXdgAppId(); @@ -337,7 +337,7 @@ NativeWindowViews::NativeWindowViews(const int32_t bas std::string window_type; options.Get(options::kType, &window_type); -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) // Set _GTK_THEME_VARIANT to dark if we have "dark-theme" option set. if (options.ValueOrDefault(options::kDarkTheme, false)) SetGTKDarkThemeEnabled(true); @@ -409,7 +409,7 @@ NativeWindowViews::NativeWindowViews(const int32_t bas ::SetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE, ex_style); #endif -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) options.Get(options::kRoundedCorners, &rounded_corner_); #endif @@ -529,7 +529,7 @@ void NativeWindowViews::SetTitleBarOverlay( auto* fv = widget()->non_client_view()->frame_view(); if (auto* frameless = views::AsViewClass(fv)) { frameless->InvalidateCaptionButtons(); -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) } else if (auto* fvl = views::AsViewClass(fv)) { fvl->InvalidateLayout(); fvl->SchedulePaint(); @@ -539,7 +539,7 @@ void NativeWindowViews::SetGTKDarkThemeEnabled(bool us } void NativeWindowViews::SetGTKDarkThemeEnabled(bool use_dark_theme) { -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) if (x11_util::IsX11()) { const std::string color = use_dark_theme ? "dark" : "light"; auto* connection = x11::Connection::Get(); @@ -600,7 +600,7 @@ void NativeWindowViews::Show() { NotifyWindowShow(); -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) if (global_menu_bar_) global_menu_bar_->OnWindowMapped(); @@ -616,7 +616,7 @@ void NativeWindowViews::ShowInactive() { NotifyWindowShow(); -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) if (global_menu_bar_) global_menu_bar_->OnWindowMapped(); @@ -635,7 +635,7 @@ void NativeWindowViews::Hide() { NotifyWindowHide(); -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) if (global_menu_bar_) global_menu_bar_->OnWindowUnmapped(); #endif @@ -666,7 +666,7 @@ bool NativeWindowViews::IsEnabled() const { bool NativeWindowViews::IsEnabled() const { #if BUILDFLAG(IS_WIN) return ::IsWindowEnabled(GetAcceleratedWidget()); -#elif BUILDFLAG(IS_LINUX) +#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) if (x11_util::IsX11()) return !event_disabler_.get(); NOTIMPLEMENTED(); @@ -891,7 +891,7 @@ void NativeWindowViews::SetBounds(const gfx::Rect& bou } #endif -#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) // On Linux and Windows the minimum and maximum size should be updated with // window size when window is not resizable. if (!CanResize()) { @@ -946,7 +946,7 @@ void NativeWindowViews::SetContentSizeConstraints( // of this to determine whether native widget has initialized. if (widget() && widget()->widget_delegate()) widget()->OnSizeConstraintsChanged(); -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) if (resizable_) old_size_constraints_ = GetSizeConstraints(); #endif @@ -1166,7 +1166,7 @@ bool NativeWindowViews::IsClosable() const { return false; } return !(info.fState & MFS_DISABLED); -#elif BUILDFLAG(IS_LINUX) +#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) return true; #endif } @@ -1306,7 +1306,7 @@ void NativeWindowViews::SetBackgroundColor(SkColor bac InvalidateRect(GetAcceleratedWidget(), nullptr, 1); #endif -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) // Widget and root view need to be transparent for CSD to draw shadow regions // and custom edges and corners. The web contents view will still be // painted with the true background color, which is cached in state. @@ -1325,7 +1325,7 @@ void NativeWindowViews::SetHasShadow(bool has_shadow) } void NativeWindowViews::SetHasShadow(bool has_shadow) { -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) auto* efvl = views::AsViewClass( widget()->non_client_view()->frame_view()); gfx::Rect visible_bounds; @@ -1341,7 +1341,7 @@ void NativeWindowViews::SetHasShadow(bool has_shadow) has_shadow ? wm::kShadowElevationInactiveWindow : wm::kShadowElevationNone); -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) if (efvl) { efvl->SetWantsFrame(!IsTranslucent() && (has_shadow || IsWindowControlsOverlayEnabled())); @@ -1457,7 +1457,7 @@ void NativeWindowViews::SetMenu(ElectronMenuModel* men } void NativeWindowViews::SetMenu(ElectronMenuModel* menu_model) { -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) // Remove global menu bar. if (global_menu_bar_ && menu_model == nullptr) { global_menu_bar_.reset(); @@ -1513,7 +1513,7 @@ void NativeWindowViews::SetParentWindow(NativeWindow* void NativeWindowViews::SetParentWindow(NativeWindow* parent) { NativeWindow::SetParentWindow(parent); -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) if (x11_util::IsX11()) { auto* connection = x11::Connection::Get(); connection->SetProperty( @@ -1567,7 +1567,7 @@ gfx::Insets NativeWindowViews::GetRestoredFrameBorderI if (auto* frameless = views::AsViewClass(frame_view)) return frameless->RestoredFrameBorderInsets(); -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) if (auto* fvl = views::AsViewClass(frame_view)) return fvl->GetRestoredFrameBorderInsets(); #endif @@ -1579,7 +1579,7 @@ void NativeWindowViews::SetProgressBar(double progress NativeWindow::ProgressState state) { #if BUILDFLAG(IS_WIN) taskbar_host_.SetProgressBar(GetAcceleratedWidget(), progress, state); -#elif BUILDFLAG(IS_LINUX) +#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) if (unity::IsRunning()) { unity::SetProgressFraction(progress); } @@ -1705,7 +1705,7 @@ content::DesktopMediaID NativeWindowViews::GetDesktopM #if BUILDFLAG(IS_WIN) window_handle = reinterpret_cast(accelerated_widget); -#elif BUILDFLAG(IS_LINUX) +#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) window_handle = static_cast(accelerated_widget); #endif aura::WindowTreeHost* const host = @@ -1835,7 +1835,7 @@ void NativeWindowViews::SetIcon(HICON window_icon, HIC SendMessage(hwnd, WM_SETICON, ICON_BIG, reinterpret_cast(app_icon_.get())); } -#elif BUILDFLAG(IS_LINUX) +#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) void NativeWindowViews::SetIcon(const gfx::ImageSkia& icon) { auto* tree_host = views::DesktopWindowTreeHostLinux::GetHostForWidget( GetAcceleratedWidget()); @@ -1956,7 +1956,7 @@ bool NativeWindowViews::CanMinimize() const { bool NativeWindowViews::CanMinimize() const { #if BUILDFLAG(IS_WIN) return minimizable_; -#elif BUILDFLAG(IS_LINUX) +#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) return true; #endif } @@ -2003,7 +2003,7 @@ std::unique_ptr NativeWindowViews::C #endif } -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) views::FrameViewLinux* NativeWindowViews::GetFrameViewLinux() const { auto* ncv = widget()->non_client_view(); if (!ncv) @@ -2022,7 +2022,7 @@ void NativeWindowViews::HandleKeyboardEvent( if (widget_destroyed_) return; -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) if (event.windows_key_code == ui::VKEY_BROWSER_BACK) NotifyWindowExecuteAppCommand(kBrowserBackward); else if (event.windows_key_code == ui::VKEY_BROWSER_FORWARD) @@ -2041,7 +2041,7 @@ void NativeWindowViews::OnMouseEvent(ui::MouseEvent* e // Alt+Click should not toggle menu bar. root_view_.ResetAltState(); -#if BUILDFLAG(IS_LINUX) +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD) if (event->changed_button_flags() == ui::EF_BACK_MOUSE_BUTTON) NotifyWindowExecuteAppCommand(kBrowserBackward); else if (event->changed_button_flags() == ui::EF_FORWARD_MOUSE_BUTTON)