We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5246

Summary: [Windows] Right-clicking on a window's title bar to open the context menu, then clicking inside the window gives the wrong coordinates
Product: SDL Reporter: jackmacwindowslinux
Component: eventsAssignee: Sam Lantinga <slouken>
Status: NEW --- QA Contact: Sam Lantinga <slouken>
Severity: minor    
Priority: P2    
Version: 2.0.12   
Hardware: x86_64   
OS: Windows 10   
Attachments: A screenshot with the events being sent

Description jackmacwindowslinux 2020-07-31 20:17:53 UTC
Created attachment 4431 [details]
A screenshot with the events being sent

I'm experiencing a problem in a program I wrote that uses SDL2. If you right-click on the title bar or click on the application icon in the corner (opening the window context menu), and then click inside the window to close the menu, the X and Y coordinates of the following MOUSEBUTTONDOWN event are extremely off. From my testing, I've seen that the X coordinate of the event much higher than the actual mouse position (though never higher than the window's width), and the Y coordinate is always 0. A user reported this issue with the Y value around 200, though, so I'm not sure why it's always 0 for me.

To reproduce:
1. Open a new SDL window with events being printed somewhere (e.g. console).
2. Right-click anywhere on the title bar of the window, or click on the window icon on the top-left. This should open a context menu.
3. Click back inside the window while the menu is still open.
4. Check for MOUSEBUTTONDOWN and MOUSEMOTION events in the console.

There should only be one MOUSEBUTTONDOWN event that fires when you click the window with the right coordinates, but instead there's one MOUSEBUTTONDOWN event with the wrong coordinates (possibly with the coordinates of the right-click?), and one MOUSEMOTION event with the right coordinates.

I've attached a screenshot showing the events being sent to the program. The mouse_click events are the MOUSEBUTTONDOWN events after clicking inside the window, with a coordinate conversion formula applied. The first number is the button (1 = left click), the second number is the X in character positions, and the third number is the Y in character positions. Notice the mouse_drag events afterward - those are MOUSEMOTION events that are sent right after the mouse_click event. These events have the right coordinates and accurately represent where I clicked.

Here's the bug report that was filed for my program, which also has a screenshot: https://github.com/MCJack123/craftos2/issues/127

If necessary, you can approximate the X and Y coordinates from character positions to the original coords sent by SDL2 with these equations:
SDL_X = (X - 1) * 12 + 4
SDL_Y = (Y - 1) * 18 + 4