Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Jul 8, 2024
1 parent cc6b862 commit ff53061
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 260 deletions.
41 changes: 20 additions & 21 deletions src/event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,29 +154,28 @@ static EVENT_HANDLER(APPLICATION_LAUNCHED)
if (default_origin) sid = window_space(window->id);

struct view *view = space_manager_find_view(&g_space_manager, sid);
if (view->layout == VIEW_FLOAT) goto next;

//
// @cleanup
//
// :AXBatching
//
// NOTE(koekeishiya): Batch all operations and mark the view as dirty so that we can perform a single flush,
// making sure that each window is only moved and resized a single time, when the final layout has been computed.
// This is necessary to make sure that we do not call the AX API for each modification to the tree.
//

window_manager_adjust_layer(window, LAYER_BELOW);
view_add_window_node_with_insertion_point(view, window, prev_window_id);
window_manager_add_managed_window(&g_window_manager, window, view);

view_set_flag(view, VIEW_IS_DIRTY);
view_list[view_count++] = view;

prev_window_id = window->id;
if (view->layout != VIEW_FLOAT) {
//
// @cleanup
//
// :AXBatching
//
// NOTE(koekeishiya): Batch all operations and mark the view as dirty so that we can perform a single flush,
// making sure that each window is only moved and resized a single time, when the final layout has been computed.
// This is necessary to make sure that we do not call the AX API for each modification to the tree.
//

window_manager_adjust_layer(window, LAYER_BELOW);
view_add_window_node_with_insertion_point(view, window, prev_window_id);
window_manager_add_managed_window(&g_window_manager, window, view);

view_set_flag(view, VIEW_IS_DIRTY);
view_list[view_count++] = view;

prev_window_id = window->id;
}
}

