Skip to content

Commit

Permalink
#203 stack is now a valid option for *window --insert*
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Jun 28, 2020
1 parent 31da219 commit 53d44f2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
7 changes: 5 additions & 2 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ extern bool g_verbose;
#define ARGUMENT_COMMON_SEL_EAST "east"
#define ARGUMENT_COMMON_SEL_SOUTH "south"
#define ARGUMENT_COMMON_SEL_WEST "west"
#define ARGUMENT_COMMON_SEL_STACK "stack"
/* ----------------------------------------------------------------------------- */

static bool token_equals(struct token token, char *match)
Expand Down Expand Up @@ -1198,7 +1199,7 @@ static struct selector parse_window_selector(FILE *rsp, char **message, struct w
return result;
}

static struct selector parse_dir_selector(FILE *rsp, char **message)
static struct selector parse_insert_selector(FILE *rsp, char **message)
{
struct selector result = {
.token = get_token(message),
Expand All @@ -1213,6 +1214,8 @@ static struct selector parse_dir_selector(FILE *rsp, char **message)
result.dir = DIR_SOUTH;
} else if (token_equals(result.token, ARGUMENT_COMMON_SEL_WEST)) {
result.dir = DIR_WEST;
} else if (token_equals(result.token, ARGUMENT_COMMON_SEL_STACK)) {
result.dir = STACK;
} else {
result.did_parse = false;
daemon_fail(rsp, "value '%.*s' is not a valid option for DIR_SEL\n", result.token.length, result.token.text);
Expand Down Expand Up @@ -1522,7 +1525,7 @@ static void handle_domain_window(FILE *rsp, struct token domain, char *message)
}
}
} else if (token_equals(command, COMMAND_WINDOW_INSERT)) {
struct selector selector = parse_dir_selector(rsp, &message);
struct selector selector = parse_insert_selector(rsp, &message);
if (selector.did_parse && selector.dir) {
enum window_op_error result = window_manager_set_window_insertion(&g_space_manager, &g_window_manager, acting_window, selector.dir);
if (result == WINDOW_OP_ERROR_INVALID_SRC_VIEW) {
Expand Down
2 changes: 2 additions & 0 deletions src/misc/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#define DIR_SOUTH 180
#define DIR_WEST 270

#define STACK 111

#define TYPE_ABS 0x1
#define TYPE_REL 0x2

Expand Down
26 changes: 18 additions & 8 deletions src/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ void insert_feedback_show(struct window_node *node)
x3 = minx; y3 = maxy;
x4 = midx; y4 = maxy;
} break;
case STACK: {
x1 = minx; y1 = miny;
x2 = minx; y2 = maxy;
x3 = maxx; y3 = maxy;
x4 = maxx; y4 = miny;
} break;
}

CGRect fill = { {x1, y1}, { x3 - x1, y3 - y1 } };
Expand Down Expand Up @@ -585,18 +591,15 @@ void view_remove_window_node(struct view *view, struct window *window)
}
}

void view_stack_window_node(struct view *view, struct window *a, struct window *b)
void view_stack_window_node(struct view *view, struct window_node *node, struct window *window)
{
struct window_node *a_node = view_find_window_node(view, a->id);
assert(a_node);

if (a_node->zoom) {
window_manager_set_window_frame(b, a_node->zoom->area.x, a_node->zoom->area.y, a_node->zoom->area.w, a_node->zoom->area.h);
if (node->zoom) {
window_manager_set_window_frame(window, node->zoom->area.x, node->zoom->area.y, node->zoom->area.w, node->zoom->area.h);
} else {
window_manager_set_window_frame(b, a_node->area.x, a_node->area.y, a_node->area.w, a_node->area.h);
window_manager_set_window_frame(window, node->area.x, node->area.y, node->area.w, node->area.h);
}

a_node->window_id[a_node->window_count++] = b->id;
node->window_id[node->window_count++] = window->id;
}

void view_add_window_node(struct view *view, struct window *window)
Expand All @@ -613,8 +616,15 @@ void view_add_window_node(struct view *view, struct window *window)
view->insertion_point = 0;

if (leaf) {
bool do_stack = leaf->insert_dir == STACK;

leaf->insert_dir = 0;
insert_feedback_destroy(leaf);

if (do_stack) {
view_stack_window_node(view, leaf, window);
return;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct window_node *window_node_find_next_leaf(struct window_node *node);

struct window_node *view_find_window_node_in_direction(struct view *view, struct window_node *source, int direction);
struct window_node *view_find_window_node(struct view *view, uint32_t window_id);
void view_stack_window_node(struct view *view, struct window *a, struct window *b);
void view_stack_window_node(struct view *view, struct window_node *node, struct window *window);
void view_add_window_node(struct view *view, struct window *window);
void view_remove_window_node(struct view *view, struct window *window);
uint32_t *view_find_window_list(struct view *view);
Expand Down
5 changes: 4 additions & 1 deletion src/window_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,10 @@ enum window_op_error window_manager_stack_window(struct space_manager *sm, struc
if (b->is_sticky) window_manager_make_window_sticky(sm, wm, b, false);
}

view_stack_window_node(a_view, a, b);
struct window_node *a_node = view_find_window_node(a_view, a->id);
assert(a_node);

view_stack_window_node(a_view, a_node, b);
window_manager_add_managed_window(wm, b, a_view);

return WINDOW_OP_ERROR_SUCCESS;
Expand Down

0 comments on commit 53d44f2

Please sign in to comment.