sway/sway/commands/seat.c

82 lines
2.5 KiB
C
Raw Normal View History

2017-12-14 11:11:56 -05:00
#include <string.h>
#include <strings.h>
#include "sway/commands.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
2017-12-14 11:11:56 -05:00
#include "log.h"
#include "stringop.h"
// must be in order for the bsearch
// these handlers perform actions on the seat
static const struct cmd_handler seat_action_handlers[] = {
{ "cursor", seat_cmd_cursor },
};
// must be in order for the bsearch
// these handlers alter the seat config
static const struct cmd_handler seat_handlers[] = {
{ "attach", seat_cmd_attach },
{ "fallback", seat_cmd_fallback },
{ "hide_cursor", seat_cmd_hide_cursor },
{ "idle_inhibit", seat_cmd_idle_inhibit },
{ "idle_wake", seat_cmd_idle_wake },
{ "keyboard_grouping", seat_cmd_keyboard_grouping },
{ "pointer_constraint", seat_cmd_pointer_constraint },
{ "shortcuts_inhibitor", seat_cmd_shortcuts_inhibitor },
{ "xcursor_theme", seat_cmd_xcursor_theme },
};
2017-12-14 11:11:56 -05:00
static struct cmd_results *action_handlers(int argc, char **argv) {
struct cmd_results *res = config_subcommand(argv, argc,
seat_action_handlers, sizeof(seat_action_handlers));
free_seat_config(config->handler_context.seat_config);
config->handler_context.seat_config = NULL;
return res;
}
static struct cmd_results *config_handlers(int argc, char **argv) {
struct cmd_results *res = config_subcommand(argv, argc,
seat_handlers, sizeof(seat_handlers));
if (res && res->status != CMD_SUCCESS) {
free_seat_config(config->handler_context.seat_config);
} else {
struct seat_config *sc =
store_seat_config(config->handler_context.seat_config);
if (!config->reading) {
input_manager_apply_seat_config(sc);
}
}
config->handler_context.seat_config = NULL;
return res;
}
2017-12-14 11:11:56 -05:00
struct cmd_results *cmd_seat(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "seat", EXPECTED_AT_LEAST, 2))) {
2017-12-14 11:11:56 -05:00
return error;
}
if (!strcmp(argv[0], "-")) {
if (config->reading) {
return cmd_results_new(CMD_FAILURE,
"Current seat alias (-) cannot be used in the config");
}
config->handler_context.seat_config =
new_seat_config(config->handler_context.seat->wlr_seat->name);
} else {
config->handler_context.seat_config = new_seat_config(argv[0]);
}
if (!config->handler_context.seat_config) {
return cmd_results_new(CMD_FAILURE, "Couldn't allocate config");
2017-12-14 11:11:56 -05:00
}
struct cmd_results *res = NULL;
if (find_handler(argv[1], seat_action_handlers,
sizeof(seat_action_handlers))) {
res = action_handlers(argc - 1, argv + 1);
} else {
res = config_handlers(argc - 1, argv + 1);
Revamp seat configs This makes seat configs work like output and input configs do. This also adds support for wildcard seat configs. A seat config is still created in the main seat command handler, but instead of creating a new one in the subcommands and destroying the main seat command's instance, the seat subcommands modify the main one. The seat config is then stored, where it is merged appropriately. The seat config returned from `store_seat_config` is then applied. When attempting to apply a wildcard seat config, a seat specific config is queried for and if found, that is used. Otherwise, the wildcard config is applied directly. Additionally, instead of adding input devices to the default seat directly when there is no seat configs, a seat config for the default seat is created with only fallback set to true, which is more explicit. It also fixes an issue where running a seat command at runtime (with no seat config in the sway config), would result in all input devices being removed from the default seat and leaving sway in an unusable state. Also, instead of checking for any seat config, the search is for a seat config with a fallback option seat. This makes it so if there are only seat configs with fallback set to -1, the default seat is still created since there is no explicit notion on what to do regarding fallbacks. However, if there is even a single fallback 0, then the default seat is not used as a fallback. This will be needed for seat subcommands like hide_cursor where the user may only want to set that property without effecting anything else.
2018-12-27 00:46:55 -05:00
}
return res ? res : cmd_results_new(CMD_SUCCESS, NULL);
2017-12-14 11:11:56 -05:00
}