aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-08-02 00:45:27 +0200
committerdec05eba <dec05eba@protonmail.com>2024-08-02 00:45:27 +0200
commit495bd6bed85c85650620dc2ae91f7f058ae2da5c (patch)
tree6029ae984bc3b76ab6d01cf7942abc650de25db2 /src
parentbe0ad41e745c3e6177d1159e25f7d23e45b02738 (diff)
Add audio devices
Diffstat (limited to 'src')
-rw-r--r--src/GsrInfo.cpp40
-rw-r--r--src/Theme.cpp23
-rw-r--r--src/main.cpp16
3 files changed, 71 insertions, 8 deletions
diff --git a/src/GsrInfo.cpp b/src/GsrInfo.cpp
index 1534363..6aa1c17 100644
--- a/src/GsrInfo.cpp
+++ b/src/GsrInfo.cpp
@@ -176,4 +176,44 @@ namespace gsr {
return GsrInfoExitStatus::FAILED_TO_RUN_COMMAND;
}
+
+ static AudioDevice parse_audio_device_line(const std::string &line) {
+ AudioDevice audio_device;
+ const size_t space_index = line.find(' ');
+ if(space_index == std::string::npos)
+ return audio_device;
+
+ const std::string_view audio_input_name = {line.c_str(), space_index};
+ const std::string_view audio_input_description = {line.c_str() + space_index + 1, line.size() - (space_index + 1)};
+ audio_device.name.assign(audio_input_name.data(), audio_input_name.size());
+ audio_device.description.assign(audio_input_description.data(), audio_input_description.size());
+ return audio_device;
+ }
+
+ std::vector<AudioDevice> get_audio_devices() {
+ std::vector<AudioDevice> audio_devices;
+
+ FILE *f = popen("gpu-screen-recorder --list-audio-devices", "r");
+ if(!f) {
+ fprintf(stderr, "error: 'gpu-screen-recorder --info' failed\n");
+ return audio_devices;
+ }
+
+ char output[16384];
+ ssize_t bytes_read = fread(output, 1, sizeof(output) - 1, f);
+ if(bytes_read < 0 || ferror(f)) {
+ fprintf(stderr, "error: failed to read 'gpu-screen-recorder --info' output\n");
+ pclose(f);
+ return audio_devices;
+ }
+ output[bytes_read] = '\0';
+
+ string_split_char(output, '\n', [&](std::string_view line) {
+ const std::string line_str(line.data(), line.size());
+ audio_devices.push_back(parse_audio_device_line(line_str));
+ return true;
+ });
+
+ return audio_devices;
+ }
} \ No newline at end of file
diff --git a/src/Theme.cpp b/src/Theme.cpp
index 0f44126..0c99320 100644
--- a/src/Theme.cpp
+++ b/src/Theme.cpp
@@ -3,32 +3,39 @@
#include <assert.h>
namespace gsr {
- static Theme theme;
- static bool initialized = false;
+ static Theme *theme = nullptr;
void init_theme(const gsr::GsrInfo &gsr_info) {
+ assert(!theme);
+ theme = new Theme();
+
switch(gsr_info.gpu_info.vendor) {
case gsr::GpuVendor::UNKNOWN: {
break;
}
case gsr::GpuVendor::AMD: {
- theme.tint_color = mgl::Color(221, 0, 49);
+ theme->tint_color = mgl::Color(221, 0, 49);
break;
}
case gsr::GpuVendor::INTEL: {
- theme.tint_color = mgl::Color(8, 109, 183);
+ theme->tint_color = mgl::Color(8, 109, 183);
break;
}
case gsr::GpuVendor::NVIDIA: {
- theme.tint_color = mgl::Color(118, 185, 0);
+ theme->tint_color = mgl::Color(118, 185, 0);
break;
}
}
- initialized = true;
+ }
+
+ void deinit_theme() {
+ assert(theme);
+ delete theme;
+ theme = nullptr;
}
const Theme& get_theme() {
- assert(initialized);
- return theme;
+ assert(theme);
+ return *theme;
}
} \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index aaffba2..f27fd7a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -149,6 +149,9 @@ int main(int argc, char **argv) {
fprintf(stderr, "error: failed to get gpu-screen-recorder info\n");
exit(1);
}
+
+ const std::vector<gsr::AudioDevice> audio_devices = gsr::get_audio_devices();
+
gsr::init_theme(gsr_info);
std::string program_root_dir = dirname(argv[0]);
@@ -482,6 +485,11 @@ int main(int argc, char **argv) {
gsr::Page *settings_content_page = settings_content_pages[i];
auto record_area_box = std::make_unique<gsr::ComboBox>(&title_font);
+ record_area_box->set_position(mgl::vec2f(50.0f, 50.0f));
+
+ const mgl::vec2f record_area_pos = record_area_box->get_position();
+ const mgl::vec2f record_area_size = record_area_box->get_size();
+
if(gsr_info.supported_capture_options.window)
record_area_box->add_item("Window", "window");
if(gsr_info.supported_capture_options.focused)
@@ -497,6 +505,13 @@ int main(int argc, char **argv) {
record_area_box->add_item("Desktop portal", "portal");
settings_content_page->add_widget(std::move(record_area_box));
+ auto audio_device_box = std::make_unique<gsr::ComboBox>(&title_font);
+ audio_device_box->set_position(record_area_pos + mgl::vec2f(0.0f, record_area_size.y + 50.0f));
+ for(const auto &audio_device : audio_devices) {
+ audio_device_box->add_item(audio_device.description, audio_device.name);
+ }
+ settings_content_page->add_widget(std::move(audio_device_box));
+
auto back_button = std::make_unique<gsr::Button>(&title_font, "Back", mgl::vec2f(window_size.x / 10, window_size.y / 15), gsr::get_theme().scrollable_page_bg_color);
back_button->set_position(settings_page_position + mgl::vec2f(settings_page_size.x + window_size.x / 50, 0.0f).floor());
back_button->on_click = settings_back_button_callback;
@@ -622,5 +637,6 @@ int main(int argc, char **argv) {
}
fprintf(stderr, "shutting down!\n");
+ gsr::deinit_theme();
return 0;
}