summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2020-01-08 19:30:27 -0500
committerSimon Ser <contact@emersion.fr>2020-01-15 18:00:39 +0100
commit06565b1827635ca91b9e5af8be3d821623f1fd8f (patch)
tree2c1edc922e293cf477bc1b88638cb689a2591470
parent5250eebafea0fd62297f9de85a58d5fe095967b3 (diff)
view: remove workspace pid mapping for assigns
If a view is mapped to a workspace using an assign, the pid should still be removed from the pid mapping list. This prevents child processes from matching against it and mapping a view to a likely undesired workspace.
-rw-r--r--include/sway/tree/root.h2
-rw-r--r--sway/tree/root.c31
-rw-r--r--sway/tree/view.c1
3 files changed, 26 insertions, 8 deletions
diff --git a/include/sway/tree/root.h b/include/sway/tree/root.h
index 799d751a9..e8f4d5738 100644
--- a/include/sway/tree/root.h
+++ b/include/sway/tree/root.h
@@ -72,6 +72,8 @@ struct sway_workspace *root_workspace_for_pid(pid_t pid);
void root_record_workspace_pid(pid_t pid);
+void root_remove_workspace_pid(pid_t pid);
+
void root_for_each_workspace(void (*f)(struct sway_workspace *ws, void *data),
void *data);
diff --git a/sway/tree/root.c b/sway/tree/root.c
index a3830976a..46a140efe 100644
--- a/sway/tree/root.c
+++ b/sway/tree/root.c
@@ -225,6 +225,13 @@ static pid_t get_parent_pid(pid_t child) {
return -1;
}
+static void pid_workspace_destroy(struct pid_workspace *pw) {
+ wl_list_remove(&pw->output_destroy.link);
+ wl_list_remove(&pw->link);
+ free(pw->workspace);
+ free(pw);
+}
+
struct sway_workspace *root_workspace_for_pid(pid_t pid) {
if (!pid_workspaces.prev && !pid_workspaces.next) {
wl_list_init(&pid_workspaces);
@@ -261,10 +268,7 @@ found:
ws = workspace_create(pw->output, pw->workspace);
}
- wl_list_remove(&pw->output_destroy.link);
- wl_list_remove(&pw->link);
- free(pw->workspace);
- free(pw);
+ pid_workspace_destroy(pw);
}
return ws;
@@ -303,10 +307,7 @@ void root_record_workspace_pid(pid_t pid) {
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);
+ pid_workspace_destroy(old);
}
}
@@ -320,6 +321,20 @@ void root_record_workspace_pid(pid_t pid) {
wl_list_insert(&pid_workspaces, &pw->link);
}
+void root_remove_workspace_pid(pid_t pid) {
+ if (!pid_workspaces.prev || !pid_workspaces.next) {
+ return;
+ }
+
+ struct pid_workspace *pw, *tmp;
+ wl_list_for_each_safe(pw, tmp, &pid_workspaces, link) {
+ if (pid == pw->pid) {
+ pid_workspace_destroy(pw);
+ return;
+ }
+ }
+}
+
void root_for_each_workspace(void (*f)(struct sway_workspace *ws, void *data),
void *data) {
for (int i = 0; i < root->outputs->length; ++i) {
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 93d4fefce..fc88cff9b 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -503,6 +503,7 @@ static struct sway_workspace *select_workspace(struct sway_view *view) {
}
list_free(criterias);
if (ws) {
+ root_remove_workspace_pid(view->pid);
return ws;
}