Fix luacheck warnings in lib/naughty
A warning pointing out an actual problem is left. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
15e72fb037
commit
2c77f9dcf8
|
@ -12,7 +12,6 @@ local pairs = pairs
|
||||||
local table = table
|
local table = table
|
||||||
local type = type
|
local type = type
|
||||||
local string = string
|
local string = string
|
||||||
local tostring = tostring
|
|
||||||
local pcall = pcall
|
local pcall = pcall
|
||||||
local capi = { screen = screen,
|
local capi = { screen = screen,
|
||||||
awesome = awesome }
|
awesome = awesome }
|
||||||
|
@ -26,11 +25,6 @@ local surface = require("gears.surface")
|
||||||
local cairo = require("lgi").cairo
|
local cairo = require("lgi").cairo
|
||||||
local dpi = require("beautiful").xresources.apply_dpi
|
local dpi = require("beautiful").xresources.apply_dpi
|
||||||
|
|
||||||
local schar = string.char
|
|
||||||
local sbyte = string.byte
|
|
||||||
local tcat = table.concat
|
|
||||||
local tins = table.insert
|
|
||||||
|
|
||||||
local naughty = {}
|
local naughty = {}
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
|
@ -169,7 +163,7 @@ end
|
||||||
--- Resume notifications
|
--- Resume notifications
|
||||||
function naughty.resume()
|
function naughty.resume()
|
||||||
suspended = false
|
suspended = false
|
||||||
for i, v in pairs(naughty.notifications.suspended) do
|
for _, v in pairs(naughty.notifications.suspended) do
|
||||||
v.box.visible = true
|
v.box.visible = true
|
||||||
if v.timer then v.timer:start() end
|
if v.timer then v.timer:start() end
|
||||||
end
|
end
|
||||||
|
@ -187,18 +181,18 @@ end
|
||||||
|
|
||||||
--- Evaluate desired position of the notification by index - internal
|
--- Evaluate desired position of the notification by index - internal
|
||||||
--
|
--
|
||||||
-- @param screen Screen to use
|
-- @param s Screen to use
|
||||||
-- @param position top_right | top_left | bottom_right | bottom_left
|
-- @param position top_right | top_left | bottom_right | bottom_left
|
||||||
-- | top_middle | bottom_middle
|
-- | top_middle | bottom_middle
|
||||||
-- @param idx Index of the notification
|
-- @param idx Index of the notification
|
||||||
-- @param[opt] width Popup width.
|
-- @param[opt] width Popup width.
|
||||||
-- @param height Popup height
|
-- @param height Popup height
|
||||||
-- @return Absolute position and index in { x = X, y = Y, idx = I } table
|
-- @return Absolute position and index in { x = X, y = Y, idx = I } table
|
||||||
local function get_offset(screen, position, idx, width, height)
|
local function get_offset(s, position, idx, width, height)
|
||||||
local ws = capi.screen[screen].workarea
|
local ws = capi.screen[s].workarea
|
||||||
local v = {}
|
local v = {}
|
||||||
local idx = idx or #naughty.notifications[screen][position] + 1
|
idx = idx or #naughty.notifications[s][position] + 1
|
||||||
local width = width or naughty.notifications[screen][position][idx].width
|
width = width or naughty.notifications[s][position][idx].width
|
||||||
|
|
||||||
-- calculate x
|
-- calculate x
|
||||||
if position:match("left") then
|
if position:match("left") then
|
||||||
|
@ -212,7 +206,7 @@ local function get_offset(screen, position, idx, width, height)
|
||||||
-- calculate existing popups' height
|
-- calculate existing popups' height
|
||||||
local existing = 0
|
local existing = 0
|
||||||
for i = 1, idx-1, 1 do
|
for i = 1, idx-1, 1 do
|
||||||
existing = existing + naughty.notifications[screen][position][i].height + naughty.config.spacing
|
existing = existing + naughty.notifications[s][position][i].height + naughty.config.spacing
|
||||||
end
|
end
|
||||||
|
|
||||||
-- calculate y
|
-- calculate y
|
||||||
|
@ -227,20 +221,20 @@ local function get_offset(screen, position, idx, width, height)
|
||||||
-- e.g. critical ones.
|
-- e.g. critical ones.
|
||||||
local find_old_to_replace = function()
|
local find_old_to_replace = function()
|
||||||
for i = 1, idx-1 do
|
for i = 1, idx-1 do
|
||||||
local n = naughty.notifications[screen][position][i]
|
local n = naughty.notifications[s][position][i]
|
||||||
if n.timeout > 0 then
|
if n.timeout > 0 then
|
||||||
return n
|
return n
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Fallback to first one.
|
-- Fallback to first one.
|
||||||
return naughty.notifications[screen][position][1]
|
return naughty.notifications[s][position][1]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if positioned outside workarea, destroy oldest popup and recalculate
|
-- if positioned outside workarea, destroy oldest popup and recalculate
|
||||||
if v.y + height > ws.y + ws.height or v.y < ws.y then
|
if v.y + height > ws.y + ws.height or v.y < ws.y then
|
||||||
naughty.destroy(find_old_to_replace())
|
naughty.destroy(find_old_to_replace())
|
||||||
idx = idx - 1
|
idx = idx - 1
|
||||||
v = get_offset(screen, position, idx, width, height)
|
v = get_offset(s, position, idx, width, height)
|
||||||
end
|
end
|
||||||
if not v.idx then v.idx = idx end
|
if not v.idx then v.idx = idx end
|
||||||
|
|
||||||
|
@ -250,10 +244,10 @@ end
|
||||||
--- Re-arrange notifications according to their position and index - internal
|
--- Re-arrange notifications according to their position and index - internal
|
||||||
--
|
--
|
||||||
-- @return None
|
-- @return None
|
||||||
local function arrange(screen)
|
local function arrange(s)
|
||||||
for p,pos in pairs(naughty.notifications[screen]) do
|
for p in pairs(naughty.notifications[s]) do
|
||||||
for i,notification in pairs(naughty.notifications[screen][p]) do
|
for i,notification in pairs(naughty.notifications[s][p]) do
|
||||||
local offset = get_offset(screen, p, i, notification.width, notification.height)
|
local offset = get_offset(s, p, i, notification.width, notification.height)
|
||||||
notification.box:geometry({ x = offset.x, y = offset.y })
|
notification.box:geometry({ x = offset.x, y = offset.y })
|
||||||
notification.idx = offset.idx
|
notification.idx = offset.idx
|
||||||
end
|
end
|
||||||
|
@ -296,8 +290,8 @@ end
|
||||||
function naughty.getById(id)
|
function naughty.getById(id)
|
||||||
-- iterate the notifications to get the notfications with the correct ID
|
-- iterate the notifications to get the notfications with the correct ID
|
||||||
for s = 1, capi.screen.count() do
|
for s = 1, capi.screen.count() do
|
||||||
for p,pos in pairs(naughty.notifications[s]) do
|
for p in pairs(naughty.notifications[s]) do
|
||||||
for i,notification in pairs(naughty.notifications[s][p]) do
|
for _, notification in pairs(naughty.notifications[s][p]) do
|
||||||
if notification.id == id then
|
if notification.id == id then
|
||||||
return notification
|
return notification
|
||||||
end
|
end
|
||||||
|
@ -437,7 +431,7 @@ function naughty.notify(args)
|
||||||
local icon_size = args.icon_size or preset.icon_size
|
local icon_size = args.icon_size or preset.icon_size
|
||||||
local text = args.text or preset.text
|
local text = args.text or preset.text
|
||||||
local title = args.title or preset.title
|
local title = args.title or preset.title
|
||||||
local screen = args.screen or preset.screen or screen.focused()
|
local s = args.screen or preset.screen or screen.focused()
|
||||||
local ontop = args.ontop or preset.ontop
|
local ontop = args.ontop or preset.ontop
|
||||||
local width = args.width or preset.width
|
local width = args.width or preset.width
|
||||||
local height = args.height or preset.height
|
local height = args.height or preset.height
|
||||||
|
@ -455,7 +449,7 @@ function naughty.notify(args)
|
||||||
local fg = args.fg or preset.fg or beautiful.fg_normal or '#ffffff'
|
local fg = args.fg or preset.fg or beautiful.fg_normal or '#ffffff'
|
||||||
local bg = args.bg or preset.bg or beautiful.bg_normal or '#535d6c'
|
local bg = args.bg or preset.bg or beautiful.bg_normal or '#535d6c'
|
||||||
local border_color = args.border_color or preset.border_color or beautiful.bg_focus or '#535d6c'
|
local border_color = args.border_color or preset.border_color or beautiful.bg_focus or '#535d6c'
|
||||||
local notification = { screen = screen, destroy_cb = destroy_cb, timeout = timeout }
|
local notification = { screen = s, destroy_cb = destroy_cb, timeout = timeout }
|
||||||
|
|
||||||
-- replace notification if needed
|
-- replace notification if needed
|
||||||
if args.replaces_id then
|
if args.replaces_id then
|
||||||
|
@ -530,8 +524,8 @@ function naughty.notify(args)
|
||||||
actiontextbox:set_markup(string.format('<b>%s</b>', action))
|
actiontextbox:set_markup(string.format('<b>%s</b>', action))
|
||||||
-- calculate the height and width
|
-- calculate the height and width
|
||||||
local w, h = actiontextbox:get_preferred_size(s)
|
local w, h = actiontextbox:get_preferred_size(s)
|
||||||
local height = h + 2 * margin
|
local action_height = h + 2 * margin
|
||||||
local width = w + 2 * margin
|
local action_width = w + 2 * margin
|
||||||
|
|
||||||
actionmarginbox:buttons(util.table.join(
|
actionmarginbox:buttons(util.table.join(
|
||||||
button({ }, 1, callback),
|
button({ }, 1, callback),
|
||||||
|
@ -539,9 +533,9 @@ function naughty.notify(args)
|
||||||
))
|
))
|
||||||
actionslayout:add(actionmarginbox)
|
actionslayout:add(actionmarginbox)
|
||||||
|
|
||||||
actions_total_height = actions_total_height + height
|
actions_total_height = actions_total_height + action_height
|
||||||
if actions_max_width < width then
|
if actions_max_width < action_width then
|
||||||
actions_max_width = width
|
actions_max_width = action_width
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -561,7 +555,7 @@ function naughty.notify(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- is the icon file readable?
|
-- is the icon file readable?
|
||||||
local icon = surface.load_uncached(icon)
|
icon = surface.load_uncached(icon)
|
||||||
|
|
||||||
-- if we have an icon, use it
|
-- if we have an icon, use it
|
||||||
if icon then
|
if icon then
|
||||||
|
@ -593,7 +587,7 @@ function naughty.notify(args)
|
||||||
|
|
||||||
-- calculate the width
|
-- calculate the width
|
||||||
if not width then
|
if not width then
|
||||||
local w, h = textbox:get_preferred_size(s)
|
local w, _ = textbox:get_preferred_size(s)
|
||||||
width = w + (iconbox and icon_w + 2 * margin or 0) + 2 * margin
|
width = w + (iconbox and icon_w + 2 * margin or 0) + 2 * margin
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -615,7 +609,7 @@ function naughty.notify(args)
|
||||||
height = height + actions_total_height
|
height = height + actions_total_height
|
||||||
|
|
||||||
-- crop to workarea size if too big
|
-- crop to workarea size if too big
|
||||||
local workarea = capi.screen[screen].workarea
|
local workarea = capi.screen[s].workarea
|
||||||
if width > workarea.width - 2 * (border_width or 0) - 2 * (naughty.config.padding or 0) then
|
if width > workarea.width - 2 * (border_width or 0) - 2 * (naughty.config.padding or 0) then
|
||||||
width = workarea.width - 2 * (border_width or 0) - 2 * (naughty.config.padding or 0)
|
width = workarea.width - 2 * (border_width or 0) - 2 * (naughty.config.padding or 0)
|
||||||
end
|
end
|
||||||
|
@ -628,7 +622,7 @@ function naughty.notify(args)
|
||||||
notification.width = width + 2 * (border_width or 0)
|
notification.width = width + 2 * (border_width or 0)
|
||||||
|
|
||||||
-- position the wibox
|
-- position the wibox
|
||||||
local offset = get_offset(screen, notification.position, nil, notification.width, notification.height)
|
local offset = get_offset(s, notification.position, nil, notification.width, notification.height)
|
||||||
notification.box.ontop = ontop
|
notification.box.ontop = ontop
|
||||||
notification.box:geometry({ width = width,
|
notification.box:geometry({ width = width,
|
||||||
height = height,
|
height = height,
|
||||||
|
@ -657,7 +651,7 @@ function naughty.notify(args)
|
||||||
end)))
|
end)))
|
||||||
|
|
||||||
-- insert the notification to the table
|
-- insert the notification to the table
|
||||||
table.insert(naughty.notifications[screen][notification.position], notification)
|
table.insert(naughty.notifications[s][notification.position], notification)
|
||||||
|
|
||||||
if suspended then
|
if suspended then
|
||||||
notification.box.visible = false
|
notification.box.visible = false
|
||||||
|
|
|
@ -23,7 +23,7 @@ local schar = string.char
|
||||||
local sbyte = string.byte
|
local sbyte = string.byte
|
||||||
local tcat = table.concat
|
local tcat = table.concat
|
||||||
local tins = table.insert
|
local tins = table.insert
|
||||||
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 naughty = require("naughty.core")
|
local naughty = require("naughty.core")
|
||||||
|
|
||||||
--- Notification library, dbus bindings
|
--- Notification library, dbus bindings
|
||||||
|
@ -88,7 +88,7 @@ local function convert_icon(w, h, rowstride, channels, data)
|
||||||
-- Now convert each row on its own
|
-- Now convert each row on its own
|
||||||
local rows = {}
|
local rows = {}
|
||||||
|
|
||||||
for y = 1, h do
|
for _ = 1, h do
|
||||||
local this_row = {}
|
local this_row = {}
|
||||||
|
|
||||||
for i = 1 + offset, w * channels + offset, channels do
|
for i = 1 + offset, w * channels + offset, channels do
|
||||||
|
@ -124,8 +124,8 @@ capi.dbus.connect_signal("org.freedesktop.Notifications", function (data, appnam
|
||||||
if appname ~= "" then
|
if appname ~= "" then
|
||||||
args.appname = appname
|
args.appname = appname
|
||||||
end
|
end
|
||||||
for i, obj in pairs(dbus.config.mapping) do
|
for _, obj in pairs(dbus.config.mapping) do
|
||||||
local filter, preset, s = obj[1], obj[2], 0
|
local filter, preset = obj[1], obj[2]
|
||||||
if (not filter.urgency or filter.urgency == hints.urgency) and
|
if (not filter.urgency or filter.urgency == hints.urgency) and
|
||||||
(not filter.category or filter.category == hints.category) and
|
(not filter.category or filter.category == hints.category) and
|
||||||
(not filter.appname or filter.appname == appname) then
|
(not filter.appname or filter.appname == appname) then
|
||||||
|
@ -176,8 +176,8 @@ capi.dbus.connect_signal("org.freedesktop.Notifications", function (data, appnam
|
||||||
-- 5 -> bits per sample
|
-- 5 -> bits per sample
|
||||||
-- 6 -> channels
|
-- 6 -> channels
|
||||||
-- 7 -> data
|
-- 7 -> data
|
||||||
local w, h, rowstride, _, _, channels, data = unpack(hints.icon_data)
|
local w, h, rowstride, _, _, channels, icon_data = unpack(hints.icon_data)
|
||||||
args.icon = convert_icon(w, h, rowstride, channels, data)
|
args.icon = convert_icon(w, h, rowstride, channels, icon_data)
|
||||||
end
|
end
|
||||||
if replaces_id and replaces_id ~= "" and replaces_id ~= 0 then
|
if replaces_id and replaces_id ~= "" and replaces_id ~= 0 then
|
||||||
args.replaces_id = replaces_id
|
args.replaces_id = replaces_id
|
||||||
|
@ -204,7 +204,7 @@ capi.dbus.connect_signal("org.freedesktop.Notifications", function (data, appnam
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
capi.dbus.connect_signal("org.freedesktop.DBus.Introspectable", function (data, text)
|
capi.dbus.connect_signal("org.freedesktop.DBus.Introspectable", function (data)
|
||||||
if data.member == "Introspect" then
|
if data.member == "Introspect" then
|
||||||
local xml = [=[<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object
|
local xml = [=[<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object
|
||||||
Introspection 1.0//EN"
|
Introspection 1.0//EN"
|
||||||
|
|
Loading…
Reference in New Issue