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 - [X11] relative mouse value is jumpy when pointer change window
Summary: [X11] relative mouse value is jumpy when pointer change window
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: 2.0.3
Hardware: x86_64 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-23 06:09 UTC by Cengiz
Modified: 2016-01-08 06:26 UTC (History)
2 users (show)

See Also:


Attachments
relative mouse value is jumpy when pointer change window (543 bytes, patch)
2015-07-23 06:09 UTC, Cengiz
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.