some function documentation, fixed gaps on config reload

master
taiyu 9 years ago
parent 1e54490b71
commit 357af228d6

@ -11,14 +11,33 @@ extern swayc_t root_container;
extern int min_sane_w;
extern int min_sane_h;
// Set initial values for root_container
void init_layout(void);
// Returns the index of child for its parent
int index_child(const swayc_t *child);
// Adds child to parent, if parent has no focus, it is set to child
// parent must be of type C_WORKSPACE or C_CONTAINER
void add_child(swayc_t *parent, swayc_t *child);
// Adds child as floating window to ws, if there is no focus it is set to child.
// ws must be of type C_WORKSPACE
void add_floating(swayc_t *ws, swayc_t *child);
// Returns parent container which needs to be rearranged.
// insert child after sibling in parents children.
swayc_t *add_sibling(swayc_t *sibling, swayc_t *child);
// Replace child with new_child in parents children
// new_child will inherit childs geometry, childs geometry will be reset
// if parents focus is on child, it will be changed to new_child
swayc_t *replace_child(swayc_t *child, swayc_t *new_child);
// Remove child from its parent, if focus is on child, focus will be changed to
// a sibling, or to a floating window, or NULL
swayc_t *remove_child(swayc_t *child);
// 2 containers are swapped, they inherit eachothers geometry and focus
void swap_container(swayc_t *a, swayc_t *b);
void move_container(swayc_t* container,swayc_t* root,enum movement_direction direction);

@ -86,7 +86,7 @@ swayc_t *new_output(wlc_handle handle) {
}
output->handle = handle;
output->name = name ? strdup(name) : NULL;
output->gaps = config->gaps_outer + config->gaps_inner / 2;
output->gaps = config->gaps_outer;
// Find position for it
if (oc && oc->x != -1 && oc->y != -1) {

@ -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,9 +137,46 @@ 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){
void move_container(swayc_t *container,swayc_t* root,enum movement_direction direction) {
sway_log(L_DEBUG, "Moved window");
swayc_t *temp;
int i;

Loading…
Cancel
Save