From aabff469c6a960ef89016bce702f3115bcb5eee5 Mon Sep 17 00:00:00 2001 From: Ronan Pigott Date: Sun, 12 Feb 2023 10:57:10 -0700 Subject: [PATCH] commands/exec: enable targeted exec Cause sway's internal launcher contexts to inherit the workspace of the handler context, rather than the focused workspace. This has the same behavior by default, but enables criteria targeted exec commands such as '[workspace=3]' exec foot to launch a client on workspace 3. --- include/sway/desktop/launcher.h | 2 +- sway/commands/exec_always.c | 3 ++- sway/desktop/launcher.c | 15 +++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/sway/desktop/launcher.h b/include/sway/desktop/launcher.h index b7716e82..daaf1616 100644 --- a/include/sway/desktop/launcher.h +++ b/include/sway/desktop/launcher.h @@ -26,7 +26,7 @@ void launcher_ctx_consume(struct launcher_ctx *ctx); void launcher_ctx_destroy(struct launcher_ctx *ctx); -struct launcher_ctx *launcher_ctx_create_internal(void); +struct launcher_ctx *launcher_ctx_create_internal(struct sway_node *node); struct launcher_ctx *launcher_ctx_create( struct wlr_xdg_activation_token_v1 *token, struct sway_node *node); diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index 8fca1909..3b3b8e03 100644 --- a/sway/commands/exec_always.c +++ b/sway/commands/exec_always.c @@ -63,7 +63,8 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) { } pid_t pid, child; - struct launcher_ctx *ctx = launcher_ctx_create_internal(); + struct sway_workspace *ws = config->handler_context.workspace; + struct launcher_ctx *ctx = launcher_ctx_create_internal(&ws->node); // Fork process if ((pid = fork()) == 0) { // Fork child process again diff --git a/sway/desktop/launcher.c b/sway/desktop/launcher.c index b666da1e..e96ebdc8 100644 --- a/sway/desktop/launcher.c +++ b/sway/desktop/launcher.c @@ -228,19 +228,22 @@ struct launcher_ctx *launcher_ctx_create(struct wlr_xdg_activation_token_v1 *tok } // Creates a context with a new token for the internal launcher -struct launcher_ctx *launcher_ctx_create_internal() { +struct launcher_ctx *launcher_ctx_create_internal(struct sway_node *node) { struct sway_seat *seat = input_manager_current_seat(); - struct sway_workspace *ws = seat_get_focused_workspace(seat); - if (!ws) { - sway_log(SWAY_DEBUG, "Failed to create launch context. No workspace."); - return NULL; + if (!node) { + struct sway_workspace *ws = seat_get_focused_workspace(seat); + if (!ws) { + sway_log(SWAY_DEBUG, "Failed to create launch context. No workspace."); + return NULL; + } + node = &ws->node; } struct wlr_xdg_activation_token_v1 *token = wlr_xdg_activation_token_v1_create(server.xdg_activation_v1); token->seat = seat->wlr_seat; - struct launcher_ctx *ctx = launcher_ctx_create(token, &ws->node); + struct launcher_ctx *ctx = launcher_ctx_create(token, node); if (!ctx) { wlr_xdg_activation_token_v1_destroy(token); return NULL;