next:
if (window_manager_is_window_eligible(window)) {
event_signal_push(SIGNAL_WINDOW_CREATED, window);
}
Expand Down
33 changes: 9 additions & 24 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,9 @@ static inline bool parse_property(struct properties *properties, char *property,

static struct properties parse_properties(FILE *rsp, struct token token, uint64_t *property_val, char **property_str, int property_count)
{
struct properties result = { .token = token, .did_parse = true, .did_error = false };
struct properties result = { .token = token, .did_error = false };

if (token_is_valid(token) && !token_prefix(token, "--")) {
if ((result.did_parse = token_is_valid(token) && !token_prefix(token, "--"))) {
for (int i = 0, cursor = 0; i < token.length; ++i) {
if (i+1 == token.length) {
if (!parse_property(&result, token.text+cursor, property_val, property_str, property_count)) {
Expand All @@ -637,8 +637,6 @@ static struct properties parse_properties(FILE *rsp, struct token token, uint64_
cursor = i+1;
}
}
} else {
result.did_parse = false;
}

return result;
Expand Down Expand Up @@ -1161,7 +1159,7 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message)
command = get_token(&message);
}

while (token_is_valid(command)) {
for (; token_is_valid(command); command = get_token(&message)) {
if (token_equals(command, COMMAND_CONFIG_DEBUG_OUTPUT)) {
struct token value = get_token(&message);
if (!token_is_valid(value)) {
Expand Down Expand Up @@ -1637,8 +1635,6 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message)
} else {
daemon_fail(rsp, "unknown command '%.*s' for domain '%.*s'\n", command.length, command.text, domain.length, domain.text);
}

command = get_token(&message);
}
}

Expand Down Expand Up @@ -1717,7 +1713,7 @@ static void handle_domain_space(FILE *rsp, struct token domain, char *message)
return;
}

while(token_is_valid(command)) {
for (; token_is_valid(command); command = get_token(&message)) {
if (token_equals(command, COMMAND_SPACE_FOCUS)) {
struct selector selector = parse_space_selector(rsp, &message, acting_sid, false);
if (selector.did_parse && selector.sid) {
Expand Down Expand Up @@ -1982,8 +1978,6 @@ static void handle_domain_space(FILE *rsp, struct token domain, char *message)
} else {
daemon_fail(rsp, "unknown command '%.*s' for domain '%.*s'\n", command.length, command.text, domain.length, domain.text);
}

command = get_token(&message);
}
}

Expand Down Expand Up @@ -2012,7 +2006,7 @@ static void handle_domain_window(FILE *rsp, struct token domain, char *message)
return;
}

while(token_is_valid(command)) {
for (; token_is_valid(command); command = get_token(&message)) {
if (token_equals(command, COMMAND_WINDOW_FOCUS)) {
struct selector selector = parse_window_selector(rsp, &message, acting_window, true);

Expand Down Expand Up @@ -2350,8 +2344,6 @@ static void handle_domain_window(FILE *rsp, struct token domain, char *message)
} else {
daemon_fail(rsp, "unknown command '%.*s' for domain '%.*s'\n", command.length, command.text, domain.length, domain.text);
}

command = get_token(&message);
}
}

Expand Down Expand Up @@ -2540,7 +2532,7 @@ static bool parse_rule(FILE *rsp, char **message, struct rule *rule, struct toke
bool did_parse = true;
bool has_filter = false;

while (token_is_valid(token)) {
for (; token_is_valid(token); token = get_token(message)) {
char *key = NULL;
char *value = NULL;
bool exclusion = false;
Expand All @@ -2549,7 +2541,7 @@ static bool parse_rule(FILE *rsp, char **message, struct rule *rule, struct toke
if (!key || !value) {
daemon_fail(rsp, "invalid key-value pair '%s'\n", token.text);
did_parse = false;
goto rnext;
continue;
}

if (string_equals(key, ARGUMENT_RULE_KEY_LABEL)) {
Expand Down Expand Up @@ -2727,9 +2719,6 @@ static bool parse_rule(FILE *rsp, char **message, struct rule *rule, struct toke
daemon_fail(rsp, "unknown key '%s'\n", key);
did_parse = false;
}

rnext:
token = get_token(message);
}

if (!has_filter) {
Expand Down Expand Up @@ -2816,8 +2805,7 @@ static void handle_domain_signal(FILE *rsp, struct token domain, char *message)
enum signal_type signal_type = SIGNAL_TYPE_UNKNOWN;
struct signal signal = {};

struct token token = get_token(&message);
while (token_is_valid(token)) {
for (struct token token = get_token(&message); token_is_valid(token); token = get_token(&message)) {
char *key = NULL;
char *value = NULL;
bool exclusion = false;
Expand All @@ -2826,7 +2814,7 @@ static void handle_domain_signal(FILE *rsp, struct token domain, char *message)
if (!key || !value) {
daemon_fail(rsp, "invalid key-value pair '%s'\n", token.text);
did_parse = false;
goto snext;
continue;
}

if (string_equals(key, ARGUMENT_SIGNAL_KEY_LABEL)) {
Expand Down Expand Up @@ -2877,9 +2865,6 @@ static void handle_domain_signal(FILE *rsp, struct token domain, char *message)
daemon_fail(rsp, "unknown key '%s'\n", key);
did_parse = false;
}

snext:
token = get_token(&message);
}

if (!has_signal_type) {
Expand Down
2 changes: 2 additions & 0 deletions src/misc/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ void _table_add(struct table *table, void *key, int key_size, void *value);
void table_remove(struct table *table, void *key);
void *table_find(struct table *table, void *key);

#define table_for(it, table_entry, code) for (struct bucket *bucket = table_entry; bucket; bucket = bucket->next) { if (!bucket->value) continue; it = bucket->value; code; }

#endif

#ifdef HASHTABLE_IMPLEMENTATION
Expand Down
58 changes: 23 additions & 35 deletions src/rule.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,20 @@ void rule_combine_effects(struct rule_effects *effects, struct rule_effects *res
void rule_reapply_all(void)
{
for (int window_index = 0; window_index < g_window_manager.window.capacity; ++window_index) {
struct bucket *bucket = g_window_manager.window.buckets[window_index];
while (bucket) {
if (bucket->value) {
struct window *window = bucket->value;
if (window->is_root) {
char *window_title = window_title_ts(window);
char *window_role = window_role_ts(window);
char *window_subrole = window_subrole_ts(window);
table_for (struct window *window, g_window_manager.window.buckets[window_index], {
if (window->is_root) {
char *window_title = window_title_ts(window);
char *window_role = window_role_ts(window);
char *window_subrole = window_subrole_ts(window);

window_manager_apply_manage_rules_to_window(&g_space_manager, &g_window_manager, window, window_title, window_role, window_subrole, false);
window_manager_apply_manage_rules_to_window(&g_space_manager, &g_window_manager, window, window_title, window_role, window_subrole, false);

if (window_manager_is_window_eligible(window)) {
window->is_eligible = true;
window_manager_apply_rules_to_window(&g_space_manager, &g_window_manager, window, window_title, window_role, window_subrole, false);
}
if (window_manager_is_window_eligible(window)) {
window->is_eligible = true;
window_manager_apply_rules_to_window(&g_space_manager, &g_window_manager, window, window_title, window_role, window_subrole, false);
}
}

bucket = bucket->next;
}
})
}
}

Expand Down Expand Up @@ -167,28 +161,22 @@ bool rule_reapply_by_label(char *label)
void rule_apply(struct rule *rule)
{
for (int window_index = 0; window_index < g_window_manager.window.capacity; ++window_index) {
struct bucket *bucket = g_window_manager.window.buckets[window_index];
while (bucket) {
if (bucket->value) {
struct window *window = bucket->value;
if (window->is_root) {
char *window_title = window_title_ts(window);
char *window_role = window_role_ts(window);
char *window_subrole = window_subrole_ts(window);

if (window_manager_rule_matches_window(rule, window, window_title, window_role, window_subrole)) {
window_manager_apply_manage_rule_effects_to_window(&g_space_manager, &g_window_manager, window, &rule->effects, window_title, window_role, window_subrole);

if (window_manager_is_window_eligible(window)) {
window->is_eligible = true;
window_manager_apply_rule_effects_to_window(&g_space_manager, &g_window_manager, window, &rule->effects, window_title, window_role, window_subrole);
}
table_for (struct window *window, g_window_manager.window.buckets[window_index], {
if (window->is_root) {
char *window_title = window_title_ts(window);
char *window_role = window_role_ts(window);
char *window_subrole = window_subrole_ts(window);

if (window_manager_rule_matches_window(rule, window, window_title, window_role, window_subrole)) {
window_manager_apply_manage_rule_effects_to_window(&g_space_manager, &g_window_manager, window, &rule->effects, window_title, window_role, window_subrole);

if (window_manager_is_window_eligible(window)) {
window->is_eligible = true;
window_manager_apply_rule_effects_to_window(&g_space_manager, &g_window_manager, window, &rule->effects, window_title, window_role, window_subrole);
}
}
}

bucket = bucket->next;
}
})
}
}

Expand Down
Loading

0 comments on commit ff53061

Please sign in to comment.