From c75741c578234a711f596dc8fed257dacfc3e4f3 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 7 Feb 2016 15:24:08 +0100 Subject: [PATCH] Fix luacheck warnings for the rest of awful This fixes *most* luacheck warnings in awful. However, some non-trivial ones remain for latter. Signed-off-by: Uli Schlachter --- lib/awful/client/shape.lua | 12 ++++----- lib/awful/hotkeys_popup/widget.lua | 2 +- lib/awful/layout/init.lua | 4 +-- lib/awful/layout/suit/corner.lua | 2 +- lib/awful/layout/suit/fair.lua | 6 ++--- lib/awful/layout/suit/floating.lua | 3 +-- lib/awful/layout/suit/magnifier.lua | 5 ++-- lib/awful/layout/suit/max.lua | 3 +-- lib/awful/layout/suit/tile.lua | 39 +++++++++++++---------------- lib/awful/mouse/finder.lua | 3 --- lib/awful/mouse/init.lua | 28 ++++++++++----------- 11 files changed, 47 insertions(+), 60 deletions(-) diff --git a/lib/awful/client/shape.lua b/lib/awful/client/shape.lua index 2f0fe1dab..e1280e0e0 100644 --- a/lib/awful/client/shape.lua +++ b/lib/awful/client/shape.lua @@ -20,11 +20,11 @@ shape.update = {} --- Get one of a client's shapes and transform it to include window decorations -- @client c The client whose shape should be retrieved --- @tparam string shape Either "bounding" or "clip" -function shape.get_transformed(c, shape) - local border = shape == "bounding" and c.border_width or 0 - local shape = surface.load_silently(c["client_shape_" .. shape], false) - if not shape then return end +-- @tparam string shape_name Either "bounding" or "clip" +function shape.get_transformed(c, shape_name) + local border = shape_name == "bounding" and c.border_width or 0 + local shape_img = surface.load_silently(c["client_shape_" .. shape_name], false) + if not shape_img then return end -- Get information about various sizes on the client local geom = c:geometry() @@ -44,7 +44,7 @@ function shape.get_transformed(c, shape) -- Draw the client's shape in the middle cr:set_operator(cairo.Operator.SOURCE) - cr:set_source_surface(shape, border + l, border + t) + cr:set_source_surface(shape_img, border + l, border + t) cr:rectangle(border + l, border + t, geom.width - l - r, geom.height - t - b) cr:fill() diff --git a/lib/awful/hotkeys_popup/widget.lua b/lib/awful/hotkeys_popup/widget.lua index 3e137def3..85d61076c 100644 --- a/lib/awful/hotkeys_popup/widget.lua +++ b/lib/awful/hotkeys_popup/widget.lua @@ -159,7 +159,7 @@ local function sort_hotkeys(target) for group, _ in pairs(group_list) do if target[group] then local sorted_table = {} - for index, key in pairs(target[group]) do + for _, key in pairs(target[group]) do table.insert(sorted_table, key) end table.sort( diff --git a/lib/awful/layout/init.lua b/lib/awful/layout/init.lua index 742658c6d..8921a9abe 100644 --- a/lib/awful/layout/init.lua +++ b/lib/awful/layout/init.lua @@ -75,7 +75,7 @@ function layout.inc(i, s, layouts) layouts, i, s = i, s, layouts end local t = tag.selected(s) - local layouts = layouts or layout.layouts + layouts = layouts or layout.layouts if t then local curlayout = layout.get(s) local curindex @@ -192,7 +192,7 @@ end -- @param _layout The layout. -- @return The layout name. function layout.getname(_layout) - local _layout = _layout or layout.get() + _layout = _layout or layout.get() return _layout.name end diff --git a/lib/awful/layout/suit/corner.lua b/lib/awful/layout/suit/corner.lua index 2024f5107..d8c672e04 100644 --- a/lib/awful/layout/suit/corner.lua +++ b/lib/awful/layout/suit/corner.lua @@ -109,7 +109,7 @@ local function do_corner(p, orientation) end for i, c in ipairs(cls) do - local g = nil + local g -- Handle master window if i == 1 then g = { diff --git a/lib/awful/layout/suit/fair.lua b/lib/awful/layout/suit/fair.lua index dcb3d3688..3291530c3 100644 --- a/lib/awful/layout/suit/fair.lua +++ b/lib/awful/layout/suit/fair.lua @@ -24,7 +24,7 @@ local function do_fair(p, orientation) end if #cls > 0 then - local rows, cols = 0, 0 + local rows, cols if #cls == 2 then rows, cols = 1, 2 else @@ -36,11 +36,11 @@ local function do_fair(p, orientation) k = k - 1 local g = {} - local row, col = 0, 0 + local row, col row = k % rows col = math.floor(k / rows) - local lrows, lcols = 0, 0 + local lrows, lcols if k >= rows * cols - rows then lrows = #cls - (rows * cols - rows) lcols = cols diff --git a/lib/awful/layout/suit/floating.lua b/lib/awful/layout/suit/floating.lua index d94672f35..b2037e43b 100644 --- a/lib/awful/layout/suit/floating.lua +++ b/lib/awful/layout/suit/floating.lua @@ -8,7 +8,6 @@ --------------------------------------------------------------------------- -- Grab environment we need -local math = math local ipairs = ipairs local capi = { @@ -44,7 +43,7 @@ function floating.mouse_resize_handler(c, corner, x, y) capi.mousegrabber.run(function (_mouse) _mouse.x = _mouse.x + coordinates_delta.x _mouse.y = _mouse.y + coordinates_delta.y - for k, v in ipairs(_mouse.buttons) do + for _, v in ipairs(_mouse.buttons) do if v then local ng prev_coords = { x =_mouse.x, y = _mouse.y } diff --git a/lib/awful/layout/suit/magnifier.lua b/lib/awful/layout/suit/magnifier.lua index 6f9bc7b01..324823691 100644 --- a/lib/awful/layout/suit/magnifier.lua +++ b/lib/awful/layout/suit/magnifier.lua @@ -32,7 +32,7 @@ function magnifier.mouse_resize_handler(c, corner, x, y) local prev_coords = {} capi.mousegrabber.run(function (_mouse) - for k, v in ipairs(_mouse.buttons) do + for _, v in ipairs(_mouse.buttons) do if v then prev_coords = { x =_mouse.x, y = _mouse.y } local dx = center_x - _mouse.x @@ -126,13 +126,12 @@ function magnifier.arrange(p) -- Then move clients that are after focused client. -- So the next focused window will be the one at the top of the screen. for k = 1, fidx - 1 do - local g = { + p.geometries[cls[k]] = { x = geometry.x, y = geometry.y, width = geometry.width, height = geometry.height } - p.geometries[cls[k]] = g geometry.y = geometry.y + geometry.height end end diff --git a/lib/awful/layout/suit/max.lua b/lib/awful/layout/suit/max.lua index 6313724c7..73603ab5d 100644 --- a/lib/awful/layout/suit/max.lua +++ b/lib/awful/layout/suit/max.lua @@ -9,7 +9,6 @@ -- Grab environment we need local pairs = pairs -local client = require("awful.client") local max = {} @@ -22,7 +21,7 @@ local function fmax(p, fs) area = p.workarea end - for k, c in pairs(p.clients) do + for _, c in pairs(p.clients) do local g = { x = area.x, y = area.y, diff --git a/lib/awful/layout/suit/tile.lua b/lib/awful/layout/suit/tile.lua index e8f0d3ee5..0071ff566 100644 --- a/lib/awful/layout/suit/tile.lua +++ b/lib/awful/layout/suit/tile.lua @@ -26,8 +26,8 @@ local tile = {} --- Jump mouse cursor to the client's corner when resizing it. tile.resize_jump_to_corner = true -local function mouse_resize_handler(c, corner, x, y, orientation) - local orientation = orientation or "tile" +local function mouse_resize_handler(c, _, _, _, orientation) + orientation = orientation or "tile" local wa = capi.screen[c.screen].workarea local mwfact = tag.getmwfact() local cursor @@ -87,47 +87,46 @@ local function mouse_resize_handler(c, corner, x, y, orientation) capi.mousegrabber.run(function (_mouse) _mouse.x = _mouse.x + coordinates_delta.x _mouse.y = _mouse.y + coordinates_delta.y - for k, v in ipairs(_mouse.buttons) do + for _, v in ipairs(_mouse.buttons) do if v then prev_coords = { x =_mouse.x, y = _mouse.y } local fact_x = (_mouse.x - wa.x) / wa.width local fact_y = (_mouse.y - wa.y) / wa.height - local mwfact - - local g = c:geometry() + local new_mwfact + local geom = c:geometry() -- we have to make sure we're not on the last visible client where we have to use different settings. local wfact local wfact_x, wfact_y - if (g.y+g.height+15) > (wa.y+wa.height) then - wfact_y = (g.y + g.height - _mouse.y) / wa.height + if (geom.y+geom.height+15) > (wa.y+wa.height) then + wfact_y = (geom.y + geom.height - _mouse.y) / wa.height else - wfact_y = (_mouse.y - g.y) / wa.height + wfact_y = (_mouse.y - geom.y) / wa.height end - if (g.x+g.width+15) > (wa.x+wa.width) then - wfact_x = (g.x + g.width - _mouse.x) / wa.width + if (geom.x+geom.width+15) > (wa.x+wa.width) then + wfact_x = (geom.x + geom.width - _mouse.x) / wa.width else - wfact_x = (_mouse.x - g.x) / wa.width + wfact_x = (_mouse.x - geom.x) / wa.width end if orientation == "tile" then - mwfact = fact_x + new_mwfact = fact_x wfact = wfact_y elseif orientation == "left" then - mwfact = 1 - fact_x + new_mwfact = 1 - fact_x wfact = wfact_y elseif orientation == "bottom" then - mwfact = fact_y + new_mwfact = fact_y wfact = wfact_x else - mwfact = 1 - fact_y + new_mwfact = 1 - fact_y wfact = wfact_x end - tag.setmwfact(math.min(math.max(mwfact, 0.01), 0.99), tag.selected(c.screen)) + tag.setmwfact(math.min(math.max(new_mwfact, 0.01), 0.99), tag.selected(c.screen)) client.setwfact(math.min(math.max(wfact,0.01), 0.99), c) return true end @@ -200,15 +199,11 @@ local function do_tile(param, orientation) orientation = orientation or "right" -- This handles all different orientations. - local height = "height" local width = "width" local x = "x" - local y = "y" if orientation == "top" or orientation == "bottom" then - height = "width" width = "height" x = "y" - y = "x" end local gs = param.geometries @@ -236,7 +231,7 @@ local function do_tile(param, orientation) local grow_master = tag.getmfpol(t) == "expand" -- this was easier than writing functions because there is a lot of data we need - for d = 1,2 do + for _ = 1,2 do if place_master and nmaster > 0 then local size = wa[width] if nother > 0 or not grow_master then diff --git a/lib/awful/mouse/finder.lua b/lib/awful/mouse/finder.lua index cb43692c3..c3985a7db 100644 --- a/lib/awful/mouse/finder.lua +++ b/lib/awful/mouse/finder.lua @@ -38,12 +38,9 @@ -- @module awful.mouse.finder ------------------------------------------------------------------------- -local mouse = mouse -local screen = screen local timer = require("gears.timer") local wibox = require("wibox") local a_placement = require("awful.placement") -local a_wibox = require("awful.wibox") local beautiful = require("beautiful") local setmetatable = setmetatable diff --git a/lib/awful/mouse/init.lua b/lib/awful/mouse/init.lua index 9d10c478d..daa662d6e 100644 --- a/lib/awful/mouse/init.lua +++ b/lib/awful/mouse/init.lua @@ -11,7 +11,6 @@ local layout = require("awful.layout") local tag = require("awful.tag") local aclient = require("awful.client") -local widget = require("awful.widget") local awibox = require("awful.wibox") local util = require("awful.util") local type = type @@ -99,14 +98,13 @@ end -- @param fixed_x True if the client isn't allowed to move in the x direction. -- @param fixed_y True if the client isn't allowed to move in the y direction. function mouse.client.snap(c, snap, x, y, fixed_x, fixed_y) - local snap = snap or 8 - local c = c or mouse.client.focus + snap = snap or 8 + c = c or mouse.client.focus local cur_geom = c:geometry() local geom = c:geometry() geom.width = geom.width + (2 * c.border_width) geom.height = geom.height + (2 * c.border_width) - local edge = "none" - local edge2 = "none" + local edge geom.x = x or geom.x geom.y = y or geom.y @@ -134,7 +132,7 @@ function mouse.client.snap(c, snap, x, y, fixed_x, fixed_y) geom.x = geom.x - (2 * c.border_width) geom.y = geom.y - (2 * c.border_width) - for k, snapper in ipairs(aclient.visible(c.screen)) do + for _, snapper in ipairs(aclient.visible(c.screen)) do if snapper ~= c then geom = snap_outside(geom, snapper:geometry(), snap) end @@ -159,7 +157,7 @@ end -- when moving the client has been finished. The client -- that has been moved will be passed to that function. function mouse.client.move(c, snap, finished_cb) - local c = c or capi.client.focus + c = c or capi.client.focus if not c or c.fullscreen @@ -178,7 +176,7 @@ function mouse.client.move(c, snap, finished_cb) local fixed_y = c.maximized_vertical capi.mousegrabber.run(function (_mouse) - for k, v in ipairs(_mouse.buttons) do + for _, v in ipairs(_mouse.buttons) do if v then local lay = layout.get(c.screen) if lay == layout.suit.floating or aclient.floating.get(c) then @@ -259,7 +257,7 @@ end --- Move the wibox under the cursor --@param w The wibox to move, or none to use that under the pointer function mouse.wibox.move(w) - local w = w or mouse.wibox_under_pointer() + w = w or mouse.wibox_under_pointer() if not w then return end local offset = { @@ -286,7 +284,7 @@ function mouse.wibox.move(w) end w.screen = capi.mouse.screen end - for k, v in ipairs(_mouse.buttons) do + for _, v in ipairs(_mouse.buttons) do if v then button_down = true end end if not button_down then @@ -302,7 +300,7 @@ end -- bottom_right. Default is auto, and auto find the nearest corner. -- @return Actual used corner and x and y coordinates. function mouse.client.corner(c, corner) - local c = c or capi.client.focus + c = c or capi.client.focus if not c then return end local g = c:geometry() @@ -346,7 +344,7 @@ end -- @param c The client to resize, or the focused one by default. -- @param corner The corner to grab on resize. Auto detected by default. function mouse.client.resize(c, corner) - local c = c or capi.client.focus + c = c or capi.client.focus if not c then return end @@ -358,12 +356,12 @@ function mouse.client.resize(c, corner) end local lay = layout.get(c.screen) - local corner, x, y = mouse.client.corner(c, corner) + local corner2, x, y = mouse.client.corner(c, corner) if lay == layout.suit.floating or aclient.floating.get(c) then - return layout.suit.floating.mouse_resize_handler(c, corner, x, y) + return layout.suit.floating.mouse_resize_handler(c, corner2, x, y) elseif lay.mouse_resize_handler then - return lay.mouse_resize_handler(c, corner, x, y) + return lay.mouse_resize_handler(c, corner2, x, y) end end