Hide globalconf.L

Everything that needs the lua_State should create a local variable like this:

  lua_State *L = globalconf_get_lua_State();

This ensures that the compiler warns if there are two variables with name "L" in
scope. The idea here is that it should become harder to accidentally use the
global lua state instead of the state of the current state.

While writing this commit, I found another place that gets its wrong: Reading
client.focus from a coroutine was broken, since it was returning the result on
the main thread instead of the current one.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2014-12-06 11:56:58 +01:00
parent da15317ac2
commit e5120e1bec
13 changed files with 417 additions and 354 deletions

View File

@ -70,15 +70,16 @@ static float main_loop_iteration_limit = 0.1;
void void
awesome_atexit(bool restart) awesome_atexit(bool restart)
{ {
lua_pushboolean(globalconf.L, restart); lua_State *L = globalconf_get_lua_State();
signal_object_emit(globalconf.L, &global_signals, "exit", 1); lua_pushboolean(L, restart);
signal_object_emit(L, &global_signals, "exit", 1);
a_dbus_cleanup(); a_dbus_cleanup();
systray_cleanup(); systray_cleanup();
/* Close Lua */ /* Close Lua */
lua_close(globalconf.L); lua_close(L);
/* X11 is a great protocol. There is a save-set so that reparenting WMs /* X11 is a great protocol. There is a save-set so that reparenting WMs
* don't kill clients when they shut down. However, when a focused windows * don't kill clients when they shut down. However, when a focused windows

118
dbus.c
View File

@ -61,11 +61,12 @@ a_dbus_cleanup_bus(DBusConnection *dbus_connection, GSource **source)
} }
/** Iterate through the D-Bus messages counting each or traverse each sub message. /** Iterate through the D-Bus messages counting each or traverse each sub message.
* \param L The Lua VM state.
* \param iter The D-Bus message iterator pointer * \param iter The D-Bus message iterator pointer
* \return The number of arguments in the iterator * \return The number of arguments in the iterator
*/ */
static int static int
a_dbus_message_iter(DBusMessageIter *iter) a_dbus_message_iter(lua_State *L, DBusMessageIter *iter)
{ {
int nargs = 0; int nargs = 0;
@ -74,7 +75,7 @@ a_dbus_message_iter(DBusMessageIter *iter)
switch(dbus_message_iter_get_arg_type(iter)) switch(dbus_message_iter_get_arg_type(iter))
{ {
default: default:
lua_pushnil(globalconf.L); lua_pushnil(L);
nargs++; nargs++;
break; break;
case DBUS_TYPE_INVALID: case DBUS_TYPE_INVALID:
@ -83,7 +84,7 @@ a_dbus_message_iter(DBusMessageIter *iter)
{ {
DBusMessageIter subiter; DBusMessageIter subiter;
dbus_message_iter_recurse(iter, &subiter); dbus_message_iter_recurse(iter, &subiter);
a_dbus_message_iter(&subiter); a_dbus_message_iter(L, &subiter);
} }
nargs++; nargs++;
break; break;
@ -94,7 +95,7 @@ a_dbus_message_iter(DBusMessageIter *iter)
/* initialize a sub iterator */ /* initialize a sub iterator */
dbus_message_iter_recurse(iter, &subiter); dbus_message_iter_recurse(iter, &subiter);
/* create a new table to store the dict */ /* create a new table to store the dict */
a_dbus_message_iter(&subiter); a_dbus_message_iter(L, &subiter);
} }
nargs++; nargs++;
break; break;
@ -104,15 +105,15 @@ a_dbus_message_iter(DBusMessageIter *iter)
/* initialize a sub iterator */ /* initialize a sub iterator */
dbus_message_iter_recurse(iter, &subiter); dbus_message_iter_recurse(iter, &subiter);
int n = a_dbus_message_iter(&subiter); int n = a_dbus_message_iter(L, &subiter);
/* create a new table to store all the value */ /* create a new table to store all the value */
lua_createtable(globalconf.L, n, 0); lua_createtable(L, n, 0);
/* move the table before array elements */ /* move the table before array elements */
lua_insert(globalconf.L, - n - 1); lua_insert(L, - n - 1);
for(int i = n; i > 0; i--) for(int i = n; i > 0; i--)
lua_rawseti(globalconf.L, - i - 1, i); lua_rawseti(L, - i - 1, i);
} }
nargs++; nargs++;
break; break;
@ -133,11 +134,11 @@ a_dbus_message_iter(DBusMessageIter *iter)
{ \ { \
const type *data; \ const type *data; \
dbus_message_iter_get_fixed_array(&sub, &data, &datalen); \ dbus_message_iter_get_fixed_array(&sub, &data, &datalen); \
lua_createtable(globalconf.L, datalen, 0); \ lua_createtable(L, datalen, 0); \
for(int i = 0; i < datalen; i++) \ for(int i = 0; i < datalen; i++) \
{ \ { \
lua_pushnumber(globalconf.L, data[i]); \ lua_pushnumber(L, data[i]); \
lua_rawseti(globalconf.L, -2, i + 1); \ lua_rawseti(L, -2, i + 1); \
} \ } \
} \ } \
break; break;
@ -153,18 +154,18 @@ a_dbus_message_iter(DBusMessageIter *iter)
{ {
const char *c; const char *c;
dbus_message_iter_get_fixed_array(&sub, &c, &datalen); dbus_message_iter_get_fixed_array(&sub, &c, &datalen);
lua_pushlstring(globalconf.L, c, datalen); lua_pushlstring(L, c, datalen);
} }
break; break;
case DBUS_TYPE_BOOLEAN: case DBUS_TYPE_BOOLEAN:
{ {
const dbus_bool_t *b; const dbus_bool_t *b;
dbus_message_iter_get_fixed_array(&sub, &b, &datalen); dbus_message_iter_get_fixed_array(&sub, &b, &datalen);
lua_createtable(globalconf.L, datalen, 0); lua_createtable(L, datalen, 0);
for(int i = 0; i < datalen; i++) for(int i = 0; i < datalen; i++)
{ {
lua_pushboolean(globalconf.L, b[i]); lua_pushboolean(L, b[i]);
lua_rawseti(globalconf.L, -2, i + 1); lua_rawseti(L, -2, i + 1);
} }
} }
break; break;
@ -178,15 +179,15 @@ a_dbus_message_iter(DBusMessageIter *iter)
/* get the keys and the values /* get the keys and the values
* n is the number of entry in dict */ * n is the number of entry in dict */
int n = a_dbus_message_iter(&subiter); int n = a_dbus_message_iter(L, &subiter);
/* create a new table to store all the value */ /* create a new table to store all the value */
lua_createtable(globalconf.L, n, 0); lua_createtable(L, n, 0);
/* move the table before array elements */ /* move the table before array elements */
lua_insert(globalconf.L, - (n * 2) - 1); lua_insert(L, - (n * 2) - 1);
for(int i = 0; i < n; i ++) for(int i = 0; i < n; i ++)
lua_rawset(globalconf.L, - (n * 2) - 1 + i * 2); lua_rawset(L, - (n * 2) - 1 + i * 2);
} }
else else
{ {
@ -195,15 +196,15 @@ a_dbus_message_iter(DBusMessageIter *iter)
dbus_message_iter_recurse(iter, &subiter); dbus_message_iter_recurse(iter, &subiter);
/* now iterate over every element of the array */ /* now iterate over every element of the array */
int n = a_dbus_message_iter(&subiter); int n = a_dbus_message_iter(L, &subiter);
/* create a new table to store all the value */ /* create a new table to store all the value */
lua_createtable(globalconf.L, n, 0); lua_createtable(L, n, 0);
/* move the table before array elements */ /* move the table before array elements */
lua_insert(globalconf.L, - n - 1); lua_insert(L, - n - 1);
for(int i = n; i > 0; i--) for(int i = n; i > 0; i--)
lua_rawseti(globalconf.L, - i - 1, i); lua_rawseti(L, - i - 1, i);
} }
} }
nargs++; nargs++;
@ -212,7 +213,7 @@ a_dbus_message_iter(DBusMessageIter *iter)
{ {
dbus_bool_t b; dbus_bool_t b;
dbus_message_iter_get_basic(iter, &b); dbus_message_iter_get_basic(iter, &b);
lua_pushboolean(globalconf.L, b); lua_pushboolean(L, b);
} }
nargs++; nargs++;
break; break;
@ -220,7 +221,7 @@ a_dbus_message_iter(DBusMessageIter *iter)
{ {
char c; char c;
dbus_message_iter_get_basic(iter, &c); dbus_message_iter_get_basic(iter, &c);
lua_pushlstring(globalconf.L, &c, 1); lua_pushlstring(L, &c, 1);
} }
nargs++; nargs++;
break; break;
@ -229,7 +230,7 @@ a_dbus_message_iter(DBusMessageIter *iter)
{ \ { \
type ui; \ type ui; \
dbus_message_iter_get_basic(iter, &ui); \ dbus_message_iter_get_basic(iter, &ui); \
lua_pushnumber(globalconf.L, ui); \ lua_pushnumber(L, ui); \
} \ } \
nargs++; \ nargs++; \
break; break;
@ -244,7 +245,7 @@ a_dbus_message_iter(DBusMessageIter *iter)
{ {
char *s; char *s;
dbus_message_iter_get_basic(iter, &s); dbus_message_iter_get_basic(iter, &s);
lua_pushstring(globalconf.L, s); lua_pushstring(L, s);
} }
nargs++; nargs++;
break; break;
@ -345,54 +346,55 @@ static void
a_dbus_process_request(DBusConnection *dbus_connection, DBusMessage *msg) a_dbus_process_request(DBusConnection *dbus_connection, DBusMessage *msg)
{ {
const char *interface = dbus_message_get_interface(msg); const char *interface = dbus_message_get_interface(msg);
int old_top = lua_gettop(globalconf.L); lua_State *L = globalconf_get_lua_State();
int old_top = lua_gettop(L);
lua_createtable(globalconf.L, 0, 5); lua_createtable(L, 0, 5);
switch(dbus_message_get_type(msg)) switch(dbus_message_get_type(msg))
{ {
case DBUS_MESSAGE_TYPE_SIGNAL: case DBUS_MESSAGE_TYPE_SIGNAL:
lua_pushliteral(globalconf.L, "signal"); lua_pushliteral(L, "signal");
break; break;
case DBUS_MESSAGE_TYPE_METHOD_CALL: case DBUS_MESSAGE_TYPE_METHOD_CALL:
lua_pushliteral(globalconf.L, "method_call"); lua_pushliteral(L, "method_call");
break; break;
case DBUS_MESSAGE_TYPE_METHOD_RETURN: case DBUS_MESSAGE_TYPE_METHOD_RETURN:
lua_pushliteral(globalconf.L, "method_return"); lua_pushliteral(L, "method_return");
break; break;
case DBUS_MESSAGE_TYPE_ERROR: case DBUS_MESSAGE_TYPE_ERROR:
lua_pushliteral(globalconf.L, "error"); lua_pushliteral(L, "error");
break; break;
default: default:
lua_pushliteral(globalconf.L, "unknown"); lua_pushliteral(L, "unknown");
break; break;
} }
lua_setfield(globalconf.L, -2, "type"); lua_setfield(L, -2, "type");
lua_pushstring(globalconf.L, interface); lua_pushstring(L, interface);
lua_setfield(globalconf.L, -2, "interface"); lua_setfield(L, -2, "interface");
const char *s = dbus_message_get_path(msg); const char *s = dbus_message_get_path(msg);
lua_pushstring(globalconf.L, s); lua_pushstring(L, s);
lua_setfield(globalconf.L, -2, "path"); lua_setfield(L, -2, "path");
s = dbus_message_get_member(msg); s = dbus_message_get_member(msg);
lua_pushstring(globalconf.L, s); lua_pushstring(L, s);
lua_setfield(globalconf.L, -2, "member"); lua_setfield(L, -2, "member");
if(dbus_connection == dbus_connection_system) if(dbus_connection == dbus_connection_system)
lua_pushliteral(globalconf.L, "system"); lua_pushliteral(L, "system");
else else
lua_pushliteral(globalconf.L, "session"); lua_pushliteral(L, "session");
lua_setfield(globalconf.L, -2, "bus"); lua_setfield(L, -2, "bus");
/* + 1 for the table above */ /* + 1 for the table above */
DBusMessageIter iter; DBusMessageIter iter;
int nargs = 1; int nargs = 1;
if(dbus_message_iter_init(msg, &iter)) if(dbus_message_iter_init(msg, &iter))
nargs += a_dbus_message_iter(&iter); nargs += a_dbus_message_iter(L, &iter);
if(dbus_message_get_no_reply(msg)) if(dbus_message_get_no_reply(msg))
{ {
@ -400,7 +402,7 @@ a_dbus_process_request(DBusConnection *dbus_connection, DBusMessage *msg)
a_strhash((const unsigned char *) NONULL(interface))); a_strhash((const unsigned char *) NONULL(interface)));
/* emit signals */ /* emit signals */
if(sigfound) if(sigfound)
signal_object_emit(globalconf.L, &dbus_signals, NONULL(interface), nargs); signal_object_emit(L, &dbus_signals, NONULL(interface), nargs);
} }
else else
{ {
@ -411,12 +413,12 @@ a_dbus_process_request(DBusConnection *dbus_connection, DBusMessage *msg)
/* there can be only ONE handler to send reply */ /* there can be only ONE handler to send reply */
void *func = (void *) sig->sigfuncs.tab[0]; void *func = (void *) sig->sigfuncs.tab[0];
int n = lua_gettop(globalconf.L) - nargs; int n = lua_gettop(L) - nargs;
luaA_object_push(globalconf.L, (void *) func); luaA_object_push(L, (void *) func);
luaA_dofunction(globalconf.L, nargs, LUA_MULTRET); luaA_dofunction(L, nargs, LUA_MULTRET);
n -= lua_gettop(globalconf.L); n -= lua_gettop(L);
DBusMessage *reply = dbus_message_new_method_return(msg); DBusMessage *reply = dbus_message_new_method_return(msg);
@ -424,26 +426,26 @@ a_dbus_process_request(DBusConnection *dbus_connection, DBusMessage *msg)
if(n % 2 != 0) if(n % 2 != 0)
{ {
luaA_warn(globalconf.L, luaA_warn(L,
"your D-Bus signal handling method returned wrong number of arguments"); "your D-Bus signal handling method returned wrong number of arguments");
/* Restore stack */ /* Restore stack */
lua_settop(globalconf.L, old_top); lua_settop(L, old_top);
return; return;
} }
/* i is negative */ /* i is negative */
for(int i = n; i < 0; i += 2) for(int i = n; i < 0; i += 2)
{ {
if(!a_dbus_convert_value(globalconf.L, i, &iter)) if(!a_dbus_convert_value(L, i, &iter))
{ {
luaA_warn(globalconf.L, "your D-Bus signal handling method returned bad data"); luaA_warn(L, "your D-Bus signal handling method returned bad data");
/* Restore stack */ /* Restore stack */
lua_settop(globalconf.L, old_top); lua_settop(L, old_top);
return; return;
} }
lua_remove(globalconf.L, i); lua_remove(L, i);
lua_remove(globalconf.L, i + 1); lua_remove(L, i + 1);
} }
dbus_connection_send(dbus_connection, reply, NULL); dbus_connection_send(dbus_connection, reply, NULL);
@ -451,7 +453,7 @@ a_dbus_process_request(DBusConnection *dbus_connection, DBusMessage *msg)
} }
} }
/* Restore stack */ /* Restore stack */
lua_settop(globalconf.L, old_top); lua_settop(L, old_top);
} }
/** Attempt to process all the requests in the D-Bus connection. /** Attempt to process all the requests in the D-Bus connection.

199
event.c
View File

@ -47,19 +47,20 @@
static void \ static void \
event_##xcbtype##_callback(xcb_##xcbtype##_press_event_t *ev, \ event_##xcbtype##_callback(xcb_##xcbtype##_press_event_t *ev, \
arraytype *arr, \ arraytype *arr, \
lua_State *L, \
int oud, \ int oud, \
int nargs, \ int nargs, \
void *data) \ void *data) \
{ \ { \
int abs_oud = oud < 0 ? ((lua_gettop(globalconf.L) + 1) + oud) : oud; \ int abs_oud = oud < 0 ? ((lua_gettop(L) + 1) + oud) : oud; \
int item_matching = 0; \ int item_matching = 0; \
foreach(item, *arr) \ foreach(item, *arr) \
if(match(ev, *item, data)) \ if(match(ev, *item, data)) \
{ \ { \
if(oud) \ if(oud) \
luaA_object_push_item(globalconf.L, abs_oud, *item); \ luaA_object_push_item(L, abs_oud, *item); \
else \ else \
luaA_object_push(globalconf.L, *item); \ luaA_object_push(L, *item); \
item_matching++; \ item_matching++; \
} \ } \
for(; item_matching > 0; item_matching--) \ for(; item_matching > 0; item_matching--) \
@ -68,18 +69,18 @@
{ \ { \
case xcbeventprefix##_PRESS: \ case xcbeventprefix##_PRESS: \
for(int i = 0; i < nargs; i++) \ for(int i = 0; i < nargs; i++) \
lua_pushvalue(globalconf.L, - nargs - item_matching); \ lua_pushvalue(L, - nargs - item_matching); \
luaA_object_emit_signal(globalconf.L, - nargs - 1, "press", nargs); \ luaA_object_emit_signal(L, - nargs - 1, "press", nargs); \
break; \ break; \
case xcbeventprefix##_RELEASE: \ case xcbeventprefix##_RELEASE: \
for(int i = 0; i < nargs; i++) \ for(int i = 0; i < nargs; i++) \
lua_pushvalue(globalconf.L, - nargs - item_matching); \ lua_pushvalue(L, - nargs - item_matching); \
luaA_object_emit_signal(globalconf.L, - nargs - 1, "release", nargs); \ luaA_object_emit_signal(L, - nargs - 1, "release", nargs); \
break; \ break; \
} \ } \
lua_pop(globalconf.L, 1); \ lua_pop(L, 1); \
} \ } \
lua_pop(globalconf.L, nargs); \ lua_pop(L, nargs); \
} }
static bool static bool
@ -113,16 +114,17 @@ event_handle_mousegrabber(int x, int y, uint16_t mask)
{ {
if(globalconf.mousegrabber != LUA_REFNIL) if(globalconf.mousegrabber != LUA_REFNIL)
{ {
lua_rawgeti(globalconf.L, LUA_REGISTRYINDEX, globalconf.mousegrabber); lua_State *L = globalconf_get_lua_State();
mousegrabber_handleevent(globalconf.L, x, y, mask); lua_rawgeti(L, LUA_REGISTRYINDEX, globalconf.mousegrabber);
if(lua_pcall(globalconf.L, 1, 1, 0)) mousegrabber_handleevent(L, x, y, mask);
if(lua_pcall(L, 1, 1, 0))
{ {
warn("error running function: %s", lua_tostring(globalconf.L, -1)); warn("error running function: %s", lua_tostring(L, -1));
luaA_mousegrabber_stop(globalconf.L); luaA_mousegrabber_stop(L);
} }
else if(!lua_isboolean(globalconf.L, -1) || !lua_toboolean(globalconf.L, -1)) else if(!lua_isboolean(L, -1) || !lua_toboolean(L, -1))
luaA_mousegrabber_stop(globalconf.L); luaA_mousegrabber_stop(L);
lua_pop(globalconf.L, 1); /* pop returned value */ lua_pop(L, 1); /* pop returned value */
return true; return true;
} }
return false; return false;
@ -130,10 +132,11 @@ event_handle_mousegrabber(int x, int y, uint16_t mask)
/** Emit a button signal. /** Emit a button signal.
* The top of the lua stack has to be the object on which to emit the event. * The top of the lua stack has to be the object on which to emit the event.
* \param L The Lua VM state.
* \param ev The event to handle. * \param ev The event to handle.
*/ */
static void static void
event_emit_button(xcb_button_press_event_t *ev) event_emit_button(lua_State *L, xcb_button_press_event_t *ev)
{ {
const char *name; const char *name;
switch(XCB_EVENT_RESPONSE_TYPE(ev)) switch(XCB_EVENT_RESPONSE_TYPE(ev))
@ -149,12 +152,12 @@ event_emit_button(xcb_button_press_event_t *ev)
} }
/* Push the event's info */ /* Push the event's info */
lua_pushnumber(globalconf.L, ev->event_x); lua_pushnumber(L, ev->event_x);
lua_pushnumber(globalconf.L, ev->event_y); lua_pushnumber(L, ev->event_y);
lua_pushnumber(globalconf.L, ev->detail); lua_pushnumber(L, ev->detail);
luaA_pushmodifiers(globalconf.L, ev->state); luaA_pushmodifiers(L, ev->state);
/* And emit the signal */ /* And emit the signal */
luaA_object_emit_signal(globalconf.L, -5, name, 4); luaA_object_emit_signal(L, -5, name, 4);
} }
/** The button press event handler. /** The button press event handler.
@ -163,6 +166,7 @@ event_emit_button(xcb_button_press_event_t *ev)
static void static void
event_handle_button(xcb_button_press_event_t *ev) event_handle_button(xcb_button_press_event_t *ev)
{ {
lua_State *L = globalconf_get_lua_State();
client_t *c; client_t *c;
drawin_t *drawin; drawin_t *drawin;
@ -189,13 +193,13 @@ event_handle_button(xcb_button_press_event_t *ev)
} }
/* Push the drawable */ /* Push the drawable */
luaA_object_push(globalconf.L, drawin); luaA_object_push(L, drawin);
luaA_object_push_item(globalconf.L, -1, drawin->drawable); luaA_object_push_item(L, -1, drawin->drawable);
/* and handle the button raw button event */ /* and handle the button raw button event */
event_emit_button(ev); event_emit_button(L, ev);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
/* check if any button object matches */ /* check if any button object matches */
event_button_callback(ev, &drawin->buttons, -1, 1, NULL); event_button_callback(ev, &drawin->buttons, L, -1, 1, NULL);
/* Either we are receiving this due to ButtonPress/Release on the root /* Either we are receiving this due to ButtonPress/Release on the root
* window or because we grabbed the button on the window. In the later * window or because we grabbed the button on the window. In the later
* case we have to call AllowEvents. * case we have to call AllowEvents.
@ -209,9 +213,9 @@ event_handle_button(xcb_button_press_event_t *ev)
} }
else if((c = client_getbyframewin(ev->event))) else if((c = client_getbyframewin(ev->event)))
{ {
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
/* And handle the button raw button event */ /* And handle the button raw button event */
event_emit_button(ev); event_emit_button(L, ev);
/* then check if a titlebar was "hit" */ /* then check if a titlebar was "hit" */
int x = ev->event_x, y = ev->event_y; int x = ev->event_x, y = ev->event_y;
drawable_t *d = client_get_drawable_offset(c, &x, &y); drawable_t *d = client_get_drawable_offset(c, &x, &y);
@ -221,12 +225,12 @@ event_handle_button(xcb_button_press_event_t *ev)
xcb_button_press_event_t event = *ev; xcb_button_press_event_t event = *ev;
event.event_x = x; event.event_x = x;
event.event_y = y; event.event_y = y;
luaA_object_push_item(globalconf.L, -1, d); luaA_object_push_item(L, -1, d);
event_emit_button(&event); event_emit_button(L, &event);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
/* then check if any button objects match */ /* then check if any button objects match */
event_button_callback(ev, &c->buttons, -1, 1, NULL); event_button_callback(ev, &c->buttons, L, -1, 1, NULL);
xcb_allow_events(globalconf.connection, xcb_allow_events(globalconf.connection,
XCB_ALLOW_REPLAY_POINTER, XCB_ALLOW_REPLAY_POINTER,
XCB_CURRENT_TIME); XCB_CURRENT_TIME);
@ -234,7 +238,7 @@ event_handle_button(xcb_button_press_event_t *ev)
else if(ev->child == XCB_NONE) else if(ev->child == XCB_NONE)
if(globalconf.screen->root == ev->event) if(globalconf.screen->root == ev->event)
{ {
event_button_callback(ev, &globalconf.buttons, 0, 0, NULL); event_button_callback(ev, &globalconf.buttons, L, 0, 0, NULL);
return; return;
} }
} }
@ -330,13 +334,15 @@ event_handle_configurerequest(xcb_configure_request_event_t *ev)
} }
if(ev->value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH) if(ev->value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH)
{ {
lua_State *L = globalconf_get_lua_State();
diff_border = ev->border_width - c->border_width; diff_border = ev->border_width - c->border_width;
diff_h += diff_border; diff_h += diff_border;
diff_w += diff_border; diff_w += diff_border;
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
window_set_border_width(globalconf.L, -1, ev->border_width); window_set_border_width(L, -1, ev->border_width);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
/* If the client resizes without moving itself, apply window gravity */ /* If the client resizes without moving itself, apply window gravity */
@ -398,6 +404,7 @@ event_handle_destroynotify(xcb_destroy_notify_event_t *ev)
static void static void
event_handle_motionnotify(xcb_motion_notify_event_t *ev) event_handle_motionnotify(xcb_motion_notify_event_t *ev)
{ {
lua_State *L = globalconf_get_lua_State();
drawin_t *w; drawin_t *w;
client_t *c; client_t *c;
@ -408,33 +415,33 @@ event_handle_motionnotify(xcb_motion_notify_event_t *ev)
if((c = client_getbyframewin(ev->event))) if((c = client_getbyframewin(ev->event)))
{ {
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
lua_pushnumber(globalconf.L, ev->event_x); lua_pushnumber(L, ev->event_x);
lua_pushnumber(globalconf.L, ev->event_y); lua_pushnumber(L, ev->event_y);
luaA_object_emit_signal(globalconf.L, -3, "mouse::move", 2); luaA_object_emit_signal(L, -3, "mouse::move", 2);
/* now check if a titlebar was "hit" */ /* now check if a titlebar was "hit" */
int x = ev->event_x, y = ev->event_y; int x = ev->event_x, y = ev->event_y;
drawable_t *d = client_get_drawable_offset(c, &x, &y); drawable_t *d = client_get_drawable_offset(c, &x, &y);
if (d) if (d)
{ {
luaA_object_push_item(globalconf.L, -1, d); luaA_object_push_item(L, -1, d);
lua_pushnumber(globalconf.L, x); lua_pushnumber(L, x);
lua_pushnumber(globalconf.L, y); lua_pushnumber(L, y);
luaA_object_emit_signal(globalconf.L, -3, "mouse::move", 2); luaA_object_emit_signal(L, -3, "mouse::move", 2);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
if((w = drawin_getbywin(ev->event))) if((w = drawin_getbywin(ev->event)))
{ {
luaA_object_push(globalconf.L, w); luaA_object_push(L, w);
luaA_object_push_item(globalconf.L, -1, w->drawable); luaA_object_push_item(L, -1, w->drawable);
lua_pushnumber(globalconf.L, ev->event_x); lua_pushnumber(L, ev->event_x);
lua_pushnumber(globalconf.L, ev->event_y); lua_pushnumber(L, ev->event_y);
luaA_object_emit_signal(globalconf.L, -3, "mouse::move", 2); luaA_object_emit_signal(L, -3, "mouse::move", 2);
lua_pop(globalconf.L, 2); lua_pop(L, 2);
} }
} }
@ -444,6 +451,7 @@ event_handle_motionnotify(xcb_motion_notify_event_t *ev)
static void static void
event_handle_leavenotify(xcb_leave_notify_event_t *ev) event_handle_leavenotify(xcb_leave_notify_event_t *ev)
{ {
lua_State *L = globalconf_get_lua_State();
drawin_t *drawin; drawin_t *drawin;
client_t *c; client_t *c;
@ -454,24 +462,24 @@ event_handle_leavenotify(xcb_leave_notify_event_t *ev)
if((c = client_getbyframewin(ev->event))) if((c = client_getbyframewin(ev->event)))
{ {
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
luaA_object_emit_signal(globalconf.L, -1, "mouse::leave", 0); luaA_object_emit_signal(L, -1, "mouse::leave", 0);
drawable_t *d = client_get_drawable(c, ev->event_x, ev->event_y); drawable_t *d = client_get_drawable(c, ev->event_x, ev->event_y);
if (d) if (d)
{ {
luaA_object_push_item(globalconf.L, -1, d); luaA_object_push_item(L, -1, d);
luaA_object_emit_signal(globalconf.L, -1, "mouse::leave", 0); luaA_object_emit_signal(L, -1, "mouse::leave", 0);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
if((drawin = drawin_getbywin(ev->event))) if((drawin = drawin_getbywin(ev->event)))
{ {
luaA_object_push(globalconf.L, drawin); luaA_object_push(L, drawin);
luaA_object_push_item(globalconf.L, -1, drawin->drawable); luaA_object_push_item(L, -1, drawin->drawable);
luaA_object_emit_signal(globalconf.L, -1, "mouse::leave", 0); luaA_object_emit_signal(L, -1, "mouse::leave", 0);
lua_pop(globalconf.L, 2); lua_pop(L, 2);
} }
} }
@ -481,6 +489,7 @@ event_handle_leavenotify(xcb_leave_notify_event_t *ev)
static void static void
event_handle_enternotify(xcb_enter_notify_event_t *ev) event_handle_enternotify(xcb_enter_notify_event_t *ev)
{ {
lua_State *L = globalconf_get_lua_State();
client_t *c; client_t *c;
drawin_t *drawin; drawin_t *drawin;
@ -491,24 +500,24 @@ event_handle_enternotify(xcb_enter_notify_event_t *ev)
if((drawin = drawin_getbywin(ev->event))) if((drawin = drawin_getbywin(ev->event)))
{ {
luaA_object_push(globalconf.L, drawin); luaA_object_push(L, drawin);
luaA_object_push_item(globalconf.L, -1, drawin->drawable); luaA_object_push_item(L, -1, drawin->drawable);
luaA_object_emit_signal(globalconf.L, -1, "mouse::enter", 0); luaA_object_emit_signal(L, -1, "mouse::enter", 0);
lua_pop(globalconf.L, 2); lua_pop(L, 2);
} }
if((c = client_getbyframewin(ev->event))) if((c = client_getbyframewin(ev->event)))
{ {
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
luaA_object_emit_signal(globalconf.L, -1, "mouse::enter", 0); luaA_object_emit_signal(L, -1, "mouse::enter", 0);
drawable_t *d = client_get_drawable(c, ev->event_x, ev->event_y); drawable_t *d = client_get_drawable(c, ev->event_x, ev->event_y);
if (d) if (d)
{ {
luaA_object_push_item(globalconf.L, -1, d); luaA_object_push_item(L, -1, d);
luaA_object_emit_signal(globalconf.L, -1, "mouse::enter", 0); luaA_object_emit_signal(L, -1, "mouse::enter", 0);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
} }
@ -574,20 +583,21 @@ event_handle_expose(xcb_expose_event_t *ev)
static void static void
event_handle_key(xcb_key_press_event_t *ev) event_handle_key(xcb_key_press_event_t *ev)
{ {
lua_State *L = globalconf_get_lua_State();
globalconf.timestamp = ev->time; globalconf.timestamp = ev->time;
if(globalconf.keygrabber != LUA_REFNIL) if(globalconf.keygrabber != LUA_REFNIL)
{ {
lua_rawgeti(globalconf.L, LUA_REGISTRYINDEX, globalconf.keygrabber); lua_rawgeti(L, LUA_REGISTRYINDEX, globalconf.keygrabber);
if(keygrabber_handlekpress(globalconf.L, ev)) if(keygrabber_handlekpress(L, ev))
{ {
if(lua_pcall(globalconf.L, 3, 1, 0)) if(lua_pcall(L, 3, 1, 0))
{ {
warn("error running function: %s", lua_tostring(globalconf.L, -1)); warn("error running function: %s", lua_tostring(L, -1));
luaA_keygrabber_stop(globalconf.L); luaA_keygrabber_stop(L);
} }
} }
lua_pop(globalconf.L, 1); /* pop returned value or function if not called */ lua_pop(L, 1); /* pop returned value or function if not called */
} }
else else
{ {
@ -596,11 +606,11 @@ event_handle_key(xcb_key_press_event_t *ev)
client_t *c; client_t *c;
if((c = client_getbyframewin(ev->event))) if((c = client_getbyframewin(ev->event)))
{ {
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
event_key_callback(ev, &c->keys, -1, 1, &keysym); event_key_callback(ev, &c->keys, L, -1, 1, &keysym);
} }
else else
event_key_callback(ev, &globalconf.keys, 0, 0, &keysym); event_key_callback(ev, &globalconf.keys, L, 0, 0, &keysym);
} }
} }
@ -634,9 +644,10 @@ event_handle_maprequest(xcb_map_request_event_t *ev)
/* Check that it may be visible, but not asked to be hidden */ /* Check that it may be visible, but not asked to be hidden */
if(client_maybevisible(c) && !c->hidden) if(client_maybevisible(c) && !c->hidden)
{ {
luaA_object_push(globalconf.L, c); lua_State *L = globalconf_get_lua_State();
client_set_minimized(globalconf.L, -1, false); luaA_object_push(L, c);
lua_pop(globalconf.L, 1); client_set_minimized(L, -1, false);
lua_pop(L, 1);
/* it will be raised, so just update ourself */ /* it will be raised, so just update ourself */
client_raise(c); client_raise(c);
} }
@ -714,12 +725,13 @@ event_handle_shape_notify(xcb_shape_notify_event_t *ev)
client_t *c = client_getbywin(ev->affected_window); client_t *c = client_getbywin(ev->affected_window);
if (c) if (c)
{ {
luaA_object_push(globalconf.L, c); lua_State *L = globalconf_get_lua_State();
luaA_object_push(L, c);
if (ev->shape_kind == XCB_SHAPE_SK_BOUNDING) if (ev->shape_kind == XCB_SHAPE_SK_BOUNDING)
luaA_object_emit_signal(globalconf.L, -1, "property::shape_client_bounding", 0); luaA_object_emit_signal(L, -1, "property::shape_client_bounding", 0);
if (ev->shape_kind == XCB_SHAPE_SK_CLIP) if (ev->shape_kind == XCB_SHAPE_SK_CLIP)
luaA_object_emit_signal(globalconf.L, -1, "property::shape_client_clip", 0); luaA_object_emit_signal(L, -1, "property::shape_client_clip", 0);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
} }
@ -740,9 +752,10 @@ event_handle_clientmessage(xcb_client_message_event_t *ev)
&& ev->format == 32 && ev->format == 32
&& ev->data.data32[0] == XCB_ICCCM_WM_STATE_ICONIC) && ev->data.data32[0] == XCB_ICCCM_WM_STATE_ICONIC)
{ {
luaA_object_push(globalconf.L, c); lua_State *L = globalconf_get_lua_State();
client_set_minimized(globalconf.L, -1, true); luaA_object_push(L, c);
lua_pop(globalconf.L, 1); client_set_minimized(L, -1, true);
lua_pop(L, 1);
} }
} }
else if(ev->type == _XEMBED) else if(ev->type == _XEMBED)

134
ewmh.c
View File

@ -107,6 +107,7 @@ ewmh_update_net_client_list(lua_State *L)
void void
ewmh_init(void) ewmh_init(void)
{ {
lua_State *L = globalconf_get_lua_State();
xcb_window_t father; xcb_window_t father;
xcb_screen_t *xscreen = globalconf.screen; xcb_screen_t *xscreen = globalconf.screen;
xcb_atom_t atom[] = xcb_atom_t atom[] =
@ -185,20 +186,20 @@ ewmh_init(void)
father, _NET_WM_PID, XCB_ATOM_CARDINAL, 32, 1, &i); father, _NET_WM_PID, XCB_ATOM_CARDINAL, 32, 1, &i);
luaA_class_connect_signal(globalconf.L, &client_class, "focus", ewmh_update_net_active_window); luaA_class_connect_signal(L, &client_class, "focus", ewmh_update_net_active_window);
luaA_class_connect_signal(globalconf.L, &client_class, "unfocus", ewmh_update_net_active_window); luaA_class_connect_signal(L, &client_class, "unfocus", ewmh_update_net_active_window);
luaA_class_connect_signal(globalconf.L, &client_class, "manage", ewmh_update_net_client_list); luaA_class_connect_signal(L, &client_class, "manage", ewmh_update_net_client_list);
luaA_class_connect_signal(globalconf.L, &client_class, "unmanage", ewmh_update_net_client_list); luaA_class_connect_signal(L, &client_class, "unmanage", ewmh_update_net_client_list);
luaA_class_connect_signal(globalconf.L, &client_class, "property::modal" , ewmh_client_update_hints); luaA_class_connect_signal(L, &client_class, "property::modal" , ewmh_client_update_hints);
luaA_class_connect_signal(globalconf.L, &client_class, "property::fullscreen" , ewmh_client_update_hints); luaA_class_connect_signal(L, &client_class, "property::fullscreen" , ewmh_client_update_hints);
luaA_class_connect_signal(globalconf.L, &client_class, "property::maximized_horizontal" , ewmh_client_update_hints); luaA_class_connect_signal(L, &client_class, "property::maximized_horizontal" , ewmh_client_update_hints);
luaA_class_connect_signal(globalconf.L, &client_class, "property::maximized_vertical" , ewmh_client_update_hints); luaA_class_connect_signal(L, &client_class, "property::maximized_vertical" , ewmh_client_update_hints);
luaA_class_connect_signal(globalconf.L, &client_class, "property::sticky" , ewmh_client_update_hints); luaA_class_connect_signal(L, &client_class, "property::sticky" , ewmh_client_update_hints);
luaA_class_connect_signal(globalconf.L, &client_class, "property::skip_taskbar" , ewmh_client_update_hints); luaA_class_connect_signal(L, &client_class, "property::skip_taskbar" , ewmh_client_update_hints);
luaA_class_connect_signal(globalconf.L, &client_class, "property::above" , ewmh_client_update_hints); luaA_class_connect_signal(L, &client_class, "property::above" , ewmh_client_update_hints);
luaA_class_connect_signal(globalconf.L, &client_class, "property::below" , ewmh_client_update_hints); luaA_class_connect_signal(L, &client_class, "property::below" , ewmh_client_update_hints);
luaA_class_connect_signal(globalconf.L, &client_class, "property::minimized" , ewmh_client_update_hints); luaA_class_connect_signal(L, &client_class, "property::minimized" , ewmh_client_update_hints);
luaA_class_connect_signal(globalconf.L, &client_class, "property::urgent" , ewmh_client_update_hints); luaA_class_connect_signal(L, &client_class, "property::urgent" , ewmh_client_update_hints);
} }
/** Set the client list in stacking order, bottom to top. /** Set the client list in stacking order, bottom to top.
@ -259,121 +260,123 @@ ewmh_update_net_desktop_names(void)
static void static void
ewmh_process_state_atom(client_t *c, xcb_atom_t state, int set) ewmh_process_state_atom(client_t *c, xcb_atom_t state, int set)
{ {
luaA_object_push(globalconf.L, c); lua_State *L = globalconf_get_lua_State();
luaA_object_push(L, c);
if(state == _NET_WM_STATE_STICKY) if(state == _NET_WM_STATE_STICKY)
{ {
if(set == _NET_WM_STATE_REMOVE) if(set == _NET_WM_STATE_REMOVE)
client_set_sticky(globalconf.L, -1, false); client_set_sticky(L, -1, false);
else if(set == _NET_WM_STATE_ADD) else if(set == _NET_WM_STATE_ADD)
client_set_sticky(globalconf.L, -1, true); client_set_sticky(L, -1, true);
else if(set == _NET_WM_STATE_TOGGLE) else if(set == _NET_WM_STATE_TOGGLE)
client_set_sticky(globalconf.L, -1, !c->sticky); client_set_sticky(L, -1, !c->sticky);
} }
else if(state == _NET_WM_STATE_SKIP_TASKBAR) else if(state == _NET_WM_STATE_SKIP_TASKBAR)
{ {
if(set == _NET_WM_STATE_REMOVE) if(set == _NET_WM_STATE_REMOVE)
client_set_skip_taskbar(globalconf.L, -1, false); client_set_skip_taskbar(L, -1, false);
else if(set == _NET_WM_STATE_ADD) else if(set == _NET_WM_STATE_ADD)
client_set_skip_taskbar(globalconf.L, -1, true); client_set_skip_taskbar(L, -1, true);
else if(set == _NET_WM_STATE_TOGGLE) else if(set == _NET_WM_STATE_TOGGLE)
client_set_skip_taskbar(globalconf.L, -1, !c->skip_taskbar); client_set_skip_taskbar(L, -1, !c->skip_taskbar);
} }
else if(state == _NET_WM_STATE_FULLSCREEN) else if(state == _NET_WM_STATE_FULLSCREEN)
{ {
if(set == _NET_WM_STATE_REMOVE) if(set == _NET_WM_STATE_REMOVE)
client_set_fullscreen(globalconf.L, -1, false); client_set_fullscreen(L, -1, false);
else if(set == _NET_WM_STATE_ADD) else if(set == _NET_WM_STATE_ADD)
client_set_fullscreen(globalconf.L, -1, true); client_set_fullscreen(L, -1, true);
else if(set == _NET_WM_STATE_TOGGLE) else if(set == _NET_WM_STATE_TOGGLE)
client_set_fullscreen(globalconf.L, -1, !c->fullscreen); client_set_fullscreen(L, -1, !c->fullscreen);
} }
else if(state == _NET_WM_STATE_MAXIMIZED_HORZ) else if(state == _NET_WM_STATE_MAXIMIZED_HORZ)
{ {
if(set == _NET_WM_STATE_REMOVE) if(set == _NET_WM_STATE_REMOVE)
client_set_maximized_horizontal(globalconf.L, -1, false); client_set_maximized_horizontal(L, -1, false);
else if(set == _NET_WM_STATE_ADD) else if(set == _NET_WM_STATE_ADD)
client_set_maximized_horizontal(globalconf.L, -1, true); client_set_maximized_horizontal(L, -1, true);
else if(set == _NET_WM_STATE_TOGGLE) else if(set == _NET_WM_STATE_TOGGLE)
client_set_maximized_horizontal(globalconf.L, -1, !c->maximized_horizontal); client_set_maximized_horizontal(L, -1, !c->maximized_horizontal);
} }
else if(state == _NET_WM_STATE_MAXIMIZED_VERT) else if(state == _NET_WM_STATE_MAXIMIZED_VERT)
{ {
if(set == _NET_WM_STATE_REMOVE) if(set == _NET_WM_STATE_REMOVE)
client_set_maximized_vertical(globalconf.L, -1, false); client_set_maximized_vertical(L, -1, false);
else if(set == _NET_WM_STATE_ADD) else if(set == _NET_WM_STATE_ADD)
client_set_maximized_vertical(globalconf.L, -1, true); client_set_maximized_vertical(L, -1, true);
else if(set == _NET_WM_STATE_TOGGLE) else if(set == _NET_WM_STATE_TOGGLE)
client_set_maximized_vertical(globalconf.L, -1, !c->maximized_vertical); client_set_maximized_vertical(L, -1, !c->maximized_vertical);
} }
else if(state == _NET_WM_STATE_ABOVE) else if(state == _NET_WM_STATE_ABOVE)
{ {
if(set == _NET_WM_STATE_REMOVE) if(set == _NET_WM_STATE_REMOVE)
client_set_above(globalconf.L, -1, false); client_set_above(L, -1, false);
else if(set == _NET_WM_STATE_ADD) else if(set == _NET_WM_STATE_ADD)
client_set_above(globalconf.L, -1, true); client_set_above(L, -1, true);
else if(set == _NET_WM_STATE_TOGGLE) else if(set == _NET_WM_STATE_TOGGLE)
client_set_above(globalconf.L, -1, !c->above); client_set_above(L, -1, !c->above);
} }
else if(state == _NET_WM_STATE_BELOW) else if(state == _NET_WM_STATE_BELOW)
{ {
if(set == _NET_WM_STATE_REMOVE) if(set == _NET_WM_STATE_REMOVE)
client_set_below(globalconf.L, -1, false); client_set_below(L, -1, false);
else if(set == _NET_WM_STATE_ADD) else if(set == _NET_WM_STATE_ADD)
client_set_below(globalconf.L, -1, true); client_set_below(L, -1, true);
else if(set == _NET_WM_STATE_TOGGLE) else if(set == _NET_WM_STATE_TOGGLE)
client_set_below(globalconf.L, -1, !c->below); client_set_below(L, -1, !c->below);
} }
else if(state == _NET_WM_STATE_MODAL) else if(state == _NET_WM_STATE_MODAL)
{ {
if(set == _NET_WM_STATE_REMOVE) if(set == _NET_WM_STATE_REMOVE)
client_set_modal(globalconf.L, -1, false); client_set_modal(L, -1, false);
else if(set == _NET_WM_STATE_ADD) else if(set == _NET_WM_STATE_ADD)
client_set_modal(globalconf.L, -1, true); client_set_modal(L, -1, true);
else if(set == _NET_WM_STATE_TOGGLE) else if(set == _NET_WM_STATE_TOGGLE)
client_set_modal(globalconf.L, -1, !c->modal); client_set_modal(L, -1, !c->modal);
} }
else if(state == _NET_WM_STATE_HIDDEN) else if(state == _NET_WM_STATE_HIDDEN)
{ {
if(set == _NET_WM_STATE_REMOVE) if(set == _NET_WM_STATE_REMOVE)
client_set_minimized(globalconf.L, -1, false); client_set_minimized(L, -1, false);
else if(set == _NET_WM_STATE_ADD) else if(set == _NET_WM_STATE_ADD)
client_set_minimized(globalconf.L, -1, true); client_set_minimized(L, -1, true);
else if(set == _NET_WM_STATE_TOGGLE) else if(set == _NET_WM_STATE_TOGGLE)
client_set_minimized(globalconf.L, -1, !c->minimized); client_set_minimized(L, -1, !c->minimized);
} }
else if(state == _NET_WM_STATE_DEMANDS_ATTENTION) else if(state == _NET_WM_STATE_DEMANDS_ATTENTION)
{ {
if(set == _NET_WM_STATE_REMOVE) if(set == _NET_WM_STATE_REMOVE)
client_set_urgent(globalconf.L, -1, false); client_set_urgent(L, -1, false);
else if(set == _NET_WM_STATE_ADD) else if(set == _NET_WM_STATE_ADD)
client_set_urgent(globalconf.L, -1, true); client_set_urgent(L, -1, true);
else if(set == _NET_WM_STATE_TOGGLE) else if(set == _NET_WM_STATE_TOGGLE)
client_set_urgent(globalconf.L, -1, !c->urgent); client_set_urgent(L, -1, !c->urgent);
} }
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
static void static void
ewmh_process_desktop(client_t *c, uint32_t desktop) ewmh_process_desktop(client_t *c, uint32_t desktop)
{ {
lua_State *L = globalconf_get_lua_State();
int idx = desktop; int idx = desktop;
if(desktop == 0xffffffff) if(desktop == 0xffffffff)
{ {
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
lua_pushnil(globalconf.L); lua_pushnil(L);
luaA_object_emit_signal(globalconf.L, -2, "request::tag", 1); luaA_object_emit_signal(L, -2, "request::tag", 1);
/* Pop the client, arguments are already popped */ /* Pop the client, arguments are already popped */
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
else if (idx >= 0 && idx < globalconf.tags.len) else if (idx >= 0 && idx < globalconf.tags.len)
{ {
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
luaA_object_push(globalconf.L, globalconf.tags.tab[idx]); luaA_object_push(L, globalconf.tags.tab[idx]);
luaA_object_emit_signal(globalconf.L, -2, "request::tag", 1); luaA_object_emit_signal(L, -2, "request::tag", 1);
/* Pop the client, arguments are already popped */ /* Pop the client, arguments are already popped */
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
} }
@ -387,9 +390,10 @@ ewmh_process_client_message(xcb_client_message_event_t *ev)
int idx = ev->data.data32[0]; int idx = ev->data.data32[0];
if (idx >= 0 && idx < globalconf.tags.len) if (idx >= 0 && idx < globalconf.tags.len)
{ {
luaA_object_push(globalconf.L, globalconf.tags.tab[idx]); lua_State *L = globalconf_get_lua_State();
luaA_object_emit_signal(globalconf.L, -1, "request::select", 0); luaA_object_push(L, globalconf.tags.tab[idx]);
lua_pop(globalconf.L, 1); luaA_object_emit_signal(L, -1, "request::select", 0);
lua_pop(L, 1);
} }
} }
else if(ev->type == _NET_CLOSE_WINDOW) else if(ev->type == _NET_CLOSE_WINDOW)
@ -417,10 +421,11 @@ ewmh_process_client_message(xcb_client_message_event_t *ev)
else if(ev->type == _NET_ACTIVE_WINDOW) else if(ev->type == _NET_ACTIVE_WINDOW)
{ {
if((c = client_getbywin(ev->window))) { if((c = client_getbywin(ev->window))) {
luaA_object_push(globalconf.L, c); lua_State *L = globalconf_get_lua_State();
lua_pushstring(globalconf.L,"ewmh"); luaA_object_push(L, c);
luaA_object_emit_signal(globalconf.L, -2, "request::activate", 1); lua_pushstring(L, "ewmh");
lua_pop(globalconf.L, 1); luaA_object_emit_signal(L, -2, "request::activate", 1);
lua_pop(L, 1);
} }
} }
@ -595,9 +600,10 @@ ewmh_process_client_strut(client_t *c)
c->strut.bottom_start_x = strut[10]; c->strut.bottom_start_x = strut[10];
c->strut.bottom_end_x = strut[11]; c->strut.bottom_end_x = strut[11];
luaA_object_push(globalconf.L, c); lua_State *L = globalconf_get_lua_State();
luaA_object_emit_signal(globalconf.L, -1, "property::struts", 0); luaA_object_push(L, c);
lua_pop(globalconf.L, 1); luaA_object_emit_signal(L, -1, "property::struts", 0);
lua_pop(L, 1);
} }
} }

View File

@ -91,8 +91,10 @@ typedef struct
xembed_window_array_t embedded; xembed_window_array_t embedded;
/** Stack client history */ /** Stack client history */
client_array_t stack; client_array_t stack;
/** Lua VM state */ /** Lua VM state (opaque to avoid mis-use, see globalconf_get_lua_State()) */
lua_State *L; struct {
lua_State *real_L_dont_use_directly;
} L;
/** All errors messages from loading config files */ /** All errors messages from loading config files */
buffer_t startup_errors; buffer_t startup_errors;
/** main loop that awesome is running on */ /** main loop that awesome is running on */
@ -150,5 +152,12 @@ typedef struct
extern awesome_t globalconf; extern awesome_t globalconf;
/** You should always use this as lua_State *L = globalconf_get_lua_State().
* That way it becomes harder to introduce coroutine-related problems.
*/
static inline lua_State *globalconf_get_lua_State(void) {
return globalconf.L.real_L_dont_use_directly;
}
#endif #endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

20
luaa.c
View File

@ -363,7 +363,7 @@ luaA_init(xdgHandle* xdg)
{ NULL, NULL } { NULL, NULL }
}; };
L = globalconf.L = luaL_newstate(); L = globalconf.L.real_L_dont_use_directly = luaL_newstate();
/* Set panic function */ /* Set panic function */
lua_atpanic(L, luaA_panic); lua_atpanic(L, luaA_panic);
@ -492,7 +492,8 @@ luaA_startup_error(const char *err)
static bool static bool
luaA_loadrc(const char *confpath, bool run) luaA_loadrc(const char *confpath, bool run)
{ {
if(!luaL_loadfile(globalconf.L, confpath)) lua_State *L = globalconf_get_lua_State();
if(!luaL_loadfile(L, confpath))
{ {
if(run) if(run)
{ {
@ -500,11 +501,11 @@ luaA_loadrc(const char *confpath, bool run)
* configuration file. */ * configuration file. */
conffile = a_strdup(confpath); conffile = a_strdup(confpath);
/* Move error handling function before function */ /* Move error handling function before function */
lua_pushcfunction(globalconf.L, luaA_dofunction_on_error); lua_pushcfunction(L, luaA_dofunction_on_error);
lua_insert(globalconf.L, -2); lua_insert(L, -2);
if(lua_pcall(globalconf.L, 0, LUA_MULTRET, -2)) if(lua_pcall(L, 0, LUA_MULTRET, -2))
{ {
const char *err = lua_tostring(globalconf.L, -1); const char *err = lua_tostring(L, -1);
luaA_startup_error(err); luaA_startup_error(err);
fprintf(stderr, "%s\n", err); fprintf(stderr, "%s\n", err);
/* An error happened, so reset this. */ /* An error happened, so reset this. */
@ -515,13 +516,13 @@ luaA_loadrc(const char *confpath, bool run)
} }
else else
{ {
lua_pop(globalconf.L, 1); lua_pop(L, 1);
return true; return true;
} }
} }
else else
{ {
const char *err = lua_tostring(globalconf.L, -1); const char *err = lua_tostring(L, -1);
luaA_startup_error(err); luaA_startup_error(err);
fprintf(stderr, "%s\n", err); fprintf(stderr, "%s\n", err);
} }
@ -593,7 +594,8 @@ luaA_class_newindex_miss_property(lua_State *L, lua_object_t *obj)
void void
luaA_emit_refresh() luaA_emit_refresh()
{ {
signal_object_emit(globalconf.L, &global_signals, "refresh", 0); lua_State *L = globalconf_get_lua_State();
signal_object_emit(L, &global_signals, "refresh", 0);
} }
int int

View File

@ -199,11 +199,12 @@ client_getbyframewin(xcb_window_t w)
static void static void
client_unfocus_internal(client_t *c) client_unfocus_internal(client_t *c)
{ {
lua_State *L = globalconf_get_lua_State();
globalconf.focus.client = NULL; globalconf.focus.client = NULL;
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
luaA_object_emit_signal(globalconf.L, -1, "unfocus", 0); luaA_object_emit_signal(L, -1, "unfocus", 0);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
/** Unfocus a client. /** Unfocus a client.
@ -297,6 +298,8 @@ client_restore_enterleave_events(void)
void void
client_focus_update(client_t *c) client_focus_update(client_t *c)
{ {
lua_State *L = globalconf_get_lua_State();
if(!client_maybevisible(c)) if(!client_maybevisible(c))
return; return;
@ -317,11 +320,11 @@ client_focus_update(client_t *c)
globalconf.focus.client = c; globalconf.focus.client = c;
/* according to EWMH, we have to remove the urgent state from a client */ /* according to EWMH, we have to remove the urgent state from a client */
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
client_set_urgent(globalconf.L, -1, false); client_set_urgent(L, -1, false);
luaA_object_emit_signal(globalconf.L, -1, "focus", 0); luaA_object_emit_signal(L, -1, "focus", 0);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
/** Give focus to client, or to first client if client is NULL. /** Give focus to client, or to first client if client is NULL.
@ -426,6 +429,7 @@ client_update_properties(lua_State *L, int cidx, client_t *c)
void void
client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, xcb_get_window_attributes_reply_t *wattr) client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, xcb_get_window_attributes_reply_t *wattr)
{ {
lua_State *L = globalconf_get_lua_State();
const uint32_t select_input_val[] = { CLIENT_SELECT_INPUT_EVENT_MASK }; const uint32_t select_input_val[] = { CLIENT_SELECT_INPUT_EVENT_MASK };
if(systray_iskdedockapp(w)) if(systray_iskdedockapp(w))
@ -445,7 +449,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, xcb_get_window_at
if (globalconf.have_shape) if (globalconf.have_shape)
xcb_shape_select_input(globalconf.connection, w, 1); xcb_shape_select_input(globalconf.connection, w, 1);
client_t *c = client_new(globalconf.L); client_t *c = client_new(L);
xcb_screen_t *s = globalconf.screen; xcb_screen_t *s = globalconf.screen;
/* consider the window banned */ /* consider the window banned */
@ -493,7 +497,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, xcb_get_window_at
* (Else, reparent could cause an UnmapNotify) */ * (Else, reparent could cause an UnmapNotify) */
xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val); xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
luaA_object_emit_signal(globalconf.L, -1, "property::window", 0); luaA_object_emit_signal(L, -1, "property::window", 0);
/* The frame window gets the border, not the real client window */ /* The frame window gets the border, not the real client window */
xcb_configure_window(globalconf.connection, w, xcb_configure_window(globalconf.connection, w,
@ -509,8 +513,8 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, xcb_get_window_at
(uint32_t[]) { XCB_STACK_MODE_BELOW}); (uint32_t[]) { XCB_STACK_MODE_BELOW});
/* Duplicate client and push it in client list */ /* Duplicate client and push it in client list */
lua_pushvalue(globalconf.L, -1); lua_pushvalue(L, -1);
client_array_push(&globalconf.clients, luaA_object_ref(globalconf.L, -1)); client_array_push(&globalconf.clients, luaA_object_ref(L, -1));
/* Set the right screen */ /* Set the right screen */
screen_client_moveto(c, screen_getbycoord(wgeom->x, wgeom->y), false); screen_client_moveto(c, screen_getbycoord(wgeom->x, wgeom->y), false);
@ -519,24 +523,24 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, xcb_get_window_at
* been set. */ * been set. */
#define HANDLE_GEOM(attr) \ #define HANDLE_GEOM(attr) \
c->geometry.attr = wgeom->attr; \ c->geometry.attr = wgeom->attr; \
luaA_object_emit_signal(globalconf.L, -1, "property::" #attr, 0); luaA_object_emit_signal(L, -1, "property::" #attr, 0);
HANDLE_GEOM(x) HANDLE_GEOM(x)
HANDLE_GEOM(y) HANDLE_GEOM(y)
HANDLE_GEOM(width) HANDLE_GEOM(width)
HANDLE_GEOM(height) HANDLE_GEOM(height)
#undef HANDLE_GEOM #undef HANDLE_GEOM
luaA_object_emit_signal(globalconf.L, -1, "property::geometry", 0); luaA_object_emit_signal(L, -1, "property::geometry", 0);
/* Set border width */ /* Set border width */
window_set_border_width(globalconf.L, -1, wgeom->border_width); window_set_border_width(L, -1, wgeom->border_width);
/* we honor size hints by default */ /* we honor size hints by default */
c->size_hints_honor = true; c->size_hints_honor = true;
luaA_object_emit_signal(globalconf.L, -1, "property::size_hints_honor", 0); luaA_object_emit_signal(L, -1, "property::size_hints_honor", 0);
/* update all properties */ /* update all properties */
client_update_properties(globalconf.L, -1, c); client_update_properties(L, -1, c);
/* Then check clients hints */ /* Then check clients hints */
ewmh_client_check_hints(c); ewmh_client_check_hints(c);
@ -571,12 +575,12 @@ HANDLE_GEOM(height)
p_delete(&reply); p_delete(&reply);
spawn_start_notify(c, startup_id); spawn_start_notify(c, startup_id);
luaA_class_emit_signal(globalconf.L, &client_class, "list", 0); luaA_class_emit_signal(L, &client_class, "list", 0);
/* client is still on top of the stack; emit signal */ /* client is still on top of the stack; emit signal */
luaA_object_emit_signal(globalconf.L, -1, "manage", 0); luaA_object_emit_signal(L, -1, "manage", 0);
/* pop client */ /* pop client */
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
static void static void
@ -721,6 +725,7 @@ client_apply_size_hints(client_t *c, area_t geometry)
static void static void
client_resize_do(client_t *c, area_t geometry, bool force_notice, bool honor_hints) client_resize_do(client_t *c, area_t geometry, bool force_notice, bool honor_hints)
{ {
lua_State *L = globalconf_get_lua_State();
bool send_notice = force_notice; bool send_notice = force_notice;
bool hide_titlebars = c->fullscreen; bool hide_titlebars = c->fullscreen;
screen_t *new_screen = screen_getbycoord(geometry.x, geometry.y); screen_t *new_screen = screen_getbycoord(geometry.x, geometry.y);
@ -767,17 +772,17 @@ client_resize_do(client_t *c, area_t geometry, bool force_notice, bool honor_hin
client_restore_enterleave_events(); client_restore_enterleave_events();
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
luaA_object_emit_signal(globalconf.L, -1, "property::geometry", 0); luaA_object_emit_signal(L, -1, "property::geometry", 0);
if (old_geometry.x != geometry.x) if (old_geometry.x != geometry.x)
luaA_object_emit_signal(globalconf.L, -1, "property::x", 0); luaA_object_emit_signal(L, -1, "property::x", 0);
if (old_geometry.y != geometry.y) if (old_geometry.y != geometry.y)
luaA_object_emit_signal(globalconf.L, -1, "property::y", 0); luaA_object_emit_signal(L, -1, "property::y", 0);
if (old_geometry.width != geometry.width) if (old_geometry.width != geometry.width)
luaA_object_emit_signal(globalconf.L, -1, "property::width", 0); luaA_object_emit_signal(L, -1, "property::width", 0);
if (old_geometry.height != geometry.height) if (old_geometry.height != geometry.height)
luaA_object_emit_signal(globalconf.L, -1, "property::height", 0); luaA_object_emit_signal(L, -1, "property::height", 0);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
screen_client_moveto(c, new_screen, false); screen_client_moveto(c, new_screen, false);
@ -786,9 +791,9 @@ client_resize_do(client_t *c, area_t geometry, bool force_notice, bool honor_hin
if (c->titlebar[bar].drawable == NULL && c->titlebar[bar].size == 0) if (c->titlebar[bar].drawable == NULL && c->titlebar[bar].size == 0)
continue; continue;
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
drawable_t *drawable = titlebar_get_drawable(globalconf.L, c, -1, bar); drawable_t *drawable = titlebar_get_drawable(L, c, -1, bar);
luaA_object_push_item(globalconf.L, -1, drawable); luaA_object_push_item(L, -1, drawable);
area_t area = titlebar_get_area(c, bar); area_t area = titlebar_get_area(c, bar);
@ -797,10 +802,10 @@ client_resize_do(client_t *c, area_t geometry, bool force_notice, bool honor_hin
area.y += geometry.y; area.y += geometry.y;
if (hide_titlebars) if (hide_titlebars)
area.width = area.height = 0; area.width = area.height = 0;
drawable_set_geometry(globalconf.L, -1, area); drawable_set_geometry(L, -1, area);
/* Pop the client and the drawable */ /* Pop the client and the drawable */
lua_pop(globalconf.L, 2); lua_pop(L, 2);
} }
} }
@ -1102,6 +1107,7 @@ client_set_ontop(lua_State *L, int cidx, bool s)
void void
client_unban(client_t *c) client_unban(client_t *c)
{ {
lua_State *L = globalconf_get_lua_State();
if(c->isbanned) if(c->isbanned)
{ {
xcb_map_window(globalconf.connection, c->frame_window); xcb_map_window(globalconf.connection, c->frame_window);
@ -1109,10 +1115,10 @@ client_unban(client_t *c)
c->isbanned = false; c->isbanned = false;
/* An unbanned client shouldn't be minimized or hidden */ /* An unbanned client shouldn't be minimized or hidden */
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
client_set_minimized(globalconf.L, -1, false); client_set_minimized(L, -1, false);
client_set_hidden(globalconf.L, -1, false); client_set_hidden(L, -1, false);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
} }
@ -1123,6 +1129,8 @@ client_unban(client_t *c)
void void
client_unmanage(client_t *c, bool window_valid) client_unmanage(client_t *c, bool window_valid)
{ {
lua_State *L = globalconf_get_lua_State();
/* Reset transient_for attributes of windows that might be referring to us */ /* Reset transient_for attributes of windows that might be referring to us */
foreach(_tc, globalconf.clients) foreach(_tc, globalconf.clients)
{ {
@ -1145,14 +1153,14 @@ client_unmanage(client_t *c, bool window_valid)
for(int i = 0; i < globalconf.tags.len; i++) for(int i = 0; i < globalconf.tags.len; i++)
untag_client(c, globalconf.tags.tab[i]); untag_client(c, globalconf.tags.tab[i]);
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
luaA_object_emit_signal(globalconf.L, -1, "unmanage", 0); luaA_object_emit_signal(L, -1, "unmanage", 0);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
luaA_class_emit_signal(globalconf.L, &client_class, "list", 0); luaA_class_emit_signal(L, &client_class, "list", 0);
if(strut_has_value(&c->strut)) if(strut_has_value(&c->strut))
client_emit_property_workarea_on_screen(globalconf.L, c); client_emit_property_workarea_on_screen(L, c);
/* Get rid of all titlebars */ /* Get rid of all titlebars */
for (client_titlebar_t bar = CLIENT_TITLEBAR_TOP; bar < CLIENT_TITLEBAR_COUNT; bar++) { for (client_titlebar_t bar = CLIENT_TITLEBAR_TOP; bar < CLIENT_TITLEBAR_COUNT; bar++) {
@ -1160,10 +1168,10 @@ client_unmanage(client_t *c, bool window_valid)
continue; continue;
/* Forget about the drawable */ /* Forget about the drawable */
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
luaA_object_unref_item(globalconf.L, -1, c->titlebar[bar].drawable); luaA_object_unref_item(L, -1, c->titlebar[bar].drawable);
c->titlebar[bar].drawable = NULL; c->titlebar[bar].drawable = NULL;
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
/* Clear our event mask so that we don't receive any events from now on, /* Clear our event mask so that we don't receive any events from now on,
@ -1206,7 +1214,7 @@ client_unmanage(client_t *c, bool window_valid)
/* set client as invalid */ /* set client as invalid */
c->window = XCB_NONE; c->window = XCB_NONE;
luaA_object_unref(globalconf.L, c); luaA_object_unref(L, c);
} }
/** Kill a client via a WM_DELETE_WINDOW request or KillClient if not /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
@ -1287,15 +1295,17 @@ luaA_client_isvisible(lua_State *L)
void void
client_set_icon(client_t *c, cairo_surface_t *s) client_set_icon(client_t *c, cairo_surface_t *s)
{ {
lua_State *L = globalconf_get_lua_State();
if (s) if (s)
s = draw_dup_image_surface(s); s = draw_dup_image_surface(s);
if(c->icon) if(c->icon)
cairo_surface_destroy(c->icon); cairo_surface_destroy(c->icon);
c->icon = s; c->icon = s;
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
luaA_object_emit_signal(globalconf.L, -1, "property::icon", 0); luaA_object_emit_signal(L, -1, "property::icon", 0);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
/** Kill a client. /** Kill a client.
@ -1340,7 +1350,7 @@ luaA_client_swap(lua_State *L)
*ref_c = swap; *ref_c = swap;
*ref_swap = c; *ref_swap = c;
luaA_class_emit_signal(globalconf.L, &client_class, "list", 0); luaA_class_emit_signal(L, &client_class, "list", 0);
} }
return 0; return 0;
@ -2156,7 +2166,7 @@ luaA_client_module_index(lua_State *L)
const char *buf = luaL_checkstring(L, 2); const char *buf = luaL_checkstring(L, 2);
if (A_STREQ(buf, "focus")) if (A_STREQ(buf, "focus"))
return luaA_object_push(globalconf.L, globalconf.focus.client); return luaA_object_push(L, globalconf.focus.client);
return 0; return 0;
} }

View File

@ -144,6 +144,8 @@ screen_scan_randr(void)
for(int i = 0; i < screen_res_r->num_crtcs; i++) for(int i = 0; i < screen_res_r->num_crtcs; i++)
{ {
lua_State *L = globalconf_get_lua_State();
/* Get info on the output crtc */ /* Get info on the output crtc */
xcb_randr_get_crtc_info_cookie_t crtc_info_c = xcb_randr_get_crtc_info(globalconf.connection, randr_crtcs[i], XCB_CURRENT_TIME); xcb_randr_get_crtc_info_cookie_t crtc_info_c = xcb_randr_get_crtc_info(globalconf.connection, randr_crtcs[i], XCB_CURRENT_TIME);
xcb_randr_get_crtc_info_reply_t *crtc_info_r = xcb_randr_get_crtc_info_reply(globalconf.connection, crtc_info_c, NULL); xcb_randr_get_crtc_info_reply_t *crtc_info_r = xcb_randr_get_crtc_info_reply(globalconf.connection, crtc_info_c, NULL);
@ -153,7 +155,7 @@ screen_scan_randr(void)
continue; continue;
/* Prepare the new screen */ /* Prepare the new screen */
screen_t *new_screen = screen_new(globalconf.L); screen_t *new_screen = screen_new(L);
new_screen->geometry.x = crtc_info_r->x; new_screen->geometry.x = crtc_info_r->x;
new_screen->geometry.y = crtc_info_r->y; new_screen->geometry.y = crtc_info_r->y;
new_screen->geometry.width= crtc_info_r->width; new_screen->geometry.width= crtc_info_r->width;
@ -179,7 +181,7 @@ screen_scan_randr(void)
p_delete(&output_info_r); p_delete(&output_info_r);
} }
screen_add(globalconf.L, -1); screen_add(L, -1);
p_delete(&crtc_info_r); p_delete(&crtc_info_r);
} }
@ -223,9 +225,10 @@ screen_scan_xinerama(void)
/* now check if screens overlaps (same x,y): if so, we take only the biggest one */ /* now check if screens overlaps (same x,y): if so, we take only the biggest one */
for(int screen = 0; screen < xinerama_screen_number; screen++) for(int screen = 0; screen < xinerama_screen_number; screen++)
{ {
screen_t *s = screen_new(globalconf.L); lua_State *L = globalconf_get_lua_State();
screen_t *s = screen_new(L);
s->geometry = screen_xsitoarea(xsi[screen]); s->geometry = screen_xsitoarea(xsi[screen]);
screen_add(globalconf.L, -1); screen_add(L, -1);
} }
p_delete(&xsq); p_delete(&xsq);
@ -239,13 +242,14 @@ screen_scan_xinerama(void)
static void screen_scan_x11(void) static void screen_scan_x11(void)
{ {
/* One screen only / Zaphod mode */ /* One screen only / Zaphod mode */
lua_State *L = globalconf_get_lua_State();
xcb_screen_t *xcb_screen = globalconf.screen; xcb_screen_t *xcb_screen = globalconf.screen;
screen_t *s = screen_new(globalconf.L); screen_t *s = screen_new(L);
s->geometry.x = 0; s->geometry.x = 0;
s->geometry.y = 0; s->geometry.y = 0;
s->geometry.width = xcb_screen->width_in_pixels; s->geometry.width = xcb_screen->width_in_pixels;
s->geometry.height = xcb_screen->height_in_pixels; s->geometry.height = xcb_screen->height_in_pixels;
screen_add(globalconf.L, -1); screen_add(L, -1);
} }
/** Get screens informations and fill global configuration. /** Get screens informations and fill global configuration.
@ -367,6 +371,7 @@ display_area_get(void)
void void
screen_client_moveto(client_t *c, screen_t *new_screen, bool doresize) screen_client_moveto(client_t *c, screen_t *new_screen, bool doresize)
{ {
lua_State *L = globalconf_get_lua_State();
screen_t *old_screen = c->screen; screen_t *old_screen = c->screen;
area_t from, to; area_t from, to;
bool had_focus = false; bool had_focus = false;
@ -381,9 +386,9 @@ screen_client_moveto(client_t *c, screen_t *new_screen, bool doresize)
if(!doresize) if(!doresize)
{ {
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
luaA_object_emit_signal(globalconf.L, -1, "property::screen", 0); luaA_object_emit_signal(L, -1, "property::screen", 0);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
if(had_focus) if(had_focus)
client_focus(c); client_focus(c);
return; return;
@ -411,9 +416,9 @@ screen_client_moveto(client_t *c, screen_t *new_screen, bool doresize)
/* move / resize the client */ /* move / resize the client */
client_resize(c, new_geometry, false); client_resize(c, new_geometry, false);
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
luaA_object_emit_signal(globalconf.L, -1, "property::screen", 0); luaA_object_emit_signal(L, -1, "property::screen", 0);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
if(had_focus) if(had_focus)
client_focus(c); client_focus(c);
} }

View File

@ -46,7 +46,8 @@ LUA_OBJECT_FUNCS(tag_class, tag_t, tag)
void void
tag_unref_simplified(tag_t **tag) tag_unref_simplified(tag_t **tag)
{ {
luaA_object_unref(globalconf.L, *tag); lua_State *L = globalconf_get_lua_State();
luaA_object_unref(L, *tag);
} }
static void static void
@ -79,8 +80,9 @@ tag_view(lua_State *L, int udx, bool view)
} }
static void static void
tag_client_emit_signal(lua_State *L, tag_t *t, client_t *c, const char *signame) tag_client_emit_signal(tag_t *t, client_t *c, const char *signame)
{ {
lua_State *L = globalconf_get_lua_State();
luaA_object_push(L, c); luaA_object_push(L, c);
luaA_object_push(L, t); luaA_object_push(L, t);
/* emit signal on client, with new tag as argument */ /* emit signal on client, with new tag as argument */
@ -114,7 +116,7 @@ tag_client(lua_State *L, client_t *c)
ewmh_client_update_desktop(c); ewmh_client_update_desktop(c);
banning_need_update(); banning_need_update();
tag_client_emit_signal(L, t, c, "tagged"); tag_client_emit_signal(t, c, "tagged");
} }
/** Untag a client with specified tag. /** Untag a client with specified tag.
@ -127,11 +129,12 @@ untag_client(client_t *c, tag_t *t)
for(int i = 0; i < t->clients.len; i++) for(int i = 0; i < t->clients.len; i++)
if(t->clients.tab[i] == c) if(t->clients.tab[i] == c)
{ {
lua_State *L = globalconf_get_lua_State();
client_array_take(&t->clients, i); client_array_take(&t->clients, i);
banning_need_update(); banning_need_update();
ewmh_client_update_desktop(c); ewmh_client_update_desktop(c);
tag_client_emit_signal(globalconf.L, t, c, "untagged"); tag_client_emit_signal(t, c, "untagged");
luaA_object_unref(globalconf.L, t); luaA_object_unref(L, t);
return; return;
} }
} }

View File

@ -38,9 +38,10 @@ LUA_OBJECT_FUNCS(timer_class, atimer_t, timer)
static gboolean static gboolean
timer_emit_signal(gpointer data) timer_emit_signal(gpointer data)
{ {
luaA_object_push(globalconf.L, data); lua_State *L = globalconf_get_lua_State();
luaA_object_emit_signal(globalconf.L, -1, "timeout", 0); luaA_object_push(L, data);
lua_pop(globalconf.L, 1); luaA_object_emit_signal(L, -1, "timeout", 0);
lua_pop(L, 1);
return TRUE; return TRUE;
} }

View File

@ -44,11 +44,12 @@
void \ void \
property_update_##funcname(client_t *c, xcb_get_property_cookie_t cookie) \ property_update_##funcname(client_t *c, xcb_get_property_cookie_t cookie) \
{ \ { \
lua_State *L = globalconf_get_lua_State(); \
xcb_get_property_reply_t * reply = \ xcb_get_property_reply_t * reply = \
xcb_get_property_reply(globalconf.connection, cookie, NULL); \ xcb_get_property_reply(globalconf.connection, cookie, NULL); \
luaA_object_push(globalconf.L, c); \ luaA_object_push(L, c); \
setfunc(globalconf.L, -1, xutil_get_text_property_from_reply(reply)); \ setfunc(L, -1, xutil_get_text_property_from_reply(reply)); \
lua_pop(globalconf.L, 1); \ lua_pop(L, 1); \
p_delete(&reply); \ p_delete(&reply); \
} \ } \
static int \ static int \
@ -102,6 +103,7 @@ property_get_wm_transient_for(client_t *c)
void void
property_update_wm_transient_for(client_t *c, xcb_get_property_cookie_t cookie) property_update_wm_transient_for(client_t *c, xcb_get_property_cookie_t cookie)
{ {
lua_State *L = globalconf_get_lua_State();
xcb_window_t trans; xcb_window_t trans;
int counter; int counter;
client_t *tc, *tmp; client_t *tc, *tmp;
@ -113,9 +115,9 @@ property_update_wm_transient_for(client_t *c, xcb_get_property_cookie_t cookie)
tmp = tc = client_getbywin(trans); tmp = tc = client_getbywin(trans);
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
client_set_type(globalconf.L, -1, WINDOW_TYPE_DIALOG); client_set_type(L, -1, WINDOW_TYPE_DIALOG);
client_set_above(globalconf.L, -1, false); client_set_above(L, -1, false);
/* Verify that there are no loops in the transient_for relation after we are done */ /* Verify that there are no loops in the transient_for relation after we are done */
for(counter = 0; tmp != NULL && counter <= globalconf.stack.len; counter++) for(counter = 0; tmp != NULL && counter <= globalconf.stack.len; counter++)
@ -126,9 +128,9 @@ property_update_wm_transient_for(client_t *c, xcb_get_property_cookie_t cookie)
tmp = tmp->transient_for; tmp = tmp->transient_for;
} }
if (counter <= globalconf.stack.len) if (counter <= globalconf.stack.len)
client_set_transient_for(globalconf.L, -1, tc); client_set_transient_for(L, -1, tc);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
xcb_get_property_cookie_t xcb_get_property_cookie_t
@ -187,6 +189,7 @@ property_get_wm_hints(client_t *c)
void void
property_update_wm_hints(client_t *c, xcb_get_property_cookie_t cookie) property_update_wm_hints(client_t *c, xcb_get_property_cookie_t cookie)
{ {
lua_State *L = globalconf_get_lua_State();
xcb_icccm_wm_hints_t wmh; xcb_icccm_wm_hints_t wmh;
if(!xcb_icccm_get_wm_hints_reply(globalconf.connection, if(!xcb_icccm_get_wm_hints_reply(globalconf.connection,
@ -194,16 +197,16 @@ property_update_wm_hints(client_t *c, xcb_get_property_cookie_t cookie)
&wmh, NULL)) &wmh, NULL))
return; return;
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
client_set_urgent(globalconf.L, -1, xcb_icccm_wm_hints_get_urgency(&wmh)); client_set_urgent(L, -1, xcb_icccm_wm_hints_get_urgency(&wmh));
if(wmh.flags & XCB_ICCCM_WM_HINT_INPUT) if(wmh.flags & XCB_ICCCM_WM_HINT_INPUT)
c->nofocus = !wmh.input; c->nofocus = !wmh.input;
if(wmh.flags & XCB_ICCCM_WM_HINT_WINDOW_GROUP) if(wmh.flags & XCB_ICCCM_WM_HINT_WINDOW_GROUP)
client_set_group_window(globalconf.L, -1, wmh.window_group); client_set_group_window(L, -1, wmh.window_group);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
xcb_get_property_cookie_t xcb_get_property_cookie_t
@ -219,6 +222,7 @@ property_get_wm_class(client_t *c)
void void
property_update_wm_class(client_t *c, xcb_get_property_cookie_t cookie) property_update_wm_class(client_t *c, xcb_get_property_cookie_t cookie)
{ {
lua_State *L = globalconf_get_lua_State();
xcb_icccm_get_wm_class_reply_t hint; xcb_icccm_get_wm_class_reply_t hint;
if(!xcb_icccm_get_wm_class_reply(globalconf.connection, if(!xcb_icccm_get_wm_class_reply(globalconf.connection,
@ -226,9 +230,9 @@ property_update_wm_class(client_t *c, xcb_get_property_cookie_t cookie)
&hint, NULL)) &hint, NULL))
return; return;
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
client_set_class_instance(globalconf.L, -1, hint.class_name, hint.instance_name); client_set_class_instance(L, -1, hint.class_name, hint.instance_name);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
xcb_icccm_get_wm_class_reply_wipe(&hint); xcb_icccm_get_wm_class_reply_wipe(&hint);
} }
@ -281,9 +285,10 @@ property_update_net_wm_pid(client_t *c, xcb_get_property_cookie_t cookie)
uint32_t *rdata = xcb_get_property_value(reply); uint32_t *rdata = xcb_get_property_value(reply);
if(rdata) if(rdata)
{ {
luaA_object_push(globalconf.L, c); lua_State *L = globalconf_get_lua_State();
client_set_pid(globalconf.L, -1, *rdata); luaA_object_push(L, c);
lua_pop(globalconf.L, 1); client_set_pid(L, -1, *rdata);
lua_pop(L, 1);
} }
} }
@ -346,22 +351,23 @@ static int
property_handle_net_wm_opacity(uint8_t state, property_handle_net_wm_opacity(uint8_t state,
xcb_window_t window) xcb_window_t window)
{ {
lua_State *L = globalconf_get_lua_State();
drawin_t *drawin = drawin_getbywin(window); drawin_t *drawin = drawin_getbywin(window);
if(drawin) if(drawin)
{ {
luaA_object_push(globalconf.L, drawin); luaA_object_push(L, drawin);
window_set_opacity(globalconf.L, -1, xwindow_get_opacity(drawin->window)); window_set_opacity(L, -1, xwindow_get_opacity(drawin->window));
lua_pop(globalconf.L, -1); lua_pop(L, -1);
} }
else else
{ {
client_t *c = client_getbywin(window); client_t *c = client_getbywin(window);
if(c) if(c)
{ {
luaA_object_push(globalconf.L, c); luaA_object_push(L, c);
window_set_opacity(globalconf.L, -1, xwindow_get_opacity(c->window)); window_set_opacity(L, -1, xwindow_get_opacity(c->window));
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
} }
@ -372,7 +378,8 @@ static int
property_handle_xrootpmap_id(uint8_t state, property_handle_xrootpmap_id(uint8_t state,
xcb_window_t window) xcb_window_t window)
{ {
signal_object_emit(globalconf.L, &global_signals, "wallpaper_changed", 0); lua_State *L = globalconf_get_lua_State();
signal_object_emit(L, &global_signals, "wallpaper_changed", 0);
return 0; return 0;
} }
@ -382,6 +389,7 @@ property_handle_xrootpmap_id(uint8_t state,
static void static void
property_handle_propertynotify_xproperty(xcb_property_notify_event_t *ev) property_handle_propertynotify_xproperty(xcb_property_notify_event_t *ev)
{ {
lua_State *L = globalconf_get_lua_State();
xproperty_t *prop; xproperty_t *prop;
xproperty_t lookup = { .atom = ev->atom }; xproperty_t lookup = { .atom = ev->atom };
buffer_t buf; buffer_t buf;
@ -409,11 +417,11 @@ property_handle_propertynotify_xproperty(xcb_property_notify_event_t *ev)
/* And emit the right signal */ /* And emit the right signal */
if (obj) if (obj)
{ {
luaA_object_push(globalconf.L, obj); luaA_object_push(L, obj);
luaA_object_emit_signal(globalconf.L, -1, buf.s, 0); luaA_object_emit_signal(L, -1, buf.s, 0);
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} else } else
signal_object_emit(globalconf.L, &global_signals, buf.s, 0); signal_object_emit(L, &global_signals, buf.s, 0);
buffer_wipe(&buf); buffer_wipe(&buf);
} }

54
spawn.c
View File

@ -67,16 +67,17 @@ spawn_monitor_timeout(gpointer sequence)
if(sig) if(sig)
{ {
/* send a timeout signal */ /* send a timeout signal */
lua_createtable(globalconf.L, 0, 2); lua_State *L = globalconf_get_lua_State();
lua_pushstring(globalconf.L, sn_startup_sequence_get_id(sequence)); lua_createtable(L, 0, 2);
lua_setfield(globalconf.L, -2, "id"); lua_pushstring(L, sn_startup_sequence_get_id(sequence));
lua_setfield(L, -2, "id");
foreach(func, sig->sigfuncs) foreach(func, sig->sigfuncs)
{ {
lua_pushvalue(globalconf.L, -1); lua_pushvalue(L, -1);
luaA_object_push(globalconf.L, (void *) *func); luaA_object_push(L, (void *) *func);
luaA_dofunction(globalconf.L, 1, 0); luaA_dofunction(L, 1, 0);
} }
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
else else
warn("spawn::timeout signal is missing"); warn("spawn::timeout signal is missing");
@ -88,12 +89,13 @@ spawn_monitor_timeout(gpointer sequence)
static void static void
spawn_monitor_event(SnMonitorEvent *event, void *data) spawn_monitor_event(SnMonitorEvent *event, void *data)
{ {
lua_State *L = globalconf_get_lua_State();
SnStartupSequence *sequence = sn_monitor_event_get_startup_sequence(event); SnStartupSequence *sequence = sn_monitor_event_get_startup_sequence(event);
SnMonitorEventType event_type = sn_monitor_event_get_type(event); SnMonitorEventType event_type = sn_monitor_event_get_type(event);
lua_createtable(globalconf.L, 0, 2); lua_createtable(L, 0, 2);
lua_pushstring(globalconf.L, sn_startup_sequence_get_id(sequence)); lua_pushstring(L, sn_startup_sequence_get_id(sequence));
lua_setfield(globalconf.L, -2, "id"); lua_setfield(L, -2, "id");
const char *event_type_str = NULL; const char *event_type_str = NULL;
@ -131,35 +133,35 @@ spawn_monitor_event(SnMonitorEvent *event, void *data)
const char *s = sn_startup_sequence_get_name(sequence); const char *s = sn_startup_sequence_get_name(sequence);
if(s) if(s)
{ {
lua_pushstring(globalconf.L, s); lua_pushstring(L, s);
lua_setfield(globalconf.L, -2, "name"); lua_setfield(L, -2, "name");
} }
if((s = sn_startup_sequence_get_description(sequence))) if((s = sn_startup_sequence_get_description(sequence)))
{ {
lua_pushstring(globalconf.L, s); lua_pushstring(L, s);
lua_setfield(globalconf.L, -2, "description"); lua_setfield(L, -2, "description");
} }
lua_pushnumber(globalconf.L, sn_startup_sequence_get_workspace(sequence)); lua_pushnumber(L, sn_startup_sequence_get_workspace(sequence));
lua_setfield(globalconf.L, -2, "workspace"); lua_setfield(L, -2, "workspace");
if((s = sn_startup_sequence_get_binary_name(sequence))) if((s = sn_startup_sequence_get_binary_name(sequence)))
{ {
lua_pushstring(globalconf.L, s); lua_pushstring(L, s);
lua_setfield(globalconf.L, -2, "binary_name"); lua_setfield(L, -2, "binary_name");
} }
if((s = sn_startup_sequence_get_icon_name(sequence))) if((s = sn_startup_sequence_get_icon_name(sequence)))
{ {
lua_pushstring(globalconf.L, s); lua_pushstring(L, s);
lua_setfield(globalconf.L, -2, "icon_name"); lua_setfield(L, -2, "icon_name");
} }
if((s = sn_startup_sequence_get_wmclass(sequence))) if((s = sn_startup_sequence_get_wmclass(sequence)))
{ {
lua_pushstring(globalconf.L, s); lua_pushstring(L, s);
lua_setfield(globalconf.L, -2, "wmclass"); lua_setfield(L, -2, "wmclass");
} }
} }
break; break;
@ -177,11 +179,11 @@ spawn_monitor_event(SnMonitorEvent *event, void *data)
{ {
foreach(func, sig->sigfuncs) foreach(func, sig->sigfuncs)
{ {
lua_pushvalue(globalconf.L, -1); lua_pushvalue(L, -1);
luaA_object_push(globalconf.L, (void *) *func); luaA_object_push(L, (void *) *func);
luaA_dofunction(globalconf.L, 1, 0); luaA_dofunction(L, 1, 0);
} }
lua_pop(globalconf.L, 1); lua_pop(L, 1);
} }
else else
warn("%s signal is missing", event_type_str); warn("%s signal is missing", event_type_str);

View File

@ -248,7 +248,8 @@ xembed_process_client_message(xcb_client_message_event_t *ev)
void void
luaA_systray_invalidate(void) luaA_systray_invalidate(void)
{ {
signal_object_emit(globalconf.L, &global_signals, "systray::update", 0); lua_State *L = globalconf_get_lua_State();
signal_object_emit(L, &global_signals, "systray::update", 0);
} }
static void static void