mirror of
https://github.com/electron/electron.git
synced 2026-10-28 11:44:46 +08:00
fix: screen.getCursorScreenPoint() crash on Wayland (#50092)
* docs: document that getCursorScreenPoint() needs a Window on Wayland * feat: add IsWayland() helper * fix: Wayland crash in GetCursorScreenPoint() fix: support Screen::GetCursorScreenPoint() on X11
This commit is contained in:
1 parent
fbfd0ed3a4
commit
dc4ad2e932
4 files changed
+22
-16
No files matched your search
@@ -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.
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
const gin::WrapperInfo Screen::kWrapperInfo = {{gin::kEmbedderNativeGin},
|
||||
@@ -94,16 +90,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
|
||||
auto* screen = GetDisplayScreen();
|
||||
return screen ? screen->GetCursorScreenPoint() : gfx::Point{};
|
||||
|
||||
@@ -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
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
namespace x11_util {
|
||||
|
||||
bool IsX11();
|
||||
[[nodiscard]] bool IsX11();
|
||||
[[nodiscard]] bool IsWayland();
|
||||
|
||||
} // namespace x11_util
|
||||
|
||||
|
||||
Reference in new issue
Block a user