diff options
author | dec05eba <dec05eba@protonmail.com> | 2023-11-29 21:54:38 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2023-11-29 21:54:38 +0100 |
commit | 84bc482c28a9198edc8a1377742b13be3a56c058 (patch) | |
tree | a84d7e9f1d8defbcf776d4e9b47fc48c5473e127 /src | |
parent | e8df27fe6dc76335e4a12a713b23c9bc59d6bccb (diff) |
Check if flatpak gsr kms server has cap instead of config option
Diffstat (limited to 'src')
-rw-r--r-- | src/config.hpp | 7 | ||||
-rw-r--r-- | src/main.cpp | 27 |
2 files changed, 16 insertions, 18 deletions
diff --git a/src/config.hpp b/src/config.hpp index e0df909..20614aa 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -31,7 +31,6 @@ struct MainConfig { std::string framerate_mode; bool advanced_view = false; bool overclock = false; - bool password_prompt_removed = false; }; struct StreamingConfig { @@ -278,11 +277,6 @@ static Config read_config(bool &config_empty) { config.main_config.overclock = true; else if(value == "false") config.main_config.overclock = false; - } else if(key == "main.password_prompt_removed") { - if(value == "true") - config.main_config.password_prompt_removed = true; - else if(value == "false") - config.main_config.password_prompt_removed = false; } else if(key == "streaming.service") { config.streaming_config.streaming_service.assign(value.str, value.size); } else if(key == "streaming.key") { @@ -370,7 +364,6 @@ static void save_config(const Config &config) { fprintf(file, "main.framerate_mode %s\n", config.main_config.framerate_mode.c_str()); fprintf(file, "main.advanced_view %s\n", config.main_config.advanced_view ? "true" : "false"); fprintf(file, "main.overclock %s\n", config.main_config.overclock ? "true" : "false"); - fprintf(file, "main.password_prompt_removed %s\n", config.main_config.password_prompt_removed ? "true" : "false"); fprintf(file, "streaming.service %s\n", config.streaming_config.streaming_service.c_str()); fprintf(file, "streaming.key %s\n", config.streaming_config.stream_key.c_str()); diff --git a/src/main.cpp b/src/main.cpp index b0fd055..3629fd0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,7 @@ extern "C" { } #include <xf86drmMode.h> #include <xf86drm.h> +#include <sys/capability.h> typedef struct { Display *display; @@ -417,8 +418,6 @@ static void save_configs() { config.main_config.framerate_mode = gtk_combo_box_get_active_id(GTK_COMBO_BOX(framerate_mode_input_menu)); config.main_config.advanced_view = strcmp(gtk_combo_box_get_active_id(GTK_COMBO_BOX(view_combo_box)), "advanced") == 0; config.main_config.overclock = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(overclock_button)); - if(restore_password_prompts_button) - config.main_config.password_prompt_removed = gtk_widget_is_sensitive(GTK_WIDGET(restore_password_prompts_button)); config.streaming_config.streaming_service = gtk_combo_box_get_active_id(GTK_COMBO_BOX(stream_service_input_menu)); config.streaming_config.stream_key = gtk_entry_get_text(stream_id_entry); @@ -2058,7 +2057,6 @@ static gboolean on_remove_password_prompts_button_click(GtkButton*, gpointer) { int result = system("flatpak-spawn --host pkexec setcap cap_sys_admin+ep /var/lib/flatpak/app/com.dec05eba.gpu_screen_recorder/current/active/files/bin/gsr-kms-server"); switch(result) { case 0: { - config.main_config.password_prompt_removed = true; gtk_widget_set_sensitive(GTK_WIDGET(remove_password_prompts_button), false); gtk_widget_set_sensitive(GTK_WIDGET(restore_password_prompts_button), true); save_configs(); @@ -2086,7 +2084,6 @@ static gboolean on_restore_password_prompts_button_click(GtkButton*, gpointer) { int result = system("flatpak-spawn --host pkexec setcap -r /var/lib/flatpak/app/com.dec05eba.gpu_screen_recorder/current/active/files/bin/gsr-kms-server"); switch(result) { case 0: { - config.main_config.password_prompt_removed = false; gtk_widget_set_sensitive(GTK_WIDGET(remove_password_prompts_button), true); gtk_widget_set_sensitive(GTK_WIDGET(restore_password_prompts_button), false); save_configs(); @@ -2137,11 +2134,6 @@ static GtkWidget* create_common_settings_page(GtkStack *stack, GtkApplication *a gtk_widget_set_sensitive(GTK_WIDGET(remove_password_prompts_button), false); gtk_widget_set_sensitive(GTK_WIDGET(restore_password_prompts_button), false); - - if(config.main_config.password_prompt_removed) - gtk_widget_set_sensitive(GTK_WIDGET(restore_password_prompts_button), true); - else - gtk_widget_set_sensitive(GTK_WIDGET(remove_password_prompts_button), true); } GtkFrame *record_area_frame = GTK_FRAME(gtk_frame_new("Record area")); @@ -2719,6 +2711,18 @@ static void add_audio_input_track(const char *name) { gtk_list_box_insert (GTK_LIST_BOX(audio_input_used_list), row, -1); } +// Checks for flatpak gsr kms server specifically +static bool kms_server_has_admin_privileges(void) { + cap_t kms_server_cap = cap_get_file("/app/bin/gsr-kms-server"); + if(kms_server_cap) { + cap_flag_value_t res = CAP_CLEAR; + cap_get_flag(kms_server_cap, CAP_SYS_ADMIN, CAP_PERMITTED, &res); + cap_free(kms_server_cap); + return res == CAP_SET; + } + return false; +} + static void load_config(const gpu_info &gpu_inf) { bool config_empty = false; config = read_config(config_empty); @@ -2853,8 +2857,9 @@ static void load_config(const gpu_info &gpu_inf) { gtk_combo_box_set_active_id(GTK_COMBO_BOX(view_combo_box), config.main_config.advanced_view ? "advanced" : "simple"); if(remove_password_prompts_button) { - gtk_widget_set_sensitive(GTK_WIDGET(remove_password_prompts_button), !config.main_config.password_prompt_removed); - gtk_widget_set_sensitive(GTK_WIDGET(restore_password_prompts_button), config.main_config.password_prompt_removed); + bool password_prompts_removed = kms_server_has_admin_privileges(); + gtk_widget_set_sensitive(GTK_WIDGET(remove_password_prompts_button), !password_prompts_removed); + gtk_widget_set_sensitive(GTK_WIDGET(restore_password_prompts_button), password_prompts_removed); } view_combo_box_change_callback(GTK_COMBO_BOX(view_combo_box), view_combo_box); |