aboutsummaryrefslogtreecommitdiff
path: root/sway/tree/view.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/view.c')
-rw-r--r--sway/tree/view.c59
1 files changed, 49 insertions, 10 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 9d88d7aa..beeb8144 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -3,6 +3,10 @@
#include <wayland-server.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_output_layout.h>
+#include "config.h"
+#ifdef HAVE_XWAYLAND
+#include <wlr/xwayland.h>
+#endif
#include "list.h"
#include "log.h"
#include "sway/criteria.h"
@@ -107,14 +111,14 @@ const char *view_get_instance(struct sway_view *view) {
}
return NULL;
}
-
+#ifdef HAVE_XWAYLAND
uint32_t view_get_x11_window_id(struct sway_view *view) {
if (view->impl->get_int_prop) {
return view->impl->get_int_prop(view, VIEW_PROP_X11_WINDOW_ID);
}
return 0;
}
-
+#endif
const char *view_get_window_role(struct sway_view *view) {
if (view->impl->get_string_prop) {
return view->impl->get_string_prop(view, VIEW_PROP_WINDOW_ROLE);
@@ -135,8 +139,10 @@ const char *view_get_shell(struct sway_view *view) {
return "xdg_shell_v6";
case SWAY_VIEW_XDG_SHELL:
return "xdg_shell";
+#ifdef HAVE_XWAYLAND
case SWAY_VIEW_XWAYLAND:
return "xwayland";
+#endif
}
return "unknown";
}
@@ -561,9 +567,27 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
return;
}
+ pid_t pid;
+#ifdef HAVE_XWAYLAND
+ if (view->type == SWAY_VIEW_XWAYLAND) {
+ struct wlr_xwayland_surface *surf =
+ wlr_xwayland_surface_from_wlr_surface(wlr_surface);
+ pid = surf->pid;
+ } else {
+ struct wl_client *client =
+ wl_resource_get_client(wlr_surface->resource);
+ wl_client_get_credentials(client, &pid, NULL, NULL);
+ }
+#else
+ struct wl_client *client =
+ wl_resource_get_client(wlr_surface->resource);
+ wl_client_get_credentials(client, &pid, NULL, NULL);
+#endif
+
struct sway_seat *seat = input_manager_current_seat(input_manager);
- struct sway_container *focus =
+ struct sway_container *target_sibling =
seat_get_focus_inactive(seat, &root_container);
+ struct sway_container *prev_focus = target_sibling;
struct sway_container *cont = NULL;
// Check if there's any `assign` criteria for the view
@@ -577,22 +601,35 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
if (!workspace) {
workspace = workspace_create(NULL, criteria->target);
}
- focus = seat_get_focus_inactive(seat, workspace);
+ prev_focus = target_sibling;
+ target_sibling = seat_get_focus_inactive(seat, workspace);
} else {
// CT_ASSIGN_OUTPUT
struct sway_container *output = output_by_name(criteria->target);
if (output) {
- focus = seat_get_focus_inactive(seat, output);
+ prev_focus = seat_get_focus_inactive(seat, output);
}
}
}
+ list_free(criterias);
+
+ if (!workspace) {
+ workspace = workspace_for_pid(pid);
+ if (workspace) {
+ prev_focus = target_sibling;
+ target_sibling = seat_get_focus_inactive(seat, workspace);
+ }
+ }
// If we're about to launch the view into the floating container, then
// launch it as a tiled view in the root of the workspace instead.
- if (container_is_floating(focus)) {
- focus = focus->parent->parent;
+ if (container_is_floating(target_sibling)) {
+ if (prev_focus == target_sibling) {
+ prev_focus = target_sibling->parent->parent;
+ }
+ target_sibling = target_sibling->parent->parent;
}
- list_free(criterias);
- cont = container_view_create(focus, view);
+
+ cont = container_view_create(target_sibling, view);
view->surface = wlr_surface;
view->swayc = cont;
@@ -615,7 +652,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
view_set_tiled(view, true);
}
- if (should_focus(view)) {
+ if (should_focus(view) && prev_focus == target_sibling) {
input_manager_set_focus(input_manager, cont);
if (workspace) {
workspace_switch(workspace);
@@ -799,11 +836,13 @@ struct sway_view *view_from_wlr_surface(struct wlr_surface *wlr_surface) {
wlr_xdg_surface_v6_from_wlr_surface(wlr_surface);
return view_from_wlr_xdg_surface_v6(xdg_surface_v6);
}
+#ifdef HAVE_XWAYLAND
if (wlr_surface_is_xwayland_surface(wlr_surface)) {
struct wlr_xwayland_surface *xsurface =
wlr_xwayland_surface_from_wlr_surface(wlr_surface);
return view_from_wlr_xwayland_surface(xsurface);
}
+#endif
if (wlr_surface_is_subsurface(wlr_surface)) {
struct wlr_subsurface *subsurface =
wlr_subsurface_from_wlr_surface(wlr_surface);