diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 112 |
1 files changed, 54 insertions, 58 deletions
diff --git a/src/main.cpp b/src/main.cpp index f515e2f..9d92b23 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,7 +20,7 @@ extern "C" { #include <vector> #include <libayatana-appindicator/app-indicator.h> -#define GSR_CURRENT_GLOBAL_HOTKEYS_CODE_VERSION 4 +#define GSR_CURRENT_GLOBAL_HOTKEYS_CODE_VERSION 5 #ifndef GSR_VERSION #define GSR_VERSION "unknown" @@ -1711,6 +1711,16 @@ static void debug_print_args(const char **args) { fprintf(stderr, "\n"); } +static bool validate_window(GtkApplication *app, Window window) { + XWindowAttributes attr; + if(XGetWindowAttributes(dpy, window, &attr)) { + return true; + } else { + show_notification(app, "GPU Screen Recorder", "The window you are trying to record no longer exists", G_NOTIFICATION_PRIORITY_URGENT); + return false; + } +} + 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); @@ -1772,6 +1782,8 @@ static gboolean on_start_replay_button_click(GtkButton *button, gpointer userdat return true; } window_str = std::to_string(select_window_userdata.selected_window); + if(!validate_window(app, select_window_userdata.selected_window)) + return true; } else if(window_str == "focused") { follow_focused = true; } @@ -1968,6 +1980,8 @@ static gboolean on_start_recording_button_click(GtkButton *button, gpointer user return true; } window_str = std::to_string(select_window_userdata.selected_window); + if(!validate_window(app, select_window_userdata.selected_window)) + return true; } else if(window_str == "focused") { follow_focused = true; } @@ -2130,6 +2144,8 @@ static gboolean on_start_streaming_button_click(GtkButton *button, gpointer user return true; } window_str = std::to_string(select_window_userdata.selected_window); + if(!validate_window(app, select_window_userdata.selected_window)) + return true; } else if(window_str == "focused") { follow_focused = true; } @@ -2734,6 +2750,39 @@ static void launch_gsr_ui(bool show_ui) { gtk_widget_destroy(dialog); } +static bool kms_server_proxy_setup_gsr_ui(const char *msg) { + GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "%s", msg); + const gint response = gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + switch(response) { + case GTK_RESPONSE_YES: + break; + case GTK_RESPONSE_NO: + default: { + config.main_config.use_new_ui = false; + save_config(config); + return false; + } + } + + const int exit_code = system("flatpak-spawn --host -- /var/lib/flatpak/app/com.dec05eba.gpu_screen_recorder/current/active/files/bin/kms-server-proxy setup-gsr-ui"); + if(exit_code != 0) { + GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Failed to setup the new UI. You either cancelled the installation or you don't have pkexec installed and a polkit agent running."); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + config.main_config.use_new_ui = false; + save_configs(); + return false; + } + + config.main_config.use_new_ui = true; + config.main_config.installed_gsr_global_hotkeys_version = GSR_CURRENT_GLOBAL_HOTKEYS_CODE_VERSION; + save_config(config); + return true; +} + static gboolean on_click_switch_to_new_ui(GtkButton*, gpointer) { if(!dpy) { GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, @@ -2783,33 +2832,12 @@ static gboolean on_click_switch_to_new_ui(GtkButton*, gpointer) { return true; } - dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, + const bool kms_server_setup_finished = kms_server_proxy_setup_gsr_ui( "The new UI needs root privileges to finish setup to make global hotkeys and recording work on any system. The new UI will also be added to system startup.\n" "\n" "Are you sure you want to continue?"); - response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - - switch(response) { - case GTK_RESPONSE_YES: - break; - case GTK_RESPONSE_NO: - default: - return true; - } - - const int exit_code = system("flatpak-spawn --host -- /var/lib/flatpak/app/com.dec05eba.gpu_screen_recorder/current/active/files/bin/kms-server-proxy setup-gsr-ui"); - if(exit_code != 0) { - GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, - "Failed to setup the new UI. You either cancelled the installation or you don't have pkexec installed and a polkit agent running."); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); + if(!kms_server_setup_finished) return true; - } - - config.main_config.use_new_ui = true; - config.main_config.installed_gsr_global_hotkeys_version = GSR_CURRENT_GLOBAL_HOTKEYS_CODE_VERSION; - save_configs(); bool service_install_successful = (system( "data_home=$(flatpak-spawn --host -- /bin/sh -c 'echo \"${XDG_DATA_HOME:-$HOME/.local/share}\"') && " @@ -4452,39 +4480,6 @@ static void activate(GtkApplication *app, gpointer) { } } -static bool kms_server_proxy_setup_gsr_ui(const char *msg) { - GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "%s", msg); - const gint response = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - - switch(response) { - case GTK_RESPONSE_YES: - break; - case GTK_RESPONSE_NO: - default: { - config.main_config.use_new_ui = false; - save_config(config); - return false; - } - } - - const int exit_code = system("flatpak-spawn --host -- /var/lib/flatpak/app/com.dec05eba.gpu_screen_recorder/current/active/files/bin/kms-server-proxy setup-gsr-ui"); - if(exit_code != 0) { - GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Failed to setup the new UI. You either cancelled the installation or you don't have pkexec installed and a polkit agent running."); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); - - config.main_config.use_new_ui = false; - save_configs(); - return false; - } - - config.main_config.use_new_ui = true; - config.main_config.installed_gsr_global_hotkeys_version = GSR_CURRENT_GLOBAL_HOTKEYS_CODE_VERSION; - save_config(config); - return true; -} - static bool is_gsr_global_hotkeys_installed() { const char *user_homepath = getenv("HOME"); if(!user_homepath) @@ -4534,7 +4529,7 @@ static void startup_new_ui(bool launched_by_daemon) { gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); }); - + config.main_config.use_new_ui = false; save_config(config); return; @@ -4558,6 +4553,7 @@ static void startup_new_ui(bool launched_by_daemon) { start_gtk_run_handler([&finished]() { finished = kms_server_proxy_setup_gsr_ui( "An update is available. The new GPU Screen Recorder UI needs root privileges to finish update to make global hotkeys and recording work on any system.\n" + "You will need to restart the application to apply the update.\n" "\n" "Are you sure you want to continue?"); }); |