2008-05-26 20:39:54 +02:00
|
|
|
/*
|
2009-04-03 13:09:17 +02:00
|
|
|
* luaa.c - Lua configuration management
|
2008-05-26 20:39:54 +02:00
|
|
|
*
|
2009-01-06 17:02:08 +01:00
|
|
|
* Copyright © 2008-2009 Julien Danjou <julien@danjou.info>
|
2008-05-26 20:39:54 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-12-21 06:54:15 +01:00
|
|
|
/** AwesomeWM lifecycle and low-level APIs.
|
2017-06-13 21:29:20 +02:00
|
|
|
*
|
2018-08-06 22:43:01 +02:00
|
|
|
* This module contains the functions and signal to manage the lifecycle of the
|
|
|
|
* AwesomeWM process. It allows to execute code at specific point from the early
|
|
|
|
* initialization all the way to the last events before exiting or restarting.
|
|
|
|
*
|
|
|
|
* Additionally it handles signals for spawn and keyboard related events.
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
|
|
|
* @author Julien Danjou <julien@danjou.info>
|
|
|
|
* @copyright 2008-2009 Julien Danjou
|
2018-08-06 22:43:01 +02:00
|
|
|
* @coreclassmod awesome
|
2015-02-27 00:24:23 +01:00
|
|
|
*/
|
|
|
|
|
2017-06-13 21:29:20 +02:00
|
|
|
/** Register a new xproperty.
|
|
|
|
*
|
|
|
|
* @tparam string name The name of the X11 property.
|
|
|
|
* @tparam string type One of "string", "number" or "boolean".
|
2022-07-05 10:37:14 +02:00
|
|
|
* @noreturn
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct register_xproperty
|
2017-06-13 21:29:20 +02:00
|
|
|
*/
|
|
|
|
|
2009-04-17 16:52:25 +02:00
|
|
|
#define _GNU_SOURCE
|
2008-11-08 14:22:20 +01:00
|
|
|
|
2014-03-30 20:07:48 +02:00
|
|
|
#include "luaa.h"
|
|
|
|
#include "globalconf.h"
|
2008-09-02 17:12:10 +02:00
|
|
|
#include "awesome.h"
|
2014-03-30 20:07:48 +02:00
|
|
|
#include "common/backtrace.h"
|
2014-04-13 17:48:03 +02:00
|
|
|
#include "common/version.h"
|
2009-09-07 17:28:55 +02:00
|
|
|
#include "config.h"
|
2014-03-30 20:07:48 +02:00
|
|
|
#include "event.h"
|
2009-09-14 20:22:12 +02:00
|
|
|
#include "objects/client.h"
|
2012-10-14 17:14:22 +02:00
|
|
|
#include "objects/drawable.h"
|
2014-03-30 20:07:48 +02:00
|
|
|
#include "objects/drawin.h"
|
2019-02-07 15:16:48 +01:00
|
|
|
#include "objects/selection_getter.h"
|
2014-03-30 15:12:47 +02:00
|
|
|
#include "objects/screen.h"
|
2019-02-10 15:49:42 +01:00
|
|
|
#include "objects/selection_acquire.h"
|
2019-02-10 17:51:53 +01:00
|
|
|
#include "objects/selection_transfer.h"
|
2019-02-06 09:30:16 +01:00
|
|
|
#include "objects/selection_watcher.h"
|
2014-03-30 20:07:48 +02:00
|
|
|
#include "objects/tag.h"
|
2014-03-07 13:49:24 +01:00
|
|
|
#include "property.h"
|
2009-01-06 17:02:08 +01:00
|
|
|
#include "selection.h"
|
2014-03-30 20:07:48 +02:00
|
|
|
#include "spawn.h"
|
2010-10-06 15:38:44 +02:00
|
|
|
#include "systray.h"
|
2015-02-23 17:08:24 +01:00
|
|
|
#include "xkb.h"
|
2015-05-14 22:57:22 +02:00
|
|
|
#include "xrdb.h"
|
2014-03-30 20:07:48 +02:00
|
|
|
|
|
|
|
#include <lua.h>
|
|
|
|
#include <lauxlib.h>
|
|
|
|
#include <lualib.h>
|
|
|
|
|
2020-02-29 23:09:07 +01:00
|
|
|
/* for strings and Unicode handling */
|
|
|
|
#include <glib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-03-30 20:07:48 +02:00
|
|
|
#include <basedir_fs.h>
|
|
|
|
|
|
|
|
#include <xcb/xcb_atom.h>
|
2017-01-01 14:18:59 +01:00
|
|
|
#include <xcb/xcb_aux.h>
|
2020-09-14 06:52:59 +02:00
|
|
|
#include "xkb_utf32_to_keysym_compat.c"
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2016-05-27 19:16:10 +02:00
|
|
|
#include <unistd.h> /* for gethostname() */
|
|
|
|
|
2009-04-18 16:07:31 +02:00
|
|
|
#ifdef WITH_DBUS
|
2012-06-06 23:07:07 +02:00
|
|
|
extern const struct luaL_Reg awesome_dbus_lib[];
|
2009-04-18 16:07:31 +02:00
|
|
|
#endif
|
2012-06-06 23:07:07 +02:00
|
|
|
extern const struct luaL_Reg awesome_keygrabber_lib[];
|
|
|
|
extern const struct luaL_Reg awesome_mousegrabber_lib[];
|
|
|
|
extern const struct luaL_Reg awesome_mouse_methods[];
|
|
|
|
extern const struct luaL_Reg awesome_mouse_meta[];
|
2018-12-26 21:50:21 +01:00
|
|
|
extern const struct luaL_Reg awesome_root_methods[];
|
|
|
|
extern const struct luaL_Reg awesome_root_meta[];
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2020-04-17 19:25:40 +02:00
|
|
|
signal_array_t global_signals;
|
|
|
|
|
2017-01-28 15:03:56 +01:00
|
|
|
/** A call into the Lua code aborted with an error.
|
|
|
|
*
|
|
|
|
* This signal is used in the example configuration, @{05-awesomerc.md},
|
|
|
|
* to let a notification box pop up.
|
2021-12-14 01:21:44 +01:00
|
|
|
* @tparam table err Table with the error object, can be converted to a string with
|
2017-01-28 15:03:56 +01:00
|
|
|
* `tostring(err)`.
|
2016-06-04 17:39:14 +02:00
|
|
|
* @signal debug::error
|
|
|
|
*/
|
|
|
|
|
2017-01-28 15:03:56 +01:00
|
|
|
/** A deprecated Lua function was called.
|
|
|
|
*
|
2017-06-21 02:06:32 +02:00
|
|
|
* @tparam string hint String with a hint on what to use instead of the
|
2017-01-28 15:03:56 +01:00
|
|
|
* deprecated functionality.
|
2017-06-21 02:06:32 +02:00
|
|
|
* @tparam[opt=nil] string|nil see The name of the newer API
|
|
|
|
* @tparam[opt=nil] table|nil args The name of the newer API
|
2016-06-04 17:39:14 +02:00
|
|
|
* @signal debug::deprecation
|
|
|
|
*/
|
|
|
|
|
2017-01-28 15:03:56 +01:00
|
|
|
/** An invalid key was read from an object.
|
|
|
|
*
|
|
|
|
* This can happen if `foo` in an `c.foo` access does not exist.
|
|
|
|
* @param unknown1 Class?
|
|
|
|
* @param unknown2 Key?
|
2016-06-04 17:39:14 +02:00
|
|
|
* @signal debug::index::miss
|
|
|
|
*/
|
|
|
|
|
2017-01-28 15:03:56 +01:00
|
|
|
/** An invalid key was written to an object.
|
|
|
|
*
|
|
|
|
* This can happen if `foo` in an `c.foo = "bar"` assignment doesn't exist.
|
|
|
|
* @param unknown1 Class?
|
|
|
|
* @param unknown2 Key?
|
|
|
|
* @param unknown3 Value?
|
2016-06-04 17:39:14 +02:00
|
|
|
* @signal debug::newindex::miss
|
|
|
|
*/
|
|
|
|
|
2017-01-28 15:03:56 +01:00
|
|
|
/** The systray should be updated.
|
|
|
|
*
|
|
|
|
* This signal is used in `wibox.widget.systray`.
|
2016-06-04 17:39:14 +02:00
|
|
|
* @signal systray::update
|
|
|
|
*/
|
|
|
|
|
2017-12-20 01:26:06 +01:00
|
|
|
/** The wallpaper has changed.
|
2017-01-28 15:03:56 +01:00
|
|
|
*
|
2017-12-20 01:26:06 +01:00
|
|
|
* This signal is used for pseudo-transparency in `wibox.drawable` if no
|
|
|
|
* composite manager is running.
|
2016-06-04 17:39:14 +02:00
|
|
|
* @signal wallpaper_changed
|
|
|
|
*/
|
|
|
|
|
2017-01-28 15:03:56 +01:00
|
|
|
/** Keyboard map has changed.
|
|
|
|
*
|
|
|
|
* This signal is sent after the new keymap has been loaded. It is used in
|
|
|
|
* `awful.widget.keyboardlayout` to redraw the layout.
|
2016-06-04 17:39:14 +02:00
|
|
|
* @signal xkb::map_changed
|
|
|
|
*/
|
|
|
|
|
2017-01-28 15:03:56 +01:00
|
|
|
/** Keyboard group has changed.
|
|
|
|
*
|
|
|
|
* It's used in `awful.widget.keyboardlayout` to redraw the layout.
|
2021-12-14 01:21:44 +01:00
|
|
|
* @tparam number group Integer containing the changed group
|
2017-01-28 15:03:56 +01:00
|
|
|
* @signal xkb::group_changed.
|
2016-06-04 17:39:14 +02:00
|
|
|
*/
|
|
|
|
|
2017-01-28 15:03:56 +01:00
|
|
|
/** Refresh.
|
|
|
|
*
|
|
|
|
* This signal is emitted as a kind of idle signal in the event loop.
|
|
|
|
* One example usage is in `gears.timer` to executed delayed calls.
|
2016-06-04 17:39:14 +02:00
|
|
|
* @signal refresh
|
|
|
|
*/
|
|
|
|
|
2018-08-06 22:43:01 +02:00
|
|
|
/** AwesomeWM is about to enter the event loop.
|
2017-01-28 15:03:56 +01:00
|
|
|
*
|
|
|
|
* This means all initialization has been done.
|
2016-06-04 17:39:14 +02:00
|
|
|
* @signal startup
|
|
|
|
*/
|
|
|
|
|
2018-08-06 22:43:01 +02:00
|
|
|
/** AwesomeWM is exiting / about to restart.
|
2017-01-28 15:03:56 +01:00
|
|
|
*
|
|
|
|
* This signal is emitted in the `atexit` handler as well when awesome
|
|
|
|
* restarts.
|
2021-12-14 01:21:44 +01:00
|
|
|
* @tparam boolean reason_restart Boolean value is true if the signal was sent
|
|
|
|
* because of a restart.
|
2016-06-04 17:39:14 +02:00
|
|
|
* @signal exit
|
|
|
|
*/
|
|
|
|
|
2017-01-28 15:03:56 +01:00
|
|
|
/** The output status of a screen has changed.
|
|
|
|
*
|
2018-08-06 22:43:01 +02:00
|
|
|
* @tparam string output String containing which output has changed.
|
|
|
|
* @tparam string connection_state String containing the connection status of
|
2017-01-28 15:03:56 +01:00
|
|
|
* the output: It will be either "Connected", "Disconnected" or
|
|
|
|
* "Unknown".
|
2016-06-04 17:39:14 +02:00
|
|
|
* @signal screen::change
|
|
|
|
*/
|
|
|
|
|
2009-11-10 10:22:04 +01:00
|
|
|
/** Path to config file */
|
|
|
|
static char *conffile;
|
|
|
|
|
2014-02-23 12:14:50 +01:00
|
|
|
/** Check whether a composite manager is running.
|
|
|
|
* \return True if such a manager is running.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
composite_manager_running(void)
|
|
|
|
{
|
|
|
|
xcb_intern_atom_reply_t *atom_r;
|
|
|
|
xcb_get_selection_owner_reply_t *selection_r;
|
|
|
|
char *atom_name;
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
if(!(atom_name = xcb_atom_name_by_screen("_NET_WM_CM", globalconf.default_screen)))
|
|
|
|
{
|
|
|
|
warn("error getting composite manager atom");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
atom_r = xcb_intern_atom_reply(globalconf.connection,
|
|
|
|
xcb_intern_atom_unchecked(globalconf.connection, false,
|
|
|
|
a_strlen(atom_name), atom_name),
|
|
|
|
NULL);
|
|
|
|
p_delete(&atom_name);
|
|
|
|
if(!atom_r)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
selection_r = xcb_get_selection_owner_reply(globalconf.connection,
|
|
|
|
xcb_get_selection_owner_unchecked(globalconf.connection,
|
|
|
|
atom_r->atom),
|
|
|
|
NULL);
|
|
|
|
p_delete(&atom_r);
|
|
|
|
|
|
|
|
result = selection_r != NULL && selection_r->owner != XCB_NONE;
|
|
|
|
p_delete(&selection_r);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Quit awesome.
|
2016-10-27 10:40:53 +02:00
|
|
|
* @tparam[opt=0] integer code The exit code to use when exiting.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct quit
|
2022-07-05 10:37:14 +02:00
|
|
|
* @noreturn
|
2008-05-26 20:39:54 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
2010-08-08 18:19:15 +02:00
|
|
|
luaA_quit(lua_State *L)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2016-10-27 10:40:53 +02:00
|
|
|
if (!lua_isnoneornil(L, 1))
|
|
|
|
globalconf.exit_code = luaL_checkinteger(L, 1);
|
2015-10-10 22:25:56 +02:00
|
|
|
if (globalconf.loop == NULL)
|
|
|
|
globalconf.loop = g_main_loop_new(NULL, FALSE);
|
2012-11-21 21:01:12 +01:00
|
|
|
g_main_loop_quit(globalconf.loop);
|
2008-05-20 15:39:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Execute another application, probably a window manager, to replace
|
|
|
|
* awesome.
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
2021-12-14 01:21:44 +01:00
|
|
|
* @tparam string cmd The command line to execute.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct exec
|
2022-07-05 10:37:14 +02:00
|
|
|
* @noreturn
|
2008-05-26 20:39:54 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_exec(lua_State *L)
|
|
|
|
{
|
|
|
|
const char *cmd = luaL_checkstring(L, 1);
|
|
|
|
|
2011-03-20 23:20:02 +01:00
|
|
|
awesome_atexit(false);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
|
|
|
a_exec(cmd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Restart awesome.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct restart
|
2022-07-05 10:37:14 +02:00
|
|
|
* @noreturn
|
2008-05-26 20:39:54 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
2010-08-08 18:19:15 +02:00
|
|
|
luaA_restart(lua_State *L)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2008-09-02 17:12:10 +02:00
|
|
|
awesome_restart();
|
2008-05-20 15:39:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:25:37 +01:00
|
|
|
/** Send a signal to a process.
|
2018-06-28 15:28:14 +02:00
|
|
|
* @tparam integer pid Process identifier. 0 and negative values have special
|
|
|
|
* meaning. See `man 3 kill`.
|
2019-01-03 13:25:37 +01:00
|
|
|
* @tparam integer sig Signal number.
|
|
|
|
* See `awesome.unix_signal` for a list of signals.
|
2016-05-27 19:08:18 +02:00
|
|
|
* @treturn boolean true if the signal was successfully sent, else false
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct kill
|
2016-05-27 19:08:18 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_kill(lua_State *L)
|
|
|
|
{
|
2019-01-03 13:25:37 +01:00
|
|
|
int pid = luaL_checknumber(L, 1);
|
2016-05-27 19:08:18 +02:00
|
|
|
int sig = luaA_checknumber_range(L, 2, 0, INT_MAX);
|
|
|
|
|
|
|
|
int result = kill(pid, sig);
|
|
|
|
lua_pushboolean(L, result == 0);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-01-01 14:18:59 +01:00
|
|
|
/** Synchronize with the X11 server. This is needed in the test suite to avoid
|
|
|
|
* some race conditions. You should never need to use this function.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct sync
|
2022-07-05 10:37:14 +02:00
|
|
|
* @noreturn
|
2017-01-01 14:18:59 +01:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_sync(lua_State *L)
|
|
|
|
{
|
|
|
|
xcb_aux_sync(globalconf.connection);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-18 18:10:35 +01:00
|
|
|
/** Translate a GdkPixbuf to a cairo image surface..
|
|
|
|
*
|
|
|
|
* @param pixbuf The pixbuf as a light user datum.
|
2018-01-13 04:58:06 +01:00
|
|
|
* @param path The pixbuf origin path
|
2021-12-14 01:21:44 +01:00
|
|
|
* @treturn gears.surface A cairo surface as light user datum.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct pixbuf_to_surface
|
2018-01-18 18:10:35 +01:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_pixbuf_to_surface(lua_State *L)
|
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf = (GdkPixbuf *) lua_touserdata(L, 1);
|
|
|
|
cairo_surface_t *surface = draw_surface_from_pixbuf(pixbuf);
|
|
|
|
|
|
|
|
/* lua has to make sure to free the ref or we have a leak */
|
|
|
|
lua_pushlightuserdata(L, surface);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-01-29 14:08:57 +01:00
|
|
|
/** Load an image from a given path.
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
2021-12-14 01:21:44 +01:00
|
|
|
* @tparam string name The file name.
|
|
|
|
* @treturn gears.surface A cairo surface as light user datum.
|
|
|
|
* @treturn nil|string The error message, if any.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct load_image
|
2024-11-28 00:44:34 +01:00
|
|
|
* @deprecated awesome.pixbuf_to_surface
|
2012-01-29 14:08:57 +01:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_load_image(lua_State *L)
|
|
|
|
{
|
2024-11-28 00:44:34 +01:00
|
|
|
luaA_deprecate(L, "awesome.pixbuf_to_surface");
|
2016-01-15 18:38:23 +01:00
|
|
|
GError *error = NULL;
|
2012-01-29 14:08:57 +01:00
|
|
|
const char *filename = luaL_checkstring(L, 1);
|
2016-01-15 18:38:23 +01:00
|
|
|
cairo_surface_t *surface = draw_load_image(L, filename, &error);
|
|
|
|
if (!surface) {
|
|
|
|
lua_pushnil(L);
|
|
|
|
lua_pushstring(L, error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2012-05-28 09:29:47 +02:00
|
|
|
/* lua has to make sure to free the ref or we have a leak */
|
|
|
|
lua_pushlightuserdata(L, surface);
|
|
|
|
return 1;
|
2012-01-29 14:08:57 +01:00
|
|
|
}
|
|
|
|
|
2015-11-30 20:26:26 +01:00
|
|
|
/** Set the preferred size for client icons.
|
|
|
|
*
|
|
|
|
* The closest equal or bigger size is picked if present, otherwise the closest
|
|
|
|
* smaller size is picked. The default is 0 pixels, ie. the smallest icon.
|
|
|
|
*
|
2021-12-14 01:21:44 +01:00
|
|
|
* @tparam integer size The size of the icons in pixels.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct set_preferred_icon_size
|
2022-07-05 10:37:14 +02:00
|
|
|
* @noreturn
|
2015-11-30 20:26:26 +01:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_set_preferred_icon_size(lua_State *L)
|
|
|
|
{
|
2016-04-17 13:44:05 +02:00
|
|
|
globalconf.preferred_icon_size = luaA_checkinteger_range(L, 1, 0, UINT32_MAX);
|
2015-11-30 20:26:26 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-19 19:14:55 +02:00
|
|
|
/** UTF-8 aware string length computing.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
2008-06-25 11:42:06 +02:00
|
|
|
static int
|
|
|
|
luaA_mbstrlen(lua_State *L)
|
|
|
|
{
|
|
|
|
const char *cmd = luaL_checkstring(L, 1);
|
2016-02-06 13:46:46 +01:00
|
|
|
lua_pushinteger(L, (ssize_t) mbstowcs(NULL, NONULL(cmd), 0));
|
2008-06-25 11:42:06 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-12-03 22:33:11 +01:00
|
|
|
/** Enhanced type() function which recognize awesome objects.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of arguments pushed on the stack.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaAe_type(lua_State *L)
|
|
|
|
{
|
|
|
|
luaL_checkany(L, 1);
|
2009-06-15 17:57:04 +02:00
|
|
|
lua_pushstring(L, luaA_typename(L, 1));
|
2008-12-03 22:33:11 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-10-01 09:55:28 +02:00
|
|
|
/** Replace various standards Lua functions with our own.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
*/
|
2008-06-25 11:42:06 +02:00
|
|
|
static void
|
|
|
|
luaA_fixups(lua_State *L)
|
|
|
|
{
|
2008-12-15 14:06:22 +01:00
|
|
|
/* export string.wlen */
|
2008-06-25 11:42:06 +02:00
|
|
|
lua_getglobal(L, "string");
|
|
|
|
lua_pushcfunction(L, luaA_mbstrlen);
|
2008-12-15 14:06:22 +01:00
|
|
|
lua_setfield(L, -2, "wlen");
|
2008-06-25 11:42:06 +02:00
|
|
|
lua_pop(L, 1);
|
2008-12-03 22:33:11 +01:00
|
|
|
/* replace type */
|
|
|
|
lua_pushcfunction(L, luaAe_type);
|
2012-06-08 01:25:35 +02:00
|
|
|
lua_setglobal(L, "type");
|
2008-06-25 11:42:06 +02:00
|
|
|
}
|
|
|
|
|
2018-12-30 08:11:50 +01:00
|
|
|
static const char *
|
|
|
|
get_modifier_name(int map_index)
|
|
|
|
{
|
|
|
|
switch (map_index) {
|
2019-01-18 17:04:56 +01:00
|
|
|
case XCB_MAP_INDEX_SHIFT: return "Shift";
|
|
|
|
case XCB_MAP_INDEX_LOCK: return "Lock";
|
|
|
|
case XCB_MAP_INDEX_CONTROL: return "Control";
|
|
|
|
case XCB_MAP_INDEX_1: return "Mod1"; /* Alt */
|
|
|
|
case XCB_MAP_INDEX_2: return "Mod2";
|
|
|
|
case XCB_MAP_INDEX_3: return "Mod3";
|
|
|
|
case XCB_MAP_INDEX_4: return "Mod4";
|
|
|
|
case XCB_MAP_INDEX_5: return "Mod5";
|
2018-12-30 08:11:50 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0; /* \0 */
|
|
|
|
}
|
|
|
|
|
2020-03-08 19:03:36 +01:00
|
|
|
/* Helper function for luaA_get_key_name() below.
|
|
|
|
* Will return the UTF-32 codepoint IF AND ONLY IF the input is exactly one
|
|
|
|
* valid UTF-8 character. Otherwise, it will return zero.
|
|
|
|
*/
|
2020-02-26 21:03:37 +01:00
|
|
|
static uint32_t
|
|
|
|
one_utf8_to_utf32(const char* input, const size_t length) {
|
2020-02-29 23:09:07 +01:00
|
|
|
gunichar character = g_utf8_get_char_validated(input, length);
|
|
|
|
// Return 0 if there is more than one UTF-8 character:
|
|
|
|
if (g_unichar_to_utf8(character, NULL) != (gint)length)
|
2020-02-26 21:03:37 +01:00
|
|
|
return 0;
|
2020-02-29 23:09:07 +01:00
|
|
|
// Return 0 if the character is invalid.
|
|
|
|
if (character == (gunichar)-1 || character == (gunichar)-2)
|
2020-02-26 21:03:37 +01:00
|
|
|
return 0;
|
2020-02-29 23:09:07 +01:00
|
|
|
return character;
|
2020-02-26 21:03:37 +01:00
|
|
|
}
|
|
|
|
|
2020-03-08 19:03:36 +01:00
|
|
|
/* Get X11 keysym and a one-character representation from an Awesome keycode.
|
2020-02-26 21:03:37 +01:00
|
|
|
*
|
2020-02-29 23:09:07 +01:00
|
|
|
* A "one-character representation" is a single UTF-8 representing the typical
|
|
|
|
* output from that keysym in a text editor (e.g. " " for space, "ñ" for
|
|
|
|
* n_tilde, "Ā" for A_macron). It usually matches the main engraving of the key
|
|
|
|
* for level-0 symbols (but lowercase).
|
2020-02-26 21:03:37 +01:00
|
|
|
*
|
|
|
|
* Keycodes may be given in a string in any valid format for `awful.key`:
|
|
|
|
* "#" + keycode, the symkey name and the UTF-8 representation will all work.
|
|
|
|
*
|
|
|
|
* If no suitable keysym is found, or a malformed keycode is given as an
|
|
|
|
* argument, this function will return (nil, nil)
|
|
|
|
*
|
|
|
|
* @treturn[1] string keysym The keysym name
|
|
|
|
* @treturn[1] nil keysym If no valid keysym is found
|
|
|
|
* @treturn[2] string printsymbol The xkb_keysym_to_utf8 result
|
|
|
|
* @treturn[2] nil printsymbol If the keysym has no printable representation.
|
2020-03-08 19:03:36 +01:00
|
|
|
* @staticfct awful.keyboard.get_key_name
|
2020-02-26 21:03:37 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
luaA_get_key_name(lua_State *L)
|
|
|
|
{
|
|
|
|
// check if argument is valid
|
|
|
|
if (lua_gettop(L) > 1 || lua_type(L, 1) != LUA_TSTRING)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* input = luaL_checkstring(L, 1);
|
|
|
|
const xkb_keysym_t *keysyms;
|
|
|
|
xkb_keysym_t keysym = XKB_KEY_NoSymbol;
|
|
|
|
const size_t length = strlen(input);
|
|
|
|
uint32_t ucs;
|
|
|
|
|
|
|
|
/* Checking for the three possible syntaxes awful.key uses:
|
|
|
|
* 1: #keycode (#8 to #255, any other is invalid)
|
|
|
|
* 2: the symbol itself (the result of xkb_keysym_to_utf8, e.g. @ for at).
|
|
|
|
* 3: the keysym
|
|
|
|
*/
|
2020-02-29 23:09:07 +01:00
|
|
|
if (input[0] == '#' && input[1] != '\0' && length < 5) // syntax #1
|
2020-02-26 21:03:37 +01:00
|
|
|
{
|
2020-02-29 23:09:07 +01:00
|
|
|
int keycode_from_hash = atoi(input+1);
|
|
|
|
// We discard keycodes with invalid values:
|
|
|
|
const xcb_setup_t *setup = xcb_get_setup(globalconf.connection);
|
|
|
|
if (keycode_from_hash < setup->min_keycode ||
|
|
|
|
keycode_from_hash > setup->max_keycode)
|
2020-02-26 21:03:37 +01:00
|
|
|
return 0;
|
|
|
|
xkb_keycode_t keycode = (xkb_keycode_t) keycode_from_hash;
|
|
|
|
struct xkb_keymap *keymap = xkb_state_get_keymap(globalconf.xkb_state);
|
|
|
|
xkb_keymap_key_get_syms_by_level(keymap, keycode, 0, 0, &keysyms);
|
|
|
|
keysym = keysyms[0];
|
|
|
|
}
|
|
|
|
else if ((ucs = one_utf8_to_utf32(input, length)) > 0) //syntax #2
|
2020-09-14 06:52:59 +02:00
|
|
|
keysym = xkb_utf32_to_keysym_compat(ucs);
|
2020-02-26 21:03:37 +01:00
|
|
|
else //syntax #3
|
|
|
|
keysym = xkb_keysym_from_name(input, XKB_KEYSYM_NO_FLAGS);
|
|
|
|
|
|
|
|
if (keysym == XKB_KEY_NoSymbol)
|
2020-02-29 23:09:07 +01:00
|
|
|
return 0;
|
2020-02-26 21:03:37 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
char *name = key_get_keysym_name(keysym);
|
|
|
|
lua_pushstring(L, name);
|
2020-02-29 23:09:07 +01:00
|
|
|
char utfname[8];
|
2020-02-26 21:03:37 +01:00
|
|
|
if (xkb_keysym_to_utf8(keysym, utfname, 8) > 0)
|
|
|
|
lua_pushstring(L, utfname);
|
|
|
|
else
|
2020-02-29 23:09:07 +01:00
|
|
|
return 1; // this will make the second returned value a nil
|
2020-02-26 21:03:37 +01:00
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2018-12-30 08:11:50 +01:00
|
|
|
/* Undocumented */
|
|
|
|
/*
|
|
|
|
* The table of keybindings modifiers.
|
|
|
|
*
|
|
|
|
* Each modifier has zero to many entries depending on the keyboard layout.
|
|
|
|
* For example, `Shift` usually both has a left and right variant. Each
|
|
|
|
* modifier entry has a `keysym` and `keycode` entry. For the US PC 105
|
|
|
|
* keyboard, it looks like:
|
|
|
|
*
|
|
|
|
* awesome.modifiers = {
|
|
|
|
* Shift = {
|
|
|
|
* {keycode = 50 , keysym = 'Shift_L' },
|
|
|
|
* {keycode = 62 , keysym = 'Shift_R' },
|
|
|
|
* },
|
|
|
|
* Lock = {},
|
|
|
|
* Control = {
|
|
|
|
* {keycode = 37 , keysym = 'Control_L' },
|
|
|
|
* {keycode = 105, keysym = 'Control_R' },
|
|
|
|
* },
|
|
|
|
* Mod1 = {
|
|
|
|
* {keycode = 64 , keysym = 'Alt_L' },
|
|
|
|
* {keycode = 108, keysym = 'Alt_R' },
|
|
|
|
* },
|
|
|
|
* Mod2 = {
|
|
|
|
* {keycode = 77 , keysym = 'Num_Lock' },
|
|
|
|
* },
|
|
|
|
* Mod3 = {},
|
|
|
|
* Mod4 = {
|
|
|
|
* {keycode = 133, keysym = 'Super_L' },
|
|
|
|
* {keycode = 134, keysym = 'Super_R' },
|
|
|
|
* },
|
|
|
|
* Mod5 = {
|
|
|
|
* {keycode = 203, keysym = 'Mode_switch'},
|
|
|
|
* },
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
* @tfield table modifiers
|
|
|
|
* @tparam table modifiers.Shift The Shift modifiers.
|
|
|
|
* @tparam table modifiers.Lock The Lock modifiers.
|
|
|
|
* @tparam table modifiers.Control The Control modifiers.
|
|
|
|
* @tparam table modifiers.Mod1 The Mod1 (Alt) modifiers.
|
|
|
|
* @tparam table modifiers.Mod2 The Mod2 modifiers.
|
|
|
|
* @tparam table modifiers.Mod3 The Mod3 modifiers.
|
|
|
|
* @tparam table modifiers.Mod4 The Mod4 modifiers.
|
|
|
|
* @tparam table modifiers.Mod5 The Mod5 modifiers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modifiers can change over time, given they are currently not tracked, just
|
|
|
|
* query them each time. Use with moderation.
|
|
|
|
*/
|
|
|
|
static int luaA_get_modifiers(lua_State *L)
|
|
|
|
{
|
2019-01-18 17:11:15 +01:00
|
|
|
xcb_get_modifier_mapping_reply_t *mods = xcb_get_modifier_mapping_reply(globalconf.connection,
|
|
|
|
xcb_get_modifier_mapping(globalconf.connection), NULL);
|
|
|
|
if (!mods)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
xcb_keycode_t *mappings = xcb_get_modifier_mapping_keycodes(mods);
|
2019-01-18 17:33:17 +01:00
|
|
|
struct xkb_keymap *keymap = xkb_state_get_keymap(globalconf.xkb_state);
|
2018-12-30 08:11:50 +01:00
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
|
|
|
|
/* This get the MAPPED modifiers, not all of them are */
|
2019-01-18 17:04:56 +01:00
|
|
|
for (int i = XCB_MAP_INDEX_SHIFT; i <= XCB_MAP_INDEX_5; i++) {
|
2018-12-30 08:11:50 +01:00
|
|
|
lua_pushstring(L, get_modifier_name(i));
|
|
|
|
lua_newtable(L);
|
|
|
|
|
2019-01-18 17:11:15 +01:00
|
|
|
for (int j = 0; j < mods->keycodes_per_modifier; j++) {
|
2019-01-18 17:33:17 +01:00
|
|
|
const xkb_keysym_t *keysyms;
|
2019-01-18 17:11:15 +01:00
|
|
|
const xcb_keycode_t key_code = mappings[i * mods->keycodes_per_modifier + j];
|
2019-01-18 17:33:17 +01:00
|
|
|
xkb_keymap_key_get_syms_by_level(keymap, key_code, 0, 0, &keysyms);
|
|
|
|
if (keysyms != NULL) {
|
2018-12-30 08:11:50 +01:00
|
|
|
/* The +1 because j starts at zero and Lua at 1 */
|
|
|
|
lua_pushinteger(L, j+1);
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
|
|
|
|
lua_pushstring(L, "keycode");
|
|
|
|
lua_pushinteger(L, key_code);
|
|
|
|
lua_settable(L, -3);
|
|
|
|
|
2019-01-18 17:33:17 +01:00
|
|
|
/* Technically it is possible to get multiple keysyms here,
|
|
|
|
* but... we just use the first one.
|
|
|
|
*/
|
2018-12-30 08:11:50 +01:00
|
|
|
lua_pushstring(L, "keysym");
|
2019-01-18 17:33:17 +01:00
|
|
|
char *string = key_get_keysym_name(keysyms[0]);
|
2019-01-18 17:24:27 +01:00
|
|
|
lua_pushstring(L, string);
|
|
|
|
p_delete(&string);
|
2018-12-30 08:11:50 +01:00
|
|
|
lua_settable(L, -3);
|
|
|
|
|
|
|
|
lua_settable(L, -3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lua_settable(L, -3);
|
|
|
|
}
|
|
|
|
|
2019-01-18 17:11:15 +01:00
|
|
|
free(mods);
|
2018-12-30 08:11:50 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-21 06:50:35 +01:00
|
|
|
/* Undocumented */
|
|
|
|
/*
|
|
|
|
* A table with the currently active modifier names.
|
|
|
|
*
|
|
|
|
* @tfield table _active_modifiers
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int luaA_get_active_modifiers(lua_State *L)
|
|
|
|
{
|
|
|
|
int count = 1;
|
|
|
|
lua_newtable(L);
|
|
|
|
|
|
|
|
for (int i = XCB_MAP_INDEX_SHIFT; i <= XCB_MAP_INDEX_5; i++) {
|
|
|
|
const int active = xkb_state_mod_index_is_active (globalconf.xkb_state, i,
|
|
|
|
XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_EFFECTIVE
|
|
|
|
);
|
|
|
|
|
|
|
|
if (active) {
|
|
|
|
lua_pushstring(L, get_modifier_name(i));
|
|
|
|
lua_rawseti(L,-2, count++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-08-21 10:18:54 +02:00
|
|
|
|
|
|
|
/**
|
2020-02-03 00:57:26 +01:00
|
|
|
* The AwesomeWM version.
|
2016-08-21 10:18:54 +02:00
|
|
|
* @tfield string version
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2020-02-03 00:57:26 +01:00
|
|
|
* The AwesomeWM release name.
|
2016-08-21 10:18:54 +02:00
|
|
|
* @tfield string release
|
|
|
|
*/
|
|
|
|
|
2020-02-03 00:57:26 +01:00
|
|
|
/**
|
|
|
|
* The AwesomeWM API level.
|
|
|
|
*
|
|
|
|
* By default, this matches the major version (first component of the version).
|
|
|
|
*
|
|
|
|
* API levels are used to allow newer version of AwesomeWM to alter the behavior
|
|
|
|
* and subset deprecated APIs. Using an older API level than the current major
|
2021-10-05 04:20:03 +02:00
|
|
|
* version allows to use legacy `rc.lua` with little porting. However, they won't
|
2020-02-03 00:57:26 +01:00
|
|
|
* be able to use all the new features. Attempting to use a newer feature along
|
|
|
|
* with an older API level is not and will not be supported, even if it almost
|
|
|
|
* works. Keeping up to date with the newer API levels is highly recommended.
|
|
|
|
*
|
|
|
|
* Going the other direction, setting an higher API level allows to take
|
|
|
|
* advantage of experimental feature. It will also be much harsher when it comes
|
|
|
|
* to deprecation. Setting the API level value beyond `current+3` will treat
|
|
|
|
* using APIs currently pending deprecation as fatal errors. All new code
|
|
|
|
* submitted to the upstream AwesomeWM codebase is forbidden to use deprecated
|
|
|
|
* APIs. Testing your patches with mode and the default config is recommended
|
|
|
|
* before submitting a patch.
|
|
|
|
*
|
|
|
|
* You can use the `-l` command line option or `api-level` modeline key to set
|
|
|
|
* the API level for your `rc.lua`. This setting is global and read only,
|
|
|
|
* individual modules cannot set their own API level.
|
|
|
|
*
|
|
|
|
* @tfield string api_level
|
|
|
|
*/
|
|
|
|
|
2016-08-21 10:18:54 +02:00
|
|
|
/**
|
|
|
|
* The configuration file which has been loaded.
|
|
|
|
* @tfield string conffile
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if we are still in startup, false otherwise.
|
|
|
|
* @tfield boolean startup
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-10-05 04:20:03 +02:00
|
|
|
* Error message for errors that occurred during
|
2015-02-27 00:24:23 +01:00
|
|
|
* startup.
|
2016-08-21 10:18:54 +02:00
|
|
|
* @tfield string startup_errors
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if a composite manager is running.
|
|
|
|
* @tfield boolean composite_manager_running
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Table mapping between signal numbers and signal identifiers.
|
|
|
|
* @tfield table unix_signal
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The hostname of the computer on which we are running.
|
|
|
|
* @tfield string hostname
|
2008-11-13 15:06:42 +01:00
|
|
|
*/
|
2016-08-21 10:18:54 +02:00
|
|
|
|
2017-01-25 09:41:11 +01:00
|
|
|
/**
|
|
|
|
* The path where themes were installed to.
|
|
|
|
* @tfield string themes_path
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The path where icons were installed to.
|
|
|
|
* @tfield string icon_path
|
|
|
|
*/
|
|
|
|
|
2008-11-13 15:06:42 +01:00
|
|
|
static int
|
|
|
|
luaA_awesome_index(lua_State *L)
|
|
|
|
{
|
|
|
|
if(luaA_usemetatable(L, 1, 2))
|
|
|
|
return 1;
|
|
|
|
|
2010-09-02 19:08:08 +02:00
|
|
|
const char *buf = luaL_checkstring(L, 2);
|
2008-11-13 15:06:42 +01:00
|
|
|
|
2011-11-17 16:38:39 +01:00
|
|
|
if(A_STREQ(buf, "conffile"))
|
|
|
|
{
|
2009-11-10 10:22:04 +01:00
|
|
|
lua_pushstring(L, conffile);
|
2011-11-17 16:38:39 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(A_STREQ(buf, "version"))
|
|
|
|
{
|
2014-04-13 17:48:03 +02:00
|
|
|
lua_pushstring(L, awesome_version_string());
|
2011-11-17 16:38:39 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(A_STREQ(buf, "release"))
|
|
|
|
{
|
2014-04-13 17:48:03 +02:00
|
|
|
lua_pushstring(L, awesome_release_string());
|
2011-11-17 16:38:39 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-02-03 00:57:26 +01:00
|
|
|
if(A_STREQ(buf, "api_level"))
|
|
|
|
{
|
|
|
|
lua_pushinteger(L, globalconf.api_level);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-03-16 20:09:43 +01:00
|
|
|
if(A_STREQ(buf, "startup"))
|
|
|
|
{
|
|
|
|
lua_pushboolean(L, globalconf.loop == NULL);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-12-30 08:11:50 +01:00
|
|
|
if(A_STREQ(buf, "_modifiers"))
|
|
|
|
{
|
|
|
|
luaA_get_modifiers(L);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-01-21 06:50:35 +01:00
|
|
|
if(A_STREQ(buf, "_active_modifiers"))
|
|
|
|
{
|
|
|
|
luaA_get_active_modifiers(L);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-03-23 19:29:04 +01:00
|
|
|
if(A_STREQ(buf, "startup_errors"))
|
2011-10-23 15:59:15 +02:00
|
|
|
{
|
2014-03-23 19:29:04 +01:00
|
|
|
if (globalconf.startup_errors.len == 0)
|
|
|
|
return 0;
|
2011-10-23 15:59:15 +02:00
|
|
|
lua_pushstring(L, globalconf.startup_errors.s);
|
|
|
|
return 1;
|
|
|
|
}
|
2008-11-13 15:06:42 +01:00
|
|
|
|
2014-02-23 12:14:50 +01:00
|
|
|
if(A_STREQ(buf, "composite_manager_running"))
|
|
|
|
{
|
|
|
|
lua_pushboolean(L, composite_manager_running());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-05-27 19:16:10 +02:00
|
|
|
if(A_STREQ(buf, "hostname"))
|
|
|
|
{
|
|
|
|
/* No good way to handle failures... */
|
|
|
|
char hostname[256] = "";
|
|
|
|
gethostname(&hostname[0], countof(hostname));
|
|
|
|
hostname[countof(hostname) - 1] = '\0';
|
|
|
|
|
|
|
|
lua_pushstring(L, hostname);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-01-25 09:41:11 +01:00
|
|
|
if(A_STREQ(buf, "themes_path"))
|
|
|
|
{
|
|
|
|
lua_pushliteral(L, AWESOME_THEMES_PATH);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(A_STREQ(buf, "icon_path"))
|
|
|
|
{
|
|
|
|
lua_pushliteral(L, AWESOME_ICON_PATH);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-03-23 19:09:11 +01:00
|
|
|
return luaA_default_index(L);
|
2008-11-13 15:06:42 +01:00
|
|
|
}
|
|
|
|
|
2009-07-31 16:28:17 +02:00
|
|
|
/** Add a global signal.
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
2021-12-14 01:21:44 +01:00
|
|
|
* @tparam string name A string with the event name.
|
|
|
|
* @tparam function func The function to call.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct connect_signal
|
2022-07-05 10:37:14 +02:00
|
|
|
* @noreturn
|
2009-07-31 16:28:17 +02:00
|
|
|
*/
|
|
|
|
static int
|
2009-10-09 20:39:55 +02:00
|
|
|
luaA_awesome_connect_signal(lua_State *L)
|
2009-07-31 16:28:17 +02:00
|
|
|
{
|
|
|
|
const char *name = luaL_checkstring(L, 1);
|
|
|
|
luaA_checkfunction(L, 2);
|
2010-08-25 20:48:42 +02:00
|
|
|
signal_connect(&global_signals, name, luaA_object_ref(L, 2));
|
2009-07-31 16:28:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Remove a global signal.
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
2021-12-14 01:21:44 +01:00
|
|
|
* @tparam string name A string with the event name.
|
|
|
|
* @tparam function func The function to call.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct disconnect_signal
|
2022-07-05 10:37:14 +02:00
|
|
|
* @noreturn
|
2009-07-31 16:28:17 +02:00
|
|
|
*/
|
|
|
|
static int
|
2009-10-09 20:39:55 +02:00
|
|
|
luaA_awesome_disconnect_signal(lua_State *L)
|
2009-07-31 16:28:17 +02:00
|
|
|
{
|
|
|
|
const char *name = luaL_checkstring(L, 1);
|
|
|
|
luaA_checkfunction(L, 2);
|
|
|
|
const void *func = lua_topointer(L, 2);
|
2016-06-09 00:03:08 +02:00
|
|
|
if (signal_disconnect(&global_signals, name, func))
|
|
|
|
luaA_object_unref(L, (void *) func);
|
2009-07-31 16:28:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Emit a global signal.
|
2015-02-27 00:24:23 +01:00
|
|
|
*
|
2021-12-14 01:21:44 +01:00
|
|
|
* @tparam function name A string with the event name.
|
2015-02-27 00:24:23 +01:00
|
|
|
* @param ... The signal arguments.
|
2019-06-08 01:08:05 +02:00
|
|
|
* @staticfct emit_signal
|
2022-07-05 10:37:14 +02:00
|
|
|
* @noreturn
|
2009-07-31 16:28:17 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_awesome_emit_signal(lua_State *L)
|
|
|
|
{
|
2009-08-18 18:11:27 +02:00
|
|
|
signal_object_emit(L, &global_signals, luaL_checkstring(L, 1), lua_gettop(L) - 1);
|
2009-07-31 16:28:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-27 16:04:40 +02:00
|
|
|
static int
|
|
|
|
luaA_panic(lua_State *L)
|
|
|
|
{
|
2009-11-09 12:44:19 +01:00
|
|
|
warn("unprotected error in call to Lua API (%s)",
|
2009-08-27 16:04:40 +02:00
|
|
|
lua_tostring(L, -1));
|
2009-11-09 12:44:19 +01:00
|
|
|
buffer_t buf;
|
|
|
|
backtrace_get(&buf);
|
|
|
|
warn("dumping backtrace\n%s", buf.s);
|
|
|
|
warn("restarting awesome");
|
2009-08-27 16:04:40 +02:00
|
|
|
awesome_restart();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-27 16:51:50 +02:00
|
|
|
#if LUA_VERSION_NUM >= 502
|
|
|
|
static const char *
|
|
|
|
luaA_tolstring(lua_State *L, int idx, size_t *len)
|
|
|
|
{
|
|
|
|
return luaL_tolstring(L, idx, len);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static const char *
|
|
|
|
luaA_tolstring(lua_State *L, int idx, size_t *len)
|
|
|
|
{
|
|
|
|
/* Try using the metatable. If that fails, push the value itself onto
|
|
|
|
* the stack.
|
|
|
|
*/
|
|
|
|
if (!luaL_callmeta(L, idx, "__tostring"))
|
|
|
|
lua_pushvalue(L, idx);
|
|
|
|
|
|
|
|
switch (lua_type(L, -1)) {
|
|
|
|
case LUA_TSTRING:
|
|
|
|
lua_pushvalue(L, -1);
|
|
|
|
break;
|
|
|
|
case LUA_TBOOLEAN:
|
|
|
|
if (lua_toboolean(L, -1))
|
|
|
|
lua_pushliteral(L, "true");
|
|
|
|
else
|
|
|
|
lua_pushliteral(L, "false");
|
|
|
|
break;
|
|
|
|
case LUA_TNUMBER:
|
|
|
|
lua_pushfstring(L, "%f", lua_tonumber(L, -1));
|
|
|
|
break;
|
|
|
|
case LUA_TNIL:
|
|
|
|
lua_pushstring(L, "nil");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lua_pushfstring(L, "%s: %p",
|
|
|
|
lua_typename(L, lua_type(L, -1)),
|
|
|
|
lua_topointer(L, -1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lua_remove(L, -2);
|
|
|
|
return lua_tolstring(L, -1, len);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-08-27 17:53:51 +02:00
|
|
|
static int
|
|
|
|
luaA_dofunction_on_error(lua_State *L)
|
|
|
|
{
|
2015-08-01 18:23:52 +02:00
|
|
|
/* Convert error to string, to prevent a follow-up error with lua_concat. */
|
2015-09-27 16:51:50 +02:00
|
|
|
luaA_tolstring(L, -1, NULL);
|
|
|
|
|
2009-08-27 17:55:47 +02:00
|
|
|
/* duplicate string error */
|
|
|
|
lua_pushvalue(L, -1);
|
|
|
|
/* emit error signal */
|
|
|
|
signal_object_emit(L, &global_signals, "debug::error", 1);
|
|
|
|
|
2016-03-06 14:46:39 +01:00
|
|
|
if(!luaL_dostring(L, "return debug.traceback(\"error while running function!\", 3)"))
|
2009-08-27 17:53:51 +02:00
|
|
|
{
|
|
|
|
/* Move traceback before error */
|
|
|
|
lua_insert(L, -2);
|
|
|
|
/* Insert sentence */
|
|
|
|
lua_pushliteral(L, "\nerror: ");
|
|
|
|
/* Move it before error */
|
|
|
|
lua_insert(L, -2);
|
|
|
|
lua_concat(L, 3);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-05-27 19:08:18 +02:00
|
|
|
static void
|
|
|
|
setup_awesome_signals(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_getglobal(L, "awesome");
|
|
|
|
lua_pushstring(L, "unix_signal");
|
|
|
|
lua_newtable(L);
|
|
|
|
|
2017-12-20 01:26:06 +01:00
|
|
|
#define SETUP_SIGNAL(sig) \
|
|
|
|
do { \
|
|
|
|
/* Set awesome.unix_signal["SIGSTOP"] = 42 */ \
|
|
|
|
lua_pushinteger(L, sig); \
|
|
|
|
lua_setfield(L, -2, #sig); \
|
|
|
|
/* Set awesome.unix_signal[42] = "SIGSTOP" */ \
|
|
|
|
lua_pushinteger(L, sig); \
|
|
|
|
lua_pushstring(L, #sig); \
|
|
|
|
lua_settable(L, -3); \
|
2016-05-27 19:08:18 +02:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* Non-standard signals. These are first so that e.g. (on my system)
|
|
|
|
* signals[29] is SIGPOLL and not SIGIO (the value gets overwritten).
|
|
|
|
*/
|
|
|
|
#ifdef SIGIOT
|
|
|
|
SETUP_SIGNAL(SIGIOT);
|
|
|
|
#endif
|
|
|
|
#ifdef SIGEMT
|
|
|
|
SETUP_SIGNAL(SIGEMT);
|
|
|
|
#endif
|
|
|
|
#ifdef SIGSTKFLT
|
|
|
|
SETUP_SIGNAL(SIGSTKFLT);
|
|
|
|
#endif
|
|
|
|
#ifdef SIGIO
|
|
|
|
SETUP_SIGNAL(SIGIO);
|
|
|
|
#endif
|
|
|
|
#ifdef SIGCLD
|
|
|
|
SETUP_SIGNAL(SIGCLD);
|
|
|
|
#endif
|
|
|
|
#ifdef SIGPWR
|
|
|
|
SETUP_SIGNAL(SIGPWR);
|
|
|
|
#endif
|
|
|
|
#ifdef SIGINFO
|
|
|
|
SETUP_SIGNAL(SIGINFO);
|
|
|
|
#endif
|
|
|
|
#ifdef SIGLOST
|
|
|
|
SETUP_SIGNAL(SIGLOST);
|
|
|
|
#endif
|
|
|
|
#ifdef SIGWINCH
|
|
|
|
SETUP_SIGNAL(SIGWINCH);
|
|
|
|
#endif
|
|
|
|
#ifdef SIGUNUSED
|
|
|
|
SETUP_SIGNAL(SIGUNUSED);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* POSIX.1-1990, according to man 7 signal */
|
|
|
|
SETUP_SIGNAL(SIGHUP);
|
|
|
|
SETUP_SIGNAL(SIGINT);
|
|
|
|
SETUP_SIGNAL(SIGQUIT);
|
|
|
|
SETUP_SIGNAL(SIGILL);
|
|
|
|
SETUP_SIGNAL(SIGABRT);
|
|
|
|
SETUP_SIGNAL(SIGFPE);
|
|
|
|
SETUP_SIGNAL(SIGKILL);
|
|
|
|
SETUP_SIGNAL(SIGSEGV);
|
|
|
|
SETUP_SIGNAL(SIGPIPE);
|
|
|
|
SETUP_SIGNAL(SIGALRM);
|
|
|
|
SETUP_SIGNAL(SIGTERM);
|
|
|
|
SETUP_SIGNAL(SIGUSR1);
|
|
|
|
SETUP_SIGNAL(SIGUSR2);
|
|
|
|
SETUP_SIGNAL(SIGCHLD);
|
|
|
|
SETUP_SIGNAL(SIGCONT);
|
|
|
|
SETUP_SIGNAL(SIGSTOP);
|
|
|
|
SETUP_SIGNAL(SIGTSTP);
|
|
|
|
SETUP_SIGNAL(SIGTTIN);
|
|
|
|
SETUP_SIGNAL(SIGTTOU);
|
|
|
|
|
|
|
|
/* POSIX.1-2001, according to man 7 signal */
|
|
|
|
SETUP_SIGNAL(SIGBUS);
|
2017-01-10 15:51:11 +01:00
|
|
|
/* Some Operating Systems doesn't have SIGPOLL (e.g. FreeBSD) */
|
|
|
|
#ifdef SIGPOLL
|
2016-05-27 19:08:18 +02:00
|
|
|
SETUP_SIGNAL(SIGPOLL);
|
2017-01-10 15:51:11 +01:00
|
|
|
#endif
|
2016-05-27 19:08:18 +02:00
|
|
|
SETUP_SIGNAL(SIGPROF);
|
|
|
|
SETUP_SIGNAL(SIGSYS);
|
|
|
|
SETUP_SIGNAL(SIGTRAP);
|
|
|
|
SETUP_SIGNAL(SIGURG);
|
|
|
|
SETUP_SIGNAL(SIGVTALRM);
|
|
|
|
SETUP_SIGNAL(SIGXCPU);
|
|
|
|
SETUP_SIGNAL(SIGXFSZ);
|
|
|
|
|
|
|
|
#undef SETUP_SIGNAL
|
|
|
|
|
|
|
|
/* Set awesome.signal to the table we just created, key was already pushed */
|
|
|
|
lua_rawset(L, -3);
|
|
|
|
|
|
|
|
/* Pop "awesome" */
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
2017-01-09 01:03:16 +01:00
|
|
|
/* Add things to the string on top of the stack */
|
|
|
|
static void
|
|
|
|
add_to_search_path(lua_State *L, string_array_t *searchpath, bool for_lua)
|
|
|
|
{
|
|
|
|
if (LUA_TSTRING != lua_type(L, -1))
|
|
|
|
{
|
|
|
|
warn("package.path is not a string");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach(entry, *searchpath)
|
|
|
|
{
|
|
|
|
int components;
|
|
|
|
size_t len = a_strlen(*entry);
|
|
|
|
lua_pushliteral(L, ";");
|
|
|
|
lua_pushlstring(L, *entry, len);
|
|
|
|
if (for_lua)
|
|
|
|
lua_pushliteral(L, "/?.lua");
|
|
|
|
else
|
|
|
|
lua_pushliteral(L, "/?.so");
|
|
|
|
lua_concat(L, 3);
|
|
|
|
|
|
|
|
if (for_lua)
|
|
|
|
{
|
|
|
|
lua_pushliteral(L, ";");
|
|
|
|
lua_pushlstring(L, *entry, len);
|
|
|
|
lua_pushliteral(L, "/?/init.lua");
|
|
|
|
lua_concat(L, 3);
|
|
|
|
|
|
|
|
components = 2;
|
|
|
|
} else {
|
|
|
|
components = 1;
|
|
|
|
}
|
|
|
|
lua_concat(L, components + 1); /* concatenate with string on top of the stack */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add Lua lib path (/usr/share/awesome/lib by default) */
|
|
|
|
if (for_lua)
|
|
|
|
{
|
|
|
|
lua_pushliteral(L, ";" AWESOME_LUA_LIB_PATH "/?.lua");
|
|
|
|
lua_pushliteral(L, ";" AWESOME_LUA_LIB_PATH "/?/init.lua");
|
|
|
|
lua_concat(L, 3); /* concatenate with thing on top of the stack when we were called */
|
|
|
|
} else {
|
|
|
|
lua_pushliteral(L, ";" AWESOME_LUA_LIB_PATH "/?.so");
|
|
|
|
lua_concat(L, 2); /* concatenate with thing on top of the stack when we were called */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-08 21:49:15 +02:00
|
|
|
/** Initialize the Lua VM
|
2009-04-08 15:47:31 +02:00
|
|
|
* \param xdg An xdg handle to use to get XDG basedir.
|
2008-06-08 21:49:15 +02:00
|
|
|
*/
|
|
|
|
void
|
2016-07-24 14:57:14 +02:00
|
|
|
luaA_init(xdgHandle* xdg, string_array_t *searchpath)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
|
|
|
lua_State *L;
|
2012-06-06 23:07:07 +02:00
|
|
|
static const struct luaL_Reg awesome_lib[] =
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
|
|
|
{ "quit", luaA_quit },
|
|
|
|
{ "exec", luaA_exec },
|
2008-08-14 22:16:13 +02:00
|
|
|
{ "spawn", luaA_spawn },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ "restart", luaA_restart },
|
2009-10-09 20:39:55 +02:00
|
|
|
{ "connect_signal", luaA_awesome_connect_signal },
|
|
|
|
{ "disconnect_signal", luaA_awesome_disconnect_signal },
|
2009-07-31 16:28:17 +02:00
|
|
|
{ "emit_signal", luaA_awesome_emit_signal },
|
2010-10-06 15:38:44 +02:00
|
|
|
{ "systray", luaA_systray },
|
2012-01-29 14:08:57 +01:00
|
|
|
{ "load_image", luaA_load_image },
|
2018-01-18 18:10:35 +01:00
|
|
|
{ "pixbuf_to_surface", luaA_pixbuf_to_surface },
|
2015-11-30 20:26:26 +01:00
|
|
|
{ "set_preferred_icon_size", luaA_set_preferred_icon_size },
|
2014-03-07 13:49:24 +01:00
|
|
|
{ "register_xproperty", luaA_register_xproperty },
|
2014-03-23 18:15:03 +01:00
|
|
|
{ "set_xproperty", luaA_set_xproperty },
|
|
|
|
{ "get_xproperty", luaA_get_xproperty },
|
2008-11-13 15:06:42 +01:00
|
|
|
{ "__index", luaA_awesome_index },
|
2014-03-23 19:09:11 +01:00
|
|
|
{ "__newindex", luaA_default_newindex },
|
2015-02-23 17:08:24 +01:00
|
|
|
{ "xkb_set_layout_group", luaA_xkb_set_layout_group},
|
|
|
|
{ "xkb_get_layout_group", luaA_xkb_get_layout_group},
|
|
|
|
{ "xkb_get_group_names", luaA_xkb_get_group_names},
|
2015-05-14 22:57:22 +02:00
|
|
|
{ "xrdb_get_value", luaA_xrdb_get_value},
|
2016-05-27 19:08:18 +02:00
|
|
|
{ "kill", luaA_kill},
|
2017-01-01 14:18:59 +01:00
|
|
|
{ "sync", luaA_sync},
|
2020-03-08 19:03:36 +01:00
|
|
|
{ "_get_key_name", luaA_get_key_name},
|
2008-05-20 15:39:47 +02:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2014-12-06 11:56:58 +01:00
|
|
|
L = globalconf.L.real_L_dont_use_directly = luaL_newstate();
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2009-08-27 16:04:40 +02:00
|
|
|
/* Set panic function */
|
|
|
|
lua_atpanic(L, luaA_panic);
|
|
|
|
|
2009-08-27 17:53:51 +02:00
|
|
|
/* Set error handling function */
|
|
|
|
lualib_dofunction_on_error = luaA_dofunction_on_error;
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
luaL_openlibs(L);
|
|
|
|
|
2008-06-25 11:42:06 +02:00
|
|
|
luaA_fixups(L);
|
|
|
|
|
2009-07-28 10:40:51 +02:00
|
|
|
luaA_object_setup(L);
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
/* Export awesome lib */
|
2008-11-13 15:06:42 +01:00
|
|
|
luaA_openlib(L, "awesome", awesome_lib, awesome_lib);
|
2016-05-27 19:08:18 +02:00
|
|
|
setup_awesome_signals(L);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2009-08-14 16:46:35 +02:00
|
|
|
/* Export root lib */
|
2018-12-26 21:50:21 +01:00
|
|
|
luaA_openlib(L, "root", awesome_root_methods, awesome_root_meta);
|
2009-01-05 14:31:42 +01:00
|
|
|
|
2009-04-18 16:07:31 +02:00
|
|
|
#ifdef WITH_DBUS
|
2008-11-18 16:31:27 +01:00
|
|
|
/* Export D-Bus lib */
|
2012-06-12 13:32:40 +02:00
|
|
|
luaA_registerlib(L, "dbus", awesome_dbus_lib);
|
|
|
|
lua_pop(L, 1); /* luaA_registerlib() leaves the table on stack */
|
2009-04-18 16:07:31 +02:00
|
|
|
#endif
|
2008-11-18 16:31:27 +01:00
|
|
|
|
2008-06-10 16:50:55 +02:00
|
|
|
/* Export keygrabber lib */
|
2012-06-12 13:32:40 +02:00
|
|
|
luaA_registerlib(L, "keygrabber", awesome_keygrabber_lib);
|
|
|
|
lua_pop(L, 1); /* luaA_registerlib() leaves the table on stack */
|
2008-06-10 16:50:55 +02:00
|
|
|
|
2008-11-13 16:08:34 +01:00
|
|
|
/* Export mousegrabber lib */
|
2012-06-12 13:32:40 +02:00
|
|
|
luaA_registerlib(L, "mousegrabber", awesome_mousegrabber_lib);
|
|
|
|
lua_pop(L, 1); /* luaA_registerlib() leaves the table on stack */
|
2008-11-13 16:08:34 +01:00
|
|
|
|
2008-06-13 15:35:47 +02:00
|
|
|
/* Export mouse */
|
|
|
|
luaA_openlib(L, "mouse", awesome_mouse_methods, awesome_mouse_meta);
|
|
|
|
|
2014-03-30 16:37:19 +02:00
|
|
|
/* Export screen */
|
|
|
|
screen_class_setup(L);
|
|
|
|
|
2008-08-12 13:23:10 +02:00
|
|
|
/* Export button */
|
2009-08-17 14:10:03 +02:00
|
|
|
button_class_setup(L);
|
2008-08-12 13:23:10 +02:00
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
/* Export tag */
|
2009-07-01 16:01:44 +02:00
|
|
|
tag_class_setup(L);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2009-09-30 16:04:42 +02:00
|
|
|
/* Export window */
|
|
|
|
window_class_setup(L);
|
|
|
|
|
2012-10-14 17:14:22 +02:00
|
|
|
/* Export drawable */
|
|
|
|
drawable_class_setup(L);
|
|
|
|
|
2010-10-06 13:35:14 +02:00
|
|
|
/* Export drawin */
|
|
|
|
drawin_class_setup(L);
|
2008-09-21 20:39:23 +02:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
/* Export client */
|
2009-08-17 17:02:45 +02:00
|
|
|
client_class_setup(L);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2019-02-07 15:16:48 +01:00
|
|
|
/* Export selection getter */
|
|
|
|
selection_getter_class_setup(L);
|
|
|
|
|
2008-05-28 12:15:00 +02:00
|
|
|
/* Export keys */
|
2009-06-24 17:44:06 +02:00
|
|
|
key_class_setup(L);
|
2008-05-28 12:15:00 +02:00
|
|
|
|
2019-02-10 15:49:42 +01:00
|
|
|
/* Export selection acquire */
|
|
|
|
selection_acquire_class_setup(L);
|
|
|
|
|
2019-02-10 17:51:53 +01:00
|
|
|
/* Export selection transfer */
|
|
|
|
selection_transfer_class_setup(L);
|
|
|
|
|
2019-02-06 09:30:16 +01:00
|
|
|
/* Export selection watcher */
|
|
|
|
selection_watcher_class_setup(L);
|
|
|
|
|
2019-02-16 15:44:42 +01:00
|
|
|
/* Setup the selection interface */
|
|
|
|
selection_setup(L);
|
|
|
|
|
2009-09-04 21:53:38 +02:00
|
|
|
/* add Lua search paths */
|
2009-05-09 10:09:21 +02:00
|
|
|
lua_getglobal(L, "package");
|
|
|
|
if (LUA_TTABLE != lua_type(L, 1))
|
|
|
|
{
|
|
|
|
warn("package is not a table");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lua_getfield(L, 1, "path");
|
2017-01-09 01:03:16 +01:00
|
|
|
add_to_search_path(L, searchpath, true);
|
2009-05-09 10:09:21 +02:00
|
|
|
lua_setfield(L, 1, "path"); /* package.path = "concatenated string" */
|
2010-08-22 17:01:28 +02:00
|
|
|
|
2017-01-09 01:03:16 +01:00
|
|
|
lua_getfield(L, 1, "cpath");
|
|
|
|
add_to_search_path(L, searchpath, false);
|
|
|
|
lua_setfield(L, 1, "cpath"); /* package.cpath = "concatenated string" */
|
2010-08-22 17:01:28 +02:00
|
|
|
|
2017-01-09 01:03:16 +01:00
|
|
|
lua_pop(L, 1); /* pop "package" */
|
2008-11-08 14:22:20 +01:00
|
|
|
}
|
2008-07-08 14:07:56 +02:00
|
|
|
|
2011-10-23 15:59:15 +02:00
|
|
|
static void
|
|
|
|
luaA_startup_error(const char *err)
|
|
|
|
{
|
|
|
|
if (globalconf.startup_errors.len > 0)
|
|
|
|
buffer_addsl(&globalconf.startup_errors, "\n\n");
|
|
|
|
buffer_adds(&globalconf.startup_errors, err);
|
|
|
|
}
|
|
|
|
|
2008-09-30 16:59:08 +02:00
|
|
|
static bool
|
2017-01-25 14:06:41 +01:00
|
|
|
luaA_loadrc(const char *confpath)
|
2008-09-30 16:59:08 +02:00
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
2016-02-17 19:03:48 +01:00
|
|
|
if(luaL_loadfile(L, confpath))
|
2011-10-23 15:59:15 +02:00
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
const char *err = lua_tostring(L, -1);
|
2011-10-23 15:59:15 +02:00
|
|
|
luaA_startup_error(err);
|
|
|
|
fprintf(stderr, "%s\n", err);
|
2016-10-22 10:44:54 +02:00
|
|
|
lua_pop(L, 1);
|
2016-02-17 19:03:48 +01:00
|
|
|
return false;
|
2011-10-23 15:59:15 +02:00
|
|
|
}
|
2009-03-02 14:16:08 +01:00
|
|
|
|
2016-02-17 19:03:48 +01:00
|
|
|
/* Set the conffile right now so it can be used inside the
|
|
|
|
* configuration file. */
|
|
|
|
conffile = a_strdup(confpath);
|
|
|
|
/* Move error handling function before function */
|
|
|
|
lua_pushcfunction(L, luaA_dofunction_on_error);
|
|
|
|
lua_insert(L, -2);
|
|
|
|
if(!lua_pcall(L, 0, 0, -2))
|
|
|
|
{
|
|
|
|
/* Pop luaA_dofunction_on_error */
|
|
|
|
lua_pop(L, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *err = lua_tostring(L, -1);
|
|
|
|
luaA_startup_error(err);
|
|
|
|
fprintf(stderr, "%s\n", err);
|
|
|
|
/* An error happened, so reset this. */
|
|
|
|
conffile = NULL;
|
|
|
|
/* Pop luaA_dofunction_on_error() and the error message */
|
|
|
|
lua_pop(L, 2);
|
|
|
|
|
2008-09-30 16:59:08 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-07-08 14:07:56 +02:00
|
|
|
/** Load a configuration file.
|
2009-04-08 15:47:31 +02:00
|
|
|
* \param xdg An xdg handle to use to get XDG basedir.
|
2008-09-30 16:59:08 +02:00
|
|
|
* \param confpatharg The configuration file to load.
|
|
|
|
* \param run Run the configuration file.
|
2008-06-08 21:49:15 +02:00
|
|
|
*/
|
2008-09-30 16:59:08 +02:00
|
|
|
bool
|
2017-01-25 14:06:41 +01:00
|
|
|
luaA_parserc(xdgHandle* xdg, const char *confpatharg)
|
|
|
|
{
|
|
|
|
const char *confpath = luaA_find_config(xdg, confpatharg, luaA_loadrc);
|
|
|
|
bool ret = confpath != NULL;
|
|
|
|
p_delete(&confpath);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Find a config file for which the given callback returns true.
|
|
|
|
* \param xdg An xdg handle to use to get XDG basedir.
|
|
|
|
* \param confpatharg The configuration file to load.
|
|
|
|
* \param callback The callback to call.
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
luaA_find_config(xdgHandle* xdg, const char *confpatharg, luaA_config_callback *callback)
|
2008-06-08 21:49:15 +02:00
|
|
|
{
|
2009-04-07 17:57:01 +02:00
|
|
|
char *confpath = NULL;
|
2008-07-08 14:07:56 +02:00
|
|
|
|
2017-01-25 14:06:41 +01:00
|
|
|
if(confpatharg && callback(confpatharg))
|
2008-07-08 14:07:56 +02:00
|
|
|
{
|
2017-01-25 14:06:41 +01:00
|
|
|
return a_strdup(confpatharg);
|
2008-07-08 14:07:56 +02:00
|
|
|
}
|
2008-11-08 14:22:20 +01:00
|
|
|
|
2009-04-07 17:57:01 +02:00
|
|
|
confpath = xdgConfigFind("awesome/rc.lua", xdg);
|
2008-07-08 14:07:56 +02:00
|
|
|
|
2009-04-07 17:57:01 +02:00
|
|
|
char *tmp = confpath;
|
2008-07-08 14:07:56 +02:00
|
|
|
|
2009-04-07 17:57:01 +02:00
|
|
|
/* confpath is "string1\0string2\0string3\0\0" */
|
2009-06-01 13:01:31 +02:00
|
|
|
while(*tmp)
|
2008-07-08 14:07:56 +02:00
|
|
|
{
|
2017-01-25 14:06:41 +01:00
|
|
|
if(callback(tmp))
|
2008-11-08 14:22:20 +01:00
|
|
|
{
|
2017-01-25 14:06:41 +01:00
|
|
|
const char *ret = a_strdup(tmp);
|
|
|
|
p_delete(&confpath);
|
|
|
|
return ret;
|
2008-11-08 14:22:20 +01:00
|
|
|
}
|
2009-04-07 17:57:01 +02:00
|
|
|
tmp += a_strlen(tmp) + 1;
|
2009-06-01 13:01:31 +02:00
|
|
|
}
|
2008-11-08 14:22:20 +01:00
|
|
|
p_delete(&confpath);
|
2017-01-25 09:21:38 +01:00
|
|
|
|
|
|
|
if(callback(AWESOME_DEFAULT_CONF))
|
|
|
|
{
|
|
|
|
return a_strdup(AWESOME_DEFAULT_CONF);
|
|
|
|
}
|
|
|
|
|
2017-01-25 14:06:41 +01:00
|
|
|
return NULL;
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
|
|
|
|
2009-08-20 17:37:46 +02:00
|
|
|
int
|
|
|
|
luaA_class_index_miss_property(lua_State *L, lua_object_t *obj)
|
|
|
|
{
|
|
|
|
signal_object_emit(L, &global_signals, "debug::index::miss", 2);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
luaA_class_newindex_miss_property(lua_State *L, lua_object_t *obj)
|
|
|
|
{
|
|
|
|
signal_object_emit(L, &global_signals, "debug::newindex::miss", 3);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-14 15:41:11 +01:00
|
|
|
void
|
|
|
|
luaA_emit_startup()
|
|
|
|
{
|
|
|
|
lua_State *L = globalconf_get_lua_State();
|
|
|
|
signal_object_emit(L, &global_signals, "startup", 0);
|
|
|
|
}
|
|
|
|
|
2010-10-15 18:48:07 +02:00
|
|
|
void
|
|
|
|
luaA_emit_refresh()
|
|
|
|
{
|
2014-12-06 11:56:58 +01:00
|
|
|
lua_State *L = globalconf_get_lua_State();
|
|
|
|
signal_object_emit(L, &global_signals, "refresh", 0);
|
2010-10-15 18:48:07 +02:00
|
|
|
}
|
|
|
|
|
2014-03-23 19:09:11 +01:00
|
|
|
int
|
|
|
|
luaA_default_index(lua_State *L)
|
|
|
|
{
|
|
|
|
return luaA_class_index_miss_property(L, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
luaA_default_newindex(lua_State *L)
|
|
|
|
{
|
|
|
|
return luaA_class_newindex_miss_property(L, NULL);
|
|
|
|
}
|
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|