mirror of
https://github.com/swaywm/sway.git
synced 2026-05-02 06:46:23 -04:00
exec: use X11 window id for I3_WINDOW_ID
This commit is contained in:
parent
fb0fc6a542
commit
488aa551f9
2 changed files with 40 additions and 26 deletions
|
|
@ -10,10 +10,29 @@
|
||||||
#include "sway/desktop/launcher.h"
|
#include "sway/desktop/launcher.h"
|
||||||
#include "sway/tree/container.h"
|
#include "sway/tree/container.h"
|
||||||
#include "sway/tree/root.h"
|
#include "sway/tree/root.h"
|
||||||
|
#include "sway/tree/view.h"
|
||||||
#include "sway/tree/workspace.h"
|
#include "sway/tree/workspace.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "stringop.h"
|
#include "stringop.h"
|
||||||
|
|
||||||
|
static void export_id(const char *env_var_name, size_t id) {
|
||||||
|
int id_len = snprintf(NULL, 0, "%zu", id);
|
||||||
|
if (id_len < 0) {
|
||||||
|
sway_log(SWAY_ERROR, "Unable to determine buffer length for %s", env_var_name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// accommodate \0
|
||||||
|
id_len++;
|
||||||
|
char* id_str = malloc(id_len);
|
||||||
|
if (!id_str) {
|
||||||
|
sway_log(SWAY_ERROR, "Unable to allocate buffer for %s", env_var_name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
snprintf(id_str, id_len, "%zu", id);
|
||||||
|
setenv(env_var_name, id_str, 1);
|
||||||
|
free(id_str);
|
||||||
|
}
|
||||||
|
|
||||||
struct cmd_results *cmd_exec_validate(int argc, char **argv) {
|
struct cmd_results *cmd_exec_validate(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
if ((error = checkarg(argc, argv[-1], EXPECTED_AT_LEAST, 1))) {
|
if ((error = checkarg(argc, argv[-1], EXPECTED_AT_LEAST, 1))) {
|
||||||
|
|
@ -28,12 +47,12 @@ struct cmd_results *cmd_exec_validate(int argc, char **argv) {
|
||||||
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_matched_container_id = false;
|
bool matched_ids = false;
|
||||||
bool no_startup_id = false;
|
bool no_startup_id = false;
|
||||||
int argv_counter = -1;
|
int argv_counter = -1;
|
||||||
while (argc > 0 && has_prefix(*argv, "--")) {
|
while (argc > 0 && has_prefix(*argv, "--")) {
|
||||||
if (strcmp(argv[0], "--no-matched-container-id") == 0) {
|
if (strcmp(argv[0], "--matched-ids") == 0) {
|
||||||
no_matched_container_id = true;
|
matched_ids = true;
|
||||||
} else if (strcmp(argv[0], "--no-startup-id") == 0) {
|
} else if (strcmp(argv[0], "--no-startup-id") == 0) {
|
||||||
no_startup_id = true;
|
no_startup_id = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -70,26 +89,20 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (no_matched_container_id || config->handler_context.node == NULL) {
|
if (!matched_ids || config->handler_context.node == NULL) {
|
||||||
goto no_con_id_export;
|
goto no_con_id_export;
|
||||||
}
|
}
|
||||||
size_t con_id = config->handler_context.node->id;
|
|
||||||
int con_id_len = snprintf(NULL, 0, "%zu", con_id);
|
struct sway_node *node = config->handler_context.node;
|
||||||
if (con_id_len < 0) {
|
export_id("SWAY_EXEC_CON_ID", node->id);
|
||||||
sway_log(SWAY_ERROR, "Unable to determine buffer length for SWAY_EXEC_CON_ID");
|
#if WLR_HAS_XWAYLAND
|
||||||
goto no_con_id_export;
|
if (node->type == N_CONTAINER &&
|
||||||
|
node->sway_container->view != NULL &&
|
||||||
|
node->sway_container->view->type == SWAY_VIEW_XWAYLAND) {
|
||||||
|
export_id("I3_WINDOW_ID", view_get_x11_window_id(node->sway_container->view));
|
||||||
}
|
}
|
||||||
// accommodate \0
|
#endif
|
||||||
con_id_len++;
|
|
||||||
char* con_id_str = malloc(con_id_len);
|
|
||||||
if (!con_id_str) {
|
|
||||||
sway_log(SWAY_ERROR, "Unable to allocate buffer for SWAY_EXEC_CON_ID");
|
|
||||||
goto no_con_id_export;
|
|
||||||
}
|
|
||||||
snprintf(con_id_str, con_id_len, "%zu", con_id);
|
|
||||||
setenv("SWAY_EXEC_CON_ID", con_id_str, 1);
|
|
||||||
setenv("I3_WINDOW_ID", con_id_str, 1);
|
|
||||||
free(con_id_str);
|
|
||||||
no_con_id_export:
|
no_con_id_export:
|
||||||
|
|
||||||
execlp("sh", "sh", "-c", cmd, (void*)NULL);
|
execlp("sh", "sh", "-c", cmd, (void*)NULL);
|
||||||
|
|
@ -118,3 +131,4 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
return cmd_exec_process(argc, argv);
|
return cmd_exec_process(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -704,12 +704,12 @@ The default colors are:
|
||||||
windows that are spawned in floating mode, not windows that become floating
|
windows that are spawned in floating mode, not windows that become floating
|
||||||
afterwards.
|
afterwards.
|
||||||
|
|
||||||
*exec* [--matched-container-id] [--no-startup-id] <shell command>
|
*exec* [--matched-ids] [--no-startup-id] <shell command>
|
||||||
Executes _shell command_ with sh. It exports the matched container id to env
|
Executes _shell command_ with sh. With _--matched-ids_, It exports the
|
||||||
variables I3_WINDOW_ID and SWAY_EXEC_CON_ID in case of a criteria match or
|
matched container id to env variable SWAY_EXEC_CON_ID and, if available,
|
||||||
the focused node otherwise, unless the _--no-matched-container-id_ option
|
X11 window id to env variable I3_WINDOW_ID in case of a criteria match or
|
||||||
is set. The _--no_startup_id_ option prevents exporting of
|
the focused node otherwise. The _--no_startup_id_ option prevents exporting
|
||||||
DESKTOP_STARTUP_ID.
|
of DESKTOP_STARTUP_ID.
|
||||||
|
|
||||||
*exec_always* [--matched-container-id] [--no-startup-id] <shell command>
|
*exec_always* [--matched-container-id] [--no-startup-id] <shell command>
|
||||||
Like *exec*, but the shell command will be executed _again_ after *reload*.
|
Like *exec*, but the shell command will be executed _again_ after *reload*.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue