Domanda

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. 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()
--
È stato utile?

Soluzione 2

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.

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

Altri suggerimenti

Instead of using a timer, you could/should use the mousegrabber like the following:

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top