Split wayvnctl output-set into output-set and output-cycle

Rather than optional params, unique commands are easier to use.

This also removes the ability to cycle through in reverse since the list
order is already arbitrary.

Signed-off-by: Jim Ramsay <i.am@jimramsay.com>
pull/221/head
Jim Ramsay 2023-01-06 15:59:02 -05:00
parent 8df085a65a
commit a28ce15521
7 changed files with 35 additions and 49 deletions

View File

@ -41,7 +41,7 @@ restore_outputs() {
local firstOutput=${OUTPUTS_TO_RECONNECT[0]}
echo "Switching wayvnc back to physical output $firstOutput"
wait_for_output_matching "$firstOutput" >/dev/null
$WAYVNCCTL output-set --switch-to="$firstOutput"
$WAYVNCCTL output-set --output-name="$firstOutput"
echo "Removing virtual output $HEADLESS"
$SWAYMSG output "$HEADLESS" unplug
fi
@ -55,14 +55,14 @@ collapse_outputs() {
local preexisting="$(find_output_matching 'HEADLESS-\\d+')"
if [[ $preexisting ]]; then
echo "Switching to preexisting virtual output $preexisting"
$WAYVNCCTL output-set --switch-to="$preexisting"
$WAYVNCCTL output-set --output-name="$preexisting"
else
echo "Creating a virtual display"
$SWAYMSG create_output
echo "Waiting for virtusl output to be created..."
HEADLESS=$(wait_for_output_matching 'HEADLESS-\\d+')
echo "Switching to virtual output $HEADLESS"
$WAYVNCCTL output-set --switch-to="$HEADLESS"
$WAYVNCCTL output-set --output-name="$HEADLESS"
fi
fi
for output in $($WAYVNCCTL -j output-list | jq -r '.[] | select(.captured==false).name'); do

View File

@ -22,6 +22,7 @@ enum cmd_type {
CMD_CLIENT_LIST,
CMD_CLIENT_DISCONNECT,
CMD_OUTPUT_LIST,
CMD_OUTPUT_CYCLE,
CMD_OUTPUT_SET,
CMD_VERSION,
CMD_WAYVNC_EXIT,

View File

@ -382,6 +382,7 @@ static void pretty_print(json_t* data,
break;
case CMD_CLIENT_DISCONNECT:
case CMD_OUTPUT_SET:
case CMD_OUTPUT_CYCLE:
case CMD_WAYVNC_EXIT:
printf("Ok\n");
break;

View File

@ -25,7 +25,7 @@ struct cmd_info ctl_command_list[] = {
{
{"command", "The command to show (optional)"},
{"event", "The event to show (optional)"},
{NULL, NULL},
{ },
}
},
[CMD_VERSION] = { "version",
@ -35,7 +35,7 @@ struct cmd_info ctl_command_list[] = {
[CMD_EVENT_RECEIVE] = { "event-receive",
"Register to begin receiving asynchronous events from wayvnc",
// TODO: Event type filtering?
{{NULL, NULL}}
{{ }}
},
[CMD_CLIENT_LIST] = { "client-list",
"Return a list of all currently connected VNC sessions",
@ -45,24 +45,27 @@ struct cmd_info ctl_command_list[] = {
"Disconnect a VNC session",
{
{"id", "The ID of the client to disconnect"},
{NULL, NULL},
{ },
}
},
[CMD_OUTPUT_LIST] = { "output-list",
"Return a list of all currently detected Wayland outputs",
{{NULL, NULL}}
},
[CMD_OUTPUT_CYCLE] = { "output-cycle",
"Cycle the actively captured output to the next available output, wrapping through all outputs.",
{{ }}
},
[CMD_OUTPUT_SET] = { "output-set",
"Switch the actively captured output",
{
{"switch-to", "The specific output name to capture"},
{"cycle", "Either \"next\" or \"prev\""},
{NULL, NULL},
{"output-name", "The specific output name to capture"},
{ },
}
},
[CMD_WAYVNC_EXIT] = { "wayvnc-exit",
"Disconnect all clients and shut down wayvnc",
{{NULL,NULL}},
{{ }},
},
};

View File

@ -137,34 +137,13 @@ static struct cmd_set_output* cmd_set_output_new(json_t* args,
struct jsonipc_error* err)
{
const char* target = NULL;
const char* cycle = NULL;
if (json_unpack(args, "{s?s,s?s}",
"switch-to", &target,
"cycle", &cycle) == -1) {
if (json_unpack(args, "{s:s}", "output-name", &target) == -1) {
jsonipc_error_printf(err, EINVAL,
"expecting \"switch-to\" or \"cycle\"");
return NULL;
}
if ((!target && !cycle) || (target && cycle)) {
jsonipc_error_printf(err, EINVAL,
"expecting exactly one of \"switch-to\" or \"cycle\"");
"required: \"output-name\"");
return NULL;
}
struct cmd_set_output* cmd = calloc(1, sizeof(*cmd));
if (target) {
strlcpy(cmd->target, target, sizeof(cmd->target));
} else if (cycle) {
if (strncmp(cycle, "prev", 4) == 0)
cmd->cycle = OUTPUT_CYCLE_REVERSE;
else if (strcmp(cycle, "next") == 0)
cmd->cycle = OUTPUT_CYCLE_FORWARD;
else {
jsonipc_error_printf(err, EINVAL,
"cycle must either be \"next\" or \"prev\"");
free(cmd);
return NULL;
}
}
return cmd;
}
@ -172,8 +151,7 @@ static struct cmd_disconnect_client* cmd_disconnect_client_new(json_t* args,
struct jsonipc_error* err)
{
const char* id = NULL;
if (json_unpack(args, "{s:s}",
"id", &id) == -1) {
if (json_unpack(args, "{s:s}", "id", &id) == -1) {
jsonipc_error_printf(err, EINVAL,
"required: \"id\"");
return NULL;
@ -222,6 +200,7 @@ static struct cmd* parse_command(struct jsonipc_request* ipc,
case CMD_EVENT_RECEIVE:
case CMD_CLIENT_LIST:
case CMD_OUTPUT_LIST:
case CMD_OUTPUT_CYCLE:
case CMD_WAYVNC_EXIT:
cmd = calloc(1, sizeof(*cmd));
break;
@ -406,10 +385,7 @@ static struct cmd_response* ctl_server_dispatch_cmd(struct ctl* self,
}
case CMD_OUTPUT_SET: {
struct cmd_set_output* c = (struct cmd_set_output*)cmd;
if (c->target[0] != '\0')
response = self->actions.on_output_switch(self, c->target);
else
response = self->actions.on_output_cycle(self, c->cycle);
break;
}
case CMD_CLIENT_DISCONNECT: {
@ -434,6 +410,9 @@ static struct cmd_response* ctl_server_dispatch_cmd(struct ctl* self,
case CMD_OUTPUT_LIST:
response = generate_output_list(self);
break;
case CMD_OUTPUT_CYCLE:
response = self->actions.on_output_cycle(self, OUTPUT_CYCLE_FORWARD);
break;
case CMD_UNKNOWN:
break;
}

View File

@ -203,18 +203,20 @@ _OUTPUT-LIST_
The *output-list* command retrieves a list of all outputs known to wayvnc and
whether or not each one is currently being captured.
_OUTPUT-CYCLE_
For multi-output wayland displays, the *output-cycle* command switches which
output is actively captured by wayvnc. Running this once will switch to the next
available output. If no more outputs are available, it cycles back to the first
again.
_OUTPUT-SET_
For multi-output wayland displays, the *output-set* command switches which
output is actively captured by wayvnc. This operates in 2 different modes,
depending on which one of these parameters is supplied:
output is actively captured by wayvnc by name.
*cycle=next|prev*
Cycle to the next/prev output in the output list, wrapping back to the
first/last if the end of the list is reached.
*switch-to=output-name*
Switch to a specific output by name.
*output-name=name*
Required: The name of the output to capture next.
_VERSION_

View File

@ -116,7 +116,7 @@ Usage: wayvncctl [options] output-set [params]
Cycle to the next active output:
```
$ wayvncctl output-set --cycle=next
$ wayvncctl output-cycle
```
Get json-formatted version information: