在awesome-wm:如何防止鼠标离开客户端? (例如全屏或窗口游戏)

时间:2016-01-03 15:11:13

标签: fullscreen steam awesome-wm

任何人都可以提示我如何防止鼠标离开某个窗口或全屏游戏吗?尝试了三个蒸汽游戏(卫星统治,城市:天际线和文明5),都有相同的问题:只要我在边框上移动鼠标(用于屏幕平移),焦点就会切换到我的第二个显示器。

对于正确的来源(我猜鼠标行为作为自定义客户端属性?)的任何建议或暗示非常受欢迎:)

谢谢!

1 个答案:

答案 0 :(得分:0)

令人敬畏的wm信号可能有用。这是一个简单的例子(更像是提示)它是如何工作的 把它放在rc.lua

的开头
local is_mouse_locked = false

此代码放在client.connect_signal("manage", function (c, startup)

-- 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
)

并将其添加到热键

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