0

Can anyone give me a hint how to prevent the mouse from leaving a certain window or fullscreen game? Tried it with three steam games (Satellite Reign, Cities:Skylines & Civ 5), all have the same issue: As soon as I move the mouse on the border (for screen panning) instead the focus is switched to my second monitor.

Any advice or hint to the right source (I guess mouse behaviour as a custom client property?) is very welcome :)

Thanks!

bahmrockk
  • 11
  • 2

1 Answers1

0

Awesome wm signals may be useful. Here is a quick example (more like hint) how it works.
Put this somewhere at the start of rc.lua

local is_mouse_locked = false

This code put inside client.connect_signal("manage", function (c, startup) block

-- in this example
-- signal connected to every window and make action if 'is_mouse_locked' switcher active
-- however much better would be connect and disconnect signal to certain window by hotkey
c:connect_signal("mouse::leave",
    function(c)
        if is_mouse_locked then
            local cg = c:geometry() -- get window size
            local mg = mouse.coords() -- get current mouse position

            -- quick and dirty calculate for mouse position correction
            local newx = mg.x <= cg.x and cg.x + 5 or mg.x >= (cg.x + cg.width) and cg.x + cg.width - 5 or mg.x
            local newy = mg.y <= cg.y and cg.y + 5 or mg.y >= (cg.y + cg.height) and cg.y + cg.height - 5 or mg.y

            -- set mouse to new position
            mouse.coords({ x = newx, y = newy })
        end
    end
)

And add this to hotkeys

awful.key({ modkey,           }, "v", function () is_mouse_locked = not is_mouse_locked end),
Worron
  • 181
  • 3