Fix luacheck warnings in lib/wibox

Warnings pointing out actual problems are left.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-02-07 14:13:43 +01:00
parent bf3b9b5f42
commit 15e72fb037
17 changed files with 105 additions and 155 deletions

View File

@ -20,8 +20,7 @@ local surface = require("gears.surface")
local timer = require("gears.timer") local timer = require("gears.timer")
local matrix = require("gears.matrix") local matrix = require("gears.matrix")
local hierarchy = require("wibox.hierarchy") local hierarchy = require("wibox.hierarchy")
local base = require("wibox.widget.base") local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
local unpack = unpack or table.unpack
local drawables = setmetatable({}, { __mode = 'k' }) local drawables = setmetatable({}, { __mode = 'k' })
local wallpaper = nil local wallpaper = nil
@ -154,32 +153,32 @@ 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(_drawable, 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, width, height = hierarchy:get_draw_extents() local x2, y2, w2, h2 = _hierarchy:get_draw_extents()
if x1 < x2 or x1 >= x2 + width then if x1 < x2 or x1 >= x2 + w2 then
return return
end end
if y1 < y2 or y1 >= y2 + height then if y1 < y2 or y1 >= y2 + h2 then
return return
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 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) 0, 0, width, height)
table.insert(result, { table.insert(result, {
x = x2, y = y2, width = w2, height = h2, x = x3, y = y3, width = w3, height = h3,
drawable = drawable, widget = hierarchy:get_widget() drawable = _drawable, widget = _hierarchy:get_widget()
}) })
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(_drawable, result, child, x, y)
end end
end end
@ -211,7 +210,7 @@ end
-- @param c The background to use. This must either be a cairo pattern object, -- @param c The background to use. This must either be a cairo pattern object,
-- nil or a string that gears.color() understands. -- nil or a string that gears.color() understands.
function drawable:set_bg(c) function drawable:set_bg(c)
local c = c or "#000000" c = c or "#000000"
local t = type(c) local t = type(c)
if t == "string" or t == "table" then 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, -- @param c The foreground to use. This must either be a cairo pattern object,
-- nil or a string that gears.color() understands. -- nil or a string that gears.color() understands.
function drawable:set_fg(c) function drawable:set_fg(c)
local c = c or "#FFFFFF" c = c or "#FFFFFF"
if type(c) == "string" or type(c) == "table" then if type(c) == "string" or type(c) == "table" then
c = color(c) c = color(c)
end end
@ -265,7 +264,7 @@ end
local function emit_difference(name, list, skip) local function emit_difference(name, list, skip)
local function in_table(table, val) 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 if v.widget == val.widget then
return true return true
end end
@ -273,7 +272,7 @@ local function emit_difference(name, list, skip)
return false return false
end end
for k, v in pairs(list) do for _, v in pairs(list) do
if not in_table(skip, v) then if not in_table(skip, v) then
v.widget:emit_signal(name,v) v.widget:emit_signal(name,v)
end end
@ -371,9 +370,9 @@ function drawable.new(d, widget_context_skeleton, drawable_name)
ret._widgets_under_mouse = {} ret._widgets_under_mouse = {}
local function button_signal(name) 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) 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 -- Calculate x/y inside of the widget
local lx = x - v.x local lx = x - v.x
local ly = y - v.y 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) d:connect_signal("mouse::leave", function() handle_leave(ret) end)
-- Set up our callbacks for repaints -- 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 if ret._widget_hierarchy_callback_arg ~= arg then
return return
end end
local m = hierarchy:get_matrix_to_device() local m = hierar:get_matrix_to_device()
local x, y, width, height = matrix.transform_rectangle(m, hierarchy:get_draw_extents()) local x, y, width, height = matrix.transform_rectangle(m, hierar:get_draw_extents())
local x1, y1 = math.floor(x), math.floor(y) local x1, y1 = math.floor(x), math.floor(y)
local x2, y2 = math.ceil(x + width), math.ceil(y + height) local x2, y2 = math.ceil(x + width), math.ceil(y + height)
ret._dirty_area:union_rectangle(cairo.RectangleInt{ ret._dirty_area:union_rectangle(cairo.RectangleInt{
@ -401,7 +400,7 @@ function drawable.new(d, widget_context_skeleton, drawable_name)
}) })
ret:draw() ret:draw()
end end
ret._layout_callback = function(hierarchy, arg) ret._layout_callback = function(_, arg)
if ret._widget_hierarchy_callback_arg ~= arg then if ret._widget_hierarchy_callback_arg ~= arg then
return return
end end
@ -413,7 +412,7 @@ function drawable.new(d, widget_context_skeleton, drawable_name)
ret.drawable_name = drawable_name or object.modulename(3) ret.drawable_name = drawable_name or object.modulename(3)
local mt = {} local mt = {}
local orig_string = tostring(ret) local orig_string = tostring(ret)
mt.__tostring = function(o) mt.__tostring = function()
return string.format("%s (%s)", ret.drawable_name, orig_string) return string.format("%s (%s)", ret.drawable_name, orig_string)
end end
ret = setmetatable(ret, mt) ret = setmetatable(ret, mt)
@ -426,7 +425,6 @@ end
-- Redraw all drawables when the wallpaper changes -- Redraw all drawables when the wallpaper changes
capi.awesome.connect_signal("wallpaper_changed", function() capi.awesome.connect_signal("wallpaper_changed", function()
local k
wallpaper = nil wallpaper = nil
for k in pairs(drawables) do for k in pairs(drawables) do
k() k()

View File

@ -16,7 +16,7 @@ local no_parent = base.no_parent_I_know_what_I_am_doing
local hierarchy = {} 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 = { local result = {
_matrix = matrix.identity, _matrix = matrix.identity,
_matrix_to_device = 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 for _, w in ipairs(layout_result or {}) do
local r = table.remove(old_children, 1) local r = table.remove(old_children, 1)
if not r then 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 r._parent = self
end end
hierarchy_update(r, context, w._widget, w._width, w._height, region, w._matrix, matrix_to_device * w._matrix) 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 -- Check which part needs to be redrawn
-- Are there any children which were removed? Their area needs a redraw. -- Are there any children which were removed? Their area needs a redraw.
for _, h in ipairs(old_children) do for _, child in ipairs(old_children) do
local x, y, width, height = matrix.transform_rectangle(h._matrix_to_device, h:get_draw_extents()) local x, y, w, h = matrix.transform_rectangle(child._matrix_to_device, child:get_draw_extents())
region:union_rectangle(cairo.RectangleInt{ 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 end
-- Did we change and need to be redrawn? -- 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. -- @param callback_arg A second argument that is given to the above callbacks.
-- @return A new widget hierarchy -- @return A new widget hierarchy
function hierarchy.new(context, widget, width, height, redraw_callback, layout_callback, callback_arg) 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) result:update(context, widget, width, height)
return result return result
end end
@ -181,7 +181,7 @@ end
-- @return A cairo region describing the changed parts (either the `region` -- @return A cairo region describing the changed parts (either the `region`
-- argument or a new, internally created region). -- argument or a new, internally created region).
function hierarchy:update(context, widget, width, height, 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) hierarchy_update(self, context, widget, width, height, region, self._matrix, self._matrix_to_device)
return region return region
end end
@ -247,7 +247,7 @@ end
--- Does the given cairo context have an empty clip (aka "no drawing possible")? --- Does the given cairo context have an empty clip (aka "no drawing possible")?
local function empty_clip(cr) 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 return width == 0 or height == 0
end end

View File

@ -13,13 +13,8 @@ local capi = {
local setmetatable = setmetatable local setmetatable = setmetatable
local pairs = pairs local pairs = pairs
local type = type local type = type
local table = table
local string_format = string.format
local color = require("gears.color")
local object = require("gears.object") local object = require("gears.object")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local surface = require("gears.surface")
local cairo = require("lgi").cairo
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
--- This provides widget box windows. Every wibox can also be used as if it were --- 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 end
local function setup_signals(_wibox) local function setup_signals(_wibox)
local w = _wibox.drawin local obj
local function clone_signal(name) local function clone_signal(name)
_wibox:add_signal(name) _wibox:add_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
w:connect_signal(name, function(_, ...) obj:connect_signal(name, function(_, ...)
_wibox:emit_signal(name, ...) _wibox:emit_signal(name, ...)
end) end)
end end
obj = _wibox.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")
@ -104,14 +100,7 @@ local function setup_signals(_wibox)
clone_signal("property::x") clone_signal("property::x")
clone_signal("property::y") clone_signal("property::y")
local d = _wibox._drawable obj = _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
clone_signal("button::press") clone_signal("button::press")
clone_signal("button::release") clone_signal("button::release")
clone_signal("mouse::enter") clone_signal("mouse::enter")
@ -146,7 +135,7 @@ local function new(args)
-- Add __tostring method to metatable. -- Add __tostring method to metatable.
local mt = {} local mt = {}
local orig_string = tostring(ret) local orig_string = tostring(ret)
mt.__tostring = function(o) mt.__tostring = function()
return string.format("wibox: %s (%s)", return string.format("wibox: %s (%s)",
tostring(ret._drawable), orig_string) tostring(ret._drawable), orig_string)
end end

View File

@ -5,7 +5,6 @@
-- @classmod wibox.layout.align -- @classmod wibox.layout.align
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
local setmetatable = setmetatable
local table = table local table = table
local pairs = pairs local pairs = pairs
local type = type local type = type
@ -125,6 +124,7 @@ function align:layout(context, width, height)
x, y = size_first, 0 x, y = size_first, 0
end end
else else
local _
if self.dir == "y" then if self.dir == "y" then
_, h = base.fit_widget(self, context, self.second, width, size_second) _, h = base.fit_widget(self, context, self.second, width, size_second)
y = floor( (height - h)/2 ) 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_dir = 0
local used_in_other = 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 w, h = base.fit_widget(self, context, v, orig_width, orig_height)
local max = self.dir == "y" and w or h local max = self.dir == "y" and w or h
@ -233,7 +233,7 @@ function align:set_expand(mode)
end end
function align:reset() function align:reset()
for k, v in pairs({ "first", "second", "third" }) do for _, v in pairs({ "first", "second", "third" }) do
self[v] = nil self[v] = nil
end end
self:emit_signal("widget::layout_changed") self:emit_signal("widget::layout_changed")

View File

@ -14,7 +14,7 @@ local math = math
local constraint = { mt = {} } local constraint = { mt = {} }
--- Layout a constraint layout --- Layout a constraint layout
function constraint:layout(context, width, height) function constraint:layout(_, width, height)
if self.widget then if self.widget then
return { base.place_widget_at(self.widget, 0, 0, width, height) } return { base.place_widget_at(self.widget, 0, 0, width, height) }
end end
@ -62,14 +62,14 @@ end
-- 'min' or 'exact'. Throws an error on invalid values. -- 'min' or 'exact'. Throws an error on invalid values.
function constraint:set_strategy(val) function constraint:set_strategy(val)
local func = { local func = {
min = function(real_size, constraint) min = function(real_size, limit)
return constraint and math.max(constraint, real_size) or real_size return limit and math.max(limit, real_size) or real_size
end, end,
max = function(real_size, constraint) max = function(real_size, limit)
return constraint and math.min(constraint, real_size) or real_size return limit and math.min(limit, real_size) or real_size
end, end,
exact = function(real_size, constraint) exact = function(real_size, limit)
return constraint or real_size return limit or real_size
end end
} }

View File

@ -22,7 +22,6 @@ function fixed:layout(context, width, height)
for k, v in pairs(self.widgets) do for k, v in pairs(self.widgets) do
local x, y, w, h, _ local x, y, w, h, _
local in_dir
if self.dir == "y" then if self.dir == "y" then
x, y = 0, pos x, y = 0, pos
w, h = width, height - 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); _, h = base.fit_widget(self, context, v, w, h);
end end
pos = pos + h + spacing pos = pos + h + spacing
in_dir = h
else else
x, y = pos, 0 x, y = pos, 0
w, h = width - pos, height w, h = width - pos, height
@ -38,7 +36,6 @@ function fixed:layout(context, width, height)
w, _ = base.fit_widget(self, context, v, w, h); w, _ = base.fit_widget(self, context, v, w, h);
end end
pos = pos + w + spacing pos = pos + w + spacing
in_dir = w
end end
if (self.dir == "y" and pos-spacing > height) or 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 width, height = orig_width, orig_height
local used_in_dir, used_max = 0, 0 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 w, h = base.fit_widget(self, context, v, width, height)
local in_dir, max local in_dir, max
if self.dir == "y" then if self.dir == "y" then

View File

@ -107,11 +107,7 @@ local flex = {}
-- @name insert -- @name insert
-- @class function -- @class function
--- Layout a flex layout. Each widget gets an equal share of the available space. function flex:layout(_, width, height)
-- @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)
local result = {} local result = {}
local pos,spacing = 0, self._spacing local pos,spacing = 0, self._spacing
local num = #self.widgets 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) space_per_item = math.min(space_per_item, self._max_widget_size)
end end
for k, v in pairs(self.widgets) do for _, v in pairs(self.widgets) do
local x, y, w, h local x, y, w, h
if self.dir == "y" then if self.dir == "y" then
x, y = 0, util.round(pos) 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_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 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 w, h = base.fit_widget(self, context, v, sub_width, sub_height)
local max = self.dir == "y" and w or h local max = self.dir == "y" and w or h

View File

@ -15,7 +15,7 @@ local cairo = require("lgi").cairo
local margin = { mt = {} } local margin = { mt = {} }
--- Draw a margin layout --- Draw a margin layout
function margin:draw(context, cr, width, height) function margin:draw(_, cr, width, height)
local x = self.left local x = self.left
local y = self.top local y = self.top
local w = self.right local w = self.right
@ -36,7 +36,7 @@ function margin:draw(context, cr, width, height)
end end
--- Layout a margin layout --- Layout a margin layout
function margin:layout(context, width, height) function margin:layout(_, width, height)
if self.widget then if self.widget then
local x = self.left local x = self.left
local y = self.top local y = self.top
@ -141,7 +141,7 @@ end
-- @class function -- @class function
-- Create setters for each direction -- 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) margin["set_" .. v] = function(layout, val)
layout[v] = val layout[v] = val
layout:emit_signal("widget::layout_changed") layout:emit_signal("widget::layout_changed")

View File

@ -10,7 +10,6 @@
local base = require("wibox.widget.base" ) local base = require("wibox.widget.base" )
local flex = require("wibox.layout.flex" ) local flex = require("wibox.layout.flex" )
local fixed = require("wibox.layout.fixed")
local table = table local table = table
local pairs = pairs local pairs = pairs
local floor = math.floor local floor = math.floor
@ -125,21 +124,12 @@ local function normalize(self)
assert(new_sum > 0.99 and new_sum < 1.01) assert(new_sum > 0.99 and new_sum < 1.01)
end end
--- Layout a ratio layout. Each widget gets a share of the size proportional function ratio:layout(_, width, height)
-- 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)
local result = {} local result = {}
local pos,spacing = 0, self._spacing 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 for k, v in ipairs(self.widgets) do
local space = nil local space
local x, y, w, h local x, y, w, h
if self.dir == "y" then if self.dir == "y" then
@ -179,8 +169,6 @@ function ratio:inc_ratio(index, increment)
return return
end end
local widget = self.widgets[index]
assert(self._ratios[index]) assert(self._ratios[index])
self:set_ratio(index, self._ratios[index] + increment) 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 -- Remove what has to be cleared from all widget
local delta = ( (percent-old) / (#self.widgets-1) ) 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 self._ratios[k] = self._ratios[k] - delta
end end

View File

@ -25,7 +25,7 @@ local function transform(layout, width, height)
end end
--- Layout this layout --- Layout this layout
function rotate:layout(context, width, height) function rotate:layout(_, width, height)
if not self.widget or not self.widget.visible then if not self.widget or not self.widget.visible then
return return
end end

View File

@ -6,14 +6,11 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
local cache = require("gears.cache") local cache = require("gears.cache")
local color = require("gears.color")
local matrix = require("gears.matrix")
local timer = require("gears.timer") local timer = require("gears.timer")
local hierarchy = require("wibox.hierarchy") local hierarchy = require("wibox.hierarchy")
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
local lgi = require("lgi") local lgi = require("lgi")
local GLib = lgi.GLib local GLib = lgi.GLib
local cairo = lgi.cairo
local scroll = {} local scroll = {}
local scroll_mt = { __index = scroll } local scroll_mt = { __index = scroll }
@ -34,8 +31,7 @@ end
-- Create a hierarchy (and some more stuff) for drawing the given widget. This -- 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. -- 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 hierarchy_cache = cache.new(function(context, widget, width, height)
local context = cleanup_context(context) context = cleanup_context(context)
local surface = cairo.ImageSurface(cairo.Format.ARGB32, width, height)
local layouts = setmetatable({}, { __mode = "k" }) local layouts = setmetatable({}, { __mode = "k" })
-- Create a widget hierarchy and update when needed -- 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) w:emit_signal(signal)
end end
end end
local function redraw_callback(h, arg) local function redraw_callback()
emit("widget::redraw_needed") emit("widget::redraw_needed")
end end
local function layout_callback(h, arg) local function layout_callback()
emit("widget::redraw_needed") emit("widget::redraw_needed")
emit("widget::layout_changed") emit("widget::layout_changed")
end end
@ -122,11 +118,11 @@ local function calculate_info(self, context, width, height)
end end
result.first_x, result.first_y = x, y result.first_x, result.first_y = x, y
-- Was the extra space already included elsewhere? -- 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 if self.dir == "h" then
x = x + surface_width + extra x = x + surface_width + extra_spacer
else else
y = y + surface_height + extra y = y + surface_height + extra_spacer
end end
result.second_x, result.second_y = x, y result.second_x, result.second_y = x, y
else else
@ -135,10 +131,10 @@ local function calculate_info(self, context, width, height)
result.surface_width, result.surface_height = surface_width, surface_height result.surface_width, result.surface_height = surface_width, surface_height
-- Get the hierarchy and subscribe ourselves to updates -- 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) self.widget, surface_width, surface_height)
result.hierarchy = hier result.hierarchy = hier
result.context = context result.context = ctx
do_pending_updates(self) do_pending_updates(self)
return result return result
@ -429,19 +425,19 @@ scroll.step_functions = {}
--- A step function that scrolls the widget in an increasing direction with --- A step function that scrolls the widget in an increasing direction with
-- constant speed. -- 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) return (elapsed * speed) % (size + extra_space)
end end
--- A step function that scrolls the widget in an decreasing direction with --- A step function that scrolls the widget in an decreasing direction with
-- constant speed. -- 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) return (-elapsed * speed) % (size + extra_space)
end end
--- A step function that scrolls the widget to its end and back to its --- 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. -- 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 local state = ((elapsed * speed) % (2 * size)) / size
state = state <= 1 and state or 2 - state state = state <= 1 and state or 2 - state
return (size - visible_size) * 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 --- 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 -- beginning, then back to its end, etc. The speed is null at the ends and
-- maximal in the middle. -- 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 state = ((elapsed * speed) % (2 * size)) / size
local negate = false local negate = false
if state > 1 then if state > 1 then
@ -478,7 +474,7 @@ end
--- A step function that scrolls the widget to its end and back to its --- 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 -- 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. -- 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 state = ((elapsed * speed) % (2 * size)) / size
local negate = false local negate = false
if state > 1 then if state > 1 then

