diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 385 |
1 files changed, 173 insertions, 212 deletions
diff --git a/src/main.cpp b/src/main.cpp index a41a7b7..39ed481 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -104,12 +104,9 @@ static GtkWidget *show_recording_stopped_notification_button; static GtkWidget *show_recording_saved_notification_button; static GtkWidget *record_cursor_button; static GtkWidget *restore_portal_session_button; -static GtkBox *audio_type_radio_button_box; -static GtkWidget *audio_devices_radio_button; -static GtkWidget *application_audio_radio_button; static GtkGrid *audio_devices_grid; -static GtkGrid *application_audio_grid; -static GtkBox *application_audio_items_box; +static GtkWidget *add_application_audio_button; +static GtkWidget *add_custom_application_audio_button; static GtkGrid *video_codec_grid; static GtkGrid *audio_codec_grid; static GtkGrid *color_range_grid; @@ -760,9 +757,13 @@ static gint combo_box_text_get_row_by_label(GtkComboBox *combo_box, const char * static GtkWidget* create_audio_device_combo_box_row(const std::string &selected_row_text) { GtkGrid *grid = GTK_GRID(gtk_grid_new()); + g_object_set_data(G_OBJECT(grid), "audio-track-type", (void*)"device"); gtk_grid_set_column_spacing(grid, 10); gtk_widget_set_hexpand(GTK_WIDGET(grid), true); + GtkLabel *label = GTK_LABEL(gtk_label_new("Device:")); + gtk_grid_attach(grid, GTK_WIDGET(label), 0, 0, 1, 1); + GtkComboBoxText *audio_device_combo_box = GTK_COMBO_BOX_TEXT(gtk_combo_box_text_new()); g_signal_connect(audio_device_combo_box, "scroll-event", G_CALLBACK(scroll_event_ignore), NULL); for(const auto &audio_input : audio_inputs) { @@ -781,10 +782,10 @@ static GtkWidget* create_audio_device_combo_box_row(const std::string &selected_ } gtk_widget_set_hexpand(GTK_WIDGET(audio_device_combo_box), true); - gtk_grid_attach(grid, GTK_WIDGET(audio_device_combo_box), 0, 0, 1, 1); + gtk_grid_attach(grid, GTK_WIDGET(audio_device_combo_box), 1, 0, 1, 1); GtkButton *remove_button = GTK_BUTTON(gtk_button_new_with_label("Remove")); - gtk_grid_attach(grid, GTK_WIDGET(remove_button), 1, 0, 1, 1); + gtk_grid_attach(grid, GTK_WIDGET(remove_button), 2, 0, 1, 1); g_signal_connect(remove_button, "clicked", G_CALLBACK(+[](GtkButton*, gpointer userdata){ GtkGrid *grid = (GtkGrid*)userdata; @@ -797,9 +798,13 @@ static GtkWidget* create_audio_device_combo_box_row(const std::string &selected_ static GtkWidget* create_application_audio_combo_box_row(const std::string &selected_row_id) { GtkGrid *grid = GTK_GRID(gtk_grid_new()); + g_object_set_data(G_OBJECT(grid), "audio-track-type", (void*)"app"); gtk_grid_set_column_spacing(grid, 10); gtk_widget_set_hexpand(GTK_WIDGET(grid), true); + GtkLabel *label = GTK_LABEL(gtk_label_new("Application:")); + gtk_grid_attach(grid, GTK_WIDGET(label), 0, 0, 1, 1); + GtkComboBoxText *application_audio_combo_box = GTK_COMBO_BOX_TEXT(gtk_combo_box_text_new()); g_signal_connect(application_audio_combo_box, "scroll-event", G_CALLBACK(scroll_event_ignore), NULL); for(const std::string &app_audio : application_audio) { @@ -812,10 +817,10 @@ static GtkWidget* create_application_audio_combo_box_row(const std::string &sele gtk_combo_box_set_active_id(GTK_COMBO_BOX(application_audio_combo_box), selected_row_id.c_str()); gtk_widget_set_hexpand(GTK_WIDGET(application_audio_combo_box), true); - gtk_grid_attach(grid, GTK_WIDGET(application_audio_combo_box), 0, 0, 1, 1); + gtk_grid_attach(grid, GTK_WIDGET(application_audio_combo_box), 1, 0, 1, 1); GtkButton *remove_button = GTK_BUTTON(gtk_button_new_with_label("Remove")); - gtk_grid_attach(grid, GTK_WIDGET(remove_button), 1, 0, 1, 1); + gtk_grid_attach(grid, GTK_WIDGET(remove_button), 2, 0, 1, 1); g_signal_connect(remove_button, "clicked", G_CALLBACK(+[](GtkButton*, gpointer userdata){ GtkGrid *grid = (GtkGrid*)userdata; @@ -828,16 +833,20 @@ static GtkWidget* create_application_audio_combo_box_row(const std::string &sele static GtkWidget* create_application_audio_custom_row(const std::string &text) { GtkGrid *grid = GTK_GRID(gtk_grid_new()); + g_object_set_data(G_OBJECT(grid), "audio-track-type", (void*)"app-custom"); gtk_grid_set_column_spacing(grid, 10); gtk_widget_set_hexpand(GTK_WIDGET(grid), true); + GtkLabel *label = GTK_LABEL(gtk_label_new("Application:")); + gtk_grid_attach(grid, GTK_WIDGET(label), 0, 0, 1, 1); + GtkEntry *application_audio_entry = GTK_ENTRY(gtk_entry_new()); gtk_widget_set_hexpand(GTK_WIDGET(application_audio_entry), true); gtk_entry_set_text(application_audio_entry, text.c_str()); - gtk_grid_attach(grid, GTK_WIDGET(application_audio_entry), 0, 0, 1, 1); + gtk_grid_attach(grid, GTK_WIDGET(application_audio_entry), 1, 0, 1, 1); GtkButton *remove_button = GTK_BUTTON(gtk_button_new_with_label("Remove")); - gtk_grid_attach(grid, GTK_WIDGET(remove_button), 1, 0, 1, 1); + gtk_grid_attach(grid, GTK_WIDGET(remove_button), 2, 0, 1, 1); g_signal_connect(remove_button, "clicked", G_CALLBACK(+[](GtkButton*, gpointer userdata){ GtkGrid *grid = (GtkGrid*)userdata; @@ -879,28 +888,23 @@ static void save_configs() { config.main_config.record_app_audio_inverted = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(record_app_audio_inverted_button)); config.main_config.change_video_resolution = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(change_video_resolution_button)); - config.main_config.audio_type_view.clear(); - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(audio_devices_radio_button))) - config.main_config.audio_type_view = "audio_devices"; - else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(application_audio_radio_button))) - config.main_config.audio_type_view = "app_audio"; - config.main_config.audio_input.clear(); gtk_container_foreach(GTK_CONTAINER(audio_devices_items_box), [](GtkWidget *widget, gpointer) { - GtkWidget *row_item_widget = gtk_grid_get_child_at(GTK_GRID(widget), 0, 0); - if(GTK_IS_COMBO_BOX_TEXT(row_item_widget)) - config.main_config.audio_input.push_back(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(row_item_widget))); - }, nullptr); - - config.main_config.application_audio.clear(); - gtk_container_foreach(GTK_CONTAINER(application_audio_items_box), [](GtkWidget *widget, gpointer) { - GtkWidget *row_item_widget = gtk_grid_get_child_at(GTK_GRID(widget), 0, 0); - const char *text = ""; - if(GTK_IS_COMBO_BOX_TEXT(row_item_widget)) - text = gtk_combo_box_get_active_id(GTK_COMBO_BOX(row_item_widget)); - else if(GTK_IS_ENTRY(row_item_widget)) - text = gtk_entry_get_text(GTK_ENTRY(row_item_widget)); - config.main_config.application_audio.push_back(text); + const char *audio_track_type = (const char*)g_object_get_data(G_OBJECT(widget), "audio-track-type"); + GtkWidget *row_item_widget = gtk_grid_get_child_at(GTK_GRID(widget), 1, 0); + if(strcmp(audio_track_type, "device") == 0) { + std::string audio_input_name = "device:"; + audio_input_name += gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(row_item_widget)); + config.main_config.audio_input.push_back(std::move(audio_input_name)); + } else if(strcmp(audio_track_type, "app") == 0) { + std::string audio_input_name = "app:"; + audio_input_name += gtk_combo_box_get_active_id(GTK_COMBO_BOX(row_item_widget)); + config.main_config.audio_input.push_back(std::move(audio_input_name)); + } else if(strcmp(audio_track_type, "app-custom") == 0) { + std::string audio_input_name = "app:"; + audio_input_name += gtk_entry_get_text(GTK_ENTRY(row_item_widget)); + config.main_config.audio_input.push_back(std::move(audio_input_name)); + } }, nullptr); config.main_config.color_range = gtk_combo_box_get_active_id(GTK_COMBO_BOX(color_range_input_menu)); @@ -1573,81 +1577,66 @@ static bool kill_gpu_screen_recorder_get_result(bool *already_dead) { return exit_success; } -struct ApplicationAudioCallbackUserdata { - const char *arg_option; - std::vector<const char*> &args; +static bool starts_with(const std::string &str, const char *substr) { + size_t len = strlen(substr); + return str.size() >= len && memcmp(str.data(), substr, len) == 0; +} + +struct AudioTracksUserdata { + std::vector<std::string> &result; + bool application_audio_invert; }; -static void add_audio_devices_command_line_args(std::vector<const char*> &args, std::string &merge_audio_tracks_arg_value) { - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(merge_audio_tracks_button))) { - gtk_container_foreach(GTK_CONTAINER(audio_devices_items_box), [](GtkWidget *widget, gpointer userdata) { - std::string &merge_audio_tracks_arg_value = *(std::string*)userdata; - GtkWidget *row_item_widget = gtk_grid_get_child_at(GTK_GRID(widget), 0, 0); - - if(GTK_IS_COMBO_BOX_TEXT(row_item_widget)) { - if(!merge_audio_tracks_arg_value.empty()) - merge_audio_tracks_arg_value += '|'; - merge_audio_tracks_arg_value += gtk_combo_box_get_active_id(GTK_COMBO_BOX(row_item_widget)); - } - }, &merge_audio_tracks_arg_value); +static std::vector<std::string> create_audio_tracks_real_names(std::string &merge_audio_tracks) { + std::vector<std::string> result; + AudioTracksUserdata audio_tracks_userdata { + result, + (bool)gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(record_app_audio_inverted_button)) + }; - if(!merge_audio_tracks_arg_value.empty()) - args.insert(args.end(), { "-a", merge_audio_tracks_arg_value.c_str() }); - } else { - gtk_container_foreach(GTK_CONTAINER(audio_devices_items_box), [](GtkWidget *widget, gpointer userdata) { - std::vector<const char*> &args = *(std::vector<const char*>*)userdata; - GtkWidget *row_item_widget = gtk_grid_get_child_at(GTK_GRID(widget), 0, 0); + gtk_container_foreach(GTK_CONTAINER(audio_devices_items_box), [](GtkWidget *widget, gpointer userdata) { + AudioTracksUserdata &audio_tracks_userdata = *(AudioTracksUserdata*)userdata; + const char *audio_track_type = (const char*)g_object_get_data(G_OBJECT(widget), "audio-track-type"); + GtkWidget *row_item_widget = gtk_grid_get_child_at(GTK_GRID(widget), 1, 0); + if(strcmp(audio_track_type, "device") == 0) { + std::string audio_input_name = "device:"; + audio_input_name += gtk_combo_box_get_active_id(GTK_COMBO_BOX(row_item_widget)); + audio_tracks_userdata.result.push_back(std::move(audio_input_name)); + } else if(strcmp(audio_track_type, "app") == 0) { + if(!gsr_info.system_info.supports_app_audio) + return; + + std::string audio_input_name = audio_tracks_userdata.application_audio_invert ? "app-inverse:" : "app:"; + audio_input_name += gtk_combo_box_get_active_id(GTK_COMBO_BOX(row_item_widget)); + audio_tracks_userdata.result.push_back(std::move(audio_input_name)); + } else if(strcmp(audio_track_type, "app-custom") == 0) { + if(!gsr_info.system_info.supports_app_audio) + return; + + std::string audio_input_name = audio_tracks_userdata.application_audio_invert ? "app-inverse:" : "app:"; + audio_input_name += gtk_entry_get_text(GTK_ENTRY(row_item_widget)); + audio_tracks_userdata.result.push_back(std::move(audio_input_name)); + } + }, &audio_tracks_userdata); - if(GTK_IS_COMBO_BOX_TEXT(row_item_widget)) - args.insert(args.end(), { "-a", gtk_combo_box_get_active_id(GTK_COMBO_BOX(row_item_widget)) }); - }, &args); + merge_audio_tracks.clear(); + for(size_t i = 0; i < result.size(); ++i) { + if(i > 0) + merge_audio_tracks += '|'; + merge_audio_tracks += result[i]; } -} -static void add_application_audio_command_line_args(std::vector<const char*> &args, std::string &merge_audio_tracks_arg_value) { - const char *arg_option = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(record_app_audio_inverted_button)) ? "-aai" : "-aa"; - ApplicationAudioCallbackUserdata app_audio_callback = { - arg_option, - args - }; + return result; +} +static void add_audio_command_line_args(std::vector<const char*> &args, const std::vector<std::string> &audio_tracks, const std::string &merge_audio_tracks) { if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(merge_audio_tracks_button))) { - gtk_container_foreach(GTK_CONTAINER(application_audio_items_box), [](GtkWidget *widget, gpointer userdata) { - std::string &merge_audio_tracks_arg_value = *(std::string*)userdata; - GtkWidget *row_item_widget = gtk_grid_get_child_at(GTK_GRID(widget), 0, 0); - - const char *text = ""; - if(GTK_IS_COMBO_BOX_TEXT(row_item_widget)) - text = gtk_combo_box_get_active_id(GTK_COMBO_BOX(row_item_widget)); - else if(GTK_IS_ENTRY(row_item_widget)) - text = gtk_entry_get_text(GTK_ENTRY(row_item_widget)); - - if(!merge_audio_tracks_arg_value.empty()) - merge_audio_tracks_arg_value += '|'; - merge_audio_tracks_arg_value += text; - }, &merge_audio_tracks_arg_value); - - if(!merge_audio_tracks_arg_value.empty()) - args.insert(args.end(), { arg_option, merge_audio_tracks_arg_value.c_str() }); + if(!merge_audio_tracks.empty()) + args.insert(args.end(), { "-a", merge_audio_tracks.c_str() }); } else { - gtk_container_foreach(GTK_CONTAINER(application_audio_items_box), [](GtkWidget *widget, gpointer userdata) { - ApplicationAudioCallbackUserdata *app_audio_callback = (ApplicationAudioCallbackUserdata*)userdata; - GtkWidget *row_item_widget = gtk_grid_get_child_at(GTK_GRID(widget), 0, 0); - const char *text = ""; - if(GTK_IS_COMBO_BOX_TEXT(row_item_widget)) - text = gtk_combo_box_get_active_id(GTK_COMBO_BOX(row_item_widget)); - else if(GTK_IS_ENTRY(row_item_widget)) - text = gtk_entry_get_text(GTK_ENTRY(row_item_widget)); - app_audio_callback->args.insert(app_audio_callback->args.end(), { app_audio_callback->arg_option, text }); - }, &app_audio_callback); - } -} - -static void add_audio_command_line_args(std::vector<const char*> &args, std::string &merge_audio_tracks_arg_value) { - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(audio_devices_radio_button))) { - add_audio_devices_command_line_args(args, merge_audio_tracks_arg_value); - } else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(application_audio_radio_button))) { - add_application_audio_command_line_args(args, merge_audio_tracks_arg_value); + for(const std::string &audio_track : audio_tracks) { + args.insert(args.end(), { "-a", audio_track.c_str() }); + } } } @@ -1695,6 +1684,15 @@ static void add_quality_command_line_args(std::vector<const char*> &args, const } } +static void debug_print_args(const char **args) { + fprintf(stderr, "info: running command:"); + while(*args) { + fprintf(stderr, " %s", *args); + ++args; + } + fprintf(stderr, "\n"); +} + static gboolean on_start_replay_button_click(GtkButton *button, gpointer userdata) { GtkApplication *app = (GtkApplication*)userdata; const gchar *dir = gtk_button_get_label(replay_file_chooser_button); @@ -1804,13 +1802,15 @@ static gboolean on_start_replay_button_click(GtkButton *button, gpointer userdat if(strcmp(framerate_mode_input_str, "auto") != 0) args.insert(args.end(), { "-fm", framerate_mode_input_str }); - std::string merge_audio_tracks_arg_value; - add_audio_command_line_args(args, merge_audio_tracks_arg_value); + std::string merge_audio_tracks; + const std::vector<std::string> audio_tracks = create_audio_tracks_real_names(merge_audio_tracks); + add_audio_command_line_args(args, audio_tracks, merge_audio_tracks); if(follow_focused || change_video_resolution) args.insert(args.end(), { "-s", area }); args.push_back(NULL); + debug_print_args(args.data()); if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(hide_window_when_recording_menu_item))) { hide_window(); @@ -2009,13 +2009,15 @@ static gboolean on_start_recording_button_click(GtkButton *button, gpointer user if(strcmp(framerate_mode_input_str, "auto") != 0) args.insert(args.end(), { "-fm", framerate_mode_input_str }); - std::string merge_audio_tracks_arg_value; - add_audio_command_line_args(args, merge_audio_tracks_arg_value); + std::string merge_audio_tracks; + const std::vector<std::string> audio_tracks = create_audio_tracks_real_names(merge_audio_tracks); + add_audio_command_line_args(args, audio_tracks, merge_audio_tracks); if(follow_focused || change_video_resolution) args.insert(args.end(), { "-s", area }); args.push_back(NULL); + debug_print_args(args.data()); if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(hide_window_when_recording_menu_item))) { hide_window(); @@ -2188,13 +2190,15 @@ static gboolean on_start_streaming_button_click(GtkButton *button, gpointer user if(strcmp(framerate_mode_input_str, "auto") != 0) args.insert(args.end(), { "-fm", framerate_mode_input_str }); - std::string merge_audio_tracks_arg_value; - add_audio_command_line_args(args, merge_audio_tracks_arg_value); + std::string merge_audio_tracks; + const std::vector<std::string> audio_tracks = create_audio_tracks_real_names(merge_audio_tracks); + add_audio_command_line_args(args, audio_tracks, merge_audio_tracks); if(follow_focused || change_video_resolution) args.insert(args.end(), { "-s", area }); args.push_back(NULL); + debug_print_args(args.data()); if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(hide_window_when_recording_menu_item))) { hide_window(); @@ -2607,11 +2611,6 @@ enum class GsrInfoSection { CAPTURE_OPTIONS }; -static bool starts_with(const std::string &str, const char *substr) { - size_t len = strlen(substr); - return str.size() >= len && memcmp(str.data(), substr, len) == 0; -} - static GsrInfoExitStatus get_gpu_screen_recorder_info(GsrInfo *_gsr_info) { *_gsr_info = GsrInfo{}; @@ -2707,19 +2706,6 @@ static void video_codec_set_sensitive(GtkCellLayout *cell_layout, GtkCellRendere g_free(id); } -static void audio_devices_application_audio_radio_toggled(GtkButton *button, gpointer) { - if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) - return; - - if(GTK_WIDGET(button) == audio_devices_radio_button) { - gtk_widget_set_visible(GTK_WIDGET(audio_devices_grid), true); - gtk_widget_set_visible(GTK_WIDGET(application_audio_grid), false); - } else if(GTK_WIDGET(button) == application_audio_radio_button) { - gtk_widget_set_visible(GTK_WIDGET(audio_devices_grid), false); - gtk_widget_set_visible(GTK_WIDGET(application_audio_grid), true); - } -} - static GtkWidget* create_common_settings_page(GtkStack *stack, GtkApplication *app) { GtkGrid *main_grid = GTK_GRID(gtk_grid_new()); gtk_stack_add_named(stack, GTK_WIDGET(main_grid), "common-settings"); @@ -2751,8 +2737,8 @@ static GtkWidget* create_common_settings_page(GtkStack *stack, GtkApplication *a GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL)); gtk_scrolled_window_set_min_content_width(scrolled_window, 100); gtk_scrolled_window_set_min_content_height(scrolled_window, 100); - gtk_scrolled_window_set_max_content_width(scrolled_window, 1280); - gtk_scrolled_window_set_max_content_height(scrolled_window, 800); + gtk_scrolled_window_set_max_content_width(scrolled_window, 1200); + gtk_scrolled_window_set_max_content_height(scrolled_window, 700); gtk_scrolled_window_set_propagate_natural_width(scrolled_window, true); gtk_scrolled_window_set_propagate_natural_height(scrolled_window, true); gtk_grid_attach(main_grid, GTK_WIDGET(scrolled_window), 0, main_grid_row++, 2, 1); @@ -2866,7 +2852,10 @@ static GtkWidget* create_common_settings_page(GtkStack *stack, GtkApplication *a gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(record_area_selection_menu), renderer, "text", 0, NULL); gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(record_area_selection_menu), renderer, record_area_set_sensitive, NULL, NULL); - gtk_combo_box_set_active(record_area_selection_menu, (allow_screen_capture || gsr_info.supported_capture_options.portal) ? 2 : 0); + if(allow_screen_capture || gsr_info.supported_capture_options.portal) + gtk_combo_box_set_active(record_area_selection_menu, 2); + else + gtk_combo_box_set_active(record_area_selection_menu, 0); gtk_widget_set_hexpand(GTK_WIDGET(record_area_selection_menu), true); gtk_grid_attach(record_area_grid, GTK_WIDGET(record_area_selection_menu), 0, record_area_row++, 3, 1); @@ -2948,19 +2937,6 @@ static GtkWidget* create_common_settings_page(GtkStack *stack, GtkApplication *a gtk_widget_set_margin(GTK_WIDGET(audio_grid), 10, 10, 10, 10); gtk_container_add(GTK_CONTAINER(audio_input_frame), GTK_WIDGET(audio_grid)); - audio_type_radio_button_box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10)); - gtk_grid_attach(audio_grid, GTK_WIDGET(audio_type_radio_button_box), 0, audio_input_area_row++, 2, 1); - - audio_devices_radio_button = gtk_radio_button_new_with_label_from_widget(nullptr, "Audio devices"); - gtk_box_pack_start(audio_type_radio_button_box, audio_devices_radio_button, false, false, 0); - g_signal_connect(audio_devices_radio_button, "toggled", G_CALLBACK(audio_devices_application_audio_radio_toggled), nullptr); - - application_audio_radio_button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(audio_devices_radio_button), "Application audio"); - gtk_box_pack_start(audio_type_radio_button_box, GTK_WIDGET(application_audio_radio_button), false, false, 0); - g_signal_connect(application_audio_radio_button, "toggled", G_CALLBACK(audio_devices_application_audio_radio_toggled), nullptr); - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(audio_devices_radio_button), true); - { int audio_devices_row = 0; @@ -2973,7 +2949,7 @@ static GtkWidget* create_common_settings_page(GtkStack *stack, GtkApplication *a GtkGrid *add_audio_grid = GTK_GRID(gtk_grid_new()); gtk_grid_set_row_spacing(add_audio_grid, 10); gtk_grid_set_column_spacing(add_audio_grid, 10); - gtk_grid_attach(audio_devices_grid, GTK_WIDGET(add_audio_grid), 0, audio_devices_row++, 1, 1); + gtk_grid_attach(audio_devices_grid, GTK_WIDGET(add_audio_grid), 0, audio_devices_row++, 2, 1); GtkWidget *add_audio_device_button = gtk_button_new_with_label("Add audio device"); gtk_grid_attach(add_audio_grid, add_audio_device_button, 0, 0, 1, 1); @@ -2985,49 +2961,27 @@ static GtkWidget* create_common_settings_page(GtkStack *stack, GtkApplication *a return true; }), nullptr); - audio_devices_items_box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 10)); - gtk_grid_attach(audio_devices_grid, GTK_WIDGET(audio_devices_items_box), 0, audio_devices_row++, 2, 1); - } - - { - int application_audio_row = 0; - - application_audio_grid = GTK_GRID(gtk_grid_new()); - gtk_grid_set_row_spacing(application_audio_grid, 10); - gtk_grid_set_column_spacing(application_audio_grid, 10); - gtk_widget_set_margin(GTK_WIDGET(application_audio_grid), 0, 0, 0, 0); - gtk_grid_attach(audio_grid, GTK_WIDGET(application_audio_grid), 0, audio_input_area_row++, 2, 1); - - GtkGrid *add_button_grid = GTK_GRID(gtk_grid_new()); - gtk_grid_set_column_spacing(add_button_grid, 10); - gtk_grid_attach(application_audio_grid, GTK_WIDGET(add_button_grid), 0, application_audio_row++, 2, 1); - - GtkWidget *add_application_audio_button = gtk_button_new_with_label("Add application audio"); - gtk_grid_attach(add_button_grid, add_application_audio_button, 0, 0, 1, 1); + add_application_audio_button = gtk_button_new_with_label("Add application audio"); + gtk_grid_attach(add_audio_grid, add_application_audio_button, 1, 0, 1, 1); g_signal_connect(add_application_audio_button, "clicked", G_CALLBACK(+[](GtkButton*, gpointer){ application_audio = get_application_audio(); GtkWidget *row = create_application_audio_combo_box_row(""); gtk_widget_show_all(row); - gtk_box_pack_start(application_audio_items_box, row, false, false, 0); + gtk_box_pack_start(audio_devices_items_box, row, false, false, 0); return true; }), nullptr); - GtkWidget *add_custom_application_audio_button = gtk_button_new_with_label("Add custom application audio"); - gtk_grid_attach(add_button_grid, add_custom_application_audio_button, 1, 0, 1, 1); + add_custom_application_audio_button = gtk_button_new_with_label("Add custom application audio"); + gtk_grid_attach(add_audio_grid, add_custom_application_audio_button, 3, 0, 1, 1); g_signal_connect(add_custom_application_audio_button, "clicked", G_CALLBACK(+[](GtkButton*, gpointer){ GtkWidget *row = create_application_audio_custom_row(""); gtk_widget_show_all(row); - gtk_box_pack_start(application_audio_items_box, row, false, false, 0); + gtk_box_pack_start(audio_devices_items_box, row, false, false, 0); return true; }), nullptr); - application_audio_items_box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 10)); - gtk_grid_attach(application_audio_grid, GTK_WIDGET(application_audio_items_box), 0, application_audio_row++, 2, 1); - - record_app_audio_inverted_button = gtk_check_button_new_with_label("Record audio from all applications except the selected ones"); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(record_app_audio_inverted_button), false); - gtk_widget_set_halign(record_app_audio_inverted_button, GTK_ALIGN_START); - gtk_grid_attach(application_audio_grid, record_app_audio_inverted_button, 0, application_audio_row++, 2, 1); + audio_devices_items_box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 10)); + gtk_grid_attach(audio_devices_grid, GTK_WIDGET(audio_devices_items_box), 0, audio_devices_row++, 2, 1); } merge_audio_tracks_button = gtk_check_button_new_with_label("Merge audio tracks"); @@ -3035,6 +2989,11 @@ static GtkWidget* create_common_settings_page(GtkStack *stack, GtkApplication *a gtk_widget_set_halign(merge_audio_tracks_button, GTK_ALIGN_START); gtk_grid_attach(audio_grid, merge_audio_tracks_button, 0, audio_input_area_row++, 2, 1); + record_app_audio_inverted_button = gtk_check_button_new_with_label("Record audio from all applications except the selected ones"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(record_app_audio_inverted_button), false); + gtk_widget_set_halign(record_app_audio_inverted_button, GTK_ALIGN_START); + gtk_grid_attach(audio_grid, record_app_audio_inverted_button, 0, audio_input_area_row++, 2, 1); + audio_codec_grid = GTK_GRID(gtk_grid_new()); gtk_grid_attach(audio_grid, GTK_WIDGET(audio_codec_grid), 0, audio_input_area_row++, 2, 1); gtk_grid_attach(audio_codec_grid, gtk_label_new("Audio codec: "), 0, 0, 1, 1); @@ -3325,20 +3284,19 @@ static gboolean on_register_hotkeys_button_clicked(GtkButton *button, gpointer u Key names are defined here: https://github.com/xkbcommon/libxkbcommon/blob/master/include/xkbcommon/xkbcommon-keysyms.h. Remove the XKB_KEY_ (or XKB_KEY_KP_) prefix from the name and user the remaining part. */ - /* LOGO = Super key */ /* Unfortunately global shortcuts cant handle same key for different shortcuts, even though GPU Screen Recorder has page specific hotkeys */ const gsr_bind_shortcut shortcuts[3] = { { "Start/stop recording/replay/streaming", - { SHORTCUT_ID_START_STOP_RECORDING, "LOGO+f1" } + { SHORTCUT_ID_START_STOP_RECORDING, "ALT+1" } }, { "Pause/unpause recording", - { SHORTCUT_ID_PAUSE_UNPAUSE_RECORDING, "LOGO+f2" } + { SHORTCUT_ID_PAUSE_UNPAUSE_RECORDING, "ALT+2" } }, { "Save replay", - { SHORTCUT_ID_SAVE_REPLAY, "LOGO+f3" } + { SHORTCUT_ID_SAVE_REPLAY, "ALT+3" } } }; @@ -3385,14 +3343,14 @@ static void create_replay_hotkey_items(GtkGrid *parent_grid, int row, int num_co gtk_grid_attach(replay_hotkeys_grid, gtk_label_new("Press"), 0, hotkeys_row, 1, 1); replay_start_stop_hotkey_button = gtk_entry_new(); - gtk_entry_set_text(GTK_ENTRY(replay_start_stop_hotkey_button), gsr_info.system_info.display_server == DisplayServer::WAYLAND ? "" : "Super + F1"); + gtk_entry_set_text(GTK_ENTRY(replay_start_stop_hotkey_button), gsr_info.system_info.display_server == DisplayServer::WAYLAND ? "" : "Alt + 1"); g_signal_connect(replay_start_stop_hotkey_button, "button-press-event", G_CALLBACK(on_hotkey_entry_click), replay_start_stop_hotkey_button); gtk_grid_attach(replay_hotkeys_grid, replay_start_stop_hotkey_button, 1, hotkeys_row, 1, 1); gtk_grid_attach(replay_hotkeys_grid, gtk_label_new("to start/stop the replay and"), 2, hotkeys_row, 1, 1); replay_save_hotkey_button = gtk_entry_new(); - gtk_entry_set_text(GTK_ENTRY(replay_save_hotkey_button), gsr_info.system_info.display_server == DisplayServer::WAYLAND ? "" : "Super + F2"); + gtk_entry_set_text(GTK_ENTRY(replay_save_hotkey_button), gsr_info.system_info.display_server == DisplayServer::WAYLAND ? "" : "Alt + 2"); g_signal_connect(replay_save_hotkey_button, "button-press-event", G_CALLBACK(on_hotkey_entry_click), replay_save_hotkey_button); gtk_grid_attach(replay_hotkeys_grid, replay_save_hotkey_button, 3, hotkeys_row, 1, 1); @@ -3516,8 +3474,8 @@ static GtkWidget* create_replay_page(GtkApplication *app, GtkStack *stack) { gtk_widget_set_valign(replay_record_time_label, GTK_ALIGN_CENTER); gtk_grid_attach(replay_bottom_panel_grid, replay_record_time_label, 1, 0, 1, 1); - replay_start_stop_hotkey.modkey_mask = modkey_to_mask(XK_Super_L); - replay_start_stop_hotkey.keysym = XK_F1; + replay_start_stop_hotkey.modkey_mask = modkey_to_mask(XK_Alt_L); + replay_start_stop_hotkey.keysym = XK_1; replay_start_stop_hotkey.hotkey_entry = replay_start_stop_hotkey_button; replay_start_stop_hotkey.hotkey_active_label = hotkey_active_label; replay_start_stop_hotkey.config = &config.replay_config.start_stop_recording_hotkey; @@ -3526,8 +3484,8 @@ static GtkWidget* create_replay_page(GtkApplication *app, GtkStack *stack) { replay_start_stop_hotkey.associated_button = start_replay_button; replay_start_stop_hotkey.shortcut_id = SHORTCUT_ID_START_STOP_RECORDING; - replay_save_hotkey.modkey_mask = modkey_to_mask(XK_Super_L); - replay_save_hotkey.keysym = XK_F2; + replay_save_hotkey.modkey_mask = modkey_to_mask(XK_Alt_L); + replay_save_hotkey.keysym = XK_2; replay_save_hotkey.hotkey_entry = replay_save_hotkey_button; replay_save_hotkey.hotkey_active_label = hotkey_active_label; replay_save_hotkey.config = &config.replay_config.save_recording_hotkey; @@ -3554,14 +3512,14 @@ static void create_recording_hotkey_items(GtkGrid *parent_grid, int row, int num gtk_grid_attach(recording_hotkeys_grid, gtk_label_new("Press"), 0, hotkeys_row, 1, 1); record_start_stop_hotkey_button = gtk_entry_new(); - gtk_entry_set_text(GTK_ENTRY(record_start_stop_hotkey_button), gsr_info.system_info.display_server == DisplayServer::WAYLAND ? "" : "Super + F1"); + gtk_entry_set_text(GTK_ENTRY(record_start_stop_hotkey_button), gsr_info.system_info.display_server == DisplayServer::WAYLAND ? "" : "Alt + 1"); g_signal_connect(record_start_stop_hotkey_button, "button-press-event", G_CALLBACK(on_hotkey_entry_click), record_start_stop_hotkey_button); gtk_grid_attach(recording_hotkeys_grid, record_start_stop_hotkey_button, 1, hotkeys_row, 1, 1); gtk_grid_attach(recording_hotkeys_grid, gtk_label_new("to start/stop recording and"), 2, hotkeys_row, 1, 1); pause_unpause_hotkey_button = gtk_entry_new(); - gtk_entry_set_text(GTK_ENTRY(pause_unpause_hotkey_button), gsr_info.system_info.display_server == DisplayServer::WAYLAND ? "" : "Super + F2"); + gtk_entry_set_text(GTK_ENTRY(pause_unpause_hotkey_button), gsr_info.system_info.display_server == DisplayServer::WAYLAND ? "" : "Alt + 2"); g_signal_connect(pause_unpause_hotkey_button, "button-press-event", G_CALLBACK(on_hotkey_entry_click), pause_unpause_hotkey_button); gtk_grid_attach(recording_hotkeys_grid, pause_unpause_hotkey_button, 3, hotkeys_row, 1, 1); @@ -3676,8 +3634,8 @@ static GtkWidget* create_recording_page(GtkApplication *app, GtkStack *stack) { gtk_widget_set_valign(recording_record_time_label, GTK_ALIGN_CENTER); gtk_grid_attach(recording_bottom_panel_grid, recording_record_time_label, 1, 0, 1, 1); - record_start_stop_hotkey.modkey_mask = modkey_to_mask(XK_Super_L); - record_start_stop_hotkey.keysym = XK_F1; + record_start_stop_hotkey.modkey_mask = modkey_to_mask(XK_Alt_L); + record_start_stop_hotkey.keysym = XK_1; record_start_stop_hotkey.hotkey_entry = record_start_stop_hotkey_button; record_start_stop_hotkey.hotkey_active_label = hotkey_active_label; record_start_stop_hotkey.config = &config.record_config.start_stop_recording_hotkey; @@ -3686,8 +3644,8 @@ static GtkWidget* create_recording_page(GtkApplication *app, GtkStack *stack) { record_start_stop_hotkey.associated_button = start_recording_button; record_start_stop_hotkey.shortcut_id = SHORTCUT_ID_START_STOP_RECORDING; - pause_unpause_hotkey.modkey_mask = modkey_to_mask(XK_Super_L); - pause_unpause_hotkey.keysym = XK_F2; + pause_unpause_hotkey.modkey_mask = modkey_to_mask(XK_Alt_L); + pause_unpause_hotkey.keysym = XK_2; pause_unpause_hotkey.hotkey_entry = pause_unpause_hotkey_button; pause_unpause_hotkey.hotkey_active_label = hotkey_active_label; pause_unpause_hotkey.config = &config.record_config.pause_unpause_recording_hotkey; @@ -3714,7 +3672,7 @@ static void create_streaming_hotkey_items(GtkGrid *parent_grid, int row, int num gtk_grid_attach(streaming_hotkeys_grid, gtk_label_new("Press"), 0, hotkeys_row, 1, 1); streaming_start_stop_hotkey_button = gtk_entry_new(); - gtk_entry_set_text(GTK_ENTRY(streaming_start_stop_hotkey_button), gsr_info.system_info.display_server == DisplayServer::WAYLAND ? "" : "Super + F1"); + gtk_entry_set_text(GTK_ENTRY(streaming_start_stop_hotkey_button), gsr_info.system_info.display_server == DisplayServer::WAYLAND ? "" : "Alt + 1"); g_signal_connect(streaming_start_stop_hotkey_button, "button-press-event", G_CALLBACK(on_hotkey_entry_click), streaming_start_stop_hotkey_button); gtk_grid_attach(streaming_hotkeys_grid, streaming_start_stop_hotkey_button, 1, hotkeys_row, 1, 1); @@ -3836,8 +3794,8 @@ static GtkWidget* create_streaming_page(GtkApplication *app, GtkStack *stack) { gtk_widget_set_valign(streaming_record_time_label, GTK_ALIGN_CENTER); gtk_grid_attach(streaming_bottom_panel_grid, streaming_record_time_label, 1, 0, 1, 1); - streaming_start_stop_hotkey.modkey_mask = modkey_to_mask(XK_Super_L); - streaming_start_stop_hotkey.keysym = XK_F1; + streaming_start_stop_hotkey.modkey_mask = modkey_to_mask(XK_Alt_L); + streaming_start_stop_hotkey.keysym = XK_1; streaming_start_stop_hotkey.hotkey_entry = streaming_start_stop_hotkey_button; streaming_start_stop_hotkey.hotkey_active_label = hotkey_active_label; streaming_start_stop_hotkey.config = &config.streaming_config.start_stop_recording_hotkey; @@ -4043,7 +4001,23 @@ static void load_config() { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(change_video_resolution_button), config.main_config.change_video_resolution); for(const std::string &audio_input : config.main_config.audio_input) { - GtkWidget *row = create_audio_device_combo_box_row(audio_input); + GtkWidget *row = nullptr; + if(starts_with(audio_input, "app:")) { + if(!gsr_info.system_info.supports_app_audio) + continue; + + std::string audio_input_name = audio_input.substr(4); + const std::string *app_audio_existing = get_application_audio_by_name_case_insensitive(application_audio, audio_input_name); + if(app_audio_existing) + row = create_application_audio_combo_box_row(*app_audio_existing); + else + row = create_application_audio_custom_row(std::move(audio_input_name)); + } else if(starts_with(audio_input, "device:")) { + row = create_audio_device_combo_box_row(audio_input.substr(7)); + } else { + row = create_audio_device_combo_box_row(audio_input); + } + gtk_widget_show_all(row); gtk_box_pack_start(audio_devices_items_box, row, false, false, 0); } @@ -4054,18 +4028,6 @@ static void load_config() { gtk_box_pack_start(audio_devices_items_box, row, false, false, 0); } - for(const std::string &app_audio : config.main_config.application_audio) { - const std::string *app_audio_existing = get_application_audio_by_name_case_insensitive(application_audio, app_audio); - GtkWidget *row = nullptr; - if(app_audio_existing) - row = create_application_audio_combo_box_row(*app_audio_existing); - else - row = create_application_audio_custom_row(app_audio); - - gtk_widget_show_all(row); - gtk_box_pack_start(application_audio_items_box, row, false, false, 0); - } - gtk_combo_box_set_active_id(GTK_COMBO_BOX(color_range_input_menu), config.main_config.color_range.c_str()); gtk_combo_box_set_active_id(GTK_COMBO_BOX(quality_input_menu), config.main_config.quality.c_str()); video_codec_selection_menu_set_active_id("auto"); @@ -4116,16 +4078,9 @@ static void load_config() { on_change_video_resolution_button_click(GTK_BUTTON(change_video_resolution_button), nullptr); if(!gsr_info.system_info.supports_app_audio) { - gtk_widget_set_visible(GTK_WIDGET(audio_type_radio_button_box), false); - gtk_widget_set_visible(GTK_WIDGET(application_audio_grid), false); - } - - if(config.main_config.audio_type_view == "app_audio" && gsr_info.system_info.supports_app_audio) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(application_audio_radio_button), true); - audio_devices_application_audio_radio_toggled(GTK_BUTTON(application_audio_radio_button), nullptr); - } else /*if(config.main_config.audio_type_view == "audio_devices") */{ - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(audio_devices_radio_button), true); - audio_devices_application_audio_radio_toggled(GTK_BUTTON(audio_devices_radio_button), nullptr); + gtk_widget_set_visible(GTK_WIDGET(add_application_audio_button), false); + gtk_widget_set_visible(GTK_WIDGET(add_custom_application_audio_button), false); + gtk_widget_set_visible(GTK_WIDGET(record_app_audio_inverted_button), false); } std::string dummy; @@ -4211,8 +4166,9 @@ static void activate(GtkApplication *app, gpointer) { if(gsr_info_exit_status == GsrInfoExitStatus::OPENGL_FAILED) { GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, - "Failed to get OpenGL information. Make sure your GPU drivers are properly installed. " - "If you are using nvidia then make sure to run \"flatpak update\" to make sure that your flatpak nvidia driver version matches your distros nvidia driver version. If this doesn't work then you might need to manually install a flatpak nvidia driver version that matches your distros nvidia driver version."); + "Failed to get OpenGL information. Make sure your GPU drivers are properly installed.\n" + "If you are using nvidia then make sure to run \"flatpak update\" to make sure that your flatpak nvidia driver version matches your distros nvidia driver version. If this doesn't work then you might need to manually install a flatpak nvidia driver version that matches your distros nvidia driver version.\n" + "If you are using nvidia and have recently updated your nvidia driver then make sure to reboot your computer first."); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); g_application_quit(G_APPLICATION(app)); @@ -4367,6 +4323,11 @@ static void activate(GtkApplication *app, gpointer) { int main(int argc, char **argv) { setlocale(LC_ALL, "C"); + if(geteuid() == 0) { + fprintf(stderr, "Error: don't run gpu-screen-recorder-gtk as the root user\n"); + return 1; + } + dpy = XOpenDisplay(NULL); gsr_info_exit_status = get_gpu_screen_recorder_info(&gsr_info); |