mirror of
https://github.com/swaywm/sway.git
synced 2026-04-20 06:47:03 -04:00
Merge 488aa551f9 into 81246fc6dc
This commit is contained in:
commit
21e36ff199
2 changed files with 57 additions and 8 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,13 +47,22 @@ 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 matched_ids = false;
|
||||||
bool no_startup_id = false;
|
bool no_startup_id = false;
|
||||||
if (strcmp(argv[0], "--no-startup-id") == 0) {
|
int argv_counter = -1;
|
||||||
|
while (argc > 0 && has_prefix(*argv, "--")) {
|
||||||
|
if (strcmp(argv[0], "--matched-ids") == 0) {
|
||||||
|
matched_ids = true;
|
||||||
|
} else if (strcmp(argv[0], "--no-startup-id") == 0) {
|
||||||
no_startup_id = true;
|
no_startup_id = true;
|
||||||
--argc; ++argv;
|
} else {
|
||||||
if ((error = checkarg(argc, argv[-1], EXPECTED_AT_LEAST, 1))) {
|
return cmd_results_new(CMD_INVALID, "Unrecognized argument '%s'", *argv);
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
--argc; ++argv; --argv_counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((error = checkarg(argc, argv[argv_counter], EXPECTED_AT_LEAST, 1))) {
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 1 && (argv[0][0] == '\'' || argv[0][0] == '"')) {
|
if (argc == 1 && (argv[0][0] == '\'' || argv[0][0] == '"')) {
|
||||||
|
|
@ -61,6 +89,22 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!matched_ids || config->handler_context.node == NULL) {
|
||||||
|
goto no_con_id_export;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sway_node *node = config->handler_context.node;
|
||||||
|
export_id("SWAY_EXEC_CON_ID", node->id);
|
||||||
|
#if WLR_HAS_XWAYLAND
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
no_con_id_export:
|
||||||
|
|
||||||
execlp("sh", "sh", "-c", cmd, (void*)NULL);
|
execlp("sh", "sh", "-c", cmd, (void*)NULL);
|
||||||
sway_log_errno(SWAY_ERROR, "execve failed");
|
sway_log_errno(SWAY_ERROR, "execve failed");
|
||||||
_exit(0); // Close child process
|
_exit(0); // Close child process
|
||||||
|
|
@ -87,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,10 +704,14 @@ 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* <shell command>
|
*exec* [--matched-ids] [--no-startup-id] <shell command>
|
||||||
Executes _shell command_ with sh.
|
Executes _shell command_ with sh. With _--matched-ids_, It exports the
|
||||||
|
matched container id to env variable SWAY_EXEC_CON_ID and, if available,
|
||||||
|
X11 window id to env variable I3_WINDOW_ID in case of a criteria match or
|
||||||
|
the focused node otherwise. The _--no_startup_id_ option prevents exporting
|
||||||
|
of DESKTOP_STARTUP_ID.
|
||||||
|
|
||||||
*exec_always* <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*.
|
||||||
|
|
||||||
*floating_maximum_size* <width> x <height>
|
*floating_maximum_size* <width> x <height>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue