Proper way to hide cursor until manually un-hidden

I need to make an extension that can hide the cursor and have it stay hidden until a key combination is pressed.

There is global.backend.get_cursor_tracker().set_pointer_visible(false); but as soon as I move the mouse it becomes visible again. So I have tried using global.backend.get_cursor_tracker().connect("visibility-changed", callback) but it’s unreliable (waving the cursor makes it briefly appear sometimes), and the mouse becomes unable to click.

Is there a better way to do this?

1 Like

The API changed to inhibit_cursor_visibility()/uninhibit_cursor_visibility() for the upcoming GNOME 49 release, which should address this (assuming all callers pair their calls correctly).

But right now different components that want to control the cursor visibility based on different conditions are bound to step on each other’s toes, so the work-around of tracking visibility changes and re-hiding is the best you can do.

Thanks for the response, I have some follow-up questions.
First of all, is it possible to get a better result by changing the cursor shape to a transparent or empty image? Is there an api for that?

And second, I have tried .connect('visibility-changed',callback) and .disconnect('visibility-changed',callback) in LookingGlass, and it fails to disconnect, i get stuck with the invisible cursor. Is it a LookingGlass issue or should I be something else to disconnect?

I doubt it. Instead of fighting over the cursor visibility, you would fight over the current cursor. Keep in mind that apps usually change the cursor depending on the hovered element (text, links, resize, …), so this is likely much worse.

Yes, that’s not how you disconnect a signal handler. .connect() returns an integer, use that to disconnect the handler.

Alright, thanks for the help. Now I can program the actual extension

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.