From e958b06e446e1ccca8be142ec01f6a43585d604f Mon Sep 17 00:00:00 2001 From: Jim Ramsay Date: Fri, 25 Nov 2022 20:56:07 -0500 Subject: [PATCH] Add wayvncctl wayvnc-exit command Signed-off-by: Jim Ramsay --- include/ctl-server.h | 1 + src/ctl-server.c | 9 +++++++++ src/main.c | 9 +++++++++ wayvnc.scd | 4 ++++ 4 files changed, 23 insertions(+) diff --git a/include/ctl-server.h b/include/ctl-server.h index 8c99f3c..bfb7783 100644 --- a/include/ctl-server.h +++ b/include/ctl-server.h @@ -43,6 +43,7 @@ struct ctl_server_actions { const char* output_name); struct cmd_response* (*on_disconnect_client)(struct ctl*, const char* id); + struct cmd_response* (*on_wayvnc_exit)(struct ctl*); // Return number of elements created // Allocate 'clients' array or set ton ULL if none diff --git a/src/ctl-server.c b/src/ctl-server.c index 2f7e695..adc81e9 100644 --- a/src/ctl-server.c +++ b/src/ctl-server.c @@ -49,6 +49,7 @@ enum cmd_type { CMD_GET_CLIENTS, CMD_GET_OUTPUTS, CMD_DISCONNECT_CLIENT, + CMD_WAYVNC_EXIT, CMD_UNKNOWN, }; #define CMD_LIST_LEN CMD_UNKNOWN @@ -113,6 +114,10 @@ static struct cmd_info cmd_list[] = { {NULL, NULL}, } }, + [CMD_WAYVNC_EXIT] = { "wayvnc-exit", + "Disconnect all clients and shut down wayvnc", + {{NULL,NULL}}, + }, }; #define CLIENT_EVENT_PARAMS(including) \ @@ -333,6 +338,7 @@ static struct cmd* parse_command(struct jsonipc_request* ipc, case CMD_EVENT_RECEIVE: case CMD_GET_CLIENTS: case CMD_GET_OUTPUTS: + case CMD_WAYVNC_EXIT: cmd = calloc(1, sizeof(*cmd)); break; case CMD_UNKNOWN: @@ -538,6 +544,9 @@ static struct cmd_response* ctl_server_dispatch_cmd(struct ctl* self, response = self->actions.on_disconnect_client(self, c->id); break; } + case CMD_WAYVNC_EXIT: + response = self->actions.on_wayvnc_exit(self); + break; case CMD_VERSION: response = generate_version_object(); break; diff --git a/src/main.c b/src/main.c index bc0264e..cdc2a91 100644 --- a/src/main.c +++ b/src/main.c @@ -539,6 +539,14 @@ static struct cmd_response* on_disconnect_client(struct ctl* ctl, return cmd_failed("No such client with ID \"%s\"", id_string); } +static struct cmd_response* on_wayvnc_exit(struct ctl* ctl) +{ + struct wayvnc* self = ctl_server_userdata(ctl); + nvnc_log(NVNC_LOG_WARNING, "Shutting down via control socket command"); + wayvnc_exit(self); + return cmd_ok(); +} + int init_main_loop(struct wayvnc* self) { struct aml* loop = aml_get_default(); @@ -1385,6 +1393,7 @@ int main(int argc, char* argv[]) .get_client_list = get_client_list, .get_output_list = get_output_list, .on_disconnect_client = on_disconnect_client, + .on_wayvnc_exit = on_wayvnc_exit, }; self.ctl = ctl_server_new(socket_path, &ctl_actions); if (!self.ctl) diff --git a/wayvnc.scd b/wayvnc.scd index e8178a4..01a4847 100644 --- a/wayvnc.scd +++ b/wayvnc.scd @@ -213,6 +213,10 @@ Parameters: Required: The ID of the client to disconnect. This ID can be found from the _GET-CLIENTS_ command or receipt of a _CLIENT-CONNECTED_ event. +_WAYVNC_EXIT_ + +The *wayvnc-exit* command disconnects all clients and shuts down wayvnc. + _GET-CLIENTS_ The *get-clients* command retrieves a list of all VNC clients currently