aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2015-08-26 14:07:17 -0400
committerDrew DeVault <sir@cmpwn.com>2015-08-26 14:07:17 -0400
commit1e54490b71a7ccacb0d25dd1e2792125b9d71c06 (patch)
tree067204ac10ae5f727c9bed71de9ad007aa80e023
parentc4257055ebb74987b62833c0529ecfb9f9a1c47c (diff)
parent1fa7a91bfb4ccbd42a535787f3bb208913b4a7e9 (diff)
Merge pull request #136 from taiyu-len/master
move_container_to fixup
-rw-r--r--include/container.h2
-rw-r--r--include/log.h6
-rw-r--r--sway/commands.c2
-rw-r--r--sway/container.c18
-rw-r--r--sway/layout.c30
-rw-r--r--sway/log.c2
-rw-r--r--sway/main.c4
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);
// Container information
bool swayc_is_fullscreen(swayc_t *view);
+bool swayc_is_active(swayc_t *view);
// Mapping functions
@@ -110,7 +111,6 @@ void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *);
void set_view_visibility(swayc_t *view, void *data);
void reset_gaps(swayc_t *view, void *data);
-
void update_visibility(swayc_t *container);
#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);
void sway_log(log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,2,3)));
void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3)));
void sway_abort(const char* format, ...) __attribute__((format(printf,1,2)));
-bool sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3)));
+
+bool _sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3)));
+#define sway_assert(COND, FMT, ...) \
+ _sway_assert(COND, "%s:" FMT, __PRETTY_FUNCTION__, ##__VA_ARGS__)
+
void error_handler(int sig);
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) {
if (ws == NULL) {
ws = workspace_create(ws_name);
}
- move_container_to(view, ws);
+ move_container_to(view, get_focused_container(ws));
} else {
return false;
}
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 @@
#include "log.h"
#define ASSERT_NONNULL(PTR) \
- sway_assert (PTR, "%s: " #PTR "must be non-null", __func__)
+ sway_assert (PTR, #PTR "must be non-null")
static swayc_t *new_swayc(enum swayc_types type) {
swayc_t *c = calloc(1, sizeof(swayc_t));
@@ -305,7 +305,7 @@ swayc_t *destroy_workspace(swayc_t *workspace) {
// Do not destroy if there are children
if (workspace->children->length == 0 && workspace->floating->length == 0) {
- sway_log(L_DEBUG, "%s: '%s'", __func__, workspace->name);
+ sway_log(L_DEBUG, "'%s'", workspace->name);
swayc_t *parent = workspace->parent;
free_swayc(workspace);
return parent;
@@ -376,7 +376,7 @@ swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) {
if (!ASSERT_NONNULL(container)) {
return NULL;
}
- if (!sway_assert(type < C_TYPES && type >= C_ROOT, "%s: invalid type", __func__)) {
+ if (!sway_assert(type < C_TYPES && type >= C_ROOT, "invalid type")) {
return NULL;
}
do {
@@ -389,7 +389,7 @@ swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts layout) {
if (!ASSERT_NONNULL(container)) {
return NULL;
}
- if (!sway_assert(layout < L_LAYOUTS && layout >= L_NONE, "%s: invalid layout", __func__)) {
+ if (!sway_assert(layout < L_LAYOUTS && layout >= L_NONE, "invalid layout")) {
return NULL;
}
do {
@@ -402,7 +402,7 @@ swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types type) {
if (!ASSERT_NONNULL(container)) {
return NULL;
}
- if (!sway_assert(type < C_TYPES && type >= C_ROOT, "%s: invalid type", __func__)) {
+ if (!sway_assert(type < C_TYPES && type >= C_ROOT, "invalid type")) {
return NULL;
}
do {
@@ -410,11 +410,12 @@ swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types type) {
} while (container && container->type != type);
return container;
}
+
swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts layout) {
if (!ASSERT_NONNULL(container)) {
return NULL;
}
- if (!sway_assert(layout < L_LAYOUTS && layout >= L_NONE, "%s: invalid layout", __func__)) {
+ if (!sway_assert(layout < L_LAYOUTS && layout >= L_NONE, "invalid layout")) {
return NULL;
}
do {
@@ -494,6 +495,10 @@ bool swayc_is_fullscreen(swayc_t *view) {
return view && view->type == C_VIEW && (wlc_view_get_state(view->handle) & WLC_BIT_FULLSCREEN);
}
+bool swayc_is_active(swayc_t *view) {
+ return view && view->type == C_VIEW && (wlc_view_get_state(view->handle) & WLC_BIT_ACTIVATED);
+}
+
// Mapping
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) {
void update_visibility(swayc_t *container) {
swayc_t *ws = swayc_active_workspace_for(container);
+ // TODO better visibility setting
bool visible = (ws->parent->focused == ws);
sway_log(L_DEBUG, "Setting visibility of container %p to %s", container, visible ? "visible" : "invisible");
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) {
void add_floating(swayc_t *ws, swayc_t *child) {
sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type,
child->width, child->height, ws, ws->type, ws->width, ws->height);
+ if (!sway_assert(ws->type == C_WORKSPACE, "Must be of workspace type")) {
+ return;
+ }
list_add(ws->floating, child);
child->parent = ws;
child->is_floating = true;
@@ -93,8 +96,8 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) {
void swap_container(swayc_t *a, swayc_t *b) {
//TODO doesnt handle floating <-> tiling swap
- if (!sway_assert(a&&b, "%s: parameters must be non null",__func__) ||
- !sway_assert(a->parent && b->parent, "%s: containers must have parents",__func__)) {
+ 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);
@@ -158,6 +161,10 @@ swayc_t *remove_child(swayc_t *child) {
parent->focused = NULL;
}
}
+ // deactivate view
+ if (child->type == C_VIEW) {
+ wlc_view_set_state(child->handle, WLC_BIT_ACTIVATED, false);
+ }
return parent;
}
@@ -209,15 +216,24 @@ void move_container_to(swayc_t* container, swayc_t* destination) {
if (container->parent == destination) {
return;
}
- destroy_container(remove_child(container));
- set_focused_container(get_focused_view(&root_container));
+ swayc_t *parent = remove_child(container);
+ // reset container geometry
+ container->width = container->height = 0;
+
+ // Send to new destination
if (container->is_floating) {
- add_floating(destination, container);
- } else {
+ add_floating(swayc_active_workspace_for(destination), container);
+ } else if (destination->type == C_WORKSPACE) {
add_child(destination, container);
+ } else {
+ add_sibling(destination, container);
}
+ // Destroy old container if we need to
+ parent = destroy_container(parent);
+ set_focused_container(get_focused_view(&root_container));
update_visibility(container);
- arrange_windows(&root_container, -1, -1);
+ arrange_windows(parent, -1, -1);
+ arrange_windows(destination->parent, -1, -1);
}
void update_geometry(swayc_t *container) {
diff --git a/sway/log.c b/sway/log.c
index bea30837..66898a28 100644
--- a/sway/log.c
+++ b/sway/log.c
@@ -100,7 +100,7 @@ void sway_log_errno(log_importance_t verbosity, char* format, ...) {
}
}
-bool sway_assert(bool condition, const char* format, ...) {
+bool _sway_assert(bool condition, const char* format, ...) {
if (condition) {
return true;
}
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) {
{"version", no_argument, NULL, 'v'},
{"verbose", no_argument, &verbose, 1},
{"get-socketpath", no_argument, NULL, 'p'},
- {0,0,0,0}
+ {0, 0, 0, 0}
};
/* Signal handling */
@@ -127,7 +127,7 @@ int main(int argc, char **argv) {
return 0;
}
-static void sigchld_handle(int signal) {
+void sigchld_handle(int signal) {
(void) signal;
while (waitpid((pid_t)-1, 0, WNOHANG) > 0);
}