2008-09-29 16:49:18 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
|
|
|
local os = os
|
|
|
|
local io = io
|
|
|
|
local assert = assert
|
|
|
|
local loadstring = loadstring
|
2008-09-30 17:00:19 +02:00
|
|
|
local loadfile = loadfile
|
2008-09-29 16:49:18 +02:00
|
|
|
local debug = debug
|
|
|
|
local print = print
|
2008-09-30 15:50:41 +02:00
|
|
|
local type = type
|
2008-09-29 16:49:18 +02:00
|
|
|
local capi =
|
|
|
|
{
|
|
|
|
awesome = awesome,
|
|
|
|
mouse = mouse
|
|
|
|
}
|
|
|
|
|
|
|
|
--- Utility module for awful
|
|
|
|
module("awful.util")
|
|
|
|
|
|
|
|
function deprecate()
|
|
|
|
print("W: awful: function is deprecated")
|
|
|
|
print(debug.traceback())
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Strip alpha part of color.
|
|
|
|
-- @param color The color.
|
|
|
|
-- @return The color without alpha channel.
|
|
|
|
function color_strip_alpha(color)
|
|
|
|
if color:len() == 9 then
|
|
|
|
color = color:sub(1, 7)
|
|
|
|
end
|
|
|
|
return color
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Make i cycle.
|
|
|
|
-- @param t A length.
|
|
|
|
-- @param i An absolute index to fit into #t.
|
|
|
|
-- @return The object at new index.
|
|
|
|
function cycle(t, i)
|
|
|
|
while i > t do i = i - t end
|
|
|
|
while i < 1 do i = i + t end
|
|
|
|
return i
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a directory
|
|
|
|
-- @param dir The directory.
|
|
|
|
-- @return mkdir return code
|
|
|
|
function mkdir(dir)
|
|
|
|
return os.execute("mkdir -p " .. dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Spawn a program.
|
|
|
|
-- @param cmd The command.
|
|
|
|
-- @param screen The screen where to spawn window.
|
|
|
|
-- @return The awesome.spawn return value.
|
|
|
|
function spawn(cmd, screen)
|
|
|
|
if cmd and cmd ~= "" then
|
|
|
|
return capi.awesome.spawn(cmd .. "&", screen or capi.mouse.screen)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Read a program output and returns its output as a string.
|
|
|
|
-- @param cmd The command to run.
|
|
|
|
-- @return A string with the program output.
|
|
|
|
function pread(cmd)
|
|
|
|
if cmd and cmd ~= "" then
|
|
|
|
local f = io.popen(cmd, 'r')
|
|
|
|
local s = f:read("*all")
|
|
|
|
f:close()
|
|
|
|
return s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Eval Lua code.
|
|
|
|
-- @return The return value of Lua code.
|
|
|
|
function eval(s)
|
|
|
|
return assert(loadstring("return " .. s))()
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Escape a string from XML char.
|
|
|
|
-- Useful to set raw text in textbox.
|
|
|
|
-- @param text Text to escape.
|
|
|
|
-- @return Escape text.
|
|
|
|
function escape(text)
|
|
|
|
if text then
|
|
|
|
text = text:gsub("&", "&")
|
|
|
|
text = text:gsub("<", "<")
|
|
|
|
text = text:gsub(">", ">")
|
|
|
|
text = text:gsub("'", "'")
|
|
|
|
text = text:gsub("\"", """)
|
|
|
|
end
|
|
|
|
return text
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Unescape a string from entities.
|
|
|
|
-- @param text Text to unescape.
|
|
|
|
-- @return Unescaped text.
|
|
|
|
function unescape(text)
|
|
|
|
if text then
|
|
|
|
text = text:gsub("&", "&")
|
|
|
|
text = text:gsub("<", "<")
|
|
|
|
text = text:gsub(">", ">")
|
|
|
|
text = text:gsub("'", "'")
|
|
|
|
text = text:gsub(""", "\"")
|
|
|
|
end
|
|
|
|
return text
|
|
|
|
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.
|
|
|
|
function 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.
|
|
|
|
function restart()
|
|
|
|
local c = checkfile(capi.awesome.conffile())
|
|
|
|
|
|
|
|
if type(c) ~= "function" then
|
|
|
|
return c
|
|
|
|
end
|
|
|
|
|
|
|
|
capi.awesome.restart()
|
|
|
|
end
|
|
|
|
|
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
|
|
|
function getdir(d)
|
|
|
|
if d == "cache" then
|
|
|
|
if os.getenv("XDG_CACHE_HOME") then
|
|
|
|
return os.getenv("XDG_CACHE_HOME").."/awesome"
|
|
|
|
end
|
|
|
|
return os.getenv("HOME").."/.cache/awesome"
|
|
|
|
end
|
|
|
|
end
|
2008-09-29 16:49:18 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|