From 36f4e6cb8a30c1ac89c45fbf5c62e7c42db202c4 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 8 Apr 2009 17:08:26 +0200 Subject: [PATCH] awful.remote: import with remote eval Signed-off-by: Julien Danjou --- lib/awful/init.lua.in | 1 + lib/awful/remote.lua.in | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 lib/awful/remote.lua.in diff --git a/lib/awful/init.lua.in b/lib/awful/init.lua.in index 12961fb4..58b05c43 100644 --- a/lib/awful/init.lua.in +++ b/lib/awful/init.lua.in @@ -17,6 +17,7 @@ require("awful.util") require("awful.widget") require("awful.menu") require("awful.mouse") +require("awful.remote") --- AWesome Functions very UsefuL module("awful") diff --git a/lib/awful/remote.lua.in b/lib/awful/remote.lua.in new file mode 100644 index 00000000..7193cf77 --- /dev/null +++ b/lib/awful/remote.lua.in @@ -0,0 +1,47 @@ +--------------------------------------------------------------------------- +-- @author Julien Danjou <julien@danjou.info> +-- @copyright 2009 Julien Danjou +-- @release @AWESOME_VERSION@ +--------------------------------------------------------------------------- + +-- Grab environment we need +local hooks = require("awful.hooks") +local loadstring = loadstring +local tostring = tostring +local ipairs = ipairs +local table = table +local unpack = unpack +local type = type + +--- Remote control module for awful +module("awful.remote") + +if hooks.dbus then + hooks.dbus.register("org.awesome.Remote", function(data, code) + if data.member == "Eval" then + local f, e = loadstring(code) + if f then + results = { f() } + retvals = {} + for _, v in ipairs(results) do + local t = type(v) + if t == "boolean" then + table.insert(retvals, "b") + table.insert(retvals, v) + elseif t == "number" then + table.insert(retvals, "d") + table.insert(retvals, v) + else + table.insert(retvals, "s") + table.insert(retvals, tostring(v)) + end + end + return unpack(retvals) + elseif e then + return "s", e + end + end + end) +end + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80