Is retrieving non-relative mouse position possible?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Pixelguru26
Prole
Posts: 15
Joined: Fri Feb 05, 2016 11:52 pm

Is retrieving non-relative mouse position possible?

I'm working on a borderless application, since I would like to add my own sort of "custom border" with all of the same options.
However, I'm having a problem making the window draggable or resizeable since I cannot get absolute, system-wide mouse position; only mouse position relative to the window. Does anyone know of a way to retrieve this information via built-in features or an elegant workaround?

zorg
Party member
Posts: 2735
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Is retrieving non-relative mouse position possible?

Yes, since i had this exact same problem beforehand (Dragging the window too fast made the mouse cursor intermittently exit the application's window, hence it slowed the dragging to a crawl after a certain point...)

I solved this by using FFI, and SDL's SDL_GetGlobalMouseState that Löve sadly doesn't expose.

I may have a working snippet too somewhere... not online, sorry; either you wait till i get home tomorrow, and then i might find it on my computer, or someone else could help with it in the mean time.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

Pixelguru26
Prole
Posts: 15
Joined: Fri Feb 05, 2016 11:52 pm

Re: Is retrieving non-relative mouse position possible?

This sounds perfect! I will look into this while I await your snippets. Thank you for the help!

zorg
Party member
Posts: 2735
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Is retrieving non-relative mouse position possible?

Okay, so we both lucky, since i did have the relevant .love file in my dropbox.

Here's the gist of it (har har)

Edit: Just a bit more info on usage. (Yes, it supports multiple displays, and hopefully even non-entirely convex layouts as well.)

Code: Select all

 local desktop = require 'path.to.file.name.without.lua.extension' -- a bit more realistic, of course.
local coordsys = desktop() -- creates a new instance, totally a byproduct of how i coded the library, but whatever.
-- 3 functions you can use

-- Gives you back the current (primary) mouse cursor position in desktop coordinates.
local gx, gy = coordsys:getGlobalMousePosition() -- or coordsys.getGlobalMousePosition(coordsys), similarly applies to the 2 below functions

-- Gives you back desktop coordinates of the display-local coordinates of one specific display
-- This works independently of what display Löve's window is actually, but it's still a neat byproduct of how the library works.
local gx, gy = coordsys:toGlobalPosition(screenX, screenY, display)

-- Gives you back the display-local coordinates and the display index from desktop-coordinates
-- This again works independently of Löve's window.
local screenX, screenY, display = coordsys:toScreenPosition(gx, gy)
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

Pixelguru26
Prole
Posts: 15
Joined: Fri Feb 05, 2016 11:52 pm

Re: Is retrieving non-relative mouse position possible?

Oh, this is perfect, and extremely robust! Thank you so much, this'll be a great help!

zorg
Party member
Posts: 2735
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Is retrieving non-relative mouse position possible?

No problem, though fair warning, i sadly didn't have time to really test it out, despite it seemingly working, it might have some flaws; i'll try to get some time later so i can really release it as a lib, instead of just a gist.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

Who is online

Users browsing this forum: Google [Bot] and 13 guests