From 15e72fb0375a99fdac7f0ee21508bdee8e4ab173 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 7 Feb 2016 14:13:43 +0100 Subject: [PATCH] Fix luacheck warnings in lib/wibox Warnings pointing out actual problems are left. Signed-off-by: Uli Schlachter --- lib/wibox/drawable.lua | 48 ++++++++++++++++----------------- lib/wibox/hierarchy.lua | 18 ++++++------- lib/wibox/init.lua | 23 +++++----------- lib/wibox/layout/align.lua | 6 ++--- lib/wibox/layout/constraint.lua | 14 +++++----- lib/wibox/layout/fixed.lua | 5 +--- lib/wibox/layout/flex.lua | 10 +++---- lib/wibox/layout/margin.lua | 6 ++--- lib/wibox/layout/ratio.lua | 18 +++---------- lib/wibox/layout/rotate.lua | 2 +- lib/wibox/layout/scroll.lua | 30 +++++++++------------ lib/wibox/layout/stack.lua | 15 +++-------- lib/wibox/widget/background.lua | 8 +++--- lib/wibox/widget/base.lua | 34 +++++++++++------------ lib/wibox/widget/imagebox.lua | 9 +++---- lib/wibox/widget/systray.lua | 4 +-- lib/wibox/widget/textbox.lua | 10 +++---- 17 files changed, 105 insertions(+), 155 deletions(-) diff --git a/lib/wibox/drawable.lua b/lib/wibox/drawable.lua index b3b6e2dc..59bce59f 100644 --- a/lib/wibox/drawable.lua +++ b/lib/wibox/drawable.lua @@ -20,8 +20,7 @@ local surface = require("gears.surface") local timer = require("gears.timer") local matrix = require("gears.matrix") local hierarchy = require("wibox.hierarchy") -local base = require("wibox.widget.base") -local unpack = unpack or table.unpack +local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1) local drawables = setmetatable({}, { __mode = 'k' }) local wallpaper = nil @@ -154,32 +153,32 @@ 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(_drawable, 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, width, height = hierarchy:get_draw_extents() - if x1 < x2 or x1 >= x2 + width then + local x2, y2, w2, h2 = _hierarchy:get_draw_extents() + if x1 < x2 or x1 >= x2 + w2 then return end - if y1 < y2 or y1 >= y2 + height then + if y1 < y2 or y1 >= y2 + h2 then return 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 x2, y2, w2, h2 = 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 = x2, y = y2, width = w2, height = h2, - drawable = drawable, widget = hierarchy:get_widget() + x = x3, y = y3, width = w3, height = h3, + drawable = _drawable, widget = _hierarchy:get_widget() }) 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(_drawable, result, child, x, y) end end @@ -211,7 +210,7 @@ end -- @param c The background to use. This must either be a cairo pattern object, -- nil or a string that gears.color() understands. function drawable:set_bg(c) - local c = c or "#000000" + c = c or "#000000" local t = type(c) if t == "string" or t == "table" then @@ -255,7 +254,7 @@ end -- @param c The foreground to use. This must either be a cairo pattern object, -- nil or a string that gears.color() understands. function drawable:set_fg(c) - local c = c or "#FFFFFF" + c = c or "#FFFFFF" if type(c) == "string" or type(c) == "table" then c = color(c) end @@ -265,7 +264,7 @@ end local function emit_difference(name, list, skip) local function in_table(table, val) - for k, v in pairs(table) do + for _, v in pairs(table) do if v.widget == val.widget then return true end @@ -273,7 +272,7 @@ local function emit_difference(name, list, skip) return false end - for k, v in pairs(list) do + for _, v in pairs(list) do if not in_table(skip, v) then v.widget:emit_signal(name,v) end @@ -371,9 +370,9 @@ function drawable.new(d, widget_context_skeleton, drawable_name) ret._widgets_under_mouse = {} local function button_signal(name) - d:connect_signal(name, function(d, x, y, button, modifiers) + d:connect_signal(name, function(_, x, y, button, modifiers) local widgets = ret:find_widgets(x, y) - for k, v in pairs(widgets) do + for _, v in pairs(widgets) do -- Calculate x/y inside of the widget local lx = x - v.x local ly = y - v.y @@ -388,12 +387,12 @@ function drawable.new(d, widget_context_skeleton, drawable_name) d:connect_signal("mouse::leave", function() handle_leave(ret) end) -- Set up our callbacks for repaints - ret._redraw_callback = function(hierarchy, arg) + ret._redraw_callback = function(hierar, arg) if ret._widget_hierarchy_callback_arg ~= arg then return end - local m = hierarchy:get_matrix_to_device() - local x, y, width, height = matrix.transform_rectangle(m, hierarchy:get_draw_extents()) + local m = hierar:get_matrix_to_device() + local x, y, width, height = matrix.transform_rectangle(m, hierar:get_draw_extents()) local x1, y1 = math.floor(x), math.floor(y) local x2, y2 = math.ceil(x + width), math.ceil(y + height) ret._dirty_area:union_rectangle(cairo.RectangleInt{ @@ -401,7 +400,7 @@ function drawable.new(d, widget_context_skeleton, drawable_name) }) ret:draw() end - ret._layout_callback = function(hierarchy, arg) + ret._layout_callback = function(_, arg) if ret._widget_hierarchy_callback_arg ~= arg then return end @@ -413,7 +412,7 @@ function drawable.new(d, widget_context_skeleton, drawable_name) ret.drawable_name = drawable_name or object.modulename(3) local mt = {} local orig_string = tostring(ret) - mt.__tostring = function(o) + mt.__tostring = function() return string.format("%s (%s)", ret.drawable_name, orig_string) end ret = setmetatable(ret, mt) @@ -426,7 +425,6 @@ end -- Redraw all drawables when the wallpaper changes capi.awesome.connect_signal("wallpaper_changed", function() - local k wallpaper = nil for k in pairs(drawables) do k() diff --git a/lib/wibox/hierarchy.lua b/lib/wibox/hierarchy.lua index feaf9827..502d912f 100644 --- a/lib/wibox/hierarchy.lua +++ b/lib/wibox/hierarchy.lua @@ -16,7 +16,7 @@ local no_parent = base.no_parent_I_know_what_I_am_doing local hierarchy = {} -local function hierarchy_new(widget, redraw_callback, layout_callback, callback_arg) +local function hierarchy_new(redraw_callback, layout_callback, callback_arg) local result = { _matrix = matrix.identity, _matrix_to_device = matrix.identity, @@ -107,7 +107,7 @@ function hierarchy_update(self, context, widget, width, height, region, matrix_t for _, w in ipairs(layout_result or {}) do local r = table.remove(old_children, 1) if not r then - r = hierarchy_new(w._widget, self._redraw_callback, self._layout_callback, self._callback_arg) + r = hierarchy_new(self._redraw_callback, self._layout_callback, self._callback_arg) r._parent = self end hierarchy_update(r, context, w._widget, w._width, w._height, region, w._matrix, matrix_to_device * w._matrix) @@ -132,12 +132,12 @@ function hierarchy_update(self, context, widget, width, height, region, matrix_t -- Check which part needs to be redrawn -- Are there any children which were removed? Their area needs a redraw. - for _, h in ipairs(old_children) do - local x, y, width, height = matrix.transform_rectangle(h._matrix_to_device, h:get_draw_extents()) + for _, child in ipairs(old_children) do + local x, y, w, h = matrix.transform_rectangle(child._matrix_to_device, child:get_draw_extents()) region:union_rectangle(cairo.RectangleInt{ - x = x, y = y, width = width, height = height + x = x, y = y, width = w, height = h }) - h._parent = nil + child._parent = nil end -- Did we change and need to be redrawn? @@ -167,7 +167,7 @@ end -- @param callback_arg A second argument that is given to the above callbacks. -- @return A new widget hierarchy function hierarchy.new(context, widget, width, height, redraw_callback, layout_callback, callback_arg) - local result = hierarchy_new(widget, redraw_callback, layout_callback, callback_arg) + local result = hierarchy_new(redraw_callback, layout_callback, callback_arg) result:update(context, widget, width, height) return result end @@ -181,7 +181,7 @@ end -- @return A cairo region describing the changed parts (either the `region` -- argument or a new, internally created region). function hierarchy:update(context, widget, width, height, region) - local region = region or cairo.Region.create() + region = region or cairo.Region.create() hierarchy_update(self, context, widget, width, height, region, self._matrix, self._matrix_to_device) return region end @@ -247,7 +247,7 @@ end --- Does the given cairo context have an empty clip (aka "no drawing possible")? local function empty_clip(cr) - local x, y, width, height = cr:clip_extents() + local _, _, width, height = cr:clip_extents() return width == 0 or height == 0 end diff --git a/lib/wibox/init.lua b/lib/wibox/init.lua index f7bdfdc9..93f1cb2a 100644 --- a/lib/wibox/init.lua +++ b/lib/wibox/init.lua @@ -13,13 +13,8 @@ local capi = { local setmetatable = setmetatable local pairs = pairs local type = type -local table = table -local string_format = string.format -local color = require("gears.color") local object = require("gears.object") local beautiful = require("beautiful") -local surface = require("gears.surface") -local cairo = require("lgi").cairo local base = require("wibox.widget.base") --- This provides widget box windows. Every wibox can also be used as if it were @@ -82,15 +77,16 @@ for _, k in pairs{ "buttons", "struts", "geometry", "get_xproperty", "set_xprope end local function setup_signals(_wibox) - local w = _wibox.drawin - + local obj local function clone_signal(name) _wibox:add_signal(name) -- When "name" is emitted on wibox.drawin, also emit it on wibox - w:connect_signal(name, function(_, ...) + obj:connect_signal(name, function(_, ...) _wibox:emit_signal(name, ...) end) end + + obj = _wibox.drawin clone_signal("property::border_color") clone_signal("property::border_width") clone_signal("property::buttons") @@ -104,14 +100,7 @@ local function setup_signals(_wibox) clone_signal("property::x") clone_signal("property::y") - local d = _wibox._drawable - local function clone_signal(name) - _wibox:add_signal(name) - -- When "name" is emitted on wibox.drawin, also emit it on wibox - d:connect_signal(name, function(_, ...) - _wibox:emit_signal(name, ...) - end) - end + obj = _wibox._drawable clone_signal("button::press") clone_signal("button::release") clone_signal("mouse::enter") @@ -146,7 +135,7 @@ local function new(args) -- Add __tostring method to metatable. local mt = {} local orig_string = tostring(ret) - mt.__tostring = function(o) + mt.__tostring = function() return string.format("wibox: %s (%s)", tostring(ret._drawable), orig_string) end diff --git a/lib/wibox/layout/align.lua b/lib/wibox/layout/align.lua index 95337aa8..069f4674 100644 --- a/lib/wibox/layout/align.lua +++ b/lib/wibox/layout/align.lua @@ -5,7 +5,6 @@ -- @classmod wibox.layout.align --------------------------------------------------------------------------- -local setmetatable = setmetatable local table = table local pairs = pairs local type = type @@ -125,6 +124,7 @@ function align:layout(context, width, height) x, y = size_first, 0 end else + local _ if self.dir == "y" then _, h = base.fit_widget(self, context, self.second, width, size_second) y = floor( (height - h)/2 ) @@ -192,7 +192,7 @@ function align:fit(context, orig_width, orig_height) local used_in_dir = 0 local used_in_other = 0 - for k, v in pairs{self.first, self.second, self.third} do + for _, v in pairs{self.first, self.second, self.third} do local w, h = base.fit_widget(self, context, v, orig_width, orig_height) local max = self.dir == "y" and w or h @@ -233,7 +233,7 @@ function align:set_expand(mode) end function align:reset() - for k, v in pairs({ "first", "second", "third" }) do + for _, v in pairs({ "first", "second", "third" }) do self[v] = nil end self:emit_signal("widget::layout_changed") diff --git a/lib/wibox/layout/constraint.lua b/lib/wibox/layout/constraint.lua index 9fd4c1d2..99177c1b 100644 --- a/lib/wibox/layout/constraint.lua +++ b/lib/wibox/layout/constraint.lua @@ -14,7 +14,7 @@ local math = math local constraint = { mt = {} } --- Layout a constraint layout -function constraint:layout(context, width, height) +function constraint:layout(_, width, height) if self.widget then return { base.place_widget_at(self.widget, 0, 0, width, height) } end @@ -62,14 +62,14 @@ end -- 'min' or 'exact'. Throws an error on invalid values. function constraint:set_strategy(val) local func = { - min = function(real_size, constraint) - return constraint and math.max(constraint, real_size) or real_size + min = function(real_size, limit) + return limit and math.max(limit, real_size) or real_size end, - max = function(real_size, constraint) - return constraint and math.min(constraint, real_size) or real_size + max = function(real_size, limit) + return limit and math.min(limit, real_size) or real_size end, - exact = function(real_size, constraint) - return constraint or real_size + exact = function(real_size, limit) + return limit or real_size end } diff --git a/lib/wibox/layout/fixed.lua b/lib/wibox/layout/fixed.lua index 0611effd..f2de84b8 100644 --- a/lib/wibox/layout/fixed.lua +++ b/lib/wibox/layout/fixed.lua @@ -22,7 +22,6 @@ function fixed:layout(context, width, height) for k, v in pairs(self.widgets) do local x, y, w, h, _ - local in_dir if self.dir == "y" then x, y = 0, pos w, h = width, height - pos @@ -30,7 +29,6 @@ function fixed:layout(context, width, height) _, h = base.fit_widget(self, context, v, w, h); end pos = pos + h + spacing - in_dir = h else x, y = pos, 0 w, h = width - pos, height @@ -38,7 +36,6 @@ function fixed:layout(context, width, height) w, _ = base.fit_widget(self, context, v, w, h); end pos = pos + w + spacing - in_dir = w end if (self.dir == "y" and pos-spacing > height) or @@ -213,7 +210,7 @@ function fixed:fit(context, orig_width, orig_height) local width, height = orig_width, orig_height local used_in_dir, used_max = 0, 0 - for k, v in pairs(self.widgets) do + for _, v in pairs(self.widgets) do local w, h = base.fit_widget(self, context, v, width, height) local in_dir, max if self.dir == "y" then diff --git a/lib/wibox/layout/flex.lua b/lib/wibox/layout/flex.lua index 9c0a4b54..4417ff7d 100644 --- a/lib/wibox/layout/flex.lua +++ b/lib/wibox/layout/flex.lua @@ -107,11 +107,7 @@ local flex = {} -- @name insert -- @class function ---- Layout a flex layout. Each widget gets an equal share of the available space. --- @param context The context in which we are drawn. --- @param width The available width. --- @param height The available height. -function flex:layout(context, width, height) +function flex:layout(_, width, height) local result = {} local pos,spacing = 0, self._spacing local num = #self.widgets @@ -128,7 +124,7 @@ function flex:layout(context, width, height) space_per_item = math.min(space_per_item, self._max_widget_size) end - for k, v in pairs(self.widgets) do + for _, v in pairs(self.widgets) do local x, y, w, h if self.dir == "y" then x, y = 0, util.round(pos) @@ -163,7 +159,7 @@ function flex:fit(context, orig_width, orig_height) local sub_height = self.dir == "x" and orig_height or orig_height / #self.widgets local sub_width = self.dir == "y" and orig_width or orig_width / #self.widgets - for k, v in pairs(self.widgets) do + for _, v in pairs(self.widgets) do local w, h = base.fit_widget(self, context, v, sub_width, sub_height) local max = self.dir == "y" and w or h diff --git a/lib/wibox/layout/margin.lua b/lib/wibox/layout/margin.lua index e9b97e75..e7629a10 100644 --- a/lib/wibox/layout/margin.lua +++ b/lib/wibox/layout/margin.lua @@ -15,7 +15,7 @@ local cairo = require("lgi").cairo local margin = { mt = {} } --- Draw a margin layout -function margin:draw(context, cr, width, height) +function margin:draw(_, cr, width, height) local x = self.left local y = self.top local w = self.right @@ -36,7 +36,7 @@ function margin:draw(context, cr, width, height) end --- Layout a margin layout -function margin:layout(context, width, height) +function margin:layout(_, width, height) if self.widget then local x = self.left local y = self.top @@ -141,7 +141,7 @@ end -- @class function -- Create setters for each direction -for k, v in pairs({ "left", "right", "top", "bottom" }) do +for _, v in pairs({ "left", "right", "top", "bottom" }) do margin["set_" .. v] = function(layout, val) layout[v] = val layout:emit_signal("widget::layout_changed") diff --git a/lib/wibox/layout/ratio.lua b/lib/wibox/layout/ratio.lua index 201e1de6..baa9b2b4 100644 --- a/lib/wibox/layout/ratio.lua +++ b/lib/wibox/layout/ratio.lua @@ -10,7 +10,6 @@ local base = require("wibox.widget.base" ) local flex = require("wibox.layout.flex" ) -local fixed = require("wibox.layout.fixed") local table = table local pairs = pairs local floor = math.floor @@ -125,21 +124,12 @@ local function normalize(self) assert(new_sum > 0.99 and new_sum < 1.01) end ---- Layout a ratio layout. Each widget gets a share of the size proportional --- to its ratio --- @param context The context in which we are drawn. --- @tparam number width The available width. --- @tparam number height The available height. -function ratio:layout(context, width, height) +function ratio:layout(_, width, height) local result = {} local pos,spacing = 0, self._spacing - local num = #self.widgets - local total_spacing = (spacing*(num-1)) - - --normalize(self) for k, v in ipairs(self.widgets) do - local space = nil + local space local x, y, w, h if self.dir == "y" then @@ -179,8 +169,6 @@ function ratio:inc_ratio(index, increment) return end - local widget = self.widgets[index] - assert(self._ratios[index]) self:set_ratio(index, self._ratios[index] + increment) @@ -214,7 +202,7 @@ function ratio:set_ratio(index, percent) -- Remove what has to be cleared from all widget local delta = ( (percent-old) / (#self.widgets-1) ) - for k, v in pairs(self.widgets) do + for k in pairs(self.widgets) do self._ratios[k] = self._ratios[k] - delta end diff --git a/lib/wibox/layout/rotate.lua b/lib/wibox/layout/rotate.lua index 616d2564..8de9ef7b 100644 --- a/lib/wibox/layout/rotate.lua +++ b/lib/wibox/layout/rotate.lua @@ -25,7 +25,7 @@ local function transform(layout, width, height) end --- Layout this layout -function rotate:layout(context, width, height) +function rotate:layout(_, width, height) if not self.widget or not self.widget.visible then return end diff --git a/lib/wibox/layout/scroll.lua b/lib/wibox/layout/scroll.lua index d443a4a4..1af8f94e 100644 --- a/lib/wibox/layout/scroll.lua +++ b/lib/wibox/layout/scroll.lua @@ -6,14 +6,11 @@ --------------------------------------------------------------------------- local cache = require("gears.cache") -local color = require("gears.color") -local matrix = require("gears.matrix") local timer = require("gears.timer") local hierarchy = require("wibox.hierarchy") local base = require("wibox.widget.base") local lgi = require("lgi") local GLib = lgi.GLib -local cairo = lgi.cairo local scroll = {} local scroll_mt = { __index = scroll } @@ -34,8 +31,7 @@ end -- Create a hierarchy (and some more stuff) for drawing the given widget. This -- allows "some stuff" to be re-used instead of re-created all the time. local hierarchy_cache = cache.new(function(context, widget, width, height) - local context = cleanup_context(context) - local surface = cairo.ImageSurface(cairo.Format.ARGB32, width, height) + context = cleanup_context(context) local layouts = setmetatable({}, { __mode = "k" }) -- Create a widget hierarchy and update when needed @@ -50,10 +46,10 @@ local hierarchy_cache = cache.new(function(context, widget, width, height) w:emit_signal(signal) end end - local function redraw_callback(h, arg) + local function redraw_callback() emit("widget::redraw_needed") end - local function layout_callback(h, arg) + local function layout_callback() emit("widget::redraw_needed") emit("widget::layout_changed") end @@ -122,11 +118,11 @@ local function calculate_info(self, context, width, height) end result.first_x, result.first_y = x, y -- Was the extra space already included elsewhere? - local extra = self.expand and 0 or self.extra_space + local extra_spacer = self.expand and 0 or self.extra_space if self.dir == "h" then - x = x + surface_width + extra + x = x + surface_width + extra_spacer else - y = y + surface_height + extra + y = y + surface_height + extra_spacer end result.second_x, result.second_y = x, y else @@ -135,10 +131,10 @@ local function calculate_info(self, context, width, height) result.surface_width, result.surface_height = surface_width, surface_height -- Get the hierarchy and subscribe ourselves to updates - local hier, do_pending_updates, context = hierarchy_cache:get(context, + local hier, do_pending_updates, ctx = hierarchy_cache:get(context, self.widget, surface_width, surface_height) result.hierarchy = hier - result.context = context + result.context = ctx do_pending_updates(self) return result @@ -429,19 +425,19 @@ scroll.step_functions = {} --- A step function that scrolls the widget in an increasing direction with -- constant speed. -function scroll.step_functions.linear_increase(elapsed, size, visible_size, speed, extra_space) +function scroll.step_functions.linear_increase(elapsed, size, _, speed, extra_space) return (elapsed * speed) % (size + extra_space) end --- A step function that scrolls the widget in an decreasing direction with -- constant speed. -function scroll.step_functions.linear_decrease(elapsed, size, visible_size, speed, extra_space) +function scroll.step_functions.linear_decrease(elapsed, size, _, speed, extra_space) return (-elapsed * speed) % (size + extra_space) end --- A step function that scrolls the widget to its end and back to its -- beginning, then back to its end, etc. The speed is constant. -function scroll.step_functions.linear_back_and_forth(elapsed, size, visible_size, speed, extra_space) +function scroll.step_functions.linear_back_and_forth(elapsed, size, visible_size, speed) local state = ((elapsed * speed) % (2 * size)) / size state = state <= 1 and state or 2 - state return (size - visible_size) * state @@ -450,7 +446,7 @@ end --- A step function that scrolls the widget to its end and back to its -- beginning, then back to its end, etc. The speed is null at the ends and -- maximal in the middle. -function scroll.step_functions.nonlinear_back_and_forth(elapsed, size, visible_size, speed, extra_space) +function scroll.step_functions.nonlinear_back_and_forth(elapsed, size, visible_size, speed) local state = ((elapsed * speed) % (2 * size)) / size local negate = false if state > 1 then @@ -478,7 +474,7 @@ end --- A step function that scrolls the widget to its end and back to its -- beginning, then back to its end, etc. The speed is null at the ends and -- maximal in the middle. At both ends the widget stands still for a moment. -function scroll.step_functions.waiting_nonlinear_back_and_forth(elapsed, size, visible_size, speed, extra_space) +function scroll.step_functions.waiting_nonlinear_back_and_forth(elapsed, size, visible_size, speed) local state = ((elapsed * speed) % (2 * size)) / size local negate = false if state > 1 then diff --git a/lib/wibox/layout/stack.lua b/lib/wibox/layout/stack.lua index ec11febc..910270cb 100644 --- a/lib/wibox/layout/stack.lua +++ b/lib/wibox/layout/stack.lua @@ -18,7 +18,6 @@ local base = require("wibox.widget.base" ) local fixed = require("wibox.layout.fixed") local table = table local pairs = pairs -local floor = math.floor local util = require("awful.util") local stack = {mt={}} @@ -97,15 +96,11 @@ local stack = {mt={}} -- @name set_spacing -- @class function ---- Layout a stack layout. Each widget get drawn on top of each other --- @param context The context in which we are drawn. --- @param width The available width. --- @param height The available height. -function stack:layout(context, width, height) +function stack:layout(_, width, height) local result = {} local spacing = self._spacing - for k, v in pairs(self.widgets) do + for _, v in pairs(self.widgets) do table.insert(result, base.place_widget_at(v, spacing, spacing, width - 2*spacing, height - 2*spacing)) if self._top_only then break end end @@ -113,15 +108,11 @@ function stack:layout(context, width, height) return result end ---- Fit the stack layout into the given space --- @param context The context in which we are fit. --- @param orig_width The available width. --- @param orig_height The available height. function stack:fit(context, orig_width, orig_height) local max_w, max_h = 0,0 local spacing = self._spacing - for k, v in pairs(self.widgets) do + for _, v in pairs(self.widgets) do local w, h = base.fit_widget(self, context, v, orig_width, orig_height) max_w, max_h = math.max(max_w, w+2*spacing), math.max(max_h, h+2*spacing) end diff --git a/lib/wibox/widget/background.lua b/lib/wibox/widget/background.lua index 519059f2..274d8024 100644 --- a/lib/wibox/widget/background.lua +++ b/lib/wibox/widget/background.lua @@ -13,7 +13,7 @@ local cairo = require("lgi").cairo local setmetatable = setmetatable local pairs = pairs local type = type -local unpack = unpack or table.unpack +local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1) local background = { mt = {} } @@ -55,7 +55,7 @@ function background:draw(context, cr, width, height) end -- Draw the border -function background:after_draw_children(context, cr, width, height) +function background:after_draw_children(_, cr) -- Draw the border if self._path and self._shape_border_width and self._shape_border_width > 0 then cr:append_path(self._path) @@ -68,14 +68,14 @@ function background:after_draw_children(context, cr, width, height) end --- Prepare drawing the children of this widget -function background:before_draw_children(context, cr, width, height) +function background:before_draw_children(_, cr) if self.foreground then cr:set_source(self.foreground) end end --- Layout this widget -function background:layout(context, width, height) +function background:layout(_, width, height) if self.widget then return { base.place_widget_at(self.widget, 0, 0, width, height) } end diff --git a/lib/wibox/widget/base.lua b/lib/wibox/widget/base.lua index 00c25f8f..c528ad1d 100644 --- a/lib/wibox/widget/base.lua +++ b/lib/wibox/widget/base.lua @@ -85,13 +85,13 @@ end -- The default implementation does nothing, this must be re-implemented by -- all layout and container widgets. -- @tparam table children A table composed of valid widgets -function base.widget:set_children(children) +function base.widget:set_children(children) -- luacheck: no unused -- Nothing on purpose end -- It could have been merged into `get_all_children`, but it's not necessary local function digg_children(ret, tlw) - for k, w in ipairs(tlw:get_children()) do + for _, w in ipairs(tlw:get_children()) do table.insert(ret, w) digg_children(ret, w) end @@ -122,9 +122,9 @@ function base.widget:index(widget, recursive, ...) if w == widget then return idx, self, {...} elseif recursive then - local idx, l, path = w:index(widget, true, self, ...) - if idx and l then - return idx, l, path + local child_idx, l, path = w:index(widget, true, self, ...) + if child_idx and l then + return child_idx, l, path end end end @@ -206,8 +206,8 @@ function base.fit_widget(parent, context, widget, width, height) end -- Sanitize the input. This also filters out e.g. NaN. - local width = math.max(0, width) - local height = math.max(0, height) + width = math.max(0, width) + height = math.max(0, height) local w, h = 0, 0 if widget.fit then @@ -250,8 +250,8 @@ function base.layout_widget(parent, context, widget, width, height) end -- Sanitize the input. This also filters out e.g. NaN. - local width = math.max(0, width) - local height = math.max(0, height) + width = math.max(0, width) + height = math.max(0, height) if widget.layout then return get_cache(widget, "layout"):get(context, width, height) @@ -261,6 +261,7 @@ end -- Handle a button event on a widget. This is used internally and should not be -- called directly. function base.handle_button(event, widget, x, y, button, modifiers, geometry) + x = x or y -- luacheck: no unused local function is_any(mod) return #mod == 1 and mod[1] == "Any" end @@ -279,7 +280,7 @@ function base.handle_button(event, widget, x, y, button, modifiers, geometry) -- Find all matching button objects local matches = {} - for k, v in pairs(widget.widget_buttons) do + for _, v in pairs(widget.widget_buttons) do local match = true -- Is it the right button? if v.button ~= 0 and v.button ~= button then match = false end @@ -291,7 +292,7 @@ function base.handle_button(event, widget, x, y, button, modifiers, geometry) end -- Emit the signals - for k, v in pairs(matches) do + for _, v in pairs(matches) do v:emit_signal(event,geometry) end end @@ -332,7 +333,6 @@ end -- Read the table, separate attributes from widgets local function parse_table(t, leave_empty) - local keys= {} local max = 0 local attributes, widgets = {}, {} for k,v in pairs(t) do @@ -450,12 +450,12 @@ function base.make_widget_declarative(args) local w, id = drill(ids, args) local mt = {} - local orig_string = tostring(ret) + local orig_string = tostring(w) rawset(w, "_by_id", ids) rawset(w, "get_children_by_id", get_children_by_id) - mt.__tostring = function(o) + mt.__tostring = function() return string.format("%s (%s)", id, orig_string) end @@ -518,7 +518,7 @@ function base.make_widget(proxy, widget_name) ret.fit = function(_, context, width, height) return base.fit_widget(ret, context, proxy, width, height) end - ret.layout = function(_, context, width, height) + ret.layout = function(_, _, width, height) return { base.place_widget_at(proxy, 0, 0, width, height) } end proxy:connect_signal("widget::layout_changed", function() @@ -544,7 +544,7 @@ function base.make_widget(proxy, widget_name) ret.widget_name = widget_name or object.modulename(3) local mt = {} local orig_string = tostring(ret) - mt.__tostring = function(o) + mt.__tostring = function() return string.format("%s (%s)", ret.widget_name, orig_string) end return setmetatable(ret, mt) @@ -559,7 +559,7 @@ end -- widget is not a valid widget. function base.check_widget(widget) assert(type(widget) == "table") - for k, func in pairs({ "add_signal", "connect_signal", "disconnect_signal" }) do + for _, func in pairs({ "add_signal", "connect_signal", "disconnect_signal" }) do assert(type(widget[func]) == "function", func .. " is not a function") end end diff --git a/lib/wibox/widget/imagebox.lua b/lib/wibox/widget/imagebox.lua index d30fe5e8..b617724c 100644 --- a/lib/wibox/widget/imagebox.lua +++ b/lib/wibox/widget/imagebox.lua @@ -10,14 +10,13 @@ local surface = require("gears.surface") local setmetatable = setmetatable local pairs = pairs local type = type -local pcall = pcall local print = print -local unpack = unpack or table.unpack +local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1) local imagebox = { mt = {} } --- Draw an imagebox with the given cairo context in the given geometry. -function imagebox:draw(context, cr, width, height) +function imagebox:draw(_, cr, width, height) if not self._image then return end if width == 0 or height == 0 then return end @@ -42,7 +41,7 @@ function imagebox:draw(context, cr, width, height) end --- Fit the imagebox into the given geometry -function imagebox:fit(context, width, height) +function imagebox:fit(_, width, height) if not self._image then return 0, 0 end @@ -81,8 +80,6 @@ end -- interpreted as the path to a png image file. -- @return true on success, false if the image cannot be used function imagebox:set_image(image) - local image = image - if type(image) == "string" then image = surface.load(image) if not image then diff --git a/lib/wibox/widget/systray.lua b/lib/wibox/widget/systray.lua index e3ecdd04..262c274e 100644 --- a/lib/wibox/widget/systray.lua +++ b/lib/wibox/widget/systray.lua @@ -48,7 +48,7 @@ function systray:draw(context, cr, width, height) base, is_rotated, bg, reverse, spacing) end -function systray:fit(context, width, height) +function systray:fit(_, width, height) local num_entries = capi.awesome.systray() local base = base_size local spacing = beautiful.systray_icon_spacing or 0 @@ -76,7 +76,7 @@ local function new(revers) ret.draw = systray.draw ret.set_base_size = function(_, size) base_size = size end ret.set_horizontal = function(_, horiz) horizontal = horiz end - ret.set_reverse = function(revers) reverse = revers end + ret.set_reverse = function(arg) reverse = arg end if revers then ret:set_reverse(true) diff --git a/lib/wibox/widget/textbox.lua b/lib/wibox/widget/textbox.lua index 241ba391..1159359a 100644 --- a/lib/wibox/widget/textbox.lua +++ b/lib/wibox/widget/textbox.lua @@ -10,13 +10,11 @@ local base = require("wibox.widget.base") local gdebug = require("gears.debug") local beautiful = require("beautiful") local lgi = require("lgi") -local cairo = lgi.cairo local Pango = lgi.Pango local PangoCairo = lgi.PangoCairo local type = type local setmetatable = setmetatable local pairs = pairs -local error = error local textbox = { mt = {} } @@ -40,7 +38,7 @@ end function textbox:draw(context, cr, width, height) setup_layout(self, width, height, context.dpi) cr:update_layout(self._layout) - local ink, logical = self._layout:get_pixel_extents() + local _, logical = self._layout:get_pixel_extents() local offset = 0 if self._valign == "center" then offset = (height - logical.height) / 2 @@ -52,7 +50,7 @@ function textbox:draw(context, cr, width, height) end local function do_fit_return(self) - local ink, logical = self._layout:get_pixel_extents() + local _, logical = self._layout:get_pixel_extents() if logical.width == 0 or logical.height == 0 then return 0, 0 end @@ -110,7 +108,7 @@ function textbox:get_height_for_width_at_dpi(width, dpi) setup_dpi(self, dpi) self._layout.width = Pango.units_from_double(width) self._layout.height = -max_lines -- show this many lines per paragraph - local w, h = do_fit_return(self) + local _, h = do_fit_return(self) return h end @@ -261,7 +259,7 @@ local function new(text, ignore_markup) return ret end -function textbox.mt:__call(...) +function textbox.mt.__call(_, ...) return new(...) end