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.
-- @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 subsets = gmath.subsets(ignore_modifiers)
for _, set in ipairs(subsets) do
local sub_button = capi.button {
modifiers = gtable.join(mod, set),
button = _button
button = btn
}
sub_button._private._legacy_convert_to = ret
@ -294,9 +294,9 @@ local function new_common(mod, _button, press, release)
return setmetatable(ret, obj_mt)
end
function button.new(args, _button, press, release)
function button.new(args, btn, press, release)
-- 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")
return new_common(
args.modifiers,
@ -305,7 +305,7 @@ function button.new(args, _button, press, release)
args.on_release
)
else
return new_common(args, _button, press, release)
return new_common(args, btn, press, release)
end
end

View File

@ -271,7 +271,7 @@ end
-- @treturn table A table with one or several key objects.
-- @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
data=release
release=nil
@ -279,7 +279,7 @@ local function new_common(mod, _keys, press, release, data)
local ret = {}
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
local sub_key = capi.key {
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
data = data and gtable.clone(data) or {}
data.mod = mod
data.keys = _keys
data.keys = keys
data.on_press = press
data.on_release = release
data._is_capi_key = false
assert((not data.key) or type(data.key) == "string")
table.insert(key.hotkeys, data)
data.execute = function(_)
assert(#_keys == 1, "key:execute() makes no sense for groups")
key.execute(mod, _keys[1])
assert(#keys == 1, "key:execute() makes no sense for groups")
key.execute(mod, keys[1])
end
-- Store the private data
@ -412,9 +412,9 @@ local function get_keys(args)
return key.keygroups[args.keygroup]
end
function key.new(args, _key, press, release, data)
function key.new(args, keycode, press, release, data)
-- 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")
local keys = get_keys(args)
@ -427,7 +427,7 @@ function key.new(args, _key, press, release, data)
args
)
else
return new_common(args, {{_key}}, press, release, data)
return new_common(args, {{keycode}}, press, release, data)
end
end
@ -436,11 +436,11 @@ end
-- @param pressed_mod The modifiers to compare with.
-- @param pressed_key The key to compare with.
-- @staticfct awful.key.match
function key.match(_key, pressed_mod, pressed_key)
function key.match(self, pressed_mod, pressed_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
local mod = _key.modifiers
local mod = self.modifiers
-- For each modifier of the key object, check that the modifier has been
-- pressed.
for _, m in ipairs(mod) do

View File

@ -480,7 +480,7 @@ end
-- @method stop
-- @emits stopped
-- @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)
local timer = self._private.timer
@ -508,7 +508,7 @@ end
-- @tparam awful.key key The key.
-- @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
if mods then

View File

@ -145,12 +145,12 @@ function layout.inc(i, s, layouts)
end
--- 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.
-- @staticfct awful.layout.set
function layout.set(_layout, t)
function layout.set(l, t)
t = t or capi.mouse.screen.selected_tag
t.layout = _layout
t.layout = l
end
--- Get the layout parameters used for the screen

View File

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

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 prev_coords = {}
capi.mousegrabber.run(function (_mouse)
capi.mousegrabber.run(function (position)
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
prev_coords = { x =_mouse.x, y = _mouse.y }
local dx = center_x - _mouse.x
local dy = center_y - _mouse.y
prev_coords = { x =position.x, y = position.y }
local dx = center_x - position.x
local dy = center_y - position.y
local dist = dx^2 + dy^2
-- New master width factor
@ -50,7 +50,7 @@ function magnifier.mouse_resize_handler(c, corner, x, y)
return true
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

View File

@ -24,7 +24,7 @@ local math = math
local spiral = {}
local function do_spiral(p, _spiral)
local function do_spiral(p, is_spiral)
local wa = p.workarea
local cls = p.clients
local n = #cls
@ -43,19 +43,19 @@ local function do_spiral(p, _spiral)
end
end
if k % 4 == 0 and _spiral then
if k % 4 == 0 and is_spiral then
wa.x = wa.x - wa.width
elseif k % 2 == 0 then
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)
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
elseif k % 2 == 1 and k ~= 1 then
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)
end

View File

@ -61,7 +61,7 @@ local function mouse_resize_handler(c, _, _, _, orientation)
if g.height+15 > wa.height then
offset = g.height * .5
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
end
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
offset = g.height * .5
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
end
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
offset = g.width * .5
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
end
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
offset = g.width * .5
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
end
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
local prev_coords = {}
capi.mousegrabber.run(function (_mouse)
capi.mousegrabber.run(function (coords)
if not c.valid then return false end
_mouse.x = _mouse.x + coordinates_delta.x
_mouse.y = _mouse.y + coordinates_delta.y
for _, v in ipairs(_mouse.buttons) do
coords.x = coords.x + coordinates_delta.x
coords.y = coords.y + coordinates_delta.y
for _, v in ipairs(coords.buttons) do
if v then
prev_coords = { x =_mouse.x, y = _mouse.y }
local fact_x = (_mouse.x - wa.x) / wa.width
local fact_y = (_mouse.y - wa.y) / wa.height
prev_coords = { x =coords.x, y = coords.y }
local fact_x = (coords.x - wa.x) / wa.width
local fact_y = (coords.y - wa.y) / wa.height
local new_mwfact
local geom = c:geometry()
@ -123,15 +123,15 @@ local function mouse_resize_handler(c, _, _, _, orientation)
local wfact
local wfact_x, wfact_y
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
wfact_y = (_mouse.y - geom.y) / wa.height
wfact_y = (coords.y - geom.y) / wa.height
end
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
wfact_x = (_mouse.x - geom.x) / wa.width
wfact_x = (coords.x - geom.x) / wa.width
end
@ -155,7 +155,7 @@ local function mouse_resize_handler(c, _, _, _, orientation)
return true
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

View File

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

View File

@ -154,7 +154,7 @@ local function handler(_, client, context, args) --luacheck: no unused_args
or "fleur"
-- 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
-- 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
-- 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
end

View File

@ -858,8 +858,8 @@ function placement.closest_corner(d, args)
local corner_i, corner_j, n
-- Use the product of 3 to get the closest point in a NxN matrix
local function f(_n, mat)
n = _n
local function f(dim, mat)
n = dim
-- The +1 is required to avoid a rounding error when
-- pos.x == sgeo.x+sgeo.width
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,
-- or keeps its position relative to the current focused screen.
-- @staticfct awful.screen.focus_bydirection
-- @param dir The direction, can be either "up", "down", "left" or "right".
-- @param _screen Screen.
function screen.focus_bydirection(dir, _screen)
local sel = get_screen(_screen or screen.focused())
-- @tparam string dir The direction, can be either "up", "down", "left" or "right".
-- @tparam screen s Screen.
function screen.focus_bydirection(dir, s)
local sel = get_screen(s or screen.focused())
local target = sel:get_next_in_direction(dir)
if target then
@ -228,18 +228,18 @@ end
--- Get or set the 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
-- 'bottom' or a number value to apply set the same padding on all sides. Can be
-- nil if you only want to retrieve padding
-- @treturn table A table with left, right, top and bottom number values.
-- @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})
if padding then
screen.object.set_padding(_screen, padding)
screen.object.set_padding(s, padding)
end
return screen.object.get_padding(_screen)
return screen.object.get_padding(s)
end
--- The screen padding.

View File

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

View File

@ -117,23 +117,23 @@ end
-- * right
--
-- @tparam string dir The direction.
-- @tparam table _gA The first rectangle.
-- @tparam table _gB The second rectangle.
-- @tparam table gA The first rectangle.
-- @tparam table gB The second rectangle.
-- @return The distance between the screens.
local function calculate_distance(dir, _gA, _gB)
local gAx = _gA.x
local gAy = _gA.y
local gBx = _gB.x
local gBy = _gB.y
local function calculate_distance(dir, gA, gB)
local gAx = gA.x
local gAy = gA.y
local gBx = gB.x
local gBy = gB.y
if dir == "up" then
gBy = _gB.y + _gB.height
gBy = gB.y + gB.height
elseif dir == "down" then
gAy = _gA.y + _gA.height
gAy = gA.y + gA.height
elseif dir == "left" then
gBx = _gB.x + _gB.width
gBx = gB.x + gB.width
elseif dir == "right" then
gAx = _gA.x + _gA.width
gAx = gA.x + gA.width
end
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.
-- @method add_matching_rules
function matcher:add_matching_rules(name, rules, depends_on, precede)
local function matching_fct(_self, c, props, callbacks)
default_rules_callback(_self, c, props, callbacks, rules)
local function matching_fct(_, c, props, callbacks)
default_rules_callback(self, c, props, callbacks, rules)
end
self._matching_rules[name] = rules

View File

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

View File

@ -152,22 +152,22 @@ end
--- Get list of matching rules for a 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.
-- @treturn table The list of matched rules.
-- @staticfct ruled.client.matching_rules
function module.matching_rules(c, _rules)
return crules:matching_rules(c, _rules)
function module.matchingrules(c, rules)
return crules:matching_rules(c, rules)
end
--- Check if a client matches a given set of rules.
-- @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.
-- @treturn bool True if at least one rule is matched, false otherwise.
-- @staticfct ruled.client.matches_list
function module.matches_list(c, _rules)
return crules:matches_rules(c, _rules)
function module.matches_list(c, rules)
return crules:matchesrules(c, rules)
end
--- Remove a source.

View File

@ -21,7 +21,7 @@ local surface = require("gears.surface")
local timer = require("gears.timer")
local grect = require("gears.geometry").rectangle
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 visible_drawables = {}
@ -92,7 +92,7 @@ local function do_redraw(self)
self._need_complete_repaint = true
if self._widget then
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)
else
self._widget_hierarchy = nil
@ -166,12 +166,12 @@ local function do_redraw(self)
assert(cr.status == "SUCCESS", "Cairo context entered error state: " .. cr.status)
end
local function find_widgets(_drawable, result, _hierarchy, x, y)
local m = _hierarchy:get_matrix_from_device()
local function find_widgets(self, result, hierarchy, x, y)
local m = hierarchy:get_matrix_from_device()
-- Is (x,y) inside of this hierarchy or any child (aka the draw extents)
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
return
end
@ -180,22 +180,22 @@ local function find_widgets(_drawable, result, _hierarchy, x, y)
end
-- 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
-- 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)
table.insert(result, {
x = x3, y = y3, width = w3, height = h3,
widget_width = width,
widget_height = height,
drawable = _drawable,
widget = _hierarchy:get_widget(),
hierarchy = _hierarchy
drawable = self,
widget = hierarchy:get_widget(),
hierarchy = hierarchy
})
end
for _, child in ipairs(_hierarchy:get_children()) do
find_widgets(_drawable, result, child, x, y)
for _, child in ipairs(hierarchy:get_children()) do
find_widgets(self, result, child, x, y)
end
end
@ -221,7 +221,7 @@ end
-- Private API. Not documented on purpose.
function drawable._set_systray_widget(widget)
hierarchy.count_widget(widget)
whierarchy.count_widget(widget)
systray_widget = widget
end
@ -331,34 +331,36 @@ local function emit_difference(name, list, skip)
end
end
local function handle_leave(_drawable)
emit_difference("mouse::leave", _drawable._widgets_under_mouse, {})
_drawable._widgets_under_mouse = {}
local function handle_leave(self)
emit_difference("mouse::leave", self._widgets_under_mouse, {})
self._widgets_under_mouse = {}
end
local function handle_motion(_drawable, x, y)
if x < 0 or y < 0 or x > _drawable.drawable:geometry().width or y > _drawable.drawable:geometry().height then
return handle_leave(_drawable)
local function handle_motion(self, x, y)
local dgeo = self.drawable:geometry()
if x < 0 or y < 0 or x > dgeo.width or y > dgeo.height then
return handle_leave(self)
end
-- 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
emit_difference("mouse::leave", _drawable._widgets_under_mouse, widgets_list)
emit_difference("mouse::leave", self._widgets_under_mouse, widgets_list)
-- 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
local function setup_signals(_drawable)
local d = _drawable.drawable
local function setup_signals(self)
local d = self.drawable
local function clone_signal(name)
-- When "name" is emitted on wibox.drawin, also emit it on wibox
d:connect_signal(name, function(_, ...)
_drawable:emit_signal(name, ...)
self:emit_signal(name, ...)
end)
end
clone_signal("button::press")

View File

@ -246,16 +246,16 @@ object.properties._legacy_accessors(wibox.object, "buttons", "_buttons", true, f
) or false
end, true)
local function setup_signals(_wibox)
local function setup_signals(w)
local obj
local function clone_signal(name)
-- When "name" is emitted on wibox.drawin, also emit it on wibox
obj:connect_signal(name, function(_, ...)
_wibox:emit_signal(name, ...)
w:emit_signal(name, ...)
end)
end
obj = _wibox.drawin
obj = w.drawin
clone_signal("property::border_color")
clone_signal("property::border_width")
clone_signal("property::buttons")
@ -273,7 +273,7 @@ local function setup_signals(_wibox)
clone_signal("property::shape_clip")
clone_signal("property::shape_input")
obj = _wibox._drawable
obj = w._drawable
clone_signal("button::press")
clone_signal("button::release")
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)
if not (new_value >= 0) then
return -- is negative or NaN
end
-- Because the graphs are at risk of dividing by zero, the value can
-- be `inf`, `-inf` and `-nan`. For example:
--
-- 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
-- Grow instantly and shrink slow