electron / electron/electron

Add API to get cursor position relative to the window

Open
#51,325 0 comments 2 reactions 0 assignees View on GitHub
component/BaseWindow enhancement :sparkles:
Dominant language
C++
Stars
123k
Forks
17.5k
Avg merge
14h 22m
Merged PRs (30d)
873

Description

### Preflight Checklist

- [x] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [x] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [x] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a feature request that matches the one I want to file, without success.

### Problem Description

It's possible to get the position of the mouse cursor relative to the display with `screen.getCursorPoint()`.

On Wayland, this function inadvertently gave the cursor position relative to the active _window_ rather than the display. While this was not the intended behaviour, it is still a useful capability which Electron should support for all platforms.

### Proposed Solution

Add a `BaseWindow.getCursorPoint()` API which provides coordinates relative to the window. (So 0,0 is the top left corner of the window.)

### Alternatives Considered

Developers can get the cursor position relative to web content with a DOM event listener in the renderer, e.g. `mousemove` event. However this does not work well if you use multiple web content views, and of course it does not work outside the web content area for framed windows.

### Additional Information

Refs https://github.com/electron/electron/issues/51153.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.