} else if (strcmp(cmd, "list_windows") == 0) {
list_windows(rsp);
return;
+ } else if (strcmp(cmd, "list_history") == 0) {
+ list_history(mon->desk, rsp);
+ } else if (strcmp(cmd, "list_rules") == 0) {
+ list_rules(rsp);
return;
} else if (strcmp(cmd, "close") == 0) {
window_close(mon->desk->focus);
if (name != NULL) {
rule_t *rule = make_rule();
strncpy(rule->cause.name, name, sizeof(rule->cause.name));
- char *arg = strtok(NULL, TOKEN_SEP);
+ char *arg = strtok(NULL, TOK_SEP);
while (arg != NULL) {
- if (strcmp(arg, "floating") == 0)
+ if (strcmp(arg, "floating") == 0) {
rule->effect.floating = true;
- arg = strtok(NULL, TOKEN_SEP);
+ } else {
+ desktop_location_t loc;
+ if (locate_desktop(arg, &loc)) {
+ rule->effect.monitor = loc.monitor;
+ rule->effect.desktop = loc.desktop;
+ }
+ }
+ arg = strtok(NULL, TOK_SEP);
}
- rule->next = rule_head;
- rule_head = rule;
+ add_rule(rule);
}
return;
+ } else if (strcmp(cmd, "remove_rule") == 0) {
+ char *arg;
+ unsigned int uid;
+ while ((arg = strtok(NULL, TOK_SEP)) != NULL)
+ if (sscanf(arg, "%X", &uid) > 0)
+ remove_rule_by_uid(uid);
+ return;
+ } else if (strcmp(cmd, "swap") == 0) {
+ swap_nodes(mon->desk->focus, mon->desk->last_focus);
} else if (strcmp(cmd, "alternate") == 0) {
- focus_node(mon, mon->desk, mon->desk->last_focus, true);
+ node_list_t *a = mon->desk->focus_history->head->prev;
+ if (a != NULL)
+ focus_node(mon, mon->desk, a->node, true);
+ return;
} else if (strcmp(cmd, "alternate_desktop") == 0) {
select_desktop(mon->last_desk);
} else if (strcmp(cmd, "alternate_monitor") == 0) {
rotate_tree(n->second_child, rot);
}
- void magnetise_tree(node_t *n, corner_t corner)
- {
- if (n == NULL || is_leaf(n))
- return;
-
- PUTS("magnetise tree");
-
- switch (n->split_type) {
- case TYPE_HORIZONTAL:
- if (corner == TOP_LEFT || corner == TOP_RIGHT)
- change_split_ratio(n, CHANGE_DECREASE);
- else
- change_split_ratio(n, CHANGE_INCREASE);
- break;
- case TYPE_VERTICAL:
- if (corner == TOP_LEFT || corner == BOTTOM_LEFT)
- change_split_ratio(n, CHANGE_DECREASE);
- else
- change_split_ratio(n, CHANGE_INCREASE);
- break;
- default:
- break;
- }
-
- magnetise_tree(n->first_child, corner);
- magnetise_tree(n->second_child, corner);
- }
-
- void dump_tree(desktop_t *d, node_t *n, char *rsp, unsigned int depth)
- {
- if (n == NULL)
- return;
-
- char line[MAXLEN];
-
- for (unsigned int i = 0; i < depth; i++)
- strncat(rsp, " ", REMLEN(rsp));
-
- if (is_leaf(n))
- snprintf(line, sizeof(line), "%s %X %s%s%s%s%s", n->client->class_name, n->client->window, (n->client->floating ? "f" : "-"), (n->client->transient ? "t" : "-"), (n->client->fullscreen ? "F" : "-"), (n->client->urgent ? "u" : "-"), (n->client->locked ? "l" : "-"));
- else
- snprintf(line, sizeof(line), "%s %.2f", (n->split_type == TYPE_HORIZONTAL ? "H" : "V"), n->split_ratio);
-
- strncat(rsp, line, REMLEN(rsp));
-
- if (n == d->focus)
- strncat(rsp, " *\n", REMLEN(rsp));
- else
- strncat(rsp, "\n", REMLEN(rsp));
-
- dump_tree(d, n->first_child, rsp, depth + 1);
- dump_tree(d, n->second_child, rsp, depth + 1);
- }
-
- void refresh_current(void) {
- if (mon->desk->focus == NULL)
- ewmh_update_active_window();
- else
- focus_node(mon, mon->desk, mon->desk->focus, true);
- }
-
- void list_monitors(list_option_t opt, char *rsp)
- {
- monitor_t *m = mon_head;
-
- while (m != NULL) {
- strncat(rsp, m->name, REMLEN(rsp));
- if (mon == m)
- strncat(rsp, " #\n", REMLEN(rsp));
- else
- strncat(rsp, "\n", REMLEN(rsp));
- if (opt == LIST_OPTION_VERBOSE)
- list_desktops(m, opt, 1, rsp);
- m = m->next;
- }
- }
-
- void list_desktops(monitor_t *m, list_option_t opt, unsigned int depth, char *rsp)
- {
- desktop_t *d = m->desk_head;
-
- while (d != NULL) {
- for (unsigned int i = 0; i < depth; i++)
- strncat(rsp, " ", REMLEN(rsp));
- strncat(rsp, d->name, REMLEN(rsp));
- if (m->desk == d)
- strncat(rsp, " @\n", REMLEN(rsp));
- else
- strncat(rsp, "\n", REMLEN(rsp));
- if (opt == LIST_OPTION_VERBOSE)
- dump_tree(d, d->root, rsp, depth + 1);
- d = d->next;
- }
- }
+void list_history(desktop_t *d, char *rsp)
+{
+ char line[MAXLEN];
+ for (node_list_t *a = d->focus_history->head; a != NULL; a = a->prev) {
+ snprintf(line, sizeof(line), "%s %X\n", a->node->client->class_name, a->node->client->window);
+ strncat(rsp, line, REMLEN(rsp));
+ }
+}
+
void arrange(monitor_t *m, desktop_t *d)
{
- PRINTF("arrange %s:%s\n", m->name, d->name);
+ PRINTF("arrange %s%s%s\n", (num_monitors > 1 ? m->name : ""), (num_monitors > 1 ? " " : ""), d->name);
xcb_rectangle_t rect = m->rectangle;
- rect.x += left_padding + window_gap;
- rect.y += top_padding + window_gap;
- rect.width -= left_padding + right_padding + window_gap;
- rect.height -= top_padding + bottom_padding + window_gap;
- if (focus_follows_mouse)
- get_pointer_position(&pointer_position);
+ int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : window_gap);
+ rect.x += m->left_padding + wg;
+ rect.y += m->top_padding + wg;
+ rect.width -= m->left_padding + m->right_padding + wg;
+ rect.height -= m->top_padding + m->bottom_padding + wg;
+ if (focus_follows_pointer)
+ save_pointer_position(&last_pointer_position);
apply_layout(m, d, d->root, rect, rect);
}
xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT, n->client->window, XCB_CURRENT_TIME);
}
- if (!is_tiled(n->client))
- window_raise(n->client->window);
+ if (focus_follows_pointer) {
+ save_pointer_position(&last_pointer_position);
+ if (n != mon->desk->focus) {
+ if (last_focused_window != XCB_NONE) {
+ uint32_t values[] = {CLIENT_EVENT_MASK_FFP};
+ xcb_change_window_attributes(dpy, last_focused_window, XCB_CW_EVENT_MASK, values);
+ }
+ uint32_t values[] = {CLIENT_EVENT_MASK};
+ xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
+ last_focused_window = n->client->window;
+ }
+ }
+
+ if (!is_tiled(n->client)) {
+ if (!adaptative_raise || !might_cover(d, n))
+ window_raise(n->client->window);
+ } else {
+ window_pseudo_raise(d, n->client->window);
+ }
if (d->focus != n) {
- d->last_focus = d->focus;
d->focus = n;
+ history_add(d->focus_history, n);
}
ewmh_update_active_window();