Search code examples
awesome-wm

How to stop mousegrabber in another function


I am creating a tasklist with drag and drop.

In the widget_template create_callback function I am using this code:

self:connect_signal("button::press",
function(_, lx, ly, button, mods)
   capi.mousegrabber.run(
   function()
     return true
     end, "hand") 
end)
self:connect_signal("button::release",
function(_, lx, ly, button, mods)
    capi.mousegrabber.stop()
end)

Mousegrabber does not stop when mouse is released and I don't understand why.


Solution

  • Thanks to @Emmanuel Lepage Vallee the solution I found looks like this:

    self:connect_signal("button::press",
    function(_, lx, ly, button, mods)
       capi.mousegrabber.run(
       function(mouse)
         return mouse.buttons[1]
       end, "hand") 
    end)
    

    Mousegrabber disables any mouse events happening that's why you can't rely on button::release signal to activate another function. The only way to interact with the mouse is through the mousegrabber function mouse parameter

    mouse.buttons[NUMBER] is an undocumented property which you can use. It returns true if it is pressed.