Ported awful.mouse to lua 5.2
Tested with lua 5.1: all good Signed-off-by: Arvydas Sidorenko <asido4@gmail.com> Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
c3ebfd99fc
commit
dd8ecdce24
|
@ -31,7 +31,9 @@ local setmetatable = setmetatable
|
||||||
-- The mouse_finder color<br/>
|
-- The mouse_finder color<br/>
|
||||||
-- <code>theme.mouse_finder_color = "#ff0000"</code><br/>
|
-- <code>theme.mouse_finder_color = "#ff0000"</code><br/>
|
||||||
-- </p>
|
-- </p>
|
||||||
module("awful.mouse.finder")
|
|
||||||
|
-- awful.mouse.finder
|
||||||
|
local finder = { mt = {} }
|
||||||
|
|
||||||
-- Mouse finder private data.
|
-- Mouse finder private data.
|
||||||
-- @name data
|
-- @name data
|
||||||
|
@ -112,7 +114,7 @@ end
|
||||||
|
|
||||||
--- Find the mouse on the screen
|
--- Find the mouse on the screen
|
||||||
-- @param self A mouse finder object.
|
-- @param self A mouse finder object.
|
||||||
function find(self)
|
function finder.find(self)
|
||||||
show(self)
|
show(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -143,6 +145,10 @@ local function new()
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
function finder.mt:__call(...)
|
||||||
|
return new(...)
|
||||||
|
end
|
||||||
|
|
||||||
|
return setmetatable(finder, finder.mt)
|
||||||
|
|
||||||
-- vim: ft=lua:et:sw=4:ts=4:sts=4:enc=utf-8:tw=78
|
-- vim: ft=lua:et:sw=4:ts=4:sts=4:enc=utf-8:tw=78
|
||||||
|
|
|
@ -23,17 +23,18 @@ local capi =
|
||||||
mousegrabber = mousegrabber,
|
mousegrabber = mousegrabber,
|
||||||
}
|
}
|
||||||
|
|
||||||
require("awful.mouse.finder")
|
local finder = require("awful.mouse.finder")
|
||||||
|
|
||||||
--- Mouse module for awful
|
--- Mouse module for awful
|
||||||
module("awful.mouse")
|
-- awful.mouse
|
||||||
|
local mouse = {}
|
||||||
|
|
||||||
client = {}
|
mouse.client = {}
|
||||||
wibox = {}
|
mouse.wibox = {}
|
||||||
|
|
||||||
--- Get the client object under the pointer.
|
--- Get the client object under the pointer.
|
||||||
-- @return The client object under the pointer, if one can be found.
|
-- @return The client object under the pointer, if one can be found.
|
||||||
function client_under_pointer()
|
function mouse.client_under_pointer()
|
||||||
local obj = capi.mouse.object_under_pointer()
|
local obj = capi.mouse.object_under_pointer()
|
||||||
if type(obj) == "client" then
|
if type(obj) == "client" then
|
||||||
return obj
|
return obj
|
||||||
|
@ -42,7 +43,7 @@ end
|
||||||
|
|
||||||
--- Get the wibox object under the pointer.
|
--- Get the wibox object under the pointer.
|
||||||
-- @return The wibox object under the pointer, if one can be found.
|
-- @return The wibox object under the pointer, if one can be found.
|
||||||
function wibox_under_pointer()
|
function mouse.wibox_under_pointer()
|
||||||
local obj = capi.mouse.object_under_pointer()
|
local obj = capi.mouse.object_under_pointer()
|
||||||
if type(obj) == "wibox" then
|
if type(obj) == "wibox" then
|
||||||
return obj
|
return obj
|
||||||
|
@ -51,7 +52,7 @@ end
|
||||||
|
|
||||||
--- Get the widget under the pointer.
|
--- Get the widget under the pointer.
|
||||||
-- @return The widget object under the pointer, if it can be found.
|
-- @return The widget object under the pointer, if it can be found.
|
||||||
function widget_under_pointer()
|
function mouse.widget_under_pointer()
|
||||||
local obj, obj2 = capi.mouse.object_under_pointer()
|
local obj, obj2 = capi.mouse.object_under_pointer()
|
||||||
if type(obj2) == "widget" then
|
if type(obj2) == "widget" then
|
||||||
return obj2
|
return obj2
|
||||||
|
@ -105,9 +106,9 @@ end
|
||||||
-- @param y The client y coordinate.
|
-- @param y The client y coordinate.
|
||||||
-- @param fixed_x True if the client isn't allowed to move in the x direction.
|
-- @param fixed_x True if the client isn't allowed to move in the x direction.
|
||||||
-- @param fixed_y True if the client isn't allowed to move in the y direction.
|
-- @param fixed_y True if the client isn't allowed to move in the y direction.
|
||||||
function client.snap(c, snap, x, y, fixed_x, fixed_y)
|
function mouse.client.snap(c, snap, x, y, fixed_x, fixed_y)
|
||||||
local snap = snap or 8
|
local snap = snap or 8
|
||||||
local c = c or client.focus
|
local c = c or mouse.client.focus
|
||||||
local cur_geom = c:geometry()
|
local cur_geom = c:geometry()
|
||||||
local geom = c:geometry()
|
local geom = c:geometry()
|
||||||
geom.width = geom.width + (2 * c.border_width)
|
geom.width = geom.width + (2 * c.border_width)
|
||||||
|
@ -162,7 +163,7 @@ 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.
|
||||||
function client.move(c, snap)
|
function mouse.client.move(c, snap)
|
||||||
local c = c or capi.client.focus
|
local c = c or capi.client.focus
|
||||||
|
|
||||||
if not c
|
if not c
|
||||||
|
@ -183,28 +184,28 @@ function client.move(c, snap)
|
||||||
local fixed_x = c.maximized_horizontal
|
local fixed_x = c.maximized_horizontal
|
||||||
local fixed_y = c.maximized_vertical
|
local fixed_y = c.maximized_vertical
|
||||||
|
|
||||||
capi.mousegrabber.run(function (mouse)
|
capi.mousegrabber.run(function (_mouse)
|
||||||
for k, v in ipairs(mouse.buttons) do
|
for k, v in ipairs(_mouse.buttons) do
|
||||||
if v then
|
if v then
|
||||||
local lay = layout.get(c.screen)
|
local lay = layout.get(c.screen)
|
||||||
if lay == layout.suit.floating or aclient.floating.get(c) then
|
if lay == layout.suit.floating or aclient.floating.get(c) then
|
||||||
local x = mouse.x - dist_x
|
local x = _mouse.x - dist_x
|
||||||
local y = mouse.y - dist_y
|
local y = _mouse.y - dist_y
|
||||||
c:geometry(client.snap(c, snap, x, y, fixed_x, fixed_y))
|
c:geometry(mouse.client.snap(c, snap, x, y, fixed_x, fixed_y))
|
||||||
elseif lay ~= layout.suit.magnifier then
|
elseif lay ~= layout.suit.magnifier then
|
||||||
-- Only move the client to the mouse
|
-- Only move the client to the mouse
|
||||||
-- screen if the target screen is not
|
-- screen if the target screen is not
|
||||||
-- floating.
|
-- floating.
|
||||||
-- Otherwise, we move if via geometry.
|
-- Otherwise, we move if via geometry.
|
||||||
if layout.get(capi.mouse.screen) == layout.suit.floating then
|
if layout.get(capi.mouse.screen) == layout.suit.floating then
|
||||||
local x = mouse.x - dist_x
|
local x = _mouse.x - dist_x
|
||||||
local y = mouse.y - dist_y
|
local y = _mouse.y - dist_y
|
||||||
c:geometry(client.snap(c, snap, x, y, fixed_x, fixed_y))
|
c:geometry(mouse.client.snap(c, snap, x, y, fixed_x, fixed_y))
|
||||||
else
|
else
|
||||||
c.screen = capi.mouse.screen
|
c.screen = capi.mouse.screen
|
||||||
end
|
end
|
||||||
if layout.get(c.screen) ~= layout.suit.floating then
|
if layout.get(c.screen) ~= layout.suit.floating then
|
||||||
local c_u_m = client_under_pointer()
|
local c_u_m = mouse.client_under_pointer()
|
||||||
if c_u_m and not aclient.floating.get(c_u_m) then
|
if c_u_m and not aclient.floating.get(c_u_m) then
|
||||||
if c_u_m ~= c then
|
if c_u_m ~= c then
|
||||||
c:swap(c_u_m)
|
c:swap(c_u_m)
|
||||||
|
@ -219,18 +220,18 @@ function client.move(c, snap)
|
||||||
end, "fleur")
|
end, "fleur")
|
||||||
end
|
end
|
||||||
|
|
||||||
client.dragtotag = { }
|
mouse.client.dragtotag = { }
|
||||||
|
|
||||||
--- Move a client to a tag by drag'n'dropping it over a taglist widget
|
--- Move a client to a tag by drag'n'dropping it over a taglist widget
|
||||||
-- @param c The client to move
|
-- @param c The client to move
|
||||||
function client.dragtotag.widget(c)
|
function mouse.client.dragtotag.widget(c)
|
||||||
capi.mousegrabber.run(function (mouse)
|
capi.mousegrabber.run(function (_mouse)
|
||||||
local button_down = false
|
local button_down = false
|
||||||
for _, v in ipairs(mouse.buttons) do
|
for _, v in ipairs(_mouse.buttons) do
|
||||||
if v then button_down = true end
|
if v then button_down = true end
|
||||||
end
|
end
|
||||||
if not button_down then
|
if not button_down then
|
||||||
local w = widget_under_pointer()
|
local w = mouse.widget_under_pointer()
|
||||||
if w and widget.taglist.gettag(w) then
|
if w and widget.taglist.gettag(w) then
|
||||||
local t = widget.taglist.gettag(w)
|
local t = widget.taglist.gettag(w)
|
||||||
if t.screen ~= c.screen then
|
if t.screen ~= c.screen then
|
||||||
|
@ -246,16 +247,16 @@ end
|
||||||
|
|
||||||
--- 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
|
||||||
-- @param c The client to move
|
-- @param c The client to move
|
||||||
function client.dragtotag.border(c)
|
function mouse.client.dragtotag.border(c)
|
||||||
capi.mousegrabber.run(function (mouse)
|
capi.mousegrabber.run(function (_mouse)
|
||||||
local button_down = false
|
local button_down = false
|
||||||
for _, v in ipairs(mouse.buttons) do
|
for _, v in ipairs(_mouse.buttons) do
|
||||||
if v then button_down = true end
|
if v then button_down = true end
|
||||||
end
|
end
|
||||||
local wa = capi.screen[c.screen].workarea
|
local wa = capi.screen[c.screen].workarea
|
||||||
if mouse.x >= wa.x + wa.width then
|
if _mouse.x >= wa.x + wa.width then
|
||||||
capi.mouse.coords({ x = wa.x + wa.width - 1 })
|
capi.mouse.coords({ x = wa.x + wa.width - 1 })
|
||||||
elseif mouse.x <= wa.x then
|
elseif _mouse.x <= wa.x then
|
||||||
capi.mouse.coords({ x = wa.x + 1 })
|
capi.mouse.coords({ x = wa.x + 1 })
|
||||||
end
|
end
|
||||||
if not button_down then
|
if not button_down then
|
||||||
|
@ -267,11 +268,11 @@ function client.dragtotag.border(c)
|
||||||
idx = i
|
idx = i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if mouse.x > wa.x + wa.width - 10 then
|
if _mouse.x > wa.x + wa.width - 10 then
|
||||||
local newtag = tags[util.cycle(#tags, idx + 1)]
|
local newtag = tags[util.cycle(#tags, idx + 1)]
|
||||||
aclient.movetotag(newtag, c)
|
aclient.movetotag(newtag, c)
|
||||||
tag.viewnext()
|
tag.viewnext()
|
||||||
elseif mouse.x < wa.x + 10 then
|
elseif _mouse.x < wa.x + 10 then
|
||||||
local newtag = tags[util.cycle(#tags, idx - 1)]
|
local newtag = tags[util.cycle(#tags, idx - 1)]
|
||||||
aclient.movetotag(newtag, c)
|
aclient.movetotag(newtag, c)
|
||||||
tag.viewprev()
|
tag.viewprev()
|
||||||
|
@ -284,8 +285,8 @@ end
|
||||||
|
|
||||||
--- Move the wibox under the cursor
|
--- Move the wibox under the cursor
|
||||||
--@param w The wibox to move, or none to use that under the pointer
|
--@param w The wibox to move, or none to use that under the pointer
|
||||||
function wibox.move(w)
|
function mouse.wibox.move(w)
|
||||||
local w = w or wibox_under_pointer()
|
local w = w or mouse.wibox_under_pointer()
|
||||||
if not w then return end
|
if not w then return end
|
||||||
|
|
||||||
local offset = {
|
local offset = {
|
||||||
|
@ -293,7 +294,7 @@ function wibox.move(w)
|
||||||
y = w.y - capi.mouse.coords().y
|
y = w.y - capi.mouse.coords().y
|
||||||
}
|
}
|
||||||
|
|
||||||
capi.mousegrabber.run(function (mouse)
|
capi.mousegrabber.run(function (_mouse)
|
||||||
local button_down = false
|
local button_down = false
|
||||||
if awibox.get_position(w) == "floating" then
|
if awibox.get_position(w) == "floating" then
|
||||||
w.x = capi.mouse.coords().x + offset.x
|
w.x = capi.mouse.coords().x + offset.x
|
||||||
|
@ -312,7 +313,7 @@ function wibox.move(w)
|
||||||
end
|
end
|
||||||
w.screen = capi.mouse.screen
|
w.screen = capi.mouse.screen
|
||||||
end
|
end
|
||||||
for k, v in ipairs(mouse.buttons) do
|
for k, v in ipairs(_mouse.buttons) do
|
||||||
if v then button_down = true end
|
if v then button_down = true end
|
||||||
end
|
end
|
||||||
if not button_down then
|
if not button_down then
|
||||||
|
@ -327,7 +328,7 @@ end
|
||||||
-- @param corner The corner to use: auto, top_left, top_right, bottom_left,
|
-- @param corner The corner to use: auto, top_left, top_right, bottom_left,
|
||||||
-- bottom_right. Default is auto, and auto find the nearest corner.
|
-- bottom_right. Default is auto, and auto find the nearest corner.
|
||||||
-- @return Actual used corner and x and y coordinates.
|
-- @return Actual used corner and x and y coordinates.
|
||||||
function client.corner(c, corner)
|
function mouse.client.corner(c, corner)
|
||||||
local c = c or capi.client.focus
|
local c = c or capi.client.focus
|
||||||
if not c then return end
|
if not c then return end
|
||||||
|
|
||||||
|
@ -369,7 +370,7 @@ function client.corner(c, corner)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function client_resize_magnifier(c, corner)
|
local function client_resize_magnifier(c, corner)
|
||||||
local corner, x, y = client.corner(c, corner)
|
local corner, x, y = mouse.client.corner(c, corner)
|
||||||
capi.mouse.coords({ x = x, y = y })
|
capi.mouse.coords({ x = x, y = y })
|
||||||
|
|
||||||
local wa = capi.screen[c.screen].workarea
|
local wa = capi.screen[c.screen].workarea
|
||||||
|
@ -377,11 +378,11 @@ local function client_resize_magnifier(c, corner)
|
||||||
local center_y = wa.y + wa.height / 2
|
local center_y = wa.y + wa.height / 2
|
||||||
local maxdist_pow = (wa.width^2 + wa.height^2) / 4
|
local maxdist_pow = (wa.width^2 + wa.height^2) / 4
|
||||||
|
|
||||||
capi.mousegrabber.run(function (mouse)
|
capi.mousegrabber.run(function (_mouse)
|
||||||
for k, v in ipairs(mouse.buttons) do
|
for k, v in ipairs(_mouse.buttons) do
|
||||||
if v then
|
if v then
|
||||||
local dx = center_x - mouse.x
|
local dx = center_x - _mouse.x
|
||||||
local dy = center_y - mouse.y
|
local dy = center_y - _mouse.y
|
||||||
local dist = dx^2 + dy^2
|
local dist = dx^2 + dy^2
|
||||||
|
|
||||||
-- New master width factor
|
-- New master width factor
|
||||||
|
@ -439,11 +440,11 @@ local function client_resize_tiled(c, lay)
|
||||||
capi.mouse.coords({ y = wa.y + wa.height * (1 - mwfact), x= g.x + offset })
|
capi.mouse.coords({ y = wa.y + wa.height * (1 - mwfact), x= g.x + offset })
|
||||||
end
|
end
|
||||||
|
|
||||||
capi.mousegrabber.run(function (mouse)
|
capi.mousegrabber.run(function (_mouse)
|
||||||
for k, v in ipairs(mouse.buttons) do
|
for k, v in ipairs(_mouse.buttons) do
|
||||||
if v then
|
if v then
|
||||||
local fact_x = (mouse.x - wa.x) / wa.width
|
local fact_x = (_mouse.x - wa.x) / wa.width
|
||||||
local fact_y = (mouse.y - wa.y) / wa.height
|
local fact_y = (_mouse.y - wa.y) / wa.height
|
||||||
local mwfact
|
local mwfact
|
||||||
|
|
||||||
local g = c:geometry()
|
local g = c:geometry()
|
||||||
|
@ -453,15 +454,15 @@ local function client_resize_tiled(c, lay)
|
||||||
local wfact
|
local wfact
|
||||||
local wfact_x, wfact_y
|
local wfact_x, wfact_y
|
||||||
if (g.y+g.height+15) > (wa.y+wa.height) then
|
if (g.y+g.height+15) > (wa.y+wa.height) then
|
||||||
wfact_y = (g.y + g.height - mouse.y) / wa.height
|
wfact_y = (g.y + g.height - _mouse.y) / wa.height
|
||||||
else
|
else
|
||||||
wfact_y = (mouse.y - g.y) / wa.height
|
wfact_y = (_mouse.y - g.y) / wa.height
|
||||||
end
|
end
|
||||||
|
|
||||||
if (g.x+g.width+15) > (wa.x+wa.width) then
|
if (g.x+g.width+15) > (wa.x+wa.width) then
|
||||||
wfact_x = (g.x + g.width - mouse.x) / wa.width
|
wfact_x = (g.x + g.width - _mouse.x) / wa.width
|
||||||
else
|
else
|
||||||
wfact_x = (mouse.x - g.x) / wa.width
|
wfact_x = (_mouse.x - g.x) / wa.width
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -489,14 +490,14 @@ local function client_resize_tiled(c, lay)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function client_resize_floating(c, corner, fixed_x, fixed_y)
|
local function client_resize_floating(c, corner, fixed_x, fixed_y)
|
||||||
local corner, x, y = client.corner(c, corner)
|
local corner, x, y = mouse.client.corner(c, corner)
|
||||||
local g = c:geometry()
|
local g = c:geometry()
|
||||||
|
|
||||||
-- Warp mouse pointer
|
-- Warp mouse pointer
|
||||||
capi.mouse.coords({ x = x, y = y })
|
capi.mouse.coords({ x = x, y = y })
|
||||||
|
|
||||||
capi.mousegrabber.run(function (mouse)
|
capi.mousegrabber.run(function (_mouse)
|
||||||
for k, v in ipairs(mouse.buttons) do
|
for k, v in ipairs(_mouse.buttons) do
|
||||||
if v then
|
if v then
|
||||||
-- Ignore screen changes
|
-- Ignore screen changes
|
||||||
if not aclient.floating.get(c)
|
if not aclient.floating.get(c)
|
||||||
|
@ -506,21 +507,21 @@ local function client_resize_floating(c, corner, fixed_x, fixed_y)
|
||||||
|
|
||||||
local ng
|
local ng
|
||||||
if corner == "bottom_right" then
|
if corner == "bottom_right" then
|
||||||
ng = { width = mouse.x - g.x,
|
ng = { width = _mouse.x - g.x,
|
||||||
height = mouse.y - g.y }
|
height = _mouse.y - g.y }
|
||||||
elseif corner == "bottom_left" then
|
elseif corner == "bottom_left" then
|
||||||
ng = { x = mouse.x,
|
ng = { x = _mouse.x,
|
||||||
width = (g.x + g.width) - mouse.x,
|
width = (g.x + g.width) - _mouse.x,
|
||||||
height = mouse.y - g.y }
|
height = _mouse.y - g.y }
|
||||||
elseif corner == "top_left" then
|
elseif corner == "top_left" then
|
||||||
ng = { x = mouse.x,
|
ng = { x = _mouse.x,
|
||||||
width = (g.x + g.width) - mouse.x,
|
width = (g.x + g.width) - _mouse.x,
|
||||||
y = mouse.y,
|
y = _mouse.y,
|
||||||
height = (g.y + g.height) - mouse.y }
|
height = (g.y + g.height) - _mouse.y }
|
||||||
else
|
else
|
||||||
ng = { width = mouse.x - g.x,
|
ng = { width = _mouse.x - g.x,
|
||||||
y = mouse.y,
|
y = _mouse.y,
|
||||||
height = (g.y + g.height) - mouse.y }
|
height = (g.y + g.height) - _mouse.y }
|
||||||
end
|
end
|
||||||
if ng.width <= 0 then ng.width = nil end
|
if ng.width <= 0 then ng.width = nil end
|
||||||
if ng.height <= 0 then ng.height = nil end
|
if ng.height <= 0 then ng.height = nil end
|
||||||
|
@ -554,7 +555,7 @@ end
|
||||||
--- Resize a client.
|
--- Resize a client.
|
||||||
-- @param c The client to resize, or the focused one by default.
|
-- @param c The client to resize, or the focused one by default.
|
||||||
-- @param corner The corner to grab on resize. Auto detected by default.
|
-- @param corner The corner to grab on resize. Auto detected by default.
|
||||||
function client.resize(c, corner)
|
function mouse.client.resize(c, corner)
|
||||||
local c = c or capi.client.focus
|
local c = c or capi.client.focus
|
||||||
|
|
||||||
if not c then return end
|
if not c then return end
|
||||||
|
@ -588,4 +589,6 @@ end
|
||||||
-- Set the cursor at startup
|
-- Set the cursor at startup
|
||||||
capi.root.cursor("left_ptr")
|
capi.root.cursor("left_ptr")
|
||||||
|
|
||||||
|
return mouse
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||||
|
|
Loading…
Reference in New Issue