Fix all luacheck warnings in lib/gears
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
66b93ffded
commit
8c26e2dab4
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
local select = select
|
local select = select
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local unpack = unpack or table.unpack
|
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
|
||||||
|
|
||||||
local cache = {}
|
local cache = {}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local string = string
|
local string = string
|
||||||
local table = table
|
local table = table
|
||||||
local unpack = unpack or table.unpack -- v5.1: unpack, v5.2: table.unpack
|
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local ipairs = ipairs
|
local ipairs = ipairs
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
|
@ -88,7 +88,6 @@ end
|
||||||
-- @param col The color for the pattern
|
-- @param col The color for the pattern
|
||||||
-- @return A cairo pattern object
|
-- @return A cairo pattern object
|
||||||
function color.create_solid_pattern(col)
|
function color.create_solid_pattern(col)
|
||||||
local col = col
|
|
||||||
if col == nil then
|
if col == nil then
|
||||||
col = "#000000"
|
col = "#000000"
|
||||||
elseif type(col) == "table" then
|
elseif type(col) == "table" then
|
||||||
|
@ -102,7 +101,6 @@ end
|
||||||
-- @param file The filename of the file
|
-- @param file The filename of the file
|
||||||
-- @return a cairo pattern object
|
-- @return a cairo pattern object
|
||||||
function color.create_png_pattern(file)
|
function color.create_png_pattern(file)
|
||||||
local file = file
|
|
||||||
if type(file) == "table" then
|
if type(file) == "table" then
|
||||||
file = file.file
|
file = file.file
|
||||||
end
|
end
|
||||||
|
@ -138,7 +136,7 @@ local function string_pattern(creator, arg)
|
||||||
local args = { parse_numbers(iterator()) }
|
local args = { parse_numbers(iterator()) }
|
||||||
local to = { parse_numbers(iterator()) }
|
local to = { parse_numbers(iterator()) }
|
||||||
-- Now merge those two tables
|
-- Now merge those two tables
|
||||||
for k, v in pairs(to) do
|
for _, v in pairs(to) do
|
||||||
table.insert(args, v)
|
table.insert(args, v)
|
||||||
end
|
end
|
||||||
-- And call our creator function with the values
|
-- And call our creator function with the values
|
||||||
|
@ -220,7 +218,7 @@ function color.create_pattern_uncached(col)
|
||||||
if cairo.Pattern:is_type_of(col) then
|
if cairo.Pattern:is_type_of(col) then
|
||||||
return col
|
return col
|
||||||
end
|
end
|
||||||
local col = col or "#000000"
|
col = col or "#000000"
|
||||||
if type(col) == "string" then
|
if type(col) == "string" then
|
||||||
local t = string.match(col, "[^:]+")
|
local t = string.match(col, "[^:]+")
|
||||||
if color.types[t] then
|
if color.types[t] then
|
||||||
|
@ -271,18 +269,17 @@ end
|
||||||
-- @return The pattern if it is surely opaque, else nil
|
-- @return The pattern if it is surely opaque, else nil
|
||||||
function color.create_opaque_pattern(col)
|
function color.create_opaque_pattern(col)
|
||||||
local pattern = color.create_pattern(col)
|
local pattern = color.create_pattern(col)
|
||||||
local type = pattern:get_type()
|
local kind = pattern:get_type()
|
||||||
local extend = pattern:get_extend()
|
|
||||||
|
|
||||||
if type == "SOLID" then
|
if kind == "SOLID" then
|
||||||
local status, r, g, b, a = pattern:get_rgba()
|
local _, _, _, _, alpha = pattern:get_rgba()
|
||||||
if a ~= 1 then
|
if alpha ~= 1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
return pattern
|
return pattern
|
||||||
elseif type == "SURFACE" then
|
elseif kind == "SURFACE" then
|
||||||
local status, surface = pattern:get_surface()
|
local status, surf = pattern:get_surface()
|
||||||
if status ~= "SUCCESS" or surface.content ~= "COLOR" then
|
if status ~= "SUCCESS" or surf.content ~= "COLOR" then
|
||||||
-- The surface has an alpha channel which *might* be non-opaque
|
-- The surface has an alpha channel which *might* be non-opaque
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -294,8 +291,8 @@ function color.create_opaque_pattern(col)
|
||||||
end
|
end
|
||||||
|
|
||||||
return pattern
|
return pattern
|
||||||
elseif type == "LINEAR" then
|
elseif kind == "LINEAR" then
|
||||||
local status, stops = pattern:get_color_stop_count()
|
local _, stops = pattern:get_color_stop_count()
|
||||||
|
|
||||||
-- No color stops or extend NONE -> pattern *might* contain transparency
|
-- No color stops or extend NONE -> pattern *might* contain transparency
|
||||||
if stops == 0 or pattern:get_extend() == "NONE" then
|
if stops == 0 or pattern:get_extend() == "NONE" then
|
||||||
|
@ -304,8 +301,8 @@ function color.create_opaque_pattern(col)
|
||||||
|
|
||||||
-- Now check if any of the color stops contain transparency
|
-- Now check if any of the color stops contain transparency
|
||||||
for i = 0, stops - 1 do
|
for i = 0, stops - 1 do
|
||||||
local status, offset, r, g, b, a = pattern:get_color_stop_rgba(i)
|
local _, _, _, _, _, alpha = pattern:get_color_stop_rgba(i)
|
||||||
if a ~= 1 then
|
if alpha ~= 1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -330,7 +327,7 @@ function color.recolor_image(image, new_color)
|
||||||
return image
|
return image
|
||||||
end
|
end
|
||||||
|
|
||||||
function color.mt:__call(...)
|
function color.mt.__call(_, ...)
|
||||||
return color.create_pattern(...)
|
return color.create_pattern(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,7 @@
|
||||||
-- @module gears.debug
|
-- @module gears.debug
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
local error = error
|
|
||||||
local tostring = tostring
|
local tostring = tostring
|
||||||
local traceback = debug.traceback
|
|
||||||
local print = print
|
local print = print
|
||||||
local type = type
|
local type = type
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
|
|
|
@ -175,7 +175,7 @@ end
|
||||||
-- @treturn number The x coordinate of the transformed point.
|
-- @treturn number The x coordinate of the transformed point.
|
||||||
-- @treturn number The x coordinate of the transformed point.
|
-- @treturn number The x coordinate of the transformed point.
|
||||||
function matrix:transform_point(x, y)
|
function matrix:transform_point(x, y)
|
||||||
local x, y = self:transform_distance(x, y)
|
x, y = self:transform_distance(x, y)
|
||||||
return self.x0 + x, self.y0 + y
|
return self.x0 + x, self.y0 + y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -195,10 +195,10 @@ function matrix:transform_rectangle(x, y, width, height)
|
||||||
local x3, y3 = self:transform_point(x + width, y + height)
|
local x3, y3 = self:transform_point(x + width, y + height)
|
||||||
local x4, y4 = self:transform_point(x + width, y)
|
local x4, y4 = self:transform_point(x + width, y)
|
||||||
-- Find the extremal points of the result
|
-- Find the extremal points of the result
|
||||||
local x = math.min(x1, x2, x3, x4)
|
x = math.min(x1, x2, x3, x4)
|
||||||
local y = math.min(y1, y2, y3, y4)
|
y = math.min(y1, y2, y3, y4)
|
||||||
local width = math.max(x1, x2, x3, x4) - x
|
width = math.max(x1, x2, x3, x4) - x
|
||||||
local height = math.max(y1, y2, y3, y4) - y
|
height = math.max(y1, y2, y3, y4) - y
|
||||||
|
|
||||||
return x, y, width, height
|
return x, y, width, height
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,6 +60,7 @@ local function make_the_gc_obey(func)
|
||||||
-- Lua 5.1 only has the behaviour we want if a userdata is used as the
|
-- Lua 5.1 only has the behaviour we want if a userdata is used as the
|
||||||
-- value in a weak table. Thus, do some magic so that we get a userdata.
|
-- value in a weak table. Thus, do some magic so that we get a userdata.
|
||||||
|
|
||||||
|
-- luacheck: globals newproxy getfenv setfenv
|
||||||
local userdata = newproxy(true)
|
local userdata = newproxy(true)
|
||||||
getmetatable(userdata).__gc = function() end
|
getmetatable(userdata).__gc = function() end
|
||||||
-- Now bind the lifetime of userdata to the lifetime of func. For this,
|
-- Now bind the lifetime of userdata to the lifetime of func. For this,
|
||||||
|
@ -137,7 +138,7 @@ local function new()
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
function object.mt:__call(...)
|
function object.mt.__call(_, ...)
|
||||||
return new(...)
|
return new(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -64,9 +64,9 @@ end
|
||||||
-- @tparam[opt=10] number arrow_size The width and height of the arrow
|
-- @tparam[opt=10] number arrow_size The width and height of the arrow
|
||||||
-- @tparam[opt=width/2 - arrow_size/2] number arrow_position The position of the arrow
|
-- @tparam[opt=width/2 - arrow_size/2] number arrow_position The position of the arrow
|
||||||
function module.infobubble(cr, width, height, corner_radius, arrow_size, arrow_position)
|
function module.infobubble(cr, width, height, corner_radius, arrow_size, arrow_position)
|
||||||
local corner_radius = corner_radius or 5
|
corner_radius = corner_radius or 5
|
||||||
local arrow_size = arrow_size or 10
|
arrow_size = arrow_size or 10
|
||||||
local arrow_position = arrow_position or width/2 - arrow_size/2
|
arrow_position = arrow_position or width/2 - arrow_size/2
|
||||||
|
|
||||||
cr:move_to(0 ,corner_radius)
|
cr:move_to(0 ,corner_radius)
|
||||||
|
|
||||||
|
@ -109,9 +109,9 @@ end
|
||||||
-- @tparam[opt=width /2] number shaft_width The width of the shaft of the arrow
|
-- @tparam[opt=width /2] number shaft_width The width of the shaft of the arrow
|
||||||
-- @tparam[opt=height/2] number shaft_length The head_length of the shaft (the rest is the head)
|
-- @tparam[opt=height/2] number shaft_length The head_length of the shaft (the rest is the head)
|
||||||
function module.arrow(cr, width, height, head_width, shaft_width, shaft_length)
|
function module.arrow(cr, width, height, head_width, shaft_width, shaft_length)
|
||||||
local shaft_length = shaft_length or height / 2
|
shaft_length = shaft_length or height / 2
|
||||||
local shaft_width = shaft_width or width / 2
|
shaft_width = shaft_width or width / 2
|
||||||
local head_width = head_width or width
|
head_width = head_width or width
|
||||||
local head_length = height - shaft_length
|
local head_length = height - shaft_length
|
||||||
|
|
||||||
cr:move_to ( width/2 , 0 )
|
cr:move_to ( width/2 , 0 )
|
||||||
|
@ -146,7 +146,7 @@ end
|
||||||
-- @tparam number height The shape height
|
-- @tparam number height The shape height
|
||||||
-- @tparam[opt=height/2] number arrow_depth The width of the arrow part of the shape
|
-- @tparam[opt=height/2] number arrow_depth The width of the arrow part of the shape
|
||||||
function module.powerline(cr, width, height, arrow_depth)
|
function module.powerline(cr, width, height, arrow_depth)
|
||||||
local arrow_depth = arrow_depth or height/2
|
arrow_depth = arrow_depth or height/2
|
||||||
cr:move_to(0 , 0 )
|
cr:move_to(0 , 0 )
|
||||||
cr:line_to(width - arrow_depth , 0 )
|
cr:line_to(width - arrow_depth , 0 )
|
||||||
cr:line_to(width , height/2 )
|
cr:line_to(width , height/2 )
|
||||||
|
|
|
@ -114,7 +114,7 @@ function surface.load(_surface)
|
||||||
return do_load_and_handle_errors(_surface, surface.load_silently)
|
return do_load_and_handle_errors(_surface, surface.load_silently)
|
||||||
end
|
end
|
||||||
|
|
||||||
function surface.mt:__call(...)
|
function surface.mt.__call(_, ...)
|
||||||
return surface.load(...)
|
return surface.load(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ local setmetatable = setmetatable
|
||||||
local table = table
|
local table = table
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local traceback = debug.traceback
|
local traceback = debug.traceback
|
||||||
local unpack = unpack or table.unpack -- v5.1: unpack, v5.2: table.unpack
|
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
|
||||||
local glib = require("lgi").GLib
|
local glib = require("lgi").GLib
|
||||||
local object = require("gears.object")
|
local object = require("gears.object")
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ function timer:start()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self.data.source_id = glib.timeout_add(glib.PRIORITY_DEFAULT, self.data.timeout * 1000, function()
|
self.data.source_id = glib.timeout_add(glib.PRIORITY_DEFAULT, self.data.timeout * 1000, function()
|
||||||
local success, message = xpcall(function()
|
xpcall(function()
|
||||||
self:emit_signal("timeout")
|
self:emit_signal("timeout")
|
||||||
end, function(err)
|
end, function(err)
|
||||||
print(debug.traceback("Error during executing timeout handler: "..tostring(err)))
|
print(debug.traceback("Error during executing timeout handler: "..tostring(err)))
|
||||||
|
@ -160,7 +160,7 @@ end
|
||||||
local delayed_calls = {}
|
local delayed_calls = {}
|
||||||
capi.awesome.connect_signal("refresh", function()
|
capi.awesome.connect_signal("refresh", function()
|
||||||
for _, callback in ipairs(delayed_calls) do
|
for _, callback in ipairs(delayed_calls) do
|
||||||
local success, message = xpcall(function()
|
xpcall(function()
|
||||||
callback[1](unpack(callback, 2))
|
callback[1](unpack(callback, 2))
|
||||||
end, function(err)
|
end, function(err)
|
||||||
print(debug.traceback("Error during delayed call: "..tostring(err), 2))
|
print(debug.traceback("Error during delayed call: "..tostring(err), 2))
|
||||||
|
@ -177,7 +177,7 @@ function timer.delayed_call(callback, ...)
|
||||||
table.insert(delayed_calls, { callback, ... })
|
table.insert(delayed_calls, { callback, ... })
|
||||||
end
|
end
|
||||||
|
|
||||||
function timer.mt:__call(...)
|
function timer.mt.__call(_, ...)
|
||||||
return timer.new(...)
|
return timer.new(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,9 @@ function wallpaper.prepare_context(s)
|
||||||
|
|
||||||
-- Set the wallpaper (delayed)
|
-- Set the wallpaper (delayed)
|
||||||
timer.delayed_call(function()
|
timer.delayed_call(function()
|
||||||
local wp = pending_wallpaper
|
local paper = pending_wallpaper
|
||||||
pending_wallpaper = nil
|
pending_wallpaper = nil
|
||||||
wallpaper.set(wp)
|
wallpaper.set(paper)
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
-- Draw to the already-pending wallpaper
|
-- Draw to the already-pending wallpaper
|
||||||
|
@ -99,8 +99,8 @@ end
|
||||||
-- gears.color. The default is black.
|
-- gears.color. The default is black.
|
||||||
function wallpaper.centered(surf, s, background)
|
function wallpaper.centered(surf, s, background)
|
||||||
local geom, cr = wallpaper.prepare_context(s)
|
local geom, cr = wallpaper.prepare_context(s)
|
||||||
local surf = surface(surf)
|
surf = surface(surf)
|
||||||
local background = color(background)
|
background = color(background)
|
||||||
|
|
||||||
-- Fill the area with the background
|
-- Fill the area with the background
|
||||||
cr.operator = cairo.Operator.SOURCE
|
cr.operator = cairo.Operator.SOURCE
|
||||||
|
@ -122,7 +122,7 @@ end
|
||||||
-- all screens are set.
|
-- all screens are set.
|
||||||
-- @param offset This can be set to a table with entries x and y.
|
-- @param offset This can be set to a table with entries x and y.
|
||||||
function wallpaper.tiled(surf, s, offset)
|
function wallpaper.tiled(surf, s, offset)
|
||||||
local geom, cr = wallpaper.prepare_context(s)
|
local _, cr = wallpaper.prepare_context(s)
|
||||||
|
|
||||||
if offset then
|
if offset then
|
||||||
cr:translate(offset.x, offset.y)
|
cr:translate(offset.x, offset.y)
|
||||||
|
@ -144,7 +144,7 @@ end
|
||||||
-- @param offset This can be set to a table with entries x and y.
|
-- @param offset This can be set to a table with entries x and y.
|
||||||
function wallpaper.maximized(surf, s, ignore_aspect, offset)
|
function wallpaper.maximized(surf, s, ignore_aspect, offset)
|
||||||
local geom, cr = wallpaper.prepare_context(s)
|
local geom, cr = wallpaper.prepare_context(s)
|
||||||
local surf = surface(surf)
|
surf = surface(surf)
|
||||||
local w, h = surface.get_size(surf)
|
local w, h = surface.get_size(surf)
|
||||||
local aspect_w = geom.width / w
|
local aspect_w = geom.width / w
|
||||||
local aspect_h = geom.height / h
|
local aspect_h = geom.height / h
|
||||||
|
@ -176,8 +176,8 @@ end
|
||||||
-- gears.color. The default is black.
|
-- gears.color. The default is black.
|
||||||
function wallpaper.fit(surf, s, background)
|
function wallpaper.fit(surf, s, background)
|
||||||
local geom, cr = wallpaper.prepare_context(s)
|
local geom, cr = wallpaper.prepare_context(s)
|
||||||
local surf = surface(surf)
|
surf = surface(surf)
|
||||||
local background = color(background)
|
background = color(background)
|
||||||
|
|
||||||
-- Fill the area with the background
|
-- Fill the area with the background
|
||||||
cr.operator = cairo.Operator.SOURCE
|
cr.operator = cairo.Operator.SOURCE
|
||||||
|
|
Loading…
Reference in New Issue