aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-08-04 20:41:45 +0100
committerGitHub <noreply@github.com>2018-08-04 20:41:45 +0100
commit0016f774407cdb96e6fe3b1b9235119d9b398f8b (patch)
treebc82fb73e33446c5ec0b50c1bae73658e3eeb6b4 /sway/commands
parent5de2223c6df480759ee6d8f4422c2643491595d0 (diff)
parent30e7e0f7c7d3d3ce2851f2e70842d735343fb402 (diff)
Merge pull request #2418 from RyanDwyer/separate-root
Separate root-related code
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/exec_always.c2
-rw-r--r--sway/commands/move.c5
-rw-r--r--sway/commands/scratchpad.c81
3 files changed, 83 insertions, 5 deletions
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c
index c730cb8b..00e39ae7 100644
--- a/sway/commands/exec_always.c
+++ b/sway/commands/exec_always.c
@@ -78,7 +78,7 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) {
waitpid(pid, NULL, 0);
if (child > 0) {
wlr_log(WLR_DEBUG, "Child process created with pid %d", child);
- workspace_record_pid(child);
+ root_record_workspace_pid(child);
} else {
return cmd_results_new(CMD_FAILURE, "exec_always",
"Second fork() failed");
diff --git a/sway/commands/move.c b/sway/commands/move.c
index 1e8b76f9..841da4c4 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -9,10 +9,9 @@
#include "sway/input/cursor.h"
#include "sway/input/seat.h"
#include "sway/output.h"
-#include "sway/scratchpad.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
-#include "sway/tree/layout.h"
+#include "sway/tree/root.h"
#include "sway/tree/workspace.h"
#include "stringop.h"
#include "list.h"
@@ -324,7 +323,7 @@ static struct cmd_results *move_to_scratchpad(struct sway_container *con) {
return cmd_results_new(CMD_INVALID, "move",
"Container is already in the scratchpad");
}
- scratchpad_add_container(con);
+ root_scratchpad_add_container(con);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
diff --git a/sway/commands/scratchpad.c b/sway/commands/scratchpad.c
index 01a91d65..0e573aeb 100644
--- a/sway/commands/scratchpad.c
+++ b/sway/commands/scratchpad.c
@@ -1,8 +1,87 @@
#include "log.h"
#include "sway/commands.h"
#include "sway/config.h"
-#include "sway/scratchpad.h"
+#include "sway/input/input-manager.h"
+#include "sway/input/seat.h"
#include "sway/tree/container.h"
+#include "sway/tree/root.h"
+#include "sway/tree/workspace.h"
+
+static void scratchpad_toggle_auto(void) {
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+ struct sway_container *focus = seat_get_focus(seat);
+ struct sway_container *ws = focus->type == C_WORKSPACE ?
+ focus : container_parent(focus, C_WORKSPACE);
+
+ // If the focus is in a floating split container,
+ // operate on the split container instead of the child.
+ if (container_is_floating_or_child(focus)) {
+ while (focus->parent->layout != L_FLOATING) {
+ focus = focus->parent;
+ }
+ }
+
+
+ // Check if the currently focused window is a scratchpad window and should
+ // be hidden again.
+ if (focus->scratchpad) {
+ wlr_log(WLR_DEBUG, "Focus is a scratchpad window - hiding %s",
+ focus->name);
+ root_scratchpad_hide(focus);
+ return;
+ }
+
+ // Check if there is an unfocused scratchpad window on the current workspace
+ // and focus it.
+ for (int i = 0; i < ws->sway_workspace->floating->children->length; ++i) {
+ struct sway_container *floater =
+ ws->sway_workspace->floating->children->items[i];
+ if (floater->scratchpad && focus != floater) {
+ wlr_log(WLR_DEBUG,
+ "Focusing other scratchpad window (%s) in this workspace",
+ floater->name);
+ root_scratchpad_show(floater);
+ return;
+ }
+ }
+
+ // Check if there is a visible scratchpad window on another workspace.
+ // In this case we move it to the current workspace.
+ for (int i = 0; i < root_container.sway_root->scratchpad->length; ++i) {
+ struct sway_container *con =
+ root_container.sway_root->scratchpad->items[i];
+ if (con->parent) {
+ wlr_log(WLR_DEBUG,
+ "Moving a visible scratchpad window (%s) to this workspace",
+ con->name);
+ root_scratchpad_show(con);
+ return;
+ }
+ }
+
+ // Take the container at the bottom of the scratchpad list
+ if (!sway_assert(root_container.sway_root->scratchpad->length,
+ "Scratchpad is empty")) {
+ return;
+ }
+ struct sway_container *con = root_container.sway_root->scratchpad->items[0];
+ wlr_log(WLR_DEBUG, "Showing %s from list", con->name);
+ root_scratchpad_show(con);
+}
+
+static void scratchpad_toggle_container(struct sway_container *con) {
+ if (!sway_assert(con->scratchpad, "Container isn't in the scratchpad")) {
+ return;
+ }
+
+ // Check if it matches a currently visible scratchpad window and hide it.
+ if (con->parent) {
+ root_scratchpad_hide(con);
+ return;
+ }
+
+ root_scratchpad_show(con);
+}
struct cmd_results *cmd_scratchpad(int argc, char **argv) {
struct cmd_results *error = NULL;