Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X11 restrict mouse to visible area

Tags:

x11

mouse

xrandr

I am currently running Linux Mint 17.2 with Cinnamon. I have 2 monitors.

When I set monitors to be adjacent in Cinnamon settings, mouse freely moves through border shared between monitors but cannot escape visible area.

That is, if I set monitors to share only corner, mouse is effectively locked to current monitor and can escape to another only through corner.

However, setting monitors to be non-adjacent allows mouse to roam freely all over virtual framebuffer, including invisible areas.

I thought that Cinnamon sets some flag that controls this behavior, but changing monitor position using xrandr has the same effect.

Also, it is the same when I start plain Xorg with nothing but xterm, even without a window manager, and configure monitors using xrandr.

What exactly stops mouse from leaving visible area when all monitors are adjacent? Is there a way to override this behavior?

Being able to control this might be useful e.g. to stop mouse from leaving monitor every time you try to click something near border, without running a busy loop that monitors mouse and moves it back if needed (and without doubling framebuffer size by making monitors be adjacent by corner).

With more control it can be used to e.g. make mouse "reluctant" to leave current window, and maybe do other fun stuff. At least it will make it possible to reimplement this thing so that it can actually lock mouse to window for apps like Chrome browser or OpenGL games and not just xterm and the like.

Now that I think of it, I may even try to implement it, if it is not yet and if I find relevant code.

like image 964
EvgEnZh Avatar asked Oct 30 '22 14:10

EvgEnZh


1 Answers

Okay, I have found the relevant code.

This behavior is hardcoded in Xorg X server, in RandR extension, including visible area continuity check.

Definitely nothing configurable. Well, unless you agree with creator of dwm on what the word "configuration" means :)
I do agree. Right now relevant code locations are randr/rrpointer.c and randr/rrcrtc.c:332,1685.
Would be nice though if someone created a proper X srver extension for that.

like image 165
EvgEnZh Avatar answered Jan 04 '23 13:01

EvgEnZh