|
|
|
@ -10,6 +10,7 @@
|
|
|
|
|
#include "focus.h"
|
|
|
|
|
|
|
|
|
|
swayc_t root_container;
|
|
|
|
|
|
|
|
|
|
int min_sane_h = 60;
|
|
|
|
|
int min_sane_w = 100;
|
|
|
|
|
|
|
|
|
@ -20,14 +21,17 @@ void init_layout(void) {
|
|
|
|
|
root_container.handle = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int index_child(swayc_t *child) {
|
|
|
|
|
int index_child(const swayc_t *child) {
|
|
|
|
|
swayc_t *parent = child->parent;
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < parent->children->length; ++i) {
|
|
|
|
|
int i, len = parent->children->length;
|
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
|
|
|
if (parent->children->items[i] == child) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!sway_assert(i < len, "Stray container")) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -37,7 +41,7 @@ void add_child(swayc_t *parent, swayc_t *child) {
|
|
|
|
|
list_add(parent->children, child);
|
|
|
|
|
child->parent = parent;
|
|
|
|
|
// set focus for this container
|
|
|
|
|
if (parent->children->length == 1) {
|
|
|
|
|
if (!parent->focused) {
|
|
|
|
|
parent->focused = child;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -59,9 +63,6 @@ void add_floating(swayc_t *ws, swayc_t *child) {
|
|
|
|
|
swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) {
|
|
|
|
|
swayc_t *parent = sibling->parent;
|
|
|
|
|
int i = index_child(sibling);
|
|
|
|
|
if (i == parent->children->length) {
|
|
|
|
|
--i;
|
|
|
|
|
}
|
|
|
|
|
list_insert(parent->children, i+1, child);
|
|
|
|
|
child->parent = parent;
|
|
|
|
|
return child->parent;
|
|
|
|
@ -74,61 +75,29 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) {
|
|
|
|
|
}
|
|
|
|
|
int i = index_child(child);
|
|
|
|
|
parent->children->items[i] = new_child;
|
|
|
|
|
new_child->parent = child->parent;
|
|
|
|
|
|
|
|
|
|
// Set parent for new child
|
|
|
|
|
// Set parent and focus for new_child
|
|
|
|
|
new_child->parent = child->parent;
|
|
|
|
|
if (child->parent->focused == child) {
|
|
|
|
|
child->parent->focused = new_child;
|
|
|
|
|
}
|
|
|
|
|
child->parent = NULL;
|
|
|
|
|
|
|
|
|
|
// Set geometry for new child
|
|
|
|
|
new_child->x = child->x;
|
|
|
|
|
new_child->y = child->y;
|
|
|
|
|
new_child->width = child->width;
|
|
|
|
|
new_child->height = child->height;
|
|
|
|
|
// set child geometry to 0
|
|
|
|
|
child->x = 0;
|
|
|
|
|
child->y = 0;
|
|
|
|
|
|
|
|
|
|
// reset geometry for child
|
|
|
|
|
child->width = 0;
|
|
|
|
|
child->height = 0;
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void swap_container(swayc_t *a, swayc_t *b) {
|
|
|
|
|
//TODO doesnt handle floating <-> tiling swap
|
|
|
|
|
if (!sway_assert(a&&b, "parameters must be non null") ||
|
|
|
|
|
!sway_assert(a->parent && b->parent, "containers must have parents")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
size_t a_index = index_child(a);
|
|
|
|
|
size_t b_index = index_child(b);
|
|
|
|
|
swayc_t *a_parent = a->parent;
|
|
|
|
|
swayc_t *b_parent = b->parent;
|
|
|
|
|
// Swap the pointers
|
|
|
|
|
a_parent->children->items[a_index] = b;
|
|
|
|
|
b_parent->children->items[b_index] = a;
|
|
|
|
|
a->parent = b_parent;
|
|
|
|
|
b->parent = a_parent;
|
|
|
|
|
if (a_parent->focused == a) {
|
|
|
|
|
a_parent->focused = b;
|
|
|
|
|
}
|
|
|
|
|
// dont want to double switch
|
|
|
|
|
if (b_parent->focused == b && a_parent != b_parent) {
|
|
|
|
|
b_parent->focused = a;
|
|
|
|
|
// deactivate child
|
|
|
|
|
if (child->type == C_VIEW) {
|
|
|
|
|
wlc_view_set_state(child->handle, WLC_BIT_ACTIVATED, false);
|
|
|
|
|
}
|
|
|
|
|
// and their geometry
|
|
|
|
|
double x = a->x;
|
|
|
|
|
double y = a->y;
|
|
|
|
|
double w = a->width;
|
|
|
|
|
double h = a->height;
|
|
|
|
|
a->x = b->x;
|
|
|
|
|
a->y = b->y;
|
|
|
|
|
a->width = b->width;
|
|
|
|
|
a->height = b->height;
|
|
|
|
|
b->x = x;
|
|
|
|
|
b->y = y;
|
|
|
|
|
b->width = w;
|
|
|
|
|
b->height = h;
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
swayc_t *remove_child(swayc_t *child) {
|
|
|
|
@ -168,6 +137,43 @@ swayc_t *remove_child(swayc_t *child) {
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void swap_container(swayc_t *a, swayc_t *b) {
|
|
|
|
|
//TODO doesnt handle floating <-> tiling swap
|
|
|
|
|
if (!sway_assert(a&&b, "parameters must be non null") ||
|
|
|
|
|
!sway_assert(a->parent && b->parent, "containers must have parents")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
size_t a_index = index_child(a);
|
|
|
|
|
size_t b_index = index_child(b);
|
|
|
|
|
swayc_t *a_parent = a->parent;
|
|
|
|
|
swayc_t *b_parent = b->parent;
|
|
|
|
|
// Swap the pointers
|
|
|
|
|
a_parent->children->items[a_index] = b;
|
|
|
|
|
b_parent->children->items[b_index] = a;
|
|
|
|
|
a->parent = b_parent;
|
|
|
|
|
b->parent = a_parent;
|
|
|
|
|
if (a_parent->focused == a) {
|
|
|
|
|
a_parent->focused = b;
|
|
|
|
|
}
|
|
|
|
|
// dont want to double switch
|
|
|
|
|
if (b_parent->focused == b && a_parent != b_parent) {
|
|
|
|
|
b_parent->focused = a;
|
|
|
|
|
}
|
|
|
|
|
// and their geometry
|
|
|
|
|
double x = a->x;
|
|
|
|
|
double y = a->y;
|
|
|
|
|
double w = a->width;
|
|
|
|
|
double h = a->height;
|
|
|
|
|
a->x = b->x;
|
|
|
|
|
a->y = b->y;
|
|
|
|
|
a->width = b->width;
|
|
|
|
|
a->height = b->height;
|
|
|
|
|
b->x = x;
|
|
|
|
|
b->y = y;
|
|
|
|
|
b->width = w;
|
|
|
|
|
b->height = h;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO: Implement horizontal movement.
|
|
|
|
|
//TODO: Implement move to a different workspace.
|
|
|
|
|
void move_container(swayc_t *container,swayc_t* root,enum movement_direction direction) {
|
|
|
|
|