Build the X11 parts of Electron only when the X11 ozone platform is enabled.

Electron is only ever built with both ozone platforms, so X11 code has
leaked out of its SUPPORTS_OZONE_X11 guards: the X11 event and device
targets and libxshmfence are linked for every Linux build (and assert
ozone_platform_x11 in gn), the desktop capturer, native window and GTK
menu code use X11 types and helpers under a plain IS_LINUX, the offscreen
display client overrides a method Chromium only declares when the X11
platform is built, and x11_util compares against platform ids that only
exist in the generated platform list when that platform is built.

--- a/electron/BUILD.gn
+++ b/electron/BUILD.gn
@@ -750,7 +750,6 @@
     }
   }
   if (is_linux) {
-    libs = [ "xshmfence" ]
     deps += [
       ":electron_gtk_stubs",
       ":libnotify_loader",
@@ -763,8 +762,6 @@
       "//device/bluetooth",
       "//third_party/crashpad/crashpad/client",
       "//ui/base/ime/linux",
-      "//ui/events/devices/x11",
-      "//ui/events/platform/x11",
       "//ui/gtk:gtk_config",
       "//ui/linux:display_server_utils",
       "//ui/linux:linux_ui",
@@ -772,7 +769,12 @@
       "//ui/wm",
     ]
     if (ozone_platform_x11) {
+      libs = [ "xshmfence" ]
       sources += filenames.lib_sources_linux_x11
+      deps += [
+        "//ui/events/devices/x11",
+        "//ui/events/platform/x11",
+      ]
       public_deps += [
         "//ui/base/x",
         "//ui/ozone/platform/x11",
--- a/electron/shell/browser/api/electron_api_desktop_capturer.cc
+++ b/electron/shell/browser/api/electron_api_desktop_capturer.cc
@@ -55,7 +55,7 @@
 #endif
 
 namespace {
-#if BUILDFLAG(IS_LINUX)
+#if BUILDFLAG(SUPPORTS_OZONE_X11)
 // Private function in ui/base/x/x11_display_util.cc
 base::flat_map<x11::RandR::Output, int> GetMonitors(
     std::pair<uint32_t, uint32_t> version,
--- a/electron/shell/browser/linux/x11_util.cc
+++ b/electron/shell/browser/linux/x11_util.cc
@@ -5,12 +5,13 @@
 #include "shell/browser/linux/x11_util.h"
 
 #include "build/build_config.h"
+#include "ui/base/ozone_buildflags.h"
 #include "ui/ozone/platform_selection.h"  // nogncheck
 
 namespace x11_util {
 
 bool IsX11() {
-#if BUILDFLAG(IS_LINUX)
+#if BUILDFLAG(SUPPORTS_OZONE_X11)
   static const bool is = ui::GetOzonePlatformId() == ui::kPlatformX11;
   return is;
 #else
@@ -19,7 +20,7 @@
 }
 
 bool IsWayland() {
-#if BUILDFLAG(IS_LINUX)
+#if BUILDFLAG(SUPPORTS_OZONE_WAYLAND)
   static const bool is = ui::GetOzonePlatformId() == ui::kPlatformWayland;
   return is;
 #else
--- a/electron/shell/browser/native_window_views.cc
+++ b/electron/shell/browser/native_window_views.cc
@@ -355,6 +355,7 @@
   if (parent)
     SetParentWindow(parent);
 
+#if BUILDFLAG(SUPPORTS_OZONE_X11)
   if (x11_util::IsX11()) {
     // Before the window is mapped the SetWMSpecState can not work, so we have
     // to manually set the _NET_WM_STATE.
@@ -386,6 +387,7 @@
       SetWindowType(static_cast<x11::Window>(GetAcceleratedWidget()),
                     window_type);
   }
+#endif  // BUILDFLAG(SUPPORTS_OZONE_X11)
 #endif
 
 #if BUILDFLAG(IS_WIN)
@@ -553,7 +555,7 @@
 }
 
 void NativeWindowViews::SetGTKDarkThemeEnabled(bool use_dark_theme) {
-#if BUILDFLAG(IS_LINUX)
+#if BUILDFLAG(SUPPORTS_OZONE_X11)
   if (x11_util::IsX11()) {
     const std::string color = use_dark_theme ? "dark" : "light";
     auto* connection = x11::Connection::Get();
@@ -622,8 +624,10 @@
   NotifyWindowShow();
 
 #if BUILDFLAG(IS_LINUX)
+#if BUILDFLAG(SUPPORTS_OZONE_X11)
   if (global_menu_bar_)
     global_menu_bar_->OnWindowMapped();
+#endif
 
   // On X11, setting Z order before showing the window doesn't take effect,
   // so we have to call it again.
@@ -640,8 +644,10 @@
   NotifyWindowShow();
 
 #if BUILDFLAG(IS_LINUX)
+#if BUILDFLAG(SUPPORTS_OZONE_X11)
   if (global_menu_bar_)
     global_menu_bar_->OnWindowMapped();
+#endif
 
   // On X11, setting Z order before showing the window doesn't take effect,
   // so we have to call it again.
@@ -658,7 +664,7 @@
 
   NotifyWindowHide();
 
-#if BUILDFLAG(IS_LINUX)
+#if BUILDFLAG(SUPPORTS_OZONE_X11)
   if (global_menu_bar_)
     global_menu_bar_->OnWindowUnmapped();
 #endif
@@ -1039,7 +1045,7 @@
   ::SetWindowPos(GetAcceleratedWidget(), GetWindow(otherWindow, GW_HWNDPREV), 0,
                  0, 0, 0,
                  SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
-#else
+#elif BUILDFLAG(SUPPORTS_OZONE_X11)
   if (x11_util::IsX11()) {
     if (!IsWindowValid(static_cast<x11::Window>(id.id)))
       return false;
@@ -1061,7 +1067,7 @@
   ::SetWindowPos(GetAcceleratedWidget(), HWND_TOP, pos.x(), pos.y(),
                  size.width(), size.height(),
                  SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
-#else
+#elif BUILDFLAG(SUPPORTS_OZONE_X11)
   if (x11_util::IsX11())
     electron::MoveWindowToForeground(
         static_cast<x11::Window>(GetAcceleratedWidget()));
@@ -1415,10 +1421,13 @@
           views::DesktopWindowTreeHostLinux::GetHostForWidget(
               GetAcceleratedWidget()))) {
     tree_host->UpdateFrameHints();
+#if BUILDFLAG(SUPPORTS_OZONE_X11)
     if (x11_util::IsX11()) {
       // Round-trip so the server has applied the input shape on return.
       x11::Connection::Get()->Sync();
-    } else if (auto* compositor = tree_host->compositor()) {
+    } else
+#endif
+    if (auto* compositor = tree_host->compositor()) {
       // Wayland applies a new input region with the next surface commit; an
       // idle window may not produce one for a while, so force a frame.
       compositor->ScheduleFullRedraw();
@@ -1469,7 +1478,7 @@
 }
 
 void NativeWindowViews::SetMenu(ElectronMenuModel* menu_model) {
-#if BUILDFLAG(IS_LINUX)
+#if BUILDFLAG(SUPPORTS_OZONE_X11)
   // Remove global menu bar.
   bool try_global_menu_bar = true;
   if (global_menu_bar_ && menu_model == nullptr) {
@@ -1537,7 +1546,7 @@
 void NativeWindowViews::SetParentWindow(NativeWindow* parent) {
   NativeWindow::SetParentWindow(parent);
 
-#if BUILDFLAG(IS_LINUX)
+#if BUILDFLAG(SUPPORTS_OZONE_X11)
   if (x11_util::IsX11()) {
     auto* connection = x11::Connection::Get();
     connection->SetProperty(

--- a/electron/shell/browser/native_window_views.h
+++ b/electron/shell/browser/native_window_views.h
@@ -40,7 +40,7 @@
 
 namespace electron {
 
-#if BUILDFLAG(IS_LINUX)
+#if BUILDFLAG(SUPPORTS_OZONE_X11)
 class GlobalMenuBarX11;
 #endif
 
@@ -294,7 +294,9 @@
   extensions::SizeConstraints old_size_constraints_;
 
 #if BUILDFLAG(IS_LINUX)
+#if BUILDFLAG(SUPPORTS_OZONE_X11)
   std::unique_ptr<GlobalMenuBarX11> global_menu_bar_;
+#endif
 
   // Set while the window is disabled; running it re-enables event dispatch.
   base::ScopedClosureRunner enable_event_listening_;

--- a/electron/shell/browser/osr/osr_host_display_client.cc
+++ b/electron/shell/browser/osr/osr_host_display_client.cc
@@ -102,7 +102,7 @@
   layered_window_updater_->SetActive(active_);
 }
 
-#if BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) && BUILDFLAG(SUPPORTS_OZONE_X11)
 void OffScreenHostDisplayClient::DidCompleteSwapWithNewSize(
     const gfx::Size& size) {}
 #endif
--- a/electron/shell/browser/osr/osr_host_display_client.h
+++ b/electron/shell/browser/osr/osr_host_display_client.h
@@ -74,7 +74,7 @@
       mojo::PendingReceiver<viz::mojom::LayeredWindowUpdater> receiver)
       override;
 
-#if BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) && BUILDFLAG(SUPPORTS_OZONE_X11)
   void DidCompleteSwapWithNewSize(const gfx::Size& size) override;
 #endif
 
--- a/electron/shell/browser/ui/gtk/menu_util.cc
+++ b/electron/shell/browser/ui/gtk/menu_util.cc
@@ -20,10 +20,14 @@
 #include "ui/base/accelerators/menu_label_accelerator_util_linux.h"
 #include "ui/base/models/image_model.h"
 #include "ui/base/models/menu_model.h"
+#include "ui/base/ozone_buildflags.h"
 #include "ui/events/event_constants.h"
-#include "ui/events/keycodes/keyboard_code_conversion_x.h"
 #include "ui/ozone/public/ozone_platform.h"
 
+#if BUILDFLAG(SUPPORTS_OZONE_X11)
+#include "ui/events/keycodes/keyboard_code_conversion_x.h"
+#endif
+
 namespace electron::gtkui {
 
 namespace {
@@ -41,6 +45,7 @@
   return flags;
 }
 
+#if BUILDFLAG(SUPPORTS_OZONE_X11)
 guint GetGdkKeyCodeForAccelerator(const ui::Accelerator& accelerator) {
   // The second parameter is false because accelerator keys are expressed in
   // terms of the non-shift-modified key.
@@ -59,6 +64,7 @@
     modifier |= GDK_MOD1_MASK;
   return static_cast<GdkModifierType>(modifier);
 }
+#endif  // BUILDFLAG(SUPPORTS_OZONE_X11)
 
 }  // namespace
 
@@ -215,6 +221,7 @@
       connect_to_activate = false;
     }
 
+#if BUILDFLAG(SUPPORTS_OZONE_X11)
     if (x11_util::IsX11()) {
       ui::Accelerator accelerator;
       if (model->GetAcceleratorAt(i, &accelerator)) {
@@ -224,6 +231,7 @@
                                    GTK_ACCEL_VISIBLE);
       }
     }
+#endif
 
     g_object_set_data(G_OBJECT(menu_item), "model", model);
     AppendMenuItemToMenu(i, model, menu_item, menu, connect_to_activate,
