At Thu, 4 Dec 2008 16:39:23 +0100
Julien Danjou <[EMAIL PROTECTED]> wrote:

> I see several problems:
> - you need to be very precise with your mouse. The actual move should be
>   done when you release the mouse button *over* a tag, not when the
>   mouse is over it.
> - having this in the same function of the client move may be a problem.
>   I'd rather see another function which can be used with or without the
>   client moving.
> 
Agreed, i added a new parameter to client.move, which, if set to true, will
enable drag and drop to move the client and I added a condition so that the
move only occurs if no mouse button had been pressed.

> >  taglist = {}
> >  taglist.label = {}
> > +taglist.tags = {}
> 
> Private data must be local.
> 
How could I then make the association widget <-> tag available to the mouse
module?

> > +    taglist.tags[scr] = { }
> 
> That does not allow to have several taglist by screen, which is a bad
> design.
> 
> I think an weak otable with the widgets as key as the tag as value would
> be enough.

Good call, i adjusted the code, creating a weak otable however was not
possible at this moment, because when the table's __mode was either 'k' or 'v'
or both, it would drop it's content immediately after aquiring it.

The new version is attached

        Gregor Best
From 393d2ea563c2f051069270473a25f6fcf2f45879 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  |   15 +++++++++++++--
 lib/awful/widget.lua.in |    4 ++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/lib/awful/mouse.lua.in b/lib/awful/mouse.lua.in
index a9443f2..ffe10a6 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
@@ -99,10 +100,12 @@ end
 
 --- Move a client.
 -- @param c The client to move, or the focused one if nil.
+-- @param tagdrop If tagdrop is true, the client can be dragged onto a tag to
+-- be moved there
 -- @param snap The pixel to snap clients.
-function client.move(c, snap)
+function client.move(c, tagdrop, snap)
     local c = c or capi.client.focus
-
+    
     if not c then return end
 
     if c.fullscreen
@@ -128,8 +131,10 @@ function client.move(c, snap)
 
     capi.mousegrabber.run(function (mouse)
                               hooks.property.unregister(ug)
+                              local button_pressed = false
                               for k, v in ipairs(mouse.buttons) do
                                   if v then
+                                      button_pressed = true
                                       local lay = layout.get(c.screen)
                                       if lay == layout.suit.floating or aclient.floating.get(c) then
                                           local x = mouse.x - dist_x
@@ -154,6 +159,12 @@ function client.move(c, snap)
                                       return true
                                   end
                               end
+                              if not button_pressed and tagdrop then
+                                  local w = widget_under_pointer()
+                                  if w and widget.taglist.tags[w] then
+                                      aclient.movetotag(widget.taglist.tags[w], c)
+                                  end
+                              end
                               return false
                           end, "fleur")
 end
diff --git a/lib/awful/widget.lua.in b/lib/awful/widget.lua.in
index 20f2b39..f54d6e9 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,
@@ -29,6 +31,7 @@ module("awful.widget")
 -- Various public structures
 taglist = {}
 taglist.label = {}
+taglist.tags = otable()
 tasklist = {}
 tasklist.label = {}
 
@@ -50,6 +53,7 @@ function taglist.new(scr, label, buttons)
         if len < #tags then
             for i = len + 1, #tags do
                 w[i] = capi.widget({ type = "textbox", name = "taglist" .. i })
+                taglist.tags[w[i]] = tags[i]
             end
         -- Remove widgets
         elseif len > #tags then
-- 
1.6.0.4

Attachment: signature.asc
Description: PGP signature

Reply via email to