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 1842

Summary: [patch] SDL_SetWindowPosition sets bad position values when given SDL_WINDOWPOS_CENTERED args
Product: SDL Reporter: Alex Szpakowski <amaranth72>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: x86_64   
OS: Mac OS X 10.7   
Attachments: Patch to fix SDL_SetWindowPosition with SDL_WINDOWPOS_CENTERED

Description Alex Szpakowski 2013-05-07 23:05:03 UTC
Created attachment 1133 [details]
Patch to fix SDL_SetWindowPosition with SDL_WINDOWPOS_CENTERED

When calling SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED), the window moves to the correct position but it seems to internally set its x/y position values to the literal value of the SDL_WINDOWPOS_CENTERED define.
This causes all sorts of problems when SDL functions which use the window position (e.g. SDL_SetWindowGrab) are called after the aforementioned SDL_SetWindowPosition call.

Looking at the SDL_SetWindowPosition code, it seems that SDL_SendWindowEvent with the SDL_WINDOWEVENT_MOVED event is called at the end of the function using the literal value of the SDL_WINDOWPOS_CENTERED define, instead of the newly set window->x and window->y values.
SDL_SendWindowEvent then sets the values of window->windowed.x and window->windowed.y to that value (0x2FFF0000, aka 805240832.)

I have attached a patch which changes SDL_SetWindowPosition to make sure SDL_SendWindowEvent is called with the correct coordinate values, if SDL_WINDOWPOS_CENTERED is used (fixes the issue for me.)

Tested with Mac OS 10.8.3.
Comment 1 Sam Lantinga 2013-05-20 01:37:17 UTC
Fixed, thanks!
http://hg.libsdl.org/SDL/rev/d206c3a59b2e