mirror of
https://github.com/swaywm/sway.git
synced 2026-05-03 06:46:26 -04:00
add tabbed windows
This commit is contained in:
parent
a8d1b05bac
commit
c7b3f9854f
5 changed files with 89 additions and 11 deletions
|
|
@ -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 <horizontal|vertical|auto>'");
|
||||
"Expected 'orientation <horizontal|vertical|tabbed|auto>'");
|
||||
}
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue