Use correct default-path for ipc-socket
This commit is contained in:
parent
fae997038d
commit
36445f500f
|
@ -6,10 +6,26 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ev.h>
|
#include <ev.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <glob.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
char *i3_default_sock_path = "/home/mero/.i3/ipc.sock";
|
char *i3_default_sock_path = "~/.i3/ipc.sock";
|
||||||
|
|
||||||
|
char *expand_path(char *path) {
|
||||||
|
static glob_t globbuf;
|
||||||
|
if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0) {
|
||||||
|
printf("glob() failed");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
char *result = strdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path);
|
||||||
|
if (result == NULL) {
|
||||||
|
printf("malloc() failed");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
globfree(&globbuf);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
int opt;
|
int opt;
|
||||||
|
@ -29,16 +45,13 @@ int main(int argc, char **argv) {
|
||||||
while ((opt = getopt_long(argc, argv, "s:c:f:h", long_opt, &option_index)) != -1) {
|
while ((opt = getopt_long(argc, argv, "s:c:f:h", long_opt, &option_index)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 's':
|
case 's':
|
||||||
socket_path = malloc(strlen(optarg));
|
socket_path = expand_path(optarg);
|
||||||
strcpy(socket_path, optarg);
|
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
command = malloc(strlen(optarg));
|
command = strdup(optarg);
|
||||||
strcpy(command, optarg);
|
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
fontname = malloc(strlen(optarg));
|
fontname = strdup(optarg);
|
||||||
strcpy(socket_path, optarg);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("Usage: %s [-s socket_path] [-c command] [-f font] [-h]\n", argv[0]);
|
printf("Usage: %s [-s socket_path] [-c command] [-f font] [-h]\n", argv[0]);
|
||||||
|
@ -57,7 +70,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
if (socket_path == NULL) {
|
if (socket_path == NULL) {
|
||||||
printf("No Socket Path Specified, default to %s\n", i3_default_sock_path);
|
printf("No Socket Path Specified, default to %s\n", i3_default_sock_path);
|
||||||
socket_path = i3_default_sock_path;
|
socket_path = expand_path(i3_default_sock_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
main_loop = ev_default_loop(0);
|
main_loop = ev_default_loop(0);
|
||||||
|
@ -66,6 +79,8 @@ int main(int argc, char **argv) {
|
||||||
init_outputs();
|
init_outputs();
|
||||||
init_connection(socket_path);
|
init_connection(socket_path);
|
||||||
|
|
||||||
|
FREE(socket_path);
|
||||||
|
|
||||||
subscribe_events();
|
subscribe_events();
|
||||||
|
|
||||||
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL);
|
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL);
|
||||||
|
|
Loading…
Reference in New Issue