简体   繁体   English

当鼠标触摸Awesome-wm中的屏幕边缘时执行命令

[英]Execute command when mouse touches screen edge in Awesome-wm

I'm new to doing custom lua for the rc.lua in Awesome and I'm having a bit of trouble working out how to launch something based on the mouse position. 我是在Awesome中为rc.lua定制自定义lua的新手,在设计如何根据鼠标位置启动某些东西时遇到了一些麻烦。 This is what I have, so-far, but it's not doing anything. 到目前为止,这就是我所拥有的,但是它什么也没做。

-- Open todo when mouse hits right screen edge.
todo_timer = timer({timeout = 0.1})
todo_timer:add_signal("todopopup", function()
    if mouse.coords.x >= 3198 then
        scratch.drop("urxvt -e vim /home/ryan/to-do", "center", "right", 0.33, 1, "true")
    end
end)
todo_timer:start()
--

Instead of using a timer, you could/should use the mousegrabber like the following: 您可以/应该像下面这样使用mousegrabber而不是使用计时器:

mousegrabber.run(function(mouse)
    if mouse.x > 3196 then
        -- Do your stuff here
    end
    -- Return true, to continue grabbing the mouse
    return true
end)

The problem with that approach is, that you can only register one mousegrabber at a time. 这种方法的问题在于,一次只能注册一个捕鼠器。 So this is a perfect solution, if you just need to listen shortly for that mouse movements. 因此,如果您只需要听一下鼠标的移动,这就是一个完美的解决方案。 If you need longer, you could stop the grabbing when you need the grabber for something else (mainly client re sizing and moving) and start it, when that that is finished. 如果需要更长的时间,则可以在需要抓取器进行其他操作时停止抓取(主要是客户端调整大小和移动),并在完成后启动抓取器。

This almost works as intended. 这几乎可以按预期工作。 For some reason the scratchpad appears on screen 1 the first time and does not center vertically properly (this problem only occurs with a horizontal position of "right", I assume it's a problem with scratchpad), for me, but it should work for people who do not have a multi-monitor setup or for launching other commands of your choice. 出于某种原因,暂存器第一次出现在屏幕1上,并且不能正确地垂直居中(此问题仅在水平位置为“正确”时发生,我认为这是暂存器的问题),对我来说,但它应该对人有用没有多显示器设置或用于启动您选择的其他命令的用户。

-- Open todo when mouse hits right screen edge.
local function todopad()
    scratch.drop("urxvt -e vimpager /home/ryan/to-do", "center", "right", .20, 800, "true", 2)
end

todo_timer = timer({timeout = 1})
todo_timer:add_signal("timeout", function()
    if mouse.coords()["x"] >= 3196 then
        todopad()
    end
end)
todo_timer:start()
--

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

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