diff options
-rw-r--r-- | include/layout.h | 21 | ||||
-rw-r--r-- | sway/container.c | 2 | ||||
-rw-r--r-- | sway/layout.c | 104 |
3 files changed, 76 insertions, 51 deletions
diff --git a/include/layout.h b/include/layout.h index 8cc26ba8..2d2a1113 100644 --- a/include/layout.h +++ b/include/layout.h | |||
@@ -11,14 +11,33 @@ extern swayc_t root_container; | |||
11 | extern int min_sane_w; | 11 | extern int min_sane_w; |
12 | extern int min_sane_h; | 12 | extern int min_sane_h; |
13 | 13 | ||
14 | // Set initial values for root_container | ||
14 | void init_layout(void); | 15 | void init_layout(void); |
15 | 16 | ||
17 | // Returns the index of child for its parent | ||
18 | int index_child(const swayc_t *child); | ||
19 | |||
20 | // Adds child to parent, if parent has no focus, it is set to child | ||
21 | // parent must be of type C_WORKSPACE or C_CONTAINER | ||
16 | void add_child(swayc_t *parent, swayc_t *child); | 22 | void add_child(swayc_t *parent, swayc_t *child); |
23 | |||
24 | // Adds child as floating window to ws, if there is no focus it is set to child. | ||
25 | // ws must be of type C_WORKSPACE | ||
17 | void add_floating(swayc_t *ws, swayc_t *child); | 26 | void add_floating(swayc_t *ws, swayc_t *child); |
18 | // Returns parent container which needs to be rearranged. | 27 | |
28 | // insert child after sibling in parents children. | ||
19 | swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); | 29 | swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); |
30 | |||
31 | // Replace child with new_child in parents children | ||
32 | // new_child will inherit childs geometry, childs geometry will be reset | ||
33 | // if parents focus is on child, it will be changed to new_child | ||
20 | swayc_t *replace_child(swayc_t *child, swayc_t *new_child); | 34 | swayc_t *replace_child(swayc_t *child, swayc_t *new_child); |
35 | |||
36 | // Remove child from its parent, if focus is on child, focus will be changed to | ||
37 | // a sibling, or to a floating window, or NULL | ||
21 | swayc_t *remove_child(swayc_t *child); | 38 | swayc_t *remove_child(swayc_t *child); |
39 | |||
40 | // 2 containers are swapped, they inherit eachothers geometry and focus | ||
22 | void swap_container(swayc_t *a, swayc_t *b); | 41 | void swap_container(swayc_t *a, swayc_t *b); |
23 | 42 | ||
24 | void move_container(swayc_t* container,swayc_t* root,enum movement_direction direction); | 43 | void move_container(swayc_t* container,swayc_t* root,enum movement_direction direction); |
diff --git a/sway/container.c b/sway/container.c index 8dc2c825..5321e3cd 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -86,7 +86,7 @@ swayc_t *new_output(wlc_handle handle) { | |||
86 | } | 86 | } |
87 | output->handle = handle; | 87 | output->handle = handle; |
88 | output->name = name ? strdup(name) : NULL; | 88 | output->name = name ? strdup(name) : NULL; |
89 | output->gaps = config->gaps_outer + config->gaps_inner / 2; | 89 | output->gaps = config->gaps_outer; |
90 | 90 | ||
91 | // Find position for it | 91 | // Find position for it |
92 | if (oc && oc->x != -1 && oc->y != -1) { | 92 | if (oc && oc->x != -1 && oc->y != -1) { |
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 | ||
12 | swayc_t root_container; | 12 | swayc_t root_container; |
13 | |||
13 | int min_sane_h = 60; | 14 | int min_sane_h = 60; |
14 | int min_sane_w = 100; | 15 | int 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 | ||
23 | static int index_child(swayc_t *child) { | 24 | int 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) { | |||
59 | swayc_t *add_sibling(swayc_t *sibling, swayc_t *child) { | 63 | swayc_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 | ||
97 | void 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 | ||
134 | swayc_t *remove_child(swayc_t *child) { | 103 | swayc_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 | ||
140 | void 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. |
173 | void move_container(swayc_t *container,swayc_t* root,enum movement_direction direction){ | 179 | void 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; |