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