Skip to content

Commit

Permalink
#203 track order separately from list and implement focus selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Jun 28, 2020
1 parent c8bde9e commit 9381692
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 63 deletions.
6 changes: 3 additions & 3 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ static void window_did_receive_focus(struct window_manager *wm, struct mouse_sta
if (node->window_count <= 1) return;

for (int i = 0; i < node->window_count; ++i) {
if (node->window_list[i] != window->id) continue;
if (node->window_order[i] != window->id) continue;

memmove(node->window_list + 1, node->window_list, sizeof(uint32_t) * i);
node->window_list[0] = window->id;
memmove(node->window_order + 1, node->window_order, sizeof(uint32_t) * i);
node->window_order[0] = window->id;

break;
}
Expand Down
50 changes: 38 additions & 12 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,20 @@ extern bool g_verbose;
/* ----------------------------------------------------------------------------- */

/* --------------------------------COMMON ARGUMENTS----------------------------- */
#define ARGUMENT_COMMON_VAL_ON "on"
#define ARGUMENT_COMMON_VAL_OFF "off"
#define ARGUMENT_COMMON_SEL_PREV "prev"
#define ARGUMENT_COMMON_SEL_NEXT "next"
#define ARGUMENT_COMMON_SEL_FIRST "first"
#define ARGUMENT_COMMON_SEL_LAST "last"
#define ARGUMENT_COMMON_SEL_RECENT "recent"
#define ARGUMENT_COMMON_SEL_NORTH "north"
#define ARGUMENT_COMMON_SEL_EAST "east"
#define ARGUMENT_COMMON_SEL_SOUTH "south"
#define ARGUMENT_COMMON_SEL_WEST "west"
#define ARGUMENT_COMMON_SEL_STACK "stack"
#define ARGUMENT_COMMON_VAL_ON "on"
#define ARGUMENT_COMMON_VAL_OFF "off"
#define ARGUMENT_COMMON_SEL_PREV "prev"
#define ARGUMENT_COMMON_SEL_NEXT "next"
#define ARGUMENT_COMMON_SEL_FIRST "first"
#define ARGUMENT_COMMON_SEL_LAST "last"
#define ARGUMENT_COMMON_SEL_RECENT "recent"
#define ARGUMENT_COMMON_SEL_NORTH "north"
#define ARGUMENT_COMMON_SEL_EAST "east"
#define ARGUMENT_COMMON_SEL_SOUTH "south"
#define ARGUMENT_COMMON_SEL_WEST "west"
#define ARGUMENT_COMMON_SEL_STACK "stack"
#define ARGUMENT_COMMON_SEL_STACK_PREV "stack.prev"
#define ARGUMENT_COMMON_SEL_STACK_NEXT "stack.next"
/* ----------------------------------------------------------------------------- */

static bool token_equals(struct token token, char *match)
Expand Down Expand Up @@ -1174,6 +1176,28 @@ static struct selector parse_window_selector(FILE *rsp, char **message, struct w
} else {
daemon_fail(rsp, "could not locate the most recently focused window.\n");
}
} else if (token_equals(result.token, ARGUMENT_COMMON_SEL_STACK_PREV)) {
if (acting_window) {
struct window *prev_window = window_manager_find_prev_window_in_stack(&g_space_manager, &g_window_manager, acting_window);
if (prev_window) {
result.window = prev_window;
} else {
daemon_fail(rsp, "could not locate the prev stacked window.\n");
}
} else {
daemon_fail(rsp, "could not locate the selected window.\n");
}
} else if (token_equals(result.token, ARGUMENT_COMMON_SEL_STACK_NEXT)) {
if (acting_window) {
struct window *next_window = window_manager_find_next_window_in_stack(&g_space_manager, &g_window_manager, acting_window);
if (next_window) {
result.window = next_window;
} else {
daemon_fail(rsp, "could not locate the next stacked window.\n");
}
} else {
daemon_fail(rsp, "could not locate the selected window.\n");
}
} else if (token_is_valid(result.token)) {
int wid = 0;
if (token_to_int(result.token, &wid)) {
Expand Down Expand Up @@ -1520,6 +1544,8 @@ static void handle_domain_window(FILE *rsp, struct token domain, char *message)
enum window_op_error result = window_manager_stack_window(&g_space_manager, &g_window_manager, acting_window, selector.window);
if (result == WINDOW_OP_ERROR_INVALID_SRC_NODE) {
daemon_fail(rsp, "the acting window is not managed.\n");
} else if (result == WINDOW_OP_ERROR_MAX_STACK) {
daemon_fail(rsp, "cannot stack window, max capacity of %d reached.\n", NODE_MAX_WINDOW_COUNT);
} else if (result == WINDOW_OP_ERROR_SAME_WINDOW) {
daemon_fail(rsp, "cannot stack a window onto itself.\n");
}
Expand Down
60 changes: 50 additions & 10 deletions src/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ void insert_feedback_show(struct window_node *node)
CGPathAddLineToPoint(outline, NULL, x4, y4);

SLSDisableUpdate(g_connection);
SLSOrderWindow(g_connection, node->feedback_window.id, 0, node->window_list[0]);
SLSOrderWindow(g_connection, node->feedback_window.id, 0, node->window_order[0]);
SLSSetWindowShape(g_connection, node->feedback_window.id, 0.0f, 0.0f, frame_region);
CGContextClearRect(node->feedback_window.context, frame);
CGContextFillRect(node->feedback_window.context, fill);
CGContextAddPath(node->feedback_window.context, outline);
CGContextStrokePath(node->feedback_window.context);
CGContextFlush(node->feedback_window.context);
SLSOrderWindow(g_connection, node->feedback_window.id, 1, node->window_list[0]);
SLSOrderWindow(g_connection, node->feedback_window.id, 1, node->window_order[0]);
SLSReenableUpdate(g_connection);
CGPathRelease(outline);
CFRelease(frame_region);
Expand Down Expand Up @@ -247,13 +247,17 @@ static void window_node_split(struct view *view, struct window_node *node, struc

if (window_node_get_child(node) == CHILD_SECOND) {
memcpy(left->window_list, node->window_list, sizeof(uint32_t) * node->window_count);
memcpy(left->window_order, node->window_order, sizeof(uint32_t) * node->window_count);
left->window_count = node->window_count;
right->window_list[0] = window->id;
right->window_order[0] = window->id;
right->window_count = 1;
} else {
memcpy(right->window_list, node->window_list, sizeof(uint32_t) * node->window_count);
memcpy(right->window_order, node->window_order, sizeof(uint32_t) * node->window_count);
right->window_count = node->window_count;
left->window_list[0] = window->id;
left->window_order[0] = window->id;
left->window_count = 1;
}

Expand Down Expand Up @@ -335,6 +339,28 @@ bool window_node_contains_window(struct window_node *node, uint32_t window_id)
return false;
}

void window_node_swap_window_list(struct window_node *a_node, struct window_node *b_node)
{
uint32_t tmp_window_list[NODE_MAX_WINDOW_COUNT];
uint32_t tmp_window_order[NODE_MAX_WINDOW_COUNT];
uint32_t tmp_window_count;

memcpy(tmp_window_list, a_node->window_list, sizeof(uint32_t) * a_node->window_count);
memcpy(tmp_window_order, a_node->window_order, sizeof(uint32_t) * a_node->window_count);
tmp_window_count = a_node->window_count;

memcpy(a_node->window_list, b_node->window_list, sizeof(uint32_t) * b_node->window_count);
memcpy(a_node->window_order, b_node->window_order, sizeof(uint32_t) * b_node->window_count);
a_node->window_count = b_node->window_count;

memcpy(b_node->window_list, tmp_window_list, sizeof(uint32_t) * tmp_window_count);
memcpy(b_node->window_order, tmp_window_order, sizeof(uint32_t) * tmp_window_count);
b_node->window_count = tmp_window_count;

a_node->zoom = NULL;
b_node->zoom = NULL;
}

struct window_node *window_node_find_first_leaf(struct window_node *root)
{
struct window_node *node = root;
Expand Down Expand Up @@ -521,15 +547,25 @@ void view_remove_window_node(struct view *view, struct window *window)
if (!node) return;

if (node->window_count > 1) {
for (int i = 0; i < node->window_count; ++i) {
if (node->window_list[i] != window->id) continue;
bool removed_entry = false;
bool removed_order = false;

memmove(node->window_list + i, node->window_list + i + 1, sizeof(uint32_t) * (node->window_count - i - 1));
--node->window_count;
for (int i = 0; i < node->window_count; ++i) {
if (!removed_entry && node->window_list[i] == window->id) {
memmove(node->window_list + i, node->window_list + i + 1, sizeof(uint32_t) * (node->window_count - i - 1));
removed_entry = true;
}

break;
if (!removed_order && node->window_order[i] == window->id) {
memmove(node->window_order + i, node->window_order + i + 1, sizeof(uint32_t) * (node->window_count - i - 1));
removed_order = true;
}
}

assert(removed_entry);
assert(removed_order);
--node->window_count;

return;
}

Expand All @@ -550,6 +586,7 @@ void view_remove_window_node(struct view *view, struct window *window)


memcpy(parent->window_list, child->window_list, sizeof(uint32_t) * child->window_count);
memcpy(parent->window_order, child->window_order, sizeof(uint32_t) * child->window_count);
parent->window_count = child->window_count;

parent->left = NULL;
Expand Down Expand Up @@ -596,14 +633,17 @@ void view_stack_window_node(struct view *view, struct window_node *node, struct
window_manager_set_window_frame(window, node->area.x, node->area.y, node->area.w, node->area.h);
}

node->window_list[node->window_count++] = window->id;
node->window_list[node->window_count] = window->id;
node->window_order[node->window_count] = window->id;
++node->window_count;
}

void view_add_window_node(struct view *view, struct window *window)
{
if (!window_node_is_occupied(view->root) &&
window_node_is_leaf(view->root)) {
view->root->window_list[0] = window->id;
view->root->window_order[0] = window->id;
view->root->window_count = 1;
} else {
struct window_node *leaf = NULL;
Expand Down Expand Up @@ -728,8 +768,8 @@ void view_serialize(FILE *rsp, struct view *view)
space_is_visible(view->sid),
view->sid == g_space_manager.current_space_id,
space_is_fullscreen(view->sid),
first_leaf ? first_leaf->window_list[0] : 0,
last_leaf ? last_leaf->window_list[0] : 0);
first_leaf ? first_leaf->window_order[0] : 0,
last_leaf ? last_leaf->window_order[0] : 0);
}

void view_update(struct view *view)
Expand Down
5 changes: 4 additions & 1 deletion src/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ struct feedback_window
CGContextRef context;
};

#define NODE_MAX_WINDOW_COUNT 32
struct window_node
{
struct area area;
struct window_node *parent;
struct window_node *left;
struct window_node *right;
struct window_node *zoom;
uint32_t window_list[64];
uint32_t window_list[NODE_MAX_WINDOW_COUNT];
uint32_t window_order[NODE_MAX_WINDOW_COUNT];
uint32_t window_count;
float ratio;
enum window_node_split split;
Expand Down Expand Up @@ -111,6 +113,7 @@ void insert_feedback_destroy(struct window_node *node);
void window_node_flush(struct window_node *node);
void window_node_update(struct view *view, struct window_node *node);
bool window_node_contains_window(struct window_node *node, uint32_t window_id);
void window_node_swap_window_list(struct window_node *a_node, struct window_node *b_node);
struct window_node *window_node_find_first_leaf(struct window_node *root);
struct window_node *window_node_find_last_leaf(struct window_node *root);
struct window_node *window_node_find_prev_leaf(struct window_node *node);
Expand Down
Loading

0 comments on commit 9381692

Please sign in to comment.