mirror of
https://github.com/swaywm/sway.git
synced 2026-05-05 06:46:49 -04:00
Got it to build.
This commit is contained in:
parent
46a53704ad
commit
a2896f33a4
55 changed files with 822 additions and 797 deletions
|
|
@ -66,6 +66,14 @@ void list_add(list_t *list, const void *data) {
|
||||||
++list->length;
|
++list->length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *list_alloc(list_t *list) {
|
||||||
|
if (!sway_assert(list, "Invalid argument") || !resize(list)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (uint8_t *)list->items + list->memb_size * list->length++;
|
||||||
|
}
|
||||||
|
|
||||||
void list_insert(list_t *list, size_t index, const void *data) {
|
void list_insert(list_t *list, size_t index, const void *data) {
|
||||||
if (!sway_assert(list && data && index <= list->length, "Invalid argument") ||
|
if (!sway_assert(list && data && index <= list->length, "Invalid argument") ||
|
||||||
!resize(list)) {
|
!resize(list)) {
|
||||||
|
|
@ -80,17 +88,7 @@ void list_insert(list_t *list, size_t index, const void *data) {
|
||||||
++list->length;
|
++list->length;
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_delete(list_t *list, size_t index) {
|
static void shrink(list_t *list) {
|
||||||
if (!sway_assert(list && index < list->length, "Invalid argument")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size = list->memb_size;
|
|
||||||
uint8_t (*array)[size] = list->items;
|
|
||||||
|
|
||||||
memmove(&array[index], &array[index + 1], size * (list->length - index));
|
|
||||||
--list->length;
|
|
||||||
|
|
||||||
/* We shrink very sparse lists, but only down to a certain size.
|
/* We shrink very sparse lists, but only down to a certain size.
|
||||||
* The choice of >= 8 is somewhat arbitrary, but leaves a minimum
|
* The choice of >= 8 is somewhat arbitrary, but leaves a minimum
|
||||||
* size of 4 elements.
|
* size of 4 elements.
|
||||||
|
|
@ -107,6 +105,28 @@ void list_delete(list_t *list, size_t index) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void list_remove(list_t *list) {
|
||||||
|
if (!sway_assert(list, "Invalid argument") || list->length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
--list->length;
|
||||||
|
shrink(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
void list_delete(list_t *list, size_t index) {
|
||||||
|
if (!sway_assert(list && index < list->length, "Invalid argument")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size = list->memb_size;
|
||||||
|
uint8_t (*array)[size] = list->items;
|
||||||
|
|
||||||
|
memmove(&array[index], &array[index + 1], size * (list->length - index));
|
||||||
|
--list->length;
|
||||||
|
shrink(list);
|
||||||
|
}
|
||||||
|
|
||||||
void list_swap(list_t *list, size_t i1, size_t i2) {
|
void list_swap(list_t *list, size_t i1, size_t i2) {
|
||||||
if (!sway_assert(list && i1 < list->length && i2 < list->length, "Invalid argument")) {
|
if (!sway_assert(list && i1 < list->length && i2 < list->length, "Invalid argument")) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -215,6 +235,15 @@ void list_foreach(list_t *list, void callback(void *item)) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void list_free_with(list_t *list, void callback(void *item)) {
|
||||||
|
if (!sway_assert(callback, "Invalid argument") || !list) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
list_foreach(list, callback);
|
||||||
|
list_free(list);
|
||||||
|
}
|
||||||
|
|
||||||
void *list_end(list_t *list) {
|
void *list_end(list_t *list) {
|
||||||
if (!sway_assert(list, "Invalid argument")) {
|
if (!sway_assert(list, "Invalid argument")) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -222,3 +251,7 @@ void *list_end(list_t *list) {
|
||||||
|
|
||||||
return (uint8_t *)list->items + list->memb_size * list->length;
|
return (uint8_t *)list->items + list->memb_size * list->length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void list_elem_free(void *item) {
|
||||||
|
free(*(void **)item);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,14 +69,14 @@ int lenient_strcmp(char *a, char *b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
list_t *split_string(const char *str, const char *delims) {
|
list_t *split_string(const char *str, const char *delims) {
|
||||||
list_t *res = create_list();
|
list_t *res = list_new(sizeof(char *), 0);
|
||||||
char *copy = strdup(str);
|
char *copy = strdup(str);
|
||||||
char *token;
|
char *token;
|
||||||
|
|
||||||
token = strtok(copy, delims);
|
token = strtok(copy, delims);
|
||||||
while(token) {
|
while(token) {
|
||||||
token = strdup(token);
|
token = strdup(token);
|
||||||
list_add(res, token);
|
list_add(res, &token);
|
||||||
token = strtok(NULL, delims);
|
token = strtok(NULL, delims);
|
||||||
}
|
}
|
||||||
free(copy);
|
free(copy);
|
||||||
|
|
@ -84,11 +84,7 @@ list_t *split_string(const char *str, const char *delims) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_flat_list(list_t *list) {
|
void free_flat_list(list_t *list) {
|
||||||
int i;
|
list_free_with(list, list_elem_free);
|
||||||
for (i = 0; i < list->length; ++i) {
|
|
||||||
free(list->items[i]);
|
|
||||||
}
|
|
||||||
list_free(list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char **split_args(const char *start, int *argc) {
|
char **split_args(const char *start, int *argc) {
|
||||||
|
|
@ -315,22 +311,25 @@ char *join_list(list_t *list, char *separator) {
|
||||||
len += (list->length - 1) * sep_len;
|
len += (list->length - 1) * sep_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < list->length; i++) {
|
for (size_t i = 0; i < list->length; i++) {
|
||||||
len += strlen(list->items[i]);
|
char *item = *(char **)list_get(list, i);
|
||||||
|
len += strlen(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *res = malloc(len);
|
char *res = malloc(len);
|
||||||
|
|
||||||
char *p = res + strlen(list->items[0]);
|
char *item = *(char **)list_get(list, 0);
|
||||||
strcpy(res, list->items[0]);
|
char *p = res + strlen(item);
|
||||||
|
strcpy(res, item);
|
||||||
|
|
||||||
for (int i = 1; i < list->length; i++) {
|
for (size_t i = 1; i < list->length; i++) {
|
||||||
|
item = *(char **)list_get(list, i);
|
||||||
if (sep_len) {
|
if (sep_len) {
|
||||||
memcpy(p, separator, sep_len);
|
memcpy(p, separator, sep_len);
|
||||||
p += sep_len;
|
p += sep_len;
|
||||||
}
|
}
|
||||||
strcpy(p, list->items[i]);
|
strcpy(p, item);
|
||||||
p += strlen(list->items[i]);
|
p += strlen(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,41 @@ list_t *list_new(size_t memb_size, size_t capacity);
|
||||||
void list_free(list_t *list);
|
void list_free(list_t *list);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adds an element to the end of the list.
|
* Frees a list, calling a function on each element before doing so.
|
||||||
|
* If list is null, no action is taken.
|
||||||
|
* DO NOT pass free as the callback. Use list_elem_free if
|
||||||
|
* you want to do that.
|
||||||
|
*/
|
||||||
|
void list_free_with(list_t *list, void callback(void *item));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is a convinience function designed to be used with
|
||||||
|
* list_free_with or list_foreach.
|
||||||
|
* It calls the stdlib free function on each element.
|
||||||
|
* We can't pass in free directly, as each pointer needs to be
|
||||||
|
* dereferenced first.
|
||||||
|
* This should only be used on lists of pointers that were
|
||||||
|
* allocated using malloc (or similar).
|
||||||
|
*/
|
||||||
|
void list_elem_free(void *item);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Adds an element at the end of the list.
|
||||||
*/
|
*/
|
||||||
void list_add(list_t *list, const void *data);
|
void list_add(list_t *list, const void *data);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Adds an uninitialized element at the end of the list,
|
||||||
|
* and returns a pointer to it.
|
||||||
|
*/
|
||||||
|
void *list_alloc(list_t *list);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Deletes the last element of the list.
|
||||||
|
* If the list is empty, no action is taken.
|
||||||
|
*/
|
||||||
|
void list_remove(list_t *list);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adds an element at an arbitrary position in the list, moving
|
* Adds an element at an arbitrary position in the list, moving
|
||||||
* the elements past index to make space.
|
* the elements past index to make space.
|
||||||
|
|
|
||||||
|
|
@ -344,7 +344,7 @@ char *do_var_replacement(char *str);
|
||||||
|
|
||||||
struct cmd_results *check_security_config();
|
struct cmd_results *check_security_config();
|
||||||
|
|
||||||
int input_identifier_cmp(const void *item, const void *data);
|
int input_identifier_cmp(const void *key, const void *item);
|
||||||
void merge_input_config(struct input_config *dst, struct input_config *src);
|
void merge_input_config(struct input_config *dst, struct input_config *src);
|
||||||
void apply_input_config(struct input_config *ic, struct libinput_device *dev);
|
void apply_input_config(struct input_config *ic, struct libinput_device *dev);
|
||||||
void free_input_config(struct input_config *ic);
|
void free_input_config(struct input_config *ic);
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ struct criteria {
|
||||||
char *cmdlist;
|
char *cmdlist;
|
||||||
};
|
};
|
||||||
|
|
||||||
int criteria_cmp(const void *item, const void *data);
|
int criteria_cmp(const void *key, const void *item);
|
||||||
void free_criteria(struct criteria *crit);
|
void free_criteria(struct criteria *crit);
|
||||||
|
|
||||||
// Pouplate list with crit_tokens extracted from criteria string, returns error
|
// Pouplate list with crit_tokens extracted from criteria string, returns error
|
||||||
|
|
@ -39,4 +39,6 @@ list_t *container_for(list_t *tokens);
|
||||||
// Returns true if any criteria in the given list matches this container
|
// Returns true if any criteria in the given list matches this container
|
||||||
bool criteria_any(swayc_t *cont, list_t *criteria);
|
bool criteria_any(swayc_t *cont, list_t *criteria);
|
||||||
|
|
||||||
|
struct crit_token;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ void add_child(swayc_t *parent, swayc_t *child);
|
||||||
|
|
||||||
// Adds child to parent at index, if parent has no focus, it is set to child
|
// Adds child to parent at index, if parent has no focus, it is set to child
|
||||||
// parent must be of type C_WORKSPACE or C_CONTAINER
|
// parent must be of type C_WORKSPACE or C_CONTAINER
|
||||||
void insert_child(swayc_t *parent, swayc_t *child, int index);
|
void insert_child(swayc_t *parent, swayc_t *child, size_t index);
|
||||||
|
|
||||||
// Adds child as floating window to ws, if there is no focus it is set to child.
|
// Adds child as floating window to ws, if there is no focus it is set to child.
|
||||||
// ws must be of type C_WORKSPACE
|
// ws must be of type C_WORKSPACE
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ static void render_title_bar(swayc_t *view, cairo_t *cr, struct wlc_geometry *b,
|
||||||
int total_len = 0;
|
int total_len = 0;
|
||||||
|
|
||||||
for(int i = view->marks->length - 1; i >= 0; --i) {
|
for(int i = view->marks->length - 1; i >= 0; --i) {
|
||||||
char *mark = (char *)view->marks->items[i];
|
char *mark = *(char **)list_get(view->marks, i);
|
||||||
if (*mark != '_') {
|
if (*mark != '_') {
|
||||||
int width, height;
|
int width, height;
|
||||||
get_text_size(cr, config->font, &width, &height, 1, false, "[%s]", mark);
|
get_text_size(cr, config->font, &width, &height, 1, false, "[%s]", mark);
|
||||||
|
|
@ -271,10 +271,9 @@ static char *generate_container_title(swayc_t *container) {
|
||||||
}
|
}
|
||||||
snprintf(name, len, "sway: %c[", layout);
|
snprintf(name, len, "sway: %c[", layout);
|
||||||
|
|
||||||
int i;
|
for (size_t i = 0; i < container->children->length; ++i) {
|
||||||
for (i = 0; i < container->children->length; ++i) {
|
|
||||||
prev_name = name;
|
prev_name = name;
|
||||||
swayc_t* child = container->children->items[i];
|
swayc_t* child = *(swayc_t **)list_get(container->children, i);
|
||||||
const char *title = NULL;
|
const char *title = NULL;
|
||||||
if (child->type == C_VIEW) {
|
if (child->type == C_VIEW) {
|
||||||
title = child->app_id ? child->app_id :
|
title = child->app_id ? child->app_id :
|
||||||
|
|
@ -330,9 +329,8 @@ void update_tabbed_stacked_titlebars(swayc_t *c, cairo_t *cr, struct wlc_geometr
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
for (size_t i = 0; i < c->children->length; ++i) {
|
||||||
for (i = 0; i < c->children->length; ++i) {
|
swayc_t *child = *(swayc_t **)list_get(c->children, i);
|
||||||
swayc_t *child = c->children->items[i];
|
|
||||||
update_tabbed_stacked_titlebars(child, cr, g, focused, focused_inactive);
|
update_tabbed_stacked_titlebars(child, cr, g, focused, focused_inactive);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -402,9 +400,8 @@ static void update_view_border(swayc_t *view) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate container titles
|
// generate container titles
|
||||||
int i;
|
for (size_t i = 0; i < p->children->length; ++i) {
|
||||||
for (i = 0; i < p->children->length; ++i) {
|
swayc_t *child = *(swayc_t **)list_get(p->children, i);
|
||||||
swayc_t *child = p->children->items[i];
|
|
||||||
if (child->type == C_CONTAINER) {
|
if (child->type == C_CONTAINER) {
|
||||||
generate_container_title(child);
|
generate_container_title(child);
|
||||||
}
|
}
|
||||||
|
|
@ -471,8 +468,9 @@ void update_container_border(swayc_t *container) {
|
||||||
update_view_border(container);
|
update_view_border(container);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < container->children->length; ++i) {
|
for (size_t i = 0; i < container->children->length; ++i) {
|
||||||
update_container_border(container->children->items[i]);
|
swayc_t *item = *(swayc_t **)list_get(container->children, i);
|
||||||
|
update_container_border(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,16 +102,15 @@ void hide_view_in_scratchpad(swayc_t *sp_view) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void input_cmd_apply(struct input_config *input) {
|
void input_cmd_apply(struct input_config *input) {
|
||||||
int i;
|
struct input_config *ic;
|
||||||
i = list_seq_find(config->input_configs, input_identifier_cmp, input->identifier);
|
ssize_t i = list_lsearch(config->input_configs, input_identifier_cmp, input->identifier, &ic);
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
// merge existing config
|
// merge existing config
|
||||||
struct input_config *ic = config->input_configs->items[i];
|
|
||||||
merge_input_config(ic, input);
|
merge_input_config(ic, input);
|
||||||
free_input_config(input);
|
free_input_config(input);
|
||||||
input = ic;
|
input = ic;
|
||||||
} else {
|
} else {
|
||||||
list_add(config->input_configs, input);
|
list_add(config->input_configs, &input);
|
||||||
}
|
}
|
||||||
|
|
||||||
current_input_config = input;
|
current_input_config = input;
|
||||||
|
|
@ -121,8 +120,8 @@ void input_cmd_apply(struct input_config *input) {
|
||||||
// this is during startup then there will be no container and config
|
// this is during startup then there will be no container and config
|
||||||
// will be applied during normal "new input" event from wlc.
|
// will be applied during normal "new input" event from wlc.
|
||||||
struct libinput_device *device = NULL;
|
struct libinput_device *device = NULL;
|
||||||
for (int i = 0; i < input_devices->length; ++i) {
|
for (size_t i = 0; i < input_devices->length; ++i) {
|
||||||
device = input_devices->items[i];
|
device = *(struct libinput_device **)list_get(input_devices, i);
|
||||||
char* dev_identifier = libinput_dev_unique_id(device);
|
char* dev_identifier = libinput_dev_unique_id(device);
|
||||||
if (!dev_identifier) {
|
if (!dev_identifier) {
|
||||||
break;
|
break;
|
||||||
|
|
@ -138,15 +137,15 @@ void input_cmd_apply(struct input_config *input) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove_view_from_scratchpad(swayc_t *view) {
|
void remove_view_from_scratchpad(swayc_t *view) {
|
||||||
int i;
|
for (size_t i = 0; i < scratchpad->length; i++) {
|
||||||
for (i = 0; i < scratchpad->length; i++) {
|
swayc_t *item = *(swayc_t **)list_get(scratchpad, i);
|
||||||
if (scratchpad->items[i] == view) {
|
if (item == view) {
|
||||||
if (sp_index == 0) {
|
if (sp_index == 0) {
|
||||||
sp_index = scratchpad->length - 1;
|
sp_index = scratchpad->length - 1;
|
||||||
} else {
|
} else {
|
||||||
sp_index--;
|
sp_index--;
|
||||||
}
|
}
|
||||||
list_del(scratchpad, sp_index);
|
list_delete(scratchpad, sp_index);
|
||||||
sp_view = NULL;
|
sp_view = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -384,7 +383,7 @@ struct cmd_results *handle_command(char *_exec, enum command_context context) {
|
||||||
char *criteria_string = argsep(&head, "]");
|
char *criteria_string = argsep(&head, "]");
|
||||||
if (head) {
|
if (head) {
|
||||||
++head;
|
++head;
|
||||||
list_t *tokens = create_list();
|
list_t *tokens = list_new(sizeof(struct crit_token *), 0);
|
||||||
char *error;
|
char *error;
|
||||||
|
|
||||||
if ((error = extract_crit_tokens(tokens, criteria_string))) {
|
if ((error = extract_crit_tokens(tokens, criteria_string))) {
|
||||||
|
|
@ -448,14 +447,14 @@ struct cmd_results *handle_command(char *_exec, enum command_context context) {
|
||||||
free_argv(argc, argv);
|
free_argv(argc, argv);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
int i = 0;
|
size_t i = 0;
|
||||||
do {
|
do {
|
||||||
if (!containers) {
|
if (!containers) {
|
||||||
current_container = get_focused_container(&root_container);
|
current_container = get_focused_container(&root_container);
|
||||||
} else if (containers->length == 0) {
|
} else if (containers->length == 0) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
current_container = (swayc_t *)containers->items[i];
|
current_container = *(swayc_t **)list_get(containers, i);
|
||||||
}
|
}
|
||||||
sway_log(L_INFO, "Running on container '%s'", current_container->name);
|
sway_log(L_INFO, "Running on container '%s'", current_container->name);
|
||||||
|
|
||||||
|
|
@ -483,7 +482,7 @@ struct cmd_results *handle_command(char *_exec, enum command_context context) {
|
||||||
cleanup:
|
cleanup:
|
||||||
free(exec);
|
free(exec);
|
||||||
if (containers) {
|
if (containers) {
|
||||||
free(containers);
|
list_free(containers);
|
||||||
}
|
}
|
||||||
if (!results) {
|
if (!results) {
|
||||||
results = cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
results = cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
|
|
@ -594,8 +593,8 @@ struct cmd_results *config_commands_command(char *exec) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct command_policy *policy = NULL;
|
struct command_policy *policy = NULL;
|
||||||
for (int i = 0; i < config->command_policies->length; ++i) {
|
for (size_t i = 0; i < config->command_policies->length; ++i) {
|
||||||
struct command_policy *p = config->command_policies->items[i];
|
struct command_policy *p = *(struct command_policy **)list_get(config->command_policies, i);
|
||||||
if (strcmp(p->command, cmd) == 0) {
|
if (strcmp(p->command, cmd) == 0) {
|
||||||
policy = p;
|
policy = p;
|
||||||
break;
|
break;
|
||||||
|
|
@ -606,7 +605,7 @@ struct cmd_results *config_commands_command(char *exec) {
|
||||||
if (!policy) {
|
if (!policy) {
|
||||||
sway_abort("Unable to allocate security policy");
|
sway_abort("Unable to allocate security policy");
|
||||||
}
|
}
|
||||||
list_add(config->command_policies, policy);
|
list_add(config->command_policies, &policy);
|
||||||
}
|
}
|
||||||
policy->context = context;
|
policy->context = context;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ struct cmd_results *cmd_assign(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
crit->crit_raw = strdup(criteria);
|
crit->crit_raw = strdup(criteria);
|
||||||
crit->cmdlist = cmdlist;
|
crit->cmdlist = cmdlist;
|
||||||
crit->tokens = create_list();
|
crit->tokens = list_new(sizeof(struct crit_token *), 0);
|
||||||
char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw);
|
char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw);
|
||||||
|
|
||||||
if (err_str) {
|
if (err_str) {
|
||||||
|
|
@ -46,12 +46,12 @@ struct cmd_results *cmd_assign(int argc, char **argv) {
|
||||||
} else if (crit->tokens->length == 0) {
|
} else if (crit->tokens->length == 0) {
|
||||||
error = cmd_results_new(CMD_INVALID, "assign", "Found no name/value pairs in criteria");
|
error = cmd_results_new(CMD_INVALID, "assign", "Found no name/value pairs in criteria");
|
||||||
free_criteria(crit);
|
free_criteria(crit);
|
||||||
} else if (list_seq_find(config->criteria, criteria_cmp, crit) != -1) {
|
} else if (list_lsearch(config->criteria, criteria_cmp, crit, NULL) != -1) {
|
||||||
sway_log(L_DEBUG, "assign: Duplicate, skipping.");
|
sway_log(L_DEBUG, "assign: Duplicate, skipping.");
|
||||||
free_criteria(crit);
|
free_criteria(crit);
|
||||||
} else {
|
} else {
|
||||||
sway_log(L_DEBUG, "assign: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist);
|
sway_log(L_DEBUG, "assign: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist);
|
||||||
list_add(config->criteria, crit);
|
list_add(config->criteria, &crit);
|
||||||
}
|
}
|
||||||
return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,13 +38,12 @@ struct cmd_results *cmd_bar(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// set bar id
|
// set bar id
|
||||||
int i;
|
for (size_t i = 0; i < config->bars->length; ++i) {
|
||||||
for (i = 0; i < config->bars->length; ++i) {
|
if (bar == *(struct bar_config **)list_get(config->bars, i)) {
|
||||||
if (bar == config->bars->items[i]) {
|
|
||||||
const int len = 5 + numlen(i); // "bar-" + i + \0
|
const int len = 5 + numlen(i); // "bar-" + i + \0
|
||||||
bar->id = malloc(len * sizeof(char));
|
bar->id = malloc(len * sizeof(char));
|
||||||
if (bar->id) {
|
if (bar->id) {
|
||||||
snprintf(bar->id, len, "bar-%d", i);
|
snprintf(bar->id, len, "bar-%zu", i);
|
||||||
} else {
|
} else {
|
||||||
return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar ID");
|
return cmd_results_new(CMD_FAILURE, "bar", "Unable to allocate bar ID");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,14 +33,14 @@ struct cmd_results *bar_cmd_bindsym(int argc, char **argv) {
|
||||||
binding->command = join_args(argv + 1, argc - 1);
|
binding->command = join_args(argv + 1, argc - 1);
|
||||||
|
|
||||||
struct bar_config *bar = config->current_bar;
|
struct bar_config *bar = config->current_bar;
|
||||||
int i = list_seq_find(bar->bindings, sway_mouse_binding_cmp_buttons, binding);
|
struct sway_mouse_binding *dup;
|
||||||
|
ssize_t i = list_lsearch(bar->bindings, sway_mouse_binding_cmp_buttons, binding, &dup);
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
sway_log(L_DEBUG, "bindsym - '%s' for swaybar already exists, overwriting", argv[0]);
|
sway_log(L_DEBUG, "bindsym - '%s' for swaybar already exists, overwriting", argv[0]);
|
||||||
struct sway_mouse_binding *dup = bar->bindings->items[i];
|
|
||||||
free_sway_mouse_binding(dup);
|
free_sway_mouse_binding(dup);
|
||||||
list_del(bar->bindings, i);
|
list_delete(bar->bindings, i);
|
||||||
}
|
}
|
||||||
list_add(bar->bindings, binding);
|
list_add(bar->bindings, &binding);
|
||||||
list_qsort(bar->bindings, sway_mouse_binding_cmp_qsort);
|
list_qsort(bar->bindings, sway_mouse_binding_cmp_qsort);
|
||||||
|
|
||||||
sway_log(L_DEBUG, "bindsym - Bound %s to command %s when clicking swaybar", argv[0], binding->command);
|
sway_log(L_DEBUG, "bindsym - Bound %s to command %s when clicking swaybar", argv[0], binding->command);
|
||||||
|
|
|
||||||
|
|
@ -58,10 +58,8 @@ struct cmd_results *bar_cmd_hidden_state(int argc, char **argv) {
|
||||||
id = argv[1];
|
id = argv[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
for (size_t i = 0; i < config->bars->length; ++i) {
|
||||||
struct bar_config *bar;
|
struct bar_config *bar = *(struct bar_config **)list_get(config->bars, i);
|
||||||
for (i = 0; i < config->bars->length; ++i) {
|
|
||||||
bar = config->bars->items[i];
|
|
||||||
if (id && strcmp(id, bar->id) == 0) {
|
if (id && strcmp(id, bar->id) == 0) {
|
||||||
return bar_set_hidden_state(bar, state);
|
return bar_set_hidden_state(bar, state);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,8 @@ struct cmd_results *bar_cmd_id(int argc, char **argv) {
|
||||||
const char *oldname = config->current_bar->id;
|
const char *oldname = config->current_bar->id;
|
||||||
|
|
||||||
// check if id is used by a previously defined bar
|
// check if id is used by a previously defined bar
|
||||||
int i;
|
for (size_t i = 0; i < config->bars->length; ++i) {
|
||||||
for (i = 0; i < config->bars->length; ++i) {
|
struct bar_config *find = *(struct bar_config **)list_get(config->bars, i);
|
||||||
struct bar_config *find = config->bars->items[i];
|
|
||||||
if (strcmp(name, find->id) == 0 && config->current_bar != find) {
|
if (strcmp(name, find->id) == 0 && config->current_bar != find) {
|
||||||
return cmd_results_new(CMD_FAILURE, "id",
|
return cmd_results_new(CMD_FAILURE, "id",
|
||||||
"Id '%s' already defined for another bar. Id unchanged (%s).",
|
"Id '%s' already defined for another bar. Id unchanged (%s).",
|
||||||
|
|
|
||||||
|
|
@ -63,10 +63,8 @@ struct cmd_results *bar_cmd_mode(int argc, char **argv) {
|
||||||
id = argv[1];
|
id = argv[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
for (size_t i = 0; i < config->bars->length; ++i) {
|
||||||
struct bar_config *bar;
|
struct bar_config *bar = *(struct bar_config **)list_get(config->bars, i);
|
||||||
for (i = 0; i < config->bars->length; ++i) {
|
|
||||||
bar = config->bars->items[i];
|
|
||||||
if (id && strcmp(id, bar->id) == 0) {
|
if (id && strcmp(id, bar->id) == 0) {
|
||||||
return bar_set_mode(bar, mode);
|
return bar_set_mode(bar, mode);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,15 @@ struct cmd_results *bar_cmd_modifier(int argc, char **argv) {
|
||||||
uint32_t mod = 0;
|
uint32_t mod = 0;
|
||||||
|
|
||||||
list_t *split = split_string(argv[0], "+");
|
list_t *split = split_string(argv[0], "+");
|
||||||
for (int i = 0; i < split->length; ++i) {
|
for (size_t i = 0; i < split->length; ++i) {
|
||||||
uint32_t tmp_mod;
|
uint32_t tmp_mod;
|
||||||
if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) {
|
char *item = *(char **)list_get(split, i);
|
||||||
|
if ((tmp_mod = get_modifier_mask_by_name(item)) > 0) {
|
||||||
mod |= tmp_mod;
|
mod |= tmp_mod;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
free_flat_list(split);
|
free_flat_list(split);
|
||||||
return cmd_results_new(CMD_INVALID, "modifier", "Unknown modifier '%s'", split->items[i]);
|
return cmd_results_new(CMD_INVALID, "modifier", "Unknown modifier '%s'", item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free_flat_list(split);
|
free_flat_list(split);
|
||||||
|
|
|
||||||
|
|
@ -17,23 +17,23 @@ struct cmd_results *bar_cmd_output(int argc, char **argv) {
|
||||||
const char *output = argv[0];
|
const char *output = argv[0];
|
||||||
list_t *outputs = config->current_bar->outputs;
|
list_t *outputs = config->current_bar->outputs;
|
||||||
if (!outputs) {
|
if (!outputs) {
|
||||||
outputs = create_list();
|
outputs = list_new(sizeof(char *), 0);
|
||||||
config->current_bar->outputs = outputs;
|
config->current_bar->outputs = outputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
|
||||||
int add_output = 1;
|
int add_output = 1;
|
||||||
if (strcmp("*", output) == 0) {
|
if (strcmp("*", output) == 0) {
|
||||||
// remove all previous defined outputs and replace with '*'
|
// remove all previous defined outputs and replace with '*'
|
||||||
for (i = 0; i < outputs->length; ++i) {
|
for (size_t i = 0; i < outputs->length; ++i) {
|
||||||
free(outputs->items[i]);
|
char *item = *(char **)list_get(outputs, i);
|
||||||
list_del(outputs, i);
|
free(item);
|
||||||
|
list_delete(outputs, i);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// only add output if not already defined with either the same
|
// only add output if not already defined with either the same
|
||||||
// name or as '*'
|
// name or as '*'
|
||||||
for (i = 0; i < outputs->length; ++i) {
|
for (size_t i = 0; i < outputs->length; ++i) {
|
||||||
const char *find = outputs->items[i];
|
const char *find = *(char **)list_get(outputs, i);
|
||||||
if (strcmp("*", find) == 0 || strcmp(output, find) == 0) {
|
if (strcmp("*", find) == 0 || strcmp(output, find) == 0) {
|
||||||
add_output = 0;
|
add_output = 0;
|
||||||
break;
|
break;
|
||||||
|
|
@ -42,7 +42,8 @@ struct cmd_results *bar_cmd_output(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (add_output) {
|
if (add_output) {
|
||||||
list_add(outputs, strdup(output));
|
char *ptr = strdup(output);
|
||||||
|
list_add(outputs, &ptr);
|
||||||
sway_log(L_DEBUG, "Adding bar: '%s' to output '%s'", config->current_bar->id, output);
|
sway_log(L_DEBUG, "Adding bar: '%s' to output '%s'", config->current_bar->id, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ struct cmd_results *cmd_bindsym(int argc, char **argv) {
|
||||||
return cmd_results_new(CMD_FAILURE, "bindsym",
|
return cmd_results_new(CMD_FAILURE, "bindsym",
|
||||||
"Unable to allocate binding");
|
"Unable to allocate binding");
|
||||||
}
|
}
|
||||||
binding->keys = create_list();
|
binding->keys = list_new(sizeof(xkb_keysym_t *), 0);
|
||||||
binding->modifiers = 0;
|
binding->modifiers = 0;
|
||||||
binding->release = false;
|
binding->release = false;
|
||||||
binding->bindcode = false;
|
binding->bindcode = false;
|
||||||
|
|
@ -44,27 +44,28 @@ struct cmd_results *cmd_bindsym(int argc, char **argv) {
|
||||||
binding->command = join_args(argv + 1, argc - 1);
|
binding->command = join_args(argv + 1, argc - 1);
|
||||||
|
|
||||||
list_t *split = split_string(argv[0], "+");
|
list_t *split = split_string(argv[0], "+");
|
||||||
for (int i = 0; i < split->length; ++i) {
|
for (size_t i = 0; i < split->length; ++i) {
|
||||||
// Check for a modifier key
|
// Check for a modifier key
|
||||||
uint32_t mod;
|
uint32_t mod;
|
||||||
if ((mod = get_modifier_mask_by_name(split->items[i])) > 0) {
|
char *item = *(char **)list_get(split, i);
|
||||||
|
if ((mod = get_modifier_mask_by_name(item)) > 0) {
|
||||||
binding->modifiers |= mod;
|
binding->modifiers |= mod;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Check for xkb key
|
// Check for xkb key
|
||||||
xkb_keysym_t sym = xkb_keysym_from_name(split->items[i],
|
xkb_keysym_t sym = xkb_keysym_from_name(item,
|
||||||
XKB_KEYSYM_CASE_INSENSITIVE);
|
XKB_KEYSYM_CASE_INSENSITIVE);
|
||||||
|
|
||||||
// Check for mouse binding
|
// Check for mouse binding
|
||||||
if (strncasecmp(split->items[i], "button", strlen("button")) == 0 &&
|
if (strncasecmp(item, "button", strlen("button")) == 0 &&
|
||||||
strlen(split->items[i]) == strlen("button0")) {
|
strlen(item) == strlen("button0")) {
|
||||||
sym = ((char *)split->items[i])[strlen("button")] - '1' + M_LEFT_CLICK;
|
sym = ((char *)item)[strlen("button")] - '1' + M_LEFT_CLICK;
|
||||||
}
|
}
|
||||||
if (!sym) {
|
if (!sym) {
|
||||||
free_sway_binding(binding);
|
free_sway_binding(binding);
|
||||||
free_flat_list(split);
|
free_flat_list(split);
|
||||||
return cmd_results_new(CMD_INVALID, "bindsym", "Unknown key '%s'",
|
return cmd_results_new(CMD_INVALID, "bindsym", "Unknown key '%s'",
|
||||||
(char *)split->items[i]);
|
item);
|
||||||
}
|
}
|
||||||
xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t));
|
xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t));
|
||||||
if (!key) {
|
if (!key) {
|
||||||
|
|
@ -74,20 +75,20 @@ struct cmd_results *cmd_bindsym(int argc, char **argv) {
|
||||||
"Unable to allocate binding");
|
"Unable to allocate binding");
|
||||||
}
|
}
|
||||||
*key = sym;
|
*key = sym;
|
||||||
list_add(binding->keys, key);
|
list_add(binding->keys, &key);
|
||||||
}
|
}
|
||||||
free_flat_list(split);
|
free_flat_list(split);
|
||||||
|
|
||||||
struct sway_mode *mode = config->current_mode;
|
struct sway_mode *mode = config->current_mode;
|
||||||
int i = list_seq_find(mode->bindings, sway_binding_cmp_keys, binding);
|
struct sway_binding *dup;
|
||||||
|
ssize_t i = list_lsearch(mode->bindings, sway_binding_cmp_keys, binding, &dup);
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
sway_log(L_DEBUG, "bindsym - '%s' already exists, overwriting", argv[0]);
|
sway_log(L_DEBUG, "bindsym - '%s' already exists, overwriting", argv[0]);
|
||||||
struct sway_binding *dup = mode->bindings->items[i];
|
|
||||||
free_sway_binding(dup);
|
free_sway_binding(dup);
|
||||||
list_del(mode->bindings, i);
|
list_delete(mode->bindings, i);
|
||||||
}
|
}
|
||||||
binding->order = binding_order++;
|
binding->order = binding_order++;
|
||||||
list_add(mode->bindings, binding);
|
list_add(mode->bindings, &binding);
|
||||||
list_qsort(mode->bindings, sway_binding_cmp_qsort);
|
list_qsort(mode->bindings, sway_binding_cmp_qsort);
|
||||||
|
|
||||||
sway_log(L_DEBUG, "bindsym - Bound %s to command %s", argv[0], binding->command);
|
sway_log(L_DEBUG, "bindsym - Bound %s to command %s", argv[0], binding->command);
|
||||||
|
|
@ -105,7 +106,7 @@ struct cmd_results *cmd_bindcode(int argc, char **argv) {
|
||||||
return cmd_results_new(CMD_FAILURE, "bindsym",
|
return cmd_results_new(CMD_FAILURE, "bindsym",
|
||||||
"Unable to allocate binding");
|
"Unable to allocate binding");
|
||||||
}
|
}
|
||||||
binding->keys = create_list();
|
binding->keys = list_new(sizeof(xkb_keycode_t *), 0);
|
||||||
binding->modifiers = 0;
|
binding->modifiers = 0;
|
||||||
binding->release = false;
|
binding->release = false;
|
||||||
binding->bindcode = true;
|
binding->bindcode = true;
|
||||||
|
|
@ -127,41 +128,42 @@ struct cmd_results *cmd_bindcode(int argc, char **argv) {
|
||||||
binding->command = join_args(argv + 1, argc - 1);
|
binding->command = join_args(argv + 1, argc - 1);
|
||||||
|
|
||||||
list_t *split = split_string(argv[0], "+");
|
list_t *split = split_string(argv[0], "+");
|
||||||
for (int i = 0; i < split->length; ++i) {
|
for (size_t i = 0; i < split->length; ++i) {
|
||||||
// Check for a modifier key
|
// Check for a modifier key
|
||||||
uint32_t mod;
|
uint32_t mod;
|
||||||
if ((mod = get_modifier_mask_by_name(split->items[i])) > 0) {
|
char *item = *(char **)list_get(split, i);
|
||||||
|
if ((mod = get_modifier_mask_by_name(item)) > 0) {
|
||||||
binding->modifiers |= mod;
|
binding->modifiers |= mod;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// parse keycode
|
// parse keycode
|
||||||
xkb_keycode_t keycode = (int)strtol(split->items[i], NULL, 10);
|
xkb_keycode_t keycode = (int)strtol(item, NULL, 10);
|
||||||
if (!xkb_keycode_is_legal_ext(keycode)) {
|
if (!xkb_keycode_is_legal_ext(keycode)) {
|
||||||
error = cmd_results_new(CMD_INVALID, "bindcode", "Invalid keycode '%s'", (char *)split->items[i]);
|
error = cmd_results_new(CMD_INVALID, "bindcode", "Invalid keycode '%s'", item);
|
||||||
free_sway_binding(binding);
|
free_sway_binding(binding);
|
||||||
list_free(split);
|
list_free(split);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
xkb_keycode_t *key = malloc(sizeof(xkb_keycode_t));
|
xkb_keycode_t *key = malloc(sizeof(xkb_keycode_t));
|
||||||
*key = keycode - 8;
|
*key = keycode - 8;
|
||||||
list_add(binding->keys, key);
|
list_add(binding->keys, &key);
|
||||||
}
|
}
|
||||||
free_flat_list(split);
|
free_flat_list(split);
|
||||||
|
|
||||||
struct sway_mode *mode = config->current_mode;
|
struct sway_mode *mode = config->current_mode;
|
||||||
int i = list_seq_find(mode->bindings, sway_binding_cmp_keys, binding);
|
struct sway_binding *dup;
|
||||||
|
ssize_t i = list_lsearch(mode->bindings, sway_binding_cmp_keys, binding, &dup);
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
struct sway_binding *dup = mode->bindings->items[i];
|
|
||||||
if (dup->bindcode) {
|
if (dup->bindcode) {
|
||||||
sway_log(L_DEBUG, "bindcode - '%s' already exists, overwriting", argv[0]);
|
sway_log(L_DEBUG, "bindcode - '%s' already exists, overwriting", argv[0]);
|
||||||
} else {
|
} else {
|
||||||
sway_log(L_DEBUG, "bindcode - '%s' already exists as bindsym, overwriting", argv[0]);
|
sway_log(L_DEBUG, "bindcode - '%s' already exists as bindsym, overwriting", argv[0]);
|
||||||
}
|
}
|
||||||
free_sway_binding(dup);
|
free_sway_binding(dup);
|
||||||
list_del(mode->bindings, i);
|
list_delete(mode->bindings, i);
|
||||||
}
|
}
|
||||||
binding->order = binding_order++;
|
binding->order = binding_order++;
|
||||||
list_add(mode->bindings, binding);
|
list_add(mode->bindings, &binding);
|
||||||
list_qsort(mode->bindings, sway_binding_cmp_qsort);
|
list_qsort(mode->bindings, sway_binding_cmp_qsort);
|
||||||
|
|
||||||
sway_log(L_DEBUG, "bindcode - Bound %s to command %s", argv[0], binding->command);
|
sway_log(L_DEBUG, "bindcode - Bound %s to command %s", argv[0], binding->command);
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,12 @@ struct cmd_results *cmd_floating_mod(int argc, char **argv) {
|
||||||
if ((error = checkarg(argc, "floating_modifier", EXPECTED_AT_LEAST, 1))) {
|
if ((error = checkarg(argc, "floating_modifier", EXPECTED_AT_LEAST, 1))) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
int i;
|
|
||||||
list_t *split = split_string(argv[0], "+");
|
list_t *split = split_string(argv[0], "+");
|
||||||
config->floating_mod = 0;
|
config->floating_mod = 0;
|
||||||
|
|
||||||
// set modifier keys
|
// set modifier keys
|
||||||
for (i = 0; i < split->length; ++i) {
|
for (size_t i = 0; i < split->length; ++i) {
|
||||||
config->floating_mod |= get_modifier_mask_by_name(split->items[i]);
|
config->floating_mod |= get_modifier_mask_by_name(*(char **)list_get(split, i));
|
||||||
}
|
}
|
||||||
free_flat_list(split);
|
free_flat_list(split);
|
||||||
if (!config->floating_mod) {
|
if (!config->floating_mod) {
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,8 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
|
||||||
} else if ((error = checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1))) {
|
} else if ((error = checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1))) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
static int floating_toggled_index = 0;
|
static size_t floating_toggled_index = 0;
|
||||||
static int tiled_toggled_index = 0;
|
static size_t tiled_toggled_index = 0;
|
||||||
if (strcasecmp(argv[0], "left") == 0) {
|
if (strcasecmp(argv[0], "left") == 0) {
|
||||||
move_focus(MOVE_LEFT);
|
move_focus(MOVE_LEFT);
|
||||||
} else if (strcasecmp(argv[0], "right") == 0) {
|
} else if (strcasecmp(argv[0], "right") == 0) {
|
||||||
|
|
@ -55,37 +55,40 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
|
||||||
} else if (strcasecmp(argv[0], "prev") == 0) {
|
} else if (strcasecmp(argv[0], "prev") == 0) {
|
||||||
move_focus(MOVE_PREV);
|
move_focus(MOVE_PREV);
|
||||||
} else if (strcasecmp(argv[0], "mode_toggle") == 0) {
|
} else if (strcasecmp(argv[0], "mode_toggle") == 0) {
|
||||||
int i;
|
|
||||||
swayc_t *workspace = swayc_active_workspace();
|
swayc_t *workspace = swayc_active_workspace();
|
||||||
swayc_t *focused = get_focused_view(workspace);
|
swayc_t *focused = get_focused_view(workspace);
|
||||||
if (focused->is_floating) {
|
if (focused->is_floating) {
|
||||||
if (workspace->children->length > 0) {
|
if (workspace->children->length > 0) {
|
||||||
for (i = 0;i < workspace->floating->length; i++) {
|
for (size_t i = 0;i < workspace->floating->length; i++) {
|
||||||
if (workspace->floating->items[i] == focused) {
|
swayc_t *item = *(swayc_t **)list_get(workspace->floating, i);
|
||||||
|
if (item == focused) {
|
||||||
floating_toggled_index = i;
|
floating_toggled_index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (workspace->children->length > tiled_toggled_index) {
|
if (workspace->children->length > tiled_toggled_index) {
|
||||||
set_focused_container(get_focused_view(workspace->children->items[tiled_toggled_index]));
|
swayc_t *item = *(swayc_t **)list_get(workspace->children, tiled_toggled_index);
|
||||||
|
set_focused_container(get_focused_view(item));
|
||||||
} else {
|
} else {
|
||||||
set_focused_container(get_focused_view(workspace->children->items[0]));
|
swayc_t *item = *(swayc_t **)list_get(workspace->children, 0);
|
||||||
|
set_focused_container(get_focused_view(item));
|
||||||
tiled_toggled_index = 0;
|
tiled_toggled_index = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (workspace->floating->length > 0) {
|
if (workspace->floating->length > 0) {
|
||||||
for (i = 0;i < workspace->children->length; i++) {
|
for (size_t i = 0;i < workspace->children->length; i++) {
|
||||||
if (workspace->children->items[i] == focused) {
|
swayc_t *item = *(swayc_t **)list_get(workspace->children, i);
|
||||||
|
if (item == focused) {
|
||||||
tiled_toggled_index = i;
|
tiled_toggled_index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (workspace->floating->length > floating_toggled_index) {
|
if (workspace->floating->length > floating_toggled_index) {
|
||||||
swayc_t *floating = workspace->floating->items[floating_toggled_index];
|
swayc_t *floating = *(swayc_t **)list_get(workspace->floating, floating_toggled_index);
|
||||||
set_focused_container(get_focused_view(floating));
|
set_focused_container(get_focused_view(floating));
|
||||||
} else {
|
} else {
|
||||||
swayc_t *floating = workspace->floating->items[workspace->floating->length - 1];
|
swayc_t *floating = *(swayc_t **)list_get(workspace->floating, workspace->floating->length - 1);
|
||||||
set_focused_container(get_focused_view(floating));
|
set_focused_container(get_focused_view(floating));
|
||||||
tiled_toggled_index = workspace->floating->length - 1;
|
tiled_toggled_index = workspace->floating->length - 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ struct cmd_results *cmd_for_window(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
crit->crit_raw = strdup(criteria);
|
crit->crit_raw = strdup(criteria);
|
||||||
crit->cmdlist = cmdlist;
|
crit->cmdlist = cmdlist;
|
||||||
crit->tokens = create_list();
|
crit->tokens = list_new(sizeof(struct crit_token *), 0);
|
||||||
char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw);
|
char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw);
|
||||||
|
|
||||||
if (err_str) {
|
if (err_str) {
|
||||||
|
|
@ -30,12 +30,12 @@ struct cmd_results *cmd_for_window(int argc, char **argv) {
|
||||||
} else if (crit->tokens->length == 0) {
|
} else if (crit->tokens->length == 0) {
|
||||||
error = cmd_results_new(CMD_INVALID, "for_window", "Found no name/value pairs in criteria");
|
error = cmd_results_new(CMD_INVALID, "for_window", "Found no name/value pairs in criteria");
|
||||||
free_criteria(crit);
|
free_criteria(crit);
|
||||||
} else if (list_seq_find(config->criteria, criteria_cmp, crit) != -1) {
|
} else if (list_lsearch(config->criteria, criteria_cmp, crit, NULL) != -1) {
|
||||||
sway_log(L_DEBUG, "for_window: Duplicate, skipping.");
|
sway_log(L_DEBUG, "for_window: Duplicate, skipping.");
|
||||||
free_criteria(crit);
|
free_criteria(crit);
|
||||||
} else {
|
} else {
|
||||||
sway_log(L_DEBUG, "for_window: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist);
|
sway_log(L_DEBUG, "for_window: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist);
|
||||||
list_add(config->criteria, crit);
|
list_add(config->criteria, &crit);
|
||||||
}
|
}
|
||||||
return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -133,11 +133,10 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
|
||||||
arrange_windows(cont->parent, -1, -1);
|
arrange_windows(cont->parent, -1, -1);
|
||||||
} else if (inout == OUTER) {
|
} else if (inout == OUTER) {
|
||||||
//resize all workspace.
|
//resize all workspace.
|
||||||
int i,j;
|
for (size_t i = 0; i < root_container.children->length; ++i) {
|
||||||
for (i = 0; i < root_container.children->length; ++i) {
|
swayc_t *op = *(swayc_t **)list_get(root_container.children, i);
|
||||||
swayc_t *op = root_container.children->items[i];
|
for (size_t j = 0; j < op->children->length; ++j) {
|
||||||
for (j = 0; j < op->children->length; ++j) {
|
swayc_t *ws = *(swayc_t **)list_get(op->children, j);
|
||||||
swayc_t *ws = op->children->items[j];
|
|
||||||
if (method == SET) {
|
if (method == SET) {
|
||||||
ws->gaps = amount;
|
ws->gaps = amount;
|
||||||
} else if ((ws->gaps += amount) < 0) {
|
} else if ((ws->gaps += amount) < 0) {
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ struct cmd_results *cmd_ipc(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
current_policy = alloc_ipc_policy(program);
|
current_policy = alloc_ipc_policy(program);
|
||||||
list_add(config->ipc_policies, current_policy);
|
list_add(config->ipc_policies, ¤t_policy);
|
||||||
|
|
||||||
free(program);
|
free(program);
|
||||||
return cmd_results_new(CMD_BLOCK_IPC, NULL, NULL);
|
return cmd_results_new(CMD_BLOCK_IPC, NULL, NULL);
|
||||||
|
|
|
||||||
|
|
@ -154,10 +154,11 @@ static struct cmd_results *cmd_layout_auto(swayc_t *container, int argc, char **
|
||||||
}
|
}
|
||||||
if (inc) {
|
if (inc) {
|
||||||
for (int i = container->nb_master;
|
for (int i = container->nb_master;
|
||||||
i >= 0 && i < container->children->length
|
i >= 0 && (size_t)i < container->children->length
|
||||||
&& i != (int)container->nb_master + inc;) {
|
&& i != (int)container->nb_master + inc;) {
|
||||||
((swayc_t *)container->children->items[i])->height = -1;
|
swayc_t *item = *(swayc_t **)list_get(container->children, i);
|
||||||
((swayc_t *)container->children->items[i])->width = -1;
|
item->height = -1;
|
||||||
|
item->width = -1;
|
||||||
i += inc > 0 ? 1 : -1;
|
i += inc > 0 ? 1 : -1;
|
||||||
}
|
}
|
||||||
container->nb_master += inc;
|
container->nb_master += inc;
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,13 @@
|
||||||
static void find_marks_callback(swayc_t *container, void *_mark) {
|
static void find_marks_callback(swayc_t *container, void *_mark) {
|
||||||
char *mark = (char *)_mark;
|
char *mark = (char *)_mark;
|
||||||
|
|
||||||
int index;
|
if (!container->marks) {
|
||||||
if (container->marks && ((index = list_seq_find(container->marks, (int (*)(const void *, const void *))strcmp, mark)) != -1)) {
|
return;
|
||||||
list_del(container->marks, index);
|
}
|
||||||
|
|
||||||
|
ssize_t index = list_lsearch(container->marks, (int (*)(const void *, const void *))strcmp, mark, NULL);
|
||||||
|
if (index != -1) {
|
||||||
|
list_delete(container->marks, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,11 +49,12 @@ struct cmd_results *cmd_mark(int argc, char **argv) {
|
||||||
|
|
||||||
if (view->marks) {
|
if (view->marks) {
|
||||||
if (add) {
|
if (add) {
|
||||||
int index;
|
ssize_t index;
|
||||||
if ((index = list_seq_find(view->marks, (int (*)(const void *, const void *))strcmp, mark)) != -1) {
|
char *item;
|
||||||
|
if ((index = list_lsearch(view->marks, (int (*)(const void *, const void *))strcmp, mark, &item)) != -1) {
|
||||||
if (toggle) {
|
if (toggle) {
|
||||||
free(view->marks->items[index]);
|
free(item);
|
||||||
list_del(view->marks, index);
|
list_delete(view->marks, index);
|
||||||
|
|
||||||
if (0 == view->marks->length) {
|
if (0 == view->marks->length) {
|
||||||
list_free(view->marks);
|
list_free(view->marks);
|
||||||
|
|
@ -58,26 +63,26 @@ struct cmd_results *cmd_mark(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
free(mark);
|
free(mark);
|
||||||
} else {
|
} else {
|
||||||
list_add(view->marks, mark);
|
list_add(view->marks, &mark);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (toggle && list_seq_find(view->marks, (int (*)(const void *, const void *))strcmp, mark) != -1) {
|
if (toggle && list_lsearch(view->marks, (int (*)(const void *, const void *))strcmp, mark, NULL) != -1) {
|
||||||
// Delete the list
|
// Delete the list
|
||||||
list_foreach(view->marks, free);
|
list_foreach(view->marks, list_elem_free);
|
||||||
list_free(view->marks);
|
list_free(view->marks);
|
||||||
view->marks = NULL;
|
view->marks = NULL;
|
||||||
} else {
|
} else {
|
||||||
// Delete and replace with a new list
|
// Delete and replace with a new list
|
||||||
list_foreach(view->marks, free);
|
list_foreach(view->marks, list_elem_free);
|
||||||
list_free(view->marks);
|
list_free(view->marks);
|
||||||
|
|
||||||
view->marks = create_list();
|
view->marks = list_new(sizeof(char *), 0);
|
||||||
list_add(view->marks, mark);
|
list_add(view->marks, &mark);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
view->marks = create_list();
|
view->marks = list_new(sizeof(char *), 0);
|
||||||
list_add(view->marks, mark);
|
list_add(view->marks, &mark);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return cmd_results_new(CMD_FAILURE, "mark",
|
return cmd_results_new(CMD_FAILURE, "mark",
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,8 @@ struct cmd_results *cmd_mode(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
struct sway_mode *mode = NULL;
|
struct sway_mode *mode = NULL;
|
||||||
// Find mode
|
// Find mode
|
||||||
int i, len = config->modes->length;
|
for (size_t i = 0; i < config->modes->length; ++i) {
|
||||||
for (i = 0; i < len; ++i) {
|
struct sway_mode *find = *(struct sway_mode **)list_get(config->modes, i);
|
||||||
struct sway_mode *find = config->modes->items[i];
|
|
||||||
if (strcasecmp(find->name, mode_name) == 0) {
|
if (strcasecmp(find->name, mode_name) == 0) {
|
||||||
mode = find;
|
mode = find;
|
||||||
break;
|
break;
|
||||||
|
|
@ -37,8 +36,8 @@ struct cmd_results *cmd_mode(int argc, char **argv) {
|
||||||
return cmd_results_new(CMD_FAILURE, "mode", "Unable to allocate mode");
|
return cmd_results_new(CMD_FAILURE, "mode", "Unable to allocate mode");
|
||||||
}
|
}
|
||||||
mode->name = strdup(mode_name);
|
mode->name = strdup(mode_name);
|
||||||
mode->bindings = create_list();
|
mode->bindings = list_new(sizeof(struct sway_mode *), 0);
|
||||||
list_add(config->modes, mode);
|
list_add(config->modes, &mode);
|
||||||
}
|
}
|
||||||
if (!mode) {
|
if (!mode) {
|
||||||
error = cmd_results_new(CMD_INVALID, "mode", "Unknown mode `%s'", mode_name);
|
error = cmd_results_new(CMD_INVALID, "mode", "Unknown mode `%s'", mode_name);
|
||||||
|
|
|
||||||
|
|
@ -126,15 +126,15 @@ struct cmd_results *cmd_move(int argc, char **argv) {
|
||||||
return cmd_results_new(CMD_FAILURE, "move scratchpad", "Can only move containers and views.");
|
return cmd_results_new(CMD_FAILURE, "move scratchpad", "Can only move containers and views.");
|
||||||
}
|
}
|
||||||
swayc_t *view = current_container;
|
swayc_t *view = current_container;
|
||||||
int i;
|
for (size_t i = 0; i < scratchpad->length; i++) {
|
||||||
for (i = 0; i < scratchpad->length; i++) {
|
swayc_t *item = *(swayc_t **)list_get(scratchpad, i);
|
||||||
if (scratchpad->items[i] == view) {
|
if (item == view) {
|
||||||
hide_view_in_scratchpad(view);
|
hide_view_in_scratchpad(view);
|
||||||
sp_view = NULL;
|
sp_view = NULL;
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
list_add(scratchpad, view);
|
list_add(scratchpad, &view);
|
||||||
if (!view->is_floating) {
|
if (!view->is_floating) {
|
||||||
destroy_container(remove_child(view));
|
destroy_container(remove_child(view));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ struct cmd_results *cmd_no_focus(int argc, char **argv) {
|
||||||
return cmd_results_new(CMD_FAILURE, "no_focus", "Unable to allocate criteria");
|
return cmd_results_new(CMD_FAILURE, "no_focus", "Unable to allocate criteria");
|
||||||
}
|
}
|
||||||
crit->crit_raw = strdup(criteria);
|
crit->crit_raw = strdup(criteria);
|
||||||
crit->tokens = create_list();
|
crit->tokens = list_new(sizeof(struct crit_token *), 0);
|
||||||
crit->cmdlist = NULL;
|
crit->cmdlist = NULL;
|
||||||
char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw);
|
char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw);
|
||||||
|
|
||||||
|
|
@ -30,12 +30,12 @@ struct cmd_results *cmd_no_focus(int argc, char **argv) {
|
||||||
} else if (crit->tokens->length == 0) {
|
} else if (crit->tokens->length == 0) {
|
||||||
error = cmd_results_new(CMD_INVALID, "no_focus", "Found no name/value pairs in criteria");
|
error = cmd_results_new(CMD_INVALID, "no_focus", "Found no name/value pairs in criteria");
|
||||||
free_criteria(crit);
|
free_criteria(crit);
|
||||||
} else if (list_seq_find(config->no_focus, criteria_cmp, crit) != -1) {
|
} else if (list_lsearch(config->no_focus, criteria_cmp, crit, NULL) != -1) {
|
||||||
sway_log(L_DEBUG, "no_focus: Duplicate, skipping.");
|
sway_log(L_DEBUG, "no_focus: Duplicate, skipping.");
|
||||||
free_criteria(crit);
|
free_criteria(crit);
|
||||||
} else {
|
} else {
|
||||||
sway_log(L_DEBUG, "no_focus: '%s' added", crit->crit_raw);
|
sway_log(L_DEBUG, "no_focus: '%s' added", crit->crit_raw);
|
||||||
list_add(config->no_focus, crit);
|
list_add(config->no_focus, &crit);
|
||||||
}
|
}
|
||||||
return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,7 @@ struct cmd_results *cmd_output(int argc, char **argv) {
|
||||||
|
|
||||||
// TODO: atoi doesn't handle invalid numbers
|
// TODO: atoi doesn't handle invalid numbers
|
||||||
|
|
||||||
int i;
|
for (int i = 1; i < argc; ++i) {
|
||||||
for (i = 1; i < argc; ++i) {
|
|
||||||
const char *command = argv[i];
|
const char *command = argv[i];
|
||||||
|
|
||||||
if (strcasecmp(command, "disable") == 0) {
|
if (strcasecmp(command, "disable") == 0) {
|
||||||
|
|
@ -157,15 +156,15 @@ struct cmd_results *cmd_output(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i = list_seq_find(config->output_configs, output_name_cmp, name);
|
struct output_config *oc;
|
||||||
|
ssize_t i = list_lsearch(config->output_configs, output_name_cmp, name, &oc);
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
// merge existing config
|
// merge existing config
|
||||||
struct output_config *oc = config->output_configs->items[i];
|
|
||||||
merge_output_config(oc, output);
|
merge_output_config(oc, output);
|
||||||
free_output_config(output);
|
free_output_config(output);
|
||||||
output = oc;
|
output = oc;
|
||||||
} else {
|
} else {
|
||||||
list_add(config->output_configs, output);
|
list_add(config->output_configs, &output);
|
||||||
}
|
}
|
||||||
|
|
||||||
sway_log(L_DEBUG, "Config stored for output %s (enabled:%d) (%d x %d @ %d, %d scale %d) (bg %s %s)",
|
sway_log(L_DEBUG, "Config stored for output %s (enabled:%d) (%d x %d @ %d, %d scale %d) (bg %s %s)",
|
||||||
|
|
@ -178,8 +177,8 @@ struct cmd_results *cmd_output(int argc, char **argv) {
|
||||||
// this is during startup then there will be no container and config
|
// this is during startup then there will be no container and config
|
||||||
// will be applied during normal "new output" event from wlc.
|
// will be applied during normal "new output" event from wlc.
|
||||||
swayc_t *cont = NULL;
|
swayc_t *cont = NULL;
|
||||||
for (int i = 0; i < root_container.children->length; ++i) {
|
for (size_t i = 0; i < root_container.children->length; ++i) {
|
||||||
cont = root_container.children->items[i];
|
cont = *(swayc_t **)list_get(root_container.children, i);
|
||||||
if (cont->name && ((strcmp(cont->name, output->name) == 0) || (strcmp(output->name, "*") == 0))) {
|
if (cont->name && ((strcmp(cont->name, output->name) == 0) || (strcmp(output->name, "*") == 0))) {
|
||||||
apply_output_config(output, cont);
|
apply_output_config(output, cont);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -118,12 +118,12 @@ static bool resize_tiled(int amount, bool use_width) {
|
||||||
// 2. Ensure that the resize operation will not make one of the resized containers drop
|
// 2. Ensure that the resize operation will not make one of the resized containers drop
|
||||||
// below the "sane" size threshold.
|
// below the "sane" size threshold.
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
swayc_t *focused = parent->children->items[idx_focused];
|
swayc_t *focused = *(swayc_t **)list_get(parent->children, idx_focused);
|
||||||
int start = use_major ? 0 : auto_group_start_index(parent, idx_focused);
|
size_t start = use_major ? 0 : (size_t)auto_group_start_index(parent, idx_focused);
|
||||||
int end = use_major ? parent->children->length : auto_group_end_index(parent, idx_focused);
|
size_t end = use_major ? parent->children->length : (size_t)auto_group_end_index(parent, idx_focused);
|
||||||
sway_log(L_DEBUG, "Check children of container %p [%d,%d[", container, start, end);
|
sway_log(L_DEBUG, "Check children of container %p [%zu,%zu[", container, start, end);
|
||||||
for (int i = start; i < end; ) {
|
for (size_t i = start; i < end; ) {
|
||||||
swayc_t *sibling = parent->children->items[i];
|
swayc_t *sibling = *(swayc_t **)list_get(parent->children, i);
|
||||||
double pixels = amount;
|
double pixels = amount;
|
||||||
bool is_before = use_width ? sibling->x < focused->x : sibling->y < focused->y;
|
bool is_before = use_width ? sibling->x < focused->x : sibling->y < focused->y;
|
||||||
bool is_after = use_width ? sibling->x > focused->x : sibling->y > focused->y;
|
bool is_after = use_width ? sibling->x > focused->x : sibling->y > focused->y;
|
||||||
|
|
@ -142,14 +142,14 @@ static bool resize_tiled(int amount, bool use_width) {
|
||||||
sway_log(L_DEBUG, "Container size no longer sane");
|
sway_log(L_DEBUG, "Container size no longer sane");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i = use_major ? auto_group_end_index(parent, i) : (i + 1);
|
i = use_major ? (size_t)auto_group_end_index(parent, i) : (i + 1);
|
||||||
sway_log(L_DEBUG, "+++++ check %i", i);
|
sway_log(L_DEBUG, "+++++ check %zu", i);
|
||||||
}
|
}
|
||||||
// 3. Apply the size change
|
// 3. Apply the size change
|
||||||
if (valid) {
|
if (valid) {
|
||||||
for (int i = start; i < end; ) {
|
for (size_t i = start; i < end; ) {
|
||||||
int next_i = use_major ? auto_group_end_index(parent, i) : (i + 1);
|
int next_i = use_major ? (size_t)auto_group_end_index(parent, i) : (i + 1);
|
||||||
swayc_t *sibling = parent->children->items[i];
|
swayc_t *sibling = *(swayc_t **)list_get(parent->children, i);
|
||||||
double pixels = amount;
|
double pixels = amount;
|
||||||
bool is_before = use_width ? sibling->x < focused->x : sibling->y < focused->y;
|
bool is_before = use_width ? sibling->x < focused->x : sibling->y < focused->y;
|
||||||
bool is_after = use_width ? sibling->x > focused->x : sibling->y > focused->y;
|
bool is_after = use_width ? sibling->x > focused->x : sibling->y > focused->y;
|
||||||
|
|
@ -162,7 +162,8 @@ static bool resize_tiled(int amount, bool use_width) {
|
||||||
sway_log(L_DEBUG, "%p: %s", sibling, is_before ? "before" : "after");
|
sway_log(L_DEBUG, "%p: %s", sibling, is_before ? "before" : "after");
|
||||||
if (use_major) {
|
if (use_major) {
|
||||||
for (int j = i; j < next_i; ++j) {
|
for (int j = i; j < next_i; ++j) {
|
||||||
recursive_resize(parent->children->items[j], pixels,
|
swayc_t *item = *(swayc_t **)list_get(parent->children, j);
|
||||||
|
recursive_resize(item, pixels,
|
||||||
use_width ?
|
use_width ?
|
||||||
(is_before ? WLC_RESIZE_EDGE_RIGHT : WLC_RESIZE_EDGE_LEFT) :
|
(is_before ? WLC_RESIZE_EDGE_RIGHT : WLC_RESIZE_EDGE_LEFT) :
|
||||||
(is_before ? WLC_RESIZE_EDGE_BOTTOM : WLC_RESIZE_EDGE_TOP));
|
(is_before ? WLC_RESIZE_EDGE_BOTTOM : WLC_RESIZE_EDGE_TOP));
|
||||||
|
|
@ -176,9 +177,10 @@ static bool resize_tiled(int amount, bool use_width) {
|
||||||
} else {
|
} else {
|
||||||
if (use_major) {
|
if (use_major) {
|
||||||
for (int j = i; j < next_i; ++j) {
|
for (int j = i; j < next_i; ++j) {
|
||||||
recursive_resize(parent->children->items[j], pixels / 2,
|
swayc_t *item = *(swayc_t **)list_get(parent->children, j);
|
||||||
|
recursive_resize(item, pixels / 2,
|
||||||
use_width ? WLC_RESIZE_EDGE_LEFT : WLC_RESIZE_EDGE_TOP);
|
use_width ? WLC_RESIZE_EDGE_LEFT : WLC_RESIZE_EDGE_TOP);
|
||||||
recursive_resize(parent->children->items[j], pixels / 2,
|
recursive_resize(item, pixels / 2,
|
||||||
use_width ? WLC_RESIZE_EDGE_RIGHT : WLC_RESIZE_EDGE_BOTTOM);
|
use_width ? WLC_RESIZE_EDGE_RIGHT : WLC_RESIZE_EDGE_BOTTOM);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@
|
||||||
#include "sway/layout.h"
|
#include "sway/layout.h"
|
||||||
|
|
||||||
static swayc_t *fetch_view_from_scratchpad() {
|
static swayc_t *fetch_view_from_scratchpad() {
|
||||||
if (sp_index >= scratchpad->length) {
|
if ((size_t)sp_index >= scratchpad->length) {
|
||||||
sp_index = 0;
|
sp_index = 0;
|
||||||
}
|
}
|
||||||
swayc_t *view = scratchpad->items[sp_index++];
|
swayc_t *view = *(swayc_t **)list_get(scratchpad, sp_index++);
|
||||||
|
|
||||||
if (wlc_view_get_output(view->handle) != swayc_active_output()->handle) {
|
if (wlc_view_get_output(view->handle) != swayc_active_output()->handle) {
|
||||||
wlc_view_set_output(view->handle, swayc_active_output()->handle);
|
wlc_view_set_output(view->handle, swayc_active_output()->handle);
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,8 @@ struct cmd_results *cmd_set(int argc, char **argv) {
|
||||||
|
|
||||||
struct sway_variable *var = NULL;
|
struct sway_variable *var = NULL;
|
||||||
// Find old variable if it exists
|
// Find old variable if it exists
|
||||||
int i;
|
for (size_t i = 0; i < config->symbols->length; ++i) {
|
||||||
for (i = 0; i < config->symbols->length; ++i) {
|
var = *(struct sway_variable **)list_get(config->symbols, i);
|
||||||
var = config->symbols->items[i];
|
|
||||||
if (strcmp(var->name, argv[0]) == 0) {
|
if (strcmp(var->name, argv[0]) == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +52,7 @@ struct cmd_results *cmd_set(int argc, char **argv) {
|
||||||
return cmd_results_new(CMD_FAILURE, "set", "Unable to allocate variable");
|
return cmd_results_new(CMD_FAILURE, "set", "Unable to allocate variable");
|
||||||
}
|
}
|
||||||
var->name = strdup(argv[0]);
|
var->name = strdup(argv[0]);
|
||||||
list_add(config->symbols, var);
|
list_add(config->symbols, &var);
|
||||||
list_qsort(config->symbols, compare_set_qsort);
|
list_qsort(config->symbols, compare_set_qsort);
|
||||||
}
|
}
|
||||||
var->value = join_args(argv + 1, argc - 1);
|
var->value = join_args(argv + 1, argc - 1);
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,11 @@ struct cmd_results *cmd_unmark(int argc, char **argv) {
|
||||||
if (view->marks) {
|
if (view->marks) {
|
||||||
if (argc) {
|
if (argc) {
|
||||||
char *mark = join_args(argv, argc);
|
char *mark = join_args(argv, argc);
|
||||||
int index;
|
char *item;
|
||||||
if ((index = list_seq_find(view->marks, (int (*)(const void *, const void *))strcmp, mark)) != -1) {
|
ssize_t index;
|
||||||
free(view->marks->items[index]);
|
if ((index = list_lsearch(view->marks, (int (*)(const void *, const void *))strcmp, mark, &item)) != -1) {
|
||||||
list_del(view->marks, index);
|
free(item);
|
||||||
|
list_delete(view->marks, index);
|
||||||
|
|
||||||
if (view->marks->length == 0) {
|
if (view->marks->length == 0) {
|
||||||
list_free(view->marks);
|
list_free(view->marks);
|
||||||
|
|
@ -22,7 +23,7 @@ struct cmd_results *cmd_unmark(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
free(mark);
|
free(mark);
|
||||||
} else {
|
} else {
|
||||||
list_foreach(view->marks, free);
|
list_foreach(view->marks, list_elem_free);
|
||||||
list_free(view->marks);
|
list_free(view->marks);
|
||||||
view->marks = NULL;
|
view->marks = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,14 +34,14 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
wso->workspace = join_args(argv, argc - 2);
|
wso->workspace = join_args(argv, argc - 2);
|
||||||
wso->output = strdup(argv[output_location + 1]);
|
wso->output = strdup(argv[output_location + 1]);
|
||||||
int i = -1;
|
ssize_t i = -1;
|
||||||
if ((i = list_seq_find(config->workspace_outputs, workspace_output_cmp_workspace, wso)) != -1) {
|
struct workspace_output *old;
|
||||||
struct workspace_output *old = config->workspace_outputs->items[i];
|
if ((i = list_lsearch(config->workspace_outputs, workspace_output_cmp_workspace, wso, &old)) != -1) {
|
||||||
free(old); // workspaces can only be assigned to a single output
|
free(old); // workspaces can only be assigned to a single output
|
||||||
list_del(config->workspace_outputs, i);
|
list_delete(config->workspace_outputs, i);
|
||||||
}
|
}
|
||||||
sway_log(L_DEBUG, "Assigning workspace %s to output %s", wso->workspace, wso->output);
|
sway_log(L_DEBUG, "Assigning workspace %s to output %s", wso->workspace, wso->output);
|
||||||
list_add(config->workspace_outputs, wso);
|
list_add(config->workspace_outputs, &wso);
|
||||||
} else {
|
} else {
|
||||||
if (config->reading || !config->active) {
|
if (config->reading || !config->active) {
|
||||||
return cmd_results_new(CMD_DEFER, "workspace", NULL);
|
return cmd_results_new(CMD_DEFER, "workspace", NULL);
|
||||||
|
|
|
||||||
212
sway/config.c
212
sway/config.c
|
|
@ -55,9 +55,8 @@ static void free_mode(struct sway_mode *mode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
free(mode->name);
|
free(mode->name);
|
||||||
int i;
|
for (size_t i = 0; mode->bindings && i < mode->bindings->length; ++i) {
|
||||||
for (i = 0; mode->bindings && i < mode->bindings->length; ++i) {
|
free_binding(*(struct sway_binding **)list_get(mode->bindings, i));
|
||||||
free_binding(mode->bindings->items[i]);
|
|
||||||
}
|
}
|
||||||
list_free(mode->bindings);
|
list_free(mode->bindings);
|
||||||
free(mode);
|
free(mode);
|
||||||
|
|
@ -72,9 +71,8 @@ static void free_bar(struct bar_config *bar) {
|
||||||
free(bar->status_command);
|
free(bar->status_command);
|
||||||
free(bar->font);
|
free(bar->font);
|
||||||
free(bar->separator_symbol);
|
free(bar->separator_symbol);
|
||||||
int i;
|
for (size_t i = 0; bar->bindings && i < bar->bindings->length; ++i) {
|
||||||
for (i = 0; bar->bindings && i < bar->bindings->length; ++i) {
|
free_sway_mouse_binding(*(struct sway_mouse_binding **)list_get(bar->bindings, i));
|
||||||
free_sway_mouse_binding(bar->bindings->items[i]);
|
|
||||||
}
|
}
|
||||||
list_free(bar->bindings);
|
list_free(bar->bindings);
|
||||||
|
|
||||||
|
|
@ -144,12 +142,12 @@ static void pid_workspace_cleanup() {
|
||||||
|
|
||||||
// work backwards through list and remove any entries
|
// work backwards through list and remove any entries
|
||||||
// older than PID_WORKSPACE_TIMEOUT
|
// older than PID_WORKSPACE_TIMEOUT
|
||||||
for (int i = config->pid_workspaces->length - 1; i > -1; i--) {
|
for (ssize_t i = config->pid_workspaces->length - 1; i > -1; i--) {
|
||||||
pw = config->pid_workspaces->items[i];
|
pw = *(struct pid_workspace **)list_get(config->pid_workspaces, i);
|
||||||
|
|
||||||
if (difftime(ts.tv_sec, *pw->time_added) >= PID_WORKSPACE_TIMEOUT) {
|
if (difftime(ts.tv_sec, *pw->time_added) >= PID_WORKSPACE_TIMEOUT) {
|
||||||
free_pid_workspace(config->pid_workspaces->items[i]);
|
free_pid_workspace(pw);
|
||||||
list_del(config->pid_workspaces, i);
|
list_delete(config->pid_workspaces, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -174,16 +172,16 @@ void pid_workspace_add(struct pid_workspace *pw) {
|
||||||
|
|
||||||
// work backwards through list and delete any entries that
|
// work backwards through list and delete any entries that
|
||||||
// have the same pid as that in our new pid_workspace
|
// have the same pid as that in our new pid_workspace
|
||||||
for (int i = config->pid_workspaces->length - 1; i > -1; i--) {
|
for (ssize_t i = config->pid_workspaces->length - 1; i > -1; i--) {
|
||||||
list_pw = config->pid_workspaces->items[i];
|
list_pw = *(struct pid_workspace **)list_get(config->pid_workspaces, i);
|
||||||
|
|
||||||
if (pw->pid == list_pw->pid) {
|
if (pw->pid == list_pw->pid) {
|
||||||
free_pid_workspace(config->pid_workspaces->items[i]);
|
free_pid_workspace(list_pw);
|
||||||
list_del(config->pid_workspaces, i);
|
list_delete(config->pid_workspaces, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
list_add(config->pid_workspaces, pw);
|
list_add(config->pid_workspaces, &pw);
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_pid_workspace(struct pid_workspace *pw) {
|
void free_pid_workspace(struct pid_workspace *pw) {
|
||||||
|
|
@ -216,61 +214,61 @@ void free_config(struct sway_config *config) {
|
||||||
if (!config) {
|
if (!config) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int i;
|
size_t i;
|
||||||
for (i = 0; config->symbols && i < config->symbols->length; ++i) {
|
for (i = 0; config->symbols && i < config->symbols->length; ++i) {
|
||||||
free_variable(config->symbols->items[i]);
|
free_variable(*(struct sway_variable **)list_get(config->symbols, i));
|
||||||
}
|
}
|
||||||
list_free(config->symbols);
|
list_free(config->symbols);
|
||||||
|
|
||||||
for (i = 0; config->modes && i < config->modes->length; ++i) {
|
for (i = 0; config->modes && i < config->modes->length; ++i) {
|
||||||
free_mode(config->modes->items[i]);
|
free_mode(*(struct sway_mode **)list_get(config->modes, i));
|
||||||
}
|
}
|
||||||
list_free(config->modes);
|
list_free(config->modes);
|
||||||
|
|
||||||
for (i = 0; config->bars && i < config->bars->length; ++i) {
|
for (i = 0; config->bars && i < config->bars->length; ++i) {
|
||||||
free_bar(config->bars->items[i]);
|
free_bar(*(struct bar_config **)list_get(config->bars, i));
|
||||||
}
|
}
|
||||||
list_free(config->bars);
|
list_free(config->bars);
|
||||||
|
|
||||||
free_flat_list(config->cmd_queue);
|
free_flat_list(config->cmd_queue);
|
||||||
|
|
||||||
for (i = 0; config->workspace_outputs && i < config->workspace_outputs->length; ++i) {
|
for (i = 0; config->workspace_outputs && i < config->workspace_outputs->length; ++i) {
|
||||||
free_workspace_output(config->workspace_outputs->items[i]);
|
free_workspace_output(*(struct workspace_output **)list_get(config->workspace_outputs, i));
|
||||||
}
|
}
|
||||||
list_free(config->workspace_outputs);
|
list_free(config->workspace_outputs);
|
||||||
|
|
||||||
for (i = 0; config->pid_workspaces && i < config->pid_workspaces->length; ++i) {
|
for (i = 0; config->pid_workspaces && i < config->pid_workspaces->length; ++i) {
|
||||||
free_pid_workspace(config->pid_workspaces->items[i]);
|
free_pid_workspace(*(struct pid_workspace **)list_get(config->pid_workspaces, i));
|
||||||
}
|
}
|
||||||
list_free(config->pid_workspaces);
|
list_free(config->pid_workspaces);
|
||||||
|
|
||||||
for (i = 0; config->criteria && i < config->criteria->length; ++i) {
|
for (i = 0; config->criteria && i < config->criteria->length; ++i) {
|
||||||
free_criteria(config->criteria->items[i]);
|
free_criteria(*(struct criteria **)list_get(config->criteria, i));
|
||||||
}
|
}
|
||||||
list_free(config->criteria);
|
list_free(config->criteria);
|
||||||
|
|
||||||
for (i = 0; config->no_focus && i < config->no_focus->length; ++i) {
|
for (i = 0; config->no_focus && i < config->no_focus->length; ++i) {
|
||||||
free_criteria(config->no_focus->items[i]);
|
free_criteria(*(struct criteria **)list_get(config->no_focus, i));
|
||||||
}
|
}
|
||||||
list_free(config->no_focus);
|
list_free(config->no_focus);
|
||||||
|
|
||||||
for (i = 0; config->input_configs && i < config->input_configs->length; ++i) {
|
for (i = 0; config->input_configs && i < config->input_configs->length; ++i) {
|
||||||
free_input_config(config->input_configs->items[i]);
|
free_input_config(*(struct input_config **)list_get(config->input_configs, i));
|
||||||
}
|
}
|
||||||
list_free(config->input_configs);
|
list_free(config->input_configs);
|
||||||
|
|
||||||
for (i = 0; config->output_configs && i < config->output_configs->length; ++i) {
|
for (i = 0; config->output_configs && i < config->output_configs->length; ++i) {
|
||||||
free_output_config(config->output_configs->items[i]);
|
free_output_config(*(struct output_config **)list_get(config->output_configs, i));
|
||||||
}
|
}
|
||||||
list_free(config->output_configs);
|
list_free(config->output_configs);
|
||||||
|
|
||||||
for (i = 0; config->command_policies && i < config->command_policies->length; ++i) {
|
for (i = 0; config->command_policies && i < config->command_policies->length; ++i) {
|
||||||
free_command_policy(config->command_policies->items[i]);
|
free_command_policy(*(struct command_policy **)list_get(config->command_policies, i));
|
||||||
}
|
}
|
||||||
list_free(config->command_policies);
|
list_free(config->command_policies);
|
||||||
|
|
||||||
for (i = 0; config->feature_policies && i < config->feature_policies->length; ++i) {
|
for (i = 0; config->feature_policies && i < config->feature_policies->length; ++i) {
|
||||||
free_feature_policy(config->feature_policies->items[i]);
|
free_feature_policy(*(struct feature_policy **)list_get(config->feature_policies, i));
|
||||||
}
|
}
|
||||||
list_free(config->feature_policies);
|
list_free(config->feature_policies);
|
||||||
|
|
||||||
|
|
@ -290,23 +288,23 @@ static bool file_exists(const char *path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void config_defaults(struct sway_config *config) {
|
static void config_defaults(struct sway_config *config) {
|
||||||
if (!(config->symbols = create_list())) goto cleanup;
|
if (!(config->symbols = list_new(sizeof(struct sway_variable *), 0))) goto cleanup;
|
||||||
if (!(config->modes = create_list())) goto cleanup;
|
if (!(config->modes = list_new(sizeof(struct sway_mode *), 0))) goto cleanup;
|
||||||
if (!(config->bars = create_list())) goto cleanup;
|
if (!(config->bars = list_new(sizeof(struct bar_config *), 0))) goto cleanup;
|
||||||
if (!(config->workspace_outputs = create_list())) goto cleanup;
|
if (!(config->workspace_outputs = list_new(sizeof(struct workspace_output *), 0))) goto cleanup;
|
||||||
if (!(config->pid_workspaces = create_list())) goto cleanup;
|
if (!(config->pid_workspaces = list_new(sizeof(struct pid_workspace *), 0))) goto cleanup;
|
||||||
if (!(config->criteria = create_list())) goto cleanup;
|
if (!(config->criteria = list_new(sizeof(struct criteria *), 0))) goto cleanup;
|
||||||
if (!(config->no_focus = create_list())) goto cleanup;
|
if (!(config->no_focus = list_new(sizeof(struct criterua *), 0))) goto cleanup;
|
||||||
if (!(config->input_configs = create_list())) goto cleanup;
|
if (!(config->input_configs = list_new(sizeof(struct list_config *), 0))) goto cleanup;
|
||||||
if (!(config->output_configs = create_list())) goto cleanup;
|
if (!(config->output_configs = list_new(sizeof(struct output_config *), 0))) goto cleanup;
|
||||||
|
|
||||||
if (!(config->cmd_queue = create_list())) goto cleanup;
|
if (!(config->cmd_queue = list_new(sizeof(char *), 0))) goto cleanup;
|
||||||
|
|
||||||
if (!(config->current_mode = malloc(sizeof(struct sway_mode)))) goto cleanup;
|
if (!(config->current_mode = malloc(sizeof(struct sway_mode)))) goto cleanup;
|
||||||
if (!(config->current_mode->name = malloc(sizeof("default")))) goto cleanup;
|
if (!(config->current_mode->name = malloc(sizeof("default")))) goto cleanup;
|
||||||
strcpy(config->current_mode->name, "default");
|
strcpy(config->current_mode->name, "default");
|
||||||
if (!(config->current_mode->bindings = create_list())) goto cleanup;
|
if (!(config->current_mode->bindings = list_new(sizeof(struct sway_binding *), 0))) goto cleanup;
|
||||||
list_add(config->modes, config->current_mode);
|
list_add(config->modes, &config->current_mode);
|
||||||
|
|
||||||
config->floating_mod = 0;
|
config->floating_mod = 0;
|
||||||
config->dragging_key = M_LEFT_CLICK;
|
config->dragging_key = M_LEFT_CLICK;
|
||||||
|
|
@ -342,9 +340,9 @@ static void config_defaults(struct sway_config *config) {
|
||||||
config->gaps_inner = 0;
|
config->gaps_inner = 0;
|
||||||
config->gaps_outer = 0;
|
config->gaps_outer = 0;
|
||||||
|
|
||||||
if (!(config->active_bar_modifiers = create_list())) goto cleanup;
|
if (!(config->active_bar_modifiers = list_new(sizeof(uint32_t *), 0))) goto cleanup;
|
||||||
|
|
||||||
if (!(config->config_chain = create_list())) goto cleanup;
|
if (!(config->config_chain = list_new(sizeof(char *), 0))) goto cleanup;
|
||||||
config->current_config = NULL;
|
config->current_config = NULL;
|
||||||
|
|
||||||
// borders
|
// borders
|
||||||
|
|
@ -388,9 +386,9 @@ static void config_defaults(struct sway_config *config) {
|
||||||
config->border_colors.background = 0xFFFFFFFF;
|
config->border_colors.background = 0xFFFFFFFF;
|
||||||
|
|
||||||
// Security
|
// Security
|
||||||
if (!(config->command_policies = create_list())) goto cleanup;
|
if (!(config->command_policies = list_new(sizeof(struct command_policy *), 0))) goto cleanup;
|
||||||
if (!(config->feature_policies = create_list())) goto cleanup;
|
if (!(config->feature_policies = list_new(sizeof(struct feature_policy *), 0))) goto cleanup;
|
||||||
if (!(config->ipc_policies = create_list())) goto cleanup;
|
if (!(config->ipc_policies = list_new(sizeof(struct ipc_policy *), 0))) goto cleanup;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
cleanup:
|
cleanup:
|
||||||
|
|
@ -407,15 +405,13 @@ static int compare_modifiers(const void *left, const void *right) {
|
||||||
void update_active_bar_modifiers() {
|
void update_active_bar_modifiers() {
|
||||||
if (config->active_bar_modifiers->length > 0) {
|
if (config->active_bar_modifiers->length > 0) {
|
||||||
list_free(config->active_bar_modifiers);
|
list_free(config->active_bar_modifiers);
|
||||||
config->active_bar_modifiers = create_list();
|
config->active_bar_modifiers = list_new(sizeof(uint32_t *), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bar_config *bar;
|
for (size_t i = 0; i < config->bars->length; ++i) {
|
||||||
int i;
|
struct bar_config *bar = *(struct bar_config **)list_get(config->bars, i);
|
||||||
for (i = 0; i < config->bars->length; ++i) {
|
|
||||||
bar = config->bars->items[i];
|
|
||||||
if (strcmp(bar->mode, "hide") == 0 && strcmp(bar->hidden_state, "hide") == 0) {
|
if (strcmp(bar->mode, "hide") == 0 && strcmp(bar->hidden_state, "hide") == 0) {
|
||||||
if (list_seq_find(config->active_bar_modifiers, compare_modifiers, &bar->modifier) < 0) {
|
if (list_lsearch(config->active_bar_modifiers, compare_modifiers, &bar->modifier, NULL) < 0) {
|
||||||
list_add(config->active_bar_modifiers, &bar->modifier);
|
list_add(config->active_bar_modifiers, &bar->modifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -524,7 +520,7 @@ bool load_main_config(const char *file, bool is_active) {
|
||||||
}
|
}
|
||||||
|
|
||||||
config->current_config = path;
|
config->current_config = path;
|
||||||
list_add(config->config_chain, path);
|
list_add(config->config_chain, &path);
|
||||||
|
|
||||||
config->reading = true;
|
config->reading = true;
|
||||||
|
|
||||||
|
|
@ -535,7 +531,7 @@ bool load_main_config(const char *file, bool is_active) {
|
||||||
sway_log(L_ERROR, "%s does not exist, sway will have no security configuration"
|
sway_log(L_ERROR, "%s does not exist, sway will have no security configuration"
|
||||||
" and will probably be broken", SYSCONFDIR "/sway/security.d");
|
" and will probably be broken", SYSCONFDIR "/sway/security.d");
|
||||||
} else {
|
} else {
|
||||||
list_t *secconfigs = create_list();
|
list_t *secconfigs = list_new(sizeof(char *), 0);
|
||||||
char *base = SYSCONFDIR "/sway/security.d/";
|
char *base = SYSCONFDIR "/sway/security.d/";
|
||||||
struct dirent *ent = readdir(dir);
|
struct dirent *ent = readdir(dir);
|
||||||
struct stat s;
|
struct stat s;
|
||||||
|
|
@ -545,15 +541,15 @@ bool load_main_config(const char *file, bool is_active) {
|
||||||
strcat(_path, ent->d_name);
|
strcat(_path, ent->d_name);
|
||||||
lstat(_path, &s);
|
lstat(_path, &s);
|
||||||
if (S_ISREG(s.st_mode)) {
|
if (S_ISREG(s.st_mode)) {
|
||||||
list_add(secconfigs, _path);
|
list_add(secconfigs, &_path);
|
||||||
}
|
}
|
||||||
ent = readdir(dir);
|
ent = readdir(dir);
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
list_qsort(secconfigs, qstrcmp);
|
list_qsort(secconfigs, qstrcmp);
|
||||||
for (int i = 0; i < secconfigs->length; ++i) {
|
for (size_t i = 0; i < secconfigs->length; ++i) {
|
||||||
char *_path = secconfigs->items[i];
|
char *_path = *(char **)list_get(secconfigs, i);
|
||||||
if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 || (((s.st_mode & 0777) != 0644) && (s.st_mode & 0777) != 0444)) {
|
if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 || (((s.st_mode & 0777) != 0644) && (s.st_mode & 0777) != 0444)) {
|
||||||
sway_log(L_ERROR, "Refusing to load %s - it must be owned by root and mode 644 or 444", _path);
|
sway_log(L_ERROR, "Refusing to load %s - it must be owned by root and mode 644 or 444", _path);
|
||||||
success = false;
|
success = false;
|
||||||
|
|
@ -608,9 +604,8 @@ static bool load_include_config(const char *path, const char *parent_dir, struct
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if config has already been included
|
// check if config has already been included
|
||||||
int j;
|
for (size_t j = 0; j < config->config_chain->length; ++j) {
|
||||||
for (j = 0; j < config->config_chain->length; ++j) {
|
char *old_path = *(char **)list_get(config->config_chain, j);
|
||||||
char *old_path = config->config_chain->items[j];
|
|
||||||
if (strcmp(real_path, old_path) == 0) {
|
if (strcmp(real_path, old_path) == 0) {
|
||||||
sway_log(L_DEBUG, "%s already included once, won't be included again.", real_path);
|
sway_log(L_DEBUG, "%s already included once, won't be included again.", real_path);
|
||||||
free(real_path);
|
free(real_path);
|
||||||
|
|
@ -619,13 +614,13 @@ static bool load_include_config(const char *path, const char *parent_dir, struct
|
||||||
}
|
}
|
||||||
|
|
||||||
config->current_config = real_path;
|
config->current_config = real_path;
|
||||||
list_add(config->config_chain, real_path);
|
list_add(config->config_chain, &real_path);
|
||||||
int index = config->config_chain->length - 1;
|
size_t index = config->config_chain->length - 1;
|
||||||
|
|
||||||
if (!load_config(real_path, config)) {
|
if (!load_config(real_path, config)) {
|
||||||
free(real_path);
|
free(real_path);
|
||||||
config->current_config = parent_config;
|
config->current_config = parent_config;
|
||||||
list_del(config->config_chain, index);
|
list_delete(config->config_chain, index);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -715,7 +710,8 @@ bool read_config(FILE *file, struct sway_config *config) {
|
||||||
|
|
||||||
case CMD_DEFER:
|
case CMD_DEFER:
|
||||||
sway_log(L_DEBUG, "Defferring command `%s'", line);
|
sway_log(L_DEBUG, "Defferring command `%s'", line);
|
||||||
list_add(config->cmd_queue, strdup(line));
|
char *ptr = strdup(line);
|
||||||
|
list_add(config->cmd_queue, &ptr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_BLOCK_MODE:
|
case CMD_BLOCK_MODE:
|
||||||
|
|
@ -778,7 +774,7 @@ bool read_config(FILE *file, struct sway_config *config) {
|
||||||
switch(block) {
|
switch(block) {
|
||||||
case CMD_BLOCK_MODE:
|
case CMD_BLOCK_MODE:
|
||||||
sway_log(L_DEBUG, "End of mode block");
|
sway_log(L_DEBUG, "End of mode block");
|
||||||
config->current_mode = config->modes->items[0];
|
config->current_mode = *(struct sway_mode **)list_get(config->modes, 0);
|
||||||
block = CMD_BLOCK_END;
|
block = CMD_BLOCK_END;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -829,10 +825,10 @@ bool read_config(FILE *file, struct sway_config *config) {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
int input_identifier_cmp(const void *item, const void *data) {
|
int input_identifier_cmp(const void *key, const void *item) {
|
||||||
const struct input_config *ic = item;
|
const struct input_config *const *ic = item;
|
||||||
const char *identifier = data;
|
const char *identifier = key;
|
||||||
return strcmp(ic->identifier, identifier);
|
return strcmp((*ic)->identifier, identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
int output_name_cmp(const void *item, const void *data) {
|
int output_name_cmp(const void *item, const void *data) {
|
||||||
|
|
@ -1003,10 +999,8 @@ void terminate_swaybg(pid_t pid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool active_output(const char *name) {
|
static bool active_output(const char *name) {
|
||||||
int i;
|
for (size_t i = 0; i < root_container.children->length; ++i) {
|
||||||
swayc_t *cont = NULL;
|
swayc_t *cont = *(swayc_t **)list_get(root_container.children, i);
|
||||||
for (i = 0; i < root_container.children->length; ++i) {
|
|
||||||
cont = root_container.children->items[i];
|
|
||||||
if (cont->type == C_OUTPUT && strcasecmp(name, cont->name) == 0) {
|
if (cont->type == C_OUTPUT && strcasecmp(name, cont->name) == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -1017,16 +1011,14 @@ static bool active_output(const char *name) {
|
||||||
|
|
||||||
void load_swaybars() {
|
void load_swaybars() {
|
||||||
// Check for bars
|
// Check for bars
|
||||||
list_t *bars = create_list();
|
list_t *bars = list_new(sizeof(struct bar_config *), 0);
|
||||||
struct bar_config *bar = NULL;
|
struct bar_config *bar = NULL;
|
||||||
int i;
|
for (size_t i = 0; i < config->bars->length; ++i) {
|
||||||
for (i = 0; i < config->bars->length; ++i) {
|
bar = *(struct bar_config **)list_get(config->bars, i);
|
||||||
bar = config->bars->items[i];
|
|
||||||
bool apply = false;
|
bool apply = false;
|
||||||
if (bar->outputs) {
|
if (bar->outputs) {
|
||||||
int j;
|
for (size_t j = 0; j < bar->outputs->length; ++j) {
|
||||||
for (j = 0; j < bar->outputs->length; ++j) {
|
char *o = *(char **)list_get(bar->outputs, j);
|
||||||
char *o = bar->outputs->items[j];
|
|
||||||
if (!strcmp(o, "*") || active_output(o)) {
|
if (!strcmp(o, "*") || active_output(o)) {
|
||||||
apply = true;
|
apply = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -1036,12 +1028,12 @@ void load_swaybars() {
|
||||||
apply = true;
|
apply = true;
|
||||||
}
|
}
|
||||||
if (apply) {
|
if (apply) {
|
||||||
list_add(bars, bar);
|
list_add(bars, &bar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < bars->length; ++i) {
|
for (size_t i = 0; i < bars->length; ++i) {
|
||||||
bar = bars->items[i];
|
bar = *(struct bar_config **)list_get(bars, i);
|
||||||
if (bar->pid != 0) {
|
if (bar->pid != 0) {
|
||||||
terminate_swaybar(bar->pid);
|
terminate_swaybar(bar->pid);
|
||||||
}
|
}
|
||||||
|
|
@ -1130,8 +1122,8 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
|
||||||
output->y = oc->y;
|
output->y = oc->y;
|
||||||
} else {
|
} else {
|
||||||
int x = 0;
|
int x = 0;
|
||||||
for (int i = 0; i < root_container.children->length; ++i) {
|
for (size_t i = 0; i < root_container.children->length; ++i) {
|
||||||
swayc_t *c = root_container.children->items[i];
|
swayc_t *c = *(swayc_t **)list_get(root_container.children, i);
|
||||||
if (c->type == C_OUTPUT) {
|
if (c->type == C_OUTPUT) {
|
||||||
if (c->width + c->x > x) {
|
if (c->width + c->x > x) {
|
||||||
x = c->width + c->x;
|
x = c->width + c->x;
|
||||||
|
|
@ -1143,17 +1135,18 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
|
||||||
|
|
||||||
if (!oc || !oc->background) {
|
if (!oc || !oc->background) {
|
||||||
// Look for a * config for background
|
// Look for a * config for background
|
||||||
int i = list_seq_find(config->output_configs, output_name_cmp, "*");
|
struct output_config *item;
|
||||||
if (i >= 0) {
|
if (list_lsearch(config->output_configs, output_name_cmp, "*", &item) != -1) {
|
||||||
oc = config->output_configs->items[i];
|
oc = item;
|
||||||
} else {
|
} else {
|
||||||
oc = NULL;
|
oc = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int output_i;
|
size_t output_i;
|
||||||
for (output_i = 0; output_i < root_container.children->length; ++output_i) {
|
for (output_i = 0; output_i < root_container.children->length; ++output_i) {
|
||||||
if (root_container.children->items[output_i] == output) {
|
swayc_t *item = *(swayc_t **)list_get(root_container.children, output_i);
|
||||||
|
if (item == output) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1163,11 +1156,11 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
|
||||||
terminate_swaybg(output->bg_pid);
|
terminate_swaybg(output->bg_pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
sway_log(L_DEBUG, "Setting background for output %d to %s", output_i, oc->background);
|
sway_log(L_DEBUG, "Setting background for output %zu to %s", output_i, oc->background);
|
||||||
|
|
||||||
size_t bufsize = 12;
|
size_t bufsize = 12;
|
||||||
char output_id[bufsize];
|
char output_id[bufsize];
|
||||||
snprintf(output_id, bufsize, "%d", output_i);
|
snprintf(output_id, bufsize, "%zu", output_i);
|
||||||
output_id[bufsize-1] = 0;
|
output_id[bufsize-1] = 0;
|
||||||
|
|
||||||
char *const cmd[] = {
|
char *const cmd[] = {
|
||||||
|
|
@ -1186,7 +1179,6 @@ void apply_output_config(struct output_config *oc, swayc_t *output) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *do_var_replacement(char *str) {
|
char *do_var_replacement(char *str) {
|
||||||
int i;
|
|
||||||
char *find = str;
|
char *find = str;
|
||||||
while ((find = strchr(find, '$'))) {
|
while ((find = strchr(find, '$'))) {
|
||||||
// Skip if escaped.
|
// Skip if escaped.
|
||||||
|
|
@ -1196,9 +1188,10 @@ char *do_var_replacement(char *str) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
size_t i;
|
||||||
// Find matching variable
|
// Find matching variable
|
||||||
for (i = 0; i < config->symbols->length; ++i) {
|
for (i = 0; i < config->symbols->length; ++i) {
|
||||||
struct sway_variable *var = config->symbols->items[i];
|
struct sway_variable *var = *(struct sway_variable **)list_get(config->symbols, i);
|
||||||
int vnlen = strlen(var->name);
|
int vnlen = strlen(var->name);
|
||||||
if (strncmp(find, var->name, vnlen) == 0) {
|
if (strncmp(find, var->name, vnlen) == 0) {
|
||||||
int vvlen = strlen(var->value);
|
int vvlen = strlen(var->value);
|
||||||
|
|
@ -1236,8 +1229,8 @@ int workspace_output_cmp_workspace(const void *a, const void *b) {
|
||||||
return lenient_strcmp(wsa->workspace, wsb->workspace);
|
return lenient_strcmp(wsa->workspace, wsb->workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sway_binding_cmp_keys(const void *a, const void *b) {
|
int sway_binding_cmp_keys(const void *key, const void *item) {
|
||||||
const struct sway_binding *binda = a, *bindb = b;
|
const struct sway_binding *binda = item, *bindb = key;
|
||||||
|
|
||||||
// Count keys pressed for this binding. important so we check long before
|
// Count keys pressed for this binding. important so we check long before
|
||||||
// short ones. for example mod+a+b before mod+a
|
// short ones. for example mod+a+b before mod+a
|
||||||
|
|
@ -1259,16 +1252,16 @@ int sway_binding_cmp_keys(const void *a, const void *b) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
struct wlc_modifiers no_mods = { 0, 0 };
|
struct wlc_modifiers no_mods = { 0, 0 };
|
||||||
for (int i = 0; i < binda->keys->length; i++) {
|
for (size_t i = 0; i < binda->keys->length; i++) {
|
||||||
xkb_keysym_t ka = *(xkb_keysym_t *)binda->keys->items[i],
|
xkb_keysym_t ka = **(xkb_keysym_t **)list_get(binda->keys, i),
|
||||||
kb = *(xkb_keysym_t *)bindb->keys->items[i];
|
kb = **(xkb_keysym_t **)list_get(bindb->keys, i);
|
||||||
if (binda->bindcode) {
|
if (binda->bindcode) {
|
||||||
uint32_t *keycode = binda->keys->items[i];
|
uint32_t *keycode = *(uint32_t **)list_get(binda->keys, i);
|
||||||
ka = wlc_keyboard_get_keysym_for_key(*keycode, &no_mods);
|
ka = wlc_keyboard_get_keysym_for_key(*keycode, &no_mods);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bindb->bindcode) {
|
if (bindb->bindcode) {
|
||||||
uint32_t *keycode = bindb->keys->items[i];
|
uint32_t *keycode = *(uint32_t **)list_get(bindb->keys, i);
|
||||||
kb = wlc_keyboard_get_keysym_for_key(*keycode, &no_mods);
|
kb = wlc_keyboard_get_keysym_for_key(*keycode, &no_mods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1297,8 +1290,8 @@ int sway_binding_cmp_qsort(const void *a, const void *b) {
|
||||||
|
|
||||||
void free_sway_binding(struct sway_binding *binding) {
|
void free_sway_binding(struct sway_binding *binding) {
|
||||||
if (binding->keys) {
|
if (binding->keys) {
|
||||||
for (int i = 0; i < binding->keys->length; i++) {
|
for (size_t i = 0; i < binding->keys->length; i++) {
|
||||||
free(binding->keys->items[i]);
|
free(*(void **)list_get(binding->keys, i));
|
||||||
}
|
}
|
||||||
list_free(binding->keys);
|
list_free(binding->keys);
|
||||||
}
|
}
|
||||||
|
|
@ -1308,8 +1301,8 @@ void free_sway_binding(struct sway_binding *binding) {
|
||||||
free(binding);
|
free(binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sway_mouse_binding_cmp_buttons(const void *a, const void *b) {
|
int sway_mouse_binding_cmp_buttons(const void *key, const void *item) {
|
||||||
const struct sway_mouse_binding *binda = a, *bindb = b;
|
const struct sway_mouse_binding *binda = item, *bindb = key;
|
||||||
if (binda->button > bindb->button) {
|
if (binda->button > bindb->button) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -1349,16 +1342,15 @@ struct sway_binding *sway_binding_dup(struct sway_binding *sb) {
|
||||||
new_sb->modifiers = sb->modifiers;
|
new_sb->modifiers = sb->modifiers;
|
||||||
new_sb->command = strdup(sb->command);
|
new_sb->command = strdup(sb->command);
|
||||||
|
|
||||||
new_sb->keys = create_list();
|
new_sb->keys = list_new(sizeof(xkb_keysym_t *), 0);
|
||||||
int i;
|
for (size_t i = 0; i < sb->keys->length; ++i) {
|
||||||
for (i = 0; i < sb->keys->length; ++i) {
|
|
||||||
xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t));
|
xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t));
|
||||||
if (!key) {
|
if (!key) {
|
||||||
free_sway_binding(new_sb);
|
free_sway_binding(new_sb);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
*key = *(xkb_keysym_t *)sb->keys->items[i];
|
*key = **(xkb_keysym_t **)list_get(sb->keys, i);
|
||||||
list_add(new_sb->keys, key);
|
list_add(new_sb->keys, &key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new_sb;
|
return new_sb;
|
||||||
|
|
@ -1375,7 +1367,7 @@ struct bar_config *default_bar_config(void) {
|
||||||
bar->modifier = WLC_BIT_MOD_LOGO;
|
bar->modifier = WLC_BIT_MOD_LOGO;
|
||||||
bar->outputs = NULL;
|
bar->outputs = NULL;
|
||||||
bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
|
bar->position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM;
|
||||||
if (!(bar->bindings = create_list())) goto cleanup;
|
if (!(bar->bindings = list_new(sizeof(struct sway_binding *), 0))) goto cleanup;
|
||||||
if (!(bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p'; sleep 1; done"))) goto cleanup;
|
if (!(bar->status_command = strdup("while :; do date +'%Y-%m-%d %l:%M:%S %p'; sleep 1; done"))) goto cleanup;
|
||||||
bar->pango_markup = false;
|
bar->pango_markup = false;
|
||||||
bar->swaybar_command = NULL;
|
bar->swaybar_command = NULL;
|
||||||
|
|
@ -1414,7 +1406,7 @@ struct bar_config *default_bar_config(void) {
|
||||||
bar->colors.binding_mode_bg = NULL;
|
bar->colors.binding_mode_bg = NULL;
|
||||||
bar->colors.binding_mode_text = NULL;
|
bar->colors.binding_mode_text = NULL;
|
||||||
|
|
||||||
list_add(config->bars, bar);
|
list_add(config->bars, &bar);
|
||||||
|
|
||||||
return bar;
|
return bar;
|
||||||
|
|
||||||
|
|
|
||||||
144
sway/container.c
144
sway/container.c
|
|
@ -35,7 +35,7 @@ static swayc_t *new_swayc(enum swayc_types type) {
|
||||||
c->nb_master = 1;
|
c->nb_master = 1;
|
||||||
c->nb_slave_groups = 1;
|
c->nb_slave_groups = 1;
|
||||||
if (type != C_VIEW) {
|
if (type != C_VIEW) {
|
||||||
c->children = create_list();
|
c->children = list_new(sizeof(swayc_t *), 0);
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +48,7 @@ static void free_swayc(swayc_t *cont) {
|
||||||
// remove children until there are no more, free_swayc calls
|
// remove children until there are no more, free_swayc calls
|
||||||
// remove_child, which removes child from this container
|
// remove_child, which removes child from this container
|
||||||
while (cont->children->length) {
|
while (cont->children->length) {
|
||||||
free_swayc(cont->children->items[0]);
|
free_swayc(*(swayc_t **)list_get(cont->children, 0));
|
||||||
}
|
}
|
||||||
list_free(cont->children);
|
list_free(cont->children);
|
||||||
}
|
}
|
||||||
|
|
@ -57,7 +57,7 @@ static void free_swayc(swayc_t *cont) {
|
||||||
}
|
}
|
||||||
if (cont->floating) {
|
if (cont->floating) {
|
||||||
while (cont->floating->length) {
|
while (cont->floating->length) {
|
||||||
free_swayc(cont->floating->items[0]);
|
free_swayc(*(swayc_t **)list_get(cont->floating, 0));
|
||||||
}
|
}
|
||||||
list_free(cont->floating);
|
list_free(cont->floating);
|
||||||
}
|
}
|
||||||
|
|
@ -99,8 +99,8 @@ static void update_root_geometry() {
|
||||||
int child_width;
|
int child_width;
|
||||||
int child_height;
|
int child_height;
|
||||||
|
|
||||||
for (int i = 0; i < root_container.children->length; ++i) {
|
for (size_t i = 0; i < root_container.children->length; ++i) {
|
||||||
child = root_container.children->items[i];
|
child = *(swayc_t **)list_get(root_container.children, i);
|
||||||
child_width = child->width + child->x;
|
child_width = child->width + child->x;
|
||||||
child_height = child->height + child->y;
|
child_height = child->height + child->y;
|
||||||
if (child_width > width) {
|
if (child_width > width) {
|
||||||
|
|
@ -123,24 +123,20 @@ swayc_t *new_output(wlc_handle handle) {
|
||||||
output_get_scaled_size(handle, &size);
|
output_get_scaled_size(handle, &size);
|
||||||
const char *name = wlc_output_get_name(handle);
|
const char *name = wlc_output_get_name(handle);
|
||||||
// Find current outputs to see if this already exists
|
// Find current outputs to see if this already exists
|
||||||
{
|
for (size_t i = 0; i < root_container.children->length; ++i) {
|
||||||
int i, len = root_container.children->length;
|
swayc_t *op = *(swayc_t **)list_get(root_container.children, i);
|
||||||
for (i = 0; i < len; ++i) {
|
const char *op_name = op->name;
|
||||||
swayc_t *op = root_container.children->items[i];
|
if (op_name && name && strcmp(op_name, name) == 0) {
|
||||||
const char *op_name = op->name;
|
sway_log(L_DEBUG, "restoring output %" PRIuPTR ":%s", handle, op_name);
|
||||||
if (op_name && name && strcmp(op_name, name) == 0) {
|
return op;
|
||||||
sway_log(L_DEBUG, "restoring output %" PRIuPTR ":%s", handle, op_name);
|
|
||||||
return op;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sway_log(L_DEBUG, "New output %" PRIuPTR ":%s", handle, name);
|
sway_log(L_DEBUG, "New output %" PRIuPTR ":%s", handle, name);
|
||||||
|
|
||||||
struct output_config *oc = NULL, *all = NULL;
|
struct output_config *oc = NULL, *all = NULL;
|
||||||
int i;
|
for (size_t i = 0; i < config->output_configs->length; ++i) {
|
||||||
for (i = 0; i < config->output_configs->length; ++i) {
|
struct output_config *cur = *(struct output_config **)list_get(config->output_configs, i);
|
||||||
struct output_config *cur = config->output_configs->items[i];
|
|
||||||
if (strcasecmp(name, cur->name) == 0) {
|
if (strcasecmp(name, cur->name) == 0) {
|
||||||
sway_log(L_DEBUG, "Matched output config for %s", name);
|
sway_log(L_DEBUG, "Matched output config for %s", name);
|
||||||
oc = cur;
|
oc = cur;
|
||||||
|
|
@ -168,7 +164,7 @@ swayc_t *new_output(wlc_handle handle) {
|
||||||
output->name = name ? strdup(name) : NULL;
|
output->name = name ? strdup(name) : NULL;
|
||||||
output->width = size.w;
|
output->width = size.w;
|
||||||
output->height = size.h;
|
output->height = size.h;
|
||||||
output->unmanaged = create_list();
|
output->unmanaged = list_new(sizeof(wlc_handle *), 0);
|
||||||
output->bg_pid = 0;
|
output->bg_pid = 0;
|
||||||
|
|
||||||
apply_output_config(oc, output);
|
apply_output_config(oc, output);
|
||||||
|
|
@ -180,8 +176,8 @@ swayc_t *new_output(wlc_handle handle) {
|
||||||
swayc_t *ws = NULL;
|
swayc_t *ws = NULL;
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
for (i = 0; i < config->workspace_outputs->length; ++i) {
|
for (size_t i = 0; i < config->workspace_outputs->length; ++i) {
|
||||||
struct workspace_output *wso = config->workspace_outputs->items[i];
|
struct workspace_output *wso = *(struct workspace_output **)list_get(config->workspace_outputs, i);
|
||||||
if (strcasecmp(wso->output, name) == 0) {
|
if (strcasecmp(wso->output, name) == 0) {
|
||||||
sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output);
|
sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output);
|
||||||
// Check if any other workspaces are using this name
|
// Check if any other workspaces are using this name
|
||||||
|
|
@ -206,7 +202,7 @@ swayc_t *new_output(wlc_handle handle) {
|
||||||
ws->is_focused = true;
|
ws->is_focused = true;
|
||||||
} else {
|
} else {
|
||||||
sort_workspaces(output);
|
sort_workspaces(output);
|
||||||
set_focused_container(output->children->items[0]);
|
set_focused_container(*(swayc_t **)list_get(output->children, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
free(ws_name);
|
free(ws_name);
|
||||||
|
|
@ -231,7 +227,7 @@ swayc_t *new_workspace(swayc_t *output, const char *name) {
|
||||||
workspace->height = output->height;
|
workspace->height = output->height;
|
||||||
workspace->name = !name ? NULL : strdup(name);
|
workspace->name = !name ? NULL : strdup(name);
|
||||||
workspace->visible = false;
|
workspace->visible = false;
|
||||||
workspace->floating = create_list();
|
workspace->floating = list_new(sizeof(swayc_t *), 0);
|
||||||
|
|
||||||
add_child(output, workspace);
|
add_child(output, workspace);
|
||||||
sort_workspaces(output);
|
sort_workspaces(output);
|
||||||
|
|
@ -265,9 +261,8 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) {
|
||||||
cont->focused = workspace->focused;
|
cont->focused = workspace->focused;
|
||||||
workspace->focused = cont;
|
workspace->focused = cont;
|
||||||
// set all children focu to container
|
// set all children focu to container
|
||||||
int i;
|
for (size_t i = 0; i < workspace->children->length; ++i) {
|
||||||
for (i = 0; i < workspace->children->length; ++i) {
|
(*(swayc_t **)list_get(workspace->children, i))->parent = cont;
|
||||||
((swayc_t *)workspace->children->items[i])->parent = cont;
|
|
||||||
}
|
}
|
||||||
// Swap children
|
// Swap children
|
||||||
list_t *tmp_list = workspace->children;
|
list_t *tmp_list = workspace->children;
|
||||||
|
|
@ -437,16 +432,17 @@ swayc_t *destroy_output(swayc_t *output) {
|
||||||
// TODO also check if there will ever be no outputs except for exiting
|
// TODO also check if there will ever be no outputs except for exiting
|
||||||
// program
|
// program
|
||||||
if (root_container.children->length > 1) {
|
if (root_container.children->length > 1) {
|
||||||
int p = root_container.children->items[0] == output;
|
int p = *(swayc_t **)list_get(root_container.children, 0) == output;
|
||||||
// Move workspace from this output to another output
|
// Move workspace from this output to another output
|
||||||
|
swayc_t *item = *(swayc_t **)list_get(root_container.children, p);
|
||||||
while (output->children->length) {
|
while (output->children->length) {
|
||||||
swayc_t *child = output->children->items[0];
|
swayc_t *child = *(swayc_t **)list_get(output->children, 0);
|
||||||
remove_child(child);
|
remove_child(child);
|
||||||
add_child(root_container.children->items[p], child);
|
add_child(item, child);
|
||||||
}
|
}
|
||||||
sort_workspaces(root_container.children->items[p]);
|
sort_workspaces(item);
|
||||||
update_visibility(root_container.children->items[p]);
|
update_visibility(item);
|
||||||
arrange_windows(root_container.children->items[p], -1, -1);
|
arrange_windows(item, -1, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sway_log(L_DEBUG, "OUTPUT: Destroying output '%" PRIuPTR "'", output->handle);
|
sway_log(L_DEBUG, "OUTPUT: Destroying output '%" PRIuPTR "'", output->handle);
|
||||||
|
|
@ -474,23 +470,24 @@ swayc_t *destroy_workspace(swayc_t *workspace) {
|
||||||
} else {
|
} else {
|
||||||
// Move children to a different workspace on this output
|
// Move children to a different workspace on this output
|
||||||
swayc_t *new_workspace = NULL;
|
swayc_t *new_workspace = NULL;
|
||||||
int i;
|
for(size_t i = 0; i < output->children->length; i++) {
|
||||||
for(i = 0; i < output->children->length; i++) {
|
new_workspace = *(swayc_t **)list_get(output->children, i);
|
||||||
if(output->children->items[i] != workspace) {
|
if (new_workspace != workspace) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
new_workspace = output->children->items[i];
|
|
||||||
|
|
||||||
sway_log(L_DEBUG, "moving children to different workspace '%s' -> '%s'",
|
sway_log(L_DEBUG, "moving children to different workspace '%s' -> '%s'",
|
||||||
workspace->name, new_workspace->name);
|
workspace->name, new_workspace->name);
|
||||||
|
|
||||||
for(i = 0; i < workspace->children->length; i++) {
|
for (size_t i = 0; i < workspace->children->length; i++) {
|
||||||
move_container_to(workspace->children->items[i], new_workspace);
|
swayc_t *item = *(swayc_t **)list_get(workspace->children, i);
|
||||||
|
move_container_to(item, new_workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < workspace->floating->length; i++) {
|
for (size_t i = 0; i < workspace->floating->length; i++) {
|
||||||
move_container_to(workspace->floating->items[i], new_workspace);
|
swayc_t *item = *(swayc_t **)list_get(workspace->floating, i);
|
||||||
|
move_container_to(item, new_workspace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -534,17 +531,16 @@ swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *dat
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// Special case for checking floating stuff
|
// Special case for checking floating stuff
|
||||||
int i;
|
|
||||||
if (container->type == C_WORKSPACE) {
|
if (container->type == C_WORKSPACE) {
|
||||||
for (i = 0; i < container->floating->length; ++i) {
|
for (size_t i = 0; i < container->floating->length; ++i) {
|
||||||
swayc_t *child = container->floating->items[i];
|
swayc_t *child = *(swayc_t **)list_get(container->floating, i);
|
||||||
if (test(child, data)) {
|
if (test(child, data)) {
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < container->children->length; ++i) {
|
for (size_t i = 0; i < container->children->length; ++i) {
|
||||||
swayc_t *child = container->children->items[i];
|
swayc_t *child = *(swayc_t **)list_get(container->children, i);
|
||||||
if (test(child, data)) {
|
if (test(child, data)) {
|
||||||
return child;
|
return child;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -710,8 +706,6 @@ swayc_t *container_under_pointer(void) {
|
||||||
struct wlc_point origin;
|
struct wlc_point origin;
|
||||||
wlc_pointer_get_position(&origin);
|
wlc_pointer_get_position(&origin);
|
||||||
while (lookup && lookup->type != C_VIEW) {
|
while (lookup && lookup->type != C_VIEW) {
|
||||||
int i;
|
|
||||||
int len;
|
|
||||||
// if tabbed/stacked go directly to focused container, otherwise search
|
// if tabbed/stacked go directly to focused container, otherwise search
|
||||||
// children
|
// children
|
||||||
if (lookup->layout == L_TABBED || lookup->layout == L_STACKED) {
|
if (lookup->layout == L_TABBED || lookup->layout == L_STACKED) {
|
||||||
|
|
@ -720,11 +714,13 @@ swayc_t *container_under_pointer(void) {
|
||||||
}
|
}
|
||||||
// if workspace, search floating
|
// if workspace, search floating
|
||||||
if (lookup->type == C_WORKSPACE) {
|
if (lookup->type == C_WORKSPACE) {
|
||||||
|
ssize_t i, len;
|
||||||
i = len = lookup->floating->length;
|
i = len = lookup->floating->length;
|
||||||
bool got_floating = false;
|
bool got_floating = false;
|
||||||
while (--i > -1) {
|
while (--i > -1) {
|
||||||
if (pointer_test(lookup->floating->items[i], &origin)) {
|
swayc_t *item = *(swayc_t **)list_get(lookup->floating, i);
|
||||||
lookup = lookup->floating->items[i];
|
if (pointer_test(item, &origin)) {
|
||||||
|
lookup = item;
|
||||||
got_floating = true;
|
got_floating = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -734,10 +730,11 @@ swayc_t *container_under_pointer(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// search children
|
// search children
|
||||||
len = lookup->children->length;
|
size_t i, len = lookup->children->length;
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
if (pointer_test(lookup->children->items[i], &origin)) {
|
swayc_t *item = *(swayc_t **)list_get(lookup->children, i);
|
||||||
lookup = lookup->children->items[i];
|
if (pointer_test(item, &origin)) {
|
||||||
|
lookup = item;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -756,8 +753,8 @@ swayc_t *container_find(swayc_t *container, bool (*f)(swayc_t *, const void *),
|
||||||
|
|
||||||
swayc_t *con;
|
swayc_t *con;
|
||||||
if (container->type == C_WORKSPACE) {
|
if (container->type == C_WORKSPACE) {
|
||||||
for (int i = 0; i < container->floating->length; ++i) {
|
for (size_t i = 0; i < container->floating->length; ++i) {
|
||||||
con = container->floating->items[i];
|
con = *(swayc_t **)list_get(container->floating, i);
|
||||||
if (f(con, data)) {
|
if (f(con, data)) {
|
||||||
return con;
|
return con;
|
||||||
}
|
}
|
||||||
|
|
@ -768,8 +765,8 @@ swayc_t *container_find(swayc_t *container, bool (*f)(swayc_t *, const void *),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < container->children->length; ++i) {
|
for (size_t i = 0; i < container->children->length; ++i) {
|
||||||
con = container->children->items[i];
|
con = *(swayc_t **)list_get(container->children, i);
|
||||||
if (f(con, data)) {
|
if (f(con, data)) {
|
||||||
return con;
|
return con;
|
||||||
}
|
}
|
||||||
|
|
@ -837,16 +834,15 @@ int swayc_gap(swayc_t *container) {
|
||||||
void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) {
|
void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) {
|
||||||
if (container) {
|
if (container) {
|
||||||
f(container, data);
|
f(container, data);
|
||||||
int i;
|
|
||||||
if (container->children) {
|
if (container->children) {
|
||||||
for (i = 0; i < container->children->length; ++i) {
|
for (size_t i = 0; i < container->children->length; ++i) {
|
||||||
swayc_t *child = container->children->items[i];
|
swayc_t *child = *(swayc_t **)list_get(container->children, i);
|
||||||
container_map(child, f, data);
|
container_map(child, f, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (container->floating) {
|
if (container->floating) {
|
||||||
for (i = 0; i < container->floating->length; ++i) {
|
for (size_t i = 0; i < container->floating->length; ++i) {
|
||||||
swayc_t *child = container->floating->items[i];
|
swayc_t *child = *(swayc_t **)list_get(container->floating, i);
|
||||||
container_map(child, f, data);
|
container_map(child, f, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -870,15 +866,15 @@ void update_visibility_output(swayc_t *container, wlc_handle output) {
|
||||||
// Update visibility for children
|
// Update visibility for children
|
||||||
else {
|
else {
|
||||||
if (container->children) {
|
if (container->children) {
|
||||||
int i, len = container->children->length;
|
for (size_t i = 0; i < container->children->length; ++i) {
|
||||||
for (i = 0; i < len; ++i) {
|
swayc_t *item = *(swayc_t **)list_get(container->children, i);
|
||||||
update_visibility_output(container->children->items[i], output);
|
update_visibility_output(item, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (container->floating) {
|
if (container->floating) {
|
||||||
int i, len = container->floating->length;
|
for (size_t i = 0; i < container->floating->length; ++i) {
|
||||||
for (i = 0; i < len; ++i) {
|
swayc_t *item = *(swayc_t **)list_get(container->floating, i);
|
||||||
update_visibility_output(container->floating->items[i], output);
|
update_visibility_output(item, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -890,9 +886,9 @@ void update_visibility(swayc_t *container) {
|
||||||
case C_ROOT:
|
case C_ROOT:
|
||||||
container->visible = true;
|
container->visible = true;
|
||||||
if (container->children) {
|
if (container->children) {
|
||||||
int i, len = container->children->length;
|
for (size_t i = 0; i < container->children->length; ++i) {
|
||||||
for (i = 0; i < len; ++i) {
|
swayc_t *item = *(swayc_t **)list_get(container->children, i);
|
||||||
update_visibility(container->children->items[i]);
|
update_visibility(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
@ -900,9 +896,9 @@ void update_visibility(swayc_t *container) {
|
||||||
case C_OUTPUT:
|
case C_OUTPUT:
|
||||||
container->visible = true;
|
container->visible = true;
|
||||||
if (container->children) {
|
if (container->children) {
|
||||||
int i, len = container->children->length;
|
for (size_t i = 0; i < container->children->length; ++i) {
|
||||||
for (i = 0; i < len; ++i) {
|
swayc_t *item = *(swayc_t **)list_get(container->children, i);
|
||||||
update_visibility_output(container->children->items[i], container->handle);
|
update_visibility_output(item, container->handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
@ -983,8 +979,8 @@ swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout) {
|
||||||
layout == L_AUTO_LEFT || layout == L_AUTO_RIGHT
|
layout == L_AUTO_LEFT || layout == L_AUTO_RIGHT
|
||||||
? L_HORIZ : L_VERT;
|
? L_HORIZ : L_VERT;
|
||||||
if (new_major != prev_major) {
|
if (new_major != prev_major) {
|
||||||
for (int i = 0; i < container->children->length; ++i) {
|
for (size_t i = 0; i < container->children->length; ++i) {
|
||||||
swayc_t *child = container->children->items[i];
|
swayc_t *child = *(swayc_t **)list_get(container->children, i);
|
||||||
double h = child->height;
|
double h = child->height;
|
||||||
child->height = child->width;
|
child->height = child->width;
|
||||||
child->width = h;
|
child->width = h;
|
||||||
|
|
|
||||||
|
|
@ -52,8 +52,8 @@ static void free_crit_token(struct crit_token *crit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_crit_tokens(list_t *crit_tokens) {
|
static void free_crit_tokens(list_t *crit_tokens) {
|
||||||
for (int i = 0; i < crit_tokens->length; i++) {
|
for (size_t i = 0; i < crit_tokens->length; i++) {
|
||||||
free_crit_token(crit_tokens->items[i]);
|
free_crit_token(*(struct crit_token **)list_get(crit_tokens, i));
|
||||||
}
|
}
|
||||||
list_free(crit_tokens);
|
list_free(crit_tokens);
|
||||||
}
|
}
|
||||||
|
|
@ -223,13 +223,13 @@ char *extract_crit_tokens(list_t *tokens, const char * const criteria) {
|
||||||
goto ect_cleanup;
|
goto ect_cleanup;
|
||||||
} else if (token->type == CRIT_URGENT || crit_is_focused(value)) {
|
} else if (token->type == CRIT_URGENT || crit_is_focused(value)) {
|
||||||
sway_log(L_DEBUG, "%s -> \"%s\"", name, value);
|
sway_log(L_DEBUG, "%s -> \"%s\"", name, value);
|
||||||
list_add(tokens, token);
|
list_add(tokens, &token);
|
||||||
} else if((error = generate_regex(&token->regex, value))) {
|
} else if((error = generate_regex(&token->regex, value))) {
|
||||||
free_crit_token(token);
|
free_crit_token(token);
|
||||||
goto ect_cleanup;
|
goto ect_cleanup;
|
||||||
} else {
|
} else {
|
||||||
sway_log(L_DEBUG, "%s -> /%s/", name, value);
|
sway_log(L_DEBUG, "%s -> /%s/", name, value);
|
||||||
list_add(tokens, token);
|
list_add(tokens, &token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ect_cleanup:
|
ect_cleanup:
|
||||||
|
|
@ -238,8 +238,10 @@ ect_cleanup:
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int regex_cmp(const char *item, const pcre *regex) {
|
static int regex_cmp(const void *key, const void *item) {
|
||||||
return pcre_exec(regex, NULL, item, strlen(item), 0, 0, NULL, 0);
|
const pcre *regex = key;
|
||||||
|
const char *str = item;
|
||||||
|
return pcre_exec(regex, NULL, str, strlen(str), 0, 0, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// test a single view if it matches list of criteria tokens (all of them).
|
// test a single view if it matches list of criteria tokens (all of them).
|
||||||
|
|
@ -247,9 +249,9 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) {
|
||||||
if (cont->type != C_VIEW) {
|
if (cont->type != C_VIEW) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int matches = 0;
|
size_t matches = 0;
|
||||||
for (int i = 0; i < tokens->length; i++) {
|
for (size_t i = 0; i < tokens->length; i++) {
|
||||||
struct crit_token *crit = tokens->items[i];
|
struct crit_token *crit = *(struct crit_token **)list_get(tokens, i);
|
||||||
switch (crit->type) {
|
switch (crit->type) {
|
||||||
case CRIT_CLASS:
|
case CRIT_CLASS:
|
||||||
if (!cont->class) {
|
if (!cont->class) {
|
||||||
|
|
@ -264,9 +266,9 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CRIT_CON_MARK:
|
case CRIT_CON_MARK:
|
||||||
if (crit->regex && cont->marks && (list_seq_find(cont->marks, (int (*)(const void *, const void *))regex_cmp, crit->regex) != -1)) {
|
if (crit->regex && cont->marks && (list_lsearch(cont->marks, regex_cmp, crit->regex, NULL) != -1)) {
|
||||||
// Make sure it isn't matching the NUL string
|
// Make sure it isn't matching the NUL string
|
||||||
if ((strcmp(crit->raw, "") == 0) == (list_seq_find(cont->marks, (int (*)(const void *, const void *))strcmp, "") != -1)) {
|
if ((strcmp(crit->raw, "") == 0) == (list_lsearch(cont->marks, (int (*)(const void *, const void *))strcmp, "", NULL) != -1)) {
|
||||||
++matches;
|
++matches;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -330,15 +332,15 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) {
|
||||||
return matches == tokens->length;
|
return matches == tokens->length;
|
||||||
}
|
}
|
||||||
|
|
||||||
int criteria_cmp(const void *a, const void *b) {
|
int criteria_cmp(const void *key, const void *item) {
|
||||||
if (a == b) {
|
if (key == item) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (!a) {
|
} else if (!item) {
|
||||||
return -1;
|
return -1;
|
||||||
} else if (!b) {
|
} else if (!key) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
const struct criteria *crit_a = a, *crit_b = b;
|
const struct criteria *crit_a = item, *crit_b = key;
|
||||||
int cmp = lenient_strcmp(crit_a->cmdlist, crit_b->cmdlist);
|
int cmp = lenient_strcmp(crit_a->cmdlist, crit_b->cmdlist);
|
||||||
if (cmp != 0) {
|
if (cmp != 0) {
|
||||||
return cmp;
|
return cmp;
|
||||||
|
|
@ -360,8 +362,8 @@ void free_criteria(struct criteria *crit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool criteria_any(swayc_t *cont, list_t *criteria) {
|
bool criteria_any(swayc_t *cont, list_t *criteria) {
|
||||||
for (int i = 0; i < criteria->length; i++) {
|
for (size_t i = 0; i < criteria->length; i++) {
|
||||||
struct criteria *bc = criteria->items[i];
|
struct criteria *bc = *(struct criteria **)list_get(criteria, i);
|
||||||
if (criteria_test(cont, bc->tokens)) {
|
if (criteria_test(cont, bc->tokens)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -370,9 +372,9 @@ bool criteria_any(swayc_t *cont, list_t *criteria) {
|
||||||
}
|
}
|
||||||
|
|
||||||
list_t *criteria_for(swayc_t *cont) {
|
list_t *criteria_for(swayc_t *cont) {
|
||||||
list_t *criteria = config->criteria, *matches = create_list();
|
list_t *matches = list_new(sizeof(struct criteria *), 0);
|
||||||
for (int i = 0; i < criteria->length; i++) {
|
for (size_t i = 0; i < config->criteria->length; i++) {
|
||||||
struct criteria *bc = criteria->items[i];
|
struct criteria *bc = *(struct criteria **)list_get(config->criteria, i);
|
||||||
if (criteria_test(cont, bc->tokens)) {
|
if (criteria_test(cont, bc->tokens)) {
|
||||||
list_add(matches, bc);
|
list_add(matches, bc);
|
||||||
}
|
}
|
||||||
|
|
@ -385,15 +387,16 @@ struct list_tokens {
|
||||||
list_t *tokens;
|
list_t *tokens;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void container_match_add(swayc_t *container, struct list_tokens *list_tokens) {
|
static void container_match_add(swayc_t *container, void *arg) {
|
||||||
|
struct list_tokens *list_tokens = arg;
|
||||||
if (criteria_test(container, list_tokens->tokens)) {
|
if (criteria_test(container, list_tokens->tokens)) {
|
||||||
list_add(list_tokens->list, container);
|
list_add(list_tokens->list, container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
list_t *container_for(list_t *tokens) {
|
list_t *container_for(list_t *tokens) {
|
||||||
struct list_tokens list_tokens = (struct list_tokens){create_list(), tokens};
|
struct list_tokens list_tokens = {list_new(sizeof(swayc_t *), 0), tokens};
|
||||||
|
|
||||||
container_map(&root_container, (void (*)(swayc_t *, void *))container_match_add, &list_tokens);
|
container_map(&root_container, container_match_add, &list_tokens);
|
||||||
|
|
||||||
return list_tokens.list;
|
return list_tokens.list;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ static void container_log(const swayc_t *c, int depth) {
|
||||||
fprintf(stderr, "x:%4.f|y:%4.f|", c->x, c->y);
|
fprintf(stderr, "x:%4.f|y:%4.f|", c->x, c->y);
|
||||||
fprintf(stderr, "g:%3d|",c->gaps);
|
fprintf(stderr, "g:%3d|",c->gaps);
|
||||||
fprintf(stderr, "vis:%c|", c->visible?'t':'f');
|
fprintf(stderr, "vis:%c|", c->visible?'t':'f');
|
||||||
fprintf(stderr, "children:%2d|",c->children?c->children->length:0);
|
fprintf(stderr, "children:%2zu|",c->children?c->children->length:0);
|
||||||
fprintf(stderr, "name:%.16s\n", c->name);
|
fprintf(stderr, "name:%.16s\n", c->name);
|
||||||
}
|
}
|
||||||
void layout_log(const swayc_t *c, int depth) {
|
void layout_log(const swayc_t *c, int depth) {
|
||||||
|
|
@ -59,7 +59,7 @@ void layout_log(const swayc_t *c, int depth) {
|
||||||
for (i = 0; i < e; ++i) {
|
for (i = 0; i < e; ++i) {
|
||||||
fputc('|',stderr);
|
fputc('|',stderr);
|
||||||
for (d = 0; d < depth; ++d) fputc('-', stderr);
|
for (d = 0; d < depth; ++d) fputc('-', stderr);
|
||||||
layout_log(c->children->items[i], depth + 1);
|
layout_log(*(swayc_t **)list_get(c->children, i), depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (c->type == C_WORKSPACE) {
|
if (c->type == C_WORKSPACE) {
|
||||||
|
|
@ -68,7 +68,7 @@ void layout_log(const swayc_t *c, int depth) {
|
||||||
for (i = 0; i < e; ++i) {
|
for (i = 0; i < e; ++i) {
|
||||||
fputc('|',stderr);
|
fputc('|',stderr);
|
||||||
for (d = 0; d < depth; ++d) fputc('=', stderr);
|
for (d = 0; d < depth; ++d) fputc('=', stderr);
|
||||||
layout_log(c->floating->items[i], depth + 1);
|
layout_log(*(swayc_t **)list_get(c->floating, i), depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@
|
||||||
struct desktop_shell_state desktop_shell;
|
struct desktop_shell_state desktop_shell;
|
||||||
|
|
||||||
static struct panel_config *find_or_create_panel_config(struct wl_resource *resource) {
|
static struct panel_config *find_or_create_panel_config(struct wl_resource *resource) {
|
||||||
for (int i = 0; i < desktop_shell.panels->length; i++) {
|
for (size_t i = 0; i < desktop_shell.panels->length; i++) {
|
||||||
struct panel_config *conf = desktop_shell.panels->items[i];
|
struct panel_config *conf = *(struct panel_config **)list_get(desktop_shell.panels, i);
|
||||||
if (conf->wl_resource == resource) {
|
if (conf->wl_resource == resource) {
|
||||||
sway_log(L_DEBUG, "Found existing panel config for resource %p", resource);
|
sway_log(L_DEBUG, "Found existing panel config for resource %p", resource);
|
||||||
return conf;
|
return conf;
|
||||||
|
|
@ -35,11 +35,10 @@ static struct panel_config *find_or_create_panel_config(struct wl_resource *reso
|
||||||
|
|
||||||
void background_surface_destructor(struct wl_resource *resource) {
|
void background_surface_destructor(struct wl_resource *resource) {
|
||||||
sway_log(L_DEBUG, "Background surface killed");
|
sway_log(L_DEBUG, "Background surface killed");
|
||||||
int i;
|
for (size_t i = 0; i < desktop_shell.backgrounds->length; ++i) {
|
||||||
for (i = 0; i < desktop_shell.backgrounds->length; ++i) {
|
struct background_config *config = *(struct background_config **)list_get(desktop_shell.backgrounds, i);
|
||||||
struct background_config *config = desktop_shell.backgrounds->items[i];
|
|
||||||
if (config->wl_surface_res == resource) {
|
if (config->wl_surface_res == resource) {
|
||||||
list_del(desktop_shell.backgrounds, i);
|
list_delete(desktop_shell.backgrounds, i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -47,11 +46,10 @@ void background_surface_destructor(struct wl_resource *resource) {
|
||||||
|
|
||||||
void panel_surface_destructor(struct wl_resource *resource) {
|
void panel_surface_destructor(struct wl_resource *resource) {
|
||||||
sway_log(L_DEBUG, "Panel surface killed");
|
sway_log(L_DEBUG, "Panel surface killed");
|
||||||
int i;
|
for (size_t i = 0; i < desktop_shell.panels->length; ++i) {
|
||||||
for (i = 0; i < desktop_shell.panels->length; ++i) {
|
struct panel_config *config = *(struct panel_config **)list_get(desktop_shell.panels, i);
|
||||||
struct panel_config *config = desktop_shell.panels->items[i];
|
|
||||||
if (config->wl_surface_res == resource) {
|
if (config->wl_surface_res == resource) {
|
||||||
list_del(desktop_shell.panels, i);
|
list_delete(desktop_shell.panels, i);
|
||||||
arrange_windows(&root_container, -1, -1);
|
arrange_windows(&root_container, -1, -1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -60,11 +58,10 @@ void panel_surface_destructor(struct wl_resource *resource) {
|
||||||
|
|
||||||
void lock_surface_destructor(struct wl_resource *resource) {
|
void lock_surface_destructor(struct wl_resource *resource) {
|
||||||
sway_log(L_DEBUG, "Lock surface killed");
|
sway_log(L_DEBUG, "Lock surface killed");
|
||||||
int i;
|
for (size_t i = 0; i < desktop_shell.lock_surfaces->length; ++i) {
|
||||||
for (i = 0; i < desktop_shell.lock_surfaces->length; ++i) {
|
struct wl_resource *surface = *(struct wl_resource **)list_get(desktop_shell.lock_surfaces, i);
|
||||||
struct wl_resource *surface = desktop_shell.lock_surfaces->items[i];
|
|
||||||
if (surface == resource) {
|
if (surface == resource) {
|
||||||
list_del(desktop_shell.lock_surfaces, i);
|
list_delete(desktop_shell.lock_surfaces, i);
|
||||||
arrange_windows(&root_container, -1, -1);
|
arrange_windows(&root_container, -1, -1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -322,9 +319,9 @@ static void gamma_control_manager_bind(struct wl_client *client, void *data,
|
||||||
|
|
||||||
void register_extensions(void) {
|
void register_extensions(void) {
|
||||||
wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 3, NULL, desktop_shell_bind);
|
wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 3, NULL, desktop_shell_bind);
|
||||||
desktop_shell.backgrounds = create_list();
|
desktop_shell.backgrounds = list_new(sizeof(struct background_config *), 0);
|
||||||
desktop_shell.panels = create_list();
|
desktop_shell.panels = list_new(sizeof(struct panel_config *), 0);
|
||||||
desktop_shell.lock_surfaces = create_list();
|
desktop_shell.lock_surfaces = list_new(sizeof(struct wl_resource *), 0);
|
||||||
desktop_shell.is_locked = false;
|
desktop_shell.is_locked = false;
|
||||||
wl_global_create(wlc_get_wl_display(), &lock_interface, 1, NULL, swaylock_bind);
|
wl_global_create(wlc_get_wl_display(), &lock_interface, 1, NULL, swaylock_bind);
|
||||||
wl_global_create(wlc_get_wl_display(), &gamma_control_manager_interface, 1,
|
wl_global_create(wlc_get_wl_display(), &gamma_control_manager_interface, 1,
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,7 @@ swayc_t *get_focused_float(swayc_t *ws) {
|
||||||
ws = swayc_active_workspace();
|
ws = swayc_active_workspace();
|
||||||
}
|
}
|
||||||
if (ws->floating->length) {
|
if (ws->floating->length) {
|
||||||
return ws->floating->items[ws->floating->length - 1];
|
return *(swayc_t **)list_get(ws->floating, ws->floating->length - 1);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
120
sway/handlers.c
120
sway/handlers.c
|
|
@ -35,9 +35,8 @@
|
||||||
#define EVENT_HANDLED true
|
#define EVENT_HANDLED true
|
||||||
|
|
||||||
static struct panel_config *if_panel_find_config(struct wl_client *client) {
|
static struct panel_config *if_panel_find_config(struct wl_client *client) {
|
||||||
int i;
|
for (size_t i = 0; i < desktop_shell.panels->length; i++) {
|
||||||
for (i = 0; i < desktop_shell.panels->length; i++) {
|
struct panel_config *config = *(struct panel_config **)list_get(desktop_shell.panels, i);
|
||||||
struct panel_config *config = desktop_shell.panels->items[i];
|
|
||||||
if (config->client == client) {
|
if (config->client == client) {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
@ -46,9 +45,8 @@ static struct panel_config *if_panel_find_config(struct wl_client *client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct background_config *if_background_find_config(struct wl_client *client) {
|
static struct background_config *if_background_find_config(struct wl_client *client) {
|
||||||
int i;
|
for (size_t i = 0; i < desktop_shell.backgrounds->length; i++) {
|
||||||
for (i = 0; i < desktop_shell.backgrounds->length; i++) {
|
struct background_config *config = *(struct background_config **)list_get(desktop_shell.backgrounds, i);
|
||||||
struct background_config *config = desktop_shell.backgrounds->items[i];
|
|
||||||
if (config->client == client) {
|
if (config->client == client) {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
@ -98,8 +96,8 @@ static void update_panel_geometry(struct panel_config *config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_panel_geometries(wlc_handle output) {
|
static void update_panel_geometries(wlc_handle output) {
|
||||||
for (int i = 0; i < desktop_shell.panels->length; i++) {
|
for (size_t i = 0; i < desktop_shell.panels->length; i++) {
|
||||||
struct panel_config *config = desktop_shell.panels->items[i];
|
struct panel_config *config = *(struct panel_config **)list_get(desktop_shell.panels, i);
|
||||||
if (config->output == output) {
|
if (config->output == output) {
|
||||||
update_panel_geometry(config);
|
update_panel_geometry(config);
|
||||||
}
|
}
|
||||||
|
|
@ -113,8 +111,8 @@ static void update_background_geometry(struct background_config *config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_background_geometries(wlc_handle output) {
|
static void update_background_geometries(wlc_handle output) {
|
||||||
for (int i = 0; i < desktop_shell.backgrounds->length; i++) {
|
for (size_t i = 0; i < desktop_shell.backgrounds->length; i++) {
|
||||||
struct background_config *config = desktop_shell.backgrounds->items[i];
|
struct background_config *config = *(struct background_config **)list_get(desktop_shell.backgrounds, i);
|
||||||
if (config->output == output) {
|
if (config->output == output) {
|
||||||
update_background_geometry(config);
|
update_background_geometry(config);
|
||||||
}
|
}
|
||||||
|
|
@ -132,12 +130,11 @@ static bool handle_input_created(struct libinput_device *device) {
|
||||||
}
|
}
|
||||||
sway_log(L_INFO, "Found input device (%s)", identifier);
|
sway_log(L_INFO, "Found input device (%s)", identifier);
|
||||||
|
|
||||||
list_add(input_devices, device);
|
list_add(input_devices, &device);
|
||||||
|
|
||||||
struct input_config *ic = NULL;
|
struct input_config *ic = NULL;
|
||||||
int i;
|
for (size_t i = 0; i < config->input_configs->length; ++i) {
|
||||||
for (i = 0; i < config->input_configs->length; ++i) {
|
struct input_config *cur = *(struct input_config **)list_get(config->input_configs, i);
|
||||||
struct input_config *cur = config->input_configs->items[i];
|
|
||||||
if (strcasecmp(identifier, cur->identifier) == 0) {
|
if (strcasecmp(identifier, cur->identifier) == 0) {
|
||||||
sway_log(L_DEBUG, "Matched input config for %s",
|
sway_log(L_DEBUG, "Matched input config for %s",
|
||||||
identifier);
|
identifier);
|
||||||
|
|
@ -157,11 +154,10 @@ static bool handle_input_created(struct libinput_device *device) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_input_destroyed(struct libinput_device *device) {
|
static void handle_input_destroyed(struct libinput_device *device) {
|
||||||
int i;
|
for (size_t i = 0; i < input_devices->length; ++i) {
|
||||||
list_t *list = input_devices;
|
struct libinput_device *item = *(struct libinput_device **)list_get(input_devices, i);
|
||||||
for (i = 0; i < list->length; ++i) {
|
if (item == device) {
|
||||||
if(((struct libinput_device *)list->items[i]) == device) {
|
list_delete(input_devices, i);
|
||||||
list_del(list, i);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -179,7 +175,7 @@ static bool handle_output_created(wlc_handle output) {
|
||||||
|
|
||||||
// Switch to workspace if we need to
|
// Switch to workspace if we need to
|
||||||
if (swayc_active_workspace() == NULL) {
|
if (swayc_active_workspace() == NULL) {
|
||||||
swayc_t *ws = op->children->items[0];
|
swayc_t *ws = *(swayc_t **)list_get(op->children, 0);
|
||||||
workspace_switch(ws);
|
workspace_switch(ws);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,21 +187,21 @@ static bool handle_output_created(wlc_handle output) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_output_destroyed(wlc_handle output) {
|
static void handle_output_destroyed(wlc_handle output) {
|
||||||
int i;
|
size_t i;
|
||||||
list_t *list = root_container.children;
|
list_t *list = root_container.children;
|
||||||
for (i = 0; i < list->length; ++i) {
|
for (i = 0; i < list->length; ++i) {
|
||||||
if (((swayc_t *)list->items[i])->handle == output) {
|
if ((*(swayc_t **)list_get(list, i))->handle == output) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i < list->length) {
|
if (i < list->length) {
|
||||||
destroy_output(list->items[i]);
|
destroy_output(*(swayc_t **)list_get(list, i));
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (list->length > 0) {
|
if (list->length > 0) {
|
||||||
// switch to other outputs active workspace
|
// switch to other outputs active workspace
|
||||||
workspace_switch(((swayc_t *)root_container.children->items[0])->focused);
|
workspace_switch((*(swayc_t **)list_get(root_container.children, 0))->focused);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -246,16 +242,16 @@ static void handle_output_focused(wlc_handle output, bool focus) {
|
||||||
|
|
||||||
static void ws_cleanup() {
|
static void ws_cleanup() {
|
||||||
swayc_t *op, *ws;
|
swayc_t *op, *ws;
|
||||||
int i = 0, j;
|
size_t i = 0, j;
|
||||||
if (!root_container.children)
|
if (!root_container.children)
|
||||||
return;
|
return;
|
||||||
while (i < root_container.children->length) {
|
while (i < root_container.children->length) {
|
||||||
op = root_container.children->items[i++];
|
op = *(swayc_t **)list_get(root_container.children, i++);
|
||||||
if (!op->children)
|
if (!op->children)
|
||||||
continue;
|
continue;
|
||||||
j = 0;
|
j = 0;
|
||||||
while (j < op->children->length) {
|
while (j < op->children->length) {
|
||||||
ws = op->children->items[j++];
|
ws = *(swayc_t **)list_get(op->children, j++);
|
||||||
if (ws->children->length == 0 && ws->floating->length == 0 && ws != op->focused) {
|
if (ws->children->length == 0 && ws->floating->length == 0 && ws != op->focused) {
|
||||||
if (destroy_workspace(ws)) {
|
if (destroy_workspace(ws)) {
|
||||||
j--;
|
j--;
|
||||||
|
|
@ -403,7 +399,7 @@ static bool handle_view_created(wlc_handle handle) {
|
||||||
// TODO find a better way of doing this
|
// TODO find a better way of doing this
|
||||||
// Or to focused container
|
// Or to focused container
|
||||||
else {
|
else {
|
||||||
focused = get_focused_container(focused->parent->children->items[0]);
|
focused = get_focused_container(*(swayc_t **)list_get(focused->parent->children, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -466,8 +462,8 @@ static bool handle_view_created(wlc_handle handle) {
|
||||||
arrange_windows(output, -1, -1);
|
arrange_windows(output, -1, -1);
|
||||||
// check if it matches for_window in config and execute if so
|
// check if it matches for_window in config and execute if so
|
||||||
list_t *criteria = criteria_for(newview);
|
list_t *criteria = criteria_for(newview);
|
||||||
for (int i = 0; i < criteria->length; i++) {
|
for (size_t i = 0; i < criteria->length; i++) {
|
||||||
struct criteria *crit = criteria->items[i];
|
struct criteria *crit = *(struct criteria **)list_get(criteria, i);
|
||||||
sway_log(L_DEBUG, "for_window '%s' matches new view %p, cmd: '%s'",
|
sway_log(L_DEBUG, "for_window '%s' matches new view %p, cmd: '%s'",
|
||||||
crit->crit_raw, newview, crit->cmdlist);
|
crit->crit_raw, newview, crit->cmdlist);
|
||||||
struct cmd_results *res = handle_command(crit->cmdlist, CONTEXT_CRITERIA);
|
struct cmd_results *res = handle_command(crit->cmdlist, CONTEXT_CRITERIA);
|
||||||
|
|
@ -492,7 +488,7 @@ static bool handle_view_created(wlc_handle handle) {
|
||||||
}
|
}
|
||||||
*h = handle;
|
*h = handle;
|
||||||
sway_log(L_DEBUG, "Adding unmanaged window %p to %p", h, output->unmanaged);
|
sway_log(L_DEBUG, "Adding unmanaged window %p to %p", h, output->unmanaged);
|
||||||
list_add(output->unmanaged, h);
|
list_add(output->unmanaged, &h);
|
||||||
wlc_view_set_mask(handle, VISIBLE);
|
wlc_view_set_mask(handle, VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -559,14 +555,12 @@ static void handle_view_destroyed(wlc_handle handle) {
|
||||||
ipc_event_window(parent, "close");
|
ipc_event_window(parent, "close");
|
||||||
} else {
|
} else {
|
||||||
// Is it unmanaged?
|
// Is it unmanaged?
|
||||||
int i;
|
for (size_t i = 0; i < root_container.children->length; ++i) {
|
||||||
for (i = 0; i < root_container.children->length; ++i) {
|
swayc_t *output = *(swayc_t **)list_get(root_container.children, i);
|
||||||
swayc_t *output = root_container.children->items[i];
|
for (size_t j = 0; j < output->unmanaged->length; ++j) {
|
||||||
int j;
|
wlc_handle *_handle = *(wlc_handle **)list_get(output->unmanaged, j);
|
||||||
for (j = 0; j < output->unmanaged->length; ++j) {
|
|
||||||
wlc_handle *_handle = output->unmanaged->items[j];
|
|
||||||
if (*_handle == handle) {
|
if (*_handle == handle) {
|
||||||
list_del(output->unmanaged, j);
|
list_delete(output->unmanaged, j);
|
||||||
free(_handle);
|
free(_handle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -693,16 +687,15 @@ static void handle_binding_command(struct sway_binding *binding) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool handle_bindsym(struct sway_binding *binding, uint32_t keysym, uint32_t keycode) {
|
static bool handle_bindsym(struct sway_binding *binding, uint32_t keysym, uint32_t keycode) {
|
||||||
int i;
|
for (size_t i = 0; i < binding->keys->length; ++i) {
|
||||||
for (i = 0; i < binding->keys->length; ++i) {
|
|
||||||
if (binding->bindcode) {
|
if (binding->bindcode) {
|
||||||
xkb_keycode_t *key = binding->keys->items[i];
|
xkb_keycode_t *key = *(xkb_keycode_t **)list_get(binding->keys, i);
|
||||||
if (keycode == *key) {
|
if (keycode == *key) {
|
||||||
handle_binding_command(binding);
|
handle_binding_command(binding);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
xkb_keysym_t *key = binding->keys->items[i];
|
xkb_keysym_t *key = *(xkb_keysym_t **)list_get(binding->keys, i);
|
||||||
if (keysym == *key) {
|
if (keysym == *key) {
|
||||||
handle_binding_command(binding);
|
handle_binding_command(binding);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -715,15 +708,14 @@ static bool handle_bindsym(struct sway_binding *binding, uint32_t keysym, uint32
|
||||||
|
|
||||||
static bool valid_bindsym(struct sway_binding *binding) {
|
static bool valid_bindsym(struct sway_binding *binding) {
|
||||||
bool match = false;
|
bool match = false;
|
||||||
int i;
|
for (size_t i = 0; i < binding->keys->length; ++i) {
|
||||||
for (i = 0; i < binding->keys->length; ++i) {
|
|
||||||
if (binding->bindcode) {
|
if (binding->bindcode) {
|
||||||
xkb_keycode_t *key = binding->keys->items[i];
|
xkb_keycode_t *key = *(xkb_keycode_t **)list_get(binding->keys, i);
|
||||||
if ((match = check_key(0, *key)) == false) {
|
if ((match = check_key(0, *key)) == false) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
xkb_keysym_t *key = binding->keys->items[i];
|
xkb_keysym_t *key = *(xkb_keysym_t **)list_get(binding->keys, i);
|
||||||
if ((match = check_key(*key, 0)) == false) {
|
if ((match = check_key(*key, 0)) == false) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -735,7 +727,7 @@ static bool valid_bindsym(struct sway_binding *binding) {
|
||||||
|
|
||||||
static bool handle_bindsym_release(struct sway_binding *binding) {
|
static bool handle_bindsym_release(struct sway_binding *binding) {
|
||||||
if (binding->keys->length == 1) {
|
if (binding->keys->length == 1) {
|
||||||
xkb_keysym_t *key = binding->keys->items[0];
|
xkb_keysym_t *key = *(xkb_keysym_t **)list_get(binding->keys, 0);
|
||||||
if (check_released_key(*key)) {
|
if (check_released_key(*key)) {
|
||||||
handle_binding_command(binding);
|
handle_binding_command(binding);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -762,8 +754,6 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
||||||
struct wlc_modifiers no_mods = { 0, 0 };
|
struct wlc_modifiers no_mods = { 0, 0 };
|
||||||
uint32_t sym = tolower(wlc_keyboard_get_keysym_for_key(key, &no_mods));
|
uint32_t sym = tolower(wlc_keyboard_get_keysym_for_key(key, &no_mods));
|
||||||
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (state == WLC_KEY_STATE_PRESSED) {
|
if (state == WLC_KEY_STATE_PRESSED) {
|
||||||
press_key(sym, key);
|
press_key(sym, key);
|
||||||
} else { // WLC_KEY_STATE_RELEASED
|
} else { // WLC_KEY_STATE_RELEASED
|
||||||
|
|
@ -772,8 +762,8 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
||||||
|
|
||||||
// handle bar modifiers pressed/released
|
// handle bar modifiers pressed/released
|
||||||
uint32_t modifier;
|
uint32_t modifier;
|
||||||
for (i = 0; i < config->active_bar_modifiers->length; ++i) {
|
for (size_t i = 0; i < config->active_bar_modifiers->length; ++i) {
|
||||||
modifier = *(uint32_t *)config->active_bar_modifiers->items[i];
|
modifier = **(uint32_t **)list_get(config->active_bar_modifiers, i);
|
||||||
|
|
||||||
switch (modifier_state_changed(modifiers->mods, modifier)) {
|
switch (modifier_state_changed(modifiers->mods, modifier)) {
|
||||||
case MOD_STATE_PRESSED:
|
case MOD_STATE_PRESSED:
|
||||||
|
|
@ -788,14 +778,14 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
||||||
modifiers_state_update(modifiers->mods);
|
modifiers_state_update(modifiers->mods);
|
||||||
|
|
||||||
// handle bindings
|
// handle bindings
|
||||||
list_t *candidates = create_list();
|
list_t *candidates = list_new(sizeof(struct sway_binding *), 0);
|
||||||
for (i = 0; i < mode->bindings->length; ++i) {
|
for (size_t i = 0; i < mode->bindings->length; ++i) {
|
||||||
struct sway_binding *binding = mode->bindings->items[i];
|
struct sway_binding *binding = *(struct sway_binding **)list_get(mode->bindings, i);
|
||||||
if ((modifiers->mods ^ binding->modifiers) == 0) {
|
if ((modifiers->mods ^ binding->modifiers) == 0) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case WLC_KEY_STATE_PRESSED: {
|
case WLC_KEY_STATE_PRESSED: {
|
||||||
if (!binding->release && valid_bindsym(binding)) {
|
if (!binding->release && valid_bindsym(binding)) {
|
||||||
list_add(candidates, binding);
|
list_add(candidates, &binding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case WLC_KEY_STATE_RELEASED:
|
case WLC_KEY_STATE_RELEASED:
|
||||||
|
|
@ -808,8 +798,8 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < candidates->length; ++i) {
|
for (size_t i = 0; i < candidates->length; ++i) {
|
||||||
struct sway_binding *binding = candidates->items[i];
|
struct sway_binding *binding = *(struct sway_binding **)list_get(candidates, i);
|
||||||
if (state == WLC_KEY_STATE_PRESSED) {
|
if (state == WLC_KEY_STATE_PRESSED) {
|
||||||
if (!binding->release && handle_bindsym(binding, sym, key)) {
|
if (!binding->release && handle_bindsym(binding, sym, key)) {
|
||||||
list_free(candidates);
|
list_free(candidates);
|
||||||
|
|
@ -919,8 +909,8 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
|
||||||
|
|
||||||
struct sway_mode *mode = config->current_mode;
|
struct sway_mode *mode = config->current_mode;
|
||||||
// handle bindings
|
// handle bindings
|
||||||
for (int i = 0; i < mode->bindings->length; ++i) {
|
for (size_t i = 0; i < mode->bindings->length; ++i) {
|
||||||
struct sway_binding *binding = mode->bindings->items[i];
|
struct sway_binding *binding = *(struct sway_binding **)list_get(mode->bindings, i);
|
||||||
if ((modifiers->mods ^ binding->modifiers) == 0) {
|
if ((modifiers->mods ^ binding->modifiers) == 0) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case WLC_BUTTON_STATE_PRESSED: {
|
case WLC_BUTTON_STATE_PRESSED: {
|
||||||
|
|
@ -1014,10 +1004,10 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
|
||||||
}
|
}
|
||||||
// Send to front if floating
|
// Send to front if floating
|
||||||
if (pointer->is_floating) {
|
if (pointer->is_floating) {
|
||||||
int i;
|
for (size_t i = 0; i < pointer->parent->floating->length; i++) {
|
||||||
for (i = 0; i < pointer->parent->floating->length; i++) {
|
swayc_t *item = *(swayc_t **)list_get(pointer->parent->floating, i);
|
||||||
if (pointer->parent->floating->items[i] == pointer) {
|
if (item == pointer) {
|
||||||
list_del(pointer->parent->floating, i);
|
list_delete(pointer->parent->floating, i);
|
||||||
list_add(pointer->parent->floating, pointer);
|
list_add(pointer->parent->floating, pointer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1077,14 +1067,14 @@ static void handle_wlc_ready(void) {
|
||||||
// Execute commands until there are none left
|
// Execute commands until there are none left
|
||||||
config->active = true;
|
config->active = true;
|
||||||
while (config->cmd_queue->length) {
|
while (config->cmd_queue->length) {
|
||||||
char *line = config->cmd_queue->items[0];
|
char *line = *(char **)list_get(config->cmd_queue, 0);
|
||||||
struct cmd_results *res = handle_command(line, CONTEXT_CONFIG);
|
struct cmd_results *res = handle_command(line, CONTEXT_CONFIG);
|
||||||
if (res->status != CMD_SUCCESS) {
|
if (res->status != CMD_SUCCESS) {
|
||||||
sway_log(L_ERROR, "Error on line '%s': %s", line, res->error);
|
sway_log(L_ERROR, "Error on line '%s': %s", line, res->error);
|
||||||
}
|
}
|
||||||
free_cmd_results(res);
|
free_cmd_results(res);
|
||||||
free(line);
|
free(line);
|
||||||
list_del(config->cmd_queue, 0);
|
list_delete(config->cmd_queue, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -145,9 +145,9 @@ static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object)
|
||||||
|
|
||||||
// window is in the scratchpad ? changed : none
|
// window is in the scratchpad ? changed : none
|
||||||
static const char *ipc_json_get_scratchpad_state(swayc_t *c) {
|
static const char *ipc_json_get_scratchpad_state(swayc_t *c) {
|
||||||
int i;
|
for (size_t i = 0; i < scratchpad->length; i++) {
|
||||||
for (i = 0; i < scratchpad->length; i++) {
|
swayc_t *item = *(swayc_t **)list_get(scratchpad, i);
|
||||||
if (scratchpad->items[i] == c) {
|
if (item == c) {
|
||||||
return "changed";
|
return "changed";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -420,9 +420,8 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
|
||||||
// Add outputs if defined
|
// Add outputs if defined
|
||||||
if (bar->outputs && bar->outputs->length > 0) {
|
if (bar->outputs && bar->outputs->length > 0) {
|
||||||
json_object *outputs = json_object_new_array();
|
json_object *outputs = json_object_new_array();
|
||||||
int i;
|
for (size_t i = 0; i < bar->outputs->length; ++i) {
|
||||||
for (i = 0; i < bar->outputs->length; ++i) {
|
const char *name = *(char **)list_get(bar->outputs, i);
|
||||||
const char *name = bar->outputs->items[i];
|
|
||||||
json_object_array_add(outputs, json_object_new_string(name));
|
json_object_array_add(outputs, json_object_new_string(name));
|
||||||
}
|
}
|
||||||
json_object_object_add(json, "outputs", outputs);
|
json_object_object_add(json, "outputs", outputs);
|
||||||
|
|
@ -433,30 +432,30 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
|
||||||
|
|
||||||
json_object *ipc_json_describe_container_recursive(swayc_t *c) {
|
json_object *ipc_json_describe_container_recursive(swayc_t *c) {
|
||||||
json_object *object = ipc_json_describe_container(c);
|
json_object *object = ipc_json_describe_container(c);
|
||||||
int i;
|
|
||||||
|
|
||||||
json_object *floating = json_object_new_array();
|
json_object *floating = json_object_new_array();
|
||||||
if (c->type != C_VIEW && c->floating && c->floating->length > 0) {
|
if (c->type != C_VIEW && c->floating && c->floating->length > 0) {
|
||||||
for (i = 0; i < c->floating->length; ++i) {
|
for (size_t i = 0; i < c->floating->length; ++i) {
|
||||||
json_object_array_add(floating, ipc_json_describe_container_recursive(c->floating->items[i]));
|
swayc_t *item = *(swayc_t **)list_get(c->floating, i);
|
||||||
|
json_object_array_add(floating, ipc_json_describe_container_recursive(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
json_object_object_add(object, "floating_nodes", floating);
|
json_object_object_add(object, "floating_nodes", floating);
|
||||||
|
|
||||||
json_object *children = json_object_new_array();
|
json_object *children = json_object_new_array();
|
||||||
if (c->type != C_VIEW && c->children && c->children->length > 0) {
|
if (c->type != C_VIEW && c->children && c->children->length > 0) {
|
||||||
for (i = 0; i < c->children->length; ++i) {
|
for (size_t i = 0; i < c->children->length; ++i) {
|
||||||
json_object_array_add(children, ipc_json_describe_container_recursive(c->children->items[i]));
|
swayc_t *item = *(swayc_t **)list_get(c->children, i);
|
||||||
|
json_object_array_add(children, ipc_json_describe_container_recursive(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
json_object_object_add(object, "nodes", children);
|
json_object_object_add(object, "nodes", children);
|
||||||
|
|
||||||
if (c->type == C_ROOT) {
|
if (c->type == C_ROOT) {
|
||||||
json_object *scratchpad_json = json_object_new_array();
|
json_object *scratchpad_json = json_object_new_array();
|
||||||
if (scratchpad->length > 0) {
|
for (size_t i = 0; i < scratchpad->length; ++i) {
|
||||||
for (i = 0; i < scratchpad->length; ++i) {
|
swayc_t *item = *(swayc_t **)list_get(scratchpad, i);
|
||||||
json_object_array_add(scratchpad_json, ipc_json_describe_container_recursive(scratchpad->items[i]));
|
json_object_array_add(scratchpad_json, ipc_json_describe_container_recursive(item));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
json_object_object_add(object, "scratchpad", scratchpad_json);
|
json_object_object_add(object, "scratchpad", scratchpad_json);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,8 +92,8 @@ void ipc_init(void) {
|
||||||
setenv("I3SOCK", ipc_sockaddr->sun_path, 1);
|
setenv("I3SOCK", ipc_sockaddr->sun_path, 1);
|
||||||
setenv("SWAYSOCK", ipc_sockaddr->sun_path, 1);
|
setenv("SWAYSOCK", ipc_sockaddr->sun_path, 1);
|
||||||
|
|
||||||
ipc_client_list = create_list();
|
ipc_client_list = list_new(sizeof(struct ipc_client *), 0);
|
||||||
ipc_get_pixel_requests = create_list();
|
ipc_get_pixel_requests = list_new(sizeof(struct get_pixels_request), 0);
|
||||||
|
|
||||||
ipc_event_source = wlc_event_loop_add_fd(ipc_socket, WLC_EVENT_READABLE, ipc_handle_connection, NULL);
|
ipc_event_source = wlc_event_loop_add_fd(ipc_socket, WLC_EVENT_READABLE, ipc_handle_connection, NULL);
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +183,7 @@ int ipc_handle_connection(int fd, uint32_t mask, void *data) {
|
||||||
pid_t pid = get_client_pid(client->fd);
|
pid_t pid = get_client_pid(client->fd);
|
||||||
client->security_policy = get_ipc_policy_mask(pid);
|
client->security_policy = get_ipc_policy_mask(pid);
|
||||||
|
|
||||||
list_add(ipc_client_list, client);
|
list_add(ipc_client_list, &client);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -260,9 +260,9 @@ void ipc_client_disconnect(struct ipc_client *client) {
|
||||||
|
|
||||||
sway_log(L_INFO, "IPC Client %d disconnected", client->fd);
|
sway_log(L_INFO, "IPC Client %d disconnected", client->fd);
|
||||||
wlc_event_source_remove(client->event_source);
|
wlc_event_source_remove(client->event_source);
|
||||||
int i = 0;
|
size_t i = 0;
|
||||||
while (i < ipc_client_list->length && ipc_client_list->items[i] != client) i++;
|
while (i < ipc_client_list->length && *(struct ipc_client **)list_get(ipc_client_list, i) != client) i++;
|
||||||
list_del(ipc_client_list, i);
|
list_delete(ipc_client_list, i);
|
||||||
close(client->fd);
|
close(client->fd);
|
||||||
free(client);
|
free(client);
|
||||||
}
|
}
|
||||||
|
|
@ -280,12 +280,11 @@ void ipc_get_pixels(wlc_handle output) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
list_t *unhandled = create_list();
|
list_t *unhandled = list_new(sizeof(struct get_pixels_request *), 0);
|
||||||
|
|
||||||
struct get_pixels_request *req;
|
struct get_pixels_request *req;
|
||||||
int i;
|
for (size_t i = 0; i < ipc_get_pixel_requests->length; ++i) {
|
||||||
for (i = 0; i < ipc_get_pixel_requests->length; ++i) {
|
req = *(struct get_pixels_request **)list_get(ipc_get_pixel_requests, i);
|
||||||
req = ipc_get_pixel_requests->items[i];
|
|
||||||
if (req->output != output) {
|
if (req->output != output) {
|
||||||
list_add(unhandled, req);
|
list_add(unhandled, req);
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -421,8 +420,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
|
||||||
}
|
}
|
||||||
json_object *inputs = json_object_new_array();
|
json_object *inputs = json_object_new_array();
|
||||||
if (input_devices) {
|
if (input_devices) {
|
||||||
for(int i = 0; i<input_devices->length; i++) {
|
for(size_t i = 0; i<input_devices->length; i++) {
|
||||||
struct libinput_device *device = input_devices->items[i];
|
struct libinput_device *device = *(struct libinput_device **)list_get(input_devices, i);
|
||||||
json_object_array_add(inputs, ipc_json_describe_input(device));
|
json_object_array_add(inputs, ipc_json_describe_input(device));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -520,7 +519,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
|
||||||
req->client = client;
|
req->client = client;
|
||||||
req->output = output->handle;
|
req->output = output->handle;
|
||||||
req->geo = g;
|
req->geo = g;
|
||||||
list_add(ipc_get_pixel_requests, req);
|
list_add(ipc_get_pixel_requests, &req);
|
||||||
wlc_output_schedule_render(output->handle);
|
wlc_output_schedule_render(output->handle);
|
||||||
goto exit_cleanup;
|
goto exit_cleanup;
|
||||||
}
|
}
|
||||||
|
|
@ -533,9 +532,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
|
||||||
if (!buf[0]) {
|
if (!buf[0]) {
|
||||||
// Send list of configured bar IDs
|
// Send list of configured bar IDs
|
||||||
json_object *bars = json_object_new_array();
|
json_object *bars = json_object_new_array();
|
||||||
int i;
|
for (size_t i = 0; i < config->bars->length; ++i) {
|
||||||
for (i = 0; i < config->bars->length; ++i) {
|
struct bar_config *bar = *(struct bar_config **)list_get(config->bars, i);
|
||||||
struct bar_config *bar = config->bars->items[i];
|
|
||||||
json_object_array_add(bars, json_object_new_string(bar->id));
|
json_object_array_add(bars, json_object_new_string(bar->id));
|
||||||
}
|
}
|
||||||
const char *json_string = json_object_to_json_string(bars);
|
const char *json_string = json_object_to_json_string(bars);
|
||||||
|
|
@ -544,9 +542,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
|
||||||
} else {
|
} else {
|
||||||
// Send particular bar's details
|
// Send particular bar's details
|
||||||
struct bar_config *bar = NULL;
|
struct bar_config *bar = NULL;
|
||||||
int i;
|
for (size_t i = 0; i < config->bars->length; ++i) {
|
||||||
for (i = 0; i < config->bars->length; ++i) {
|
bar = *(struct bar_config **)list_get(config->bars, i);
|
||||||
bar = config->bars->items[i];
|
|
||||||
if (strcmp(buf, bar->id) == 0) {
|
if (strcmp(buf, bar->id) == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -626,8 +623,8 @@ void ipc_get_outputs_callback(swayc_t *container, void *data) {
|
||||||
static void ipc_get_marks_callback(swayc_t *container, void *data) {
|
static void ipc_get_marks_callback(swayc_t *container, void *data) {
|
||||||
json_object *object = (json_object *)data;
|
json_object *object = (json_object *)data;
|
||||||
if (container->marks) {
|
if (container->marks) {
|
||||||
for (int i = 0; i < container->marks->length; ++i) {
|
for (size_t i = 0; i < container->marks->length; ++i) {
|
||||||
char *mark = (char *)container->marks->items[i];
|
char *mark = *(char **)list_get(container->marks, i);
|
||||||
json_object_array_add(object, json_object_new_string(mark));
|
json_object_array_add(object, json_object_new_string(mark));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -654,10 +651,8 @@ void ipc_send_event(const char *json_string, enum ipc_command_type event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
for (size_t i = 0; i < ipc_client_list->length; i++) {
|
||||||
struct ipc_client *client;
|
struct ipc_client *client = *(struct ipc_client **)list_get(ipc_client_list, i);
|
||||||
for (i = 0; i < ipc_client_list->length; i++) {
|
|
||||||
client = ipc_client_list->items[i];
|
|
||||||
if (!(client->security_policy & security_mask)) {
|
if (!(client->security_policy & security_mask)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -765,9 +760,8 @@ void ipc_event_binding_keyboard(struct sway_binding *sb) {
|
||||||
const char *names[10];
|
const char *names[10];
|
||||||
|
|
||||||
int len = get_modifier_names(names, sb->modifiers);
|
int len = get_modifier_names(names, sb->modifiers);
|
||||||
int i;
|
|
||||||
json_object *modifiers = json_object_new_array();
|
json_object *modifiers = json_object_new_array();
|
||||||
for (i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
json_object_array_add(modifiers, json_object_new_string(names[i]));
|
json_object_array_add(modifiers, json_object_new_string(names[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -780,8 +774,8 @@ void ipc_event_binding_keyboard(struct sway_binding *sb) {
|
||||||
|
|
||||||
if (sb->bindcode) { // bindcode: populate input_codes
|
if (sb->bindcode) { // bindcode: populate input_codes
|
||||||
uint32_t keycode;
|
uint32_t keycode;
|
||||||
for (i = 0; i < sb->keys->length; ++i) {
|
for (size_t i = 0; i < sb->keys->length; ++i) {
|
||||||
keycode = *(uint32_t *)sb->keys->items[i];
|
keycode = **(uint32_t **)list_get(sb->keys, i);
|
||||||
json_object_array_add(input_codes, json_object_new_int(keycode));
|
json_object_array_add(input_codes, json_object_new_int(keycode));
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
input_code = keycode;
|
input_code = keycode;
|
||||||
|
|
@ -790,8 +784,8 @@ void ipc_event_binding_keyboard(struct sway_binding *sb) {
|
||||||
} else { // bindsym: populate symbols
|
} else { // bindsym: populate symbols
|
||||||
uint32_t keysym;
|
uint32_t keysym;
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
for (i = 0; i < sb->keys->length; ++i) {
|
for (size_t i = 0; i < sb->keys->length; ++i) {
|
||||||
keysym = *(uint32_t *)sb->keys->items[i];
|
keysym = **(uint32_t **)list_get(sb->keys, i);
|
||||||
if (xkb_keysym_get_name(keysym, buffer, 64) > 0) {
|
if (xkb_keysym_get_name(keysym, buffer, 64) > 0) {
|
||||||
json_object *str = json_object_new_string(buffer);
|
json_object *str = json_object_new_string(buffer);
|
||||||
json_object_array_add(symbols, str);
|
json_object_array_add(symbols, str);
|
||||||
|
|
|
||||||
201
sway/layout.c
201
sway/layout.c
|
|
@ -27,11 +27,11 @@ void init_layout(void) {
|
||||||
root_container.type = C_ROOT;
|
root_container.type = C_ROOT;
|
||||||
root_container.layout = L_NONE;
|
root_container.layout = L_NONE;
|
||||||
root_container.name = strdup("root");
|
root_container.name = strdup("root");
|
||||||
root_container.children = create_list();
|
root_container.children = list_new(sizeof(swayc_t *), 0);
|
||||||
root_container.handle = -1;
|
root_container.handle = -1;
|
||||||
root_container.visible = true;
|
root_container.visible = true;
|
||||||
current_focus = &root_container;
|
current_focus = &root_container;
|
||||||
scratchpad = create_list();
|
scratchpad = list_new(sizeof(swayc_t *), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int index_child(const swayc_t *child) {
|
int index_child(const swayc_t *child) {
|
||||||
|
|
@ -40,14 +40,16 @@ int index_child(const swayc_t *child) {
|
||||||
if (!child->is_floating) {
|
if (!child->is_floating) {
|
||||||
len = parent->children->length;
|
len = parent->children->length;
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
if (parent->children->items[i] == child) {
|
swayc_t *item = *(swayc_t **)list_get(parent->children, i);
|
||||||
|
if (item == child) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
len = parent->floating->length;
|
len = parent->floating->length;
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
if (parent->floating->items[i] == child) {
|
swayc_t *item = *(swayc_t **)list_get(parent->floating, i);
|
||||||
|
if (item == child) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -80,14 +82,11 @@ static double *get_width(swayc_t *cont) {
|
||||||
return &cont->width;
|
return &cont->width;
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert_child(swayc_t *parent, swayc_t *child, int index) {
|
void insert_child(swayc_t *parent, swayc_t *child, size_t index) {
|
||||||
if (index > parent->children->length) {
|
if (index > parent->children->length) {
|
||||||
index = parent->children->length;
|
index = parent->children->length;
|
||||||
}
|
}
|
||||||
if (index < 0) {
|
list_insert(parent->children, index, &child);
|
||||||
index = 0;
|
|
||||||
}
|
|
||||||
list_insert(parent->children, index, child);
|
|
||||||
child->parent = parent;
|
child->parent = parent;
|
||||||
if (!parent->focused) {
|
if (!parent->focused) {
|
||||||
parent->focused = child;
|
parent->focused = child;
|
||||||
|
|
@ -106,21 +105,21 @@ void insert_child(swayc_t *parent, swayc_t *child, int index) {
|
||||||
get_maj_dim = get_height;
|
get_maj_dim = get_height;
|
||||||
get_min_dim = get_width;
|
get_min_dim = get_width;
|
||||||
}
|
}
|
||||||
for (int i = index; i < parent->children->length;) {
|
for (size_t i = index; i < parent->children->length;) {
|
||||||
int start = auto_group_start_index(parent, i);
|
size_t start = auto_group_start_index(parent, i);
|
||||||
int end = auto_group_end_index(parent, i);
|
size_t end = auto_group_end_index(parent, i);
|
||||||
swayc_t *first = parent->children->items[start];
|
swayc_t *first = *(swayc_t **)list_get(parent->children, start);
|
||||||
if (start + 1 < parent->children->length) {
|
if (start + 1 < parent->children->length) {
|
||||||
/* preserve the group's dimension along major axis */
|
/* preserve the group's dimension along major axis */
|
||||||
*get_maj_dim(first) = *get_maj_dim(parent->children->items[start + 1]);
|
*get_maj_dim(first) = *get_maj_dim(*(swayc_t **)list_get(parent->children, start + 1));
|
||||||
} else {
|
} else {
|
||||||
/* new group, let the apply_layout handle it */
|
/* new group, let the apply_layout handle it */
|
||||||
first->height = first->width = 0;
|
first->height = first->width = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
double remaining = *get_min_dim(parent);
|
double remaining = *get_min_dim(parent);
|
||||||
for (int j = end - 1; j > start; --j) {
|
for (size_t j = end - 1; j > start; --j) {
|
||||||
swayc_t *sibling = parent->children->items[j];
|
swayc_t *sibling = *(swayc_t **)list_get(parent->children, j);
|
||||||
if (sibling == child) {
|
if (sibling == child) {
|
||||||
/* the inserted child won't yet have its minor
|
/* the inserted child won't yet have its minor
|
||||||
dimension set */
|
dimension set */
|
||||||
|
|
@ -184,9 +183,9 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) {
|
||||||
}
|
}
|
||||||
int i = index_child(child);
|
int i = index_child(child);
|
||||||
if (child->is_floating) {
|
if (child->is_floating) {
|
||||||
parent->floating->items[i] = new_child;
|
*(swayc_t **)list_get(parent->floating, i) = new_child;
|
||||||
} else {
|
} else {
|
||||||
parent->children->items[i] = new_child;
|
*(swayc_t **)list_get(parent->children, i) = new_child;
|
||||||
}
|
}
|
||||||
// Set parent and focus for new_child
|
// Set parent and focus for new_child
|
||||||
new_child->parent = child->parent;
|
new_child->parent = child->parent;
|
||||||
|
|
@ -213,21 +212,23 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) {
|
||||||
}
|
}
|
||||||
|
|
||||||
swayc_t *remove_child(swayc_t *child) {
|
swayc_t *remove_child(swayc_t *child) {
|
||||||
int i;
|
size_t i;
|
||||||
swayc_t *parent = child->parent;
|
swayc_t *parent = child->parent;
|
||||||
if (child->is_floating) {
|
if (child->is_floating) {
|
||||||
// Special case for floating views
|
// Special case for floating views
|
||||||
for (i = 0; i < parent->floating->length; ++i) {
|
for (i = 0; i < parent->floating->length; ++i) {
|
||||||
if (parent->floating->items[i] == child) {
|
swayc_t *item = *(swayc_t **)list_get(parent->floating, i);
|
||||||
list_del(parent->floating, i);
|
if (item == child) {
|
||||||
|
list_delete(parent->floating, i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < parent->children->length; ++i) {
|
for (i = 0; i < parent->children->length; ++i) {
|
||||||
if (parent->children->items[i] == child) {
|
swayc_t *item = *(swayc_t **)list_get(parent->children, i);
|
||||||
list_del(parent->children, i);
|
if (item == child) {
|
||||||
|
list_delete(parent->children, i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -242,27 +243,27 @@ swayc_t *remove_child(swayc_t *child) {
|
||||||
get_maj_dim = get_height;
|
get_maj_dim = get_height;
|
||||||
get_min_dim = get_width;
|
get_min_dim = get_width;
|
||||||
}
|
}
|
||||||
for (int j = parent->children->length - 1; j >= i;) {
|
for (size_t j = parent->children->length - 1; j >= i;) {
|
||||||
int start = auto_group_start_index(parent, j);
|
size_t start = auto_group_start_index(parent, j);
|
||||||
int end = auto_group_end_index(parent, j);
|
size_t end = auto_group_end_index(parent, j);
|
||||||
swayc_t *first = parent->children->items[start];
|
swayc_t *first = *(swayc_t **)list_get(parent->children, start);
|
||||||
if (i == start) {
|
if (i == start) {
|
||||||
/* removed element was first child in the current group,
|
/* removed element was first child in the current group,
|
||||||
use its size along the major axis */
|
use its size along the major axis */
|
||||||
*get_maj_dim(first) = *get_maj_dim(child);
|
*get_maj_dim(first) = *get_maj_dim(child);
|
||||||
} else if (start > i) {
|
} else if (start > i) {
|
||||||
/* preserve the group's dimension along major axis */
|
/* preserve the group's dimension along major axis */
|
||||||
*get_maj_dim(first) = *get_maj_dim(parent->children->items[start - 1]);
|
*get_maj_dim(first) = *get_maj_dim(*(swayc_t **)list_get(parent->children, start - 1));
|
||||||
}
|
}
|
||||||
if (end != parent->children->length) {
|
if (end != parent->children->length) {
|
||||||
double remaining = *get_min_dim(parent);
|
double remaining = *get_min_dim(parent);
|
||||||
for (int k = start; k < end - 1; ++k) {
|
for (size_t k = start; k < end - 1; ++k) {
|
||||||
swayc_t *sibling = parent->children->items[k];
|
swayc_t *sibling = *(swayc_t **)list_get(parent->children, k);
|
||||||
remaining -= *get_min_dim(sibling);
|
remaining -= *get_min_dim(sibling);
|
||||||
}
|
}
|
||||||
/* last element of the group gets remaining size, elements
|
/* last element of the group gets remaining size, elements
|
||||||
that don't change groups keep their ratio */
|
that don't change groups keep their ratio */
|
||||||
*get_min_dim((swayc_t *) parent->children->items[end - 1]) = remaining;
|
*get_min_dim(*(swayc_t **)list_get(parent->children, end - 1)) = remaining;
|
||||||
} /* else last group, let apply_layout handle it */
|
} /* else last group, let apply_layout handle it */
|
||||||
j = start - 1;
|
j = start - 1;
|
||||||
}
|
}
|
||||||
|
|
@ -271,9 +272,9 @@ swayc_t *remove_child(swayc_t *child) {
|
||||||
// Set focused to new container
|
// Set focused to new container
|
||||||
if (parent->focused == child) {
|
if (parent->focused == child) {
|
||||||
if (parent->children->length > 0) {
|
if (parent->children->length > 0) {
|
||||||
parent->focused = parent->children->items[i ? i-1:0];
|
parent->focused = *(swayc_t **)list_get(parent->children, i ? i-1:0);
|
||||||
} else if (parent->floating && parent->floating->length) {
|
} else if (parent->floating && parent->floating->length) {
|
||||||
parent->focused = parent->floating->items[parent->floating->length - 1];
|
parent->focused = *(swayc_t **)list_get(parent->floating, parent->floating->length - 1);
|
||||||
} else {
|
} else {
|
||||||
parent->focused = NULL;
|
parent->focused = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -297,14 +298,14 @@ void swap_container(swayc_t *a, swayc_t *b) {
|
||||||
swayc_t *b_parent = b->parent;
|
swayc_t *b_parent = b->parent;
|
||||||
// Swap the pointers
|
// Swap the pointers
|
||||||
if (a->is_floating) {
|
if (a->is_floating) {
|
||||||
a_parent->floating->items[a_index] = b;
|
*(swayc_t **)list_get(a_parent->floating, a_index) = b;
|
||||||
} else {
|
} else {
|
||||||
a_parent->children->items[a_index] = b;
|
*(swayc_t **)list_get(a_parent->children, a_index) = b;
|
||||||
}
|
}
|
||||||
if (b->is_floating) {
|
if (b->is_floating) {
|
||||||
b_parent->floating->items[b_index] = a;
|
*(swayc_t **)list_get(b_parent->floating, b_index) = a;
|
||||||
} else {
|
} else {
|
||||||
b_parent->children->items[b_index] = a;
|
*(swayc_t **)list_get(b_parent->children, b_index) = a;
|
||||||
}
|
}
|
||||||
a->parent = b_parent;
|
a->parent = b_parent;
|
||||||
b->parent = a_parent;
|
b->parent = a_parent;
|
||||||
|
|
@ -332,14 +333,12 @@ void swap_geometry(swayc_t *a, swayc_t *b) {
|
||||||
b->height = h;
|
b->height = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void swap_children(swayc_t *container, int a, int b) {
|
static void swap_children(swayc_t *container, size_t a, size_t b) {
|
||||||
if (a >= 0 && b >= 0 && a < container->children->length
|
if (a < container->children->length && b < container->children->length && a != b) {
|
||||||
&& b < container->children->length
|
swayc_t *pa = *(swayc_t **)list_get(container->children, a);
|
||||||
&& a != b) {
|
swayc_t *pb = *(swayc_t **)list_get(container->children, b);
|
||||||
swayc_t *pa = (swayc_t *)container->children->items[a];
|
*(swayc_t **)list_get(container->children, a) = *(swayc_t **)list_get(container->children, b);
|
||||||
swayc_t *pb = (swayc_t *)container->children->items[b];
|
*(swayc_t **)list_get(container->children, b) = pa;
|
||||||
container->children->items[a] = container->children->items[b];
|
|
||||||
container->children->items[b] = pa;
|
|
||||||
if (is_auto_layout(container->layout)) {
|
if (is_auto_layout(container->layout)) {
|
||||||
size_t ga = auto_group_index(container, a);
|
size_t ga = auto_group_index(container, a);
|
||||||
size_t gb = auto_group_index(container, b);
|
size_t gb = auto_group_index(container, b);
|
||||||
|
|
@ -385,7 +384,7 @@ void move_container(swayc_t *container, enum movement_direction dir, int move_am
|
||||||
// swap first child in auto layout with currently focused child
|
// swap first child in auto layout with currently focused child
|
||||||
if (is_auto_layout(parent->layout)) {
|
if (is_auto_layout(parent->layout)) {
|
||||||
int focused_idx = index_child(container);
|
int focused_idx = index_child(container);
|
||||||
swayc_t *first = parent->children->items[0];
|
swayc_t *first = *(swayc_t **)list_get(parent->children, 0);
|
||||||
if (focused_idx > 0) {
|
if (focused_idx > 0) {
|
||||||
list_swap(parent->children, 0, focused_idx);
|
list_swap(parent->children, 0, focused_idx);
|
||||||
swap_geometry(first, container);
|
swap_geometry(first, container);
|
||||||
|
|
@ -432,20 +431,20 @@ void move_container(swayc_t *container, enum movement_direction dir, int move_am
|
||||||
diff = dir == MOVE_LEFT || dir == MOVE_UP || dir == MOVE_PREV ? -1 : 1;
|
diff = dir == MOVE_LEFT || dir == MOVE_UP || dir == MOVE_PREV ? -1 : 1;
|
||||||
}
|
}
|
||||||
int idx = index_child(child);
|
int idx = index_child(child);
|
||||||
int desired = idx + diff;
|
ssize_t desired = idx + diff;
|
||||||
if (dir == MOVE_NEXT || dir == MOVE_PREV) {
|
if (dir == MOVE_NEXT || dir == MOVE_PREV) {
|
||||||
// Next/Prev always wrap.
|
// Next/Prev always wrap.
|
||||||
if (desired < 0) {
|
if (desired < 0) {
|
||||||
desired += parent->children->length;
|
desired += parent->children->length;
|
||||||
} else if (desired >= parent->children->length) {
|
} else if (desired >= (ssize_t)parent->children->length) {
|
||||||
desired = 0;
|
desired = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// when it has ascended, legal insertion position is 0:len
|
// when it has ascended, legal insertion position is 0:len
|
||||||
// when it has not, legal insertion position is 0:len-1
|
// when it has not, legal insertion position is 0:len-1
|
||||||
if (desired >= 0 && desired - ascended < parent->children->length) {
|
if (desired >= 0 && desired - ascended < (ssize_t)parent->children->length) {
|
||||||
if (!ascended) {
|
if (!ascended) {
|
||||||
child = parent->children->items[desired];
|
child = *(swayc_t **)list_get(parent->children, desired);
|
||||||
// Move container into sibling container
|
// Move container into sibling container
|
||||||
if (child->type == C_CONTAINER) {
|
if (child->type == C_CONTAINER) {
|
||||||
parent = child;
|
parent = child;
|
||||||
|
|
@ -469,7 +468,7 @@ void move_container(swayc_t *container, enum movement_direction dir, int move_am
|
||||||
swayc_t *old_parent = remove_child(container);
|
swayc_t *old_parent = remove_child(container);
|
||||||
insert_child(parent, container, desired);
|
insert_child(parent, container, desired);
|
||||||
destroy_container(old_parent);
|
destroy_container(old_parent);
|
||||||
sway_log(L_DEBUG,"Moving to %p %d", parent, desired);
|
sway_log(L_DEBUG,"Moving to %p %zd", parent, desired);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -676,9 +675,8 @@ void update_layout_geometry(swayc_t *parent, enum swayc_layouts prev_layout) {
|
||||||
case L_STACKED:
|
case L_STACKED:
|
||||||
if (prev_layout != L_TABBED && prev_layout != L_STACKED) {
|
if (prev_layout != L_TABBED && prev_layout != L_STACKED) {
|
||||||
// cache current geometry for all non-float children
|
// cache current geometry for all non-float children
|
||||||
int i;
|
for (size_t i = 0; i < parent->children->length; ++i) {
|
||||||
for (i = 0; i < parent->children->length; ++i) {
|
swayc_t *child = *(swayc_t **)list_get(parent->children, i);
|
||||||
swayc_t *child = parent->children->items[i];
|
|
||||||
child->cached_geometry.origin.x = child->x;
|
child->cached_geometry.origin.x = child->x;
|
||||||
child->cached_geometry.origin.y = child->y;
|
child->cached_geometry.origin.y = child->y;
|
||||||
child->cached_geometry.size.w = child->width;
|
child->cached_geometry.size.w = child->width;
|
||||||
|
|
@ -689,9 +687,8 @@ void update_layout_geometry(swayc_t *parent, enum swayc_layouts prev_layout) {
|
||||||
default:
|
default:
|
||||||
if (prev_layout == L_TABBED || prev_layout == L_STACKED) {
|
if (prev_layout == L_TABBED || prev_layout == L_STACKED) {
|
||||||
// recover cached geometry for all non-float children
|
// recover cached geometry for all non-float children
|
||||||
int i;
|
for (size_t i = 0; i < parent->children->length; ++i) {
|
||||||
for (i = 0; i < parent->children->length; ++i) {
|
swayc_t *child = *(swayc_t **)list_get(parent->children, i);
|
||||||
swayc_t *child = parent->children->items[i];
|
|
||||||
// only recoverer cached geometry if non-zero
|
// only recoverer cached geometry if non-zero
|
||||||
if (!wlc_geometry_equals(&child->cached_geometry, &wlc_geometry_zero)) {
|
if (!wlc_geometry_equals(&child->cached_geometry, &wlc_geometry_zero)) {
|
||||||
child->x = child->cached_geometry.origin.x;
|
child->x = child->cached_geometry.origin.x;
|
||||||
|
|
@ -831,15 +828,15 @@ void update_geometry(swayc_t *container) {
|
||||||
int title_bar_height = config->font_height + 4; //borders + padding
|
int title_bar_height = config->font_height + 4; //borders + padding
|
||||||
|
|
||||||
if (parent->layout == L_TABBED && parent->children->length > 1) {
|
if (parent->layout == L_TABBED && parent->children->length > 1) {
|
||||||
int i, x = 0, w, l, r;
|
int x = 0, w, l, r;
|
||||||
l = parent->children->length;
|
l = parent->children->length;
|
||||||
w = geometry.size.w / l;
|
w = geometry.size.w / l;
|
||||||
r = geometry.size.w % l;
|
r = geometry.size.w % l;
|
||||||
for (i = 0; i < parent->children->length; ++i) {
|
for (size_t i = 0; i < parent->children->length; ++i) {
|
||||||
swayc_t *view = parent->children->items[i];
|
swayc_t *view = *(swayc_t **)list_get(parent->children, i);
|
||||||
if (view == container) {
|
if (view == container) {
|
||||||
x = w * i;
|
x = w * i;
|
||||||
if (i == l - 1) {
|
if ((ssize_t)i == l - 1) {
|
||||||
w += r;
|
w += r;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -862,9 +859,9 @@ void update_geometry(swayc_t *container) {
|
||||||
geometry.size.h -= (border_bottom + title_bar.size.h);
|
geometry.size.h -= (border_bottom + title_bar.size.h);
|
||||||
container->title_bar_geometry = title_bar;
|
container->title_bar_geometry = title_bar;
|
||||||
} else if (parent->layout == L_STACKED && parent->children->length > 1) {
|
} else if (parent->layout == L_STACKED && parent->children->length > 1) {
|
||||||
int i, y = 0;
|
int y = 0;
|
||||||
for (i = 0; i < parent->children->length; ++i) {
|
for (size_t i = 0; i < parent->children->length; ++i) {
|
||||||
swayc_t *view = parent->children->items[i];
|
swayc_t *view = *(swayc_t **)list_get(parent->children, i);
|
||||||
if (view == container) {
|
if (view == container) {
|
||||||
y = title_bar_height * i;
|
y = title_bar_height * i;
|
||||||
}
|
}
|
||||||
|
|
@ -951,7 +948,7 @@ static void apply_auto_layout(swayc_t *container, const double x, const double y
|
||||||
bool master_first);
|
bool master_first);
|
||||||
|
|
||||||
static void arrange_windows_r(swayc_t *container, double width, double height) {
|
static void arrange_windows_r(swayc_t *container, double width, double height) {
|
||||||
int i;
|
size_t i;
|
||||||
if (width == -1 || height == -1) {
|
if (width == -1 || height == -1) {
|
||||||
swayc_log(L_DEBUG, container, "Arranging layout for %p", container);
|
swayc_log(L_DEBUG, container, "Arranging layout for %p", container);
|
||||||
width = container->width;
|
width = container->width;
|
||||||
|
|
@ -971,7 +968,7 @@ static void arrange_windows_r(swayc_t *container, double width, double height) {
|
||||||
switch (container->type) {
|
switch (container->type) {
|
||||||
case C_ROOT:
|
case C_ROOT:
|
||||||
for (i = 0; i < container->children->length; ++i) {
|
for (i = 0; i < container->children->length; ++i) {
|
||||||
swayc_t *output = container->children->items[i];
|
swayc_t *output = *(swayc_t **)list_get(container->children, i);
|
||||||
sway_log(L_DEBUG, "Arranging output '%s' at %f,%f", output->name, output->x, output->y);
|
sway_log(L_DEBUG, "Arranging output '%s' at %f,%f", output->name, output->x, output->y);
|
||||||
arrange_windows_r(output, -1, -1);
|
arrange_windows_r(output, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
@ -988,12 +985,12 @@ static void arrange_windows_r(swayc_t *container, double width, double height) {
|
||||||
}
|
}
|
||||||
// arrange all workspaces:
|
// arrange all workspaces:
|
||||||
for (i = 0; i < container->children->length; ++i) {
|
for (i = 0; i < container->children->length; ++i) {
|
||||||
swayc_t *child = container->children->items[i];
|
swayc_t *child = *(swayc_t **)list_get(container->children, i);
|
||||||
arrange_windows_r(child, -1, -1);
|
arrange_windows_r(child, -1, -1);
|
||||||
}
|
}
|
||||||
// Bring all unmanaged views to the front
|
// Bring all unmanaged views to the front
|
||||||
for (i = 0; i < container->unmanaged->length; ++i) {
|
for (i = 0; i < container->unmanaged->length; ++i) {
|
||||||
wlc_handle *handle = container->unmanaged->items[i];
|
wlc_handle *handle = *(wlc_handle **)list_get(container->unmanaged, i);
|
||||||
wlc_view_bring_to_front(*handle);
|
wlc_view_bring_to_front(*handle);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
@ -1002,7 +999,7 @@ static void arrange_windows_r(swayc_t *container, double width, double height) {
|
||||||
swayc_t *output = swayc_parent_by_type(container, C_OUTPUT);
|
swayc_t *output = swayc_parent_by_type(container, C_OUTPUT);
|
||||||
width = output->width, height = output->height;
|
width = output->width, height = output->height;
|
||||||
for (i = 0; i < desktop_shell.panels->length; ++i) {
|
for (i = 0; i < desktop_shell.panels->length; ++i) {
|
||||||
struct panel_config *config = desktop_shell.panels->items[i];
|
struct panel_config *config = *(struct panel_config **)list_get(desktop_shell.panels, i);
|
||||||
if (config->output == output->handle) {
|
if (config->output == output->handle) {
|
||||||
struct wlc_size size = *wlc_surface_get_size(config->surface);
|
struct wlc_size size = *wlc_surface_get_size(config->surface);
|
||||||
sway_log(L_DEBUG, "-> Found panel for this workspace: %ux%u, position: %u", size.w, size.h, config->panel_position);
|
sway_log(L_DEBUG, "-> Found panel for this workspace: %ux%u, position: %u", size.w, size.h, config->panel_position);
|
||||||
|
|
@ -1107,8 +1104,8 @@ static void arrange_windows_r(swayc_t *container, double width, double height) {
|
||||||
|
|
||||||
// Arrage floating layouts for workspaces last
|
// Arrage floating layouts for workspaces last
|
||||||
if (container->type == C_WORKSPACE) {
|
if (container->type == C_WORKSPACE) {
|
||||||
for (int i = 0; i < container->floating->length; ++i) {
|
for (size_t i = 0; i < container->floating->length; ++i) {
|
||||||
swayc_t *view = container->floating->items[i];
|
swayc_t *view = *(swayc_t **)list_get(container->floating, i);
|
||||||
if (view->type == C_VIEW) {
|
if (view->type == C_VIEW) {
|
||||||
update_geometry(view);
|
update_geometry(view);
|
||||||
sway_log(L_DEBUG, "Set floating view to %.f x %.f @ %.f, %.f",
|
sway_log(L_DEBUG, "Set floating view to %.f x %.f @ %.f, %.f",
|
||||||
|
|
@ -1130,7 +1127,7 @@ void apply_horiz_layout(swayc_t *container, const double x, const double y,
|
||||||
double scale = 0;
|
double scale = 0;
|
||||||
// Calculate total width
|
// Calculate total width
|
||||||
for (int i = start; i < end; ++i) {
|
for (int i = start; i < end; ++i) {
|
||||||
double *old_width = &((swayc_t *)container->children->items[i])->width;
|
double *old_width = &(*(swayc_t **)list_get(container->children, i))->width;
|
||||||
if (*old_width <= 0) {
|
if (*old_width <= 0) {
|
||||||
if (end - start > 1) {
|
if (end - start > 1) {
|
||||||
*old_width = width / (end - start - 1);
|
*old_width = width / (end - start - 1);
|
||||||
|
|
@ -1148,7 +1145,7 @@ void apply_horiz_layout(swayc_t *container, const double x, const double y,
|
||||||
sway_log(L_DEBUG, "Arranging %p horizontally", container);
|
sway_log(L_DEBUG, "Arranging %p horizontally", container);
|
||||||
swayc_t *focused = NULL;
|
swayc_t *focused = NULL;
|
||||||
for (int i = start; i < end; ++i) {
|
for (int i = start; i < end; ++i) {
|
||||||
swayc_t *child = container->children->items[i];
|
swayc_t *child = *(swayc_t **)list_get(container->children, i);
|
||||||
sway_log(L_DEBUG,
|
sway_log(L_DEBUG,
|
||||||
"Calculating arrangement for %p:%d (will scale %f by %f)", child,
|
"Calculating arrangement for %p:%d (will scale %f by %f)", child,
|
||||||
child->type, width, scale);
|
child->type, width, scale);
|
||||||
|
|
@ -1183,7 +1180,7 @@ void apply_vert_layout(swayc_t *container, const double x, const double y,
|
||||||
double scale = 0;
|
double scale = 0;
|
||||||
// Calculate total height
|
// Calculate total height
|
||||||
for (i = start; i < end; ++i) {
|
for (i = start; i < end; ++i) {
|
||||||
double *old_height = &((swayc_t *)container->children->items[i])->height;
|
double *old_height = &(*(swayc_t **)list_get(container->children, i))->height;
|
||||||
if (*old_height <= 0) {
|
if (*old_height <= 0) {
|
||||||
if (end - start > 1) {
|
if (end - start > 1) {
|
||||||
*old_height = height / (end - start - 1);
|
*old_height = height / (end - start - 1);
|
||||||
|
|
@ -1201,7 +1198,7 @@ void apply_vert_layout(swayc_t *container, const double x, const double y,
|
||||||
sway_log(L_DEBUG, "Arranging %p vertically", container);
|
sway_log(L_DEBUG, "Arranging %p vertically", container);
|
||||||
swayc_t *focused = NULL;
|
swayc_t *focused = NULL;
|
||||||
for (i = start; i < end; ++i) {
|
for (i = start; i < end; ++i) {
|
||||||
swayc_t *child = container->children->items[i];
|
swayc_t *child = *(swayc_t **)list_get(container->children, i);
|
||||||
sway_log(L_DEBUG,
|
sway_log(L_DEBUG,
|
||||||
"Calculating arrangement for %p:%d (will scale %f by %f)", child,
|
"Calculating arrangement for %p:%d (will scale %f by %f)", child,
|
||||||
child->type, height, scale);
|
child->type, height, scale);
|
||||||
|
|
@ -1231,10 +1228,9 @@ void apply_vert_layout(swayc_t *container, const double x, const double y,
|
||||||
|
|
||||||
void apply_tabbed_or_stacked_layout(swayc_t *container, double x, double y,
|
void apply_tabbed_or_stacked_layout(swayc_t *container, double x, double y,
|
||||||
double width, double height) {
|
double width, double height) {
|
||||||
int i;
|
|
||||||
swayc_t *focused = NULL;
|
swayc_t *focused = NULL;
|
||||||
for (i = 0; i < container->children->length; ++i) {
|
for (size_t i = 0; i < container->children->length; ++i) {
|
||||||
swayc_t *child = container->children->items[i];
|
swayc_t *child = *(swayc_t **)list_get(container->children, i);
|
||||||
child->x = x;
|
child->x = x;
|
||||||
child->y = y;
|
child->y = y;
|
||||||
if (child == container->focused) {
|
if (child == container->focused) {
|
||||||
|
|
@ -1326,7 +1322,7 @@ void apply_auto_layout(swayc_t *container, const double x, const double y,
|
||||||
for (size_t group = 0; group < nb_groups; ++group) {
|
for (size_t group = 0; group < nb_groups; ++group) {
|
||||||
int idx;
|
int idx;
|
||||||
if (auto_group_bounds(container, group, &idx, NULL)) {
|
if (auto_group_bounds(container, group, &idx, NULL)) {
|
||||||
swayc_t *child = container->children->items[idx];
|
swayc_t *child = *(swayc_t **)list_get(container->children, idx);
|
||||||
double *dim = group_layout == L_HORIZ ? &child->height : &child->width;
|
double *dim = group_layout == L_HORIZ ? &child->height : &child->width;
|
||||||
if (*dim <= 0) {
|
if (*dim <= 0) {
|
||||||
// New child with uninitialized dimension
|
// New child with uninitialized dimension
|
||||||
|
|
@ -1380,9 +1376,8 @@ void arrange_windows(swayc_t *container, double width, double height) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void arrange_backgrounds(void) {
|
void arrange_backgrounds(void) {
|
||||||
struct background_config *bg;
|
for (size_t i = 0; i < desktop_shell.backgrounds->length; ++i) {
|
||||||
for (int i = 0; i < desktop_shell.backgrounds->length; ++i) {
|
struct background_config *bg = *(struct background_config **)list_get(desktop_shell.backgrounds, i);
|
||||||
bg = desktop_shell.backgrounds->items[i];
|
|
||||||
wlc_view_send_to_back(bg->handle);
|
wlc_view_send_to_back(bg->handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1400,10 +1395,10 @@ static swayc_t *get_swayc_in_output_direction(swayc_t *output, enum movement_dir
|
||||||
switch (dir) {
|
switch (dir) {
|
||||||
case MOVE_LEFT:
|
case MOVE_LEFT:
|
||||||
// get most right child of new output
|
// get most right child of new output
|
||||||
return ws->children->items[ws->children->length-1];
|
return *(swayc_t **)list_get(ws->children, ws->children->length-1);
|
||||||
case MOVE_RIGHT:
|
case MOVE_RIGHT:
|
||||||
// get most left child of new output
|
// get most left child of new output
|
||||||
return ws->children->items[0];
|
return *(swayc_t **)list_get(ws->children, 0);
|
||||||
case MOVE_UP:
|
case MOVE_UP:
|
||||||
case MOVE_DOWN:
|
case MOVE_DOWN:
|
||||||
{
|
{
|
||||||
|
|
@ -1413,10 +1408,10 @@ static swayc_t *get_swayc_in_output_direction(swayc_t *output, enum movement_dir
|
||||||
if (parent->layout == L_VERT) {
|
if (parent->layout == L_VERT) {
|
||||||
if (dir == MOVE_UP) {
|
if (dir == MOVE_UP) {
|
||||||
// get child furthest down on new output
|
// get child furthest down on new output
|
||||||
return parent->children->items[parent->children->length-1];
|
return *(swayc_t **)list_get(parent->children, parent->children->length-1);
|
||||||
} else if (dir == MOVE_DOWN) {
|
} else if (dir == MOVE_DOWN) {
|
||||||
// get child furthest up on new output
|
// get child furthest up on new output
|
||||||
return parent->children->items[0];
|
return *(swayc_t **)list_get(parent->children, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return focused_view;
|
return focused_view;
|
||||||
|
|
@ -1455,7 +1450,7 @@ swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_directio
|
||||||
if (desired < 0) {
|
if (desired < 0) {
|
||||||
desired += parent->children->length;
|
desired += parent->children->length;
|
||||||
}
|
}
|
||||||
return parent->children->items[desired];
|
return *(swayc_t **)list_get(parent->children, desired);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1523,33 +1518,34 @@ swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_directio
|
||||||
if (can_move) {
|
if (can_move) {
|
||||||
if (container->is_floating) {
|
if (container->is_floating) {
|
||||||
if (desired < 0) {
|
if (desired < 0) {
|
||||||
wrap_candidate = parent->floating->items[parent->floating->length-1];
|
wrap_candidate = *(swayc_t **)list_get(parent->floating, parent->floating->length-1);
|
||||||
} else if (desired >= parent->floating->length){
|
} else if (desired >= (ssize_t)parent->floating->length){
|
||||||
wrap_candidate = parent->floating->items[0];
|
wrap_candidate = *(swayc_t **)list_get(parent->floating, 0);
|
||||||
} else {
|
} else {
|
||||||
wrap_candidate = parent->floating->items[desired];
|
wrap_candidate = *(swayc_t **)list_get(parent->floating, desired);
|
||||||
}
|
}
|
||||||
if (wrap_candidate) {
|
if (wrap_candidate) {
|
||||||
wlc_view_bring_to_front(wrap_candidate->handle);
|
wlc_view_bring_to_front(wrap_candidate->handle);
|
||||||
}
|
}
|
||||||
return wrap_candidate;
|
return wrap_candidate;
|
||||||
} else if (desired < 0 || desired >= parent->children->length) {
|
} else if (desired < 0 || desired >= (ssize_t)parent->children->length) {
|
||||||
can_move = false;
|
can_move = false;
|
||||||
int len = parent->children->length;
|
int len = parent->children->length;
|
||||||
if (!wrap_candidate && len > 1) {
|
if (!wrap_candidate && len > 1) {
|
||||||
if (desired < 0) {
|
if (desired < 0) {
|
||||||
wrap_candidate = parent->children->items[len-1];
|
wrap_candidate = *(swayc_t **)list_get(parent->children, len-1);
|
||||||
} else {
|
} else {
|
||||||
wrap_candidate = parent->children->items[0];
|
wrap_candidate = *(swayc_t **)list_get(parent->children, 0);
|
||||||
}
|
}
|
||||||
if (config->force_focus_wrapping) {
|
if (config->force_focus_wrapping) {
|
||||||
return wrap_candidate;
|
return wrap_candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
swayc_t *item = *(swayc_t **)list_get(parent->children, desired);
|
||||||
sway_log(L_DEBUG, "%s cont %d-%p dir %i sibling %d: %p", __func__,
|
sway_log(L_DEBUG, "%s cont %d-%p dir %i sibling %d: %p", __func__,
|
||||||
idx, container, dir, desired, parent->children->items[desired]);
|
idx, container, dir, desired, item);
|
||||||
return parent->children->items[desired];
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!can_move) {
|
if (!can_move) {
|
||||||
|
|
@ -1568,7 +1564,6 @@ swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge) {
|
void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge) {
|
||||||
int i;
|
|
||||||
bool layout_match = true;
|
bool layout_match = true;
|
||||||
sway_log(L_DEBUG, "Resizing %p with amount: %f", container, amount);
|
sway_log(L_DEBUG, "Resizing %p with amount: %f", container, amount);
|
||||||
if (edge == WLC_RESIZE_EDGE_LEFT || edge == WLC_RESIZE_EDGE_RIGHT) {
|
if (edge == WLC_RESIZE_EDGE_LEFT || edge == WLC_RESIZE_EDGE_RIGHT) {
|
||||||
|
|
@ -1583,12 +1578,14 @@ void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge ed
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (layout_match) {
|
if (layout_match) {
|
||||||
for (i = 0; i < container->children->length; i++) {
|
for (size_t i = 0; i < container->children->length; i++) {
|
||||||
recursive_resize(container->children->items[i], amount/container->children->length, edge);
|
swayc_t *item = *(swayc_t **)list_get(container->children, i);
|
||||||
|
recursive_resize(item, amount/container->children->length, edge);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < container->children->length; i++) {
|
for (size_t i = 0; i < container->children->length; i++) {
|
||||||
recursive_resize(container->children->items[i], amount, edge);
|
swayc_t *item = *(swayc_t **)list_get(container->children, i);
|
||||||
|
recursive_resize(item, amount, edge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1613,8 +1610,6 @@ bool is_auto_layout(enum swayc_layouts layout) {
|
||||||
* Return the number of master elements in a container
|
* Return the number of master elements in a container
|
||||||
*/
|
*/
|
||||||
static inline size_t auto_master_count(const swayc_t *container) {
|
static inline size_t auto_master_count(const swayc_t *container) {
|
||||||
sway_assert(container->children->length >= 0, "Container %p has (negative) children %d",
|
|
||||||
container, container->children->length);
|
|
||||||
return MIN(container->nb_master, (size_t)container->children->length);
|
return MIN(container->nb_master, (size_t)container->children->length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -343,7 +343,7 @@ int main(int argc, char **argv) {
|
||||||
log_env();
|
log_env();
|
||||||
detect_proprietary();
|
detect_proprietary();
|
||||||
|
|
||||||
input_devices = create_list();
|
input_devices = list_new(sizeof(struct libudev_device *), 0);
|
||||||
|
|
||||||
/* Changing code earlier than this point requires detailed review */
|
/* Changing code earlier than this point requires detailed review */
|
||||||
/* (That code runs as root on systems without logind, and wlc_init drops to
|
/* (That code runs as root on systems without logind, and wlc_init drops to
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,8 @@ swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos) {
|
||||||
output = swayc_opposite_output(MOVE_UP, abs_pos);
|
output = swayc_opposite_output(MOVE_UP, abs_pos);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(int i = 0; i < root_container.children->length; ++i) {
|
for (size_t i = 0; i < root_container.children->length; ++i) {
|
||||||
swayc_t *c = root_container.children->items[i];
|
swayc_t *c = *(swayc_t **)list_get(root_container.children, i);
|
||||||
if (c->type == C_OUTPUT && strcasecmp(c->name, name) == 0) {
|
if (c->type == C_OUTPUT && strcasecmp(c->name, name) == 0) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
@ -58,8 +58,8 @@ swayc_t *swayc_opposite_output(enum movement_direction dir,
|
||||||
switch(dir) {
|
switch(dir) {
|
||||||
case MOVE_LEFT:
|
case MOVE_LEFT:
|
||||||
case MOVE_RIGHT: ;
|
case MOVE_RIGHT: ;
|
||||||
for (int i = 0; i < root_container.children->length; ++i) {
|
for (size_t i = 0; i < root_container.children->length; ++i) {
|
||||||
swayc_t *c = root_container.children->items[i];
|
swayc_t *c = *(swayc_t **)list_get(root_container.children, i);
|
||||||
if (abs_pos->y >= c->y && abs_pos->y <= c->y + c->height) {
|
if (abs_pos->y >= c->y && abs_pos->y <= c->y + c->height) {
|
||||||
if (!opposite) {
|
if (!opposite) {
|
||||||
opposite = c;
|
opposite = c;
|
||||||
|
|
@ -73,8 +73,8 @@ swayc_t *swayc_opposite_output(enum movement_direction dir,
|
||||||
break;
|
break;
|
||||||
case MOVE_UP:
|
case MOVE_UP:
|
||||||
case MOVE_DOWN: ;
|
case MOVE_DOWN: ;
|
||||||
for (int i = 0; i < root_container.children->length; ++i) {
|
for (size_t i = 0; i < root_container.children->length; ++i) {
|
||||||
swayc_t *c = root_container.children->items[i];
|
swayc_t *c = *(swayc_t **)list_get(root_container.children, i);
|
||||||
if (abs_pos->x >= c->x && abs_pos->x <= c->x + c->width) {
|
if (abs_pos->x >= c->x && abs_pos->x <= c->x + c->width) {
|
||||||
if (!opposite) {
|
if (!opposite) {
|
||||||
opposite = c;
|
opposite = c;
|
||||||
|
|
@ -116,8 +116,8 @@ swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir,
|
||||||
case MOVE_LEFT:
|
case MOVE_LEFT:
|
||||||
case MOVE_RIGHT: ;
|
case MOVE_RIGHT: ;
|
||||||
double delta_y = 0;
|
double delta_y = 0;
|
||||||
for(int i = 0; i < root_container.children->length; ++i) {
|
for (size_t i = 0; i < root_container.children->length; ++i) {
|
||||||
swayc_t *c = root_container.children->items[i];
|
swayc_t *c = *(swayc_t **)list_get(root_container.children, i);
|
||||||
if (c == output || c->type != C_OUTPUT) {
|
if (c == output || c->type != C_OUTPUT) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -169,8 +169,8 @@ swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir,
|
||||||
case MOVE_UP:
|
case MOVE_UP:
|
||||||
case MOVE_DOWN: ;
|
case MOVE_DOWN: ;
|
||||||
double delta_x = 0;
|
double delta_x = 0;
|
||||||
for(int i = 0; i < root_container.children->length; ++i) {
|
for (size_t i = 0; i < root_container.children->length; ++i) {
|
||||||
swayc_t *c = root_container.children->items[i];
|
swayc_t *c = *(swayc_t **)list_get(root_container.children, i);
|
||||||
if (c == output || c->type != C_OUTPUT) {
|
if (c == output || c->type != C_OUTPUT) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -273,5 +273,5 @@ static int sort_workspace_cmp_qsort(const void *_a, const void *_b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void sort_workspaces(swayc_t *output) {
|
void sort_workspaces(swayc_t *output) {
|
||||||
list_stable_sort(output->children, sort_workspace_cmp_qsort);
|
list_isort(output->children, sort_workspace_cmp_qsort);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,8 @@ struct feature_policy *alloc_feature_policy(const char *program) {
|
||||||
if (!validate_ipc_target(program)) {
|
if (!validate_ipc_target(program)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < config->feature_policies->length; ++i) {
|
for (size_t i = 0; i < config->feature_policies->length; ++i) {
|
||||||
struct feature_policy *policy = config->feature_policies->items[i];
|
struct feature_policy *policy = *(struct feature_policy **)list_get(config->feature_policies, i);
|
||||||
if (strcmp(policy->program, "*") == 0) {
|
if (strcmp(policy->program, "*") == 0) {
|
||||||
default_policy = policy->features;
|
default_policy = policy->features;
|
||||||
break;
|
break;
|
||||||
|
|
@ -76,8 +76,8 @@ struct ipc_policy *alloc_ipc_policy(const char *program) {
|
||||||
if (!validate_ipc_target(program)) {
|
if (!validate_ipc_target(program)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < config->ipc_policies->length; ++i) {
|
for (size_t i = 0; i < config->ipc_policies->length; ++i) {
|
||||||
struct ipc_policy *policy = config->ipc_policies->items[i];
|
struct ipc_policy *policy = *(struct ipc_policy **)list_get(config->ipc_policies, i);
|
||||||
if (strcmp(policy->program, "*") == 0) {
|
if (strcmp(policy->program, "*") == 0) {
|
||||||
default_policy = policy->features;
|
default_policy = policy->features;
|
||||||
break;
|
break;
|
||||||
|
|
@ -143,8 +143,8 @@ static const char *get_pid_exe(pid_t pid) {
|
||||||
struct feature_policy *get_feature_policy(const char *name) {
|
struct feature_policy *get_feature_policy(const char *name) {
|
||||||
struct feature_policy *policy = NULL;
|
struct feature_policy *policy = NULL;
|
||||||
|
|
||||||
for (int i = 0; i < config->feature_policies->length; ++i) {
|
for (size_t i = 0; i < config->feature_policies->length; ++i) {
|
||||||
struct feature_policy *p = config->feature_policies->items[i];
|
struct feature_policy *p = *(struct feature_policy **)list_get(config->feature_policies, i);
|
||||||
if (strcmp(p->program, name) == 0) {
|
if (strcmp(p->program, name) == 0) {
|
||||||
policy = p;
|
policy = p;
|
||||||
break;
|
break;
|
||||||
|
|
@ -155,7 +155,7 @@ struct feature_policy *get_feature_policy(const char *name) {
|
||||||
if (!policy) {
|
if (!policy) {
|
||||||
sway_abort("Unable to allocate security policy");
|
sway_abort("Unable to allocate security policy");
|
||||||
}
|
}
|
||||||
list_add(config->feature_policies, policy);
|
list_add(config->feature_policies, &policy);
|
||||||
}
|
}
|
||||||
return policy;
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
@ -164,8 +164,8 @@ uint32_t get_feature_policy_mask(pid_t pid) {
|
||||||
uint32_t default_policy = 0;
|
uint32_t default_policy = 0;
|
||||||
const char *link = get_pid_exe(pid);
|
const char *link = get_pid_exe(pid);
|
||||||
|
|
||||||
for (int i = 0; i < config->feature_policies->length; ++i) {
|
for (size_t i = 0; i < config->feature_policies->length; ++i) {
|
||||||
struct feature_policy *policy = config->feature_policies->items[i];
|
struct feature_policy *policy = *(struct feature_policy **)list_get(config->feature_policies, i);
|
||||||
if (strcmp(policy->program, "*") == 0) {
|
if (strcmp(policy->program, "*") == 0) {
|
||||||
default_policy = policy->features;
|
default_policy = policy->features;
|
||||||
}
|
}
|
||||||
|
|
@ -181,8 +181,8 @@ uint32_t get_ipc_policy_mask(pid_t pid) {
|
||||||
uint32_t default_policy = 0;
|
uint32_t default_policy = 0;
|
||||||
const char *link = get_pid_exe(pid);
|
const char *link = get_pid_exe(pid);
|
||||||
|
|
||||||
for (int i = 0; i < config->ipc_policies->length; ++i) {
|
for (size_t i = 0; i < config->ipc_policies->length; ++i) {
|
||||||
struct ipc_policy *policy = config->ipc_policies->items[i];
|
struct ipc_policy *policy = *(struct ipc_policy **)list_get(config->ipc_policies, i);
|
||||||
if (strcmp(policy->program, "*") == 0) {
|
if (strcmp(policy->program, "*") == 0) {
|
||||||
default_policy = policy->features;
|
default_policy = policy->features;
|
||||||
}
|
}
|
||||||
|
|
@ -197,8 +197,8 @@ uint32_t get_ipc_policy_mask(pid_t pid) {
|
||||||
uint32_t get_command_policy_mask(const char *cmd) {
|
uint32_t get_command_policy_mask(const char *cmd) {
|
||||||
uint32_t default_policy = 0;
|
uint32_t default_policy = 0;
|
||||||
|
|
||||||
for (int i = 0; i < config->command_policies->length; ++i) {
|
for (size_t i = 0; i < config->command_policies->length; ++i) {
|
||||||
struct command_policy *policy = config->command_policies->items[i];
|
struct command_policy *policy = *(struct command_policy **)list_get(config->command_policies, i);
|
||||||
if (strcmp(policy->command, "*") == 0) {
|
if (strcmp(policy->command, "*") == 0) {
|
||||||
default_policy = policy->context;
|
default_policy = policy->context;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,8 @@ struct workspace_by_number_data {
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool workspace_valid_on_output(const char *output_name, const char *ws_name) {
|
static bool workspace_valid_on_output(const char *output_name, const char *ws_name) {
|
||||||
int i;
|
for (size_t i = 0; i < config->workspace_outputs->length; ++i) {
|
||||||
for (i = 0; i < config->workspace_outputs->length; ++i) {
|
struct workspace_output *wso = *(struct workspace_output **)list_get(config->workspace_outputs, i);
|
||||||
struct workspace_output *wso = config->workspace_outputs->items[i];
|
|
||||||
if (strcasecmp(wso->workspace, ws_name) == 0) {
|
if (strcasecmp(wso->workspace, ws_name) == 0) {
|
||||||
if (strcasecmp(wso->output, output_name) != 0) {
|
if (strcasecmp(wso->output, output_name) != 0) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -44,7 +43,6 @@ static bool workspace_valid_on_output(const char *output_name, const char *ws_na
|
||||||
|
|
||||||
char *workspace_next_name(const char *output_name) {
|
char *workspace_next_name(const char *output_name) {
|
||||||
sway_log(L_DEBUG, "Workspace: Generating new workspace name for output %s", output_name);
|
sway_log(L_DEBUG, "Workspace: Generating new workspace name for output %s", output_name);
|
||||||
int i;
|
|
||||||
int l = 1;
|
int l = 1;
|
||||||
// Scan all workspace bindings to find the next available workspace name,
|
// Scan all workspace bindings to find the next available workspace name,
|
||||||
// if none are found/available then default to a number
|
// if none are found/available then default to a number
|
||||||
|
|
@ -52,8 +50,8 @@ char *workspace_next_name(const char *output_name) {
|
||||||
|
|
||||||
int order = INT_MAX;
|
int order = INT_MAX;
|
||||||
char *target = NULL;
|
char *target = NULL;
|
||||||
for (i = 0; i < mode->bindings->length; ++i) {
|
for (size_t i = 0; i < mode->bindings->length; ++i) {
|
||||||
struct sway_binding *binding = mode->bindings->items[i];
|
struct sway_binding *binding = *(struct sway_binding **)list_get(mode->bindings, i);
|
||||||
char *cmdlist = strdup(binding->command);
|
char *cmdlist = strdup(binding->command);
|
||||||
char *dup = cmdlist;
|
char *dup = cmdlist;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
|
|
@ -133,15 +131,14 @@ char *workspace_next_name(const char *output_name) {
|
||||||
swayc_t *workspace_create(const char* name) {
|
swayc_t *workspace_create(const char* name) {
|
||||||
swayc_t *parent;
|
swayc_t *parent;
|
||||||
// Search for workspace<->output pair
|
// Search for workspace<->output pair
|
||||||
int i, e = config->workspace_outputs->length;
|
size_t i, e = config->workspace_outputs->length;
|
||||||
for (i = 0; i < e; ++i) {
|
for (i = 0; i < e; ++i) {
|
||||||
struct workspace_output *wso = config->workspace_outputs->items[i];
|
struct workspace_output *wso = *(struct workspace_output **)list_get(config->workspace_outputs, i);
|
||||||
if (strcasecmp(wso->workspace, name) == 0)
|
if (strcasecmp(wso->workspace, name) == 0) {
|
||||||
{
|
|
||||||
// Find output to use if it exists
|
// Find output to use if it exists
|
||||||
e = root_container.children->length;
|
e = root_container.children->length;
|
||||||
for (i = 0; i < e; ++i) {
|
for (i = 0; i < e; ++i) {
|
||||||
parent = root_container.children->items[i];
|
parent = *(swayc_t **)list_get(root_container.children, i);
|
||||||
if (strcmp(parent->name, wso->output) == 0) {
|
if (strcmp(parent->name, wso->output) == 0) {
|
||||||
return new_workspace(parent, name);
|
return new_workspace(parent, name);
|
||||||
}
|
}
|
||||||
|
|
@ -208,10 +205,10 @@ swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
for (size_t i = 0; i < output->children->length; i++) {
|
||||||
for (i = 0; i < output->children->length; i++) {
|
swayc_t *item = *(swayc_t **)list_get(output->children, i);
|
||||||
if (output->children->items[i] == output->focused) {
|
if (item == output->focused) {
|
||||||
return output->children->items[wrap(i + (next ? 1 : -1), output->children->length)];
|
return *(swayc_t **)list_get(output->children, (wrap(i + (next ? 1 : -1), output->children->length)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -231,20 +228,21 @@ swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) {
|
||||||
|
|
||||||
swayc_t *current_output = workspace->parent;
|
swayc_t *current_output = workspace->parent;
|
||||||
int offset = next ? 1 : -1;
|
int offset = next ? 1 : -1;
|
||||||
int start = next ? 0 : 1;
|
size_t start = next ? 0 : 1;
|
||||||
int end = next ? (current_output->children->length) - 1 : current_output->children->length;
|
size_t end = next ? (current_output->children->length) - 1 : current_output->children->length;
|
||||||
int i;
|
for (size_t i = start; i < end; i++) {
|
||||||
for (i = start; i < end; i++) {
|
swayc_t *item = *(swayc_t **)list_get(current_output->children, i);
|
||||||
if (current_output->children->items[i] == workspace) {
|
if (item == workspace) {
|
||||||
return current_output->children->items[i + offset];
|
return *(swayc_t **)list_get(current_output->children, i + offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Given workspace is the first/last on the output, jump to the previous/next output
|
// Given workspace is the first/last on the output, jump to the previous/next output
|
||||||
int num_outputs = root_container.children->length;
|
size_t num_outputs = root_container.children->length;
|
||||||
for (i = 0; i < num_outputs; i++) {
|
for (size_t i = 0; i < num_outputs; i++) {
|
||||||
if (root_container.children->items[i] == current_output) {
|
swayc_t *item = *(swayc_t **)list_get(root_container.children, i);
|
||||||
swayc_t *next_output = root_container.children->items[wrap(i + offset, num_outputs)];
|
if (item == current_output) {
|
||||||
|
swayc_t *next_output = *(swayc_t **)list_get(root_container.children, wrap(i + offset, num_outputs));
|
||||||
return workspace_output_prev_next_impl(next_output, next);
|
return workspace_output_prev_next_impl(next_output, next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -294,15 +292,15 @@ bool workspace_switch(swayc_t *workspace) {
|
||||||
// move sticky containers
|
// move sticky containers
|
||||||
if (swayc_parent_by_type(active_ws, C_OUTPUT) == swayc_parent_by_type(workspace, C_OUTPUT)) {
|
if (swayc_parent_by_type(active_ws, C_OUTPUT) == swayc_parent_by_type(workspace, C_OUTPUT)) {
|
||||||
// don't change list while traversing it, use intermediate list instead
|
// don't change list while traversing it, use intermediate list instead
|
||||||
list_t *stickies = create_list();
|
list_t *stickies = list_new(sizeof(swayc_t *), 0);
|
||||||
for (int i = 0; i < active_ws->floating->length; i++) {
|
for (size_t i = 0; i < active_ws->floating->length; i++) {
|
||||||
swayc_t *cont = active_ws->floating->items[i];
|
swayc_t *cont = *(swayc_t **)list_get(active_ws->floating, i);
|
||||||
if (cont->sticky) {
|
if (cont->sticky) {
|
||||||
list_add(stickies, cont);
|
list_add(stickies, &cont);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < stickies->length; i++) {
|
for (size_t i = 0; i < stickies->length; i++) {
|
||||||
swayc_t *cont = stickies->items[i];
|
swayc_t *cont = *(swayc_t **)list_get(stickies, i);
|
||||||
sway_log(L_DEBUG, "Moving sticky container %p to %p:%s",
|
sway_log(L_DEBUG, "Moving sticky container %p to %p:%s",
|
||||||
cont, workspace, workspace->name);
|
cont, workspace, workspace->name);
|
||||||
swayc_t *parent = remove_child(cont);
|
swayc_t *parent = remove_child(cont);
|
||||||
|
|
@ -323,9 +321,9 @@ bool workspace_switch(swayc_t *workspace) {
|
||||||
}
|
}
|
||||||
|
|
||||||
swayc_t *workspace_for_pid(pid_t pid) {
|
swayc_t *workspace_for_pid(pid_t pid) {
|
||||||
int i;
|
|
||||||
swayc_t *ws = NULL;
|
swayc_t *ws = NULL;
|
||||||
struct pid_workspace *pw = NULL;
|
struct pid_workspace *pw = NULL;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
sway_log(L_DEBUG, "looking for workspace for pid %d", pid);
|
sway_log(L_DEBUG, "looking for workspace for pid %d", pid);
|
||||||
|
|
||||||
|
|
@ -338,7 +336,7 @@ swayc_t *workspace_for_pid(pid_t pid) {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
for (i = 0; i < config->pid_workspaces->length; i++) {
|
for (i = 0; i < config->pid_workspaces->length; i++) {
|
||||||
pw = config->pid_workspaces->items[i];
|
pw = *(struct pid_workspace **)list_get(config->pid_workspaces, i);
|
||||||
pid_t *pw_pid = pw->pid;
|
pid_t *pw_pid = pw->pid;
|
||||||
|
|
||||||
if (pid == *pw_pid) {
|
if (pid == *pw_pid) {
|
||||||
|
|
@ -367,7 +365,7 @@ swayc_t *workspace_for_pid(pid_t pid) {
|
||||||
ws = workspace_create(pw->workspace);
|
ws = workspace_create(pw->workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
list_del(config->pid_workspaces, i);
|
list_delete(config->pid_workspaces, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ws;
|
return ws;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
static void bar_init(struct bar *bar) {
|
static void bar_init(struct bar *bar) {
|
||||||
bar->config = init_config();
|
bar->config = init_config();
|
||||||
bar->status = init_status_line();
|
bar->status = init_status_line();
|
||||||
bar->outputs = create_list();
|
bar->outputs = list_new(sizeof(struct output *), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spawn_status_cmd_proc(struct bar *bar) {
|
static void spawn_status_cmd_proc(struct bar *bar) {
|
||||||
|
|
@ -55,7 +55,7 @@ struct output *new_output(const char *name) {
|
||||||
output->name = strdup(name);
|
output->name = strdup(name);
|
||||||
output->window = NULL;
|
output->window = NULL;
|
||||||
output->registry = NULL;
|
output->registry = NULL;
|
||||||
output->workspaces = create_list();
|
output->workspaces = list_new(sizeof(struct workspace *), 0);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,8 +67,8 @@ static void mouse_button_notify(struct window *window, int x, int y,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct output *clicked_output = NULL;
|
struct output *clicked_output = NULL;
|
||||||
for (int i = 0; i < swaybar.outputs->length; i++) {
|
for (size_t i = 0; i < swaybar.outputs->length; i++) {
|
||||||
struct output *output = swaybar.outputs->items[i];
|
struct output *output = *(struct output **)list_get(swaybar.outputs, i);
|
||||||
if (window == output->window) {
|
if (window == output->window) {
|
||||||
clicked_output = output;
|
clicked_output = output;
|
||||||
break;
|
break;
|
||||||
|
|
@ -80,8 +80,8 @@ static void mouse_button_notify(struct window *window, int x, int y,
|
||||||
}
|
}
|
||||||
|
|
||||||
double button_x = 0.5;
|
double button_x = 0.5;
|
||||||
for (int i = 0; i < clicked_output->workspaces->length; i++) {
|
for (size_t i = 0; i < clicked_output->workspaces->length; i++) {
|
||||||
struct workspace *workspace = clicked_output->workspaces->items[i];
|
struct workspace *workspace = *(struct workspace **)list_get(clicked_output->workspaces, i);
|
||||||
int button_width, button_height;
|
int button_width, button_height;
|
||||||
|
|
||||||
workspace_button_size(window, workspace->name, &button_width, &button_height);
|
workspace_button_size(window, workspace->name, &button_width, &button_height);
|
||||||
|
|
@ -95,14 +95,14 @@ static void mouse_button_notify(struct window *window, int x, int y,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) {
|
static void mouse_scroll_notify(struct window *window, enum scroll_direction direction) {
|
||||||
|
size_t i;
|
||||||
sway_log(L_DEBUG, "Mouse wheel scrolled %s", direction == SCROLL_UP ? "up" : "down");
|
sway_log(L_DEBUG, "Mouse wheel scrolled %s", direction == SCROLL_UP ? "up" : "down");
|
||||||
|
|
||||||
if (!swaybar.config->wrap_scroll) {
|
if (!swaybar.config->wrap_scroll) {
|
||||||
// Find output this window lives on
|
// Find output this window lives on
|
||||||
int i;
|
|
||||||
struct output *output = NULL;
|
struct output *output = NULL;
|
||||||
for (i = 0; i < swaybar.outputs->length; ++i) {
|
for (i = 0; i < swaybar.outputs->length; ++i) {
|
||||||
output = swaybar.outputs->items[i];
|
output = *(struct output **)list_get(swaybar.outputs, i);
|
||||||
if (output->window == window) {
|
if (output->window == window) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -112,7 +112,7 @@ static void mouse_scroll_notify(struct window *window, enum scroll_direction dir
|
||||||
}
|
}
|
||||||
int focused = -1;
|
int focused = -1;
|
||||||
for (i = 0; i < output->workspaces->length; ++i) {
|
for (i = 0; i < output->workspaces->length; ++i) {
|
||||||
struct workspace *ws = output->workspaces->items[i];
|
struct workspace *ws = *(struct workspace **)list_get(output->workspaces, i);
|
||||||
if (ws->focused) {
|
if (ws->focused) {
|
||||||
focused = i;
|
focused = i;
|
||||||
break;
|
break;
|
||||||
|
|
@ -122,7 +122,7 @@ static void mouse_scroll_notify(struct window *window, enum scroll_direction dir
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((focused == 0 && direction == SCROLL_UP) ||
|
if ((focused == 0 && direction == SCROLL_UP) ||
|
||||||
(focused == output->workspaces->length - 1 && direction == SCROLL_DOWN)) {
|
(focused == (ssize_t)output->workspaces->length - 1 && direction == SCROLL_DOWN)) {
|
||||||
// Do not wrap
|
// Do not wrap
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -142,9 +142,8 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {
|
||||||
|
|
||||||
ipc_bar_init(bar, bar_id);
|
ipc_bar_init(bar, bar_id);
|
||||||
|
|
||||||
int i;
|
for (size_t i = 0; i < bar->outputs->length; ++i) {
|
||||||
for (i = 0; i < bar->outputs->length; ++i) {
|
struct output *bar_output = *(struct output **)list_get(bar->outputs, i);
|
||||||
struct output *bar_output = bar->outputs->items[i];
|
|
||||||
|
|
||||||
bar_output->registry = registry_poll();
|
bar_output->registry = registry_poll();
|
||||||
|
|
||||||
|
|
@ -152,7 +151,7 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) {
|
||||||
sway_abort("swaybar requires the compositor to support the desktop-shell extension.");
|
sway_abort("swaybar requires the compositor to support the desktop-shell extension.");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct output_state *output = bar_output->registry->outputs->items[bar_output->idx];
|
struct output_state *output = *(struct output_state **)list_get(bar_output->registry->outputs, bar_output->idx);
|
||||||
|
|
||||||
bar_output->window = window_setup(bar_output->registry,
|
bar_output->window = window_setup(bar_output->registry,
|
||||||
output->width / output->scale, 30, output->scale, false);
|
output->width / output->scale, 30, output->scale, false);
|
||||||
|
|
@ -190,18 +189,16 @@ void bar_run(struct bar *bar) {
|
||||||
pfd[1].fd = bar->status_read_fd;
|
pfd[1].fd = bar->status_read_fd;
|
||||||
pfd[1].events = POLLIN;
|
pfd[1].events = POLLIN;
|
||||||
|
|
||||||
int i;
|
for (size_t i = 0; i < bar->outputs->length; ++i) {
|
||||||
for (i = 0; i < bar->outputs->length; ++i) {
|
struct output *output = *(struct output **)list_get(bar->outputs, i);
|
||||||
struct output *output = bar->outputs->items[i];
|
|
||||||
pfd[i+2].fd = wl_display_get_fd(output->registry->display);
|
pfd[i+2].fd = wl_display_get_fd(output->registry->display);
|
||||||
pfd[i+2].events = POLLIN;
|
pfd[i+2].events = POLLIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (dirty) {
|
if (dirty) {
|
||||||
int i;
|
for (size_t i = 0; i < bar->outputs->length; ++i) {
|
||||||
for (i = 0; i < bar->outputs->length; ++i) {
|
struct output *output = *(struct output **)list_get(bar->outputs, i);
|
||||||
struct output *output = bar->outputs->items[i];
|
|
||||||
if (window_prerender(output->window) && output->window->cairo) {
|
if (window_prerender(output->window) && output->window->cairo) {
|
||||||
render(output, bar->config, bar->status);
|
render(output, bar->config, bar->status);
|
||||||
window_render(output->window);
|
window_render(output->window);
|
||||||
|
|
@ -225,8 +222,8 @@ void bar_run(struct bar *bar) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// dispatch wl_display events
|
// dispatch wl_display events
|
||||||
for (i = 0; i < bar->outputs->length; ++i) {
|
for (size_t i = 0; i < bar->outputs->length; ++i) {
|
||||||
struct output *output = bar->outputs->items[i];
|
struct output *output = *(struct output **)list_get(bar->outputs, i);
|
||||||
if (pfd[i+2].revents & POLLIN) {
|
if (pfd[i+2].revents & POLLIN) {
|
||||||
if (wl_display_dispatch(output->registry->display) == -1) {
|
if (wl_display_dispatch(output->registry->display) == -1) {
|
||||||
sway_log(L_ERROR, "failed to dispatch wl: %d", errno);
|
sway_log(L_ERROR, "failed to dispatch wl: %d", errno);
|
||||||
|
|
@ -239,9 +236,8 @@ void bar_run(struct bar *bar) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_workspaces(list_t *workspaces) {
|
void free_workspaces(list_t *workspaces) {
|
||||||
int i;
|
for (size_t i = 0; i < workspaces->length; ++i) {
|
||||||
for (i = 0; i < workspaces->length; ++i) {
|
struct workspace *ws = *(struct workspace **)list_get(workspaces, i);
|
||||||
struct workspace *ws = workspaces->items[i];
|
|
||||||
free(ws->name);
|
free(ws->name);
|
||||||
free(ws);
|
free(ws);
|
||||||
}
|
}
|
||||||
|
|
@ -264,9 +260,9 @@ static void free_output(struct output *output) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_outputs(list_t *outputs) {
|
static void free_outputs(list_t *outputs) {
|
||||||
int i;
|
for (size_t i = 0; i < outputs->length; ++i) {
|
||||||
for (i = 0; i < outputs->length; ++i) {
|
struct output *item = *(struct output **)list_get(outputs, i);
|
||||||
free_output(outputs->items[i]);
|
free_output(item);
|
||||||
}
|
}
|
||||||
list_free(outputs);
|
list_free(outputs);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ struct config *init_config() {
|
||||||
config->wrap_scroll = false;
|
config->wrap_scroll = false;
|
||||||
config->workspace_buttons = true;
|
config->workspace_buttons = true;
|
||||||
config->all_outputs = false;
|
config->all_outputs = false;
|
||||||
config->outputs = create_list();
|
config->outputs = list_new(sizeof(char *), 0);
|
||||||
|
|
||||||
/* height */
|
/* height */
|
||||||
config->height = 0;
|
config->height = 0;
|
||||||
|
|
|
||||||
|
|
@ -84,25 +84,25 @@ static void ipc_parse_config(struct config *config, const char *payload) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// free previous outputs list
|
// free previous outputs list
|
||||||
int i;
|
for (size_t i = 0; i < config->outputs->length; ++i) {
|
||||||
for (i = 0; i < config->outputs->length; ++i) {
|
free(*(char **)list_get(config->outputs, i));
|
||||||
free(config->outputs->items[i]);
|
|
||||||
}
|
}
|
||||||
list_free(config->outputs);
|
list_free(config->outputs);
|
||||||
config->outputs = create_list();
|
config->outputs = list_new(sizeof(char *), 0);
|
||||||
|
|
||||||
if (outputs) {
|
if (outputs) {
|
||||||
int length = json_object_array_length(outputs);
|
int length = json_object_array_length(outputs);
|
||||||
json_object *output;
|
json_object *output;
|
||||||
const char *output_str;
|
const char *output_str;
|
||||||
for (i = 0; i < length; ++i) {
|
for (int i = 0; i < length; ++i) {
|
||||||
output = json_object_array_get_idx(outputs, i);
|
output = json_object_array_get_idx(outputs, i);
|
||||||
output_str = json_object_get_string(output);
|
output_str = json_object_get_string(output);
|
||||||
if (strcmp("*", output_str) == 0) {
|
if (strcmp("*", output_str) == 0) {
|
||||||
config->all_outputs = true;
|
config->all_outputs = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
list_add(config->outputs, strdup(output_str));
|
char *ptr = strdup(output_str);
|
||||||
|
list_add(config->outputs, &ptr);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
config->all_outputs = true;
|
config->all_outputs = true;
|
||||||
|
|
@ -214,13 +214,12 @@ static void ipc_parse_config(struct config *config, const char *payload) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ipc_update_workspaces(struct bar *bar) {
|
static void ipc_update_workspaces(struct bar *bar) {
|
||||||
int i;
|
for (size_t i = 0; i < bar->outputs->length; ++i) {
|
||||||
for (i = 0; i < bar->outputs->length; ++i) {
|
struct output *output = *(struct output **)list_get(bar->outputs, i);
|
||||||
struct output *output = bar->outputs->items[i];
|
|
||||||
if (output->workspaces) {
|
if (output->workspaces) {
|
||||||
free_workspaces(output->workspaces);
|
free_workspaces(output->workspaces);
|
||||||
}
|
}
|
||||||
output->workspaces = create_list();
|
output->workspaces = list_new(sizeof(struct workspace *), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t len = 0;
|
uint32_t len = 0;
|
||||||
|
|
@ -234,7 +233,7 @@ static void ipc_update_workspaces(struct bar *bar) {
|
||||||
int length = json_object_array_length(results);
|
int length = json_object_array_length(results);
|
||||||
json_object *ws_json;
|
json_object *ws_json;
|
||||||
json_object *num, *name, *visible, *focused, *out, *urgent;
|
json_object *num, *name, *visible, *focused, *out, *urgent;
|
||||||
for (i = 0; i < length; ++i) {
|
for (int i = 0; i < length; ++i) {
|
||||||
ws_json = json_object_array_get_idx(results, i);
|
ws_json = json_object_array_get_idx(results, i);
|
||||||
|
|
||||||
json_object_object_get_ex(ws_json, "num", &num);
|
json_object_object_get_ex(ws_json, "num", &num);
|
||||||
|
|
@ -244,9 +243,8 @@ static void ipc_update_workspaces(struct bar *bar) {
|
||||||
json_object_object_get_ex(ws_json, "output", &out);
|
json_object_object_get_ex(ws_json, "output", &out);
|
||||||
json_object_object_get_ex(ws_json, "urgent", &urgent);
|
json_object_object_get_ex(ws_json, "urgent", &urgent);
|
||||||
|
|
||||||
int j;
|
for (size_t j = 0; j < bar->outputs->length; ++j) {
|
||||||
for (j = 0; j < bar->outputs->length; ++j) {
|
struct output *output = *(struct output **)list_get(bar->outputs, j);
|
||||||
struct output *output = bar->outputs->items[j];
|
|
||||||
if (strcmp(json_object_get_string(out), output->name) == 0) {
|
if (strcmp(json_object_get_string(out), output->name) == 0) {
|
||||||
struct workspace *ws = malloc(sizeof(struct workspace));
|
struct workspace *ws = malloc(sizeof(struct workspace));
|
||||||
ws->num = json_object_get_int(num);
|
ws->num = json_object_get_int(num);
|
||||||
|
|
@ -261,7 +259,7 @@ static void ipc_update_workspaces(struct bar *bar) {
|
||||||
output->focused = true;
|
output->focused = true;
|
||||||
}
|
}
|
||||||
ws->urgent = json_object_get_boolean(urgent);
|
ws->urgent = json_object_get_boolean(urgent);
|
||||||
list_add(output->workspaces, ws);
|
list_add(output->workspaces, &ws);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -301,9 +299,8 @@ void ipc_bar_init(struct bar *bar, const char *bar_id) {
|
||||||
if (bar->config->all_outputs) {
|
if (bar->config->all_outputs) {
|
||||||
use_output = true;
|
use_output = true;
|
||||||
} else {
|
} else {
|
||||||
int j = 0;
|
for (size_t j = 0; j < bar->config->outputs->length; ++j) {
|
||||||
for (j = 0; j < bar->config->outputs->length; ++j) {
|
const char *conf_name = *(char **)list_get(bar->config->outputs, j);
|
||||||
const char *conf_name = bar->config->outputs->items[j];
|
|
||||||
if (strcasecmp(name, conf_name) == 0) {
|
if (strcasecmp(name, conf_name) == 0) {
|
||||||
use_output = true;
|
use_output = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -275,8 +275,6 @@ static void render_binding_mode_indicator(struct window *window, struct config *
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(struct output *output, struct config *config, struct status_line *line) {
|
void render(struct output *output, struct config *config, struct status_line *line) {
|
||||||
int i;
|
|
||||||
|
|
||||||
struct window *window = output->window;
|
struct window *window = output->window;
|
||||||
cairo_t *cairo = window->cairo;
|
cairo_t *cairo = window->cairo;
|
||||||
bool is_focused = output->focused;
|
bool is_focused = output->focused;
|
||||||
|
|
@ -316,8 +314,8 @@ void render(struct output *output, struct config *config, struct status_line *li
|
||||||
} else if (line->protocol == I3BAR && line->block_line) {
|
} else if (line->protocol == I3BAR && line->block_line) {
|
||||||
double pos = (window->width * window->scale) - 0.5;
|
double pos = (window->width * window->scale) - 0.5;
|
||||||
bool edge = true;
|
bool edge = true;
|
||||||
for (i = line->block_line->length - 1; i >= 0; --i) {
|
for (ssize_t i = line->block_line->length - 1; i >= 0; --i) {
|
||||||
struct status_block *block = line->block_line->items[i];
|
struct status_block *block = *(struct status_block **)list_get(line->block_line, i);
|
||||||
if (block->full_text && block->full_text[0]) {
|
if (block->full_text && block->full_text[0]) {
|
||||||
render_block(window, config, block, &pos, edge, is_focused);
|
render_block(window, config, block, &pos, edge, is_focused);
|
||||||
edge = false;
|
edge = false;
|
||||||
|
|
@ -330,8 +328,8 @@ void render(struct output *output, struct config *config, struct status_line *li
|
||||||
|
|
||||||
// Workspaces
|
// Workspaces
|
||||||
if (config->workspace_buttons) {
|
if (config->workspace_buttons) {
|
||||||
for (i = 0; i < output->workspaces->length; ++i) {
|
for (size_t i = 0; i < output->workspaces->length; ++i) {
|
||||||
struct workspace *ws = output->workspaces->items[i];
|
struct workspace *ws = *(struct workspace **)list_get(output->workspaces, i);
|
||||||
render_workspace_button(window, config, ws, &x);
|
render_workspace_button(window, config, ws, &x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,11 +62,15 @@ static void parse_json(struct bar *bar, const char *text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bar->status->block_line) {
|
if (bar->status->block_line) {
|
||||||
list_foreach(bar->status->block_line, free_status_block);
|
//list_foreach(bar->status->block_line, free_status_block);
|
||||||
|
for (size_t i = 0; i < bar->status->block_line->length; ++i) {
|
||||||
|
struct status_block *item = *(struct status_block **)list_get(bar->status->block_line, i);
|
||||||
|
free_status_block(item);
|
||||||
|
}
|
||||||
list_free(bar->status->block_line);
|
list_free(bar->status->block_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
bar->status->block_line = create_list();
|
bar->status->block_line = list_new(sizeof(struct status_block *), 0);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < json_object_array_length(results); ++i) {
|
for (i = 0; i < json_object_array_length(results); ++i) {
|
||||||
|
|
@ -199,7 +203,7 @@ static void parse_json(struct bar *bar, const char *text) {
|
||||||
new->border_right = 1;
|
new->border_right = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
list_add(bar->status->block_line, new);
|
list_add(bar->status->block_line, &new);
|
||||||
}
|
}
|
||||||
|
|
||||||
json_object_put(results);
|
json_object_put(results);
|
||||||
|
|
@ -438,7 +442,7 @@ bool handle_status_line(struct bar *bar) {
|
||||||
|
|
||||||
struct status_line *init_status_line() {
|
struct status_line *init_status_line() {
|
||||||
struct status_line *line = malloc(sizeof(struct status_line));
|
struct status_line *line = malloc(sizeof(struct status_line));
|
||||||
line->block_line = create_list();
|
line->block_line = list_new(sizeof(struct status_block *), 0);
|
||||||
line->text_line = NULL;
|
line->text_line = NULL;
|
||||||
line->protocol = UNDEF;
|
line->protocol = UNDEF;
|
||||||
|
|
||||||
|
|
@ -447,7 +451,11 @@ struct status_line *init_status_line() {
|
||||||
|
|
||||||
void free_status_line(struct status_line *line) {
|
void free_status_line(struct status_line *line) {
|
||||||
if (line->block_line) {
|
if (line->block_line) {
|
||||||
list_foreach(line->block_line, free_status_block);
|
//list_foreach(line->block_line, free_status_block);
|
||||||
|
for (size_t i = 0; i < line->block_line->length; ++i) {
|
||||||
|
struct status_block *item = *(struct status_block **)list_get(line->block_line, i);
|
||||||
|
free_status_block(item);
|
||||||
|
}
|
||||||
list_free(line->block_line);
|
list_free(line->block_line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,8 @@ enum scaling_mode {
|
||||||
};
|
};
|
||||||
|
|
||||||
void sway_terminate(int exit_code) {
|
void sway_terminate(int exit_code) {
|
||||||
int i;
|
for (size_t i = 0; i < surfaces->length; ++i) {
|
||||||
for (i = 0; i < surfaces->length; ++i) {
|
struct window *window = *(struct window **)list_get(surfaces, i);
|
||||||
struct window *window = surfaces->items[i];
|
|
||||||
window_teardown(window);
|
window_teardown(window);
|
||||||
}
|
}
|
||||||
list_free(surfaces);
|
list_free(surfaces);
|
||||||
|
|
@ -54,7 +53,7 @@ bool is_valid_color(const char *color) {
|
||||||
|
|
||||||
int main(int argc, const char **argv) {
|
int main(int argc, const char **argv) {
|
||||||
init_log(L_INFO);
|
init_log(L_INFO);
|
||||||
surfaces = create_list();
|
surfaces = list_new(sizeof(struct window *), 0);
|
||||||
registry = registry_poll();
|
registry = registry_poll();
|
||||||
|
|
||||||
if (argc != 4) {
|
if (argc != 4) {
|
||||||
|
|
@ -66,9 +65,8 @@ int main(int argc, const char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int desired_output = atoi(argv[1]);
|
int desired_output = atoi(argv[1]);
|
||||||
sway_log(L_INFO, "Using output %d of %d", desired_output, registry->outputs->length);
|
sway_log(L_INFO, "Using output %d of %zu", desired_output, registry->outputs->length);
|
||||||
int i;
|
struct output_state *output = *(struct output_state **)list_get(registry->outputs, desired_output);
|
||||||
struct output_state *output = registry->outputs->items[desired_output];
|
|
||||||
struct window *window = window_setup(registry,
|
struct window *window = window_setup(registry,
|
||||||
output->width, output->height, output->scale, false);
|
output->width, output->height, output->scale, false);
|
||||||
if (!window) {
|
if (!window) {
|
||||||
|
|
@ -76,7 +74,7 @@ int main(int argc, const char **argv) {
|
||||||
}
|
}
|
||||||
desktop_shell_set_background(registry->desktop_shell, output->output, window->surface);
|
desktop_shell_set_background(registry->desktop_shell, output->output, window->surface);
|
||||||
window_make_shell(window);
|
window_make_shell(window);
|
||||||
list_add(surfaces, window);
|
list_add(surfaces, &window);
|
||||||
|
|
||||||
if (strcmp(argv[3], "solid_color") == 0 && is_valid_color(argv[2])) {
|
if (strcmp(argv[3], "solid_color") == 0 && is_valid_color(argv[2])) {
|
||||||
cairo_set_source_u32(window->cairo, parse_color(argv[2]));
|
cairo_set_source_u32(window->cairo, parse_color(argv[2]));
|
||||||
|
|
@ -119,8 +117,8 @@ int main(int argc, const char **argv) {
|
||||||
int wwidth = window->width * window->scale;
|
int wwidth = window->width * window->scale;
|
||||||
int wheight = window->height * window->scale;
|
int wheight = window->height * window->scale;
|
||||||
|
|
||||||
for (i = 0; i < surfaces->length; ++i) {
|
for (size_t i = 0; i < surfaces->length; ++i) {
|
||||||
struct window *window = surfaces->items[i];
|
struct window *window = *(struct window **)list_get(surfaces, i);
|
||||||
if (window_prerender(window) && window->cairo) {
|
if (window_prerender(window) && window->cairo) {
|
||||||
switch (scaling_mode) {
|
switch (scaling_mode) {
|
||||||
case SCALING_MODE_STRETCH:
|
case SCALING_MODE_STRETCH:
|
||||||
|
|
@ -196,8 +194,8 @@ int main(int argc, const char **argv) {
|
||||||
|
|
||||||
while (wl_display_dispatch(registry->display) != -1);
|
while (wl_display_dispatch(registry->display) != -1);
|
||||||
|
|
||||||
for (i = 0; i < surfaces->length; ++i) {
|
for (size_t i = 0; i < surfaces->length; ++i) {
|
||||||
struct window *window = surfaces->items[i];
|
struct window *window = *(struct window **)list_get(surfaces, i);
|
||||||
window_teardown(window);
|
window_teardown(window);
|
||||||
}
|
}
|
||||||
list_free(surfaces);
|
list_free(surfaces);
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,8 @@ void sigalarm_handler(int sig) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void sway_terminate(int exit_code) {
|
void sway_terminate(int exit_code) {
|
||||||
int i;
|
for (size_t i = 0; i < render_data.surfaces->length; ++i) {
|
||||||
for (i = 0; i < render_data.surfaces->length; ++i) {
|
struct window *window = *(struct window **)list_get(render_data.surfaces, i);
|
||||||
struct window *window = render_data.surfaces->items[i];
|
|
||||||
window_teardown(window);
|
window_teardown(window);
|
||||||
}
|
}
|
||||||
list_free(render_data.surfaces);
|
list_free(render_data.surfaces);
|
||||||
|
|
@ -346,7 +345,6 @@ cairo_surface_t *load_image(char *image_path) {
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
const char *scaling_mode_str = "fit", *socket_path = NULL;
|
const char *scaling_mode_str = "fit", *socket_path = NULL;
|
||||||
int i;
|
|
||||||
void *images = NULL;
|
void *images = NULL;
|
||||||
config = init_config();
|
config = init_config();
|
||||||
|
|
||||||
|
|
@ -535,7 +533,7 @@ int main(int argc, char **argv) {
|
||||||
password_size = 1024;
|
password_size = 1024;
|
||||||
password = malloc(password_size);
|
password = malloc(password_size);
|
||||||
password[0] = '\0';
|
password[0] = '\0';
|
||||||
render_data.surfaces = create_list();
|
render_data.surfaces = list_new(sizeof(struct window *), 0);
|
||||||
if (!socket_path) {
|
if (!socket_path) {
|
||||||
socket_path = get_socketpath();
|
socket_path = get_socketpath();
|
||||||
if (!socket_path) {
|
if (!socket_path) {
|
||||||
|
|
@ -557,14 +555,14 @@ int main(int argc, char **argv) {
|
||||||
registry->pointer = NULL;
|
registry->pointer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < registry->outputs->length; ++i) {
|
for (size_t i = 0; i < registry->outputs->length; ++i) {
|
||||||
struct output_state *output = registry->outputs->items[i];
|
struct output_state *output = *(struct output_state **)list_get(registry->outputs, i);
|
||||||
struct window *window = window_setup(registry,
|
struct window *window = window_setup(registry,
|
||||||
output->width, output->height, output->scale, true);
|
output->width, output->height, output->scale, true);
|
||||||
if (!window) {
|
if (!window) {
|
||||||
sway_abort("Failed to create surfaces.");
|
sway_abort("Failed to create surfaces.");
|
||||||
}
|
}
|
||||||
list_add(render_data.surfaces, window);
|
list_add(render_data.surfaces, &window);
|
||||||
}
|
}
|
||||||
|
|
||||||
registry->input->notify = notify_key;
|
registry->input->notify = notify_key;
|
||||||
|
|
@ -579,7 +577,7 @@ int main(int argc, char **argv) {
|
||||||
char *outputs = ipc_single_command(socketfd, IPC_GET_OUTPUTS, "", &len);
|
char *outputs = ipc_single_command(socketfd, IPC_GET_OUTPUTS, "", &len);
|
||||||
struct json_object *json_outputs = json_tokener_parse(outputs);
|
struct json_object *json_outputs = json_tokener_parse(outputs);
|
||||||
|
|
||||||
for (i = 0; i < registry->outputs->length; ++i) {
|
for (size_t i = 0; i < registry->outputs->length; ++i) {
|
||||||
if (displays_paths[i * 2] != NULL) {
|
if (displays_paths[i * 2] != NULL) {
|
||||||
for (int j = 0;; ++j) {
|
for (int j = 0;; ++j) {
|
||||||
if (j >= json_object_array_length(json_outputs)) {
|
if (j >= json_object_array_length(json_outputs)) {
|
||||||
|
|
@ -608,9 +606,9 @@ int main(int argc, char **argv) {
|
||||||
bool locked = false;
|
bool locked = false;
|
||||||
while (wl_display_dispatch(registry->display) != -1) {
|
while (wl_display_dispatch(registry->display) != -1) {
|
||||||
if (!locked) {
|
if (!locked) {
|
||||||
for (i = 0; i < registry->outputs->length; ++i) {
|
for (size_t i = 0; i < registry->outputs->length; ++i) {
|
||||||
struct output_state *output = registry->outputs->items[i];
|
struct output_state *output = *(struct output_state **)list_get(registry->outputs, i);
|
||||||
struct window *window = render_data.surfaces->items[i];
|
struct window *window = *(struct window **)list_get(render_data.surfaces, i);
|
||||||
lock_set_lock_surface(registry->swaylock, output->output, window->surface);
|
lock_set_lock_surface(registry->swaylock, output->output, window->surface);
|
||||||
}
|
}
|
||||||
locked = true;
|
locked = true;
|
||||||
|
|
@ -621,7 +619,7 @@ int main(int argc, char **argv) {
|
||||||
if (render_data.num_images == -1) {
|
if (render_data.num_images == -1) {
|
||||||
cairo_surface_destroy(render_data.image);
|
cairo_surface_destroy(render_data.image);
|
||||||
} else if (render_data.num_images >= 1) {
|
} else if (render_data.num_images >= 1) {
|
||||||
for (i = 0; i < registry->outputs->length; ++i) {
|
for (size_t i = 0; i < registry->outputs->length; ++i) {
|
||||||
if (render_data.images[i] != NULL) {
|
if (render_data.images[i] != NULL) {
|
||||||
cairo_surface_destroy(render_data.images[i]);
|
cairo_surface_destroy(render_data.images[i]);
|
||||||
}
|
}
|
||||||
|
|
@ -629,8 +627,8 @@ int main(int argc, char **argv) {
|
||||||
free(render_data.images);
|
free(render_data.images);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < render_data.surfaces->length; ++i) {
|
for (size_t i = 0; i < render_data.surfaces->length; ++i) {
|
||||||
struct window *window = render_data.surfaces->items[i];
|
struct window *window = *(struct window **)list_get(render_data.surfaces, i);
|
||||||
window_teardown(window);
|
window_teardown(window);
|
||||||
}
|
}
|
||||||
list_free(render_data.surfaces);
|
list_free(render_data.surfaces);
|
||||||
|
|
@ -642,10 +640,9 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(struct render_data *render_data, struct lock_config *config) {
|
void render(struct render_data *render_data, struct lock_config *config) {
|
||||||
int i;
|
for (size_t i = 0; i < render_data->surfaces->length; ++i) {
|
||||||
for (i = 0; i < render_data->surfaces->length; ++i) {
|
sway_log(L_DEBUG, "Render surface %zu of %zu", i, render_data->surfaces->length);
|
||||||
sway_log(L_DEBUG, "Render surface %d of %d", i, render_data->surfaces->length);
|
struct window *window = *(struct window **)list_get(render_data->surfaces, i);
|
||||||
struct window *window = render_data->surfaces->items[i];
|
|
||||||
if (!window_prerender(window) || !window->cairo) {
|
if (!window_prerender(window) || !window->cairo) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ static void registry_global(void *data, struct wl_registry *registry,
|
||||||
ostate->output = output;
|
ostate->output = output;
|
||||||
ostate->scale = 1;
|
ostate->scale = 1;
|
||||||
wl_output_add_listener(output, &output_listener, ostate);
|
wl_output_add_listener(output, &output_listener, ostate);
|
||||||
list_add(reg->outputs, ostate);
|
list_add(reg->outputs, &ostate);
|
||||||
} else if (strcmp(interface, desktop_shell_interface.name) == 0) {
|
} else if (strcmp(interface, desktop_shell_interface.name) == 0) {
|
||||||
reg->desktop_shell = wl_registry_bind(registry, name, &desktop_shell_interface, version);
|
reg->desktop_shell = wl_registry_bind(registry, name, &desktop_shell_interface, version);
|
||||||
} else if (strcmp(interface, lock_interface.name) == 0) {
|
} else if (strcmp(interface, lock_interface.name) == 0) {
|
||||||
|
|
@ -247,7 +247,7 @@ static const struct wl_registry_listener registry_listener = {
|
||||||
struct registry *registry_poll(void) {
|
struct registry *registry_poll(void) {
|
||||||
struct registry *registry = malloc(sizeof(struct registry));
|
struct registry *registry = malloc(sizeof(struct registry));
|
||||||
memset(registry, 0, sizeof(struct registry));
|
memset(registry, 0, sizeof(struct registry));
|
||||||
registry->outputs = create_list();
|
registry->outputs = list_new(sizeof(struct output_state *), 0);
|
||||||
registry->input = calloc(sizeof(struct input), 1);
|
registry->input = calloc(sizeof(struct input), 1);
|
||||||
registry->input->xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
registry->input->xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue