From 27e7b4bc9ba39929f3c8cd9ab695fc5a63034f82 Mon Sep 17 00:00:00 2001 From: Gregor Best Date: Mon, 8 Dec 2008 19:56:00 +0100 Subject: [PATCH] awful.mouse/widget: enable drag'n'dropping clients on tags Signed-off-by: Gregor Best Signed-off-by: Julien Danjou --- lib/awful/mouse.lua.in | 26 ++++++++++++++++++++++++++ lib/awful/widget.lua.in | 12 +++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/awful/mouse.lua.in b/lib/awful/mouse.lua.in index d8404101c..ef56788d9 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 @@ -158,6 +159,31 @@ 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) + capi.mousegrabber.run(function (mouse) + local button_down = false + for k, v in ipairs(mouse.buttons) do + if v then + button_down = true + end + end + if not button_down then + local w = widget_under_pointer() + if w and widget.taglist.gettag(w) then + local t = widget.taglist.gettag(w) + if t.screen ~= c.screen then + aclient.movetoscreen(c, t.screen) + end + aclient.movetotag(t, c) + end + return false + end + return true + end, "fleur") +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 ecc666ee7..a52981e1f 100644 --- a/lib/awful/widget.lua.in +++ b/lib/awful/widget.lua.in @@ -33,6 +33,9 @@ taglist.label = {} tasklist = {} tasklist.label = {} +-- Private structures +local tagwidgets = otable() + local function taglist_update (screen, w, label, buttons, data) local tags = capi.screen[screen]:tags() -- Hack: if it has been registered as a widget in a wibox, @@ -42,11 +45,14 @@ local function taglist_update (screen, w, label, buttons, data) -- Add more widgets if len < #tags then for i = len + 1, #tags do - w[i] = capi.widget({ type = "textbox" }) + local wi = capi.widget({ type = "textbox" }) + 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 @@ -74,6 +80,10 @@ local function taglist_update (screen, w, label, buttons, data) end end +function taglist.gettag(widget) + return tagwidgets[widget] +end + --- Create a new taglist widget. -- @param screen The screen to draw tag list for. -- @param label Label function to use.