2008-05-26 20:39:54 +02:00
|
|
|
/*
|
|
|
|
* lua.c - Lua configuration management
|
|
|
|
*
|
|
|
|
* Copyright © 2008 Julien Danjou <julien@danjou.info>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <lua.h>
|
|
|
|
#include <lauxlib.h>
|
|
|
|
#include <lualib.h>
|
|
|
|
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xcb_aux.h>
|
|
|
|
|
2008-05-20 19:55:14 +02:00
|
|
|
#include "config.h"
|
2008-05-20 15:39:47 +02:00
|
|
|
#include "structs.h"
|
|
|
|
#include "lua.h"
|
|
|
|
#include "tag.h"
|
|
|
|
#include "client.h"
|
2008-05-28 12:15:00 +02:00
|
|
|
#include "window.h"
|
2008-06-04 19:21:21 +02:00
|
|
|
#include "statusbar.h"
|
|
|
|
#include "titlebar.h"
|
2008-05-20 15:39:47 +02:00
|
|
|
#include "layouts/tile.h"
|
|
|
|
|
2008-05-24 08:59:27 +02:00
|
|
|
extern awesome_t globalconf;
|
2008-05-26 20:39:54 +02:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
extern bool running;
|
|
|
|
extern const name_func_link_t FloatingPlacementList[];
|
|
|
|
|
|
|
|
extern const struct luaL_reg awesome_mouse_lib[];
|
|
|
|
extern const struct luaL_reg awesome_client_methods[];
|
|
|
|
extern const struct luaL_reg awesome_client_meta[];
|
|
|
|
extern const struct luaL_reg awesome_titlebar_methods[];
|
|
|
|
extern const struct luaL_reg awesome_titlebar_meta[];
|
|
|
|
extern const struct luaL_reg awesome_tag_methods[];
|
|
|
|
extern const struct luaL_reg awesome_tag_meta[];
|
|
|
|
extern const struct luaL_reg awesome_widget_methods[];
|
|
|
|
extern const struct luaL_reg awesome_widget_meta[];
|
|
|
|
extern const struct luaL_reg awesome_statusbar_methods[];
|
|
|
|
extern const struct luaL_reg awesome_statusbar_meta[];
|
2008-05-28 12:15:00 +02:00
|
|
|
extern const struct luaL_reg awesome_keybinding_methods[];
|
|
|
|
extern const struct luaL_reg awesome_keybinding_meta[];
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Define a global mouse binding. This binding will be available wehn you
|
|
|
|
* click on root window.
|
|
|
|
* \param A table with modifiers keys.
|
|
|
|
* \param A mouse button number.
|
|
|
|
* \param A function to execute.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_mouse(lua_State *L)
|
|
|
|
{
|
|
|
|
size_t i, len;
|
|
|
|
int b;
|
2008-05-23 13:35:46 +02:00
|
|
|
button_t *button;
|
2008-05-20 15:39:47 +02:00
|
|
|
|
|
|
|
/* arg 1 is modkey table */
|
|
|
|
luaA_checktable(L, 1);
|
|
|
|
/* arg 2 is mouse button */
|
|
|
|
b = luaL_checknumber(L, 2);
|
|
|
|
/* arg 3 is cmd to run */
|
|
|
|
luaA_checkfunction(L, 3);
|
|
|
|
|
2008-05-23 13:35:46 +02:00
|
|
|
button = p_new(button_t, 1);
|
2008-05-20 15:39:47 +02:00
|
|
|
button->button = xutil_button_fromint(b);
|
|
|
|
button->fct = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
|
|
|
|
len = lua_objlen(L, 1);
|
|
|
|
for(i = 1; i <= len; i++)
|
|
|
|
{
|
|
|
|
lua_rawgeti(L, 1, i);
|
|
|
|
button->mod |= xutil_keymask_fromstr(luaL_checkstring(L, -1));
|
|
|
|
}
|
|
|
|
|
|
|
|
button_list_push(&globalconf.buttons.root, button);
|
|
|
|
|
|
|
|
window_root_grabbutton(button);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Set the floating placement algorithm. This will be used to compute the
|
|
|
|
* initial floating position of floating windows.
|
|
|
|
* \param An algorith name, either `none', `smart' or `mouse'.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_floating_placement_set(lua_State *L)
|
|
|
|
{
|
|
|
|
const char *pl = luaL_checkstring(L, 1);
|
|
|
|
globalconf.floating_placement = name_func_lookup(pl, FloatingPlacementList);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Quit awesome.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_quit(lua_State *L __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
running = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Execute another application, probably a window manager, to replace
|
|
|
|
* awesome.
|
|
|
|
* \param The command line to execute.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_exec(lua_State *L)
|
|
|
|
{
|
|
|
|
client_t *c;
|
|
|
|
const char *cmd = luaL_checkstring(L, 1);
|
|
|
|
|
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
|
|
|
client_unban(c);
|
|
|
|
|
|
|
|
xcb_aux_sync(globalconf.connection);
|
|
|
|
xcb_disconnect(globalconf.connection);
|
|
|
|
|
|
|
|
a_exec(cmd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Restart awesome.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_restart(lua_State *L __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
a_exec(globalconf.argv);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Set the screen padding. This can be used to define margin around the
|
|
|
|
* screen. awesome will not use this area.
|
|
|
|
* \param A table with a list of margin for `right', `left', `top' and
|
|
|
|
* `bottom'.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_padding_set(lua_State *L)
|
|
|
|
{
|
|
|
|
int screen = luaL_checknumber(L, 1) - 1;
|
|
|
|
|
|
|
|
if(screen >= 0 && screen < globalconf.screens_info->nscreen)
|
|
|
|
{
|
|
|
|
luaA_checktable(L, 2);
|
|
|
|
|
|
|
|
globalconf.screens[screen].padding.right = luaA_getopt_number(L, 2, "right", 0);
|
|
|
|
globalconf.screens[screen].padding.left = luaA_getopt_number(L, 2, "left", 0);
|
|
|
|
globalconf.screens[screen].padding.top = luaA_getopt_number(L, 2, "top", 0);
|
|
|
|
globalconf.screens[screen].padding.bottom = luaA_getopt_number(L, 2, "bottom", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Define if awesome should respect applications size hints when resizing
|
|
|
|
* windows in tiled mode. If you set this to true, you will experience gaps
|
|
|
|
* between windows, but they will have the best size they can have.
|
|
|
|
* \param A boolean value, true to enable, false to disable.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_resizehints_set(lua_State *L)
|
|
|
|
{
|
|
|
|
globalconf.resize_hints = luaA_checkboolean(L, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Get the screen count.
|
|
|
|
* \return The screen count, at least 1.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_screen_count(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_pushnumber(L, globalconf.screens_info->nscreen);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Give the focus to a screen.
|
|
|
|
* \param A screen number
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_screen_focus(lua_State *L)
|
|
|
|
{
|
|
|
|
/* Our table begin at 0, Lua begins at 1 */
|
|
|
|
int screen = luaL_checknumber(L, 1) - 1;
|
|
|
|
luaA_checkscreen(screen);
|
2008-05-26 16:17:57 +02:00
|
|
|
client_focus(NULL, screen);
|
2008-05-20 15:39:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
luaA_screen_coords_get(lua_State *L)
|
|
|
|
{
|
|
|
|
int screen = luaL_checknumber(L, 1) - 1;
|
|
|
|
luaA_checkscreen(screen);
|
|
|
|
lua_newtable(L);
|
|
|
|
lua_pushnumber(L, globalconf.screens_info->geometry[screen].x);
|
|
|
|
lua_setfield(L, -2, "x");
|
|
|
|
lua_pushnumber(L, globalconf.screens_info->geometry[screen].y);
|
|
|
|
lua_setfield(L, -2, "y");
|
|
|
|
lua_pushnumber(L, globalconf.screens_info->geometry[screen].width);
|
|
|
|
lua_setfield(L, -2, "width");
|
|
|
|
lua_pushnumber(L, globalconf.screens_info->geometry[screen].height);
|
|
|
|
lua_setfield(L, -2, "height");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Set the function called each time a client gets focus. This function is
|
|
|
|
* called with the client object as argument.
|
|
|
|
* \param A function to call each time a client gets focus.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_hooks_focus(lua_State *L)
|
|
|
|
{
|
|
|
|
luaA_checkfunction(L, 1);
|
|
|
|
if(globalconf.hooks.focus)
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, globalconf.hooks.focus);
|
|
|
|
globalconf.hooks.focus = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Set the function called each time a client loses focus. This function is
|
|
|
|
* called with the client object as argument.
|
|
|
|
* \param A function to call each time a client loses focus.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_hooks_unfocus(lua_State *L)
|
|
|
|
{
|
|
|
|
luaA_checkfunction(L, 1);
|
|
|
|
if(globalconf.hooks.unfocus)
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, globalconf.hooks.unfocus);
|
|
|
|
globalconf.hooks.unfocus = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Set the function called each time a new client appears. This function is
|
|
|
|
* called with the client object as argument
|
|
|
|
* \param A function to call on each new client.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_hooks_newclient(lua_State *L)
|
|
|
|
{
|
|
|
|
luaA_checkfunction(L, 1);
|
|
|
|
if(globalconf.hooks.newclient)
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, globalconf.hooks.newclient);
|
|
|
|
globalconf.hooks.newclient = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Set the function called each time the mouse enter a new window. This
|
|
|
|
* function is called with the client object as argument.
|
2008-05-28 08:59:35 +02:00
|
|
|
* \param A function to call each time a client gets mouse over it.
|
2008-05-26 20:39:54 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_hooks_mouseover(lua_State *L)
|
|
|
|
{
|
|
|
|
luaA_checkfunction(L, 1);
|
|
|
|
if(globalconf.hooks.mouseover)
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, globalconf.hooks.mouseover);
|
|
|
|
globalconf.hooks.mouseover = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Set the function called on each screen arrange. This function is called
|
|
|
|
* with the screen number as argument.
|
|
|
|
* \param A function to call on each screen arrange.
|
|
|
|
*/
|
2008-05-23 17:09:34 +02:00
|
|
|
static int
|
|
|
|
luaA_hooks_arrange(lua_State *L)
|
|
|
|
{
|
|
|
|
luaA_checkfunction(L, 1);
|
|
|
|
if(globalconf.hooks.arrange)
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, globalconf.hooks.arrange);
|
|
|
|
globalconf.hooks.arrange = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Set the function called on each title update. This function is called with
|
|
|
|
* the client object as argument.
|
|
|
|
* \param A function to call on each title update of each client.
|
|
|
|
*/
|
2008-05-25 17:51:45 +02:00
|
|
|
static int
|
|
|
|
luaA_hooks_titleupdate(lua_State *L)
|
|
|
|
{
|
|
|
|
luaA_checkfunction(L, 1);
|
|
|
|
if(globalconf.hooks.titleupdate)
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, globalconf.hooks.titleupdate);
|
|
|
|
globalconf.hooks.titleupdate = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-28 11:08:48 +02:00
|
|
|
/** Set the function called when a client get urgency flag. This function is called with
|
|
|
|
* the client object as argument.
|
|
|
|
* \param A function to call when a client get the urgent flag.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_hooks_urgent(lua_State *L)
|
|
|
|
{
|
|
|
|
luaA_checkfunction(L, 1);
|
|
|
|
if(globalconf.hooks.urgent)
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, globalconf.hooks.urgent);
|
|
|
|
globalconf.hooks.urgent = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-29 13:47:11 +02:00
|
|
|
/** Set the function to be called every N seconds.
|
|
|
|
* \param The number of seconds to run function every. Set 0 to disable.
|
|
|
|
* \param A function to call every N seconds (optionnal).
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_hooks_timer(lua_State *L)
|
|
|
|
{
|
2008-05-31 23:43:28 +02:00
|
|
|
globalconf.timer.tv_usec = 0;
|
|
|
|
globalconf.timer.tv_sec = luaL_checknumber(L, 1);
|
2008-05-29 13:47:11 +02:00
|
|
|
|
|
|
|
if(lua_gettop(L) == 2 && lua_isfunction(L, 2))
|
|
|
|
{
|
|
|
|
if(globalconf.hooks.timer)
|
|
|
|
luaL_unref(L, LUA_REGISTRYINDEX, globalconf.hooks.timer);
|
|
|
|
globalconf.hooks.timer = luaL_ref(L, LUA_REGISTRYINDEX);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Set default font.
|
|
|
|
* \param A string with a font name in Pango format.
|
|
|
|
*/
|
2008-05-21 17:28:54 +02:00
|
|
|
static int
|
2008-05-21 17:03:10 +02:00
|
|
|
luaA_font_set(lua_State *L)
|
|
|
|
{
|
|
|
|
const char *font = luaL_checkstring(L, 1);
|
|
|
|
draw_font_delete(&globalconf.font);
|
|
|
|
globalconf.font = draw_font_new(globalconf.connection,
|
|
|
|
globalconf.default_screen, font);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Set default colors.
|
|
|
|
* \param A table with `fg' and `bg' elements, containing colors.
|
|
|
|
*/
|
2008-05-23 18:15:41 +02:00
|
|
|
static int
|
|
|
|
luaA_colors_set(lua_State *L)
|
|
|
|
{
|
|
|
|
const char *fg, *bg;
|
|
|
|
luaA_checktable(L, 1);
|
|
|
|
if((fg = luaA_getopt_string(L, 1, "fg", NULL)))
|
2008-05-30 12:34:38 +02:00
|
|
|
xcolor_new(globalconf.connection, globalconf.default_screen,
|
2008-05-23 18:15:41 +02:00
|
|
|
fg, &globalconf.colors.fg);
|
|
|
|
if((bg = luaA_getopt_string(L, 1, "bg",NULL)))
|
2008-05-30 12:34:38 +02:00
|
|
|
xcolor_new(globalconf.connection, globalconf.default_screen,
|
2008-05-23 18:15:41 +02:00
|
|
|
bg, &globalconf.colors.bg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-04 19:21:21 +02:00
|
|
|
/** Push a pointer onto the stack according to its type.
|
|
|
|
* \param L The Lua state.
|
|
|
|
* \param p The pointer.
|
|
|
|
* \param type Its type.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
luaA_pushpointer(void *p, awesome_type_t type)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case AWESOME_TYPE_STATUSBAR:
|
|
|
|
luaA_statusbar_userdata_new(p);
|
|
|
|
break;
|
|
|
|
case AWESOME_TYPE_TITLEBAR:
|
|
|
|
luaA_titlebar_userdata_new(p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
static void
|
|
|
|
luaA_openlib(lua_State *L, const char *name,
|
|
|
|
const struct luaL_reg methods[],
|
|
|
|
const struct luaL_reg meta[])
|
|
|
|
{
|
|
|
|
luaL_newmetatable(L, name);
|
|
|
|
lua_pushliteral(L, "__index");
|
|
|
|
lua_pushvalue(L, -2); /* dup metatable*/
|
|
|
|
lua_settable(L, -3); /* metatable.__index = metatable */
|
|
|
|
|
|
|
|
luaL_register(L, NULL, meta);
|
|
|
|
luaL_register(L, name, methods);
|
|
|
|
}
|
|
|
|
|
2008-06-08 21:49:15 +02:00
|
|
|
/** Initialize the Lua VM
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
luaA_init(void)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
|
|
|
lua_State *L;
|
|
|
|
|
|
|
|
static const struct luaL_reg awesome_lib[] =
|
|
|
|
{
|
|
|
|
{ "quit", luaA_quit },
|
|
|
|
{ "exec", luaA_exec },
|
|
|
|
{ "restart", luaA_restart },
|
|
|
|
{ "floating_placement_set", luaA_floating_placement_set },
|
|
|
|
{ "padding_set", luaA_padding_set },
|
|
|
|
{ "mouse", luaA_mouse },
|
|
|
|
{ "resizehints_set", luaA_resizehints_set },
|
2008-05-21 17:03:10 +02:00
|
|
|
{ "font_set", luaA_font_set },
|
2008-05-23 18:15:41 +02:00
|
|
|
{ "colors_set", luaA_colors_set },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
2008-05-27 16:07:17 +02:00
|
|
|
static const struct luaL_reg awesome_screen_lib[] =
|
|
|
|
{
|
|
|
|
{ "coords_get", luaA_screen_coords_get },
|
|
|
|
{ "count", luaA_screen_count },
|
|
|
|
{ "focus", luaA_screen_focus },
|
2008-05-28 06:49:32 +02:00
|
|
|
{ NULL, NULL }
|
2008-05-27 16:07:17 +02:00
|
|
|
};
|
2008-05-20 15:39:47 +02:00
|
|
|
static const struct luaL_reg awesome_hooks_lib[] =
|
|
|
|
{
|
|
|
|
{ "focus", luaA_hooks_focus },
|
|
|
|
{ "unfocus", luaA_hooks_unfocus },
|
|
|
|
{ "newclient", luaA_hooks_newclient },
|
|
|
|
{ "mouseover", luaA_hooks_mouseover },
|
2008-05-23 17:09:34 +02:00
|
|
|
{ "arrange", luaA_hooks_arrange },
|
2008-05-25 17:51:45 +02:00
|
|
|
{ "titleupdate", luaA_hooks_titleupdate },
|
2008-05-28 11:08:48 +02:00
|
|
|
{ "urgent", luaA_hooks_urgent },
|
2008-05-29 13:47:11 +02:00
|
|
|
{ "timer", luaA_hooks_timer },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
L = globalconf.L = lua_open();
|
|
|
|
|
|
|
|
luaL_openlibs(L);
|
|
|
|
|
|
|
|
/* Export awesome lib */
|
2008-05-20 20:26:58 +02:00
|
|
|
luaL_register(L, "awesome", awesome_lib);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-05-27 16:07:17 +02:00
|
|
|
/* Export screen lib */
|
|
|
|
luaL_register(L, "screen", awesome_screen_lib);
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
/* Export hooks lib */
|
2008-05-20 20:26:58 +02:00
|
|
|
luaL_register(L, "hooks", awesome_hooks_lib);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
|
|
|
/* Export hooks lib */
|
2008-05-20 20:26:58 +02:00
|
|
|
luaL_register(L, "mouse", awesome_mouse_lib);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
|
|
|
/* Export tag */
|
|
|
|
luaA_openlib(L, "tag", awesome_tag_methods, awesome_tag_meta);
|
|
|
|
|
|
|
|
/* Export statusbar */
|
|
|
|
luaA_openlib(L, "statusbar", awesome_statusbar_methods, awesome_statusbar_meta);
|
|
|
|
|
|
|
|
/* Export widget */
|
|
|
|
luaA_openlib(L, "widget", awesome_widget_methods, awesome_widget_meta);
|
|
|
|
|
|
|
|
/* Export client */
|
|
|
|
luaA_openlib(L, "client", awesome_client_methods, awesome_client_meta);
|
|
|
|
|
|
|
|
/* Export titlebar */
|
|
|
|
luaA_openlib(L, "titlebar", awesome_titlebar_methods, awesome_titlebar_meta);
|
|
|
|
|
2008-05-28 12:15:00 +02:00
|
|
|
/* Export keys */
|
|
|
|
luaA_openlib(L, "keybinding", awesome_keybinding_methods, awesome_keybinding_meta);
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
lua_pushliteral(L, "AWESOME_VERSION");
|
|
|
|
lua_pushliteral(L, VERSION);
|
|
|
|
lua_settable(L, LUA_GLOBALSINDEX);
|
|
|
|
|
2008-05-20 18:10:02 +02:00
|
|
|
luaA_dostring(L, "package.path = package.path .. \";" AWESOME_LUA_LIB_PATH "/?.lua\"");
|
2008-06-08 21:49:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Load a configuration file
|
|
|
|
*
|
|
|
|
* \param rcfile The configuration file to load.
|
|
|
|
* \return True on succes, false on failure.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
luaA_parserc(const char* rcfile)
|
|
|
|
{
|
|
|
|
int screen;
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-08 21:49:15 +02:00
|
|
|
if(luaL_dofile(globalconf.L, rcfile))
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2008-06-08 21:49:15 +02:00
|
|
|
fprintf(stderr, "%s\n", lua_tostring(globalconf.L, -1));
|
2008-05-20 15:39:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Assure there's at least one tag */
|
|
|
|
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
|
|
|
if(!globalconf.screens[screen].tags)
|
|
|
|
tag_append_to_screen(tag_new("default", layout_tile, 0.5, 1, 0), screen);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Parse a command.
|
|
|
|
* \param cmd The buffer to parse.
|
|
|
|
* \return true on succes, false on failure.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
luaA_docmd(char *cmd)
|
|
|
|
{
|
|
|
|
char *p, *curcmd = cmd;
|
|
|
|
|
|
|
|
if(a_strlen(cmd))
|
|
|
|
while((p = strchr(curcmd, '\n')))
|
|
|
|
{
|
|
|
|
*p = '\0';
|
|
|
|
luaA_dostring(globalconf.L, curcmd);
|
|
|
|
curcmd = p + 1;
|
|
|
|
}
|
|
|
|
}
|