make i3-msg and i3-input use the new default path

This commit is contained in:
Michael Stapelberg 2010-03-27 14:50:12 +01:00
parent 34f79416d5
commit dc9bc89172
2 changed files with 37 additions and 5 deletions

View File

@ -3,7 +3,7 @@
* *
* i3 - an improved dynamic tiling window manager * i3 - an improved dynamic tiling window manager
* *
* © 2009 Michael Stapelberg and contributors * © 2009-2010 Michael Stapelberg and contributors
* *
* See file LICENSE for license information. * See file LICENSE for license information.
* *
@ -22,6 +22,7 @@
#include <err.h> #include <err.h>
#include <stdint.h> #include <stdint.h>
#include <getopt.h> #include <getopt.h>
#include <glob.h>
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include <xcb/xcb_aux.h> #include <xcb/xcb_aux.h>
@ -51,6 +52,21 @@ static char *prompt;
static int prompt_len; static int prompt_len;
static int limit; static int limit;
/*
* This function resolves ~ in pathnames (and more, see glob(3)).
*
*/
static char *glob_path(const char *path) {
static glob_t globbuf;
if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
errx(EXIT_FAILURE, "glob() failed");
char *result = strdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path);
if (result == NULL)
err(EXIT_FAILURE, "malloc() failed");
globfree(&globbuf);
return result;
}
/* /*
* Concats the glyphs (either UCS-2 or UTF-8) to a single string, suitable for * Concats the glyphs (either UCS-2 or UTF-8) to a single string, suitable for
* rendering it (UCS-2) or sending it to i3 (UTF-8). * rendering it (UCS-2) or sending it to i3 (UTF-8).
@ -241,7 +257,7 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
char *socket_path = "/tmp/i3-ipc.sock"; char *socket_path = glob_path("~/.i3/ipc.sock");
char *pattern = "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"; char *pattern = "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
int o, option_index = 0; int o, option_index = 0;
@ -260,7 +276,7 @@ int main(int argc, char *argv[]) {
while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) { while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) {
switch (o) { switch (o) {
case 's': case 's':
socket_path = strdup(optarg); socket_path = glob_path(optarg);
break; break;
case 'v': case 'v':
printf("i3-input " I3_VERSION); printf("i3-input " I3_VERSION);

View File

@ -27,9 +27,25 @@
#include <err.h> #include <err.h>
#include <stdint.h> #include <stdint.h>
#include <getopt.h> #include <getopt.h>
#include <glob.h>
#include <i3/ipc.h> #include <i3/ipc.h>
/*
* This function resolves ~ in pathnames (and more, see glob(3)).
*
*/
static char *glob_path(const char *path) {
static glob_t globbuf;
if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
errx(EXIT_FAILURE, "glob() failed");
char *result = strdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path);
if (result == NULL)
err(EXIT_FAILURE, "malloc() failed");
globfree(&globbuf);
return result;
}
/* /*
* Formats a message (payload) of the given size and type and sends it to i3 via * Formats a message (payload) of the given size and type and sends it to i3 via
* the given socket file descriptor. * the given socket file descriptor.
@ -107,7 +123,7 @@ static void ipc_recv_message(int sockfd, uint32_t message_type,
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
char *socket_path = "/tmp/i3-ipc.sock"; char *socket_path = glob_path("~/.i3/ipc.sock");
int o, option_index = 0; int o, option_index = 0;
int message_type = I3_IPC_MESSAGE_TYPE_COMMAND; int message_type = I3_IPC_MESSAGE_TYPE_COMMAND;
char *payload = ""; char *payload = "";
@ -126,7 +142,7 @@ int main(int argc, char *argv[]) {
while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) { while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) {
if (o == 's') { if (o == 's') {
socket_path = strdup(optarg); socket_path = glob_path(optarg);
} else if (o == 't') { } else if (o == 't') {
if (strcasecmp(optarg, "command") == 0) if (strcasecmp(optarg, "command") == 0)
message_type = I3_IPC_MESSAGE_TYPE_COMMAND; message_type = I3_IPC_MESSAGE_TYPE_COMMAND;