From cd632e4a84d8b59b0978423db8e9ea8998ff163f Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Wed, 27 Apr 2016 23:20:00 -0400 Subject: [PATCH] mouse.dragtotag: Fix and port to the new move API It wasn't really working as it would in other WM. It might have been a feature, but I got the behavior in line with KDE and Gnome. --- lib/awful/mouse/drag_to_tag.lua | 59 +++++++++++++++++++++++++++++++++ lib/awful/mouse/init.lua | 46 +++++-------------------- 2 files changed, 68 insertions(+), 37 deletions(-) create mode 100644 lib/awful/mouse/drag_to_tag.lua diff --git a/lib/awful/mouse/drag_to_tag.lua b/lib/awful/mouse/drag_to_tag.lua new file mode 100644 index 00000000..ee4cb895 --- /dev/null +++ b/lib/awful/mouse/drag_to_tag.lua @@ -0,0 +1,59 @@ +--------------------------------------------------------------------------- +--- 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 +-- @release @AWESOME_VERSION@ +-- @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 = capi.screen[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}) diff --git a/lib/awful/mouse/init.lua b/lib/awful/mouse/init.lua index ee86d2fe..1e10713d 100644 --- a/lib/awful/mouse/init.lua +++ b/lib/awful/mouse/init.lua @@ -9,7 +9,6 @@ -- Grab environment we need local layout = require("awful.layout") -local tag = require("awful.tag") local aplace = require("awful.placement") local awibox = require("awful.wibox") local util = require("awful.util") @@ -27,6 +26,7 @@ local capi = local mouse = { resize = require("awful.mouse.resize"), snap = require("awful.mouse.snap"), + drag_to_tag = require("awful.mouse.drag_to_tag") } mouse.object = {} @@ -45,7 +45,7 @@ mouse.wibox = {} -- @tfield[opt=true] boolean awful.mouse.snap.client_enabled --- Enable changing tag when a client is dragged to the edge of the screen. --- @tfield[opt=false] integer awful.mouse.snap.drag_to_tag_enabled +-- @tfield[opt=false] integer awful.mouse.drag_to_tag.enabled --- The snap outline background color. -- @beautiful beautiful.snap_bg @@ -109,44 +109,16 @@ end mouse.client.dragtotag = { } --- Move a client to a tag by dragging it onto the left / right side of the screen. --- @function awful.mouse.client.dragtotag.border +-- @deprecated awful.mouse.client.dragtotag.border -- @param c The client to move function mouse.client.dragtotag.border(c) - capi.mousegrabber.run(function (_mouse) - if not c.valid then return false end + util.deprecated("Use awful.mouse.snap.drag_to_tag_enabled = true instead ".. + "of awful.mouse.client.dragtotag.border(c). It will now be enabled.") - local button_down = false - for _, v in ipairs(_mouse.buttons) do - if v then button_down = true end - end - local wa = capi.screen[c.screen].workarea - if _mouse.x >= wa.x + wa.width then - capi.mouse.coords({ x = wa.x + wa.width - 1 }) - elseif _mouse.x <= wa.x then - capi.mouse.coords({ x = wa.x + 1 }) - end - if not button_down then - local tags = c.screen.tags - local t = c.screen.selected_tag - local idx - for i, v in ipairs(tags) do - if v == t then - idx = i - end - end - if _mouse.x > wa.x + wa.width - 10 then - local newtag = tags[util.cycle(#tags, idx + 1)] - c:move_to_tag(newtag) - tag.viewnext() - elseif _mouse.x < wa.x + 10 then - local newtag = tags[util.cycle(#tags, idx - 1)] - c:move_to_tag(newtag) - tag.viewprev() - end - return false - end - return true - end, "fleur") + -- Enable drag to border + mouse.snap.drag_to_tag_enabled = true + + return mouse.client.move(c) end --- Move the wibox under the cursor.