From c455e1f90e01364021c7d6c4cc435b8f38d92d8e Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 7 Feb 2016 15:02:25 +0100 Subject: [PATCH] Fix luacheck warnings in half of awful Boy, awful is huge... Let's better do it in two parts Signed-off-by: Uli Schlachter --- lib/awful/autofocus.lua | 1 - lib/awful/button.lua | 4 +- lib/awful/client.lua | 118 +++++++++++++++++++-------------------- lib/awful/completion.lua | 4 +- lib/awful/ewmh.lua | 3 +- lib/awful/init.lua | 2 +- lib/awful/key.lua | 4 +- lib/awful/keygrabber.lua | 2 +- lib/awful/menu.lua | 12 ++-- lib/awful/placement.lua | 22 ++++---- lib/awful/prompt.lua | 22 ++++---- lib/awful/remote.lua | 4 +- lib/awful/rules.lua | 3 +- lib/awful/spawn.lua | 2 +- lib/awful/tag.lua | 71 +++++++++++------------ lib/awful/titlebar.lua | 38 ++++++------- lib/awful/tooltip.lua | 1 - lib/awful/util.lua | 17 +++--- lib/awful/wibox.lua | 108 +++++++++++++++++------------------ 19 files changed, 212 insertions(+), 226 deletions(-) diff --git a/lib/awful/autofocus.lua b/lib/awful/autofocus.lua index 8e7c02caf..0112cfc2f 100644 --- a/lib/awful/autofocus.lua +++ b/lib/awful/autofocus.lua @@ -11,7 +11,6 @@ --------------------------------------------------------------------------- local client = client -local screen = screen local aclient = require("awful.client") local atag = require("awful.tag") local timer = require("gears.timer") diff --git a/lib/awful/button.lua b/lib/awful/button.lua index 47db912d3..88e593d6a 100644 --- a/lib/awful/button.lua +++ b/lib/awful/button.lua @@ -44,10 +44,10 @@ function button.new(mod, _button, press, release) ret[#ret + 1] = capi.button({ modifiers = util.table.join(mod, set), button = _button }) if press then - ret[#ret]:connect_signal("press", function(bobj, ...) press(...) end) + ret[#ret]:connect_signal("press", function(_, ...) press(...) end) end if release then - ret[#ret]:connect_signal("release", function (bobj, ...) release(...) end) + ret[#ret]:connect_signal("release", function (_, ...) release(...) end) end end return ret diff --git a/lib/awful/client.lua b/lib/awful/client.lua index 2d2585a45..77d51bee2 100644 --- a/lib/awful/client.lua +++ b/lib/awful/client.lua @@ -29,7 +29,7 @@ local capi = local screen do screen = setmetatable({}, { - __index = function(t, k) + __index = function(_, k) screen = require("awful.screen") return screen[k] end, @@ -91,7 +91,7 @@ function client.urgent.get() else -- fallback behaviour: iterate through clients and get the first urgent local clients = capi.client.get() - for k, cl in pairs(clients) do + for _, cl in pairs(clients) do if cl.urgent then return cl end @@ -171,21 +171,21 @@ end --- Get the latest focused client for a screen in history. -- --- @tparam int screen The screen number to look for. +-- @tparam int s The screen number to look for. -- @tparam int idx The index: 0 will return first candidate, -- 1 will return second, etc. -- @tparam function filter An optional filter. If no client is found in the -- first iteration, client.focus.filter is used by default to get any -- client. -- @treturn client.object A client. -function client.focus.history.get(screen, idx, filter) +function client.focus.history.get(s, idx, filter) -- When this counter is equal to idx, we return the client local counter = 0 - local vc = client.visible(screen, true) - for k, c in ipairs(client.data.focus) do - if c.screen == screen then + local vc = client.visible(s, true) + for _, c in ipairs(client.data.focus) do + if c.screen == s then if not filter or filter(c) then - for j, vcc in ipairs(vc) do + for _, vcc in ipairs(vc) do if vcc == c then if counter == idx then return c @@ -200,9 +200,9 @@ function client.focus.history.get(screen, idx, filter) end -- Argh nobody found in history, give the first one visible if there is one -- that passes the filter. - local filter = filter or client.focus.filter + filter = filter or client.focus.filter if counter == 0 then - for k, v in ipairs(vc) do + for _, v in ipairs(vc) do if filter(v) then return v end @@ -223,13 +223,13 @@ end --- Get visible clients from a screen. -- --- @tparam[opt] integer screen The screen number, or nil for all screens. +-- @tparam[opt] integer s The screen number, or nil for all screens. -- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom) -- @treturn table A table with all visible clients. -function client.visible(screen, stacked) - local cls = capi.client.get(screen, stacked) +function client.visible(s, stacked) + local cls = capi.client.get(s, stacked) local vcls = {} - for k, c in pairs(cls) do + for _, c in pairs(cls) do if c:isvisible() then table.insert(vcls, c) end @@ -239,14 +239,14 @@ end --- Get visible and tiled clients -- --- @tparam integer screen The screen number, or nil for all screens. +-- @tparam integer s The screen number, or nil for all screens. -- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom) -- @treturn table A table with all visible and tiled clients. -function client.tiled(screen, stacked) - local clients = client.visible(screen, stacked) +function client.tiled(s, stacked) + local clients = client.visible(s, stacked) local tclients = {} -- Remove floating clients - for k, c in pairs(clients) do + for _, c in pairs(clients) do if not client.floating.get(c) and not c.fullscreen and not c.maximized_vertical @@ -261,7 +261,7 @@ end -- If no client is passed, the focused client will be used. -- -- @tparam int i The index. Use 1 to get the next, -1 to get the previous. --- @client[opt] c The client. +-- @client[opt] sel The client. -- @tparam[opt=false] boolean stacked Use stacking order? (top to bottom) -- @return A client, or nil if no client is available. -- @@ -269,15 +269,15 @@ end -- awful.client.next(1) -- -- focus the previous -- awful.client.next(-1) -function client.next(i, c, stacked) +function client.next(i, sel, stacked) -- Get currently focused client - local sel = c or capi.client.focus + sel = sel or capi.client.focus if sel then -- Get all visible clients local cls = client.visible(sel.screen, stacked) local fcls = {} -- Remove all non-normal clients - for idx, c in ipairs(cls) do + for _, c in ipairs(cls) do if client.focus.filter(c) or c == sel then table.insert(fcls, c) end @@ -385,9 +385,9 @@ end --- Swap a client with another client in the given direction. Swaps across screens. -- @param dir The direction, can be either "up", "down", "left" or "right". --- @client[opt] c The client. -function client.swap.global_bydirection(dir, c) - local sel = c or capi.client.focus +-- @client[opt] sel The client. +function client.swap.global_bydirection(dir, sel) + sel = sel or capi.client.focus local scr = sel and sel.screen or screen.focused() if sel then @@ -463,7 +463,7 @@ end -- @client c The window to set as master. function client.setmaster(c) local cls = util.table.reverse(capi.client.get(c.screen)) - for k, v in pairs(cls) do + for _, v in pairs(cls) do c:swap(v) end end @@ -472,7 +472,7 @@ end -- @client c The window to set as slave. function client.setslave(c) local cls = capi.client.get(c.screen) - for k, v in pairs(cls) do + for _, v in pairs(cls) do c:swap(v) end end @@ -565,7 +565,7 @@ end function client.mark(c) local cl = c or capi.client.focus if cl then - for k, v in pairs(client.data.marked) do + for _, v in pairs(client.data.marked) do if cl == v then return false end @@ -601,7 +601,7 @@ end function client.ismarked(c) local cl = c or capi.client.focus if cl then - for k, v in pairs(client.data.marked) do + for _, v in pairs(client.data.marked) do if cl == v then return true end @@ -613,8 +613,7 @@ end --- Toggle a client as marked. -- @client c The client to toggle mark. function client.togglemarked(c) - local cl = c or capi.client.focus - + c = c or capi.client.focus if not client.mark(c) then client.unmark(c) end @@ -623,11 +622,11 @@ end --- Return the marked clients and empty the marked table. -- @return A table with all marked clients. function client.getmarked() - for k, v in pairs(client.data.marked) do + for _, v in pairs(client.data.marked) do v:emit_signal("unmarked") end - t = client.data.marked + local t = client.data.marked client.data.marked = {} return t end @@ -637,7 +636,7 @@ end -- @client c A client. -- @param s True or false. function client.floating.set(c, s) - local c = c or capi.client.focus + c = c or capi.client.focus if c and client.property.get(c, "floating") ~= s then client.property.set(c, "floating", s) local scr = c.screen @@ -655,12 +654,12 @@ local function store_floating_geometry(c) end -- Store the initial client geometry. -capi.client.connect_signal("new", function(c) +capi.client.connect_signal("new", function(cl) local function store_init_geometry(c) client.property.set(c, "floating_geometry", c:geometry()) c:disconnect_signal("property::border_width", store_init_geometry) end - c:connect_signal("property::border_width", store_init_geometry) + cl:connect_signal("property::border_width", store_init_geometry) end) capi.client.connect_signal("property::geometry", store_floating_geometry) @@ -668,7 +667,7 @@ capi.client.connect_signal("property::geometry", store_floating_geometry) --- Return if a client has a fixe size or not. -- @client c The client. function client.isfixed(c) - local c = c or capi.client.focus + c = c or capi.client.focus if not c then return end local h = c.size_hints if h.min_width and h.max_width @@ -688,7 +687,7 @@ end -- did not set them manually. For example, windows with a type different than -- normal. function client.floating.get(c) - local c = c or capi.client.focus + c = c or capi.client.focus if c then local value = client.property.get(c, "floating") if value ~= nil then @@ -708,7 +707,7 @@ end --- Toggle the floating state of a client between 'auto' and 'true'. -- @client c A client. function client.floating.toggle(c) - local c = c or capi.client.focus + c = c or capi.client.focus -- If it has been set to floating if client.floating.get(c) then client.floating.set(c, false) @@ -730,11 +729,10 @@ function client.restore(s) s = s or screen.focused() local cls = capi.client.get(s) local tags = tag.selectedlist(s) - local mcls = {} - for k, c in pairs(cls) do + for _, c in pairs(cls) do local ctags = c:tags() if c.minimized then - for k, t in ipairs(tags) do + for _, t in ipairs(tags) do if util.table.hasitem(ctags, t) then c.minimized = false return c @@ -749,7 +747,7 @@ end -- @param set the set of numbers to normalize -- @param num the number of numbers to normalize local function normalize(set, num) - local num = num or #set + num = num or #set local total = 0 if num then for i = 1,num do @@ -759,7 +757,7 @@ local function normalize(set, num) set[i] = set[i] / total end else - for i,v in ipairs(set) do + for _,v in ipairs(set) do total = total + v end @@ -777,7 +775,7 @@ end -- @return idx index of the client in the column -- @return num the number of visible clients in the column function client.idx(c) - local c = c or capi.client.focus + c = c or capi.client.focus if not c then return end -- Only check the tiled clients, the others un irrelevant @@ -836,7 +834,7 @@ end -- @client c the client function client.setwfact(wfact, c) -- get the currently selected window - local c = c or capi.client.focus + c = c or capi.client.focus if not c or not c:isvisible() then return end local w = client.idx(c) @@ -845,9 +843,6 @@ function client.setwfact(wfact, c) local t = tag.selected(c.screen) - local cls = client.tiled(tag.getscreen(t)) - local nmaster = tag.getnmaster(t) - -- n is the number of windows currently visible for which we have to be concerned with the properties local data = tag.getproperty(t, "windowfact") or {} local colfact = data[w.col] @@ -890,17 +885,16 @@ end -- @param add amount to increase the client's window -- @client c the client function client.incwfact(add, c) - local c = c or capi.client.focus + c = c or capi.client.focus if not c then return end local t = tag.selected(c.screen) local w = client.idx(c) - local nmaster = tag.getnmaster(t) local data = tag.getproperty(t, "windowfact") or {} local colfact = data[w.col] or {} - curr = colfact[w.idx] or 1 + local curr = colfact[w.idx] or 1 colfact[w.idx] = curr + add -- keep our ratios normalized @@ -982,15 +976,15 @@ end --- Set a client property to be persistent across restarts (via X properties). -- -- @param prop The property name. --- @param type The type (used for register_xproperty). +-- @param kind The type (used for register_xproperty). -- One of "string", "number" or "boolean". -function client.property.persist(prop, type) +function client.property.persist(prop, kind) local xprop = "awful.client.property." .. prop - capi.awesome.register_xproperty(xprop, type) + capi.awesome.register_xproperty(xprop, kind) client.data.persistent_properties_registered[prop] = true -- Make already-set properties persistent - for c, tab in pairs(client.data.properties) do + for c in pairs(client.data.properties) do if client.data.properties[c] and client.data.properties[c][prop] ~= nil then c:set_xproperty(xprop, client.data.properties[c][prop]) end @@ -1017,7 +1011,7 @@ end function client.iterate(filter, start, s) local clients = capi.client.get(s) local focused = capi.client.focus - local start = start or util.table.hasitem(clients, focused) + start = start or util.table.hasitem(clients, focused) return util.table.iterate(clients, filter, start) end @@ -1041,13 +1035,13 @@ function client.run_or_raise(cmd, matcher, merge) local findex = util.table.hasitem(clients, capi.client.focus) or 1 local start = util.cycle(#clients, findex + 1) - for c in client.iterate(matcher, start) do + local c = client.iterate(matcher, start)() + if c then client.jumpto(c, merge) - return + else + -- client not found, spawn it + spawn(cmd) end - - -- client not found, spawn it - spawn(cmd) end --- Get a matching transient_for client (if any). diff --git a/lib/awful/completion.lua b/lib/awful/completion.lua index 4af7dd541..255378798 100644 --- a/lib/awful/completion.lua +++ b/lib/awful/completion.lua @@ -18,7 +18,6 @@ local math = math local print = print local pairs = pairs local string = string -local util = require("awful.util") local completion = {} @@ -128,7 +127,6 @@ function completion.shell(command, cur_pos, ncomp, shell) end local c, err = io.popen(shell_cmd .. " | sort -u") local output = {} - i = 0 if c then while true do local line = c:read("*line") @@ -168,7 +166,7 @@ end -- @param ncomp The number of yet requested completion using current text. -- @param keywords The keywords table uised for completion. -- @return The new match, the new cursor position, the table of all matches. -function completion.generic(text, cur_pos, ncomp, keywords) +function completion.generic(text, cur_pos, ncomp, keywords) -- luacheck: no unused args -- The keywords table may be empty if #keywords == 0 then return text, #text + 1 diff --git a/lib/awful/ewmh.lua b/lib/awful/ewmh.lua index e02fe8177..cd04c9ea3 100644 --- a/lib/awful/ewmh.lua +++ b/lib/awful/ewmh.lua @@ -70,7 +70,6 @@ local function fullscreen(window, set) if set then store_geometry(window, "fullscreen") data[window].fullscreen.border_width = window.border_width - local g = screen[window.screen].geometry window:geometry(screen[window.screen].geometry) window.border_width = 0 elseif data[window] and data[window].fullscreen then @@ -163,7 +162,7 @@ end -- @tparam string context The context where this signal was used. -- @tparam[opt] table hints A table with additional hints: -- @tparam[opt=false] boolean hints.raise should the client be raised? -function ewmh.activate(c, context, hints) +function ewmh.activate(c, context, hints) -- luacheck: no unused args if c:isvisible() then client.focus = c end diff --git a/lib/awful/init.lua b/lib/awful/init.lua index 52eab8319..9ed82b116 100644 --- a/lib/awful/init.lua +++ b/lib/awful/init.lua @@ -10,7 +10,7 @@ -- TODO: This is a hack for backwards-compatibility with 3.5, remove! local util = require("awful.util") local gtimer = require("gears.timer") -function timer(...) +function timer(...) -- luacheck: ignore util.deprecate("gears.timer") return gtimer(...) end diff --git a/lib/awful/key.lua b/lib/awful/key.lua index cd3b80eed..30feb5dc4 100644 --- a/lib/awful/key.lua +++ b/lib/awful/key.lua @@ -54,10 +54,10 @@ function key.new(mod, _key, press, release, data) ret[#ret + 1] = capi.key({ modifiers = util.table.join(mod, set), key = _key }) if press then - ret[#ret]:connect_signal("press", function(kobj, ...) press(...) end) + ret[#ret]:connect_signal("press", function(_, ...) press(...) end) end if release then - ret[#ret]:connect_signal("release", function(kobj, ...) release(...) end) + ret[#ret]:connect_signal("release", function(_, ...) release(...) end) end end diff --git a/lib/awful/keygrabber.lua b/lib/awful/keygrabber.lua index 1b08ca351..fd41bf08c 100644 --- a/lib/awful/keygrabber.lua +++ b/lib/awful/keygrabber.lua @@ -20,7 +20,7 @@ local keygrabbing = false local function grabber(mod, key, event) - for i, keygrabber_function in ipairs(grabbers) do + for _, keygrabber_function in ipairs(grabbers) do -- continue if the grabber explicitly returns false if keygrabber_function(mod, key, event) ~= false then break diff --git a/lib/awful/menu.lua b/lib/awful/menu.lua index c4a0af0f5..2e29179df 100644 --- a/lib/awful/menu.lua +++ b/lib/awful/menu.lua @@ -99,7 +99,7 @@ end local function item_position(_menu, child) - local in_dir, other, a, b = 0, 0, "height", "width" + local a, b = "height", "width" local dir = _menu.layout.dir or "y" if dir == "x" then a, b = b, a end @@ -191,7 +191,7 @@ local function check_access_key(_menu, key) end -local function grabber(_menu, mod, key, event) +local function grabber(_menu, _, key, event) if event ~= "press" then return end local sel = _menu.sel or 0 @@ -499,10 +499,10 @@ end -------------------------------------------------------------------------------- --- Default awful.menu.entry constructor --- @param parent The parent menu +-- @param parent The parent menu (TODO: This is apparently unused) -- @param args the item params -- @return table with 'widget', 'cmd', 'akey' and all the properties the user wants to change -function menu.entry(parent, args) +function menu.entry(parent, args) -- luacheck: no unused args args = args or {} args.text = args[1] or args.text or "" args.cmd = args[2] or args.cmd @@ -651,9 +651,9 @@ function menu.new(args, parent) end -- Create items - for i, v in ipairs(args) do _menu:add(v) end + for _, v in ipairs(args) do _menu:add(v) end if args.items then - for i, v in pairs(args.items) do _menu:add(v) end + for _, v in pairs(args.items) do _menu:add(v) end end _menu._keygrabber = function (...) diff --git a/lib/awful/placement.lua b/lib/awful/placement.lua index 0912aa6ff..f7469c80a 100644 --- a/lib/awful/placement.lua +++ b/lib/awful/placement.lua @@ -119,9 +119,9 @@ end -- @tparam[opt=client's screen] integer screen The screen. -- @treturn table The new client geometry. function placement.no_offscreen(c, screen) - local c = c or capi.client.focus + c = c or capi.client.focus local geometry = get_area(c) - local screen = screen or c.screen or a_screen.getbycoord(geometry.x, geometry.y) + screen = screen or c.screen or a_screen.getbycoord(geometry.x, geometry.y) local screen_geometry = capi.screen[screen].workarea if geometry.x + geometry.width > screen_geometry.x + screen_geometry.width then @@ -149,7 +149,7 @@ function placement.no_overlap(c) local cls = client.visible(screen) local curlay = layout.get() local areas = { capi.screen[screen].workarea } - for i, cl in pairs(cls) do + for _, cl in pairs(cls) do if cl ~= c and cl.type ~= "desktop" and (client.floating.get(cl) or curlay == layout.suit.floating) then areas = area_remove(areas, get_area(cl)) end @@ -158,7 +158,7 @@ function placement.no_overlap(c) -- Look for available space local found = false local new = { x = geometry.x, y = geometry.y, width = 0, height = 0 } - for i, r in ipairs(areas) do + for _, r in ipairs(areas) do if r.width >= geometry.width and r.height >= geometry.height and r.width * r.height > new.width * new.height then @@ -179,7 +179,7 @@ function placement.no_overlap(c) -- We did not find an area with enough space for our size: -- just take the biggest available one and go in if not found then - for i, r in ipairs(areas) do + for _, r in ipairs(areas) do if r.width * r.height > new.width * new.height then new = r end @@ -197,7 +197,7 @@ end -- @param c The client. -- @return The new client geometry. function placement.under_mouse(c) - local c = c or capi.client.focus + c = c or capi.client.focus local c_geometry = get_area(c) local m_coords = capi.mouse.coords() return c:geometry({ x = m_coords.x - c_geometry.width / 2, @@ -220,8 +220,10 @@ function placement.next_to_mouse(c, offset) local m_coords = capi.mouse.coords() local screen_geometry = capi.screen[capi.mouse.screen].workarea + local x, y + -- Prefer it to be on the right. - local x = m_coords.x + offset + x = m_coords.x + offset if x + c_width > screen_geometry.width then -- Then to the left. x = m_coords.x - c_width - offset @@ -245,7 +247,7 @@ end -- @param[opt] p The parent (nil for screen centering). -- @return The new client geometry. function placement.centered(c, p) - local c = c or capi.client.focus + c = c or capi.client.focus local c_geometry = get_area(c) local screen = c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y) local s_geometry @@ -263,7 +265,7 @@ end -- @param[opt] p The parent (nil for screen centering). -- @return The new client geometry. function placement.center_horizontal(c, p) - local c = c or capi.client.focus + c = c or capi.client.focus local c_geometry = get_area(c) local screen = c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y) local s_geometry @@ -280,7 +282,7 @@ end -- @param[opt] p The parent (nil for screen centering). -- @return The new client geometry. function placement.center_vertical(c, p) - local c = c or capi.client.focus + c = c or capi.client.focus local c_geometry = get_area(c) local screen = c.screen or a_screen.getbycoord(c_geometry.x, c_geometry.y) local s_geometry diff --git a/lib/awful/prompt.lua b/lib/awful/prompt.lua index 7223af95b..91b745a04 100644 --- a/lib/awful/prompt.lua +++ b/lib/awful/prompt.lua @@ -290,9 +290,9 @@ function prompt.run(args, textbox, exe_callback, completion_callback, history_pa end -- Build the hook map - for k,v in ipairs(args.hooks or {}) do + for _,v in ipairs(args.hooks or {}) do if #v == 3 then - local mods,key,callback = unpack(v) + local _,key,callback = unpack(v) if type(callback) == "function" then hooks[key] = hooks[key] or {} hooks[key][#hooks[key]+1] = v @@ -332,7 +332,7 @@ function prompt.run(args, textbox, exe_callback, completion_callback, history_pa if event ~= "press" then return end -- Convert index array to hash table local mod = {} - for k, v in ipairs(modifiers) do mod[v] = true end + for _, v in ipairs(modifiers) do mod[v] = true end -- Call the user specified callback. If it returns true as -- the first result then return from the function. Treat the @@ -360,10 +360,10 @@ function prompt.run(args, textbox, exe_callback, completion_callback, history_pa -- User defined cases if hooks[key] then - for k,v in ipairs(hooks[key]) do + for _,v in ipairs(hooks[key]) do if #modifiers == #v[1] then local match = true - for k2,v2 in ipairs(v[1]) do + for _,v2 in ipairs(v[1]) do match = match and mod[v2] end if match or #modifiers == 0 then @@ -489,19 +489,19 @@ function prompt.run(args, textbox, exe_callback, completion_callback, history_pa elseif key == "w" or key == "BackSpace" then local wstart = 1 local wend = 1 - local cword_start = 1 - local cword_end = 1 + local cword_start_pos = 1 + local cword_end_pos = 1 while wend < cur_pos do wend = command:find("[{[(,.:;_-+=@/ ]", wstart) if not wend then wend = #command + 1 end if cur_pos >= wstart and cur_pos <= wend + 1 then - cword_start = wstart - cword_end = cur_pos - 1 + cword_start_pos = wstart + cword_end_pos = cur_pos - 1 break end wstart = wend + 1 end - command = command:sub(1, cword_start - 1) .. command:sub(cword_end + 1) + command = command:sub(1, cword_start_pos - 1) .. command:sub(cword_end_pos + 1) cur_pos = cword_start elseif key == "Delete" then -- delete from history only if: @@ -531,7 +531,7 @@ function prompt.run(args, textbox, exe_callback, completion_callback, history_pa elseif key == "d" then command = command:sub(1, cur_pos - 1) .. command:sub(cword_end(command, cur_pos)) elseif key == "BackSpace" then - wstart = cword_start(command, cur_pos) + local wstart = cword_start(command, cur_pos) command = command:sub(1, wstart - 1) .. command:sub(cur_pos) cur_pos = wstart end diff --git a/lib/awful/remote.lua b/lib/awful/remote.lua index 0f5188fab..d2b6bd959 100644 --- a/lib/awful/remote.lua +++ b/lib/awful/remote.lua @@ -9,11 +9,11 @@ -- Grab environment we need require("awful.dbus") -local load = loadstring or load -- v5.1 - loadstring, v5.2 - load +local load = loadstring or load -- luacheck: globals loadstring (compatibility with Lua 5.1) local tostring = tostring local ipairs = ipairs 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 dbus = dbus local type = type diff --git a/lib/awful/rules.lua b/lib/awful/rules.lua index 87b1c23e4..26abc33e3 100644 --- a/lib/awful/rules.lua +++ b/lib/awful/rules.lua @@ -213,6 +213,7 @@ function rules.execute(c, props, callbacks) c:geometry(geo); elseif property == "focus" then -- This will be handled below + (function() end)() -- I haven't found a nice way to silence luacheck here elseif type(c[property]) == "function" then c[property](c, value) else @@ -222,7 +223,7 @@ function rules.execute(c, props, callbacks) -- Apply all callbacks. if callbacks then - for i, callback in pairs(callbacks) do + for _, callback in pairs(callbacks) do callback(c) end end diff --git a/lib/awful/spawn.lua b/lib/awful/spawn.lua index 09a0bd0f3..9b5bd29e4 100644 --- a/lib/awful/spawn.lua +++ b/lib/awful/spawn.lua @@ -110,7 +110,7 @@ function spawn.with_line_callback(cmd, callbacks) local stdout_callback, stderr_callback, done_callback, exit_callback = callbacks.stdout, callbacks.stderr, callbacks.output_done, callbacks.exit local have_stdout, have_stderr = stdout_callback ~= nil, stderr_callback ~= nil - local pid, sn_id, stdin, stdout, stderr = capi.awesome.spawn(cmd, + local pid, _, stdin, stdout, stderr = capi.awesome.spawn(cmd, false, false, have_stdout, have_stderr, exit_callback) if type(pid) == "string" then -- Error diff --git a/lib/awful/tag.lua b/lib/awful/tag.lua index 2c44f7f8d..7ebcc61a4 100644 --- a/lib/awful/tag.lua +++ b/lib/awful/tag.lua @@ -10,9 +10,7 @@ -- Grab environment we need local util = require("awful.util") local ascreen = require("awful.screen") -local timer = require("gears.timer") local beautiful = require("beautiful") -local tostring = tostring local pairs = pairs local ipairs = ipairs local table = table @@ -46,7 +44,7 @@ tag.history.limit = 20 -- @param target_tag The tag that should be moved. If null, the currently -- selected tag is used. function tag.move(new_index, target_tag) - local target_tag = target_tag or tag.selected() + target_tag = target_tag or tag.selected() local scr = tag.getscreen(target_tag) local tmp_tags = tag.gettags(scr) @@ -121,7 +119,7 @@ end -- @param layout The layout or layout table to set for this tags by default. -- @return A table with all created tags. function tag.new(names, screen, layout) - local screen = screen or 1 + screen = screen or 1 local tags = {} for id, name in ipairs(names) do table.insert(tags, id, tag.add(name, {screen = screen, @@ -158,7 +156,7 @@ end -- history or select the first tag on the screen. function tag.delete(target_tag, fallback_tag) -- abort if no tag is passed or currently selected - local target_tag = target_tag or tag.selected() + target_tag = target_tag or tag.selected() if target_tag == nil or target_tag.activated == false then return end local target_scr = tag.getscreen(target_tag) @@ -167,7 +165,6 @@ function tag.delete(target_tag, fallback_tag) local ntags = #tags -- We can't use the target tag as a fallback. - local fallback_tag = fallback_tag if fallback_tag == target_tag then return end -- No fallback_tag provided, try and get one. @@ -292,7 +289,7 @@ end -- @return A table with all available tags function tag.gettags(s) local tags = {} - for i, t in ipairs(root.tags()) do + for _, t in ipairs(root.tags()) do if tag.getscreen(t) == s then table.insert(tags, t) end @@ -315,7 +312,7 @@ function tag.setscreen(s, t) s, t = t, s end - local s = s or ascreen.focused() + s = s or ascreen.focused() local sel = tag.selected local old_screen = tag.getproperty(t, "screen") if s == old_screen then return end @@ -327,15 +324,15 @@ function tag.setscreen(s, t) tag.setproperty(t, "screen", s, true) -- Make sure the client's screen matches its tags - for k,c in ipairs(t:clients()) do + for _,c in ipairs(t:clients()) do c.screen = s --Move all clients c:tags({t}) end -- Update all indexes for _,screen in ipairs {old_screen, s} do - for i,t in ipairs(tag.gettags(screen)) do - tag.setproperty(t, "index", i, true) + for i,t2 in ipairs(tag.gettags(screen)) do + tag.setproperty(t2, "index", i, true) end end @@ -349,7 +346,7 @@ end -- @param[opt] t tag object -- @return Screen number function tag.getscreen(t) - local t = t or tag.selected() + t = t or tag.selected() return tag.getproperty(t, "screen") end @@ -360,7 +357,7 @@ function tag.selectedlist(s) local screen = s or ascreen.focused() local tags = tag.gettags(screen) local vtags = {} - for i, t in pairs(tags) do + for _, t in pairs(tags) do if t.selected then vtags[#vtags + 1] = t end @@ -378,7 +375,7 @@ end -- @param mwfact Master width factor. -- @param t The tag to modify, if null tag.selected() is used. function tag.setmwfact(mwfact, t) - local t = t or tag.selected() + t = t or tag.selected() if mwfact >= 0 and mwfact <= 1 then tag.setproperty(t, "mwfact", mwfact, true) end @@ -394,7 +391,7 @@ end --- Get master width factor. -- @param[opt] t The tag. function tag.getmwfact(t) - local t = t or tag.selected() + t = t or tag.selected() return tag.getproperty(t, "mwfact") or 0.5 end @@ -438,7 +435,7 @@ end -- @param useless_gap The spacing between clients -- @param t The tag to modify, if null tag.selected() is used. function tag.setgap(useless_gap, t) - local t = t or tag.selected() + t = t or tag.selected() if useless_gap >= 0 then tag.setproperty(t, "useless_gap", useless_gap, true) end @@ -457,7 +454,7 @@ end -- return 0 for a single client. You can override this function to change -- this behavior. function tag.getgap(t, numclients) - local t = t or tag.selected() + t = t or tag.selected() if numclients == 1 then return 0 end @@ -470,7 +467,7 @@ end -- "mwfact" (fill only an area inside the master width factor) -- @tparam[opt=tag.selected()] tag t The tag to modify function tag.setmfpol(policy, t) - local t = t or tag.selected() + t = t or tag.selected() tag.setproperty(t, "master_fill_policy", policy, true) end @@ -491,7 +488,7 @@ end -- "expand" (fill all the available workarea, default one) or -- "mwfact" (fill only an area inside the master width factor) function tag.getmfpol(t) - local t = t or tag.selected() + t = t or tag.selected() return tag.getproperty(t, "master_fill_policy") or "expand" end @@ -499,7 +496,7 @@ end -- @param nmaster The number of master windows. -- @param[opt] t The tag. function tag.setnmaster(nmaster, t) - local t = t or tag.selected() + t = t or tag.selected() if nmaster >= 0 then tag.setproperty(t, "nmaster", nmaster, true) end @@ -508,7 +505,7 @@ end --- Get the number of master windows. -- @param[opt] t The tag. function tag.getnmaster(t) - local t = t or tag.selected() + t = t or tag.selected() return tag.getproperty(t, "nmaster") or 1 end @@ -542,14 +539,14 @@ end -- @param icon the icon to set, either path or image object -- @param _tag the tag function tag.seticon(icon, _tag) - local _tag = _tag or tag.selected() + _tag = _tag or tag.selected() tag.setproperty(_tag, "icon", icon, true) end --- Get the tag icon -- @param _tag the tag function tag.geticon(_tag) - local _tag = _tag or tag.selected() + _tag = _tag or tag.selected() return tag.getproperty(_tag, "icon") end @@ -557,7 +554,7 @@ end -- @param ncol The number of column. -- @param t The tag to modify, if null tag.selected() is used. function tag.setncol(ncol, t) - local t = t or tag.selected() + t = t or tag.selected() if ncol >= 1 then tag.setproperty(t, "ncol", ncol, true) end @@ -566,7 +563,7 @@ end --- Get number of column windows. -- @param[opt] t The tag. function tag.getncol(t) - local t = t or tag.selected() + t = t or tag.selected() return tag.getproperty(t, "ncol") or 1 end @@ -601,7 +598,7 @@ end -- @tparam[opt] int screen The screen number. function tag.viewnone(screen) local tags = tag.gettags(screen or ascreen.focused()) - for i, t in pairs(tags) do + for _, t in pairs(tags) do t.selected = false end end @@ -610,10 +607,10 @@ end -- @param i The relative index to see. -- @param[opt] screen The screen number. function tag.viewidx(i, screen) - local screen = screen or ascreen.focused() + screen = screen or ascreen.focused() local tags = tag.gettags(screen) local showntags = {} - for k, t in ipairs(tags) do + for _, t in ipairs(tags) do if not tag.getproperty(t, "hide") then table.insert(showntags, t) end @@ -632,7 +629,7 @@ end -- @param query_tag The tag object to find. [selected()] -- @return The index of the tag, nil if the tag is not found. function tag.getidx(query_tag) - local query_tag = query_tag or tag.selected() + query_tag = query_tag or tag.selected() if query_tag == nil then return end for i, t in ipairs(tag.gettags(tag.getscreen(query_tag))) do @@ -675,7 +672,7 @@ end -- @param tags A table with tags to view only. -- @param[opt] screen The screen number of the tags. function tag.viewmore(tags, screen) - local screen = screen or ascreen.focused() + screen = screen or ascreen.focused() local screen_tags = tag.gettags(screen) for _, _tag in ipairs(screen_tags) do if not util.table.hasitem(tags, _tag) then @@ -738,7 +735,7 @@ end -- @param c The client to tag. function tag.withcurrent(c) local tags = {} - for k, t in ipairs(c:tags()) do + for _, t in ipairs(c:tags()) do if tag.getscreen(t) == c.screen then table.insert(tags, t) end @@ -755,7 +752,7 @@ function tag.withcurrent(c) end local function attached_connect_signal_screen(screen, sig, func) - capi.tag.connect_signal(sig, function(_tag, ...) + capi.tag.connect_signal(sig, function(_tag) if tag.getscreen(_tag) == screen then func(_tag) end @@ -792,7 +789,7 @@ capi.client.connect_signal("manage", function(c) end) -- Keep track of the number of urgent clients. -local function update_urgent(c, t, modif) +local function update_urgent(t, modif) local count = tag.getproperty(t, "urgent_count") or 0 count = (count + modif) >= 0 and (count + modif) or 0 tag.setproperty(t, "urgent" , count > 0) @@ -802,21 +799,21 @@ end -- Update the urgent counter when a client is tagged. local function client_tagged(c, t) if c.urgent then - update_urgent(c, t, 1) + update_urgent(t, 1) end end -- Update the urgent counter when a client is untagged. local function client_untagged(c, t) if c.urgent then - update_urgent(c, t, -1) + update_urgent(t, -1) end end -- Count the urgent clients. local function urgent_callback(c) - for k,t in ipairs(c:tags()) do - update_urgent(c, t, c.urgent and 1 or -1) + for _,t in ipairs(c:tags()) do + update_urgent(t, c.urgent and 1 or -1) end end diff --git a/lib/awful/titlebar.lua b/lib/awful/titlebar.lua index aedd9aef6..d64b49e54 100644 --- a/lib/awful/titlebar.lua +++ b/lib/awful/titlebar.lua @@ -14,9 +14,7 @@ local abutton = require("awful.button") local aclient = require("awful.client") local atooltip = require("awful.tooltip") local beautiful = require("beautiful") -local object = require("gears.object") local drawable = require("wibox.drawable") -local base = require("wibox.widget.base") local imagebox = require("wibox.widget.imagebox") local textbox = require("wibox.widget.textbox") local capi = { @@ -72,7 +70,7 @@ end -- can be configured via e.g. "bg_normal" and "bg_focus". -- @name titlebar local function new(c, args) - local args = args or {} + args = args or {} local position = args.position or "top" local size = args.size or util.round(beautiful.get_font_height(args.font) * 1.5) local d = get_titlebar_function(c, position)(c, size) @@ -92,10 +90,10 @@ local function new(c, args) } ret = drawable(d, context, "awful.titlebar") local function update_colors() - local args = bars[position].args - ret:set_bg(get_color("bg", c, args)) - ret:set_fg(get_color("fg", c, args)) - ret:set_bgimage(get_color("bgimage", c, args)) + local args_ = bars[position].args + ret:set_bg(get_color("bg", c, args_)) + ret:set_fg(get_color("fg", c, args_)) + ret:set_bgimage(get_color("bgimage", c, args_)) end bars[position] = { @@ -126,7 +124,7 @@ end -- @param[opt] position The position of the titlebar. Must be one of "left", -- "right", "top", "bottom". Default is "top". function titlebar.show(c, position) - local position = position or "top" + position = position or "top" local bars = all_titlebars[c] local data = bars and bars[position] local args = data and data.args @@ -138,7 +136,7 @@ end -- @param[opt] position The position of the titlebar. Must be one of "left", -- "right", "top", "bottom". Default is "top". function titlebar.hide(c, position) - local position = position or "top" + position = position or "top" get_titlebar_function(c, position)(c, 0) end @@ -147,8 +145,8 @@ end -- @param[opt] position The position of the titlebar. Must be one of "left", -- "right", "top", "bottom". Default is "top". function titlebar.toggle(c, position) - local position = position or "top" - local drawable, size = get_titlebar_function(c, position)(c) + position = position or "top" + local _, size = get_titlebar_function(c, position)(c) if size == 0 then titlebar.show(c, position) else @@ -265,11 +263,11 @@ end --- Create a new maximize button for a client. -- @param c The client for which the button is wanted. function titlebar.widget.maximizedbutton(c) - local widget = titlebar.widget.button(c, "maximized", function(c) - return c.maximized_horizontal or c.maximized_vertical - end, function(c, state) - c.maximized_horizontal = not state - c.maximized_vertical = not state + local widget = titlebar.widget.button(c, "maximized", function(cl) + return cl.maximized_horizontal or cl.maximized_vertical + end, function(cl, state) + cl.maximized_horizontal = not state + cl.maximized_vertical = not state end) c:connect_signal("property::maximized_vertical", widget.update) c:connect_signal("property::maximized_horizontal", widget.update) @@ -279,7 +277,7 @@ end --- Create a new minimize button for a client. -- @param c The client for which the button is wanted. function titlebar.widget.minimizebutton(c) - local widget = titlebar.widget.button(c, "minimize", function() return c.minimized end, function(c) c.minimized = not c.minimized end) + local widget = titlebar.widget.button(c, "minimize", function(cl) return cl.minimized end, function(cl) cl.minimized = not cl.minimized end) c:connect_signal("property::minimized", widget.update) return widget end @@ -287,13 +285,13 @@ end --- Create a new closing button for a client. -- @param c The client for which the button is wanted. function titlebar.widget.closebutton(c) - return titlebar.widget.button(c, "close", function() return "" end, function(c) c:kill() end) + return titlebar.widget.button(c, "close", function() return "" end, function(cl) cl:kill() end) end --- Create a new ontop button for a client. -- @param c The client for which the button is wanted. function titlebar.widget.ontopbutton(c) - local widget = titlebar.widget.button(c, "ontop", function(c) return c.ontop end, function(c, state) c.ontop = not state end) + local widget = titlebar.widget.button(c, "ontop", function(cl) return cl.ontop end, function(cl, state) cl.ontop = not state end) c:connect_signal("property::ontop", widget.update) return widget end @@ -301,7 +299,7 @@ end --- Create a new sticky button for a client. -- @param c The client for which the button is wanted. function titlebar.widget.stickybutton(c) - local widget = titlebar.widget.button(c, "sticky", function(c) return c.sticky end, function(c, state) c.sticky = not state end) + local widget = titlebar.widget.button(c, "sticky", function(cl) return cl.sticky end, function(cl, state) cl.sticky = not state end) c:connect_signal("property::sticky", widget.update) return widget end diff --git a/lib/awful/tooltip.lua b/lib/awful/tooltip.lua index 83899f3da..72af21fed 100644 --- a/lib/awful/tooltip.lua +++ b/lib/awful/tooltip.lua @@ -41,7 +41,6 @@ ------------------------------------------------------------------------- local mouse = mouse -local screen = screen local timer = require("gears.timer") local wibox = require("wibox") local a_placement = require("awful.placement") diff --git a/lib/awful/util.lua b/lib/awful/util.lua index 4157c32aa..cd61fea5c 100644 --- a/lib/awful/util.lua +++ b/lib/awful/util.lua @@ -11,14 +11,13 @@ local os = os local io = io local assert = assert -local load = loadstring or load -- v5.1 - loadstring, v5.2 - load +local load = loadstring or load -- luacheck: globals loadstring (compatibility with Lua 5.1) local loadfile = loadfile local debug = debug local pairs = pairs local ipairs = ipairs local type = type local rtable = table -local pairs = pairs local string = string local lgi = require("lgi") local Gio = require("lgi").Gio @@ -195,8 +194,8 @@ end -- @tparam[opt] string size The size. If this is specified, subdirectories `x` -- of the dirs are searched first. function util.geticonpath(iconname, exts, dirs, size) - local exts = exts or { 'png', 'gif' } - local dirs = dirs or { '/usr/share/pixmaps/', '/usr/share/icons/hicolor/' } + exts = exts or { 'png', 'gif' } + dirs = dirs or { '/usr/share/pixmaps/', '/usr/share/icons/hicolor/' } local icontypes = { 'apps', 'actions', 'categories', 'emblems', 'mimetypes', 'status', 'devices', 'extras', 'places', 'stock' } for _, d in pairs(dirs) do @@ -385,7 +384,7 @@ end -- @return A new table containing all keys from the arguments. function util.table.join(...) local ret = {} - for i, t in pairs({...}) do + for _, t in pairs({...}) do if t then for k, v in pairs(t) do if type(k) == "number" then @@ -422,7 +421,7 @@ end -- @treturn table A packed table with all numeric keys function util.table.from_sparse(t) local keys= {} - for k,v in pairs(t) do + for k in pairs(t) do if type(k) == "number" then keys[#keys+1] = k end @@ -462,7 +461,7 @@ function util.linewrap(text, width, indent) local pos = 1 return text:gsub("(%s+)()(%S+)()", - function(sp, st, word, fi) + function(_, st, word, fi) if fi - pos > width then pos = st return "\n" .. string.rep(" ", indent) .. word @@ -532,7 +531,7 @@ end -- @param deep Create a deep clone? (default: true) -- @return a clone of t function util.table.clone(t, deep) - local deep = deep == nil and true or deep + deep = deep == nil and true or deep local c = { } for k, v in pairs(t) do if deep and type(v) == "table" then @@ -592,7 +591,7 @@ end -- Generate a pattern matching expression that ignores case. -- @param s Original pattern matching expression. function util.query_to_pattern(q) - s = util.quote_pattern(q) + local s = util.quote_pattern(q) -- Poor man's case-insensitive character matching. s = string.gsub(s, "%a", function (c) diff --git a/lib/awful/wibox.lua b/lib/awful/wibox.lua index 462afe448..7d7978b2c 100644 --- a/lib/awful/wibox.lua +++ b/lib/awful/wibox.lua @@ -32,11 +32,11 @@ local awfulwibox = { mt = {} } local wiboxes = {} --- Get a wibox position if it has been set, or return top. --- @param wibox The wibox +-- @param wb The wibox -- @return The wibox position. -function awfulwibox.get_position(wibox) +function awfulwibox.get_position(wb) for _, wprop in ipairs(wiboxes) do - if wprop.wibox == wibox then + if wprop.wibox == wb then return wprop.position end end @@ -44,28 +44,28 @@ function awfulwibox.get_position(wibox) end --- Put a wibox on a screen at this position. --- @param wibox The wibox to attach. +-- @param wb The wibox to attach. -- @param position The position: top, bottom left or right. -- @param screen If the wibox it not attached to a screen, specified on which -- screen the position should be set. -function awfulwibox.set_position(wibox, position, screen) +function awfulwibox.set_position(wb, position, screen) local area = capi.screen[screen].geometry -- The "length" of a wibox is always chosen to be the optimal size -- (non-floating). -- The "width" of a wibox is kept if it exists. if position == "right" then - wibox.x = area.x + area.width - (wibox.width + 2 * wibox.border_width) + wb.x = area.x + area.width - (wb.width + 2 * wb.border_width) elseif position == "left" then - wibox.x = area.x + wb.x = area.x elseif position == "bottom" then - wibox.y = (area.y + area.height) - (wibox.height + 2 * wibox.border_width) + wb.y = (area.y + area.height) - (wb.height + 2 * wb.border_width) elseif position == "top" then - wibox.y = area.y + wb.y = area.y end for _, wprop in ipairs(wiboxes) do - if wprop.wibox == wibox then + if wprop.wibox == wb then wprop.position = position break end @@ -79,23 +79,23 @@ local function update_all_wiboxes_position() end end -local function call_wibox_position_hook_on_prop_update(w) +local function call_wibox_position_hook_on_prop_update() update_all_wiboxes_position() end -local function wibox_update_strut(wibox) +local function wibox_update_strut(wb) for _, wprop in ipairs(wiboxes) do - if wprop.wibox == wibox then - if not wibox.visible then - wibox:struts { left = 0, right = 0, bottom = 0, top = 0 } + if wprop.wibox == wb then + if not wb.visible then + wb:struts { left = 0, right = 0, bottom = 0, top = 0 } elseif wprop.position == "top" then - wibox:struts { left = 0, right = 0, bottom = 0, top = wibox.height + 2 * wibox.border_width } + wb:struts { left = 0, right = 0, bottom = 0, top = wb.height + 2 * wb.border_width } elseif wprop.position == "bottom" then - wibox:struts { left = 0, right = 0, bottom = wibox.height + 2 * wibox.border_width, top = 0 } + wb:struts { left = 0, right = 0, bottom = wb.height + 2 * wb.border_width, top = 0 } elseif wprop.position == "left" then - wibox:struts { left = wibox.width + 2 * wibox.border_width, right = 0, bottom = 0, top = 0 } + wb:struts { left = wb.width + 2 * wb.border_width, right = 0, bottom = 0, top = 0 } elseif wprop.position == "right" then - wibox:struts { left = 0, right = wibox.width + 2 * wibox.border_width, bottom = 0, top = 0 } + wb:struts { left = 0, right = wb.width + 2 * wb.border_width, bottom = 0, top = 0 } end break end @@ -105,10 +105,10 @@ end --- Attach a wibox to a screen. -- If a wibox is attached, it will be automatically be moved when other wiboxes -- will be attached. --- @param wibox The wibox to attach. +-- @param wb The wibox to attach. -- @param position The position of the wibox: top, bottom, left or right. -- @param screen TODO, this seems to be unused -function awfulwibox.attach(wibox, position, screen) +function awfulwibox.attach(wb, position, screen) -- Store wibox as attached in a weak-valued table local wibox_prop_table -- Start from end since we sometimes remove items @@ -117,7 +117,7 @@ function awfulwibox.attach(wibox, position, screen) -- If they did, remove their entries if wiboxes[i].wibox == nil then table.remove(wiboxes, i) - elseif wiboxes[i].wibox == wibox then + elseif wiboxes[i].wibox == wb then wibox_prop_table = wiboxes[i] -- We could break here, but well, let's check if there is no other -- table with their wiboxes been garbage collected. @@ -125,81 +125,81 @@ function awfulwibox.attach(wibox, position, screen) end if not wibox_prop_table then - table.insert(wiboxes, setmetatable({ wibox = wibox, position = position, screen = screen }, { __mode = 'v' })) + table.insert(wiboxes, setmetatable({ wibox = wb, position = position, screen = screen }, { __mode = 'v' })) else wibox_prop_table.position = position end - wibox:connect_signal("property::width", wibox_update_strut) - wibox:connect_signal("property::height", wibox_update_strut) - wibox:connect_signal("property::visible", wibox_update_strut) + wb:connect_signal("property::width", wibox_update_strut) + wb:connect_signal("property::height", wibox_update_strut) + wb:connect_signal("property::visible", wibox_update_strut) - wibox:connect_signal("property::width", call_wibox_position_hook_on_prop_update) - wibox:connect_signal("property::height", call_wibox_position_hook_on_prop_update) - wibox:connect_signal("property::visible", call_wibox_position_hook_on_prop_update) - wibox:connect_signal("property::border_width", call_wibox_position_hook_on_prop_update) + wb:connect_signal("property::width", call_wibox_position_hook_on_prop_update) + wb:connect_signal("property::height", call_wibox_position_hook_on_prop_update) + wb:connect_signal("property::visible", call_wibox_position_hook_on_prop_update) + wb:connect_signal("property::border_width", call_wibox_position_hook_on_prop_update) end --- Align a wibox. --- @param wibox The wibox. +-- @param wb The wibox. -- @param align The alignment: left, right or center. -- @param screen If the wibox is not attached to any screen, you can specify the -- screen where to align. Otherwise 1 is assumed. -function awfulwibox.align(wibox, align, screen) - local position = awfulwibox.get_position(wibox) +function awfulwibox.align(wb, align, screen) + local position = awfulwibox.get_position(wb) local area = capi.screen[screen].workarea if position == "right" then if align == "right" then - wibox.y = area.y + wb.y = area.y elseif align == "left" then - wibox.y = area.y + area.height - (wibox.height + 2 * wibox.border_width) + wb.y = area.y + area.height - (wb.height + 2 * wb.border_width) elseif align == "center" then - wibox.y = area.y + round((area.height - wibox.height) / 2) + wb.y = area.y + round((area.height - wb.height) / 2) end elseif position == "left" then if align == "right" then - wibox.y = (area.y + area.height) - (wibox.height + 2 * wibox.border_width) + wb.y = (area.y + area.height) - (wb.height + 2 * wb.border_width) elseif align == "left" then - wibox.y = area.y + wb.y = area.y elseif align == "center" then - wibox.y = area.y + round((area.height - wibox.height) / 2) + wb.y = area.y + round((area.height - wb.height) / 2) end elseif position == "bottom" then if align == "right" then - wibox.x = area.x + area.width - (wibox.width + 2 * wibox.border_width) + wb.x = area.x + area.width - (wb.width + 2 * wb.border_width) elseif align == "left" then - wibox.x = area.x + wb.x = area.x elseif align == "center" then - wibox.x = area.x + round((area.width - wibox.width) / 2) + wb.x = area.x + round((area.width - wb.width) / 2) end elseif position == "top" then if align == "right" then - wibox.x = area.x + area.width - (wibox.width + 2 * wibox.border_width) + wb.x = area.x + area.width - (wb.width + 2 * wb.border_width) elseif align == "left" then - wibox.x = area.x + wb.x = area.x elseif align == "center" then - wibox.x = area.x + round((area.width - wibox.width) / 2) + wb.x = area.x + round((area.width - wb.width) / 2) end end -- Update struts regardless of changes - wibox_update_strut(wibox) + wibox_update_strut(wb) end --- Stretch a wibox so it takes all screen width or height. --- @param wibox The wibox. +-- @param wb The wibox. -- @param screen The screen to stretch on, or the wibox screen. -function awfulwibox.stretch(wibox, screen) +function awfulwibox.stretch(wb, screen) if screen then - local position = awfulwibox.get_position(wibox) + local position = awfulwibox.get_position(wb) local area = capi.screen[screen].workarea if position == "right" or position == "left" then - wibox.height = area.height - (2 * wibox.border_width) - wibox.y = area.y + wb.height = area.height - (2 * wb.border_width) + wb.y = area.y else - wibox.width = area.width - (2 * wibox.border_width) - wibox.x = area.x + wb.width = area.width - (2 * wb.border_width) + wb.x = area.x end end end @@ -213,7 +213,7 @@ end -- If not specified, 1 is assumed. -- @return The wibox created. function awfulwibox.new(arg) - local arg = arg or {} + arg = arg or {} local position = arg.position or "top" local has_to_stretch = true local screen = arg.screen or 1