Implement fixes for Luacheck 0.26.1

* Rename or mute parameters starting with _
 * Replace `not (>=)` with `<`
This commit is contained in:
Emmanuel Lepage Vallee 2022-07-02 23:10:31 -07:00
parent 05a405b38b
commit 75019c3f6f
20 changed files with 273 additions and 250 deletions

View File

@ -258,14 +258,14 @@ local obj_mt = {
-- @tparam function args.on_release Callback for when the button is released. -- @tparam function args.on_release Callback for when the button is released.
-- @treturn table An `awful.button` object. -- @treturn table An `awful.button` object.
local function new_common(mod, _button, press, release) local function new_common(mod, btn, press, release)
local ret = {} local ret = {}
local subsets = gmath.subsets(ignore_modifiers) local subsets = gmath.subsets(ignore_modifiers)
for _, set in ipairs(subsets) do for _, set in ipairs(subsets) do
local sub_button = capi.button { local sub_button = capi.button {
modifiers = gtable.join(mod, set), modifiers = gtable.join(mod, set),
button = _button button = btn
} }
sub_button._private._legacy_convert_to = ret sub_button._private._legacy_convert_to = ret
@ -294,9 +294,9 @@ local function new_common(mod, _button, press, release)
return setmetatable(ret, obj_mt) return setmetatable(ret, obj_mt)
end end
function button.new(args, _button, press, release) function button.new(args, btn, press, release)
-- Assume this is the new constructor. -- Assume this is the new constructor.
if not _button then if not btn then
assert(not (press or release), "Calling awful.button() requires a button name") assert(not (press or release), "Calling awful.button() requires a button name")
return new_common( return new_common(
args.modifiers, args.modifiers,
@ -305,7 +305,7 @@ function button.new(args, _button, press, release)
args.on_release args.on_release
) )
else else
return new_common(args, _button, press, release) return new_common(args, btn, press, release)
end end
end end

View File

@ -271,7 +271,7 @@ end
-- @treturn table A table with one or several key objects. -- @treturn table A table with one or several key objects.
-- @constructorfct awful.key -- @constructorfct awful.key
local function new_common(mod, _keys, press, release, data) local function new_common(mod, keys, press, release, data)
if type(release)=='table' then if type(release)=='table' then
data=release data=release
release=nil release=nil
@ -279,7 +279,7 @@ local function new_common(mod, _keys, press, release, data)
local ret = {} local ret = {}
local subsets = gmath.subsets(key.ignore_modifiers) local subsets = gmath.subsets(key.ignore_modifiers)
for _, key_pair in ipairs(_keys) do for _, key_pair in ipairs(keys) do
for _, set in ipairs(subsets) do for _, set in ipairs(subsets) do
local sub_key = capi.key { local sub_key = capi.key {
modifiers = gtable.join(mod, set), modifiers = gtable.join(mod, set),
@ -315,15 +315,15 @@ local function new_common(mod, _keys, press, release, data)
-- append custom userdata (like description) to a hotkey -- append custom userdata (like description) to a hotkey
data = data and gtable.clone(data) or {} data = data and gtable.clone(data) or {}
data.mod = mod data.mod = mod
data.keys = _keys data.keys = keys
data.on_press = press data.on_press = press
data.on_release = release data.on_release = release
data._is_capi_key = false data._is_capi_key = false
assert((not data.key) or type(data.key) == "string") assert((not data.key) or type(data.key) == "string")
table.insert(key.hotkeys, data) table.insert(key.hotkeys, data)
data.execute = function(_) data.execute = function(_)
assert(#_keys == 1, "key:execute() makes no sense for groups") assert(#keys == 1, "key:execute() makes no sense for groups")
key.execute(mod, _keys[1]) key.execute(mod, keys[1])
end end
-- Store the private data -- Store the private data
@ -412,9 +412,9 @@ local function get_keys(args)
return key.keygroups[args.keygroup] return key.keygroups[args.keygroup]
end end
function key.new(args, _key, press, release, data) function key.new(args, keycode, press, release, data)
-- Assume this is the new constructor. -- Assume this is the new constructor.
if not _key then if not keycode then
assert(not (press or release or data), "Calling awful.key() requires a key name") assert(not (press or release or data), "Calling awful.key() requires a key name")
local keys = get_keys(args) local keys = get_keys(args)
@ -427,7 +427,7 @@ function key.new(args, _key, press, release, data)
args args
) )
else else
return new_common(args, {{_key}}, press, release, data) return new_common(args, {{keycode}}, press, release, data)
end end
end end
@ -436,11 +436,11 @@ end
-- @param pressed_mod The modifiers to compare with. -- @param pressed_mod The modifiers to compare with.
-- @param pressed_key The key to compare with. -- @param pressed_key The key to compare with.
-- @staticfct awful.key.match -- @staticfct awful.key.match
function key.match(_key, pressed_mod, pressed_key) function key.match(self, pressed_mod, pressed_key)
-- First, compare key. -- First, compare key.
if pressed_key ~= _key.key then return false end if pressed_key ~= self.key then return false end
-- Then, compare mod -- Then, compare mod
local mod = _key.modifiers local mod = self.modifiers
-- For each modifier of the key object, check that the modifier has been -- For each modifier of the key object, check that the modifier has been
-- pressed. -- pressed.
for _, m in ipairs(mod) do for _, m in ipairs(mod) do

View File

@ -480,7 +480,7 @@ end
-- @method stop -- @method stop
-- @emits stopped -- @emits stopped
-- @emits property::current_instance -- @emits property::current_instance
function keygrabber:stop(_stop_key, _stop_mods) -- (at)function disables ldoc params function keygrabber:stop(_stop_key, _stop_mods) --luacheck: ignore 214
keygrab.stop(self.grabber) keygrab.stop(self.grabber)
local timer = self._private.timer local timer = self._private.timer
@ -508,7 +508,7 @@ end
-- @tparam awful.key key The key. -- @tparam awful.key key The key.
-- @tparam string description.group The keybinding group -- @tparam string description.group The keybinding group
function keygrabber:add_keybinding(key, _keycode, _callback, _description) function keygrabber:add_keybinding(key, _keycode, _callback, _description) --luacheck: ignore 214
local mods = not key._is_awful_key and key or nil local mods = not key._is_awful_key and key or nil
if mods then if mods then

View File

@ -145,12 +145,12 @@ function layout.inc(i, s, layouts)
end end
--- Set the layout function of the current tag. --- Set the layout function of the current tag.
-- @param _layout Layout name. -- @tparam layout|function l Layout object or function.
-- @tparam[opt=mouse.screen.selected_tag] tag t The tag to modify. -- @tparam[opt=mouse.screen.selected_tag] tag t The tag to modify.
-- @staticfct awful.layout.set -- @staticfct awful.layout.set
function layout.set(_layout, t) function layout.set(l, t)
t = t or capi.mouse.screen.selected_tag t = t or capi.mouse.screen.selected_tag
t.layout = _layout t.layout = l
end end
--- Get the layout parameters used for the screen --- Get the layout parameters used for the screen

View File

@ -33,48 +33,55 @@ function floating.mouse_resize_handler(c, corner, x, y)
local fixed_y = c.maximized_vertical local fixed_y = c.maximized_vertical
local prev_coords = {} local prev_coords = {}
local coordinates_delta = {x=0,y=0} local coordinates_delta = {x=0, y=0}
if floating.resize_jump_to_corner then if floating.resize_jump_to_corner then
-- Warp mouse pointer -- Warp mouse pointer
capi.mouse.coords({ x = x, y = y }) capi.mouse.coords({ x = x, y = y })
else else
local corner_x, corner_y = x, y local corner_x, corner_y = x, y
local mouse_coords = capi.mouse.coords() local mouse_coords = capi.mouse.coords()
x = mouse_coords.x x = mouse_coords.x
y = mouse_coords.y y = mouse_coords.y
coordinates_delta = {x=corner_x-x,y=corner_y-y} coordinates_delta = {x = corner_x-x,y = corner_y-y}
end end
capi.mousegrabber.run(function (_mouse) capi.mousegrabber.run(function (state)
if not c.valid then return false end if not c.valid then return false end
_mouse.x = _mouse.x + coordinates_delta.x state.x = state.x + coordinates_delta.x
_mouse.y = _mouse.y + coordinates_delta.y state.y = state.y + coordinates_delta.y
for _, v in ipairs(_mouse.buttons) do
for _, v in ipairs(state.buttons) do
if v then if v then
local ng local ng
prev_coords = { x =_mouse.x, y = _mouse.y }
prev_coords = { x = state.x, y = state.y }
if corner == "bottom_right" then if corner == "bottom_right" then
ng = { width = _mouse.x - g.x, ng = { width = state.x - g.x,
height = _mouse.y - g.y } height = state.y - g.y }
elseif corner == "bottom_left" then elseif corner == "bottom_left" then
ng = { x = _mouse.x, ng = { x = state.x,
width = (g.x + g.width) - _mouse.x, width = (g.x + g.width) - state.x,
height = _mouse.y - g.y } height = state.y - g.y }
elseif corner == "top_left" then elseif corner == "top_left" then
ng = { x = _mouse.x, ng = { x = state.x,
width = (g.x + g.width) - _mouse.x, width = (g.x + g.width) - state.x,
y = _mouse.y, y = state.y,
height = (g.y + g.height) - _mouse.y } height = (g.y + g.height) - state.y }
else else
ng = { width = _mouse.x - g.x, ng = { width = state.x - g.x,
y = _mouse.y, y = state.y,
height = (g.y + g.height) - _mouse.y } height = (g.y + g.height) - state.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
if fixed_x then ng.width = g.width ng.x = g.x end if fixed_x then ng.width = g.width ng.x = g.x end
if fixed_y then ng.height = g.height ng.y = g.y end if fixed_y then ng.height = g.height ng.y = g.y end
c:geometry(ng) c:geometry(ng)
-- Get real geometry that has been applied -- Get real geometry that has been applied
-- in case we honor size hints -- in case we honor size hints
@ -92,11 +99,13 @@ function floating.mouse_resize_handler(c, corner, x, y)
else else
ng = { y = (g.y + g.height) - rg.height } ng = { y = (g.y + g.height) - rg.height }
end end
c:geometry({ x = ng.x, y = ng.y }) c:geometry({ x = ng.x, y = ng.y })
return true return true
end end
end end
return prev_coords.x == _mouse.x and prev_coords.y == _mouse.y
return prev_coords.x == state.x and prev_coords.y == state.y
end, corner .. "_corner") end, corner .. "_corner")
end end

View File

@ -33,14 +33,14 @@ function magnifier.mouse_resize_handler(c, corner, x, y)
local maxdist_pow = (wa.width^2 + wa.height^2) / 4 local maxdist_pow = (wa.width^2 + wa.height^2) / 4
local prev_coords = {} local prev_coords = {}
capi.mousegrabber.run(function (_mouse) capi.mousegrabber.run(function (position)
if not c.valid then return false end if not c.valid then return false end
for _, v in ipairs(_mouse.buttons) do for _, v in ipairs(position.buttons) do
if v then if v then
prev_coords = { x =_mouse.x, y = _mouse.y } prev_coords = { x =position.x, y = position.y }
local dx = center_x - _mouse.x local dx = center_x - position.x
local dy = center_y - _mouse.y local dy = center_y - position.y
local dist = dx^2 + dy^2 local dist = dx^2 + dy^2
-- New master width factor -- New master width factor
@ -50,7 +50,7 @@ function magnifier.mouse_resize_handler(c, corner, x, y)
return true return true
end end
end end
return prev_coords.x == _mouse.x and prev_coords.y == _mouse.y return prev_coords.x == position.x and prev_coords.y == position.y
end, corner .. "_corner") end, corner .. "_corner")
end end

View File

@ -24,7 +24,7 @@ local math = math
local spiral = {} local spiral = {}
local function do_spiral(p, _spiral) local function do_spiral(p, is_spiral)
local wa = p.workarea local wa = p.workarea
local cls = p.clients local cls = p.clients
local n = #cls local n = #cls
@ -43,19 +43,19 @@ local function do_spiral(p, _spiral)
end end
end end
if k % 4 == 0 and _spiral then if k % 4 == 0 and is_spiral then
wa.x = wa.x - wa.width wa.x = wa.x - wa.width
elseif k % 2 == 0 then elseif k % 2 == 0 then
wa.x = wa.x + old_width wa.x = wa.x + old_width
elseif k % 4 == 3 and k < n and _spiral then elseif k % 4 == 3 and k < n and is_spiral then
wa.x = wa.x + math.ceil(old_width / 2) wa.x = wa.x + math.ceil(old_width / 2)
end end
if k % 4 == 1 and k ~= 1 and _spiral then if k % 4 == 1 and k ~= 1 and is_spiral then
wa.y = wa.y - wa.height wa.y = wa.y - wa.height
elseif k % 2 == 1 and k ~= 1 then elseif k % 2 == 1 and k ~= 1 then
wa.y = wa.y + old_height wa.y = wa.y + old_height
elseif k % 4 == 0 and k < n and _spiral then elseif k % 4 == 0 and k < n and is_spiral then
wa.y = wa.y + math.ceil(old_height / 2) wa.y = wa.y + math.ceil(old_height / 2)
end end

View File

@ -61,7 +61,7 @@ local function mouse_resize_handler(c, _, _, _, orientation)
if g.height+15 > wa.height then if g.height+15 > wa.height then
offset = g.height * .5 offset = g.height * .5
cursor = "sb_h_double_arrow" cursor = "sb_h_double_arrow"
elseif not (g.y+g.height+15 > wa.y+wa.height) then elseif g.y+g.height+15 <= wa.y+wa.height then
offset = g.height offset = g.height
end end
corner_coords = { x = wa.x + wa.width * mwfact, y = g.y + offset } corner_coords = { x = wa.x + wa.width * mwfact, y = g.y + offset }
@ -70,7 +70,7 @@ local function mouse_resize_handler(c, _, _, _, orientation)
if g.height+15 >= wa.height then if g.height+15 >= wa.height then
offset = g.height * .5 offset = g.height * .5
cursor = "sb_h_double_arrow" cursor = "sb_h_double_arrow"
elseif not (g.y+g.height+15 > wa.y+wa.height) then elseif g.y+g.height+15 <= wa.y+wa.height then
offset = g.height offset = g.height
end end
corner_coords = { x = wa.x + wa.width * (1 - mwfact), y = g.y + offset } corner_coords = { x = wa.x + wa.width * (1 - mwfact), y = g.y + offset }
@ -79,7 +79,7 @@ local function mouse_resize_handler(c, _, _, _, orientation)
if g.width+15 >= wa.width then if g.width+15 >= wa.width then
offset = g.width * .5 offset = g.width * .5
cursor = "sb_v_double_arrow" cursor = "sb_v_double_arrow"
elseif not (g.x+g.width+15 > wa.x+wa.width) then elseif g.x+g.width+15 <= wa.x+wa.width then
offset = g.width offset = g.width
end end
corner_coords = { y = wa.y + wa.height * mwfact, x = g.x + offset} corner_coords = { y = wa.y + wa.height * mwfact, x = g.x + offset}
@ -88,7 +88,7 @@ local function mouse_resize_handler(c, _, _, _, orientation)
if g.width+15 >= wa.width then if g.width+15 >= wa.width then
offset = g.width * .5 offset = g.width * .5
cursor = "sb_v_double_arrow" cursor = "sb_v_double_arrow"
elseif not (g.x+g.width+15 > wa.x+wa.width) then elseif g.x+g.width+15 <= wa.x+wa.width then
offset = g.width offset = g.width
end end
corner_coords = { y = wa.y + wa.height * (1 - mwfact), x= g.x + offset } corner_coords = { y = wa.y + wa.height * (1 - mwfact), x= g.x + offset }
@ -104,16 +104,16 @@ local function mouse_resize_handler(c, _, _, _, orientation)
end end
local prev_coords = {} local prev_coords = {}
capi.mousegrabber.run(function (_mouse) capi.mousegrabber.run(function (coords)
if not c.valid then return false end if not c.valid then return false end
_mouse.x = _mouse.x + coordinates_delta.x coords.x = coords.x + coordinates_delta.x
_mouse.y = _mouse.y + coordinates_delta.y coords.y = coords.y + coordinates_delta.y
for _, v in ipairs(_mouse.buttons) do for _, v in ipairs(coords.buttons) do
if v then if v then
prev_coords = { x =_mouse.x, y = _mouse.y } prev_coords = { x =coords.x, y = coords.y }
local fact_x = (_mouse.x - wa.x) / wa.width local fact_x = (coords.x - wa.x) / wa.width
local fact_y = (_mouse.y - wa.y) / wa.height local fact_y = (coords.y - wa.y) / wa.height
local new_mwfact local new_mwfact
local geom = c:geometry() local geom = c:geometry()
@ -123,15 +123,15 @@ local function mouse_resize_handler(c, _, _, _, orientation)
local wfact local wfact
local wfact_x, wfact_y local wfact_x, wfact_y
if (geom.y+geom.height+15) > (wa.y+wa.height) then if (geom.y+geom.height+15) > (wa.y+wa.height) then
wfact_y = (geom.y + geom.height - _mouse.y) / wa.height wfact_y = (geom.y + geom.height - coords.y) / wa.height
else else
wfact_y = (_mouse.y - geom.y) / wa.height wfact_y = (coords.y - geom.y) / wa.height
end end
if (geom.x+geom.width+15) > (wa.x+wa.width) then if (geom.x+geom.width+15) > (wa.x+wa.width) then
wfact_x = (geom.x + geom.width - _mouse.x) / wa.width wfact_x = (geom.x + geom.width - coords.x) / wa.width
else else
wfact_x = (_mouse.x - geom.x) / wa.width wfact_x = (coords.x - geom.x) / wa.width
end end
@ -155,7 +155,7 @@ local function mouse_resize_handler(c, _, _, _, orientation)
return true return true
end end
end end
return prev_coords.x == _mouse.x and prev_coords.y == _mouse.y return prev_coords.x == coords.x and prev_coords.y == coords.y
end, cursor) end, cursor)
end end

View File

@ -147,16 +147,16 @@ local function load_theme(a, b)
end end
local function item_position(_menu, child) local function item_position(self, child)
local a, b = "height", "width" local a, b = "height", "width"
local dir = _menu.layout.dir or "y" local dir = self.layout.dir or "y"
if dir == "x" then a, b = b, a end if dir == "x" then a, b = b, a end
local in_dir, other = 0, _menu[b] local in_dir, other = 0, self[b]
local num = gtable.hasitem(_menu.child, child) local num = gtable.hasitem(self.child, child)
if num then if num then
for i = 0, num - 1 do for i = 0, num - 1 do
local item = _menu.items[i] local item = self.items[i]
if item then if item then
other = math.max(other, item[b]) other = math.max(other, item[b])
in_dir = in_dir + item[a] in_dir = in_dir + item[a]
@ -169,97 +169,97 @@ local function item_position(_menu, child)
end end
local function set_coords(_menu, s, m_coords) local function set_coords(self, s, m_coords)
local s_geometry = s.workarea local s_geometry = s.workarea
local screen_w = s_geometry.x + s_geometry.width local screen_w = s_geometry.x + s_geometry.width
local screen_h = s_geometry.y + s_geometry.height local screen_h = s_geometry.y + s_geometry.height
_menu.width = _menu.wibox.width self.width = self.wibox.width
_menu.height = _menu.wibox.height self.height = self.wibox.height
_menu.x = _menu.wibox.x self.x = self.wibox.x
_menu.y = _menu.wibox.y self.y = self.wibox.y
if _menu.parent then if self.parent then
local w, h = item_position(_menu.parent, _menu) local w, h = item_position(self.parent, self)
w = w + _menu.parent.theme.border_width w = w + self.parent.theme.border_width
_menu.y = _menu.parent.y + h + _menu.height > screen_h and self.y = self.parent.y + h + self.height > screen_h and
screen_h - _menu.height or _menu.parent.y + h screen_h - self.height or self.parent.y + h
_menu.x = _menu.parent.x + w + _menu.width > screen_w and self.x = self.parent.x + w + self.width > screen_w and
_menu.parent.x - _menu.width or _menu.parent.x + w self.parent.x - self.width or self.parent.x + w
else else
if m_coords == nil then if m_coords == nil then
m_coords = capi.mouse.coords() m_coords = capi.mouse.coords()
m_coords.x = m_coords.x + 1 m_coords.x = m_coords.x + 1
m_coords.y = m_coords.y + 1 m_coords.y = m_coords.y + 1
end end
_menu.y = m_coords.y < s_geometry.y and s_geometry.y or m_coords.y self.y = m_coords.y < s_geometry.y and s_geometry.y or m_coords.y
_menu.x = m_coords.x < s_geometry.x and s_geometry.x or m_coords.x self.x = m_coords.x < s_geometry.x and s_geometry.x or m_coords.x
_menu.y = _menu.y + _menu.height > screen_h and self.y = self.y + self.height > screen_h and
screen_h - _menu.height or _menu.y screen_h - self.height or self.y
_menu.x = _menu.x + _menu.width > screen_w and self.x = self.x + self.width > screen_w and
screen_w - _menu.width or _menu.x screen_w - self.width or self.x
end end
_menu.wibox.x = _menu.x self.wibox.x = self.x
_menu.wibox.y = _menu.y self.wibox.y = self.y
end end
local function set_size(_menu) local function set_size(self)
local in_dir, other, a, b = 0, 0, "height", "width" local in_dir, other, a, b = 0, 0, "height", "width"
local dir = _menu.layout.dir or "y" local dir = self.layout.dir or "y"
if dir == "x" then a, b = b, a end if dir == "x" then a, b = b, a end
for _, item in ipairs(_menu.items) do for _, item in ipairs(self.items) do
other = math.max(other, item[b]) other = math.max(other, item[b])
in_dir = in_dir + item[a] in_dir = in_dir + item[a]
end end
_menu[a], _menu[b] = in_dir, other self[a], self[b] = in_dir, other
if in_dir > 0 and other > 0 then if in_dir > 0 and other > 0 then
_menu.wibox[a] = in_dir self.wibox[a] = in_dir
_menu.wibox[b] = other self.wibox[b] = other
return true return true
end end
return false return false
end end
local function check_access_key(_menu, key) local function check_access_key(self, key)
for i, item in ipairs(_menu.items) do for i, item in ipairs(self.items) do
if item.akey == key then if item.akey == key then
_menu:item_enter(i) self:item_enter(i)
_menu:exec(i, { exec = true }) self:exec(i, { exec = true })
return return
end end
end end
if _menu.parent then if self.parent then
check_access_key(_menu.parent, key) check_access_key(self.parent, key)
end end
end end
local function grabber(_menu, _, key, event) local function grabber(self, _, key, event)
if event ~= "press" then return end if event ~= "press" then return end
local sel = _menu.sel or 0 local sel = self.sel or 0
if gtable.hasitem(menu.menu_keys.up, key) then if gtable.hasitem(menu.menu_keys.up, key) then
local sel_new = sel-1 < 1 and #_menu.items or sel-1 local sel_new = sel-1 < 1 and #self.items or sel-1
_menu:item_enter(sel_new) self:item_enter(sel_new)
elseif gtable.hasitem(menu.menu_keys.down, key) then elseif gtable.hasitem(menu.menu_keys.down, key) then
local sel_new = sel+1 > #_menu.items and 1 or sel+1 local sel_new = sel+1 > #self.items and 1 or sel+1
_menu:item_enter(sel_new) self:item_enter(sel_new)
elseif sel > 0 and gtable.hasitem(menu.menu_keys.enter, key) then elseif sel > 0 and gtable.hasitem(menu.menu_keys.enter, key) then
_menu:exec(sel) self:exec(sel)
elseif sel > 0 and gtable.hasitem(menu.menu_keys.exec, key) then elseif sel > 0 and gtable.hasitem(menu.menu_keys.exec, key) then
_menu:exec(sel, { exec = true }) self:exec(sel, { exec = true })
elseif gtable.hasitem(menu.menu_keys.back, key) then elseif gtable.hasitem(menu.menu_keys.back, key) then
_menu:hide() self:hide()
elseif gtable.hasitem(menu.menu_keys.close, key) then elseif gtable.hasitem(menu.menu_keys.close, key) then
menu.get_root(_menu):hide() menu.get_root(self):hide()
else else
check_access_key(_menu, key) check_access_key(self, key)
end end
end end

View File

@ -154,7 +154,7 @@ local function handler(_, client, context, args) --luacheck: no unused_args
or "fleur" or "fleur"
-- Execute the placement function and use request::geometry -- Execute the placement function and use request::geometry
capi.mousegrabber.run(function (_mouse) capi.mousegrabber.run(function (coords)
if not client.valid then return end if not client.valid then return end
-- Resize everytime the mouse moves (default behavior) in live mode, -- Resize everytime the mouse moves (default behavior) in live mode,
@ -194,7 +194,7 @@ local function handler(_, client, context, args) --luacheck: no unused_args
end end
-- Quit when the button is released -- Quit when the button is released
for _,v in pairs(_mouse.buttons) do for _,v in pairs(coords.buttons) do
if v then return true end if v then return true end
end end

View File

@ -858,8 +858,8 @@ function placement.closest_corner(d, args)
local corner_i, corner_j, n local corner_i, corner_j, n
-- Use the product of 3 to get the closest point in a NxN matrix -- Use the product of 3 to get the closest point in a NxN matrix
local function f(_n, mat) local function f(dim, mat)
n = _n n = dim
-- The +1 is required to avoid a rounding error when -- The +1 is required to avoid a rounding error when
-- pos.x == sgeo.x+sgeo.width -- pos.x == sgeo.x+sgeo.width
corner_i = -math.ceil( ( (sgeo.x - pos.x) * n) / (sgeo.width + 1)) corner_i = -math.ceil( ( (sgeo.x - pos.x) * n) / (sgeo.width + 1))

View File

@ -155,10 +155,10 @@ end
-- This moves the mouse pointer to the last known position on the new screen, -- This moves the mouse pointer to the last known position on the new screen,
-- or keeps its position relative to the current focused screen. -- or keeps its position relative to the current focused screen.
-- @staticfct awful.screen.focus_bydirection -- @staticfct awful.screen.focus_bydirection
-- @param dir The direction, can be either "up", "down", "left" or "right". -- @tparam string dir The direction, can be either "up", "down", "left" or "right".
-- @param _screen Screen. -- @tparam screen s Screen.
function screen.focus_bydirection(dir, _screen) function screen.focus_bydirection(dir, s)
local sel = get_screen(_screen or screen.focused()) local sel = get_screen(s or screen.focused())
local target = sel:get_next_in_direction(dir) local target = sel:get_next_in_direction(dir)
if target then if target then
@ -228,18 +228,18 @@ end
--- Get or set the screen padding. --- Get or set the screen padding.
-- --
-- @deprecated awful.screen.padding -- @deprecated awful.screen.padding
-- @param _screen The screen object to change the padding on -- @param s The screen object to change the padding on
-- @param[opt=nil] padding The padding, a table with 'top', 'left', 'right' and/or -- @param[opt=nil] padding The padding, a table with 'top', 'left', 'right' and/or
-- 'bottom' or a number value to apply set the same padding on all sides. Can be -- 'bottom' or a number value to apply set the same padding on all sides. Can be
-- nil if you only want to retrieve padding -- nil if you only want to retrieve padding
-- @treturn table A table with left, right, top and bottom number values. -- @treturn table A table with left, right, top and bottom number values.
-- @see padding -- @see padding
function screen.padding(_screen, padding) function screen.padding(s, padding)
gdebug.deprecate("Use _screen.padding = value instead of awful.screen.padding", {deprecated_in=4}) gdebug.deprecate("Use _screen.padding = value instead of awful.screen.padding", {deprecated_in=4})
if padding then if padding then
screen.object.set_padding(_screen, padding) screen.object.set_padding(s, padding)
end end
return screen.object.get_padding(_screen) return screen.object.get_padding(s)
end end
--- The screen padding. --- The screen padding.

View File

@ -1650,10 +1650,10 @@ end
-- Do not use. -- Do not use.
-- --
-- @deprecated awful.tag.getdata -- @deprecated awful.tag.getdata
-- @tparam tag _tag The tag. -- @tparam tag t The tag.
-- @return The data table. -- @return The data table.
function tag.getdata(_tag) function tag.getdata(t)
return _tag._private.awful_tag_properties return t._private.awful_tag_properties
end end
--- Get a tag property. --- Get a tag property.
@ -1661,14 +1661,14 @@ end
-- Use `_tag.prop` directly. -- Use `_tag.prop` directly.
-- --
-- @deprecated awful.tag.getproperty -- @deprecated awful.tag.getproperty
-- @tparam tag _tag The tag. -- @tparam tag t The tag.
-- @tparam string prop The property name. -- @tparam string prop The property name.
-- @return The property. -- @return The property.
function tag.getproperty(_tag, prop) function tag.getproperty(t, prop)
if not _tag then return end -- FIXME: Turn this into an error? if not t then return end -- FIXME: Turn this into an error?
if _tag._private.awful_tag_properties then if t._private.awful_tag_properties then
return _tag._private.awful_tag_properties[prop] return t._private.awful_tag_properties[prop]
end end
end end
@ -1676,20 +1676,20 @@ end
-- This properties are internal to awful. Some are used to draw taglist, or to -- This properties are internal to awful. Some are used to draw taglist, or to
-- handle layout, etc. -- handle layout, etc.
-- --
-- Use `_tag.prop = value` -- Use `t.prop = value`
-- --
-- @deprecated awful.tag.setproperty -- @deprecated awful.tag.setproperty
-- @param _tag The tag. -- @param t The tag.
-- @param prop The property name. -- @param prop The property name.
-- @param value The value. -- @param value The value.
function tag.setproperty(_tag, prop, value) function tag.setproperty(t, prop, value)
if not _tag._private.awful_tag_properties then if not t._private.awful_tag_properties then
_tag._private.awful_tag_properties = {} t._private.awful_tag_properties = {}
end end
if _tag._private.awful_tag_properties[prop] ~= value then if t._private.awful_tag_properties[prop] ~= value then
_tag._private.awful_tag_properties[prop] = value t._private.awful_tag_properties[prop] = value
_tag:emit_signal("property::" .. prop) t:emit_signal("property::" .. prop)
end end
end end
@ -1721,9 +1721,9 @@ end
local function attached_connect_signal_screen(screen, sig, func) local function attached_connect_signal_screen(screen, sig, func)
screen = get_screen(screen) screen = get_screen(screen)
capi.tag.connect_signal(sig, function(_tag) capi.tag.connect_signal(sig, function(t)
if get_screen(tag.getproperty(_tag, "screen")) == screen then if get_screen(tag.getproperty(t, "screen")) == screen then
func(_tag) func(t)
end end
end) end)
end end

View File

@ -117,23 +117,23 @@ end
-- * right -- * right
-- --
-- @tparam string dir The direction. -- @tparam string dir The direction.
-- @tparam table _gA The first rectangle. -- @tparam table gA The first rectangle.
-- @tparam table _gB The second rectangle. -- @tparam table gB The second rectangle.
-- @return The distance between the screens. -- @return The distance between the screens.
local function calculate_distance(dir, _gA, _gB) local function calculate_distance(dir, gA, gB)
local gAx = _gA.x local gAx = gA.x
local gAy = _gA.y local gAy = gA.y
local gBx = _gB.x local gBx = gB.x
local gBy = _gB.y local gBy = gB.y
if dir == "up" then if dir == "up" then
gBy = _gB.y + _gB.height gBy = gB.y + gB.height
elseif dir == "down" then elseif dir == "down" then
gAy = _gA.y + _gA.height gAy = gA.y + gA.height
elseif dir == "left" then elseif dir == "left" then
gBx = _gB.x + _gB.width gBx = gB.x + gB.width
elseif dir == "right" then elseif dir == "right" then
gAx = _gA.x + _gA.width gAx = gA.x + gA.width
end end
return math.sqrt((gBx - gAx) ^ 2 + (gBy - gAy) ^ 2) return math.sqrt((gBx - gAx) ^ 2 + (gBy - gAy) ^ 2)

View File

@ -358,8 +358,8 @@ end
-- @treturn boolean Returns false if a dependency conflict was found. -- @treturn boolean Returns false if a dependency conflict was found.
-- @method add_matching_rules -- @method add_matching_rules
function matcher:add_matching_rules(name, rules, depends_on, precede) function matcher:add_matching_rules(name, rules, depends_on, precede)
local function matching_fct(_self, c, props, callbacks) local function matching_fct(_, c, props, callbacks)
default_rules_callback(_self, c, props, callbacks, rules) default_rules_callback(self, c, props, callbacks, rules)
end end
self._matching_rules[name] = rules self._matching_rules[name] = rules

View File

@ -31,7 +31,7 @@ end
--- Try to convert the argument into an lgi cairo surface. --- Try to convert the argument into an lgi cairo surface.
-- This is usually needed for loading images by file name. -- This is usually needed for loading images by file name.
-- @param _surface The surface to load or nil -- @param surface The surface to load or nil
-- @param default The default value to return on error; when nil, then a surface -- @param default The default value to return on error; when nil, then a surface
-- in an error state is returned. -- in an error state is returned.
-- @return The loaded surface, or the replacement default -- @return The loaded surface, or the replacement default
@ -67,60 +67,60 @@ end
--- Try to convert the argument into an lgi cairo surface. --- Try to convert the argument into an lgi cairo surface.
-- This is usually needed for loading images by file name and uses a cache. -- This is usually needed for loading images by file name and uses a cache.
-- In contrast to `load()`, errors are returned to the caller. -- In contrast to `load()`, errors are returned to the caller.
-- @param _surface The surface to load or nil -- @param surface The surface to load or nil
-- @param default The default value to return on error; when nil, then a surface -- @param default The default value to return on error; when nil, then a surface
-- in an error state is returned. -- in an error state is returned.
-- @return The loaded surface, or the replacement default, or nil if called with -- @return The loaded surface, or the replacement default, or nil if called with
-- nil. -- nil.
-- @return An error message, or nil on success. -- @return An error message, or nil on success.
-- @staticfct load_silently -- @staticfct load_silently
function surface.load_silently(_surface, default) function surface.load_silently(self, default)
if type(_surface) == "string" then if type(self) == "string" then
local cache = surface_cache[_surface] local cache = surface_cache[self]
if cache then if cache then
return cache return cache
end end
local result, err = surface.load_uncached_silently(_surface, default) local result, err = surface.load_uncached_silently(self, default)
if not err then if not err then
-- Cache the file -- Cache the file
surface_cache[_surface] = result surface_cache[self] = result
end end
return result, err return result, err
end end
return surface.load_uncached_silently(_surface, default) return surface.load_uncached_silently(self, default)
end end
local function do_load_and_handle_errors(_surface, func) local function do_load_and_handle_errors(self, func)
if type(_surface) == 'nil' then if type(self) == 'nil' then
return get_default() return get_default()
end end
local result, err = func(_surface, false) local result, err = func(self, false)
if result then if result then
return result return result
end end
gdebug.print_error(debug.traceback( gdebug.print_error(debug.traceback(
"Failed to load '" .. tostring(_surface) .. "': " .. tostring(err))) "Failed to load '" .. tostring(self) .. "': " .. tostring(err)))
return get_default() return get_default()
end end
--- Try to convert the argument into an lgi cairo surface. --- Try to convert the argument into an lgi cairo surface.
-- This is usually needed for loading images by file name. Errors are handled -- This is usually needed for loading images by file name. Errors are handled
-- via `gears.debug.print_error`. -- via `gears.debug.print_error`.
-- @param _surface The surface to load or nil -- @param surface The surface to load or nil
-- @return The loaded surface, or nil -- @return The loaded surface, or nil
-- @staticfct load_uncached -- @staticfct load_uncached
function surface.load_uncached(_surface) function surface.load_uncached(self)
return do_load_and_handle_errors(_surface, surface.load_uncached_silently) return do_load_and_handle_errors(self, surface.load_uncached_silently)
end end
--- Try to convert the argument into an lgi cairo surface. --- Try to convert the argument into an lgi cairo surface.
-- This is usually needed for loading images by file name. Errors are handled -- This is usually needed for loading images by file name. Errors are handled
-- via `gears.debug.print_error`. -- via `gears.debug.print_error`.
-- @param _surface The surface to load or nil -- @param surface The surface to load or nil
-- @return The loaded surface, or nil. -- @return The loaded surface, or nil.
-- @staticfct gears.surface -- @staticfct gears.surface
function surface.load(_surface) function surface.load(self)
return do_load_and_handle_errors(_surface, surface.load_silently) return do_load_and_handle_errors(self, surface.load_silently)
end end
function surface.mt.__call(_, ...) function surface.mt.__call(_, ...)

View File

@ -152,22 +152,22 @@ end
--- Get list of matching rules for a client. --- Get list of matching rules for a client.
-- @tparam client c The client. -- @tparam client c The client.
-- @tparam table _rules The rules to check. List with "rule", "rule_any", "except" and -- @tparam table rules The rules to check. List with "rule", "rule_any", "except" and
-- "except_any" keys. -- "except_any" keys.
-- @treturn table The list of matched rules. -- @treturn table The list of matched rules.
-- @staticfct ruled.client.matching_rules -- @staticfct ruled.client.matching_rules
function module.matching_rules(c, _rules) function module.matchingrules(c, rules)
return crules:matching_rules(c, _rules) return crules:matching_rules(c, rules)
end end
--- Check if a client matches a given set of rules. --- Check if a client matches a given set of rules.
-- @tparam client c The client. -- @tparam client c The client.
-- @tparam table _rules The rules to check. List of tables with `rule`, `rule_any`, -- @tparam table rules The rules to check. List of tables with `rule`, `rule_any`,
-- `except` and `except_any` keys. -- `except` and `except_any` keys.
-- @treturn bool True if at least one rule is matched, false otherwise. -- @treturn bool True if at least one rule is matched, false otherwise.
-- @staticfct ruled.client.matches_list -- @staticfct ruled.client.matches_list
function module.matches_list(c, _rules) function module.matches_list(c, rules)
return crules:matches_rules(c, _rules) return crules:matchesrules(c, rules)
end end
--- Remove a source. --- Remove a source.

View File

@ -21,7 +21,7 @@ local surface = require("gears.surface")
local timer = require("gears.timer") local timer = require("gears.timer")
local grect = require("gears.geometry").rectangle local grect = require("gears.geometry").rectangle
local matrix = require("gears.matrix") local matrix = require("gears.matrix")
local hierarchy = require("wibox.hierarchy") local whierarchy = require("wibox.hierarchy")
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1) local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
local visible_drawables = {} local visible_drawables = {}
@ -92,7 +92,7 @@ local function do_redraw(self)
self._need_complete_repaint = true self._need_complete_repaint = true
if self._widget then if self._widget then
self._widget_hierarchy_callback_arg = {} self._widget_hierarchy_callback_arg = {}
self._widget_hierarchy = hierarchy.new(context, self._widget, width, height, self._widget_hierarchy = whierarchy.new(context, self._widget, width, height,
self._redraw_callback, self._layout_callback, self._widget_hierarchy_callback_arg) self._redraw_callback, self._layout_callback, self._widget_hierarchy_callback_arg)
else else
self._widget_hierarchy = nil self._widget_hierarchy = nil
@ -166,12 +166,12 @@ local function do_redraw(self)
assert(cr.status == "SUCCESS", "Cairo context entered error state: " .. cr.status) assert(cr.status == "SUCCESS", "Cairo context entered error state: " .. cr.status)
end end
local function find_widgets(_drawable, result, _hierarchy, x, y) local function find_widgets(self, result, hierarchy, x, y)
local m = _hierarchy:get_matrix_from_device() local m = hierarchy:get_matrix_from_device()
-- Is (x,y) inside of this hierarchy or any child (aka the draw extents) -- Is (x,y) inside of this hierarchy or any child (aka the draw extents)
local x1, y1 = m:transform_point(x, y) local x1, y1 = m:transform_point(x, y)
local x2, y2, w2, h2 = _hierarchy:get_draw_extents() local x2, y2, w2, h2 = hierarchy:get_draw_extents()
if x1 < x2 or x1 >= x2 + w2 then if x1 < x2 or x1 >= x2 + w2 then
return return
end end
@ -180,22 +180,22 @@ local function find_widgets(_drawable, result, _hierarchy, x, y)
end end
-- Is (x,y) inside of this widget? -- Is (x,y) inside of this widget?
local width, height = _hierarchy:get_size() local width, height = hierarchy:get_size()
if x1 >= 0 and y1 >= 0 and x1 <= width and y1 <= height then if x1 >= 0 and y1 >= 0 and x1 <= width and y1 <= height then
-- Get the extents of this widget in the device space -- Get the extents of this widget in the device space
local x3, y3, w3, h3 = matrix.transform_rectangle(_hierarchy:get_matrix_to_device(), local x3, y3, w3, h3 = matrix.transform_rectangle(hierarchy:get_matrix_to_device(),
0, 0, width, height) 0, 0, width, height)
table.insert(result, { table.insert(result, {
x = x3, y = y3, width = w3, height = h3, x = x3, y = y3, width = w3, height = h3,
widget_width = width, widget_width = width,
widget_height = height, widget_height = height,
drawable = _drawable, drawable = self,
widget = _hierarchy:get_widget(), widget = hierarchy:get_widget(),
hierarchy = _hierarchy hierarchy = hierarchy
}) })
end end
for _, child in ipairs(_hierarchy:get_children()) do for _, child in ipairs(hierarchy:get_children()) do
find_widgets(_drawable, result, child, x, y) find_widgets(self, result, child, x, y)
end end
end end
@ -221,7 +221,7 @@ end
-- Private API. Not documented on purpose. -- Private API. Not documented on purpose.
function drawable._set_systray_widget(widget) function drawable._set_systray_widget(widget)
hierarchy.count_widget(widget) whierarchy.count_widget(widget)
systray_widget = widget systray_widget = widget
end end
@ -331,34 +331,36 @@ local function emit_difference(name, list, skip)
end end
end end
local function handle_leave(_drawable) local function handle_leave(self)
emit_difference("mouse::leave", _drawable._widgets_under_mouse, {}) emit_difference("mouse::leave", self._widgets_under_mouse, {})
_drawable._widgets_under_mouse = {} self._widgets_under_mouse = {}
end end
local function handle_motion(_drawable, x, y) local function handle_motion(self, x, y)
if x < 0 or y < 0 or x > _drawable.drawable:geometry().width or y > _drawable.drawable:geometry().height then local dgeo = self.drawable:geometry()
return handle_leave(_drawable)
if x < 0 or y < 0 or x > dgeo.width or y > dgeo.height then
return handle_leave(self)
end end
-- Build a plain list of all widgets on that point -- Build a plain list of all widgets on that point
local widgets_list = _drawable:find_widgets(x, y) local widgets_list = self:find_widgets(x, y)
-- First, "leave" all widgets that were left -- First, "leave" all widgets that were left
emit_difference("mouse::leave", _drawable._widgets_under_mouse, widgets_list) emit_difference("mouse::leave", self._widgets_under_mouse, widgets_list)
-- Then enter some widgets -- Then enter some widgets
emit_difference("mouse::enter", widgets_list, _drawable._widgets_under_mouse) emit_difference("mouse::enter", widgets_list, self._widgets_under_mouse)
_drawable._widgets_under_mouse = widgets_list self._widgets_under_mouse = widgets_list
end end
local function setup_signals(_drawable) local function setup_signals(self)
local d = _drawable.drawable local d = self.drawable
local function clone_signal(name) local function clone_signal(name)
-- When "name" is emitted on wibox.drawin, also emit it on wibox -- When "name" is emitted on wibox.drawin, also emit it on wibox
d:connect_signal(name, function(_, ...) d:connect_signal(name, function(_, ...)
_drawable:emit_signal(name, ...) self:emit_signal(name, ...)
end) end)
end end
clone_signal("button::press") clone_signal("button::press")

View File

@ -246,16 +246,16 @@ object.properties._legacy_accessors(wibox.object, "buttons", "_buttons", true, f
) or false ) or false
end, true) end, true)
local function setup_signals(_wibox) local function setup_signals(w)
local obj local obj
local function clone_signal(name) local function clone_signal(name)
-- When "name" is emitted on wibox.drawin, also emit it on wibox -- When "name" is emitted on wibox.drawin, also emit it on wibox
obj:connect_signal(name, function(_, ...) obj:connect_signal(name, function(_, ...)
_wibox:emit_signal(name, ...) w:emit_signal(name, ...)
end) end)
end end
obj = _wibox.drawin obj = w.drawin
clone_signal("property::border_color") clone_signal("property::border_color")
clone_signal("property::border_width") clone_signal("property::border_width")
clone_signal("property::buttons") clone_signal("property::buttons")
@ -273,7 +273,7 @@ local function setup_signals(_wibox)
clone_signal("property::shape_clip") clone_signal("property::shape_clip")
clone_signal("property::shape_input") clone_signal("property::shape_input")
obj = _wibox._drawable obj = w._drawable
clone_signal("button::press") clone_signal("button::press")
clone_signal("button::release") clone_signal("button::release")
clone_signal("mouse::enter") clone_signal("mouse::enter")

View File

@ -343,9 +343,21 @@ prop_fallbacks.nan_color = build_fallback_nan_color()
-- --
local function graph_gather_drawn_values_num_stats(self, new_value) local function graph_gather_drawn_values_num_stats(self, new_value)
if not (new_value >= 0) then -- Because the graphs are at risk of dividing by zero, the value can
return -- is negative or NaN -- be `inf`, `-inf` and `-nan`. For example:
end --
-- nan = 0/0
-- print(not (nan >= 0), nan < 0)
-- > true, false
--
-- Because if this, we need to ignore the luacheck rule which promotes
-- the removal of double negative and DeMorgan's law style optimizations.
-- Those only works on real numbers, which `NaN` and `Inf` are not part of.
--
-- The `luacheck` project decided that adding this check by default and
-- adding annotations where it doesn't work is the way to go
-- https://github.com/lunarmodules/luacheck/issues/43#issuecomment-1014949507
if not (new_value >= 0) then return end --luacheck: ignore 581
local last_value = self._private.last_drawn_values_num or 0 local last_value = self._private.last_drawn_values_num or 0
-- Grow instantly and shrink slow -- Grow instantly and shrink slow