diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-08-04 14:01:49 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-08-04 14:01:49 +1000 |
commit | 30e7e0f7c7d3d3ce2851f2e70842d735343fb402 (patch) | |
tree | bc82fb73e33446c5ec0b50c1bae73658e3eeb6b4 /sway/tree/workspace.c | |
parent | Separate root-related code (diff) | |
download | sway-30e7e0f7c7d3d3ce2851f2e70842d735343fb402.tar.gz sway-30e7e0f7c7d3d3ce2851f2e70842d735343fb402.tar.zst sway-30e7e0f7c7d3d3ce2851f2e70842d735343fb402.zip |
Move workspace pid code to root.c
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r-- | sway/tree/workspace.c | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 687d9c95..cc225e79 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -539,116 +539,3 @@ void workspace_detect_urgent(struct sway_container *workspace) { | |||
539 | container_damage_whole(workspace); | 539 | container_damage_whole(workspace); |
540 | } | 540 | } |
541 | } | 541 | } |
542 | |||
543 | struct pid_workspace { | ||
544 | pid_t pid; | ||
545 | char *workspace; | ||
546 | struct timespec time_added; | ||
547 | |||
548 | struct sway_container *output; | ||
549 | struct wl_listener output_destroy; | ||
550 | |||
551 | struct wl_list link; | ||
552 | }; | ||
553 | |||
554 | static struct wl_list pid_workspaces; | ||
555 | |||
556 | struct sway_container *workspace_for_pid(pid_t pid) { | ||
557 | if (!pid_workspaces.prev && !pid_workspaces.next) { | ||
558 | wl_list_init(&pid_workspaces); | ||
559 | return NULL; | ||
560 | } | ||
561 | |||
562 | struct sway_container *ws = NULL; | ||
563 | struct pid_workspace *pw = NULL; | ||
564 | |||
565 | wlr_log(WLR_DEBUG, "Looking up workspace for pid %d", pid); | ||
566 | |||
567 | do { | ||
568 | struct pid_workspace *_pw = NULL; | ||
569 | wl_list_for_each(_pw, &pid_workspaces, link) { | ||
570 | if (pid == _pw->pid) { | ||
571 | pw = _pw; | ||
572 | wlr_log(WLR_DEBUG, | ||
573 | "found pid_workspace for pid %d, workspace %s", | ||
574 | pid, pw->workspace); | ||
575 | goto found; | ||
576 | } | ||
577 | } | ||
578 | pid = get_parent_pid(pid); | ||
579 | } while (pid > 1); | ||
580 | found: | ||
581 | |||
582 | if (pw && pw->workspace) { | ||
583 | ws = workspace_by_name(pw->workspace); | ||
584 | |||
585 | if (!ws) { | ||
586 | wlr_log(WLR_DEBUG, | ||
587 | "Creating workspace %s for pid %d because it disappeared", | ||
588 | pw->workspace, pid); | ||
589 | ws = workspace_create(pw->output, pw->workspace); | ||
590 | } | ||
591 | |||
592 | wl_list_remove(&pw->output_destroy.link); | ||
593 | wl_list_remove(&pw->link); | ||
594 | free(pw->workspace); | ||
595 | free(pw); | ||
596 | } | ||
597 | |||
598 | return ws; | ||
599 | } | ||
600 | |||
601 | static void pw_handle_output_destroy(struct wl_listener *listener, void *data) { | ||
602 | struct pid_workspace *pw = wl_container_of(listener, pw, output_destroy); | ||
603 | pw->output = NULL; | ||
604 | wl_list_remove(&pw->output_destroy.link); | ||
605 | wl_list_init(&pw->output_destroy.link); | ||
606 | } | ||
607 | |||
608 | void workspace_record_pid(pid_t pid) { | ||
609 | wlr_log(WLR_DEBUG, "Recording workspace for process %d", pid); | ||
610 | if (!pid_workspaces.prev && !pid_workspaces.next) { | ||
611 | wl_list_init(&pid_workspaces); | ||
612 | } | ||
613 | |||
614 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
615 | struct sway_container *ws = | ||
616 | seat_get_focus_inactive(seat, &root_container); | ||
617 | if (ws && ws->type != C_WORKSPACE) { | ||
618 | ws = container_parent(ws, C_WORKSPACE); | ||
619 | } | ||
620 | if (!ws) { | ||
621 | wlr_log(WLR_DEBUG, "Bailing out, no workspace"); | ||
622 | return; | ||
623 | } | ||
624 | struct sway_container *output = ws->parent; | ||
625 | if (!output) { | ||
626 | wlr_log(WLR_DEBUG, "Bailing out, no output"); | ||
627 | return; | ||
628 | } | ||
629 | |||
630 | struct timespec now; | ||
631 | clock_gettime(CLOCK_MONOTONIC, &now); | ||
632 | |||
633 | // Remove expired entries | ||
634 | static const int timeout = 60; | ||
635 | struct pid_workspace *old, *_old; | ||
636 | wl_list_for_each_safe(old, _old, &pid_workspaces, link) { | ||
637 | if (now.tv_sec - old->time_added.tv_sec >= timeout) { | ||
638 | wl_list_remove(&old->output_destroy.link); | ||
639 | wl_list_remove(&old->link); | ||
640 | free(old->workspace); | ||
641 | free(old); | ||
642 | } | ||
643 | } | ||
644 | |||
645 | struct pid_workspace *pw = calloc(1, sizeof(struct pid_workspace)); | ||
646 | pw->workspace = strdup(ws->name); | ||
647 | pw->output = output; | ||
648 | pw->pid = pid; | ||
649 | memcpy(&pw->time_added, &now, sizeof(struct timespec)); | ||
650 | pw->output_destroy.notify = pw_handle_output_destroy; | ||
651 | wl_signal_add(&output->sway_output->wlr_output->events.destroy, | ||
652 | &pw->output_destroy); | ||
653 | wl_list_insert(&pid_workspaces, &pw->link); | ||
654 | } | ||