From 60b3b87edd06c3a9aa793074e4295d549ef054ed Mon Sep 17 00:00:00 2001 From: minus Date: Sun, 23 Aug 2015 00:23:51 +0200 Subject: [PATCH] added "move container to workspace", changed scratchpad still WIP, latter is not really working --- include/layout.h | 10 ++++------ sway/commands.c | 42 ++++++++++++++++++++++++++++++------------ sway/container.c | 2 ++ sway/layout.c | 39 +++++++++++++++++++-------------------- 4 files changed, 55 insertions(+), 38 deletions(-) diff --git a/include/layout.h b/include/layout.h index 7d18108cb..23aa98e9c 100644 --- a/include/layout.h +++ b/include/layout.h @@ -11,6 +11,8 @@ extern swayc_t root_container; extern int min_sane_w; extern int min_sane_h; +extern swayc_t *scratchpad; + void init_layout(void); void add_child(swayc_t *parent, swayc_t *child); @@ -20,7 +22,8 @@ swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); swayc_t *replace_child(swayc_t *child, swayc_t *new_child); swayc_t *remove_child(swayc_t *child); -void move_container(swayc_t* container,swayc_t* root,enum movement_direction direction); +void move_container_to_direction(swayc_t* container,swayc_t* root,enum movement_direction direction); +void move_container_to(swayc_t* container, swayc_t* destination); // Layout void arrange_windows(swayc_t *container, double width, double height); @@ -32,9 +35,4 @@ void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge ed void view_set_floating(swayc_t *view, bool floating); -// Scratchpad - -void scratchpad_push(swayc_t *view); -swayc_t *scratchpad_pop(void); - #endif diff --git a/sway/commands.c b/sway/commands.c index 7490c3eb9..f6fdba066 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -312,25 +312,40 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char * } static bool cmd_move(struct sway_config *config, int argc, char **argv) { - if (!checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 1)) { + if (!checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1)) { return false; } swayc_t *view = get_focused_container(&root_container); if (strcasecmp(argv[0], "left") == 0) { - move_container(view, &root_container, MOVE_LEFT); + move_container_to_direction(view, &root_container, MOVE_LEFT); } else if (strcasecmp(argv[0], "right") == 0) { - move_container(view, &root_container, MOVE_RIGHT); + move_container_to_direction(view, &root_container, MOVE_RIGHT); } else if (strcasecmp(argv[0], "up") == 0) { - move_container(view, &root_container, MOVE_UP); + move_container_to_direction(view, &root_container, MOVE_UP); } else if (strcasecmp(argv[0], "down") == 0) { - move_container(view, &root_container, MOVE_DOWN); + move_container_to_direction(view, &root_container, MOVE_DOWN); + } else if (strcasecmp(argv[0], "container") == 0) { + // "move container to workspace x" + if (!checkarg(argc, "move container", EXPECTED_EQUAL_TO, 4) || + strcasecmp(argv[1], "to") != 0 || + strcasecmp(argv[2], "workspace") != 0) { + return false; + } + + if (view->type != C_CONTAINER && view->type != C_VIEW) { + return false; + } + + swayc_t *ws = workspace_by_name(argv[3]); + if (ws == NULL) { + ws = workspace_create(argv[3]); + } + move_container_to(view, ws); } else if (strcasecmp(argv[0], "scratchpad") == 0 && view->type == C_VIEW) { - swayc_t *parent = destroy_container(remove_child(view)); - scratchpad_push(view); - set_focused_container(get_focused_view(parent)); - arrange_windows(parent, -1, -1); + view_set_floating(view, true); + move_container_to(view, scratchpad); } else { return false; } @@ -347,11 +362,14 @@ static bool cmd_scratchpad(struct sway_config *config, int argc, char **argv) { return false; } - swayc_t *view = scratchpad_pop(); - if (view == NULL) { + if (scratchpad->floating->length == 0) { return false; } - view_set_floating(view, true); + + swayc_t *view = scratchpad->floating->items[0]; + sway_log(L_DEBUG, "Popped view %p from scratchpad", view); + remove_child(view); + move_container_to(view, swayc_active_workspace()); return true; } diff --git a/sway/container.c b/sway/container.c index 41d21c3b2..4bd4108c1 100644 --- a/sway/container.c +++ b/sway/container.c @@ -490,8 +490,10 @@ void set_view_visibility(swayc_t *view, void *data) { if (view->type == C_VIEW) { wlc_view_set_mask(view->handle, *p); if (*p == 2) { + sway_log(L_DEBUG, "Showing view %p(%s)", view, view->name); wlc_view_bring_to_front(view->handle); } else { + sway_log(L_DEBUG, "Hiding view %p(%s)", view, view->name); wlc_view_send_to_back(view->handle); } } diff --git a/sway/layout.c b/sway/layout.c index 5b1fa9743..1217866c6 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -15,7 +15,7 @@ int min_sane_h = 60; int min_sane_w = 100; static swayc_t null_output; -static swayc_t *scratchpad = NULL; +swayc_t *scratchpad = NULL; void init_layout(void) { root_container.type = C_ROOT; @@ -128,7 +128,7 @@ swayc_t *remove_child(swayc_t *child) { //TODO: Implement horizontal movement. //TODO: Implement move to a different workspace. -void move_container(swayc_t *container,swayc_t* root,enum movement_direction direction){ +void move_container_to_direction(swayc_t *container,swayc_t* root,enum movement_direction direction){ sway_log(L_DEBUG, "Moved window"); swayc_t *temp; int i; @@ -164,13 +164,29 @@ void move_container(swayc_t *container,swayc_t* root,enum movement_direction dir break; } else if (child->children != NULL){ - move_container(container,child,direction); + move_container_to_direction(container,child,direction); } } } +void move_container_to(swayc_t* container, swayc_t* destination) { + destroy_container(remove_child(container)); + set_focused_container(get_focused_view(&root_container)); + if (container->is_floating) { + add_floating(destination, container); + } else { + add_child(destination, container); + } + // TODO: don't set it invisible here, it could have been + // moved to another visible workspace, or from the scratchpad + uint32_t mask = 2; + set_view_visibility(container, &mask); + arrange_windows(&root_container, -1, -1); +} + + void arrange_windows(swayc_t *container, double width, double height) { int i; if (width == -1 || height == -1) { @@ -479,20 +495,3 @@ void view_set_floating(swayc_t *view, bool floating) { arrange_windows(swayc_active_workspace(), -1, -1); } } - -void scratchpad_push(swayc_t *view) { - add_floating(scratchpad, view); - wlc_view_set_mask(view->handle, 2); // invisible mask - wlc_view_send_to_back(view->handle); -} - -swayc_t *scratchpad_pop(void) { - if (scratchpad->floating->length == 0) { - return NULL; - } - - swayc_t *view = scratchpad->floating->items[0]; - wlc_view_set_mask(view->handle, 1); // visible mask - remove_child(view); - return view; -}