Mouse positioning in Linux

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Mouse positioning in Linux

Post by grump »

I have some trouble with love.mouse.getPosition and .setPosition on my Linux system.

Code: Select all

function love.draw()
	love.graphics.print(("%d %d"):format(love.mouse.getPosition()))
end
This prints 0, 0 regardless of where the cursor actually is when the game starts. Only after the user moves the mouse, the coordinates become correct.

Calling love.mouse.setPosition(500, 500) makes it show 500, 500 instead, but the cursor does not move to that position. love.mouse.setPosition does never actually move the cursor on my system.

Code: Select all

function love.draw()
	love.graphics.print(("%d %d"):format(love.mouse.getPosition()))
	love.mouse.setPosition(500, 500) --  does not move mouse cursor to 500, 500
end
I tested this on my Linux machine in 0.10.2 and 11.1, both versions show the same behavior. It works as expected in Windows.

Code: Select all

$ uname -a
Linux deb9 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) x86_64 GNU/Linux
Is this a bug in LÖVE? Or my system? Is it a known limitation?

It's a minor problem, but a GUI element at 0, 0 assumes it's being hovered, even though the cursor is pointing at a different element when the game starts.
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Mouse positioning in Linux

Post by pgimeno »

The getMousePosition problem is happening since 0.9.0, which IIRC is the first version to use SDL2, so I'd say that's the likely culprit.

setMousePosition works for me, with the quirk that when the cursor starts outside the window, even after using setMousePosition, I still get the old coordinates from getMousePosition. The same happens if the cursor is already at the destination position when I call setMousePosition, which is kind of unsurprising but a bit annoying.

I'm using Debian's libsdl2-2.0-0:amd64 2.0.5+dfsg1-2. Not sure if it matters, but I've installed xserver-xorg-input-evdev.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Mouse positioning in Linux

Post by grump »

Okay, thanks for the info.

So I tried this:

Code: Select all

ffi = require('ffi')

ffi.cdef [[
	void SDL_WarpMouseGlobal(int x, int y);
	void SDL_WarpMouseInWindow(void* window, int x, int y);
	const char* SDL_GetError(void);
	void SDL_ClearError();
]]

print(ffi.string(ffi.C.SDL_GetError()))
ffi.C.SDL_ClearError()
ffi.C.SDL_WarpMouseGlobal(500, 500)
print(ffi.string(ffi.C.SDL_GetError()))
ffi.C.SDL_WarpMouseInWindow(nil, 500, 500)
print(ffi.string(ffi.C.SDL_GetError()))
But no mouse related error came up (and no cursor move). Just this:

Code: Select all

glXSwapIntervalMESA failed
...which at least explains why vsync isn't working for me.
Post Reply

Who is online

Users browsing this forum: No registered users and 89 guests