diff options
author | taiyu <taiyu.len@gmail.com> | 2015-08-26 11:01:26 -0700 |
---|---|---|
committer | taiyu <taiyu.len@gmail.com> | 2015-08-26 11:01:26 -0700 |
commit | 1fa7a91bfb4ccbd42a535787f3bb208913b4a7e9 (patch) | |
tree | 067204ac10ae5f727c9bed71de9ad007aa80e023 | |
parent | Merge pull request #135 from Luminarys/master (diff) | |
download | sway-1fa7a91bfb4ccbd42a535787f3bb208913b4a7e9.tar.gz sway-1fa7a91bfb4ccbd42a535787f3bb208913b4a7e9.tar.zst sway-1fa7a91bfb4ccbd42a535787f3bb208913b4a7e9.zip |
move_container_to fixup
-rw-r--r-- | include/container.h | 2 | ||||
-rw-r--r-- | include/log.h | 6 | ||||
-rw-r--r-- | sway/commands.c | 2 | ||||
-rw-r--r-- | sway/container.c | 18 | ||||
-rw-r--r-- | sway/layout.c | 30 | ||||
-rw-r--r-- | sway/log.c | 2 | ||||
-rw-r--r-- | sway/main.c | 4 |
7 files changed, 45 insertions, 19 deletions
diff --git a/include/container.h b/include/container.h index 798a31a2..6c0de104 100644 --- a/include/container.h +++ b/include/container.h | |||
@@ -101,6 +101,7 @@ swayc_t *swayc_active_workspace_for(swayc_t *view); | |||
101 | // Container information | 101 | // Container information |
102 | 102 | ||
103 | bool swayc_is_fullscreen(swayc_t *view); | 103 | bool swayc_is_fullscreen(swayc_t *view); |
104 | bool swayc_is_active(swayc_t *view); | ||
104 | 105 | ||
105 | // Mapping functions | 106 | // Mapping functions |
106 | 107 | ||
@@ -110,7 +111,6 @@ void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); | |||
110 | void set_view_visibility(swayc_t *view, void *data); | 111 | void set_view_visibility(swayc_t *view, void *data); |
111 | void reset_gaps(swayc_t *view, void *data); | 112 | void reset_gaps(swayc_t *view, void *data); |
112 | 113 | ||
113 | |||
114 | void update_visibility(swayc_t *container); | 114 | void update_visibility(swayc_t *container); |
115 | 115 | ||
116 | #endif | 116 | #endif |
diff --git a/include/log.h b/include/log.h index 945ad239..f8deaf26 100644 --- a/include/log.h +++ b/include/log.h | |||
@@ -15,7 +15,11 @@ void sway_log_colors(int mode); | |||
15 | void sway_log(log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,2,3))); | 15 | void sway_log(log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,2,3))); |
16 | void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3))); | 16 | void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3))); |
17 | void sway_abort(const char* format, ...) __attribute__((format(printf,1,2))); | 17 | void sway_abort(const char* format, ...) __attribute__((format(printf,1,2))); |
18 | bool sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3))); | 18 | |
19 | bool _sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3))); | ||
20 | #define sway_assert(COND, FMT, ...) \ | ||
21 | _sway_assert(COND, "%s:" FMT, __PRETTY_FUNCTION__, ##__VA_ARGS__) | ||
22 | |||
19 | void error_handler(int sig); | 23 | void error_handler(int sig); |
20 | 24 | ||
21 | void layout_log(const swayc_t *c, int depth); | 25 | void layout_log(const swayc_t *c, int depth); |
diff --git a/sway/commands.c b/sway/commands.c index 74c19b5b..2bdfeff6 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -380,7 +380,7 @@ static bool cmd_move(struct sway_config *config, int argc, char **argv) { | |||
380 | if (ws == NULL) { | 380 | if (ws == NULL) { |
381 | ws = workspace_create(ws_name); | 381 | ws = workspace_create(ws_name); |
382 | } | 382 | } |
383 | move_container_to(view, ws); | 383 | move_container_to(view, get_focused_container(ws)); |
384 | } else { | 384 | } else { |
385 | return false; | 385 | return false; |
386 | } | 386 | } |
diff --git a/sway/container.c b/sway/container.c index cd7c9b13..8dc2c825 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -9,7 +9,7 @@ | |||
9 | #include "log.h" | 9 | #include "log.h" |
10 | 10 | ||
11 | #define ASSERT_NONNULL(PTR) \ | 11 | #define ASSERT_NONNULL(PTR) \ |
12 | sway_assert (PTR, "%s: " #PTR "must be non-null", __func__) | 12 | sway_assert (PTR, #PTR "must be non-null") |
13 | 13 | ||
14 | static swayc_t *new_swayc(enum swayc_types type) { | 14 | static swayc_t *new_swayc(enum swayc_types type) { |
15 | swayc_t *c = calloc(1, sizeof(swayc_t)); | 15 | swayc_t *c = calloc(1, sizeof(swayc_t)); |
@@ -305,7 +305,7 @@ swayc_t *destroy_workspace(swayc_t *workspace) { | |||
305 | 305 | ||
306 | // Do not destroy if there are children | 306 | // Do not destroy if there are children |
307 | if (workspace->children->length == 0 && workspace->floating->length == 0) { | 307 | if (workspace->children->length == 0 && workspace->floating->length == 0) { |
308 | sway_log(L_DEBUG, "%s: '%s'", __func__, workspace->name); | 308 | sway_log(L_DEBUG, "'%s'", workspace->name); |
309 | swayc_t *parent = workspace->parent; | 309 | swayc_t *parent = workspace->parent; |
310 | free_swayc(workspace); | 310 | free_swayc(workspace); |
311 | return parent; | 311 | return parent; |
@@ -376,7 +376,7 @@ swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { | |||
376 | if (!ASSERT_NONNULL(container)) { | 376 | if (!ASSERT_NONNULL(container)) { |
377 | return NULL; | 377 | return NULL; |
378 | } | 378 | } |
379 | if (!sway_assert(type < C_TYPES && type >= C_ROOT, "%s: invalid type", __func__)) { | 379 | if (!sway_assert(type < C_TYPES && type >= C_ROOT, "invalid type")) { |
380 | return NULL; | 380 | return NULL; |
381 | } | 381 | } |
382 | do { | 382 | do { |
@@ -389,7 +389,7 @@ swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts layout) { | |||
389 | if (!ASSERT_NONNULL(container)) { | 389 | if (!ASSERT_NONNULL(container)) { |
390 | return NULL; | 390 | return NULL; |
391 | } | 391 | } |
392 | if (!sway_assert(layout < L_LAYOUTS && layout >= L_NONE, "%s: invalid layout", __func__)) { | 392 | if (!sway_assert(layout < L_LAYOUTS && layout >= L_NONE, "invalid layout")) { |
393 | return NULL; | 393 | return NULL; |
394 | } | 394 | } |
395 | do { | 395 | do { |
@@ -402,7 +402,7 @@ swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types type) { | |||
402 | if (!ASSERT_NONNULL(container)) { | 402 | if (!ASSERT_NONNULL(container)) { |
403 | return NULL; | 403 | return NULL; |
404 | } | 404 | } |
405 | if (!sway_assert(type < C_TYPES && type >= C_ROOT, "%s: invalid type", __func__)) { | 405 | if (!sway_assert(type < C_TYPES && type >= C_ROOT, "invalid type")) { |
406 | return NULL; | 406 | return NULL; |
407 | } | 407 | } |
408 | do { | 408 | do { |
@@ -410,11 +410,12 @@ swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types type) { | |||
410 | } while (container && container->type != type); | 410 | } while (container && container->type != type); |
411 | return container; | 411 | return container; |
412 | } | 412 | } |
413 | |||
413 | swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts layout) { | 414 | swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts layout) { |
414 | if (!ASSERT_NONNULL(container)) { | 415 | if (!ASSERT_NONNULL(container)) { |
415 | return NULL; | 416 | return NULL; |
416 | } | 417 | } |
417 | if (!sway_assert(layout < L_LAYOUTS && layout >= L_NONE, "%s: invalid layout", __func__)) { | 418 | if (!sway_assert(layout < L_LAYOUTS && layout >= L_NONE, "invalid layout")) { |
418 | return NULL; | 419 | return NULL; |
419 | } | 420 | } |
420 | do { | 421 | do { |
@@ -494,6 +495,10 @@ bool swayc_is_fullscreen(swayc_t *view) { | |||
494 | return view && view->type == C_VIEW && (wlc_view_get_state(view->handle) & WLC_BIT_FULLSCREEN); | 495 | return view && view->type == C_VIEW && (wlc_view_get_state(view->handle) & WLC_BIT_FULLSCREEN); |
495 | } | 496 | } |
496 | 497 | ||
498 | bool swayc_is_active(swayc_t *view) { | ||
499 | return view && view->type == C_VIEW && (wlc_view_get_state(view->handle) & WLC_BIT_ACTIVATED); | ||
500 | } | ||
501 | |||
497 | // Mapping | 502 | // Mapping |
498 | 503 | ||
499 | void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { | 504 | void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { |
@@ -536,6 +541,7 @@ void set_view_visibility(swayc_t *view, void *data) { | |||
536 | 541 | ||
537 | void update_visibility(swayc_t *container) { | 542 | void update_visibility(swayc_t *container) { |
538 | swayc_t *ws = swayc_active_workspace_for(container); | 543 | swayc_t *ws = swayc_active_workspace_for(container); |
544 | // TODO better visibility setting | ||
539 | bool visible = (ws->parent->focused == ws); | 545 | bool visible = (ws->parent->focused == ws); |
540 | sway_log(L_DEBUG, "Setting visibility of container %p to %s", container, visible ? "visible" : "invisible"); | 546 | sway_log(L_DEBUG, "Setting visibility of container %p to %s", container, visible ? "visible" : "invisible"); |
541 | container_map(ws, set_view_visibility, &visible); | 547 | container_map(ws, set_view_visibility, &visible); |
diff --git a/sway/layout.c b/sway/layout.c index ed9479ab..c33291b2 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -45,6 +45,9 @@ void add_child(swayc_t *parent, swayc_t *child) { | |||
45 | void add_floating(swayc_t *ws, swayc_t *child) { | 45 | void add_floating(swayc_t *ws, swayc_t *child) { |
46 | sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type, | 46 | sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type, |
47 | child->width, child->height, ws, ws->type, ws->width, ws->height); | 47 | child->width, child->height, ws, ws->type, ws->width, ws->height); |
48 | if (!sway_assert(ws->type == C_WORKSPACE, "Must be of workspace type")) { | ||
49 | return; | ||
50 | } | ||
48 | list_add(ws->floating, child); | 51 | list_add(ws->floating, child); |
49 | child->parent = ws; | 52 | child->parent = ws; |
50 | child->is_floating = true; | 53 | child->is_floating = true; |
@@ -93,8 +96,8 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) { | |||
93 | 96 | ||
94 | void swap_container(swayc_t *a, swayc_t *b) { | 97 | void swap_container(swayc_t *a, swayc_t *b) { |
95 | //TODO doesnt handle floating <-> tiling swap | 98 | //TODO doesnt handle floating <-> tiling swap |
96 | if (!sway_assert(a&&b, "%s: parameters must be non null",__func__) || | 99 | if (!sway_assert(a&&b, "parameters must be non null") || |
97 | !sway_assert(a->parent && b->parent, "%s: containers must have parents",__func__)) { | 100 | !sway_assert(a->parent && b->parent, "containers must have parents")) { |
98 | return; | 101 | return; |
99 | } | 102 | } |
100 | size_t a_index = index_child(a); | 103 | size_t a_index = index_child(a); |
@@ -158,6 +161,10 @@ swayc_t *remove_child(swayc_t *child) { | |||
158 | parent->focused = NULL; | 161 | parent->focused = NULL; |
159 | } | 162 | } |
160 | } | 163 | } |
164 | // deactivate view | ||
165 | if (child->type == C_VIEW) { | ||
166 | wlc_view_set_state(child->handle, WLC_BIT_ACTIVATED, false); | ||
167 | } | ||
161 | return parent; | 168 | return parent; |
162 | } | 169 | } |
163 | 170 | ||
@@ -209,15 +216,24 @@ void move_container_to(swayc_t* container, swayc_t* destination) { | |||
209 | if (container->parent == destination) { | 216 | if (container->parent == destination) { |
210 | return; | 217 | return; |
211 | } | 218 | } |
212 | destroy_container(remove_child(container)); | 219 | swayc_t *parent = remove_child(container); |
213 | set_focused_container(get_focused_view(&root_container)); | 220 | // reset container geometry |
221 | container->width = container->height = 0; | ||
222 | |||
223 | // Send to new destination | ||
214 | if (container->is_floating) { | 224 | if (container->is_floating) { |
215 | add_floating(destination, container); | 225 | add_floating(swayc_active_workspace_for(destination), container); |
216 | } else { | 226 | } else if (destination->type == C_WORKSPACE) { |
217 | add_child(destination, container); | 227 | add_child(destination, container); |
228 | } else { | ||
229 | add_sibling(destination, container); | ||
218 | } | 230 | } |
231 | // Destroy old container if we need to | ||
232 | parent = destroy_container(parent); | ||
233 | set_focused_container(get_focused_view(&root_container)); | ||
219 | update_visibility(container); | 234 | update_visibility(container); |
220 | arrange_windows(&root_container, -1, -1); | 235 | arrange_windows(parent, -1, -1); |
236 | arrange_windows(destination->parent, -1, -1); | ||
221 | } | 237 | } |
222 | 238 | ||
223 | void update_geometry(swayc_t *container) { | 239 | void update_geometry(swayc_t *container) { |
@@ -100,7 +100,7 @@ void sway_log_errno(log_importance_t verbosity, char* format, ...) { | |||
100 | } | 100 | } |
101 | } | 101 | } |
102 | 102 | ||
103 | bool sway_assert(bool condition, const char* format, ...) { | 103 | bool _sway_assert(bool condition, const char* format, ...) { |
104 | if (condition) { | 104 | if (condition) { |
105 | return true; | 105 | return true; |
106 | } | 106 | } |
diff --git a/sway/main.c b/sway/main.c index 0880cb8c..3591e7ff 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -41,7 +41,7 @@ int main(int argc, char **argv) { | |||
41 | {"version", no_argument, NULL, 'v'}, | 41 | {"version", no_argument, NULL, 'v'}, |
42 | {"verbose", no_argument, &verbose, 1}, | 42 | {"verbose", no_argument, &verbose, 1}, |
43 | {"get-socketpath", no_argument, NULL, 'p'}, | 43 | {"get-socketpath", no_argument, NULL, 'p'}, |
44 | {0,0,0,0} | 44 | {0, 0, 0, 0} |
45 | }; | 45 | }; |
46 | 46 | ||
47 | /* Signal handling */ | 47 | /* Signal handling */ |
@@ -127,7 +127,7 @@ int main(int argc, char **argv) { | |||
127 | return 0; | 127 | return 0; |
128 | } | 128 | } |
129 | 129 | ||
130 | static void sigchld_handle(int signal) { | 130 | void sigchld_handle(int signal) { |
131 | (void) signal; | 131 | (void) signal; |
132 | while (waitpid((pid_t)-1, 0, WNOHANG) > 0); | 132 | while (waitpid((pid_t)-1, 0, WNOHANG) > 0); |
133 | } | 133 | } |