2008-09-29 16:49:18 +02:00
|
|
|
---------------------------------------------------------------------------
|
2019-11-21 15:43:15 +01:00
|
|
|
--- Utility module for awful.
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008 Julien Danjou
|
2014-05-20 13:02:39 +02:00
|
|
|
-- @module awful.util
|
2008-09-29 16:49:18 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
|
|
|
local os = os
|
|
|
|
local assert = assert
|
2016-02-07 15:02:25 +01:00
|
|
|
local load = loadstring or load -- luacheck: globals loadstring (compatibility with Lua 5.1)
|
2008-09-30 17:00:19 +02:00
|
|
|
local loadfile = loadfile
|
2009-07-02 02:04:59 +02:00
|
|
|
local pairs = pairs
|
2008-09-30 15:50:41 +02:00
|
|
|
local type = type
|
2017-03-08 21:18:33 +01:00
|
|
|
local gtable = require("gears.table")
|
2009-05-27 17:49:20 +02:00
|
|
|
local string = string
|
2017-03-12 00:57:32 +01:00
|
|
|
local gstring = require("gears.string")
|
2016-05-16 06:57:15 +02:00
|
|
|
local grect = require("gears.geometry").rectangle
|
2017-03-03 00:02:03 +01:00
|
|
|
local gcolor = require("gears.color")
|
2017-02-14 00:16:45 +01:00
|
|
|
local gfs = require("gears.filesystem")
|
2008-09-29 16:49:18 +02:00
|
|
|
local capi =
|
|
|
|
{
|
|
|
|
awesome = awesome,
|
|
|
|
mouse = mouse
|
|
|
|
}
|
2017-03-15 06:08:40 +01:00
|
|
|
local gdebug = require("gears.debug")
|
2017-02-19 17:39:16 +01:00
|
|
|
local gmath = require("gears.math")
|
2008-09-29 16:49:18 +02:00
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
local util = {}
|
|
|
|
util.table = {}
|
2009-04-15 10:46:34 +02:00
|
|
|
|
2016-12-15 02:46:42 +01:00
|
|
|
--- The default shell used when spawing processes.
|
2019-06-08 06:15:59 +02:00
|
|
|
-- @param string
|
2012-11-30 22:46:55 +01:00
|
|
|
util.shell = os.getenv("SHELL") or "/bin/sh"
|
2009-05-09 13:28:57 +02:00
|
|
|
|
2017-06-06 00:55:11 +02:00
|
|
|
--- Execute a system command and road the output.
|
|
|
|
-- This function implementation **has been removed** and no longer
|
|
|
|
-- do anything. Use `awful.spawn.easy_async`.
|
|
|
|
-- @deprecated awful.util.pread
|
|
|
|
|
2015-02-09 20:23:03 +01:00
|
|
|
--- Display a deprecation notice, but only once per traceback.
|
2017-03-15 06:08:40 +01:00
|
|
|
-- @deprecated deprecate
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @param[opt] see The message to a new method / function to use.
|
2016-12-11 20:51:33 +01:00
|
|
|
-- @tparam table args Extra arguments
|
2017-04-10 21:57:12 +02:00
|
|
|
-- @tparam boolean args.raw Print the message as-is without the automatic
|
|
|
|
-- context (but only append a leading dot).
|
2017-03-01 23:02:49 +01:00
|
|
|
-- @tparam integer args.deprecated_in Print the message only when Awesome's
|
|
|
|
-- version is equal to or greater than deprecated_in.
|
2017-03-15 06:08:40 +01:00
|
|
|
-- @see gears.debug
|
2016-12-11 20:51:33 +01:00
|
|
|
function util.deprecate(see, args)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.debug.deprecate", {deprecated_in=5})
|
|
|
|
return gdebug.deprecate(see, args)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
2016-05-23 05:34:59 +02:00
|
|
|
--- Create a class proxy with deprecation messages.
|
|
|
|
-- This is useful when a class has moved somewhere else.
|
2017-03-15 06:08:40 +01:00
|
|
|
-- @deprecated deprecate_class
|
2016-05-23 05:34:59 +02:00
|
|
|
-- @tparam table fallback The new class
|
|
|
|
-- @tparam string old_name The old class name
|
|
|
|
-- @tparam string new_name The new class name
|
|
|
|
-- @treturn table A proxy class.
|
2017-03-15 06:08:40 +01:00
|
|
|
-- @see gears.debug
|
2016-05-23 05:34:59 +02:00
|
|
|
function util.deprecate_class(fallback, old_name, new_name)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.debug.deprecate_class", {deprecated_in=5})
|
|
|
|
return gdebug.deprecate_class(fallback, old_name, new_name)
|
2016-05-23 05:34:59 +02:00
|
|
|
end
|
|
|
|
|
2015-07-11 00:09:45 +02:00
|
|
|
--- Get a valid color for Pango markup
|
2017-03-03 00:02:03 +01:00
|
|
|
-- @deprecated ensure_pango_color
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @param color The color.
|
2015-07-11 00:09:45 +02:00
|
|
|
-- @tparam string fallback The color to return if the first is invalid. (default: black)
|
|
|
|
-- @treturn string color if it is valid, else fallback.
|
2017-03-03 00:02:03 +01:00
|
|
|
-- @see gears.color
|
2015-07-11 00:09:45 +02:00
|
|
|
function util.ensure_pango_color(color, fallback)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.color.ensure_pango_color", {deprecated_in=5})
|
2017-03-03 00:02:03 +01:00
|
|
|
return gcolor.ensure_pango_color(color, fallback)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Make i cycle.
|
2017-02-19 17:39:16 +01:00
|
|
|
-- @deprecated util.cycle
|
2011-11-09 21:34:30 +01:00
|
|
|
-- @param t A length. Must be greater than zero.
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @param i An absolute index to fit into #t.
|
2011-11-09 21:34:30 +01:00
|
|
|
-- @return An integer in (1, t) or nil if t is less than or equal to zero.
|
2017-02-19 17:39:16 +01:00
|
|
|
-- @see gears.math
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.cycle(t, i)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.math.cycle", {deprecated_in=5})
|
2017-02-19 17:39:16 +01:00
|
|
|
return gmath.cycle(t, i)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a directory
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @deprecated mkdir
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @param dir The directory.
|
|
|
|
-- @return mkdir return code
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @see gears.filesystem
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.mkdir(dir)
|
2017-08-10 12:18:54 +02:00
|
|
|
gdebug.deprecate("gears.filesystem.make_directories", {deprecated_in=5})
|
2017-04-08 11:02:53 +02:00
|
|
|
return gfs.make_directories(dir)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Eval Lua code.
|
|
|
|
-- @return The return value of Lua code.
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.util.eval
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.eval(s)
|
2012-06-16 14:22:35 +02:00
|
|
|
return assert(load(s))()
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Escape a string from XML char.
|
|
|
|
-- Useful to set raw text in textbox.
|
2017-03-12 00:57:32 +01:00
|
|
|
-- @deprecated util.escape
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @param text Text to escape.
|
|
|
|
-- @return Escape text.
|
2017-03-12 00:57:32 +01:00
|
|
|
-- @see gears.string
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.escape(text)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.string.xml_escape", {deprecated_in=5})
|
2017-03-12 00:57:32 +01:00
|
|
|
return gstring.xml_escape(text)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Unescape a string from entities.
|
2017-03-12 00:57:32 +01:00
|
|
|
-- @deprecated util.unescape
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @param text Text to unescape.
|
|
|
|
-- @return Unescaped text.
|
2017-03-12 00:57:32 +01:00
|
|
|
-- @see gears.string
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.unescape(text)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.string.xml_unescape", {deprecated_in=5})
|
2017-03-12 00:57:32 +01:00
|
|
|
return gstring.xml_unescape(text)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
2008-09-30 15:50:41 +02:00
|
|
|
--- Check if a file is a Lua valid file.
|
2008-09-30 17:00:19 +02:00
|
|
|
-- This is done by loading the content and compiling it with loadfile().
|
2008-09-30 15:50:41 +02:00
|
|
|
-- @param path The file path.
|
|
|
|
-- @return A function if everything is alright, a string with the error
|
|
|
|
-- otherwise.
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.util.checkfile
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.checkfile(path)
|
2008-09-30 17:07:25 +02:00
|
|
|
local f, e = loadfile(path)
|
2008-09-30 15:50:41 +02:00
|
|
|
-- Return function if function, otherwise return error.
|
|
|
|
if f then return f end
|
|
|
|
return e
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Try to restart awesome.
|
|
|
|
-- It checks if the configuration file is valid, and then restart if it's ok.
|
|
|
|
-- If it's not ok, the error will be returned.
|
|
|
|
-- @return Never return if awesome restart, or return a string error.
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.util.restart
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.restart()
|
|
|
|
local c = util.checkfile(capi.awesome.conffile)
|
2008-09-30 15:50:41 +02:00
|
|
|
|
|
|
|
if type(c) ~= "function" then
|
|
|
|
return c
|
|
|
|
end
|
|
|
|
|
|
|
|
capi.awesome.restart()
|
|
|
|
end
|
|
|
|
|
2015-11-28 19:33:33 +01:00
|
|
|
--- Get the config home according to the XDG basedir specification.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @deprecated get_xdg_config_home
|
2015-11-28 19:33:33 +01:00
|
|
|
-- @return the config home (XDG_CONFIG_HOME) with a slash at the end.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @see gears.filesystem
|
2015-11-28 19:33:33 +01:00
|
|
|
function util.get_xdg_config_home()
|
2017-08-10 12:18:54 +02:00
|
|
|
gdebug.deprecate("gears.filesystem.get_xdg_config_home", {deprecated_in=5})
|
2017-02-14 00:16:45 +01:00
|
|
|
return gfs.get_xdg_config_home()
|
2015-11-28 19:33:33 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Get the cache home according to the XDG basedir specification.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @deprecated get_xdg_cache_home
|
2015-11-28 19:33:33 +01:00
|
|
|
-- @return the cache home (XDG_CACHE_HOME) with a slash at the end.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @see gears.filesystem
|
2015-11-28 19:33:33 +01:00
|
|
|
function util.get_xdg_cache_home()
|
2017-08-10 12:18:54 +02:00
|
|
|
gdebug.deprecate("gears.filesystem.get_xdg_cache_home", {deprecated_in=5})
|
2017-02-14 00:16:45 +01:00
|
|
|
return gfs.get_xdg_cache_home()
|
2015-11-28 19:33:33 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Get the path to the user's config dir.
|
|
|
|
-- This is the directory containing the configuration file ("rc.lua").
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @deprecated get_configuration_dir
|
2015-11-28 19:33:33 +01:00
|
|
|
-- @return A string with the requested path with a slash at the end.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @see gears.filesystem
|
2015-11-28 19:33:33 +01:00
|
|
|
function util.get_configuration_dir()
|
2017-08-10 12:18:54 +02:00
|
|
|
gdebug.deprecate("gears.filesystem.get_configuration_dir", {deprecated_in=5})
|
2017-02-14 00:16:45 +01:00
|
|
|
return gfs.get_configuration_dir()
|
2015-11-28 19:33:33 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Get the path to a directory that should be used for caching data.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @deprecated get_cache_dir
|
2015-11-28 19:33:33 +01:00
|
|
|
-- @return A string with the requested path with a slash at the end.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @see gears.filesystem
|
2015-11-28 19:33:33 +01:00
|
|
|
function util.get_cache_dir()
|
2017-08-10 12:18:54 +02:00
|
|
|
gdebug.deprecate("gears.filesystem.get_cache_dir", {deprecated_in=5})
|
2017-02-14 00:16:45 +01:00
|
|
|
return gfs.get_cache_dir()
|
2015-11-28 19:33:33 +01:00
|
|
|
end
|
|
|
|
|
2015-12-11 18:24:30 +01:00
|
|
|
--- Get the path to the directory where themes are installed.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @deprecated get_themes_dir
|
2015-12-11 18:24:30 +01:00
|
|
|
-- @return A string with the requested path with a slash at the end.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @see gears.filesystem
|
2015-12-11 18:24:30 +01:00
|
|
|
function util.get_themes_dir()
|
2017-08-10 12:18:54 +02:00
|
|
|
gdebug.deprecate("gears.filesystem.get_themes_dir", {deprecated_in=5})
|
2017-02-14 00:16:45 +01:00
|
|
|
return gfs.get_themes_dir()
|
2015-12-11 18:24:30 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Get the path to the directory where our icons are installed.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @deprecated get_awesome_icon_dir
|
2015-12-11 18:24:30 +01:00
|
|
|
-- @return A string with the requested path with a slash at the end.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @see gears.filesystem
|
2015-12-11 18:24:30 +01:00
|
|
|
function util.get_awesome_icon_dir()
|
2017-08-10 12:18:54 +02:00
|
|
|
gdebug.deprecate("gears.filesystem.get_awesome_icon_dir", {deprecated_in=5})
|
2017-02-14 00:16:45 +01:00
|
|
|
return gfs.get_awesome_icon_dir()
|
2015-12-11 18:24:30 +01:00
|
|
|
end
|
|
|
|
|
2009-02-15 20:12:44 +01:00
|
|
|
--- Get the user's config or cache dir.
|
|
|
|
-- It first checks XDG_CONFIG_HOME / XDG_CACHE_HOME, but then goes with the
|
|
|
|
-- default paths.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @deprecated getdir
|
2009-02-15 20:12:44 +01:00
|
|
|
-- @param d The directory to get (either "config" or "cache").
|
|
|
|
-- @return A string containing the requested path.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @see gears.filesystem
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.getdir(d)
|
2017-08-10 12:18:54 +02:00
|
|
|
gdebug.deprecate("gears.filesystem.get_dir", {deprecated_in=5})
|
2017-02-14 00:16:45 +01:00
|
|
|
return gfs.get_dir(d)
|
Various changes to awful.util and invaders
This commit changes various aspects of awful.util and invaders:
awful.util:
- added awful.util.getdir(d)
This function takes one argument and returns a matching directory,
as of now, only "cache" is supported. The return value is either
$XDG_CACHE_HOME/awesome/ or $HOME/.cache/awesome/, XDG_CACHE_HOME
takes precedence
invaders:
- renamed invaders to awesome invaders
at two places in the sourcecode, invaders is referred to as
"Space Invaders for Awesome". As Taiko holds the trademark for
the term "Space Invaders", I changed both of its occurences to
"Awesome Invaders" to avoid conflicts with the law of Japan and
the United States of America (and possibly others)
- added support for XDG_CACHE_HOME
this change adds support for XDG_CACHE_HOME as the cache directory
for highscores and screenshots
- added some parameters to invaders.run()
this change adds three parameters to invaders.run, supplied as a
table. They are "x", "y" and "solidbg".
"x" sets the X coordinate of the playfield
"y" sets the Y coordinate of the playfield
"solidbg" sets the color of the playfield background for people who
have problems with transparency. This still looks rather hackish and
needs to be polished
- changed startup position
up until now, invaders always started at (100,100) on the first
screen, now it starts centered to the screen on which the mouse cursor
is.
2008-10-17 19:05:57 +02:00
|
|
|
end
|
2008-11-22 17:23:03 +01:00
|
|
|
|
2011-11-02 02:42:37 +01:00
|
|
|
--- Search for an icon and return the full path.
|
2015-02-26 15:40:00 +01:00
|
|
|
-- It searches for the icon path under the given directories with respect to the
|
|
|
|
-- given extensions for the icon filename.
|
2011-11-02 02:42:37 +01:00
|
|
|
-- @param iconname The name of the icon to search for.
|
|
|
|
-- @param exts Table of image extensions allowed, otherwise { 'png', gif' }
|
|
|
|
-- @param dirs Table of dirs to search, otherwise { '/usr/share/pixmaps/' }
|
2015-02-26 22:06:34 +01:00
|
|
|
-- @tparam[opt] string size The size. If this is specified, subdirectories `x`
|
2015-02-26 15:40:00 +01:00
|
|
|
-- of the dirs are searched first.
|
2019-06-08 01:08:05 +02:00
|
|
|
-- @staticfct awful.util.geticonpath
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.geticonpath(iconname, exts, dirs, size)
|
2016-02-07 15:02:25 +01:00
|
|
|
exts = exts or { 'png', 'gif' }
|
|
|
|
dirs = dirs or { '/usr/share/pixmaps/', '/usr/share/icons/hicolor/' }
|
2014-05-03 11:15:14 +02:00
|
|
|
local icontypes = { 'apps', 'actions', 'categories', 'emblems',
|
|
|
|
'mimetypes', 'status', 'devices', 'extras', 'places', 'stock' }
|
2011-11-02 02:42:37 +01:00
|
|
|
for _, d in pairs(dirs) do
|
2014-04-11 23:09:10 +02:00
|
|
|
local icon
|
2011-11-02 02:42:37 +01:00
|
|
|
for _, e in pairs(exts) do
|
2012-05-28 19:16:11 +02:00
|
|
|
icon = d .. iconname .. '.' .. e
|
2017-02-14 00:16:45 +01:00
|
|
|
if gfs.file_readable(icon) then
|
2011-11-02 02:42:37 +01:00
|
|
|
return icon
|
2012-09-14 21:49:14 +02:00
|
|
|
end
|
2014-04-11 23:09:10 +02:00
|
|
|
if size then
|
|
|
|
for _, t in pairs(icontypes) do
|
|
|
|
icon = string.format("%s%ux%u/%s/%s.%s", d, size, size, t, iconname, e)
|
2017-02-14 00:16:45 +01:00
|
|
|
if gfs.file_readable(icon) then
|
2014-04-11 23:09:10 +02:00
|
|
|
return icon
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-09-14 21:49:14 +02:00
|
|
|
end
|
|
|
|
end
|
2011-11-02 02:42:37 +01:00
|
|
|
end
|
|
|
|
|
2017-02-14 00:16:45 +01:00
|
|
|
--- Check if a file exists, is readable and not a directory.
|
|
|
|
-- @deprecated file_readable
|
2015-02-09 20:17:40 +01:00
|
|
|
-- @param filename The file path.
|
|
|
|
-- @return True if file exists and is readable.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @see gears.filesystem
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.file_readable(filename)
|
2017-08-10 12:18:54 +02:00
|
|
|
gdebug.deprecate("gears.filesystem.file_readable", {deprecated_in=5})
|
2017-02-14 00:16:45 +01:00
|
|
|
return gfs.file_readable(filename)
|
2008-11-22 17:23:03 +01:00
|
|
|
end
|
|
|
|
|
2015-10-11 13:14:15 +02:00
|
|
|
--- Check if a path exists, is readable and is a directory.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @deprecated dir_readable
|
2015-10-11 13:14:15 +02:00
|
|
|
-- @tparam string path The directory path.
|
|
|
|
-- @treturn boolean True if dir exists and is readable.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @see gears.filesystem
|
2015-10-11 13:14:15 +02:00
|
|
|
function util.dir_readable(path)
|
2017-08-10 12:18:54 +02:00
|
|
|
gdebug.deprecate("gears.filesystem.dir_readable", {deprecated_in=5})
|
2017-02-14 00:16:45 +01:00
|
|
|
return gfs.dir_readable(path)
|
2015-10-11 13:14:15 +02:00
|
|
|
end
|
|
|
|
|
2015-10-18 13:04:56 +02:00
|
|
|
--- Check if a path is a directory.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @deprecated is_dir
|
2015-10-18 13:04:56 +02:00
|
|
|
-- @tparam string path
|
|
|
|
-- @treturn bool True if path exists and is a directory.
|
2017-02-14 00:16:45 +01:00
|
|
|
-- @see gears.filesystem
|
2015-10-18 13:04:56 +02:00
|
|
|
function util.is_dir(path)
|
2017-08-10 12:18:54 +02:00
|
|
|
gdebug.deprecate("gears.filesystem.is_dir", {deprecated_in=5})
|
2017-02-14 00:16:45 +01:00
|
|
|
return gfs.is_dir(path)
|
2015-10-18 13:04:56 +02:00
|
|
|
end
|
|
|
|
|
2009-04-15 10:31:41 +02:00
|
|
|
--- Return all subsets of a specific set.
|
|
|
|
-- This function, giving a set, will return all subset it.
|
|
|
|
-- For example, if we consider a set with value { 10, 15, 34 },
|
|
|
|
-- it will return a table containing 2^n set:
|
|
|
|
-- { }, { 10 }, { 15 }, { 34 }, { 10, 15 }, { 10, 34 }, etc.
|
2017-02-19 17:39:16 +01:00
|
|
|
-- @deprecated util.subsets
|
2009-04-15 10:31:41 +02:00
|
|
|
-- @param set A set.
|
|
|
|
-- @return A table with all subset.
|
2017-02-19 17:39:16 +01:00
|
|
|
-- @see gears.math
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.subsets(set)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.math.subsets", {deprecated_in=5})
|
2017-02-19 17:39:16 +01:00
|
|
|
return gmath.subsets(set)
|
2009-04-15 10:31:41 +02:00
|
|
|
end
|
|
|
|
|
2015-02-20 15:45:53 +01:00
|
|
|
--- Get the nearest rectangle in the given direction. Every rectangle is specified as a table
|
2012-09-14 21:49:14 +02:00
|
|
|
-- with 'x', 'y', 'width', 'height' keys, the same as client or screen geometries.
|
2016-05-16 06:57:15 +02:00
|
|
|
-- @deprecated awful.util.get_rectangle_in_direction
|
2012-09-14 21:49:14 +02:00
|
|
|
-- @param dir The direction, can be either "up", "down", "left" or "right".
|
|
|
|
-- @param recttbl A table of rectangle specifications.
|
|
|
|
-- @param cur The current rectangle.
|
|
|
|
-- @return The index for the rectangle in recttbl closer to cur in the given direction. nil if none found.
|
2016-05-16 06:57:15 +02:00
|
|
|
-- @see gears.geometry
|
2012-09-14 21:49:14 +02:00
|
|
|
function util.get_rectangle_in_direction(dir, recttbl, cur)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.geometry.rectangle.get_in_direction", {deprecated_in=4})
|
2016-05-16 06:57:15 +02:00
|
|
|
return grect.get_in_direction(dir, recttbl, cur)
|
2012-09-14 21:49:14 +02:00
|
|
|
end
|
|
|
|
|
2009-04-15 21:33:21 +02:00
|
|
|
--- Join all tables given as parameters.
|
2009-04-18 22:44:36 +02:00
|
|
|
-- This will iterate all tables and insert all their keys into a new table.
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @deprecated util.table.join
|
2009-04-15 21:33:21 +02:00
|
|
|
-- @param args A list of tables to join
|
2009-04-18 22:44:36 +02:00
|
|
|
-- @return A new table containing all keys from the arguments.
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @see gears.table
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.table.join(...)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.table.join", {deprecated_in=5})
|
2017-03-08 21:18:33 +01:00
|
|
|
return gtable.join(...)
|
2009-04-15 10:46:34 +02:00
|
|
|
end
|
|
|
|
|
2016-05-28 05:24:03 +02:00
|
|
|
--- Override elements in the first table by the one in the second.
|
|
|
|
--
|
|
|
|
-- Note that this method doesn't copy entries found in `__index`.
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @deprecated util.table.crush
|
2016-01-16 04:05:24 +01:00
|
|
|
-- @tparam table t the table to be overriden
|
|
|
|
-- @tparam table set the table used to override members of `t`
|
2016-05-28 05:24:03 +02:00
|
|
|
-- @tparam[opt=false] boolean raw Use rawset (avoid the metatable)
|
2016-01-16 04:05:24 +01:00
|
|
|
-- @treturn table t (for convenience)
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @see gears.table
|
2016-05-28 05:24:03 +02:00
|
|
|
function util.table.crush(t, set, raw)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.table.crush", {deprecated_in=5})
|
2017-03-08 21:18:33 +01:00
|
|
|
return gtable.crush(t, set, raw)
|
2016-01-16 04:05:24 +01:00
|
|
|
end
|
|
|
|
|
2016-01-16 04:46:35 +01:00
|
|
|
--- 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
|
|
|
|
--
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @deprecated util.table.from_sparse
|
2016-01-16 04:46:35 +01:00
|
|
|
-- @tparam table t A potentially sparse table
|
|
|
|
-- @treturn table A packed table with all numeric keys
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @see gears.table
|
2016-01-16 04:46:35 +01:00
|
|
|
function util.table.from_sparse(t)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.table.from_sparse", {deprecated_in=5})
|
2017-03-08 21:18:33 +01:00
|
|
|
return gtable.from_sparse(t)
|
2016-01-16 04:46:35 +01:00
|
|
|
end
|
|
|
|
|
2009-04-27 18:33:15 +02:00
|
|
|
--- Check if a table has an item and return its key.
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @deprecated util.table.hasitem
|
2009-04-27 18:33:15 +02:00
|
|
|
-- @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.
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @see gears.table
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.table.hasitem(t, item)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.table.hasitem", {deprecated_in=5})
|
2017-03-08 21:18:33 +01:00
|
|
|
return gtable.hasitem(t, item)
|
2009-04-27 18:33:15 +02:00
|
|
|
end
|
|
|
|
|
2009-05-27 17:49:20 +02:00
|
|
|
--- Split a string into multiple lines
|
2017-03-12 00:57:32 +01:00
|
|
|
-- @deprecated util.linewrap
|
2009-05-27 17:49:20 +02:00
|
|
|
-- @param text String to wrap.
|
|
|
|
-- @param width Maximum length of each line. Default: 72.
|
|
|
|
-- @param indent Number of spaces added before each wrapped line. Default: 0.
|
|
|
|
-- @return The string with lines wrapped to width.
|
2017-03-12 00:57:32 +01:00
|
|
|
-- @see gears.string
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.linewrap(text, width, indent)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.string.linewrap", {deprecated_in=5})
|
2017-03-12 00:57:32 +01:00
|
|
|
return gstring.linewrap(text, width, indent)
|
2009-05-27 17:49:20 +02:00
|
|
|
end
|
|
|
|
|
2015-09-20 16:42:24 +02:00
|
|
|
--- Count number of lines in a string
|
2017-03-12 00:57:32 +01:00
|
|
|
-- @deprecated util.linecount
|
2015-09-20 16:42:24 +02:00
|
|
|
-- @tparam string text Input string.
|
|
|
|
-- @treturn int Number of lines.
|
2017-03-12 00:57:32 +01:00
|
|
|
-- @see gears.string
|
2015-09-20 16:42:24 +02:00
|
|
|
function util.linecount(text)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.string.linecount", {deprecated_in=5})
|
2017-03-12 00:57:32 +01:00
|
|
|
return gstring.linecount(text)
|
2015-09-20 16:42:24 +02:00
|
|
|
end
|
|
|
|
|
2021-03-22 20:05:17 +01:00
|
|
|
--- Get a sorted table with all keys from a table.
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @deprecated util.table.keys
|
2009-07-02 02:04:59 +02:00
|
|
|
-- @param t the table for which the keys to get
|
|
|
|
-- @return A table with keys
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @see gears.table
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.table.keys(t)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.table.keys", {deprecated_in=5})
|
2017-03-08 21:18:33 +01:00
|
|
|
return gtable.keys(t)
|
2009-07-02 02:04:59 +02:00
|
|
|
end
|
|
|
|
|
2009-07-02 02:05:29 +02:00
|
|
|
--- Filter a tables keys for certain content types
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @deprecated util.table.keys_filter
|
2009-07-02 02:05:29 +02:00
|
|
|
-- @param t The table to retrieve the keys for
|
|
|
|
-- @param ... the types to look for
|
|
|
|
-- @return A filtered table with keys
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @see gears.table
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.table.keys_filter(t, ...)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.table.keys_filter", {deprecated_in=5})
|
2017-03-08 21:18:33 +01:00
|
|
|
return gtable.keys_filter(t, ...)
|
2009-07-02 02:05:29 +02:00
|
|
|
end
|
|
|
|
|
2009-07-02 02:05:42 +02:00
|
|
|
--- Reverse a table
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @deprecated util.table.reverse
|
2009-07-02 02:05:42 +02:00
|
|
|
-- @param t the table to reverse
|
|
|
|
-- @return the reversed table
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @see gears.table
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.table.reverse(t)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.table.reverse", {deprecated_in=5})
|
2017-03-08 21:18:33 +01:00
|
|
|
return gtable.reverse(t)
|
2009-07-02 02:05:42 +02:00
|
|
|
end
|
|
|
|
|
2009-06-25 01:15:07 +02:00
|
|
|
--- Clone a table
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @deprecated util.table.clone
|
2009-06-25 01:15:07 +02:00
|
|
|
-- @param t the table to clone
|
2014-03-14 17:10:24 +01:00
|
|
|
-- @param deep Create a deep clone? (default: true)
|
2009-06-25 01:15:07 +02:00
|
|
|
-- @return a clone of t
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @see gears.table
|
2014-03-14 17:10:24 +01:00
|
|
|
function util.table.clone(t, deep)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.table.clone", {deprecated_in=5})
|
2017-03-08 21:18:33 +01:00
|
|
|
return gtable.clone(t, deep)
|
2009-06-25 01:15:07 +02:00
|
|
|
end
|
|
|
|
|
2012-02-16 22:00:41 +01:00
|
|
|
---
|
|
|
|
-- Returns an iterator to cycle through, starting from the first element or the
|
2014-03-15 02:56:58 +01:00
|
|
|
-- given index, all elements of a table that match a given criteria.
|
2012-04-02 13:36:12 +02:00
|
|
|
--
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @deprecated util.table.iterate
|
2012-02-16 22:00:41 +01:00
|
|
|
-- @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)
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @see gears.table
|
2012-06-12 20:13:09 +02:00
|
|
|
function util.table.iterate(t, filter, start)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.table.iterate", {deprecated_in=5})
|
2017-03-08 21:18:33 +01:00
|
|
|
return gtable.iterate(t, filter, start)
|
2012-02-16 22:00:41 +01:00
|
|
|
end
|
2012-06-12 20:13:09 +02:00
|
|
|
|
2015-09-20 16:42:24 +02:00
|
|
|
|
|
|
|
--- Merge items from the one table to another one
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @deprecated util.table.merge
|
2015-09-20 16:42:24 +02:00
|
|
|
-- @tparam table t the container table
|
|
|
|
-- @tparam table set the mixin table
|
2016-01-19 23:14:29 +01:00
|
|
|
-- @treturn table Return `t` for convenience
|
2017-03-08 21:18:33 +01:00
|
|
|
-- @see gears.table
|
2015-09-20 16:42:24 +02:00
|
|
|
function util.table.merge(t, set)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.table.merge", {deprecated_in=5})
|
2017-03-08 21:18:33 +01:00
|
|
|
return gtable.merge(t, set)
|
2015-09-20 16:42:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-01-22 01:30:13 +01:00
|
|
|
-- Escape all special pattern-matching characters so that lua interprets them
|
|
|
|
-- literally instead of as a character class.
|
|
|
|
-- Source: http://stackoverflow.com/a/20778724/15690
|
2017-03-12 00:57:32 +01:00
|
|
|
-- @deprecated util.quote_pattern
|
|
|
|
-- @see gears.string
|
2015-01-22 01:30:13 +01:00
|
|
|
function util.quote_pattern(s)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.string.quote_pattern", {deprecated_in=5})
|
2017-03-12 00:57:32 +01:00
|
|
|
return gstring.quote_pattern(s)
|
2015-01-22 01:30:13 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Generate a pattern matching expression that ignores case.
|
|
|
|
-- @param s Original pattern matching expression.
|
2017-03-12 00:57:32 +01:00
|
|
|
-- @deprecated util.query_to_pattern
|
|
|
|
-- @see gears.string
|
2015-01-22 01:30:13 +01:00
|
|
|
function util.query_to_pattern(q)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.string.query_to_pattern", {deprecated_in=5})
|
2017-03-12 00:57:32 +01:00
|
|
|
return gstring.query_to_pattern(q)
|
2015-01-22 01:30:13 +01:00
|
|
|
end
|
|
|
|
|
2015-08-12 14:09:45 +02:00
|
|
|
--- Round a number to an integer.
|
2017-02-19 17:39:16 +01:00
|
|
|
-- @deprecated util.round
|
2015-08-12 14:09:45 +02:00
|
|
|
-- @tparam number x
|
|
|
|
-- @treturn integer
|
2017-02-19 17:39:16 +01:00
|
|
|
-- @see gears.math
|
2015-08-12 14:09:45 +02:00
|
|
|
function util.round(x)
|
2017-03-15 06:08:40 +01:00
|
|
|
gdebug.deprecate("gears.math.round", {deprecated_in=5})
|
2017-02-19 17:39:16 +01:00
|
|
|
return gmath.round(x)
|
2015-08-12 14:09:45 +02:00
|
|
|
end
|
|
|
|
|
2012-06-12 20:13:09 +02:00
|
|
|
return util
|
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|