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.
This commit is contained in:
parent
a62e749216
commit
cd632e4a84
|
@ -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})
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
-- Grab environment we need
|
-- Grab environment we need
|
||||||
local layout = require("awful.layout")
|
local layout = require("awful.layout")
|
||||||
local tag = require("awful.tag")
|
|
||||||
local aplace = require("awful.placement")
|
local aplace = require("awful.placement")
|
||||||
local awibox = require("awful.wibox")
|
local awibox = require("awful.wibox")
|
||||||
local util = require("awful.util")
|
local util = require("awful.util")
|
||||||
|
@ -27,6 +26,7 @@ local capi =
|
||||||
local mouse = {
|
local mouse = {
|
||||||
resize = require("awful.mouse.resize"),
|
resize = require("awful.mouse.resize"),
|
||||||
snap = require("awful.mouse.snap"),
|
snap = require("awful.mouse.snap"),
|
||||||
|
drag_to_tag = require("awful.mouse.drag_to_tag")
|
||||||
}
|
}
|
||||||
|
|
||||||
mouse.object = {}
|
mouse.object = {}
|
||||||
|
@ -45,7 +45,7 @@ mouse.wibox = {}
|
||||||
-- @tfield[opt=true] boolean awful.mouse.snap.client_enabled
|
-- @tfield[opt=true] boolean awful.mouse.snap.client_enabled
|
||||||
|
|
||||||
--- Enable changing tag when a client is dragged to the edge of the screen.
|
--- 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.
|
--- The snap outline background color.
|
||||||
-- @beautiful beautiful.snap_bg
|
-- @beautiful beautiful.snap_bg
|
||||||
|
@ -109,44 +109,16 @@ end
|
||||||
mouse.client.dragtotag = { }
|
mouse.client.dragtotag = { }
|
||||||
|
|
||||||
--- Move a client to a tag by dragging it onto the left / right side of the screen.
|
--- 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
|
-- @param c The client to move
|
||||||
function mouse.client.dragtotag.border(c)
|
function mouse.client.dragtotag.border(c)
|
||||||
capi.mousegrabber.run(function (_mouse)
|
util.deprecated("Use awful.mouse.snap.drag_to_tag_enabled = true instead "..
|
||||||
if not c.valid then return false end
|
"of awful.mouse.client.dragtotag.border(c). It will now be enabled.")
|
||||||
|
|
||||||
local button_down = false
|
-- Enable drag to border
|
||||||
for _, v in ipairs(_mouse.buttons) do
|
mouse.snap.drag_to_tag_enabled = true
|
||||||
if v then button_down = true end
|
|
||||||
end
|
return mouse.client.move(c)
|
||||||
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")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Move the wibox under the cursor.
|
--- Move the wibox under the cursor.
|
||||||
|
|
Loading…
Reference in New Issue