diff --git a/docs/api/screen.md b/docs/api/screen.md index c3bc334887..d3411069af 100644 --- a/docs/api/screen.md +++ b/docs/api/screen.md @@ -110,6 +110,8 @@ Returns [`Point`](structures/point.md) The current absolute position of the mouse pointer. +Not supported on Wayland (Linux). + > [!NOTE] > The return value is a DIP point, not a screen physical point. diff --git a/shell/browser/api/electron_api_screen.cc b/shell/browser/api/electron_api_screen.cc index 3b4cb6f7df..d403f68c8d 100644 --- a/shell/browser/api/electron_api_screen.cc +++ b/shell/browser/api/electron_api_screen.cc @@ -32,10 +32,6 @@ #include "shell/browser/linux/x11_util.h" #endif -#if defined(USE_OZONE) -#include "ui/ozone/public/ozone_platform.h" -#endif - namespace electron::api { gin::DeprecatedWrapperInfo Screen::kWrapperInfo = {gin::kEmbedderNativeGin}; @@ -81,16 +77,9 @@ Screen::~Screen() { } gfx::Point Screen::GetCursorScreenPoint(v8::Isolate* isolate) { -#if defined(USE_OZONE) - // Wayland will crash unless a window is created prior to calling - // GetCursorScreenPoint. - if (!ui::OzonePlatform::IsInitialized()) { - gin_helper::ErrorThrower thrower(isolate); - thrower.ThrowError( - "screen.getCursorScreenPoint() cannot be called before a window has " - "been created."); +#if BUILDFLAG(IS_LINUX) + if (x11_util::IsWayland()) return {}; - } #endif return screen_->GetCursorScreenPoint(); } diff --git a/shell/browser/linux/x11_util.cc b/shell/browser/linux/x11_util.cc index f65453b68d..e58c8fe4c8 100644 --- a/shell/browser/linux/x11_util.cc +++ b/shell/browser/linux/x11_util.cc @@ -4,13 +4,27 @@ #include "shell/browser/linux/x11_util.h" +#include "build/build_config.h" #include "ui/ozone/platform_selection.h" // nogncheck namespace x11_util { bool IsX11() { - static const bool is_x11 = ui::GetOzonePlatformId() == ui::kPlatformX11; - return is_x11; +#if BUILDFLAG(IS_LINUX) + static const bool is = ui::GetOzonePlatformId() == ui::kPlatformX11; + return is; +#else + return false; +#endif +} + +bool IsWayland() { +#if BUILDFLAG(IS_LINUX) + static const bool is = ui::GetOzonePlatformId() == ui::kPlatformWayland; + return is; +#else + return false; +#endif } } // namespace x11_util diff --git a/shell/browser/linux/x11_util.h b/shell/browser/linux/x11_util.h index 246d1b2aa2..d11ade313d 100644 --- a/shell/browser/linux/x11_util.h +++ b/shell/browser/linux/x11_util.h @@ -7,7 +7,8 @@ namespace x11_util { -bool IsX11(); +[[nodiscard]] bool IsX11(); +[[nodiscard]] bool IsWayland(); } // namespace x11_util