mirror of
https://github.com/swaywm/sway.git
synced 2024-12-28 16:06:37 +01:00
Tabbed and stacked layout
This commit is contained in:
parent
7efa9ab34a
commit
ec7ff769c7
6 changed files with 254 additions and 80 deletions
150
sway/border.c
150
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:
|
||||
swayc_t *p = view->parent;
|
||||
|
||||
if (p->layout == L_TABBED || p->layout == L_STACKED) {
|
||||
cr = create_border_buffer(view, view->border_geometry, &surface);
|
||||
if (!cr) {
|
||||
if (focused == view) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
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 (focused == view) {
|
||||
render_borders(view, cr, &config->border_colors.focused);
|
||||
} else if (focused_inactive == view) {
|
||||
render_borders(view, cr, &config->border_colors.focused_inactive);
|
||||
} else {
|
||||
render_borders(view, cr, &config->border_colors.unfocused);
|
||||
}
|
||||
|
||||
break;
|
||||
case B_NORMAL:
|
||||
cr = create_border_buffer(view, view->border_geometry, &surface);
|
||||
if (!cr) {
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (surface) {
|
||||
cairo_surface_flush(surface);
|
||||
cairo_surface_destroy(surface);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
10
sway/focus.c
10
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) {
|
||||
|
|
159
sway/layout.c
159
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:
|
||||
geometry.origin.x += border_left;
|
||||
geometry.origin.y += border_top;
|
||||
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
|
||||
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;
|
||||
}
|
||||
};
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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 += 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;
|
||||
} 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 += border_top;
|
||||
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 = 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue