mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-22 04:15:39 +02:00
module/i3: try SWAYSOCK before falling back to I3_SOCKET_PATH
This commit is contained in:
parent
ed8e17c6c9
commit
8e769b491a
1 changed files with 65 additions and 46 deletions
47
modules/i3.c
47
modules/i3.c
|
@ -371,19 +371,15 @@ handle_workspace_event(struct private *m, const struct json_object *json)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static bool
|
||||||
run(struct module *mod)
|
get_socket_address_x11(struct sockaddr_un *addr)
|
||||||
{
|
{
|
||||||
struct private *m = mod->private;
|
|
||||||
|
|
||||||
struct sockaddr_un addr = {.sun_family = AF_UNIX};
|
|
||||||
{
|
|
||||||
int default_screen;
|
int default_screen;
|
||||||
xcb_connection_t *conn = xcb_connect(NULL, &default_screen);
|
xcb_connection_t *conn = xcb_connect(NULL, &default_screen);
|
||||||
if (xcb_connection_has_error(conn) > 0) {
|
if (xcb_connection_has_error(conn) > 0) {
|
||||||
LOG_ERR("failed to connect to X");
|
LOG_ERR("failed to connect to X");
|
||||||
xcb_disconnect(conn);
|
xcb_disconnect(conn);
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
xcb_screen_t *screen = xcb_aux_get_screen(conn, default_screen);
|
xcb_screen_t *screen = xcb_aux_get_screen(conn, default_screen);
|
||||||
|
@ -394,7 +390,7 @@ run(struct module *mod)
|
||||||
xcb_get_property_cookie_t cookie
|
xcb_get_property_cookie_t cookie
|
||||||
= xcb_get_property_unchecked(
|
= xcb_get_property_unchecked(
|
||||||
conn, false, screen->root, atom,
|
conn, false, screen->root, atom,
|
||||||
XCB_GET_PROPERTY_TYPE_ANY, 0, sizeof(addr.sun_path));
|
XCB_GET_PROPERTY_TYPE_ANY, 0, sizeof(addr->sun_path));
|
||||||
|
|
||||||
xcb_generic_error_t *err;
|
xcb_generic_error_t *err;
|
||||||
xcb_get_property_reply_t *reply =
|
xcb_get_property_reply_t *reply =
|
||||||
|
@ -404,24 +400,47 @@ run(struct module *mod)
|
||||||
LOG_ERR("failed to get i3 socket path: %s", xcb_error(err));
|
LOG_ERR("failed to get i3 socket path: %s", xcb_error(err));
|
||||||
free(err);
|
free(err);
|
||||||
free(reply);
|
free(reply);
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int len = xcb_get_property_value_length(reply);
|
const int len = xcb_get_property_value_length(reply);
|
||||||
assert(len < sizeof(addr.sun_path));
|
assert(len < sizeof(addr->sun_path));
|
||||||
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
LOG_ERR("failed to get i3 socket path: empty reply");
|
LOG_ERR("failed to get i3 socket path: empty reply");
|
||||||
free(reply);
|
free(reply);
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(addr.sun_path, xcb_get_property_value(reply), len);
|
memcpy(addr->sun_path, xcb_get_property_value(reply), len);
|
||||||
addr.sun_path[len] = '\0';
|
addr->sun_path[len] = '\0';
|
||||||
|
|
||||||
free(reply);
|
free(reply);
|
||||||
xcb_disconnect(conn);
|
xcb_disconnect(conn);
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
get_socket_address(struct sockaddr_un *addr)
|
||||||
|
{
|
||||||
|
*addr = (struct sockaddr_un){.sun_family = AF_UNIX};
|
||||||
|
|
||||||
|
const char *sway_sock = getenv("SWAYSOCK");
|
||||||
|
if (sway_sock == NULL)
|
||||||
|
return get_socket_address_x11(addr);
|
||||||
|
|
||||||
|
strncpy(addr->sun_path, sway_sock, sizeof(addr->sun_path));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
run(struct module *mod)
|
||||||
|
{
|
||||||
|
struct private *m = mod->private;
|
||||||
|
|
||||||
|
struct sockaddr_un addr;
|
||||||
|
if (!get_socket_address(&addr))
|
||||||
|
return 1;
|
||||||
|
|
||||||
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (sock == -1) {
|
if (sock == -1) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue