Hi people,

during the last few days, i got some time to fiddle around with awful.mouse
This fiddling let to the creation of awful.mouse.wibox.move(), which lets the
user move the wibox under the pointer (or the supplied one) similar to
awful.mouse.client.move(). If the user drags the wibox to one side of the
screen and it is not floating, its position is changed instead.

-- 
    Gregor Best
From 40a62b2f7c3bd6817dc517e7100b8242c7d30a36 Mon Sep 17 00:00:00 2001
From: Gregor Best <[EMAIL PROTECTED]>
Date: Wed, 10 Dec 2008 19:57:58 +0100
Subject: [PATCH] awful.mouse: add wibox.move()

Signed-off-by: Gregor Best <[EMAIL PROTECTED]>
---
 lib/awful/mouse.lua.in |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/lib/awful/mouse.lua.in b/lib/awful/mouse.lua.in
index ef56788..5896214 100644
--- a/lib/awful/mouse.lua.in
+++ b/lib/awful/mouse.lua.in
@@ -25,6 +25,7 @@ local capi =
 module("awful.mouse")
 
 client = {}
+wibox = {}
 
 function client_under_pointer()
     local obj = capi.mouse.object_under_pointer()
@@ -184,6 +185,48 @@ function client.dragtotag(c)
                           end, "fleur")
 end
 
+--- Move the wibox under the cursor
[EMAIL PROTECTED] w The wibox to move, or none to use that under the pointer
+function wibox.move(w)
+    if not w then w = wibox_under_pointer() end
+    if not w then return end
+
+    local offset = {
+        x = w:geometry()["x"] - capi.mouse.coords()["x"],
+        y = w:geometry()["y"] - capi.mouse.coords()["y"]
+    }
+
+    capi.mousegrabber.run(function (mouse)
+        local button_down = false
+        if w.position == "floating" then
+            w:geometry({ 
+                x = capi.mouse.coords()["x"] + offset["x"],
+                y = capi.mouse.coords()["y"] + offset["y"],
+            })
+        else
+            local wa = capi.screen[capi.mouse.screen].workarea
+
+            if capi.mouse.coords()["y"] > wa.y + wa.height - 10 then
+                w.position = "bottom"
+            elseif capi.mouse.coords()["y"] < wa.y + 10 then
+                w.position = "top"
+            elseif capi.mouse.coords()["x"] > wa.x + wa.width - 10 then
+                w.position = "right"
+            elseif capi.mouse.coords()["x"] < wa.x + 10 then
+                w.position = "left"
+            end
+            w.screen = capi.mouse.screen
+        end
+        for k, v in ipairs(mouse.buttons) do
+            if v then button_down = true end
+        end
+        if not button_down then
+            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,
-- 
1.6.0.4

Attachment: signature.asc
Description: PGP signature

Reply via email to