aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2020-01-08 19:30:27 -0500
committerLibravatar Simon Ser <contact@emersion.fr>2020-01-15 18:00:39 +0100
commit06565b1827635ca91b9e5af8be3d821623f1fd8f (patch)
tree2c1edc922e293cf477bc1b88638cb689a2591470
parentinput/cursor: handle setting a NULL image surface (diff)
downloadsway-06565b1827635ca91b9e5af8be3d821623f1fd8f.tar.gz
sway-06565b1827635ca91b9e5af8be3d821623f1fd8f.tar.zst
sway-06565b1827635ca91b9e5af8be3d821623f1fd8f.zip
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 799d751a..e8f4d573 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);
72 72
73void root_record_workspace_pid(pid_t pid); 73void root_record_workspace_pid(pid_t pid);
74 74
75void root_remove_workspace_pid(pid_t pid);
76
75void root_for_each_workspace(void (*f)(struct sway_workspace *ws, void *data), 77void root_for_each_workspace(void (*f)(struct sway_workspace *ws, void *data),
76 void *data); 78 void *data);
77 79
diff --git a/sway/tree/root.c b/sway/tree/root.c
index a3830976..46a140ef 100644
--- a/sway/tree/root.c
+++ b/sway/tree/root.c
@@ -225,6 +225,13 @@ static pid_t get_parent_pid(pid_t child) {
225 return -1; 225 return -1;
226} 226}
227 227
228static void pid_workspace_destroy(struct pid_workspace *pw) {
229 wl_list_remove(&pw->output_destroy.link);
230 wl_list_remove(&pw->link);
231 free(pw->workspace);
232 free(pw);
233}
234
228struct sway_workspace *root_workspace_for_pid(pid_t pid) { 235struct sway_workspace *root_workspace_for_pid(pid_t pid) {
229 if (!pid_workspaces.prev && !pid_workspaces.next) { 236 if (!pid_workspaces.prev && !pid_workspaces.next) {
230 wl_list_init(&pid_workspaces); 237 wl_list_init(&pid_workspaces);
@@ -261,10 +268,7 @@ found:
261 ws = workspace_create(pw->output, pw->workspace); 268 ws = workspace_create(pw->output, pw->workspace);
262 } 269 }
263 270
264 wl_list_remove(&pw->output_destroy.link); 271 pid_workspace_destroy(pw);
265 wl_list_remove(&pw->link);
266 free(pw->workspace);
267 free(pw);
268 } 272 }
269 273
270 return ws; 274 return ws;
@@ -303,10 +307,7 @@ void root_record_workspace_pid(pid_t pid) {
303 struct pid_workspace *old, *_old; 307 struct pid_workspace *old, *_old;
304 wl_list_for_each_safe(old, _old, &pid_workspaces, link) { 308 wl_list_for_each_safe(old, _old, &pid_workspaces, link) {
305 if (now.tv_sec - old->time_added.tv_sec >= timeout) { 309 if (now.tv_sec - old->time_added.tv_sec >= timeout) {
306 wl_list_remove(&old->output_destroy.link); 310 pid_workspace_destroy(old);
307 wl_list_remove(&old->link);
308 free(old->workspace);
309 free(old);
310 } 311 }
311 } 312 }
312 313
@@ -320,6 +321,20 @@ void root_record_workspace_pid(pid_t pid) {
320 wl_list_insert(&pid_workspaces, &pw->link); 321 wl_list_insert(&pid_workspaces, &pw->link);
321} 322}
322 323
324void root_remove_workspace_pid(pid_t pid) {
325 if (!pid_workspaces.prev || !pid_workspaces.next) {
326 return;
327 }
328
329 struct pid_workspace *pw, *tmp;
330 wl_list_for_each_safe(pw, tmp, &pid_workspaces, link) {
331 if (pid == pw->pid) {
332 pid_workspace_destroy(pw);
333 return;
334 }
335 }
336}
337
323void root_for_each_workspace(void (*f)(struct sway_workspace *ws, void *data), 338void root_for_each_workspace(void (*f)(struct sway_workspace *ws, void *data),
324 void *data) { 339 void *data) {
325 for (int i = 0; i < root->outputs->length; ++i) { 340 for (int i = 0; i < root->outputs->length; ++i) {
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 93d4fefc..fc88cff9 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) {
503 } 503 }
504 list_free(criterias); 504 list_free(criterias);
505 if (ws) { 505 if (ws) {
506 root_remove_workspace_pid(view->pid);
506 return ws; 507 return ws;
507 } 508 }
508 509