Skip to content

Commit

Permalink
#337 implement stacking layout for spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Jul 2, 2020
1 parent 622f6e0 commit 40e915d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 24 deletions.
20 changes: 20 additions & 0 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extern bool g_verbose;
#define ARGUMENT_CONFIG_WINDOW_PLACEMENT_SND "second_child"
#define ARGUMENT_CONFIG_SHADOW_FLT "float"
#define ARGUMENT_CONFIG_LAYOUT_BSP "bsp"
#define ARGUMENT_CONFIG_LAYOUT_STACK "stack"
#define ARGUMENT_CONFIG_LAYOUT_FLOAT "float"
#define ARGUMENT_CONFIG_MOUSE_MOD_ALT "alt"
#define ARGUMENT_CONFIG_MOUSE_MOD_SHIFT "shift"
Expand Down Expand Up @@ -101,6 +102,7 @@ extern bool g_verbose;
#define ARGUMENT_SPACE_TGL_MC "mission-control"
#define ARGUMENT_SPACE_TGL_SD "show-desktop"
#define ARGUMENT_SPACE_LAYOUT_BSP "bsp"
#define ARGUMENT_SPACE_LAYOUT_STACK "stack"
#define ARGUMENT_SPACE_LAYOUT_FLT "float"
/* ----------------------------------------------------------------------------- */

