clang-format: enable InsertBraces (#5882)
Enforces a rule that we have followed for years now. Yes, the diff is quite big but we get it over with once and we prevent having to nit-pick future PRs.
This commit is contained in:
parent
5fdfb14530
commit
f169624560
@ -1,13 +1,14 @@
|
||||
BasedOnStyle: google
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
IndentWidth: 4
|
||||
PointerBindsToType: false
|
||||
BasedOnStyle: google
|
||||
ColumnLimit: 0
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SortIncludes: false
|
||||
ForEachMacros: [ TAILQ_FOREACH, TAILQ_FOREACH_REVERSE, SLIST_FOREACH, CIRCLEQ_FOREACH, CIRCLEQ_FOREACH_REVERSE, NODES_FOREACH, NODES_FOREACH_REVERSE, FOREACH_NONINTERNAL]
|
||||
IndentWidth: 4
|
||||
InsertBraces: true
|
||||
PointerBindsToType: false
|
||||
SortIncludes: false
|
||||
SpaceBeforeParens: ControlStatements
|
||||
TypenameMacros: [ SLIST_HEAD, SLIST_ENTRY, LIST_HEAD, LIST_ENTRY, SIMPLEQ_HEAD, SIMPLEQ_ENTRY, TAILQ_HEAD, TAILQ_ENTRY, CIRCLEQ_HEAD, CIRCLEQ_ENTRY ]
|
||||
|
@ -157,8 +157,9 @@ static struct stack_entry stack[10];
|
||||
static void push_string(const char *identifier, const char *str) {
|
||||
for (int c = 0; c < 10; c++) {
|
||||
if (stack[c].identifier != NULL &&
|
||||
strcmp(stack[c].identifier, identifier) != 0)
|
||||
strcmp(stack[c].identifier, identifier) != 0) {
|
||||
continue;
|
||||
}
|
||||
if (stack[c].identifier == NULL) {
|
||||
/* Found a free slot, let’s store it here. */
|
||||
stack[c].identifier = identifier;
|
||||
@ -184,8 +185,9 @@ static void push_string(const char *identifier, const char *str) {
|
||||
|
||||
static void push_long(const char *identifier, long num) {
|
||||
for (int c = 0; c < 10; c++) {
|
||||
if (stack[c].identifier != NULL)
|
||||
if (stack[c].identifier != NULL) {
|
||||
continue;
|
||||
}
|
||||
/* Found a free slot, let’s store it here. */
|
||||
stack[c].identifier = identifier;
|
||||
stack[c].val.num = num;
|
||||
@ -204,18 +206,21 @@ static void push_long(const char *identifier, long num) {
|
||||
|
||||
static const char *get_string(const char *identifier) {
|
||||
for (int c = 0; c < 10; c++) {
|
||||
if (stack[c].identifier == NULL)
|
||||
if (stack[c].identifier == NULL) {
|
||||
break;
|
||||
if (strcmp(identifier, stack[c].identifier) == 0)
|
||||
}
|
||||
if (strcmp(identifier, stack[c].identifier) == 0) {
|
||||
return stack[c].val.str;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void clear_stack(void) {
|
||||
for (int c = 0; c < 10; c++) {
|
||||
if (stack[c].type == STACK_STR)
|
||||
if (stack[c].type == STACK_STR) {
|
||||
free(stack[c].val.str);
|
||||
}
|
||||
stack[c].identifier = NULL;
|
||||
stack[c].val.str = NULL;
|
||||
stack[c].val.num = 0;
|
||||
@ -233,11 +238,13 @@ static bool keysym_used_on_other_key(KeySym sym, xcb_keycode_t except_keycode) {
|
||||
max_keycode = xcb_get_setup(conn)->max_keycode;
|
||||
|
||||
for (i = min_keycode; i && i <= max_keycode; i++) {
|
||||
if (i == except_keycode)
|
||||
if (i == except_keycode) {
|
||||
continue;
|
||||
}
|
||||
for (int level = 0; level < 4; level++) {
|
||||
if (xcb_key_symbols_get_keysym(keysyms, i, level) != sym)
|
||||
if (xcb_key_symbols_get_keysym(keysyms, i, level) != sym) {
|
||||
continue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -269,22 +276,27 @@ static char *next_state(const cmdp_token *token) {
|
||||
* qwerty (yes, that happens quite often). */
|
||||
const xkb_keysym_t *syms;
|
||||
int num = xkb_keymap_key_get_syms_by_level(xkb_keymap, keycode, 0, 0, &syms);
|
||||
if (num == 0)
|
||||
if (num == 0) {
|
||||
errx(1, "xkb_keymap_key_get_syms_by_level returned no symbols for keycode %d", keycode);
|
||||
if (!keysym_used_on_other_key(syms[0], keycode))
|
||||
}
|
||||
if (!keysym_used_on_other_key(syms[0], keycode)) {
|
||||
level = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const xkb_keysym_t *syms;
|
||||
int num = xkb_keymap_key_get_syms_by_level(xkb_keymap, keycode, 0, level, &syms);
|
||||
if (num == 0)
|
||||
if (num == 0) {
|
||||
errx(1, "xkb_keymap_key_get_syms_by_level returned no symbols for keycode %d", keycode);
|
||||
if (num > 1)
|
||||
}
|
||||
if (num > 1) {
|
||||
printf("xkb_keymap_key_get_syms_by_level (keycode = %d) returned %d symbolsinstead of 1, using only the first one.\n", keycode, num);
|
||||
}
|
||||
|
||||
char str[4096];
|
||||
if (xkb_keysym_get_name(syms[0], str, sizeof(str)) == -1)
|
||||
if (xkb_keysym_get_name(syms[0], str, sizeof(str)) == -1) {
|
||||
errx(EXIT_FAILURE, "xkb_keysym_get_name(%u) failed", syms[0]);
|
||||
}
|
||||
const char *release = get_string("release");
|
||||
char *res;
|
||||
char *modrep = (modifiers == NULL ? sstrdup("") : sstrdup(modifiers));
|
||||
@ -303,8 +315,9 @@ static char *next_state(const cmdp_token *token) {
|
||||
/* See if we are jumping back to a state in which we were in previously
|
||||
* (statelist contains INITIAL) and just move statelist_idx accordingly. */
|
||||
for (int i = 0; i < statelist_idx; i++) {
|
||||
if (statelist[i] != _next_state)
|
||||
if (statelist[i] != _next_state) {
|
||||
continue;
|
||||
}
|
||||
statelist_idx = i + 1;
|
||||
return NULL;
|
||||
}
|
||||
@ -329,8 +342,9 @@ static char *rewrite_binding(const char *input) {
|
||||
while ((size_t)(walk - input) <= len) {
|
||||
/* Skip whitespace before every token, newlines are relevant since they
|
||||
* separate configuration directives. */
|
||||
while ((*walk == ' ' || *walk == '\t') && *walk != '\0')
|
||||
while ((*walk == ' ' || *walk == '\t') && *walk != '\0') {
|
||||
walk++;
|
||||
}
|
||||
|
||||
cmdp_token_ptr *ptr = &(tokens[state]);
|
||||
for (c = 0; c < ptr->n; c++) {
|
||||
@ -339,11 +353,13 @@ static char *rewrite_binding(const char *input) {
|
||||
/* A literal. */
|
||||
if (token->name[0] == '\'') {
|
||||
if (strncasecmp(walk, token->name + 1, strlen(token->name) - 1) == 0) {
|
||||
if (token->identifier != NULL)
|
||||
if (token->identifier != NULL) {
|
||||
push_string(token->identifier, token->name + 1);
|
||||
}
|
||||
walk += strlen(token->name) - 1;
|
||||
if ((result = next_state(token)) != NULL)
|
||||
if ((result = next_state(token)) != NULL) {
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
@ -355,20 +371,24 @@ static char *rewrite_binding(const char *input) {
|
||||
errno = 0;
|
||||
long int num = strtol(walk, &end, 10);
|
||||
if ((errno == ERANGE && (num == LONG_MIN || num == LONG_MAX)) ||
|
||||
(errno != 0 && num == 0))
|
||||
(errno != 0 && num == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* No valid numbers found */
|
||||
if (end == walk)
|
||||
if (end == walk) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (token->identifier != NULL)
|
||||
if (token->identifier != NULL) {
|
||||
push_long(token->identifier, num);
|
||||
}
|
||||
|
||||
/* Set walk to the first non-number character */
|
||||
walk = end;
|
||||
if ((result = next_state(token)) != NULL)
|
||||
if ((result = next_state(token)) != NULL) {
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -379,12 +399,14 @@ static char *rewrite_binding(const char *input) {
|
||||
if (*walk == '"') {
|
||||
beginning++;
|
||||
walk++;
|
||||
while (*walk != '\0' && (*walk != '"' || *(walk - 1) == '\\'))
|
||||
while (*walk != '\0' && (*walk != '"' || *(walk - 1) == '\\')) {
|
||||
walk++;
|
||||
}
|
||||
} else {
|
||||
if (token->name[0] == 's') {
|
||||
while (*walk != '\0' && *walk != '\r' && *walk != '\n')
|
||||
while (*walk != '\0' && *walk != '\r' && *walk != '\n') {
|
||||
walk++;
|
||||
}
|
||||
} else {
|
||||
/* For a word, the delimiters are white space (' ' or
|
||||
* '\t'), closing square bracket (]), comma (,) and
|
||||
@ -392,8 +414,9 @@ static char *rewrite_binding(const char *input) {
|
||||
while (*walk != ' ' && *walk != '\t' &&
|
||||
*walk != ']' && *walk != ',' &&
|
||||
*walk != ';' && *walk != '\r' &&
|
||||
*walk != '\n' && *walk != '\0')
|
||||
*walk != '\n' && *walk != '\0') {
|
||||
walk++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (walk != beginning) {
|
||||
@ -406,27 +429,32 @@ static char *rewrite_binding(const char *input) {
|
||||
/* We only handle escaped double quotes to not break
|
||||
* backwards compatibility with people using \w in
|
||||
* regular expressions etc. */
|
||||
if (beginning[inpos] == '\\' && beginning[inpos + 1] == '"')
|
||||
if (beginning[inpos] == '\\' && beginning[inpos + 1] == '"') {
|
||||
inpos++;
|
||||
}
|
||||
str[outpos] = beginning[inpos];
|
||||
}
|
||||
if (token->identifier)
|
||||
if (token->identifier) {
|
||||
push_string(token->identifier, str);
|
||||
}
|
||||
free(str);
|
||||
/* If we are at the end of a quoted string, skip the ending
|
||||
* double quote. */
|
||||
if (*walk == '"')
|
||||
if (*walk == '"') {
|
||||
walk++;
|
||||
if ((result = next_state(token)) != NULL)
|
||||
}
|
||||
if ((result = next_state(token)) != NULL) {
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(token->name, "end") == 0) {
|
||||
if (*walk == '\0' || *walk == '\n' || *walk == '\r') {
|
||||
if ((result = next_state(token)) != NULL)
|
||||
if ((result = next_state(token)) != NULL) {
|
||||
return result;
|
||||
}
|
||||
/* To make sure we start with an appropriate matching data
|
||||
* structure for commands which do *not* specify any
|
||||
* criteria, we re-initialize the criteria system after
|
||||
@ -513,17 +541,19 @@ static int handle_expose(void) {
|
||||
txt(13, 10, "to abort", white, black);
|
||||
|
||||
/* the not-selected modifier */
|
||||
if (modifier == MOD_Mod4)
|
||||
if (modifier == MOD_Mod4) {
|
||||
txt(5, 5, "<Alt>", white, black);
|
||||
else
|
||||
} else {
|
||||
txt(5, 4, "<Win>", white, black);
|
||||
}
|
||||
|
||||
/* the selected modifier */
|
||||
set_font(&bold_font);
|
||||
if (modifier == MOD_Mod4)
|
||||
if (modifier == MOD_Mod4) {
|
||||
txt(2, 4, "-> <Win>", white, black);
|
||||
else
|
||||
} else {
|
||||
txt(2, 5, "-> <Alt>", white, black);
|
||||
}
|
||||
|
||||
set_font(&font);
|
||||
txt(4, 9, "<Enter>", green, black);
|
||||
@ -562,8 +592,9 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
|
||||
strlen("i3: generate config"),
|
||||
"i3: generate config");
|
||||
xcb_flush(conn);
|
||||
} else
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
/* Swap between modifiers when up or down is pressed. */
|
||||
@ -573,8 +604,9 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
|
||||
}
|
||||
|
||||
/* cancel any time */
|
||||
if (sym == XK_Escape)
|
||||
if (sym == XK_Escape) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Check if this is Mod1 or Mod4. The modmap contains Shift, Lock, Control,
|
||||
* Mod1, Mod2, Mod3, Mod4, Mod5 (in that order) */
|
||||
@ -583,8 +615,9 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
|
||||
int mask = 3;
|
||||
for (int i = 0; i < modmap_reply->keycodes_per_modifier; i++) {
|
||||
xcb_keycode_t code = modmap[(mask * modmap_reply->keycodes_per_modifier) + i];
|
||||
if (code == XCB_NONE)
|
||||
if (code == XCB_NONE) {
|
||||
continue;
|
||||
}
|
||||
printf("Modifier keycode for Mod1: 0x%02x\n", code);
|
||||
if (code == event->detail) {
|
||||
modifier = MOD_Mod1;
|
||||
@ -596,8 +629,9 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
|
||||
mask = 6;
|
||||
for (int i = 0; i < modmap_reply->keycodes_per_modifier; i++) {
|
||||
xcb_keycode_t code = modmap[(mask * modmap_reply->keycodes_per_modifier) + i];
|
||||
if (code == XCB_NONE)
|
||||
if (code == XCB_NONE) {
|
||||
continue;
|
||||
}
|
||||
printf("Modifier keycode for Mod4: 0x%02x\n", code);
|
||||
if (code == event->detail) {
|
||||
modifier = MOD_Mod4;
|
||||
@ -614,11 +648,13 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
|
||||
*
|
||||
*/
|
||||
static void handle_button_press(xcb_button_press_event_t *event) {
|
||||
if (current_step != STEP_GENERATE)
|
||||
if (current_step != STEP_GENERATE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->event_x < col_x(5) || event->event_x > col_x(10))
|
||||
if (event->event_x < col_x(5) || event->event_x > col_x(10)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->event_y >= row_y(4) && event->event_y <= (row_y(4) + font.height)) {
|
||||
modifier = MOD_Mod4;
|
||||
@ -640,20 +676,24 @@ static void finish(void) {
|
||||
|
||||
struct xkb_context *xkb_context;
|
||||
|
||||
if ((xkb_context = xkb_context_new(0)) == NULL)
|
||||
if ((xkb_context = xkb_context_new(0)) == NULL) {
|
||||
errx(1, "could not create xkbcommon context");
|
||||
}
|
||||
|
||||
int32_t device_id = xkb_x11_get_core_keyboard_device_id(conn);
|
||||
if ((xkb_keymap = xkb_x11_keymap_new_from_device(xkb_context, conn, device_id, 0)) == NULL)
|
||||
if ((xkb_keymap = xkb_x11_keymap_new_from_device(xkb_context, conn, device_id, 0)) == NULL) {
|
||||
errx(1, "xkb_x11_keymap_new_from_device failed");
|
||||
}
|
||||
|
||||
FILE *kc_config = fopen(SYSCONFDIR "/i3/config.keycodes", "r");
|
||||
if (kc_config == NULL)
|
||||
if (kc_config == NULL) {
|
||||
err(1, "Could not open input file \"%s\"", SYSCONFDIR "/i3/config.keycodes");
|
||||
}
|
||||
|
||||
FILE *ks_config = fopen(config_path, "w");
|
||||
if (ks_config == NULL)
|
||||
if (ks_config == NULL) {
|
||||
err(1, "Could not open output config file \"%s\"", config_path);
|
||||
}
|
||||
free(config_path);
|
||||
|
||||
char *line = NULL;
|
||||
@ -684,8 +724,9 @@ static void finish(void) {
|
||||
#endif
|
||||
/* skip the warning block at the beginning of the input file */
|
||||
if (head_of_file &&
|
||||
strncmp("# WARNING", line, strlen("# WARNING")) == 0)
|
||||
strncmp("# WARNING", line, strlen("# WARNING")) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
head_of_file = false;
|
||||
|
||||
@ -699,10 +740,11 @@ static void finish(void) {
|
||||
|
||||
/* Set the modifier the user chose */
|
||||
if (strncmp(walk, "set $mod ", strlen("set $mod ")) == 0) {
|
||||
if (modifier == MOD_Mod1)
|
||||
if (modifier == MOD_Mod1) {
|
||||
fputs("set $mod Mod1\n", ks_config);
|
||||
else
|
||||
} else {
|
||||
fputs("set $mod Mod4\n", ks_config);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -767,12 +809,13 @@ int main(int argc, char *argv[]) {
|
||||
return 0;
|
||||
case 'm':
|
||||
headless_run = true;
|
||||
if (strcmp(optarg, "alt") == 0)
|
||||
if (strcmp(optarg, "alt") == 0) {
|
||||
modifier = MOD_Mod1;
|
||||
else if (strcmp(optarg, "win") == 0)
|
||||
} else if (strcmp(optarg, "win") == 0) {
|
||||
modifier = MOD_Mod4;
|
||||
else
|
||||
} else {
|
||||
err(EXIT_FAILURE, "Invalid modifier key %s", optarg);
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
printf("i3-config-wizard " I3_VERSION "\n");
|
||||
@ -789,8 +832,9 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
/* Always write to $XDG_CONFIG_HOME/i3/config by default. */
|
||||
if ((xdg_config_home = getenv("XDG_CONFIG_HOME")) == NULL)
|
||||
if ((xdg_config_home = getenv("XDG_CONFIG_HOME")) == NULL) {
|
||||
xdg_config_home = "~/.config";
|
||||
}
|
||||
|
||||
xdg_config_home = resolve_tilde(xdg_config_home);
|
||||
sasprintf(&config_path, "%s/i3/config", xdg_config_home);
|
||||
@ -799,9 +843,11 @@ int main(int argc, char *argv[]) {
|
||||
char *config_dir;
|
||||
struct stat stbuf;
|
||||
sasprintf(&config_dir, "%s/i3", xdg_config_home);
|
||||
if (stat(config_dir, &stbuf) != 0)
|
||||
if (mkdirp(config_dir, DEFAULT_DIR_MODE) != 0)
|
||||
if (stat(config_dir, &stbuf) != 0) {
|
||||
if (mkdirp(config_dir, DEFAULT_DIR_MODE) != 0) {
|
||||
err(EXIT_FAILURE, "mkdirp(%s) failed", config_dir);
|
||||
}
|
||||
}
|
||||
free(config_dir);
|
||||
free(xdg_config_home);
|
||||
|
||||
@ -815,8 +861,9 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
int screen;
|
||||
if ((conn = xcb_connect(NULL, &screen)) == NULL ||
|
||||
xcb_connection_has_error(conn))
|
||||
xcb_connection_has_error(conn)) {
|
||||
errx(1, "Cannot open display");
|
||||
}
|
||||
|
||||
if (xkb_x11_setup_xkb_extension(conn,
|
||||
XKB_X11_MIN_MAJOR_XKB_VERSION,
|
||||
@ -825,8 +872,9 @@ int main(int argc, char *argv[]) {
|
||||
NULL,
|
||||
NULL,
|
||||
&xkb_base_event,
|
||||
&xkb_base_error) != 1)
|
||||
&xkb_base_error) != 1) {
|
||||
errx(EXIT_FAILURE, "Could not setup XKB extension.");
|
||||
}
|
||||
|
||||
keysyms = xcb_key_symbols_alloc(conn);
|
||||
xcb_get_modifier_mapping_cookie_t modmap_cookie;
|
||||
@ -852,8 +900,9 @@ int main(int argc, char *argv[]) {
|
||||
root_screen = xcb_aux_get_screen(conn, screen);
|
||||
root = root_screen->root;
|
||||
|
||||
if (!(modmap_reply = xcb_get_modifier_mapping_reply(conn, modmap_cookie, NULL)))
|
||||
if (!(modmap_reply = xcb_get_modifier_mapping_reply(conn, modmap_cookie, NULL))) {
|
||||
errx(EXIT_FAILURE, "Could not get modifier mapping");
|
||||
}
|
||||
|
||||
xcb_numlock_mask = get_mod_mask_for(XCB_NUM_LOCK, symbols, modmap_reply);
|
||||
|
||||
|
@ -39,8 +39,9 @@ static int ipcfd = -1;
|
||||
static void disable_shmlog(void) {
|
||||
const char *disablecmd = "debuglog off; shmlog off";
|
||||
if (ipc_send_message(ipcfd, strlen(disablecmd),
|
||||
I3_IPC_MESSAGE_TYPE_COMMAND, (uint8_t *)disablecmd) != 0)
|
||||
I3_IPC_MESSAGE_TYPE_COMMAND, (uint8_t *)disablecmd) != 0) {
|
||||
err(EXIT_FAILURE, "IPC send");
|
||||
}
|
||||
|
||||
/* Ensure the command was sent by waiting for the reply: */
|
||||
uint32_t reply_length = 0;
|
||||
@ -53,8 +54,9 @@ static void disable_shmlog(void) {
|
||||
}
|
||||
|
||||
static int check_for_wrap(void) {
|
||||
if (wrap_count == header->wrap_count)
|
||||
if (wrap_count == header->wrap_count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The log wrapped. Print the remaining content and reset walk to the top
|
||||
* of the log. */
|
||||
@ -148,8 +150,9 @@ int main(int argc, char *argv[]) {
|
||||
ipcfd = ipc_connect(NULL);
|
||||
const char *enablecmd = "debuglog on; shmlog 5242880";
|
||||
if (ipc_send_message(ipcfd, strlen(enablecmd),
|
||||
I3_IPC_MESSAGE_TYPE_COMMAND, (uint8_t *)enablecmd) != 0)
|
||||
I3_IPC_MESSAGE_TYPE_COMMAND, (uint8_t *)enablecmd) != 0) {
|
||||
err(EXIT_FAILURE, "IPC send");
|
||||
}
|
||||
/* By the time we receive a reply, I3_SHMLOG_PATH is set: */
|
||||
uint32_t reply_length = 0;
|
||||
uint8_t *reply = NULL;
|
||||
@ -175,8 +178,9 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
if (*shmname == '\0')
|
||||
if (*shmname == '\0') {
|
||||
errx(EXIT_FAILURE, "Cannot dump log: SHM logging is disabled in i3.");
|
||||
}
|
||||
|
||||
struct stat statbuf;
|
||||
|
||||
@ -211,8 +215,9 @@ int main(int argc, char *argv[]) {
|
||||
/* In case there was a write to the buffer already, skip the first
|
||||
* old line, it very likely is mangled. Not a problem, though, the log
|
||||
* is chatty enough to have plenty lines left. */
|
||||
while (*walk != '\n')
|
||||
while (*walk != '\n') {
|
||||
walk++;
|
||||
}
|
||||
walk++;
|
||||
}
|
||||
|
||||
|
@ -822,21 +822,23 @@ long keysym2ucs(xcb_keysym_t keysym) {
|
||||
|
||||
/* first check for Latin-1 characters (1:1 mapping) */
|
||||
if ((keysym >= 0x0020 && keysym <= 0x007e) ||
|
||||
(keysym >= 0x00a0 && keysym <= 0x00ff))
|
||||
(keysym >= 0x00a0 && keysym <= 0x00ff)) {
|
||||
return keysym;
|
||||
}
|
||||
|
||||
/* also check for directly encoded 24-bit UCS characters */
|
||||
if ((keysym & 0xff000000) == 0x01000000)
|
||||
if ((keysym & 0xff000000) == 0x01000000) {
|
||||
return keysym & 0x00ffffff;
|
||||
}
|
||||
|
||||
/* binary search in table */
|
||||
while (max >= min) {
|
||||
mid = (min + max) / 2;
|
||||
if (keysymtab[mid].keysym < keysym)
|
||||
if (keysymtab[mid].keysym < keysym) {
|
||||
min = mid + 1;
|
||||
else if (keysymtab[mid].keysym > keysym)
|
||||
} else if (keysymtab[mid].keysym > keysym) {
|
||||
max = mid - 1;
|
||||
else {
|
||||
} else {
|
||||
/* found it */
|
||||
return keysymtab[mid].ucs;
|
||||
}
|
||||
|
@ -226,8 +226,9 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
|
||||
|
||||
/* If modeswitch is currently active, we need to look in group 2 or 3,
|
||||
* respectively. */
|
||||
if (modeswitch_active)
|
||||
if (modeswitch_active) {
|
||||
col += 2;
|
||||
}
|
||||
|
||||
xcb_keysym_t sym = xcb_key_press_lookup_keysym(symbols, event, col);
|
||||
if (sym == XK_Mode_switch) {
|
||||
@ -236,12 +237,14 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (sym == XK_Return)
|
||||
if (sym == XK_Return) {
|
||||
finish_input();
|
||||
}
|
||||
|
||||
if (sym == XK_BackSpace) {
|
||||
if (input_position == 0)
|
||||
if (input_position == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
input_position--;
|
||||
free(glyphs_utf8[input_position]);
|
||||
@ -262,8 +265,9 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
|
||||
printf("xcb_is_misc_function_key = %d\n", xcb_is_misc_function_key(sym));
|
||||
printf("xcb_is_modifier_key = %d\n", xcb_is_modifier_key(sym));
|
||||
|
||||
if (xcb_is_modifier_key(sym) || xcb_is_cursor_key(sym))
|
||||
if (xcb_is_modifier_key(sym) || xcb_is_cursor_key(sym)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("sym = %c (%d)\n", sym, sym);
|
||||
|
||||
@ -287,8 +291,9 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
|
||||
glyphs_utf8[input_position] = out;
|
||||
input_position++;
|
||||
|
||||
if (input_position == limit)
|
||||
if (input_position == limit) {
|
||||
finish_input();
|
||||
}
|
||||
|
||||
handle_expose(NULL, conn, NULL);
|
||||
return 1;
|
||||
@ -442,8 +447,9 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
int screen;
|
||||
conn = xcb_connect(NULL, &screen);
|
||||
if (!conn || xcb_connection_has_error(conn))
|
||||
if (!conn || xcb_connection_has_error(conn)) {
|
||||
die("Cannot open display");
|
||||
}
|
||||
|
||||
sockfd = ipc_connect(socket_path);
|
||||
|
||||
@ -456,8 +462,9 @@ int main(int argc, char *argv[]) {
|
||||
font = load_font(pattern ? pattern : "pango:monospace 8", true);
|
||||
set_font(&font);
|
||||
|
||||
if (prompt != NULL)
|
||||
if (prompt != NULL) {
|
||||
prompt_offset = predict_text_width(prompt);
|
||||
}
|
||||
|
||||
const xcb_rectangle_t win_pos = get_window_position();
|
||||
|
||||
|
@ -61,22 +61,24 @@ static int exit_code = 0;
|
||||
static reply_t last_reply;
|
||||
|
||||
static int reply_boolean_cb(void *params, int val) {
|
||||
if (strcmp(last_key, "success") == 0)
|
||||
if (strcmp(last_key, "success") == 0) {
|
||||
last_reply.success = val;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int reply_string_cb(void *params, const unsigned char *val, size_t len) {
|
||||
char *str = sstrndup((const char *)val, len);
|
||||
|
||||
if (strcmp(last_key, "error") == 0)
|
||||
if (strcmp(last_key, "error") == 0) {
|
||||
last_reply.error = str;
|
||||
else if (strcmp(last_key, "input") == 0)
|
||||
} else if (strcmp(last_key, "input") == 0) {
|
||||
last_reply.input = str;
|
||||
else if (strcmp(last_key, "errorposition") == 0)
|
||||
} else if (strcmp(last_key, "errorposition") == 0) {
|
||||
last_reply.errorposition = str;
|
||||
else
|
||||
} else {
|
||||
free(str);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -147,8 +149,9 @@ static yajl_callbacks config_callbacks = {
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
#if defined(__OpenBSD__)
|
||||
if (pledge("stdio rpath unix", NULL) == -1)
|
||||
if (pledge("stdio rpath unix", NULL) == -1) {
|
||||
err(EXIT_FAILURE, "pledge");
|
||||
}
|
||||
#endif
|
||||
char *socket_path = NULL;
|
||||
int o, option_index = 0;
|
||||
@ -244,12 +247,14 @@ int main(int argc, char *argv[]) {
|
||||
optind++;
|
||||
}
|
||||
|
||||
if (!payload)
|
||||
if (!payload) {
|
||||
payload = sstrdup("");
|
||||
}
|
||||
|
||||
int sockfd = ipc_connect(socket_path);
|
||||
if (ipc_send_message(sockfd, strlen(payload), message_type, (uint8_t *)payload) == -1)
|
||||
if (ipc_send_message(sockfd, strlen(payload), message_type, (uint8_t *)payload) == -1) {
|
||||
err(EXIT_FAILURE, "IPC: write()");
|
||||
}
|
||||
free(payload);
|
||||
|
||||
uint32_t reply_length;
|
||||
@ -257,12 +262,14 @@ int main(int argc, char *argv[]) {
|
||||
uint8_t *reply;
|
||||
int ret;
|
||||
if ((ret = ipc_recv_message(sockfd, &reply_type, &reply_length, &reply)) != 0) {
|
||||
if (ret == -1)
|
||||
if (ret == -1) {
|
||||
err(EXIT_FAILURE, "IPC: read()");
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
if (reply_type != message_type)
|
||||
if (reply_type != message_type) {
|
||||
errx(EXIT_FAILURE, "IPC: Received reply of type %d but expected %d", reply_type, message_type);
|
||||
}
|
||||
/* For the reply of commands, have a look if that command was successful.
|
||||
* If not, nicely format the error message. */
|
||||
if (reply_type == I3_IPC_REPLY_TYPE_COMMAND) {
|
||||
@ -303,8 +310,9 @@ int main(int argc, char *argv[]) {
|
||||
do {
|
||||
free(reply);
|
||||
if ((ret = ipc_recv_message(sockfd, &reply_type, &reply_length, &reply)) != 0) {
|
||||
if (ret == -1)
|
||||
if (ret == -1) {
|
||||
err(EXIT_FAILURE, "IPC: read()");
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -126,9 +126,11 @@ static void start_application(const char *command) {
|
||||
}
|
||||
|
||||
static button_t *get_button_at(int16_t x, int16_t y) {
|
||||
for (int c = 0; c < buttoncnt; c++)
|
||||
if (x >= (buttons[c].x) && x <= (buttons[c].x + buttons[c].width))
|
||||
for (int c = 0; c < buttoncnt; c++) {
|
||||
if (x >= (buttons[c].x) && x <= (buttons[c].x + buttons[c].width)) {
|
||||
return &buttons[c];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -148,11 +150,13 @@ static void handle_button_release(xcb_connection_t *conn, xcb_button_release_eve
|
||||
printf("button released on x = %d, y = %d\n",
|
||||
event->event_x, event->event_y);
|
||||
/* If the user hits the close button, we exit(0) */
|
||||
if (event->event_x >= btn_close.x && event->event_x < btn_close.x + btn_close.width)
|
||||
if (event->event_x >= btn_close.x && event->event_x < btn_close.x + btn_close.width) {
|
||||
exit(0);
|
||||
}
|
||||
button_t *button = get_button_at(event->event_x, event->event_y);
|
||||
if (!button)
|
||||
if (!button) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* We need to create a custom script containing our actual command
|
||||
* since not every terminal emulator which is contained in
|
||||
@ -460,8 +464,9 @@ int main(int argc, char *argv[]) {
|
||||
buttons[buttoncnt].action);
|
||||
buttoncnt++;
|
||||
printf("now %d buttons\n", buttoncnt);
|
||||
if (optind < argc)
|
||||
if (optind < argc) {
|
||||
optind++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -470,8 +475,9 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
int screens;
|
||||
if ((conn = xcb_connect(NULL, &screens)) == NULL ||
|
||||
xcb_connection_has_error(conn))
|
||||
xcb_connection_has_error(conn)) {
|
||||
die("Cannot open display");
|
||||
}
|
||||
|
||||
/* Place requests for the atoms we need as soon as possible */
|
||||
#define xmacro(atom) \
|
||||
@ -508,8 +514,9 @@ int main(int argc, char *argv[]) {
|
||||
set_font(&font);
|
||||
|
||||
#if defined(__OpenBSD__)
|
||||
if (pledge("stdio rpath wpath cpath getpw proc exec", NULL) == -1)
|
||||
if (pledge("stdio rpath wpath cpath getpw proc exec", NULL) == -1) {
|
||||
err(EXIT_FAILURE, "pledge");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Default values if we cannot determine the preferred window position. */
|
||||
|
@ -195,10 +195,11 @@ static int stdin_start_map(void *context) {
|
||||
memset(&(ctx->block), '\0', sizeof(struct status_block));
|
||||
|
||||
/* Default width of the separator block. */
|
||||
if (config.separator_symbol == NULL)
|
||||
if (config.separator_symbol == NULL) {
|
||||
ctx->block.sep_block_width = logical_px(9);
|
||||
else
|
||||
} else {
|
||||
ctx->block.sep_block_width = logical_px(8) + separator_symbol_width;
|
||||
}
|
||||
|
||||
/* By default we draw all four borders if a border is set. */
|
||||
ctx->block.border_top = 1;
|
||||
@ -337,10 +338,12 @@ static int stdin_end_map(void *context) {
|
||||
memcpy(new_block, &(ctx->block), sizeof(struct status_block));
|
||||
/* Ensure we have a full_text set, so that when it is missing (or null),
|
||||
* i3bar doesn’t crash and the user gets an annoying message. */
|
||||
if (!new_block->full_text)
|
||||
if (!new_block->full_text) {
|
||||
new_block->full_text = i3string_from_utf8("SPEC VIOLATION: full_text is NULL!");
|
||||
if (new_block->urgent)
|
||||
}
|
||||
if (new_block->urgent) {
|
||||
ctx->has_urgent = true;
|
||||
}
|
||||
|
||||
if (new_block->min_width_str) {
|
||||
i3String *text = i3string_from_utf8(new_block->min_width_str);
|
||||
@ -351,8 +354,9 @@ static int stdin_end_map(void *context) {
|
||||
|
||||
i3string_set_markup(new_block->full_text, new_block->pango_markup);
|
||||
|
||||
if (new_block->short_text != NULL)
|
||||
if (new_block->short_text != NULL) {
|
||||
i3string_set_markup(new_block->short_text, new_block->pango_markup);
|
||||
}
|
||||
|
||||
TAILQ_INSERT_TAIL(&statusline_buffer, new_block, blocks);
|
||||
return 1;
|
||||
@ -444,8 +448,9 @@ static bool read_json_input(unsigned char *input, int length) {
|
||||
char *message = (char *)yajl_get_error(parser, 0, input, length);
|
||||
|
||||
/* strip the newline yajl adds to the error message */
|
||||
if (message[strlen(message) - 1] == '\n')
|
||||
if (message[strlen(message) - 1] == '\n') {
|
||||
message[strlen(message) - 1] = '\0';
|
||||
}
|
||||
|
||||
fprintf(stderr, "[i3bar] Could not parse JSON input (code = %d, message = %s): %.*s\n",
|
||||
status, message, length, input);
|
||||
@ -694,8 +699,9 @@ static void child_write_output(void) {
|
||||
yajl_gen_get_buf(gen, &output, &size);
|
||||
|
||||
n = writeall(child_stdin, output, size);
|
||||
if (n != -1)
|
||||
if (n != -1) {
|
||||
n = writeall(child_stdin, "\n", 1);
|
||||
}
|
||||
|
||||
yajl_gen_clear(gen);
|
||||
|
||||
@ -871,20 +877,27 @@ void send_block_clicked(int button, const char *name, const char *instance, int
|
||||
|
||||
ystr("modifiers");
|
||||
yajl_gen_array_open(gen);
|
||||
if (mods & XCB_MOD_MASK_SHIFT)
|
||||
if (mods & XCB_MOD_MASK_SHIFT) {
|
||||
ystr("Shift");
|
||||
if (mods & XCB_MOD_MASK_CONTROL)
|
||||
}
|
||||
if (mods & XCB_MOD_MASK_CONTROL) {
|
||||
ystr("Control");
|
||||
if (mods & XCB_MOD_MASK_1)
|
||||
}
|
||||
if (mods & XCB_MOD_MASK_1) {
|
||||
ystr("Mod1");
|
||||
if (mods & XCB_MOD_MASK_2)
|
||||
}
|
||||
if (mods & XCB_MOD_MASK_2) {
|
||||
ystr("Mod2");
|
||||
if (mods & XCB_MOD_MASK_3)
|
||||
}
|
||||
if (mods & XCB_MOD_MASK_3) {
|
||||
ystr("Mod3");
|
||||
if (mods & XCB_MOD_MASK_4)
|
||||
}
|
||||
if (mods & XCB_MOD_MASK_4) {
|
||||
ystr("Mod4");
|
||||
if (mods & XCB_MOD_MASK_5)
|
||||
}
|
||||
if (mods & XCB_MOD_MASK_5) {
|
||||
ystr("Mod5");
|
||||
}
|
||||
yajl_gen_array_close(gen);
|
||||
|
||||
ystr("x");
|
||||
|
@ -76,8 +76,9 @@ static int config_null_cb(void *params_) {
|
||||
static int config_string_cb(void *params_, const unsigned char *val, size_t _len) {
|
||||
int len = (int)_len;
|
||||
/* The id and socket_path are ignored, we already know them. */
|
||||
if (!strcmp(cur_key, "id") || !strcmp(cur_key, "socket_path"))
|
||||
if (!strcmp(cur_key, "id") || !strcmp(cur_key, "socket_path")) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (parsing_bindings) {
|
||||
if (strcmp(cur_key, "command") == 0) {
|
||||
|
@ -212,8 +212,9 @@ static void got_bar_config_update(const unsigned char *event, size_t size) {
|
||||
sasprintf(&expected_id, "\"id\":\"%s\"", config.bar_id);
|
||||
char *found_id = strstr((const char *)event, expected_id);
|
||||
FREE(expected_id);
|
||||
if (found_id == NULL)
|
||||
if (found_id == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* reconfigure the bar based on the current outputs */
|
||||
i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL);
|
||||
|
@ -119,8 +119,9 @@ void parse_mode_json(const unsigned char *json, size_t size) {
|
||||
}
|
||||
|
||||
/* We don't want to indicate default binding mode */
|
||||
if (strcmp("default", i3string_as_utf8(params.mode->name)) == 0)
|
||||
if (strcmp("default", i3string_as_utf8(params.mode->name)) == 0) {
|
||||
I3STRING_FREE(params.mode->name);
|
||||
}
|
||||
|
||||
/* Set the new binding mode */
|
||||
set_current_mode(&binding);
|
||||
|
@ -112,8 +112,9 @@ static int outputs_string_cb(void *params_, const unsigned char *val, size_t len
|
||||
errno = 0;
|
||||
long parsed_num = strtol(copy, &end, 10);
|
||||
if (errno == 0 &&
|
||||
(end && *end == '\0'))
|
||||
(end && *end == '\0')) {
|
||||
params->outputs_walk->ws = parsed_num;
|
||||
}
|
||||
|
||||
FREE(copy);
|
||||
FREE(params->cur_key);
|
||||
|
@ -106,11 +106,13 @@ void parse_json_header(i3bar_child *child, const unsigned char *buffer, int leng
|
||||
yajl_status state = yajl_parse(handle, buffer, length);
|
||||
if (state != yajl_status_ok) {
|
||||
child_init(child);
|
||||
if (consumed != NULL)
|
||||
if (consumed != NULL) {
|
||||
*consumed = 0;
|
||||
}
|
||||
} else {
|
||||
if (consumed != NULL)
|
||||
if (consumed != NULL) {
|
||||
*consumed = yajl_get_bytes_consumed(handle);
|
||||
}
|
||||
}
|
||||
|
||||
yajl_free(handle);
|
||||
|
@ -118,8 +118,9 @@ static int workspaces_string_cb(void *params_, const unsigned char *val, size_t
|
||||
size_t offset = strspn(ws_name, ws_num);
|
||||
|
||||
/* Also strip off the conventional ws name delimiter */
|
||||
if (offset && ws_name[offset] == ':')
|
||||
if (offset && ws_name[offset] == ':') {
|
||||
offset += 1;
|
||||
}
|
||||
|
||||
if (config.strip_ws_numbers) {
|
||||
/* Offset may be equal to length, in which case display the number */
|
||||
|
@ -138,8 +138,9 @@ int _xcb_request_failed(xcb_void_cookie_t cookie, char *err_msg, int line) {
|
||||
}
|
||||
|
||||
static uint32_t get_sep_offset(struct status_block *block) {
|
||||
if (!block->no_separator && block->sep_block_width > 0)
|
||||
if (!block->no_separator && block->sep_block_width > 0) {
|
||||
return block->sep_block_width / 2 + block->sep_block_width % 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -147,12 +148,14 @@ static int get_tray_width(struct tc_head *trayclients) {
|
||||
trayclient *trayclient;
|
||||
int tray_width = 0;
|
||||
TAILQ_FOREACH_REVERSE (trayclient, trayclients, tc_head, tailq) {
|
||||
if (!trayclient->mapped)
|
||||
if (!trayclient->mapped) {
|
||||
continue;
|
||||
}
|
||||
tray_width += icon_size + logical_px(config.tray_padding);
|
||||
}
|
||||
if (tray_width > 0)
|
||||
if (tray_width > 0) {
|
||||
tray_width += logical_px(tray_loff_px);
|
||||
}
|
||||
return tray_width;
|
||||
}
|
||||
|
||||
@ -165,8 +168,9 @@ static void draw_separator(i3_output *output, uint32_t x, struct status_block *b
|
||||
color_t bar_bg = (use_focus_colors ? colors.focus_bar_bg : colors.bar_bg);
|
||||
|
||||
uint32_t sep_offset = get_sep_offset(block);
|
||||
if (TAILQ_NEXT(block, blocks) == NULL || sep_offset == 0)
|
||||
if (TAILQ_NEXT(block, blocks) == NULL || sep_offset == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t center_x = x - sep_offset;
|
||||
if (config.separator_symbol == NULL) {
|
||||
@ -196,12 +200,14 @@ static uint32_t predict_statusline_length(bool use_short_text) {
|
||||
render = &block->short_render;
|
||||
}
|
||||
|
||||
if (i3string_get_num_bytes(text) == 0)
|
||||
if (i3string_get_num_bytes(text) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
render->width = predict_text_width(text);
|
||||
if (block->border)
|
||||
if (block->border) {
|
||||
render->width += logical_px(block->border_left + block->border_right);
|
||||
}
|
||||
|
||||
/* Compute offset and append for text alignment in min_width. */
|
||||
if (block->min_width <= render->width) {
|
||||
@ -226,8 +232,9 @@ static uint32_t predict_statusline_length(bool use_short_text) {
|
||||
width += render->width + render->x_offset + render->x_append;
|
||||
|
||||
/* If this is not the last block, add some pixels for a separator. */
|
||||
if (TAILQ_NEXT(block, blocks) != NULL)
|
||||
if (TAILQ_NEXT(block, blocks) != NULL) {
|
||||
width += block->sep_block_width;
|
||||
}
|
||||
}
|
||||
|
||||
return width;
|
||||
@ -259,8 +266,9 @@ static void draw_statusline(i3_output *output, uint32_t clip_left, bool use_focu
|
||||
render = &block->short_render;
|
||||
}
|
||||
|
||||
if (i3string_get_num_bytes(text) == 0)
|
||||
if (i3string_get_num_bytes(text) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
color_t fg_color;
|
||||
if (block->urgent) {
|
||||
@ -284,10 +292,12 @@ static void draw_statusline(i3_output *output, uint32_t clip_left, bool use_focu
|
||||
border_color = colors.urgent_ws_border;
|
||||
bg_color = colors.urgent_ws_bg;
|
||||
} else {
|
||||
if (block->border)
|
||||
if (block->border) {
|
||||
border_color = draw_util_hex_to_color(block->border);
|
||||
if (block->background)
|
||||
}
|
||||
if (block->background) {
|
||||
bg_color = draw_util_hex_to_color(block->background);
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw the border. */
|
||||
@ -363,10 +373,11 @@ static void unhide_bars(void) {
|
||||
XCB_CONFIG_WINDOW_HEIGHT |
|
||||
XCB_CONFIG_WINDOW_STACK_MODE;
|
||||
values[0] = walk->rect.x;
|
||||
if (config.position == POS_TOP)
|
||||
if (config.position == POS_TOP) {
|
||||
values[1] = walk->rect.y;
|
||||
else
|
||||
} else {
|
||||
values[1] = walk->rect.y + walk->rect.h - bar_height;
|
||||
}
|
||||
values[2] = walk->rect.w;
|
||||
values[3] = bar_height;
|
||||
values[4] = XCB_STACK_MODE_ABOVE;
|
||||
@ -434,8 +445,9 @@ void init_colors(const struct xcb_color_strings_t *new_colors) {
|
||||
static bool execute_custom_command(xcb_keycode_t input_code, bool event_is_release) {
|
||||
binding_t *binding;
|
||||
TAILQ_FOREACH (binding, &(config.bindings), bindings) {
|
||||
if ((binding->input_code != input_code) || (binding->release != event_is_release))
|
||||
if ((binding->input_code != input_code) || (binding->release != event_is_release)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
i3_send_msg(I3_IPC_MESSAGE_TYPE_RUN_COMMAND, binding->command);
|
||||
return true;
|
||||
@ -575,13 +587,16 @@ static void handle_button(xcb_button_press_event_t *event) {
|
||||
|
||||
TAILQ_FOREACH (ws_walk, walk->workspaces, tailq) {
|
||||
int w = predict_button_width(ws_walk->name_width);
|
||||
if (x >= workspace_width && x <= workspace_width + w)
|
||||
if (x >= workspace_width && x <= workspace_width + w) {
|
||||
clicked_ws = ws_walk;
|
||||
if (ws_walk->visible)
|
||||
}
|
||||
if (ws_walk->visible) {
|
||||
cur_ws = ws_walk;
|
||||
}
|
||||
workspace_width += w;
|
||||
if (TAILQ_NEXT(ws_walk, tailq) != NULL)
|
||||
if (TAILQ_NEXT(ws_walk, tailq) != NULL) {
|
||||
workspace_width += logical_px(ws_spacing_px);
|
||||
}
|
||||
}
|
||||
|
||||
if (child_want_click_events() && x > workspace_width) {
|
||||
@ -626,8 +641,9 @@ static void handle_button(xcb_button_press_event_t *event) {
|
||||
* If there is no more workspace, don’t even send the workspace
|
||||
* command, otherwise (with workspace auto_back_and_forth) we’d end
|
||||
* up on the wrong workspace. */
|
||||
if (cur_ws == TAILQ_FIRST(walk->workspaces))
|
||||
if (cur_ws == TAILQ_FIRST(walk->workspaces)) {
|
||||
return;
|
||||
}
|
||||
|
||||
cur_ws = TAILQ_PREV(cur_ws, ws_head, tailq);
|
||||
break;
|
||||
@ -637,8 +653,9 @@ static void handle_button(xcb_button_press_event_t *event) {
|
||||
* If there is no more workspace, don’t even send the workspace
|
||||
* command, otherwise (with workspace auto_back_and_forth) we’d end
|
||||
* up on the wrong workspace. */
|
||||
if (cur_ws == TAILQ_LAST(walk->workspaces, ws_head))
|
||||
if (cur_ws == TAILQ_LAST(walk->workspaces, ws_head)) {
|
||||
return;
|
||||
}
|
||||
|
||||
cur_ws = TAILQ_NEXT(cur_ws, tailq);
|
||||
break;
|
||||
@ -649,14 +666,16 @@ static void handle_button(xcb_button_press_event_t *event) {
|
||||
* workspace if it is not already focused */
|
||||
if (cur_ws == NULL) {
|
||||
TAILQ_FOREACH (cur_ws, walk->workspaces, tailq) {
|
||||
if (cur_ws->visible && !cur_ws->focused)
|
||||
if (cur_ws->visible && !cur_ws->focused) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* if there is nothing to focus, we are done */
|
||||
if (cur_ws == NULL)
|
||||
if (cur_ws == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
@ -885,8 +904,9 @@ static void handle_client_message(xcb_client_message_event_t *event) {
|
||||
DLOG("xembed flags = %d\n", xembed[1]);
|
||||
map_it = ((xembed[1] & XEMBED_MAPPED) == XEMBED_MAPPED);
|
||||
xe_version = xembed[0];
|
||||
if (xe_version > 1)
|
||||
if (xe_version > 1) {
|
||||
xe_version = 1;
|
||||
}
|
||||
free(xembedr);
|
||||
} else {
|
||||
ELOG("Window %08x violates the XEMBED protocol, _XEMBED_INFO not set\n", client);
|
||||
@ -904,8 +924,9 @@ static void handle_client_message(xcb_client_message_event_t *event) {
|
||||
output_for_tray->bar.id,
|
||||
output_for_tray->rect.w - icon_size - logical_px(config.tray_padding),
|
||||
logical_px(config.tray_padding));
|
||||
if (xcb_request_failed(rcookie, "Could not reparent window. Maybe it is using an incorrect depth/visual?"))
|
||||
if (xcb_request_failed(rcookie, "Could not reparent window. Maybe it is using an incorrect depth/visual?")) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* We reconfigure the window to use a reasonable size. The systray
|
||||
* specification explicitly says:
|
||||
@ -1104,17 +1125,20 @@ static void handle_configuration_change(xcb_window_t window) {
|
||||
trayclient *trayclient;
|
||||
i3_output *output;
|
||||
SLIST_FOREACH (output, outputs, slist) {
|
||||
if (!output->active)
|
||||
if (!output->active) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int clients = 0;
|
||||
TAILQ_FOREACH_REVERSE (trayclient, output->trayclients, tc_head, tailq) {
|
||||
if (!trayclient->mapped)
|
||||
if (!trayclient->mapped) {
|
||||
continue;
|
||||
}
|
||||
clients++;
|
||||
|
||||
if (trayclient->win != window)
|
||||
if (trayclient->win != window) {
|
||||
continue;
|
||||
}
|
||||
|
||||
xcb_rectangle_t rect;
|
||||
rect.x = output->rect.w - (clients * (icon_size + logical_px(config.tray_padding)));
|
||||
@ -1361,8 +1385,9 @@ static void deregister_xkb_keyevents(void) {
|
||||
*
|
||||
*/
|
||||
void init_xcb_late(char *fontname) {
|
||||
if (fontname == NULL)
|
||||
if (fontname == NULL) {
|
||||
fontname = "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
|
||||
}
|
||||
|
||||
/* Load the font */
|
||||
font = load_font(fontname, true);
|
||||
@ -1390,13 +1415,15 @@ void init_xcb_late(char *fontname) {
|
||||
bar_height = default_px + padding_scaled;
|
||||
icon_size = bar_height - 2 * logical_px(config.tray_padding);
|
||||
|
||||
if (config.separator_symbol)
|
||||
if (config.separator_symbol) {
|
||||
separator_symbol_width = predict_text_width(config.separator_symbol);
|
||||
}
|
||||
|
||||
xcb_flush(xcb_connection);
|
||||
|
||||
if (config.hide_on_modifier == M_HIDE)
|
||||
if (config.hide_on_modifier == M_HIDE) {
|
||||
register_xkb_keyevents();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1435,8 +1462,9 @@ static void init_tray(void) {
|
||||
char atomname[strlen("_NET_SYSTEM_TRAY_S") + 11];
|
||||
snprintf(atomname, strlen("_NET_SYSTEM_TRAY_S") + 11, "_NET_SYSTEM_TRAY_S%d", screen);
|
||||
xcb_intern_atom_cookie_t tray_cookie;
|
||||
if (tray_reply == NULL)
|
||||
if (tray_reply == NULL) {
|
||||
tray_cookie = xcb_intern_atom(xcb_connection, 0, strlen(atomname), atomname);
|
||||
}
|
||||
|
||||
/* tray support: we need a window to own the selection */
|
||||
selwin = xcb_generate_id(xcb_connection);
|
||||
@ -1603,8 +1631,9 @@ void get_atoms(void) {
|
||||
*
|
||||
*/
|
||||
void kick_tray_clients(i3_output *output) {
|
||||
if (TAILQ_EMPTY(output->trayclients))
|
||||
if (TAILQ_EMPTY(output->trayclients)) {
|
||||
return;
|
||||
}
|
||||
|
||||
trayclient *trayclient;
|
||||
while (!TAILQ_EMPTY(output->trayclients)) {
|
||||
@ -1899,10 +1928,11 @@ void reconfig_windows(bool redraw_bars) {
|
||||
XCB_CONFIG_WINDOW_HEIGHT |
|
||||
XCB_CONFIG_WINDOW_STACK_MODE;
|
||||
values[0] = walk->rect.x;
|
||||
if (config.position == POS_TOP)
|
||||
if (config.position == POS_TOP) {
|
||||
values[1] = walk->rect.y;
|
||||
else
|
||||
} else {
|
||||
values[1] = walk->rect.y + walk->rect.h - bar_height;
|
||||
}
|
||||
values[2] = walk->rect.w;
|
||||
values[3] = bar_height;
|
||||
values[4] = XCB_STACK_MODE_ABOVE;
|
||||
@ -2078,8 +2108,9 @@ void draw_bars(bool unhide) {
|
||||
workspace_width, w, ws_walk->name_width, ws_walk->name);
|
||||
|
||||
workspace_width += w;
|
||||
if (TAILQ_NEXT(ws_walk, tailq) != NULL)
|
||||
if (TAILQ_NEXT(ws_walk, tailq) != NULL) {
|
||||
workspace_width += logical_px(ws_spacing_px);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,8 @@ int logical_px(const int logical) {
|
||||
* systems to 96 dpi in order to get the behavior they expect/are used to,
|
||||
* but since we can easily detect this case in code, let’s do it for them.
|
||||
*/
|
||||
if ((dpi / 96.0) < 1.25)
|
||||
if ((dpi / 96.0) < 1.25) {
|
||||
return logical;
|
||||
}
|
||||
return ceil((dpi / 96.0) * logical);
|
||||
}
|
||||
|
@ -110,8 +110,9 @@ void draw_util_surface_init(xcb_connection_t *conn, surface_t *surface, xcb_draw
|
||||
surface->width = width;
|
||||
surface->height = height;
|
||||
|
||||
if (visual == NULL)
|
||||
if (visual == NULL) {
|
||||
visual = visual_type;
|
||||
}
|
||||
|
||||
surface->gc = get_gc(conn, get_visual_depth(visual->visual_id), drawable, &surface->owns_gc);
|
||||
surface->surface = cairo_xcb_surface_create(conn, surface->id, visual, width, height);
|
||||
|
33
libi3/font.c
33
libi3/font.c
@ -96,10 +96,11 @@ static void draw_text_pango(const char *text, size_t text_len,
|
||||
pango_layout_set_wrap(layout, PANGO_WRAP_CHAR);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
|
||||
if (pango_markup)
|
||||
if (pango_markup) {
|
||||
pango_layout_set_markup(layout, text, text_len);
|
||||
else
|
||||
} else {
|
||||
pango_layout_set_text(layout, text, text_len);
|
||||
}
|
||||
|
||||
/* Do the drawing */
|
||||
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
||||
@ -131,10 +132,11 @@ static int predict_text_width_pango(const char *text, size_t text_len, bool pang
|
||||
gint width;
|
||||
pango_layout_set_font_description(layout, savedFont->specific.pango_desc);
|
||||
|
||||
if (pango_markup)
|
||||
if (pango_markup) {
|
||||
pango_layout_set_markup(layout, text, text_len);
|
||||
else
|
||||
} else {
|
||||
pango_layout_set_text(layout, text, text_len);
|
||||
}
|
||||
|
||||
pango_cairo_update_layout(cr, layout);
|
||||
pango_layout_get_pixel_size(layout, &width, NULL);
|
||||
@ -214,10 +216,11 @@ i3Font load_font(const char *pattern, const bool fallback) {
|
||||
info_cookie = xcb_query_font(conn, font.specific.xcb.id);
|
||||
|
||||
free(error);
|
||||
if ((error = xcb_request_check(conn, font_cookie)) != NULL)
|
||||
if ((error = xcb_request_check(conn, font_cookie)) != NULL) {
|
||||
errx(EXIT_FAILURE, "Could open neither requested font nor fallbacks "
|
||||
"(fixed or -misc-*): X11 error %d",
|
||||
error->error_code);
|
||||
}
|
||||
}
|
||||
}
|
||||
free(error);
|
||||
@ -226,14 +229,16 @@ i3Font load_font(const char *pattern, const bool fallback) {
|
||||
LOG("Using X font %s\n", pattern);
|
||||
|
||||
/* Get information (height/name) for this font */
|
||||
if (!(font.specific.xcb.info = xcb_query_font_reply(conn, info_cookie, NULL)))
|
||||
if (!(font.specific.xcb.info = xcb_query_font_reply(conn, info_cookie, NULL))) {
|
||||
errx(EXIT_FAILURE, "Could not load font \"%s\"", pattern);
|
||||
}
|
||||
|
||||
/* Get the font table, if possible */
|
||||
if (xcb_query_font_char_infos_length(font.specific.xcb.info) == 0)
|
||||
if (xcb_query_font_char_infos_length(font.specific.xcb.info) == 0) {
|
||||
font.specific.xcb.table = NULL;
|
||||
else
|
||||
} else {
|
||||
font.specific.xcb.table = xcb_query_font_char_infos(font.specific.xcb.info);
|
||||
}
|
||||
|
||||
/* Calculate the font height */
|
||||
font.height = font.specific.xcb.info->font_ascent + font.specific.xcb.info->font_descent;
|
||||
@ -258,8 +263,9 @@ void set_font(i3Font *font) {
|
||||
*/
|
||||
void free_font(void) {
|
||||
/* if there is no saved font, simply return */
|
||||
if (savedFont == NULL)
|
||||
if (savedFont == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
free(savedFont->pattern);
|
||||
switch (savedFont->type) {
|
||||
@ -340,8 +346,9 @@ static void draw_text_xcb(const xcb_char2b_t *text, size_t text_len, xcb_drawabl
|
||||
text_len -= chunk_size;
|
||||
|
||||
/* Check if we're done */
|
||||
if (text_len == 0)
|
||||
if (text_len == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Advance pos_x based on the predicted text width */
|
||||
x += predict_text_width_xcb(chunk, chunk_size);
|
||||
@ -405,8 +412,9 @@ static int xcb_query_text_width(const xcb_char2b_t *text, size_t text_len) {
|
||||
}
|
||||
|
||||
static int predict_text_width_xcb(const xcb_char2b_t *input, size_t text_len) {
|
||||
if (text_len == 0)
|
||||
if (text_len == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int width;
|
||||
if (savedFont->specific.xcb.table == NULL) {
|
||||
@ -427,8 +435,9 @@ static int predict_text_width_xcb(const xcb_char2b_t *input, size_t text_len) {
|
||||
if (row < font_info->min_byte1 ||
|
||||
row > font_info->max_byte1 ||
|
||||
col < font_info->min_char_or_byte2 ||
|
||||
col > font_info->max_char_or_byte2)
|
||||
col > font_info->max_char_or_byte2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Don't you ask me, how this one works… (Merovius) */
|
||||
info = &font_table[((row - font_info->min_byte1) *
|
||||
|
@ -19,16 +19,18 @@
|
||||
*
|
||||
*/
|
||||
char *format_placeholders(char *format, placeholder_t *placeholders, int num) {
|
||||
if (format == NULL)
|
||||
if (format == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* We have to first iterate over the string to see how much buffer space
|
||||
* we need to allocate. */
|
||||
int buffer_len = strlen(format) + 1;
|
||||
for (char *walk = format; *walk != '\0'; walk++) {
|
||||
for (int i = 0; i < num; i++) {
|
||||
if (!CS_STARTS_WITH(walk, placeholders[i].name))
|
||||
if (!CS_STARTS_WITH(walk, placeholders[i].name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
buffer_len = buffer_len - strlen(placeholders[i].name) + strlen(placeholders[i].value);
|
||||
walk += strlen(placeholders[i].name) - 1;
|
||||
@ -57,8 +59,9 @@ char *format_placeholders(char *format, placeholder_t *placeholders, int num) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!matched)
|
||||
if (!matched) {
|
||||
*(outwalk++) = *walk;
|
||||
}
|
||||
}
|
||||
|
||||
*outwalk = '\0';
|
||||
|
@ -56,8 +56,9 @@ uint32_t get_colorpixel(const char *hex) {
|
||||
/* Lookup this colorpixel in the cache */
|
||||
struct Colorpixel *colorpixel;
|
||||
SLIST_FOREACH (colorpixel, &(colorpixels), colorpixels) {
|
||||
if (strcmp(colorpixel->hex, hex) == 0)
|
||||
if (strcmp(colorpixel->hex, hex) == 0) {
|
||||
return colorpixel->pixel;
|
||||
}
|
||||
}
|
||||
|
||||
#define RGB_8_TO_16(i) (65535 * ((i)&0xFF) / 255)
|
||||
|
@ -83,8 +83,9 @@ char *get_exe_path(const char *argv0) {
|
||||
const char *component;
|
||||
char *str = path;
|
||||
while (1) {
|
||||
if ((component = strtok(str, ":")) == NULL)
|
||||
if ((component = strtok(str, ":")) == NULL) {
|
||||
break;
|
||||
}
|
||||
str = NULL;
|
||||
free(destpath);
|
||||
sasprintf(&destpath, "%s/%s", component, argv0);
|
||||
|
@ -29,8 +29,9 @@ uint32_t aio_get_mod_mask_for(uint32_t keysym, xcb_key_symbols_t *symbols) {
|
||||
|
||||
/* Get the current modifier mapping (this is blocking!) */
|
||||
cookie = xcb_get_modifier_mapping(conn);
|
||||
if (!(modmap_r = xcb_get_modifier_mapping_reply(conn, cookie, NULL)))
|
||||
if (!(modmap_r = xcb_get_modifier_mapping_reply(conn, cookie, NULL))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t result = get_mod_mask_for(keysym, symbols, modmap_r);
|
||||
free(modmap_r);
|
||||
@ -53,25 +54,28 @@ uint32_t get_mod_mask_for(uint32_t keysym,
|
||||
modmap = xcb_get_modifier_mapping_keycodes(modmap_reply);
|
||||
|
||||
/* Get the list of keycodes for the given symbol */
|
||||
if (!(codes = xcb_key_symbols_get_keycode(symbols, keysym)))
|
||||
if (!(codes = xcb_key_symbols_get_keycode(symbols, keysym))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Loop through all modifiers (Mod1-Mod5, Shift, Control, Lock) */
|
||||
for (int mod = 0; mod < 8; mod++)
|
||||
for (int mod = 0; mod < 8; mod++) {
|
||||
for (int j = 0; j < modmap_reply->keycodes_per_modifier; j++) {
|
||||
/* Store the current keycode (for modifier 'mod') */
|
||||
mod_code = modmap[(mod * modmap_reply->keycodes_per_modifier) + j];
|
||||
/* Check if that keycode is in the list of previously resolved
|
||||
* keycodes for our symbol. If so, return the modifier mask. */
|
||||
for (xcb_keycode_t *code = codes; *code; code++) {
|
||||
if (*code != mod_code)
|
||||
if (*code != mod_code) {
|
||||
continue;
|
||||
}
|
||||
|
||||
free(codes);
|
||||
/* This corresponds to the XCB_MOD_MASK_* constants */
|
||||
return (1 << mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -20,8 +20,9 @@ xcb_visualtype_t *get_visualtype(xcb_screen_t *screen) {
|
||||
for (visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
|
||||
visual_iter.rem;
|
||||
xcb_visualtype_next(&visual_iter)) {
|
||||
if (screen->root_visual == visual_iter.data->visual_id)
|
||||
if (screen->root_visual == visual_iter.data->visual_id) {
|
||||
return visual_iter.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
@ -55,8 +55,9 @@ int ipc_connect(const char *socket_path) {
|
||||
*/
|
||||
int ipc_connect_impl(const char *socket_path) {
|
||||
int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||
if (sockfd == -1)
|
||||
if (sockfd == -1) {
|
||||
err(EXIT_FAILURE, "Could not create socket");
|
||||
}
|
||||
|
||||
(void)fcntl(sockfd, F_SETFD, FD_CLOEXEC);
|
||||
|
||||
|
@ -36,8 +36,9 @@ int ipc_recv_message(int sockfd, uint32_t *message_type,
|
||||
uint32_t read_bytes = 0;
|
||||
while (read_bytes < to_read) {
|
||||
int n = read(sockfd, msg + read_bytes, to_read - read_bytes);
|
||||
if (n == -1)
|
||||
if (n == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (n == 0) {
|
||||
if (read_bytes == 0) {
|
||||
return -2;
|
||||
@ -60,8 +61,9 @@ int ipc_recv_message(int sockfd, uint32_t *message_type,
|
||||
walk += strlen(I3_IPC_MAGIC);
|
||||
memcpy(reply_length, walk, sizeof(uint32_t));
|
||||
walk += sizeof(uint32_t);
|
||||
if (message_type != NULL)
|
||||
if (message_type != NULL) {
|
||||
memcpy(message_type, walk, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
*reply = smalloc(*reply_length);
|
||||
|
||||
@ -69,8 +71,9 @@ int ipc_recv_message(int sockfd, uint32_t *message_type,
|
||||
while (read_bytes < *reply_length) {
|
||||
const int n = read(sockfd, *reply + read_bytes, *reply_length - read_bytes);
|
||||
if (n == -1) {
|
||||
if (errno == EINTR || errno == EAGAIN)
|
||||
if (errno == EINTR || errno == EAGAIN) {
|
||||
continue;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (n == 0) {
|
||||
|
@ -26,11 +26,13 @@ int ipc_send_message(int sockfd, const uint32_t message_size,
|
||||
.size = message_size,
|
||||
.type = message_type};
|
||||
|
||||
if (writeall(sockfd, ((void *)&header), sizeof(i3_ipc_header_t)) == -1)
|
||||
if (writeall(sockfd, ((void *)&header), sizeof(i3_ipc_header_t)) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (writeall(sockfd, payload, message_size) == -1)
|
||||
if (writeall(sockfd, payload, message_size) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -18,8 +18,9 @@
|
||||
*
|
||||
*/
|
||||
int mkdirp(const char *path, mode_t mode) {
|
||||
if (mkdir(path, mode) == 0)
|
||||
if (mkdir(path, mode) == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (errno == EEXIST) {
|
||||
struct stat st;
|
||||
/* Check that the named file actually is a directory. */
|
||||
@ -38,8 +39,9 @@ int mkdirp(const char *path, mode_t mode) {
|
||||
}
|
||||
char *copy = sstrdup(path);
|
||||
/* strip trailing slashes, if any */
|
||||
while (copy[strlen(copy) - 1] == '/')
|
||||
while (copy[strlen(copy) - 1] == '/') {
|
||||
copy[strlen(copy) - 1] = '\0';
|
||||
}
|
||||
|
||||
char *sep = strrchr(copy, '/');
|
||||
if (sep == NULL) {
|
||||
@ -48,8 +50,9 @@ int mkdirp(const char *path, mode_t mode) {
|
||||
}
|
||||
*sep = '\0';
|
||||
int result = -1;
|
||||
if (mkdirp(copy, mode) == 0)
|
||||
if (mkdirp(copy, mode) == 0) {
|
||||
result = mkdirp(path, mode);
|
||||
}
|
||||
free(copy);
|
||||
|
||||
return result;
|
||||
|
@ -28,9 +28,9 @@ char *resolve_tilde(const char *path) {
|
||||
int res = glob(head, GLOB_TILDE, NULL, &globbuf);
|
||||
free(head);
|
||||
/* no match, or many wildcard matches are bad */
|
||||
if (res == GLOB_NOMATCH || globbuf.gl_pathc != 1)
|
||||
if (res == GLOB_NOMATCH || globbuf.gl_pathc != 1) {
|
||||
result = sstrdup(path);
|
||||
else if (res != 0) {
|
||||
} else if (res != 0) {
|
||||
err(EXIT_FAILURE, "glob() failed");
|
||||
} else {
|
||||
head = globbuf.gl_pathv[0];
|
||||
|
@ -86,7 +86,8 @@ out:
|
||||
out_atom:
|
||||
free(atom_reply);
|
||||
out_conn:
|
||||
if (provided_conn == NULL)
|
||||
if (provided_conn == NULL) {
|
||||
xcb_disconnect(conn);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
@ -20,36 +20,41 @@
|
||||
*/
|
||||
void *smalloc(size_t size) {
|
||||
void *result = malloc(size);
|
||||
if (result == NULL)
|
||||
if (result == NULL) {
|
||||
err(EXIT_FAILURE, "malloc(%zd)", size);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void *scalloc(size_t num, size_t size) {
|
||||
void *result = calloc(num, size);
|
||||
if (result == NULL)
|
||||
if (result == NULL) {
|
||||
err(EXIT_FAILURE, "calloc(%zd, %zd)", num, size);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void *srealloc(void *ptr, size_t size) {
|
||||
void *result = realloc(ptr, size);
|
||||
if (result == NULL && size > 0)
|
||||
if (result == NULL && size > 0) {
|
||||
err(EXIT_FAILURE, "realloc(%zd)", size);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
char *sstrdup(const char *str) {
|
||||
char *result = strdup(str);
|
||||
if (result == NULL)
|
||||
if (result == NULL) {
|
||||
err(EXIT_FAILURE, "strdup()");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
char *sstrndup(const char *str, size_t size) {
|
||||
char *result = strndup(str, size);
|
||||
if (result == NULL)
|
||||
if (result == NULL) {
|
||||
err(EXIT_FAILURE, "strndup()");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -58,8 +63,9 @@ int sasprintf(char **strp, const char *fmt, ...) {
|
||||
int result;
|
||||
|
||||
va_start(args, fmt);
|
||||
if ((result = vasprintf(strp, fmt, args)) == -1)
|
||||
if ((result = vasprintf(strp, fmt, args)) == -1) {
|
||||
err(EXIT_FAILURE, "asprintf(%s)", fmt);
|
||||
}
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
@ -70,8 +76,9 @@ ssize_t writeall(int fd, const void *buf, size_t count) {
|
||||
while (written < count) {
|
||||
const ssize_t n = write(fd, ((char *)buf) + written, count - written);
|
||||
if (n == -1) {
|
||||
if (errno == EINTR || errno == EAGAIN)
|
||||
if (errno == EINTR || errno == EAGAIN) {
|
||||
continue;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
written += (size_t)n;
|
||||
@ -103,10 +110,11 @@ ssize_t swrite(int fd, const void *buf, size_t count) {
|
||||
ssize_t n;
|
||||
|
||||
n = writeall(fd, buf, count);
|
||||
if (n == -1)
|
||||
if (n == -1) {
|
||||
err(EXIT_FAILURE, "Failed to write %d", fd);
|
||||
else
|
||||
} else {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -113,23 +113,27 @@ i3String *i3string_copy(i3String *str) {
|
||||
*
|
||||
*/
|
||||
void i3string_free(i3String *str) {
|
||||
if (str == NULL)
|
||||
if (str == NULL) {
|
||||
return;
|
||||
}
|
||||
free(str->utf8);
|
||||
free(str->ucs2);
|
||||
free(str);
|
||||
}
|
||||
|
||||
static void i3string_ensure_utf8(i3String *str) {
|
||||
if (str->utf8 != NULL)
|
||||
if (str->utf8 != NULL) {
|
||||
return;
|
||||
if ((str->utf8 = convert_ucs2_to_utf8(str->ucs2, str->num_glyphs)) != NULL)
|
||||
}
|
||||
if ((str->utf8 = convert_ucs2_to_utf8(str->ucs2, str->num_glyphs)) != NULL) {
|
||||
str->num_bytes = strlen(str->utf8);
|
||||
}
|
||||
}
|
||||
|
||||
static void i3string_ensure_ucs2(i3String *str) {
|
||||
if (str->ucs2 != NULL)
|
||||
if (str->ucs2 != NULL) {
|
||||
return;
|
||||
}
|
||||
str->ucs2 = convert_utf8_to_ucs2(str->utf8, &str->num_glyphs);
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,9 @@ char *strndup(const char *str, size_t n) {
|
||||
size_t len;
|
||||
char *copy;
|
||||
|
||||
for (len = 0; len < n && str[len]; len++)
|
||||
for (len = 0; len < n && str[len]; len++) {
|
||||
continue;
|
||||
}
|
||||
|
||||
copy = smalloc(len + 1);
|
||||
memcpy(copy, str, len);
|
||||
|
@ -32,8 +32,9 @@ char *convert_ucs2_to_utf8(xcb_char2b_t *text, size_t num_glyphs) {
|
||||
if (utf8_conversion_descriptor == (iconv_t)-1) {
|
||||
/* Get a new conversion descriptor */
|
||||
utf8_conversion_descriptor = iconv_open("UTF-8", "UCS-2BE");
|
||||
if (utf8_conversion_descriptor == (iconv_t)-1)
|
||||
if (utf8_conversion_descriptor == (iconv_t)-1) {
|
||||
err(EXIT_FAILURE, "Error opening the conversion context");
|
||||
}
|
||||
} else {
|
||||
/* Reset the existing conversion descriptor */
|
||||
iconv(utf8_conversion_descriptor, NULL, NULL, NULL, NULL);
|
||||
|
@ -22,21 +22,24 @@ void run_assignments(i3Window *window) {
|
||||
/* Check if any assignments match */
|
||||
Assignment *current;
|
||||
TAILQ_FOREACH (current, &assignments, assignments) {
|
||||
if (current->type != A_COMMAND || !match_matches_window(&(current->match), window))
|
||||
if (current->type != A_COMMAND || !match_matches_window(&(current->match), window)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool skip = false;
|
||||
for (uint32_t c = 0; c < window->nr_assignments; c++) {
|
||||
if (window->ran_assignments[c] != current)
|
||||
if (window->ran_assignments[c] != current) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DLOG("This assignment already ran for the given window, not executing it again.\n");
|
||||
skip = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (skip)
|
||||
if (skip) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Store that we ran this assignment to not execute it again. We have
|
||||
* to do this before running the actual command to prevent infinite
|
||||
@ -51,15 +54,17 @@ void run_assignments(i3Window *window) {
|
||||
CommandResult *result = parse_command(full_command, NULL, NULL);
|
||||
free(full_command);
|
||||
|
||||
if (result->needs_tree_render)
|
||||
if (result->needs_tree_render) {
|
||||
needs_tree_render = true;
|
||||
}
|
||||
|
||||
command_result_free(result);
|
||||
}
|
||||
|
||||
/* If any of the commands required re-rendering, we will do that now. */
|
||||
if (needs_tree_render)
|
||||
if (needs_tree_render) {
|
||||
tree_render();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -71,8 +76,9 @@ Assignment *assignment_for(i3Window *window, int type) {
|
||||
|
||||
TAILQ_FOREACH (assignment, &assignments, assignments) {
|
||||
if ((type != A_ANY && (assignment->type & type) == 0) ||
|
||||
!match_matches_window(&(assignment->match), window))
|
||||
!match_matches_window(&(assignment->match), window)) {
|
||||
continue;
|
||||
}
|
||||
DLOG("got a matching assignment\n");
|
||||
return assignment;
|
||||
}
|
||||
|
@ -86,16 +86,21 @@ Binding *configure_binding(const char *bindtype, const char *modifiers, const ch
|
||||
new_binding->command = sstrdup(command);
|
||||
new_binding->event_state_mask = event_state_from_str(modifiers);
|
||||
int group_bits_set = 0;
|
||||
if ((new_binding->event_state_mask >> 16) & I3_XKB_GROUP_MASK_1)
|
||||
if ((new_binding->event_state_mask >> 16) & I3_XKB_GROUP_MASK_1) {
|
||||
group_bits_set++;
|
||||
if ((new_binding->event_state_mask >> 16) & I3_XKB_GROUP_MASK_2)
|
||||
}
|
||||
if ((new_binding->event_state_mask >> 16) & I3_XKB_GROUP_MASK_2) {
|
||||
group_bits_set++;
|
||||
if ((new_binding->event_state_mask >> 16) & I3_XKB_GROUP_MASK_3)
|
||||
}
|
||||
if ((new_binding->event_state_mask >> 16) & I3_XKB_GROUP_MASK_3) {
|
||||
group_bits_set++;
|
||||
if ((new_binding->event_state_mask >> 16) & I3_XKB_GROUP_MASK_4)
|
||||
}
|
||||
if ((new_binding->event_state_mask >> 16) & I3_XKB_GROUP_MASK_4) {
|
||||
group_bits_set++;
|
||||
if (group_bits_set > 1)
|
||||
}
|
||||
if (group_bits_set > 1) {
|
||||
ELOG("Keybinding has more than one Group specified, but your X server is always in precisely one group. The keybinding can never trigger.\n");
|
||||
}
|
||||
|
||||
struct Mode *mode = mode_from_name(modename, pango_markup);
|
||||
TAILQ_INSERT_TAIL(mode->bindings, new_binding, bindings);
|
||||
@ -107,8 +112,9 @@ Binding *configure_binding(const char *bindtype, const char *modifiers, const ch
|
||||
|
||||
static bool binding_in_current_group(const Binding *bind) {
|
||||
/* If no bits are set, the binding should be installed in every group. */
|
||||
if ((bind->event_state_mask >> 16) == I3_XKB_GROUP_MASK_ANY)
|
||||
if ((bind->event_state_mask >> 16) == I3_XKB_GROUP_MASK_ANY) {
|
||||
return true;
|
||||
}
|
||||
switch (xkb_current_group) {
|
||||
case XCB_XKB_GROUP_1:
|
||||
return ((bind->event_state_mask >> 16) & I3_XKB_GROUP_MASK_1);
|
||||
@ -149,11 +155,13 @@ static void grab_keycode_for_binding(xcb_connection_t *conn, Binding *bind, uint
|
||||
void grab_all_keys(xcb_connection_t *conn) {
|
||||
Binding *bind;
|
||||
TAILQ_FOREACH (bind, bindings, bindings) {
|
||||
if (bind->input_type != B_KEYBOARD)
|
||||
if (bind->input_type != B_KEYBOARD) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!binding_in_current_group(bind))
|
||||
if (!binding_in_current_group(bind)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* The easy case: the user specified a keycode directly. */
|
||||
if (bind->keycode > 0) {
|
||||
@ -182,8 +190,9 @@ void regrab_all_buttons(xcb_connection_t *conn) {
|
||||
|
||||
Con *con;
|
||||
TAILQ_FOREACH (con, &all_cons, all_cons) {
|
||||
if (con->window == NULL)
|
||||
if (con->window == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
xcb_ungrab_button(conn, XCB_BUTTON_INDEX_ANY, con->window->id, XCB_BUTTON_MASK_ANY);
|
||||
xcb_grab_buttons(conn, con->window->id, buttons);
|
||||
@ -206,10 +215,12 @@ static Binding *get_binding(i3_event_state_mask_t state_filtered, bool is_releas
|
||||
/* On a press event, we first reset all B_UPON_KEYRELEASE_IGNORE_MODS
|
||||
* bindings back to B_UPON_KEYRELEASE */
|
||||
TAILQ_FOREACH (bind, bindings, bindings) {
|
||||
if (bind->input_type != input_type)
|
||||
if (bind->input_type != input_type) {
|
||||
continue;
|
||||
if (bind->release == B_UPON_KEYRELEASE_IGNORE_MODS)
|
||||
}
|
||||
if (bind->release == B_UPON_KEYRELEASE_IGNORE_MODS) {
|
||||
bind->release = B_UPON_KEYRELEASE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -386,18 +397,22 @@ static void add_keycode_if_matches(struct xkb_keymap *keymap, xkb_keycode_t key,
|
||||
/* Check if Shift was specified, and try resolving the symbol without
|
||||
* shift, so that “bindsym $mod+Shift+a nop” actually works. */
|
||||
const xkb_layout_index_t layout = xkb_state_key_get_layout(resolving->xkb_state, key);
|
||||
if (layout == XKB_LAYOUT_INVALID)
|
||||
if (layout == XKB_LAYOUT_INVALID) {
|
||||
return;
|
||||
if (xkb_state_key_get_level(resolving->xkb_state, key, layout) > 1)
|
||||
}
|
||||
if (xkb_state_key_get_level(resolving->xkb_state, key, layout) > 1) {
|
||||
return;
|
||||
}
|
||||
/* Skip the Shift fallback for keypad keys, otherwise one cannot bind
|
||||
* KP_1 independent of KP_End. */
|
||||
if (sym >= XKB_KEY_KP_Space && sym <= XKB_KEY_KP_Equal)
|
||||
if (sym >= XKB_KEY_KP_Space && sym <= XKB_KEY_KP_Equal) {
|
||||
return;
|
||||
}
|
||||
numlock_state = resolving->xkb_state_numlock_no_shift;
|
||||
sym = xkb_state_key_get_one_sym(resolving->xkb_state_no_shift, key);
|
||||
if (sym != resolving->keysym)
|
||||
if (sym != resolving->keysym) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Binding *bind = resolving->bind;
|
||||
|
||||
@ -460,12 +475,13 @@ void translate_keysyms(void) {
|
||||
}
|
||||
|
||||
xkb_layout_index_t group = XCB_XKB_GROUP_1;
|
||||
if ((bind->event_state_mask >> 16) & I3_XKB_GROUP_MASK_2)
|
||||
if ((bind->event_state_mask >> 16) & I3_XKB_GROUP_MASK_2) {
|
||||
group = XCB_XKB_GROUP_2;
|
||||
else if ((bind->event_state_mask >> 16) & I3_XKB_GROUP_MASK_3)
|
||||
} else if ((bind->event_state_mask >> 16) & I3_XKB_GROUP_MASK_3) {
|
||||
group = XCB_XKB_GROUP_3;
|
||||
else if ((bind->event_state_mask >> 16) & I3_XKB_GROUP_MASK_4)
|
||||
} else if ((bind->event_state_mask >> 16) & I3_XKB_GROUP_MASK_4) {
|
||||
group = XCB_XKB_GROUP_4;
|
||||
}
|
||||
|
||||
DLOG("Binding %p group = %d, event_state_mask = %d, &2 = %s, &3 = %s, &4 = %s\n",
|
||||
bind,
|
||||
@ -583,14 +599,17 @@ void translate_keysyms(void) {
|
||||
/* check for duplicate bindings */
|
||||
Binding *check;
|
||||
TAILQ_FOREACH (check, bindings, bindings) {
|
||||
if (check == bind)
|
||||
if (check == bind) {
|
||||
continue;
|
||||
if (check->symbol != NULL)
|
||||
}
|
||||
if (check->symbol != NULL) {
|
||||
continue;
|
||||
}
|
||||
if (check->keycode != binding_keycode->keycode ||
|
||||
check->event_state_mask != binding_keycode->modifiers ||
|
||||
check->release != bind->release)
|
||||
check->release != bind->release) {
|
||||
continue;
|
||||
}
|
||||
has_errors = true;
|
||||
ELOG("Duplicate keybinding in config file:\n keysym = %s, keycode = %d, state_mask = 0x%x\n", bind->symbol, check->keycode, bind->event_state_mask);
|
||||
}
|
||||
@ -623,8 +642,9 @@ void switch_mode(const char *new_mode) {
|
||||
DLOG("Switching to mode %s\n", new_mode);
|
||||
|
||||
SLIST_FOREACH (mode, &modes, modes) {
|
||||
if (strcmp(mode->name, new_mode) != 0)
|
||||
if (strcmp(mode->name, new_mode) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ungrab_all_keys(conn);
|
||||
bindings = mode->bindings;
|
||||
@ -637,8 +657,9 @@ void switch_mode(const char *new_mode) {
|
||||
* activating one of them. */
|
||||
Binding *bind;
|
||||
TAILQ_FOREACH (bind, bindings, bindings) {
|
||||
if (bind->release == B_UPON_KEYRELEASE_IGNORE_MODS)
|
||||
if (bind->release == B_UPON_KEYRELEASE_IGNORE_MODS) {
|
||||
bind->release = B_UPON_KEYRELEASE;
|
||||
}
|
||||
}
|
||||
|
||||
char *event_msg;
|
||||
@ -713,8 +734,9 @@ void reorder_bindings(void) {
|
||||
SLIST_FOREACH (mode, &modes, modes) {
|
||||
const bool current_mode = (mode->bindings == bindings);
|
||||
reorder_bindings_of_mode(mode);
|
||||
if (current_mode)
|
||||
if (current_mode) {
|
||||
bindings = mode->bindings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -791,10 +813,12 @@ void check_for_duplicate_bindings(struct context *context) {
|
||||
static Binding *binding_copy(Binding *bind) {
|
||||
Binding *ret = smalloc(sizeof(Binding));
|
||||
*ret = *bind;
|
||||
if (bind->symbol != NULL)
|
||||
if (bind->symbol != NULL) {
|
||||
ret->symbol = sstrdup(bind->symbol);
|
||||
if (bind->command != NULL)
|
||||
}
|
||||
if (bind->command != NULL) {
|
||||
ret->command = sstrdup(bind->command);
|
||||
}
|
||||
TAILQ_INIT(&(ret->keycodes_head));
|
||||
struct Binding_Keycode *binding_keycode;
|
||||
TAILQ_FOREACH (binding_keycode, &(bind->keycodes_head), keycodes) {
|
||||
@ -838,10 +862,11 @@ CommandResult *run_binding(Binding *bind, Con *con) {
|
||||
/* We need to copy the binding and command since “reload” may be part of
|
||||
* the command, and then the memory that bind points to may not contain the
|
||||
* same data anymore. */
|
||||
if (con == NULL)
|
||||
if (con == NULL) {
|
||||
command = sstrdup(bind->command);
|
||||
else
|
||||
} else {
|
||||
sasprintf(&command, "[con_id=\"%p\"] %s", con, bind->command);
|
||||
}
|
||||
|
||||
Binding *bind_cp = binding_copy(bind);
|
||||
/* The "mode" command might change the current mode, so back it up to
|
||||
@ -851,8 +876,9 @@ CommandResult *run_binding(Binding *bind, Con *con) {
|
||||
CommandResult *result = parse_command(command, NULL, NULL);
|
||||
free(command);
|
||||
|
||||
if (result->needs_tree_render)
|
||||
if (result->needs_tree_render) {
|
||||
tree_render();
|
||||
}
|
||||
|
||||
if (result->parse_error) {
|
||||
char *pageraction;
|
||||
@ -886,8 +912,9 @@ static int fill_rmlvo_from_root(struct xkb_rule_names *xkb_names) {
|
||||
|
||||
atom_reply = xcb_intern_atom_reply(
|
||||
conn, xcb_intern_atom(conn, 0, strlen("_XKB_RULES_NAMES"), "_XKB_RULES_NAMES"), NULL);
|
||||
if (atom_reply == NULL)
|
||||
if (atom_reply == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
xcb_get_property_cookie_t prop_cookie;
|
||||
xcb_get_property_reply_t *prop_reply;
|
||||
@ -1021,12 +1048,14 @@ int *bindings_get_buttons_to_grab(void) {
|
||||
|
||||
Binding *bind;
|
||||
TAILQ_FOREACH (bind, bindings, bindings) {
|
||||
if (num + 1 == num_max)
|
||||
if (num + 1 == num_max) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* We are only interested in whole window mouse bindings. */
|
||||
if (bind->input_type != B_MOUSE || !bind->whole_window)
|
||||
if (bind->input_type != B_MOUSE || !bind->whole_window) {
|
||||
continue;
|
||||
}
|
||||
|
||||
long button;
|
||||
if (!parse_long(bind->symbol + (sizeof("button") - 1), &button, 10)) {
|
||||
|
30
src/click.c
30
src/click.c
@ -95,23 +95,27 @@ static bool floating_mod_on_tiled_client(Con *con, xcb_button_press_event_t *eve
|
||||
|
||||
if (to_right < to_left &&
|
||||
to_right < to_top &&
|
||||
to_right < to_bottom)
|
||||
to_right < to_bottom) {
|
||||
return tiling_resize_for_border(con, BORDER_RIGHT, event, false);
|
||||
}
|
||||
|
||||
if (to_left < to_right &&
|
||||
to_left < to_top &&
|
||||
to_left < to_bottom)
|
||||
to_left < to_bottom) {
|
||||
return tiling_resize_for_border(con, BORDER_LEFT, event, false);
|
||||
}
|
||||
|
||||
if (to_top < to_right &&
|
||||
to_top < to_left &&
|
||||
to_top < to_bottom)
|
||||
to_top < to_bottom) {
|
||||
return tiling_resize_for_border(con, BORDER_TOP, event, false);
|
||||
}
|
||||
|
||||
if (to_bottom < to_right &&
|
||||
to_bottom < to_left &&
|
||||
to_bottom < to_top)
|
||||
to_bottom < to_top) {
|
||||
return tiling_resize_for_border(con, BORDER_BOTTOM, event, false);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -130,19 +134,23 @@ static bool tiling_resize(Con *con, xcb_button_press_event_t *event, const click
|
||||
return tiling_resize_for_border(con, BORDER_TOP, event, use_threshold);
|
||||
} else if (dest == CLICK_BORDER) {
|
||||
if (event->event_y >= 0 && event->event_y <= (int32_t)bsr.y &&
|
||||
event->event_x >= (int32_t)bsr.x && event->event_x <= (int32_t)(con->rect.width + bsr.width))
|
||||
event->event_x >= (int32_t)bsr.x && event->event_x <= (int32_t)(con->rect.width + bsr.width)) {
|
||||
return tiling_resize_for_border(con, BORDER_TOP, event, false);
|
||||
}
|
||||
}
|
||||
if (event->event_x >= 0 && event->event_x <= (int32_t)bsr.x &&
|
||||
event->event_y >= (int32_t)bsr.y && event->event_y <= (int32_t)(con->rect.height + bsr.height))
|
||||
event->event_y >= (int32_t)bsr.y && event->event_y <= (int32_t)(con->rect.height + bsr.height)) {
|
||||
return tiling_resize_for_border(con, BORDER_LEFT, event, false);
|
||||
}
|
||||
|
||||
if (event->event_x >= (int32_t)(con->window_rect.x + con->window_rect.width) &&
|
||||
event->event_y >= (int32_t)bsr.y && event->event_y <= (int32_t)(con->rect.height + bsr.height))
|
||||
event->event_y >= (int32_t)bsr.y && event->event_y <= (int32_t)(con->rect.height + bsr.height)) {
|
||||
return tiling_resize_for_border(con, BORDER_RIGHT, event, false);
|
||||
}
|
||||
|
||||
if (event->event_y >= (int32_t)(con->window_rect.y + con->window_rect.height))
|
||||
if (event->event_y >= (int32_t)(con->window_rect.y + con->window_rect.height)) {
|
||||
return tiling_resize_for_border(con, BORDER_BOTTOM, event, false);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -393,8 +401,9 @@ void handle_button_press(xcb_button_press_event_t *event) {
|
||||
Con *output, *ws;
|
||||
TAILQ_FOREACH (output, &(croot->nodes_head), nodes) {
|
||||
if (con_is_internal(output) ||
|
||||
!rect_contains(output->rect, event->event_x, event->event_y))
|
||||
!rect_contains(output->rect, event->event_x, event->event_y)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ws = TAILQ_FIRST(&(output_get_content(output)->focus_head));
|
||||
if (ws != con_get_workspace(focused)) {
|
||||
@ -421,8 +430,9 @@ void handle_button_press(xcb_button_press_event_t *event) {
|
||||
} else {
|
||||
Con *child;
|
||||
TAILQ_FOREACH_REVERSE (child, &(con->nodes_head), nodes_head, nodes) {
|
||||
if (!rect_contains(child->deco_rect, event->event_x, event->event_y))
|
||||
if (!rect_contains(child->deco_rect, event->event_x, event->event_y)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
route_click(child, event, mod_pressed, CLICK_DECORATION);
|
||||
return;
|
||||
|
115
src/commands.c
115
src/commands.c
@ -84,8 +84,9 @@ static bool maybe_back_and_forth(struct CommandResultIR *cmd_output, const char
|
||||
Con *ws = con_get_workspace(focused);
|
||||
|
||||
/* If we switched to a different workspace, do nothing */
|
||||
if (strcmp(ws->name, name) != 0)
|
||||
if (strcmp(ws->name, name) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DLOG("This workspace is already focused.\n");
|
||||
if (config.workspace_auto_back_and_forth) {
|
||||
@ -102,8 +103,9 @@ static bool maybe_back_and_forth(struct CommandResultIR *cmd_output, const char
|
||||
static Con *maybe_auto_back_and_forth_workspace(Con *workspace) {
|
||||
Con *current, *baf;
|
||||
|
||||
if (!config.workspace_auto_back_and_forth)
|
||||
if (!config.workspace_auto_back_and_forth) {
|
||||
return workspace;
|
||||
}
|
||||
|
||||
current = con_get_workspace(focused);
|
||||
|
||||
@ -206,8 +208,9 @@ void cmd_criteria_match_windows(I3_CMD) {
|
||||
|
||||
mark_t *mark;
|
||||
TAILQ_FOREACH (mark, &(current->con->marks_head), marks) {
|
||||
if (!regex_matches(current_match->mark, mark->name))
|
||||
if (!regex_matches(current_match->mark, mark->name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DLOG("match by mark\n");
|
||||
matched_by_mark = true;
|
||||
@ -301,17 +304,17 @@ void cmd_move_con_to_workspace(I3_CMD, const char *which) {
|
||||
|
||||
/* get the workspace */
|
||||
Con *ws;
|
||||
if (strcmp(which, "next") == 0)
|
||||
if (strcmp(which, "next") == 0) {
|
||||
ws = workspace_next();
|
||||
else if (strcmp(which, "prev") == 0)
|
||||
} else if (strcmp(which, "prev") == 0) {
|
||||
ws = workspace_prev();
|
||||
else if (strcmp(which, "next_on_output") == 0)
|
||||
} else if (strcmp(which, "next_on_output") == 0) {
|
||||
ws = workspace_next_on_output();
|
||||
else if (strcmp(which, "prev_on_output") == 0)
|
||||
} else if (strcmp(which, "prev_on_output") == 0) {
|
||||
ws = workspace_prev_on_output();
|
||||
else if (strcmp(which, "current") == 0)
|
||||
} else if (strcmp(which, "current") == 0) {
|
||||
ws = con_get_workspace(focused);
|
||||
else {
|
||||
} else {
|
||||
yerror("BUG: called with which=%s", which);
|
||||
return;
|
||||
}
|
||||
@ -521,8 +524,9 @@ static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *dir
|
||||
Con *child;
|
||||
TAILQ_FOREACH (child, &(current->parent->nodes_head), nodes) {
|
||||
LOG("child->percent = %f (child %p)\n", child->percent, child);
|
||||
if (child->percent == 0.0)
|
||||
if (child->percent == 0.0) {
|
||||
child->percent = percentage;
|
||||
}
|
||||
}
|
||||
|
||||
double new_current_percent;
|
||||
@ -559,8 +563,9 @@ static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *dir
|
||||
LOG("current->percent after = %f\n", current->percent);
|
||||
|
||||
TAILQ_FOREACH (child, &(current->parent->nodes_head), nodes) {
|
||||
if (child == current)
|
||||
if (child == current) {
|
||||
continue;
|
||||
}
|
||||
child->percent -= subtract_percent;
|
||||
LOG("child->percent after (%p) = %f\n", child, child->percent);
|
||||
}
|
||||
@ -808,8 +813,9 @@ void cmd_append_layout(I3_CMD, const char *cpath) {
|
||||
* container must not have any children (by definition).
|
||||
* Note that we explicitly check for workspaces, since they are okay for
|
||||
* this purpose, but con_accepts_window() returns false for workspaces. */
|
||||
while (parent->type != CT_WORKSPACE && !con_accepts_window(parent))
|
||||
while (parent->type != CT_WORKSPACE && !con_accepts_window(parent)) {
|
||||
parent = parent->parent;
|
||||
}
|
||||
}
|
||||
DLOG("Appending to parent=%p instead of focused=%p\n", parent, focused);
|
||||
char *errormsg = NULL;
|
||||
@ -835,8 +841,9 @@ void cmd_append_layout(I3_CMD, const char *cpath) {
|
||||
|
||||
restore_open_placeholder_windows(parent);
|
||||
|
||||
if (content == JSON_CONTENT_WORKSPACE)
|
||||
if (content == JSON_CONTENT_WORKSPACE) {
|
||||
ipc_send_workspace_event("restored", parent, NULL);
|
||||
}
|
||||
|
||||
cmd_output->needs_tree_render = true;
|
||||
out:
|
||||
@ -862,15 +869,15 @@ void cmd_workspace(I3_CMD, const char *which) {
|
||||
|
||||
disable_global_fullscreen();
|
||||
|
||||
if (strcmp(which, "next") == 0)
|
||||
if (strcmp(which, "next") == 0) {
|
||||
ws = workspace_next();
|
||||
else if (strcmp(which, "prev") == 0)
|
||||
} else if (strcmp(which, "prev") == 0) {
|
||||
ws = workspace_prev();
|
||||
else if (strcmp(which, "next_on_output") == 0)
|
||||
} else if (strcmp(which, "next_on_output") == 0) {
|
||||
ws = workspace_next_on_output();
|
||||
else if (strcmp(which, "prev_on_output") == 0)
|
||||
} else if (strcmp(which, "prev_on_output") == 0) {
|
||||
ws = workspace_prev_on_output();
|
||||
else {
|
||||
} else {
|
||||
yerror("BUG: called with which=%s", which);
|
||||
return;
|
||||
}
|
||||
@ -1241,17 +1248,18 @@ void cmd_split(I3_CMD, const char *direction) {
|
||||
*
|
||||
*/
|
||||
void cmd_kill(I3_CMD, const char *kill_mode_str) {
|
||||
if (kill_mode_str == NULL)
|
||||
if (kill_mode_str == NULL) {
|
||||
kill_mode_str = "window";
|
||||
}
|
||||
|
||||
DLOG("kill_mode=%s\n", kill_mode_str);
|
||||
|
||||
int kill_mode;
|
||||
if (strcmp(kill_mode_str, "window") == 0)
|
||||
if (strcmp(kill_mode_str, "window") == 0) {
|
||||
kill_mode = KILL_WINDOW;
|
||||
else if (strcmp(kill_mode_str, "client") == 0)
|
||||
} else if (strcmp(kill_mode_str, "client") == 0) {
|
||||
kill_mode = KILL_CLIENT;
|
||||
else {
|
||||
} else {
|
||||
yerror("BUG: called with kill_mode=%s", kill_mode_str);
|
||||
return;
|
||||
}
|
||||
@ -1406,8 +1414,9 @@ void cmd_focus_window_mode(I3_CMD, const char *window_mode) {
|
||||
bool success = false;
|
||||
TAILQ_FOREACH (current, &(ws->focus_head), focused) {
|
||||
if ((to_floating && current->type != CT_FLOATING_CON) ||
|
||||
(!to_floating && current->type == CT_FLOATING_CON))
|
||||
(!to_floating && current->type == CT_FLOATING_CON)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
con_activate_unblock(con_descend_focused(current));
|
||||
success = true;
|
||||
@ -1434,16 +1443,18 @@ void cmd_focus_level(I3_CMD, const char *level) {
|
||||
* focused container won't escape the fullscreen container. */
|
||||
if (strcmp(level, "parent") == 0) {
|
||||
if (focused && focused->parent) {
|
||||
if (con_fullscreen_permits_focusing(focused->parent))
|
||||
if (con_fullscreen_permits_focusing(focused->parent)) {
|
||||
success = level_up();
|
||||
else
|
||||
} else {
|
||||
ELOG("'focus parent': Currently in fullscreen, not going up\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Focusing a child should always be allowed. */
|
||||
else
|
||||
else {
|
||||
success = level_down();
|
||||
}
|
||||
|
||||
cmd_output->needs_tree_render = success;
|
||||
// XXX: default reply for now, make this a better reply
|
||||
@ -1549,12 +1560,13 @@ void cmd_sticky(I3_CMD, const char *action) {
|
||||
DLOG("setting sticky for container = %p / %s\n", current->con, current->con->name);
|
||||
|
||||
bool sticky = false;
|
||||
if (strcmp(action, "enable") == 0)
|
||||
if (strcmp(action, "enable") == 0) {
|
||||
sticky = true;
|
||||
else if (strcmp(action, "disable") == 0)
|
||||
} else if (strcmp(action, "disable") == 0) {
|
||||
sticky = false;
|
||||
else if (strcmp(action, "toggle") == 0)
|
||||
} else if (strcmp(action, "toggle") == 0) {
|
||||
sticky = !current->con->sticky;
|
||||
}
|
||||
|
||||
current->con->sticky = sticky;
|
||||
ewmh_update_sticky(current->con->window->id, sticky);
|
||||
@ -1653,15 +1665,16 @@ void cmd_layout(I3_CMD, const char *layout_str) {
|
||||
void cmd_layout_toggle(I3_CMD, const char *toggle_mode) {
|
||||
owindow *current;
|
||||
|
||||
if (toggle_mode == NULL)
|
||||
if (toggle_mode == NULL) {
|
||||
toggle_mode = "default";
|
||||
}
|
||||
|
||||
DLOG("toggling layout (mode = %s)\n", toggle_mode);
|
||||
|
||||
/* check if the match is empty, not if the result is empty */
|
||||
if (match_is_empty(current_match))
|
||||
if (match_is_empty(current_match)) {
|
||||
con_toggle_layout(focused, toggle_mode);
|
||||
else {
|
||||
} else {
|
||||
TAILQ_FOREACH (current, &owindows, owindows) {
|
||||
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
||||
con_toggle_layout(current->con, toggle_mode);
|
||||
@ -1850,8 +1863,9 @@ void cmd_move_window_to_position(I3_CMD, long x, const char *mode_x, long y, con
|
||||
}
|
||||
}
|
||||
|
||||
if (!has_error)
|
||||
if (!has_error) {
|
||||
ysuccess(true);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1894,8 +1908,9 @@ void cmd_move_window_to_center(I3_CMD, const char *method) {
|
||||
}
|
||||
|
||||
// XXX: default reply for now, make this a better reply
|
||||
if (!has_error)
|
||||
if (!has_error) {
|
||||
ysuccess(true);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2215,15 +2230,15 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
|
||||
void cmd_bar_mode(I3_CMD, const char *bar_mode, const char *bar_id) {
|
||||
int mode = M_DOCK;
|
||||
bool toggle = false;
|
||||
if (strcmp(bar_mode, "dock") == 0)
|
||||
if (strcmp(bar_mode, "dock") == 0) {
|
||||
mode = M_DOCK;
|
||||
else if (strcmp(bar_mode, "hide") == 0)
|
||||
} else if (strcmp(bar_mode, "hide") == 0) {
|
||||
mode = M_HIDE;
|
||||
else if (strcmp(bar_mode, "invisible") == 0)
|
||||
} else if (strcmp(bar_mode, "invisible") == 0) {
|
||||
mode = M_INVISIBLE;
|
||||
else if (strcmp(bar_mode, "toggle") == 0)
|
||||
} else if (strcmp(bar_mode, "toggle") == 0) {
|
||||
toggle = true;
|
||||
else {
|
||||
} else {
|
||||
ELOG("Unknown bar mode \"%s\", this is a mismatch between code and parser spec.\n", bar_mode);
|
||||
assert(false);
|
||||
}
|
||||
@ -2274,13 +2289,13 @@ void cmd_bar_mode(I3_CMD, const char *bar_mode, const char *bar_id) {
|
||||
void cmd_bar_hidden_state(I3_CMD, const char *bar_hidden_state, const char *bar_id) {
|
||||
int hidden_state = S_SHOW;
|
||||
bool toggle = false;
|
||||
if (strcmp(bar_hidden_state, "hide") == 0)
|
||||
if (strcmp(bar_hidden_state, "hide") == 0) {
|
||||
hidden_state = S_HIDE;
|
||||
else if (strcmp(bar_hidden_state, "show") == 0)
|
||||
} else if (strcmp(bar_hidden_state, "show") == 0) {
|
||||
hidden_state = S_SHOW;
|
||||
else if (strcmp(bar_hidden_state, "toggle") == 0)
|
||||
} else if (strcmp(bar_hidden_state, "toggle") == 0) {
|
||||
toggle = true;
|
||||
else {
|
||||
} else {
|
||||
ELOG("Unknown bar state \"%s\", this is a mismatch between code and parser spec.\n", bar_hidden_state);
|
||||
assert(false);
|
||||
}
|
||||
@ -2329,14 +2344,14 @@ void cmd_bar_hidden_state(I3_CMD, const char *bar_hidden_state, const char *bar_
|
||||
*
|
||||
*/
|
||||
void cmd_shmlog(I3_CMD, const char *argument) {
|
||||
if (!strcmp(argument, "toggle"))
|
||||
if (!strcmp(argument, "toggle")) {
|
||||
/* Toggle shm log, if size is not 0. If it is 0, set it to default. */
|
||||
shmlog_size = shmlog_size ? -shmlog_size : default_shmlog_size;
|
||||
else if (!strcmp(argument, "on"))
|
||||
} else if (!strcmp(argument, "on")) {
|
||||
shmlog_size = default_shmlog_size;
|
||||
else if (!strcmp(argument, "off"))
|
||||
} else if (!strcmp(argument, "off")) {
|
||||
shmlog_size = 0;
|
||||
else {
|
||||
} else {
|
||||
long new_size = 0;
|
||||
if (!parse_long(argument, &new_size, 0)) {
|
||||
yerror("Failed to parse %s into a shmlog size.", argument);
|
||||
@ -2410,11 +2425,11 @@ static bool gaps_update(gap_accessor get, const char *scope, const char *mode, i
|
||||
DLOG("global_gap_size=%d, current_value=%d\n", global_gap_size, current_value);
|
||||
|
||||
bool reset = false;
|
||||
if (strcmp(mode, "plus") == 0)
|
||||
if (strcmp(mode, "plus") == 0) {
|
||||
current_value += pixels;
|
||||
else if (strcmp(mode, "minus") == 0)
|
||||
} else if (strcmp(mode, "minus") == 0) {
|
||||
current_value -= pixels;
|
||||
else if (strcmp(mode, "set") == 0) {
|
||||
} else if (strcmp(mode, "set") == 0) {
|
||||
current_value = pixels;
|
||||
reset = true;
|
||||
} else if (strcmp(mode, "toggle") == 0) {
|
||||
|
@ -63,8 +63,9 @@ typedef struct tokenptr {
|
||||
*/
|
||||
static void push_string(struct stack *stack, const char *identifier, char *str) {
|
||||
for (int c = 0; c < 10; c++) {
|
||||
if (stack->stack[c].identifier != NULL)
|
||||
if (stack->stack[c].identifier != NULL) {
|
||||
continue;
|
||||
}
|
||||
/* Found a free slot, let’s store it here. */
|
||||
stack->stack[c].identifier = identifier;
|
||||
stack->stack[c].val.str = str;
|
||||
@ -106,10 +107,12 @@ static void push_long(struct stack *stack, const char *identifier, long num) {
|
||||
// TODO move to a common util
|
||||
static const char *get_string(struct stack *stack, const char *identifier) {
|
||||
for (int c = 0; c < 10; c++) {
|
||||
if (stack->stack[c].identifier == NULL)
|
||||
if (stack->stack[c].identifier == NULL) {
|
||||
break;
|
||||
if (strcmp(identifier, stack->stack[c].identifier) == 0)
|
||||
}
|
||||
if (strcmp(identifier, stack->stack[c].identifier) == 0) {
|
||||
return stack->stack[c].val.str;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -117,10 +120,12 @@ static const char *get_string(struct stack *stack, const char *identifier) {
|
||||
// TODO move to a common util
|
||||
static long get_long(struct stack *stack, const char *identifier) {
|
||||
for (int c = 0; c < 10; c++) {
|
||||
if (stack->stack[c].identifier == NULL)
|
||||
if (stack->stack[c].identifier == NULL) {
|
||||
break;
|
||||
if (strcmp(identifier, stack->stack[c].identifier) == 0)
|
||||
}
|
||||
if (strcmp(identifier, stack->stack[c].identifier) == 0) {
|
||||
return stack->stack[c].val.num;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -129,8 +134,9 @@ static long get_long(struct stack *stack, const char *identifier) {
|
||||
// TODO move to a common util
|
||||
static void clear_stack(struct stack *stack) {
|
||||
for (int c = 0; c < 10; c++) {
|
||||
if (stack->stack[c].type == STACK_STR)
|
||||
if (stack->stack[c].type == STACK_STR) {
|
||||
free(stack->stack[c].val.str);
|
||||
}
|
||||
stack->stack[c].identifier = NULL;
|
||||
stack->stack[c].val.str = NULL;
|
||||
stack->stack[c].val.num = 0;
|
||||
@ -162,8 +168,9 @@ static void next_state(const cmdp_token *token) {
|
||||
state = subcommand_output.next_state;
|
||||
/* If any subcommand requires a tree_render(), we need to make the
|
||||
* whole parser result request a tree_render(). */
|
||||
if (subcommand_output.needs_tree_render)
|
||||
if (subcommand_output.needs_tree_render) {
|
||||
command_output.needs_tree_render = true;
|
||||
}
|
||||
clear_stack(&stack);
|
||||
return;
|
||||
}
|
||||
@ -186,9 +193,11 @@ char *parse_string(const char **walk, bool as_word) {
|
||||
if (**walk == '"') {
|
||||
beginning++;
|
||||
(*walk)++;
|
||||
for (; **walk != '\0' && **walk != '"'; (*walk)++)
|
||||
if (**walk == '\\' && *(*walk + 1) != '\0')
|
||||
for (; **walk != '\0' && **walk != '"'; (*walk)++) {
|
||||
if (**walk == '\\' && *(*walk + 1) != '\0') {
|
||||
(*walk)++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!as_word) {
|
||||
/* For a string (starting with 's'), the delimiters are
|
||||
@ -197,8 +206,9 @@ char *parse_string(const char **walk, bool as_word) {
|
||||
* end a command. */
|
||||
while (**walk != ';' && **walk != ',' &&
|
||||
**walk != '\0' && **walk != '\r' &&
|
||||
**walk != '\n')
|
||||
**walk != '\n') {
|
||||
(*walk)++;
|
||||
}
|
||||
} else {
|
||||
/* For a word, the delimiters are white space (' ' or
|
||||
* '\t'), closing square bracket (]), comma (,) and
|
||||
@ -206,12 +216,14 @@ char *parse_string(const char **walk, bool as_word) {
|
||||
while (**walk != ' ' && **walk != '\t' &&
|
||||
**walk != ']' && **walk != ',' &&
|
||||
**walk != ';' && **walk != '\r' &&
|
||||
**walk != '\n' && **walk != '\0')
|
||||
**walk != '\n' && **walk != '\0') {
|
||||
(*walk)++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (*walk == beginning)
|
||||
if (*walk == beginning) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *str = scalloc(*walk - beginning + 1, 1);
|
||||
/* We copy manually to handle escaping of characters. */
|
||||
@ -222,8 +234,9 @@ char *parse_string(const char **walk, bool as_word) {
|
||||
/* We only handle escaped double quotes and backslashes to not break
|
||||
* backwards compatibility with people using \w in regular expressions
|
||||
* etc. */
|
||||
if (beginning[inpos] == '\\' && (beginning[inpos + 1] == '"' || beginning[inpos + 1] == '\\'))
|
||||
if (beginning[inpos] == '\\' && (beginning[inpos + 1] == '"' || beginning[inpos + 1] == '\\')) {
|
||||
inpos++;
|
||||
}
|
||||
str[outpos] = beginning[inpos];
|
||||
}
|
||||
|
||||
@ -267,8 +280,9 @@ CommandResult *parse_command(const char *input, yajl_gen gen, ipc_client *client
|
||||
/* skip whitespace and newlines before every token */
|
||||
while ((*walk == ' ' || *walk == '\t' ||
|
||||
*walk == '\r' || *walk == '\n') &&
|
||||
*walk != '\0')
|
||||
*walk != '\0') {
|
||||
walk++;
|
||||
}
|
||||
|
||||
cmdp_token_ptr *ptr = &(tokens[state]);
|
||||
token_handled = false;
|
||||
@ -295,12 +309,14 @@ CommandResult *parse_command(const char *input, yajl_gen gen, ipc_client *client
|
||||
errno = 0;
|
||||
long int num = strtol(walk, &end, 10);
|
||||
if ((errno == ERANGE && (num == LONG_MIN || num == LONG_MAX)) ||
|
||||
(errno != 0 && num == 0))
|
||||
(errno != 0 && num == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* No valid numbers found */
|
||||
if (end == walk)
|
||||
if (end == walk) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (token->identifier != NULL) {
|
||||
push_long(&stack, token->identifier, num);
|
||||
@ -322,8 +338,9 @@ CommandResult *parse_command(const char *input, yajl_gen gen, ipc_client *client
|
||||
}
|
||||
/* If we are at the end of a quoted string, skip the ending
|
||||
* double quote. */
|
||||
if (*walk == '"')
|
||||
if (*walk == '"') {
|
||||
walk++;
|
||||
}
|
||||
next_state(token);
|
||||
token_handled = true;
|
||||
break;
|
||||
@ -340,8 +357,9 @@ CommandResult *parse_command(const char *input, yajl_gen gen, ipc_client *client
|
||||
* every command. */
|
||||
// TODO: make this testable
|
||||
#ifndef TEST_PARSER
|
||||
if (*walk == '\0' || *walk == ';')
|
||||
if (*walk == '\0' || *walk == ';') {
|
||||
cmd_criteria_init(¤t_match, &subcommand_output);
|
||||
}
|
||||
#endif
|
||||
walk++;
|
||||
break;
|
||||
@ -353,8 +371,9 @@ CommandResult *parse_command(const char *input, yajl_gen gen, ipc_client *client
|
||||
/* Figure out how much memory we will need to fill in the names of
|
||||
* all tokens afterwards. */
|
||||
int tokenlen = 0;
|
||||
for (c = 0; c < ptr->n; c++)
|
||||
for (c = 0; c < ptr->n; c++) {
|
||||
tokenlen += strlen(ptr->array[c].name) + strlen("'', ");
|
||||
}
|
||||
|
||||
/* Build up a decent error message. We include the problem, the
|
||||
* full input, and underline the position where the parser
|
||||
@ -392,8 +411,9 @@ CommandResult *parse_command(const char *input, yajl_gen gen, ipc_client *client
|
||||
/* Contains the same amount of characters as 'input' has, but with
|
||||
* the unparsable part highlighted using ^ characters. */
|
||||
char *position = smalloc(len + 1);
|
||||
for (const char *copywalk = input; *copywalk != '\0'; copywalk++)
|
||||
for (const char *copywalk = input; *copywalk != '\0'; copywalk++) {
|
||||
position[(copywalk - input)] = (copywalk >= walk ? '^' : ' ');
|
||||
}
|
||||
position[len] = '\0';
|
||||
|
||||
ELOG("%s\n", errormessage);
|
||||
@ -436,8 +456,9 @@ CommandResult *parse_command(const char *input, yajl_gen gen, ipc_client *client
|
||||
* Frees a CommandResult
|
||||
*/
|
||||
void command_result_free(CommandResult *result) {
|
||||
if (result == NULL)
|
||||
if (result == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
FREE(result->error_message);
|
||||
FREE(result);
|
||||
|
270
src/con.c
270
src/con.c
@ -57,8 +57,9 @@ Con *con_new_skeleton(Con *parent, i3Window *window) {
|
||||
TAILQ_INIT(&(new->swallow_head));
|
||||
TAILQ_INIT(&(new->marks_head));
|
||||
|
||||
if (parent != NULL)
|
||||
if (parent != NULL) {
|
||||
con_attach(new, parent, false);
|
||||
}
|
||||
|
||||
return new;
|
||||
}
|
||||
@ -123,10 +124,11 @@ static void _con_attach(Con *con, Con *parent, Con *previous, bool ignore_focus)
|
||||
}
|
||||
}
|
||||
/* we need to insert con after current, if current is not NULL */
|
||||
if (current)
|
||||
if (current) {
|
||||
TAILQ_INSERT_BEFORE(current, con, nodes);
|
||||
else
|
||||
} else {
|
||||
TAILQ_INSERT_TAIL(nodes_head, con, nodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
goto add_to_focus_head;
|
||||
@ -163,8 +165,9 @@ static void _con_attach(Con *con, Con *parent, Con *previous, bool ignore_focus)
|
||||
if (!ignore_focus) {
|
||||
/* Get the first tiling container in focus stack */
|
||||
TAILQ_FOREACH (loop, &(parent->focus_head), focused) {
|
||||
if (loop->type == CT_FLOATING_CON)
|
||||
if (loop->type == CT_FLOATING_CON) {
|
||||
continue;
|
||||
}
|
||||
current = loop;
|
||||
break;
|
||||
}
|
||||
@ -197,8 +200,9 @@ static void _con_attach(Con *con, Con *parent, Con *previous, bool ignore_focus)
|
||||
if (current != NULL && parent->type != CT_OUTPUT) {
|
||||
DLOG("Inserting con = %p after con %p\n", con, current);
|
||||
TAILQ_INSERT_AFTER(nodes_head, current, con, nodes);
|
||||
} else
|
||||
} else {
|
||||
TAILQ_INSERT_TAIL(nodes_head, con, nodes);
|
||||
}
|
||||
}
|
||||
|
||||
add_to_focus_head:
|
||||
@ -251,8 +255,9 @@ void con_focus(Con *con) {
|
||||
/* 2: exchange the position of the container in focus stack of the parent all the way up */
|
||||
TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
|
||||
TAILQ_INSERT_HEAD(&(con->parent->focus_head), con, focused);
|
||||
if (con->parent->parent != NULL)
|
||||
if (con->parent->parent != NULL) {
|
||||
con_focus(con->parent);
|
||||
}
|
||||
|
||||
focused = con;
|
||||
/* We can't blindly reset non-leaf containers since they might have
|
||||
@ -383,8 +388,9 @@ bool con_has_children(Con *con) {
|
||||
*
|
||||
*/
|
||||
bool con_is_split(Con *con) {
|
||||
if (con_is_leaf(con))
|
||||
if (con_is_leaf(con)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (con->layout) {
|
||||
case L_DOCKAREA:
|
||||
@ -409,8 +415,9 @@ bool con_is_hidden(Con *con) {
|
||||
while (current != NULL && current->type != CT_WORKSPACE) {
|
||||
Con *parent = current->parent;
|
||||
if (parent != NULL && (parent->layout == L_TABBED || parent->layout == L_STACKED)) {
|
||||
if (TAILQ_FIRST(&(parent->focus_head)) != current)
|
||||
if (TAILQ_FIRST(&(parent->focus_head)) != current) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
current = parent;
|
||||
@ -483,13 +490,15 @@ bool con_is_maximized(Con *con, orientation_t orientation) {
|
||||
*
|
||||
*/
|
||||
bool con_is_sticky(Con *con) {
|
||||
if (con->sticky)
|
||||
if (con->sticky) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Con *child;
|
||||
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
|
||||
if (con_is_sticky(child))
|
||||
if (con_is_sticky(child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -502,8 +511,9 @@ bool con_is_sticky(Con *con) {
|
||||
*/
|
||||
bool con_accepts_window(Con *con) {
|
||||
/* 1: workspaces never accept direct windows */
|
||||
if (con->type == CT_WORKSPACE)
|
||||
if (con->type == CT_WORKSPACE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (con_is_split(con)) {
|
||||
DLOG("container %p does not accept windows, it is a split container.\n", con);
|
||||
@ -521,8 +531,9 @@ bool con_accepts_window(Con *con) {
|
||||
*/
|
||||
Con *con_get_output(Con *con) {
|
||||
Con *result = con;
|
||||
while (result != NULL && result->type != CT_OUTPUT)
|
||||
while (result != NULL && result->type != CT_OUTPUT) {
|
||||
result = result->parent;
|
||||
}
|
||||
/* We must be able to get an output because focus can never be set higher
|
||||
* in the tree (root node cannot be focused). */
|
||||
assert(result != NULL);
|
||||
@ -535,8 +546,9 @@ Con *con_get_output(Con *con) {
|
||||
*/
|
||||
Con *con_get_workspace(Con *con) {
|
||||
Con *result = con;
|
||||
while (result != NULL && result->type != CT_WORKSPACE)
|
||||
while (result != NULL && result->type != CT_WORKSPACE) {
|
||||
result = result->parent;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -548,8 +560,9 @@ Con *con_get_workspace(Con *con) {
|
||||
Con *con_parent_with_orientation(Con *con, orientation_t orientation) {
|
||||
DLOG("Searching for parent of Con %p with orientation %d\n", con, orientation);
|
||||
Con *parent = con->parent;
|
||||
if (parent->type == CT_FLOATING_CON)
|
||||
if (parent->type == CT_FLOATING_CON) {
|
||||
return NULL;
|
||||
}
|
||||
while (con_orientation(parent) != orientation) {
|
||||
DLOG("Need to go one level further up\n");
|
||||
parent = parent->parent;
|
||||
@ -557,10 +570,12 @@ Con *con_parent_with_orientation(Con *con, orientation_t orientation) {
|
||||
if (parent &&
|
||||
(parent->type == CT_FLOATING_CON ||
|
||||
parent->type == CT_OUTPUT ||
|
||||
(parent->parent && parent->parent->type == CT_OUTPUT)))
|
||||
(parent->parent && parent->parent->type == CT_OUTPUT))) {
|
||||
parent = NULL;
|
||||
if (parent == NULL)
|
||||
}
|
||||
if (parent == NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
DLOG("Result: %p\n", parent);
|
||||
return parent;
|
||||
@ -662,11 +677,13 @@ bool con_is_floating(Con *con) {
|
||||
*
|
||||
*/
|
||||
bool con_is_docked(Con *con) {
|
||||
if (con->parent == NULL)
|
||||
if (con->parent == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (con->parent->type == CT_DOCKAREA)
|
||||
if (con->parent->type == CT_DOCKAREA) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return con_is_docked(con->parent);
|
||||
}
|
||||
@ -681,14 +698,17 @@ Con *con_inside_floating(Con *con) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (con->type == CT_FLOATING_CON)
|
||||
if (con->type == CT_FLOATING_CON) {
|
||||
return con;
|
||||
}
|
||||
|
||||
if (con->floating >= FLOATING_AUTO_ON)
|
||||
if (con->floating >= FLOATING_AUTO_ON) {
|
||||
return con->parent;
|
||||
}
|
||||
|
||||
if (con->type == CT_WORKSPACE || con->type == CT_OUTPUT)
|
||||
if (con->type == CT_WORKSPACE || con->type == CT_OUTPUT) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return con_inside_floating(con->parent);
|
||||
}
|
||||
@ -698,10 +718,12 @@ Con *con_inside_floating(Con *con) {
|
||||
*
|
||||
*/
|
||||
bool con_inside_focused(Con *con) {
|
||||
if (con == focused)
|
||||
if (con == focused) {
|
||||
return true;
|
||||
if (!con->parent)
|
||||
}
|
||||
if (!con->parent) {
|
||||
return false;
|
||||
}
|
||||
return con_inside_focused(con->parent);
|
||||
}
|
||||
|
||||
@ -785,8 +807,9 @@ Con *con_by_frame_id(xcb_window_t frame) {
|
||||
Con *con_by_mark(const char *mark) {
|
||||
Con *con;
|
||||
TAILQ_FOREACH (con, &all_cons, all_cons) {
|
||||
if (con_has_mark(con, mark))
|
||||
if (con_has_mark(con, mark)) {
|
||||
return con;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -834,8 +857,9 @@ bool con_find_transient_for_window(Con *start, xcb_window_t target) {
|
||||
bool con_has_mark(Con *con, const char *mark) {
|
||||
mark_t *current;
|
||||
TAILQ_FOREACH (current, &(con->marks_head), marks) {
|
||||
if (strcmp(current->name, mark) == 0)
|
||||
if (strcmp(current->name, mark) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -897,11 +921,13 @@ void con_unmark(Con *con, const char *name) {
|
||||
if (name == NULL) {
|
||||
DLOG("Unmarking all containers.\n");
|
||||
TAILQ_FOREACH (current, &all_cons, all_cons) {
|
||||
if (con != NULL && current != con)
|
||||
if (con != NULL && current != con) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (TAILQ_EMPTY(&(current->marks_head)))
|
||||
if (TAILQ_EMPTY(&(current->marks_head))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mark_t *mark;
|
||||
while (!TAILQ_EMPTY(&(current->marks_head))) {
|
||||
@ -928,8 +954,9 @@ void con_unmark(Con *con, const char *name) {
|
||||
|
||||
mark_t *mark;
|
||||
TAILQ_FOREACH (mark, &(current->marks_head), marks) {
|
||||
if (strcmp(mark->name, name) != 0)
|
||||
if (strcmp(mark->name, name) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
FREE(mark->name);
|
||||
TAILQ_REMOVE(&(current->marks_head), mark, marks);
|
||||
@ -952,28 +979,34 @@ Con *con_for_window(Con *con, i3Window *window, Match **store_match) {
|
||||
|
||||
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
|
||||
TAILQ_FOREACH (match, &(child->swallow_head), matches) {
|
||||
if (!match_matches_window(match, window))
|
||||
if (!match_matches_window(match, window)) {
|
||||
continue;
|
||||
if (store_match != NULL)
|
||||
}
|
||||
if (store_match != NULL) {
|
||||
*store_match = match;
|
||||
}
|
||||
return child;
|
||||
}
|
||||
Con *result = con_for_window(child, window, store_match);
|
||||
if (result != NULL)
|
||||
if (result != NULL) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
TAILQ_FOREACH (child, &(con->floating_head), floating_windows) {
|
||||
TAILQ_FOREACH (match, &(child->swallow_head), matches) {
|
||||
if (!match_matches_window(match, window))
|
||||
if (!match_matches_window(match, window)) {
|
||||
continue;
|
||||
if (store_match != NULL)
|
||||
}
|
||||
if (store_match != NULL) {
|
||||
*store_match = match;
|
||||
}
|
||||
return child;
|
||||
}
|
||||
Con *result = con_for_window(child, window, store_match);
|
||||
if (result != NULL)
|
||||
if (result != NULL) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -1056,18 +1089,21 @@ int con_num_children(Con *con) {
|
||||
* this will return 2 instead of 1.
|
||||
*/
|
||||
int con_num_visible_children(Con *con) {
|
||||
if (con == NULL)
|
||||
if (con == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int children = 0;
|
||||
Con *current = NULL;
|
||||
TAILQ_FOREACH (current, &(con->nodes_head), nodes) {
|
||||
/* Visible leaf nodes are a child. */
|
||||
if (!con_is_hidden(current) && con_is_leaf(current))
|
||||
if (!con_is_hidden(current) && con_is_leaf(current)) {
|
||||
children++;
|
||||
}
|
||||
/* All other containers need to be recursed. */
|
||||
else
|
||||
else {
|
||||
children += con_num_visible_children(current);
|
||||
}
|
||||
}
|
||||
|
||||
return children;
|
||||
@ -1078,11 +1114,13 @@ int con_num_visible_children(Con *con) {
|
||||
*
|
||||
*/
|
||||
int con_num_windows(Con *con) {
|
||||
if (con == NULL)
|
||||
if (con == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (con_has_managed_window(con))
|
||||
if (con_has_managed_window(con)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int num = 0;
|
||||
Con *current = NULL;
|
||||
@ -1159,10 +1197,11 @@ void con_toggle_fullscreen(Con *con, int fullscreen_mode) {
|
||||
|
||||
DLOG("toggling fullscreen for %p / %s\n", con, con->name);
|
||||
|
||||
if (con->fullscreen_mode == CF_NONE)
|
||||
if (con->fullscreen_mode == CF_NONE) {
|
||||
con_enable_fullscreen(con, fullscreen_mode);
|
||||
else
|
||||
} else {
|
||||
con_disable_fullscreen(con);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1182,8 +1221,9 @@ static void con_set_fullscreen_mode(Con *con, fullscreen_mode_t fullscreen_mode)
|
||||
/* update _NET_WM_STATE if this container has a window */
|
||||
/* TODO: when a window is assigned to a container which is already
|
||||
* fullscreened, this state needs to be pushed to the client, too */
|
||||
if (con->window == NULL)
|
||||
if (con->window == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (con->fullscreen_mode != CF_NONE) {
|
||||
DLOG("Setting _NET_WM_STATE_FULLSCREEN for con = %p / window = %d.\n", con, con->window->id);
|
||||
@ -1213,10 +1253,11 @@ void con_enable_fullscreen(Con *con, fullscreen_mode_t fullscreen_mode) {
|
||||
|
||||
assert(fullscreen_mode == CF_GLOBAL || fullscreen_mode == CF_OUTPUT);
|
||||
|
||||
if (fullscreen_mode == CF_GLOBAL)
|
||||
if (fullscreen_mode == CF_GLOBAL) {
|
||||
DLOG("enabling global fullscreen for %p / %s\n", con, con->name);
|
||||
else
|
||||
} else {
|
||||
DLOG("enabling fullscreen for %p / %s\n", con, con->name);
|
||||
}
|
||||
|
||||
if (con->fullscreen_mode == fullscreen_mode) {
|
||||
DLOG("fullscreen already enabled for %p / %s\n", con, con->name);
|
||||
@ -1227,21 +1268,25 @@ void con_enable_fullscreen(Con *con, fullscreen_mode_t fullscreen_mode) {
|
||||
|
||||
/* Disable any fullscreen container that would conflict the new one. */
|
||||
Con *fullscreen = con_get_fullscreen_con(croot, CF_GLOBAL);
|
||||
if (fullscreen == NULL)
|
||||
if (fullscreen == NULL) {
|
||||
fullscreen = con_get_fullscreen_con(con_ws, CF_OUTPUT);
|
||||
if (fullscreen != NULL)
|
||||
}
|
||||
if (fullscreen != NULL) {
|
||||
con_disable_fullscreen(fullscreen);
|
||||
}
|
||||
|
||||
/* Set focus to new fullscreen container. Unless in global fullscreen mode
|
||||
* and on another workspace restore focus afterwards.
|
||||
* Switch to the container’s workspace if mode is global. */
|
||||
Con *cur_ws = con_get_workspace(focused);
|
||||
Con *old_focused = focused;
|
||||
if (fullscreen_mode == CF_GLOBAL && cur_ws != con_ws)
|
||||
if (fullscreen_mode == CF_GLOBAL && cur_ws != con_ws) {
|
||||
workspace_show(con_ws);
|
||||
}
|
||||
con_activate(con);
|
||||
if (fullscreen_mode != CF_GLOBAL && cur_ws != con_ws)
|
||||
if (fullscreen_mode != CF_GLOBAL && cur_ws != con_ws) {
|
||||
con_activate(old_focused);
|
||||
}
|
||||
|
||||
con_set_fullscreen_mode(con, fullscreen_mode);
|
||||
}
|
||||
@ -1293,8 +1338,9 @@ static bool _con_move_to_con(Con *con, Con *target, bool behind_focused, bool fi
|
||||
}
|
||||
|
||||
/* If there are no non-floating children, ignore the workspace. */
|
||||
if (con_is_leaf(con))
|
||||
if (con_is_leaf(con)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
con = workspace_encapsulate(con);
|
||||
if (con == NULL) {
|
||||
@ -1349,8 +1395,9 @@ static bool _con_move_to_con(Con *con, Con *target, bool behind_focused, bool fi
|
||||
* to the coordinate space of the correct output */
|
||||
if (fix_coordinates && con->type == CT_FLOATING_CON) {
|
||||
floating_fix_coordinates(con, &(source_output->rect), &(dest_output->rect));
|
||||
} else
|
||||
} else {
|
||||
DLOG("Not fixing coordinates, fix_coordinates flag = %d\n", fix_coordinates);
|
||||
}
|
||||
}
|
||||
|
||||
/* If moving a fullscreen container and the destination already has a
|
||||
@ -1417,16 +1464,18 @@ static bool _con_move_to_con(Con *con, Con *target, bool behind_focused, bool fi
|
||||
|
||||
/* Set focus only if con was on current workspace before moving.
|
||||
* Otherwise we would give focus to some window on different workspace. */
|
||||
if (focus_next)
|
||||
if (focus_next) {
|
||||
con_activate(con_descend_focused(focus_next));
|
||||
}
|
||||
|
||||
/* 8. If anything within the container is associated with a startup sequence,
|
||||
* delete it so child windows won't be created on the old workspace. */
|
||||
if (!con_is_leaf(con)) {
|
||||
Con *child;
|
||||
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
|
||||
if (!child->window)
|
||||
if (!child->window) {
|
||||
continue;
|
||||
}
|
||||
startup_sequence_delete_by_window(child->window);
|
||||
}
|
||||
}
|
||||
@ -1648,8 +1697,9 @@ Con *con_next_focused(Con *con) {
|
||||
*/
|
||||
Con *con_descend_focused(Con *con) {
|
||||
Con *next = con;
|
||||
while (next != focused && !TAILQ_EMPTY(&(next->focus_head)))
|
||||
while (next != focused && !TAILQ_EMPTY(&(next->focus_head))) {
|
||||
next = TAILQ_FIRST(&(next->focus_head));
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
@ -1665,13 +1715,15 @@ Con *con_descend_tiling_focused(Con *con) {
|
||||
Con *next = con;
|
||||
Con *before;
|
||||
Con *child;
|
||||
if (next == focused)
|
||||
if (next == focused) {
|
||||
return next;
|
||||
}
|
||||
do {
|
||||
before = next;
|
||||
TAILQ_FOREACH (child, &(next->focus_head), focused) {
|
||||
if (child->type == CT_FLOATING_CON)
|
||||
if (child->type == CT_FLOATING_CON) {
|
||||
continue;
|
||||
}
|
||||
|
||||
next = child;
|
||||
break;
|
||||
@ -1696,10 +1748,11 @@ Con *con_descend_direction(Con *con, direction_t direction) {
|
||||
if (orientation == HORIZ) {
|
||||
/* If the direction is horizontal, we can use either the first
|
||||
* (D_RIGHT) or the last con (D_LEFT) */
|
||||
if (direction == D_RIGHT)
|
||||
if (direction == D_RIGHT) {
|
||||
most = TAILQ_FIRST(&(con->nodes_head));
|
||||
else
|
||||
} else {
|
||||
most = TAILQ_LAST(&(con->nodes_head), nodes_head);
|
||||
}
|
||||
} else if (orientation == VERT) {
|
||||
/* Wrong orientation. We use the last focused con. Within that con,
|
||||
* we recurse to chose the left/right con or at least the last
|
||||
@ -1721,10 +1774,11 @@ Con *con_descend_direction(Con *con, direction_t direction) {
|
||||
if (orientation == VERT) {
|
||||
/* If the direction is vertical, we can use either the first
|
||||
* (D_DOWN) or the last con (D_UP) */
|
||||
if (direction == D_UP)
|
||||
if (direction == D_UP) {
|
||||
most = TAILQ_LAST(&(con->nodes_head), nodes_head);
|
||||
else
|
||||
} else {
|
||||
most = TAILQ_FIRST(&(con->nodes_head));
|
||||
}
|
||||
} else if (orientation == HORIZ) {
|
||||
/* Wrong orientation. We use the last focused con. Within that con,
|
||||
* we recurse to chose the top/bottom con or at least the last
|
||||
@ -1742,8 +1796,9 @@ Con *con_descend_direction(Con *con, direction_t direction) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!most)
|
||||
if (!most) {
|
||||
return con;
|
||||
}
|
||||
return con_descend_direction(most, direction);
|
||||
}
|
||||
|
||||
@ -1773,8 +1828,9 @@ static Rect con_border_style_rect_without_title(Con *con) {
|
||||
(config.smart_borders == SMART_BORDERS_NO_GAPS && !has_outer_gaps(calculate_effective_gaps(con))) ||
|
||||
(config.hide_edge_borders == HEBM_SMART && con_num_visible_children(con_get_workspace(con)) <= 1) ||
|
||||
(config.hide_edge_borders == HEBM_SMART_NO_GAPS && con_num_visible_children(con_get_workspace(con)) <= 1 && !has_outer_gaps(calculate_effective_gaps(con)))) {
|
||||
if (!con_is_floating(con))
|
||||
if (!con_is_floating(con)) {
|
||||
return (Rect){0, 0, 0, 0};
|
||||
}
|
||||
}
|
||||
|
||||
adjacent_t borders_to_hide = ADJ_NONE;
|
||||
@ -1791,8 +1847,9 @@ static Rect con_border_style_rect_without_title(Con *con) {
|
||||
DLOG("Effective border width is set to: %d\n", border_width);
|
||||
/* Shortcut to avoid calling con_adjacent_borders() on dock containers. */
|
||||
int border_style = con_border_style(con);
|
||||
if (border_style == BS_NONE)
|
||||
if (border_style == BS_NONE) {
|
||||
return (Rect){0, 0, 0, 0};
|
||||
}
|
||||
if (border_style == BS_NORMAL) {
|
||||
result = (Rect){border_width, 0, -(2 * border_width), -(border_width)};
|
||||
} else {
|
||||
@ -1848,18 +1905,23 @@ adjacent_t con_adjacent_borders(Con *con) {
|
||||
adjacent_t result = ADJ_NONE;
|
||||
/* Floating windows are never adjacent to any other window, so
|
||||
don’t hide their border(s). This prevents bug #998. */
|
||||
if (con_is_floating(con))
|
||||
if (con_is_floating(con)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
Con *workspace = con_get_workspace(con);
|
||||
if (con->rect.x == workspace->rect.x)
|
||||
if (con->rect.x == workspace->rect.x) {
|
||||
result |= ADJ_LEFT_SCREEN_EDGE;
|
||||
if (con->rect.x + con->rect.width == workspace->rect.x + workspace->rect.width)
|
||||
}
|
||||
if (con->rect.x + con->rect.width == workspace->rect.x + workspace->rect.width) {
|
||||
result |= ADJ_RIGHT_SCREEN_EDGE;
|
||||
if (con->rect.y == workspace->rect.y)
|
||||
}
|
||||
if (con->rect.y == workspace->rect.y) {
|
||||
result |= ADJ_UPPER_SCREEN_EDGE;
|
||||
if (con->rect.y + con->rect.height == workspace->rect.y + workspace->rect.height)
|
||||
}
|
||||
if (con->rect.y + con->rect.height == workspace->rect.y + workspace->rect.height) {
|
||||
result |= ADJ_LOWER_SCREEN_EDGE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1946,14 +2008,16 @@ void con_set_layout(Con *con, layout_t layout) {
|
||||
/* Users can focus workspaces, but not any higher in the hierarchy.
|
||||
* Focus on the workspace is a special case, since in every other case, the
|
||||
* user means "change the layout of the parent split container". */
|
||||
if (con->type != CT_WORKSPACE)
|
||||
if (con->type != CT_WORKSPACE) {
|
||||
con = con->parent;
|
||||
}
|
||||
|
||||
/* We fill in last_split_layout when switching to a different layout
|
||||
* since there are many places in the code that don’t use
|
||||
* con_set_layout(). */
|
||||
if (con->layout == L_SPLITH || con->layout == L_SPLITV)
|
||||
if (con->layout == L_SPLITH || con->layout == L_SPLITV) {
|
||||
con->last_split_layout = con->layout;
|
||||
}
|
||||
|
||||
/* When the container type is CT_WORKSPACE, the user wants to change the
|
||||
* whole workspace into stacked/tabbed mode. To do this and still allow
|
||||
@ -2009,8 +2073,9 @@ void con_set_layout(Con *con, layout_t layout) {
|
||||
* splitv) in order to still do the same thing. */
|
||||
con->layout = con->last_split_layout;
|
||||
/* In case last_split_layout was not initialized… */
|
||||
if (con->layout == L_DEFAULT)
|
||||
if (con->layout == L_DEFAULT) {
|
||||
con->layout = L_SPLITH;
|
||||
}
|
||||
} else {
|
||||
con->layout = layout;
|
||||
}
|
||||
@ -2029,8 +2094,9 @@ void con_toggle_layout(Con *con, const char *toggle_mode) {
|
||||
/* Users can focus workspaces, but not any higher in the hierarchy.
|
||||
* Focus on the workspace is a special case, since in every other case, the
|
||||
* user means "change the layout of the parent split container". */
|
||||
if (con->type != CT_WORKSPACE)
|
||||
if (con->type != CT_WORKSPACE) {
|
||||
parent = con->parent;
|
||||
}
|
||||
DLOG("con_toggle_layout(%p, %s), parent = %p\n", con, toggle_mode, parent);
|
||||
|
||||
const char delim[] = " ";
|
||||
@ -2088,22 +2154,24 @@ void con_toggle_layout(Con *con, const char *toggle_mode) {
|
||||
con_set_layout(con, new_layout);
|
||||
}
|
||||
} else if (strcasecmp(toggle_mode, "all") == 0 || strcasecmp(toggle_mode, "default") == 0) {
|
||||
if (parent->layout == L_STACKED)
|
||||
if (parent->layout == L_STACKED) {
|
||||
con_set_layout(con, L_TABBED);
|
||||
else if (parent->layout == L_TABBED) {
|
||||
if (strcasecmp(toggle_mode, "all") == 0)
|
||||
} else if (parent->layout == L_TABBED) {
|
||||
if (strcasecmp(toggle_mode, "all") == 0) {
|
||||
con_set_layout(con, L_SPLITH);
|
||||
else
|
||||
} else {
|
||||
con_set_layout(con, parent->last_split_layout);
|
||||
}
|
||||
} else if (parent->layout == L_SPLITH || parent->layout == L_SPLITV) {
|
||||
if (strcasecmp(toggle_mode, "all") == 0) {
|
||||
/* When toggling through all modes, we toggle between
|
||||
* splith/splitv, whereas normally we just directly jump to
|
||||
* stacked. */
|
||||
if (parent->layout == L_SPLITH)
|
||||
if (parent->layout == L_SPLITH) {
|
||||
con_set_layout(con, L_SPLITV);
|
||||
else
|
||||
} else {
|
||||
con_set_layout(con, L_STACKED);
|
||||
}
|
||||
} else {
|
||||
con_set_layout(con, L_STACKED);
|
||||
}
|
||||
@ -2242,13 +2310,15 @@ Rect con_minimum_size(Con *con) {
|
||||
*/
|
||||
bool con_fullscreen_permits_focusing(Con *con) {
|
||||
/* No focus, no problem. */
|
||||
if (!focused)
|
||||
if (!focused) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Find the first fullscreen ascendent. */
|
||||
Con *fs = focused;
|
||||
while (fs && fs->fullscreen_mode == CF_NONE)
|
||||
while (fs && fs->fullscreen_mode == CF_NONE) {
|
||||
fs = fs->parent;
|
||||
}
|
||||
|
||||
/* fs must be non-NULL since the workspace con doesn’t have CF_NONE and
|
||||
* there always has to be a workspace con in the hierarchy. */
|
||||
@ -2256,12 +2326,14 @@ bool con_fullscreen_permits_focusing(Con *con) {
|
||||
/* The most common case is we hit the workspace level. In this
|
||||
* situation, changing focus is also harmless. */
|
||||
assert(fs->fullscreen_mode != CF_NONE);
|
||||
if (fs->type == CT_WORKSPACE)
|
||||
if (fs->type == CT_WORKSPACE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Allow it if the container itself is the fullscreen container. */
|
||||
if (con == fs)
|
||||
if (con == fs) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* If fullscreen is per-output, the focus being in a different workspace is
|
||||
* sufficient to guarantee that change won't leave fullscreen in bad shape. */
|
||||
@ -2283,14 +2355,16 @@ bool con_fullscreen_permits_focusing(Con *con) {
|
||||
bool con_has_urgent_child(Con *con) {
|
||||
Con *child;
|
||||
|
||||
if (con_is_leaf(con))
|
||||
if (con_is_leaf(con)) {
|
||||
return con->urgent;
|
||||
}
|
||||
|
||||
/* We are not interested in floating windows since they can only be
|
||||
* attached to a workspace → nodes_head instead of focus_head */
|
||||
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
|
||||
if (con_has_urgent_child(child))
|
||||
if (con_has_urgent_child(child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -2308,8 +2382,9 @@ void con_update_parents_urgency(Con *con) {
|
||||
* hierarchy than the workspace level. Unfortunately, since the content
|
||||
* container has type == CT_CON, that’s not easy to verify in the loop
|
||||
* below, so we need another condition to catch that case: */
|
||||
if (con->type == CT_WORKSPACE)
|
||||
if (con->type == CT_WORKSPACE) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool new_urgency_value = con->urgent;
|
||||
while (parent && parent->type != CT_WORKSPACE && parent->type != CT_DOCKAREA) {
|
||||
@ -2318,8 +2393,9 @@ void con_update_parents_urgency(Con *con) {
|
||||
} else {
|
||||
/* We can only reset the urgency when the parent
|
||||
* has no other urgent children */
|
||||
if (!con_has_urgent_child(parent))
|
||||
if (!con_has_urgent_child(parent)) {
|
||||
parent->urgent = false;
|
||||
}
|
||||
}
|
||||
parent = parent->parent;
|
||||
}
|
||||
@ -2339,8 +2415,9 @@ void con_set_urgency(Con *con, bool urgent) {
|
||||
|
||||
if (con->urgency_timer == NULL) {
|
||||
con->urgent = urgent;
|
||||
} else
|
||||
} else {
|
||||
DLOG("Discarding urgency WM_HINT because timer is running\n");
|
||||
}
|
||||
|
||||
if (con->window) {
|
||||
if (con->urgent) {
|
||||
@ -2356,8 +2433,9 @@ void con_set_urgency(Con *con, bool urgent) {
|
||||
Con *ws;
|
||||
/* Set the urgency flag on the workspace, if a workspace could be found
|
||||
* (for dock clients, that is not the case). */
|
||||
if ((ws = con_get_workspace(con)) != NULL)
|
||||
if ((ws = con_get_workspace(con)) != NULL) {
|
||||
workspace_update_urgent_flag(ws);
|
||||
}
|
||||
|
||||
if (con->urgent != old_urgent) {
|
||||
LOG("Urgency flag changed to %d\n", con->urgent);
|
||||
@ -2381,28 +2459,30 @@ char *con_get_tree_representation(Con *con) {
|
||||
|
||||
/* end of recursion */
|
||||
if (con_is_leaf(con)) {
|
||||
if (!con->window)
|
||||
if (!con->window) {
|
||||
return sstrdup("nowin");
|
||||
}
|
||||
|
||||
if (!con->window->class_instance)
|
||||
if (!con->window->class_instance) {
|
||||
return sstrdup("noinstance");
|
||||
}
|
||||
|
||||
return sstrdup(con->window->class_instance);
|
||||
}
|
||||
|
||||
char *buf;
|
||||
/* 1) add the Layout type to buf */
|
||||
if (con->layout == L_DEFAULT)
|
||||
if (con->layout == L_DEFAULT) {
|
||||
buf = sstrdup("D[");
|
||||
else if (con->layout == L_SPLITV)
|
||||
} else if (con->layout == L_SPLITV) {
|
||||
buf = sstrdup("V[");
|
||||
else if (con->layout == L_SPLITH)
|
||||
} else if (con->layout == L_SPLITH) {
|
||||
buf = sstrdup("H[");
|
||||
else if (con->layout == L_TABBED)
|
||||
} else if (con->layout == L_TABBED) {
|
||||
buf = sstrdup("T[");
|
||||
else if (con->layout == L_STACKED)
|
||||
} else if (con->layout == L_STACKED) {
|
||||
buf = sstrdup("S[");
|
||||
else {
|
||||
} else {
|
||||
ELOG("BUG: Code not updated to account for new layout type\n");
|
||||
assert(false);
|
||||
}
|
||||
|
13
src/config.c
13
src/config.c
@ -61,12 +61,13 @@ static void free_configuration(void) {
|
||||
|
||||
while (!TAILQ_EMPTY(&assignments)) {
|
||||
struct Assignment *assign = TAILQ_FIRST(&assignments);
|
||||
if (assign->type == A_TO_WORKSPACE || assign->type == A_TO_WORKSPACE_NUMBER)
|
||||
if (assign->type == A_TO_WORKSPACE || assign->type == A_TO_WORKSPACE_NUMBER) {
|
||||
FREE(assign->dest.workspace);
|
||||
else if (assign->type == A_COMMAND)
|
||||
} else if (assign->type == A_COMMAND) {
|
||||
FREE(assign->dest.command);
|
||||
else if (assign->type == A_TO_OUTPUT)
|
||||
} else if (assign->type == A_TO_OUTPUT) {
|
||||
FREE(assign->dest.output);
|
||||
}
|
||||
match_free(&(assign->match));
|
||||
TAILQ_REMOVE(&assignments, assign, assignments);
|
||||
FREE(assign);
|
||||
@ -85,8 +86,9 @@ static void free_configuration(void) {
|
||||
while (!TAILQ_EMPTY(&barconfigs)) {
|
||||
barconfig = TAILQ_FIRST(&barconfigs);
|
||||
FREE(barconfig->id);
|
||||
for (int c = 0; c < barconfig->num_outputs; c++)
|
||||
for (int c = 0; c < barconfig->num_outputs; c++) {
|
||||
free(barconfig->outputs[c]);
|
||||
}
|
||||
|
||||
while (!TAILQ_EMPTY(&(barconfig->bar_bindings))) {
|
||||
struct Barbinding *binding = TAILQ_FIRST(&(barconfig->bar_bindings));
|
||||
@ -224,8 +226,9 @@ bool load_configuration(const char *override_configpath, config_load_t load_type
|
||||
config.gaps.left = 0;
|
||||
|
||||
/* Set default urgency reset delay to 500ms */
|
||||
if (config.workspace_urgency_timer == 0)
|
||||
if (config.workspace_urgency_timer == 0) {
|
||||
config.workspace_urgency_timer = 0.5;
|
||||
}
|
||||
|
||||
config.focus_wrapping = FOCUS_WRAPPING_ON;
|
||||
|
||||
|
@ -133,33 +133,45 @@ i3_event_state_mask_t event_state_from_str(const char *str) {
|
||||
/* It might be better to use strtok() here, but the simpler strstr() should
|
||||
* do for now. */
|
||||
i3_event_state_mask_t result = 0;
|
||||
if (str == NULL)
|
||||
if (str == NULL) {
|
||||
return result;
|
||||
if (strstr(str, "Mod1") != NULL)
|
||||
}
|
||||
if (strstr(str, "Mod1") != NULL) {
|
||||
result |= XCB_KEY_BUT_MASK_MOD_1;
|
||||
if (strstr(str, "Mod2") != NULL)
|
||||
}
|
||||
if (strstr(str, "Mod2") != NULL) {
|
||||
result |= XCB_KEY_BUT_MASK_MOD_2;
|
||||
if (strstr(str, "Mod3") != NULL)
|
||||
}
|
||||
if (strstr(str, "Mod3") != NULL) {
|
||||
result |= XCB_KEY_BUT_MASK_MOD_3;
|
||||
if (strstr(str, "Mod4") != NULL)
|
||||
}
|
||||
if (strstr(str, "Mod4") != NULL) {
|
||||
result |= XCB_KEY_BUT_MASK_MOD_4;
|
||||
if (strstr(str, "Mod5") != NULL)
|
||||
}
|
||||
if (strstr(str, "Mod5") != NULL) {
|
||||
result |= XCB_KEY_BUT_MASK_MOD_5;
|
||||
}
|
||||
if (strstr(str, "Control") != NULL ||
|
||||
strstr(str, "Ctrl") != NULL)
|
||||
strstr(str, "Ctrl") != NULL) {
|
||||
result |= XCB_KEY_BUT_MASK_CONTROL;
|
||||
if (strstr(str, "Shift") != NULL)
|
||||
}
|
||||
if (strstr(str, "Shift") != NULL) {
|
||||
result |= XCB_KEY_BUT_MASK_SHIFT;
|
||||
}
|
||||
|
||||
if (strstr(str, "Group1") != NULL)
|
||||
if (strstr(str, "Group1") != NULL) {
|
||||
result |= (I3_XKB_GROUP_MASK_1 << 16);
|
||||
}
|
||||
if (strstr(str, "Group2") != NULL ||
|
||||
strstr(str, "Mode_switch") != NULL)
|
||||
strstr(str, "Mode_switch") != NULL) {
|
||||
result |= (I3_XKB_GROUP_MASK_2 << 16);
|
||||
if (strstr(str, "Group3") != NULL)
|
||||
}
|
||||
if (strstr(str, "Group3") != NULL) {
|
||||
result |= (I3_XKB_GROUP_MASK_3 << 16);
|
||||
if (strstr(str, "Group4") != NULL)
|
||||
}
|
||||
if (strstr(str, "Group4") != NULL) {
|
||||
result |= (I3_XKB_GROUP_MASK_4 << 16);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -314,17 +326,19 @@ CFGFUN(gaps, const char *workspace, const char *scope, const long value) {
|
||||
}
|
||||
|
||||
CFGFUN(smart_borders, const char *enable) {
|
||||
if (!strcmp(enable, "no_gaps"))
|
||||
if (!strcmp(enable, "no_gaps")) {
|
||||
config.smart_borders = SMART_BORDERS_NO_GAPS;
|
||||
else
|
||||
} else {
|
||||
config.smart_borders = boolstr(enable) ? SMART_BORDERS_ON : SMART_BORDERS_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
CFGFUN(smart_gaps, const char *enable) {
|
||||
if (!strcmp(enable, "inverse_outer"))
|
||||
if (!strcmp(enable, "inverse_outer")) {
|
||||
config.smart_gaps = SMART_GAPS_INVERSE_OUTER;
|
||||
else
|
||||
} else {
|
||||
config.smart_gaps = boolstr(enable) ? SMART_GAPS_ON : SMART_GAPS_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
CFGFUN(floating_minimum_size, const long width, const long height) {
|
||||
@ -342,22 +356,24 @@ CFGFUN(floating_modifier, const char *modifiers) {
|
||||
}
|
||||
|
||||
CFGFUN(default_orientation, const char *orientation) {
|
||||
if (strcmp(orientation, "horizontal") == 0)
|
||||
if (strcmp(orientation, "horizontal") == 0) {
|
||||
config.default_orientation = HORIZ;
|
||||
else if (strcmp(orientation, "vertical") == 0)
|
||||
} else if (strcmp(orientation, "vertical") == 0) {
|
||||
config.default_orientation = VERT;
|
||||
else
|
||||
} else {
|
||||
config.default_orientation = NO_ORIENTATION;
|
||||
}
|
||||
}
|
||||
|
||||
CFGFUN(workspace_layout, const char *layout) {
|
||||
if (strcmp(layout, "default") == 0)
|
||||
if (strcmp(layout, "default") == 0) {
|
||||
config.default_layout = L_DEFAULT;
|
||||
else if (strcmp(layout, "stacking") == 0 ||
|
||||
strcmp(layout, "stacked") == 0)
|
||||
} else if (strcmp(layout, "stacking") == 0 ||
|
||||
strcmp(layout, "stacked") == 0) {
|
||||
config.default_layout = L_STACKED;
|
||||
else
|
||||
} else {
|
||||
config.default_layout = L_TABBED;
|
||||
}
|
||||
}
|
||||
|
||||
CFGFUN(default_border, const char *windowtype, const char *border, const long width) {
|
||||
@ -393,22 +409,23 @@ CFGFUN(default_border, const char *windowtype, const char *border, const long wi
|
||||
}
|
||||
|
||||
CFGFUN(hide_edge_borders, const char *borders) {
|
||||
if (strcmp(borders, "smart_no_gaps") == 0)
|
||||
if (strcmp(borders, "smart_no_gaps") == 0) {
|
||||
config.hide_edge_borders = HEBM_SMART_NO_GAPS;
|
||||
else if (strcmp(borders, "smart") == 0)
|
||||
} else if (strcmp(borders, "smart") == 0) {
|
||||
config.hide_edge_borders = HEBM_SMART;
|
||||
else if (strcmp(borders, "vertical") == 0)
|
||||
} else if (strcmp(borders, "vertical") == 0) {
|
||||
config.hide_edge_borders = HEBM_VERTICAL;
|
||||
else if (strcmp(borders, "horizontal") == 0)
|
||||
} else if (strcmp(borders, "horizontal") == 0) {
|
||||
config.hide_edge_borders = HEBM_HORIZONTAL;
|
||||
else if (strcmp(borders, "both") == 0)
|
||||
} else if (strcmp(borders, "both") == 0) {
|
||||
config.hide_edge_borders = HEBM_BOTH;
|
||||
else if (strcmp(borders, "none") == 0)
|
||||
} else if (strcmp(borders, "none") == 0) {
|
||||
config.hide_edge_borders = HEBM_NONE;
|
||||
else if (boolstr(borders))
|
||||
} else if (boolstr(borders)) {
|
||||
config.hide_edge_borders = HEBM_VERTICAL;
|
||||
else
|
||||
} else {
|
||||
config.hide_edge_borders = HEBM_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
CFGFUN(focus_follows_mouse, const char *value) {
|
||||
@ -416,10 +433,11 @@ CFGFUN(focus_follows_mouse, const char *value) {
|
||||
}
|
||||
|
||||
CFGFUN(mouse_warping, const char *value) {
|
||||
if (strcmp(value, "none") == 0)
|
||||
if (strcmp(value, "none") == 0) {
|
||||
config.mouse_warping = POINTER_WARPING_NONE;
|
||||
else if (strcmp(value, "output") == 0)
|
||||
} else if (strcmp(value, "output") == 0) {
|
||||
config.mouse_warping = POINTER_WARPING_OUTPUT;
|
||||
}
|
||||
}
|
||||
|
||||
CFGFUN(force_xinerama, const char *value) {
|
||||
@ -469,15 +487,15 @@ CFGFUN(force_display_urgency_hint, const long duration_ms) {
|
||||
}
|
||||
|
||||
CFGFUN(focus_on_window_activation, const char *mode) {
|
||||
if (strcmp(mode, "smart") == 0)
|
||||
if (strcmp(mode, "smart") == 0) {
|
||||
config.focus_on_window_activation = FOWA_SMART;
|
||||
else if (strcmp(mode, "urgent") == 0)
|
||||
} else if (strcmp(mode, "urgent") == 0) {
|
||||
config.focus_on_window_activation = FOWA_URGENT;
|
||||
else if (strcmp(mode, "focus") == 0)
|
||||
} else if (strcmp(mode, "focus") == 0) {
|
||||
config.focus_on_window_activation = FOWA_FOCUS;
|
||||
else if (strcmp(mode, "none") == 0)
|
||||
} else if (strcmp(mode, "none") == 0) {
|
||||
config.focus_on_window_activation = FOWA_NONE;
|
||||
else {
|
||||
} else {
|
||||
ELOG("Unknown focus_on_window_activation mode \"%s\", ignoring it.\n", mode);
|
||||
return;
|
||||
}
|
||||
@ -854,18 +872,19 @@ CFGFUN(bar_tray_padding, const long padding_px) {
|
||||
}
|
||||
|
||||
CFGFUN(bar_color_single, const char *colorclass, const char *color) {
|
||||
if (strcmp(colorclass, "background") == 0)
|
||||
if (strcmp(colorclass, "background") == 0) {
|
||||
current_bar->colors.background = sstrdup(color);
|
||||
else if (strcmp(colorclass, "separator") == 0)
|
||||
} else if (strcmp(colorclass, "separator") == 0) {
|
||||
current_bar->colors.separator = sstrdup(color);
|
||||
else if (strcmp(colorclass, "statusline") == 0)
|
||||
} else if (strcmp(colorclass, "statusline") == 0) {
|
||||
current_bar->colors.statusline = sstrdup(color);
|
||||
else if (strcmp(colorclass, "focused_background") == 0)
|
||||
} else if (strcmp(colorclass, "focused_background") == 0) {
|
||||
current_bar->colors.focused_background = sstrdup(color);
|
||||
else if (strcmp(colorclass, "focused_separator") == 0)
|
||||
} else if (strcmp(colorclass, "focused_separator") == 0) {
|
||||
current_bar->colors.focused_separator = sstrdup(color);
|
||||
else
|
||||
} else {
|
||||
current_bar->colors.focused_statusline = sstrdup(color);
|
||||
}
|
||||
}
|
||||
|
||||
CFGFUN(bar_status_command, const char *command) {
|
||||
@ -909,8 +928,9 @@ CFGFUN(bar_start) {
|
||||
CFGFUN(bar_finish) {
|
||||
DLOG("\t new bar configuration finished, saving.\n");
|
||||
/* Generate a unique ID for this bar if not already configured */
|
||||
if (current_bar->id == NULL)
|
||||
if (current_bar->id == NULL) {
|
||||
sasprintf(¤t_bar->id, "bar-%d", config.number_barconfigs);
|
||||
}
|
||||
|
||||
config.number_barconfigs++;
|
||||
|
||||
|
@ -80,8 +80,9 @@ typedef struct tokenptr {
|
||||
static void push_string(struct stack *ctx, const char *identifier, const char *str) {
|
||||
for (int c = 0; c < 10; c++) {
|
||||
if (ctx->stack[c].identifier != NULL &&
|
||||
strcmp(ctx->stack[c].identifier, identifier) != 0)
|
||||
strcmp(ctx->stack[c].identifier, identifier) != 0) {
|
||||
continue;
|
||||
}
|
||||
if (ctx->stack[c].identifier == NULL) {
|
||||
/* Found a free slot, let’s store it here. */
|
||||
ctx->stack[c].identifier = identifier;
|
||||
@ -128,28 +129,33 @@ static void push_long(struct stack *ctx, const char *identifier, long num) {
|
||||
|
||||
static const char *get_string(struct stack *ctx, const char *identifier) {
|
||||
for (int c = 0; c < 10; c++) {
|
||||
if (ctx->stack[c].identifier == NULL)
|
||||
if (ctx->stack[c].identifier == NULL) {
|
||||
break;
|
||||
if (strcmp(identifier, ctx->stack[c].identifier) == 0)
|
||||
}
|
||||
if (strcmp(identifier, ctx->stack[c].identifier) == 0) {
|
||||
return ctx->stack[c].val.str;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static long get_long(struct stack *ctx, const char *identifier) {
|
||||
for (int c = 0; c < 10; c++) {
|
||||
if (ctx->stack[c].identifier == NULL)
|
||||
if (ctx->stack[c].identifier == NULL) {
|
||||
break;
|
||||
if (strcmp(identifier, ctx->stack[c].identifier) == 0)
|
||||
}
|
||||
if (strcmp(identifier, ctx->stack[c].identifier) == 0) {
|
||||
return ctx->stack[c].val.num;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void clear_stack(struct stack *ctx) {
|
||||
for (int c = 0; c < 10; c++) {
|
||||
if (ctx->stack[c].type == STACK_STR)
|
||||
if (ctx->stack[c].type == STACK_STR) {
|
||||
free(ctx->stack[c].val.str);
|
||||
}
|
||||
ctx->stack[c].identifier = NULL;
|
||||
ctx->stack[c].val.str = NULL;
|
||||
ctx->stack[c].val.num = 0;
|
||||
@ -218,8 +224,9 @@ static const char *start_of_line(const char *walk, const char *beginning) {
|
||||
static char *single_line(const char *start) {
|
||||
char *result = sstrdup(start);
|
||||
char *end = strchr(result, '\n');
|
||||
if (end != NULL)
|
||||
if (end != NULL) {
|
||||
*end = '\0';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -264,8 +271,9 @@ static void parse_config(struct parser_ctx *ctx, const char *input, struct conte
|
||||
while ((size_t)(walk - input) <= len) {
|
||||
/* Skip whitespace before every token, newlines are relevant since they
|
||||
* separate configuration directives. */
|
||||
while ((*walk == ' ' || *walk == '\t') && *walk != '\0')
|
||||
while ((*walk == ' ' || *walk == '\t') && *walk != '\0') {
|
||||
walk++;
|
||||
}
|
||||
|
||||
cmdp_token_ptr *ptr = &(tokens[ctx->state]);
|
||||
token_handled = false;
|
||||
@ -292,12 +300,14 @@ static void parse_config(struct parser_ctx *ctx, const char *input, struct conte
|
||||
errno = 0;
|
||||
long int num = strtol(walk, &end, 10);
|
||||
if ((errno == ERANGE && (num == LONG_MIN || num == LONG_MAX)) ||
|
||||
(errno != 0 && num == 0))
|
||||
(errno != 0 && num == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* No valid numbers found */
|
||||
if (end == walk)
|
||||
if (end == walk) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (token->identifier != NULL) {
|
||||
push_long(ctx->stack, token->identifier, num);
|
||||
@ -317,12 +327,14 @@ static void parse_config(struct parser_ctx *ctx, const char *input, struct conte
|
||||
if (*walk == '"') {
|
||||
beginning++;
|
||||
walk++;
|
||||
while (*walk != '\0' && (*walk != '"' || *(walk - 1) == '\\'))
|
||||
while (*walk != '\0' && (*walk != '"' || *(walk - 1) == '\\')) {
|
||||
walk++;
|
||||
}
|
||||
} else {
|
||||
if (token->name[0] == 's') {
|
||||
while (*walk != '\0' && *walk != '\r' && *walk != '\n')
|
||||
while (*walk != '\0' && *walk != '\r' && *walk != '\n') {
|
||||
walk++;
|
||||
}
|
||||
} else {
|
||||
/* For a word, the delimiters are white space (' ' or
|
||||
* '\t'), closing square bracket (]), comma (,) and
|
||||
@ -330,8 +342,9 @@ static void parse_config(struct parser_ctx *ctx, const char *input, struct conte
|
||||
while (*walk != ' ' && *walk != '\t' &&
|
||||
*walk != ']' && *walk != ',' &&
|
||||
*walk != ';' && *walk != '\r' &&
|
||||
*walk != '\n' && *walk != '\0')
|
||||
*walk != '\n' && *walk != '\0') {
|
||||
walk++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (walk != beginning) {
|
||||
@ -344,8 +357,9 @@ static void parse_config(struct parser_ctx *ctx, const char *input, struct conte
|
||||
/* We only handle escaped double quotes to not break
|
||||
* backwards compatibility with people using \w in
|
||||
* regular expressions etc. */
|
||||
if (beginning[inpos] == '\\' && beginning[inpos + 1] == '"')
|
||||
if (beginning[inpos] == '\\' && beginning[inpos + 1] == '"') {
|
||||
inpos++;
|
||||
}
|
||||
str[outpos] = beginning[inpos];
|
||||
}
|
||||
if (token->identifier) {
|
||||
@ -354,8 +368,9 @@ static void parse_config(struct parser_ctx *ctx, const char *input, struct conte
|
||||
free(str);
|
||||
/* If we are at the end of a quoted string, skip the ending
|
||||
* double quote. */
|
||||
if (*walk == '"')
|
||||
if (*walk == '"') {
|
||||
walk++;
|
||||
}
|
||||
next_state(token, ctx);
|
||||
token_handled = true;
|
||||
break;
|
||||
@ -363,8 +378,9 @@ static void parse_config(struct parser_ctx *ctx, const char *input, struct conte
|
||||
}
|
||||
|
||||
if (strcmp(token->name, "line") == 0) {
|
||||
while (*walk != '\0' && *walk != '\n' && *walk != '\r')
|
||||
while (*walk != '\0' && *walk != '\n' && *walk != '\r') {
|
||||
walk++;
|
||||
}
|
||||
next_state(token, ctx);
|
||||
token_handled = true;
|
||||
linecnt++;
|
||||
@ -394,8 +410,9 @@ static void parse_config(struct parser_ctx *ctx, const char *input, struct conte
|
||||
/* Figure out how much memory we will need to fill in the names of
|
||||
* all tokens afterwards. */
|
||||
int tokenlen = 0;
|
||||
for (c = 0; c < ptr->n; c++)
|
||||
for (c = 0; c < ptr->n; c++) {
|
||||
tokenlen += strlen(ptr->array[c].name) + strlen("'', ");
|
||||
}
|
||||
|
||||
/* Build up a decent error message. We include the problem, the
|
||||
* full input, and underline the position where the parser
|
||||
@ -415,8 +432,9 @@ static void parse_config(struct parser_ctx *ctx, const char *input, struct conte
|
||||
} else {
|
||||
/* Skip error tokens in error messages, they are used
|
||||
* internally only and might confuse users. */
|
||||
if (strcmp(token->name, "error") == 0)
|
||||
if (strcmp(token->name, "error") == 0) {
|
||||
continue;
|
||||
}
|
||||
/* Any other token is copied to the error message enclosed
|
||||
* with angle brackets. */
|
||||
*tokenwalk++ = '<';
|
||||
@ -443,8 +461,9 @@ static void parse_config(struct parser_ctx *ctx, const char *input, struct conte
|
||||
const char *copywalk;
|
||||
for (copywalk = error_line;
|
||||
*copywalk != '\n' && *copywalk != '\r' && *copywalk != '\0';
|
||||
copywalk++)
|
||||
copywalk++) {
|
||||
position[(copywalk - error_line)] = (copywalk >= walk ? '^' : (*copywalk == '\t' ? '\t' : ' '));
|
||||
}
|
||||
position[(copywalk - error_line)] = '\0';
|
||||
|
||||
ELOG("CONFIG: %s\n", errormessage);
|
||||
@ -481,8 +500,9 @@ static void parse_config(struct parser_ctx *ctx, const char *input, struct conte
|
||||
context->has_errors = true;
|
||||
|
||||
/* Skip the rest of this line, but continue parsing. */
|
||||
while ((size_t)(walk - input) <= len && *walk != '\n')
|
||||
while ((size_t)(walk - input) <= len && *walk != '\n') {
|
||||
walk++;
|
||||
}
|
||||
|
||||
free(position);
|
||||
free(errormessage);
|
||||
@ -495,8 +515,9 @@ static void parse_config(struct parser_ctx *ctx, const char *input, struct conte
|
||||
for (int i = ctx->statelist_idx - 1; (i >= 0) && !error_token_found; i--) {
|
||||
cmdp_token_ptr *errptr = &(tokens[ctx->statelist[i]]);
|
||||
for (int j = 0; j < errptr->n; j++) {
|
||||
if (strcmp(errptr->array[j].name, "error") != 0)
|
||||
if (strcmp(errptr->array[j].name, "error") != 0) {
|
||||
continue;
|
||||
}
|
||||
next_state(&(errptr->array[j]), ctx);
|
||||
error_token_found = true;
|
||||
break;
|
||||
@ -599,18 +620,24 @@ static int detect_version(char *buf) {
|
||||
/* if this is a bind statement, we can check the command */
|
||||
if (strncasecmp(line, "bind", strlen("bind")) == 0) {
|
||||
char *bind = strchr(line, ' ');
|
||||
if (bind == NULL)
|
||||
if (bind == NULL) {
|
||||
goto next;
|
||||
while ((*bind == ' ' || *bind == '\t') && *bind != '\0')
|
||||
}
|
||||
while ((*bind == ' ' || *bind == '\t') && *bind != '\0') {
|
||||
bind++;
|
||||
if (*bind == '\0')
|
||||
}
|
||||
if (*bind == '\0') {
|
||||
goto next;
|
||||
if ((bind = strchr(bind, ' ')) == NULL)
|
||||
}
|
||||
if ((bind = strchr(bind, ' ')) == NULL) {
|
||||
goto next;
|
||||
while ((*bind == ' ' || *bind == '\t') && *bind != '\0')
|
||||
}
|
||||
while ((*bind == ' ' || *bind == '\t') && *bind != '\0') {
|
||||
bind++;
|
||||
if (*bind == '\0')
|
||||
}
|
||||
if (*bind == '\0') {
|
||||
goto next;
|
||||
}
|
||||
if (strncasecmp(bind, "layout", strlen("layout")) == 0 ||
|
||||
strncasecmp(bind, "floating", strlen("floating")) == 0 ||
|
||||
strncasecmp(bind, "workspace", strlen("workspace")) == 0 ||
|
||||
@ -793,8 +820,9 @@ static void upsert_variable(struct variables_head *variables, char *key, char *v
|
||||
/* ensure that the correct variable is matched in case of one being
|
||||
* the prefix of another */
|
||||
SLIST_FOREACH (test, variables, variables) {
|
||||
if (strlen(new->key) >= strlen(test->key))
|
||||
if (strlen(new->key) >= strlen(test->key)) {
|
||||
break;
|
||||
}
|
||||
loc = test;
|
||||
}
|
||||
|
||||
@ -893,11 +921,13 @@ parse_file_result_t parse_file(struct parser_ctx *ctx, const char *f, IncludedFi
|
||||
bool invalid_sets = false;
|
||||
|
||||
while (!feof(fstr)) {
|
||||
if (!continuation)
|
||||
if (!continuation) {
|
||||
continuation = buffer;
|
||||
}
|
||||
if (fgets(continuation, sizeof(buffer) - (continuation - buffer), fstr) == NULL) {
|
||||
if (feof(fstr))
|
||||
if (feof(fstr)) {
|
||||
break;
|
||||
}
|
||||
return PARSE_FILE_FAILED;
|
||||
}
|
||||
if (buffer[strlen(buffer) - 1] != '\n' && !feof(fstr)) {
|
||||
@ -1027,8 +1057,9 @@ parse_file_result_t parse_file(struct parser_ctx *ctx, const char *f, IncludedFi
|
||||
nearest = NULL;
|
||||
int distance = stbuf.st_size;
|
||||
SLIST_FOREACH (current, &(ctx->variables), variables) {
|
||||
if (current->next_match == NULL)
|
||||
if (current->next_match == NULL) {
|
||||
continue;
|
||||
}
|
||||
if ((current->next_match - walk) < distance) {
|
||||
distance = (current->next_match - walk);
|
||||
nearest = current;
|
||||
@ -1093,8 +1124,9 @@ parse_file_result_t parse_file(struct parser_ctx *ctx, const char *f, IncludedFi
|
||||
|
||||
if (ctx->use_nagbar && (context->has_errors || context->has_warnings || invalid_sets)) {
|
||||
ELOG("FYI: You are using i3 version %s\n", i3_version);
|
||||
if (version == 3)
|
||||
if (version == 3) {
|
||||
ELOG("Please convert your configfile first, then fix any remaining errors (see above).\n");
|
||||
}
|
||||
|
||||
start_config_error_nagbar(f, context->has_errors || invalid_sets);
|
||||
}
|
||||
|
@ -100,27 +100,31 @@ void display_running_version(void) {
|
||||
|
||||
int sockfd = ipc_connect(NULL);
|
||||
if (ipc_send_message(sockfd, 0, I3_IPC_MESSAGE_TYPE_GET_VERSION,
|
||||
(uint8_t *)"") == -1)
|
||||
(uint8_t *)"") == -1) {
|
||||
err(EXIT_FAILURE, "IPC: write()");
|
||||
}
|
||||
|
||||
uint32_t reply_length;
|
||||
uint32_t reply_type;
|
||||
uint8_t *reply;
|
||||
int ret;
|
||||
if ((ret = ipc_recv_message(sockfd, &reply_type, &reply_length, &reply)) != 0) {
|
||||
if (ret == -1)
|
||||
if (ret == -1) {
|
||||
err(EXIT_FAILURE, "IPC: read()");
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (reply_type != I3_IPC_MESSAGE_TYPE_GET_VERSION)
|
||||
if (reply_type != I3_IPC_MESSAGE_TYPE_GET_VERSION) {
|
||||
errx(EXIT_FAILURE, "Got reply type %d, but expected %d (GET_VERSION)", reply_type, I3_IPC_MESSAGE_TYPE_GET_VERSION);
|
||||
}
|
||||
|
||||
yajl_handle handle = yajl_alloc(&version_callbacks, NULL, NULL);
|
||||
|
||||
yajl_status state = yajl_parse(handle, (const unsigned char *)reply, (int)reply_length);
|
||||
if (state != yajl_status_ok)
|
||||
if (state != yajl_status_ok) {
|
||||
errx(EXIT_FAILURE, "Could not parse my own reply. That's weird. reply is %.*s", (int)reply_length, reply);
|
||||
}
|
||||
|
||||
printf("\r\x1b[K");
|
||||
printf("Running i3 version: %s (pid %s)\n", human_readable_version, pid_from_atom);
|
||||
@ -146,8 +150,9 @@ void display_running_version(void) {
|
||||
destpath_size = destpath_size * 2;
|
||||
destpath = srealloc(destpath, destpath_size);
|
||||
}
|
||||
if (linksize == -1)
|
||||
if (linksize == -1) {
|
||||
err(EXIT_FAILURE, "readlink(%s)", exepath);
|
||||
}
|
||||
|
||||
/* readlink() does not NULL-terminate strings, so we have to. */
|
||||
destpath[linksize] = '\0';
|
||||
@ -162,16 +167,18 @@ void display_running_version(void) {
|
||||
destpath_size = destpath_size * 2;
|
||||
destpath = srealloc(destpath, destpath_size);
|
||||
}
|
||||
if (linksize == -1)
|
||||
if (linksize == -1) {
|
||||
err(EXIT_FAILURE, "readlink(%s)", exepath);
|
||||
}
|
||||
|
||||
/* readlink() does not NULL-terminate strings, so we have to. */
|
||||
destpath[linksize] = '\0';
|
||||
|
||||
/* Check if "(deleted)" is the readlink result. If so, the running version
|
||||
* does not match the file on disk. */
|
||||
if (strstr(destpath, "(deleted)") != NULL)
|
||||
if (strstr(destpath, "(deleted)") != NULL) {
|
||||
printf("RUNNING BINARY DIFFERENT FROM BINARY ON DISK!\n");
|
||||
}
|
||||
|
||||
/* Since readlink() might put a "(deleted)" somewhere in the buffer and
|
||||
* stripping that out seems hackish and ugly, we read the process’s argv[0]
|
||||
@ -180,10 +187,12 @@ void display_running_version(void) {
|
||||
sasprintf(&exepath, "/proc/%s/cmdline", pid_from_atom);
|
||||
|
||||
int fd;
|
||||
if ((fd = open(exepath, O_RDONLY)) == -1)
|
||||
if ((fd = open(exepath, O_RDONLY)) == -1) {
|
||||
err(EXIT_FAILURE, "open(%s)", exepath);
|
||||
if (read(fd, destpath, sizeof(destpath)) == -1)
|
||||
}
|
||||
if (read(fd, destpath, sizeof(destpath)) == -1) {
|
||||
err(EXIT_FAILURE, "read(%s)", exepath);
|
||||
}
|
||||
close(fd);
|
||||
|
||||
printf("The i3 binary you are running: %s\n", destpath);
|
||||
|
@ -103,8 +103,9 @@ static bool drain_drag_events(EV_P, struct drag_x11_cb *dragloop) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (last_motion_notify != (xcb_motion_notify_event_t *)event)
|
||||
if (last_motion_notify != (xcb_motion_notify_event_t *)event) {
|
||||
free(event);
|
||||
}
|
||||
|
||||
if (dragloop->result != DRAGGING) {
|
||||
ev_break(EV_A_ EVBREAK_ONE);
|
||||
@ -233,8 +234,9 @@ drag_result_t drag_pointer(Con *con, const xcb_button_press_event_t *event,
|
||||
.extra = extra,
|
||||
};
|
||||
ev_prepare *prepare = &loop.prepare;
|
||||
if (con)
|
||||
if (con) {
|
||||
loop.old_rect = con->rect;
|
||||
}
|
||||
ev_prepare_init(prepare, xcb_drag_prepare_cb);
|
||||
prepare->data = &loop;
|
||||
main_set_x11_cb(false);
|
||||
|
@ -138,8 +138,9 @@ static void ewmh_update_wm_desktop_recursively(Con *con, const uint32_t desktop)
|
||||
}
|
||||
}
|
||||
|
||||
if (!con_has_managed_window(con))
|
||||
if (!con_has_managed_window(con)) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t wm_desktop = desktop;
|
||||
/* Sticky windows are only actually sticky when they are floating or inside
|
||||
@ -160,8 +161,9 @@ static void ewmh_update_wm_desktop_recursively(Con *con, const uint32_t desktop)
|
||||
}
|
||||
|
||||
/* If this is the cached value, we don't need to do anything. */
|
||||
if (con->window->wm_desktop == wm_desktop)
|
||||
if (con->window->wm_desktop == wm_desktop) {
|
||||
return;
|
||||
}
|
||||
con->window->wm_desktop = wm_desktop;
|
||||
|
||||
const xcb_window_t window = con->window->id;
|
||||
@ -351,8 +353,9 @@ void ewmh_setup_hints(void) {
|
||||
*
|
||||
*/
|
||||
Con *ewmh_get_workspace_by_index(uint32_t idx) {
|
||||
if (idx == NET_WM_DESKTOP_NONE)
|
||||
if (idx == NET_WM_DESKTOP_NONE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t current_index = 0;
|
||||
|
||||
|
@ -46,8 +46,9 @@ void fake_outputs_init(const char *output_spec) {
|
||||
primary = true;
|
||||
walk++;
|
||||
}
|
||||
if (*walk == ',')
|
||||
if (*walk == ',') {
|
||||
walk++; /* Skip delimiter */
|
||||
}
|
||||
DLOG("Parsed output as width = %u, height = %u at (%u, %u)%s\n",
|
||||
width, height, x, y, primary ? " (primary)" : "");
|
||||
|
||||
@ -71,10 +72,11 @@ void fake_outputs_init(const char *output_spec) {
|
||||
new_output->rect.width = width;
|
||||
new_output->rect.height = height;
|
||||
/* We always treat the screen at 0x0 as the primary screen */
|
||||
if (new_output->rect.x == 0 && new_output->rect.y == 0)
|
||||
if (new_output->rect.x == 0 && new_output->rect.y == 0) {
|
||||
TAILQ_INSERT_HEAD(&outputs, new_output, outputs);
|
||||
else
|
||||
} else {
|
||||
TAILQ_INSERT_TAIL(&outputs, new_output, outputs);
|
||||
}
|
||||
output_init_con(new_output);
|
||||
init_ws_for_output(new_output);
|
||||
num_screens++;
|
||||
|
@ -20,8 +20,9 @@
|
||||
*
|
||||
*/
|
||||
static Rect total_outputs_dimensions(void) {
|
||||
if (TAILQ_EMPTY(&outputs))
|
||||
if (TAILQ_EMPTY(&outputs)) {
|
||||
return (Rect){0, 0, root_screen->width_in_pixels, root_screen->height_in_pixels};
|
||||
}
|
||||
|
||||
Output *output;
|
||||
/* Use Rect to encapsulate dimensions, ignoring x/y */
|
||||
@ -407,8 +408,9 @@ bool floating_enable(Con *con, bool automatic) {
|
||||
/* render the cons to get initial window_rect correct */
|
||||
render_con(nc);
|
||||
|
||||
if (set_focus)
|
||||
if (set_focus) {
|
||||
con_activate(con);
|
||||
}
|
||||
|
||||
floating_set_hint_atom(nc, true);
|
||||
ipc_send_window_event("floating", con);
|
||||
@ -556,10 +558,12 @@ void floating_move_to_pointer(Con *con) {
|
||||
/* Correct target coordinates to be in-bounds. */
|
||||
x = MAX(x, (int32_t)output->rect.x);
|
||||
y = MAX(y, (int32_t)output->rect.y);
|
||||
if (x + con->rect.width > output->rect.x + output->rect.width)
|
||||
if (x + con->rect.width > output->rect.x + output->rect.width) {
|
||||
x = output->rect.x + output->rect.width - con->rect.width;
|
||||
if (y + con->rect.height > output->rect.y + output->rect.height)
|
||||
}
|
||||
if (y + con->rect.height > output->rect.y + output->rect.height) {
|
||||
y = output->rect.y + output->rect.height - con->rect.height;
|
||||
}
|
||||
|
||||
/* Update container's coordinates to position it correctly. */
|
||||
floating_reposition(con, (Rect){x, y, con->rect.width, con->rect.height});
|
||||
@ -575,8 +579,9 @@ DRAGGING_CB(drag_window_callback) {
|
||||
xcb_flush(conn);
|
||||
|
||||
/* Check if we cross workspace boundaries while moving */
|
||||
if (!floating_maybe_reassign_ws(con))
|
||||
if (!floating_maybe_reassign_ws(con)) {
|
||||
return;
|
||||
}
|
||||
/* Ensure not to warp the pointer while dragging */
|
||||
x_set_warp_to(NULL);
|
||||
tree_render();
|
||||
@ -612,8 +617,9 @@ void floating_drag_window(Con *con, const xcb_button_press_event_t *event, bool
|
||||
}
|
||||
|
||||
/* If this is a scratchpad window, don't auto center it from now on. */
|
||||
if (con->scratchpad_state == SCRATCHPAD_FRESH)
|
||||
if (con->scratchpad_state == SCRATCHPAD_FRESH) {
|
||||
con->scratchpad_state = SCRATCHPAD_CHANGED;
|
||||
}
|
||||
|
||||
tree_render();
|
||||
}
|
||||
@ -643,15 +649,17 @@ DRAGGING_CB(resize_window_callback) {
|
||||
|
||||
/* First guess: We resize by exactly the amount the mouse moved,
|
||||
* taking into account in which corner the client was grabbed */
|
||||
if (corner & BORDER_LEFT)
|
||||
if (corner & BORDER_LEFT) {
|
||||
dest_width = old_rect->width - (new_x - event->root_x);
|
||||
else
|
||||
} else {
|
||||
dest_width = old_rect->width + (new_x - event->root_x);
|
||||
}
|
||||
|
||||
if (corner & BORDER_TOP)
|
||||
if (corner & BORDER_TOP) {
|
||||
dest_height = old_rect->height - (new_y - event->root_y);
|
||||
else
|
||||
} else {
|
||||
dest_height = old_rect->height + (new_y - event->root_y);
|
||||
}
|
||||
|
||||
/* User wants to keep proportions, so we may have to adjust our values */
|
||||
if (params->proportional) {
|
||||
@ -666,11 +674,13 @@ DRAGGING_CB(resize_window_callback) {
|
||||
|
||||
/* If not the lower right corner is grabbed, we must also reposition
|
||||
* the client by exactly the amount we resized it */
|
||||
if (corner & BORDER_LEFT)
|
||||
if (corner & BORDER_LEFT) {
|
||||
dest_x = old_rect->x + (old_rect->width - con->rect.width);
|
||||
}
|
||||
|
||||
if (corner & BORDER_TOP)
|
||||
if (corner & BORDER_TOP) {
|
||||
dest_y = old_rect->y + (old_rect->height - con->rect.height);
|
||||
}
|
||||
|
||||
con->rect.x = dest_x;
|
||||
con->rect.y = dest_y;
|
||||
@ -697,10 +707,11 @@ void floating_resize_window(Con *con, const bool proportional,
|
||||
* a bitmask of the nearest borders (BORDER_LEFT, BORDER_RIGHT, …) */
|
||||
border_t corner = 0;
|
||||
|
||||
if (event->event_x <= (int16_t)(con->rect.width / 2))
|
||||
if (event->event_x <= (int16_t)(con->rect.width / 2)) {
|
||||
corner |= BORDER_LEFT;
|
||||
else
|
||||
} else {
|
||||
corner |= BORDER_RIGHT;
|
||||
}
|
||||
|
||||
int cursor = 0;
|
||||
if (event->event_y <= (int16_t)(con->rect.height / 2)) {
|
||||
@ -724,12 +735,14 @@ void floating_resize_window(Con *con, const bool proportional,
|
||||
}
|
||||
|
||||
/* If the user cancels, undo the resize */
|
||||
if (drag_result == DRAG_REVERT)
|
||||
if (drag_result == DRAG_REVERT) {
|
||||
floating_reposition(con, initial_rect);
|
||||
}
|
||||
|
||||
/* If this is a scratchpad window, don't auto center it from now on. */
|
||||
if (con->scratchpad_state == SCRATCHPAD_FRESH)
|
||||
if (con->scratchpad_state == SCRATCHPAD_FRESH) {
|
||||
con->scratchpad_state = SCRATCHPAD_CHANGED;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -752,8 +765,9 @@ bool floating_reposition(Con *con, Rect newrect) {
|
||||
floating_maybe_reassign_ws(con);
|
||||
|
||||
/* If this is a scratchpad window, don't auto center it from now on. */
|
||||
if (con->scratchpad_state == SCRATCHPAD_FRESH)
|
||||
if (con->scratchpad_state == SCRATCHPAD_FRESH) {
|
||||
con->scratchpad_state = SCRATCHPAD_CHANGED;
|
||||
}
|
||||
|
||||
tree_render();
|
||||
return true;
|
||||
@ -779,16 +793,19 @@ void floating_resize(Con *floating_con, uint32_t x, uint32_t y) {
|
||||
bool prefer_height = (rect->width == x);
|
||||
rect->width = x;
|
||||
rect->height = y;
|
||||
if (wi)
|
||||
if (wi) {
|
||||
rect->width += (wi - 1 - rect->width) % wi;
|
||||
if (hi)
|
||||
}
|
||||
if (hi) {
|
||||
rect->height += (hi - 1 - rect->height) % hi;
|
||||
}
|
||||
|
||||
floating_check_size(floating_con, prefer_height);
|
||||
|
||||
/* If this is a scratchpad window, don't auto center it from now on. */
|
||||
if (floating_con->scratchpad_state == SCRATCHPAD_FRESH)
|
||||
if (floating_con->scratchpad_state == SCRATCHPAD_FRESH) {
|
||||
floating_con->scratchpad_state = SCRATCHPAD_CHANGED;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
18
src/gaps.c
18
src/gaps.c
@ -15,16 +15,18 @@
|
||||
*/
|
||||
gaps_t calculate_effective_gaps(Con *con) {
|
||||
Con *workspace = con_get_workspace(con);
|
||||
if (workspace == NULL)
|
||||
if (workspace == NULL) {
|
||||
return (gaps_t){0, 0, 0, 0, 0};
|
||||
}
|
||||
|
||||
bool one_child = con_num_visible_children(workspace) <= 1 ||
|
||||
(con_num_children(workspace) == 1 &&
|
||||
(TAILQ_FIRST(&(workspace->nodes_head))->layout == L_TABBED ||
|
||||
TAILQ_FIRST(&(workspace->nodes_head))->layout == L_STACKED));
|
||||
|
||||
if (config.smart_gaps == SMART_GAPS_ON && one_child)
|
||||
if (config.smart_gaps == SMART_GAPS_ON && one_child) {
|
||||
return (gaps_t){0, 0, 0, 0, 0};
|
||||
}
|
||||
|
||||
gaps_t gaps = {
|
||||
.inner = (workspace->gaps.inner + config.gaps.inner),
|
||||
@ -90,22 +92,26 @@ bool gaps_should_inset_con(Con *con, int children) {
|
||||
bool gaps_has_adjacent_container(Con *con, direction_t direction) {
|
||||
Con *workspace = con_get_workspace(con);
|
||||
Con *fullscreen = con_get_fullscreen_con(workspace, CF_GLOBAL);
|
||||
if (fullscreen == NULL)
|
||||
if (fullscreen == NULL) {
|
||||
fullscreen = con_get_fullscreen_con(workspace, CF_OUTPUT);
|
||||
}
|
||||
|
||||
/* If this container is fullscreen by itself, there's no adjacent container. */
|
||||
if (con == fullscreen)
|
||||
if (con == fullscreen) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Con *first = con;
|
||||
Con *second = NULL;
|
||||
bool found_neighbor = resize_find_tiling_participants(&first, &second, direction, false);
|
||||
if (!found_neighbor)
|
||||
if (!found_neighbor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* If we have an adjacent container and nothing is fullscreen, we consider it. */
|
||||
if (fullscreen == NULL)
|
||||
if (fullscreen == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* For fullscreen containers, only consider the adjacent container if it is also fullscreen. */
|
||||
return con_has_parent(con, fullscreen) && con_has_parent(second, fullscreen);
|
||||
|
@ -58,17 +58,20 @@ bool event_is_ignored(const int sequence, const int response_type) {
|
||||
event = SLIST_NEXT(event, ignore_events);
|
||||
SLIST_REMOVE(&ignore_events, save, Ignore_Event, ignore_events);
|
||||
free(save);
|
||||
} else
|
||||
} else {
|
||||
event = SLIST_NEXT(event, ignore_events);
|
||||
}
|
||||
}
|
||||
|
||||
SLIST_FOREACH (event, &ignore_events, ignore_events) {
|
||||
if (event->sequence != sequence)
|
||||
if (event->sequence != sequence) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (event->response_type != -1 &&
|
||||
event->response_type != response_type)
|
||||
event->response_type != response_type) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Instead of removing & freeing a sequence number we better wait until
|
||||
* it gets garbage collected. It may generate multiple events (there
|
||||
@ -89,8 +92,9 @@ static void check_crossing_screen_boundary(uint32_t x, uint32_t y) {
|
||||
Output *output;
|
||||
|
||||
/* If the user disable focus follows mouse, we have nothing to do here */
|
||||
if (config.disable_focus_follows_mouse)
|
||||
if (config.disable_focus_follows_mouse) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((output = get_output_containing(x, y)) == NULL) {
|
||||
ELOG("ERROR: No such screen\n");
|
||||
@ -111,8 +115,9 @@ static void check_crossing_screen_boundary(uint32_t x, uint32_t y) {
|
||||
con_focus(next);
|
||||
|
||||
/* If the focus changed, we re-render to get updated decorations */
|
||||
if (old_focused != focused)
|
||||
if (old_focused != focused) {
|
||||
tree_render();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -167,19 +172,22 @@ static void handle_enter_notify(xcb_enter_notify_event_t *event) {
|
||||
}
|
||||
}
|
||||
|
||||
if (config.disable_focus_follows_mouse)
|
||||
if (config.disable_focus_follows_mouse) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* if this container is already focused, there is nothing to do. */
|
||||
if (con == focused)
|
||||
if (con == focused) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get the currently focused workspace to check if the focus change also
|
||||
* involves changing workspaces. If so, we need to call workspace_show() to
|
||||
* correctly update state and send the IPC event. */
|
||||
Con *ws = con_get_workspace(con);
|
||||
if (ws != con_get_workspace(focused))
|
||||
if (ws != con_get_workspace(focused)) {
|
||||
workspace_show(ws);
|
||||
}
|
||||
|
||||
focused_id = XCB_NONE;
|
||||
con_focus(con_descend_focused(con));
|
||||
@ -197,8 +205,9 @@ static void handle_motion_notify(xcb_motion_notify_event_t *event) {
|
||||
|
||||
/* Skip events where the pointer was over a child window, we are only
|
||||
* interested in events on the root window. */
|
||||
if (event->child != XCB_NONE)
|
||||
if (event->child != XCB_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
Con *con;
|
||||
if ((con = con_by_frame_id(event->event)) == NULL) {
|
||||
@ -207,18 +216,21 @@ static void handle_motion_notify(xcb_motion_notify_event_t *event) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (config.disable_focus_follows_mouse)
|
||||
if (config.disable_focus_follows_mouse) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (con->layout != L_DEFAULT && con->layout != L_SPLITV && con->layout != L_SPLITH)
|
||||
if (con->layout != L_DEFAULT && con->layout != L_SPLITV && con->layout != L_SPLITH) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* see over which rect the user is */
|
||||
if (con->window != NULL) {
|
||||
if (rect_contains(con->deco_rect, event->event_x, event->event_y)) {
|
||||
/* We found the rect, let’s see if this window is focused */
|
||||
if (TAILQ_FIRST(&(con->parent->focus_head)) == con)
|
||||
if (TAILQ_FIRST(&(con->parent->focus_head)) == con) {
|
||||
return;
|
||||
}
|
||||
|
||||
con_focus(con);
|
||||
x_push_changes(croot);
|
||||
@ -227,12 +239,14 @@ static void handle_motion_notify(xcb_motion_notify_event_t *event) {
|
||||
} else {
|
||||
Con *current;
|
||||
TAILQ_FOREACH_REVERSE (current, &(con->nodes_head), nodes_head, nodes) {
|
||||
if (!rect_contains(current->deco_rect, event->event_x, event->event_y))
|
||||
if (!rect_contains(current->deco_rect, event->event_x, event->event_y)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* We found the rect, let’s see if this window is focused */
|
||||
if (TAILQ_FIRST(&(con->focus_head)) == current)
|
||||
if (TAILQ_FIRST(&(con->focus_head)) == current) {
|
||||
return;
|
||||
}
|
||||
|
||||
con_focus(current);
|
||||
x_push_changes(croot);
|
||||
@ -248,8 +262,9 @@ static void handle_motion_notify(xcb_motion_notify_event_t *event) {
|
||||
*/
|
||||
static void handle_mapping_notify(xcb_mapping_notify_event_t *event) {
|
||||
if (event->request != XCB_MAPPING_KEYBOARD &&
|
||||
event->request != XCB_MAPPING_MODIFIER)
|
||||
event->request != XCB_MAPPING_MODIFIER) {
|
||||
return;
|
||||
}
|
||||
|
||||
DLOG("Received mapping_notify for keyboard or modifier mapping, re-grabbing keys\n");
|
||||
xcb_refresh_keyboard_mapping(keysyms, event);
|
||||
@ -479,8 +494,9 @@ static void handle_unmap_notify_event(xcb_unmap_notify_event_t *event) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (con->ignore_unmap > 0)
|
||||
if (con->ignore_unmap > 0) {
|
||||
con->ignore_unmap--;
|
||||
}
|
||||
/* See the end of this function. */
|
||||
cookie = xcb_get_input_focus(conn);
|
||||
DLOG("ignore_unmap = %d for frame of container %p\n", con->ignore_unmap, con);
|
||||
@ -549,12 +565,14 @@ static void handle_destroy_notify_event(xcb_destroy_notify_event_t *event) {
|
||||
}
|
||||
|
||||
static bool window_name_changed(i3Window *window, char *old_name) {
|
||||
if ((old_name == NULL) && (window->name == NULL))
|
||||
if ((old_name == NULL) && (window->name == NULL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Either the old or the new one is NULL, but not both. */
|
||||
if ((old_name == NULL) ^ (window->name == NULL))
|
||||
if ((old_name == NULL) ^ (window->name == NULL)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (strcmp(old_name, i3string_as_utf8(window->name)) != 0);
|
||||
}
|
||||
@ -572,8 +590,9 @@ static bool handle_windowname_change(Con *con, xcb_get_property_reply_t *prop) {
|
||||
|
||||
x_push_changes(croot);
|
||||
|
||||
if (window_name_changed(con->window, old_name))
|
||||
if (window_name_changed(con->window, old_name)) {
|
||||
ipc_send_window_event("title", con);
|
||||
}
|
||||
|
||||
FREE(old_name);
|
||||
|
||||
@ -594,8 +613,9 @@ static bool handle_windowname_change_legacy(Con *con, xcb_get_property_reply_t *
|
||||
|
||||
x_push_changes(croot);
|
||||
|
||||
if (window_name_changed(con->window, old_name))
|
||||
if (window_name_changed(con->window, old_name)) {
|
||||
ipc_send_window_event("title", con);
|
||||
}
|
||||
|
||||
FREE(old_name);
|
||||
|
||||
@ -660,8 +680,9 @@ static void handle_expose_event(xcb_expose_event_t *event) {
|
||||
static void handle_client_message(xcb_client_message_event_t *event) {
|
||||
/* If this is a startup notification ClientMessage, the library will handle
|
||||
* it and call our monitor_event() callback. */
|
||||
if (sn_xcb_display_process_event(sndisplay, (xcb_generic_event_t *)event))
|
||||
if (sn_xcb_display_process_event(sndisplay, (xcb_generic_event_t *)event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG("ClientMessage for window 0x%08x\n", event->window);
|
||||
if (event->type == A__NET_WM_STATE) {
|
||||
@ -704,12 +725,13 @@ static void handle_client_message(xcb_client_message_event_t *event) {
|
||||
}
|
||||
} else if (event->data.data32[1] == A__NET_WM_STATE_STICKY) {
|
||||
DLOG("Received a client message to modify _NET_WM_STATE_STICKY.\n");
|
||||
if (event->data.data32[0] == _NET_WM_STATE_ADD)
|
||||
if (event->data.data32[0] == _NET_WM_STATE_ADD) {
|
||||
con->sticky = true;
|
||||
else if (event->data.data32[0] == _NET_WM_STATE_REMOVE)
|
||||
} else if (event->data.data32[0] == _NET_WM_STATE_REMOVE) {
|
||||
con->sticky = false;
|
||||
else if (event->data.data32[0] == _NET_WM_STATE_TOGGLE)
|
||||
} else if (event->data.data32[0] == _NET_WM_STATE_TOGGLE) {
|
||||
con->sticky = !con->sticky;
|
||||
}
|
||||
|
||||
DLOG("New sticky status for con = %p is %i.\n", con, con->sticky);
|
||||
ewmh_update_sticky(con->window->id, con->sticky);
|
||||
@ -719,8 +741,9 @@ static void handle_client_message(xcb_client_message_event_t *event) {
|
||||
|
||||
tree_render();
|
||||
} else if (event->type == A__NET_ACTIVE_WINDOW) {
|
||||
if (event->format != 32)
|
||||
if (event->format != 32) {
|
||||
return;
|
||||
}
|
||||
|
||||
DLOG("_NET_ACTIVE_WINDOW: Window 0x%08x should be activated\n", event->window);
|
||||
|
||||
@ -769,8 +792,9 @@ static void handle_client_message(xcb_client_message_event_t *event) {
|
||||
DLOG("Marking con = %p urgent\n", con);
|
||||
con_set_urgency(con, true);
|
||||
con = remanage_window(con);
|
||||
} else
|
||||
} else {
|
||||
DLOG("Ignoring request for con = %p.\n", con);
|
||||
}
|
||||
}
|
||||
|
||||
tree_render();
|
||||
@ -880,8 +904,9 @@ static void handle_client_message(xcb_client_message_event_t *event) {
|
||||
if (con) {
|
||||
DLOG("Handling _NET_CLOSE_WINDOW request (con = %p)\n", con);
|
||||
|
||||
if (event->data.data32[0])
|
||||
if (event->data.data32[0]) {
|
||||
last_timestamp = event->data.data32[0];
|
||||
}
|
||||
|
||||
tree_close_internal(con, KILL_WINDOW, false);
|
||||
tree_render();
|
||||
@ -1032,8 +1057,9 @@ static void handle_focus_in(xcb_focus_in_event_t *event) {
|
||||
}
|
||||
|
||||
Con *con;
|
||||
if ((con = con_by_window_id(event->event)) == NULL || con->window == NULL)
|
||||
if ((con = con_by_window_id(event->event)) == NULL || con->window == NULL) {
|
||||
return;
|
||||
}
|
||||
DLOG("That is con %p / %s\n", con, con->name);
|
||||
|
||||
if (event->mode == XCB_NOTIFY_MODE_GRAB ||
|
||||
@ -1349,8 +1375,9 @@ static void property_notify(uint8_t state, xcb_window_t window, xcb_atom_t atom)
|
||||
Con *con;
|
||||
|
||||
for (size_t c = 0; c < NUM_HANDLERS; c++) {
|
||||
if (property_handlers[c].atom != atom)
|
||||
if (property_handlers[c].atom != atom) {
|
||||
continue;
|
||||
}
|
||||
|
||||
handler = &property_handlers[c];
|
||||
break;
|
||||
@ -1377,8 +1404,9 @@ static void property_notify(uint8_t state, xcb_window_t window, xcb_atom_t atom)
|
||||
}
|
||||
|
||||
/* the handler will free() the reply unless it returns false */
|
||||
if (!handler->cb(con, propr))
|
||||
if (!handler->cb(con, propr)) {
|
||||
FREE(propr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1387,8 +1415,9 @@ static void property_notify(uint8_t state, xcb_window_t window, xcb_atom_t atom)
|
||||
*
|
||||
*/
|
||||
void handle_event(int type, xcb_generic_event_t *event) {
|
||||
if (type != XCB_MOTION_NOTIFY)
|
||||
if (type != XCB_MOTION_NOTIFY) {
|
||||
DLOG("event type %d, xkb_base %d\n", type, xkb_base);
|
||||
}
|
||||
|
||||
if (randr_base > -1 &&
|
||||
type == randr_base + XCB_RANDR_SCREEN_CHANGE_NOTIFY) {
|
||||
@ -1404,8 +1433,9 @@ void handle_event(int type, xcb_generic_event_t *event) {
|
||||
DLOG("xkb new keyboard notify, sequence %d, time %d\n", state->sequence, state->time);
|
||||
xcb_key_symbols_free(keysyms);
|
||||
keysyms = xcb_key_symbols_alloc(conn);
|
||||
if (((xcb_xkb_new_keyboard_notify_event_t *)event)->changed & XCB_XKB_NKN_DETAIL_KEYCODES)
|
||||
if (((xcb_xkb_new_keyboard_notify_event_t *)event)->changed & XCB_XKB_NKN_DETAIL_KEYCODES) {
|
||||
(void)load_keymap();
|
||||
}
|
||||
ungrab_all_keys(conn);
|
||||
translate_keysyms();
|
||||
grab_all_keys(conn);
|
||||
@ -1424,8 +1454,9 @@ void handle_event(int type, xcb_generic_event_t *event) {
|
||||
}
|
||||
} else if (state->xkbType == XCB_XKB_STATE_NOTIFY) {
|
||||
DLOG("xkb state group = %d\n", state->group);
|
||||
if (xkb_current_group == state->group)
|
||||
if (xkb_current_group == state->group) {
|
||||
return;
|
||||
}
|
||||
xkb_current_group = state->group;
|
||||
ungrab_all_keys(conn);
|
||||
grab_all_keys(conn);
|
||||
|
78
src/ipc.c
78
src/ipc.c
@ -216,8 +216,9 @@ IPC_HANDLER(run_command) {
|
||||
CommandResult *result = parse_command(command, gen, client);
|
||||
free(command);
|
||||
|
||||
if (result->needs_tree_render)
|
||||
if (result->needs_tree_render) {
|
||||
tree_render();
|
||||
}
|
||||
|
||||
command_result_free(result);
|
||||
|
||||
@ -338,10 +339,11 @@ static void dump_binding(yajl_gen gen, Binding *bind) {
|
||||
ystr((const char *)(bind->input_type == B_KEYBOARD ? "keyboard" : "mouse"));
|
||||
|
||||
ystr("symbol");
|
||||
if (bind->symbol == NULL)
|
||||
if (bind->symbol == NULL) {
|
||||
y(null);
|
||||
else
|
||||
} else {
|
||||
ystr(bind->symbol);
|
||||
}
|
||||
|
||||
ystr("command");
|
||||
ystr(bind->command);
|
||||
@ -386,13 +388,14 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
|
||||
|
||||
/* provided for backwards compatibility only. */
|
||||
ystr("orientation");
|
||||
if (!con_is_split(con))
|
||||
if (!con_is_split(con)) {
|
||||
ystr("none");
|
||||
else {
|
||||
if (con_orientation(con) == HORIZ)
|
||||
} else {
|
||||
if (con_orientation(con) == HORIZ) {
|
||||
ystr("horizontal");
|
||||
else
|
||||
} else {
|
||||
ystr("vertical");
|
||||
}
|
||||
}
|
||||
|
||||
ystr("scratchpad_state");
|
||||
@ -409,10 +412,11 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
|
||||
}
|
||||
|
||||
ystr("percent");
|
||||
if (con->percent == 0.0)
|
||||
if (con->percent == 0.0) {
|
||||
y(null);
|
||||
else
|
||||
} else {
|
||||
y(double, con->percent);
|
||||
}
|
||||
|
||||
ystr("urgent");
|
||||
y(bool, con->urgent);
|
||||
@ -516,12 +520,13 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
|
||||
dump_rect(gen, "geometry", con->geometry);
|
||||
|
||||
ystr("name");
|
||||
if (con->window && con->window->name)
|
||||
if (con->window && con->window->name) {
|
||||
ystr(i3string_as_utf8(con->window->name));
|
||||
else if (con->name != NULL)
|
||||
} else if (con->name != NULL) {
|
||||
ystr(con->name);
|
||||
else
|
||||
} else {
|
||||
y(null);
|
||||
}
|
||||
|
||||
if (con->title_format != NULL) {
|
||||
ystr("title_format");
|
||||
@ -539,10 +544,11 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
|
||||
}
|
||||
|
||||
ystr("window");
|
||||
if (con->window)
|
||||
if (con->window) {
|
||||
y(integer, con->window->id);
|
||||
else
|
||||
} else {
|
||||
y(null);
|
||||
}
|
||||
|
||||
ystr("window_type");
|
||||
if (con->window) {
|
||||
@ -571,8 +577,9 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
|
||||
} else {
|
||||
ystr("unknown");
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
y(null);
|
||||
}
|
||||
|
||||
if (con->window && !inplace_restart) {
|
||||
/* Window properties are useless to preserve when restarting because
|
||||
@ -600,10 +607,11 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
|
||||
}
|
||||
|
||||
ystr("transient_for");
|
||||
if (con->window->transient_for == XCB_NONE)
|
||||
if (con->window->transient_for == XCB_NONE) {
|
||||
y(null);
|
||||
else
|
||||
} else {
|
||||
y(integer, con->window->transient_for);
|
||||
}
|
||||
|
||||
y(map_close);
|
||||
}
|
||||
@ -660,8 +668,9 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
|
||||
TAILQ_FOREACH (match, &(con->swallow_head), matches) {
|
||||
/* We will generate a new restart_mode match specification after this
|
||||
* loop, so skip this one. */
|
||||
if (match->restart_mode)
|
||||
if (match->restart_mode) {
|
||||
continue;
|
||||
}
|
||||
y(map_open);
|
||||
if (match->dock != M_DONTCHECK) {
|
||||
ystr("dock");
|
||||
@ -714,8 +723,9 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
|
||||
}
|
||||
|
||||
static void dump_bar_bindings(yajl_gen gen, Barconfig *config) {
|
||||
if (TAILQ_EMPTY(&(config->bar_bindings)))
|
||||
if (TAILQ_EMPTY(&(config->bar_bindings))) {
|
||||
return;
|
||||
}
|
||||
|
||||
ystr("bindings");
|
||||
y(array_open);
|
||||
@ -821,10 +831,11 @@ static void dump_bar_config(yajl_gen gen, Barconfig *config) {
|
||||
dump_bar_bindings(gen, config);
|
||||
|
||||
ystr("position");
|
||||
if (config->position == P_BOTTOM)
|
||||
if (config->position == P_BOTTOM) {
|
||||
ystr("bottom");
|
||||
else
|
||||
} else {
|
||||
ystr("top");
|
||||
}
|
||||
|
||||
YSTR_IF_SET(status_command);
|
||||
YSTR_IF_SET(workspace_command);
|
||||
@ -925,8 +936,9 @@ IPC_HANDLER(get_workspaces) {
|
||||
|
||||
Con *output;
|
||||
TAILQ_FOREACH (output, &(croot->nodes_head), nodes) {
|
||||
if (con_is_internal(output))
|
||||
if (con_is_internal(output)) {
|
||||
continue;
|
||||
}
|
||||
Con *ws;
|
||||
TAILQ_FOREACH (ws, &(output_get_content(output)->nodes_head), nodes) {
|
||||
assert(ws->type == CT_WORKSPACE);
|
||||
@ -1015,10 +1027,11 @@ IPC_HANDLER(get_outputs) {
|
||||
|
||||
ystr("current_workspace");
|
||||
Con *ws = NULL;
|
||||
if (output->con && (ws = con_get_fullscreen_con(output->con, CF_OUTPUT)))
|
||||
if (output->con && (ws = con_get_fullscreen_con(output->con, CF_OUTPUT))) {
|
||||
ystr(ws->name);
|
||||
else
|
||||
} else {
|
||||
y(null);
|
||||
}
|
||||
|
||||
y(map_close);
|
||||
}
|
||||
@ -1137,8 +1150,9 @@ IPC_HANDLER(get_bar_config) {
|
||||
LOG("IPC: looking for config for bar ID \"%s\"\n", bar_id);
|
||||
Barconfig *current, *config = NULL;
|
||||
TAILQ_FOREACH (current, &barconfigs, configs) {
|
||||
if (strcmp(current->id, bar_id) != 0)
|
||||
if (strcmp(current->id, bar_id) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
config = current;
|
||||
break;
|
||||
@ -1460,9 +1474,9 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (message_type >= (sizeof(handlers) / sizeof(handler_t)))
|
||||
if (message_type >= (sizeof(handlers) / sizeof(handler_t))) {
|
||||
DLOG("Unhandled message type: %d\n", message_type);
|
||||
else {
|
||||
} else {
|
||||
handler_t h = handlers[message_type];
|
||||
h(client, message, 0, message_length, message_type);
|
||||
}
|
||||
@ -1592,16 +1606,18 @@ yajl_gen ipc_marshal_workspace_event(const char *change, Con *current, Con *old)
|
||||
ystr(change);
|
||||
|
||||
ystr("current");
|
||||
if (current == NULL)
|
||||
if (current == NULL) {
|
||||
y(null);
|
||||
else
|
||||
} else {
|
||||
dump_node(gen, current, false);
|
||||
}
|
||||
|
||||
ystr("old");
|
||||
if (old == NULL)
|
||||
if (old == NULL) {
|
||||
y(null);
|
||||
else
|
||||
} else {
|
||||
dump_node(gen, old, false);
|
||||
}
|
||||
|
||||
y(map_close);
|
||||
|
||||
|
@ -25,8 +25,9 @@ void handle_key_press(xcb_key_press_event_t *event) {
|
||||
Binding *bind = get_binding_from_xcb_event((xcb_generic_event_t *)event);
|
||||
|
||||
/* if we couldn't find a binding, we are done */
|
||||
if (bind == NULL)
|
||||
if (bind == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandResult *result = run_binding(bind, NULL);
|
||||
command_result_free(result);
|
||||
|
@ -233,8 +233,9 @@ static int json_end_array(void *ctx) {
|
||||
LOG("focus (reverse) %d\n", mapping->old_id);
|
||||
Con *con;
|
||||
TAILQ_FOREACH (con, &(json_node->focus_head), focused) {
|
||||
if (con->old_id != mapping->old_id)
|
||||
if (con->old_id != mapping->old_id) {
|
||||
continue;
|
||||
}
|
||||
LOG("got it! %p\n", con);
|
||||
/* Move this entry to the top of the focus list. */
|
||||
TAILQ_REMOVE(&(json_node->focus_head), con, focused);
|
||||
@ -257,29 +258,37 @@ static int json_key(void *ctx, const unsigned char *val, size_t len) {
|
||||
FREE(last_key);
|
||||
last_key = scalloc(len + 1, 1);
|
||||
memcpy(last_key, val, len);
|
||||
if (strcasecmp(last_key, "swallows") == 0)
|
||||
if (strcasecmp(last_key, "swallows") == 0) {
|
||||
parsing_swallows = true;
|
||||
}
|
||||
|
||||
if (strcasecmp(last_key, "gaps") == 0)
|
||||
if (strcasecmp(last_key, "gaps") == 0) {
|
||||
parsing_gaps = true;
|
||||
}
|
||||
|
||||
if (strcasecmp(last_key, "rect") == 0)
|
||||
if (strcasecmp(last_key, "rect") == 0) {
|
||||
parsing_rect = true;
|
||||
}
|
||||
|
||||
if (strcasecmp(last_key, "actual_deco_rect") == 0)
|
||||
if (strcasecmp(last_key, "actual_deco_rect") == 0) {
|
||||
parsing_actual_deco_rect = true;
|
||||
}
|
||||
|
||||
if (strcasecmp(last_key, "deco_rect") == 0)
|
||||
if (strcasecmp(last_key, "deco_rect") == 0) {
|
||||
parsing_deco_rect = true;
|
||||
}
|
||||
|
||||
if (strcasecmp(last_key, "window_rect") == 0)
|
||||
if (strcasecmp(last_key, "window_rect") == 0) {
|
||||
parsing_window_rect = true;
|
||||
}
|
||||
|
||||
if (strcasecmp(last_key, "geometry") == 0)
|
||||
if (strcasecmp(last_key, "geometry") == 0) {
|
||||
parsing_geometry = true;
|
||||
}
|
||||
|
||||
if (strcasecmp(last_key, "focus") == 0)
|
||||
if (strcasecmp(last_key, "focus") == 0) {
|
||||
parsing_focus = true;
|
||||
}
|
||||
|
||||
if (strcasecmp(last_key, "marks") == 0) {
|
||||
num_marks = 0;
|
||||
@ -341,12 +350,13 @@ static int json_string(void *ctx, const unsigned char *val, size_t len) {
|
||||
char *buf = NULL;
|
||||
sasprintf(&buf, "%.*s", (int)len, val);
|
||||
if (strcasecmp(buf, "none") == 0 ||
|
||||
strcasecmp(buf, "horizontal") == 0)
|
||||
strcasecmp(buf, "horizontal") == 0) {
|
||||
json_node->last_split_layout = L_SPLITH;
|
||||
else if (strcasecmp(buf, "vertical") == 0)
|
||||
} else if (strcasecmp(buf, "vertical") == 0) {
|
||||
json_node->last_split_layout = L_SPLITV;
|
||||
else
|
||||
} else {
|
||||
LOG("Unhandled orientation: %s\n", buf);
|
||||
}
|
||||
free(buf);
|
||||
} else if (strcasecmp(last_key, "border") == 0) {
|
||||
char *buf = NULL;
|
||||
@ -367,63 +377,67 @@ static int json_string(void *ctx, const unsigned char *val, size_t len) {
|
||||
} else if (strcasecmp(last_key, "type") == 0) {
|
||||
char *buf = NULL;
|
||||
sasprintf(&buf, "%.*s", (int)len, val);
|
||||
if (strcasecmp(buf, "root") == 0)
|
||||
if (strcasecmp(buf, "root") == 0) {
|
||||
json_node->type = CT_ROOT;
|
||||
else if (strcasecmp(buf, "output") == 0)
|
||||
} else if (strcasecmp(buf, "output") == 0) {
|
||||
json_node->type = CT_OUTPUT;
|
||||
else if (strcasecmp(buf, "con") == 0)
|
||||
} else if (strcasecmp(buf, "con") == 0) {
|
||||
json_node->type = CT_CON;
|
||||
else if (strcasecmp(buf, "floating_con") == 0)
|
||||
} else if (strcasecmp(buf, "floating_con") == 0) {
|
||||
json_node->type = CT_FLOATING_CON;
|
||||
else if (strcasecmp(buf, "workspace") == 0)
|
||||
} else if (strcasecmp(buf, "workspace") == 0) {
|
||||
json_node->type = CT_WORKSPACE;
|
||||
else if (strcasecmp(buf, "dockarea") == 0)
|
||||
} else if (strcasecmp(buf, "dockarea") == 0) {
|
||||
json_node->type = CT_DOCKAREA;
|
||||
else
|
||||
} else {
|
||||
LOG("Unhandled \"type\": %s\n", buf);
|
||||
}
|
||||
free(buf);
|
||||
} else if (strcasecmp(last_key, "layout") == 0) {
|
||||
char *buf = NULL;
|
||||
sasprintf(&buf, "%.*s", (int)len, val);
|
||||
if (strcasecmp(buf, "default") == 0)
|
||||
if (strcasecmp(buf, "default") == 0) {
|
||||
/* This set above when we read "orientation". */
|
||||
json_node->layout = json_node->last_split_layout;
|
||||
else if (strcasecmp(buf, "stacked") == 0)
|
||||
} else if (strcasecmp(buf, "stacked") == 0) {
|
||||
json_node->layout = L_STACKED;
|
||||
else if (strcasecmp(buf, "tabbed") == 0)
|
||||
} else if (strcasecmp(buf, "tabbed") == 0) {
|
||||
json_node->layout = L_TABBED;
|
||||
else if (strcasecmp(buf, "dockarea") == 0)
|
||||
} else if (strcasecmp(buf, "dockarea") == 0) {
|
||||
json_node->layout = L_DOCKAREA;
|
||||
else if (strcasecmp(buf, "output") == 0)
|
||||
} else if (strcasecmp(buf, "output") == 0) {
|
||||
json_node->layout = L_OUTPUT;
|
||||
else if (strcasecmp(buf, "splith") == 0)
|
||||
} else if (strcasecmp(buf, "splith") == 0) {
|
||||
json_node->layout = L_SPLITH;
|
||||
else if (strcasecmp(buf, "splitv") == 0)
|
||||
} else if (strcasecmp(buf, "splitv") == 0) {
|
||||
json_node->layout = L_SPLITV;
|
||||
else
|
||||
} else {
|
||||
LOG("Unhandled \"layout\": %s\n", buf);
|
||||
}
|
||||
free(buf);
|
||||
} else if (strcasecmp(last_key, "workspace_layout") == 0) {
|
||||
char *buf = NULL;
|
||||
sasprintf(&buf, "%.*s", (int)len, val);
|
||||
if (strcasecmp(buf, "default") == 0)
|
||||
if (strcasecmp(buf, "default") == 0) {
|
||||
json_node->workspace_layout = L_DEFAULT;
|
||||
else if (strcasecmp(buf, "stacked") == 0)
|
||||
} else if (strcasecmp(buf, "stacked") == 0) {
|
||||
json_node->workspace_layout = L_STACKED;
|
||||
else if (strcasecmp(buf, "tabbed") == 0)
|
||||
} else if (strcasecmp(buf, "tabbed") == 0) {
|
||||
json_node->workspace_layout = L_TABBED;
|
||||
else
|
||||
} else {
|
||||
LOG("Unhandled \"workspace_layout\": %s\n", buf);
|
||||
}
|
||||
free(buf);
|
||||
} else if (strcasecmp(last_key, "last_split_layout") == 0) {
|
||||
char *buf = NULL;
|
||||
sasprintf(&buf, "%.*s", (int)len, val);
|
||||
if (strcasecmp(buf, "splith") == 0)
|
||||
if (strcasecmp(buf, "splith") == 0) {
|
||||
json_node->last_split_layout = L_SPLITH;
|
||||
else if (strcasecmp(buf, "splitv") == 0)
|
||||
} else if (strcasecmp(buf, "splitv") == 0) {
|
||||
json_node->last_split_layout = L_SPLITV;
|
||||
else
|
||||
} else {
|
||||
LOG("Unhandled \"last_splitlayout\": %s\n", buf);
|
||||
}
|
||||
free(buf);
|
||||
} else if (strcasecmp(last_key, "mark") == 0) {
|
||||
DLOG("Found deprecated key \"mark\".\n");
|
||||
@ -435,24 +449,26 @@ static int json_string(void *ctx, const unsigned char *val, size_t len) {
|
||||
} else if (strcasecmp(last_key, "floating") == 0) {
|
||||
char *buf = NULL;
|
||||
sasprintf(&buf, "%.*s", (int)len, val);
|
||||
if (strcasecmp(buf, "auto_off") == 0)
|
||||
if (strcasecmp(buf, "auto_off") == 0) {
|
||||
json_node->floating = FLOATING_AUTO_OFF;
|
||||
else if (strcasecmp(buf, "auto_on") == 0)
|
||||
} else if (strcasecmp(buf, "auto_on") == 0) {
|
||||
json_node->floating = FLOATING_AUTO_ON;
|
||||
else if (strcasecmp(buf, "user_off") == 0)
|
||||
} else if (strcasecmp(buf, "user_off") == 0) {
|
||||
json_node->floating = FLOATING_USER_OFF;
|
||||
else if (strcasecmp(buf, "user_on") == 0)
|
||||
} else if (strcasecmp(buf, "user_on") == 0) {
|
||||
json_node->floating = FLOATING_USER_ON;
|
||||
}
|
||||
free(buf);
|
||||
} else if (strcasecmp(last_key, "scratchpad_state") == 0) {
|
||||
char *buf = NULL;
|
||||
sasprintf(&buf, "%.*s", (int)len, val);
|
||||
if (strcasecmp(buf, "none") == 0)
|
||||
if (strcasecmp(buf, "none") == 0) {
|
||||
json_node->scratchpad_state = SCRATCHPAD_NONE;
|
||||
else if (strcasecmp(buf, "fresh") == 0)
|
||||
} else if (strcasecmp(buf, "fresh") == 0) {
|
||||
json_node->scratchpad_state = SCRATCHPAD_FRESH;
|
||||
else if (strcasecmp(buf, "changed") == 0)
|
||||
} else if (strcasecmp(buf, "changed") == 0) {
|
||||
json_node->scratchpad_state = SCRATCHPAD_CHANGED;
|
||||
}
|
||||
free(buf);
|
||||
} else if (strcasecmp(last_key, "previous_workspace_name") == 0) {
|
||||
FREE(previous_workspace_name);
|
||||
@ -465,27 +481,33 @@ static int json_string(void *ctx, const unsigned char *val, size_t len) {
|
||||
static int json_int(void *ctx, long long val) {
|
||||
LOG("int %lld for key %s\n", val, last_key);
|
||||
/* For backwards compatibility with i3 < 4.8 */
|
||||
if (strcasecmp(last_key, "type") == 0)
|
||||
if (strcasecmp(last_key, "type") == 0) {
|
||||
json_node->type = val;
|
||||
}
|
||||
|
||||
if (strcasecmp(last_key, "fullscreen_mode") == 0)
|
||||
if (strcasecmp(last_key, "fullscreen_mode") == 0) {
|
||||
json_node->fullscreen_mode = val;
|
||||
}
|
||||
|
||||
if (strcasecmp(last_key, "num") == 0)
|
||||
if (strcasecmp(last_key, "num") == 0) {
|
||||
json_node->num = val;
|
||||
}
|
||||
|
||||
if (strcasecmp(last_key, "current_border_width") == 0)
|
||||
if (strcasecmp(last_key, "current_border_width") == 0) {
|
||||
json_node->current_border_width = val;
|
||||
}
|
||||
|
||||
if (strcasecmp(last_key, "window_icon_padding") == 0) {
|
||||
json_node->window_icon_padding = val;
|
||||
}
|
||||
|
||||
if (strcasecmp(last_key, "depth") == 0)
|
||||
if (strcasecmp(last_key, "depth") == 0) {
|
||||
json_node->depth = val;
|
||||
}
|
||||
|
||||
if (!parsing_swallows && strcasecmp(last_key, "id") == 0)
|
||||
if (!parsing_swallows && strcasecmp(last_key, "id") == 0) {
|
||||
json_node->old_id = val;
|
||||
}
|
||||
|
||||
if (parsing_focus) {
|
||||
struct focus_mapping *focus_mapping = scalloc(1, sizeof(struct focus_mapping));
|
||||
@ -495,22 +517,24 @@ static int json_int(void *ctx, long long val) {
|
||||
|
||||
if (parsing_rect || parsing_window_rect || parsing_geometry) {
|
||||
Rect *r;
|
||||
if (parsing_rect)
|
||||
if (parsing_rect) {
|
||||
r = &(json_node->rect);
|
||||
else if (parsing_window_rect)
|
||||
} else if (parsing_window_rect) {
|
||||
r = &(json_node->window_rect);
|
||||
else
|
||||
} else {
|
||||
r = &(json_node->geometry);
|
||||
if (strcasecmp(last_key, "x") == 0)
|
||||
}
|
||||
if (strcasecmp(last_key, "x") == 0) {
|
||||
r->x = val;
|
||||
else if (strcasecmp(last_key, "y") == 0)
|
||||
} else if (strcasecmp(last_key, "y") == 0) {
|
||||
r->y = val;
|
||||
else if (strcasecmp(last_key, "width") == 0)
|
||||
} else if (strcasecmp(last_key, "width") == 0) {
|
||||
r->width = val;
|
||||
else if (strcasecmp(last_key, "height") == 0)
|
||||
} else if (strcasecmp(last_key, "height") == 0) {
|
||||
r->height = val;
|
||||
else
|
||||
} else {
|
||||
ELOG("WARNING: unknown key %s in rect\n", last_key);
|
||||
}
|
||||
DLOG("rect now: (%d, %d, %d, %d)\n",
|
||||
r->x, r->y, r->width, r->height);
|
||||
}
|
||||
@ -529,16 +553,17 @@ static int json_int(void *ctx, long long val) {
|
||||
}
|
||||
}
|
||||
if (parsing_gaps) {
|
||||
if (strcasecmp(last_key, "inner") == 0)
|
||||
if (strcasecmp(last_key, "inner") == 0) {
|
||||
json_node->gaps.inner = val;
|
||||
else if (strcasecmp(last_key, "top") == 0)
|
||||
} else if (strcasecmp(last_key, "top") == 0) {
|
||||
json_node->gaps.top = val;
|
||||
else if (strcasecmp(last_key, "right") == 0)
|
||||
} else if (strcasecmp(last_key, "right") == 0) {
|
||||
json_node->gaps.right = val;
|
||||
else if (strcasecmp(last_key, "bottom") == 0)
|
||||
} else if (strcasecmp(last_key, "bottom") == 0) {
|
||||
json_node->gaps.bottom = val;
|
||||
else if (strcasecmp(last_key, "left") == 0)
|
||||
} else if (strcasecmp(last_key, "left") == 0) {
|
||||
json_node->gaps.left = val;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -550,8 +575,9 @@ static int json_bool(void *ctx, int val) {
|
||||
to_focus = json_node;
|
||||
}
|
||||
|
||||
if (strcasecmp(last_key, "sticky") == 0)
|
||||
if (strcasecmp(last_key, "sticky") == 0) {
|
||||
json_node->sticky = val;
|
||||
}
|
||||
|
||||
if (parsing_swallows) {
|
||||
if (strcasecmp(last_key, "restart_mode") == 0) {
|
||||
@ -585,12 +611,14 @@ static int json_determine_content_shallower(void *ctx) {
|
||||
}
|
||||
|
||||
static int json_determine_content_string(void *ctx, const unsigned char *val, size_t len) {
|
||||
if (strcasecmp(last_key, "type") != 0 || content_level > 1)
|
||||
if (strcasecmp(last_key, "type") != 0 || content_level > 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
DLOG("string = %.*s, last_key = %s\n", (int)len, val, last_key);
|
||||
if (strncasecmp((const char *)val, "workspace", len) == 0)
|
||||
if (strncasecmp((const char *)val, "workspace", len) == 0) {
|
||||
content_result = JSON_CONTENT_WORKSPACE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -702,8 +730,9 @@ void tree_append_json(Con *con, const char *buf, const size_t len, char **errorm
|
||||
if (stat != yajl_status_ok) {
|
||||
unsigned char *str = yajl_get_error(hand, 1, (const unsigned char *)buf, len);
|
||||
ELOG("JSON parsing error: %s\n", str);
|
||||
if (errormsg != NULL)
|
||||
if (errormsg != NULL) {
|
||||
*errormsg = sstrdup((const char *)str);
|
||||
}
|
||||
yajl_free_error(hand, str);
|
||||
while (incomplete-- > 0) {
|
||||
Con *parent = json_node->parent;
|
||||
|
27
src/log.c
27
src/log.c
@ -94,9 +94,9 @@ static void store_log_markers(void) {
|
||||
*/
|
||||
void init_logging(void) {
|
||||
if (!errorfilename) {
|
||||
if (!(errorfilename = get_process_filename("errorlog")))
|
||||
if (!(errorfilename = get_process_filename("errorlog"))) {
|
||||
fprintf(stderr, "Could not initialize errorlog\n");
|
||||
else {
|
||||
} else {
|
||||
errorfile = fopen(errorfilename, "w");
|
||||
if (!errorfile) {
|
||||
fprintf(stderr, "Could not initialize errorlog on %s: %s\n",
|
||||
@ -121,10 +121,11 @@ void init_logging(void) {
|
||||
/* Start SHM logging if shmlog_size is > 0. shmlog_size is SHMLOG_SIZE by
|
||||
* default on development versions, and 0 on release versions. If it is
|
||||
* not > 0, the user has turned it off, so let's close the logbuffer. */
|
||||
if (shmlog_size > 0 && logbuffer == NULL)
|
||||
if (shmlog_size > 0 && logbuffer == NULL) {
|
||||
open_logbuffer();
|
||||
else if (shmlog_size <= 0 && logbuffer)
|
||||
} else if (shmlog_size <= 0 && logbuffer) {
|
||||
close_logbuffer();
|
||||
}
|
||||
atexit(purge_zerobyte_logfile);
|
||||
}
|
||||
|
||||
@ -292,8 +293,9 @@ static void vlog(const bool print, const char *fmt, va_list args) {
|
||||
|
||||
store_log_markers();
|
||||
|
||||
if (print)
|
||||
if (print) {
|
||||
fwrite(message, len, 1, stdout);
|
||||
}
|
||||
|
||||
log_broadcast_to_clients(message, len);
|
||||
}
|
||||
@ -307,8 +309,9 @@ static void vlog(const bool print, const char *fmt, va_list args) {
|
||||
void verboselog(char *fmt, ...) {
|
||||
va_list args;
|
||||
|
||||
if (!logbuffer && !verbose)
|
||||
if (!logbuffer && !verbose) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_start(args, fmt);
|
||||
vlog(verbose, fmt, args);
|
||||
@ -342,8 +345,9 @@ void errorlog(char *fmt, ...) {
|
||||
void debuglog(char *fmt, ...) {
|
||||
va_list args;
|
||||
|
||||
if (!logbuffer && !(debug_logging))
|
||||
if (!logbuffer && !(debug_logging)) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_start(args, fmt);
|
||||
vlog(debug_logging, fmt, args);
|
||||
@ -359,15 +363,18 @@ void purge_zerobyte_logfile(void) {
|
||||
struct stat st;
|
||||
char *slash;
|
||||
|
||||
if (!errorfilename)
|
||||
if (!errorfilename) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* don't delete the log file if it contains something */
|
||||
if ((stat(errorfilename, &st)) == -1 || st.st_size > 0)
|
||||
if ((stat(errorfilename, &st)) == -1 || st.st_size > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (unlink(errorfilename) == -1)
|
||||
if (unlink(errorfilename) == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((slash = strrchr(errorfilename, '/')) != NULL) {
|
||||
*slash = '\0';
|
||||
|
64
src/main.c
64
src/main.c
@ -134,9 +134,9 @@ static void xcb_prepare_cb(EV_P_ ev_prepare *w, int revents) {
|
||||
|
||||
while ((event = xcb_poll_for_event(conn)) != NULL) {
|
||||
if (event->response_type == 0) {
|
||||
if (event_is_ignored(event->sequence, 0))
|
||||
if (event_is_ignored(event->sequence, 0)) {
|
||||
DLOG("Expected X11 Error received for sequence %x\n", event->sequence);
|
||||
else {
|
||||
} else {
|
||||
xcb_generic_error_t *error = (xcb_generic_error_t *)event;
|
||||
DLOG("X11 Error received (probably harmless)! sequence 0x%x, error_code = %d\n",
|
||||
error->sequence, error->error_code);
|
||||
@ -322,8 +322,9 @@ int main(int argc, char *argv[]) {
|
||||
getrlimit(RLIMIT_CORE, &original_rlimit_core);
|
||||
|
||||
/* Disable output buffering to make redirects in .xsession actually useful for debugging */
|
||||
if (!isatty(fileno(stdout)))
|
||||
if (!isatty(fileno(stdout))) {
|
||||
setbuf(stdout, NULL);
|
||||
}
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
@ -506,20 +507,23 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||
if (sockfd == -1)
|
||||
if (sockfd == -1) {
|
||||
err(EXIT_FAILURE, "Could not create socket");
|
||||
}
|
||||
|
||||
struct sockaddr_un addr;
|
||||
memset(&addr, 0, sizeof(struct sockaddr_un));
|
||||
addr.sun_family = AF_LOCAL;
|
||||
strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
|
||||
FREE(socket_path);
|
||||
if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0)
|
||||
if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) {
|
||||
err(EXIT_FAILURE, "Could not connect to i3");
|
||||
}
|
||||
|
||||
if (ipc_send_message(sockfd, strlen(payload), I3_IPC_MESSAGE_TYPE_RUN_COMMAND,
|
||||
(uint8_t *)payload) == -1)
|
||||
(uint8_t *)payload) == -1) {
|
||||
err(EXIT_FAILURE, "IPC: write()");
|
||||
}
|
||||
FREE(payload);
|
||||
|
||||
uint32_t reply_length;
|
||||
@ -527,12 +531,14 @@ int main(int argc, char *argv[]) {
|
||||
uint8_t *reply;
|
||||
int ret;
|
||||
if ((ret = ipc_recv_message(sockfd, &reply_type, &reply_length, &reply)) != 0) {
|
||||
if (ret == -1)
|
||||
if (ret == -1) {
|
||||
err(EXIT_FAILURE, "IPC: read()");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (reply_type != I3_IPC_REPLY_TYPE_COMMAND)
|
||||
if (reply_type != I3_IPC_REPLY_TYPE_COMMAND) {
|
||||
errx(EXIT_FAILURE, "IPC: received reply of type %d but expected %d (COMMAND)", reply_type, I3_IPC_REPLY_TYPE_COMMAND);
|
||||
}
|
||||
printf("%.*s\n", reply_length, reply);
|
||||
FREE(reply);
|
||||
return 0;
|
||||
@ -556,14 +562,16 @@ int main(int argc, char *argv[]) {
|
||||
cwd_size = cwd_size * 2;
|
||||
cwd = srealloc(cwd, cwd_size);
|
||||
}
|
||||
if (cwd_ret != NULL)
|
||||
if (cwd_ret != NULL) {
|
||||
LOG("CORE DUMPS: Your current working directory is \"%s\".\n", cwd);
|
||||
}
|
||||
int patternfd;
|
||||
if ((patternfd = open("/proc/sys/kernel/core_pattern", O_RDONLY)) >= 0) {
|
||||
memset(cwd, '\0', cwd_size);
|
||||
if (read(patternfd, cwd, cwd_size) > 0)
|
||||
if (read(patternfd, cwd, cwd_size) > 0) {
|
||||
/* a trailing newline is included in cwd */
|
||||
LOG("CORE DUMPS: Your core_pattern is: %s", cwd);
|
||||
}
|
||||
close(patternfd);
|
||||
}
|
||||
free(cwd);
|
||||
@ -572,8 +580,9 @@ int main(int argc, char *argv[]) {
|
||||
LOG("i3 %s starting\n", i3_version);
|
||||
|
||||
conn = xcb_connect(NULL, &conn_screen);
|
||||
if (xcb_connection_has_error(conn))
|
||||
if (xcb_connection_has_error(conn)) {
|
||||
errx(EXIT_FAILURE, "Cannot open display");
|
||||
}
|
||||
|
||||
sndisplay = sn_xcb_display_new(conn, NULL, NULL);
|
||||
|
||||
@ -585,8 +594,9 @@ int main(int argc, char *argv[]) {
|
||||
* only the default loop can handle ev_child events and reap zombies
|
||||
* (the start_application routine relies on that too). */
|
||||
main_loop = EV_DEFAULT;
|
||||
if (main_loop == NULL)
|
||||
if (main_loop == NULL) {
|
||||
die("Could not initialize libev. Bad LIBEV_FLAGS?\n");
|
||||
}
|
||||
|
||||
root_screen = xcb_aux_get_screen(conn, conn_screen);
|
||||
root = root_screen->root;
|
||||
@ -682,10 +692,11 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
if (config.ipc_socket_path == NULL) {
|
||||
/* Fall back to a file name in /tmp/ based on the PID */
|
||||
if ((config.ipc_socket_path = getenv("I3SOCK")) == NULL)
|
||||
if ((config.ipc_socket_path = getenv("I3SOCK")) == NULL) {
|
||||
config.ipc_socket_path = get_process_filename("ipc-socket");
|
||||
else
|
||||
} else {
|
||||
config.ipc_socket_path = sstrdup(config.ipc_socket_path);
|
||||
}
|
||||
}
|
||||
/* Create the UNIX domain socket for IPC */
|
||||
int ipc_socket = create_socket(config.ipc_socket_path, ¤t_socketpath);
|
||||
@ -907,8 +918,9 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
xcb_numlock_mask = aio_get_mod_mask_for(XCB_NUM_LOCK, keysyms);
|
||||
|
||||
if (!load_keymap())
|
||||
if (!load_keymap()) {
|
||||
die("Could not load keymap\n");
|
||||
}
|
||||
|
||||
translate_keysyms();
|
||||
grab_all_keys(conn);
|
||||
@ -925,14 +937,16 @@ int main(int argc, char *argv[]) {
|
||||
rmdir(dir);
|
||||
}
|
||||
}
|
||||
if (needs_tree_init)
|
||||
if (needs_tree_init) {
|
||||
tree_init(greply);
|
||||
}
|
||||
|
||||
free(greply);
|
||||
|
||||
/* Setup fake outputs for testing */
|
||||
if (fake_outputs == NULL && config.fake_outputs != NULL)
|
||||
if (fake_outputs == NULL && config.fake_outputs != NULL) {
|
||||
fake_outputs = config.fake_outputs;
|
||||
}
|
||||
|
||||
if (fake_outputs != NULL) {
|
||||
fake_outputs_init(fake_outputs);
|
||||
@ -957,8 +971,9 @@ int main(int argc, char *argv[]) {
|
||||
TAILQ_FOREACH (con, &(croot->nodes_head), nodes) {
|
||||
Output *output;
|
||||
TAILQ_FOREACH (output, &outputs, outputs) {
|
||||
if (output->active || strcmp(con->name, output_primary_name(output)) != 0)
|
||||
if (output->active || strcmp(con->name, output_primary_name(output)) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* This will correctly correlate the output with its content
|
||||
* container. We need to make the connection to properly
|
||||
@ -1102,8 +1117,9 @@ int main(int argc, char *argv[]) {
|
||||
/* We still need to handle MapRequests which are sent in the
|
||||
* timespan starting from when we register as a window manager and
|
||||
* this piece of code which drops events. */
|
||||
if (type == XCB_MAP_REQUEST)
|
||||
if (type == XCB_MAP_REQUEST) {
|
||||
handle_event(type, event);
|
||||
}
|
||||
|
||||
free(event);
|
||||
}
|
||||
@ -1132,13 +1148,14 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
#if defined(__OpenBSD__)
|
||||
if (pledge("stdio rpath wpath cpath proc exec unix", NULL) == -1)
|
||||
if (pledge("stdio rpath wpath cpath proc exec unix", NULL) == -1) {
|
||||
err(EXIT_FAILURE, "pledge");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!disable_signalhandler)
|
||||
if (!disable_signalhandler) {
|
||||
setup_signal_handler();
|
||||
else {
|
||||
} else {
|
||||
struct sigaction action;
|
||||
|
||||
action.sa_sigaction = handle_core_signal;
|
||||
@ -1150,8 +1167,9 @@ int main(int argc, char *argv[]) {
|
||||
sigaction(SIGILL, &action, NULL) == -1 ||
|
||||
sigaction(SIGABRT, &action, NULL) == -1 ||
|
||||
sigaction(SIGFPE, &action, NULL) == -1 ||
|
||||
sigaction(SIGSEGV, &action, NULL) == -1)
|
||||
sigaction(SIGSEGV, &action, NULL) == -1) {
|
||||
ELOG("Could not setup signal handler.\n");
|
||||
}
|
||||
}
|
||||
|
||||
setup_term_handlers();
|
||||
|
42
src/manage.c
42
src/manage.c
@ -48,20 +48,23 @@ void manage_existing_windows(xcb_window_t root) {
|
||||
xcb_get_window_attributes_cookie_t *cookies;
|
||||
|
||||
/* Get the tree of windows whose parent is the root window (= all) */
|
||||
if ((reply = xcb_query_tree_reply(conn, xcb_query_tree(conn, root), 0)) == NULL)
|
||||
if ((reply = xcb_query_tree_reply(conn, xcb_query_tree(conn, root), 0)) == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
len = xcb_query_tree_children_length(reply);
|
||||
cookies = smalloc(len * sizeof(*cookies));
|
||||
|
||||
/* Request the window attributes for every window */
|
||||
children = xcb_query_tree_children(reply);
|
||||
for (i = 0; i < len; ++i)
|
||||
for (i = 0; i < len; ++i) {
|
||||
cookies[i] = xcb_get_window_attributes(conn, children[i]);
|
||||
}
|
||||
|
||||
/* Call manage_window with the attributes for every window */
|
||||
for (i = 0; i < len; ++i)
|
||||
for (i = 0; i < len; ++i) {
|
||||
manage_window(children[i], cookies[i], true);
|
||||
}
|
||||
|
||||
free(reply);
|
||||
free(cookies);
|
||||
@ -304,14 +307,16 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
|
||||
|
||||
nc = con_descend_tiling_focused(assigned_ws);
|
||||
DLOG("focused on ws %s: %p / %s\n", assigned_ws->name, nc, nc->name);
|
||||
if (nc->type == CT_WORKSPACE)
|
||||
if (nc->type == CT_WORKSPACE) {
|
||||
nc = tree_open_con(nc, cwindow);
|
||||
else
|
||||
} else {
|
||||
nc = tree_open_con(nc->parent, cwindow);
|
||||
}
|
||||
|
||||
/* set the urgency hint on the window if the workspace is not visible */
|
||||
if (!workspace_is_visible(assigned_ws))
|
||||
if (!workspace_is_visible(assigned_ws)) {
|
||||
urgency_hint = true;
|
||||
}
|
||||
} else if (cwindow->wm_desktop != NET_WM_DESKTOP_NONE &&
|
||||
cwindow->wm_desktop != NET_WM_DESKTOP_ALL &&
|
||||
(wm_desktop_ws = ewmh_get_workspace_by_index(cwindow->wm_desktop)) != NULL) {
|
||||
@ -323,27 +328,30 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
|
||||
wm_desktop_ws, wm_desktop_ws->name, cwindow->wm_desktop);
|
||||
|
||||
nc = con_descend_tiling_focused(wm_desktop_ws);
|
||||
if (nc->type == CT_WORKSPACE)
|
||||
if (nc->type == CT_WORKSPACE) {
|
||||
nc = tree_open_con(nc, cwindow);
|
||||
else
|
||||
} else {
|
||||
nc = tree_open_con(nc->parent, cwindow);
|
||||
}
|
||||
} else if (startup_ws) {
|
||||
/* If it was started on a specific workspace, we want to open it there. */
|
||||
DLOG("Using workspace on which this application was started (%s)\n", startup_ws);
|
||||
nc = con_descend_tiling_focused(workspace_get(startup_ws));
|
||||
DLOG("focused on ws %s: %p / %s\n", startup_ws, nc, nc->name);
|
||||
if (nc->type == CT_WORKSPACE)
|
||||
if (nc->type == CT_WORKSPACE) {
|
||||
nc = tree_open_con(nc, cwindow);
|
||||
else
|
||||
} else {
|
||||
nc = tree_open_con(nc->parent, cwindow);
|
||||
}
|
||||
} else {
|
||||
/* If not, insert it at the currently focused position */
|
||||
if (focused->type == CT_CON && con_accepts_window(focused)) {
|
||||
LOG("using current container, focused = %p, focused->name = %s\n",
|
||||
focused, focused->name);
|
||||
nc = focused;
|
||||
} else
|
||||
} else {
|
||||
nc = tree_open_con(NULL, cwindow);
|
||||
}
|
||||
}
|
||||
|
||||
if ((assignment = assignment_for(cwindow, A_TO_OUTPUT))) {
|
||||
@ -407,8 +415,9 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
|
||||
* of an output, move the window to that output. This is
|
||||
* needed e.g. for LibreOffice Impress multi-monitor
|
||||
* presentations to work out of the box. */
|
||||
if (output != NULL)
|
||||
if (output != NULL) {
|
||||
con_move_to_output(nc, output, false);
|
||||
}
|
||||
con_toggle_fullscreen(nc, CF_OUTPUT);
|
||||
}
|
||||
fs = NULL;
|
||||
@ -466,8 +475,9 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
|
||||
want_floating = true;
|
||||
}
|
||||
|
||||
if (xcb_reply_contains_atom(state_reply, A__NET_WM_STATE_STICKY))
|
||||
if (xcb_reply_contains_atom(state_reply, A__NET_WM_STATE_STICKY)) {
|
||||
nc->sticky = true;
|
||||
}
|
||||
|
||||
/* We ignore the hint for an internal workspace because windows in the
|
||||
* scratchpad also have this value, but upon restarting i3 we don't want
|
||||
@ -500,16 +510,18 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
|
||||
}
|
||||
|
||||
/* dock clients cannot be floating, that makes no sense */
|
||||
if (cwindow->dock)
|
||||
if (cwindow->dock) {
|
||||
want_floating = false;
|
||||
}
|
||||
|
||||
/* Store the requested geometry. The width/height gets raised to at least
|
||||
* 75x50 when entering floating mode, which is the minimum size for a
|
||||
* window to be useful (smaller windows are usually overlays/toolbars/…
|
||||
* which are not managed by the wm anyways). We store the original geometry
|
||||
* here because it’s used for dock clients. */
|
||||
if (nc->geometry.width == 0)
|
||||
if (nc->geometry.width == 0) {
|
||||
nc->geometry = (Rect){geom->x, geom->y, geom->width, geom->height};
|
||||
}
|
||||
|
||||
if (want_floating) {
|
||||
DLOG("geometry = %d x %d\n", nc->geometry.width, nc->geometry.height);
|
||||
|
@ -168,12 +168,14 @@ bool match_matches_window(Match *match, i3Window *window) {
|
||||
}
|
||||
|
||||
if (match->workspace != NULL) {
|
||||
if ((con = con_by_window_id(window->id)) == NULL)
|
||||
if ((con = con_by_window_id(window->id)) == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Con *ws = con_get_workspace(con);
|
||||
if (ws == NULL)
|
||||
if (ws == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strcmp(match->workspace->pattern, "__focused__") == 0 &&
|
||||
strcmp(ws->name, con_get_workspace(focused)->name) == 0) {
|
||||
@ -199,8 +201,9 @@ bool match_matches_window(Match *match, i3Window *window) {
|
||||
}
|
||||
|
||||
if (match->mark != NULL) {
|
||||
if ((con = con_by_window_id(window->id)) == NULL)
|
||||
if ((con = con_by_window_id(window->id)) == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool matched = false;
|
||||
mark_t *mark;
|
||||
|
@ -355,8 +355,9 @@ void tree_move(Con *con, direction_t direction) {
|
||||
/* This is the container *above* 'con' (an ancestor of con) which is inside
|
||||
* 'same_orientation' */
|
||||
Con *above = con;
|
||||
while (above->parent != same_orientation)
|
||||
while (above->parent != same_orientation) {
|
||||
above = above->parent;
|
||||
}
|
||||
|
||||
/* Enforce the fullscreen focus restrictions. */
|
||||
if (!con_fullscreen_permits_focusing(above->parent)) {
|
||||
|
96
src/randr.c
96
src/randr.c
@ -106,8 +106,9 @@ static bool any_randr_output_active(void) {
|
||||
Output *output;
|
||||
|
||||
TAILQ_FOREACH (output, &outputs, outputs) {
|
||||
if (output != root_output && !output->to_be_disabled && output->active)
|
||||
if (output != root_output && !output->to_be_disabled && output->active) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -121,13 +122,15 @@ static bool any_randr_output_active(void) {
|
||||
Output *get_output_containing(unsigned int x, unsigned int y) {
|
||||
Output *output;
|
||||
TAILQ_FOREACH (output, &outputs, outputs) {
|
||||
if (!output->active)
|
||||
if (!output->active) {
|
||||
continue;
|
||||
}
|
||||
DLOG("comparing x=%d y=%d with x=%d and y=%d width %d height %d\n",
|
||||
x, y, output->rect.x, output->rect.y, output->rect.width, output->rect.height);
|
||||
if (x >= output->rect.x && x < (output->rect.x + output->rect.width) &&
|
||||
y >= output->rect.y && y < (output->rect.y + output->rect.height))
|
||||
y >= output->rect.y && y < (output->rect.y + output->rect.height)) {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -155,14 +158,16 @@ Output *get_output_from_rect(Rect rect) {
|
||||
Output *get_output_with_dimensions(Rect rect) {
|
||||
Output *output;
|
||||
TAILQ_FOREACH (output, &outputs, outputs) {
|
||||
if (!output->active)
|
||||
if (!output->active) {
|
||||
continue;
|
||||
}
|
||||
DLOG("comparing x=%d y=%d %dx%d with x=%d and y=%d %dx%d\n",
|
||||
rect.x, rect.y, rect.width, rect.height,
|
||||
output->rect.x, output->rect.y, output->rect.width, output->rect.height);
|
||||
if (rect.x == output->rect.x && rect.width == output->rect.width &&
|
||||
rect.y == output->rect.y && rect.height == output->rect.height)
|
||||
rect.y == output->rect.y && rect.height == output->rect.height) {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -182,8 +187,9 @@ Output *output_containing_rect(Rect rect) {
|
||||
long max_area = 0;
|
||||
Output *result = NULL;
|
||||
TAILQ_FOREACH (output, &outputs, outputs) {
|
||||
if (!output->active)
|
||||
if (!output->active) {
|
||||
continue;
|
||||
}
|
||||
int lx_o = (int)output->rect.x, uy_o = (int)output->rect.y;
|
||||
int rx_o = (int)(output->rect.x + output->rect.width), by_o = (int)(output->rect.y + output->rect.height);
|
||||
DLOG("comparing x=%d y=%d with x=%d and y=%d width %d height %d\n",
|
||||
@ -217,18 +223,20 @@ Output *get_output_next_wrap(direction_t direction, Output *current) {
|
||||
/* If no output can be found, wrap */
|
||||
if (!best) {
|
||||
direction_t opposite;
|
||||
if (direction == D_RIGHT)
|
||||
if (direction == D_RIGHT) {
|
||||
opposite = D_LEFT;
|
||||
else if (direction == D_LEFT)
|
||||
} else if (direction == D_LEFT) {
|
||||
opposite = D_RIGHT;
|
||||
else if (direction == D_DOWN)
|
||||
} else if (direction == D_DOWN) {
|
||||
opposite = D_UP;
|
||||
else
|
||||
} else {
|
||||
opposite = D_DOWN;
|
||||
}
|
||||
best = get_output_next(opposite, current, FARTHEST_OUTPUT);
|
||||
}
|
||||
if (!best)
|
||||
if (!best) {
|
||||
best = current;
|
||||
}
|
||||
DLOG("current = %s, best = %s\n", output_primary_name(current), output_primary_name(best));
|
||||
return best;
|
||||
}
|
||||
@ -250,8 +258,9 @@ Output *get_output_next(direction_t direction, Output *current, output_close_far
|
||||
Output *output,
|
||||
*best = NULL;
|
||||
TAILQ_FOREACH (output, &outputs, outputs) {
|
||||
if (!output->active)
|
||||
if (!output->active) {
|
||||
continue;
|
||||
}
|
||||
|
||||
other = &(output->rect);
|
||||
|
||||
@ -260,17 +269,20 @@ Output *get_output_next(direction_t direction, Output *current, output_close_far
|
||||
/* Skip the output when it doesn’t overlap the other one’s y
|
||||
* coordinate at all. */
|
||||
if ((other->y + other->height) <= cur->y ||
|
||||
(cur->y + cur->height) <= other->y)
|
||||
(cur->y + cur->height) <= other->y) {
|
||||
continue;
|
||||
}
|
||||
} else if ((direction == D_DOWN && other->y > cur->y) ||
|
||||
(direction == D_UP && other->y < cur->y)) {
|
||||
/* Skip the output when it doesn’t overlap the other one’s x
|
||||
* coordinate at all. */
|
||||
if ((other->x + other->width) <= cur->x ||
|
||||
(cur->x + cur->width) <= other->x)
|
||||
(cur->x + cur->width) <= other->x) {
|
||||
continue;
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* No candidate yet? Start with this one. */
|
||||
if (!best) {
|
||||
@ -340,8 +352,9 @@ void output_init_con(Output *output) {
|
||||
/* Search for a Con with that name directly below the root node. There
|
||||
* might be one from a restored layout. */
|
||||
TAILQ_FOREACH (current, &(croot->nodes_head), nodes) {
|
||||
if (strcmp(current->name, output_primary_name(output)) != 0)
|
||||
if (strcmp(current->name, output_primary_name(output)) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
con = current;
|
||||
reused = true;
|
||||
@ -546,14 +559,16 @@ static void output_change_mode(xcb_connection_t *conn, Output *output) {
|
||||
TAILQ_FOREACH (workspace, &(content->nodes_head), nodes) {
|
||||
/* Workspaces with more than one child are left untouched because
|
||||
* we do not want to change an existing layout. */
|
||||
if (con_num_children(workspace) > 1)
|
||||
if (con_num_children(workspace) > 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
workspace->layout = (output->rect.height > output->rect.width) ? L_SPLITV : L_SPLITH;
|
||||
DLOG("Setting workspace [%d,%s]'s layout to %d.\n", workspace->num, workspace->name, workspace->layout);
|
||||
if ((child = TAILQ_FIRST(&(workspace->nodes_head)))) {
|
||||
if (child->layout == L_SPLITV || child->layout == L_SPLITH)
|
||||
if (child->layout == L_SPLITV || child->layout == L_SPLITH) {
|
||||
child->layout = workspace->layout;
|
||||
}
|
||||
DLOG("Setting child [%d,%s]'s layout to %d.\n", child->num, child->name, child->layout);
|
||||
}
|
||||
}
|
||||
@ -731,12 +746,14 @@ static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id,
|
||||
* position/size) */
|
||||
if (output->crtc == XCB_NONE) {
|
||||
if (!existing) {
|
||||
if (new->primary)
|
||||
if (new->primary) {
|
||||
TAILQ_INSERT_HEAD(&outputs, new, outputs);
|
||||
else
|
||||
} else {
|
||||
TAILQ_INSERT_TAIL(&outputs, new, outputs);
|
||||
} else if (new->active)
|
||||
}
|
||||
} else if (new->active) {
|
||||
new->to_be_disabled = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -769,10 +786,11 @@ static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id,
|
||||
* need to insert the new output or we are done. */
|
||||
if (!updated || !existing) {
|
||||
if (!existing) {
|
||||
if (new->primary)
|
||||
if (new->primary) {
|
||||
TAILQ_INSERT_HEAD(&outputs, new, outputs);
|
||||
else
|
||||
} else {
|
||||
TAILQ_INSERT_TAIL(&outputs, new, outputs);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -793,10 +811,11 @@ static void randr_query_outputs_14(void) {
|
||||
xcb_randr_get_output_primary_cookie_t pcookie;
|
||||
pcookie = xcb_randr_get_output_primary(conn, root);
|
||||
|
||||
if ((primary = xcb_randr_get_output_primary_reply(conn, pcookie, NULL)) == NULL)
|
||||
if ((primary = xcb_randr_get_output_primary_reply(conn, pcookie, NULL)) == NULL) {
|
||||
ELOG("Could not get RandR primary output\n");
|
||||
else
|
||||
} else {
|
||||
DLOG("primary output is %08x\n", primary->output);
|
||||
}
|
||||
|
||||
xcb_randr_get_screen_resources_current_reply_t *res =
|
||||
xcb_randr_get_screen_resources_current_reply(conn, rcookie, NULL);
|
||||
@ -816,15 +835,17 @@ static void randr_query_outputs_14(void) {
|
||||
|
||||
/* Request information for each output */
|
||||
xcb_randr_get_output_info_cookie_t ocookie[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
for (int i = 0; i < len; i++) {
|
||||
ocookie[i] = xcb_randr_get_output_info(conn, randr_outputs[i], cts);
|
||||
}
|
||||
|
||||
/* Loop through all outputs available for this X11 screen */
|
||||
for (int i = 0; i < len; i++) {
|
||||
xcb_randr_get_output_info_reply_t *output;
|
||||
|
||||
if ((output = xcb_randr_get_output_info_reply(conn, ocookie[i], NULL)) == NULL)
|
||||
if ((output = xcb_randr_get_output_info_reply(conn, ocookie[i], NULL)) == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
handle_output(conn, randr_outputs[i], output, cts, res);
|
||||
free(output);
|
||||
@ -930,20 +951,23 @@ void randr_query_outputs(void) {
|
||||
/* Check for clones, disable the clones and reduce the mode to the
|
||||
* lowest common mode */
|
||||
TAILQ_FOREACH (output, &outputs, outputs) {
|
||||
if (!output->active || output->to_be_disabled)
|
||||
if (!output->active || output->to_be_disabled) {
|
||||
continue;
|
||||
}
|
||||
DLOG("output %p / %s, position (%d, %d), checking for clones\n",
|
||||
output, output_primary_name(output), output->rect.x, output->rect.y);
|
||||
|
||||
for (other = output;
|
||||
other != TAILQ_END(&outputs);
|
||||
other = TAILQ_NEXT(other, outputs)) {
|
||||
if (other == output || !other->active || other->to_be_disabled)
|
||||
if (other == output || !other->active || other->to_be_disabled) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (other->rect.x != output->rect.x ||
|
||||
other->rect.y != output->rect.y)
|
||||
other->rect.y != output->rect.y) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DLOG("output %p has the same position, its mode = %d x %d\n",
|
||||
other, other->rect.width, other->rect.height);
|
||||
@ -1010,19 +1034,22 @@ void randr_query_outputs(void) {
|
||||
|
||||
/* Just go through each active output and assign one workspace */
|
||||
TAILQ_FOREACH (output, &outputs, outputs) {
|
||||
if (!output->active)
|
||||
if (!output->active) {
|
||||
continue;
|
||||
}
|
||||
Con *content = output_get_content(output->con);
|
||||
if (!TAILQ_EMPTY(&(content->nodes_head)))
|
||||
if (!TAILQ_EMPTY(&(content->nodes_head))) {
|
||||
continue;
|
||||
}
|
||||
DLOG("Should add ws for output %s\n", output_primary_name(output));
|
||||
init_ws_for_output(output);
|
||||
}
|
||||
|
||||
/* Focus the primary screen, if possible */
|
||||
TAILQ_FOREACH (output, &outputs, outputs) {
|
||||
if (!output->primary || !output->con)
|
||||
if (!output->primary || !output->con) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DLOG("Focusing primary output %s\n", output_primary_name(output));
|
||||
Con *content = output_get_content(output->con);
|
||||
@ -1101,8 +1128,9 @@ void randr_init(int *event_base, const bool disable_randr15) {
|
||||
|
||||
randr_query_outputs();
|
||||
|
||||
if (event_base != NULL)
|
||||
if (event_base != NULL) {
|
||||
*event_base = extreply->first_event;
|
||||
}
|
||||
|
||||
xcb_randr_select_input(conn, root,
|
||||
XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE |
|
||||
|
@ -45,8 +45,9 @@ struct regex *regex_new(const char *pattern) {
|
||||
*
|
||||
*/
|
||||
void regex_free(struct regex *regex) {
|
||||
if (!regex)
|
||||
if (!regex) {
|
||||
return;
|
||||
}
|
||||
FREE(regex->pattern);
|
||||
FREE(regex->regex);
|
||||
FREE(regex);
|
||||
|
15
src/render.c
15
src/render.c
@ -26,8 +26,9 @@ static void render_con_dockarea(Con *con, Con *child, render_params *p);
|
||||
*/
|
||||
int render_deco_height(void) {
|
||||
int deco_height = config.font.height + 4;
|
||||
if (config.font.height & 0x01)
|
||||
if (config.font.height & 0x01) {
|
||||
++deco_height;
|
||||
}
|
||||
return deco_height;
|
||||
}
|
||||
|
||||
@ -151,8 +152,9 @@ void render_con(Con *con) {
|
||||
|
||||
if (con->layout == L_OUTPUT) {
|
||||
/* Skip i3-internal outputs */
|
||||
if (con_is_internal(con))
|
||||
if (con_is_internal(con)) {
|
||||
goto free_params;
|
||||
}
|
||||
render_output(con);
|
||||
} else if (con->type == CT_ROOT) {
|
||||
render_root(con, fullscreen);
|
||||
@ -205,12 +207,13 @@ void render_con(Con *con) {
|
||||
render_con(child);
|
||||
}
|
||||
|
||||
if (params.children != 1)
|
||||
if (params.children != 1) {
|
||||
/* Raise the stack con itself. This will put the stack
|
||||
* decoration on top of every stack window. That way, when a
|
||||
* new window is opened in the stack, the old window will not
|
||||
* obscure part of the decoration (it’s unmapped afterwards). */
|
||||
x_raise_con(con);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,8 +264,9 @@ static void render_root(Con *con, Con *fullscreen) {
|
||||
* windows/containers so that they overlap on another output. */
|
||||
DLOG("Rendering floating windows:\n");
|
||||
TAILQ_FOREACH (output, &(con->nodes_head), nodes) {
|
||||
if (con_is_internal(output))
|
||||
if (con_is_internal(output)) {
|
||||
continue;
|
||||
}
|
||||
/* Get the active workspace of that output */
|
||||
Con *content = output_get_content(output);
|
||||
if (!content || TAILQ_EMPTY(&(content->focus_head))) {
|
||||
@ -352,8 +356,9 @@ static void render_output(Con *con) {
|
||||
/* First pass: determine the height of all CT_DOCKAREAs (the sum of their
|
||||
* children) and figure out how many pixels we have left for the rest */
|
||||
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
|
||||
if (child->type != CT_DOCKAREA)
|
||||
if (child->type != CT_DOCKAREA) {
|
||||
continue;
|
||||
}
|
||||
|
||||
child->rect.height = 0;
|
||||
TAILQ_FOREACH (dockchild, &(child->nodes_head), nodes) {
|
||||
|
@ -50,15 +50,17 @@ DRAGGING_CB(resize_callback) {
|
||||
if (params->orientation == HORIZ) {
|
||||
/* Check if the new coordinates are within screen boundaries */
|
||||
if (new_x > (output->rect.x + output->rect.width - 25) ||
|
||||
new_x < (output->rect.x + 25))
|
||||
new_x < (output->rect.x + 25)) {
|
||||
return;
|
||||
}
|
||||
|
||||
*(params->new_position) = new_x;
|
||||
xcb_configure_window(conn, params->helpwin, XCB_CONFIG_WINDOW_X, params->new_position);
|
||||
} else {
|
||||
if (new_y > (output->rect.y + output->rect.height - 25) ||
|
||||
new_y < (output->rect.y + 25))
|
||||
new_y < (output->rect.y + 25)) {
|
||||
return;
|
||||
}
|
||||
|
||||
*(params->new_position) = new_y;
|
||||
xcb_configure_window(conn, params->helpwin, XCB_CONFIG_WINDOW_Y, params->new_position);
|
||||
|
@ -208,9 +208,10 @@ static void open_placeholder_window(Con *con) {
|
||||
/* Set the same name as was stored in the layout file. While perhaps
|
||||
* slightly confusing in the first instant, this brings additional
|
||||
* clarity to which placeholder is waiting for which actual window. */
|
||||
if (con->name != NULL)
|
||||
if (con->name != NULL) {
|
||||
xcb_change_property(restore_conn, XCB_PROP_MODE_REPLACE, placeholder,
|
||||
A__NET_WM_NAME, A_UTF8_STRING, 8, strlen(con->name), con->name);
|
||||
}
|
||||
DLOG("Created placeholder window 0x%08x for leaf container %p / %s\n",
|
||||
placeholder, con, con->name);
|
||||
|
||||
@ -269,8 +270,9 @@ void restore_open_placeholder_windows(Con *parent) {
|
||||
bool restore_kill_placeholder(xcb_window_t placeholder) {
|
||||
placeholder_state *state;
|
||||
TAILQ_FOREACH (state, &state_head, state) {
|
||||
if (state->window != placeholder)
|
||||
if (state->window != placeholder) {
|
||||
continue;
|
||||
}
|
||||
|
||||
xcb_destroy_window(restore_conn, state->window);
|
||||
draw_util_surface_free(restore_conn, &(state->surface));
|
||||
@ -287,8 +289,9 @@ bool restore_kill_placeholder(xcb_window_t placeholder) {
|
||||
static void expose_event(xcb_expose_event_t *event) {
|
||||
placeholder_state *state;
|
||||
TAILQ_FOREACH (state, &state_head, state) {
|
||||
if (state->window != event->window)
|
||||
if (state->window != event->window) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DLOG("refreshing window 0x%08x contents (con %p)\n", state->window, state->con);
|
||||
|
||||
@ -309,8 +312,9 @@ static void expose_event(xcb_expose_event_t *event) {
|
||||
static void configure_notify(xcb_configure_notify_event_t *event) {
|
||||
placeholder_state *state;
|
||||
TAILQ_FOREACH (state, &state_head, state) {
|
||||
if (state->window != event->window)
|
||||
if (state->window != event->window) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DLOG("ConfigureNotify: window 0x%08x has now width=%d, height=%d (con %p)\n",
|
||||
state->window, event->width, event->height, state->con);
|
||||
|
@ -101,8 +101,9 @@ bool scratchpad_show(Con *con) {
|
||||
/* If the current con or any of its parents are in fullscreen mode, we
|
||||
* first need to disable it before showing the scratchpad con. */
|
||||
Con *fs = focused;
|
||||
while (fs && fs->fullscreen_mode == CF_NONE)
|
||||
while (fs && fs->fullscreen_mode == CF_NONE) {
|
||||
fs = fs->parent;
|
||||
}
|
||||
|
||||
if (fs && fs->type != CT_WORKSPACE) {
|
||||
con_toggle_fullscreen(fs, CF_OUTPUT);
|
||||
@ -215,8 +216,9 @@ bool scratchpad_show(Con *con) {
|
||||
*
|
||||
*/
|
||||
static int _gcd(const int m, const int n) {
|
||||
if (n == 0)
|
||||
if (n == 0) {
|
||||
return m;
|
||||
}
|
||||
return _gcd(n, (m % n));
|
||||
}
|
||||
|
||||
@ -254,8 +256,9 @@ void scratchpad_fix_resolution(void) {
|
||||
int new_width = -1,
|
||||
new_height = -1;
|
||||
TAILQ_FOREACH (output, &(croot->nodes_head), nodes) {
|
||||
if (output == __i3_output)
|
||||
if (output == __i3_output) {
|
||||
continue;
|
||||
}
|
||||
DLOG("output %s's resolution: (%d, %d) %d x %d\n",
|
||||
output->name, output->rect.x, output->rect.y,
|
||||
output->rect.width, output->rect.height);
|
||||
|
128
src/sd-daemon.c
128
src/sd-daemon.c
@ -100,8 +100,9 @@ int sd_listen_fds(int unset_environment) {
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (flags & FD_CLOEXEC)
|
||||
if (flags & FD_CLOEXEC) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
|
||||
r = -errno;
|
||||
@ -123,23 +124,27 @@ finish:
|
||||
int sd_is_fifo(int fd, const char *path) {
|
||||
struct stat st_fd;
|
||||
|
||||
if (fd < 0)
|
||||
if (fd < 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
memset(&st_fd, 0, sizeof(st_fd));
|
||||
if (fstat(fd, &st_fd) < 0)
|
||||
if (fstat(fd, &st_fd) < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
if (!S_ISFIFO(st_fd.st_mode))
|
||||
if (!S_ISFIFO(st_fd.st_mode)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (path) {
|
||||
struct stat st_path;
|
||||
|
||||
memset(&st_path, 0, sizeof(st_path));
|
||||
if (stat(path, &st_path) < 0) {
|
||||
if (errno == ENOENT || errno == ENOTDIR)
|
||||
if (errno == ENOENT || errno == ENOTDIR) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -errno;
|
||||
}
|
||||
@ -154,41 +159,50 @@ int sd_is_fifo(int fd, const char *path) {
|
||||
static int sd_is_socket_internal(int fd, int type, int listening) {
|
||||
struct stat st_fd;
|
||||
|
||||
if (fd < 0 || type < 0)
|
||||
if (fd < 0 || type < 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (fstat(fd, &st_fd) < 0)
|
||||
if (fstat(fd, &st_fd) < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
if (!S_ISSOCK(st_fd.st_mode))
|
||||
if (!S_ISSOCK(st_fd.st_mode)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (type != 0) {
|
||||
int other_type = 0;
|
||||
socklen_t l = sizeof(other_type);
|
||||
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &other_type, &l) < 0)
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &other_type, &l) < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
if (l != sizeof(other_type))
|
||||
if (l != sizeof(other_type)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (other_type != type)
|
||||
if (other_type != type) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (listening >= 0) {
|
||||
int accepting = 0;
|
||||
socklen_t l = sizeof(accepting);
|
||||
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &accepting, &l) < 0)
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &accepting, &l) < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
if (l != sizeof(accepting))
|
||||
if (l != sizeof(accepting)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!accepting != !listening)
|
||||
if (!accepting != !listening) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -205,11 +219,13 @@ union sockaddr_union {
|
||||
int sd_is_socket(int fd, int family, int type, int listening) {
|
||||
int r;
|
||||
|
||||
if (family < 0)
|
||||
if (family < 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
|
||||
if ((r = sd_is_socket_internal(fd, type, listening)) <= 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
if (family > 0) {
|
||||
union sockaddr_union sockaddr;
|
||||
@ -218,11 +234,13 @@ int sd_is_socket(int fd, int family, int type, int listening) {
|
||||
memset(&sockaddr, 0, sizeof(sockaddr));
|
||||
l = sizeof(sockaddr);
|
||||
|
||||
if (getsockname(fd, &sockaddr.sa, &l) < 0)
|
||||
if (getsockname(fd, &sockaddr.sa, &l) < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
if (l < sizeof(sa_family_t))
|
||||
if (l < sizeof(sa_family_t)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return sockaddr.sa.sa_family == family;
|
||||
}
|
||||
@ -235,38 +253,47 @@ int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port
|
||||
socklen_t l;
|
||||
int r;
|
||||
|
||||
if (family != 0 && family != AF_INET && family != AF_INET6)
|
||||
if (family != 0 && family != AF_INET && family != AF_INET6) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
|
||||
if ((r = sd_is_socket_internal(fd, type, listening)) <= 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
memset(&sockaddr, 0, sizeof(sockaddr));
|
||||
l = sizeof(sockaddr);
|
||||
|
||||
if (getsockname(fd, &sockaddr.sa, &l) < 0)
|
||||
if (getsockname(fd, &sockaddr.sa, &l) < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
if (l < sizeof(sa_family_t))
|
||||
if (l < sizeof(sa_family_t)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (sockaddr.sa.sa_family != AF_INET &&
|
||||
sockaddr.sa.sa_family != AF_INET6)
|
||||
sockaddr.sa.sa_family != AF_INET6) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (family > 0)
|
||||
if (sockaddr.sa.sa_family != family)
|
||||
if (family > 0) {
|
||||
if (sockaddr.sa.sa_family != family) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (port > 0) {
|
||||
if (sockaddr.sa.sa_family == AF_INET) {
|
||||
if (l < sizeof(struct sockaddr_in))
|
||||
if (l < sizeof(struct sockaddr_in)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return htons(port) == sockaddr.in4.sin_port;
|
||||
} else {
|
||||
if (l < sizeof(struct sockaddr_in6))
|
||||
if (l < sizeof(struct sockaddr_in6)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return htons(port) == sockaddr.in6.sin6_port;
|
||||
}
|
||||
@ -280,37 +307,44 @@ int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t
|
||||
socklen_t l;
|
||||
int r;
|
||||
|
||||
if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
|
||||
if ((r = sd_is_socket_internal(fd, type, listening)) <= 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
memset(&sockaddr, 0, sizeof(sockaddr));
|
||||
l = sizeof(sockaddr);
|
||||
|
||||
if (getsockname(fd, &sockaddr.sa, &l) < 0)
|
||||
if (getsockname(fd, &sockaddr.sa, &l) < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
if (l < sizeof(sa_family_t))
|
||||
if (l < sizeof(sa_family_t)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (sockaddr.sa.sa_family != AF_UNIX)
|
||||
if (sockaddr.sa.sa_family != AF_UNIX) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (path) {
|
||||
if (length <= 0)
|
||||
if (length <= 0) {
|
||||
length = strlen(path);
|
||||
}
|
||||
|
||||
if (length <= 0)
|
||||
if (length <= 0) {
|
||||
/* Unnamed socket */
|
||||
return l == offsetof(struct sockaddr_un, sun_path);
|
||||
}
|
||||
|
||||
if (path[0])
|
||||
if (path[0]) {
|
||||
/* Normal path socket */
|
||||
return (l >= offsetof(struct sockaddr_un, sun_path) + length + 1) &&
|
||||
memcmp(path, sockaddr.un.sun_path, length + 1) == 0;
|
||||
else
|
||||
} else {
|
||||
/* Abstract namespace socket */
|
||||
return (l == offsetof(struct sockaddr_un, sun_path) + length) &&
|
||||
memcmp(path, sockaddr.un.sun_path, length) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -331,8 +365,9 @@ int sd_notify(int unset_environment, const char *state) {
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (!(e = getenv("NOTIFY_SOCKET")))
|
||||
if (!(e = getenv("NOTIFY_SOCKET"))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Must be an abstract socket, or an absolute path */
|
||||
if ((e[0] != '@' && e[0] != '/') || e[1] == 0) {
|
||||
@ -354,8 +389,9 @@ int sd_notify(int unset_environment, const char *state) {
|
||||
sockaddr.sa.sa_family = AF_UNIX;
|
||||
strncpy(sockaddr.un.sun_path, e, sizeof(sockaddr.un.sun_path) - 1);
|
||||
|
||||
if (sockaddr.un.sun_path[0] == '@')
|
||||
if (sockaddr.un.sun_path[0] == '@') {
|
||||
sockaddr.un.sun_path[0] = 0;
|
||||
}
|
||||
|
||||
memset(&iovec, 0, sizeof(iovec));
|
||||
iovec.iov_base = (char *)state;
|
||||
@ -365,8 +401,9 @@ int sd_notify(int unset_environment, const char *state) {
|
||||
msghdr.msg_name = &sockaddr;
|
||||
msghdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) + strlen(e);
|
||||
|
||||
if (msghdr.msg_namelen > sizeof(struct sockaddr_un))
|
||||
if (msghdr.msg_namelen > sizeof(struct sockaddr_un)) {
|
||||
msghdr.msg_namelen = sizeof(struct sockaddr_un);
|
||||
}
|
||||
|
||||
msghdr.msg_iov = &iovec;
|
||||
msghdr.msg_iovlen = 1;
|
||||
@ -379,11 +416,13 @@ int sd_notify(int unset_environment, const char *state) {
|
||||
r = 1;
|
||||
|
||||
finish:
|
||||
if (unset_environment)
|
||||
if (unset_environment) {
|
||||
unsetenv("NOTIFY_SOCKET");
|
||||
}
|
||||
|
||||
if (fd >= 0)
|
||||
if (fd >= 0) {
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return r;
|
||||
#endif
|
||||
@ -401,8 +440,9 @@ int sd_notifyf(int unset_environment, const char *format, ...) {
|
||||
r = vasprintf(&p, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (r < 0 || !p)
|
||||
if (r < 0 || !p) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
r = sd_notify(unset_environment, p);
|
||||
free(p);
|
||||
@ -420,11 +460,13 @@ int sd_booted(void) {
|
||||
|
||||
/* We simply test whether the systemd cgroup hierarchy is mounted */
|
||||
|
||||
if (lstat("/sys/fs/cgroup", &a) < 0)
|
||||
if (lstat("/sys/fs/cgroup", &a) < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lstat("/sys/fs/cgroup/systemd", &b) < 0)
|
||||
if (lstat("/sys/fs/cgroup/systemd", &b) < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return a.st_dev != b.st_dev;
|
||||
#endif
|
||||
|
@ -48,8 +48,9 @@ static int margin = 4;
|
||||
*/
|
||||
static int sighandler_backtrace(void) {
|
||||
char *tmpdir = getenv("TMPDIR");
|
||||
if (tmpdir == NULL)
|
||||
if (tmpdir == NULL) {
|
||||
tmpdir = "/tmp";
|
||||
}
|
||||
|
||||
pid_t pid_parent = getpid();
|
||||
|
||||
@ -343,6 +344,7 @@ void setup_signal_handler(void) {
|
||||
sigaction(SIGILL, &action, NULL) == -1 ||
|
||||
sigaction(SIGABRT, &action, NULL) == -1 ||
|
||||
sigaction(SIGFPE, &action, NULL) == -1 ||
|
||||
sigaction(SIGSEGV, &action, NULL) == -1)
|
||||
sigaction(SIGSEGV, &action, NULL) == -1) {
|
||||
ELOG("Could not setup signal handler.\n");
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,9 @@ static void startup_timeout(EV_P_ ev_timer *w, int revents) {
|
||||
|
||||
struct Startup_Sequence *current, *sequence = NULL;
|
||||
TAILQ_FOREACH (current, &startup_sequences, sequences) {
|
||||
if (strcmp(current->id, id) != 0)
|
||||
if (strcmp(current->id, id) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sequence = current;
|
||||
break;
|
||||
@ -86,8 +87,9 @@ static int _prune_startup_sequences(void) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (current_time <= current->delete_at)
|
||||
if (current_time <= current->delete_at) {
|
||||
continue;
|
||||
}
|
||||
|
||||
startup_sequence_delete(current);
|
||||
}
|
||||
@ -142,8 +144,9 @@ void start_application(const char *command, bool no_startup_id) {
|
||||
* spaces in the command), since we don’t want the parameters. */
|
||||
char *first_word = sstrdup(command);
|
||||
char *space = strchr(first_word, ' ');
|
||||
if (space)
|
||||
if (space) {
|
||||
*space = '\0';
|
||||
}
|
||||
sn_launcher_context_initiate(context, "i3", first_word, last_timestamp);
|
||||
free(first_word);
|
||||
|
||||
@ -187,8 +190,9 @@ void start_application(const char *command, bool no_startup_id) {
|
||||
unsetenv("LISTEN_FDS");
|
||||
signal(SIGPIPE, SIG_DFL);
|
||||
/* Setup the environment variable(s) */
|
||||
if (!no_startup_id)
|
||||
if (!no_startup_id) {
|
||||
sn_launcher_context_setup_child_process(context);
|
||||
}
|
||||
setenv("I3SOCK", current_socketpath, 1);
|
||||
|
||||
execl(_PATH_BSHELL, _PATH_BSHELL, "-c", command, NULL);
|
||||
@ -214,8 +218,9 @@ void startup_monitor_event(SnMonitorEvent *event, void *userdata) {
|
||||
const char *id = sn_startup_sequence_get_id(snsequence);
|
||||
struct Startup_Sequence *current, *sequence = NULL;
|
||||
TAILQ_FOREACH (current, &startup_sequences, sequences) {
|
||||
if (strcmp(current->id, id) != 0)
|
||||
if (strcmp(current->id, id) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sequence = current;
|
||||
break;
|
||||
@ -255,8 +260,9 @@ void startup_monitor_event(SnMonitorEvent *event, void *userdata) {
|
||||
void startup_sequence_rename_workspace(const char *old_name, const char *new_name) {
|
||||
struct Startup_Sequence *current;
|
||||
TAILQ_FOREACH (current, &startup_sequences, sequences) {
|
||||
if (strcmp(current->workspace, old_name) != 0)
|
||||
if (strcmp(current->workspace, old_name) != 0) {
|
||||
continue;
|
||||
}
|
||||
DLOG("Renaming workspace \"%s\" to \"%s\" in startup sequence %s.\n",
|
||||
old_name, new_name, current->id);
|
||||
free(current->workspace);
|
||||
@ -275,8 +281,9 @@ struct Startup_Sequence *startup_sequence_get(i3Window *cwindow,
|
||||
if (startup_id_reply == NULL || xcb_get_property_value_length(startup_id_reply) == 0) {
|
||||
FREE(startup_id_reply);
|
||||
DLOG("No _NET_STARTUP_ID set on window 0x%08x\n", cwindow->id);
|
||||
if (cwindow->leader == XCB_NONE)
|
||||
if (cwindow->leader == XCB_NONE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* This is a special case that causes the leader's startup sequence
|
||||
* to only be returned if it has never been mapped, useful primarily
|
||||
@ -311,8 +318,9 @@ struct Startup_Sequence *startup_sequence_get(i3Window *cwindow,
|
||||
(char *)xcb_get_property_value(startup_id_reply));
|
||||
struct Startup_Sequence *current, *sequence = NULL;
|
||||
TAILQ_FOREACH (current, &startup_sequences, sequences) {
|
||||
if (strcmp(current->id, startup_id) != 0)
|
||||
if (strcmp(current->id, startup_id) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sequence = current;
|
||||
break;
|
||||
@ -342,8 +350,9 @@ struct Startup_Sequence *startup_sequence_get(i3Window *cwindow,
|
||||
*/
|
||||
char *startup_workspace_for_window(i3Window *cwindow, xcb_get_property_reply_t *startup_id_reply) {
|
||||
struct Startup_Sequence *sequence = startup_sequence_get(cwindow, startup_id_reply, false);
|
||||
if (sequence == NULL)
|
||||
if (sequence == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* If the startup sequence's time span has elapsed, delete it. */
|
||||
time_t current_time = time(NULL);
|
||||
|
24
src/tree.c
24
src/tree.c
@ -161,8 +161,9 @@ Con *tree_open_con(Con *con, i3Window *window) {
|
||||
* workspace. */
|
||||
if (con->type == CT_FLOATING_CON) {
|
||||
con = con_descend_tiling_focused(con->parent);
|
||||
if (con->type != CT_WORKSPACE)
|
||||
if (con->type != CT_WORKSPACE) {
|
||||
con = con->parent;
|
||||
}
|
||||
}
|
||||
DLOG("con = %p\n", con);
|
||||
}
|
||||
@ -293,8 +294,9 @@ bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_par
|
||||
* Rendering has to be avoided when dont_kill_parent is set (when
|
||||
* tree_close_internal calls itself recursively) because the tree is in a
|
||||
* non-renderable state during that time. */
|
||||
if (!dont_kill_parent)
|
||||
if (!dont_kill_parent) {
|
||||
tree_render();
|
||||
}
|
||||
|
||||
/* kill the X11 part of this container */
|
||||
x_con_kill(con);
|
||||
@ -313,8 +315,9 @@ bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_par
|
||||
}
|
||||
|
||||
/* check if the parent container is empty now and close it */
|
||||
if (!dont_kill_parent)
|
||||
if (!dont_kill_parent) {
|
||||
CALL(parent, on_remove_child);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -419,8 +422,9 @@ bool level_down(void) {
|
||||
if (child == TAILQ_END(&(next->focus_head))) {
|
||||
DLOG("cannot go down\n");
|
||||
return false;
|
||||
} else
|
||||
} else {
|
||||
next = TAILQ_FIRST(&(next->focus_head));
|
||||
}
|
||||
}
|
||||
|
||||
con_activate(next);
|
||||
@ -449,8 +453,9 @@ static void mark_unmapped(Con *con) {
|
||||
*
|
||||
*/
|
||||
void tree_render(void) {
|
||||
if (croot == NULL)
|
||||
if (croot == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
DLOG("-- BEGIN RENDERING --\n");
|
||||
/* Reset map state for all nodes in tree */
|
||||
@ -659,13 +664,15 @@ void tree_flatten(Con *con) {
|
||||
/* We only consider normal containers without windows */
|
||||
if (con->type != CT_CON ||
|
||||
parent->layout == L_OUTPUT || /* con == "content" */
|
||||
con->window != NULL)
|
||||
con->window != NULL) {
|
||||
goto recurse;
|
||||
}
|
||||
|
||||
/* Ensure it got only one child */
|
||||
child = TAILQ_FIRST(&(con->nodes_head));
|
||||
if (child == NULL || TAILQ_NEXT(child, nodes) != NULL)
|
||||
if (child == NULL || TAILQ_NEXT(child, nodes) != NULL) {
|
||||
goto recurse;
|
||||
}
|
||||
|
||||
DLOG("child = %p, con = %p, parent = %p\n", child, con, parent);
|
||||
|
||||
@ -676,8 +683,9 @@ void tree_flatten(Con *con) {
|
||||
(con->layout != L_SPLITH && con->layout != L_SPLITV) ||
|
||||
(child->layout != L_SPLITH && child->layout != L_SPLITV) ||
|
||||
con_orientation(con) == con_orientation(child) ||
|
||||
con_orientation(child) != con_orientation(parent))
|
||||
con_orientation(child) != con_orientation(parent)) {
|
||||
goto recurse;
|
||||
}
|
||||
|
||||
DLOG("Alright, I have to flatten this situation now. Stay calm.\n");
|
||||
/* 1: save focus */
|
||||
|
34
src/util.c
34
src/util.c
@ -66,9 +66,11 @@ bool rect_equals(Rect a, Rect b) {
|
||||
*/
|
||||
__attribute__((pure)) bool name_is_digits(const char *name) {
|
||||
/* positive integers and zero are interpreted as numbers */
|
||||
for (size_t i = 0; i < strlen(name); i++)
|
||||
if (!isdigit(name[i]))
|
||||
for (size_t i = 0; i < strlen(name); i++) {
|
||||
if (!isdigit(name[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -182,8 +184,8 @@ void exec_i3_utility(char *name, char *argv[]) {
|
||||
*/
|
||||
static char **add_argument(char **original, char *opt_char, char *opt_arg, char *opt_name) {
|
||||
int num_args;
|
||||
for (num_args = 0; original[num_args] != NULL; num_args++)
|
||||
;
|
||||
for (num_args = 0; original[num_args] != NULL; num_args++) {
|
||||
}
|
||||
char **result = scalloc(num_args + 3, sizeof(char *));
|
||||
|
||||
/* copy the arguments, but skip the ones we'll replace */
|
||||
@ -196,8 +198,9 @@ static char **add_argument(char **original, char *opt_char, char *opt_arg, char
|
||||
}
|
||||
if (!strcmp(original[i], opt_char) ||
|
||||
(opt_name && !strcmp(original[i], opt_name))) {
|
||||
if (opt_arg)
|
||||
if (opt_arg) {
|
||||
skip_next = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
result[write_index++] = original[i];
|
||||
@ -230,8 +233,9 @@ static char *store_restart_layout(void) {
|
||||
char *filename;
|
||||
if (config.restart_state_path == NULL) {
|
||||
filename = get_process_filename("restart-state");
|
||||
if (!filename)
|
||||
if (!filename) {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
filename = resolve_tilde(config.restart_state_path);
|
||||
}
|
||||
@ -241,8 +245,9 @@ static char *store_restart_layout(void) {
|
||||
char *filenamecopy = sstrdup(filename);
|
||||
char *base = dirname(filenamecopy);
|
||||
DLOG("Creating \"%s\" for storing the restart layout\n", base);
|
||||
if (mkdirp(base, DEFAULT_DIR_MODE) != 0)
|
||||
if (mkdirp(base, DEFAULT_DIR_MODE) != 0) {
|
||||
ELOG("Could not create \"%s\" for storing the restart layout, layout will be lost.\n", base);
|
||||
}
|
||||
free(filenamecopy);
|
||||
|
||||
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
||||
@ -310,8 +315,9 @@ void i3_restart(bool forget_layout) {
|
||||
*
|
||||
*/
|
||||
char *pango_escape_markup(char *input) {
|
||||
if (!font_is_pango())
|
||||
if (!font_is_pango()) {
|
||||
return input;
|
||||
}
|
||||
|
||||
char *escaped = g_markup_escape_text(input, -1);
|
||||
FREE(input);
|
||||
@ -364,8 +370,9 @@ void start_nagbar(pid_t *nagbar_pid, char *argv[]) {
|
||||
}
|
||||
|
||||
/* child */
|
||||
if (*nagbar_pid == 0)
|
||||
if (*nagbar_pid == 0) {
|
||||
exec_i3_utility("i3-nagbar", argv);
|
||||
}
|
||||
|
||||
DLOG("Starting i3-nagbar with PID %d\n", *nagbar_pid);
|
||||
|
||||
@ -385,14 +392,17 @@ void start_nagbar(pid_t *nagbar_pid, char *argv[]) {
|
||||
*
|
||||
*/
|
||||
void kill_nagbar(pid_t nagbar_pid, bool wait_for_it) {
|
||||
if (nagbar_pid == -1)
|
||||
if (nagbar_pid == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (kill(nagbar_pid, SIGTERM) == -1)
|
||||
if (kill(nagbar_pid, SIGTERM) == -1) {
|
||||
warn("kill(configerror_nagbar) failed");
|
||||
}
|
||||
|
||||
if (!wait_for_it)
|
||||
if (!wait_for_it) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* When restarting, we don’t enter the ev main loop anymore and after the
|
||||
* exec(), our old pid is no longer watched. So, ev won’t handle SIGCHLD
|
||||
|
11
src/window.c
11
src/window.c
@ -49,10 +49,11 @@ void window_update_class(i3Window *win, xcb_get_property_reply_t *prop) {
|
||||
FREE(win->class_class);
|
||||
|
||||
win->class_instance = sstrndup(new_class, prop_length);
|
||||
if (class_class_index < prop_length)
|
||||
if (class_class_index < prop_length) {
|
||||
win->class_class = sstrndup(new_class + class_class_index, prop_length - class_class_index);
|
||||
else
|
||||
} else {
|
||||
win->class_class = NULL;
|
||||
}
|
||||
LOG("WM_CLASS changed to %s (instance), %s (class)\n",
|
||||
win->class_instance, win->class_class);
|
||||
|
||||
@ -375,8 +376,9 @@ bool window_update_normal_hints(i3Window *win, xcb_get_property_reply_t *reply,
|
||||
*
|
||||
*/
|
||||
void window_update_hints(i3Window *win, xcb_get_property_reply_t *prop, bool *urgency_hint) {
|
||||
if (urgency_hint != NULL)
|
||||
if (urgency_hint != NULL) {
|
||||
*urgency_hint = false;
|
||||
}
|
||||
|
||||
if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
|
||||
DLOG("WM_HINTS not set.\n");
|
||||
@ -397,8 +399,9 @@ void window_update_hints(i3Window *win, xcb_get_property_reply_t *prop, bool *ur
|
||||
LOG("WM_HINTS.input changed to \"%d\"\n", hints.input);
|
||||
}
|
||||
|
||||
if (urgency_hint != NULL)
|
||||
if (urgency_hint != NULL) {
|
||||
*urgency_hint = (xcb_icccm_wm_hints_get_urgency(&hints) != 0);
|
||||
}
|
||||
|
||||
free(prop);
|
||||
}
|
||||
|
150
src/workspace.c
150
src/workspace.c
@ -190,12 +190,14 @@ void extract_workspace_names_from_bindings(void) {
|
||||
TAILQ_FOREACH (bind, bindings, bindings) {
|
||||
DLOG("binding with command %s\n", bind->command);
|
||||
if (strlen(bind->command) < strlen("workspace ") ||
|
||||
strncasecmp(bind->command, "workspace", strlen("workspace")) != 0)
|
||||
strncasecmp(bind->command, "workspace", strlen("workspace")) != 0) {
|
||||
continue;
|
||||
}
|
||||
DLOG("relevant command = %s\n", bind->command);
|
||||
const char *target = bind->command + strlen("workspace ");
|
||||
while (*target == ' ' || *target == '\t')
|
||||
while (*target == ' ' || *target == '\t') {
|
||||
target++;
|
||||
}
|
||||
/* We check if this is the workspace
|
||||
* next/prev/next_on_output/prev_on_output/back_and_forth command.
|
||||
* Beware: The workspace names "next", "prev", "next_on_output",
|
||||
@ -206,21 +208,25 @@ void extract_workspace_names_from_bindings(void) {
|
||||
strncasecmp(target, "next_on_output", strlen("next_on_output")) == 0 ||
|
||||
strncasecmp(target, "prev_on_output", strlen("prev_on_output")) == 0 ||
|
||||
strncasecmp(target, "back_and_forth", strlen("back_and_forth")) == 0 ||
|
||||
strncasecmp(target, "current", strlen("current")) == 0)
|
||||
strncasecmp(target, "current", strlen("current")) == 0) {
|
||||
continue;
|
||||
}
|
||||
if (strncasecmp(target, "--no-auto-back-and-forth", strlen("--no-auto-back-and-forth")) == 0) {
|
||||
target += strlen("--no-auto-back-and-forth");
|
||||
while (*target == ' ' || *target == '\t')
|
||||
while (*target == ' ' || *target == '\t') {
|
||||
target++;
|
||||
}
|
||||
}
|
||||
if (strncasecmp(target, "number", strlen("number")) == 0) {
|
||||
target += strlen("number");
|
||||
while (*target == ' ' || *target == '\t')
|
||||
while (*target == ' ' || *target == '\t') {
|
||||
target++;
|
||||
}
|
||||
}
|
||||
char *target_name = parse_string(&target, false);
|
||||
if (target_name == NULL)
|
||||
if (target_name == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (strncasecmp(target_name, "__", strlen("__")) == 0) {
|
||||
LOG("Cannot create workspace \"%s\". Names starting with __ are i3-internal.\n", target);
|
||||
free(target_name);
|
||||
@ -331,24 +337,28 @@ static Con *_get_sticky(Con *con, const char *sticky_group, Con *exclude) {
|
||||
if (current != exclude &&
|
||||
current->sticky_group != NULL &&
|
||||
current->window != NULL &&
|
||||
strcmp(current->sticky_group, sticky_group) == 0)
|
||||
strcmp(current->sticky_group, sticky_group) == 0) {
|
||||
return current;
|
||||
}
|
||||
|
||||
Con *recurse = _get_sticky(current, sticky_group, exclude);
|
||||
if (recurse != NULL)
|
||||
if (recurse != NULL) {
|
||||
return recurse;
|
||||
}
|
||||
}
|
||||
|
||||
TAILQ_FOREACH (current, &(con->floating_head), floating_windows) {
|
||||
if (current != exclude &&
|
||||
current->sticky_group != NULL &&
|
||||
current->window != NULL &&
|
||||
strcmp(current->sticky_group, sticky_group) == 0)
|
||||
strcmp(current->sticky_group, sticky_group) == 0) {
|
||||
return current;
|
||||
}
|
||||
|
||||
Con *recurse = _get_sticky(current, sticky_group, exclude);
|
||||
if (recurse != NULL)
|
||||
if (recurse != NULL) {
|
||||
return recurse;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -429,14 +439,16 @@ void workspace_show(Con *workspace) {
|
||||
Con *current, *old = NULL;
|
||||
|
||||
/* safe-guard against showing i3-internal workspaces like __i3_scratch */
|
||||
if (con_is_internal(workspace))
|
||||
if (con_is_internal(workspace)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* disable fullscreen for the other workspaces and get the workspace we are
|
||||
* currently on. */
|
||||
TAILQ_FOREACH (current, &(workspace->parent->nodes_head), nodes) {
|
||||
if (current->fullscreen_mode == CF_OUTPUT)
|
||||
if (current->fullscreen_mode == CF_OUTPUT) {
|
||||
old = current;
|
||||
}
|
||||
current->fullscreen_mode = CF_NONE;
|
||||
}
|
||||
|
||||
@ -503,8 +515,9 @@ void workspace_show(Con *workspace) {
|
||||
focused, workspace);
|
||||
ev_timer_again(main_loop, focused->urgency_timer);
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
con_focus(next);
|
||||
}
|
||||
|
||||
ipc_send_workspace_event("focus", workspace, current);
|
||||
|
||||
@ -572,20 +585,25 @@ Con *workspace_next(void) {
|
||||
|
||||
if (current->num == -1) {
|
||||
/* If currently a named workspace, find next named workspace. */
|
||||
if ((next = TAILQ_NEXT(current, nodes)) != NULL)
|
||||
if ((next = TAILQ_NEXT(current, nodes)) != NULL) {
|
||||
return next;
|
||||
}
|
||||
bool found_current = false;
|
||||
TAILQ_FOREACH (output, &(croot->nodes_head), nodes) {
|
||||
/* Skip outputs starting with __, they are internal. */
|
||||
if (con_is_internal(output))
|
||||
if (con_is_internal(output)) {
|
||||
continue;
|
||||
}
|
||||
NODES_FOREACH (output_get_content(output)) {
|
||||
if (child->type != CT_WORKSPACE)
|
||||
if (child->type != CT_WORKSPACE) {
|
||||
continue;
|
||||
if (!first)
|
||||
}
|
||||
if (!first) {
|
||||
first = child;
|
||||
if (!first_opposite || (child->num != -1 && child->num < first_opposite->num))
|
||||
}
|
||||
if (!first_opposite || (child->num != -1 && child->num < first_opposite->num)) {
|
||||
first_opposite = child;
|
||||
}
|
||||
if (child == current) {
|
||||
found_current = true;
|
||||
} else if (child->num == -1 && found_current) {
|
||||
@ -598,28 +616,35 @@ Con *workspace_next(void) {
|
||||
/* If currently a numbered workspace, find next numbered workspace. */
|
||||
TAILQ_FOREACH (output, &(croot->nodes_head), nodes) {
|
||||
/* Skip outputs starting with __, they are internal. */
|
||||
if (con_is_internal(output))
|
||||
if (con_is_internal(output)) {
|
||||
continue;
|
||||
}
|
||||
NODES_FOREACH (output_get_content(output)) {
|
||||
if (child->type != CT_WORKSPACE)
|
||||
if (child->type != CT_WORKSPACE) {
|
||||
continue;
|
||||
if (!first || (child->num != -1 && child->num < first->num))
|
||||
}
|
||||
if (!first || (child->num != -1 && child->num < first->num)) {
|
||||
first = child;
|
||||
if (!first_opposite && child->num == -1)
|
||||
}
|
||||
if (!first_opposite && child->num == -1) {
|
||||
first_opposite = child;
|
||||
if (child->num == -1)
|
||||
}
|
||||
if (child->num == -1) {
|
||||
break;
|
||||
}
|
||||
/* Need to check child against current and next because we are
|
||||
* traversing multiple lists and thus are not guaranteed the
|
||||
* relative order between the list of workspaces. */
|
||||
if (current->num < child->num && (!next || child->num < next->num))
|
||||
if (current->num < child->num && (!next || child->num < next->num)) {
|
||||
next = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!next)
|
||||
if (!next) {
|
||||
next = first_opposite ? first_opposite : first;
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
@ -636,21 +661,26 @@ Con *workspace_prev(void) {
|
||||
if (current->num == -1) {
|
||||
/* If named workspace, find previous named workspace. */
|
||||
prev = TAILQ_PREV(current, nodes_head, nodes);
|
||||
if (prev && prev->num != -1)
|
||||
if (prev && prev->num != -1) {
|
||||
prev = NULL;
|
||||
}
|
||||
if (!prev) {
|
||||
bool found_current = false;
|
||||
TAILQ_FOREACH_REVERSE (output, &(croot->nodes_head), nodes_head, nodes) {
|
||||
/* Skip outputs starting with __, they are internal. */
|
||||
if (con_is_internal(output))
|
||||
if (con_is_internal(output)) {
|
||||
continue;
|
||||
}
|
||||
NODES_FOREACH_REVERSE (output_get_content(output)) {
|
||||
if (child->type != CT_WORKSPACE)
|
||||
if (child->type != CT_WORKSPACE) {
|
||||
continue;
|
||||
if (!last)
|
||||
}
|
||||
if (!last) {
|
||||
last = child;
|
||||
if (!first_opposite || (child->num != -1 && child->num > first_opposite->num))
|
||||
}
|
||||
if (!first_opposite || (child->num != -1 && child->num > first_opposite->num)) {
|
||||
first_opposite = child;
|
||||
}
|
||||
if (child == current) {
|
||||
found_current = true;
|
||||
} else if (child->num == -1 && found_current) {
|
||||
@ -664,28 +694,35 @@ Con *workspace_prev(void) {
|
||||
/* If numbered workspace, find previous numbered workspace. */
|
||||
TAILQ_FOREACH_REVERSE (output, &(croot->nodes_head), nodes_head, nodes) {
|
||||
/* Skip outputs starting with __, they are internal. */
|
||||
if (con_is_internal(output))
|
||||
if (con_is_internal(output)) {
|
||||
continue;
|
||||
}
|
||||
NODES_FOREACH_REVERSE (output_get_content(output)) {
|
||||
if (child->type != CT_WORKSPACE)
|
||||
if (child->type != CT_WORKSPACE) {
|
||||
continue;
|
||||
if (!last || (child->num != -1 && last->num < child->num))
|
||||
}
|
||||
if (!last || (child->num != -1 && last->num < child->num)) {
|
||||
last = child;
|
||||
if (!first_opposite && child->num == -1)
|
||||
}
|
||||
if (!first_opposite && child->num == -1) {
|
||||
first_opposite = child;
|
||||
if (child->num == -1)
|
||||
}
|
||||
if (child->num == -1) {
|
||||
continue;
|
||||
}
|
||||
/* Need to check child against current and previous because we
|
||||
* are traversing multiple lists and thus are not guaranteed
|
||||
* the relative order between the list of workspaces. */
|
||||
if (current->num > child->num && (!prev || child->num > prev->num))
|
||||
if (current->num > child->num && (!prev || child->num > prev->num)) {
|
||||
prev = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!prev)
|
||||
if (!prev) {
|
||||
prev = first_opposite ? first_opposite : last;
|
||||
}
|
||||
|
||||
return prev;
|
||||
}
|
||||
@ -705,15 +742,18 @@ Con *workspace_next_on_output(void) {
|
||||
} else {
|
||||
/* If currently a numbered workspace, find next numbered workspace. */
|
||||
NODES_FOREACH (output_get_content(output)) {
|
||||
if (child->type != CT_WORKSPACE)
|
||||
if (child->type != CT_WORKSPACE) {
|
||||
continue;
|
||||
if (child->num == -1)
|
||||
}
|
||||
if (child->num == -1) {
|
||||
break;
|
||||
}
|
||||
/* Need to check child against current and next because we are
|
||||
* traversing multiple lists and thus are not guaranteed the
|
||||
* relative order between the list of workspaces. */
|
||||
if (current->num < child->num && (!next || child->num < next->num))
|
||||
if (current->num < child->num && (!next || child->num < next->num)) {
|
||||
next = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -721,8 +761,9 @@ Con *workspace_next_on_output(void) {
|
||||
if (!next) {
|
||||
bool found_current = false;
|
||||
NODES_FOREACH (output_get_content(output)) {
|
||||
if (child->type != CT_WORKSPACE)
|
||||
if (child->type != CT_WORKSPACE) {
|
||||
continue;
|
||||
}
|
||||
if (child == current) {
|
||||
found_current = true;
|
||||
} else if (child->num == -1 && (current->num != -1 || found_current)) {
|
||||
@ -735,10 +776,12 @@ Con *workspace_next_on_output(void) {
|
||||
/* Find first workspace. */
|
||||
if (!next) {
|
||||
NODES_FOREACH (output_get_content(output)) {
|
||||
if (child->type != CT_WORKSPACE)
|
||||
if (child->type != CT_WORKSPACE) {
|
||||
continue;
|
||||
if (!next || (child->num != -1 && child->num < next->num))
|
||||
}
|
||||
if (!next || (child->num != -1 && child->num < next->num)) {
|
||||
next = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
workspace_next_on_output_end:
|
||||
@ -758,18 +801,21 @@ Con *workspace_prev_on_output(void) {
|
||||
if (current->num == -1) {
|
||||
/* If named workspace, find previous named workspace. */
|
||||
prev = TAILQ_PREV(current, nodes_head, nodes);
|
||||
if (prev && prev->num != -1)
|
||||
if (prev && prev->num != -1) {
|
||||
prev = NULL;
|
||||
}
|
||||
} else {
|
||||
/* If numbered workspace, find previous numbered workspace. */
|
||||
NODES_FOREACH_REVERSE (output_get_content(output)) {
|
||||
if (child->type != CT_WORKSPACE || child->num == -1)
|
||||
if (child->type != CT_WORKSPACE || child->num == -1) {
|
||||
continue;
|
||||
}
|
||||
/* Need to check child against current and previous because we
|
||||
* are traversing multiple lists and thus are not guaranteed
|
||||
* the relative order between the list of workspaces. */
|
||||
if (current->num > child->num && (!prev || child->num > prev->num))
|
||||
if (current->num > child->num && (!prev || child->num > prev->num)) {
|
||||
prev = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -777,8 +823,9 @@ Con *workspace_prev_on_output(void) {
|
||||
if (!prev) {
|
||||
bool found_current = false;
|
||||
NODES_FOREACH_REVERSE (output_get_content(output)) {
|
||||
if (child->type != CT_WORKSPACE)
|
||||
if (child->type != CT_WORKSPACE) {
|
||||
continue;
|
||||
}
|
||||
if (child == current) {
|
||||
found_current = true;
|
||||
} else if (child->num == -1 && (current->num != -1 || found_current)) {
|
||||
@ -791,10 +838,12 @@ Con *workspace_prev_on_output(void) {
|
||||
/* Find last workspace. */
|
||||
if (!prev) {
|
||||
NODES_FOREACH_REVERSE (output_get_content(output)) {
|
||||
if (child->type != CT_WORKSPACE)
|
||||
if (child->type != CT_WORKSPACE) {
|
||||
continue;
|
||||
if (!prev || child->num > prev->num)
|
||||
}
|
||||
if (!prev || child->num > prev->num) {
|
||||
prev = child;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -855,8 +904,9 @@ void workspace_update_urgent_flag(Con *ws) {
|
||||
ws->urgent = get_urgency_flag(ws);
|
||||
DLOG("Workspace urgency flag changed from %d to %d\n", old_flag, ws->urgent);
|
||||
|
||||
if (old_flag != ws->urgent)
|
||||
if (old_flag != ws->urgent) {
|
||||
ipc_send_workspace_event("urgent", ws, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
87
src/x.c
87
src/x.c
@ -308,13 +308,16 @@ bool window_supports_protocol(xcb_window_t window, xcb_atom_t atom) {
|
||||
bool result = false;
|
||||
|
||||
cookie = xcb_icccm_get_wm_protocols(conn, window, A_WM_PROTOCOLS);
|
||||
if (xcb_icccm_get_wm_protocols_reply(conn, cookie, &protocols, NULL) != 1)
|
||||
if (xcb_icccm_get_wm_protocols_reply(conn, cookie, &protocols, NULL) != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check if the client’s protocols have the requested atom set */
|
||||
for (uint32_t i = 0; i < protocols.atoms_len; i++)
|
||||
if (protocols.atoms[i] == atom)
|
||||
for (uint32_t i = 0; i < protocols.atoms_len; i++) {
|
||||
if (protocols.atoms[i] == atom) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
xcb_icccm_get_wm_protocols_reply_wipe(&protocols);
|
||||
|
||||
@ -473,18 +476,21 @@ void x_draw_decoration(Con *con) {
|
||||
parent->layout != L_TABBED) ||
|
||||
parent->type == CT_OUTPUT ||
|
||||
parent->type == CT_DOCKAREA ||
|
||||
con->type == CT_FLOATING_CON)
|
||||
con->type == CT_FLOATING_CON) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Skip containers whose height is 0 (for example empty dockareas) */
|
||||
if (con->rect.height == 0)
|
||||
if (con->rect.height == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Skip containers whose pixmap has not yet been created (can happen when
|
||||
* decoration rendering happens recursively for a window for which
|
||||
* x_push_node() was not yet called) */
|
||||
if (leaf && con->frame_buffer.id == XCB_NONE)
|
||||
if (leaf && con->frame_buffer.id == XCB_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* 1: build deco_params and compare with cache */
|
||||
struct deco_render_params *p = scalloc(1, sizeof(struct deco_render_params));
|
||||
@ -534,8 +540,9 @@ void x_draw_decoration(Con *con) {
|
||||
FREE(con->deco_render_params);
|
||||
con->deco_render_params = p;
|
||||
|
||||
if (con->window != NULL && con->window->name_x_changed)
|
||||
if (con->window != NULL && con->window->name_x_changed) {
|
||||
con->window->name_x_changed = false;
|
||||
}
|
||||
|
||||
parent->pixmap_recreated = false;
|
||||
con->pixmap_recreated = false;
|
||||
@ -604,8 +611,9 @@ void x_draw_decoration(Con *con) {
|
||||
|
||||
/* If the parent hasn't been set up yet, skip the decoration rendering
|
||||
* for now. */
|
||||
if (dest_surface->id == XCB_NONE)
|
||||
if (dest_surface->id == XCB_NONE) {
|
||||
goto copy_pixmaps;
|
||||
}
|
||||
|
||||
/* For the first child, we clear the parent pixmap to ensure there's no
|
||||
* garbage left on there. This is important to avoid tearing when using
|
||||
@ -616,8 +624,9 @@ void x_draw_decoration(Con *con) {
|
||||
|
||||
/* if this is a borderless/1pixel window, we don’t need to render the
|
||||
* decoration. */
|
||||
if (p->border_style != BS_NORMAL)
|
||||
if (p->border_style != BS_NORMAL) {
|
||||
goto copy_pixmaps;
|
||||
}
|
||||
|
||||
/* 4: paint the bar */
|
||||
DLOG("con->deco_rect = (x=%d, y=%d, w=%d, h=%d) for con->name=%s\n",
|
||||
@ -643,8 +652,9 @@ void x_draw_decoration(Con *con) {
|
||||
|
||||
mark_t *mark;
|
||||
TAILQ_FOREACH (mark, &(con->marks_head), marks) {
|
||||
if (mark->name[0] == '_')
|
||||
if (mark->name[0] == '_') {
|
||||
continue;
|
||||
}
|
||||
had_visible_mark = true;
|
||||
|
||||
char *buf;
|
||||
@ -789,8 +799,9 @@ void x_deco_recurse(Con *con) {
|
||||
}
|
||||
|
||||
if ((con->type != CT_ROOT && con->type != CT_OUTPUT) &&
|
||||
(!leaf || con->mapped))
|
||||
(!leaf || con->mapped)) {
|
||||
x_draw_decoration(con);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -804,8 +815,9 @@ static void set_hidden_state(Con *con) {
|
||||
|
||||
con_state *state = state_for_frame(con->frame.id);
|
||||
bool should_be_hidden = con_is_hidden(con);
|
||||
if (should_be_hidden == state->is_hidden)
|
||||
if (should_be_hidden == state->is_hidden) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (should_be_hidden) {
|
||||
DLOG("setting _NET_WM_STATE_HIDDEN for con = %p\n", con);
|
||||
@ -954,8 +966,9 @@ void x_push_node(Con *con) {
|
||||
}
|
||||
}
|
||||
rect.height = max_y + max_height;
|
||||
if (rect.height == 0)
|
||||
if (rect.height == 0) {
|
||||
con->mapped = false;
|
||||
}
|
||||
} else if (con->window == NULL) {
|
||||
/* not a stacked or tabbed split container */
|
||||
con->mapped = false;
|
||||
@ -1012,8 +1025,9 @@ void x_push_node(Con *con) {
|
||||
/* The root con and output cons will never require a pixmap. In particular for the
|
||||
* __i3 output, this will likely not work anyway because it might be ridiculously
|
||||
* large, causing an XCB_ALLOC error. */
|
||||
if (con->type == CT_ROOT || con->type == CT_OUTPUT)
|
||||
if (con->type == CT_ROOT || con->type == CT_OUTPUT) {
|
||||
is_pixmap_needed = false;
|
||||
}
|
||||
|
||||
bool fake_notify = false;
|
||||
/* Set new position if rect changed (and if height > 0) or if the pixmap
|
||||
@ -1044,8 +1058,9 @@ void x_push_node(Con *con) {
|
||||
}
|
||||
|
||||
uint16_t win_depth = root_depth;
|
||||
if (con->window)
|
||||
if (con->window) {
|
||||
win_depth = con->window->depth;
|
||||
}
|
||||
|
||||
/* Ensure we have valid dimensions for our surface. */
|
||||
/* TODO: This is probably a bug in the condition above as we should
|
||||
@ -1075,11 +1090,12 @@ void x_push_node(Con *con) {
|
||||
* TODO: Should this work the same way for L_TABBED? */
|
||||
if (!con->parent ||
|
||||
con->parent->layout != L_STACKED ||
|
||||
TAILQ_FIRST(&(con->parent->focus_head)) == con)
|
||||
TAILQ_FIRST(&(con->parent->focus_head)) == con) {
|
||||
/* Render the decoration now to make the correct decoration visible
|
||||
* from the very first moment. Later calls will be cached, so this
|
||||
* doesn’t hurt performance. */
|
||||
x_deco_recurse(con);
|
||||
}
|
||||
}
|
||||
|
||||
DLOG("setting rect (%d, %d, %d, %d)\n", rect.x, rect.y, rect.width, rect.height);
|
||||
@ -1226,13 +1242,15 @@ static void x_push_node_unmaps(Con *con) {
|
||||
* TODO: Remove once #1185 has been fixed
|
||||
*/
|
||||
static bool is_con_attached(Con *con) {
|
||||
if (con->parent == NULL)
|
||||
if (con->parent == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Con *current;
|
||||
TAILQ_FOREACH (current, &(con->parent->nodes_head), nodes) {
|
||||
if (current == con)
|
||||
if (current == con) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -1264,8 +1282,9 @@ void x_push_changes(Con *con) {
|
||||
* them become ConfigureRequests that i3 handles. */
|
||||
uint32_t values[1] = {XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT};
|
||||
CIRCLEQ_FOREACH_REVERSE (state, &state_head, state) {
|
||||
if (state->mapped)
|
||||
if (state->mapped) {
|
||||
xcb_change_window_attributes(conn, state->id, XCB_CW_EVENT_MASK, values);
|
||||
}
|
||||
}
|
||||
bool order_changed = false;
|
||||
bool stacking_changed = false;
|
||||
@ -1293,13 +1312,15 @@ void x_push_changes(Con *con) {
|
||||
|
||||
/* X11 correctly represents the stack if we push it from bottom to top */
|
||||
CIRCLEQ_FOREACH_REVERSE (state, &state_head, state) {
|
||||
if (con_has_managed_window(state->con))
|
||||
if (con_has_managed_window(state->con)) {
|
||||
memcpy(walk++, &(state->con->window->id), sizeof(xcb_window_t));
|
||||
}
|
||||
|
||||
con_state *prev = CIRCLEQ_PREV(state, state);
|
||||
con_state *old_prev = CIRCLEQ_PREV(state, old_state);
|
||||
if (prev != old_prev)
|
||||
if (prev != old_prev) {
|
||||
order_changed = true;
|
||||
}
|
||||
if ((state->initial || order_changed) && prev != CIRCLEQ_END(&state_head)) {
|
||||
stacking_changed = true;
|
||||
uint32_t mask = 0;
|
||||
@ -1322,8 +1343,9 @@ void x_push_changes(Con *con) {
|
||||
|
||||
/* reorder by initial mapping */
|
||||
TAILQ_FOREACH (state, &initial_mapping_head, initial_mapping_order) {
|
||||
if (con_has_managed_window(state->con))
|
||||
if (con_has_managed_window(state->con)) {
|
||||
*walk++ = state->con->window->id;
|
||||
}
|
||||
}
|
||||
|
||||
ewmh_update_client_list(client_list_windows, client_list_count);
|
||||
@ -1356,15 +1378,17 @@ void x_push_changes(Con *con) {
|
||||
|
||||
values[0] = FRAME_EVENT_MASK;
|
||||
CIRCLEQ_FOREACH_REVERSE (state, &state_head, state) {
|
||||
if (state->mapped)
|
||||
if (state->mapped) {
|
||||
xcb_change_window_attributes(conn, state->id, XCB_CW_EVENT_MASK, values);
|
||||
}
|
||||
}
|
||||
|
||||
x_deco_recurse(con);
|
||||
|
||||
xcb_window_t to_focus = focused->frame.id;
|
||||
if (focused->window != NULL)
|
||||
if (focused->window != NULL) {
|
||||
to_focus = focused->window->id;
|
||||
}
|
||||
|
||||
if (focused_id != to_focus) {
|
||||
if (!focused->mapped) {
|
||||
@ -1381,8 +1405,9 @@ void x_push_changes(Con *con) {
|
||||
|
||||
change_ewmh_focus((con_has_managed_window(focused) ? focused->window->id : XCB_WINDOW_NONE), last_focused);
|
||||
|
||||
if (to_focus != last_focused && is_con_attached(focused))
|
||||
if (to_focus != last_focused && is_con_attached(focused)) {
|
||||
ipc_send_window_event("focus", focused);
|
||||
}
|
||||
} else {
|
||||
DLOG("Updating focus (focused: %p / %s) to X11 window 0x%08x\n", focused, focused->name, to_focus);
|
||||
/* We remove XCB_EVENT_MASK_FOCUS_CHANGE from the event mask to get
|
||||
@ -1400,8 +1425,9 @@ void x_push_changes(Con *con) {
|
||||
|
||||
change_ewmh_focus((con_has_managed_window(focused) ? focused->window->id : XCB_WINDOW_NONE), last_focused);
|
||||
|
||||
if (to_focus != XCB_NONE && to_focus != last_focused && focused->window != NULL && is_con_attached(focused))
|
||||
if (to_focus != XCB_NONE && to_focus != last_focused && focused->window != NULL && is_con_attached(focused)) {
|
||||
ipc_send_window_event("focus", focused);
|
||||
}
|
||||
}
|
||||
|
||||
focused_id = last_focused = to_focus;
|
||||
@ -1431,8 +1457,9 @@ void x_push_changes(Con *con) {
|
||||
* EnterNotify event. */
|
||||
values[0] = FRAME_EVENT_MASK & ~XCB_EVENT_MASK_ENTER_WINDOW;
|
||||
CIRCLEQ_FOREACH_REVERSE (state, &state_head, state) {
|
||||
if (!state->unmap_now)
|
||||
if (!state->unmap_now) {
|
||||
continue;
|
||||
}
|
||||
xcb_change_window_attributes(conn, state->id, XCB_CW_EVENT_MASK, values);
|
||||
}
|
||||
|
||||
@ -1516,8 +1543,9 @@ void x_set_i3_atoms(void) {
|
||||
*
|
||||
*/
|
||||
void x_set_warp_to(Rect *rect) {
|
||||
if (config.mouse_warping != POINTER_WARPING_NONE)
|
||||
if (config.mouse_warping != POINTER_WARPING_NONE) {
|
||||
warp_to = rect;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1531,8 +1559,9 @@ void x_mask_event_mask(uint32_t mask) {
|
||||
|
||||
con_state *state;
|
||||
CIRCLEQ_FOREACH_REVERSE (state, &state_head, state) {
|
||||
if (state->mapped)
|
||||
if (state->mapped) {
|
||||
xcb_change_window_attributes(conn, state->id, XCB_CW_EVENT_MASK, values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
36
src/xcb.c
36
src/xcb.c
@ -49,8 +49,9 @@ xcb_window_t create_window(xcb_connection_t *conn, Rect dims,
|
||||
xcb_change_window_attributes(conn, result, XCB_CW_CURSOR, cursor_values);
|
||||
|
||||
/* Map the window (= make it visible) */
|
||||
if (map)
|
||||
if (map) {
|
||||
xcb_map_window(conn, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -62,8 +63,9 @@ xcb_window_t create_window(xcb_connection_t *conn, Rect dims,
|
||||
*/
|
||||
void fake_absolute_configure_notify(Con *con) {
|
||||
xcb_rectangle_t absolute;
|
||||
if (con->window == NULL)
|
||||
if (con->window == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
absolute.x = con->rect.x + con->window_rect.x;
|
||||
absolute.y = con->rect.y + con->window_rect.y;
|
||||
@ -119,12 +121,14 @@ void xcb_set_window_rect(xcb_connection_t *conn, xcb_window_t window, Rect r) {
|
||||
*
|
||||
*/
|
||||
xcb_atom_t xcb_get_preferred_window_type(xcb_get_property_reply_t *reply) {
|
||||
if (reply == NULL || xcb_get_property_value_length(reply) == 0)
|
||||
if (reply == NULL || xcb_get_property_value_length(reply) == 0) {
|
||||
return XCB_NONE;
|
||||
}
|
||||
|
||||
xcb_atom_t *atoms;
|
||||
if ((atoms = xcb_get_property_value(reply)) == NULL)
|
||||
if ((atoms = xcb_get_property_value(reply)) == NULL) {
|
||||
return XCB_NONE;
|
||||
}
|
||||
|
||||
for (int i = 0; i < xcb_get_property_value_length(reply) / (reply->format / 8); i++) {
|
||||
if (atoms[i] == A__NET_WM_WINDOW_TYPE_NORMAL ||
|
||||
@ -149,16 +153,20 @@ xcb_atom_t xcb_get_preferred_window_type(xcb_get_property_reply_t *reply) {
|
||||
*
|
||||
*/
|
||||
bool xcb_reply_contains_atom(xcb_get_property_reply_t *prop, xcb_atom_t atom) {
|
||||
if (prop == NULL || xcb_get_property_value_length(prop) == 0)
|
||||
if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
xcb_atom_t *atoms;
|
||||
if ((atoms = xcb_get_property_value(prop)) == NULL)
|
||||
if ((atoms = xcb_get_property_value(prop)) == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < xcb_get_property_value_length(prop) / (prop->format / 8); i++)
|
||||
if (atoms[i] == atom)
|
||||
for (int i = 0; i < xcb_get_property_value_length(prop) / (prop->format / 8); i++) {
|
||||
if (atoms[i] == atom) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -193,14 +201,16 @@ xcb_visualid_t get_visualid_by_depth(uint16_t depth) {
|
||||
|
||||
depth_iter = xcb_screen_allowed_depths_iterator(root_screen);
|
||||
for (; depth_iter.rem; xcb_depth_next(&depth_iter)) {
|
||||
if (depth_iter.data->depth != depth)
|
||||
if (depth_iter.data->depth != depth) {
|
||||
continue;
|
||||
}
|
||||
|
||||
xcb_visualtype_iterator_t visual_iter;
|
||||
|
||||
visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
|
||||
if (!visual_iter.rem)
|
||||
if (!visual_iter.rem) {
|
||||
continue;
|
||||
}
|
||||
return visual_iter.data->visual_id;
|
||||
}
|
||||
return 0;
|
||||
@ -227,8 +237,9 @@ void xcb_remove_property_atom(xcb_connection_t *conn, xcb_window_t window, xcb_a
|
||||
xcb_get_property_reply_t *reply =
|
||||
xcb_get_property_reply(conn,
|
||||
xcb_get_property(conn, false, window, property, XCB_GET_PROPERTY_TYPE_ANY, 0, 4096), NULL);
|
||||
if (reply == NULL || xcb_get_property_value_length(reply) == 0)
|
||||
if (reply == NULL || xcb_get_property_value_length(reply) == 0) {
|
||||
goto release_grab;
|
||||
}
|
||||
xcb_atom_t *atoms = xcb_get_property_value(reply);
|
||||
if (atoms == NULL) {
|
||||
goto release_grab;
|
||||
@ -239,8 +250,9 @@ void xcb_remove_property_atom(xcb_connection_t *conn, xcb_window_t window, xcb_a
|
||||
const int current_size = xcb_get_property_value_length(reply) / (reply->format / 8);
|
||||
xcb_atom_t values[current_size];
|
||||
for (int i = 0; i < current_size; i++) {
|
||||
if (atoms[i] != atom)
|
||||
if (atoms[i] != atom) {
|
||||
values[num++] = atoms[i];
|
||||
}
|
||||
}
|
||||
|
||||
xcb_change_property(conn, XCB_PROP_MODE_REPLACE, window, property, XCB_ATOM_ATOM, 32, num, values);
|
||||
|
@ -68,10 +68,11 @@ static void query_screens(xcb_connection_t *conn) {
|
||||
s->rect.width = screen_info[screen].width;
|
||||
s->rect.height = screen_info[screen].height;
|
||||
/* We always treat the screen at 0x0 as the primary screen */
|
||||
if (s->rect.x == 0 && s->rect.y == 0)
|
||||
if (s->rect.x == 0 && s->rect.y == 0) {
|
||||
TAILQ_INSERT_HEAD(&outputs, s, outputs);
|
||||
else
|
||||
} else {
|
||||
TAILQ_INSERT_TAIL(&outputs, s, outputs);
|
||||
}
|
||||
output_init_con(s);
|
||||
init_ws_for_output(s);
|
||||
num_screens++;
|
||||
@ -119,8 +120,9 @@ void xinerama_init(void) {
|
||||
if (reply == NULL || !reply->state) {
|
||||
DLOG("Xinerama is not active (in your X-Server), using root output.\n");
|
||||
use_root_output(conn);
|
||||
} else
|
||||
} else {
|
||||
query_screens(conn);
|
||||
}
|
||||
|
||||
FREE(reply);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user