2019-12-11 17:00:39 +01:00
|
|
|
#include <limits.h>
|
2017-12-16 17:25:59 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "sway/config.h"
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
struct seat_config *new_seat_config(const char* name) {
|
|
|
|
struct seat_config *seat = calloc(1, sizeof(struct seat_config));
|
|
|
|
if (!seat) {
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Unable to allocate seat config");
|
2017-12-16 17:25:59 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
seat->name = strdup(name);
|
|
|
|
if (!sway_assert(seat->name, "could not allocate name for seat")) {
|
2017-12-20 12:12:08 +01:00
|
|
|
free(seat);
|
2017-12-16 17:25:59 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-12-11 17:00:39 +01:00
|
|
|
seat->idle_inhibit_sources = seat->idle_wake_sources = UINT32_MAX;
|
|
|
|
|
2017-12-17 16:39:22 +01:00
|
|
|
seat->fallback = -1;
|
2017-12-16 17:25:59 +01:00
|
|
|
seat->attachments = create_list();
|
|
|
|
if (!sway_assert(seat->attachments,
|
|
|
|
"could not allocate seat attachments list")) {
|
2017-12-20 12:12:08 +01:00
|
|
|
free(seat->name);
|
|
|
|
free(seat);
|
2017-12-16 17:25:59 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-12-27 06:32:15 +01:00
|
|
|
seat->hide_cursor_timeout = -1;
|
2020-09-07 00:44:13 +02:00
|
|
|
seat->hide_cursor_when_typing = HIDE_WHEN_TYPING_DEFAULT;
|
2019-02-01 04:58:52 +01:00
|
|
|
seat->allow_constrain = CONSTRAIN_DEFAULT;
|
2020-02-16 00:40:18 +01:00
|
|
|
seat->shortcuts_inhibit = SHORTCUTS_INHIBIT_DEFAULT;
|
2019-11-03 20:20:05 +01:00
|
|
|
seat->keyboard_grouping = KEYBOARD_GROUP_DEFAULT;
|
2019-06-01 21:05:09 +02:00
|
|
|
seat->xcursor_theme.name = NULL;
|
|
|
|
seat->xcursor_theme.size = 24;
|
2017-12-16 17:25:59 +01:00
|
|
|
|
|
|
|
return seat;
|
|
|
|
}
|
|
|
|
|
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 06:46:55 +01:00
|
|
|
static void merge_wildcard_on_all(struct seat_config *wildcard) {
|
|
|
|
for (int i = 0; i < config->seat_configs->length; i++) {
|
|
|
|
struct seat_config *sc = config->seat_configs->items[i];
|
|
|
|
if (strcmp(wildcard->name, sc->name) != 0) {
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Merging seat * config on %s", sc->name);
|
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 06:46:55 +01:00
|
|
|
merge_seat_config(sc, wildcard);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct seat_config *store_seat_config(struct seat_config *sc) {
|
|
|
|
bool wildcard = strcmp(sc->name, "*") == 0;
|
|
|
|
if (wildcard) {
|
|
|
|
merge_wildcard_on_all(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
int i = list_seq_find(config->seat_configs, seat_name_cmp, sc->name);
|
|
|
|
if (i >= 0) {
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Merging on top of existing seat config");
|
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 06:46:55 +01:00
|
|
|
struct seat_config *current = config->seat_configs->items[i];
|
|
|
|
merge_seat_config(current, sc);
|
|
|
|
free_seat_config(sc);
|
|
|
|
sc = current;
|
|
|
|
} else if (!wildcard) {
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Adding non-wildcard seat config");
|
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 06:46:55 +01:00
|
|
|
i = list_seq_find(config->seat_configs, seat_name_cmp, "*");
|
|
|
|
if (i >= 0) {
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Merging on top of seat * config");
|
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 06:46:55 +01:00
|
|
|
struct seat_config *current = new_seat_config(sc->name);
|
|
|
|
merge_seat_config(current, config->seat_configs->items[i]);
|
|
|
|
merge_seat_config(current, sc);
|
|
|
|
free_seat_config(sc);
|
|
|
|
sc = current;
|
|
|
|
}
|
|
|
|
list_add(config->seat_configs, sc);
|
|
|
|
} else {
|
|
|
|
// New wildcard config. Just add it
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Adding seat * config");
|
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 06:46:55 +01:00
|
|
|
list_add(config->seat_configs, sc);
|
|
|
|
}
|
|
|
|
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Config stored for seat %s", sc->name);
|
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 06:46:55 +01:00
|
|
|
|
|
|
|
return sc;
|
|
|
|
}
|
|
|
|
|
2018-09-30 12:58:49 +02:00
|
|
|
struct seat_attachment_config *seat_attachment_config_new(void) {
|
2017-12-16 17:25:59 +01:00
|
|
|
struct seat_attachment_config *attachment =
|
|
|
|
calloc(1, sizeof(struct seat_attachment_config));
|
|
|
|
if (!attachment) {
|
2019-01-20 19:51:12 +01:00
|
|
|
sway_log(SWAY_DEBUG, "cannot allocate attachment config");
|
2017-12-16 17:25:59 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return attachment;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void seat_attachment_config_free(
|
|
|
|
struct seat_attachment_config *attachment) {
|
|
|
|
free(attachment->identifier);
|
|
|
|
free(attachment);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct seat_attachment_config *seat_attachment_config_copy(
|
|
|
|
struct seat_attachment_config *attachment) {
|
|
|
|
struct seat_attachment_config *copy = seat_attachment_config_new();
|
|
|
|
if (!copy) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
copy->identifier = strdup(attachment->identifier);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void merge_seat_attachment_config(struct seat_attachment_config *dest,
|
|
|
|
struct seat_attachment_config *source) {
|
|
|
|
// nothing to merge yet, but there will be some day
|
|
|
|
}
|
|
|
|
|
|
|
|
void merge_seat_config(struct seat_config *dest, struct seat_config *source) {
|
2017-12-17 16:39:22 +01:00
|
|
|
if (source->fallback != -1) {
|
|
|
|
dest->fallback = source->fallback;
|
|
|
|
}
|
|
|
|
|
2017-12-16 17:25:59 +01:00
|
|
|
for (int i = 0; i < source->attachments->length; ++i) {
|
|
|
|
struct seat_attachment_config *source_attachment =
|
|
|
|
source->attachments->items[i];
|
|
|
|
bool found = false;
|
|
|
|
for (int j = 0; j < dest->attachments->length; ++j) {
|
|
|
|
struct seat_attachment_config *dest_attachment =
|
|
|
|
dest->attachments->items[j];
|
|
|
|
if (strcmp(source_attachment->identifier,
|
|
|
|
dest_attachment->identifier) == 0) {
|
|
|
|
merge_seat_attachment_config(dest_attachment,
|
|
|
|
source_attachment);
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
struct seat_attachment_config *copy =
|
|
|
|
seat_attachment_config_copy(source_attachment);
|
|
|
|
if (copy) {
|
|
|
|
list_add(dest->attachments, copy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-27 06:32:15 +01:00
|
|
|
|
|
|
|
if (source->hide_cursor_timeout != -1) {
|
|
|
|
dest->hide_cursor_timeout = source->hide_cursor_timeout;
|
|
|
|
}
|
2019-02-01 04:58:52 +01:00
|
|
|
|
2020-09-07 00:44:13 +02:00
|
|
|
if (source->hide_cursor_when_typing != HIDE_WHEN_TYPING_DEFAULT) {
|
|
|
|
dest->hide_cursor_when_typing = source->hide_cursor_when_typing;
|
|
|
|
}
|
|
|
|
|
2019-02-01 04:58:52 +01:00
|
|
|
if (source->allow_constrain != CONSTRAIN_DEFAULT) {
|
|
|
|
dest->allow_constrain = source->allow_constrain;
|
|
|
|
}
|
2019-06-01 21:05:09 +02:00
|
|
|
|
2020-02-16 00:40:18 +01:00
|
|
|
if (source->shortcuts_inhibit != SHORTCUTS_INHIBIT_DEFAULT) {
|
|
|
|
dest->shortcuts_inhibit = source->shortcuts_inhibit;
|
|
|
|
}
|
|
|
|
|
2019-11-03 20:20:05 +01:00
|
|
|
if (source->keyboard_grouping != KEYBOARD_GROUP_DEFAULT) {
|
|
|
|
dest->keyboard_grouping = source->keyboard_grouping;
|
|
|
|
}
|
|
|
|
|
2019-06-01 21:05:09 +02:00
|
|
|
if (source->xcursor_theme.name != NULL) {
|
|
|
|
free(dest->xcursor_theme.name);
|
|
|
|
dest->xcursor_theme.name = strdup(source->xcursor_theme.name);
|
|
|
|
dest->xcursor_theme.size = source->xcursor_theme.size;
|
|
|
|
}
|
2019-12-11 17:00:39 +01:00
|
|
|
|
|
|
|
if (source->idle_inhibit_sources != UINT32_MAX) {
|
|
|
|
dest->idle_inhibit_sources = source->idle_inhibit_sources;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source->idle_wake_sources != UINT32_MAX) {
|
|
|
|
dest->idle_wake_sources = source->idle_wake_sources;
|
|
|
|
}
|
2017-12-16 17:25:59 +01:00
|
|
|
}
|
|
|
|
|
2018-01-17 15:49:02 +01:00
|
|
|
struct seat_config *copy_seat_config(struct seat_config *seat) {
|
|
|
|
struct seat_config *copy = new_seat_config(seat->name);
|
|
|
|
if (copy == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
merge_seat_config(copy, seat);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2017-12-16 17:25:59 +01:00
|
|
|
void free_seat_config(struct seat_config *seat) {
|
|
|
|
if (!seat) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(seat->name);
|
|
|
|
for (int i = 0; i < seat->attachments->length; ++i) {
|
2018-12-09 00:55:14 +01:00
|
|
|
seat_attachment_config_free(seat->attachments->items[i]);
|
2017-12-16 17:25:59 +01:00
|
|
|
}
|
|
|
|
list_free(seat->attachments);
|
2019-06-01 21:05:09 +02:00
|
|
|
free(seat->xcursor_theme.name);
|
2017-12-16 17:25:59 +01:00
|
|
|
free(seat);
|
|
|
|
}
|
|
|
|
|
|
|
|
int seat_name_cmp(const void *item, const void *data) {
|
|
|
|
const struct seat_config *sc = item;
|
|
|
|
const char *name = data;
|
|
|
|
return strcmp(sc->name, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct seat_attachment_config *seat_config_get_attachment(
|
|
|
|
struct seat_config *seat_config, char *identifier) {
|
|
|
|
for (int i = 0; i < seat_config->attachments->length; ++i) {
|
|
|
|
struct seat_attachment_config *attachment =
|
|
|
|
seat_config->attachments->items[i];
|
|
|
|
if (strcmp(attachment->identifier, identifier) == 0) {
|
|
|
|
return attachment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|