socket, lua: use xcb_parse_display
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
608b2e2647
commit
dcbd7a7c14
|
@ -18,6 +18,7 @@ include_directories(
|
||||||
${SOURCE_DIR}
|
${SOURCE_DIR}
|
||||||
${BUILD_DIR}
|
${BUILD_DIR}
|
||||||
${BUILD_DIR}/common
|
${BUILD_DIR}/common
|
||||||
|
${AWESOME_COMMON_REQUIRED_INCLUDE_DIRS}
|
||||||
${AWESOME_REQUIRED_INCLUDE_DIRS}
|
${AWESOME_REQUIRED_INCLUDE_DIRS}
|
||||||
${AWESOME_OPTIONAL_INCLUDE_DIRS})
|
${AWESOME_OPTIONAL_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
@ -107,10 +108,12 @@ set_target_properties(${PROJECT_AWE_NAME}
|
||||||
LINK_FLAGS -export-dynamic)
|
LINK_FLAGS -export-dynamic)
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_AWE_NAME}
|
target_link_libraries(${PROJECT_AWE_NAME}
|
||||||
|
${AWESOME_COMMON_REQUIRED_LIBRARIES}
|
||||||
${AWESOME_REQUIRED_LIBRARIES}
|
${AWESOME_REQUIRED_LIBRARIES}
|
||||||
${AWESOME_OPTIONAL_LIBRARIES})
|
${AWESOME_OPTIONAL_LIBRARIES})
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_AWECLIENT_NAME}
|
target_link_libraries(${PROJECT_AWECLIENT_NAME}
|
||||||
|
${AWESOME_COMMON_REQUIRED_LIBRARIES}
|
||||||
${AWESOMECLIENT_LIBRARIES})
|
${AWESOMECLIENT_LIBRARIES})
|
||||||
|
|
||||||
# {{{ Generated sources
|
# {{{ Generated sources
|
||||||
|
|
|
@ -134,12 +134,14 @@ execute_process(
|
||||||
# AWESOMECLIENT_LIBRARIES
|
# AWESOMECLIENT_LIBRARIES
|
||||||
|
|
||||||
# Use pkgconfig to get most of the libraries
|
# Use pkgconfig to get most of the libraries
|
||||||
|
pkg_check_modules(AWESOME_COMMON_REQUIRED REQUIRED
|
||||||
|
xcb)
|
||||||
|
|
||||||
pkg_check_modules(AWESOME_REQUIRED REQUIRED
|
pkg_check_modules(AWESOME_REQUIRED REQUIRED
|
||||||
glib-2.0
|
glib-2.0
|
||||||
cairo
|
cairo
|
||||||
pango
|
pango
|
||||||
pangocairo
|
pangocairo
|
||||||
xcb
|
|
||||||
xcb-event
|
xcb-event
|
||||||
xcb-randr
|
xcb-randr
|
||||||
xcb-xinerama
|
xcb-xinerama
|
||||||
|
@ -149,7 +151,7 @@ pkg_check_modules(AWESOME_REQUIRED REQUIRED
|
||||||
xcb-icccm
|
xcb-icccm
|
||||||
cairo-xcb)
|
cairo-xcb)
|
||||||
|
|
||||||
if(NOT AWESOME_REQUIRED_FOUND)
|
if(NOT AWESOME_REQUIRED_FOUND OR NOT AWESOME_COMMON_REQUIRED_FOUND)
|
||||||
message(FATAL_ERROR)
|
message(FATAL_ERROR)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -170,16 +172,25 @@ if(NOT LUA_FOUND)
|
||||||
message(FATAL_ERROR "lua library not found")
|
message(FATAL_ERROR "lua library not found")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(AWESOME_REQUIRED_LIBRARIES ${AWESOME_REQUIRED_LIBRARIES}
|
set(AWESOME_REQUIRED_LIBRARIES
|
||||||
|
${AWESOME_COMMON_REQUIRED_LIBRARIES}
|
||||||
|
${AWESOME_REQUIRED_LIBRARIES}
|
||||||
${LIB_EV}
|
${LIB_EV}
|
||||||
${LUA_LIBRARIES})
|
${LUA_LIBRARIES})
|
||||||
|
|
||||||
set(AWESOME_REQUIRED_INCLUDE_DIRS ${AWESOME_REQUIRED_INCLUDE_DIRS}
|
set(AWESOME_REQUIRED_INCLUDE_DIRS
|
||||||
|
${AWESOME_COMMON_REQUIRED_INCLUDE_DIRS}
|
||||||
|
${AWESOME_REQUIRED_INCLUDE_DIRS}
|
||||||
${LUA_INCLUDE_DIR})
|
${LUA_INCLUDE_DIR})
|
||||||
|
|
||||||
set(AWESOMECLIENT_LIBRARIES
|
set(AWESOMECLIENT_LIBRARIES
|
||||||
|
${AWESOME_COMMON_REQUIRED_LIBRARIES}
|
||||||
${LIB_READLINE}
|
${LIB_READLINE}
|
||||||
|
${LIB_XCB}
|
||||||
${CURSES_LIBRARIES})
|
${CURSES_LIBRARIES})
|
||||||
|
|
||||||
|
set(AWESOMECLIENT_REQUIRED_INCLUDE_DIRS
|
||||||
|
${AWESOME_COMMON_REQUIRED_INCLUDE_DIRS})
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# {{{ Optional libraries
|
# {{{ Optional libraries
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
|
|
||||||
|
#include <xcb/xcb.h>
|
||||||
|
|
||||||
#include "common/socket.h"
|
#include "common/socket.h"
|
||||||
#include "common/util.h"
|
#include "common/util.h"
|
||||||
|
|
||||||
|
@ -38,77 +40,27 @@
|
||||||
struct sockaddr_un *
|
struct sockaddr_un *
|
||||||
socket_getaddr(const char *display)
|
socket_getaddr(const char *display)
|
||||||
{
|
{
|
||||||
char *homedir, *tmp, *dot;
|
char *homedir, *host = NULL;
|
||||||
char *hostname = NULL, *screen = NULL;
|
int screenp, displayp;
|
||||||
ssize_t path_len, hostname_len, screen_len;
|
ssize_t path_len;
|
||||||
struct sockaddr_un *addr;
|
struct sockaddr_un *addr;
|
||||||
|
|
||||||
addr = p_new(struct sockaddr_un, 1);
|
addr = p_new(struct sockaddr_un, 1);
|
||||||
homedir = getenv("HOME");
|
homedir = getenv("HOME");
|
||||||
|
|
||||||
if(a_strlen(display))
|
xcb_parse_display(NULL, &host, &displayp, &screenp);
|
||||||
{
|
|
||||||
/* find hostname */
|
|
||||||
if((tmp = strchr(display, ':')))
|
|
||||||
{
|
|
||||||
/* if display starts with : */
|
|
||||||
if(tmp == display)
|
|
||||||
{
|
|
||||||
hostname = a_strdup("localhost");
|
|
||||||
hostname_len = 9;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hostname_len = tmp - display;
|
|
||||||
hostname = a_strndup(display, hostname_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp++;
|
|
||||||
if((dot = strchr(tmp, '.')))
|
|
||||||
{
|
|
||||||
screen_len = dot - tmp;
|
|
||||||
screen = a_strndup(tmp, screen_len);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
screen = a_strdup(tmp);
|
|
||||||
screen_len = a_strlen(screen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hostname = a_strdup("unknown");
|
|
||||||
hostname_len = 7;
|
|
||||||
screen = a_strdup("0");
|
|
||||||
screen_len = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hostname = a_strdup("localhost");
|
|
||||||
hostname_len = 9;
|
|
||||||
screen = a_strdup("0");
|
|
||||||
screen_len = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* + 2 for / and . and \0 */
|
/* + 2 for / and . and \0 */
|
||||||
path_len = a_strlen(homedir) + sizeof(CONTROL_UNIX_SOCKET_PATH) - 1
|
path_len = snprintf(addr->sun_path, sizeof(addr->sun_path),
|
||||||
+ screen_len + hostname_len + 3;
|
"%s/" CONTROL_UNIX_SOCKET_PATH "%s%s%d",
|
||||||
|
homedir, host, a_strlen(host) ? "." : "",
|
||||||
|
displayp);
|
||||||
|
|
||||||
if(path_len >= ssizeof(addr->sun_path))
|
if(path_len >= ssizeof(addr->sun_path))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "error: path of control UNIX domain socket is too long");
|
fprintf(stderr, "error: path of control UNIX domain socket is too long");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
a_strcpy(addr->sun_path, path_len, homedir);
|
|
||||||
a_strcat(addr->sun_path, path_len, "/");
|
|
||||||
a_strcat(addr->sun_path, path_len, CONTROL_UNIX_SOCKET_PATH);
|
|
||||||
a_strcat(addr->sun_path, path_len, hostname);
|
|
||||||
a_strcat(addr->sun_path, path_len, "|");
|
|
||||||
a_strcat(addr->sun_path, path_len, screen);
|
|
||||||
|
|
||||||
p_delete(&hostname);
|
|
||||||
p_delete(&screen);
|
|
||||||
|
|
||||||
addr->sun_family = AF_UNIX;
|
addr->sun_family = AF_UNIX;
|
||||||
|
|
||||||
|
|
14
lua.c
14
lua.c
|
@ -483,9 +483,9 @@ static int
|
||||||
luaA_spawn(lua_State *L)
|
luaA_spawn(lua_State *L)
|
||||||
{
|
{
|
||||||
static const char *shell = NULL;
|
static const char *shell = NULL;
|
||||||
char display[128], *tmp, newdisplay[128];
|
char *host, newdisplay[128];
|
||||||
const char *cmd;
|
const char *cmd;
|
||||||
int screen = 0;
|
int screen = 0, screenp, displayp;
|
||||||
|
|
||||||
if(!shell && !(shell = getenv("SHELL")))
|
if(!shell && !(shell = getenv("SHELL")))
|
||||||
shell = "/bin/sh";
|
shell = "/bin/sh";
|
||||||
|
@ -498,14 +498,12 @@ luaA_spawn(lua_State *L)
|
||||||
|
|
||||||
cmd = luaL_checkstring(L, 1);
|
cmd = luaL_checkstring(L, 1);
|
||||||
|
|
||||||
if(!globalconf.screens_info->xinerama_is_active
|
if(!globalconf.screens_info->xinerama_is_active)
|
||||||
&& (tmp = getenv("DISPLAY")))
|
|
||||||
{
|
{
|
||||||
a_strcpy(display, sizeof(display) - 1, tmp);
|
xcb_parse_display(NULL, &host, &displayp, &screenp);
|
||||||
if((tmp = strrchr(display, '.')))
|
snprintf(newdisplay, sizeof(newdisplay), "%s:%d.%d", host, displayp, screen);
|
||||||
*tmp = '\0';
|
|
||||||
snprintf(newdisplay, sizeof(newdisplay) - 1, "%s.%d", display, screen);
|
|
||||||
setenv("DISPLAY", newdisplay, 1);
|
setenv("DISPLAY", newdisplay, 1);
|
||||||
|
p_delete(&host);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The double-fork construct avoids zombie processes and keeps the code
|
/* The double-fork construct avoids zombie processes and keeps the code
|
||||||
|
|
Loading…
Reference in New Issue