aboutsummaryrefslogtreecommitdiff
path: root/sway/tree
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-05-21 19:52:08 -0400
committerGitHub <noreply@github.com>2018-05-21 19:52:08 -0400
commit9731d080bea58fee78bd52bb5633cb37ec7edc22 (patch)
tree7fbc2b11fc371cdec7ed1b5cdbeb2224d429cace /sway/tree
parent8bbf78fdd430a7e315356ebeda36adbf48b8953d (diff)
parent4de137e02161ef8188775d50fe5dc8d9e9bb2216 (diff)
downloadsway-9731d080bea58fee78bd52bb5633cb37ec7edc22.tar.xz
Merge pull request #2015 from RyanDwyer/stacked-layout
Implement stacked layout
Diffstat (limited to 'sway/tree')
-rw-r--r--sway/tree/arrange.c32
-rw-r--r--sway/tree/container.c25
-rw-r--r--sway/tree/view.c15
3 files changed, 55 insertions, 17 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index 8aebc0cc..37f4a066 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -86,12 +86,14 @@ static void apply_horiz_layout(struct sway_container *parent) {
if (!num_children) {
return;
}
- size_t parent_height = parent->height;
size_t parent_offset = 0;
if (parent->parent->layout == L_TABBED) {
- parent_offset = config->border_thickness * 2 + config->font_height;
- parent_height -= parent_offset;
+ parent_offset = container_titlebar_height();
+ } else if (parent->parent->layout == L_STACKED) {
+ parent_offset =
+ container_titlebar_height() * parent->parent->children->length;
}
+ size_t parent_height = parent->height - parent_offset;
// Calculate total width of children
double total_width = 0;
@@ -132,12 +134,14 @@ static void apply_vert_layout(struct sway_container *parent) {
if (!num_children) {
return;
}
- size_t parent_height = parent->height;
size_t parent_offset = 0;
if (parent->parent->layout == L_TABBED) {
- parent_offset = config->border_thickness * 2 + config->font_height;
- parent_height -= parent_offset;
+ parent_offset = container_titlebar_height();
+ } else if (parent->parent->layout == L_STACKED) {
+ parent_offset =
+ container_titlebar_height() * parent->parent->children->length;
}
+ size_t parent_height = parent->height - parent_offset;
// Calculate total height of children
double total_height = 0;
@@ -186,6 +190,19 @@ static void apply_tabbed_layout(struct sway_container *parent) {
}
}
+static void apply_stacked_layout(struct sway_container *parent) {
+ if (!parent->children->length) {
+ return;
+ }
+ for (int i = 0; i < parent->children->length; ++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;
@@ -219,6 +236,9 @@ void arrange_children_of(struct sway_container *parent) {
case L_TABBED:
apply_tabbed_layout(parent);
break;
+ case L_STACKED:
+ apply_stacked_layout(parent);
+ break;
default:
wlr_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout);
apply_horiz_layout(parent);
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 5d88325f..9cf18f61 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -510,7 +510,7 @@ static struct sway_container *container_at_tabbed(struct sway_container *parent,
struct sway_seat *seat = input_manager_current_seat(input_manager);
// Tab titles
- int title_height = config->border_thickness * 2 + config->font_height;
+ int title_height = container_titlebar_height();
if (oy < parent->y + title_height) {
int tab_width = parent->width / parent->children->length;
int child_index = (ox - parent->x) / tab_width;
@@ -533,8 +533,23 @@ static struct sway_container *container_at_tabbed(struct sway_container *parent,
static struct sway_container *container_at_stacked(
struct sway_container *parent, double ox, double oy,
struct wlr_surface **surface, double *sx, double *sy) {
- // TODO
- return NULL;
+ if (oy < parent->y || oy > parent->y + parent->height) {
+ return NULL;
+ }
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+
+ // Title bars
+ int title_height = container_titlebar_height();
+ int child_index = (oy - parent->y) / title_height;
+ if (child_index < parent->children->length) {
+ struct sway_container *child = parent->children->items[child_index];
+ return seat_get_focus_inactive(seat, child);
+ }
+
+ // Surfaces
+ struct sway_container *current = seat_get_active_child(seat, parent);
+
+ return container_at(current, ox, oy, surface, sx, sy);
}
/**
@@ -847,3 +862,7 @@ void container_notify_child_title_changed(struct sway_container *container) {
container_update_title_textures(container);
container_notify_child_title_changed(container->parent);
}
+
+size_t container_titlebar_height() {
+ return config->font_height + TITLEBAR_V_PADDING * 2;
+}
diff --git a/sway/tree/view.c b/sway/tree/view.c
index c013e635..07157818 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -182,11 +182,11 @@ void view_autoconfigure(struct sway_view *view) {
// area. We have to offset the surface y by the height of the title bar, and
// disable any top border because we'll always have the title bar.
if (view->swayc->parent->layout == L_TABBED) {
- y_offset = config->border_thickness * 2 + config->font_height;
+ y_offset = container_titlebar_height();
view->border_top = 0;
} else if (view->swayc->parent->layout == L_STACKED) {
- y_offset = config->border_thickness * 2 + config->font_height;
- y_offset *= view->swayc->parent->children->length;
+ y_offset = container_titlebar_height()
+ * view->swayc->parent->children->length;
view->border_top = 0;
}
@@ -208,7 +208,7 @@ void view_autoconfigure(struct sway_view *view) {
- view->border_thickness * view->border_bottom;
break;
case B_NORMAL:
- // Height is: border + title height + border + view height + border
+ // Height is: 1px border + 3px pad + title height + 3px pad + 1px border
x = view->swayc->x + view->border_thickness * view->border_left;
width = view->swayc->width
- view->border_thickness * view->border_left
@@ -218,10 +218,9 @@ void view_autoconfigure(struct sway_view *view) {
height = view->swayc->height - y_offset
- view->border_thickness * view->border_bottom;
} else {
- y = view->swayc->y + config->font_height + view->border_thickness * 2
- + y_offset;
- height = view->swayc->height - config->font_height
- - view->border_thickness * (2 + view->border_bottom);
+ y = view->swayc->y + container_titlebar_height();
+ height = view->swayc->height - container_titlebar_height()
+ - view->border_thickness * view->border_bottom;
}
break;
}