Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion shell/browser/api/electron_api_screen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include "ui/display/win/screen_win.h"
#endif

#if defined(USE_OZONE)
#include "ui/ozone/public/ozone_platform.h"
#endif

namespace electron::api {

gin::WrapperInfo Screen::kWrapperInfo = {gin::kEmbedderNativeGin};
Expand Down Expand Up @@ -68,7 +72,18 @@ Screen::~Screen() {
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();
}

Expand Down
2 changes: 1 addition & 1 deletion shell/browser/api/electron_api_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Screen : public gin::Wrappable<Screen>,
Screen(v8::Isolate* isolate, display::Screen* screen);
~Screen() override;

gfx::Point GetCursorScreenPoint();
gfx::Point GetCursorScreenPoint(v8::Isolate* isolate);
display::Display GetPrimaryDisplay();
std::vector<display::Display> GetAllDisplays();
display::Display GetDisplayNearestPoint(const gfx::Point& point);
Expand Down