2015-08-06 22:24:14 +10:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <wlc/wlc.h>
|
|
|
|
#include "layout.h"
|
2015-08-19 04:22:52 +10:00
|
|
|
#include "log.h"
|
|
|
|
#include "list.h"
|
2015-08-19 08:44:50 +10:00
|
|
|
#include "config.h"
|
2015-08-11 13:47:14 +10:00
|
|
|
#include "container.h"
|
2015-08-11 06:31:23 +10:00
|
|
|
#include "workspace.h"
|
2015-08-19 04:22:52 +10:00
|
|
|
#include "focus.h"
|
2015-08-06 22:24:14 +10:00
|
|
|
|
2015-08-09 07:44:51 +10:00
|
|
|
swayc_t root_container;
|
2015-08-22 13:26:11 +10:00
|
|
|
int min_sane_h = 60;
|
|
|
|
int min_sane_w = 100;
|
2015-08-09 07:01:22 +10:00
|
|
|
|
2015-08-15 05:42:19 +10:00
|
|
|
void init_layout(void) {
|
|
|
|
root_container.type = C_ROOT;
|
|
|
|
root_container.layout = L_NONE;
|
|
|
|
root_container.children = create_list();
|
|
|
|
root_container.handle = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int index_child(swayc_t *parent, swayc_t *child) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < parent->children->length; ++i) {
|
|
|
|
if (parent->children->items[i] == child) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_child(swayc_t *parent, swayc_t *child) {
|
2015-08-21 12:37:59 +10:00
|
|
|
sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type,
|
2015-08-15 05:42:19 +10:00
|
|
|
child->width, child->height, parent, parent->type, parent->width, parent->height);
|
|
|
|
list_add(parent->children, child);
|
|
|
|
child->parent = parent;
|
2015-08-20 22:06:22 +10:00
|
|
|
// set focus for this container
|
2015-08-19 15:20:31 +10:00
|
|
|
if (parent->children->length == 1) {
|
2015-08-22 03:28:37 +10:00
|
|
|
parent->focused = child;
|
2015-08-19 15:20:31 +10:00
|
|
|
}
|
2015-08-15 05:42:19 +10:00
|
|
|
}
|
|
|
|
|
2015-08-19 17:28:53 +10:00
|
|
|
void add_floating(swayc_t *ws, swayc_t *child) {
|
2015-08-21 12:37:59 +10:00
|
|
|
sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type,
|
2015-08-19 17:28:53 +10:00
|
|
|
child->width, child->height, ws, ws->type, ws->width, ws->height);
|
|
|
|
list_add(ws->floating, child);
|
|
|
|
child->parent = ws;
|
|
|
|
child->is_floating = true;
|
|
|
|
if (!ws->focused) {
|
2015-08-22 03:28:37 +10:00
|
|
|
ws->focused = child;
|
2015-08-19 17:28:53 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-15 05:42:19 +10:00
|
|
|
swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) {
|
|
|
|
swayc_t *parent = sibling->parent;
|
|
|
|
int i = index_child(parent, sibling);
|
|
|
|
if (i == parent->children->length) {
|
|
|
|
--i;
|
|
|
|
}
|
|
|
|
list_insert(parent->children, i+1, child);
|
|
|
|
child->parent = parent;
|
|
|
|
return child->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
swayc_t *replace_child(swayc_t *child, swayc_t *new_child) {
|
|
|
|
swayc_t *parent = child->parent;
|
|
|
|
if (parent == NULL) {
|
2015-08-09 23:23:10 +10:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-08-15 05:42:19 +10:00
|
|
|
int i = index_child(parent, child);
|
|
|
|
parent->children->items[i] = new_child;
|
|
|
|
new_child->parent = child->parent;
|
|
|
|
|
|
|
|
if (child->parent->focused == child) {
|
2015-08-22 03:28:37 +10:00
|
|
|
child->parent->focused = new_child;
|
2015-08-15 05:42:19 +10:00
|
|
|
}
|
|
|
|
child->parent = NULL;
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2015-08-18 19:46:14 +10:00
|
|
|
swayc_t *remove_child(swayc_t *child) {
|
2015-08-09 23:23:10 +10:00
|
|
|
int i;
|
2015-08-18 19:46:14 +10:00
|
|
|
swayc_t *parent = child->parent;
|
2015-08-17 15:38:34 +10:00
|
|
|
if (child->is_floating) {
|
2015-08-18 21:19:20 +10:00
|
|
|
// Special case for floating views
|
2015-08-17 15:38:34 +10:00
|
|
|
for (i = 0; i < parent->floating->length; ++i) {
|
|
|
|
if (parent->floating->items[i] == child) {
|
|
|
|
list_del(parent->floating, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-08-19 17:28:53 +10:00
|
|
|
i = 0;
|
2015-08-18 01:18:06 +10:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < parent->children->length; ++i) {
|
|
|
|
if (parent->children->items[i] == child) {
|
|
|
|
list_del(parent->children, i);
|
|
|
|
break;
|
|
|
|
}
|
2015-08-09 23:23:10 +10:00
|
|
|
}
|
|
|
|
}
|
2015-08-20 22:06:22 +10:00
|
|
|
// Set focused to new container
|
2015-08-15 05:42:19 +10:00
|
|
|
if (parent->focused == child) {
|
2015-08-18 19:46:14 +10:00
|
|
|
if (parent->children->length > 0) {
|
2015-08-22 03:28:37 +10:00
|
|
|
parent->focused = parent->children->items[i?i-1:0];
|
2015-08-18 19:46:14 +10:00
|
|
|
} else {
|
|
|
|
parent->focused = NULL;
|
|
|
|
}
|
2015-08-15 05:42:19 +10:00
|
|
|
}
|
|
|
|
return parent;
|
2015-08-09 23:23:10 +10:00
|
|
|
}
|
|
|
|
|
2015-08-21 06:45:00 +10:00
|
|
|
//TODO: Implement horizontal movement.
|
|
|
|
//TODO: Implement move to a different workspace.
|
|
|
|
void move_container(swayc_t *container,swayc_t* root,enum movement_direction direction){
|
2015-08-21 06:27:38 +10:00
|
|
|
sway_log(L_DEBUG, "Moved window");
|
|
|
|
swayc_t *temp;
|
|
|
|
int i;
|
2015-08-22 00:53:11 +10:00
|
|
|
int clength = root->children->length;
|
2015-08-21 06:27:38 +10:00
|
|
|
//Rearrange
|
|
|
|
for (i = 0; i < clength; ++i) {
|
|
|
|
swayc_t *child = root->children->items[i];
|
2015-08-21 07:29:36 +10:00
|
|
|
if (child->handle == container->handle){
|
|
|
|
if (clength == 1){
|
2015-08-21 06:27:38 +10:00
|
|
|
//Only one container, meh.
|
|
|
|
break;
|
|
|
|
}
|
2015-08-21 07:29:36 +10:00
|
|
|
if (direction == MOVE_LEFT && i > 0){
|
2015-08-21 06:27:38 +10:00
|
|
|
temp = root->children->items[i-1];
|
|
|
|
root->children->items[i] = temp;
|
|
|
|
root->children->items[i-1] = container;
|
|
|
|
arrange_windows(&root_container,-1,-1);
|
|
|
|
}
|
2015-08-21 07:29:36 +10:00
|
|
|
else if (direction == MOVE_RIGHT && i < clength-1){
|
2015-08-21 06:27:38 +10:00
|
|
|
temp = root->children->items[i+1];
|
|
|
|
root->children->items[i] = temp;
|
|
|
|
root->children->items[i+1] = container;
|
|
|
|
arrange_windows(&root_container,-1,-1);
|
|
|
|
|
|
|
|
}
|
2015-08-21 07:29:36 +10:00
|
|
|
else if (direction == MOVE_UP){
|
2015-08-21 06:27:38 +10:00
|
|
|
sway_log(L_INFO, "Moving up not implemented");
|
|
|
|
}
|
2015-08-21 07:29:36 +10:00
|
|
|
else if (direction == MOVE_DOWN){
|
2015-08-21 06:27:38 +10:00
|
|
|
sway_log(L_INFO, "Moving down not implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2015-08-21 07:29:36 +10:00
|
|
|
else if (child->children != NULL){
|
2015-08-21 06:27:38 +10:00
|
|
|
move_container(container,child,direction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-15 05:42:19 +10:00
|
|
|
|
2015-08-21 15:17:26 +10:00
|
|
|
void arrange_windows(swayc_t *container, double width, double height) {
|
2015-08-09 08:17:08 +10:00
|
|
|
int i;
|
|
|
|
if (width == -1 || height == -1) {
|
|
|
|
sway_log(L_DEBUG, "Arranging layout for %p", container);
|
|
|
|
width = container->width;
|
|
|
|
height = container->height;
|
|
|
|
}
|
|
|
|
|
2015-08-11 13:47:14 +10:00
|
|
|
int x = 0, y = 0;
|
2015-08-09 08:34:33 +10:00
|
|
|
switch (container->type) {
|
|
|
|
case C_ROOT:
|
2015-08-09 08:17:08 +10:00
|
|
|
for (i = 0; i < container->children->length; ++i) {
|
2015-08-11 13:47:14 +10:00
|
|
|
swayc_t *child = container->children->items[i];
|
|
|
|
sway_log(L_DEBUG, "Arranging output at %d", x);
|
2015-08-11 13:54:23 +10:00
|
|
|
arrange_windows(child, -1, -1);
|
2015-08-23 04:44:47 +10:00
|
|
|
x += child->width;
|
2015-08-09 08:17:08 +10:00
|
|
|
}
|
|
|
|
return;
|
2015-08-11 13:54:23 +10:00
|
|
|
case C_OUTPUT:
|
|
|
|
container->width = width;
|
|
|
|
container->height = height;
|
2015-08-23 04:44:47 +10:00
|
|
|
x = 0, y = 0;
|
2015-08-16 07:13:08 +10:00
|
|
|
for (i = 0; i < container->children->length; ++i) {
|
|
|
|
swayc_t *child = container->children->items[i];
|
2015-08-19 08:44:50 +10:00
|
|
|
child->x = x + container->gaps;
|
|
|
|
child->y = y + container->gaps;
|
|
|
|
child->width = width - container->gaps * 2;
|
|
|
|
child->height = height - container->gaps * 2;
|
2015-08-21 12:37:59 +10:00
|
|
|
sway_log(L_DEBUG, "Arranging workspace #%d at %f, %f", i, child->x, child->y);
|
2015-08-16 07:13:08 +10:00
|
|
|
arrange_windows(child, -1, -1);
|
|
|
|
}
|
|
|
|
return;
|
2015-08-09 08:34:33 +10:00
|
|
|
case C_VIEW:
|
2015-08-10 10:58:03 +10:00
|
|
|
{
|
|
|
|
struct wlc_geometry geometry = {
|
|
|
|
.origin = {
|
2015-08-20 16:46:06 +10:00
|
|
|
.x = container->x + container->gaps / 2,
|
|
|
|
.y = container->y + container->gaps / 2
|
2015-08-10 10:58:03 +10:00
|
|
|
},
|
|
|
|
.size = {
|
2015-08-20 16:46:06 +10:00
|
|
|
.w = width - container->gaps,
|
|
|
|
.h = height - container->gaps
|
2015-08-10 10:58:03 +10:00
|
|
|
}
|
|
|
|
};
|
2015-08-22 03:45:18 +10:00
|
|
|
if (swayc_is_fullscreen(container)) {
|
2015-08-21 02:52:54 +10:00
|
|
|
swayc_t *parent = swayc_parent_by_type(container, C_OUTPUT);
|
2015-08-19 08:44:50 +10:00
|
|
|
geometry.origin.x = 0;
|
|
|
|
geometry.origin.y = 0;
|
|
|
|
geometry.size.w = parent->width;
|
|
|
|
geometry.size.h = parent->height;
|
2015-08-19 07:24:01 +10:00
|
|
|
wlc_view_set_geometry(container->handle, 0, &geometry);
|
2015-08-10 10:58:03 +10:00
|
|
|
wlc_view_bring_to_front(container->handle);
|
|
|
|
} else {
|
2015-08-19 07:24:01 +10:00
|
|
|
wlc_view_set_geometry(container->handle, 0, &geometry);
|
2015-08-10 10:58:03 +10:00
|
|
|
container->width = width;
|
|
|
|
container->height = height;
|
2015-08-09 08:17:08 +10:00
|
|
|
}
|
2015-08-10 10:58:03 +10:00
|
|
|
sway_log(L_DEBUG, "Set view to %d x %d @ %d, %d", geometry.size.w, geometry.size.h,
|
|
|
|
geometry.origin.x, geometry.origin.y);
|
2015-08-10 10:49:19 +10:00
|
|
|
}
|
2015-08-09 08:17:08 +10:00
|
|
|
return;
|
2015-08-09 08:34:33 +10:00
|
|
|
default:
|
|
|
|
container->width = width;
|
|
|
|
container->height = height;
|
|
|
|
break;
|
2015-08-09 08:17:08 +10:00
|
|
|
}
|
|
|
|
|
2015-08-20 21:47:36 +10:00
|
|
|
x = y = 0;
|
|
|
|
double scale = 0;
|
2015-08-09 08:17:08 +10:00
|
|
|
switch (container->layout) {
|
|
|
|
case L_HORIZ:
|
|
|
|
default:
|
2015-08-20 22:06:22 +10:00
|
|
|
// Calculate total width
|
2015-08-09 08:17:08 +10:00
|
|
|
for (i = 0; i < container->children->length; ++i) {
|
2015-08-21 12:37:59 +10:00
|
|
|
double *old_width = &((swayc_t *)container->children->items[i])->width;
|
2015-08-20 21:57:01 +10:00
|
|
|
if (*old_width <= 0) {
|
2015-08-20 21:47:36 +10:00
|
|
|
if (container->children->length > 1) {
|
|
|
|
*old_width = width / (container->children->length - 1);
|
|
|
|
} else {
|
|
|
|
*old_width = width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scale += *old_width;
|
|
|
|
}
|
2015-08-20 22:06:22 +10:00
|
|
|
// Resize windows
|
2015-08-20 21:47:36 +10:00
|
|
|
if (scale > 0.1) {
|
|
|
|
scale = width / scale;
|
|
|
|
sway_log(L_DEBUG, "Arranging %p horizontally", container);
|
|
|
|
for (i = 0; i < container->children->length; ++i) {
|
|
|
|
swayc_t *child = container->children->items[i];
|
2015-08-21 15:17:26 +10:00
|
|
|
sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, width, scale);
|
2015-08-20 21:47:36 +10:00
|
|
|
child->x = x + container->x;
|
|
|
|
child->y = y + container->y;
|
|
|
|
arrange_windows(child, child->width * scale, height);
|
|
|
|
x += child->width;
|
|
|
|
}
|
2015-08-09 08:17:08 +10:00
|
|
|
}
|
|
|
|
break;
|
2015-08-09 08:34:33 +10:00
|
|
|
case L_VERT:
|
2015-08-20 22:06:22 +10:00
|
|
|
// Calculate total height
|
2015-08-09 08:34:33 +10:00
|
|
|
for (i = 0; i < container->children->length; ++i) {
|
2015-08-21 12:37:59 +10:00
|
|
|
double *old_height = &((swayc_t *)container->children->items[i])->height;
|
2015-08-20 21:57:01 +10:00
|
|
|
if (*old_height <= 0) {
|
2015-08-20 21:47:36 +10:00
|
|
|
if (container->children->length > 1) {
|
|
|
|
*old_height = height / (container->children->length - 1);
|
|
|
|
} else {
|
|
|
|
*old_height = height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scale += *old_height;
|
|
|
|
}
|
2015-08-20 22:06:22 +10:00
|
|
|
// Resize
|
2015-08-20 21:47:36 +10:00
|
|
|
if (scale > 0.1) {
|
|
|
|
scale = height / scale;
|
|
|
|
sway_log(L_DEBUG, "Arranging %p vertically", container);
|
|
|
|
for (i = 0; i < container->children->length; ++i) {
|
|
|
|
swayc_t *child = container->children->items[i];
|
2015-08-21 15:17:26 +10:00
|
|
|
sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, height, scale);
|
2015-08-20 21:47:36 +10:00
|
|
|
child->x = x + container->x;
|
|
|
|
child->y = y + container->y;
|
|
|
|
arrange_windows(child, width, child->height * scale);
|
|
|
|
y += child->height;
|
|
|
|
}
|
2015-08-09 08:34:33 +10:00
|
|
|
}
|
|
|
|
break;
|
2015-08-09 08:17:08 +10:00
|
|
|
}
|
2015-08-17 15:38:34 +10:00
|
|
|
|
|
|
|
// Arrage floating layouts for workspaces last
|
|
|
|
if (container->type == C_WORKSPACE) {
|
|
|
|
for (i = 0; i < container->floating->length; ++i) {
|
2015-08-18 17:28:44 +10:00
|
|
|
swayc_t *view = container->floating->items[i];
|
2015-08-19 04:22:52 +10:00
|
|
|
if (view->type == C_VIEW) {
|
|
|
|
// Set the geometry
|
|
|
|
struct wlc_geometry geometry = {
|
|
|
|
.origin = {
|
|
|
|
.x = view->x,
|
|
|
|
.y = view->y
|
|
|
|
},
|
|
|
|
.size = {
|
|
|
|
.w = view->width,
|
|
|
|
.h = view->height
|
|
|
|
}
|
|
|
|
};
|
2015-08-22 03:45:18 +10:00
|
|
|
if (swayc_is_fullscreen(view)) {
|
2015-08-21 02:52:54 +10:00
|
|
|
swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT);
|
2015-08-19 04:22:52 +10:00
|
|
|
geometry.origin.x = 0;
|
|
|
|
geometry.origin.y = 0;
|
|
|
|
geometry.size.w = parent->width;
|
|
|
|
geometry.size.h = parent->height;
|
2015-08-19 07:24:01 +10:00
|
|
|
wlc_view_set_geometry(view->handle, 0, &geometry);
|
2015-08-19 04:22:52 +10:00
|
|
|
wlc_view_bring_to_front(view->handle);
|
|
|
|
} else {
|
2015-08-19 07:24:01 +10:00
|
|
|
wlc_view_set_geometry(view->handle, 0, &geometry);
|
2015-08-19 04:22:52 +10:00
|
|
|
// Bring the views to the front in order of the list, the list
|
|
|
|
// will be kept up to date so that more recently focused views
|
|
|
|
// have higher indexes
|
|
|
|
// This is conditional on there not being a fullscreen view in the workspace
|
|
|
|
if (!container->focused
|
2015-08-22 03:45:18 +10:00
|
|
|
|| !swayc_is_fullscreen(container->focused)) {
|
2015-08-19 04:22:52 +10:00
|
|
|
wlc_view_bring_to_front(view->handle);
|
|
|
|
}
|
2015-08-17 15:38:34 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-16 04:55:06 +10:00
|
|
|
layout_log(&root_container, 0);
|
2015-08-09 07:01:22 +10:00
|
|
|
}
|
2015-08-06 22:40:16 +10:00
|
|
|
|
2015-08-09 07:01:22 +10:00
|
|
|
|
2015-08-20 13:22:15 +10:00
|
|
|
swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) {
|
|
|
|
swayc_t *parent = container->parent;
|
|
|
|
|
|
|
|
if (dir == MOVE_PARENT) {
|
|
|
|
if (parent->type == C_OUTPUT) {
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (true) {
|
|
|
|
// Test if we can even make a difference here
|
|
|
|
bool can_move = false;
|
|
|
|
int diff = 0;
|
2015-08-23 05:19:02 +10:00
|
|
|
int i;
|
|
|
|
if (parent->type == C_ROOT) {
|
|
|
|
// Find the next output
|
|
|
|
int target = -1, max_x = 0, max_y = 0, self = -1;
|
|
|
|
sway_log(L_DEBUG, "Moving between outputs");
|
|
|
|
|
|
|
|
for (i = 0; i < parent->children->length; ++i) {
|
|
|
|
swayc_t *next = parent->children->items[i];
|
|
|
|
if (next == container) {
|
|
|
|
self = i;
|
|
|
|
sway_log(L_DEBUG, "self is %p %d", next, self);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (next->type == C_OUTPUT) {
|
|
|
|
sway_log(L_DEBUG, "Testing with %p %d (dir %d)", next, i, dir);
|
|
|
|
// Check if it's more extreme
|
|
|
|
if (dir == MOVE_RIGHT) {
|
|
|
|
if (container->x + container->width <= next->x) {
|
|
|
|
if (target == -1 || next->x < max_x) {
|
|
|
|
target = i;
|
|
|
|
max_x = next->x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (dir == MOVE_LEFT) {
|
2015-08-23 05:21:56 +10:00
|
|
|
if (container->x >= next->x + next->width) {
|
2015-08-23 05:19:02 +10:00
|
|
|
if (target == -1 || max_x < next->x) {
|
|
|
|
target = i;
|
|
|
|
max_x = next->x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (dir == MOVE_DOWN) {
|
|
|
|
if (container->y + container->height <= next->y) {
|
|
|
|
if (target == -1 || next->y < max_y) {
|
|
|
|
target = i;
|
|
|
|
max_y = next->y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (dir == MOVE_UP) {
|
2015-08-23 05:21:56 +10:00
|
|
|
if (container->y >= next->y + next->height) {
|
2015-08-23 05:19:02 +10:00
|
|
|
if (target == -1 || max_y < next->y) {
|
|
|
|
target = i;
|
|
|
|
max_y = next->y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target == -1) {
|
|
|
|
can_move = false;
|
|
|
|
} else {
|
2015-08-20 13:22:15 +10:00
|
|
|
can_move = true;
|
2015-08-23 05:19:02 +10:00
|
|
|
diff = target - self;
|
2015-08-20 13:22:15 +10:00
|
|
|
}
|
|
|
|
} else {
|
2015-08-23 05:19:02 +10:00
|
|
|
if (dir == MOVE_LEFT || dir == MOVE_RIGHT) {
|
|
|
|
if (parent->layout == L_HORIZ) {
|
|
|
|
can_move = true;
|
|
|
|
diff = dir == MOVE_LEFT ? -1 : 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (parent->layout == L_VERT) {
|
|
|
|
can_move = true;
|
|
|
|
diff = dir == MOVE_UP ? -1 : 1;
|
|
|
|
}
|
2015-08-20 13:22:15 +10:00
|
|
|
}
|
|
|
|
}
|
2015-08-23 05:19:02 +10:00
|
|
|
|
2015-08-20 13:22:15 +10:00
|
|
|
if (can_move) {
|
|
|
|
for (i = 0; i < parent->children->length; ++i) {
|
|
|
|
swayc_t *child = parent->children->items[i];
|
|
|
|
if (child == container) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int desired = i + diff;
|
|
|
|
if (desired < 0 || desired >= parent->children->length) {
|
|
|
|
can_move = false;
|
|
|
|
} else {
|
|
|
|
return parent->children->items[desired];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!can_move) {
|
|
|
|
container = parent;
|
|
|
|
parent = parent->parent;
|
|
|
|
if (!parent) {
|
|
|
|
// Nothing we can do
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-21 02:30:32 +10:00
|
|
|
|
2015-08-21 12:37:59 +10:00
|
|
|
void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge) {
|
2015-08-21 02:30:32 +10:00
|
|
|
int i;
|
|
|
|
bool layout_match = true;
|
2015-08-21 12:37:59 +10:00
|
|
|
sway_log(L_DEBUG, "Resizing %p with amount: %f", container, amount);
|
|
|
|
if (edge == WLC_RESIZE_EDGE_LEFT || edge == WLC_RESIZE_EDGE_RIGHT) {
|
|
|
|
container->width += amount;
|
2015-08-21 02:30:32 +10:00
|
|
|
layout_match = container->layout == L_HORIZ;
|
2015-08-21 12:37:59 +10:00
|
|
|
} else if (edge == WLC_RESIZE_EDGE_TOP || edge == WLC_RESIZE_EDGE_BOTTOM) {
|
|
|
|
container->height += amount;
|
2015-08-21 02:30:32 +10:00
|
|
|
layout_match = container->layout == L_VERT;
|
|
|
|
}
|
|
|
|
if (container->type == C_VIEW) {
|
2015-08-21 12:37:59 +10:00
|
|
|
struct wlc_geometry geometry = {
|
|
|
|
.origin = {
|
|
|
|
.x = container->x + container->gaps / 2,
|
|
|
|
.y = container->y + container->gaps / 2
|
|
|
|
},
|
|
|
|
.size = {
|
|
|
|
.w = container->width - container->gaps,
|
|
|
|
.h = container->height - container->gaps
|
|
|
|
}
|
|
|
|
};
|
|
|
|
wlc_view_set_geometry(container->handle, edge, &geometry);
|
2015-08-21 02:30:32 +10:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (layout_match) {
|
|
|
|
for (i = 0; i < container->children->length; i++) {
|
2015-08-21 12:37:59 +10:00
|
|
|
recursive_resize(container->children->items[i], amount/container->children->length, edge);
|
2015-08-21 02:30:32 +10:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < container->children->length; i++) {
|
2015-08-21 12:37:59 +10:00
|
|
|
recursive_resize(container->children->items[i], amount, edge);
|
2015-08-21 02:30:32 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|