aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-11-29 21:54:38 +0100
committerdec05eba <dec05eba@protonmail.com>2023-11-29 21:54:38 +0100
commit84bc482c28a9198edc8a1377742b13be3a56c058 (patch)
treea84d7e9f1d8defbcf776d4e9b47fc48c5473e127
parente8df27fe6dc76335e4a12a713b23c9bc59d6bccb (diff)
Check if flatpak gsr kms server has cap instead of config option
-rw-r--r--README.md2
-rwxr-xr-xbuild.sh2
-rw-r--r--project.conf3
-rw-r--r--src/config.hpp7
-rw-r--r--src/main.cpp27
5 files changed, 20 insertions, 21 deletions
diff --git a/README.md b/README.md
index d574710..41c73e4 100644
--- a/README.md
+++ b/README.md
@@ -31,7 +31,7 @@ Performance is the same when recording a single window or the monitor, however i
## Installation
This program depends on [gpu-screen-recorder](https://git.dec05eba.com/gpu-screen-recorder/) which needs to be installed first.\
Run `sudo ./install.sh` or if you are running Arch Linux, then you can find gpu screen recorder gtk on aur under the name gpu-screen-recorder-gtk-git (`yay -S gpu-screen-recorder-gtk-git`).\
-Dependencies needed when building using `build.sh` or `install.sh`: `gtk3 libx11 libxrandr libpulse libdrm wayland-client`.\
+Dependencies needed when building using `build.sh` or `install.sh`: `gtk3 libx11 libxrandr libpulse libcap libdrm wayland-client`.\
You can also install gpu screen recorder (the gtk gui version) from [flathub](https://flathub.org/apps/details/com.dec05eba.gpu_screen_recorder). This flatpak includes gpu-screen-recorder so no need to install that first.\
Note that if you use the flatpak version then you wont be able to use overclocking unless you set "Coolbits" NVIDIA X setting. See https://git.dec05eba.com/gpu-screen-recorder/about/ for more information and how to overcome this.
diff --git a/build.sh b/build.sh
index c0c14ad..9327b62 100755
--- a/build.sh
+++ b/build.sh
@@ -15,7 +15,7 @@ build_wayland_protocol() {
}
build_gsr_gtk() {
- dependencies="gtk+-3.0 x11 xrandr libpulse libdrm wayland-egl wayland-client"
+ dependencies="gtk+-3.0 x11 xrandr libpulse libcap libdrm wayland-egl wayland-client"
includes="$(pkg-config --cflags $dependencies)"
libs="$(pkg-config --libs $dependencies) -ldl"
$CC -c src/egl.c $opts $includes
diff --git a/project.conf b/project.conf
index 9c58c71..07a23dc 100644
--- a/project.conf
+++ b/project.conf
@@ -14,4 +14,5 @@ xrandr = "1"
libpulse = ">=13"
libdrm = ">=2"
wayland-egl = ">=15"
-wayland-client = ">=1" \ No newline at end of file
+wayland-client = ">=1"
+libcap = ">=2" \ No newline at end of file
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);