gears: Move awful.util.table to gears.table (#1641)

* Move table functions out of awful.util into new gears.table

* travis: Use v9999 prefix for full requests

Make sure no newly deprecated functions are used

* Move all `awful.util.table.*` calls to `gears.table.*` calls
Move table test functions from awful/util_spec to new gears/table_spec
Change awful.util.subsets call to gears.math.subsets in awful/key.lua
This commit is contained in:
Kevin Zander 2017-03-08 14:18:33 -06:00 committed by Emmanuel Lepage Vallée
parent e7822303d3
commit c3461b535c
52 changed files with 448 additions and 259 deletions

View File

@ -105,7 +105,12 @@ install:
# Determine custom version. # Determine custom version.
- export AWESOME_VERSION="${TRAVIS_BRANCH}-g$(git rev-parse --short HEAD)" - export AWESOME_VERSION="${TRAVIS_BRANCH}-g$(git rev-parse --short HEAD)"
- 'if [ "$TRAVIS_PULL_REQUEST" != false ]; then AWESOME_VERSION="${AWESOME_VERSION}-PR${TRAVIS_PULL_REQUEST}"; fi' - |
if [ "$TRAVIS_PULL_REQUEST" != false ] && [ "$TEST_PREV_COMMITS" = 1 ]; then
AWESOME_VERSION="${AWESOME_VERSION}-PR${TRAVIS_PULL_REQUEST}"
elif [ "$TRAVIS_PULL_REQUEST" != false ]; then
AWESOME_VERSION="v9999-PR${TRAVIS_PULL_REQUEST}";
fi
# function for codecov support # function for codecov support
- if [ "$DO_COVERAGE" = "codecov" ]; then travis_retry wget -O /tmp/codecov-bash https://codecov.io/bash; fi - if [ "$DO_COVERAGE" = "codecov" ]; then travis_retry wget -O /tmp/codecov-bash https://codecov.io/bash; fi
- | - |

View File

@ -127,7 +127,7 @@ mytextclock = wibox.widget.textclock()
-- Create a wibox for each screen and add it -- Create a wibox for each screen and add it
-- @TAGLIST_BUTTON@ -- @TAGLIST_BUTTON@
local taglist_buttons = awful.util.table.join( local taglist_buttons = gears.table.join(
awful.button({ }, 1, function(t) t:view_only() end), awful.button({ }, 1, function(t) t:view_only() end),
awful.button({ modkey }, 1, function(t) awful.button({ modkey }, 1, function(t)
if client.focus then if client.focus then
@ -145,7 +145,7 @@ local taglist_buttons = awful.util.table.join(
) )
-- @TASKLIST_BUTTON@ -- @TASKLIST_BUTTON@
local tasklist_buttons = awful.util.table.join( local tasklist_buttons = gears.table.join(
awful.button({ }, 1, function (c) awful.button({ }, 1, function (c)
if c == client.focus then if c == client.focus then
c.minimized = true c.minimized = true
@ -199,7 +199,7 @@ awful.screen.connect_for_each_screen(function(s)
-- Create an imagebox widget which will contains an icon indicating which layout we're using. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
-- We need one layoutbox per screen. -- We need one layoutbox per screen.
s.mylayoutbox = awful.widget.layoutbox(s) s.mylayoutbox = awful.widget.layoutbox(s)
s.mylayoutbox:buttons(awful.util.table.join( s.mylayoutbox:buttons(gears.table.join(
awful.button({ }, 1, function () awful.layout.inc( 1) end), awful.button({ }, 1, function () awful.layout.inc( 1) end),
awful.button({ }, 3, function () awful.layout.inc(-1) end), awful.button({ }, 3, function () awful.layout.inc(-1) end),
awful.button({ }, 4, function () awful.layout.inc( 1) end), awful.button({ }, 4, function () awful.layout.inc( 1) end),
@ -238,7 +238,7 @@ end)
-- {{{ Mouse bindings -- {{{ Mouse bindings
-- @DOC_ROOT_BUTTONS@ -- @DOC_ROOT_BUTTONS@
root.buttons(awful.util.table.join( root.buttons(gears.table.join(
awful.button({ }, 3, function () mymainmenu:toggle() end), awful.button({ }, 3, function () mymainmenu:toggle() end),
awful.button({ }, 4, awful.tag.viewnext), awful.button({ }, 4, awful.tag.viewnext),
awful.button({ }, 5, awful.tag.viewprev) awful.button({ }, 5, awful.tag.viewprev)
@ -247,7 +247,7 @@ root.buttons(awful.util.table.join(
-- {{{ Key bindings -- {{{ Key bindings
-- @DOC_GLOBAL_KEYBINDINGS@ -- @DOC_GLOBAL_KEYBINDINGS@
globalkeys = awful.util.table.join( globalkeys = gears.table.join(
awful.key({ modkey, }, "s", hotkeys_popup.show_help, awful.key({ modkey, }, "s", hotkeys_popup.show_help,
{description="show help", group="awesome"}), {description="show help", group="awesome"}),
awful.key({ modkey, }, "Left", awful.tag.viewprev, awful.key({ modkey, }, "Left", awful.tag.viewprev,
@ -348,7 +348,7 @@ globalkeys = awful.util.table.join(
) )
-- @DOC_CLIENT_KEYBINDINGS@ -- @DOC_CLIENT_KEYBINDINGS@
clientkeys = awful.util.table.join( clientkeys = gears.table.join(
awful.key({ modkey, }, "f", awful.key({ modkey, }, "f",
function (c) function (c)
c.fullscreen = not c.fullscreen c.fullscreen = not c.fullscreen
@ -397,7 +397,7 @@ clientkeys = awful.util.table.join(
-- Be careful: we use keycodes to make it work on any keyboard layout. -- Be careful: we use keycodes to make it work on any keyboard layout.
-- This should map on the top row of your keyboard, usually 1 to 9. -- This should map on the top row of your keyboard, usually 1 to 9.
for i = 1, 9 do for i = 1, 9 do
globalkeys = awful.util.table.join(globalkeys, globalkeys = gears.table.join(globalkeys,
-- View tag only. -- View tag only.
awful.key({ modkey }, "#" .. i + 9, awful.key({ modkey }, "#" .. i + 9,
function () function ()
@ -444,7 +444,7 @@ for i = 1, 9 do
end end
-- @DOC_CLIENT_BUTTONS@ -- @DOC_CLIENT_BUTTONS@
clientbuttons = awful.util.table.join( clientbuttons = gears.table.join(
awful.button({ }, 1, function (c) client.focus = c; c:raise() end), awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
awful.button({ modkey }, 1, awful.mouse.client.move), awful.button({ modkey }, 1, awful.mouse.client.move),
awful.button({ modkey }, 3, awful.mouse.client.resize)) awful.button({ modkey }, 3, awful.mouse.client.resize))
@ -530,7 +530,7 @@ end)
-- Add a titlebar if titlebars_enabled is set to true in the rules. -- Add a titlebar if titlebars_enabled is set to true in the rules.
client.connect_signal("request::titlebars", function(c) client.connect_signal("request::titlebars", function(c)
-- buttons for the titlebar -- buttons for the titlebar
local buttons = awful.util.table.join( local buttons = gears.table.join(
awful.button({ }, 1, function() awful.button({ }, 1, function()
client.focus = c client.focus = c
c:raise() c:raise()

View File

@ -10,7 +10,8 @@
local setmetatable = setmetatable local setmetatable = setmetatable
local ipairs = ipairs local ipairs = ipairs
local capi = { button = button } local capi = { button = button }
local util = require("awful.util") local gmath = require("gears.math")
local gtable = require("gears.table")
local button = { mt = {} } local button = { mt = {} }
@ -38,9 +39,9 @@ local ignore_modifiers = { "Lock", "Mod2" }
-- @treturn table A table with one or several button objects. -- @treturn table A table with one or several button objects.
function button.new(mod, _button, press, release) function button.new(mod, _button, press, release)
local ret = {} local ret = {}
local subsets = util.subsets(ignore_modifiers) local subsets = gmath.subsets(ignore_modifiers)
for _, set in ipairs(subsets) do for _, set in ipairs(subsets) do
ret[#ret + 1] = capi.button({ modifiers = util.table.join(mod, set), ret[#ret + 1] = capi.button({ modifiers = gtable.join(mod, set),
button = _button }) button = _button })
if press then if press then
ret[#ret]:connect_signal("press", function(_, ...) press(...) end) ret[#ret]:connect_signal("press", function(_, ...) press(...) end)

View File

@ -13,6 +13,7 @@ local set_shape = require("awful.client.shape").update.all
local object = require("gears.object") local object = require("gears.object")
local grect = require("gears.geometry").rectangle local grect = require("gears.geometry").rectangle
local gmath = require("gears.math") local gmath = require("gears.math")
local gtable = require("gears.table")
local pairs = pairs local pairs = pairs
local type = type local type = type
local ipairs = ipairs local ipairs = ipairs
@ -291,7 +292,7 @@ end
-- @legacylayout awful.client.setmaster -- @legacylayout awful.client.setmaster
-- @client c The window to set as master. -- @client c The window to set as master.
function client.setmaster(c) function client.setmaster(c)
local cls = util.table.reverse(capi.client.get(c.screen)) local cls = gtable.reverse(capi.client.get(c.screen))
for _, v in pairs(cls) do for _, v in pairs(cls) do
c:swap(v) c:swap(v)
end end
@ -540,7 +541,7 @@ end
-- @function awful.client.getmarked -- @function awful.client.getmarked
-- @return A table with all marked clients. -- @return A table with all marked clients.
function client.getmarked() function client.getmarked()
local copy = util.table.clone(client.data.marked, false) local copy = gtable.clone(client.data.marked, false)
for _, v in pairs(copy) do for _, v in pairs(copy) do
client.property.set(v, "marked", false) client.property.set(v, "marked", false)
@ -755,7 +756,7 @@ function client.restore(s)
local ctags = c:tags() local ctags = c:tags()
if c.minimized then if c.minimized then
for _, t in ipairs(tags) do for _, t in ipairs(tags) do
if util.table.hasitem(ctags, t) then if gtable.hasitem(ctags, t) then
c.minimized = false c.minimized = false
return c return c
end end
@ -1066,8 +1067,8 @@ end
function client.iterate(filter, start, s) function client.iterate(filter, start, s)
local clients = capi.client.get(s) local clients = capi.client.get(s)
local focused = capi.client.focus local focused = capi.client.focus
start = start or util.table.hasitem(clients, focused) start = start or gtable.hasitem(clients, focused)
return util.table.iterate(clients, filter, start) return gtable.iterate(clients, filter, start)
end end
--- Switch to a client matching the given condition if running, else spawn it. --- Switch to a client matching the given condition if running, else spawn it.
@ -1090,7 +1091,7 @@ end
-- end); -- end);
function client.run_or_raise(cmd, matcher, merge) function client.run_or_raise(cmd, matcher, merge)
local clients = capi.client.get() local clients = capi.client.get()
local findex = util.table.hasitem(clients, capi.client.focus) or 1 local findex = gtable.hasitem(clients, capi.client.focus) or 1
local start = gmath.cycle(#clients, findex + 1) local start = gmath.cycle(#clients, findex + 1)
local c = client.iterate(matcher, start)() local c = client.iterate(matcher, start)()

View File

@ -9,7 +9,7 @@
local client = client local client = client
local screen = screen local screen = screen
local ipairs = ipairs local ipairs = ipairs
local util = require("awful.util") local gtable = require("gears.table")
local aclient = require("awful.client") local aclient = require("awful.client")
local aplace = require("awful.placement") local aplace = require("awful.placement")
local asuit = require("awful.layout.suit") local asuit = require("awful.layout.suit")
@ -259,7 +259,7 @@ function ewmh.geometry(c, context, hints)
-- Now, map it to something useful -- Now, map it to something useful
context = context_mapper[context] or context context = context_mapper[context] or context
local props = util.table.clone(hints or {}, false) local props = gtable.clone(hints or {}, false)
props.store_geometry = props.store_geometry==nil and true or props.store_geometry props.store_geometry = props.store_geometry==nil and true or props.store_geometry
-- If it is a known placement function, then apply it, otherwise let -- If it is a known placement function, then apply it, otherwise let

View File

@ -12,6 +12,7 @@ local capi = {
keygrabber = keygrabber, keygrabber = keygrabber,
} }
local awful = require("awful") local awful = require("awful")
local gtable = require("gears.table")
local wibox = require("wibox") local wibox = require("wibox")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local dpi = beautiful.xresources.apply_dpi local dpi = beautiful.xresources.apply_dpi
@ -133,7 +134,7 @@ function widget.new(args)
merge_duplicates = ( merge_duplicates = (
args.merge_duplicates == nil args.merge_duplicates == nil
) and widget.merge_duplicates or args.merge_duplicates, ) and widget.merge_duplicates or args.merge_duplicates,
group_rules = args.group_rules or awful.util.table.clone(widget.group_rules), group_rules = args.group_rules or gtable.clone(widget.group_rules),
labels = args.labels or { labels = args.labels or {
Mod4="Super", Mod4="Super",
Mod1="Alt", Mod1="Alt",
@ -322,7 +323,7 @@ function widget.new(args)
local max_height_px = height - group_label_height local max_height_px = height - group_label_height
local column_layouts = {} local column_layouts = {}
for _, group in ipairs(available_groups) do for _, group in ipairs(available_groups) do
local keys = awful.util.table.join(self._cached_awful_keys[group], self._additional_hotkeys[group]) local keys = gtable.join(self._cached_awful_keys[group], self._additional_hotkeys[group])
local joined_descriptions = "" local joined_descriptions = ""
for i, key in ipairs(keys) do for i, key in ipairs(keys) do
joined_descriptions = joined_descriptions .. key.description .. (i~=#keys and "\n" or "") joined_descriptions = joined_descriptions .. key.description .. (i~=#keys and "\n" or "")
@ -447,7 +448,7 @@ function widget.new(args)
height = height, height = height,
}) })
mywibox:set_widget(pages[1]) mywibox:set_widget(pages[1])
mywibox:buttons(awful.util.table.join( mywibox:buttons(gtable.join(
awful.button({ }, 1, function () mywibox.visible=false end), awful.button({ }, 1, function () mywibox.visible=false end),
awful.button({ }, 3, function () mywibox.visible=false end) awful.button({ }, 3, function () mywibox.visible=false end)
)) ))

View File

@ -10,7 +10,8 @@
local setmetatable = setmetatable local setmetatable = setmetatable
local ipairs = ipairs local ipairs = ipairs
local capi = { key = key, root = root } local capi = { key = key, root = root }
local util = require("awful.util") local gmath = require("gears.math")
local gtable = require("gears.table")
@ -82,9 +83,9 @@ function key.new(mod, _key, press, release, data)
release=nil release=nil
end end
local ret = {} local ret = {}
local subsets = util.subsets(key.ignore_modifiers) local subsets = gmath.subsets(key.ignore_modifiers)
for _, set in ipairs(subsets) do for _, set in ipairs(subsets) do
ret[#ret + 1] = capi.key({ modifiers = util.table.join(mod, set), ret[#ret + 1] = capi.key({ modifiers = gtable.join(mod, set),
key = _key }) key = _key })
if press then if press then
ret[#ret]:connect_signal("press", function(_, ...) press(...) end) ret[#ret]:connect_signal("press", function(_, ...) press(...) end)
@ -95,7 +96,7 @@ function key.new(mod, _key, press, release, data)
end end
-- append custom userdata (like description) to a hotkey -- append custom userdata (like description) to a hotkey
data = data and util.table.clone(data) or {} data = data and gtable.clone(data) or {}
data.mod = mod data.mod = mod
data.key = _key data.key = _key
table.insert(key.hotkeys, data) table.insert(key.hotkeys, data)
@ -117,7 +118,7 @@ function key.match(_key, pressed_mod, pressed_key)
-- pressed. -- pressed.
for _, m in ipairs(mod) do for _, m in ipairs(mod) do
-- Has it been pressed? -- Has it been pressed?
if not util.table.hasitem(pressed_mod, m) then if not gtable.hasitem(pressed_mod, m) then
-- No, so this is failure! -- No, so this is failure!
return false return false
end end

View File

@ -11,6 +11,7 @@
local wibox = require("wibox") local wibox = require("wibox")
local button = require("awful.button") local button = require("awful.button")
local util = require("awful.util") local util = require("awful.util")
local gtable = require("gears.table")
local spawn = require("awful.spawn") local spawn = require("awful.spawn")
local tags = require("awful.tag") local tags = require("awful.tag")
local keygrabber = require("awful.keygrabber") local keygrabber = require("awful.keygrabber")
@ -146,7 +147,7 @@ local function item_position(_menu, child)
if dir == "x" then a, b = b, a end if dir == "x" then a, b = b, a end
local in_dir, other = 0, _menu[b] local in_dir, other = 0, _menu[b]
local num = util.table.hasitem(_menu.child, child) local num = gtable.hasitem(_menu.child, child)
if num then if num then
for i = 0, num - 1 do for i = 0, num - 1 do
local item = _menu.items[i] local item = _menu.items[i]
@ -237,19 +238,19 @@ local function grabber(_menu, _, key, event)
if event ~= "press" then return end if event ~= "press" then return end
local sel = _menu.sel or 0 local sel = _menu.sel or 0
if util.table.hasitem(menu.menu_keys.up, key) then if gtable.hasitem(menu.menu_keys.up, key) then
local sel_new = sel-1 < 1 and #_menu.items or sel-1 local sel_new = sel-1 < 1 and #_menu.items or sel-1
_menu:item_enter(sel_new) _menu:item_enter(sel_new)
elseif util.table.hasitem(menu.menu_keys.down, key) then elseif gtable.hasitem(menu.menu_keys.down, key) then
local sel_new = sel+1 > #_menu.items and 1 or sel+1 local sel_new = sel+1 > #_menu.items and 1 or sel+1
_menu:item_enter(sel_new) _menu:item_enter(sel_new)
elseif sel > 0 and util.table.hasitem(menu.menu_keys.enter, key) then elseif sel > 0 and gtable.hasitem(menu.menu_keys.enter, key) then
_menu:exec(sel) _menu:exec(sel)
elseif sel > 0 and util.table.hasitem(menu.menu_keys.exec, key) then elseif sel > 0 and gtable.hasitem(menu.menu_keys.exec, key) then
_menu:exec(sel, { exec = true }) _menu:exec(sel, { exec = true })
elseif util.table.hasitem(menu.menu_keys.back, key) then elseif gtable.hasitem(menu.menu_keys.back, key) then
_menu:hide() _menu:hide()
elseif util.table.hasitem(menu.menu_keys.close, key) then elseif gtable.hasitem(menu.menu_keys.close, key) then
menu.get_root(_menu):hide() menu.get_root(_menu):hide()
else else
check_access_key(_menu, key) check_access_key(_menu, key)
@ -433,17 +434,17 @@ function menu:add(args, index)
-- Create bindings -- Create bindings
item._background:buttons(util.table.join( item._background:buttons(gtable.join(
button({}, 3, function () self:hide() end), button({}, 3, function () self:hide() end),
button({}, 1, function () button({}, 1, function ()
local num = util.table.hasitem(self.items, item) local num = gtable.hasitem(self.items, item)
self:item_enter(num, { mouse = true }) self:item_enter(num, { mouse = true })
self:exec(num, { exec = true, mouse = true }) self:exec(num, { exec = true, mouse = true })
end ))) end )))
item._mouse = function () item._mouse = function ()
local num = util.table.hasitem(self.items, item) local num = gtable.hasitem(self.items, item)
self:item_enter(num, { hover = true, moue = true }) self:item_enter(num, { hover = true, moue = true })
end end
item.widget:connect_signal("mouse::enter", item._mouse) item.widget:connect_signal("mouse::enter", item._mouse)
@ -468,7 +469,7 @@ end
-- @param num The position in the table of the menu entry to be deleted; can be also the menu entry itself -- @param num The position in the table of the menu entry to be deleted; can be also the menu entry itself
function menu:delete(num) function menu:delete(num)
if type(num) == "table" then if type(num) == "table" then
num = util.table.hasitem(self.items, num) num = gtable.hasitem(self.items, num)
end end
local item = self.items[num] local item = self.items[num]
if not item then return end if not item then return end
@ -519,15 +520,15 @@ function menu.clients(args, item_args, filter)
c.icon } c.icon }
if item_args then if item_args then
if type(item_args) == "function" then if type(item_args) == "function" then
util.table.merge(cls_t[#cls_t], item_args(c)) gtable.merge(cls_t[#cls_t], item_args(c))
else else
util.table.merge(cls_t[#cls_t], item_args) gtable.merge(cls_t[#cls_t], item_args)
end end
end end
end end
args = args or {} args = args or {}
args.items = args.items or {} args.items = args.items or {}
util.table.merge(args.items, cls_t) gtable.merge(args.items, cls_t)
local m = menu.new(args) local m = menu.new(args)
m:show(args) m:show(args)

View File

@ -94,6 +94,7 @@ local layout = require("awful.layout")
local a_screen = require("awful.screen") local a_screen = require("awful.screen")
local grect = require("gears.geometry").rectangle local grect = require("gears.geometry").rectangle
local util = require("awful.util") local util = require("awful.util")
local gtable = require("gears.table")
local cairo = require( "lgi" ).cairo local cairo = require( "lgi" ).cairo
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1) local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
@ -357,7 +358,7 @@ area_common = function(d, new_geo, ignore_border_width, args)
-- When using the placement composition along with the "pretend" -- When using the placement composition along with the "pretend"
-- option, it is necessary to keep a "virtual" geometry. -- option, it is necessary to keep a "virtual" geometry.
if args and args.override_geometry then if args and args.override_geometry then
geometry = util.table.clone(args.override_geometry) geometry = gtable.clone(args.override_geometry)
end end
geometry.width = geometry.width + 2 * border geometry.width = geometry.width + 2 * border

View File

@ -126,6 +126,7 @@ local util = require("awful.util")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local akey = require("awful.key") local akey = require("awful.key")
local debug = require('gears.debug') local debug = require('gears.debug')
local gtable = require("gears.table")
local prompt = {} local prompt = {}
@ -156,7 +157,7 @@ local function history_check_load(id, max)
-- Read history file -- Read history file
for line in f:lines() do for line in f:lines() do
if util.table.hasitem(data.history[id].table, line) == nil then if gtable.hasitem(data.history[id].table, line) == nil then
table.insert(data.history[id].table, line) table.insert(data.history[id].table, line)
if #data.history[id].table >= data.history[id].max then if #data.history[id].table >= data.history[id].max then
break break
@ -239,7 +240,7 @@ end
-- @param command The command to add -- @param command The command to add
local function history_add(id, command) local function history_add(id, command)
if data.history[id] and command ~= "" then if data.history[id] and command ~= "" then
local index = util.table.hasitem(data.history[id].table, command) local index = gtable.hasitem(data.history[id].table, command)
if index == nil then if index == nil then
table.insert(data.history[id].table, command) table.insert(data.history[id].table, command)
@ -593,7 +594,7 @@ function prompt.run(args, textbox, exe_callback, completion_callback,
if hooks[key] then if hooks[key] then
-- Remove caps and num lock -- Remove caps and num lock
for _, m in ipairs(modifiers) do for _, m in ipairs(modifiers) do
if not util.table.hasitem(akey.ignore_modifiers, m) then if not gtable.hasitem(akey.ignore_modifiers, m) then
table.insert(filtered_modifiers, m) table.insert(filtered_modifiers, m)
end end
end end

View File

@ -31,7 +31,7 @@ local type = type
local ipairs = ipairs local ipairs = ipairs
local pairs = pairs local pairs = pairs
local atag = require("awful.tag") local atag = require("awful.tag")
local util = require("awful.util") local gtable = require("gears.table")
local a_place = require("awful.placement") local a_place = require("awful.placement")
local protected_call = require("gears.protected_call") local protected_call = require("gears.protected_call")
@ -352,7 +352,7 @@ function rules.high_priority_properties.new_tag(c, value, props)
elseif ty == "table" then elseif ty == "table" then
-- Assume a table of tags properties. Set the right screen, but -- Assume a table of tags properties. Set the right screen, but
-- avoid editing the original table -- avoid editing the original table
local values = value.screen and value or util.table.clone(value) local values = value.screen and value or gtable.clone(value)
values.screen = values.screen or c.screen values.screen = values.screen or c.screen
t = atag.add(value.name or c.class or "N/A", values) t = atag.add(value.name or c.class or "N/A", values)
@ -416,7 +416,7 @@ function rules.high_priority_properties.tags(c, value, props)
if #current == 0 or (value[1] and value[1].screen ~= current[1].screen) then if #current == 0 or (value[1] and value[1].screen ~= current[1].screen) then
c:tags(tags) c:tags(tags)
else else
c:tags(util.table.merge(current, tags)) c:tags(gtable.merge(current, tags))
end end
end end

View File

@ -13,6 +13,7 @@ local beautiful = require("beautiful")
local gmath = require("gears.math") local gmath = require("gears.math")
local object = require("gears.object") local object = require("gears.object")
local timer = require("gears.timer") local timer = require("gears.timer")
local gtable = require("gears.table")
local pairs = pairs local pairs = pairs
local ipairs = ipairs local ipairs = ipairs
local table = table local table = table
@ -262,7 +263,7 @@ function tag.find_fallback(screen, invalids)
local t = invalids or scr.selected_tags local t = invalids or scr.selected_tags
for _, v in pairs(scr.tags) do for _, v in pairs(scr.tags) do
if not util.table.hasitem(t, v) then return v end if not gtable.hasitem(t, v) then return v end
end end
end end
@ -1266,7 +1267,7 @@ function tag.viewmore(tags, screen)
screen = get_screen(screen or ascreen.focused()) screen = get_screen(screen or ascreen.focused())
local screen_tags = screen.tags local screen_tags = screen.tags
for _, _tag in ipairs(screen_tags) do for _, _tag in ipairs(screen_tags) do
if not util.table.hasitem(tags, _tag) then if not gtable.hasitem(tags, _tag) then
_tag.selected = false _tag.selected = false
end end
end end

View File

@ -41,7 +41,7 @@
local mouse = mouse local mouse = mouse
local timer = require("gears.timer") local timer = require("gears.timer")
local util = require("awful.util") local gtable = require("gears.table")
local object = require("gears.object") local object = require("gears.object")
local color = require("gears.color") local color = require("gears.color")
local wibox = require("wibox") local wibox = require("wibox")
@ -558,7 +558,7 @@ function tooltip.new(args)
end end
-- export functions -- export functions
util.table.crush(self, tooltip, true) gtable.crush(self, tooltip, true)
-- setup the timer action only if needed -- setup the timer action only if needed
if args.timer_function then if args.timer_function then

View File

@ -13,9 +13,8 @@ local load = loadstring or load -- luacheck: globals loadstring (compatibility w
local loadfile = loadfile local loadfile = loadfile
local debug = debug local debug = debug
local pairs = pairs local pairs = pairs
local ipairs = ipairs
local type = type local type = type
local rtable = table local gtable = require("gears.table")
local string = string local string = string
local lgi = require("lgi") local lgi = require("lgi")
local grect = require("gears.geometry").rectangle local grect = require("gears.geometry").rectangle
@ -324,43 +323,29 @@ end
--- Join all tables given as parameters. --- Join all tables given as parameters.
-- This will iterate all tables and insert all their keys into a new table. -- This will iterate all tables and insert all their keys into a new table.
-- @deprecated util.table.join
-- @param args A list of tables to join -- @param args A list of tables to join
-- @return A new table containing all keys from the arguments. -- @return A new table containing all keys from the arguments.
-- @see gears.table
function util.table.join(...) function util.table.join(...)
local ret = {} util.deprecate("gears.table.join", {deprecated_in=5})
for _, t in pairs({...}) do
if t then return gtable.join(...)
for k, v in pairs(t) do
if type(k) == "number" then
rtable.insert(ret, v)
else
ret[k] = v
end
end
end
end
return ret
end end
--- Override elements in the first table by the one in the second. --- Override elements in the first table by the one in the second.
-- --
-- Note that this method doesn't copy entries found in `__index`. -- Note that this method doesn't copy entries found in `__index`.
-- @deprecated util.table.crush
-- @tparam table t the table to be overriden -- @tparam table t the table to be overriden
-- @tparam table set the table used to override members of `t` -- @tparam table set the table used to override members of `t`
-- @tparam[opt=false] boolean raw Use rawset (avoid the metatable) -- @tparam[opt=false] boolean raw Use rawset (avoid the metatable)
-- @treturn table t (for convenience) -- @treturn table t (for convenience)
-- @see gears.table
function util.table.crush(t, set, raw) function util.table.crush(t, set, raw)
if raw then util.deprecate("gears.table.crush", {deprecated_in=5})
for k, v in pairs(set) do
rawset(t, k, v)
end
else
for k, v in pairs(set) do
t[k] = v
end
end
return t return gtable.crush(t, set, raw)
end end
--- Pack all elements with an integer key into a new table --- Pack all elements with an integer key into a new table
@ -370,36 +355,26 @@ end
-- --
-- This function remove any non numeric keys from the value set -- This function remove any non numeric keys from the value set
-- --
-- @deprecated util.table.from_sparse
-- @tparam table t A potentially sparse table -- @tparam table t A potentially sparse table
-- @treturn table A packed table with all numeric keys -- @treturn table A packed table with all numeric keys
-- @see gears.table
function util.table.from_sparse(t) function util.table.from_sparse(t)
local keys= {} util.deprecate("gears.table.from_sparse", {deprecated_in=5})
for k in pairs(t) do
if type(k) == "number" then
keys[#keys+1] = k
end
end
table.sort(keys) return gtable.from_sparse(t)
local ret = {}
for _,v in ipairs(keys) do
ret[#ret+1] = t[v]
end
return ret
end end
--- Check if a table has an item and return its key. --- Check if a table has an item and return its key.
-- @deprecated util.table.hasitem
-- @param t The table. -- @param t The table.
-- @param item The item to look for in values of the table. -- @param item The item to look for in values of the table.
-- @return The key were the item is found, or nil if not found. -- @return The key were the item is found, or nil if not found.
-- @see gears.table
function util.table.hasitem(t, item) function util.table.hasitem(t, item)
for k, v in pairs(t) do util.deprecate("gears.table.hasitem", {deprecated_in=5})
if v == item then
return k return gtable.hasitem(t, item)
end
end
end end
--- Split a string into multiple lines --- Split a string into multiple lines
@ -430,105 +405,78 @@ function util.linecount(text)
end end
--- Get a sorted table with all integer keys from a table --- Get a sorted table with all integer keys from a table
-- @deprecated util.table.keys
-- @param t the table for which the keys to get -- @param t the table for which the keys to get
-- @return A table with keys -- @return A table with keys
-- @see gears.table
function util.table.keys(t) function util.table.keys(t)
local keys = { } util.deprecate("gears.table.keys", {deprecated_in=5})
for k, _ in pairs(t) do
rtable.insert(keys, k) return gtable.keys(t)
end
rtable.sort(keys, function (a, b)
return type(a) == type(b) and a < b or false
end)
return keys
end end
--- Filter a tables keys for certain content types --- Filter a tables keys for certain content types
-- @deprecated util.table.keys_filter
-- @param t The table to retrieve the keys for -- @param t The table to retrieve the keys for
-- @param ... the types to look for -- @param ... the types to look for
-- @return A filtered table with keys -- @return A filtered table with keys
-- @see gears.table
function util.table.keys_filter(t, ...) function util.table.keys_filter(t, ...)
local keys = util.table.keys(t) util.deprecate("gears.table.keys_filter", {deprecated_in=5})
local keys_filtered = { }
for _, k in pairs(keys) do return gtable.keys_filter(t, ...)
for _, et in pairs({...}) do
if type(t[k]) == et then
rtable.insert(keys_filtered, k)
break
end
end
end
return keys_filtered
end end
--- Reverse a table --- Reverse a table
-- @deprecated util.table.reverse
-- @param t the table to reverse -- @param t the table to reverse
-- @return the reversed table -- @return the reversed table
-- @see gears.table
function util.table.reverse(t) function util.table.reverse(t)
local tr = { } util.deprecate("gears.table.reverse", {deprecated_in=5})
-- reverse all elements with integer keys
for _, v in ipairs(t) do return gtable.reverse(t)
rtable.insert(tr, 1, v)
end
-- add the remaining elements
for k, v in pairs(t) do
if type(k) ~= "number" then
tr[k] = v
end
end
return tr
end end
--- Clone a table --- Clone a table
-- @deprecated util.table.clone
-- @param t the table to clone -- @param t the table to clone
-- @param deep Create a deep clone? (default: true) -- @param deep Create a deep clone? (default: true)
-- @return a clone of t -- @return a clone of t
-- @see gears.table
function util.table.clone(t, deep) function util.table.clone(t, deep)
deep = deep == nil and true or deep util.deprecate("gears.table.clone", {deprecated_in=5})
local c = { }
for k, v in pairs(t) do return gtable.clone(t, deep)
if deep and type(v) == "table" then
c[k] = util.table.clone(v)
else
c[k] = v
end
end
return c
end end
--- ---
-- Returns an iterator to cycle through, starting from the first element or the -- Returns an iterator to cycle through, starting from the first element or the
-- given index, all elements of a table that match a given criteria. -- given index, all elements of a table that match a given criteria.
-- --
-- @deprecated util.table.iterate
-- @param t the table to iterate -- @param t the table to iterate
-- @param filter a function that returns true to indicate a positive match -- @param filter a function that returns true to indicate a positive match
-- @param start what index to start iterating from. Default is 1 (=> start of -- @param start what index to start iterating from. Default is 1 (=> start of
-- the table) -- the table)
-- @see gears.table
function util.table.iterate(t, filter, start) function util.table.iterate(t, filter, start)
local count = 0 util.deprecate("gears.table.iterate", {deprecated_in=5})
local index = start or 1
local length = #t
return function () return gtable.iterate(t, filter, start)
while count < length do
local item = t[index]
index = gmath.cycle(#t, index + 1)
count = count + 1
if filter(item) then return item end
end
end
end end
--- Merge items from the one table to another one --- Merge items from the one table to another one
-- @deprecated util.table.merge
-- @tparam table t the container table -- @tparam table t the container table
-- @tparam table set the mixin table -- @tparam table set the mixin table
-- @treturn table Return `t` for convenience -- @treturn table Return `t` for convenience
-- @see gears.table
function util.table.merge(t, set) function util.table.merge(t, set)
for _, v in ipairs(set) do util.deprecate("gears.table.merge", {deprecated_in=5})
table.insert(t, v)
end return gtable.merge(t, set)
return t
end end

View File

@ -1,7 +1,7 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
-- A simple button widget. -- A simple button widget.
-- @usage local button = awful.widget.button() -- @usage local button = awful.widget.button()
-- button:buttons(awful.util.table.join( -- button:buttons(gears.table.join(
-- button:buttons(), -- button:buttons(),
-- awful.button({}, 1, nil, function () -- awful.button({}, 1, nil, function ()
-- print("Mouse was clicked") -- print("Mouse was clicked")

View File

@ -8,7 +8,7 @@ local capi = {awesome = awesome}
local setmetatable = setmetatable local setmetatable = setmetatable
local textbox = require("wibox.widget.textbox") local textbox = require("wibox.widget.textbox")
local button = require("awful.button") local button = require("awful.button")
local util = require("awful.util") local gtable = require("gears.table")
local widget_base = require("wibox.widget.base") local widget_base = require("wibox.widget.base")
local gdebug = require("gears.debug") local gdebug = require("gears.debug")
@ -288,7 +288,7 @@ function keyboardlayout.new()
-- Mouse bindings -- Mouse bindings
self:buttons( self:buttons(
util.table.join(button({ }, 1, self.next_layout)) gtable.join(button({ }, 1, self.next_layout))
) )
return self return self

View File

@ -5,7 +5,7 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
local setmetatable = setmetatable local setmetatable = setmetatable
local util = require("awful.util") local gtable = require("gears.table")
local spawn = require("awful.spawn") local spawn = require("awful.spawn")
local wbutton = require("awful.widget.button") local wbutton = require("awful.widget.button")
local button = require("awful.button") local button = require("awful.button")
@ -23,9 +23,9 @@ function launcher.new(args)
local b local b
if args.command then if args.command then
b = util.table.join(w:buttons(), button({}, 1, nil, function () spawn(args.command) end)) b = gtable.join(w:buttons(), button({}, 1, nil, function () spawn(args.command) end))
elseif args.menu then elseif args.menu then
b = util.table.join(w:buttons(), button({}, 1, nil, function () args.menu:toggle() end)) b = gtable.join(w:buttons(), button({}, 1, nil, function () args.menu:toggle() end))
end end
w:buttons(b) w:buttons(b)

View File

@ -11,7 +11,7 @@ local type = type
local pairs = pairs local pairs = pairs
local setmetatable = setmetatable local setmetatable = setmetatable
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
local util = require("awful.util") local gtable = require("gears.table")
local capi = { local capi = {
screen = screen, screen = screen,
awesome = awesome awesome = awesome
@ -98,7 +98,7 @@ end
local function new(widget, s) local function new(widget, s)
local ret = base.make_widget(nil, nil, {enable_properties = true}) local ret = base.make_widget(nil, nil, {enable_properties = true})
util.table.crush(ret, only_on_screen, true) gtable.crush(ret, only_on_screen, true)
ret:set_widget(widget) ret:set_widget(widget)
ret:set_screen(s or "primary") ret:set_screen(s or "primary")

View File

@ -9,7 +9,7 @@
-- Grab environment -- Grab environment
local awesome = awesome local awesome = awesome
local screen = screen local screen = screen
local round = require("awful.util").round local round = require("gears.math").round
local gears_debug = require("gears.debug") local gears_debug = require("gears.debug")
local xresources = {} local xresources = {}

View File

@ -19,6 +19,7 @@ return
protected_call = require("gears.protected_call"); protected_call = require("gears.protected_call");
geometry = require("gears.geometry"); geometry = require("gears.geometry");
math = require("gears.math"); math = require("gears.math");
table = require("gears.table");
} }
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

216
lib/gears/table.lua Normal file
View File

@ -0,0 +1,216 @@
---------------------------------------------------------------------------
--- Table module for gears
--
-- @module gears.table
---------------------------------------------------------------------------
local rtable = table
local gmath = require("gears.math")
local gtable = {}
--- Join all tables given as parameters.
-- This will iterate all tables and insert all their keys into a new table.
-- @class function
-- @name join
-- @param args A list of tables to join
-- @return A new table containing all keys from the arguments.
function gtable.join(...)
local ret = {}
for _, t in pairs({...}) do
if t then
for k, v in pairs(t) do
if type(k) == "number" then
rtable.insert(ret, v)
else
ret[k] = v
end
end
end
end
return ret
end
--- Override elements in the first table by the one in the second.
--
-- Note that this method doesn't copy entries found in `__index`.
-- @class function
-- @name crush
-- @tparam table t the table to be overriden
-- @tparam table set the table used to override members of `t`
-- @tparam[opt=false] boolean raw Use rawset (avoid the metatable)
-- @treturn table t (for convenience)
function gtable.crush(t, set, raw)
if raw then
for k, v in pairs(set) do
rawset(t, k, v)
end
else
for k, v in pairs(set) do
t[k] = v
end
end
return t
end
--- Pack all elements with an integer key into a new table
-- While both lua and luajit implement __len over sparse
-- table, the standard define it as an implementation
-- detail.
--
-- This function remove any non numeric keys from the value set
--
-- @class function
-- @name from_sparse
-- @tparam table t A potentially sparse table
-- @treturn table A packed table with all numeric keys
function gtable.from_sparse(t)
local keys= {}
for k in pairs(t) do
if type(k) == "number" then
keys[#keys+1] = k
end
end
table.sort(keys)
local ret = {}
for _,v in ipairs(keys) do
ret[#ret+1] = t[v]
end
return ret
end
--- Check if a table has an item and return its key.
-- @class function
-- @name hasitem
-- @param t The table.
-- @param item The item to look for in values of the table.
-- @return The key were the item is found, or nil if not found.
function gtable.hasitem(t, item)
for k, v in pairs(t) do
if v == item then
return k
end
end
end
--- Get a sorted table with all integer keys from a table
-- @class function
-- @name keys
-- @param t the table for which the keys to get
-- @return A table with keys
function gtable.keys(t)
local keys = { }
for k, _ in pairs(t) do
rtable.insert(keys, k)
end
rtable.sort(keys, function (a, b)
return type(a) == type(b) and a < b or false
end)
return keys
end
--- Filter a tables keys for certain content types
-- @class function
-- @name keys_filter
-- @param t The table to retrieve the keys for
-- @param ... the types to look for
-- @return A filtered table with keys
function gtable.keys_filter(t, ...)
local keys = gtable.keys(t)
local keys_filtered = { }
for _, k in pairs(keys) do
for _, et in pairs({...}) do
if type(t[k]) == et then
rtable.insert(keys_filtered, k)
break
end
end
end
return keys_filtered
end
--- Reverse a table
-- @class function
-- @name reverse
-- @param t the table to reverse
-- @return the reversed table
function gtable.reverse(t)
local tr = { }
-- reverse all elements with integer keys
for _, v in ipairs(t) do
rtable.insert(tr, 1, v)
end
-- add the remaining elements
for k, v in pairs(t) do
if type(k) ~= "number" then
tr[k] = v
end
end
return tr
end
--- Clone a table
-- @class function
-- @name clone
-- @param t the table to clone
-- @param deep Create a deep clone? (default: true)
-- @return a clone of t
function gtable.clone(t, deep)
deep = deep == nil and true or deep
local c = { }
for k, v in pairs(t) do
if deep and type(v) == "table" then
c[k] = gtable.clone(v)
else
c[k] = v
end
end
return c
end
---
-- Returns an iterator to cycle through, starting from the first element or the
-- given index, all elements of a table that match a given criteria.
--
-- @class function
-- @name iterate
-- @param t the table to iterate
-- @param filter a function that returns true to indicate a positive match
-- @param start what index to start iterating from. Default is 1 (=> start of
-- the table)
function gtable.iterate(t, filter, start)
local count = 0
local index = start or 1
local length = #t
return function ()
while count < length do
local item = t[index]
index = gmath.cycle(#t, index + 1)
count = count + 1
if filter(item) then return item end
end
end
end
--- Merge items from the one table to another one
-- @class function
-- @name merge
-- @tparam table t the container table
-- @tparam table set the mixin table
-- @treturn table Return `t` for convenience
function gtable.merge(t, set)
for _, v in ipairs(set) do
table.insert(t, v)
end
return t
end
return gtable

View File

@ -20,6 +20,7 @@ local timer = require("gears.timer")
local button = require("awful.button") local button = require("awful.button")
local screen = require("awful.screen") local screen = require("awful.screen")
local util = require("awful.util") local util = require("awful.util")
local gtable = require("gears.table")
local bt = require("beautiful") local bt = require("beautiful")
local wibox = require("wibox") local wibox = require("wibox")
local surface = require("gears.surface") local surface = require("gears.surface")
@ -502,7 +503,7 @@ function naughty.notify(args)
end end
-- gather variables together -- gather variables together
local preset = util.table.join(naughty.config.defaults or {}, local preset = gtable.join(naughty.config.defaults or {},
args.preset or naughty.config.presets.normal or {}) args.preset or naughty.config.presets.normal or {})
local timeout = args.timeout or preset.timeout local timeout = args.timeout or preset.timeout
local icon = args.icon or preset.icon local icon = args.icon or preset.icon
@ -622,7 +623,7 @@ function naughty.notify(args)
local action_height = h + 2 * margin local action_height = h + 2 * margin
local action_width = w + 2 * margin local action_width = w + 2 * margin
actionmarginbox:buttons(util.table.join( actionmarginbox:buttons(gtable.join(
button({ }, 1, callback), button({ }, 1, callback),
button({ }, 3, callback) button({ }, 3, callback)
)) ))
@ -745,7 +746,7 @@ function naughty.notify(args)
notification.box:set_widget(completelayout) notification.box:set_widget(completelayout)
-- Setup the mouse events -- Setup the mouse events
layout:buttons(util.table.join(button({}, 1, nil, run), layout:buttons(gtable.join(button({}, 1, nil, run),
button({}, 3, nil, function() button({}, 3, nil, function()
die(naughty.notificationClosedReason.dismissedByUser) die(naughty.notificationClosedReason.dismissedByUser)
end))) end)))

View File

@ -15,7 +15,7 @@ local type = type
local string = string local string = string
local capi = { awesome = awesome, local capi = { awesome = awesome,
dbus = dbus } dbus = dbus }
local util = require("awful.util") local gtable = require("gears.table")
local cairo = require("lgi").cairo local cairo = require("lgi").cairo
local schar = string.char local schar = string.char
@ -129,7 +129,7 @@ capi.dbus.connect_signal("org.freedesktop.Notifications",
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
args.preset = util.table.join(args.preset, preset) args.preset = gtable.join(args.preset, preset)
end end
end end
local preset = args.preset or naughty.config.defaults local preset = args.preset or naughty.config.defaults

View File

@ -13,7 +13,7 @@
local setmetatable = setmetatable local setmetatable = setmetatable
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
local shape = require("gears.shape" ) local shape = require("gears.shape" )
local util = require( "awful.util" ) local gtable = require( "gears.table" )
local color = require( "gears.color" ) local color = require( "gears.color" )
local beautiful = require("beautiful" ) local beautiful = require("beautiful" )
@ -324,7 +324,7 @@ local function new(widget)
enable_properties = true, enable_properties = true,
}) })
util.table.crush(ret, arcchart) gtable.crush(ret, arcchart)
ret:set_widget(widget) ret:set_widget(widget)

View File

@ -13,7 +13,7 @@ local color = require("gears.color")
local surface = require("gears.surface") local surface = require("gears.surface")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local cairo = require("lgi").cairo local cairo = require("lgi").cairo
local util = require("awful.util") local gtable = require("gears.table")
local setmetatable = setmetatable local setmetatable = setmetatable
local type = type local type = type
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1) local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
@ -278,7 +278,7 @@ local function new(widget, bg, shape)
enable_properties = true, enable_properties = true,
}) })
util.table.crush(ret, background, true) gtable.crush(ret, background, true)
ret._private.shape = shape ret._private.shape = shape

View File

@ -8,7 +8,7 @@
local setmetatable = setmetatable local setmetatable = setmetatable
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
local util = require("awful.util") local gtable = require("gears.table")
local math = math local math = math
local constraint = { mt = {} } local constraint = { mt = {} }
@ -144,7 +144,7 @@ end
local function new(widget, strategy, width, height) local function new(widget, strategy, width, height)
local ret = base.make_widget(nil, nil, {enable_properties = true}) local ret = base.make_widget(nil, nil, {enable_properties = true})
util.table.crush(ret, constraint, true) gtable.crush(ret, constraint, true)
ret:set_strategy(strategy or "max") ret:set_strategy(strategy or "max")
ret:set_width(width) ret:set_width(width)

View File

@ -11,7 +11,7 @@ local setmetatable = setmetatable
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
local gcolor = require("gears.color") local gcolor = require("gears.color")
local cairo = require("lgi").cairo local cairo = require("lgi").cairo
local util = require("awful.util") local gtable = require("gears.table")
local margin = { mt = {} } local margin = { mt = {} }
@ -188,7 +188,7 @@ end
local function new(widget, left, right, top, bottom, color, draw_empty) local function new(widget, left, right, top, bottom, color, draw_empty)
local ret = base.make_widget(nil, nil, {enable_properties = true}) local ret = base.make_widget(nil, nil, {enable_properties = true})
util.table.crush(ret, margin, true) gtable.crush(ret, margin, true)
ret:set_left(left or 0) ret:set_left(left or 0)
ret:set_right(right or 0) ret:set_right(right or 0)

View File

@ -12,7 +12,7 @@ local ipairs = ipairs
local setmetatable = setmetatable local setmetatable = setmetatable
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
local matrix = require("gears.matrix") local matrix = require("gears.matrix")
local util = require("awful.util") local gtable = require("gears.table")
local mirror = { mt = {} } local mirror = { mt = {} }
@ -118,7 +118,7 @@ local function new(widget, reflection)
ret._private.horizontal = false ret._private.horizontal = false
ret._private.vertical = false ret._private.vertical = false
util.table.crush(ret, mirror, true) gtable.crush(ret, mirror, true)
ret:set_widget(widget) ret:set_widget(widget)
ret:set_reflection(reflection or {}) ret:set_reflection(reflection or {})

View File

@ -10,7 +10,7 @@
local setmetatable = setmetatable local setmetatable = setmetatable
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
local util = require("awful.util") local gtable = require("gears.table")
local place = { mt = {} } local place = { mt = {} }
@ -181,7 +181,7 @@ end
local function new(widget, halign, valign) local function new(widget, halign, valign)
local ret = base.make_widget(nil, nil, {enable_properties = true}) local ret = base.make_widget(nil, nil, {enable_properties = true})
util.table.crush(ret, place, true) gtable.crush(ret, place, true)
ret:set_widget(widget) ret:set_widget(widget)
ret:set_halign(halign) ret:set_halign(halign)

View File

@ -14,7 +14,7 @@
local setmetatable = setmetatable local setmetatable = setmetatable
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
local shape = require("gears.shape" ) local shape = require("gears.shape" )
local util = require( "awful.util" ) local gtable = require( "gears.table" )
local color = require( "gears.color" ) local color = require( "gears.color" )
local beautiful = require("beautiful" ) local beautiful = require("beautiful" )
@ -243,7 +243,7 @@ local function new(widget)
enable_properties = true, enable_properties = true,
}) })
util.table.crush(ret, radialprogressbar) gtable.crush(ret, radialprogressbar)
ret._private.max_value = 1 ret._private.max_value = 1
ret._private.min_value = 0 ret._private.min_value = 0

View File

@ -13,7 +13,7 @@ local setmetatable = setmetatable
local tostring = tostring local tostring = tostring
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
local matrix = require("gears.matrix") local matrix = require("gears.matrix")
local util = require("awful.util") local gtable = require("gears.table")
local rotate = { mt = {} } local rotate = { mt = {} }
@ -141,7 +141,7 @@ end
local function new(widget, dir) local function new(widget, dir)
local ret = base.make_widget(nil, nil, {enable_properties = true}) local ret = base.make_widget(nil, nil, {enable_properties = true})
util.table.crush(ret, rotate, true) gtable.crush(ret, rotate, true)
ret:set_widget(widget) ret:set_widget(widget)
ret:set_direction(dir or "north") ret:set_direction(dir or "north")

View File

@ -27,7 +27,7 @@ local cache = require("gears.cache")
local timer = require("gears.timer") local timer = require("gears.timer")
local hierarchy = require("wibox.hierarchy") local hierarchy = require("wibox.hierarchy")
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
local util = require("awful.util") local gtable = require("gears.table")
local lgi = require("lgi") local lgi = require("lgi")
local GLib = lgi.GLib local GLib = lgi.GLib
@ -403,7 +403,7 @@ local function get_layout(dir, widget, fps, speed, extra_space, expand, max_size
ret._private.timer = GLib.Timer() ret._private.timer = GLib.Timer()
ret._private.scroll_timer = nil ret._private.scroll_timer = nil
util.table.crush(ret, scroll, true) gtable.crush(ret, scroll, true)
ret:set_direction(dir) ret:set_direction(dir)
ret:set_widget(widget) ret:set_widget(widget)

View File

@ -10,7 +10,7 @@ local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
local table = table local table = table
local pairs = pairs local pairs = pairs
local util = require("awful.util") local gtable = require("gears.table")
local fixed = {} local fixed = {}
@ -272,7 +272,7 @@ end
local function get_layout(dir, widget1, ...) local function get_layout(dir, widget1, ...)
local ret = base.make_widget(nil, nil, {enable_properties = true}) local ret = base.make_widget(nil, nil, {enable_properties = true})
util.table.crush(ret, fixed, true) gtable.crush(ret, fixed, true)
ret._private.dir = dir ret._private.dir = dir
ret._private.widgets = {} ret._private.widgets = {}

View File

@ -12,7 +12,7 @@ local table = table
local pairs = pairs local pairs = pairs
local floor = math.floor local floor = math.floor
local gmath = require("gears.math") local gmath = require("gears.math")
local util = require("awful.util") local gtable = require("gears.table")
local flex = {} local flex = {}
@ -141,7 +141,7 @@ end
local function get_layout(dir, widget1, ...) local function get_layout(dir, widget1, ...)
local ret = fixed[dir](widget1, ...) local ret = fixed[dir](widget1, ...)
util.table.crush(ret, flex, true) gtable.crush(ret, flex, true)
ret._private.fill_space = nil ret._private.fill_space = nil

View File

@ -22,7 +22,7 @@ local table = table
local pairs = pairs local pairs = pairs
local ipairs = ipairs local ipairs = ipairs
local math = math local math = math
local util = require("awful.util") local gtable = require("gears.table")
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
local grid = { mt = {} } local grid = { mt = {} }
@ -868,7 +868,7 @@ local function new(orientation)
local ret = base.make_widget(nil, nil, {enable_properties = true}) local ret = base.make_widget(nil, nil, {enable_properties = true})
util.table.crush(ret, grid, true) gtable.crush(ret, grid, true)
ret._private.orientation = dir ret._private.orientation = dir
ret._private.widgets = {} ret._private.widgets = {}

View File

@ -15,7 +15,7 @@ local table = table
local pairs = pairs local pairs = pairs
local floor = math.floor local floor = math.floor
local gmath = require("gears.math") local gmath = require("gears.math")
local util = require("awful.util") local gtable = require("gears.table")
local ratio = {} local ratio = {}
@ -294,7 +294,7 @@ end
local function get_layout(dir, widget1, ...) local function get_layout(dir, widget1, ...)
local ret = flex[dir](widget1, ...) local ret = flex[dir](widget1, ...)
util.table.crush(ret, ratio, true) gtable.crush(ret, ratio, true)
ret._private.fill_space = nil ret._private.fill_space = nil

View File

@ -18,7 +18,7 @@ local base = require("wibox.widget.base" )
local fixed = require("wibox.layout.fixed") local fixed = require("wibox.layout.fixed")
local table = table local table = table
local pairs = pairs local pairs = pairs
local util = require("awful.util") local gtable = require("gears.table")
local stack = {mt={}} local stack = {mt={}}
@ -128,7 +128,7 @@ end
local function new(...) local function new(...)
local ret = fixed.horizontal(...) local ret = fixed.horizontal(...)
util.table.crush(ret, stack, true) gtable.crush(ret, stack, true)
return ret return ret
end end

View File

@ -8,7 +8,7 @@ local object = require("gears.object")
local cache = require("gears.cache") local cache = require("gears.cache")
local matrix = require("gears.matrix") local matrix = require("gears.matrix")
local protected_call = require("gears.protected_call") local protected_call = require("gears.protected_call")
local util = require("awful.util") local gtable = require("gears.table")
local setmetatable = setmetatable local setmetatable = setmetatable
local pairs = pairs local pairs = pairs
local type = type local type = type
@ -440,7 +440,7 @@ local function parse_table(t, leave_empty)
-- Pack the sparse table, if the container doesn't support sparse tables. -- Pack the sparse table, if the container doesn't support sparse tables.
if not leave_empty then if not leave_empty then
widgets = util.table.from_sparse(widgets) widgets = gtable.from_sparse(widgets)
max = #widgets max = #widgets
end end

View File

@ -15,7 +15,7 @@ local color = require( "gears.color" )
local base = require( "wibox.widget.base" ) local base = require( "wibox.widget.base" )
local beautiful = require( "beautiful" ) local beautiful = require( "beautiful" )
local shape = require( "gears.shape" ) local shape = require( "gears.shape" )
local util = require( "awful.util" ) local gtable = require( "gears.table" )
local checkbox = {} local checkbox = {}
@ -231,7 +231,7 @@ local function new(checked, args)
enable_properties = true, enable_properties = true,
}) })
util.table.crush(ret, checkbox) gtable.crush(ret, checkbox)
ret._private.checked = checked ret._private.checked = checked
ret._private.color = args.color and color(args.color) or nil ret._private.color = args.color and color(args.color) or nil

View File

@ -8,7 +8,7 @@
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
local surface = require("gears.surface") local surface = require("gears.surface")
local util = require("awful.util") local gtable = require("gears.table")
local setmetatable = setmetatable local setmetatable = setmetatable
local type = type local type = type
local print = print local print = print
@ -160,7 +160,7 @@ end
local function new(image, resize_allowed, clip_shape) local function new(image, resize_allowed, clip_shape)
local ret = base.make_widget(nil, nil, {enable_properties = true}) local ret = base.make_widget(nil, nil, {enable_properties = true})
util.table.crush(ret, imagebox, true) gtable.crush(ret, imagebox, true)
if image then if image then
ret:set_image(image) ret:set_image(image)

View File

@ -13,7 +13,7 @@
local color = require( "gears.color" ) local color = require( "gears.color" )
local base = require( "wibox.widget.base" ) local base = require( "wibox.widget.base" )
local beautiful = require( "beautiful" ) local beautiful = require( "beautiful" )
local util = require( "awful.util" ) local gtable = require( "gears.table" )
local pie = require( "gears.shape" ).pie local pie = require( "gears.shape" ).pie
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1) local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
@ -224,7 +224,7 @@ local function new(data_list)
enable_properties = true, enable_properties = true,
}) })
util.table.crush(ret, piechart) gtable.crush(ret, piechart)
rawset(ret, "fit" , fit ) rawset(ret, "fit" , fit )
rawset(ret, "draw", draw) rawset(ret, "draw", draw)

View File

@ -28,6 +28,7 @@ local base = require("wibox.widget.base")
local color = require("gears.color") local color = require("gears.color")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local shape = require("gears.shape") local shape = require("gears.shape")
local gtable = require("gears.table")
local progressbar = { mt = {} } local progressbar = { mt = {} }
@ -437,7 +438,7 @@ function progressbar.new(args)
pbar._private.value = 0 pbar._private.value = 0
pbar._private.max_value = 1 pbar._private.max_value = 1
util.table.crush(pbar, progressbar, true) gtable.crush(pbar, progressbar, true)
return pbar return pbar
end end

View File

@ -12,7 +12,7 @@
local setmetatable = setmetatable local setmetatable = setmetatable
local type = type local type = type
local color = require("gears.color") local color = require("gears.color")
local util = require("awful.util") local gtable = require("gears.table")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local base = require("wibox.widget.base") local base = require("wibox.widget.base")
local shape = require("gears.shape") local shape = require("gears.shape")
@ -441,9 +441,9 @@ local function new(args)
enable_properties = true, enable_properties = true,
}) })
util.table.crush(ret._private, args or {}) gtable.crush(ret._private, args or {})
util.table.crush(ret, slider, true) gtable.crush(ret, slider, true)
ret:connect_signal("button::press", mouse_press) ret:connect_signal("button::press", mouse_press)

View File

@ -6,7 +6,7 @@
local wbase = require("wibox.widget.base") local wbase = require("wibox.widget.base")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local util = require("awful.util") local gtable = require("gears.table")
local capi = { local capi = {
awesome = awesome, awesome = awesome,
screen = screen screen = screen
@ -155,7 +155,7 @@ end
local function new(revers) local function new(revers)
local ret = wbase.make_widget() local ret = wbase.make_widget()
util.table.crush(ret, systray, true) gtable.crush(ret, systray, true)
if revers then if revers then
ret:set_reverse(true) ret:set_reverse(true)

View File

@ -11,7 +11,7 @@ local base = require("wibox.widget.base")
local gdebug = require("gears.debug") local gdebug = require("gears.debug")
local beautiful = require("beautiful") local beautiful = require("beautiful")
local lgi = require("lgi") local lgi = require("lgi")
local util = require("awful.util") local gtable = require("gears.table")
local Pango = lgi.Pango local Pango = lgi.Pango
local PangoCairo = lgi.PangoCairo local PangoCairo = lgi.PangoCairo
local setmetatable = setmetatable local setmetatable = setmetatable
@ -263,7 +263,7 @@ end
local function new(text, ignore_markup) local function new(text, ignore_markup)
local ret = base.make_widget(nil, nil, {enable_properties = true}) local ret = base.make_widget(nil, nil, {enable_properties = true})
util.table.crush(ret, textbox, true) gtable.crush(ret, textbox, true)
ret._private.dpi = -1 ret._private.dpi = -1
ret._private.ctx = PangoCairo.font_map_get_default():create_context() ret._private.ctx = PangoCairo.font_map_get_default():create_context()

View File

@ -6,46 +6,6 @@
local util = require("awful.util") local util = require("awful.util")
describe("awful.util", function() describe("awful.util", function()
it("table.keys_filter", function()
local t = { "a", 1, function() end, false}
assert.is.same(util.table.keys_filter(t, "number", "function"), { 2, 3 })
end)
it("table.reverse", function()
local t = { "a", "b", c = "c", "d" }
assert.is.same(util.table.reverse(t), { "d", "b", "a", c = "c" })
end)
describe("table.iterate", function()
it("no filter", function()
local t = { "a", "b", c = "c", "d" }
local f = util.table.iterate(t, function() return true end)
assert.is.equal(f(), "a")
assert.is.equal(f(), "b")
assert.is.equal(f(), "d")
assert.is.equal(f(), nil)
assert.is.equal(f(), nil)
end)
it("b filter", function()
local t = { "a", "b", c = "c", "d" }
local f = util.table.iterate(t, function(i) return i == "b" end)
assert.is.equal(f(), "b")
assert.is.equal(f(), nil)
assert.is.equal(f(), nil)
end)
it("with offset", function()
local t = { "a", "b", c = "c", "d" }
local f = util.table.iterate(t, function() return true end, 2)
assert.is.equal(f(), "b")
assert.is.equal(f(), "d")
assert.is.equal(f(), "a")
assert.is.equal(f(), nil)
assert.is.equal(f(), nil)
end)
end)
describe("quote_pattern", function() describe("quote_pattern", function()
it("text", function() it("text", function()
assert.is.equal(util.quote_pattern("text"), "text") assert.is.equal(util.quote_pattern("text"), "text")

44
spec/gears/table_spec.lua Normal file
View File

@ -0,0 +1,44 @@
local gtable = require("gears.table")
describe("gears.table", function()
it("table.keys_filter", function()
local t = { "a", 1, function() end, false}
assert.is.same(gtable.keys_filter(t, "number", "function"), { 2, 3 })
end)
it("table.reverse", function()
local t = { "a", "b", c = "c", "d" }
assert.is.same(gtable.reverse(t), { "d", "b", "a", c = "c" })
end)
describe("table.iterate", function()
it("no filter", function()
local t = { "a", "b", c = "c", "d" }
local f = gtable.iterate(t, function() return true end)
assert.is.equal(f(), "a")
assert.is.equal(f(), "b")
assert.is.equal(f(), "d")
assert.is.equal(f(), nil)
assert.is.equal(f(), nil)
end)
it("b filter", function()
local t = { "a", "b", c = "c", "d" }
local f = gtable.iterate(t, function(i) return i == "b" end)
assert.is.equal(f(), "b")
assert.is.equal(f(), nil)
assert.is.equal(f(), nil)
end)
it("with offset", function()
local t = { "a", "b", c = "c", "d" }
local f = gtable.iterate(t, function() return true end, 2)
assert.is.equal(f(), "b")
assert.is.equal(f(), "d")
assert.is.equal(f(), "a")
assert.is.equal(f(), nil)
assert.is.equal(f(), nil)
end)
end)
end)

View File

@ -1,5 +1,6 @@
local timer = require("gears.timer") local timer = require("gears.timer")
local awful = require("awful") local awful = require("awful")
local gtable = require("gears.table")
local runner = { local runner = {
quit_awesome_on_error = os.getenv('TEST_PAUSE_ON_ERRORS') ~= '1', quit_awesome_on_error = os.getenv('TEST_PAUSE_ON_ERRORS') ~= '1',
@ -8,9 +9,9 @@ local runner = {
-- Helpers. -- Helpers.
--- Add some rules to awful.rules.rules, after the defaults. --- Add some rules to awful.rules.rules, after the defaults.
local default_rules = awful.util.table.clone(awful.rules.rules) local default_rules = gtable.clone(awful.rules.rules)
runner.add_to_default_rules = function(r) runner.add_to_default_rules = function(r)
awful.rules.rules = awful.util.table.clone(default_rules) awful.rules.rules = gtable.clone(default_rules)
table.insert(awful.rules.rules, r) table.insert(awful.rules.rules, r)
end end

View File

@ -2,6 +2,7 @@
-- it doesn't check if the layout are correct. -- it doesn't check if the layout are correct.
local awful = require("awful") local awful = require("awful")
local gtable = require("gears.table")
local first_layout = nil local first_layout = nil
@ -113,10 +114,10 @@ for _ in ipairs(awful.layout.layouts) do
if not first then if not first then
first = true first = true
else else
awful.util.table.merge(steps, {next_layout}) gtable.merge(steps, {next_layout})
end end
awful.util.table.merge(steps, common_steps) gtable.merge(steps, common_steps)
end end
require("_runner").run_steps(steps) require("_runner").run_steps(steps)

View File

@ -2,6 +2,7 @@ local runner = require( "_runner" )
local wibox = require( "wibox" ) local wibox = require( "wibox" )
local awful = require( "awful" ) local awful = require( "awful" )
local beautiful = require( "beautiful" ) local beautiful = require( "beautiful" )
local gtable = require("gears.table")
local steps = {} local steps = {}
@ -63,7 +64,7 @@ table.insert(steps, function()
layout = w.widget layout = w.widget
assert(layout) assert(layout)
button:buttons(awful.util.table.join( button:buttons(gtable.join(
button:buttons(), button:buttons(),
awful.button({}, 1, nil, function () awful.button({}, 1, nil, function ()
button:emit_signal_recursive("test::recursive") button:emit_signal_recursive("test::recursive")

View File

@ -3,6 +3,7 @@
local runner = require("_runner") local runner = require("_runner")
local test_client = require("_client") local test_client = require("_client")
local awful = require("awful") local awful = require("awful")
local gtable = require("gears.table")
local c local c
local s = screen[1] local s = screen[1]
@ -10,7 +11,7 @@ local tags = s.tags
local function wait_for_current_desktop(tag) local function wait_for_current_desktop(tag)
-- The X property has 0-based indicies -- The X property has 0-based indicies
local idx = awful.util.table.hasitem(tags, tag) - 1 local idx = gtable.hasitem(tags, tag) - 1
return function() return function()
local file = io.popen("xprop -notype -root _NET_CURRENT_DESKTOP") local file = io.popen("xprop -notype -root _NET_CURRENT_DESKTOP")
local result = file:read("*all") local result = file:read("*all")

View File

@ -2,10 +2,11 @@
local runner = require("_runner") local runner = require("_runner")
local awful = require("awful") local awful = require("awful")
local wibox = require("wibox") local wibox = require("wibox")
local gtable = require("gears.table")
-- "Enable" titlebars (so that the titlebar can prevent garbage collection) -- "Enable" titlebars (so that the titlebar can prevent garbage collection)
client.connect_signal("manage", function (c) client.connect_signal("manage", function (c)
local buttons = awful.util.table.join( local buttons = gtable.join(
awful.button({ }, 1, function() awful.button({ }, 1, function()
client.focus = c client.focus = c
c:raise() c:raise()