introduce sasprintf() in libi3, use it everywhere
This commit is contained in:
parent
14abafb3c8
commit
9d15a00ba8
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
#include "libi3.h"
|
||||||
|
|
||||||
extern Display *dpy;
|
extern Display *dpy;
|
||||||
|
|
||||||
struct context {
|
struct context {
|
||||||
|
@ -141,7 +143,7 @@ bindcode:
|
||||||
char *str = XKeysymToString(sym);
|
char *str = XKeysymToString(sym);
|
||||||
char *modifiers = modifier_to_string($<number>3);
|
char *modifiers = modifier_to_string($<number>3);
|
||||||
// TODO: modifier to string
|
// TODO: modifier to string
|
||||||
asprintf(&(context->result), "bindsym %s%s %s\n", modifiers, str, $<string>6);
|
sasprintf(&(context->result), "bindsym %s%s %s\n", modifiers, str, $<string>6);
|
||||||
free(modifiers);
|
free(modifiers);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
|
@ -306,7 +306,7 @@ int main(int argc, char *argv[]) {
|
||||||
/* This option is deprecated, but will still work in i3 v4.1, 4.2 and 4.3 */
|
/* This option is deprecated, but will still work in i3 v4.1, 4.2 and 4.3 */
|
||||||
fprintf(stderr, "i3-input: WARNING: the -p option is DEPRECATED in favor of the -F (format) option\n");
|
fprintf(stderr, "i3-input: WARNING: the -p option is DEPRECATED in favor of the -F (format) option\n");
|
||||||
FREE(format);
|
FREE(format);
|
||||||
asprintf(&format, "%s%%s", optarg);
|
sasprintf(&format, "%s%%s", optarg);
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
limit = atoi(optarg);
|
limit = atoi(optarg);
|
||||||
|
|
|
@ -14,7 +14,7 @@ i3bar: $(TOPDIR)/libi3/libi3.a ${FILES}
|
||||||
echo "[i3bar] LINK"
|
echo "[i3bar] LINK"
|
||||||
$(CC) $(LDFLAGS) -o $@ $(filter-out libi3/libi3.a,$^) $(LIBS)
|
$(CC) $(LDFLAGS) -o $@ $(filter-out libi3/libi3.a,$^) $(LIBS)
|
||||||
|
|
||||||
$(TOPDIR)/libi3/%.a:
|
$(TOPDIR)/libi3/%.a: $(TOPDIR)/libi3/*.c
|
||||||
$(MAKE) -C $(TOPDIR)/libi3
|
$(MAKE) -C $(TOPDIR)/libi3
|
||||||
|
|
||||||
doc:
|
doc:
|
||||||
|
|
|
@ -89,13 +89,13 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in
|
||||||
* Therefore we save the command in 'config' and access it later in
|
* Therefore we save the command in 'config' and access it later in
|
||||||
* got_bar_config() */
|
* got_bar_config() */
|
||||||
DLOG("command = %.*s\n", len, val);
|
DLOG("command = %.*s\n", len, val);
|
||||||
asprintf(&config.command, "%.*s", len, val);
|
sasprintf(&config.command, "%.*s", len, val);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(cur_key, "font")) {
|
if (!strcmp(cur_key, "font")) {
|
||||||
DLOG("font = %.*s\n", len, val);
|
DLOG("font = %.*s\n", len, val);
|
||||||
asprintf(&config.fontname, "%.*s", len, val);
|
sasprintf(&config.fontname, "%.*s", len, val);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in
|
||||||
DLOG("+output %.*s\n", len, val);
|
DLOG("+output %.*s\n", len, val);
|
||||||
int new_num_outputs = config.num_outputs + 1;
|
int new_num_outputs = config.num_outputs + 1;
|
||||||
config.outputs = srealloc(config.outputs, sizeof(char*) * new_num_outputs);
|
config.outputs = srealloc(config.outputs, sizeof(char*) * new_num_outputs);
|
||||||
asprintf(&config.outputs[config.num_outputs], "%.*s", len, val);
|
sasprintf(&config.outputs[config.num_outputs], "%.*s", len, val);
|
||||||
config.num_outputs = new_num_outputs;
|
config.num_outputs = new_num_outputs;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in
|
||||||
if (!strcmp(cur_key, "tray_output")) {
|
if (!strcmp(cur_key, "tray_output")) {
|
||||||
DLOG("tray_output %.*s\n", len, val);
|
DLOG("tray_output %.*s\n", len, val);
|
||||||
FREE(config.tray_output);
|
FREE(config.tray_output);
|
||||||
asprintf(&config.tray_output, "%.*s", len, val);
|
sasprintf(&config.tray_output, "%.*s", len, val);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in
|
||||||
do { \
|
do { \
|
||||||
if (!strcmp(cur_key, #json_name)) { \
|
if (!strcmp(cur_key, #json_name)) { \
|
||||||
DLOG(#json_name " = " #struct_name " = %.*s\n", len, val); \
|
DLOG(#json_name " = " #struct_name " = %.*s\n", len, val); \
|
||||||
asprintf(&(config.colors.struct_name), "%.*s", len, val); \
|
sasprintf(&(config.colors.struct_name), "%.*s", len, val); \
|
||||||
return 1; \
|
return 1; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#ifndef _LIBI3_H
|
#ifndef _LIBI3_H
|
||||||
#define _LIBI3_H
|
#define _LIBI3_H
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
#include <xcb/xproto.h>
|
#include <xcb/xproto.h>
|
||||||
|
|
||||||
|
@ -45,6 +46,13 @@ void *srealloc(void *ptr, size_t size);
|
||||||
*/
|
*/
|
||||||
char *sstrdup(const char *str);
|
char *sstrdup(const char *str);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Safe-wrapper around asprintf which exits if it returns -1 (meaning that
|
||||||
|
* there is no more memory available)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int sasprintf(char **strp, const char *fmt, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
*/
|
*/
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,3 +47,14 @@ char *sstrdup(const char *str) {
|
||||||
err(EXIT_FAILURE, "strdup()");
|
err(EXIT_FAILURE, "strdup()");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sasprintf(char **strp, const char *fmt, ...) {
|
||||||
|
va_list args;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
va_start(args, fmt);
|
||||||
|
if ((result = vasprintf(strp, fmt, args)) == -1)
|
||||||
|
err(EXIT_FAILURE, "asprintf(%s)", fmt);
|
||||||
|
va_end(args);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ void run_assignments(i3Window *window) {
|
||||||
if (current->type == A_COMMAND) {
|
if (current->type == A_COMMAND) {
|
||||||
DLOG("execute command %s\n", current->dest.command);
|
DLOG("execute command %s\n", current->dest.command);
|
||||||
char *full_command;
|
char *full_command;
|
||||||
asprintf(&full_command, "[id=\"%d\"] %s", window->id, current->dest.command);
|
sasprintf(&full_command, "[id=\"%d\"] %s", window->id, current->dest.command);
|
||||||
char *json_result = parse_cmd(full_command);
|
char *json_result = parse_cmd(full_command);
|
||||||
FREE(full_command);
|
FREE(full_command);
|
||||||
FREE(json_result);
|
FREE(json_result);
|
||||||
|
|
|
@ -280,10 +280,8 @@ static void start_configerror_nagbar(const char *config_path) {
|
||||||
if (configerror_pid == 0) {
|
if (configerror_pid == 0) {
|
||||||
char *editaction,
|
char *editaction,
|
||||||
*pageraction;
|
*pageraction;
|
||||||
if (asprintf(&editaction, "i3-sensible-terminal -e sh -c \"i3-sensible-editor \\\"%s\\\" && i3-msg reload\"", config_path) == -1)
|
sasprintf(&editaction, "i3-sensible-terminal -e sh -c \"i3-sensible-editor \\\"%s\\\" && i3-msg reload\"", config_path);
|
||||||
exit(1);
|
sasprintf(&pageraction, "i3-sensible-terminal -e i3-sensible-pager \"%s\"", errorfilename);
|
||||||
if (asprintf(&pageraction, "i3-sensible-terminal -e i3-sensible-pager \"%s\"", errorfilename) == -1)
|
|
||||||
exit(1);
|
|
||||||
char *argv[] = {
|
char *argv[] = {
|
||||||
NULL, /* will be replaced by the executable path */
|
NULL, /* will be replaced by the executable path */
|
||||||
"-t",
|
"-t",
|
||||||
|
@ -938,7 +936,7 @@ word_or_number:
|
||||||
WORD
|
WORD
|
||||||
| NUMBER
|
| NUMBER
|
||||||
{
|
{
|
||||||
asprintf(&$$, "%d", $1);
|
sasprintf(&$$, "%d", $1);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -1345,7 +1343,7 @@ workspace:
|
||||||
} else {
|
} else {
|
||||||
char *ws_name = NULL;
|
char *ws_name = NULL;
|
||||||
if ($5 == NULL) {
|
if ($5 == NULL) {
|
||||||
asprintf(&ws_name, "%d", ws_num);
|
sasprintf(&ws_name, "%d", ws_num);
|
||||||
} else {
|
} else {
|
||||||
ws_name = $5;
|
ws_name = $5;
|
||||||
}
|
}
|
||||||
|
@ -1422,20 +1420,14 @@ assign:
|
||||||
if ((separator = strchr(criteria, '/')) != NULL) {
|
if ((separator = strchr(criteria, '/')) != NULL) {
|
||||||
*(separator++) = '\0';
|
*(separator++) = '\0';
|
||||||
char *pattern;
|
char *pattern;
|
||||||
if (asprintf(&pattern, "(?i)%s", separator) == -1) {
|
sasprintf(&pattern, "(?i)%s", separator);
|
||||||
ELOG("asprintf failed\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
match->title = regex_new(pattern);
|
match->title = regex_new(pattern);
|
||||||
free(pattern);
|
free(pattern);
|
||||||
printf(" title = %s\n", separator);
|
printf(" title = %s\n", separator);
|
||||||
}
|
}
|
||||||
if (*criteria != '\0') {
|
if (*criteria != '\0') {
|
||||||
char *pattern;
|
char *pattern;
|
||||||
if (asprintf(&pattern, "(?i)%s", criteria) == -1) {
|
sasprintf(&pattern, "(?i)%s", criteria);
|
||||||
ELOG("asprintf failed\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
match->class = regex_new(pattern);
|
match->class = regex_new(pattern);
|
||||||
free(pattern);
|
free(pattern);
|
||||||
printf(" class = %s\n", criteria);
|
printf(" class = %s\n", criteria);
|
||||||
|
|
|
@ -90,8 +90,8 @@ char *parse_cmd(const char *new) {
|
||||||
context->filename = "cmd";
|
context->filename = "cmd";
|
||||||
if (cmdyyparse() != 0) {
|
if (cmdyyparse() != 0) {
|
||||||
fprintf(stderr, "Could not parse command\n");
|
fprintf(stderr, "Could not parse command\n");
|
||||||
asprintf(&json_output, "{\"success\":false, \"error\":\"%s at position %d\"}",
|
sasprintf(&json_output, "{\"success\":false, \"error\":\"%s at position %d\"}",
|
||||||
context->compact_error, context->first_column);
|
context->compact_error, context->first_column);
|
||||||
FREE(context->line_copy);
|
FREE(context->line_copy);
|
||||||
FREE(context->compact_error);
|
FREE(context->compact_error);
|
||||||
free(context);
|
free(context);
|
||||||
|
@ -433,8 +433,8 @@ focus:
|
||||||
ELOG("You have to specify which window/container should be focused.\n");
|
ELOG("You have to specify which window/container should be focused.\n");
|
||||||
ELOG("Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
|
ELOG("Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
|
||||||
|
|
||||||
asprintf(&json_output, "{\"success\":false, \"error\":\"You have to "
|
sasprintf(&json_output, "{\"success\":false, \"error\":\"You have to "
|
||||||
"specify which window/container should be focused\"}");
|
"specify which window/container should be focused\"}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,7 +623,7 @@ open:
|
||||||
printf("opening new container\n");
|
printf("opening new container\n");
|
||||||
Con *con = tree_open_con(NULL, NULL);
|
Con *con = tree_open_con(NULL, NULL);
|
||||||
con_focus(con);
|
con_focus(con);
|
||||||
asprintf(&json_output, "{\"success\":true, \"id\":%ld}", (long int)con);
|
sasprintf(&json_output, "{\"success\":true, \"id\":%ld}", (long int)con);
|
||||||
|
|
||||||
tree_render();
|
tree_render();
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,8 +196,7 @@ static char *get_config_path(const char *override_configpath) {
|
||||||
xdg_config_home = "~/.config";
|
xdg_config_home = "~/.config";
|
||||||
|
|
||||||
xdg_config_home = resolve_tilde(xdg_config_home);
|
xdg_config_home = resolve_tilde(xdg_config_home);
|
||||||
if (asprintf(&config_path, "%s/i3/config", xdg_config_home) == -1)
|
sasprintf(&config_path, "%s/i3/config", xdg_config_home);
|
||||||
die("asprintf() failed");
|
|
||||||
free(xdg_config_home);
|
free(xdg_config_home);
|
||||||
|
|
||||||
if (path_exists(config_path))
|
if (path_exists(config_path))
|
||||||
|
@ -217,8 +216,7 @@ static char *get_config_path(const char *override_configpath) {
|
||||||
char *tok = strtok(buf, ":");
|
char *tok = strtok(buf, ":");
|
||||||
while (tok != NULL) {
|
while (tok != NULL) {
|
||||||
tok = resolve_tilde(tok);
|
tok = resolve_tilde(tok);
|
||||||
if (asprintf(&config_path, "%s/i3/config", tok) == -1)
|
sasprintf(&config_path, "%s/i3/config", tok);
|
||||||
die("asprintf() failed");
|
|
||||||
free(tok);
|
free(tok);
|
||||||
if (path_exists(config_path)) {
|
if (path_exists(config_path)) {
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
|
@ -90,7 +90,7 @@ void floating_enable(Con *con, bool automatic) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
asprintf(&name, "[i3 con] floatingcon around %p", con);
|
sasprintf(&name, "[i3 con] floatingcon around %p", con);
|
||||||
x_set_name(nc, name);
|
x_set_name(nc, name);
|
||||||
free(name);
|
free(name);
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ static int json_string(void *ctx, const unsigned char *val, unsigned int len) {
|
||||||
LOG("sticky_group of this container is %s\n", json_node->sticky_group);
|
LOG("sticky_group of this container is %s\n", json_node->sticky_group);
|
||||||
} else if (strcasecmp(last_key, "orientation") == 0) {
|
} else if (strcasecmp(last_key, "orientation") == 0) {
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
asprintf(&buf, "%.*s", (int)len, val);
|
sasprintf(&buf, "%.*s", (int)len, val);
|
||||||
if (strcasecmp(buf, "none") == 0)
|
if (strcasecmp(buf, "none") == 0)
|
||||||
json_node->orientation = NO_ORIENTATION;
|
json_node->orientation = NO_ORIENTATION;
|
||||||
else if (strcasecmp(buf, "horizontal") == 0)
|
else if (strcasecmp(buf, "horizontal") == 0)
|
||||||
|
@ -128,7 +128,7 @@ static int json_string(void *ctx, const unsigned char *val, unsigned int len) {
|
||||||
free(buf);
|
free(buf);
|
||||||
} else if (strcasecmp(last_key, "border") == 0) {
|
} else if (strcasecmp(last_key, "border") == 0) {
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
asprintf(&buf, "%.*s", (int)len, val);
|
sasprintf(&buf, "%.*s", (int)len, val);
|
||||||
if (strcasecmp(buf, "none") == 0)
|
if (strcasecmp(buf, "none") == 0)
|
||||||
json_node->border_style = BS_NONE;
|
json_node->border_style = BS_NONE;
|
||||||
else if (strcasecmp(buf, "1pixel") == 0)
|
else if (strcasecmp(buf, "1pixel") == 0)
|
||||||
|
@ -139,7 +139,7 @@ static int json_string(void *ctx, const unsigned char *val, unsigned int len) {
|
||||||
free(buf);
|
free(buf);
|
||||||
} else if (strcasecmp(last_key, "layout") == 0) {
|
} else if (strcasecmp(last_key, "layout") == 0) {
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
asprintf(&buf, "%.*s", (int)len, val);
|
sasprintf(&buf, "%.*s", (int)len, val);
|
||||||
if (strcasecmp(buf, "default") == 0)
|
if (strcasecmp(buf, "default") == 0)
|
||||||
json_node->layout = L_DEFAULT;
|
json_node->layout = L_DEFAULT;
|
||||||
else if (strcasecmp(buf, "stacked") == 0)
|
else if (strcasecmp(buf, "stacked") == 0)
|
||||||
|
@ -154,7 +154,7 @@ static int json_string(void *ctx, const unsigned char *val, unsigned int len) {
|
||||||
free(buf);
|
free(buf);
|
||||||
} else if (strcasecmp(last_key, "mark") == 0) {
|
} else if (strcasecmp(last_key, "mark") == 0) {
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
asprintf(&buf, "%.*s", (int)len, val);
|
sasprintf(&buf, "%.*s", (int)len, val);
|
||||||
json_node->mark = buf;
|
json_node->mark = buf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,8 +339,7 @@ int main(int argc, char *argv[]) {
|
||||||
payload = sstrdup(argv[optind]);
|
payload = sstrdup(argv[optind]);
|
||||||
} else {
|
} else {
|
||||||
char *both;
|
char *both;
|
||||||
if (asprintf(&both, "%s %s", payload, argv[optind]) == -1)
|
sasprintf(&both, "%s %s", payload, argv[optind]);
|
||||||
err(EXIT_FAILURE, "asprintf");
|
|
||||||
free(payload);
|
free(payload);
|
||||||
payload = both;
|
payload = both;
|
||||||
}
|
}
|
||||||
|
@ -647,8 +646,8 @@ int main(int argc, char *argv[]) {
|
||||||
Barconfig *barconfig;
|
Barconfig *barconfig;
|
||||||
TAILQ_FOREACH(barconfig, &barconfigs, configs) {
|
TAILQ_FOREACH(barconfig, &barconfigs, configs) {
|
||||||
char *command = NULL;
|
char *command = NULL;
|
||||||
asprintf(&command, "i3bar --bar_id=%s --socket=\"%s\"",
|
sasprintf(&command, "i3bar --bar_id=%s --socket=\"%s\"",
|
||||||
barconfig->id, current_socketpath);
|
barconfig->id, current_socketpath);
|
||||||
LOG("Starting bar process: %s\n", command);
|
LOG("Starting bar process: %s\n", command);
|
||||||
start_application(command);
|
start_application(command);
|
||||||
free(command);
|
free(command);
|
||||||
|
|
|
@ -265,7 +265,7 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
|
||||||
nc->border_width = geom->border_width;
|
nc->border_width = geom->border_width;
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
asprintf(&name, "[i3 con] container around %p", cwindow);
|
sasprintf(&name, "[i3 con] container around %p", cwindow);
|
||||||
x_set_name(nc, name);
|
x_set_name(nc, name);
|
||||||
free(name);
|
free(name);
|
||||||
|
|
||||||
|
|
14
src/randr.c
14
src/randr.c
|
@ -243,7 +243,7 @@ void output_init_con(Output *output) {
|
||||||
output->con = con;
|
output->con = con;
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
asprintf(&name, "[i3 con] output %s", con->name);
|
sasprintf(&name, "[i3 con] output %s", con->name);
|
||||||
x_set_name(con, name);
|
x_set_name(con, name);
|
||||||
FREE(name);
|
FREE(name);
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ void output_init_con(Output *output) {
|
||||||
FREE(topdock->name);
|
FREE(topdock->name);
|
||||||
topdock->name = sstrdup("topdock");
|
topdock->name = sstrdup("topdock");
|
||||||
|
|
||||||
asprintf(&name, "[i3 con] top dockarea %s", con->name);
|
sasprintf(&name, "[i3 con] top dockarea %s", con->name);
|
||||||
x_set_name(topdock, name);
|
x_set_name(topdock, name);
|
||||||
FREE(name);
|
FREE(name);
|
||||||
DLOG("attaching\n");
|
DLOG("attaching\n");
|
||||||
|
@ -281,7 +281,7 @@ void output_init_con(Output *output) {
|
||||||
FREE(content->name);
|
FREE(content->name);
|
||||||
content->name = sstrdup("content");
|
content->name = sstrdup("content");
|
||||||
|
|
||||||
asprintf(&name, "[i3 con] content %s", con->name);
|
sasprintf(&name, "[i3 con] content %s", con->name);
|
||||||
x_set_name(content, name);
|
x_set_name(content, name);
|
||||||
FREE(name);
|
FREE(name);
|
||||||
con_attach(content, con, false);
|
con_attach(content, con, false);
|
||||||
|
@ -301,7 +301,7 @@ void output_init_con(Output *output) {
|
||||||
FREE(bottomdock->name);
|
FREE(bottomdock->name);
|
||||||
bottomdock->name = sstrdup("bottomdock");
|
bottomdock->name = sstrdup("bottomdock");
|
||||||
|
|
||||||
asprintf(&name, "[i3 con] bottom dockarea %s", con->name);
|
sasprintf(&name, "[i3 con] bottom dockarea %s", con->name);
|
||||||
x_set_name(bottomdock, name);
|
x_set_name(bottomdock, name);
|
||||||
FREE(name);
|
FREE(name);
|
||||||
DLOG("attaching\n");
|
DLOG("attaching\n");
|
||||||
|
@ -464,7 +464,7 @@ void init_ws_for_output(Output *output, Con *content) {
|
||||||
c++;
|
c++;
|
||||||
|
|
||||||
FREE(ws->name);
|
FREE(ws->name);
|
||||||
asprintf(&(ws->name), "%d", c);
|
sasprintf(&(ws->name), "%d", c);
|
||||||
|
|
||||||
current = NULL;
|
current = NULL;
|
||||||
TAILQ_FOREACH(out, &(croot->nodes_head), nodes)
|
TAILQ_FOREACH(out, &(croot->nodes_head), nodes)
|
||||||
|
@ -477,7 +477,7 @@ void init_ws_for_output(Output *output, Con *content) {
|
||||||
}
|
}
|
||||||
con_attach(ws, content, false);
|
con_attach(ws, content, false);
|
||||||
|
|
||||||
asprintf(&name, "[i3 con] workspace %s", ws->name);
|
sasprintf(&name, "[i3 con] workspace %s", ws->name);
|
||||||
x_set_name(ws, name);
|
x_set_name(ws, name);
|
||||||
free(name);
|
free(name);
|
||||||
|
|
||||||
|
@ -562,7 +562,7 @@ static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id,
|
||||||
new->id = id;
|
new->id = id;
|
||||||
new->primary = (primary && primary->output == id);
|
new->primary = (primary && primary->output == id);
|
||||||
FREE(new->name);
|
FREE(new->name);
|
||||||
asprintf(&new->name, "%.*s",
|
sasprintf(&new->name, "%.*s",
|
||||||
xcb_randr_get_output_info_name_length(output),
|
xcb_randr_get_output_info_name_length(output),
|
||||||
xcb_randr_get_output_info_name(output));
|
xcb_randr_get_output_info_name(output));
|
||||||
|
|
||||||
|
|
20
src/util.c
20
src/util.c
|
@ -85,7 +85,7 @@ void exec_i3_utility(char *name, char *argv[]) {
|
||||||
* argv[0]’s dirname */
|
* argv[0]’s dirname */
|
||||||
char *pathbuf = strdup(start_argv[0]);
|
char *pathbuf = strdup(start_argv[0]);
|
||||||
char *dir = dirname(pathbuf);
|
char *dir = dirname(pathbuf);
|
||||||
asprintf(&migratepath, "%s/%s", dir, name);
|
sasprintf(&migratepath, "%s/%s", dir, name);
|
||||||
argv[0] = migratepath;
|
argv[0] = migratepath;
|
||||||
execvp(migratepath, argv);
|
execvp(migratepath, argv);
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ void exec_i3_utility(char *name, char *argv[]) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
dir = dirname(buffer);
|
dir = dirname(buffer);
|
||||||
asprintf(&migratepath, "%s/%s", dir, name);
|
sasprintf(&migratepath, "%s/%s", dir, name);
|
||||||
argv[0] = migratepath;
|
argv[0] = migratepath;
|
||||||
execvp(migratepath, argv);
|
execvp(migratepath, argv);
|
||||||
#endif
|
#endif
|
||||||
|
@ -237,16 +237,10 @@ char *get_process_filename(const char *prefix) {
|
||||||
if (dir == NULL) {
|
if (dir == NULL) {
|
||||||
struct passwd *pw = getpwuid(getuid());
|
struct passwd *pw = getpwuid(getuid());
|
||||||
const char *username = pw ? pw->pw_name : "unknown";
|
const char *username = pw ? pw->pw_name : "unknown";
|
||||||
if (asprintf(&dir, "/tmp/i3-%s", username) == -1) {
|
sasprintf(&dir, "/tmp/i3-%s", username);
|
||||||
perror("asprintf()");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
char *tmp;
|
char *tmp;
|
||||||
if (asprintf(&tmp, "%s/i3", dir) == -1) {
|
sasprintf(&tmp, "%s/i3", dir);
|
||||||
perror("asprintf()");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
dir = tmp;
|
dir = tmp;
|
||||||
}
|
}
|
||||||
if (!path_exists(dir)) {
|
if (!path_exists(dir)) {
|
||||||
|
@ -256,11 +250,7 @@ char *get_process_filename(const char *prefix) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
char *filename;
|
char *filename;
|
||||||
if (asprintf(&filename, "%s/%s.%d", dir, prefix, getpid()) == -1) {
|
sasprintf(&filename, "%s/%s.%d", dir, prefix, getpid());
|
||||||
perror("asprintf()");
|
|
||||||
filename = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(dir);
|
free(dir);
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ Con *workspace_get(const char *num, bool *created) {
|
||||||
* will handle CT_WORKSPACEs differently */
|
* will handle CT_WORKSPACEs differently */
|
||||||
workspace = con_new(NULL, NULL);
|
workspace = con_new(NULL, NULL);
|
||||||
char *name;
|
char *name;
|
||||||
asprintf(&name, "[i3 con] workspace %s", num);
|
sasprintf(&name, "[i3 con] workspace %s", num);
|
||||||
x_set_name(workspace, name);
|
x_set_name(workspace, name);
|
||||||
free(name);
|
free(name);
|
||||||
workspace->type = CT_WORKSPACE;
|
workspace->type = CT_WORKSPACE;
|
||||||
|
|
|
@ -56,7 +56,7 @@ static void query_screens(xcb_connection_t *conn) {
|
||||||
s->rect.height = min(s->rect.height, screen_info[screen].height);
|
s->rect.height = min(s->rect.height, screen_info[screen].height);
|
||||||
} else {
|
} else {
|
||||||
s = scalloc(sizeof(Output));
|
s = scalloc(sizeof(Output));
|
||||||
asprintf(&(s->name), "xinerama-%d", num_screens);
|
sasprintf(&(s->name), "xinerama-%d", num_screens);
|
||||||
DLOG("Created new Xinerama screen %s (%p)\n", s->name, s);
|
DLOG("Created new Xinerama screen %s (%p)\n", s->name, s);
|
||||||
s->active = true;
|
s->active = true;
|
||||||
s->rect.x = screen_info[screen].x_org;
|
s->rect.x = screen_info[screen].x_org;
|
||||||
|
|
Loading…
Reference in New Issue