mirror of
https://github.com/swaywm/sway.git
synced 2024-11-16 13:13:17 +00:00
move_container_to fixup
This commit is contained in:
parent
c4257055eb
commit
1fa7a91bfb
|
@ -101,6 +101,7 @@ swayc_t *swayc_active_workspace_for(swayc_t *view);
|
||||||
// Container information
|
// Container information
|
||||||
|
|
||||||
bool swayc_is_fullscreen(swayc_t *view);
|
bool swayc_is_fullscreen(swayc_t *view);
|
||||||
|
bool swayc_is_active(swayc_t *view);
|
||||||
|
|
||||||
// Mapping functions
|
// 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 set_view_visibility(swayc_t *view, void *data);
|
||||||
void reset_gaps(swayc_t *view, void *data);
|
void reset_gaps(swayc_t *view, void *data);
|
||||||
|
|
||||||
|
|
||||||
void update_visibility(swayc_t *container);
|
void update_visibility(swayc_t *container);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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(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_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3)));
|
||||||
void sway_abort(const char* format, ...) __attribute__((format(printf,1,2)));
|
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 error_handler(int sig);
|
||||||
|
|
||||||
void layout_log(const swayc_t *c, int depth);
|
void layout_log(const swayc_t *c, int depth);
|
||||||
|
|
|
@ -380,7 +380,7 @@ static bool cmd_move(struct sway_config *config, int argc, char **argv) {
|
||||||
if (ws == NULL) {
|
if (ws == NULL) {
|
||||||
ws = workspace_create(ws_name);
|
ws = workspace_create(ws_name);
|
||||||
}
|
}
|
||||||
move_container_to(view, ws);
|
move_container_to(view, get_focused_container(ws));
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#define ASSERT_NONNULL(PTR) \
|
#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) {
|
static swayc_t *new_swayc(enum swayc_types type) {
|
||||||
swayc_t *c = calloc(1, sizeof(swayc_t));
|
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
|
// Do not destroy if there are children
|
||||||
if (workspace->children->length == 0 && workspace->floating->length == 0) {
|
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;
|
swayc_t *parent = workspace->parent;
|
||||||
free_swayc(workspace);
|
free_swayc(workspace);
|
||||||
return parent;
|
return parent;
|
||||||
|
@ -376,7 +376,7 @@ swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) {
|
||||||
if (!ASSERT_NONNULL(container)) {
|
if (!ASSERT_NONNULL(container)) {
|
||||||
return NULL;
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
|
@ -389,7 +389,7 @@ swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts layout) {
|
||||||
if (!ASSERT_NONNULL(container)) {
|
if (!ASSERT_NONNULL(container)) {
|
||||||
return NULL;
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
|
@ -402,7 +402,7 @@ swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types type) {
|
||||||
if (!ASSERT_NONNULL(container)) {
|
if (!ASSERT_NONNULL(container)) {
|
||||||
return NULL;
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
|
@ -410,11 +410,12 @@ swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types type) {
|
||||||
} while (container && container->type != type);
|
} while (container && container->type != type);
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts layout) {
|
swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts layout) {
|
||||||
if (!ASSERT_NONNULL(container)) {
|
if (!ASSERT_NONNULL(container)) {
|
||||||
return NULL;
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
do {
|
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);
|
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
|
// Mapping
|
||||||
|
|
||||||
void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) {
|
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) {
|
void update_visibility(swayc_t *container) {
|
||||||
swayc_t *ws = swayc_active_workspace_for(container);
|
swayc_t *ws = swayc_active_workspace_for(container);
|
||||||
|
// TODO better visibility setting
|
||||||
bool visible = (ws->parent->focused == ws);
|
bool visible = (ws->parent->focused == ws);
|
||||||
sway_log(L_DEBUG, "Setting visibility of container %p to %s", container, visible ? "visible" : "invisible");
|
sway_log(L_DEBUG, "Setting visibility of container %p to %s", container, visible ? "visible" : "invisible");
|
||||||
container_map(ws, set_view_visibility, &visible);
|
container_map(ws, set_view_visibility, &visible);
|
||||||
|
|
|
@ -45,6 +45,9 @@ void add_child(swayc_t *parent, swayc_t *child) {
|
||||||
void add_floating(swayc_t *ws, 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,
|
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);
|
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);
|
list_add(ws->floating, child);
|
||||||
child->parent = ws;
|
child->parent = ws;
|
||||||
child->is_floating = true;
|
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) {
|
void swap_container(swayc_t *a, swayc_t *b) {
|
||||||
//TODO doesnt handle floating <-> tiling swap
|
//TODO doesnt handle floating <-> tiling swap
|
||||||
if (!sway_assert(a&&b, "%s: parameters must be non null",__func__) ||
|
if (!sway_assert(a&&b, "parameters must be non null") ||
|
||||||
!sway_assert(a->parent && b->parent, "%s: containers must have parents",__func__)) {
|
!sway_assert(a->parent && b->parent, "containers must have parents")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size_t a_index = index_child(a);
|
size_t a_index = index_child(a);
|
||||||
|
@ -158,6 +161,10 @@ swayc_t *remove_child(swayc_t *child) {
|
||||||
parent->focused = NULL;
|
parent->focused = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// deactivate view
|
||||||
|
if (child->type == C_VIEW) {
|
||||||
|
wlc_view_set_state(child->handle, WLC_BIT_ACTIVATED, false);
|
||||||
|
}
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,15 +216,24 @@ void move_container_to(swayc_t* container, swayc_t* destination) {
|
||||||
if (container->parent == destination) {
|
if (container->parent == destination) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
destroy_container(remove_child(container));
|
swayc_t *parent = remove_child(container);
|
||||||
set_focused_container(get_focused_view(&root_container));
|
// reset container geometry
|
||||||
|
container->width = container->height = 0;
|
||||||
|
|
||||||
|
// Send to new destination
|
||||||
if (container->is_floating) {
|
if (container->is_floating) {
|
||||||
add_floating(destination, container);
|
add_floating(swayc_active_workspace_for(destination), container);
|
||||||
} else {
|
} else if (destination->type == C_WORKSPACE) {
|
||||||
add_child(destination, container);
|
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);
|
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) {
|
void update_geometry(swayc_t *container) {
|
||||||
|
|
|
@ -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) {
|
if (condition) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ int main(int argc, char **argv) {
|
||||||
{"version", no_argument, NULL, 'v'},
|
{"version", no_argument, NULL, 'v'},
|
||||||
{"verbose", no_argument, &verbose, 1},
|
{"verbose", no_argument, &verbose, 1},
|
||||||
{"get-socketpath", no_argument, NULL, 'p'},
|
{"get-socketpath", no_argument, NULL, 'p'},
|
||||||
{0,0,0,0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Signal handling */
|
/* Signal handling */
|
||||||
|
@ -127,7 +127,7 @@ int main(int argc, char **argv) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sigchld_handle(int signal) {
|
void sigchld_handle(int signal) {
|
||||||
(void) signal;
|
(void) signal;
|
||||||
while (waitpid((pid_t)-1, 0, WNOHANG) > 0);
|
while (waitpid((pid_t)-1, 0, WNOHANG) > 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue