简体   繁体   English

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

[英]In awesome-wm: How to prevent mouse from leaving a client? (e.g. fullscreen or windowed game)

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. 在三个蒸汽游戏(Satellite Reign,Cities:Skylines&Civ 5)中进行了尝试,所有这些都具有相同的问题:一旦我将鼠标移到边框上(用于屏幕平移),焦点便切换到了第二个监视器。

Any advice or hint to the right source (I guess mouse behaviour as a custom client property?) is very welcome :) 任何对正确来源的建议或暗示(我想将鼠标的行为视为自定义客户端属性?):)

Thanks! 谢谢!

Awesome wm signals may be useful. 很棒的wm信号可能有用。 Here is a quick example (more like hint) how it works. 这是一个简单的示例(更像提示)。
Put this somewhere at the start of rc.lua 将其放在rc.lua的开头

local is_mouse_locked = false

This code put inside client.connect_signal("manage", function (c, startup) block 这段代码放在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
)

And add this to hotkeys 并将其添加到热键

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM