Skip to content

Commit 664fc45

Browse files
authored
feat: add output listing capability (#317)
* feat: add output listing capability * Add help command and man entry for --list-output * fix typo * Extract print available outputs code into function for reusability * fix typo in manpage
1 parent a6a22c2 commit 664fc45

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ The man page can be read with `man ./manpage/wf-recorder.1`.
9292
In its simplest form, run `wf-recorder` to start recording and use Ctrl+C to stop. This will create a file called `recording.mp4` in the current working directory using the default codec.
9393

9494
Use `-f <filename>` to specify the output file. In case of multiple outputs, you'll first be prompted to select the output you want to record. If you know the output name beforehand, you can use the `-o <output name>` option.
95+
To view all available output options, use the list flag `-L` or `--list-output`
9596

9697
To select a specific part of the screen you can either use `-g <geometry>`, or use [slurp](https://github.com/emersion/slurp) for interactive selection of the screen area that will be recorded:
9798

manpage/wf-recorder.1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
.Op Fl h, -help
2222
.Op Fl l, -log
2323
.Op Fl m, -muxer Ar muxer
24+
.Op Fl L, -list-output
2425
.Op Fl o, -output Ar output
2526
.Op Fl p, -codec-param Op Ar option_param=option_value
2627
.Op Fl v, -version
@@ -133,6 +134,9 @@ Generates a log on the current terminal. For debug purposes.
133134
.It Fl m , -muxer Ar muxer
134135
Set the output format to a specific muxer instead of detecting it from the filename.
135136
.Pp
137+
.It Fl L , -list-output
138+
List the available outputs.
139+
.Pp
136140
.It Fl o , -output
137141
Specify the output where the video is to be recorded.
138142
.Pp

src/main.cpp

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -805,16 +805,23 @@ static void load_output_info()
805805
sync_wayland();
806806
}
807807

808-
static wf_recorder_output* choose_interactive()
808+
static void print_available_outputs()
809809
{
810-
fprintf(stdout, "Please select an output from the list to capture (enter output no.):\n");
811-
812810
int i = 1;
813811
for (auto& wo : available_outputs)
814812
{
815813
printf("%d. Name: %s Description: %s\n", i++, wo.name.c_str(),
816814
wo.description.c_str());
817815
}
816+
}
817+
818+
819+
820+
static wf_recorder_output* choose_interactive()
821+
{
822+
fprintf(stdout, "Please select an output from the list to capture (enter output no.):\n");
823+
824+
print_available_outputs();
818825

819826
printf("Enter output no.:");
820827
fflush(stdout);
@@ -942,6 +949,8 @@ Use Ctrl+C to stop.)");
942949
943950
-l, --log Generates a log on the current terminal. Debug purposes.
944951
952+
-L, --list-output List the available outputs.
953+
945954
-o, --output Specify the output where the video is to be recorded.
946955
947956
-p, --codec-param Change the codec parameters.
@@ -1050,6 +1059,29 @@ static void parse_codec_opts(std::map<std::string, std::string>& options, const
10501059
}
10511060
}
10521061

1062+
static void init_wayland_client()
1063+
{
1064+
display = wl_display_connect(NULL);
1065+
if (display == NULL)
1066+
{
1067+
fprintf(stderr, "failed to create display: %m\n");
1068+
exit(EXIT_FAILURE);
1069+
}
1070+
struct wl_registry *registry = wl_display_get_registry(display);
1071+
wl_registry_add_listener(registry, &registry_listener, NULL);
1072+
sync_wayland();
1073+
}
1074+
1075+
static void list_available_outputs()
1076+
{
1077+
init_wayland_client();
1078+
load_output_info();
1079+
print_available_outputs();
1080+
1081+
exit(EXIT_SUCCESS);
1082+
}
1083+
1084+
10531085
int main(int argc, char *argv[])
10541086
{
10551087
FrameWriterParams params = FrameWriterParams(exit_main_loop);
@@ -1092,11 +1124,12 @@ int main(int argc, char *argv[])
10921124
{ "version", no_argument, NULL, 'v' },
10931125
{ "no-damage", no_argument, NULL, 'D' },
10941126
{ "overwrite", no_argument, NULL, 'y' },
1127+
{ "list-output", no_argument, NULL, 'L' },
10951128
{ 0, 0, NULL, 0 }
10961129
};
10971130

10981131
int c, i;
1099-
while((c = getopt_long(argc, argv, "o:f:m:g:c:p:r:x:C:P:R:X:d:b:B:la::hvDF:y", opts, &i)) != -1)
1132+
while((c = getopt_long(argc, argv, "o:f:m:g:c:p:r:x:C:P:R:X:d:b:B:la::hvDF:y:L", opts, &i)) != -1)
11001133
{
11011134
switch(c)
11021135
{
@@ -1197,6 +1230,10 @@ int main(int argc, char *argv[])
11971230
case 'y':
11981231
force_overwrite = true;
11991232
break;
1233+
1234+
case 'L':
1235+
list_available_outputs();
1236+
break;
12001237
#ifdef HAVE_AUDIO
12011238
case '*':
12021239
audioParams.audio_backend = optarg;
@@ -1212,16 +1249,7 @@ int main(int argc, char *argv[])
12121249
return EXIT_FAILURE;
12131250
}
12141251

1215-
display = wl_display_connect(NULL);
1216-
if (display == NULL)
1217-
{
1218-
fprintf(stderr, "failed to create display: %m\n");
1219-
return EXIT_FAILURE;
1220-
}
1221-
1222-
struct wl_registry *registry = wl_display_get_registry(display);
1223-
wl_registry_add_listener(registry, &registry_listener, NULL);
1224-
sync_wayland();
1252+
init_wayland_client();
12251253

12261254
if (params.codec.find("vaapi") != std::string::npos)
12271255
{

0 commit comments

Comments
 (0)