diff options
-rw-r--r-- | config.in | 3 | ||||
-rw-r--r-- | include/sway/config.h | 11 | ||||
-rw-r--r-- | include/sway/tree/workspace.h | 4 | ||||
-rw-r--r-- | sway/commands/exec_always.c | 2 | ||||
-rw-r--r-- | sway/config.c | 2 | ||||
-rw-r--r-- | sway/desktop/xdg_shell.c | 3 | ||||
-rw-r--r-- | sway/desktop/xdg_shell_v6.c | 3 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 3 | ||||
-rw-r--r-- | sway/tree/view.c | 42 | ||||
-rw-r--r-- | sway/tree/workspace.c | 112 |
10 files changed, 153 insertions, 32 deletions
@@ -16,7 +16,8 @@ set $right l | |||
16 | # Your preferred terminal emulator | 16 | # Your preferred terminal emulator |
17 | set $term urxvt | 17 | set $term urxvt |
18 | # Your preferred application launcher | 18 | # Your preferred application launcher |
19 | set $menu dmenu_run | 19 | # Note: it's recommended that you pass the final command to sway |
20 | set $menu dmenu_path | dmenu | xargs swaymsg exec | ||
20 | 21 | ||
21 | ### Output configuration | 22 | ### Output configuration |
22 | # | 23 | # |
diff --git a/include/sway/config.h b/include/sway/config.h index b8da29c5..9d2e1bf9 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -1,6 +1,5 @@ | |||
1 | #ifndef _SWAY_CONFIG_H | 1 | #ifndef _SWAY_CONFIG_H |
2 | #define _SWAY_CONFIG_H | 2 | #define _SWAY_CONFIG_H |
3 | #define PID_WORKSPACE_TIMEOUT 60 | ||
4 | #include <libinput.h> | 3 | #include <libinput.h> |
5 | #include <stdint.h> | 4 | #include <stdint.h> |
6 | #include <string.h> | 5 | #include <string.h> |
@@ -146,12 +145,6 @@ struct workspace_output { | |||
146 | char *workspace; | 145 | char *workspace; |
147 | }; | 146 | }; |
148 | 147 | ||
149 | struct pid_workspace { | ||
150 | pid_t *pid; | ||
151 | char *workspace; | ||
152 | time_t *time_added; | ||
153 | }; | ||
154 | |||
155 | struct bar_config { | 148 | struct bar_config { |
156 | /** | 149 | /** |
157 | * One of "dock", "hide", "invisible" | 150 | * One of "dock", "hide", "invisible" |
@@ -302,7 +295,6 @@ struct sway_config { | |||
302 | list_t *bars; | 295 | list_t *bars; |
303 | list_t *cmd_queue; | 296 | list_t *cmd_queue; |
304 | list_t *workspace_outputs; | 297 | list_t *workspace_outputs; |
305 | list_t *pid_workspaces; | ||
306 | list_t *output_configs; | 298 | list_t *output_configs; |
307 | list_t *input_configs; | 299 | list_t *input_configs; |
308 | list_t *seat_configs; | 300 | list_t *seat_configs; |
@@ -388,9 +380,6 @@ struct sway_config { | |||
388 | } handler_context; | 380 | } handler_context; |
389 | }; | 381 | }; |
390 | 382 | ||
391 | void pid_workspace_add(struct pid_workspace *pw); | ||
392 | void free_pid_workspace(struct pid_workspace *pw); | ||
393 | |||
394 | /** | 383 | /** |
395 | * Loads the main config from the given path. is_active should be true when | 384 | * Loads the main config from the given path. is_active should be true when |
396 | * reloading the config. | 385 | * reloading the config. |
diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index bc95317a..ff66da6b 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h | |||
@@ -44,6 +44,10 @@ void workspace_output_add_priority(struct sway_container *workspace, | |||
44 | struct sway_container *workspace_output_get_highest_available( | 44 | struct sway_container *workspace_output_get_highest_available( |
45 | struct sway_container *ws, struct sway_container *exclude); | 45 | struct sway_container *ws, struct sway_container *exclude); |
46 | 46 | ||
47 | struct sway_container *workspace_for_pid(pid_t pid); | ||
48 | |||
49 | void workspace_record_pid(pid_t pid); | ||
50 | |||
47 | void workspace_detect_urgent(struct sway_container *workspace); | 51 | void workspace_detect_urgent(struct sway_container *workspace); |
48 | 52 | ||
49 | #endif | 53 | #endif |
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index c7727857..9bf2b320 100644 --- a/sway/commands/exec_always.c +++ b/sway/commands/exec_always.c | |||
@@ -74,7 +74,7 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) { | |||
74 | waitpid(pid, NULL, 0); | 74 | waitpid(pid, NULL, 0); |
75 | if (child > 0) { | 75 | if (child > 0) { |
76 | wlr_log(WLR_DEBUG, "Child process created with pid %d", child); | 76 | wlr_log(WLR_DEBUG, "Child process created with pid %d", child); |
77 | // TODO: add PID to active workspace | 77 | workspace_record_pid(child); |
78 | } else { | 78 | } else { |
79 | return cmd_results_new(CMD_FAILURE, "exec_always", | 79 | return cmd_results_new(CMD_FAILURE, "exec_always", |
80 | "Second fork() failed"); | 80 | "Second fork() failed"); |
diff --git a/sway/config.c b/sway/config.c index ed624bfa..5f6dd7ad 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -87,7 +87,6 @@ void free_config(struct sway_config *config) { | |||
87 | } | 87 | } |
88 | list_free(config->cmd_queue); | 88 | list_free(config->cmd_queue); |
89 | list_free(config->workspace_outputs); | 89 | list_free(config->workspace_outputs); |
90 | list_free(config->pid_workspaces); | ||
91 | if (config->output_configs) { | 90 | if (config->output_configs) { |
92 | for (int i = 0; i < config->output_configs->length; i++) { | 91 | for (int i = 0; i < config->output_configs->length; i++) { |
93 | free_output_config(config->output_configs->items[i]); | 92 | free_output_config(config->output_configs->items[i]); |
@@ -157,7 +156,6 @@ static void config_defaults(struct sway_config *config) { | |||
157 | if (!(config->modes = create_list())) goto cleanup; | 156 | if (!(config->modes = create_list())) goto cleanup; |
158 | if (!(config->bars = create_list())) goto cleanup; | 157 | if (!(config->bars = create_list())) goto cleanup; |
159 | if (!(config->workspace_outputs = create_list())) goto cleanup; | 158 | if (!(config->workspace_outputs = create_list())) goto cleanup; |
160 | if (!(config->pid_workspaces = create_list())) goto cleanup; | ||
161 | if (!(config->criteria = create_list())) goto cleanup; | 159 | if (!(config->criteria = create_list())) goto cleanup; |
162 | if (!(config->no_focus = create_list())) goto cleanup; | 160 | if (!(config->no_focus = create_list())) goto cleanup; |
163 | if (!(config->input_configs = create_list())) goto cleanup; | 161 | if (!(config->input_configs = create_list())) goto cleanup; |
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 62c3abc8..f3e4fef8 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c | |||
@@ -418,9 +418,6 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { | |||
418 | view_init(&xdg_shell_view->view, SWAY_VIEW_XDG_SHELL, &view_impl); | 418 | view_init(&xdg_shell_view->view, SWAY_VIEW_XDG_SHELL, &view_impl); |
419 | xdg_shell_view->view.wlr_xdg_surface = xdg_surface; | 419 | xdg_shell_view->view.wlr_xdg_surface = xdg_surface; |
420 | 420 | ||
421 | // TODO: | ||
422 | // - Look up pid and open on appropriate workspace | ||
423 | |||
424 | xdg_shell_view->map.notify = handle_map; | 421 | xdg_shell_view->map.notify = handle_map; |
425 | wl_signal_add(&xdg_surface->events.map, &xdg_shell_view->map); | 422 | wl_signal_add(&xdg_surface->events.map, &xdg_shell_view->map); |
426 | 423 | ||
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 7fb85410..46fd4769 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c | |||
@@ -409,9 +409,6 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { | |||
409 | view_init(&xdg_shell_v6_view->view, SWAY_VIEW_XDG_SHELL_V6, &view_impl); | 409 | view_init(&xdg_shell_v6_view->view, SWAY_VIEW_XDG_SHELL_V6, &view_impl); |
410 | xdg_shell_v6_view->view.wlr_xdg_surface_v6 = xdg_surface; | 410 | xdg_shell_v6_view->view.wlr_xdg_surface_v6 = xdg_surface; |
411 | 411 | ||
412 | // TODO: | ||
413 | // - Look up pid and open on appropriate workspace | ||
414 | |||
415 | xdg_shell_v6_view->map.notify = handle_map; | 412 | xdg_shell_v6_view->map.notify = handle_map; |
416 | wl_signal_add(&xdg_surface->events.map, &xdg_shell_v6_view->map); | 413 | wl_signal_add(&xdg_surface->events.map, &xdg_shell_v6_view->map); |
417 | 414 | ||
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 2546168b..65d4fcd4 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c | |||
@@ -514,9 +514,6 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { | |||
514 | view_init(&xwayland_view->view, SWAY_VIEW_XWAYLAND, &view_impl); | 514 | view_init(&xwayland_view->view, SWAY_VIEW_XWAYLAND, &view_impl); |
515 | xwayland_view->view.wlr_xwayland_surface = xsurface; | 515 | xwayland_view->view.wlr_xwayland_surface = xsurface; |
516 | 516 | ||
517 | // TODO: | ||
518 | // - Look up pid and open on appropriate workspace | ||
519 | |||
520 | wl_signal_add(&xsurface->events.destroy, &xwayland_view->destroy); | 517 | wl_signal_add(&xsurface->events.destroy, &xwayland_view->destroy); |
521 | xwayland_view->destroy.notify = handle_destroy; | 518 | xwayland_view->destroy.notify = handle_destroy; |
522 | 519 | ||
diff --git a/sway/tree/view.c b/sway/tree/view.c index 9d88d7aa..a55c8a29 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include <wayland-server.h> | 3 | #include <wayland-server.h> |
4 | #include <wlr/render/wlr_renderer.h> | 4 | #include <wlr/render/wlr_renderer.h> |
5 | #include <wlr/types/wlr_output_layout.h> | 5 | #include <wlr/types/wlr_output_layout.h> |
6 | #include <wlr/xwayland.h> | ||
6 | #include "list.h" | 7 | #include "list.h" |
7 | #include "log.h" | 8 | #include "log.h" |
8 | #include "sway/criteria.h" | 9 | #include "sway/criteria.h" |
@@ -561,9 +562,21 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
561 | return; | 562 | return; |
562 | } | 563 | } |
563 | 564 | ||
565 | pid_t pid; | ||
566 | if (view->type == SWAY_VIEW_XWAYLAND) { | ||
567 | struct wlr_xwayland_surface *surf = | ||
568 | wlr_xwayland_surface_from_wlr_surface(wlr_surface); | ||
569 | pid = surf->pid; | ||
570 | } else { | ||
571 | struct wl_client *client = | ||
572 | wl_resource_get_client(wlr_surface->resource); | ||
573 | wl_client_get_credentials(client, &pid, NULL, NULL); | ||
574 | } | ||
575 | |||
564 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 576 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
565 | struct sway_container *focus = | 577 | struct sway_container *target_sibling = |
566 | seat_get_focus_inactive(seat, &root_container); | 578 | seat_get_focus_inactive(seat, &root_container); |
579 | struct sway_container *prev_focus = target_sibling; | ||
567 | struct sway_container *cont = NULL; | 580 | struct sway_container *cont = NULL; |
568 | 581 | ||
569 | // Check if there's any `assign` criteria for the view | 582 | // Check if there's any `assign` criteria for the view |
@@ -577,22 +590,35 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
577 | if (!workspace) { | 590 | if (!workspace) { |
578 | workspace = workspace_create(NULL, criteria->target); | 591 | workspace = workspace_create(NULL, criteria->target); |
579 | } | 592 | } |
580 | focus = seat_get_focus_inactive(seat, workspace); | 593 | prev_focus = target_sibling; |
594 | target_sibling = seat_get_focus_inactive(seat, workspace); | ||
581 | } else { | 595 | } else { |
582 | // CT_ASSIGN_OUTPUT | 596 | // CT_ASSIGN_OUTPUT |
583 | struct sway_container *output = output_by_name(criteria->target); | 597 | struct sway_container *output = output_by_name(criteria->target); |
584 | if (output) { | 598 | if (output) { |
585 | focus = seat_get_focus_inactive(seat, output); | 599 | prev_focus = seat_get_focus_inactive(seat, output); |
586 | } | 600 | } |
587 | } | 601 | } |
588 | } | 602 | } |
603 | list_free(criterias); | ||
604 | |||
605 | if (!workspace) { | ||
606 | workspace = workspace_for_pid(pid); | ||
607 | if (workspace) { | ||
608 | prev_focus = target_sibling; | ||
609 | target_sibling = seat_get_focus_inactive(seat, workspace); | ||
610 | } | ||
611 | } | ||
589 | // If we're about to launch the view into the floating container, then | 612 | // If we're about to launch the view into the floating container, then |
590 | // launch it as a tiled view in the root of the workspace instead. | 613 | // launch it as a tiled view in the root of the workspace instead. |
591 | if (container_is_floating(focus)) { | 614 | if (container_is_floating(target_sibling)) { |
592 | focus = focus->parent->parent; | 615 | if (prev_focus == target_sibling) { |
616 | prev_focus = target_sibling->parent->parent; | ||
617 | } | ||
618 | target_sibling = target_sibling->parent->parent; | ||
593 | } | 619 | } |
594 | list_free(criterias); | 620 | |
595 | cont = container_view_create(focus, view); | 621 | cont = container_view_create(target_sibling, view); |
596 | 622 | ||
597 | view->surface = wlr_surface; | 623 | view->surface = wlr_surface; |
598 | view->swayc = cont; | 624 | view->swayc = cont; |
@@ -615,7 +641,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { | |||
615 | view_set_tiled(view, true); | 641 | view_set_tiled(view, true); |
616 | } | 642 | } |
617 | 643 | ||
618 | if (should_focus(view)) { | 644 | if (should_focus(view) && prev_focus == target_sibling) { |
619 | input_manager_set_focus(input_manager, cont); | 645 | input_manager_set_focus(input_manager, cont); |
620 | if (workspace) { | 646 | if (workspace) { |
621 | workspace_switch(workspace); | 647 | workspace_switch(workspace); |
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 622f01ec..a93d9f44 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include "sway/input/input-manager.h" | 9 | #include "sway/input/input-manager.h" |
10 | #include "sway/input/seat.h" | 10 | #include "sway/input/seat.h" |
11 | #include "sway/ipc-server.h" | 11 | #include "sway/ipc-server.h" |
12 | #include "sway/output.h" | ||
12 | #include "sway/tree/arrange.h" | 13 | #include "sway/tree/arrange.h" |
13 | #include "sway/tree/container.h" | 14 | #include "sway/tree/container.h" |
14 | #include "sway/tree/view.h" | 15 | #include "sway/tree/view.h" |
@@ -529,3 +530,114 @@ void workspace_detect_urgent(struct sway_container *workspace) { | |||
529 | container_damage_whole(workspace); | 530 | container_damage_whole(workspace); |
530 | } | 531 | } |
531 | } | 532 | } |
533 | |||
534 | struct pid_workspace { | ||
535 | pid_t pid; | ||
536 | char *workspace; | ||
537 | struct timespec time_added; | ||
538 | |||
539 | struct sway_container *output; | ||
540 | struct wl_listener output_destroy; | ||
541 | |||
542 | struct wl_list link; | ||
543 | }; | ||
544 | |||
545 | static struct wl_list pid_workspaces; | ||
546 | |||
547 | struct sway_container *workspace_for_pid(pid_t pid) { | ||
548 | if (!pid_workspaces.prev && !pid_workspaces.next) { | ||
549 | wl_list_init(&pid_workspaces); | ||
550 | return NULL; | ||
551 | } | ||
552 | |||
553 | struct sway_container *ws = NULL; | ||
554 | struct pid_workspace *pw = NULL; | ||
555 | |||
556 | wlr_log(WLR_DEBUG, "Looking up workspace for pid %d", pid); | ||
557 | |||
558 | do { | ||
559 | struct pid_workspace *_pw = NULL; | ||
560 | wl_list_for_each(_pw, &pid_workspaces, link) { | ||
561 | if (pid == _pw->pid) { | ||
562 | pw = _pw; | ||
563 | wlr_log(WLR_DEBUG, | ||
564 | "found pid_workspace for pid %d, workspace %s", | ||
565 | pid, pw->workspace); | ||
566 | goto found; | ||
567 | } | ||
568 | } | ||
569 | pid = get_parent_pid(pid); | ||
570 | } while (pid > 1); | ||
571 | found: | ||
572 | |||
573 | if (pw && pw->workspace) { | ||
574 | ws = workspace_by_name(pw->workspace); | ||
575 | |||
576 | if (!ws) { | ||
577 | wlr_log(WLR_DEBUG, | ||
578 | "Creating workspace %s for pid %d because it disappeared", | ||
579 | pw->workspace, pid); | ||
580 | ws = workspace_create(pw->output, pw->workspace); | ||
581 | } | ||
582 | |||
583 | wl_list_remove(&pw->output_destroy.link); | ||
584 | wl_list_remove(&pw->link); | ||
585 | free(pw->workspace); | ||
586 | free(pw); | ||
587 | } | ||
588 | |||
589 | return ws; | ||
590 | } | ||
591 | |||
592 | static void pw_handle_output_destroy(struct wl_listener *listener, void *data) { | ||
593 | struct pid_workspace *pw = wl_container_of(listener, pw, output_destroy); | ||
594 | pw->output = NULL; | ||
595 | } | ||
596 | |||
597 | void workspace_record_pid(pid_t pid) { | ||
598 | wlr_log(WLR_DEBUG, "Recording workspace for process %d", pid); | ||
599 | if (!pid_workspaces.prev && !pid_workspaces.next) { | ||
600 | wl_list_init(&pid_workspaces); | ||
601 | } | ||
602 | |||
603 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
604 | struct sway_container *ws = | ||
605 | seat_get_focus_inactive(seat, &root_container); | ||
606 | if (ws && ws->type != C_WORKSPACE) { | ||
607 | ws = container_parent(ws, C_WORKSPACE); | ||
608 | } | ||
609 | if (!ws) { | ||
610 | wlr_log(WLR_DEBUG, "Bailing out, no workspace"); | ||
611 | return; | ||
612 | } | ||
613 | struct sway_container *output = ws->parent; | ||
614 | if (!output) { | ||
615 | wlr_log(WLR_DEBUG, "Bailing out, no output"); | ||
616 | return; | ||
617 | } | ||
618 | |||
619 | struct timespec now; | ||
620 | clock_gettime(CLOCK_MONOTONIC, &now); | ||
621 | |||
622 | // Remove expired entries | ||
623 | static const int timeout = 60; | ||
624 | struct pid_workspace *old, *_old; | ||
625 | wl_list_for_each_safe(old, _old, &pid_workspaces, link) { | ||
626 | if (now.tv_sec - old->time_added.tv_sec >= timeout) { | ||
627 | wl_list_remove(&old->output_destroy.link); | ||
628 | wl_list_remove(&old->link); | ||
629 | free(old->workspace); | ||
630 | free(old); | ||
631 | } | ||
632 | } | ||
633 | |||
634 | struct pid_workspace *pw = calloc(1, sizeof(struct pid_workspace)); | ||
635 | pw->workspace = strdup(ws->name); | ||
636 | pw->output = output; | ||
637 | pw->pid = pid; | ||
638 | memcpy(&pw->time_added, &now, sizeof(struct timespec)); | ||
639 | pw->output_destroy.notify = pw_handle_output_destroy; | ||
640 | wl_signal_add(&output->sway_output->wlr_output->events.destroy, | ||
641 | &pw->output_destroy); | ||
642 | wl_list_insert(&pid_workspaces, &pw->link); | ||
643 | } | ||