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-06-16 23:47:14 +02:00
|
|
|
#include <errno.h>
|
2008-05-20 15:39:47 +02:00
|
|
|
#include <stdio.h>
|
2008-06-16 23:47:14 +02:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
2008-05-20 15:39:47 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2008-06-16 23:47:14 +02:00
|
|
|
#include <ev.h>
|
2008-06-26 18:10:45 +02:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
#include <lua.h>
|
|
|
|
#include <lauxlib.h>
|
|
|
|
#include <lualib.h>
|
|
|
|
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xcb_aux.h>
|
|
|
|
|
2008-07-31 17:48:27 +02:00
|
|
|
#include "awesome-version-internal.h"
|
2008-06-17 22:12:30 +02:00
|
|
|
#include "ewmh.h"
|
2008-05-20 19:55:14 +02:00
|
|
|
#include "config.h"
|
2008-05-20 15:39:47 +02:00
|
|
|
#include "lua.h"
|
2008-06-09 21:43:09 +02:00
|
|
|
#include "tag.h"
|
2008-05-20 15:39:47 +02:00
|
|
|
#include "client.h"
|
2008-06-04 19:21:21 +02:00
|
|
|
#include "statusbar.h"
|
|
|
|
#include "titlebar.h"
|
2008-06-17 22:12:30 +02:00
|
|
|
#include "screen.h"
|
2008-05-20 15:39:47 +02:00
|
|
|
#include "layouts/tile.h"
|
2008-06-17 22:12:30 +02:00
|
|
|
#include "common/socket.h"
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-05-24 08:59:27 +02:00
|
|
|
extern awesome_t globalconf;
|
2008-05-26 20:39:54 +02:00
|
|
|
|
2008-06-10 16:50:55 +02:00
|
|
|
extern const struct luaL_reg awesome_keygrabber_lib[];
|
2008-06-13 15:35:47 +02:00
|
|
|
extern const struct luaL_reg awesome_mouse_methods[];
|
|
|
|
extern const struct luaL_reg awesome_mouse_meta[];
|
2008-05-20 15:39:47 +02:00
|
|
|
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[];
|
2008-06-09 21:43:09 +02:00
|
|
|
extern const struct luaL_reg awesome_tag_methods[];
|
|
|
|
extern const struct luaL_reg awesome_tag_meta[];
|
2008-05-20 15:39:47 +02:00
|
|
|
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-06-16 23:47:14 +02:00
|
|
|
static struct sockaddr_un *addr;
|
|
|
|
static ev_io csio = { .fd = -1 };
|
|
|
|
|
2008-06-13 15:35:47 +02:00
|
|
|
/** Add a global mouse binding. This binding will be available when you'll
|
2008-05-26 20:39:54 +02:00
|
|
|
* click on root window.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
2008-06-13 15:35:47 +02:00
|
|
|
* \lparam A mouse button binding.
|
2008-05-26 20:39:54 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
2008-06-13 15:35:47 +02:00
|
|
|
luaA_mouse_add(lua_State *L)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2008-06-13 15:35:47 +02:00
|
|
|
button_t **button = luaA_checkudata(L, 1, "mouse");
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-13 15:35:47 +02:00
|
|
|
button_list_push(&globalconf.buttons.root, *button);
|
|
|
|
button_ref(button);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
|
|
|
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)))
|
|
|
|
{
|
2008-06-17 00:30:53 +02:00
|
|
|
ev_unloop(globalconf.loop, 1);
|
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.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lparam The command line to execute.
|
2008-05-26 20:39:54 +02:00
|
|
|
*/
|
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)))
|
|
|
|
{
|
2008-07-22 10:23:07 +02:00
|
|
|
ewmh_restart();
|
2008-05-20 15:39:47 +02:00
|
|
|
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.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
2008-07-29 18:24:35 +02:00
|
|
|
* \return The number of elements pushed on stack.
|
2008-06-10 20:12:51 +02:00
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lparam A screen number.
|
|
|
|
* \lparam A table with a list of margin for `right', `left', `top' and
|
2008-05-26 20:39:54 +02:00
|
|
|
* `bottom'.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
2008-07-01 22:37:35 +02:00
|
|
|
luaA_screen_padding_set(lua_State *L)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
|
|
|
int screen = luaL_checknumber(L, 1) - 1;
|
|
|
|
|
2008-07-01 22:37:35 +02:00
|
|
|
luaA_checkscreen(screen);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-07-01 22:37:35 +02:00
|
|
|
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);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-17 22:12:30 +02:00
|
|
|
ewmh_update_workarea(screen_virttophys(screen));
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Get the screen count.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
2008-07-29 18:24:35 +02:00
|
|
|
* \return The number of elements pushed on stack.
|
2008-06-10 20:12:51 +02:00
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lreturn The screen count, at least 1.
|
2008-05-26 20:39:54 +02:00
|
|
|
*/
|
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-07-29 18:24:35 +02:00
|
|
|
/** Return screen coordinates.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
|
|
|
* \lparam A screen number.
|
|
|
|
* \lreturn A table with the screen geometry: x, y, width and height.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
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-07-29 18:24:35 +02:00
|
|
|
/** Return the geometry of the workspace, i.e. where applications live.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
|
|
|
* \lparam A screen number.
|
|
|
|
* \lreturn A table with the workspace geometry.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_screen_workspace_get(lua_State *L)
|
|
|
|
{
|
|
|
|
area_t g;
|
|
|
|
int screen = luaL_checknumber(L, 1) - 1;
|
|
|
|
luaA_checkscreen(screen);
|
|
|
|
g = screen_area_get(screen,
|
|
|
|
globalconf.screens[screen].statusbar,
|
|
|
|
&globalconf.screens[screen].padding);
|
|
|
|
lua_newtable(L);
|
|
|
|
lua_pushnumber(L, g.x);
|
|
|
|
lua_setfield(L, -2, "x");
|
|
|
|
lua_pushnumber(L, g.y);
|
|
|
|
lua_setfield(L, -2, "y");
|
|
|
|
lua_pushnumber(L, g.width);
|
|
|
|
lua_setfield(L, -2, "width");
|
|
|
|
lua_pushnumber(L, g.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.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
2008-07-29 18:24:35 +02:00
|
|
|
* \return The number of elements pushed on stack.
|
2008-06-10 20:12:51 +02:00
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lparam A function to call each time a client gets focus.
|
2008-05-26 20:39:54 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_hooks_focus(lua_State *L)
|
|
|
|
{
|
2008-07-09 11:51:08 +02:00
|
|
|
return luaA_registerfct(L, &globalconf.hooks.focus);
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
|
|
|
|
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.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lparam A function to call each time a client loses focus.
|
2008-05-26 20:39:54 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_hooks_unfocus(lua_State *L)
|
|
|
|
{
|
2008-07-09 11:51:08 +02:00
|
|
|
return luaA_registerfct(L, &globalconf.hooks.unfocus);
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Set the function called each time a new client appears. This function is
|
2008-06-10 19:03:10 +02:00
|
|
|
* called with the client object as argument.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lparam A function to call on each new client.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_hooks_manage(lua_State *L)
|
|
|
|
{
|
2008-07-09 11:51:08 +02:00
|
|
|
return luaA_registerfct(L, &globalconf.hooks.manage);
|
2008-06-10 19:03:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Set the function called each time a client goes away. This function is
|
|
|
|
* called with the client object as argument.
|
|
|
|
* \param L The Lua VM state.
|
2008-06-12 13:42:39 +02:00
|
|
|
*
|
2008-06-10 19:03:10 +02:00
|
|
|
* \luastack
|
2008-06-10 20:12:51 +02:00
|
|
|
* \lparam A function to call when a client goes away.
|
2008-05-26 20:39:54 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
2008-06-10 19:03:10 +02:00
|
|
|
luaA_hooks_unmanage(lua_State *L)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2008-07-09 11:51:08 +02:00
|
|
|
return luaA_registerfct(L, &globalconf.hooks.unmanage);
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
|
|
|
|
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-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lparam 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)
|
|
|
|
{
|
2008-07-09 11:51:08 +02:00
|
|
|
return luaA_registerfct(L, &globalconf.hooks.mouseover);
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
|
|
|
|
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.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lparam A function to call on each screen arrange.
|
2008-05-26 20:39:54 +02:00
|
|
|
*/
|
2008-05-23 17:09:34 +02:00
|
|
|
static int
|
|
|
|
luaA_hooks_arrange(lua_State *L)
|
|
|
|
{
|
2008-07-09 11:51:08 +02:00
|
|
|
return luaA_registerfct(L, &globalconf.hooks.arrange);
|
2008-05-23 17:09:34 +02:00
|
|
|
}
|
|
|
|
|
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.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lparam A function to call on each title update of each client.
|
2008-05-26 20:39:54 +02:00
|
|
|
*/
|
2008-05-25 17:51:45 +02:00
|
|
|
static int
|
|
|
|
luaA_hooks_titleupdate(lua_State *L)
|
|
|
|
{
|
2008-07-09 11:51:08 +02:00
|
|
|
return luaA_registerfct(L, &globalconf.hooks.titleupdate);
|
2008-05-25 17:51:45 +02:00
|
|
|
}
|
|
|
|
|
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.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lparam A function to call when a client get the urgent flag.
|
2008-05-28 11:08:48 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_hooks_urgent(lua_State *L)
|
|
|
|
{
|
2008-07-09 11:51:08 +02:00
|
|
|
return luaA_registerfct(L, &globalconf.hooks.urgent);
|
2008-05-28 11:08:48 +02:00
|
|
|
}
|
|
|
|
|
2008-05-29 13:47:11 +02:00
|
|
|
/** Set the function to be called every N seconds.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lparam The number of seconds to run function every. Set 0 to disable.
|
2008-06-12 13:42:39 +02:00
|
|
|
* \lparam A function to call every N seconds (optional).
|
2008-05-29 13:47:11 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_hooks_timer(lua_State *L)
|
|
|
|
{
|
2008-06-17 00:30:53 +02:00
|
|
|
globalconf.timer.repeat = luaL_checknumber(L, 1);
|
2008-05-29 13:47:11 +02:00
|
|
|
|
2008-06-10 20:32:26 +02:00
|
|
|
if(lua_gettop(L) == 2 && !lua_isnil(L, 2))
|
2008-07-09 11:51:08 +02:00
|
|
|
luaA_registerfct(L, &globalconf.hooks.timer);
|
2008-05-29 13:47:11 +02:00
|
|
|
|
2008-06-17 00:30:53 +02:00
|
|
|
ev_timer_again(globalconf.loop, &globalconf.timer);
|
2008-05-29 13:47:11 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-26 20:39:54 +02:00
|
|
|
/** Set default font.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lparam A string with a font name in Pango format.
|
2008-05-26 20:39:54 +02:00
|
|
|
*/
|
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.
|
2008-06-10 20:12:51 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lparam A table with `fg' and `bg' elements, containing colors.
|
2008-05-26 20:39:54 +02:00
|
|
|
*/
|
2008-05-23 18:15:41 +02:00
|
|
|
static int
|
|
|
|
luaA_colors_set(lua_State *L)
|
|
|
|
{
|
2008-06-28 13:30:17 +02:00
|
|
|
const char *buf;
|
2008-07-10 15:30:16 +02:00
|
|
|
size_t len;
|
2008-06-28 13:30:17 +02:00
|
|
|
|
2008-05-23 18:15:41 +02:00
|
|
|
luaA_checktable(L, 1);
|
2008-06-28 13:30:17 +02:00
|
|
|
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaA_getopt_lstring(L, 1, "fg", NULL, &len)))
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
xcolor_init(&globalconf.colors.fg, globalconf.connection,
|
2008-07-10 15:30:16 +02:00
|
|
|
globalconf.default_screen, buf, len);
|
2008-06-28 13:30:17 +02:00
|
|
|
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaA_getopt_lstring(L, 1, "bg", NULL, &len)))
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
xcolor_init(&globalconf.colors.bg, globalconf.connection,
|
2008-07-10 15:30:16 +02:00
|
|
|
globalconf.default_screen, buf, len);
|
2008-05-23 18:15:41 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-04 19:21:21 +02:00
|
|
|
/** Push a pointer onto the stack according to its type.
|
|
|
|
* \param p The pointer.
|
|
|
|
* \param type Its type.
|
|
|
|
*/
|
|
|
|
void
|
2008-06-18 18:31:35 +02:00
|
|
|
luaA_pushpointer(lua_State *L, void *p, awesome_type_t type)
|
2008-06-04 19:21:21 +02:00
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case AWESOME_TYPE_STATUSBAR:
|
2008-06-18 18:31:35 +02:00
|
|
|
luaA_statusbar_userdata_new(L, p);
|
2008-06-04 19:21:21 +02:00
|
|
|
break;
|
|
|
|
case AWESOME_TYPE_TITLEBAR:
|
2008-06-18 18:31:35 +02:00
|
|
|
luaA_titlebar_userdata_new(L, p);
|
2008-06-04 19:21:21 +02:00
|
|
|
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[])
|
|
|
|
{
|
2008-06-28 00:52:12 +02:00
|
|
|
luaL_newmetatable(L, name); /* 1 */
|
|
|
|
lua_pushvalue(L, -1); /* dup metatable 2 */
|
|
|
|
lua_setfield(L, -2, "__index"); /* metatable.__index = metatable 1 */
|
|
|
|
|
|
|
|
luaL_register(L, NULL, meta); /* 1 */
|
|
|
|
luaL_register(L, name, methods); /* 2 */
|
|
|
|
lua_pushvalue(L, -1); /* dup self as metatable 3 */
|
|
|
|
lua_setmetatable(L, -2); /* set self as metatable 2 */
|
|
|
|
lua_pop(L, 2);
|
2008-05-26 20:39:54 +02:00
|
|
|
}
|
|
|
|
|
2008-06-25 11:42:06 +02:00
|
|
|
static int
|
|
|
|
luaA_mbstrlen(lua_State *L)
|
|
|
|
{
|
|
|
|
const char *cmd = luaL_checkstring(L, 1);
|
|
|
|
lua_pushnumber(L, mbstowcs(NULL, NONULL(cmd), 0));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
luaA_fixups(lua_State *L)
|
|
|
|
{
|
|
|
|
lua_getglobal(L, "string");
|
|
|
|
lua_pushcfunction(L, luaA_mbstrlen);
|
|
|
|
lua_setfield(L, -2, "len");
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
|
|
|
|
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 },
|
2008-06-13 15:35:47 +02:00
|
|
|
{ "mouse_add", luaA_mouse_add },
|
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[] =
|
|
|
|
{
|
2008-07-01 22:37:35 +02:00
|
|
|
{ "padding_set", luaA_screen_padding_set },
|
2008-05-27 16:07:17 +02:00
|
|
|
{ "coords_get", luaA_screen_coords_get },
|
2008-07-29 18:24:35 +02:00
|
|
|
{ "workspace_get", luaA_screen_workspace_get },
|
2008-05-27 16:07:17 +02:00
|
|
|
{ "count", luaA_screen_count },
|
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 },
|
2008-06-10 19:03:10 +02:00
|
|
|
{ "manage", luaA_hooks_manage },
|
|
|
|
{ "unmanage", luaA_hooks_unmanage },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ "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 }
|
|
|
|
};
|
|
|
|
|
2008-06-28 13:57:11 +02:00
|
|
|
L = globalconf.L = luaL_newstate();
|
2008-05-20 15:39:47 +02:00
|
|
|
|
|
|
|
luaL_openlibs(L);
|
|
|
|
|
2008-06-25 11:42:06 +02:00
|
|
|
luaA_fixups(L);
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
/* 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
|
|
|
|
2008-06-10 16:50:55 +02:00
|
|
|
/* Export keygrabber lib */
|
|
|
|
luaL_register(L, "keygrabber", awesome_keygrabber_lib);
|
|
|
|
|
2008-06-13 15:35:47 +02:00
|
|
|
/* Export mouse */
|
|
|
|
luaA_openlib(L, "mouse", awesome_mouse_methods, awesome_mouse_meta);
|
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
/* Export tag */
|
|
|
|
luaA_openlib(L, "tag", awesome_tag_methods, awesome_tag_meta);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
|
|
|
/* 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");
|
2008-07-31 17:48:27 +02:00
|
|
|
lua_pushstring(L, AWESOME_VERSION);
|
2008-05-20 15:39:47 +02:00
|
|
|
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-08-01 19:10:25 +02:00
|
|
|
luaA_dostring(L, "package.path = package.path .. \";" AWESOME_LUA_LIB_PATH "/?/init.lua\"");
|
2008-07-09 11:51:08 +02:00
|
|
|
|
|
|
|
/* init hooks */
|
|
|
|
globalconf.hooks.manage = LUA_REFNIL;
|
|
|
|
globalconf.hooks.unmanage = LUA_REFNIL;
|
|
|
|
globalconf.hooks.focus = LUA_REFNIL;
|
|
|
|
globalconf.hooks.unfocus = LUA_REFNIL;
|
|
|
|
globalconf.hooks.mouseover = LUA_REFNIL;
|
|
|
|
globalconf.hooks.arrange = LUA_REFNIL;
|
|
|
|
globalconf.hooks.titleupdate = LUA_REFNIL;
|
|
|
|
globalconf.hooks.urgent = LUA_REFNIL;
|
|
|
|
globalconf.hooks.timer = LUA_REFNIL;
|
2008-06-08 21:49:15 +02:00
|
|
|
}
|
|
|
|
|
2008-07-09 08:15:17 +02:00
|
|
|
#define XDG_CONFIG_HOME_DEFAULT "/.config"
|
2008-07-08 14:07:56 +02:00
|
|
|
|
2008-07-09 08:15:17 +02:00
|
|
|
#define AWESOME_CONFIG_FILE "/awesome/rc.lua"
|
2008-07-08 14:07:56 +02:00
|
|
|
|
|
|
|
/** Load a configuration file.
|
2008-06-08 21:49:15 +02:00
|
|
|
* \param rcfile The configuration file to load.
|
|
|
|
*/
|
2008-07-08 14:07:56 +02:00
|
|
|
void
|
|
|
|
luaA_parserc(const char *confpatharg)
|
2008-06-08 21:49:15 +02:00
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
int screen;
|
2008-07-08 14:07:56 +02:00
|
|
|
const char *confdir, *xdg_config_dirs;
|
2008-07-30 18:20:19 +02:00
|
|
|
char *confpath = NULL, **xdg_files, **buf, path[1024];
|
2008-07-08 14:07:56 +02:00
|
|
|
ssize_t len;
|
2008-07-30 17:53:43 +02:00
|
|
|
|
2008-07-08 14:07:56 +02:00
|
|
|
if(confpatharg)
|
|
|
|
{
|
|
|
|
if(luaL_dofile(globalconf.L, confpatharg))
|
|
|
|
fprintf(stderr, "%s\n", lua_tostring(globalconf.L, -1));
|
|
|
|
else
|
|
|
|
goto bailout;
|
|
|
|
}
|
|
|
|
|
|
|
|
confdir = getenv("XDG_CONFIG_HOME");
|
2008-06-09 21:43:09 +02:00
|
|
|
|
2008-07-30 17:53:43 +02:00
|
|
|
if((len = a_strlen(confdir)))
|
2008-07-08 14:07:56 +02:00
|
|
|
{
|
2008-07-30 17:53:43 +02:00
|
|
|
len += sizeof(AWESOME_CONFIG_FILE);
|
2008-07-08 14:07:56 +02:00
|
|
|
confpath = p_new(char, len);
|
|
|
|
a_strcpy(confpath, len, confdir);
|
2008-07-30 18:20:19 +02:00
|
|
|
/* update package.path */
|
|
|
|
snprintf(path, sizeof(path) - 1, "package.path = package.path .. \";%s/awesome/?.lua\"", confdir);
|
|
|
|
luaA_dostring(globalconf.L, path);
|
2008-07-08 14:07:56 +02:00
|
|
|
}
|
|
|
|
else
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2008-07-08 14:07:56 +02:00
|
|
|
confdir = getenv("HOME");
|
2008-07-20 05:45:15 +02:00
|
|
|
len = a_strlen(confdir) + sizeof(AWESOME_CONFIG_FILE)-1 + sizeof(XDG_CONFIG_HOME_DEFAULT);
|
2008-07-08 14:07:56 +02:00
|
|
|
confpath = p_new(char, len);
|
|
|
|
a_strcpy(confpath, len, confdir);
|
|
|
|
a_strcat(confpath, len, XDG_CONFIG_HOME_DEFAULT);
|
2008-07-30 18:20:19 +02:00
|
|
|
/* update package.path */
|
|
|
|
snprintf(path, sizeof(path) - 1, "package.path = package.path .. \";%s" XDG_CONFIG_HOME_DEFAULT "/awesome/?.lua\"", confdir);
|
|
|
|
luaA_dostring(globalconf.L, path);
|
2008-07-08 14:07:56 +02:00
|
|
|
}
|
|
|
|
a_strcat(confpath, len, AWESOME_CONFIG_FILE);
|
|
|
|
|
|
|
|
if(luaL_dofile(globalconf.L, confpath))
|
2008-06-08 21:49:15 +02:00
|
|
|
fprintf(stderr, "%s\n", lua_tostring(globalconf.L, -1));
|
2008-07-08 14:07:56 +02:00
|
|
|
else
|
|
|
|
goto bailout;
|
|
|
|
|
|
|
|
xdg_config_dirs = getenv("XDG_CONFIG_DIRS");
|
|
|
|
|
|
|
|
if(!(len = a_strlen(xdg_config_dirs)))
|
|
|
|
{
|
2008-07-18 07:51:47 +02:00
|
|
|
xdg_config_dirs = XDG_CONFIG_DIR;
|
|
|
|
len = sizeof(XDG_CONFIG_DIR) - 1;
|
2008-07-08 14:07:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
xdg_files = a_strsplit(xdg_config_dirs, len, ':');
|
|
|
|
|
|
|
|
for(buf = xdg_files; *buf; buf++)
|
|
|
|
{
|
|
|
|
p_delete(&confpath);
|
2008-07-20 05:45:15 +02:00
|
|
|
len = a_strlen(*buf) + sizeof("AWESOME_CONFIG_FILE");
|
2008-07-08 14:07:56 +02:00
|
|
|
confpath = p_new(char, len);
|
|
|
|
a_strcpy(confpath, len, *buf);
|
|
|
|
a_strcat(confpath, len, AWESOME_CONFIG_FILE);
|
2008-07-30 18:20:19 +02:00
|
|
|
snprintf(path, sizeof(path) - 1, "package.path = package.path .. \";%s/awesome/?.lua\"", *buf);
|
|
|
|
luaA_dostring(globalconf.L, path);
|
2008-07-08 14:07:56 +02:00
|
|
|
if(luaL_dofile(globalconf.L, confpath))
|
|
|
|
fprintf(stderr, "%s\n", lua_tostring(globalconf.L, -1));
|
|
|
|
else
|
|
|
|
break;
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
|
|
|
|
2008-07-08 14:07:56 +02:00
|
|
|
for(buf = xdg_files; *buf; buf++)
|
|
|
|
p_delete(buf);
|
|
|
|
p_delete(&xdg_files);
|
2008-07-30 17:53:43 +02:00
|
|
|
|
2008-07-08 14:07:56 +02:00
|
|
|
bailout:
|
2008-06-09 21:43:09 +02:00
|
|
|
/* Assure there's at least one tag */
|
|
|
|
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
2008-06-23 17:37:19 +02:00
|
|
|
if(!globalconf.screens[screen].tags.len)
|
2008-07-20 05:45:15 +02:00
|
|
|
tag_append_to_screen(tag_new("default", sizeof("default")-1, layout_tile, 0.5, 1, 0), screen);
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-07-08 14:07:56 +02:00
|
|
|
p_delete(&confpath);
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Parse a command.
|
|
|
|
* \param cmd The buffer to parse.
|
|
|
|
* \return true on succes, false on failure.
|
|
|
|
*/
|
2008-06-16 23:47:14 +02:00
|
|
|
static void
|
2008-07-10 15:11:23 +02:00
|
|
|
luaA_docmd(const char *cmd)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2008-07-10 15:11:23 +02:00
|
|
|
char *p;
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-07-10 15:11:23 +02:00
|
|
|
while((p = strchr(cmd, '\n')))
|
|
|
|
{
|
|
|
|
*p = '\0';
|
|
|
|
luaA_dostring(globalconf.L, cmd);
|
|
|
|
cmd = p + 1;
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
2008-06-16 23:47:14 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
luaA_cb(EV_P_ ev_io *w, int revents)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
int r;
|
|
|
|
|
|
|
|
switch(r = recv(w->fd, buf, sizeof(buf)-1, MSG_TRUNC))
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
warn("error reading UNIX domain socket: %s", strerror(errno));
|
|
|
|
luaA_cs_cleanup();
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if(r >= ssizeof(buf))
|
|
|
|
break;
|
|
|
|
buf[r] = '\0';
|
|
|
|
luaA_docmd(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
luaA_cs_init(void)
|
|
|
|
{
|
|
|
|
int csfd = socket_getclient();
|
|
|
|
|
|
|
|
if (csfd < 0)
|
|
|
|
return;
|
|
|
|
addr = socket_getaddr(getenv("DISPLAY"));
|
|
|
|
|
|
|
|
if(bind(csfd, (const struct sockaddr *) addr, SUN_LEN(addr)))
|
|
|
|
{
|
|
|
|
if(errno == EADDRINUSE)
|
|
|
|
{
|
|
|
|
if(unlink(addr->sun_path))
|
|
|
|
warn("error unlinking existing file: %s", strerror(errno));
|
|
|
|
if(bind(csfd, (const struct sockaddr *) addr, SUN_LEN(addr)))
|
|
|
|
warn("error binding UNIX domain socket: %s", strerror(errno));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
warn("error binding UNIX domain socket: %s", strerror(errno));
|
|
|
|
}
|
|
|
|
ev_io_init(&csio, &luaA_cb, csfd, EV_READ);
|
|
|
|
ev_io_start(EV_DEFAULT_UC_ &csio);
|
|
|
|
ev_unref(EV_DEFAULT_UC);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
luaA_cs_cleanup(void)
|
|
|
|
{
|
|
|
|
if(csio.fd < 0)
|
|
|
|
return;
|
|
|
|
ev_ref(EV_DEFAULT_UC);
|
|
|
|
ev_io_stop(EV_DEFAULT_UC_ &csio);
|
|
|
|
if (close(csio.fd))
|
|
|
|
warn("error closing UNIX domain socket: %s", strerror(errno));
|
|
|
|
if(unlink(addr->sun_path))
|
|
|
|
warn("error unlinking UNIX domain socket: %s", strerror(errno));
|
|
|
|
p_delete(&addr);
|
|
|
|
csio.fd = -1;
|
|
|
|
}
|
2008-06-17 00:30:53 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
luaA_on_timer(EV_P_ ev_timer *w, int revents)
|
|
|
|
{
|
2008-07-09 12:12:52 +02:00
|
|
|
luaA_dofunction(globalconf.L, globalconf.hooks.timer, 0, 0);
|
2008-08-06 20:34:28 +02:00
|
|
|
layout_refresh();
|
|
|
|
statusbar_refresh();
|
|
|
|
titlebar_refresh();
|
2008-06-17 00:30:53 +02:00
|
|
|
}
|
2008-07-02 11:04:17 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
luaA_pushcolor(lua_State *L, const xcolor_t *c)
|
|
|
|
{
|
|
|
|
uint8_t r = (unsigned)c->red * 0xff / 0xffff;
|
|
|
|
uint8_t g = (unsigned)c->green * 0xff / 0xffff;
|
|
|
|
uint8_t b = (unsigned)c->blue * 0xff / 0xffff;
|
|
|
|
uint8_t a = (unsigned)c->alpha * 0xff / 0xffff;
|
2008-07-24 17:56:42 +02:00
|
|
|
char s[10];
|
|
|
|
snprintf(s, sizeof(s), "#%02x%02x%02x%02x", r, g, b, a);
|
|
|
|
lua_pushlstring(L, s, sizeof(s));
|
2008-07-02 11:04:17 +02:00
|
|
|
}
|