View File

@ -18,7 +18,6 @@ local base = require("wibox.widget.base" )
local fixed = require("wibox.layout.fixed") local fixed = require("wibox.layout.fixed")
local table = table local table = table
local pairs = pairs local pairs = pairs
local floor = math.floor
local util = require("awful.util") local util = require("awful.util")
local stack = {mt={}} local stack = {mt={}}
@ -97,15 +96,11 @@ local stack = {mt={}}
-- @name set_spacing -- @name set_spacing
-- @class function -- @class function
--- Layout a stack layout. Each widget get drawn on top of each other function stack:layout(_, width, height)
-- @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)
local result = {} local result = {}
local spacing = self._spacing 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)) table.insert(result, base.place_widget_at(v, spacing, spacing, width - 2*spacing, height - 2*spacing))
if self._top_only then break end if self._top_only then break end
end end
@ -113,15 +108,11 @@ function stack:layout(context, width, height)
return result return result
end 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) function stack:fit(context, orig_width, orig_height)
local max_w, max_h = 0,0 local max_w, max_h = 0,0
local spacing = self._spacing 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) 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) max_w, max_h = math.max(max_w, w+2*spacing), math.max(max_h, h+2*spacing)
end end

View File

@ -13,7 +13,7 @@ local cairo = require("lgi").cairo
local setmetatable = setmetatable local setmetatable = setmetatable
local pairs = pairs local pairs = pairs
local type = type 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 = {} } local background = { mt = {} }
@ -55,7 +55,7 @@ function background:draw(context, cr, width, height)
end end
-- Draw the border -- Draw the border
function background:after_draw_children(context, cr, width, height) function background:after_draw_children(_, cr)
-- Draw the border -- Draw the border
if self._path and self._shape_border_width and self._shape_border_width > 0 then if self._path and self._shape_border_width and self._shape_border_width > 0 then
cr:append_path(self._path) cr:append_path(self._path)
@ -68,14 +68,14 @@ function background:after_draw_children(context, cr, width, height)
end end
--- Prepare drawing the children of this widget --- 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 if self.foreground then
cr:set_source(self.foreground) cr:set_source(self.foreground)
end end
end end
--- Layout this widget --- Layout this widget
function background:layout(context, width, height) function background:layout(_, width, height)
if self.widget then if self.widget then
return { base.place_widget_at(self.widget, 0, 0, width, height) } return { base.place_widget_at(self.widget, 0, 0, width, height) }
end end

