From 8b74b083e9b65237a61e95db22a9ccfd84cbd576 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 5 Jul 2024 02:55:29 +0200 Subject: Ugly hack to fix systray icon when not using flatpak --- README.md | 8 ++++---- meson.build | 1 + src/main.cpp | 43 +++++++++++++++++++++++++++++++------------ 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 82a89db..f1ad010 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![](https://dec05eba.com/images/gpu_screen_recorder_logo_small.png) -gtk frontend for [gpu-screen-recorder](https://git.dec05eba.com/gpu-screen-recorder/about/). +gtk frontend for [GPU Screen Recorder](https://git.dec05eba.com/gpu-screen-recorder/about/). This is a screen recorder that has minimal impact on system performance by recording your monitor using the GPU only, similar to shadowplay on windows. This is the fastest screen recording tool for Linux. @@ -8,7 +8,7 @@ similar to shadowplay on windows. This is the fastest screen recording tool for This screen recorder can be used for recording your desktop offline, for live streaming and for nvidia shadowplay-like instant replay, where only the last few minutes are saved. -More info at [gpu-screen-recorder](https://git.dec05eba.com/gpu-screen-recorder/about/). +More info at [GPU Screen Recorder](https://git.dec05eba.com/gpu-screen-recorder/about/). ## Note This software works with x11 and wayland, but when using wayland only monitors can be recorded. Hotkeys are also not supported on wayland (wayland doesn't really support this properly yet). Use X11 if you want a proper desktop experience in general. @@ -30,9 +30,9 @@ Hotkeys are currently only supported on X11. Most Wayland compositors are missin Bind a key to `killall -SIGINT gpu-screen-recorder` to stop recording (also saves the video when recording a regular video). Bind another key to `killall -SIGUSR1 gpu-screen-recorder` to save a replay and another key to `killall -SIGUSR2 gpu-screen-recorder` to pause/unpause the recording (when recording a regular video). ## Installation -This program depends on [gpu-screen-recorder](https://git.dec05eba.com/gpu-screen-recorder/) which needs to be installed first.\ +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 ayatana-appindicator3-0.1`.\ +Dependencies needed when building using `install.sh`: `meson gtk3 libx11 libxrandr libpulse libdrm wayland-client ayatana-appindicator3-0.1`.\ 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. ## Screenshots diff --git a/meson.build b/meson.build index cdfc095..d9eaa16 100644 --- a/meson.build +++ b/meson.build @@ -12,6 +12,7 @@ src = [ 'src/library_loader.c', 'src/main.cpp', ] + dep = [ dependency('gtk+-3.0'), dependency('x11'), diff --git a/src/main.cpp b/src/main.cpp index f5fbdbd..a18228c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -140,9 +140,6 @@ static double notification_timeout_seconds = 0.0; static double notification_start_seconds = 0.0; static AppIndicator *app_indicator; -static const char *tray_idle_icon_name = "com.dec05eba.gpu_screen_recorder.tray-idle"; -static const char *tray_recording_icon_name = "com.dec05eba.gpu_screen_recorder.tray-recording"; -static const char *tray_paused_icon_name = "com.dec05eba.gpu_screen_recorder.tray-paused"; struct AudioInput { std::string name; @@ -222,6 +219,28 @@ typedef struct { static gpu_info gpu_inf; +// Dumb hacks below!! why dont these fking paths work outside flatpak.. except in kde. TODO: fix this! +static const char* get_tray_idle_icon_name() { + if(flatpak) + return "com.dec05eba.gpu_screen_recorder.tray-idle"; + else + return "/usr/share/icons/hicolor/32x32/status/com.dec05eba.gpu_screen_recorder.tray-idle.png"; +} + +static const char* get_tray_recording_icon_name() { + if(flatpak) + return "com.dec05eba.gpu_screen_recorder.tray-recording"; + else + return "/usr/share/icons/hicolor/32x32/status/com.dec05eba.gpu_screen_recorder.tray-recording.png"; +} + +static const char* get_tray_paused_icon_name() { + if(flatpak) + return "com.dec05eba.gpu_screen_recorder.tray-paused"; + else + return "/usr/share/icons/hicolor/32x32/status/com.dec05eba.gpu_screen_recorder.tray-paused.png"; +} + static bool is_program_installed(const StringView program_name) { const char *path = getenv("PATH"); if(!path) @@ -391,7 +410,7 @@ static GtkMenuShell* create_systray_menu(GtkApplication *app, SystrayPage systra static void setup_systray(GtkApplication *app) { app_indicator = app_indicator_new("com.dec05eba.gpu_screen_recorder", "", APP_INDICATOR_CATEGORY_APPLICATION_STATUS); - app_indicator_set_icon_full(app_indicator, tray_idle_icon_name, "Idle"); + app_indicator_set_icon_full(app_indicator, get_tray_idle_icon_name(), "Idle"); // This triggers Gdk assert: gdk_window_thaw_toplevel_updates: assertion 'window->update_and_descendants_freeze_count > 0' failed, // dont know why but it works anyways app_indicator_set_title(app_indicator, "GPU Screen Recorder"); @@ -1716,7 +1735,7 @@ static gboolean on_start_replay_button_click(GtkButton *button, gpointer userdat gtk_menu_item_set_label(GTK_MENU_ITEM(start_stop_replay_menu_item), "Start replay"); gtk_widget_set_sensitive(save_replay_menu_item, false); - app_indicator_set_icon_full(app_indicator, tray_idle_icon_name, "Idle"); + app_indicator_set_icon_full(app_indicator, get_tray_idle_icon_name(), "Idle"); if(exit_status == 10) { show_notification(app, "GPU Screen Recorder", @@ -1823,7 +1842,7 @@ static gboolean on_start_replay_button_click(GtkButton *button, gpointer userdat gtk_menu_item_set_label(GTK_MENU_ITEM(start_stop_replay_menu_item), "Stop replay"); gtk_widget_set_sensitive(save_replay_menu_item, true); - app_indicator_set_icon_full(app_indicator, tray_recording_icon_name, "Recording"); + app_indicator_set_icon_full(app_indicator, get_tray_recording_icon_name(), "Recording"); record_start_time_sec = clock_get_monotonic_seconds(); return true; @@ -1850,13 +1869,13 @@ static gboolean on_pause_unpause_button_click(GtkButton*, gpointer) { gtk_button_set_label(pause_recording_button, "Unpause recording"); gtk_image_set_from_icon_name(GTK_IMAGE(recording_record_icon), "media-playback-pause", GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_menu_item_set_label(GTK_MENU_ITEM(pause_recording_menu_item), "Unpause recording"); - app_indicator_set_icon_full(app_indicator, tray_paused_icon_name, "Paused"); + app_indicator_set_icon_full(app_indicator, get_tray_paused_icon_name(), "Paused"); pause_start_sec = clock_get_monotonic_seconds(); } else { gtk_button_set_label(pause_recording_button, "Pause recording"); gtk_image_set_from_icon_name(GTK_IMAGE(recording_record_icon), "media-record", GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_menu_item_set_label(GTK_MENU_ITEM(pause_recording_menu_item), "Pause recording"); - app_indicator_set_icon_full(app_indicator, tray_recording_icon_name, "Recording"); + app_indicator_set_icon_full(app_indicator, get_tray_recording_icon_name(), "Recording"); paused_time_offset_sec += (clock_get_monotonic_seconds() - pause_start_sec); } return true; @@ -1886,7 +1905,7 @@ static gboolean on_start_recording_button_click(GtkButton *button, gpointer user gtk_menu_item_set_label(GTK_MENU_ITEM(start_stop_recording_menu_item), "Start recording"); gtk_menu_item_set_label(GTK_MENU_ITEM(pause_recording_menu_item), "Pause recording"); gtk_widget_set_sensitive(pause_recording_menu_item, false); - app_indicator_set_icon_full(app_indicator, tray_idle_icon_name, "Idle"); + app_indicator_set_icon_full(app_indicator, get_tray_idle_icon_name(), "Idle"); if(exit_status == 10) { show_notification(app, "GPU Screen Recorder", @@ -1996,7 +2015,7 @@ static gboolean on_start_recording_button_click(GtkButton *button, gpointer user gtk_menu_item_set_label(GTK_MENU_ITEM(start_stop_recording_menu_item), "Stop recording"); gtk_widget_set_sensitive(pause_recording_menu_item, true); - app_indicator_set_icon_full(app_indicator, tray_recording_icon_name, "recording"); + app_indicator_set_icon_full(app_indicator, get_tray_recording_icon_name(), "Recording"); record_start_time_sec = clock_get_monotonic_seconds(); paused_time_offset_sec = 0.0; @@ -2019,7 +2038,7 @@ static gboolean on_start_streaming_button_click(GtkButton *button, gpointer user gtk_label_set_text(GTK_LABEL(streaming_record_time_label), "00:00:00"); gtk_menu_item_set_label(GTK_MENU_ITEM(start_stop_streaming_menu_item), "Start streaming"); - app_indicator_set_icon_full(app_indicator, tray_idle_icon_name, "Idle"); + app_indicator_set_icon_full(app_indicator, get_tray_idle_icon_name(), "Idle"); if(exit_status == 10) { show_notification(app, "GPU Screen Recorder", @@ -2146,7 +2165,7 @@ static gboolean on_start_streaming_button_click(GtkButton *button, gpointer user gtk_widget_set_opacity(GTK_WIDGET(streaming_bottom_panel_grid), 1.0); gtk_menu_item_set_label(GTK_MENU_ITEM(start_stop_streaming_menu_item), "Stop streaming"); - app_indicator_set_icon_full(app_indicator, tray_recording_icon_name, "Recording"); + app_indicator_set_icon_full(app_indicator, get_tray_recording_icon_name(), "Recording"); record_start_time_sec = clock_get_monotonic_seconds(); return true; -- cgit v1.2.3