From ec7ff769c7b4da616ebe6bfd90b70350dd39e166 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Fri, 1 Apr 2016 00:04:08 +0200 Subject: [PATCH 01/14] Tabbed and stacked layout --- sway/border.c | 138 +++++++++++++++++++++++++++++++----------- sway/commands.c | 11 +++- sway/config.c | 2 +- sway/container.c | 2 +- sway/focus.c | 10 +++- sway/layout.c | 153 +++++++++++++++++++++++++++++++++++++---------- 6 files changed, 245 insertions(+), 71 deletions(-) diff --git a/sway/border.c b/sway/border.c index a6ed4238..ada5af2a 100644 --- a/sway/border.c +++ b/sway/border.c @@ -91,7 +91,7 @@ int get_font_text_height(const char *font) { return height; } -static void render_borders(swayc_t *view, cairo_t *cr, struct border_colors *colors) { +static void render_borders(swayc_t *view, cairo_t *cr, struct border_colors *colors, bool top) { struct wlc_geometry *b = &view->border_geometry; struct wlc_geometry *v = &view->actual_geometry; @@ -118,7 +118,7 @@ static void render_borders(swayc_t *view, cairo_t *cr, struct border_colors *col // top border int top_border = v->origin.y - b->origin.y; - if (top_border > 0) { + if (top && top_border > 0) { render_sharp_line(cr, colors->child_border, 0, 0, @@ -138,38 +138,69 @@ static void render_borders(swayc_t *view, cairo_t *cr, struct border_colors *col } } -static void render_with_title_bar(swayc_t *view, cairo_t *cr, struct border_colors *colors) { +static void render_title_bar(swayc_t *view, cairo_t *cr, struct border_colors *colors) { struct wlc_geometry *tb = &view->title_bar_geometry; struct wlc_geometry *b = &view->border_geometry; int title_y = MIN(view->actual_geometry.origin.y - (int)tb->size.h, 0); // borders - render_borders(view, cr, colors); + /* render_borders(view, cr, colors); */ + int x = tb->origin.x - b->origin.x; + int y = tb->origin.y - b->origin.y; + + /* // title bar background */ + /* cairo_set_source_u32(cr, colors->child_border); */ + /* cairo_rectangle(cr, x, y, tb->size.w, tb->size.h); */ + /* cairo_fill(cr); */ // title bar background cairo_set_source_u32(cr, colors->background); cairo_rectangle(cr, 0, title_y, tb->size.w, tb->size.h); cairo_fill(cr); // header top line + /* render_sharp_line(cr, colors->border, x, y, tb->size.w, 1); */ render_sharp_line(cr, colors->border, 0, title_y, tb->size.w, 1); // text if (view->name) { int width, height; get_text_size(cr, config->font, &width, &height, false, "%s", view->name); - int x = MIN(view->actual_geometry.origin.x, view->border_thickness); - int y = MIN(view->actual_geometry.origin.y - height - 2, 2); - cairo_move_to(cr, x, y); + int x_text = MIN(view->actual_geometry.origin.x, view->border_thickness); + int y_text = MIN(view->actual_geometry.origin.y - height - 2, 2); + cairo_move_to(cr, x_text, y_text); cairo_set_source_u32(cr, colors->text); pango_printf(cr, config->font, false, "%s", view->name); } - // header bottom line - render_sharp_line(cr, colors->border, - view->actual_geometry.origin.x - b->origin.x, - title_y + tb->size.h - 1, - view->actual_geometry.size.w, 1); + // titlebars has a border all around for tabbed layouts + if (view->parent->layout == L_TABBED) { + // header bottom line + render_sharp_line(cr, colors->border, x, y + tb->size.h - 1, + tb->size.w, 1); + + // left border + render_sharp_line(cr, colors->border, x, y, 1, tb->size.h); + + // right border + render_sharp_line(cr, colors->border, x + tb->size.w - 1, y, + 1, tb->size.h); + + return; + } + + if ((uint32_t)(view->actual_geometry.origin.y - tb->origin.y) == tb->size.h) { + // header bottom line + render_sharp_line(cr, colors->border, + x + view->actual_geometry.origin.x - b->origin.x, + y + tb->size.h - 1, + view->actual_geometry.size.w, 1); + } else { + // header bottom line + render_sharp_line(cr, colors->border, x, + title_y + tb->size.h - 1, + tb->size.w, 1); + } } void map_update_view_border(swayc_t *view, void *data) { @@ -179,6 +210,10 @@ void map_update_view_border(swayc_t *view, void *data) { } void update_view_border(swayc_t *view) { + if (!view->visible) { + return; + } + cairo_t *cr = NULL; cairo_surface_t *surface = NULL; @@ -187,6 +222,7 @@ void update_view_border(swayc_t *view) { view->border = NULL; } + // get focused and focused_intactive views swayc_t *focused = get_focused_view(&root_container); swayc_t *container = swayc_parent_by_type(view, C_CONTAINER); swayc_t *focused_inactive = NULL; @@ -199,40 +235,70 @@ void update_view_border(swayc_t *view) { } } - switch (view->border_type) { - case B_NONE: - break; - case B_PIXEL: - cr = create_border_buffer(view, view->border_geometry, &surface); - if (!cr) { - break; - } + swayc_t *p = view->parent; + if (p->layout == L_TABBED || p->layout == L_STACKED) { + cr = create_border_buffer(view, view->border_geometry, &surface); if (focused == view) { - render_borders(view, cr, &config->border_colors.focused); + render_borders(view, cr, &config->border_colors.focused, false); } else if (focused_inactive == view) { - render_borders(view, cr, &config->border_colors.focused_inactive); + render_borders(view, cr, &config->border_colors.focused_inactive, false); } else { - render_borders(view, cr, &config->border_colors.unfocused); + render_borders(view, cr, &config->border_colors.unfocused, false); } - break; - case B_NORMAL: - cr = create_border_buffer(view, view->border_geometry, &surface); - if (!cr) { - break; - } + int i; + for (i = 0; i < p->children->length; ++i) { + swayc_t *child = p->children->items[i]; - if (focused == view) { - render_with_title_bar(view, cr, &config->border_colors.focused); - } else if (focused_inactive == view) { - render_with_title_bar(view, cr, &config->border_colors.focused_inactive); - } else { - render_with_title_bar(view, cr, &config->border_colors.unfocused); + if (focused == child) { + render_title_bar(child, cr, &config->border_colors.focused); + } else if (focused_inactive == child) { + render_title_bar(child, cr, &config->border_colors.focused_inactive); + } else { + render_title_bar(child, cr, &config->border_colors.unfocused); + } } + } else { + switch (view->border_type) { + case B_NONE: + break; + case B_PIXEL: + cr = create_border_buffer(view, view->border_geometry, &surface); + if (!cr) { + break; + } + + if (focused == view) { + render_borders(view, cr, &config->border_colors.focused, true); + } else if (focused_inactive == view) { + render_borders(view, cr, &config->border_colors.focused_inactive, true); + } else { + render_borders(view, cr, &config->border_colors.unfocused, true); + } - break; + break; + case B_NORMAL: + cr = create_border_buffer(view, view->border_geometry, &surface); + if (!cr) { + break; + } + + if (focused == view) { + render_borders(view, cr, &config->border_colors.focused, false); + render_title_bar(view, cr, &config->border_colors.focused); + } else if (focused_inactive == view) { + render_borders(view, cr, &config->border_colors.focused_inactive, false); + render_title_bar(view, cr, &config->border_colors.focused_inactive); + } else { + render_borders(view, cr, &config->border_colors.unfocused, false); + render_title_bar(view, cr, &config->border_colors.unfocused); + } + + break; + } } + if (surface) { cairo_surface_flush(surface); cairo_surface_destroy(surface); diff --git a/sway/commands.c b/sway/commands.c index 11284577..07dd715c 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -1759,7 +1759,15 @@ static struct cmd_results *cmd_layout(int argc, char **argv) { parent = parent->parent; } - if (strcasecmp(argv[0], "splith") == 0) { + if (strcasecmp(argv[0], "default") == 0) { + // TODO: determine default from default_orientation and + // cmd_workspace_layout + parent->layout = L_HORIZ; + } else if (strcasecmp(argv[0], "tabbed") == 0) { + parent->layout = L_TABBED; + } else if (strcasecmp(argv[0], "stacking") == 0) { + parent->layout = L_STACKED; + } else if (strcasecmp(argv[0], "splith") == 0) { parent->layout = L_HORIZ; } else if (strcasecmp(argv[0], "splitv") == 0) { parent->layout = L_VERT; @@ -1770,6 +1778,7 @@ static struct cmd_results *cmd_layout(int argc, char **argv) { parent->layout = L_VERT; } } + arrange_windows(parent, parent->width, parent->height); return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/config.c b/sway/config.c index ebcee95b..c11ccf53 100644 --- a/sway/config.c +++ b/sway/config.c @@ -160,7 +160,7 @@ static void config_defaults(struct sway_config *config) { config->dragging_key = M_LEFT_CLICK; config->resizing_key = M_RIGHT_CLICK; config->floating_scroll = FSB_GAPS_INNER; - config->default_layout = L_NONE; + config->default_layout = L_HORIZ; config->default_orientation = L_NONE; config->font = strdup("monospace 10"); config->font_height = get_font_text_height(config->font); diff --git a/sway/container.c b/sway/container.c index 95a46632..e77ba062 100644 --- a/sway/container.c +++ b/sway/container.c @@ -725,7 +725,7 @@ void update_visibility_output(swayc_t *container, wlc_handle output) { if (parent->type == C_OUTPUT || parent->layout == L_TABBED || parent->layout == L_STACKED) { - container->visible = parent->focused == container; + container->visible = parent->focused == container && parent->visible; } // Set visibility and output for view if (container->type == C_VIEW) { diff --git a/sway/focus.c b/sway/focus.c index cdc9a888..8acdc772 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -141,9 +141,17 @@ bool set_focused_container(swayc_t *c) { // set focus if view_focus is unlocked if (!locked_view_focus) { wlc_view_focus(p->handle); - update_view_border(p); + if (p->parent->layout != L_TABBED + && p->parent->layout != L_STACKED) { + update_view_border(p); + } } } + + // rearrange if parent container is tabbed/stacked + if (p->parent->layout == L_TABBED || p->parent->layout == L_STACKED) { + arrange_windows(p->parent, -1, -1); + } } else if (p->type == C_WORKSPACE) { // remove previous focus if view_focus is unlocked if (!locked_view_focus) { diff --git a/sway/layout.c b/sway/layout.c index 0b498937..0328d361 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -453,14 +453,24 @@ void update_geometry(swayc_t *container) { gap -= 1; } + int width = container->width; + int height = container->height; + + // use parent size if window is in a stacked/tabbed layout + swayc_t *parent = container->parent; + if (parent->layout == L_STACKED || parent->layout == L_TABBED) { + width = parent->width; + height = parent->height; + } + struct wlc_geometry geometry = { .origin = { .x = container->x + gap/2 < op->width ? container->x + gap/2 : op->width-1, .y = container->y + gap/2 < op->height ? container->y + gap/2 : op->height-1 }, .size = { - .w = container->width > gap ? container->width - gap : 1, - .h = container->height > gap ? container->height - gap : 1, + .w = width > gap ? width - gap : 1, + .h = height > gap ? height - gap : 1, } }; if (swayc_is_fullscreen(container)) { @@ -480,16 +490,16 @@ void update_geometry(swayc_t *container) { // with gap, and align correctly). if (container->x - gap <= ws->x) { geometry.origin.x = ws->x; - geometry.size.w = container->width - gap/2; + geometry.size.w = width - gap/2; } if (container->y - gap <= ws->y) { geometry.origin.y = ws->y; - geometry.size.h = container->height - gap/2; + geometry.size.h = height - gap/2; } - if (container->x + container->width + gap >= ws->x + ws->width) { + if (container->x + width + gap >= ws->x + ws->width) { geometry.size.w = ws->x + ws->width - geometry.origin.x; } - if (container->y + container->height + gap >= ws->y + ws->height) { + if (container->y + height + gap >= ws->y + ws->height) { geometry.size.h = ws->y + ws->height - geometry.origin.y; } } @@ -533,33 +543,93 @@ void update_geometry(swayc_t *container) { } } - switch (container->border_type) { - case B_NONE: - break; - case B_PIXEL: + int title_bar_height = config->font_height + 4; //borders + padding + + if (parent->layout == L_TABBED) { + int i, x = 0, w, l, r; + l = parent->children->length; + w = geometry.size.w / l; + r = geometry.size.w % l; + for (i = 0; i < parent->children->length; ++i) { + swayc_t *view = parent->children->items[i]; + if (view == container) { + x = w * i; + if (i == l - 1) { + w += r; + } + break; + } + } + + struct wlc_geometry title_bar = { + .origin = { + .x = container->border_geometry.origin.x + x, + .y = container->border_geometry.origin.y + }, + .size = { + .w = w, + .h = title_bar_height + } + }; geometry.origin.x += border_left; - geometry.origin.y += border_top; + geometry.origin.y += title_bar.size.h; geometry.size.w -= (border_left + border_right); - geometry.size.h -= (border_top + border_bottom); - break; - case B_NORMAL: - { - struct wlc_geometry title_bar = { - .origin = { - .x = container->border_geometry.origin.x, - .y = container->border_geometry.origin.y - }, - .size = { - .w = container->border_geometry.size.w, - .h = config->font_height + 4 // borders + padding - } - }; + geometry.size.h -= (border_bottom + title_bar.size.h); + container->title_bar_geometry = title_bar; + } else if (parent->layout == L_STACKED) { + int i, y; + for (i = 0; i < parent->children->length; ++i) { + swayc_t *view = parent->children->items[i]; + if (view == container) { + y = title_bar_height * i; + } + } + + struct wlc_geometry title_bar = { + .origin = { + .x = container->border_geometry.origin.x, + .y = container->border_geometry.origin.y + y + }, + .size = { + .w = container->border_geometry.size.w, + .h = title_bar_height + } + }; + title_bar_height = title_bar_height * parent->children->length; + geometry.origin.x += border_left; + geometry.origin.y += title_bar_height; + geometry.size.w -= (border_left + border_right); + geometry.size.h -= (border_bottom + title_bar_height); + container->title_bar_geometry = title_bar; + } else { + switch (container->border_type) { + case B_NONE: + break; + case B_PIXEL: geometry.origin.x += border_left; - geometry.origin.y += title_bar.size.h; + geometry.origin.y += border_top; geometry.size.w -= (border_left + border_right); - geometry.size.h -= (border_bottom + title_bar.size.h); - container->title_bar_geometry = title_bar; + geometry.size.h -= (border_top + border_bottom); break; + case B_NORMAL: + { + struct wlc_geometry title_bar = { + .origin = { + .x = container->border_geometry.origin.x, + .y = container->border_geometry.origin.y + }, + .size = { + .w = container->border_geometry.size.w, + .h = title_bar_height + } + }; + geometry.origin.x += border_left; + geometry.origin.y += title_bar.size.h; + geometry.size.w -= (border_left + border_right); + geometry.size.h -= (border_bottom + title_bar.size.h); + container->title_bar_geometry = title_bar; + break; + } } } @@ -648,7 +718,7 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { height = container->height = height - gap * 2; sway_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", container->name, container->x, container->y); } - // children are properly handled below + // children are properly handled below break; case C_VIEW: { @@ -683,6 +753,7 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { } scale += *old_width; } + // Resize windows if (scale > 0.1) { scale = width / scale; @@ -734,6 +805,26 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { } } break; + case L_TABBED: + case L_STACKED: + { + swayc_t *focused = NULL; + for (i = 0; i < container->children->length; ++i) { + swayc_t *child = container->children->items[i]; + child->x = x; + child->y = y; + if (child == container->focused) { + focused = child; + } else { + arrange_windows_r(child, -1, -1); + } + } + + if (focused) { + arrange_windows_r(focused, -1, -1); + } + break; + } } // Arrage floating layouts for workspaces last @@ -840,12 +931,12 @@ swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_directio return get_swayc_in_output_direction(output, dir); } else { if (dir == MOVE_LEFT || dir == MOVE_RIGHT) { - if (parent->layout == L_HORIZ) { + if (parent->layout == L_HORIZ || parent->layout == L_TABBED) { can_move = true; diff = dir == MOVE_LEFT ? -1 : 1; } } else { - if (parent->layout == L_VERT) { + if (parent->layout == L_VERT || parent->layout == L_STACKED) { can_move = true; diff = dir == MOVE_UP ? -1 : 1; } From 8d700fe008ccf9f7eb4664e236277c9f30a449fb Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Fri, 1 Apr 2016 13:36:36 +0200 Subject: [PATCH 02/14] Fix problems with floating windows Makes any tabbed/stacked layout a container to separate from floating windows which may be attached to a workspace. --- include/container.h | 6 ++++++ sway/border.c | 2 +- sway/commands.c | 8 ++++++++ sway/container.c | 11 +++++++---- sway/focus.c | 2 +- sway/layout.c | 4 +++- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/include/container.h b/include/container.h index 26da851e..d9f33b8a 100644 --- a/include/container.h +++ b/include/container.h @@ -240,6 +240,12 @@ bool swayc_is_parent_of(swayc_t *parent, swayc_t *child); * Returns true if the child is a desecendant of the parent. */ bool swayc_is_child_of(swayc_t *child, swayc_t *parent); + +/** + * Returns true if view is stacked or tabbed. + */ +bool swayc_is_tabbed_stacked(swayc_t *view); + /** * Returns the gap (padding) of the container. * diff --git a/sway/border.c b/sway/border.c index ada5af2a..061c1427 100644 --- a/sway/border.c +++ b/sway/border.c @@ -237,7 +237,7 @@ void update_view_border(swayc_t *view) { swayc_t *p = view->parent; - if (p->layout == L_TABBED || p->layout == L_STACKED) { + if (swayc_is_tabbed_stacked(view)) { cr = create_border_buffer(view, view->border_geometry, &surface); if (focused == view) { render_borders(view, cr, &config->border_colors.focused, false); diff --git a/sway/commands.c b/sway/commands.c index 07dd715c..12d60854 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -1764,8 +1764,16 @@ static struct cmd_results *cmd_layout(int argc, char **argv) { // cmd_workspace_layout parent->layout = L_HORIZ; } else if (strcasecmp(argv[0], "tabbed") == 0) { + if (parent->type != C_CONTAINER) { + parent = new_container(parent, L_TABBED); + } + parent->layout = L_TABBED; } else if (strcasecmp(argv[0], "stacking") == 0) { + if (parent->type != C_CONTAINER) { + parent = new_container(parent, L_STACKED); + } + parent->layout = L_STACKED; } else if (strcasecmp(argv[0], "splith") == 0) { parent->layout = L_HORIZ; diff --git a/sway/container.c b/sway/container.c index e77ba062..2b100f40 100644 --- a/sway/container.c +++ b/sway/container.c @@ -237,7 +237,7 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { add_child(workspace, cont); // give them proper layouts cont->layout = workspace->layout; - workspace->layout = layout; + /* TODO: might break shit in move_container!!! workspace->layout = layout; */ set_focused_container_for(workspace, get_focused_view(workspace)); } else { // Or is built around container swayc_t *parent = replace_child(child, cont); @@ -722,9 +722,7 @@ void update_visibility_output(swayc_t *container, wlc_handle output) { swayc_t *parent = container->parent; container->visible = parent->visible; // special cases where visibility depends on focus - if (parent->type == C_OUTPUT - || parent->layout == L_TABBED - || parent->layout == L_STACKED) { + if (parent->type == C_OUTPUT || swayc_is_tabbed_stacked(container)) { container->visible = parent->focused == container && parent->visible; } // Set visibility and output for view @@ -814,3 +812,8 @@ static void close_view(swayc_t *container, void *data) { void close_views(swayc_t *container) { container_map(container, close_view, NULL); } + +bool swayc_is_tabbed_stacked(swayc_t *view) { + return (view->parent->layout == L_TABBED + || view->parent->layout == L_STACKED); +} diff --git a/sway/focus.c b/sway/focus.c index 8acdc772..8ce22456 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -149,7 +149,7 @@ bool set_focused_container(swayc_t *c) { } // rearrange if parent container is tabbed/stacked - if (p->parent->layout == L_TABBED || p->parent->layout == L_STACKED) { + if (swayc_is_tabbed_stacked(p)) { arrange_windows(p->parent, -1, -1); } } else if (p->type == C_WORKSPACE) { diff --git a/sway/layout.c b/sway/layout.c index 0328d361..527579d9 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -458,7 +458,7 @@ void update_geometry(swayc_t *container) { // use parent size if window is in a stacked/tabbed layout swayc_t *parent = container->parent; - if (parent->layout == L_STACKED || parent->layout == L_TABBED) { + if (swayc_is_tabbed_stacked(container)) { width = parent->width; height = parent->height; } @@ -833,6 +833,8 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { swayc_t *view = container->floating->items[i]; if (view->type == C_VIEW) { update_geometry(view); + sway_log(L_DEBUG, "Set floating view to %.f x %.f @ %.f, %.f", view->width, + view->height, view->x, view->y); if (swayc_is_fullscreen(view)) { wlc_view_bring_to_front(view->handle); } else if (!container->focused From d26658fb355fdf7feee2d6aa801e487502e6ce8b Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Fri, 1 Apr 2016 15:58:29 +0200 Subject: [PATCH 03/14] Correctly determine default layout --- include/layout.h | 5 +++++ sway/commands.c | 5 ++--- sway/config.c | 2 +- sway/container.c | 12 ++---------- sway/layout.c | 12 ++++++++++++ 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/include/layout.h b/include/layout.h index b7731031..84552754 100644 --- a/include/layout.h +++ b/include/layout.h @@ -67,4 +67,9 @@ void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge ed void layout_log(const swayc_t *c, int depth); void swayc_log(log_importance_t verbosity, swayc_t *cont, const char* format, ...) __attribute__((format(printf,3,4))); +/** + * Get default layout. + */ +enum swayc_layouts default_layout(swayc_t *output); + #endif diff --git a/sway/commands.c b/sway/commands.c index 12d60854..ce1fe8a3 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -1760,9 +1760,8 @@ static struct cmd_results *cmd_layout(int argc, char **argv) { } if (strcasecmp(argv[0], "default") == 0) { - // TODO: determine default from default_orientation and - // cmd_workspace_layout - parent->layout = L_HORIZ; + swayc_t *output = swayc_parent_by_type(parent, C_OUTPUT); + parent->layout = default_layout(output); } else if (strcasecmp(argv[0], "tabbed") == 0) { if (parent->type != C_CONTAINER) { parent = new_container(parent, L_TABBED); diff --git a/sway/config.c b/sway/config.c index c11ccf53..ebcee95b 100644 --- a/sway/config.c +++ b/sway/config.c @@ -160,7 +160,7 @@ static void config_defaults(struct sway_config *config) { config->dragging_key = M_LEFT_CLICK; config->resizing_key = M_RIGHT_CLICK; config->floating_scroll = FSB_GAPS_INNER; - config->default_layout = L_HORIZ; + config->default_layout = L_NONE; config->default_orientation = L_NONE; config->font = strdup("monospace 10"); config->font_height = get_font_text_height(config->font); diff --git a/sway/container.c b/sway/container.c index 2b100f40..5579fddb 100644 --- a/sway/container.c +++ b/sway/container.c @@ -163,16 +163,8 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { sway_log(L_DEBUG, "Added workspace %s for output %u", name, (unsigned int)output->handle); swayc_t *workspace = new_swayc(C_WORKSPACE); - // TODO: default_layout - if (config->default_layout != L_NONE) { - workspace->layout = config->default_layout; - } else if (config->default_orientation != L_NONE) { - workspace->layout = config->default_orientation; - } else if (output->width >= output->height) { - workspace->layout = L_HORIZ; - } else { - workspace->layout = L_VERT; - } + workspace->layout = default_layout(output); + workspace->x = output->x; workspace->y = output->y; workspace->width = output->width; diff --git a/sway/layout.c b/sway/layout.c index 527579d9..261e2138 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -993,3 +993,15 @@ void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge ed } } } + +enum swayc_layouts default_layout(swayc_t *output) { + if (config->default_layout != L_NONE) { + return config->default_layout; + } else if (config->default_orientation != L_NONE) { + return config->default_orientation; + } else if (output->width >= output->height) { + return L_HORIZ; + } else { + return L_VERT; + } +} From a0cebb7c5a0530414e85c85fb0231881f988df7c Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Fri, 1 Apr 2016 21:39:15 +0200 Subject: [PATCH 04/14] Improve move command with tabbed/stacked layout --- sway/debug_log.c | 1 + sway/layout.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sway/debug_log.c b/sway/debug_log.c index 761dca6c..f804a541 100644 --- a/sway/debug_log.c +++ b/sway/debug_log.c @@ -38,6 +38,7 @@ static void container_log(const swayc_t *c, int depth) { c->layout == L_HORIZ ? "Horiz": c->layout == L_VERT ? "Vert": c->layout == L_STACKED ? "Stack": + c->layout == L_TABBED ? "Tab": c->layout == L_FLOATING ? "Float": "Unknown"); fprintf(stderr, "w:%4.f|h:%4.f|", c->width, c->height); diff --git a/sway/layout.c b/sway/layout.c index 261e2138..e9eb8add 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -244,7 +244,9 @@ void move_container(swayc_t *container, enum movement_direction dir) { while (true) { sway_log(L_DEBUG, "container:%p, parent:%p, child %p,", container,parent,child); - if (parent->layout == layout) { + if (parent->layout == layout + || (parent->layout == L_TABBED && layout == L_HORIZ) + || (parent->layout == L_STACKED && layout == L_VERT)) { int diff; // If it has ascended (parent has moved up), no container is removed // so insert it at index, or index+1. @@ -264,9 +266,11 @@ void move_container(swayc_t *container, enum movement_direction dir) { // Move container into sibling container if (child->type == C_CONTAINER) { parent = child; - // Insert it in first/last if matching layout,otherwise + // Insert it in first/last if matching layout, otherwise // inesrt it next to focused container - if (parent->layout == layout) { + if (parent->layout == layout + || (parent->layout == L_TABBED && layout == L_HORIZ) + || (parent->layout == L_STACKED && layout == L_VERT)) { desired = (diff < 0) * parent->children->length; } else { desired = index_child(child->focused); @@ -300,7 +304,7 @@ void move_container(swayc_t *container, enum movement_direction dir) { parent = child->parent; } // Dirty hack to fix a certain case - arrange_windows(parent, -1, -1); + /* arrange_windows(parent, -1, -1); */ arrange_windows(parent->parent, -1, -1); set_focused_container_for(parent->parent, container); } From e226b20bd8d2ce98077aee35b2a33b73943db247 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Sat, 2 Apr 2016 16:29:31 +0200 Subject: [PATCH 05/14] Reapply prev layout when exiting tabbed/stacked --- include/container.h | 1 + sway/commands.c | 45 +++++++++++++++++++++++++++------------------ sway/container.c | 3 +++ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/include/container.h b/include/container.h index d9f33b8a..29d4ea12 100644 --- a/include/container.h +++ b/include/container.h @@ -56,6 +56,7 @@ struct sway_container { enum swayc_types type; enum swayc_layouts layout; + enum swayc_layouts prev_layout; /** * Width and height of this container, without borders or gaps. diff --git a/sway/commands.c b/sway/commands.c index ce1fe8a3..ad5416f7 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -1760,29 +1760,38 @@ static struct cmd_results *cmd_layout(int argc, char **argv) { } if (strcasecmp(argv[0], "default") == 0) { - swayc_t *output = swayc_parent_by_type(parent, C_OUTPUT); - parent->layout = default_layout(output); - } else if (strcasecmp(argv[0], "tabbed") == 0) { - if (parent->type != C_CONTAINER) { - parent = new_container(parent, L_TABBED); + parent->layout = parent->prev_layout; + if (parent->layout == L_NONE) { + swayc_t *output = swayc_parent_by_type(parent, C_OUTPUT); + parent->layout = default_layout(output); } - - parent->layout = L_TABBED; - } else if (strcasecmp(argv[0], "stacking") == 0) { - if (parent->type != C_CONTAINER) { - parent = new_container(parent, L_STACKED); + } else { + if (parent->layout != L_TABBED && parent->layout != L_STACKED) { + parent->prev_layout = parent->layout; } - parent->layout = L_STACKED; - } else if (strcasecmp(argv[0], "splith") == 0) { - parent->layout = L_HORIZ; - } else if (strcasecmp(argv[0], "splitv") == 0) { - parent->layout = L_VERT; - } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) { - if (parent->layout == L_VERT) { + if (strcasecmp(argv[0], "tabbed") == 0) { + if (parent->type != C_CONTAINER) { + parent = new_container(parent, L_TABBED); + } + + parent->layout = L_TABBED; + } else if (strcasecmp(argv[0], "stacking") == 0) { + if (parent->type != C_CONTAINER) { + parent = new_container(parent, L_STACKED); + } + + parent->layout = L_STACKED; + } else if (strcasecmp(argv[0], "splith") == 0) { parent->layout = L_HORIZ; - } else { + } else if (strcasecmp(argv[0], "splitv") == 0) { parent->layout = L_VERT; + } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) { + if (parent->layout == L_VERT) { + parent->layout = L_HORIZ; + } else { + parent->layout = L_VERT; + } } } diff --git a/sway/container.c b/sway/container.c index 5579fddb..42f6a69a 100644 --- a/sway/container.c +++ b/sway/container.c @@ -163,6 +163,7 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { sway_log(L_DEBUG, "Added workspace %s for output %u", name, (unsigned int)output->handle); swayc_t *workspace = new_swayc(C_WORKSPACE); + workspace->prev_layout = L_NONE; workspace->layout = default_layout(output); workspace->x = output->x; @@ -203,6 +204,7 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { sway_log(L_DEBUG, "creating container %p around %p", cont, child); + cont->prev_layout = L_NONE; cont->layout = layout; cont->width = child->width; cont->height = child->height; @@ -229,6 +231,7 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { add_child(workspace, cont); // give them proper layouts cont->layout = workspace->layout; + cont->prev_layout = workspace->prev_layout; /* TODO: might break shit in move_container!!! workspace->layout = layout; */ set_focused_container_for(workspace, get_focused_view(workspace)); } else { // Or is built around container From 969f76a1a44b5da92a03d9ac3c865109b0ef9f39 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Sun, 3 Apr 2016 13:48:39 +0200 Subject: [PATCH 06/14] Make floating border fixes work with tabbed/stacked code --- sway/border.c | 26 +++++++------------------- sway/layout.c | 12 +++++------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/sway/border.c b/sway/border.c index 061c1427..80e51580 100644 --- a/sway/border.c +++ b/sway/border.c @@ -141,34 +141,22 @@ static void render_borders(swayc_t *view, cairo_t *cr, struct border_colors *col static void render_title_bar(swayc_t *view, cairo_t *cr, struct border_colors *colors) { struct wlc_geometry *tb = &view->title_bar_geometry; struct wlc_geometry *b = &view->border_geometry; - int title_y = MIN(view->actual_geometry.origin.y - (int)tb->size.h, 0); + int x = MIN(tb->origin.x, tb->origin.x - b->origin.x); + int y = MIN(tb->origin.y, tb->origin.y - b->origin.y); - // borders - /* render_borders(view, cr, colors); */ - - int x = tb->origin.x - b->origin.x; - int y = tb->origin.y - b->origin.y; - - /* // title bar background */ - /* cairo_set_source_u32(cr, colors->child_border); */ - /* cairo_rectangle(cr, x, y, tb->size.w, tb->size.h); */ - /* cairo_fill(cr); */ // title bar background cairo_set_source_u32(cr, colors->background); - cairo_rectangle(cr, 0, title_y, tb->size.w, tb->size.h); + cairo_rectangle(cr, x, y, tb->size.w, tb->size.h); cairo_fill(cr); // header top line - /* render_sharp_line(cr, colors->border, x, y, tb->size.w, 1); */ - render_sharp_line(cr, colors->border, 0, title_y, tb->size.w, 1); + render_sharp_line(cr, colors->border, x, y, tb->size.w, 1); // text if (view->name) { int width, height; get_text_size(cr, config->font, &width, &height, false, "%s", view->name); - int x_text = MIN(view->actual_geometry.origin.x, view->border_thickness); - int y_text = MIN(view->actual_geometry.origin.y - height - 2, 2); - cairo_move_to(cr, x_text, y_text); + cairo_move_to(cr, x + 2, y + 2); cairo_set_source_u32(cr, colors->text); pango_printf(cr, config->font, false, "%s", view->name); } @@ -192,13 +180,13 @@ static void render_title_bar(swayc_t *view, cairo_t *cr, struct border_colors *c if ((uint32_t)(view->actual_geometry.origin.y - tb->origin.y) == tb->size.h) { // header bottom line render_sharp_line(cr, colors->border, - x + view->actual_geometry.origin.x - b->origin.x, + x + view->actual_geometry.origin.x - tb->origin.x, y + tb->size.h - 1, view->actual_geometry.size.w, 1); } else { // header bottom line render_sharp_line(cr, colors->border, x, - title_y + tb->size.h - 1, + y + tb->size.h - 1, tb->size.w, 1); } } diff --git a/sway/layout.c b/sway/layout.c index e9eb8add..65ca2402 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -384,16 +384,14 @@ static void adjust_border_geometry(swayc_t *c, struct wlc_geometry *g, g->size.w += left + right; if (g->origin.x - left < 0) { g->size.w += g->origin.x - left; - } - else if (g->origin.x + g->size.w - right > res->w) { + } else if (g->origin.x + g->size.w - right > res->w) { g->size.w = res->w - g->origin.x + right; } g->size.h += top + bottom; if (g->origin.y - top < 0) { g->size.h += g->origin.y - top; - } - else if (g->origin.y + g->size.h - top > res->h) { + } else if (g->origin.y + g->size.h - top > res->h) { g->size.h = res->h - g->origin.y + top; } @@ -425,11 +423,11 @@ static void update_border_geometry_floating(swayc_t *c, struct wlc_geometry *geo struct wlc_geometry title_bar = { .origin = { - .x = g.origin.x, - .y = g.origin.y + .x = c->actual_geometry.origin.x - c->border_thickness, + .y = c->actual_geometry.origin.y - title_bar_height }, .size = { - .w = g.size.w, + .w = c->actual_geometry.size.w + (2 * c->border_thickness), .h = title_bar_height } }; From 3955c66ce80989fa9d784eb9644fd41b096b3338 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Sun, 17 Apr 2016 13:36:17 +0200 Subject: [PATCH 07/14] Use tabs for indentation --- sway/border.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sway/border.c b/sway/border.c index 80e51580..2eefbbf5 100644 --- a/sway/border.c +++ b/sway/border.c @@ -11,13 +11,13 @@ #include void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { - color = htonl(color); + color = htonl(color); - cairo_set_source_rgba(cairo, - (color >> (2*8) & 0xFF) / 255.0, - (color >> (1*8) & 0xFF) / 255.0, - (color >> (0*8) & 0xFF) / 255.0, - (color >> (3*8) & 0xFF) / 255.0); + cairo_set_source_rgba(cairo, + (color >> (2*8) & 0xFF) / 255.0, + (color >> (1*8) & 0xFF) / 255.0, + (color >> (0*8) & 0xFF) / 255.0, + (color >> (3*8) & 0xFF) / 255.0); } static cairo_t *create_border_buffer(swayc_t *view, struct wlc_geometry geo, cairo_surface_t **surface) { From 3e1f78ab26e8bc6b6cefd53ee137e97533c2695e Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Wed, 20 Apr 2016 00:22:15 +0200 Subject: [PATCH 08/14] Add support for nested tabbed/stacked containers --- include/border.h | 5 ++ include/container.h | 19 ++++++- include/layout.h | 6 +- sway/border.c | 131 ++++++++++++++++++++++++++++---------------- sway/commands.c | 5 ++ sway/container.c | 24 +++++++- sway/focus.c | 5 +- sway/layout.c | 115 ++++++++++++++++++++++++++++++-------- 8 files changed, 233 insertions(+), 77 deletions(-) diff --git a/include/border.h b/include/border.h index 85c656e0..c99c02ea 100644 --- a/include/border.h +++ b/include/border.h @@ -3,6 +3,11 @@ #include #include "container.h" +struct border { + unsigned char *buffer; + struct wlc_geometry geometry; +}; + void render_view_borders(wlc_handle view); void update_view_border(swayc_t *view); void map_update_view_border(swayc_t *view, void *data); diff --git a/include/container.h b/include/container.h index 29d4ea12..ae57d1e3 100644 --- a/include/container.h +++ b/include/container.h @@ -2,9 +2,12 @@ #define _SWAY_CONTAINER_H #include #include + +#include "list.h" + typedef struct sway_container swayc_t; -#include "layout.h" +extern swayc_t root_container; /** * Different kinds of containers. @@ -75,6 +78,12 @@ struct sway_container { */ double x, y; + /** + * Cached geometry used to store view/container geometry when switching + * between tabbed/stacked and horizontal/vertical layouts. + */ + struct wlc_geometry cached_geometry; + /** * False if this view is invisible. It could be in the scratchpad or on a * workspace that is not shown. @@ -120,7 +129,7 @@ struct sway_container { * If this container is a view, this may be set to the window's decoration * buffer (or NULL). */ - unsigned char *border; + struct border *border; enum swayc_border_types border_type; struct wlc_geometry border_geometry; struct wlc_geometry title_bar_geometry; @@ -247,6 +256,12 @@ bool swayc_is_child_of(swayc_t *child, swayc_t *parent); */ bool swayc_is_tabbed_stacked(swayc_t *view); +/** + * Returns the top most tabbed or stacked parent container. Returns NULL if + * view is not in a tabbed/stacked layout. + */ +swayc_t *swayc_tabbed_stacked_parent(swayc_t *view); + /** * Returns the gap (padding) of the container. * diff --git a/include/layout.h b/include/layout.h index 84552754..c05e9e69 100644 --- a/include/layout.h +++ b/include/layout.h @@ -7,8 +7,6 @@ #include "container.h" #include "focus.h" -extern swayc_t root_container; - extern list_t *scratchpad; extern int min_sane_w; @@ -55,6 +53,10 @@ void move_container_to(swayc_t* container, swayc_t* destination); void move_workspace_to(swayc_t* workspace, swayc_t* destination); // Layout +/** + * Update child container geometries when switching between layouts. + */ +void update_layout_geometry(swayc_t *parent, enum swayc_layouts prev_layout); void update_geometry(swayc_t *view); void arrange_windows(swayc_t *container, double width, double height); diff --git a/sway/border.c b/sway/border.c index 2eefbbf5..cc329b6a 100644 --- a/sway/border.c +++ b/sway/border.c @@ -20,28 +20,31 @@ void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { (color >> (3*8) & 0xFF) / 255.0); } -static cairo_t *create_border_buffer(swayc_t *view, struct wlc_geometry geo, cairo_surface_t **surface) { +static cairo_t *create_border_buffer(swayc_t *view, struct wlc_geometry g, cairo_surface_t **surface) { + if (view->border == NULL) { + view->border = malloc(sizeof(struct border)); + } cairo_t *cr; - view->border_geometry = geo; - int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, geo.size.w); - view->border = calloc(stride * geo.size.h, sizeof(unsigned char)); - if (!view->border) { + int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, g.size.w); + view->border->buffer = calloc(stride * g.size.h, sizeof(unsigned char)); + view->border->geometry = g; + if (!view->border->buffer) { sway_log(L_DEBUG, "Unable to allocate buffer"); return NULL; } - *surface = cairo_image_surface_create_for_data(view->border, - CAIRO_FORMAT_ARGB32, geo.size.w, geo.size.h, stride); + *surface = cairo_image_surface_create_for_data(view->border->buffer, + CAIRO_FORMAT_ARGB32, g.size.w, g.size.h, stride); if (cairo_surface_status(*surface) != CAIRO_STATUS_SUCCESS) { free(view->border); - view->border = NULL; + view->border->buffer = NULL; sway_log(L_DEBUG, "Unable to allocate surface"); return NULL; } cr = cairo_create(*surface); if (cairo_status(cr) != CAIRO_STATUS_SUCCESS) { cairo_surface_destroy(*surface); - free(view->border); - view->border = NULL; + free(view->border->buffer); + view->border->buffer = NULL; sway_log(L_DEBUG, "Unable to create cairo context"); return NULL; } @@ -92,15 +95,19 @@ int get_font_text_height(const char *font) { } static void render_borders(swayc_t *view, cairo_t *cr, struct border_colors *colors, bool top) { + struct wlc_geometry *g = &view->border->geometry; struct wlc_geometry *b = &view->border_geometry; struct wlc_geometry *v = &view->actual_geometry; + int x = b->origin.x - g->origin.x; + int y = b->origin.y - g->origin.y; + // left border int left_border = v->origin.x - b->origin.x; if (left_border > 0) { render_sharp_line(cr, colors->child_border, - 0, 0, + x, y, left_border, b->size.h); } @@ -110,8 +117,8 @@ static void render_borders(swayc_t *view, cairo_t *cr, struct border_colors *col if (right_border > 0) { render_sharp_line(cr, colors->child_border, - b->size.w - right_border, - 0, + x + b->size.w - right_border, + y, right_border, b->size.h); } @@ -121,7 +128,7 @@ static void render_borders(swayc_t *view, cairo_t *cr, struct border_colors *col if (top && top_border > 0) { render_sharp_line(cr, colors->child_border, - 0, 0, + x, y, b->size.w, top_border); } @@ -131,16 +138,15 @@ static void render_borders(swayc_t *view, cairo_t *cr, struct border_colors *col if (bottom_border > 0) { render_sharp_line(cr, colors->child_border, - 0, - b->size.h - bottom_border, + x, + y + b->size.h - bottom_border, b->size.w, bottom_border); } } -static void render_title_bar(swayc_t *view, cairo_t *cr, struct border_colors *colors) { +static void render_title_bar(swayc_t *view, cairo_t *cr, struct wlc_geometry *b, struct border_colors *colors) { struct wlc_geometry *tb = &view->title_bar_geometry; - struct wlc_geometry *b = &view->border_geometry; int x = MIN(tb->origin.x, tb->origin.x - b->origin.x); int y = MIN(tb->origin.y, tb->origin.y - b->origin.y); @@ -197,6 +203,34 @@ void map_update_view_border(swayc_t *view, void *data) { } } +void update_tabbed_stacked_titlebars(swayc_t *c, cairo_t *cr, struct wlc_geometry *g, swayc_t *focused, swayc_t *focused_inactive) { + if (c->type == C_CONTAINER) { + if (c->parent->focused == c) { + render_title_bar(c, cr, g, &config->border_colors.focused_inactive); + } else { + render_title_bar(c, cr, g, &config->border_colors.unfocused); + } + + if (!c->visible) { + return; + } + + int i; + for (i = 0; i < c->children->length; ++i) { + swayc_t *child = c->children->items[i]; + update_tabbed_stacked_titlebars(child, cr, g, focused, focused_inactive); + } + } else { + if (focused == c) { + render_title_bar(c, cr, g, &config->border_colors.focused); + } else if (focused_inactive == c) { + render_title_bar(c, cr, g, &config->border_colors.focused_inactive); + } else { + render_title_bar(c, cr, g, &config->border_colors.unfocused); + } + } +} + void update_view_border(swayc_t *view) { if (!view->visible) { return; @@ -205,12 +239,12 @@ void update_view_border(swayc_t *view) { cairo_t *cr = NULL; cairo_surface_t *surface = NULL; - if (view->border) { - free(view->border); - view->border = NULL; + if (view->border && view->border->buffer) { + free(view->border->buffer); + view->border->buffer = NULL; } - // get focused and focused_intactive views + // get focused and focused_inactive views swayc_t *focused = get_focused_view(&root_container); swayc_t *container = swayc_parent_by_type(view, C_CONTAINER); swayc_t *focused_inactive = NULL; @@ -223,30 +257,27 @@ void update_view_border(swayc_t *view) { } } - swayc_t *p = view->parent; - - if (swayc_is_tabbed_stacked(view)) { - cr = create_border_buffer(view, view->border_geometry, &surface); - if (focused == view) { + // for tabbed/stacked layouts the focused view has to draw all the + // titlebars of the hidden views. + swayc_t *p = swayc_tabbed_stacked_parent(view); + if (p && view->parent->focused == view) { + struct wlc_geometry g = { + .origin = { + .x = p->x, + .y = p->y + }, + .size = { + .w = p->width, + .h = p->height + } + }; + cr = create_border_buffer(view, g, &surface); + if (view == focused) { render_borders(view, cr, &config->border_colors.focused, false); - } else if (focused_inactive == view) { - render_borders(view, cr, &config->border_colors.focused_inactive, false); } else { - render_borders(view, cr, &config->border_colors.unfocused, false); - } - - int i; - for (i = 0; i < p->children->length; ++i) { - swayc_t *child = p->children->items[i]; - - if (focused == child) { - render_title_bar(child, cr, &config->border_colors.focused); - } else if (focused_inactive == child) { - render_title_bar(child, cr, &config->border_colors.focused_inactive); - } else { - render_title_bar(child, cr, &config->border_colors.unfocused); - } + render_borders(view, cr, &config->border_colors.focused_inactive, false); } + update_tabbed_stacked_titlebars(p, cr, &g, focused, focused_inactive); } else { switch (view->border_type) { case B_NONE: @@ -274,13 +305,16 @@ void update_view_border(swayc_t *view) { if (focused == view) { render_borders(view, cr, &config->border_colors.focused, false); - render_title_bar(view, cr, &config->border_colors.focused); + render_title_bar(view, cr, &view->border_geometry, + &config->border_colors.focused); } else if (focused_inactive == view) { render_borders(view, cr, &config->border_colors.focused_inactive, false); - render_title_bar(view, cr, &config->border_colors.focused_inactive); + render_title_bar(view, cr, &view->border_geometry, + &config->border_colors.focused_inactive); } else { render_borders(view, cr, &config->border_colors.unfocused, false); - render_title_bar(view, cr, &config->border_colors.unfocused); + render_title_bar(view, cr, &view->border_geometry, + &config->border_colors.unfocused); } break; @@ -291,6 +325,7 @@ void update_view_border(swayc_t *view) { cairo_surface_flush(surface); cairo_surface_destroy(surface); } + if (cr) { cairo_destroy(cr); } @@ -316,7 +351,7 @@ void render_view_borders(wlc_handle view) { } } - if (c->border) { - wlc_pixels_write(WLC_RGBA8888, &c->border_geometry, c->border); + if (c->border && c->border->buffer) { + wlc_pixels_write(WLC_RGBA8888, &c->border->geometry, c->border->buffer); } } diff --git a/sway/commands.c b/sway/commands.c index ad5416f7..ff1ddc5b 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -1759,6 +1759,8 @@ static struct cmd_results *cmd_layout(int argc, char **argv) { parent = parent->parent; } + enum swayc_layouts old_layout = parent->layout; + if (strcasecmp(argv[0], "default") == 0) { parent->layout = parent->prev_layout; if (parent->layout == L_NONE) { @@ -1795,6 +1797,8 @@ static struct cmd_results *cmd_layout(int argc, char **argv) { } } + update_layout_geometry(parent, old_layout); + arrange_windows(parent, parent->width, parent->height); return cmd_results_new(CMD_SUCCESS, NULL, NULL); @@ -2032,6 +2036,7 @@ static struct cmd_results *_do_split(int argc, char **argv, int layout) { /* regular case where new split container is build around focused container * or in case of workspace, container inherits its children */ sway_log(L_DEBUG, "Adding new container around current focused container"); + sway_log(L_INFO, "FOCUSED SIZE: %.f %.f", focused->width, focused->height); swayc_t *parent = new_container(focused, layout); set_focused_container(focused); arrange_windows(parent, -1, -1); diff --git a/sway/container.c b/sway/container.c index 42f6a69a..f4258c84 100644 --- a/sway/container.c +++ b/sway/container.c @@ -8,6 +8,7 @@ #include "container.h" #include "workspace.h" #include "focus.h" +#include "border.h" #include "layout.h" #include "input_state.h" #include "log.h" @@ -64,7 +65,12 @@ static void free_swayc(swayc_t *cont) { if (cont->bg_pid != 0) { terminate_swaybg(cont->bg_pid); } - free(cont->border); + if (cont->border) { + if (cont->border->buffer) { + free(cont->border->buffer); + } + free(cont->border); + } free(cont); } @@ -211,6 +217,7 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { cont->x = child->x; cont->y = child->y; cont->visible = child->visible; + cont->cached_geometry = child->cached_geometry; /* Container inherits all of workspaces children, layout and whatnot */ if (child->type == C_WORKSPACE) { @@ -812,3 +819,18 @@ bool swayc_is_tabbed_stacked(swayc_t *view) { return (view->parent->layout == L_TABBED || view->parent->layout == L_STACKED); } + +swayc_t *swayc_tabbed_stacked_parent(swayc_t *view) { + swayc_t *parent = NULL; + if (!ASSERT_NONNULL(view)) { + return NULL; + } + do { + view = view->parent; + if (view->layout == L_TABBED || view->layout == L_STACKED) { + parent = view; + } + } while (view && view->type != C_WORKSPACE); + + return parent; +} diff --git a/sway/focus.c b/sway/focus.c index 8ce22456..b4dfc423 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -149,8 +149,9 @@ bool set_focused_container(swayc_t *c) { } // rearrange if parent container is tabbed/stacked - if (swayc_is_tabbed_stacked(p)) { - arrange_windows(p->parent, -1, -1); + swayc_t *parent = swayc_tabbed_stacked_parent(p); + if (parent != NULL) { + arrange_windows(parent, -1, -1); } } else if (p->type == C_WORKSPACE) { // remove previous focus if view_focus is unlocked diff --git a/sway/layout.c b/sway/layout.c index 65ca2402..801f6f6b 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -3,7 +3,6 @@ #include #include #include "extensions.h" -#include "layout.h" #include "log.h" #include "list.h" #include "config.h" @@ -13,6 +12,7 @@ #include "output.h" #include "ipc-server.h" #include "border.h" +#include "layout.h" swayc_t root_container; list_t *scratchpad; @@ -442,12 +442,49 @@ static void update_border_geometry_floating(swayc_t *c, struct wlc_geometry *geo update_view_border(c); } +void update_layout_geometry(swayc_t *parent, enum swayc_layouts prev_layout) { + switch (parent->layout) { + case L_TABBED: + case L_STACKED: + if (prev_layout != L_TABBED && prev_layout != L_STACKED) { + // cache current geometry for all non-float children + int i; + for (i = 0; i < parent->children->length; ++i) { + swayc_t *child = parent->children->items[i]; + child->cached_geometry.origin.x = child->x; + child->cached_geometry.origin.y = child->y; + child->cached_geometry.size.w = child->width; + child->cached_geometry.size.h = child->height; + } + } + break; + default: + if (prev_layout == L_TABBED || prev_layout == L_STACKED) { + // recover cached geometry for all non-float children + int i; + for (i = 0; i < parent->children->length; ++i) { + swayc_t *child = parent->children->items[i]; + // only recoverer cached geometry if non-zero + if (!wlc_geometry_equals(&child->cached_geometry, &wlc_geometry_zero)) { + child->x = child->cached_geometry.origin.x; + child->y = child->cached_geometry.origin.y; + child->width = child->cached_geometry.size.w; + child->height = child->cached_geometry.size.h; + } + } + } + break; + } +} + void update_geometry(swayc_t *container) { - if (container->type != C_VIEW) { + if (container->type != C_VIEW && container->type != C_CONTAINER) { return; } + swayc_t *ws = swayc_parent_by_type(container, C_WORKSPACE); swayc_t *op = ws->parent; + swayc_t *parent = container->parent; int gap = container->is_floating ? 0 : swayc_gap(container); if (gap % 2 != 0) { // because gaps are implemented as "half sized margins" it's currently @@ -455,24 +492,14 @@ void update_geometry(swayc_t *container) { gap -= 1; } - int width = container->width; - int height = container->height; - - // use parent size if window is in a stacked/tabbed layout - swayc_t *parent = container->parent; - if (swayc_is_tabbed_stacked(container)) { - width = parent->width; - height = parent->height; - } - struct wlc_geometry geometry = { .origin = { .x = container->x + gap/2 < op->width ? container->x + gap/2 : op->width-1, .y = container->y + gap/2 < op->height ? container->y + gap/2 : op->height-1 }, .size = { - .w = width > gap ? width - gap : 1, - .h = height > gap ? height - gap : 1, + .w = container->width > gap ? container->width - gap : 1, + .h = container->height > gap ? container->height - gap : 1, } }; if (swayc_is_fullscreen(container)) { @@ -492,16 +519,16 @@ void update_geometry(swayc_t *container) { // with gap, and align correctly). if (container->x - gap <= ws->x) { geometry.origin.x = ws->x; - geometry.size.w = width - gap/2; + geometry.size.w = container->width - gap/2; } if (container->y - gap <= ws->y) { geometry.origin.y = ws->y; - geometry.size.h = height - gap/2; + geometry.size.h = container->height - gap/2; } - if (container->x + width + gap >= ws->x + ws->width) { + if (container->x + container->width + gap >= ws->x + ws->width) { geometry.size.w = ws->x + ws->width - geometry.origin.x; } - if (container->y + height + gap >= ws->y + ws->height) { + if (container->y + container->height + gap >= ws->y + ws->height) { geometry.size.h = ws->y + ws->height - geometry.origin.y; } } @@ -637,10 +664,14 @@ void update_geometry(swayc_t *container) { container->actual_geometry = geometry; - update_view_border(container); + if (container->type == C_VIEW) { + update_view_border(container); + } } - wlc_view_set_geometry(container->handle, 0, &geometry); + if (container->type == C_VIEW) { + wlc_view_set_geometry(container->handle, 0, &geometry); + } } static void arrange_windows_r(swayc_t *container, double width, double height) { @@ -736,6 +767,22 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { container->height = height; x = container->x; y = container->y; + + // update container size if it's a child in a tabbed/stacked layout + if (swayc_is_tabbed_stacked(container)) { + // Use parent geometry as a base for calculating + // container geometry + container->width = container->parent->width; + container->height = container->parent->height; + container->x = container->parent->x; + container->y = container->parent->y; + update_geometry(container); + width = container->width = container->actual_geometry.size.w; + height = container->height = container->actual_geometry.size.h; + x = container->x = container->actual_geometry.origin.x; + y = container->y = container->actual_geometry.origin.y; + } + break; } @@ -760,11 +807,17 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { if (scale > 0.1) { scale = width / scale; sway_log(L_DEBUG, "Arranging %p horizontally", container); + swayc_t *focused = NULL; for (i = 0; i < container->children->length; ++i) { swayc_t *child = container->children->items[i]; sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, width, scale); child->x = x; child->y = y; + + if (child == container->focused) { + focused = child; + } + if (i == container->children->length - 1) { double remaining_width = container->x + width - x; arrange_windows_r(child, remaining_width, height); @@ -773,6 +826,12 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { } x += child->width; } + + // update focused view border last because it may + // depend on the title bar geometry of its siblings. + if (focused && container->children->length > 1) { + update_view_border(focused); + } } break; case L_VERT: @@ -792,11 +851,17 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { if (scale > 0.1) { scale = height / scale; sway_log(L_DEBUG, "Arranging %p vertically", container); + swayc_t *focused = NULL; for (i = 0; i < container->children->length; ++i) { swayc_t *child = container->children->items[i]; sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, height, scale); child->x = x; child->y = y; + + if (child == container->focused) { + focused = child; + } + if (i == container->children->length - 1) { double remaining_height = container->y + height - y; arrange_windows_r(child, width, remaining_height); @@ -805,6 +870,12 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { } y += child->height; } + + // update focused view border last because it may + // depend on the title bar geometry of its siblings. + if (focused && container->children->length > 1) { + update_view_border(focused); + } } break; case L_TABBED: @@ -818,12 +889,12 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { if (child == container->focused) { focused = child; } else { - arrange_windows_r(child, -1, -1); + arrange_windows_r(child, width, height); } } if (focused) { - arrange_windows_r(focused, -1, -1); + arrange_windows_r(focused, width, height); } break; } From 5492277f0c007eea632d242a6d7cbd9cee7cdcf6 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Fri, 22 Apr 2016 22:44:02 +0200 Subject: [PATCH 09/14] Disable inner gaps when in tabbed/stacked mode --- sway/container.c | 3 +- sway/layout.c | 102 ++++++++++++++++++++++++++++++----------------- 2 files changed, 68 insertions(+), 37 deletions(-) diff --git a/sway/container.c b/sway/container.c index f4258c84..9db81012 100644 --- a/sway/container.c +++ b/sway/container.c @@ -218,6 +218,7 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { cont->y = child->y; cont->visible = child->visible; cont->cached_geometry = child->cached_geometry; + cont->gaps = child->gaps; /* Container inherits all of workspaces children, layout and whatnot */ if (child->type == C_WORKSPACE) { @@ -680,7 +681,7 @@ bool swayc_is_child_of(swayc_t *child, swayc_t *parent) { } int swayc_gap(swayc_t *container) { - if (container->type == C_VIEW) { + if (container->type == C_VIEW || container->type == C_CONTAINER) { return container->gaps >= 0 ? container->gaps : config->gaps_inner; } else if (container->type == C_WORKSPACE) { int base = container->gaps >= 0 ? container->gaps : config->gaps_outer; diff --git a/sway/layout.c b/sway/layout.c index 801f6f6b..f9ea5cdc 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -477,14 +477,9 @@ void update_layout_geometry(swayc_t *parent, enum swayc_layouts prev_layout) { } } -void update_geometry(swayc_t *container) { - if (container->type != C_VIEW && container->type != C_CONTAINER) { - return; - } - +static int update_gap_geometry(swayc_t *container, struct wlc_geometry *g) { swayc_t *ws = swayc_parent_by_type(container, C_WORKSPACE); swayc_t *op = ws->parent; - swayc_t *parent = container->parent; int gap = container->is_floating ? 0 : swayc_gap(container); if (gap % 2 != 0) { // because gaps are implemented as "half sized margins" it's currently @@ -492,16 +487,63 @@ void update_geometry(swayc_t *container) { gap -= 1; } + g->origin.x = container->x + gap/2 < op->width ? container->x + gap/2 : op->width-1; + g->origin.y = container->y + gap/2 < op->height ? container->y + gap/2 : op->height-1; + g->size.w = container->width > gap ? container->width - gap : 1; + g->size.h = container->height > gap ? container->height - gap : 1; + + if ((!config->edge_gaps && gap > 0) || (config->smart_gaps && ws->children->length == 1)) { + // Remove gap against the workspace edges. Because a pixel is not + // divisable, depending on gap size and the number of siblings our view + // might be at the workspace edge without being exactly so (thus test + // with gap, and align correctly). + if (container->x - gap <= ws->x) { + g->origin.x = ws->x; + g->size.w = container->width - gap/2; + } + if (container->y - gap <= ws->y) { + g->origin.y = ws->y; + g->size.h = container->height - gap/2; + } + if (container->x + container->width + gap >= ws->x + ws->width) { + g->size.w = ws->x + ws->width - g->origin.x; + } + if (container->y + container->height + gap >= ws->y + ws->height) { + g->size.h = ws->y + ws->height - g->origin.y; + } + } + + return gap; +} + +void update_geometry(swayc_t *container) { + if (container->type != C_VIEW && container->type != C_CONTAINER) { + return; + } + + swayc_t *ws = swayc_parent_by_type(container, C_WORKSPACE); + swayc_t *op = ws->parent; + swayc_t *parent = container->parent; + struct wlc_geometry geometry = { .origin = { - .x = container->x + gap/2 < op->width ? container->x + gap/2 : op->width-1, - .y = container->y + gap/2 < op->height ? container->y + gap/2 : op->height-1 + .x = container->x < op->width ? container->x : op->width-1, + .y = container->y < op->height ? container->y : op->height-1 }, .size = { - .w = container->width > gap ? container->width - gap : 1, - .h = container->height > gap ? container->height - gap : 1, + .w = container->width, + .h = container->height, } }; + + int gap = 0; + + // apply inner gaps to non-tabbed/stacked containers + swayc_t *p = swayc_tabbed_stacked_parent(container); + if (p == NULL) { + gap = update_gap_geometry(container, &geometry); + } + if (swayc_is_fullscreen(container)) { swayc_t *output = swayc_parent_by_type(container, C_OUTPUT); const struct wlc_size *size = wlc_output_get_resolution(output->handle); @@ -512,28 +554,7 @@ void update_geometry(swayc_t *container) { if (op->focused == ws) { wlc_view_bring_to_front(container->handle); } - } else if ((!config->edge_gaps && gap > 0) || (config->smart_gaps && ws->children->length == 1)) { - // Remove gap against the workspace edges. Because a pixel is not - // divisable, depending on gap size and the number of siblings our view - // might be at the workspace edge without being exactly so (thus test - // with gap, and align correctly). - if (container->x - gap <= ws->x) { - geometry.origin.x = ws->x; - geometry.size.w = container->width - gap/2; - } - if (container->y - gap <= ws->y) { - geometry.origin.y = ws->y; - geometry.size.h = container->height - gap/2; - } - if (container->x + container->width + gap >= ws->x + ws->width) { - geometry.size.w = ws->x + ws->width - geometry.origin.x; - } - if (container->y + container->height + gap >= ws->y + ws->height) { - geometry.size.h = ws->y + ws->height - geometry.origin.y; - } - } - if (swayc_is_fullscreen(container)) { container->border_geometry = wlc_geometry_zero; container->title_bar_geometry = wlc_geometry_zero; } else if (container->is_floating) { // allocate border for floating window @@ -768,14 +789,23 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { x = container->x; y = container->y; + // add gaps to top level tapped/stacked container + if (container->layout == L_TABBED || container->layout == L_STACKED) { + update_geometry(container); + width = container->border_geometry.size.w; + height = container->border_geometry.size.h; + x = container->border_geometry.origin.x; + y = container->border_geometry.origin.y; + } + // update container size if it's a child in a tabbed/stacked layout if (swayc_is_tabbed_stacked(container)) { - // Use parent geometry as a base for calculating + // Use parent border_geometry as a base for calculating // container geometry - container->width = container->parent->width; - container->height = container->parent->height; - container->x = container->parent->x; - container->y = container->parent->y; + container->width = container->parent->border_geometry.size.w; + container->height = container->parent->border_geometry.size.h; + container->x = container->parent->border_geometry.origin.x; + container->y = container->parent->border_geometry.origin.y; update_geometry(container); width = container->width = container->actual_geometry.size.w; height = container->height = container->actual_geometry.size.h; From 6c7ed7e7cb1f25429db05103b98e6fcee11d0362 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Sun, 24 Apr 2016 01:47:57 +0200 Subject: [PATCH 10/14] Add title to nested tabbed/stacked containers --- sway/border.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ sway/commands.c | 12 +++++++++ 2 files changed, 78 insertions(+) diff --git a/sway/border.c b/sway/border.c index cc329b6a..cec443f4 100644 --- a/sway/border.c +++ b/sway/border.c @@ -203,6 +203,62 @@ void map_update_view_border(swayc_t *view, void *data) { } } +/** + * Generate nested container title for tabbed/stacked layouts + */ +static char *generate_container_title(swayc_t *container) { + char layout = 'H'; + char *name, *prev_name = NULL; + switch (container->layout) { + case L_TABBED: + layout = 'T'; + break; + case L_STACKED: + layout = 'S'; + break; + case L_VERT: + layout = 'V'; + break; + default: + layout = 'H'; + } + int len = 9; + name = malloc(len * sizeof(char)); + snprintf(name, len, "sway: %c[", layout); + + int i; + for (i = 0; i < container->children->length; ++i) { + prev_name = name; + swayc_t* child = container->children->items[i]; + const char *title = child->name; + if (child->type == C_CONTAINER) { + title = generate_container_title(child); + } + + len = strlen(name) + strlen(title) + 1; + if (i < container->children->length-1) { + len++; + } + + name = malloc(len * sizeof(char)); + if (i < container->children->length-1) { + snprintf(name, len, "%s%s ", prev_name, title); + } else { + snprintf(name, len, "%s%s", prev_name, title); + } + free(prev_name); + } + + prev_name = name; + len = strlen(name) + 2; + name = malloc(len * sizeof(char)); + snprintf(name, len, "%s]", prev_name); + free(prev_name); + free(container->name); + container->name = name; + return container->name + 6; // don't include "sway: " +} + void update_tabbed_stacked_titlebars(swayc_t *c, cairo_t *cr, struct wlc_geometry *g, swayc_t *focused, swayc_t *focused_inactive) { if (c->type == C_CONTAINER) { if (c->parent->focused == c) { @@ -277,6 +333,16 @@ void update_view_border(swayc_t *view) { } else { render_borders(view, cr, &config->border_colors.focused_inactive, false); } + + // generate container titles + int i; + for (i = 0; i < p->children->length; ++i) { + swayc_t *child = p->children->items[i]; + if (child->type == C_CONTAINER) { + generate_container_title(child); + } + } + update_tabbed_stacked_titlebars(p, cr, &g, focused, focused_inactive); } else { switch (view->border_type) { diff --git a/sway/commands.c b/sway/commands.c index ff1ddc5b..34364917 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -2041,6 +2042,17 @@ static struct cmd_results *_do_split(int argc, char **argv, int layout) { set_focused_container(focused); arrange_windows(parent, -1, -1); } + + // update container title if tabbed/stacked + if (swayc_tabbed_stacked_parent(focused)) { + update_view_border(focused); + swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT); + // schedule render to make changes take effect right away, + // otherwise we would have to wait for the view to render, + // which is unpredictable. + wlc_output_schedule_render(output->handle); + } + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } From 5886ee156e948b4c7bc338d1035c2e91dc597458 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Sun, 24 Apr 2016 01:50:44 +0200 Subject: [PATCH 11/14] Use correct geometry for nested containers --- sway/layout.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sway/layout.c b/sway/layout.c index f9ea5cdc..fa613211 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -790,7 +790,8 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { y = container->y; // add gaps to top level tapped/stacked container - if (container->layout == L_TABBED || container->layout == L_STACKED) { + if (container->parent->type == C_WORKSPACE && + (container->layout == L_TABBED || container->layout == L_STACKED)) { update_geometry(container); width = container->border_geometry.size.w; height = container->border_geometry.size.h; @@ -799,13 +800,14 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { } // update container size if it's a child in a tabbed/stacked layout - if (swayc_is_tabbed_stacked(container)) { - // Use parent border_geometry as a base for calculating + if (swayc_tabbed_stacked_parent(container) != NULL) { + // Use parent actual_geometry as a base for calculating // container geometry - container->width = container->parent->border_geometry.size.w; - container->height = container->parent->border_geometry.size.h; - container->x = container->parent->border_geometry.origin.x; - container->y = container->parent->border_geometry.origin.y; + container->width = container->parent->actual_geometry.size.w; + container->height = container->parent->actual_geometry.size.h; + container->x = container->parent->actual_geometry.origin.x; + container->y = container->parent->actual_geometry.origin.y; + update_geometry(container); width = container->width = container->actual_geometry.size.w; height = container->height = container->actual_geometry.size.h; From 5a22c0f1c08eddc84a738e8de74dcfab33f41dcf Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Sun, 24 Apr 2016 21:54:33 +0200 Subject: [PATCH 12/14] Don't send invisble view to back --- sway/container.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/sway/container.c b/sway/container.c index 9db81012..d54dfd96 100644 --- a/sway/container.c +++ b/sway/container.c @@ -732,9 +732,6 @@ void update_visibility_output(swayc_t *container, wlc_handle output) { if (container->type == C_VIEW) { wlc_view_set_output(container->handle, output); wlc_view_set_mask(container->handle, container->visible ? VISIBLE : 0); - if (!container->visible) { - wlc_view_send_to_back(container->handle); - } } // Update visibility for children else { From 856ac7d5cca35dcff2f484003fceba1217b1e491 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Sun, 24 Apr 2016 22:04:26 +0200 Subject: [PATCH 13/14] Remove unused function --- include/container.h | 5 ----- sway/container.c | 8 ++------ 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/include/container.h b/include/container.h index ae57d1e3..d1905720 100644 --- a/include/container.h +++ b/include/container.h @@ -251,11 +251,6 @@ bool swayc_is_parent_of(swayc_t *parent, swayc_t *child); */ bool swayc_is_child_of(swayc_t *child, swayc_t *parent); -/** - * Returns true if view is stacked or tabbed. - */ -bool swayc_is_tabbed_stacked(swayc_t *view); - /** * Returns the top most tabbed or stacked parent container. Returns NULL if * view is not in a tabbed/stacked layout. diff --git a/sway/container.c b/sway/container.c index d54dfd96..b49b32ee 100644 --- a/sway/container.c +++ b/sway/container.c @@ -725,7 +725,8 @@ void update_visibility_output(swayc_t *container, wlc_handle output) { swayc_t *parent = container->parent; container->visible = parent->visible; // special cases where visibility depends on focus - if (parent->type == C_OUTPUT || swayc_is_tabbed_stacked(container)) { + if (parent->type == C_OUTPUT || parent->layout == L_TABBED || + parent->layout == L_STACKED) { container->visible = parent->focused == container && parent->visible; } // Set visibility and output for view @@ -813,11 +814,6 @@ void close_views(swayc_t *container) { container_map(container, close_view, NULL); } -bool swayc_is_tabbed_stacked(swayc_t *view) { - return (view->parent->layout == L_TABBED - || view->parent->layout == L_STACKED); -} - swayc_t *swayc_tabbed_stacked_parent(swayc_t *view) { swayc_t *parent = NULL; if (!ASSERT_NONNULL(view)) { From 05b4965a99417b74df13e9138b14347e7dc47685 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Mon, 25 Apr 2016 13:40:21 +0200 Subject: [PATCH 14/14] Remove commented code --- sway/layout.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sway/layout.c b/sway/layout.c index fa613211..3e550927 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -303,8 +303,6 @@ void move_container(swayc_t *container, enum movement_direction dir) { child = parent; parent = child->parent; } - // Dirty hack to fix a certain case - /* arrange_windows(parent, -1, -1); */ arrange_windows(parent->parent, -1, -1); set_focused_container_for(parent->parent, container); }