View File

@ -85,13 +85,13 @@ end
-- The default implementation does nothing, this must be re-implemented by -- The default implementation does nothing, this must be re-implemented by
-- all layout and container widgets. -- all layout and container widgets.
-- @tparam table children A table composed of valid 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 -- Nothing on purpose
end end
-- It could have been merged into `get_all_children`, but it's not necessary -- It could have been merged into `get_all_children`, but it's not necessary
local function digg_children(ret, tlw) 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) table.insert(ret, w)
digg_children(ret, w) digg_children(ret, w)
end end
@ -122,9 +122,9 @@ function base.widget:index(widget, recursive, ...)
if w == widget then if w == widget then
return idx, self, {...} return idx, self, {...}
elseif recursive then elseif recursive then
local idx, l, path = w:index(widget, true, self, ...) local child_idx, l, path = w:index(widget, true, self, ...)
if idx and l then if child_idx and l then
return idx, l, path return child_idx, l, path
end end
end end
end end
@ -206,8 +206,8 @@ function base.fit_widget(parent, context, widget, width, height)
end end
-- Sanitize the input. This also filters out e.g. NaN. -- Sanitize the input. This also filters out e.g. NaN.
local width = math.max(0, width) width = math.max(0, width)
local height = math.max(0, height) height = math.max(0, height)
local w, h = 0, 0 local w, h = 0, 0
if widget.fit then if widget.fit then
@ -250,8 +250,8 @@ function base.layout_widget(parent, context, widget, width, height)
end end
-- Sanitize the input. This also filters out e.g. NaN. -- Sanitize the input. This also filters out e.g. NaN.
local width = math.max(0, width) width = math.max(0, width)
local height = math.max(0, height) height = math.max(0, height)
if widget.layout then if widget.layout then
return get_cache(widget, "layout"):get(context, width, height) 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 -- Handle a button event on a widget. This is used internally and should not be
-- called directly. -- called directly.
function base.handle_button(event, widget, x, y, button, modifiers, geometry) function base.handle_button(event, widget, x, y, button, modifiers, geometry)
x = x or y -- luacheck: no unused
local function is_any(mod) local function is_any(mod)
return #mod == 1 and mod[1] == "Any" return #mod == 1 and mod[1] == "Any"
end end
@ -279,7 +280,7 @@ function base.handle_button(event, widget, x, y, button, modifiers, geometry)
-- Find all matching button objects -- Find all matching button objects
local matches = {} local matches = {}
for k, v in pairs(widget.widget_buttons) do for _, v in pairs(widget.widget_buttons) do
local match = true local match = true
-- Is it the right button? -- Is it the right button?
if v.button ~= 0 and v.button ~= button then match = false end 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 end
-- Emit the signals -- Emit the signals
for k, v in pairs(matches) do for _, v in pairs(matches) do
v:emit_signal(event,geometry) v:emit_signal(event,geometry)
end end
end end
@ -332,7 +333,6 @@ end
-- Read the table, separate attributes from widgets -- Read the table, separate attributes from widgets
local function parse_table(t, leave_empty) local function parse_table(t, leave_empty)
local keys= {}
local max = 0 local max = 0
local attributes, widgets = {}, {} local attributes, widgets = {}, {}
for k,v in pairs(t) do for k,v in pairs(t) do
@ -450,12 +450,12 @@ function base.make_widget_declarative(args)
local w, id = drill(ids, args) local w, id = drill(ids, args)
local mt = {} local mt = {}
local orig_string = tostring(ret) local orig_string = tostring(w)
rawset(w, "_by_id", ids) rawset(w, "_by_id", ids)
rawset(w, "get_children_by_id", get_children_by_id) 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) return string.format("%s (%s)", id, orig_string)
end end
@ -518,7 +518,7 @@ function base.make_widget(proxy, widget_name)
ret.fit = function(_, context, width, height) ret.fit = function(_, context, width, height)
return base.fit_widget(ret, context, proxy, width, height) return base.fit_widget(ret, context, proxy, width, height)
end end
ret.layout = function(_, context, width, height) ret.layout = function(_, _, width, height)
return { base.place_widget_at(proxy, 0, 0, width, height) } return { base.place_widget_at(proxy, 0, 0, width, height) }
end end
proxy:connect_signal("widget::layout_changed", function() 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) ret.widget_name = widget_name or object.modulename(3)
local mt = {} local mt = {}
local orig_string = tostring(ret) local orig_string = tostring(ret)
mt.__tostring = function(o) mt.__tostring = function()
return string.format("%s (%s)", ret.widget_name, orig_string) return string.format("%s (%s)", ret.widget_name, orig_string)
end end
return setmetatable(ret, mt) return setmetatable(ret, mt)
@ -559,7 +559,7 @@ end
-- widget is not a valid widget. -- widget is not a valid widget.
function base.check_widget(widget) function base.check_widget(widget)
assert(type(widget) == "table") 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") assert(type(widget[func]) == "function", func .. " is not a function")
end end
end end

