launcher: export X startup ids and use them for workspace matching

(cherry picked from commit 28fda4c0d3)
This commit is contained in:
Ronan Pigott 2022-11-16 15:50:34 -07:00 committed by Simon Ser
parent 97423ca9c7
commit d5872d0880
3 changed files with 43 additions and 1 deletions

View File

@ -156,6 +156,7 @@ struct sway_xwayland_view {
struct wl_listener set_title; struct wl_listener set_title;
struct wl_listener set_class; struct wl_listener set_class;
struct wl_listener set_role; struct wl_listener set_role;
struct wl_listener set_startup_id;
struct wl_listener set_window_type; struct wl_listener set_window_type;
struct wl_listener set_hints; struct wl_listener set_hints;
struct wl_listener set_decorations; struct wl_listener set_decorations;

View File

@ -32,11 +32,17 @@ static void export_xdga_token(struct launcher_ctx *ctx) {
setenv("XDG_ACTIVATION_TOKEN", token, 1); setenv("XDG_ACTIVATION_TOKEN", token, 1);
} }
static void export_startup_id(struct launcher_ctx *ctx) {
const char *token = launcher_ctx_get_token_name(ctx);
setenv("DESKTOP_STARTUP_ID", token, 1);
}
struct cmd_results *cmd_exec_process(int argc, char **argv) { struct cmd_results *cmd_exec_process(int argc, char **argv) {
struct cmd_results *error = NULL; struct cmd_results *error = NULL;
char *cmd = NULL; char *cmd = NULL;
bool no_startup_id = false;
if (strcmp(argv[0], "--no-startup-id") == 0) { if (strcmp(argv[0], "--no-startup-id") == 0) {
sway_log(SWAY_INFO, "exec switch '--no-startup-id' not supported, ignored."); no_startup_id = true;
--argc; ++argv; --argc; ++argv;
if ((error = checkarg(argc, argv[-1], EXPECTED_AT_LEAST, 1))) { if ((error = checkarg(argc, argv[-1], EXPECTED_AT_LEAST, 1))) {
return error; return error;
@ -74,6 +80,9 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) {
if (ctx) { if (ctx) {
export_xdga_token(ctx); export_xdga_token(ctx);
} }
if (ctx && !no_startup_id) {
export_startup_id(ctx);
}
execlp("sh", "sh", "-c", cmd, (void *)NULL); execlp("sh", "sh", "-c", cmd, (void *)NULL);
sway_log_errno(SWAY_ERROR, "execlp failed"); sway_log_errno(SWAY_ERROR, "execlp failed");
_exit(1); _exit(1);

View File

@ -5,6 +5,7 @@
#include <wayland-server-core.h> #include <wayland-server-core.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_xdg_activation_v1.h>
#include <wlr/xwayland.h> #include <wlr/xwayland.h>
#include <xcb/xcb_icccm.h> #include <xcb/xcb_icccm.h>
#include "log.h" #include "log.h"
@ -16,6 +17,7 @@
#include "sway/output.h" #include "sway/output.h"
#include "sway/tree/arrange.h" #include "sway/tree/arrange.h"
#include "sway/tree/container.h" #include "sway/tree/container.h"
#include "sway/server.h"
#include "sway/tree/view.h" #include "sway/tree/view.h"
#include "sway/tree/workspace.h" #include "sway/tree/workspace.h"
@ -466,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_title.link);
wl_list_remove(&xwayland_view->set_class.link); wl_list_remove(&xwayland_view->set_class.link);
wl_list_remove(&xwayland_view->set_role.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_window_type.link);
wl_list_remove(&xwayland_view->set_hints.link); wl_list_remove(&xwayland_view->set_hints.link);
wl_list_remove(&xwayland_view->set_decorations.link); wl_list_remove(&xwayland_view->set_decorations.link);
@ -666,6 +669,31 @@ static void handle_set_role(struct wl_listener *listener, void *data) {
view_execute_criteria(view); 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) { static void handle_set_window_type(struct wl_listener *listener, void *data) {
struct sway_xwayland_view *xwayland_view = struct sway_xwayland_view *xwayland_view =
wl_container_of(listener, xwayland_view, set_window_type); wl_container_of(listener, xwayland_view, set_window_type);
@ -751,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); wl_signal_add(&xsurface->events.set_role, &xwayland_view->set_role);
xwayland_view->set_role.notify = handle_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, wl_signal_add(&xsurface->events.set_window_type,
&xwayland_view->set_window_type); &xwayland_view->set_window_type);
xwayland_view->set_window_type.notify = handle_set_window_type; xwayland_view->set_window_type.notify = handle_set_window_type;