aboutsummaryrefslogtreecommitdiff
path: root/sway/config/seat.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-12-20 11:56:39 -0500
committerGitHub <noreply@github.com>2017-12-20 11:56:39 -0500
commit373def44468e0c919031a6ffe3049f91680e05ca (patch)
treee40dfdcc9292a71fcc2160bc5d643a66996664dc /sway/config/seat.c
parenta51e74beb91a98181d6bc69137d377cd49e72d1f (diff)
parent63f7fb95172a72436698a1562b4f7ea1e9100a7e (diff)
Merge pull request #1505 from acrisci/feature/input
input management and seat
Diffstat (limited to 'sway/config/seat.c')
-rw-r--r--sway/config/seat.c135
1 files changed, 135 insertions, 0 deletions
diff --git a/sway/config/seat.c b/sway/config/seat.c
new file mode 100644
index 00000000..113139e8
--- /dev/null
+++ b/sway/config/seat.c
@@ -0,0 +1,135 @@
+#define _XOPEN_SOURCE 700
+#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) {
+ sway_log(L_DEBUG, "Unable to allocate seat config");
+ return NULL;
+ }
+
+ sway_log(L_DEBUG, "new_seat_config(%s)", name);
+ seat->name = strdup(name);
+ if (!sway_assert(seat->name, "could not allocate name for seat")) {
+ free(seat);
+ return NULL;
+ }
+
+ seat->fallback = -1;
+ seat->attachments = create_list();
+ if (!sway_assert(seat->attachments,
+ "could not allocate seat attachments list")) {
+ free(seat->name);
+ free(seat);
+ return NULL;
+ }
+
+ return seat;
+}
+
+struct seat_attachment_config *seat_attachment_config_new() {
+ struct seat_attachment_config *attachment =
+ calloc(1, sizeof(struct seat_attachment_config));
+ if (!attachment) {
+ sway_log(L_DEBUG, "cannot allocate attachment config");
+ return NULL;
+ }
+ return attachment;
+}
+
+static void seat_attachment_config_free(
+ struct seat_attachment_config *attachment) {
+ free(attachment->identifier);
+ free(attachment);
+ return;
+}
+
+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) {
+ if (source->name) {
+ free(dest->name);
+ 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];
+ 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);
+ }
+ }
+ }
+}
+
+void free_seat_config(struct seat_config *seat) {
+ if (!seat) {
+ return;
+ }
+
+ free(seat->name);
+ for (int i = 0; i < seat->attachments->length; ++i) {
+ struct seat_attachment_config *attachment =
+ seat->attachments->items[i];
+ seat_attachment_config_free(attachment);
+ }
+
+ list_free(seat->attachments);
+ 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;
+}