godotengine / godotengine/godot

[InputEvent] Event mouse y position is incorrect by 1px unless game is played embedded in the editor

Open
#113,406 5 comments 0 reactions 0 assignees View on GitHub
bug needs testing topic:editor topic:input
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

Reproducible in 4.5.x and latest master commit ffa5cf956.

### System information

MacOS 14.7.5

### Issue description

`InputEvent` mouse position `y` values are offset incorrectly by `-1` pixel for exported projects and when the game is played in the Editor in non-embedded mode. When played embedded, the `InputEvent` mouse position `y` value is correct. This can be verified against `get_local_mouse_position` at the time of the `InputEvent`.

This shows up per below in bugs in `FoldableContainer` where the hover highlighting is orphaned because the mouse leaves the title area while `_get_title_rect().has_point` is still returning true.

The `FoldableContainer` bug can be hacked to work correctly by replacing `m->get_position()` below with `get_local_mouse_position`, but it seems like this important issue should be fixed instead.

Before I tracked this down, the same 1px error was confounding me while fixing issues with `PopupMenu` where I could not figure out why hacking a 1 pixel y shift would correct an unexplained offset. Fixing this issue will also improve the mouse detection alignment in `PopupMenu` because I did not add any hack there.

```
void FoldableContainer::gui_input(const Ref &p_event) {
ERR_FAIL_COND(p_event.is_null());

Ref m = p_event;
if (m.is_valid()) {
if (_get_title_rect().has_point(m->get_position())) {
if (!is_hovering) {
is_hovering = true;
queue_redraw();
}
```
1 Pixel Y offset in non-embedded game window with orphaned hover highlighting. Notice the mismatched postion Y values between `event.position` and `get_local_mouse_position`. This is consistent also in `gui_input` inside `foldable_container.cpp`.

https://github.com/user-attachments/assets/3308fa95-412b-4d39-b75e-4b1da2acc91f

This is with the game window embedded in the Editor. Now the positions are in concurrence and the highlighting bug goes away.

https://github.com/user-attachments/assets/be4acf1b-f019-400c-a3af-430f0a26ab5b

### Steps to reproduce

See MRP.

### Minimal reproduction project (MRP)

[foldable-container-issues.zip](https://github.com/user-attachments/files/23860380/foldable-container-issues.zip)

Contributor guide

Open the contributing guide

Research direction

Start with the attached foldable-container-issues.zip MRP and compare InputEvent mouse positions with get_local_mouse_position in exported and non-embedded runs. Read FoldableContainer::gui_input in foldable_container.cpp, then inspect the related PopupMenu behavior. Done means the y values agree and FoldableContainer hover highlighting works without a one-pixel workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.