aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/view.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-06-26 20:32:09 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-07-01 09:58:18 -0400
commitacd79e1505c06089e4fb9fb6c0c6e1d351ba9176 (patch)
tree9f677ebac9604075e3138788fb72d6db423e1f17 /sway/tree/view.c
parentMerge pull request #2180 from martinetd/xdg_fullscreen (diff)
downloadsway-acd79e1505c06089e4fb9fb6c0c6e1d351ba9176.tar.gz
sway-acd79e1505c06089e4fb9fb6c0c6e1d351ba9176.tar.zst
sway-acd79e1505c06089e4fb9fb6c0c6e1d351ba9176.zip
Implement pid->workspace tracking
When you spawn a process with the exec command, sway now notes the workspace you had focused and the pid of the child process, then assigns that workspace to the child when its window appears. Some of this is carried over from sway 0.15, but with some major refactoring and centralization of state.
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r--sway/tree/view.c43
1 files changed, 34 insertions, 9 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 06e9edc5..24fb6864 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"
@@ -492,9 +493,21 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
492 return; 493 return;
493 } 494 }
494 495
496 pid_t pid;
497 if (view->type == SWAY_VIEW_XWAYLAND) {
498 struct wlr_xwayland_surface *surf =
499 wlr_xwayland_surface_from_wlr_surface(wlr_surface);
500 pid = surf->pid;
501 } else {
502 struct wl_client *client =
503 wl_resource_get_client(wlr_surface->resource);
504 wl_client_get_credentials(client, &pid, NULL, NULL);
505 }
506
495 struct sway_seat *seat = input_manager_current_seat(input_manager); 507 struct sway_seat *seat = input_manager_current_seat(input_manager);
496 struct sway_container *focus = 508 struct sway_container *target_sibling =
497 seat_get_focus_inactive(seat, &root_container); 509 seat_get_focus_inactive(seat, &root_container);
510 struct sway_container *prev_focus = target_sibling;
498 struct sway_container *cont = NULL; 511 struct sway_container *cont = NULL;
499 512
500 // Check if there's any `assign` criteria for the view 513 // Check if there's any `assign` criteria for the view
@@ -508,18 +521,31 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
508 if (!workspace) { 521 if (!workspace) {
509 workspace = workspace_create(NULL, criteria->target); 522 workspace = workspace_create(NULL, criteria->target);
510 } 523 }
511 focus = seat_get_focus_inactive(seat, workspace); 524 prev_focus = target_sibling;
525 target_sibling = seat_get_focus_inactive(seat, workspace);
512 } else { 526 } else {
513 // TODO: CT_ASSIGN_OUTPUT 527 // TODO: CT_ASSIGN_OUTPUT
514 } 528 }
515 } 529 }
530 list_free(criterias);
531
532 if (!workspace) {
533 workspace = workspace_for_pid(pid);
534 if (workspace) {
535 prev_focus = target_sibling;
536 target_sibling = seat_get_focus_inactive(seat, workspace);
537 }
538 }
516 // If we're about to launch the view into the floating container, then 539 // If we're about to launch the view into the floating container, then
517 // launch it as a tiled view in the root of the workspace instead. 540 // launch it as a tiled view in the root of the workspace instead.
518 if (container_is_floating(focus)) { 541 if (container_is_floating(target_sibling)) {
519 focus = focus->parent->parent; 542 if (prev_focus == target_sibling) {
543 prev_focus = target_sibling->parent->parent;
544 }
545 target_sibling = target_sibling->parent->parent;
520 } 546 }
521 free(criterias); 547
522 cont = container_view_create(focus, view); 548 cont = container_view_create(target_sibling, view);
523 549
524 view->surface = wlr_surface; 550 view->surface = wlr_surface;
525 view->swayc = cont; 551 view->swayc = cont;
@@ -538,9 +564,8 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
538 container_set_floating(view->swayc, true); 564 container_set_floating(view->swayc, true);
539 } 565 }
540 566
541 input_manager_set_focus(input_manager, cont); 567 if (prev_focus == target_sibling) {
542 if (workspace) { 568 input_manager_set_focus(input_manager, cont);
543 workspace_switch(workspace);
544 } 569 }
545 570
546 view_update_title(view, false); 571 view_update_title(view, false);