summaryrefslogtreecommitdiff
path: root/awesome/lib/awful/mouse/drag_to_tag.lua
diff options
context:
space:
mode:
Diffstat (limited to 'awesome/lib/awful/mouse/drag_to_tag.lua')
-rw-r--r--awesome/lib/awful/mouse/drag_to_tag.lua58
1 files changed, 58 insertions, 0 deletions
diff --git a/awesome/lib/awful/mouse/drag_to_tag.lua b/awesome/lib/awful/mouse/drag_to_tag.lua
new file mode 100644
index 0000000..141456b
--- /dev/null
+++ b/awesome/lib/awful/mouse/drag_to_tag.lua
@@ -0,0 +1,58 @@
+---------------------------------------------------------------------------
+--- When the the mouse reach the end of the screen, then switch tag instead
+-- of screens.
+--
+-- @author Julien Danjou <julien@danjou.info>
+-- @copyright 2008 Julien Danjou
+-- @submodule mouse
+---------------------------------------------------------------------------
+
+local capi = {screen = screen, mouse = mouse}
+local util = require("awful.util")
+local tag = require("awful.tag")
+local resize = require("awful.mouse.resize")
+
+local module = {}
+
+function module.drag_to_tag(c)
+ if (not c) or (not c.valid) then return end
+
+ local coords = capi.mouse.coords()
+
+ local dir = nil
+
+ local wa = c.screen.workarea
+
+ if coords.x >= wa.x + wa.width - 1 then
+ capi.mouse.coords({ x = wa.x + 2 }, true)
+ dir = "right"
+ elseif coords.x <= wa.x + 1 then
+ capi.mouse.coords({ x = wa.x + wa.width - 2 }, true)
+ dir = "left"
+ end
+
+ local tags = c.screen.tags
+ local t = c.screen.selected_tag
+ local idx = t.index
+
+ if dir then
+
+ if dir == "right" then
+ local newtag = tags[util.cycle(#tags, idx + 1)]
+ c:move_to_tag(newtag)
+ tag.viewnext()
+ elseif dir == "left" then
+ local newtag = tags[util.cycle(#tags, idx - 1)]
+ c:move_to_tag(newtag)
+ tag.viewprev()
+ end
+ end
+end
+
+resize.add_move_callback(function(c, _, _)
+ if module.enabled then
+ module.drag_to_tag(c)
+ end
+end, "mouse.move")
+
+return setmetatable(module, {__call = function(_, ...) return module.drag_to_tag(...) end})