mirror of
https://github.com/gwenhael-le-moine/sway-patched-tray-menu.git
synced 2025-01-30 08:35:02 +01:00
take seat param for handle_command and rename
This commit is contained in:
parent
6becfc1431
commit
ac8269d536
5 changed files with 32 additions and 25 deletions
|
@ -46,9 +46,9 @@ struct cmd_results *checkarg(int argc, const char *name,
|
||||||
enum expected_args type, int val);
|
enum expected_args type, int val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse and handles a command.
|
* Parse and executes a command.
|
||||||
*/
|
*/
|
||||||
struct cmd_results *handle_command(char *command);
|
struct cmd_results *execute_command(char *command, struct sway_seat *seat);
|
||||||
/**
|
/**
|
||||||
* Parse and handles a command during config file loading.
|
* Parse and handles a command during config file loading.
|
||||||
*
|
*
|
||||||
|
|
|
@ -198,7 +198,7 @@ static struct cmd_handler *find_handler(char *line, enum cmd_status block) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd_results *handle_command(char *_exec) {
|
struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
|
||||||
// Even though this function will process multiple commands we will only
|
// Even though this function will process multiple commands we will only
|
||||||
// return the last error, if any (for now). (Since we have access to an
|
// return the last error, if any (for now). (Since we have access to an
|
||||||
// error string we could e.g. concatenate all errors there.)
|
// error string we could e.g. concatenate all errors there.)
|
||||||
|
@ -209,6 +209,16 @@ struct cmd_results *handle_command(char *_exec) {
|
||||||
char *cmd;
|
char *cmd;
|
||||||
list_t *containers = NULL;
|
list_t *containers = NULL;
|
||||||
|
|
||||||
|
if (seat == NULL) {
|
||||||
|
// passing a NULL seat means we just pick the default seat
|
||||||
|
seat = sway_input_manager_get_default_seat(input_manager);
|
||||||
|
if (!sway_assert(seat, "could not find a seat to run the command on")) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config->handler_context.seat = seat;
|
||||||
|
|
||||||
head = exec;
|
head = exec;
|
||||||
do {
|
do {
|
||||||
// Extract criteria (valid for this command list only).
|
// Extract criteria (valid for this command list only).
|
||||||
|
@ -278,24 +288,22 @@ struct cmd_results *handle_command(char *_exec) {
|
||||||
if (!has_criteria) {
|
if (!has_criteria) {
|
||||||
// without criteria, the command acts upon the focused
|
// without criteria, the command acts upon the focused
|
||||||
// container
|
// container
|
||||||
struct sway_seat *seat = config->handler_context.seat;
|
config->handler_context.current_container =
|
||||||
if (!seat) {
|
sway_seat_get_focus_inactive(seat, &root_container);
|
||||||
seat = sway_input_manager_get_default_seat(input_manager);
|
if (!sway_assert(config->handler_context.current_container,
|
||||||
|
"could not get focus-inactive for root container")) {
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
if (seat) {
|
struct cmd_results *res = handler->handle(argc-1, argv+1);
|
||||||
config->handler_context.current_container =
|
if (res->status != CMD_SUCCESS) {
|
||||||
sway_seat_get_focus(seat);
|
free_argv(argc, argv);
|
||||||
struct cmd_results *res = handler->handle(argc-1, argv+1);
|
if (results) {
|
||||||
if (res->status != CMD_SUCCESS) {
|
free_cmd_results(results);
|
||||||
free_argv(argc, argv);
|
|
||||||
if (results) {
|
|
||||||
free_cmd_results(results);
|
|
||||||
}
|
|
||||||
results = res;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
free_cmd_results(res);
|
results = res;
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
free_cmd_results(res);
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < containers->length; ++i) {
|
for (int i = 0; i < containers->length; ++i) {
|
||||||
config->handler_context.current_container = containers->items[i];
|
config->handler_context.current_container = containers->items[i];
|
||||||
|
@ -322,13 +330,13 @@ cleanup:
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is like handle_command above, except:
|
// this is like execute_command above, except:
|
||||||
// 1) it ignores empty commands (empty lines)
|
// 1) it ignores empty commands (empty lines)
|
||||||
// 2) it does variable substitution
|
// 2) it does variable substitution
|
||||||
// 3) it doesn't split commands (because the multiple commands are supposed to
|
// 3) it doesn't split commands (because the multiple commands are supposed to
|
||||||
// be chained together)
|
// be chained together)
|
||||||
// 4) handle_command handles all state internally while config_command has some
|
// 4) execute_command handles all state internally while config_command has
|
||||||
// state handled outside (notably the block mode, in read_config)
|
// some state handled outside (notably the block mode, in read_config)
|
||||||
struct cmd_results *config_command(char *exec, enum cmd_status block) {
|
struct cmd_results *config_command(char *exec, enum cmd_status block) {
|
||||||
struct cmd_results *results = NULL;
|
struct cmd_results *results = NULL;
|
||||||
int argc;
|
int argc;
|
||||||
|
|
|
@ -95,7 +95,7 @@ static void keyboard_execute_command(struct sway_keyboard *keyboard,
|
||||||
binding->command);
|
binding->command);
|
||||||
config_clear_handler_context(config);
|
config_clear_handler_context(config);
|
||||||
config->handler_context.seat = keyboard->seat_device->sway_seat;
|
config->handler_context.seat = keyboard->seat_device->sway_seat;
|
||||||
struct cmd_results *results = handle_command(binding->command);
|
struct cmd_results *results = execute_command(binding->command, NULL);
|
||||||
if (results->status != CMD_SUCCESS) {
|
if (results->status != CMD_SUCCESS) {
|
||||||
wlr_log(L_DEBUG, "could not run command for binding: %s",
|
wlr_log(L_DEBUG, "could not run command for binding: %s",
|
||||||
binding->command);
|
binding->command);
|
||||||
|
|
|
@ -336,8 +336,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
|
||||||
case IPC_COMMAND:
|
case IPC_COMMAND:
|
||||||
{
|
{
|
||||||
config_clear_handler_context(config);
|
config_clear_handler_context(config);
|
||||||
config->handler_context.seat = input_manager_current_seat(input_manager);
|
struct cmd_results *results = execute_command(buf, NULL);
|
||||||
struct cmd_results *results = handle_command(buf);
|
|
||||||
const char *json = cmd_results_to_json(results);
|
const char *json = cmd_results_to_json(results);
|
||||||
char reply[256];
|
char reply[256];
|
||||||
int length = snprintf(reply, sizeof(reply), "%s", json);
|
int length = snprintf(reply, sizeof(reply), "%s", json);
|
||||||
|
|
|
@ -22,7 +22,7 @@ static void server_ready(struct wl_listener *listener, void *data) {
|
||||||
config->active = true;
|
config->active = true;
|
||||||
while (config->cmd_queue->length) {
|
while (config->cmd_queue->length) {
|
||||||
char *line = config->cmd_queue->items[0];
|
char *line = config->cmd_queue->items[0];
|
||||||
struct cmd_results *res = handle_command(line);
|
struct cmd_results *res = execute_command(line, NULL);
|
||||||
if (res->status != CMD_SUCCESS) {
|
if (res->status != CMD_SUCCESS) {
|
||||||
wlr_log(L_ERROR, "Error on line '%s': %s", line, res->error);
|
wlr_log(L_ERROR, "Error on line '%s': %s", line, res->error);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue