From 87c034db436d7c3c0b202e61c990109d3f23480d Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sat, 25 Mar 2023 13:22:51 +0000 Subject: [PATCH] Add seat name to client-connected event --- include/ctl-server.h | 8 ++------ src/ctl-server.c | 41 +++++++++++++++++++---------------------- src/main.c | 28 ++++++++++++++++------------ 3 files changed, 37 insertions(+), 40 deletions(-) diff --git a/include/ctl-server.h b/include/ctl-server.h index 8392b28..02c55ca 100644 --- a/include/ctl-server.h +++ b/include/ctl-server.h @@ -70,15 +70,11 @@ struct cmd_response* cmd_ok(void); struct cmd_response* cmd_failed(const char* fmt, ...); void ctl_server_event_connected(struct ctl*, - const char* client_id, - const char* client_hostname, - const char* client_username, + const struct ctl_server_client_info *info, int new_connection_count); void ctl_server_event_disconnected(struct ctl*, - const char* client_id, - const char* client_hostname, - const char* client_username, + const struct ctl_server_client_info *info, int new_connection_count); void ctl_server_event_capture_changed(struct ctl*, diff --git a/src/ctl-server.c b/src/ctl-server.c index 4c5e68d..b01dd7a 100644 --- a/src/ctl-server.c +++ b/src/ctl-server.c @@ -856,15 +856,18 @@ struct cmd_response* cmd_failed(const char* fmt, ...) } json_t* pack_connection_event_params( - const char* client_id, - const char* client_hostname, - const char* client_username, + const struct ctl_server_client_info *info, int new_connection_count) { - return json_pack("{s:s, s:s?, s:s?, s:i}", - "id", client_id, - "hostname", client_hostname, - "username", client_username, + // TODO: Why is the id a string? + char id_str[64]; + snprintf(id_str, sizeof(id_str), "%d", info->id); + + return json_pack("{s:s, s:s?, s:s?, s:s?, s:i}", + "id", id_str, + "hostname", info->hostname, + "username", info->username, + "seat", info->seat, "connection_count", new_connection_count); } @@ -906,34 +909,28 @@ int ctl_server_enqueue_event(struct ctl* self, enum event_type evt_type, static void ctl_server_event_connect(struct ctl* self, enum event_type evt_type, - const char* client_id, - const char* client_hostname, - const char* client_username, + const struct ctl_server_client_info *info, int new_connection_count) { - json_t* params = pack_connection_event_params(client_id, client_hostname, - client_username, new_connection_count); + json_t* params = + pack_connection_event_params(info, new_connection_count); ctl_server_enqueue_event(self, evt_type, params); } void ctl_server_event_connected(struct ctl* self, - const char* client_id, - const char* client_hostname, - const char* client_username, + const struct ctl_server_client_info *info, int new_connection_count) { - ctl_server_event_connect(self, EVT_CLIENT_CONNECTED, client_id, - client_hostname, client_username, new_connection_count); + ctl_server_event_connect(self, EVT_CLIENT_CONNECTED, info, + new_connection_count); } void ctl_server_event_disconnected(struct ctl* self, - const char* client_id, - const char* client_hostname, - const char* client_username, + const struct ctl_server_client_info *info, int new_connection_count) { - ctl_server_event_connect(self, EVT_CLIENT_DISCONNECTED, client_id, - client_hostname, client_username, new_connection_count); + ctl_server_event_connect(self, EVT_CLIENT_DISCONNECTED, info, + new_connection_count); } void ctl_server_event_capture_changed(struct ctl* self, diff --git a/src/main.c b/src/main.c index b28dd7c..7417890 100644 --- a/src/main.c +++ b/src/main.c @@ -1034,12 +1034,14 @@ static void on_nvnc_client_cleanup(struct nvnc_client* client) nvnc_log(NVNC_LOG_DEBUG, "Client disconnected, new client count: %d", self->nr_clients); - char id[64]; - snprintf(id, sizeof(id), "%u", wayvnc_client->id); - ctl_server_event_disconnected(self->ctl, id, - nvnc_client_get_hostname(client), - nvnc_client_get_auth_username(client), - self->nr_clients); + struct ctl_server_client_info info = { + .id = wayvnc_client->id, + .hostname = nvnc_client_get_hostname(client), + .username = nvnc_client_get_auth_username(client), + .seat = wayvnc_client->seat->name, + }; + + ctl_server_event_disconnected(self->ctl, &info, self->nr_clients); if (self->nr_clients == 0) { nvnc_log(NVNC_LOG_INFO, "Stopping screen capture"); @@ -1067,12 +1069,14 @@ static void on_nvnc_client_new(struct nvnc_client* client) nvnc_log(NVNC_LOG_DEBUG, "Client connected, new client count: %d", self->nr_clients); - char id[64]; - snprintf(id, sizeof(id), "%u", wayvnc_client->id); - ctl_server_event_connected(self->ctl, id, - nvnc_client_get_hostname(client), - nvnc_client_get_auth_username(client), - self->nr_clients); + struct ctl_server_client_info info = { + .id = wayvnc_client->id, + .hostname = nvnc_client_get_hostname(client), + .username = nvnc_client_get_auth_username(client), + .seat = wayvnc_client->seat->name, + }; + + ctl_server_event_connected(self->ctl, &info, self->nr_clients); } void parse_keyboard_option(struct wayvnc* self, const char* arg)