mirror of
https://github.com/swaywm/sway.git
synced 2026-04-30 06:46:24 -04:00
Merge 021933f735 into 5f8676f214
This commit is contained in:
commit
1ff14a35e5
14 changed files with 33 additions and 23 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
size_t utf8_chsize(uint32_t ch) {
|
size_t utf8_chsize(uint32_t ch) {
|
||||||
if (ch < 0x80) {
|
if (ch < 0x80) {
|
||||||
|
|
@ -92,7 +93,7 @@ static const struct {
|
||||||
|
|
||||||
int utf8_size(const char *s) {
|
int utf8_size(const char *s) {
|
||||||
uint8_t c = (uint8_t)*s;
|
uint8_t c = (uint8_t)*s;
|
||||||
for (size_t i = 0; i < sizeof(sizes) / sizeof(*sizes); ++i) {
|
for (size_t i = 0; i < ARRAY_SIZE(sizes); ++i) {
|
||||||
if ((c & sizes[i].mask) == sizes[i].result) {
|
if ((c & sizes[i].mask) == sizes[i].result) {
|
||||||
return sizes[i].octets;
|
return sizes[i].octets;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ static struct modifier_key {
|
||||||
|
|
||||||
uint32_t get_modifier_mask_by_name(const char *name) {
|
uint32_t get_modifier_mask_by_name(const char *name) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) {
|
for (i = 0; i < (int)(ARRAY_SIZE(modifiers)); ++i) {
|
||||||
if (strcasecmp(modifiers[i].name, name) == 0) {
|
if (strcasecmp(modifiers[i].name, name) == 0) {
|
||||||
return modifiers[i].mod;
|
return modifiers[i].mod;
|
||||||
}
|
}
|
||||||
|
|
@ -54,7 +54,7 @@ uint32_t get_modifier_mask_by_name(const char *name) {
|
||||||
|
|
||||||
const char *get_modifier_name_by_mask(uint32_t modifier) {
|
const char *get_modifier_name_by_mask(uint32_t modifier) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) {
|
for (i = 0; i < (int)(ARRAY_SIZE(modifiers)); ++i) {
|
||||||
if (modifiers[i].mod == modifier) {
|
if (modifiers[i].mod == modifier) {
|
||||||
return modifiers[i].name;
|
return modifiers[i].name;
|
||||||
}
|
}
|
||||||
|
|
@ -66,7 +66,7 @@ const char *get_modifier_name_by_mask(uint32_t modifier) {
|
||||||
int get_modifier_names(const char **names, uint32_t modifier_masks) {
|
int get_modifier_names(const char **names, uint32_t modifier_masks) {
|
||||||
int length = 0;
|
int length = 0;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++i) {
|
for (i = 0; i < (int)(ARRAY_SIZE(modifiers)); ++i) {
|
||||||
if ((modifier_masks & modifiers[i].mod) != 0) {
|
if ((modifier_masks & modifiers[i].mod) != 0) {
|
||||||
names[length] = modifiers[i].name;
|
names[length] = modifiers[i].name;
|
||||||
++length;
|
++length;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <xkbcommon/xkbcommon.h>
|
#include <xkbcommon/xkbcommon.h>
|
||||||
|
|
||||||
|
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a)[0])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap i into the range [0, max[
|
* Wrap i into the range [0, max[
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
#include "sway/tree/view.h"
|
#include "sway/tree/view.h"
|
||||||
#include "stringop.h"
|
#include "stringop.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
// Returns error object, or NULL if check succeeds.
|
// Returns error object, or NULL if check succeeds.
|
||||||
struct cmd_results *checkarg(int argc, const char *name, enum expected_args type, int val) {
|
struct cmd_results *checkarg(int argc, const char *name, enum expected_args type, int val) {
|
||||||
|
|
@ -177,7 +178,7 @@ struct cmd_handler *find_handler(char *line, struct cmd_handler *cmd_handlers,
|
||||||
|
|
||||||
if (!config_loading) {
|
if (!config_loading) {
|
||||||
res = bsearch(&d, command_handlers,
|
res = bsearch(&d, command_handlers,
|
||||||
sizeof(command_handlers) / sizeof(struct cmd_handler),
|
ARRAY_SIZE(command_handlers),
|
||||||
sizeof(struct cmd_handler), handler_compare);
|
sizeof(struct cmd_handler), handler_compare);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
|
|
@ -187,7 +188,7 @@ struct cmd_handler *find_handler(char *line, struct cmd_handler *cmd_handlers,
|
||||||
|
|
||||||
if (config->reading) {
|
if (config->reading) {
|
||||||
res = bsearch(&d, config_handlers,
|
res = bsearch(&d, config_handlers,
|
||||||
sizeof(config_handlers) / sizeof(struct cmd_handler),
|
ARRAY_SIZE(config_handlers),
|
||||||
sizeof(struct cmd_handler), handler_compare);
|
sizeof(struct cmd_handler), handler_compare);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
|
|
@ -455,12 +456,12 @@ struct cmd_results *config_commands_command(char *exec) {
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
size_t j;
|
size_t j;
|
||||||
for (j = 0; j < sizeof(context_names) / sizeof(context_names[0]); ++j) {
|
for (j = 0; j < ARRAY_SIZE(context_names); ++j) {
|
||||||
if (strcmp(context_names[j].name, argv[i]) == 0) {
|
if (strcmp(context_names[j].name, argv[i]) == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (j == sizeof(context_names) / sizeof(context_names[0])) {
|
if (j == ARRAY_SIZE(context_names)) {
|
||||||
results = cmd_results_new(CMD_INVALID, cmd,
|
results = cmd_results_new(CMD_INVALID, cmd,
|
||||||
"Invalid command context %s", argv[i]);
|
"Invalid command context %s", argv[i]);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct cmd_results *bar_cmd_position(int argc, char **argv) {
|
struct cmd_results *bar_cmd_position(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
|
|
@ -13,7 +14,7 @@ struct cmd_results *bar_cmd_position(int argc, char **argv) {
|
||||||
return cmd_results_new(CMD_FAILURE, "position", "No bar defined.");
|
return cmd_results_new(CMD_FAILURE, "position", "No bar defined.");
|
||||||
}
|
}
|
||||||
char *valid[] = { "top", "bottom", "left", "right" };
|
char *valid[] = { "top", "bottom", "left", "right" };
|
||||||
for (size_t i = 0; i < sizeof(valid) / sizeof(valid[0]); ++i) {
|
for (size_t i = 0; i < ARRAY_SIZE(valid); ++i) {
|
||||||
if (strcasecmp(valid[i], argv[0]) == 0) {
|
if (strcasecmp(valid[i], argv[0]) == 0) {
|
||||||
wlr_log(WLR_DEBUG, "Setting bar position '%s' for bar: %s",
|
wlr_log(WLR_DEBUG, "Setting bar position '%s' for bar: %s",
|
||||||
argv[0], config->current_bar->id);
|
argv[0], config->current_bar->id);
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
#include "sway/tree/workspace.h"
|
#include "sway/tree/workspace.h"
|
||||||
#include "stringop.h"
|
#include "stringop.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
static const char* expected_syntax =
|
static const char* expected_syntax =
|
||||||
"Expected 'move <left|right|up|down> <[px] px>' or "
|
"Expected 'move <left|right|up|down> <[px] px>' or "
|
||||||
|
|
@ -34,7 +35,7 @@ static struct sway_container *output_in_direction(const char *direction,
|
||||||
{ "left", WLR_DIRECTION_LEFT },
|
{ "left", WLR_DIRECTION_LEFT },
|
||||||
{ "right", WLR_DIRECTION_RIGHT },
|
{ "right", WLR_DIRECTION_RIGHT },
|
||||||
};
|
};
|
||||||
for (size_t i = 0; i < sizeof(names) / sizeof(names[0]); ++i) {
|
for (size_t i = 0; i < ARRAY_SIZE(names); ++i) {
|
||||||
if (strcasecmp(names[i].name, direction) == 0) {
|
if (strcasecmp(names[i].name, direction) == 0) {
|
||||||
struct wlr_output *adjacent = wlr_output_layout_adjacent_output(
|
struct wlr_output *adjacent = wlr_output_layout_adjacent_output(
|
||||||
root_container.sway_root->output_layout,
|
root_container.sway_root->output_layout,
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include "sway/config.h"
|
#include "sway/config.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "stringop.h"
|
#include "stringop.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
static const char *bg_options[] = {
|
static const char *bg_options[] = {
|
||||||
"stretch",
|
"stretch",
|
||||||
|
|
@ -43,7 +44,7 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
|
||||||
size_t j;
|
size_t j;
|
||||||
for (j = 0; j < (size_t)argc; ++j) {
|
for (j = 0; j < (size_t)argc; ++j) {
|
||||||
mode = argv[j];
|
mode = argv[j];
|
||||||
size_t n = sizeof(bg_options) / sizeof(char *);
|
size_t n = ARRAY_SIZE(bg_options);
|
||||||
for (size_t k = 0; k < n; ++k) {
|
for (size_t k = 0; k < n; ++k) {
|
||||||
if (strcasecmp(mode, bg_options[k]) == 0) {
|
if (strcasecmp(mode, bg_options[k]) == 0) {
|
||||||
valid = true;
|
valid = true;
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
#include "stringop.h"
|
#include "stringop.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
struct sway_config *config = NULL;
|
struct sway_config *config = NULL;
|
||||||
|
|
||||||
|
|
@ -305,7 +306,7 @@ static char *get_config_path(void) {
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < (int)(sizeof(config_paths) / sizeof(char *)); ++i) {
|
for (i = 0; i < (int)(ARRAY_SIZE(config_paths)); ++i) {
|
||||||
if (wordexp(config_paths[i], &p, 0) == 0) {
|
if (wordexp(config_paths[i], &p, 0) == 0) {
|
||||||
path = strdup(p.we_wordv[0]);
|
path = strdup(p.we_wordv[0]);
|
||||||
wordfree(&p);
|
wordfree(&p);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#include "sway/server.h"
|
#include "sway/server.h"
|
||||||
#include "sway/tree/layout.h"
|
#include "sway/tree/layout.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
static void apply_exclusive(struct wlr_box *usable_area,
|
static void apply_exclusive(struct wlr_box *usable_area,
|
||||||
uint32_t anchor, int32_t exclusive,
|
uint32_t anchor, int32_t exclusive,
|
||||||
|
|
@ -65,7 +66,7 @@ static void apply_exclusive(struct wlr_box *usable_area,
|
||||||
.margin = margin_right,
|
.margin = margin_right,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
for (size_t i = 0; i < sizeof(edges) / sizeof(edges[0]); ++i) {
|
for (size_t i = 0; i < ARRAY_SIZE(edges); ++i) {
|
||||||
if ((anchor & edges[i].anchors) == edges[i].anchors) {
|
if ((anchor & edges[i].anchors) == edges[i].anchors) {
|
||||||
if (edges[i].positive_axis) {
|
if (edges[i].positive_axis) {
|
||||||
*edges[i].positive_axis += exclusive + edges[i].margin;
|
*edges[i].positive_axis += exclusive + edges[i].margin;
|
||||||
|
|
@ -193,7 +194,7 @@ void arrange_layers(struct sway_output *output) {
|
||||||
ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY,
|
ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY,
|
||||||
ZWLR_LAYER_SHELL_V1_LAYER_TOP,
|
ZWLR_LAYER_SHELL_V1_LAYER_TOP,
|
||||||
};
|
};
|
||||||
size_t nlayers = sizeof(layers_above_shell) / sizeof(layers_above_shell[0]);
|
size_t nlayers = ARRAY_SIZE(layers_above_shell);
|
||||||
struct sway_layer_surface *layer, *topmost = NULL;
|
struct sway_layer_surface *layer, *topmost = NULL;
|
||||||
for (size_t i = 0; i < nlayers; ++i) {
|
for (size_t i = 0; i < nlayers; ++i) {
|
||||||
wl_list_for_each_reverse(layer,
|
wl_list_for_each_reverse(layer,
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
#include <wlr/util/region.h>
|
#include <wlr/util/region.h>
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "util.h"
|
||||||
#include "sway/config.h"
|
#include "sway/config.h"
|
||||||
#include "sway/input/input-manager.h"
|
#include "sway/input/input-manager.h"
|
||||||
#include "sway/input/seat.h"
|
#include "sway/input/seat.h"
|
||||||
|
|
@ -559,7 +560,7 @@ void output_enable(struct sway_output *output) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t len = sizeof(output->layers) / sizeof(output->layers[0]);
|
size_t len = ARRAY_SIZE(output->layers);
|
||||||
for (size_t i = 0; i < len; ++i) {
|
for (size_t i = 0; i < len; ++i) {
|
||||||
wl_list_init(&output->layers[i]);
|
wl_list_init(&output->layers[i]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ static void log_env() {
|
||||||
"SWAY_CURSOR_SIZE",
|
"SWAY_CURSOR_SIZE",
|
||||||
"SWAYSOCK"
|
"SWAYSOCK"
|
||||||
};
|
};
|
||||||
for (size_t i = 0; i < sizeof(log_vars) / sizeof(char *); ++i) {
|
for (size_t i = 0; i < ARRAY_SIZE(log_vars); ++i) {
|
||||||
wlr_log(WLR_INFO, "%s=%s", log_vars[i], getenv(log_vars[i]));
|
wlr_log(WLR_INFO, "%s=%s", log_vars[i], getenv(log_vars[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +142,7 @@ static void log_distro() {
|
||||||
"/etc/redhat-release",
|
"/etc/redhat-release",
|
||||||
"/etc/gentoo-release",
|
"/etc/gentoo-release",
|
||||||
};
|
};
|
||||||
for (size_t i = 0; i < sizeof(paths) / sizeof(char *); ++i) {
|
for (size_t i = 0; i < ARRAY_SIZE(paths); ++i) {
|
||||||
FILE *f = fopen(paths[i], "r");
|
FILE *f = fopen(paths[i], "r");
|
||||||
if (f) {
|
if (f) {
|
||||||
wlr_log(WLR_INFO, "Contents of %s:", paths[i]);
|
wlr_log(WLR_INFO, "Contents of %s:", paths[i]);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "swaybar/config.h"
|
#include "swaybar/config.h"
|
||||||
#include "swaybar/status_line.h"
|
#include "swaybar/status_line.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
void i3bar_block_free(struct i3bar_block *block) {
|
void i3bar_block_free(struct i3bar_block *block) {
|
||||||
if (!block) {
|
if (!block) {
|
||||||
|
|
@ -146,8 +147,7 @@ bool i3bar_handle_readable(struct status_line *status) {
|
||||||
switch (*cur) {
|
switch (*cur) {
|
||||||
case '[':
|
case '[':
|
||||||
++state->depth;
|
++state->depth;
|
||||||
if (state->depth >
|
if (state->depth > ARRAY_SIZE(state->nodes)) {
|
||||||
sizeof(state->nodes) / sizeof(state->nodes[0])) {
|
|
||||||
status_error(status, "[i3bar json too deep]");
|
status_error(status, "[i3bar json too deep]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -177,8 +177,7 @@ bool i3bar_handle_readable(struct status_line *status) {
|
||||||
break;
|
break;
|
||||||
case '"':
|
case '"':
|
||||||
++state->depth;
|
++state->depth;
|
||||||
if (state->depth >
|
if (state->depth > ARRAY_SIZE(state->nodes)) {
|
||||||
sizeof(state->nodes) / sizeof(state->nodes[0])) {
|
|
||||||
status_error(status, "[i3bar json too deep]");
|
status_error(status, "[i3bar json too deep]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -783,7 +783,7 @@ static char *get_config_path(void) {
|
||||||
|
|
||||||
wordexp_t p;
|
wordexp_t p;
|
||||||
char *path;
|
char *path;
|
||||||
for (size_t i = 0; i < sizeof(config_paths) / sizeof(char *); ++i) {
|
for (size_t i = 0; i < ARRAY_SIZE(config_paths); ++i) {
|
||||||
if (wordexp(config_paths[i], &p, 0) == 0) {
|
if (wordexp(config_paths[i], &p, 0) == 0) {
|
||||||
path = strdup(p.we_wordv[0]);
|
path = strdup(p.we_wordv[0]);
|
||||||
wordfree(&p);
|
wordfree(&p);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#include "ipc-client.h"
|
#include "ipc-client.h"
|
||||||
#include "readline.h"
|
#include "readline.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
void sway_terminate(int exit_code) {
|
void sway_terminate(int exit_code) {
|
||||||
exit(exit_code);
|
exit(exit_code);
|
||||||
|
|
@ -101,7 +102,7 @@ static const char *pretty_type_name(const char *name) {
|
||||||
{ "touch", "Touch" },
|
{ "touch", "Touch" },
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof(type_names) / sizeof(type_names[0]); ++i) {
|
for (size_t i = 0; i < ARRAY_SIZE(type_names); ++i) {
|
||||||
if (strcmp(type_names[i].a, name) == 0) {
|
if (strcmp(type_names[i].a, name) == 0) {
|
||||||
return type_names[i].b;
|
return type_names[i].b;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue