summaryrefslogtreecommitdiffstats
path: root/sway/tree/view.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-07-24 14:44:01 -0400
committerLibravatar GitHub <noreply@github.com>2018-07-24 14:44:01 -0400
commit817d37c95032946a2e508fcc33cfa5c7ed65cc0d (patch)
tree69fb79348eaff481fabaee4c2bb25991487d438b /sway/tree/view.c
parentMerge pull request #2346 from RyanDwyer/fix-crash-on-click (diff)
parentAddress @emersion's review comments (diff)
downloadsway-817d37c95032946a2e508fcc33cfa5c7ed65cc0d.tar.gz
sway-817d37c95032946a2e508fcc33cfa5c7ed65cc0d.tar.zst
sway-817d37c95032946a2e508fcc33cfa5c7ed65cc0d.zip
Merge pull request #2165 from swaywm/pid-workspaces
Implement pid->workspace tracking
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r--sway/tree/view.c42
1 files changed, 34 insertions, 8 deletions
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);