Resent to the list, I noticed my mistake today :P

> At Thu, 4 Dec 2008 20:27:24 +0100
> Julien Danjou wrote:
> 
> > I'd really like a version which *only* move to tag, to avoid switching
> > client when moving the mouse. :)
> > 
> Done, the new function is called awful.mouse.droptotag(c)
> 
> > > How could I then make the association widget <-> tag available to the
> > > mouse module?
> > 
> > Accessors ? :)
> > 
> Also done
> 
> > You're leaking!
> > 
> 
> I hope that's fixed now.
> 
> A patch is attached.

-- 
    Gregor Best
From fa234bd81a9be49391ee03097d2f0d1daf6b5f3e Mon Sep 17 00:00:00 2001
From: Gregor Best <[EMAIL PROTECTED]>
Date: Thu, 4 Dec 2008 15:53:16 +0100
Subject: [PATCH] awful.mouse/widget: enable drag'n'dropping clients on tags

Signed-off-by: Gregor Best <[EMAIL PROTECTED]>
---
 lib/awful/mouse.lua.in  |   35 ++++++++++++++++++++++++++++++++++-
 lib/awful/widget.lua.in |   14 +++++++++++++-
 2 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/lib/awful/mouse.lua.in b/lib/awful/mouse.lua.in
index a9443f2..4eee98d 100644
--- a/lib/awful/mouse.lua.in
+++ b/lib/awful/mouse.lua.in
@@ -9,6 +9,7 @@ local layout = require("awful.layout")
 local tag = require("awful.tag")
 local hooks = require("awful.hooks")
 local aclient = require("awful.client")
+local widget = require("awful.widget")
 local type = type
 local math = math
 local ipairs = ipairs
@@ -102,7 +103,7 @@ end
 -- @param snap The pixel to snap clients.
 function client.move(c, snap)
     local c = c or capi.client.focus
-
+    
     if not c then return end
 
     if c.fullscreen
@@ -158,6 +159,38 @@ function client.move(c, snap)
                           end, "fleur")
 end
 
+--- Move a client to a tag by drag'n'dropping it over a taglist widget
+-- @param c The client to move
+function client.dragtotag(c)
+    local m_c = capi.mouse.coords()
+    local dist_x = 0
+    local dist_y = 0
+
+    local function ud()
+        capi.mouse.coords({ x = m_c.x + dist_x, y = m_c.y + dist_y })
+    end
+
+    hooks.timer.register(0.001, ud)
+    capi.mousegrabber.run(function (mouse)
+                              local button_down = false
+                              for k, v in ipairs(mouse.buttons) do
+                                  if v then
+                                      button_down = true
+                                      dist_x = mouse.x - dist_x
+                                      dist_y = mouse.y - dist_y
+                                  end
+                              end
+                              if not button_down then
+                                  local w = widget_under_pointer()
+                                  if w and widget.taglist.gettag(w) then
+                                      aclient.movetotag(widget.taglist.gettag(w), c)
+                                  end
+                                  return false
+                              end
+                              return true
+                          end, "fleur")
+    hooks.timer.unregister(ud)
+end
 --- Get a client corner coordinates.
 -- @param c The client to get corner from, focused one by default.
 -- @param corner The corner to use: auto, top_left, top_right, bottom_left,
diff --git a/lib/awful/widget.lua.in b/lib/awful/widget.lua.in
index 20f2b39..8891991 100644
--- a/lib/awful/widget.lua.in
+++ b/lib/awful/widget.lua.in
@@ -8,6 +8,8 @@
 local ipairs = ipairs
 local pairs = pairs
 local table = table
+local otable = otable
+local setmetatable = setmetatable
 local capi =
 {
     screen = screen,
@@ -32,6 +34,13 @@ taglist.label = {}
 tasklist = {}
 tasklist.label = {}
 
+-- Private structures
+local tagwidgets = otable()
+
+function taglist.gettag(widget)
+    return tagwidgets[widget]
+end
+
 --- Create a new taglist widget.
 -- @param screen The screen to draw tag list.
 -- @param label Label function to use.
@@ -49,11 +58,14 @@ function taglist.new(scr, label, buttons)
         -- Add more widgets
         if len < #tags then
             for i = len + 1, #tags do
-                w[i] = capi.widget({ type = "textbox", name = "taglist" .. i })
+                local wi = capi.widget({ type = "textbox", name = "taglist" .. i })
+                w[i] = wi
+                tagwidgets[wi] = tags[i]
             end
         -- Remove widgets
         elseif len > #tags then
             for i = #tags + 1, len do
+                tagwidgets[w[i]] = nil
                 w[i] = nil
             end
         end
-- 
1.6.0.4

Attachment: signature.asc
Description: PGP signature

Reply via email to