From 0414e1fd870798d160350b5506960173ffccb0fc Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sat, 25 Mar 2023 10:33:10 +0000 Subject: [PATCH] Show seat in client list --- include/ctl-server.h | 1 + src/ctl-server.c | 2 ++ src/main.c | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/include/ctl-server.h b/include/ctl-server.h index d0fc141..f787a4c 100644 --- a/include/ctl-server.h +++ b/include/ctl-server.h @@ -25,6 +25,7 @@ struct ctl_server_vnc_client { char id[64]; char hostname[256]; char username[256]; + char seat[256]; }; struct ctl_server_output { diff --git a/src/ctl-server.c b/src/ctl-server.c index f15baab..b68cccf 100644 --- a/src/ctl-server.c +++ b/src/ctl-server.c @@ -343,6 +343,8 @@ static struct cmd_response* generate_vnc_client_list(struct ctl* self) if (clients[i].username[0] != '\0') json_object_set_new(packed, "username", json_string(clients[i].username)); + json_object_set_new(packed, "seat", + json_string(clients[i].seat)); json_array_append_new(response->data, packed); } free(clients); diff --git a/src/main.c b/src/main.c index c95fc68..c5dcdc2 100644 --- a/src/main.c +++ b/src/main.c @@ -515,24 +515,33 @@ static int get_client_list(struct ctl* ctl, *clients = NULL; return 0; } + *clients = calloc(self->nr_clients, sizeof(**clients)); struct nvnc_client* nvnc_client = nvnc_client_first(self->nvnc); + for (int i = 0; i < self->nr_clients && nvnc_client; ++i) { struct wayvnc_client* client = nvnc_get_userdata(nvnc_client); struct ctl_server_vnc_client* ctl_client =&(*clients)[i]; snprintf(ctl_client->id, sizeof(ctl_client->id), "%u", client->id); + const char* hostname = nvnc_client_get_hostname(nvnc_client); if (hostname) strlcpy(ctl_client->hostname, hostname, sizeof(ctl_client->hostname)); + const char* username = nvnc_client_get_auth_username(nvnc_client); if (username) strlcpy(ctl_client->username, username, sizeof(ctl_client->username)); + + strlcpy(ctl_client->seat, client->seat->name, + sizeof(ctl_client->seat)); + nvnc_client = nvnc_client_next(nvnc_client); } + return self->nr_clients; }