summaryrefslogtreecommitdiffstats
path: root/sway/layout.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/layout.c')
-rw-r--r--sway/layout.c104
1 files changed, 55 insertions, 49 deletions
diff --git a/sway/layout.c b/sway/layout.c
index c33291b2..72d3de77 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -10,6 +10,7 @@
10#include "focus.h" 10#include "focus.h"
11 11
12swayc_t root_container; 12swayc_t root_container;
13
13int min_sane_h = 60; 14int min_sane_h = 60;
14int min_sane_w = 100; 15int min_sane_w = 100;
15 16
@@ -20,14 +21,17 @@ void init_layout(void) {
20 root_container.handle = -1; 21 root_container.handle = -1;
21} 22}
22 23
23static int index_child(swayc_t *child) { 24int index_child(const swayc_t *child) {
24 swayc_t *parent = child->parent; 25 swayc_t *parent = child->parent;
25 int i; 26 int i, len = parent->children->length;
26 for (i = 0; i < parent->children->length; ++i) { 27 for (i = 0; i < len; ++i) {
27 if (parent->children->items[i] == child) { 28 if (parent->children->items[i] == child) {
28 break; 29 break;
29 } 30 }
30 } 31 }
32 if (!sway_assert(i < len, "Stray container")) {
33 return -1;
34 }
31 return i; 35 return i;
32} 36}
33 37
@@ -37,7 +41,7 @@ void add_child(swayc_t *parent, swayc_t *child) {
37 list_add(parent->children, child); 41 list_add(parent->children, child);
38 child->parent = parent; 42 child->parent = parent;
39 // set focus for this container 43 // set focus for this container
40 if (parent->children->length == 1) { 44 if (!parent->focused) {
41 parent->focused = child; 45 parent->focused = child;
42 } 46 }
43} 47}
@@ -59,9 +63,6 @@ void add_floating(swayc_t *ws, swayc_t *child) {
59swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) { 63swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) {
60 swayc_t *parent = sibling->parent; 64 swayc_t *parent = sibling->parent;
61 int i = index_child(sibling); 65 int i = index_child(sibling);
62 if (i == parent->children->length) {
63 --i;
64 }
65 list_insert(parent->children, i+1, child); 66 list_insert(parent->children, i+1, child);
66 child->parent = parent; 67 child->parent = parent;
67 return child->parent; 68 return child->parent;
@@ -74,61 +75,29 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) {
74 } 75 }
75 int i = index_child(child); 76 int i = index_child(child);
76 parent->children->items[i] = new_child; 77 parent->children->items[i] = new_child;
77 new_child->parent = child->parent;
78 78
79 // Set parent for new child 79 // Set parent and focus for new_child
80 new_child->parent = child->parent;
80 if (child->parent->focused == child) { 81 if (child->parent->focused == child) {
81 child->parent->focused = new_child; 82 child->parent->focused = new_child;
82 } 83 }
83 child->parent = NULL; 84 child->parent = NULL;
85
84 // Set geometry for new child 86 // Set geometry for new child
85 new_child->x = child->x; 87 new_child->x = child->x;
86 new_child->y = child->y; 88 new_child->y = child->y;
87 new_child->width = child->width; 89 new_child->width = child->width;
88 new_child->height = child->height; 90 new_child->height = child->height;
89 // set child geometry to 0 91
90 child->x = 0; 92 // reset geometry for child
91 child->y = 0;
92 child->width = 0; 93 child->width = 0;
93 child->height = 0; 94 child->height = 0;
94 return parent;
95}
96 95
97void swap_container(swayc_t *a, swayc_t *b) { 96 // deactivate child
98 //TODO doesnt handle floating <-> tiling swap 97 if (child->type == C_VIEW) {
99 if (!sway_assert(a&&b, "parameters must be non null") || 98 wlc_view_set_state(child->handle, WLC_BIT_ACTIVATED, false);
100 !sway_assert(a->parent && b->parent, "containers must have parents")) {
101 return;
102 }
103 size_t a_index = index_child(a);
104 size_t b_index = index_child(b);
105 swayc_t *a_parent = a->parent;
106 swayc_t *b_parent = b->parent;
107 // Swap the pointers
108 a_parent->children->items[a_index] = b;
109 b_parent->children->items[b_index] = a;
110 a->parent = b_parent;
111 b->parent = a_parent;
112 if (a_parent->focused == a) {
113 a_parent->focused = b;
114 }
115 // dont want to double switch
116 if (b_parent->focused == b && a_parent != b_parent) {
117 b_parent->focused = a;
118 } 99 }
119 // and their geometry 100 return parent;
120 double x = a->x;
121 double y = a->y;
122 double w = a->width;
123 double h = a->height;
124 a->x = b->x;
125 a->y = b->y;
126 a->width = b->width;
127 a->height = b->height;
128 b->x = x;
129 b->y = y;
130 b->width = w;
131 b->height = h;
132} 101}
133 102
134swayc_t *remove_child(swayc_t *child) { 103swayc_t *remove_child(swayc_t *child) {
@@ -168,9 +137,46 @@ swayc_t *remove_child(swayc_t *child) {
168 return parent; 137 return parent;
169} 138}
170 139
140void swap_container(swayc_t *a, swayc_t *b) {
141 //TODO doesnt handle floating <-> tiling swap
142 if (!sway_assert(a&&b, "parameters must be non null") ||
143 !sway_assert(a->parent && b->parent, "containers must have parents")) {
144 return;
145 }
146 size_t a_index = index_child(a);
147 size_t b_index = index_child(b);
148 swayc_t *a_parent = a->parent;
149 swayc_t *b_parent = b->parent;
150 // Swap the pointers
151 a_parent->children->items[a_index] = b;
152 b_parent->children->items[b_index] = a;
153 a->parent = b_parent;
154 b->parent = a_parent;
155 if (a_parent->focused == a) {
156 a_parent->focused = b;
157 }
158 // dont want to double switch
159 if (b_parent->focused == b && a_parent != b_parent) {
160 b_parent->focused = a;
161 }
162 // and their geometry
163 double x = a->x;
164 double y = a->y;
165 double w = a->width;
166 double h = a->height;
167 a->x = b->x;
168 a->y = b->y;
169 a->width = b->width;
170 a->height = b->height;
171 b->x = x;
172 b->y = y;
173 b->width = w;
174 b->height = h;
175}
176
171//TODO: Implement horizontal movement. 177//TODO: Implement horizontal movement.
172//TODO: Implement move to a different workspace. 178//TODO: Implement move to a different workspace.
173void move_container(swayc_t *container,swayc_t* root,enum movement_direction direction){ 179void move_container(swayc_t *container,swayc_t* root,enum movement_direction direction) {
174 sway_log(L_DEBUG, "Moved window"); 180 sway_log(L_DEBUG, "Moved window");
175 swayc_t *temp; 181 swayc_t *temp;
176 int i; 182 int i;