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
parent
8df085a65a
commit
a28ce15521
|
@ -41,7 +41,7 @@ restore_outputs() {
|
||||||
local firstOutput=${OUTPUTS_TO_RECONNECT[0]}
|
local firstOutput=${OUTPUTS_TO_RECONNECT[0]}
|
||||||
echo "Switching wayvnc back to physical output $firstOutput"
|
echo "Switching wayvnc back to physical output $firstOutput"
|
||||||
wait_for_output_matching "$firstOutput" >/dev/null
|
wait_for_output_matching "$firstOutput" >/dev/null
|
||||||
$WAYVNCCTL output-set --switch-to="$firstOutput"
|
$WAYVNCCTL output-set --output-name="$firstOutput"
|
||||||
echo "Removing virtual output $HEADLESS"
|
echo "Removing virtual output $HEADLESS"
|
||||||
$SWAYMSG output "$HEADLESS" unplug
|
$SWAYMSG output "$HEADLESS" unplug
|
||||||
fi
|
fi
|
||||||
|
@ -55,14 +55,14 @@ collapse_outputs() {
|
||||||
local preexisting="$(find_output_matching 'HEADLESS-\\d+')"
|
local preexisting="$(find_output_matching 'HEADLESS-\\d+')"
|
||||||
if [[ $preexisting ]]; then
|
if [[ $preexisting ]]; then
|
||||||
echo "Switching to preexisting virtual output $preexisting"
|
echo "Switching to preexisting virtual output $preexisting"
|
||||||
$WAYVNCCTL output-set --switch-to="$preexisting"
|
$WAYVNCCTL output-set --output-name="$preexisting"
|
||||||
else
|
else
|
||||||
echo "Creating a virtual display"
|
echo "Creating a virtual display"
|
||||||
$SWAYMSG create_output
|
$SWAYMSG create_output
|
||||||
echo "Waiting for virtusl output to be created..."
|
echo "Waiting for virtusl output to be created..."
|
||||||
HEADLESS=$(wait_for_output_matching 'HEADLESS-\\d+')
|
HEADLESS=$(wait_for_output_matching 'HEADLESS-\\d+')
|
||||||
echo "Switching to virtual output $HEADLESS"
|
echo "Switching to virtual output $HEADLESS"
|
||||||
$WAYVNCCTL output-set --switch-to="$HEADLESS"
|
$WAYVNCCTL output-set --output-name="$HEADLESS"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
for output in $($WAYVNCCTL -j output-list | jq -r '.[] | select(.captured==false).name'); do
|
for output in $($WAYVNCCTL -j output-list | jq -r '.[] | select(.captured==false).name'); do
|
||||||
|
|
|
@ -22,6 +22,7 @@ enum cmd_type {
|
||||||
CMD_CLIENT_LIST,
|
CMD_CLIENT_LIST,
|
||||||
CMD_CLIENT_DISCONNECT,
|
CMD_CLIENT_DISCONNECT,
|
||||||
CMD_OUTPUT_LIST,
|
CMD_OUTPUT_LIST,
|
||||||
|
CMD_OUTPUT_CYCLE,
|
||||||
CMD_OUTPUT_SET,
|
CMD_OUTPUT_SET,
|
||||||
CMD_VERSION,
|
CMD_VERSION,
|
||||||
CMD_WAYVNC_EXIT,
|
CMD_WAYVNC_EXIT,
|
||||||
|
|
|
@ -382,6 +382,7 @@ static void pretty_print(json_t* data,
|
||||||
break;
|
break;
|
||||||
case CMD_CLIENT_DISCONNECT:
|
case CMD_CLIENT_DISCONNECT:
|
||||||
case CMD_OUTPUT_SET:
|
case CMD_OUTPUT_SET:
|
||||||
|
case CMD_OUTPUT_CYCLE:
|
||||||
case CMD_WAYVNC_EXIT:
|
case CMD_WAYVNC_EXIT:
|
||||||
printf("Ok\n");
|
printf("Ok\n");
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -25,7 +25,7 @@ struct cmd_info ctl_command_list[] = {
|
||||||
{
|
{
|
||||||
{"command", "The command to show (optional)"},
|
{"command", "The command to show (optional)"},
|
||||||
{"event", "The event to show (optional)"},
|
{"event", "The event to show (optional)"},
|
||||||
{NULL, NULL},
|
{ },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[CMD_VERSION] = { "version",
|
[CMD_VERSION] = { "version",
|
||||||
|
@ -35,7 +35,7 @@ struct cmd_info ctl_command_list[] = {
|
||||||
[CMD_EVENT_RECEIVE] = { "event-receive",
|
[CMD_EVENT_RECEIVE] = { "event-receive",
|
||||||
"Register to begin receiving asynchronous events from wayvnc",
|
"Register to begin receiving asynchronous events from wayvnc",
|
||||||
// TODO: Event type filtering?
|
// TODO: Event type filtering?
|
||||||
{{NULL, NULL}}
|
{{ }}
|
||||||
},
|
},
|
||||||
[CMD_CLIENT_LIST] = { "client-list",
|
[CMD_CLIENT_LIST] = { "client-list",
|
||||||
"Return a list of all currently connected VNC sessions",
|
"Return a list of all currently connected VNC sessions",
|
||||||
|
@ -45,24 +45,27 @@ struct cmd_info ctl_command_list[] = {
|
||||||
"Disconnect a VNC session",
|
"Disconnect a VNC session",
|
||||||
{
|
{
|
||||||
{"id", "The ID of the client to disconnect"},
|
{"id", "The ID of the client to disconnect"},
|
||||||
{NULL, NULL},
|
{ },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[CMD_OUTPUT_LIST] = { "output-list",
|
[CMD_OUTPUT_LIST] = { "output-list",
|
||||||
"Return a list of all currently detected Wayland outputs",
|
"Return a list of all currently detected Wayland outputs",
|
||||||
{{NULL, NULL}}
|
{{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",
|
[CMD_OUTPUT_SET] = { "output-set",
|
||||||
"Switch the actively captured output",
|
"Switch the actively captured output",
|
||||||
{
|
{
|
||||||
{"switch-to", "The specific output name to capture"},
|
{"output-name", "The specific output name to capture"},
|
||||||
{"cycle", "Either \"next\" or \"prev\""},
|
{ },
|
||||||
{NULL, NULL},
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[CMD_WAYVNC_EXIT] = { "wayvnc-exit",
|
[CMD_WAYVNC_EXIT] = { "wayvnc-exit",
|
||||||
"Disconnect all clients and shut down wayvnc",
|
"Disconnect all clients and shut down wayvnc",
|
||||||
{{NULL,NULL}},
|
{{ }},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -137,34 +137,13 @@ static struct cmd_set_output* cmd_set_output_new(json_t* args,
|
||||||
struct jsonipc_error* err)
|
struct jsonipc_error* err)
|
||||||
{
|
{
|
||||||
const char* target = NULL;
|
const char* target = NULL;
|
||||||
const char* cycle = NULL;
|
if (json_unpack(args, "{s:s}", "output-name", &target) == -1) {
|
||||||
if (json_unpack(args, "{s?s,s?s}",
|
|
||||||
"switch-to", &target,
|
|
||||||
"cycle", &cycle) == -1) {
|
|
||||||
jsonipc_error_printf(err, EINVAL,
|
jsonipc_error_printf(err, EINVAL,
|
||||||
"expecting \"switch-to\" or \"cycle\"");
|
"required: \"output-name\"");
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if ((!target && !cycle) || (target && cycle)) {
|
|
||||||
jsonipc_error_printf(err, EINVAL,
|
|
||||||
"expecting exactly one of \"switch-to\" or \"cycle\"");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
struct cmd_set_output* cmd = calloc(1, sizeof(*cmd));
|
struct cmd_set_output* cmd = calloc(1, sizeof(*cmd));
|
||||||
if (target) {
|
strlcpy(cmd->target, target, sizeof(cmd->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;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,8 +151,7 @@ static struct cmd_disconnect_client* cmd_disconnect_client_new(json_t* args,
|
||||||
struct jsonipc_error* err)
|
struct jsonipc_error* err)
|
||||||
{
|
{
|
||||||
const char* id = NULL;
|
const char* id = NULL;
|
||||||
if (json_unpack(args, "{s:s}",
|
if (json_unpack(args, "{s:s}", "id", &id) == -1) {
|
||||||
"id", &id) == -1) {
|
|
||||||
jsonipc_error_printf(err, EINVAL,
|
jsonipc_error_printf(err, EINVAL,
|
||||||
"required: \"id\"");
|
"required: \"id\"");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -222,6 +200,7 @@ static struct cmd* parse_command(struct jsonipc_request* ipc,
|
||||||
case CMD_EVENT_RECEIVE:
|
case CMD_EVENT_RECEIVE:
|
||||||
case CMD_CLIENT_LIST:
|
case CMD_CLIENT_LIST:
|
||||||
case CMD_OUTPUT_LIST:
|
case CMD_OUTPUT_LIST:
|
||||||
|
case CMD_OUTPUT_CYCLE:
|
||||||
case CMD_WAYVNC_EXIT:
|
case CMD_WAYVNC_EXIT:
|
||||||
cmd = calloc(1, sizeof(*cmd));
|
cmd = calloc(1, sizeof(*cmd));
|
||||||
break;
|
break;
|
||||||
|
@ -406,10 +385,7 @@ static struct cmd_response* ctl_server_dispatch_cmd(struct ctl* self,
|
||||||
}
|
}
|
||||||
case CMD_OUTPUT_SET: {
|
case CMD_OUTPUT_SET: {
|
||||||
struct cmd_set_output* c = (struct cmd_set_output*)cmd;
|
struct cmd_set_output* c = (struct cmd_set_output*)cmd;
|
||||||
if (c->target[0] != '\0')
|
response = self->actions.on_output_switch(self, c->target);
|
||||||
response = self->actions.on_output_switch(self, c->target);
|
|
||||||
else
|
|
||||||
response = self->actions.on_output_cycle(self, c->cycle);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_CLIENT_DISCONNECT: {
|
case CMD_CLIENT_DISCONNECT: {
|
||||||
|
@ -434,6 +410,9 @@ static struct cmd_response* ctl_server_dispatch_cmd(struct ctl* self,
|
||||||
case CMD_OUTPUT_LIST:
|
case CMD_OUTPUT_LIST:
|
||||||
response = generate_output_list(self);
|
response = generate_output_list(self);
|
||||||
break;
|
break;
|
||||||
|
case CMD_OUTPUT_CYCLE:
|
||||||
|
response = self->actions.on_output_cycle(self, OUTPUT_CYCLE_FORWARD);
|
||||||
|
break;
|
||||||
case CMD_UNKNOWN:
|
case CMD_UNKNOWN:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
18
wayvnc.scd
18
wayvnc.scd
|
@ -203,18 +203,20 @@ _OUTPUT-LIST_
|
||||||
The *output-list* command retrieves a list of all outputs known to wayvnc and
|
The *output-list* command retrieves a list of all outputs known to wayvnc and
|
||||||
whether or not each one is currently being captured.
|
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_
|
_OUTPUT-SET_
|
||||||
|
|
||||||
For multi-output wayland displays, the *output-set* command switches which
|
For multi-output wayland displays, the *output-set* command switches which
|
||||||
output is actively captured by wayvnc. This operates in 2 different modes,
|
output is actively captured by wayvnc by name.
|
||||||
depending on which one of these parameters is supplied:
|
|
||||||
|
|
||||||
*cycle=next|prev*
|
*output-name=name*
|
||||||
Cycle to the next/prev output in the output list, wrapping back to the
|
Required: The name of the output to capture next.
|
||||||
first/last if the end of the list is reached.
|
|
||||||
|
|
||||||
*switch-to=output-name*
|
|
||||||
Switch to a specific output by name.
|
|
||||||
|
|
||||||
_VERSION_
|
_VERSION_
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ Usage: wayvncctl [options] output-set [params]
|
||||||
Cycle to the next active output:
|
Cycle to the next active output:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ wayvncctl output-set --cycle=next
|
$ wayvncctl output-cycle
|
||||||
```
|
```
|
||||||
|
|
||||||
Get json-formatted version information:
|
Get json-formatted version information:
|
||||||
|
|
Loading…
Reference in New Issue