fix: screen.getCursorScreenPoint() crash on Wayland (#35503)

fix: screen.getCursorScreenPoint() crash on Wayland
This commit is contained in:
Shelley Vohr 2022-09-05 10:10:50 +02:00 committed by GitHub
parent 98c0fa1c8b
commit 2db0f7f8d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -24,6 +24,10 @@
#include "ui/display/win/screen_win.h" #include "ui/display/win/screen_win.h"
#endif #endif
#if defined(USE_OZONE)
#include "ui/ozone/public/ozone_platform.h"
#endif
namespace electron::api { namespace electron::api {
gin::WrapperInfo Screen::kWrapperInfo = {gin::kEmbedderNativeGin}; gin::WrapperInfo Screen::kWrapperInfo = {gin::kEmbedderNativeGin};
@ -68,7 +72,18 @@ Screen::~Screen() {
screen_->RemoveObserver(this); screen_->RemoveObserver(this);
} }
gfx::Point Screen::GetCursorScreenPoint() { 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.");
return gfx::Point();
}
#endif
return screen_->GetCursorScreenPoint(); return screen_->GetCursorScreenPoint();
} }

View file

@ -40,7 +40,7 @@ class Screen : public gin::Wrappable<Screen>,
Screen(v8::Isolate* isolate, display::Screen* screen); Screen(v8::Isolate* isolate, display::Screen* screen);
~Screen() override; ~Screen() override;
gfx::Point GetCursorScreenPoint(); gfx::Point GetCursorScreenPoint(v8::Isolate* isolate);
display::Display GetPrimaryDisplay(); display::Display GetPrimaryDisplay();
std::vector<display::Display> GetAllDisplays(); std::vector<display::Display> GetAllDisplays();
display::Display GetDisplayNearestPoint(const gfx::Point& point); display::Display GetDisplayNearestPoint(const gfx::Point& point);