1
1
mirror of https://github.com/swaywm/sway synced 2024-09-30 09:01:21 +02:00

some function documentation, fixed gaps on config reload

This commit is contained in:
taiyu 2015-08-26 13:35:22 -07:00
parent 1e54490b71
commit 357af228d6
3 changed files with 77 additions and 52 deletions

@ -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,23 +75,65 @@ 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;
// deactivate child
if (child->type == C_VIEW) {
wlc_view_set_state(child->handle, WLC_BIT_ACTIVATED, false);
}
return parent;
}
swayc_t *remove_child(swayc_t *child) {
int i;
swayc_t *parent = child->parent;
if (child->is_floating) {
// Special case for floating views
for (i = 0; i < parent->floating->length; ++i) {
if (parent->floating->items[i] == child) {
list_del(parent->floating, i);
break;
}
}
i = 0;
} else {
for (i = 0; i < parent->children->length; ++i) {
if (parent->children->items[i] == child) {
list_del(parent->children, i);
break;
}
}
}
// Set focused to new container
if (parent->focused == child) {
if (parent->children->length > 0) {
parent->focused = parent->children->items[i ? i-1:0];
} else if (parent->floating && parent->floating->length) {
parent->focused = parent->floating->items[parent->floating->length - 1];
} else {
parent->focused = NULL;
}
}
// deactivate view
if (child->type == C_VIEW) {
wlc_view_set_state(child->handle, WLC_BIT_ACTIVATED, false);
}
return parent;
}
@ -131,46 +174,9 @@ void swap_container(swayc_t *a, swayc_t *b) {
b->height = h;
}
swayc_t *remove_child(swayc_t *child) {
int i;
swayc_t *parent = child->parent;
if (child->is_floating) {
// Special case for floating views
for (i = 0; i < parent->floating->length; ++i) {
if (parent->floating->items[i] == child) {
list_del(parent->floating, i);
break;
}
}
i = 0;
} else {
for (i = 0; i < parent->children->length; ++i) {
if (parent->children->items[i] == child) {
list_del(parent->children, i);
break;
}
}
}
// Set focused to new container
if (parent->focused == child) {
if (parent->children->length > 0) {
parent->focused = parent->children->items[i ? i-1:0];
} else if (parent->floating && parent->floating->length) {
parent->focused = parent->floating->items[parent->floating->length - 1];
} else {
parent->focused = NULL;
}
}
// deactivate view
if (child->type == C_VIEW) {
wlc_view_set_state(child->handle, WLC_BIT_ACTIVATED, false);
}
return parent;
}
//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;