2 * spawn.c - Lua configuration management
4 * Copyright © 2009 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <sys/types.h>
32 * This function is multi-head (Zaphod) aware and will set display to
33 * the right screen according to mouse position.
34 * \param L The Lua VM state.
35 * \return The number of elements pushed on stack
37 * \lparam The command to launch.
38 * \lparam The optional screen number to spawn the command on.
41 luaA_spawn(lua_State
*L
)
43 char *host
, newdisplay
[128];
45 int screen
= 0, screenp
, displayp
;
47 if(lua_gettop(L
) == 2)
49 screen
= luaL_checknumber(L
, 2) - 1;
50 luaA_checkscreen(screen
);
53 cmd
= luaL_checkstring(L
, 1);
55 if(!globalconf
.xinerama_is_active
)
57 xcb_parse_display(NULL
, &host
, &displayp
, &screenp
);
58 snprintf(newdisplay
, sizeof(newdisplay
), "%s:%d.%d", host
, displayp
, screen
);
59 setenv("DISPLAY", newdisplay
, 1);
63 /* The double-fork construct avoids zombie processes and keeps the code
64 * clean from stupid signal handlers. */
69 if(globalconf
.connection
)
70 xcb_disconnect(globalconf
.connection
);
73 warn("execl '%s' failed: %s\n", cmd
, strerror(errno
));
82 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80