Expand Down Expand Up @@ -668,6 +670,16 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message)
if (space_is_user(sel_sid)) {
view->layout = VIEW_BSP;
view->custom_layout = true;
view_clear(view);
window_manager_validate_and_check_for_windows_on_space(&g_space_manager, &g_window_manager, sel_sid);
} else {
daemon_fail(rsp, "cannot set layout for a macOS fullscreen space!\n");
}
} else if (token_equals(value, ARGUMENT_CONFIG_LAYOUT_STACK)) {
if (space_is_user(sel_sid)) {
view->layout = VIEW_STACK;
view->custom_layout = true;
view_clear(view);
window_manager_validate_and_check_for_windows_on_space(&g_space_manager, &g_window_manager, sel_sid);
} else {
daemon_fail(rsp, "cannot set layout for a macOS fullscreen space!\n");
Expand All @@ -691,6 +703,8 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message)
fprintf(rsp, "%s\n", view_type_str[g_space_manager.layout]);
} else if (token_equals(value, ARGUMENT_CONFIG_LAYOUT_BSP)) {
space_manager_set_layout_for_all_spaces(&g_space_manager, VIEW_BSP);
} else if (token_equals(value, ARGUMENT_CONFIG_LAYOUT_STACK)) {
space_manager_set_layout_for_all_spaces(&g_space_manager, VIEW_STACK);
} else if (token_equals(value, ARGUMENT_CONFIG_LAYOUT_FLOAT)) {
space_manager_set_layout_for_all_spaces(&g_space_manager, VIEW_FLOAT);
} else {
Expand Down Expand Up @@ -1507,6 +1521,12 @@ static void handle_domain_space(FILE *rsp, struct token domain, char *message)
} else {
daemon_fail(rsp, "cannot set layout for a macOS fullscreen space!\n");
}
} else if (token_equals(value, ARGUMENT_SPACE_LAYOUT_STACK)) {
if (space_is_user(acting_sid)) {
space_manager_set_layout_for_space(&g_space_manager, acting_sid, VIEW_STACK);
} else {
daemon_fail(rsp, "cannot set layout for a macOS fullscreen space!\n");
}
} else if (token_equals(value, ARGUMENT_SPACE_LAYOUT_FLT)) {
if (space_is_user(acting_sid)) {
space_manager_set_layout_for_space(&g_space_manager, acting_sid, VIEW_FLOAT);
Expand Down
39 changes: 19 additions & 20 deletions src/space_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ struct view *space_manager_find_view(struct space_manager *sm, uint64_t sid)
void space_manager_refresh_view(struct space_manager *sm, uint64_t sid)
{
struct view *view = space_manager_find_view(sm, sid);
if (view->layout != VIEW_BSP) return;
if (view->layout == VIEW_FLOAT) return;

view_update(view);
view_flush(view);
Expand All @@ -126,22 +126,22 @@ void space_manager_refresh_view(struct space_manager *sm, uint64_t sid)
void space_manager_mark_view_invalid(struct space_manager *sm, uint64_t sid)
{
struct view *view = space_manager_find_view(sm, sid);
if (view->layout != VIEW_BSP) return;
if (view->layout == VIEW_FLOAT) return;

view->is_valid = false;
}

void space_manager_mark_view_dirty(struct space_manager *sm, uint64_t sid)
{
struct view *view = space_manager_find_view(sm, sid);
if (view->layout != VIEW_BSP) return;
if (view->layout == VIEW_FLOAT) return;

view->is_dirty = true;
}

void space_manager_untile_window(struct space_manager *sm, struct view *view, struct window *window)
{
if (view->layout != VIEW_BSP) return;
if (view->layout == VIEW_FLOAT) return;

view_remove_window_node(view, window);
view_flush(view);
Expand Down Expand Up @@ -212,18 +212,17 @@ void space_manager_set_layout_for_space(struct space_manager *sm, uint64_t sid,
{
struct view *view = space_manager_find_view(sm, sid);
view->layout = layout;
view_clear(view);

if (view->layout == VIEW_BSP) {
if (view->layout != VIEW_FLOAT) {
window_manager_validate_and_check_for_windows_on_space(sm, &g_window_manager, sid);
} else if (view->layout == VIEW_FLOAT) {
view_clear(view);
}
}

bool space_manager_set_gap_for_space(struct space_manager *sm, uint64_t sid, int type, int gap)
{
struct view *view = space_manager_find_view(sm, sid);
if (view->layout != VIEW_BSP) return false;
if (view->layout == VIEW_FLOAT) return false;

if (type == TYPE_ABS) {
view->window_gap = gap;
Expand All @@ -240,7 +239,7 @@ bool space_manager_set_gap_for_space(struct space_manager *sm, uint64_t sid, int
bool space_manager_toggle_gap_for_space(struct space_manager *sm, uint64_t sid)
{
struct view *view = space_manager_find_view(sm, sid);
if (view->layout != VIEW_BSP) return false;
if (view->layout == VIEW_FLOAT) return false;

view->enable_gap = !view->enable_gap;
view_update(view);
Expand Down Expand Up @@ -272,10 +271,10 @@ void space_manager_set_layout_for_all_spaces(struct space_manager *sm, enum view
if (!view->custom_layout) {
if (space_is_user(view->sid)) {
view->layout = layout;
if (view->layout == VIEW_BSP) {
view_clear(view);

if (view->layout != VIEW_FLOAT) {
window_manager_validate_and_check_for_windows_on_space(sm, &g_window_manager, view->sid);
} else if (view->layout == VIEW_FLOAT) {
view_clear(view);
}
}
}
Expand Down Expand Up @@ -330,7 +329,7 @@ void space_manager_set_right_padding_for_all_spaces(struct space_manager *sm, in
bool space_manager_set_padding_for_space(struct space_manager *sm, uint64_t sid, int type, int top, int bottom, int left, int right)
{
struct view *view = space_manager_find_view(sm, sid);
if (view->layout != VIEW_BSP) return false;
if (view->layout == VIEW_FLOAT) return false;

if (type == TYPE_ABS) {
view->top_padding = top;
Expand All @@ -353,7 +352,7 @@ bool space_manager_set_padding_for_space(struct space_manager *sm, uint64_t sid,
bool space_manager_toggle_padding_for_space(struct space_manager *sm, uint64_t sid)
{
struct view *view = space_manager_find_view(sm, sid);
if (view->layout != VIEW_BSP) return false;
if (view->layout == VIEW_FLOAT) return false;

view->enable_padding = !view->enable_padding;
view_update(view);
Expand Down Expand Up @@ -403,24 +402,24 @@ struct view *space_manager_tile_window_on_space_with_insertion_point(struct spac
uint32_t prev_insertion_point;

struct view *view = space_manager_find_view(sm, sid);
if (view->layout != VIEW_BSP) return view;
if (view->layout == VIEW_FLOAT) return view;

if (insertion_point) {
if (view->layout == VIEW_BSP && insertion_point) {
prev_insertion_point = view->insertion_point;
view->insertion_point = insertion_point;
}

view_add_window_node(view, window);
view_flush(view);

if (insertion_point) {
view->insertion_point = prev_insertion_point;
}

if (!space_is_visible(view->sid)) {
view->is_dirty = true;
}

if (view->layout == VIEW_BSP && insertion_point) {
view->insertion_point = prev_insertion_point;
}

return view;
}

Expand Down
4 changes: 3 additions & 1 deletion src/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ void view_add_window_node(struct view *view, struct window *window)
view->root->window_list[0] = window->id;
view->root->window_order[0] = window->id;
view->root->window_count = 1;
} else {
} else if (view->layout == VIEW_BSP) {
struct window_node *leaf = NULL;

if (view->insertion_point) {
Expand Down Expand Up @@ -683,6 +683,8 @@ void view_add_window_node(struct view *view, struct window *window)
window_node_equalize(view->root);
view_update(view);
}
} else if (view->layout == VIEW_STACK) {
view_stack_window_node(view, view->root, window);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ enum view_type
{
VIEW_DEFAULT,
VIEW_BSP,
VIEW_STACK,
VIEW_FLOAT
};

static const char *view_type_str[] =
{
"default",
"bsp",
"stack",
"float"
};

Expand Down
6 changes: 3 additions & 3 deletions src/window_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ void window_manager_remove_managed_window(struct window_manager *wm, uint32_t wi

void window_manager_add_managed_window(struct window_manager *wm, struct window *window, struct view *view)
{
if (view->layout != VIEW_BSP) return;
if (view->layout == VIEW_FLOAT) return;
table_add(&wm->managed_window, &window->id, view);
window_manager_purify_window(wm, window);
}
Expand Down Expand Up @@ -1528,13 +1528,13 @@ static void window_manager_check_for_windows_on_space(struct space_manager *sm,
if (window->is_minimized || window->application->is_hidden) continue;

struct view *existing_view = window_manager_find_managed_window(wm, window);
if (existing_view && existing_view->layout == VIEW_BSP && existing_view->sid != sid) {
if (existing_view && existing_view->layout != VIEW_FLOAT && existing_view->sid != sid) {
space_manager_untile_window(sm, existing_view, window);
window_manager_remove_managed_window(wm, window->id);
window_manager_purify_window(wm, window);
}

if (!existing_view || (existing_view->layout == VIEW_BSP && existing_view->sid != sid)) {
if (!existing_view || (existing_view->layout != VIEW_FLOAT && existing_view->sid != sid)) {
struct view *view = space_manager_tile_window_on_space(sm, window, sid);
window_manager_add_managed_window(wm, window, view);
}
Expand Down

0 comments on commit 40e915d

Please sign in to comment.