awful.mouse: Move clients using request::geometry

This commit is contained in:
Emmanuel Lepage Vallee 2016-04-22 00:50:28 -04:00
parent c286470c17
commit cdcfb913f1
1 changed files with 30 additions and 55 deletions

View File

@ -10,12 +10,10 @@
-- Grab environment we need -- Grab environment we need
local layout = require("awful.layout") local layout = require("awful.layout")
local tag = require("awful.tag") local tag = require("awful.tag")
local aclient = require("awful.client")
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")
local type = type local type = type
local math = math
local ipairs = ipairs local ipairs = ipairs
local capi = local capi =
{ {
@ -154,10 +152,13 @@ end
--- Move a client. --- Move a client.
-- @param c The client to move, or the focused one if nil. -- @param c The client to move, or the focused one if nil.
-- @param snap The pixel to snap clients. -- @param snap The pixel to snap clients.
-- @param finished_cb An optional callback function, that will be called -- @param finished_cb Deprecated, do not use
-- when moving the client has been finished. The client function mouse.client.move(c, snap, finished_cb) --luacheck: no unused args
-- that has been moved will be passed to that function. if finished_cb then
function mouse.client.move(c, snap, finished_cb) util.deprecated("The mouse.client.move `finished_cb` argument is no longer"..
" used, please use awful.mouse.resize.add_leave_callback(f, 'mouse.move')")
end
c = c or capi.client.focus c = c or capi.client.focus
if not c if not c
@ -168,53 +169,16 @@ function mouse.client.move(c, snap, finished_cb)
return return
end end
local orig = c:geometry() -- Compute the offset
local m_c = capi.mouse.coords() local coords = capi.mouse.coords()
local dist_x = m_c.x - orig.x local geo = aplace.centered(capi.mouse,{parent=c, pretend=true})
local dist_y = m_c.y - orig.y
-- Only allow moving in the non-maximized directions
local fixed_x = c.maximized_horizontal
local fixed_y = c.maximized_vertical
capi.mousegrabber.run(function (_mouse) local offset = {
if not c.valid then return false end x = geo.x - coords.x,
y = geo.y - coords.y,
}
for _, v in ipairs(_mouse.buttons) do mouse.resize(c, "mouse.move", {placement=aplace.under_mouse, offset=offset})
if v then
local lay = layout.get(c.screen)
if lay == layout.suit.floating or c.floating then
local x = _mouse.x - dist_x
local y = _mouse.y - dist_y
c:geometry(mouse.client.snap(c, snap, x, y, fixed_x, fixed_y))
elseif lay ~= layout.suit.magnifier then
-- Only move the client to the mouse
-- screen if the target screen is not
-- floating.
-- Otherwise, we move if via geometry.
if layout.get(capi.mouse.screen) == layout.suit.floating then
local x = _mouse.x - dist_x
local y = _mouse.y - dist_y
c:geometry(mouse.client.snap(c, snap, x, y, fixed_x, fixed_y))
else
c.screen = capi.mouse.screen
end
if layout.get(c.screen) ~= layout.suit.floating then
local c_u_m = mouse.client_under_pointer()
if c_u_m and not c_u_m.floating then
if c_u_m ~= c then
c:swap(c_u_m)
end
end
end
end
return true
end
end
if finished_cb then
finished_cb(c)
end
return false
end, "fleur")
end end
mouse.client.dragtotag = { } mouse.client.dragtotag = { }
@ -362,11 +326,22 @@ function mouse.resize_handler(c, context, hints)
local lay = c.screen.selected_tag.layout local lay = c.screen.selected_tag.layout
if lay == layout.suit.floating or c.floating then if lay == layout.suit.floating or c.floating then
local offset = hints and hints.offset or {}
if type(offset) == "number" then
offset = {
x = offset,
y = offset,
width = offset,
height = offset,
}
end
c:geometry { c:geometry {
x = hints.x, x = hints.x + (offset.x or 0 ),
y = hints.y, y = hints.y + (offset.y or 0 ),
width = hints.width, width = hints.width + (offset.width or 0 ),
height = hints.height, height = hints.height + (offset.height or 0 ),
} }
elseif lay.resize_handler then elseif lay.resize_handler then
lay.resize_handler(c, context, hints) lay.resize_handler(c, context, hints)