View File

@ -10,14 +10,13 @@ local surface = require("gears.surface")
local setmetatable = setmetatable local setmetatable = setmetatable
local pairs = pairs local pairs = pairs
local type = type local type = type
local pcall = pcall
local print = print 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 = {} } local imagebox = { mt = {} }
--- Draw an imagebox with the given cairo context in the given geometry. --- 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 not self._image then return end
if width == 0 or height == 0 then return end if width == 0 or height == 0 then return end
@ -42,7 +41,7 @@ function imagebox:draw(context, cr, width, height)
end end
--- Fit the imagebox into the given geometry --- Fit the imagebox into the given geometry
function imagebox:fit(context, width, height) function imagebox:fit(_, width, height)
if not self._image then if not self._image then
return 0, 0 return 0, 0
end end
@ -81,8 +80,6 @@ end
-- interpreted as the path to a png image file. -- interpreted as the path to a png image file.
-- @return true on success, false if the image cannot be used -- @return true on success, false if the image cannot be used
function imagebox:set_image(image) function imagebox:set_image(image)
local image = image
if type(image) == "string" then if type(image) == "string" then
image = surface.load(image) image = surface.load(image)
if not image then if not image then

View File

@ -48,7 +48,7 @@ function systray:draw(context, cr, width, height)
base, is_rotated, bg, reverse, spacing) base, is_rotated, bg, reverse, spacing)
end end
function systray:fit(context, width, height) function systray:fit(_, width, height)
local num_entries = capi.awesome.systray() local num_entries = capi.awesome.systray()
local base = base_size local base = base_size
local spacing = beautiful.systray_icon_spacing or 0 local spacing = beautiful.systray_icon_spacing or 0
@ -76,7 +76,7 @@ local function new(revers)
ret.draw = systray.draw ret.draw = systray.draw
ret.set_base_size = function(_, size) base_size = size end ret.set_base_size = function(_, size) base_size = size end
ret.set_horizontal = function(_, horiz) horizontal = horiz 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 if revers then
ret:set_reverse(true) ret:set_reverse(true)

