From c7b3f9854fa511f879bc3b16d5728c10c8d10f1f Mon Sep 17 00:00:00 2001 From: dudemanguy Date: Thu, 3 May 2018 15:53:05 -0500 Subject: [PATCH] add tabbed windows --- sway/commands/default_orientation.c | 4 +- sway/commands/layout.c | 5 ++ sway/desktop/output.c | 73 +++++++++++++++++++++++++---- sway/tree/arrange.c | 17 +++++++ sway/tree/layout.c | 1 + 5 files changed, 89 insertions(+), 11 deletions(-) diff --git a/sway/commands/default_orientation.c b/sway/commands/default_orientation.c index a5347ce21..848b1a44e 100644 --- a/sway/commands/default_orientation.c +++ b/sway/commands/default_orientation.c @@ -11,11 +11,13 @@ struct cmd_results *cmd_default_orientation(int argc, char **argv) { config->default_orientation = L_HORIZ; } else if (strcasecmp(argv[0], "vertical") == 0) { config->default_orientation = L_VERT; + } else if (strcasecmp(argv[0], "tabbed") == 0) { + config->default_orientation = L_TABBED; } else if (strcasecmp(argv[0], "auto") == 0) { // Do nothing } else { return cmd_results_new(CMD_INVALID, "default_orientation", - "Expected 'orientation '"); + "Expected 'orientation '"); } return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/layout.c b/sway/commands/layout.c index bb36bb18b..559be7c5b 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c @@ -25,6 +25,7 @@ struct cmd_results *cmd_layout(int argc, char **argv) { // TODO: stacks and tabs + if (strcasecmp(argv[0], "default") == 0) { parent->layout = parent->prev_layout; if (parent->layout == L_NONE) { @@ -35,6 +36,10 @@ struct cmd_results *cmd_layout(int argc, char **argv) { parent->prev_layout = parent->layout; } + if (strcasecmp(argv[0], "tabbed") == 0) { + parent->layout = L_TABBED; + } + if (strcasecmp(argv[0], "splith") == 0) { parent->layout = L_HORIZ; } else if (strcasecmp(argv[0], "splitv") == 0) { diff --git a/sway/desktop/output.c b/sway/desktop/output.c index d17a6e143..4fd8db8c9 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -228,11 +228,19 @@ static void render_view(struct sway_view *view, struct sway_output *output) { */ static void render_container_simple_border_normal(struct sway_output *output, struct sway_container *con, struct border_colors *colors, - struct wlr_texture *title_texture) { + struct wlr_texture *title_texture, int iteration) { struct wlr_renderer *renderer = wlr_backend_get_renderer(output->wlr_output->backend); struct wlr_box box; float color[4]; + size_t num_tabs; + + if (con->parent->layout == L_TABBED) { + num_tabs = con->parent->children->length; + } + else { + num_tabs = 1; + } // Child border - left edge memcpy(&color, colors->child_border, sizeof(float) * 4); @@ -278,18 +286,18 @@ static void render_container_simple_border_normal(struct sway_output *output, // Single pixel bar above title memcpy(&color, colors->border, sizeof(float) * 4); color[3] *= con->alpha; - box.x = con->x; + box.x = con->x + iteration * (con->width / num_tabs); box.y = con->y; - box.width = con->width; + box.width = con->width / num_tabs; box.height = 1; scale_box(&box, output->wlr_output->scale); wlr_render_rect(renderer, &box, color, output->wlr_output->transform_matrix); // Single pixel bar below title - box.x = con->x + con->sway_view->border_thickness; + box.x = con->x + iteration * (con->width / num_tabs); box.y = con->sway_view->y - 1; - box.width = con->width - con->sway_view->border_thickness * 2; + box.width = con->width / num_tabs; box.height = 1; scale_box(&box, output->wlr_output->scale); wlr_render_rect(renderer, &box, color, @@ -298,9 +306,9 @@ static void render_container_simple_border_normal(struct sway_output *output, // Title background memcpy(&color, colors->background, sizeof(float) * 4); color[3] *= con->alpha; - box.x = con->x + con->sway_view->border_thickness; + box.x = con->x + iteration * (con->width / num_tabs); box.y = con->y + 1; - box.width = con->width - con->sway_view->border_thickness * 2; + box.width = con->width / num_tabs; box.height = con->sway_view->y - con->y - 2; scale_box(&box, output->wlr_output->scale); wlr_render_rect(renderer, &box, color, @@ -325,7 +333,6 @@ static void render_container_simple_border_pixel(struct sway_output *output, struct wlr_box box; float color[4]; - // Child border - left edge memcpy(&color, colors->child_border, sizeof(float) * 4); color[3] *= con->alpha; box.x = con->x; @@ -410,7 +417,7 @@ static void render_container_simple(struct sway_output *output, if (child->sway_view->border == B_NORMAL) { render_container_simple_border_normal(output, child, - colors, title_texture); + colors, title_texture, 0); } else { render_container_simple_border_pixel(output, child, colors); } @@ -427,7 +434,53 @@ static void render_container_simple(struct sway_output *output, */ static void render_container_tabbed(struct sway_output *output, struct sway_container *con) { - // TODO + struct sway_seat *seat = input_manager_current_seat(input_manager); + struct sway_container *focus = seat_get_focus(seat); + + for (int i = 0; i < con->children->length; ++i) { + struct sway_container *child = con->children->items[i]; + + if (child->type == C_VIEW) { + if (child->sway_view->border != B_NONE) { + struct border_colors *colors; + struct wlr_texture *title_texture; + if (focus == child) { + colors = &config->border_colors.focused; + title_texture = child->title_focused; + + if (child->sway_view->border == B_NORMAL) { + render_container_simple_border_normal(output, child, + colors, title_texture, i); + } else { + render_container_simple_border_pixel(output, child, colors); + } + render_view(child->sway_view, output); + } else if (seat_get_focus_inactive(seat, con) == child) { + colors = &config->border_colors.focused_inactive; + title_texture = child->title_focused_inactive; + if (child->sway_view->border == B_NORMAL) { + render_container_simple_border_normal(output, child, + colors, title_texture, i); + } else { + render_container_simple_border_pixel(output, child, colors); + } + render_view(child->sway_view, output); + } else { + colors = &config->border_colors.unfocused; + title_texture = child->title_unfocused; + if (child->sway_view->border == B_NORMAL) { + render_container_simple_border_normal(output, child, + colors, title_texture, i); + } else { + render_container_simple_border_pixel(output, child, colors); + } + } + } + } + else { + render_container(output, child); + } + } } /** diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index 83bb20fbe..3fe68ec5b 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -159,6 +159,20 @@ static void apply_vert_layout(struct sway_container *parent) { child->height = parent->y + parent->height - child->y; } +static void apply_tabbed_layout(struct sway_container *parent) { + size_t num_children = parent->children->length; + if (!num_children) { + return; + } + for (size_t i=0; i < num_children; ++i) { + struct sway_container *child = parent->children->items[i]; + child->x = parent->x; + child->y = parent->y; + child->width = parent->width; + child->height = parent->height; + } +} + void arrange_children_of(struct sway_container *parent) { if (config->reloading) { return; @@ -189,6 +203,9 @@ void arrange_children_of(struct sway_container *parent) { case L_VERT: apply_vert_layout(parent); break; + case L_TABBED: + apply_tabbed_layout(parent); + break; default: wlr_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout); apply_horiz_layout(parent); diff --git a/sway/tree/layout.c b/sway/tree/layout.c index ec1c6fe5b..0a795b907 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -234,6 +234,7 @@ static bool is_parallel(enum sway_container_layout layout, enum movement_direction dir) { switch (layout) { case L_TABBED: + return dir == MOVE_LEFT || dir == MOVE_RIGHT; case L_STACKED: case L_HORIZ: return dir == MOVE_LEFT || dir == MOVE_RIGHT;