itch.io is community of indie game creators and players

Devlogs

A Linux version

Native mouselock for GameMaker
A downloadable extension for Windows

A few people asked about this over years and the Linux API is kind of similar, so there’s this.

  • The respective X11 function (XGrabPointer) can only lock the mouse to the window (not a specific screen region), so display_mouse_lock’s arguments will be ignored on Linux.
  • display_mouse_unlock works as usual.
  • I added a display_mouse_lock_auto() function to auto-lock to window region for consistency between Windows/Linux.
  • Since X11 doesn’t let you lock mouse to a region, display_mouse_bounds will return undefined on Linux.

Anyway, the following will work both on Windows and Linux:

if (window_has_focus()) {
	display_mouse_lock_auto();
} else {
	display_mouse_unlock();
}

“But what about Mac?”

As far as I can tell, CGAssociateMouseAndMouseCursorPosition is the closest approximation of mouse locking on Mac OS, which is what window_mouse_set_locked uses. There’s no benefit to me re-implementing it in an extension.

Files

  • display_mouse_lock (for GM2022+).yymps 11 kB
    3 days ago
  • display_mouse_lock_demo (for GM2022+).yyz 37 kB
    3 days ago
Download Native mouselock for GameMaker
Leave a comment