mirror of
https://github.com/swaywm/sway.git
synced 2024-11-11 13:04:11 +01:00
seat fallback config
This commit is contained in:
parent
e27eff8a29
commit
88bcd43ebf
@ -198,6 +198,7 @@ sway_cmd input_cmd_xkb_options;
|
||||
sway_cmd input_cmd_xkb_rules;
|
||||
sway_cmd input_cmd_xkb_variant;
|
||||
|
||||
sway_cmd seat_cmd_fallback;
|
||||
sway_cmd seat_cmd_attach;
|
||||
|
||||
sway_cmd cmd_ipc_cmd;
|
||||
|
@ -90,6 +90,7 @@ struct seat_attachment_config {
|
||||
*/
|
||||
struct seat_config {
|
||||
char *name;
|
||||
int fallback; // -1 means not set
|
||||
list_t *attachments; // list of seat_attachment configs
|
||||
};
|
||||
|
||||
|
@ -165,6 +165,7 @@ static struct cmd_handler input_handlers[] = {
|
||||
// must be in order for the bsearch
|
||||
static struct cmd_handler seat_handlers[] = {
|
||||
{ "attach", seat_cmd_attach },
|
||||
{ "fallback", seat_cmd_fallback },
|
||||
};
|
||||
|
||||
static struct cmd_handler *find_handler(char *line, enum cmd_status block) {
|
||||
|
@ -24,6 +24,8 @@ struct cmd_results *cmd_seat(int argc, char **argv) {
|
||||
current_seat_config = new_seat_config(argv[0]);
|
||||
if (strcasecmp("attach", argv[1]) == 0) {
|
||||
res = seat_cmd_attach(argc_new, argv_new);
|
||||
} else if (strcasecmp("fallback", argv[1]) == 0) {
|
||||
res = seat_cmd_fallback(argc_new, argv_new);
|
||||
} else {
|
||||
res = cmd_results_new(CMD_INVALID, "seat <name>", "Unknown command %s", argv[1]);
|
||||
}
|
||||
|
29
sway/commands/seat/fallback.c
Normal file
29
sway/commands/seat/fallback.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include "sway/config.h"
|
||||
#include "sway/commands.h"
|
||||
#include "sway/input/input-manager.h"
|
||||
|
||||
struct cmd_results *seat_cmd_fallback(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "fallback", EXPECTED_AT_LEAST, 1))) {
|
||||
return error;
|
||||
}
|
||||
if (!current_seat_config) {
|
||||
return cmd_results_new(CMD_FAILURE, "fallback", "No seat defined");
|
||||
}
|
||||
struct seat_config *new_config =
|
||||
new_seat_config(current_seat_config->name);
|
||||
|
||||
if (strcasecmp(argv[0], "true") == 0) {
|
||||
new_config->fallback = 1;
|
||||
} else if (strcasecmp(argv[0], "false") == 0) {
|
||||
new_config->fallback = 0;
|
||||
} else {
|
||||
return cmd_results_new(CMD_INVALID, "fallback",
|
||||
"Expected 'fallback <true|false>'");
|
||||
}
|
||||
|
||||
apply_seat_config(new_config);
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
@ -17,6 +17,7 @@ struct seat_config *new_seat_config(const char* name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
seat->fallback = -1;
|
||||
seat->attachments = create_list();
|
||||
if (!sway_assert(seat->attachments,
|
||||
"could not allocate seat attachments list")) {
|
||||
@ -66,6 +67,10 @@ void merge_seat_config(struct seat_config *dest, struct seat_config *source) {
|
||||
dest->name = strdup(source->name);
|
||||
}
|
||||
|
||||
if (source->fallback != -1) {
|
||||
dest->fallback = source->fallback;
|
||||
}
|
||||
|
||||
for (int i = 0; i < source->attachments->length; ++i) {
|
||||
struct seat_attachment_config *source_attachment =
|
||||
source->attachments->items[i];
|
||||
|
@ -56,9 +56,9 @@ static char *get_device_identifier(struct wlr_input_device *device) {
|
||||
|
||||
int len =
|
||||
(strlen(name) +
|
||||
strlen_num(device->vendor) +
|
||||
strlen_num(device->product) +
|
||||
3) * sizeof(char);
|
||||
strlen_num(device->vendor) +
|
||||
strlen_num(device->product) +
|
||||
3) * sizeof(char);
|
||||
|
||||
char *identifier = malloc(len);
|
||||
if (!identifier) {
|
||||
@ -151,13 +151,30 @@ static void input_add_notify(struct wl_listener *listener, void *data) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool added = false;
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
if (seat->config &&
|
||||
(seat_config_get_attachment(seat->config, input_device->identifier) ||
|
||||
seat_config_get_attachment(seat->config, "*"))) {
|
||||
sway_seat_add_device(seat, input_device);
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!added) {
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
if (seat->config && seat->config->fallback == 1) {
|
||||
sway_seat_add_device(seat, input_device);
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!added) {
|
||||
sway_log(L_DEBUG,
|
||||
"device '%s' is not configured on any seats",
|
||||
input_device->identifier);
|
||||
}
|
||||
}
|
||||
|
||||
static void input_remove_notify(struct wl_listener *listener, void *data) {
|
||||
@ -248,35 +265,53 @@ void sway_input_manager_apply_seat_config(struct sway_input_manager *input,
|
||||
struct seat_config *seat_config) {
|
||||
sway_log(L_DEBUG, "applying new seat config for seat %s", seat_config->name);
|
||||
struct sway_seat *seat = input_manager_get_seat(input, seat_config->name);
|
||||
// the old config is invalid so clear it
|
||||
sway_seat_set_config(seat, NULL);
|
||||
|
||||
// clear devices
|
||||
struct sway_input_device *input_device = NULL;
|
||||
wl_list_for_each(input_device, &input->devices, link) {
|
||||
sway_seat_remove_device(seat, input_device);
|
||||
}
|
||||
|
||||
if (seat_config_get_attachment(seat_config, "*")) {
|
||||
wl_list_for_each(input_device, &input->devices, link) {
|
||||
sway_seat_add_device(seat, input_device);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < seat_config->attachments->length; ++i) {
|
||||
struct seat_attachment_config *attachment =
|
||||
seat_config->attachments->items[i];
|
||||
|
||||
struct sway_input_device *device =
|
||||
input_sway_device_from_identifier(input,
|
||||
attachment->identifier);
|
||||
|
||||
if (device) {
|
||||
sway_seat_add_device(seat, device);
|
||||
}
|
||||
}
|
||||
if (!seat) {
|
||||
return;
|
||||
}
|
||||
|
||||
sway_seat_set_config(seat, seat_config);
|
||||
|
||||
// for every device, try to add it to a seat and if no seat has it
|
||||
// attached, add it to the fallback seats.
|
||||
struct sway_input_device *input_device = NULL;
|
||||
wl_list_for_each(input_device, &input->devices, link) {
|
||||
list_t *seat_list = create_list();
|
||||
struct sway_seat *seat = NULL;
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
if (!seat->config) {
|
||||
continue;
|
||||
}
|
||||
if (seat_config_get_attachment(seat->config, "*") ||
|
||||
seat_config_get_attachment(seat->config, input_device->identifier)) {
|
||||
list_add(seat_list, seat);
|
||||
}
|
||||
}
|
||||
|
||||
if (seat_list->length) {
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
bool attached = false;
|
||||
for (int i = 0; i < seat_list->length; ++i) {
|
||||
if (seat == seat_list->items[i]) {
|
||||
attached = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (attached) {
|
||||
sway_seat_add_device(seat, input_device);
|
||||
} else {
|
||||
sway_seat_remove_device(seat, input_device);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
if (seat->config && seat->config->fallback == 1) {
|
||||
sway_seat_add_device(seat, input_device);
|
||||
} else {
|
||||
sway_seat_remove_device(seat, input_device);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sway_input_manager_configure_xcursor(struct sway_input_manager *input) {
|
||||
|
@ -120,6 +120,7 @@ void sway_seat_configure_device(struct sway_seat *seat,
|
||||
void sway_seat_add_device(struct sway_seat *seat,
|
||||
struct sway_input_device *input_device) {
|
||||
if (sway_seat_get_device(seat, input_device)) {
|
||||
sway_seat_configure_device(seat, input_device);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -246,7 +247,5 @@ void sway_seat_set_config(struct sway_seat *seat,
|
||||
seat_device->attachment_config =
|
||||
seat_config_get_attachment(seat_config,
|
||||
seat_device->input_device->identifier);
|
||||
sway_seat_configure_device(seat, seat_device->input_device);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ sway_sources = files(
|
||||
'commands/input.c',
|
||||
'commands/seat.c',
|
||||
'commands/seat/attach.c',
|
||||
'commands/seat/fallback.c',
|
||||
'commands/input/accel_profile.c',
|
||||
'commands/input/click_method.c',
|
||||
'commands/input/drag_lock.c',
|
||||
|
Loading…
Reference in New Issue
Block a user