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 3067

Summary: [X11] relative mouse value is jumpy when pointer change window
Product: SDL Reporter: Cengiz <yaakuro>
Component: eventsAssignee: Ryan C. Gordon <icculus>
Status: ASSIGNED --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: icculus, sezeroz
Version: 2.0.3   
Hardware: x86_64   
OS: Linux   
Attachments: relative mouse value is jumpy when pointer change window

Description Cengiz 2015-07-23 06:09:56 UTC
Created attachment 2223 [details]
relative mouse value is jumpy when pointer change window

Hi there, 

hi icculus. I think you know already about this. Here the issue in short. When the mouse pointer leaves a window and enters another window the xrel, yrel values jumps. Here a print out:

WindowID: 2, abs=(319, 64) rel=(320, -5)
WindowID: 2, abs=(318, 64) rel=(-1, 0)
WindowID: 2, abs=(319, 64) rel=(1, 0)
WindowID: 2, abs=(319, 64) rel=(1, 0)
WindowID: 3, abs=(0, 64) rel=(-320, 0)
WindowID: 3, abs=(1, 64) rel=(1, 0)
WindowID: 3, abs=(2, 64) rel=(1, 0)
WindowID: 3, abs=(3, 64) rel=(1, 0)
WindowID: 3, abs=(2, 64) rel=(-1, 0)
WindowID: 3, abs=(1, 64) rel=(-1, 0)
WindowID: 3, abs=(0, 64) rel=(-1, 0)
WindowID: 3, abs=(0, 64) rel=(-1, 0)
WindowID: 2, abs=(319, 62) rel=(320, -2)
WindowID: 2, abs=(318, 62) rel=(-1, 0)
WindowID: 2, abs=(317, 62) rel=(-1, 0)
WindowID: 2, abs=(318, 62) rel=(1, 0)
WindowID: 2, abs=(319, 62) rel=(1, 0)
WindowID: 2, abs=(319, 62) rel=(1, 0)
WindowID: 3, abs=(0, 64) rel=(-320, 2)
WindowID: 3, abs=(1, 64) rel=(1, 0)
WindowID: 3, abs=(2, 64) rel=(1, 0)

As you can see the jump happens when pointer changes the window. This happens for the y direction too.

Here my test code:

#include <SDL.h>
#include <stdio.h>

int main(int argc, char **argv)
{
	SDL_Init(SDL_INIT_EVERYTHING);
	SDL_Window* window1 = SDL_CreateWindow("Window 1", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,320, 200, 0);
	SDL_Window* window2 = SDL_CreateWindow("Window 2", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 320, 200, 0);

	while(true) {
		SDL_Event e;
		if(SDL_PollEvent(&e)) {
			if(e.type == SDL_QUIT) {
                break;
            } else if(e.type == SDL_KEYDOWN) {
                break;
            } else if(e.type == SDL_MOUSEMOTION) {
                printf("WindowID: %d, abs=(%d, %d) rel=(%d, %d)\n", e.window.windowID, (int)e.motion.x, (int)e.motion.y, (int)e.motion.xrel, (int)e.motion.yrel);
            }
		}
	}
	SDL_DestroyWindow(window1);
    SDL_DestroyWindow(window2);
	SDL_Quit();
	return 0;
}

Just move one window away from the other and move the pointer from one window to the other.
In the attachment I put a fix. Not sure if that is the best solution but it works. Entering a window should reset the last_x, last_y variables of the mouse pointer.


Cengiz (yaakuro)
Comment 1 Ryan C. Gordon 2016-01-08 06:24:10 UTC
This patch is now https://hg.libsdl.org/SDL/rev/e1f07cbb3c86, thanks!

--ryan.
Comment 2 Ryan C. Gordon 2016-01-08 06:26:11 UTC
This patch appears to solve the problem for X11, but I have a suspicion this bug hits other platforms, too. 

I'll look into resetting last_x/last_y in SDL_OnWindowEnter() before I resolve this bug fully, but we appear good to go in the place we're specifically seeing this issue (multi-window UnrealEd on Linux).

--ryan.