You are not logged in.

#1 2024-11-09 19:19:35

itarill
Member
Registered: 2020-06-03
Posts: 60

Kwin rule to limit mouse to area

I would like to limit my cursor movement if a specific window is open. The window is full screen and so I assume it wouldn't make a problem in general. My problem is that I am completely foreign to kwin rules, and chatGPT did not really give a working solution I can import:

~/.local/share/kwin/scripts/limit_mouse/contents/code/main.js

var targetWindowTitle = "whatever";
var restrictedHeight = screenGeometry(0).height - 10;

function limitMouseMovement() {
    var currentWindow = workspace.activeClient;
    if (currentWindow && currentWindow.caption.includes(targetWindowTitle)) {
        var mousePos = workspace.cursorPos;
        if (mousePos.y > restrictedHeight) {
            workspace.cursorPos = {
                x: mousePos.x,
                y: restrictedHeight
            };
        }
    }
}

workspace.clientActivated.connect(limitMouseMovement);
workspace.clientMinimized.connect(limitMouseMovement);
workspace.clientUnminimized.connect(limitMouseMovement);
workspace.cursorPosChanged.connect(limitMouseMovement);

~/.local/share/kwin/scripts/limit_mouse/metadata.desktop:

[Desktop Entry]
Name=Limit Mouse 
Comment=Limits mouse movement to avoid the lowest 10 pixels
Type=Service
X-KWin-PluginInfo-Name=limit_mouse
X-KWin-PluginInfo-Category=Windows Management
X-KWin-PluginInfo-EnabledByDefault=true

Is there anything to it to continue on? I suspect the solution is fundamentally flawed.

Thanks.

Offline

Board footer

Powered by FluxBB