aboutsummaryrefslogtreecommitdiff
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
parent5de2223c6df480759ee6d8f4422c2643491595d0 (diff)
parent30e7e0f7c7d3d3ce2851f2e70842d735343fb402 (diff)
downloadsway-0016f774407cdb96e6fe3b1b9235119d9b398f8b.zip
sway-0016f774407cdb96e6fe3b1b9235119d9b398f8b.tar.gz
sway-0016f774407cdb96e6fe3b1b9235119d9b398f8b.tar.bz2
Merge pull request #2418 from RyanDwyer/separate-root
Separate root-related code
-rw-r--r--include/sway/scratchpad.h26
-rw-r--r--include/sway/tree/layout.h23
-rw-r--r--include/sway/tree/root.h61
-rw-r--r--include/sway/tree/workspace.h4
-rw-r--r--sway/commands/exec_always.c2
-rw-r--r--sway/commands/move.c5
-rw-r--r--sway/commands/scratchpad.c81
-rw-r--r--sway/main.c3
-rw-r--r--sway/meson.build2
-rw-r--r--sway/scratchpad.c181
-rw-r--r--sway/tree/arrange.c2
-rw-r--r--sway/tree/container.c6
-rw-r--r--sway/tree/layout.c34
-rw-r--r--sway/tree/root.c262
-rw-r--r--sway/tree/view.c2
-rw-r--r--sway/tree/workspace.c113
16 files changed, 413 insertions, 394 deletions
diff --git a/include/sway/scratchpad.h b/include/sway/scratchpad.h
deleted file mode 100644
index 5af5256..0000000
--- a/include/sway/scratchpad.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#ifndef _SWAY_SCRATCHPAD_H
-#define _SWAY_SCRATCHPAD_H
-
-#include "tree/container.h"
-
-/**
- * Move a container to the scratchpad.
- */
-void scratchpad_add_container(struct sway_container *con);
-
-/**
- * Remove a container from the scratchpad.
- */
-void scratchpad_remove_container(struct sway_container *con);
-
-/**
- * Show or hide the next container on the scratchpad.
- */
-void scratchpad_toggle_auto(void);
-
-/**
- * Show or hide a specific container on the scratchpad.
- */
-void scratchpad_toggle_container(struct sway_container *con);
-
-#endif
diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h
index a4c31bf..77cd954 100644
--- a/include/sway/tree/layout.h
+++ b/include/sway/tree/layout.h
@@ -3,6 +3,7 @@
#include <wlr/types/wlr_output_layout.h>
#include <wlr/render/wlr_texture.h>
#include "sway/tree/container.h"
+#include "sway/tree/root.h"
#include "config.h"
enum movement_direction {
@@ -24,28 +25,6 @@ enum resize_edge {
struct sway_container;
-struct sway_root {
- struct wlr_output_layout *output_layout;
-
- struct wl_listener output_layout_change;
-#ifdef HAVE_XWAYLAND
- struct wl_list xwayland_unmanaged; // sway_xwayland_unmanaged::link
-#endif
- struct wl_list drag_icons; // sway_drag_icon::link
-
- struct wlr_texture *debug_tree;
-
- struct wl_list outputs; // sway_output::link
-
- list_t *scratchpad; // struct sway_container
-
- struct {
- struct wl_signal new_container;
- } events;
-};
-
-void layout_init(void);
-
void container_add_child(struct sway_container *parent,
struct sway_container *child);
diff --git a/include/sway/tree/root.h b/include/sway/tree/root.h
new file mode 100644
index 0000000..edb7c81
--- /dev/null
+++ b/include/sway/tree/root.h
@@ -0,0 +1,61 @@
+#ifndef _SWAY_ROOT_H
+#define _SWAY_ROOT_H
+#include <wayland-server-core.h>
+#include <wayland-util.h>
+#include <wlr/types/wlr_output_layout.h>
+#include <wlr/render/wlr_texture.h>
+#include "sway/tree/container.h"
+#include "config.h"
+#include "list.h"
+
+extern struct sway_container root_container;
+
+struct sway_root {
+ struct wlr_output_layout *output_layout;
+
+ struct wl_listener output_layout_change;
+#ifdef HAVE_XWAYLAND
+ struct wl_list xwayland_unmanaged; // sway_xwayland_unmanaged::link
+#endif
+ struct wl_list drag_icons; // sway_drag_icon::link
+
+ struct wlr_texture *debug_tree;
+
+ struct wl_list outputs; // sway_output::link
+
+ list_t *scratchpad; // struct sway_container
+
+ struct {
+ struct wl_signal new_container;
+ } events;
+};
+
+void root_create(void);
+
+void root_destroy(void);
+
+/**
+ * Move a container to the scratchpad.
+ */
+void root_scratchpad_add_container(struct sway_container *con);
+
+/**
+ * Remove a container from the scratchpad.
+ */
+void root_scratchpad_remove_container(struct sway_container *con);
+
+/**
+ * Show a single scratchpad container.
+ */
+void root_scratchpad_show(struct sway_container *con);
+
+/**
+ * Hide a single scratchpad container.
+ */
+void root_scratchpad_hide(struct sway_container *con);
+
+struct sway_container *root_workspace_for_pid(pid_t pid);
+
+void root_record_workspace_pid(pid_t pid);
+
+#endif
diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h
index 5ae0ae3..3337f2c 100644
--- a/include/sway/tree/workspace.h
+++ b/include/sway/tree/workspace.h
@@ -44,10 +44,6 @@ void workspace_output_add_priority(struct sway_container *workspace,
struct sway_container *workspace_output_get_highest_available(
struct sway_container *ws, struct sway_container *exclude);
-struct sway_container *workspace_for_pid(pid_t pid);
-
-void workspace_record_pid(pid_t pid);
-
void workspace_detect_urgent(struct sway_container *workspace);
#endif
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c
index c730cb8..00e39ae 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 1e8b76f..841da4c 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 01a91d6..0e573ae 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;
diff --git a/sway/main.c b/sway/main.c
index c02caf4..d433368 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -407,7 +407,7 @@ int main(int argc, char **argv) {
wlr_log(WLR_INFO, "Starting sway version " SWAY_VERSION);
- layout_init();
+ root_create();
if (!server_init(&server)) {
return 1;
@@ -464,6 +464,7 @@ int main(int argc, char **argv) {
wlr_log(WLR_INFO, "Shutting down sway");
server_fini(&server);
+ root_destroy();
if (config) {
free_config(config);
diff --git a/sway/meson.build b/sway/meson.build
index 17406f6..c18fb6e 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -7,7 +7,6 @@ sway_sources = files(
'debug-tree.c',
'ipc-json.c',
'ipc-server.c',
- 'scratchpad.c',
'security.c',
'swaynag.c',
@@ -150,6 +149,7 @@ sway_sources = files(
'tree/arrange.c',
'tree/container.c',
'tree/layout.c',
+ 'tree/root.c',
'tree/view.c',
'tree/workspace.c',
'tree/output.c',
diff --git a/sway/scratchpad.c b/sway/scratchpad.c
deleted file mode 100644
index b7d6fd9..0000000
--- a/sway/scratchpad.c
+++ /dev/null
@@ -1,181 +0,0 @@
-#define _XOPEN_SOURCE 700
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include "sway/scratchpad.h"
-#include "sway/input/seat.h"
-#include "sway/tree/arrange.h"
-#include "sway/tree/container.h"
-#include "sway/tree/view.h"
-#include "sway/tree/workspace.h"
-#include "list.h"
-#include "log.h"
-
-void scratchpad_add_container(struct sway_container *con) {
- if (!sway_assert(!con->scratchpad, "Container is already in scratchpad")) {
- return;
- }
- con->scratchpad = true;
- list_add(root_container.sway_root->scratchpad, con);
-
- struct sway_container *parent = con->parent;
- container_set_floating(con, true);
- container_remove_child(con);
- arrange_windows(parent);
-
- struct sway_seat *seat = input_manager_current_seat(input_manager);
- seat_set_focus(seat, seat_get_focus_inactive(seat, parent));
-}
-
-void scratchpad_remove_container(struct sway_container *con) {
- if (!sway_assert(con->scratchpad, "Container is not in scratchpad")) {
- return;
- }
- con->scratchpad = false;
- for (int i = 0; i < root_container.sway_root->scratchpad->length; ++i) {
- if (root_container.sway_root->scratchpad->items[i] == con) {
- list_del(root_container.sway_root->scratchpad, i);
- break;
- }
- }
-}
-
-/**
- * Show a single scratchpad container.
- * The container might be visible on another workspace already.
- */
-static void scratchpad_show(struct sway_container *con) {
- struct sway_seat *seat = input_manager_current_seat(input_manager);
- struct sway_container *ws = seat_get_focus(seat);
- if (ws->type != C_WORKSPACE) {
- ws = container_parent(ws, C_WORKSPACE);
- }
-
- // If the current con or any of its parents are in fullscreen mode, we
- // first need to disable it before showing the scratchpad con.
- if (ws->sway_workspace->fullscreen) {
- container_set_fullscreen(ws->sway_workspace->fullscreen, false);
- }
-
- // Show the container
- if (con->parent) {
- container_remove_child(con);
- }
- container_add_child(ws->sway_workspace->floating, con);
-
- // Make sure the container's center point overlaps this workspace
- double center_lx = con->x + con->width / 2;
- double center_ly = con->y + con->height / 2;
-
- struct wlr_box workspace_box;
- container_get_box(ws, &workspace_box);
- if (!wlr_box_contains_point(&workspace_box, center_lx, center_ly)) {
- // Maybe resize it
- if (con->width > ws->width || con->height > ws->height) {
- container_init_floating(con);
- }
-
- // Center it
- double new_lx = ws->x + (ws->width - con->width) / 2;
- double new_ly = ws->y + (ws->height - con->height) / 2;
- container_floating_move_to(con, new_lx, new_ly);
- }
-
- arrange_windows(ws);
- seat_set_focus(seat, seat_get_focus_inactive(seat, con));
-
- container_set_dirty(con->parent);
-}
-
-/**
- * Hide a single scratchpad container.
- * The container might not be the focused container (eg. when using criteria).
- */
-static void scratchpad_hide(struct sway_container *con) {
- struct sway_seat *seat = input_manager_current_seat(input_manager);
- struct sway_container *focus = seat_get_focus(seat);
- struct sway_container *ws = container_parent(con, C_WORKSPACE);
-
- container_remove_child(con);
- arrange_windows(ws);
- if (con == focus) {
- seat_set_focus(seat, seat_get_focus_inactive(seat, ws));
- }
- list_move_to_end(root_container.sway_root->scratchpad, con);
-}
-
-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);
- 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);
- 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);
- 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);
- scratchpad_show(con);
-}
-
-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) {
- scratchpad_hide(con);
- return;
- }
-
- scratchpad_show(con);
-}
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index 5452b13..494a846 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -14,8 +14,6 @@
#include "list.h"
#include "log.h"
-struct sway_container root_container;
-
static void apply_horiz_layout(struct sway_container *parent) {
size_t num_children = parent->children->length;
if (!num_children) {
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 4a50365..6da5ac3 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -17,7 +17,6 @@
#include "sway/input/seat.h"
#include "sway/ipc-server.h"
#include "sway/output.h"
-#include "sway/scratchpad.h"
#include "sway/server.h"
#include "sway/tree/arrange.h"
#include "sway/tree/layout.h"
@@ -336,7 +335,6 @@ static struct sway_container *container_destroy_noreaping(
// Workspaces will refuse to be destroyed if they're the last workspace
// on their output.
if (!container_workspace_destroy(con)) {
- wlr_log(WLR_ERROR, "workspace doesn't want to destroy");
return NULL;
}
}
@@ -347,7 +345,7 @@ static struct sway_container *container_destroy_noreaping(
container_set_dirty(con);
if (con->scratchpad) {
- scratchpad_remove_container(con);
+ root_scratchpad_remove_container(con);
}
if (!con->parent) {
@@ -1097,7 +1095,7 @@ void container_set_floating(struct sway_container *container, bool enable) {
} else {
// Returning to tiled
if (container->scratchpad) {
- scratchpad_remove_container(container);
+ root_scratchpad_remove_container(container);
}
container_remove_child(container);
struct sway_container *reference =
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 1f82e53..07de966 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -19,40 +19,6 @@
#include "list.h"
#include "log.h"
-struct sway_container root_container;
-
-static void output_layout_handle_change(struct wl_listener *listener,
- void *data) {
- arrange_windows(&root_container);
- transaction_commit_dirty();
-}
-
-void layout_init(void) {
- root_container.id = 0; // normally assigned in new_swayc()
- root_container.type = C_ROOT;
- root_container.layout = L_NONE;
- root_container.name = strdup("root");
- root_container.instructions = create_list();
- root_container.children = create_list();
- root_container.current.children = create_list();
- wl_signal_init(&root_container.events.destroy);
-
- root_container.sway_root = calloc(1, sizeof(*root_container.sway_root));
- root_container.sway_root->output_layout = wlr_output_layout_create();
- wl_list_init(&root_container.sway_root->outputs);
-#ifdef HAVE_XWAYLAND
- wl_list_init(&root_container.sway_root->xwayland_unmanaged);
-#endif
- wl_list_init(&root_container.sway_root->drag_icons);
- wl_signal_init(&root_container.sway_root->events.new_container);
- root_container.sway_root->scratchpad = create_list();
-
- root_container.sway_root->output_layout_change.notify =
- output_layout_handle_change;
- wl_signal_add(&root_container.sway_root->output_layout->events.change,
- &root_container.sway_root->output_layout_change);
-}
-
static int index_child(const struct sway_container *child) {
struct sway_container *parent = child->parent;
for (int i = 0; i < parent->children->length; ++i) {
diff --git a/sway/tree/root.c b/sway/tree/root.c
new file mode 100644
index 0000000..79f2194
--- /dev/null
+++ b/sway/tree/root.c
@@ -0,0 +1,262 @@
+#define _POSIX_C_SOURCE 200809L
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wlr/types/wlr_output_layout.h>
+#include "sway/input/seat.h"
+#include "sway/output.h"
+#include "sway/tree/arrange.h"
+#include "sway/tree/container.h"
+#include "sway/tree/root.h"
+#include "sway/tree/workspace.h"
+#include "list.h"
+#include "log.h"
+#include "util.h"
+
+struct sway_container root_container;
+
+static void output_layout_handle_change(struct wl_listener *listener,
+ void *data) {
+ arrange_windows(&root_container);
+ transaction_commit_dirty();
+}
+
+void root_create(void) {
+ root_container.id = 0; // normally assigned in new_swayc()
+ root_container.type = C_ROOT;
+ root_container.layout = L_NONE;
+ root_container.name = strdup("root");
+ root_container.instructions = create_list();
+ root_container.children = create_list();
+ root_container.current.children = create_list();
+ wl_signal_init(&root_container.events.destroy);
+
+ root_container.sway_root = calloc(1, sizeof(*root_container.sway_root));
+ root_container.sway_root->output_layout = wlr_output_layout_create();
+ wl_list_init(&root_container.sway_root->outputs);
+#ifdef HAVE_XWAYLAND
+ wl_list_init(&root_container.sway_root->xwayland_unmanaged);
+#endif
+ wl_list_init(&root_container.sway_root->drag_icons);
+ wl_signal_init(&root_container.sway_root->events.new_container);
+ root_container.sway_root->scratchpad = create_list();
+
+ root_container.sway_root->output_layout_change.notify =
+ output_layout_handle_change;
+ wl_signal_add(&root_container.sway_root->output_layout->events.change,
+ &root_container.sway_root->output_layout_change);
+}
+
+void root_destroy(void) {
+ // sway_root
+ wl_list_remove(&root_container.sway_root->output_layout_change.link);
+ list_free(root_container.sway_root->scratchpad);
+ wlr_output_layout_destroy(root_container.sway_root->output_layout);
+ free(root_container.sway_root);
+
+ // root_container
+ list_free(root_container.instructions);
+ list_free(root_container.children);
+ list_free(root_container.current.children);
+ free(root_container.name);
+
+ memset(&root_container, 0, sizeof(root_container));
+}
+
+void root_scratchpad_add_container(struct sway_container *con) {
+ if (!sway_assert(!con->scratchpad, "Container is already in scratchpad")) {
+ return;
+ }
+ con->scratchpad = true;
+ list_add(root_container.sway_root->scratchpad, con);
+
+ struct sway_container *parent = con->parent;
+ container_set_floating(con, true);
+ container_remove_child(con);
+ arrange_windows(parent);
+
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+ seat_set_focus(seat, seat_get_focus_inactive(seat, parent));
+}
+
+void root_scratchpad_remove_container(struct sway_container *con) {
+ if (!sway_assert(con->scratchpad, "Container is not in scratchpad")) {
+ return;
+ }
+ con->scratchpad = false;
+ for (int i = 0; i < root_container.sway_root->scratchpad->length; ++i) {
+ if (root_container.sway_root->scratchpad->items[i] == con) {
+ list_del(root_container.sway_root->scratchpad, i);
+ break;
+ }
+ }
+}
+
+void root_scratchpad_show(struct sway_container *con) {
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+ struct sway_container *ws = seat_get_focus(seat);
+ if (ws->type != C_WORKSPACE) {
+ ws = container_parent(ws, C_WORKSPACE);
+ }
+
+ // If the current con or any of its parents are in fullscreen mode, we
+ // first need to disable it before showing the scratchpad con.
+ if (ws->sway_workspace->fullscreen) {
+ container_set_fullscreen(ws->sway_workspace->fullscreen, false);
+ }
+
+ // Show the container
+ if (con->parent) {
+ container_remove_child(con);
+ }
+ container_add_child(ws->sway_workspace->floating, con);
+
+ // Make sure the container's center point overlaps this workspace
+ double center_lx = con->x + con->width / 2;
+ double center_ly = con->y + con->height / 2;
+
+ struct wlr_box workspace_box;
+ container_get_box(ws, &workspace_box);
+ if (!wlr_box_contains_point(&workspace_box, center_lx, center_ly)) {
+ // Maybe resize it
+ if (con->width > ws->width || con->height > ws->height) {
+ container_init_floating(con);
+ }
+
+ // Center it
+ double new_lx = ws->x + (ws->width - con->width) / 2;
+ double new_ly = ws->y + (ws->height - con->height) / 2;
+ container_floating_move_to(con, new_lx, new_ly);
+ }
+
+ arrange_windows(ws);
+ seat_set_focus(seat, seat_get_focus_inactive(seat, con));
+
+ container_set_dirty(con->parent);
+}
+
+void root_scratchpad_hide(struct sway_container *con) {
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+ struct sway_container *focus = seat_get_focus(seat);
+ struct sway_container *ws = container_parent(con, C_WORKSPACE);
+
+ container_remove_child(con);
+ arrange_windows(ws);
+ if (con == focus) {
+ seat_set_focus(seat, seat_get_focus_inactive(seat, ws));
+ }
+ list_move_to_end(root_container.sway_root->scratchpad, con);
+}
+
+struct pid_workspace {
+ pid_t pid;
+ char *workspace;
+ struct timespec time_added;
+
+ struct sway_container *output;
+ struct wl_listener output_destroy;
+
+ struct wl_list link;
+};
+
+static struct wl_list pid_workspaces;
+
+struct sway_container *root_workspace_for_pid(pid_t pid) {
+ if (!pid_workspaces.prev && !pid_workspaces.next) {
+ wl_list_init(&pid_workspaces);
+ return NULL;
+ }
+
+ struct sway_container *ws = NULL;
+ struct pid_workspace *pw = NULL;
+
+ wlr_log(WLR_DEBUG, "Looking up workspace for pid %d", pid);
+
+ do {
+ struct pid_workspace *_pw = NULL;
+ wl_list_for_each(_pw, &pid_workspaces, link) {
+ if (pid == _pw->pid) {
+ pw = _pw;
+ wlr_log(WLR_DEBUG,
+ "found pid_workspace for pid %d, workspace %s",
+ pid, pw->workspace);
+ goto found;
+ }
+ }
+ pid = get_parent_pid(pid);
+ } while (pid > 1);
+found:
+
+ if (pw && pw->workspace) {
+ ws = workspace_by_name(pw->workspace);
+
+ if (!ws) {
+ wlr_log(WLR_DEBUG,
+ "Creating workspace %s for pid %d because it disappeared",
+ pw->workspace, pid);
+ ws = workspace_create(pw->output, pw->workspace);
+ }
+
+ wl_list_remove(&pw->output_destroy.link);
+ wl_list_remove(&pw->link);
+ free(pw->workspace);
+ free(pw);
+ }
+
+ return ws;
+}
+
+static void pw_handle_output_destroy(struct wl_listener *listener, void *data) {
+ struct pid_workspace *pw = wl_container_of(listener, pw, output_destroy);
+ pw->output = NULL;
+ wl_list_remove(&pw->output_destroy.link);
+ wl_list_init(&pw->output_destroy.link);
+}
+
+void root_record_workspace_pid(pid_t pid) {
+ wlr_log(WLR_DEBUG, "Recording workspace for process %d", pid);
+ if (!pid_workspaces.prev && !pid_workspaces.next) {
+ wl_list_init(&pid_workspaces);
+ }
+
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+ struct sway_container *ws =
+ seat_get_focus_inactive(seat, &root_container);
+ if (ws && ws->type != C_WORKSPACE) {
+ ws = container_parent(ws, C_WORKSPACE);
+ }
+ if (!ws) {
+ wlr_log(WLR_DEBUG, "Bailing out, no workspace");
+ return;
+ }
+ struct sway_container *output = ws->parent;
+ if (!output) {
+ wlr_log(WLR_DEBUG, "Bailing out, no output");
+ return;
+ }
+
+ struct timespec now;
+ clock_gettime(CLOCK_MONOTONIC, &now);
+
+ // Remove expired entries
+ static const int timeout = 60;
+ struct pid_workspace *old, *_old;
+ wl_list_for_each_safe(old, _old, &pid_workspaces, link) {
+ if (now.tv_sec - old->time_added.tv_sec >= timeout) {
+ wl_list_remove(&old->output_destroy.link);
+ wl_list_remove(&old->link);
+ free(old->workspace);
+ free(old);
+ }
+ }
+
+ struct pid_workspace *pw = calloc(1, sizeof(struct pid_workspace));
+ pw->workspace = strdup(ws->name);
+ pw->output = output;
+ pw->pid = pid;
+ memcpy(&pw->time_added, &now, sizeof(struct timespec));
+ pw->output_destroy.notify = pw_handle_output_destroy;
+ wl_signal_add(&output->sway_output->wlr_output->events.destroy,
+ &pw->output_destroy);
+ wl_list_insert(&pid_workspaces, &pw->link);
+}
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 78baa70..9465b3a 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -490,7 +490,7 @@ static struct sway_container *select_workspace(struct sway_view *view) {
wl_resource_get_client(view->surface->resource);
wl_client_get_credentials(client, &pid, NULL, NULL);
#endif
- ws = workspace_for_pid(pid);
+ ws = root_workspace_for_pid(pid);
if (ws) {
return ws;
}
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 687d9c9..cc225e7 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -539,116 +539,3 @@ void workspace_detect_urgent(struct sway_container *workspace) {
container_damage_whole(workspace);
}
}
-
-struct pid_workspace {
- pid_t pid;
- char *workspace;
- struct timespec time_added;
-
- struct sway_container *output;
- struct wl_listener output_destroy;
-
- struct wl_list link;
-};
-
-static struct wl_list pid_workspaces;
-
-struct sway_container *workspace_for_pid(pid_t pid) {
- if (!pid_workspaces.prev && !pid_workspaces.next) {
- wl_list_init(&pid_workspaces);
- return NULL;
- }
-
- struct sway_container *ws = NULL;
- struct pid_workspace *pw = NULL;
-
- wlr_log(WLR_DEBUG, "Looking up workspace for pid %d", pid);
-
- do {
- struct pid_workspace *_pw = NULL;
- wl_list_for_each(_pw, &pid_workspaces, link) {
- if (pid == _pw->pid) {
- pw = _pw;
- wlr_log(WLR_DEBUG,
- "found pid_workspace for pid %d, workspace %s",
- pid, pw->workspace);
- goto found;
- }
- }
- pid = get_parent_pid(pid);
- } while (pid > 1);
-found:
-
- if (pw && pw->workspace) {
- ws = workspace_by_name(pw->workspace);
-
- if (!ws) {
- wlr_log(WLR_DEBUG,
- "Creating workspace %s for pid %d because it disappeared",
- pw->workspace, pid);
- ws = workspace_create(pw->output, pw->workspace);
- }
-
- wl_list_remove(&pw->output_destroy.link);
- wl_list_remove(&pw->link);
- free(pw->workspace);
- free(pw);
- }
-
- return ws;
-}
-
-static void pw_handle_output_destroy(struct wl_listener *listener, void *data) {
- struct pid_workspace *pw = wl_container_of(listener, pw, output_destroy);
- pw->output = NULL;
- wl_list_remove(&pw->output_destroy.link);
- wl_list_init(&pw->output_destroy.link);
-}
-
-void workspace_record_pid(pid_t pid) {
- wlr_log(WLR_DEBUG, "Recording workspace for process %d", pid);
- if (!pid_workspaces.prev && !pid_workspaces.next) {
- wl_list_init(&pid_workspaces);
- }
-
- struct sway_seat *seat = input_manager_current_seat(input_manager);
- struct sway_container *ws =
- seat_get_focus_inactive(seat, &root_container);
- if (ws && ws->type != C_WORKSPACE) {
- ws = container_parent(ws, C_WORKSPACE);
- }
- if (!ws) {
- wlr_log(WLR_DEBUG, "Bailing out, no workspace");
- return;
- }
- struct sway_container *output = ws->parent;
- if (!output) {
- wlr_log(WLR_DEBUG, "Bailing out, no output");
- return;
- }
-
- struct timespec now;
- clock_gettime(CLOCK_MONOTONIC, &now);
-
- // Remove expired entries
- static const int timeout = 60;
- struct pid_workspace *old, *_old;
- wl_list_for_each_safe(old, _old, &pid_workspaces, link) {
- if (now.tv_sec - old->time_added.tv_sec >= timeout) {
- wl_list_remove(&old->output_destroy.link);
- wl_list_remove(&old->link);
- free(old->workspace);
- free(old);
- }
- }
-
- struct pid_workspace *pw = calloc(1, sizeof(struct pid_workspace));
- pw->workspace = strdup(ws->name);
- pw->output = output;
- pw->pid = pid;
- memcpy(&pw->time_added, &now, sizeof(struct timespec));
- pw->output_destroy.notify = pw_handle_output_destroy;
- wl_signal_add(&output->sway_output->wlr_output->events.destroy,
- &pw->output_destroy);
- wl_list_insert(&pid_workspaces, &pw->link);
-}