View File

@ -10,13 +10,11 @@ local base = require("wibox.widget.base")
local gdebug = require("gears.debug") local gdebug = require("gears.debug")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local lgi = require("lgi") local lgi = require("lgi")
local cairo = lgi.cairo
local Pango = lgi.Pango local Pango = lgi.Pango
local PangoCairo = lgi.PangoCairo local PangoCairo = lgi.PangoCairo
local type = type local type = type
local setmetatable = setmetatable local setmetatable = setmetatable
local pairs = pairs local pairs = pairs
local error = error
local textbox = { mt = {} } local textbox = { mt = {} }
@ -40,7 +38,7 @@ end
function textbox:draw(context, cr, width, height) function textbox:draw(context, cr, width, height)
setup_layout(self, width, height, context.dpi) setup_layout(self, width, height, context.dpi)
cr:update_layout(self._layout) cr:update_layout(self._layout)
local ink, logical = self._layout:get_pixel_extents() local _, logical = self._layout:get_pixel_extents()
local offset = 0 local offset = 0
if self._valign == "center" then if self._valign == "center" then
offset = (height - logical.height) / 2 offset = (height - logical.height) / 2
@ -52,7 +50,7 @@ function textbox:draw(context, cr, width, height)
end end
local function do_fit_return(self) 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 if logical.width == 0 or logical.height == 0 then
return 0, 0 return 0, 0
end end
@ -110,7 +108,7 @@ function textbox:get_height_for_width_at_dpi(width, dpi)
setup_dpi(self, dpi) setup_dpi(self, dpi)
self._layout.width = Pango.units_from_double(width) self._layout.width = Pango.units_from_double(width)
self._layout.height = -max_lines -- show this many lines per paragraph 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 return h
end end
@ -261,7 +259,7 @@ local function new(text, ignore_markup)
return ret return ret
end end
function textbox.mt:__call(...) function textbox.mt.__call(_, ...)
return new(...) return new(...)
end end