diff options
Diffstat (limited to 'sway/desktop/xwayland.c')
| -rw-r--r-- | sway/desktop/xwayland.c | 62 | 
1 files changed, 57 insertions, 5 deletions
| diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 40288f97..e15a3341 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -5,7 +5,9 @@  #include <wayland-server-core.h>  #include <wlr/types/wlr_output_layout.h>  #include <wlr/types/wlr_output.h> +#include <wlr/types/wlr_xdg_activation_v1.h>  #include <wlr/xwayland.h> +#include <xcb/xcb_icccm.h>  #include "log.h"  #include "sway/desktop.h"  #include "sway/desktop/transaction.h" @@ -15,6 +17,7 @@  #include "sway/output.h"  #include "sway/tree/arrange.h"  #include "sway/tree/container.h" +#include "sway/server.h"  #include "sway/tree/view.h"  #include "sway/tree/workspace.h" @@ -121,6 +124,20 @@ static void unmanaged_handle_unmap(struct wl_listener *listener, void *data) {  	}  } +static void unmanaged_handle_request_activate(struct wl_listener *listener, void *data) { +	struct wlr_xwayland_surface *xsurface = data; +	if (!xsurface->mapped) { +		return; +	} +	struct sway_seat *seat = input_manager_current_seat(); +	struct sway_container *focus = seat_get_focused_container(seat); +	if (focus && focus->view && focus->view->pid != xsurface->pid) { +		return; +	} + +	seat_set_focus_surface(seat, xsurface->surface, false); +} +  static void unmanaged_handle_destroy(struct wl_listener *listener, void *data) {  	struct sway_xwayland_unmanaged *surface =  		wl_container_of(listener, surface, destroy); @@ -129,6 +146,7 @@ static void unmanaged_handle_destroy(struct wl_listener *listener, void *data) {  	wl_list_remove(&surface->unmap.link);  	wl_list_remove(&surface->destroy.link);  	wl_list_remove(&surface->override_redirect.link); +	wl_list_remove(&surface->request_activate.link);  	free(surface);  } @@ -176,6 +194,8 @@ static struct sway_xwayland_unmanaged *create_unmanaged(  	surface->destroy.notify = unmanaged_handle_destroy;  	wl_signal_add(&xsurface->events.set_override_redirect, &surface->override_redirect);  	surface->override_redirect.notify = unmanaged_handle_override_redirect; +	wl_signal_add(&xsurface->events.request_activate, &surface->request_activate); +	surface->request_activate.notify = unmanaged_handle_request_activate;  	return surface;  } @@ -294,7 +314,7 @@ static bool wants_floating(struct sway_view *view) {  		}  	} -	struct wlr_xwayland_surface_size_hints *size_hints = surface->size_hints; +	xcb_size_hints_t *size_hints = surface->size_hints;  	if (size_hints != NULL &&  			size_hints->min_width > 0 && size_hints->min_height > 0 &&  			(size_hints->max_width == size_hints->min_width || @@ -348,7 +368,7 @@ static void destroy(struct sway_view *view) {  static void get_constraints(struct sway_view *view, double *min_width,  		double *max_width, double *min_height, double *max_height) {  	struct wlr_xwayland_surface *surface = view->wlr_xwayland_surface; -	struct wlr_xwayland_surface_size_hints *size_hints = surface->size_hints; +	xcb_size_hints_t *size_hints = surface->size_hints;  	if (size_hints == NULL) {  		*min_width = DBL_MIN; @@ -448,6 +468,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) {  	wl_list_remove(&xwayland_view->set_title.link);  	wl_list_remove(&xwayland_view->set_class.link);  	wl_list_remove(&xwayland_view->set_role.link); +	wl_list_remove(&xwayland_view->set_startup_id.link);  	wl_list_remove(&xwayland_view->set_window_type.link);  	wl_list_remove(&xwayland_view->set_hints.link);  	wl_list_remove(&xwayland_view->set_decorations.link); @@ -577,7 +598,8 @@ static void handle_request_move(struct wl_listener *listener, void *data) {  	if (!xsurface->mapped) {  		return;  	} -	if (!container_is_floating(view->container)) { +	if (!container_is_floating(view->container) || +			view->container->pending.fullscreen_mode) {  		return;  	}  	struct sway_seat *seat = input_manager_current_seat(); @@ -647,6 +669,31 @@ static void handle_set_role(struct wl_listener *listener, void *data) {  	view_execute_criteria(view);  } +static void handle_set_startup_id(struct wl_listener *listener, void *data) { +	struct sway_xwayland_view *xwayland_view = +		wl_container_of(listener, xwayland_view, set_startup_id); +	struct sway_view *view = &xwayland_view->view; +	struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; +	if (xsurface->startup_id == NULL) { +		return; +	} + +	struct wlr_xdg_activation_token_v1 *token = +		wlr_xdg_activation_v1_find_token( +				server.xdg_activation_v1, xsurface->startup_id); +	if (token == NULL) { +		// Tried to activate with an unknown or expired token +		return; +	} + +	struct launcher_ctx *ctx = token->data; +	if (token->data == NULL) { +		// TODO: support external launchers in X +		return; +	} +	view_assign_ctx(view, ctx); +} +  static void handle_set_window_type(struct wl_listener *listener, void *data) {  	struct sway_xwayland_view *xwayland_view =  		wl_container_of(listener, xwayland_view, set_window_type); @@ -666,14 +713,15 @@ static void handle_set_hints(struct wl_listener *listener, void *data) {  	if (!xsurface->mapped) {  		return;  	} -	if (!xsurface->hints_urgency && view->urgent_timer) { +	const bool hints_urgency = xcb_icccm_wm_hints_get_urgency(xsurface->hints); +	if (!hints_urgency && view->urgent_timer) {  		// The view is in the timeout period. We'll ignore the request to  		// unset urgency so that the view remains urgent until the timer clears  		// it.  		return;  	}  	if (view->allow_request_urgent) { -		view_set_urgent(view, (bool)xsurface->hints_urgency); +		view_set_urgent(view, hints_urgency);  	}  } @@ -731,6 +779,10 @@ struct sway_xwayland_view *create_xwayland_view(struct wlr_xwayland_surface *xsu  	wl_signal_add(&xsurface->events.set_role, &xwayland_view->set_role);  	xwayland_view->set_role.notify = handle_set_role; +	wl_signal_add(&xsurface->events.set_startup_id, +			&xwayland_view->set_startup_id); +	xwayland_view->set_startup_id.notify = handle_set_startup_id; +  	wl_signal_add(&xsurface->events.set_window_type,  			&xwayland_view->set_window_type);  	xwayland_view->set_window_type.notify = handle_set_window_type; | 
