diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 80 |
1 files changed, 43 insertions, 37 deletions
diff --git a/src/main.cpp b/src/main.cpp index 887e854..dec9515 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1744,8 +1744,7 @@ static gboolean on_start_replay_button_click(GtkButton *button, gpointer userdat app_indicator_set_icon_full(app_indicator, get_tray_idle_icon_name(), "Idle"); if(exit_status == 10) { - show_notification(app, "GPU Screen Recorder", - "You need to have pkexec installed and a polkit agent running to record your monitor", G_NOTIFICATION_PRIORITY_URGENT); + show_notification(app, "GPU Screen Recorder", "You need to have pkexec installed and have a polkit agent running to record your monitor", G_NOTIFICATION_PRIORITY_URGENT); } else if(exit_status == 50) { show_notification(app, "GPU Screen Recorder", "Desktop portal capture failed. Either you canceled the desktop portal or your Wayland compositor doesn't support desktop portal capture or it's incorrectly setup on your system", G_NOTIFICATION_PRIORITY_URGENT); } else if(exit_status == 60) { @@ -1951,8 +1950,7 @@ static gboolean on_start_recording_button_click(GtkButton *button, gpointer user app_indicator_set_icon_full(app_indicator, get_tray_idle_icon_name(), "Idle"); if(exit_status == 10) { - show_notification(app, "GPU Screen Recorder", - "You need to have pkexec installed and a polkit agent running to record your monitor", G_NOTIFICATION_PRIORITY_URGENT); + show_notification(app, "GPU Screen Recorder", "You need to have pkexec installed and have a polkit agent running to record your monitor", G_NOTIFICATION_PRIORITY_URGENT); } else if(exit_status == 50) { show_notification(app, "GPU Screen Recorder", "Desktop portal capture failed. Either you canceled the desktop portal or your Wayland compositor doesn't support desktop portal capture or it's incorrectly setup on your system", G_NOTIFICATION_PRIORITY_URGENT); } else if(exit_status == 60) { @@ -2116,8 +2114,7 @@ static gboolean on_start_streaming_button_click(GtkButton *button, gpointer user app_indicator_set_icon_full(app_indicator, get_tray_idle_icon_name(), "Idle"); if(exit_status == 10) { - show_notification(app, "GPU Screen Recorder", - "You need to have pkexec installed and a polkit agent running to record your monitor", G_NOTIFICATION_PRIORITY_URGENT); + show_notification(app, "GPU Screen Recorder", "You need to have pkexec installed and have a polkit agent running to record your monitor", G_NOTIFICATION_PRIORITY_URGENT); } else if(exit_status == 50) { show_notification(app, "GPU Screen Recorder", "Desktop portal capture failed. Either you canceled the desktop portal or your Wayland compositor doesn't support desktop portal capture or it's incorrectly setup on your system", G_NOTIFICATION_PRIORITY_URGENT); } else if(exit_status == 60) { @@ -4246,7 +4243,8 @@ static void load_config() { "Unable to find a hardware video encoder on your system, using software video encoder instead (slow!). If you know that your system supports H264/HEVC hardware video encoding and " "you are using the flatpak version of GPU Screen Recorder then try installing mesa-extra freedesktop runtime by running this command:\n" "flatpak install --system org.freedesktop.Platform.GL.default//23.08-extra\n" - "and then restart GPU Screen Recorder. If that doesn't work then you may have to install another mesa package for your distro.\n" + "and then restart GPU Screen Recorder. If that doesn't work then you may have to install another mesa package for your distro if you are using AMD.\n" + "If you are using NVIDIA then you might need to run the \"nvidia-smi\" command first before starting GPU Screen Recorder if NVIDIA is incorrectly setup on your distro.\n" "If you are using a distro such as manjaro which disables hardware accelerated video encoding then you can also try the <a href=\"https://flathub.org/apps/com.dec05eba.gpu_screen_recorder\">flatpak version of GPU Screen Recorder</a> instead which doesn't have this issue."); set_dialog_selectable(dialog); gtk_dialog_run(GTK_DIALOG(dialog)); @@ -4305,11 +4303,7 @@ static const char* gpu_vendor_to_name(GpuVendor vendor) { return ""; } -static void activate(GtkApplication *app, gpointer) { - flatpak = is_inside_flatpak(); - nvfbc_installed = gsr_info.system_info.display_server != DisplayServer::WAYLAND && is_nv_fbc_installed(); - page_navigation_userdata.app = app; - +static bool gsr_startup_validation() { if(gsr_info_exit_status == GsrInfoExitStatus::FAILED_TO_RUN_COMMAND) { const char *cmd = flatpak ? "flatpak run --command=gpu-screen-recorder com.dec05eba.gpu_screen_recorder -w screen -f 60 -o video.mp4" : "gpu-screen-recorder -w screen -f 60 -o video.mp4"; GtkWidget *dialog = gtk_message_dialog_new_with_markup(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, @@ -4319,8 +4313,7 @@ static void activate(GtkApplication *app, gpointer) { set_dialog_selectable(dialog); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); - g_application_quit(G_APPLICATION(app)); - return; + return false; } if(gsr_info_exit_status == GsrInfoExitStatus::OPENGL_FAILED) { @@ -4331,8 +4324,7 @@ static void activate(GtkApplication *app, gpointer) { set_dialog_selectable(dialog); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); - g_application_quit(G_APPLICATION(app)); - return; + return false; } if(gsr_info_exit_status == GsrInfoExitStatus::NO_DRM_CARD) { @@ -4340,8 +4332,7 @@ static void activate(GtkApplication *app, gpointer) { "Failed to find a valid DRM card. If you are running GPU Screen Recorder with prime-run then try running without it."); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); - g_application_quit(G_APPLICATION(app)); - return; + return false; } if(gsr_info.system_info.display_server == DisplayServer::UNKNOWN) { @@ -4349,8 +4340,7 @@ static void activate(GtkApplication *app, gpointer) { "Neither X11 nor Wayland is running."); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); - g_application_quit(G_APPLICATION(app)); - return; + return false; } if(gsr_info.system_info.display_server == DisplayServer::X11 && !dpy) { @@ -4358,8 +4348,7 @@ static void activate(GtkApplication *app, gpointer) { "Failed to connect to the X11 server"); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); - g_application_quit(G_APPLICATION(app)); - return; + return false; } if(gsr_info.gpu_info.vendor == GpuVendor::NVIDIA) { @@ -4368,8 +4357,7 @@ static void activate(GtkApplication *app, gpointer) { "CUDA is not installed on your system. GPU Screen Recorder requires CUDA to be installed to work with a NVIDIA GPU."); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); - g_application_quit(G_APPLICATION(app)); - return; + return false; } if(!is_nvenc_installed()) { @@ -4377,11 +4365,21 @@ static void activate(GtkApplication *app, gpointer) { "NVENC is not installed on your system. GPU Screen Recorder requires NVENC to be installed to work with a NVIDIA GPU."); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); - g_application_quit(G_APPLICATION(app)); - return; + return false; } } + return true; +} + +static void activate(GtkApplication *app, gpointer) { + if(!gsr_startup_validation()) { + g_application_quit(G_APPLICATION(app)); + return; + } + + page_navigation_userdata.app = app; + std::string window_title = "GPU Screen Recorder v" + std::string(GSR_VERSION) + " | Running on "; window_title += gpu_vendor_to_name(gsr_info.gpu_info.vendor); @@ -4486,7 +4484,7 @@ static bool is_kms_server_proxy_installed() { user_homepath = "/tmp"; char path[PATH_MAX]; - snprintf(path, sizeof(path), "%s/.local/share/gpu-screen-recorder/kms-server-proxy-1", user_homepath); + snprintf(path, sizeof(path), "%s/.local/share/gpu-screen-recorder/kms-server-proxy-2", user_homepath); return access(path, F_OK) == 0; } @@ -4526,6 +4524,11 @@ static void startup_new_ui(bool launched_by_daemon) { } } + start_gtk_run_handler([]() { + if(!gsr_startup_validation()) + exit(0); + }); + if(!flatpak_is_installed_as_system()) { start_gtk_run_handler([]() { GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, @@ -4587,17 +4590,7 @@ int main(int argc, char **argv) { config_empty = false; config = read_config(config_empty); - if(use_old_ui_opt) { - system("flatpak-spawn --host -- systemctl disable --now --user gpu-screen-recorder-ui"); - config.main_config.use_new_ui = false; - save_config(config); - } - - if(config.main_config.use_new_ui) - startup_new_ui(launched_by_daemon_opt); - gsr_info_exit_status = get_gpu_screen_recorder_info(&gsr_info); - if(gsr_info_exit_status == GsrInfoExitStatus::OK) { if(gsr_info.system_info.display_server == DisplayServer::WAYLAND) { setenv("GDK_BACKEND", "wayland", true); @@ -4606,6 +4599,19 @@ int main(int argc, char **argv) { } } + flatpak = is_inside_flatpak(); + nvfbc_installed = gsr_info.system_info.display_server != DisplayServer::WAYLAND && is_nv_fbc_installed(); + + if(use_old_ui_opt) { + system("flatpak-spawn --host -- systemctl disable --user gpu-screen-recorder-ui"); + system("flatpak-spawn --host -- systemctl stop --user gpu-screen-recorder-ui"); + config.main_config.use_new_ui = false; + save_config(config); + } + + if(config.main_config.use_new_ui) + startup_new_ui(launched_by_daemon_opt); + char app_id[] = "com.dec05eba.gpu_screen_recorder"; // Gtk sets wayland app id / x11 wm class from the binary name, so we override it here. // This is needed for the correct window icon on wayland (app id needs to match the desktop file name). |