aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp80
1 files changed, 60 insertions, 20 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 22ad190..0a171dd 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;
@@ -188,7 +185,7 @@ struct SupportedVideoCodecs {
};
static SupportedVideoCodecs supported_video_codecs;
-static bool got_supported_video_codecs = false;
+static int supported_video_codecs_exit_status = 0;
struct Container {
const char *container_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",
@@ -2068,12 +2087,18 @@ static gboolean on_start_streaming_button_click(GtkButton *button, gpointer user
{}
else if(stream_url.size() >= 8 && strncmp(stream_url.c_str(), "rtmps://", 8) == 0)
{}
+ else if(stream_url.size() >= 7 && strncmp(stream_url.c_str(), "rtsp://", 7) == 0)
+ {}
else if(stream_url.size() >= 6 && strncmp(stream_url.c_str(), "srt://", 6) == 0)
{}
else if(stream_url.size() >= 7 && strncmp(stream_url.c_str(), "http://", 7) == 0)
{}
else if(stream_url.size() >= 8 && strncmp(stream_url.c_str(), "https://", 8) == 0)
{}
+ else if(stream_url.size() >= 6 && strncmp(stream_url.c_str(), "tcp://", 6) == 0)
+ {}
+ else if(stream_url.size() >= 6 && strncmp(stream_url.c_str(), "udp://", 6) == 0)
+ {}
else
stream_url = "rtmp://" + stream_url;
}
@@ -2140,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;
@@ -2460,7 +2485,8 @@ static gsr_connection_type get_connection_type() {
}
}
-static bool get_supported_video_codecs(SupportedVideoCodecs *supported_video_codecs) {
+// Returns the exit status
+static int get_supported_video_codecs(SupportedVideoCodecs *supported_video_codecs) {
supported_video_codecs->h264 = false;
supported_video_codecs->hevc = false;
supported_video_codecs->av1 = false;
@@ -2468,7 +2494,7 @@ static bool get_supported_video_codecs(SupportedVideoCodecs *supported_video_cod
FILE *f = popen("gpu-screen-recorder --list-supported-video-codecs", "r");
if(!f) {
fprintf(stderr, "error: 'gpu-screen-recorder --list-supported-video-codecs' failed\n");
- return false;
+ return -1;
}
char output[1024];
@@ -2476,7 +2502,7 @@ static bool get_supported_video_codecs(SupportedVideoCodecs *supported_video_cod
if(bytes_read < 0 || ferror(f)) {
fprintf(stderr, "error: failed to read 'gpu-screen-recorder --list-supported-video-codecs' output\n");
pclose(f);
- return false;
+ return -1;
}
output[bytes_read] = '\0';
@@ -2487,8 +2513,10 @@ static bool get_supported_video_codecs(SupportedVideoCodecs *supported_video_cod
if(strstr(output, "av1"))
supported_video_codecs->av1 = true;
- pclose(f);
- return true;
+ int status = pclose(f);
+ if(WIFEXITED(status))
+ return WEXITSTATUS(status);
+ return 0;
}
static void record_area_set_sensitive(GtkCellLayout *cell_layout, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) {
@@ -2735,7 +2763,7 @@ static GtkWidget* create_common_settings_page(GtkStack *stack, GtkApplication *a
gtk_grid_attach(video_codec_grid, gtk_label_new("Video codec: "), 0, 0, 1, 1);
video_codec_input_menu = GTK_COMBO_BOX_TEXT(gtk_combo_box_text_new());
gtk_combo_box_text_append(video_codec_input_menu, "auto", "Auto (Recommended)");
- if(got_supported_video_codecs) {
+ if(supported_video_codecs_exit_status == 0) {
if(supported_video_codecs.h264)
gtk_combo_box_text_append(video_codec_input_menu, "h264", "H264");
if(supported_video_codecs.hevc)
@@ -3520,6 +3548,18 @@ static void load_config(const gpu_info &gpu_inf) {
enable_stream_record_button_if_info_filled();
stream_service_item_change_callback(GTK_COMBO_BOX(stream_service_input_menu), nullptr);
+ if(supported_video_codecs_exit_status != 0) {
+ 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(GTK_WINDOW(window), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
+ "Failed to run 'gpu-screen-recorder' command. If you are using gpu-screen-recorder flatpak then this is a bug. Otherwise you need to make sure gpu-screen-recorder is installed on your system and working properly (install necessary depedencies depending on your GPU, such as libva-mesa-driver, libva-intel-driver, intel-media-driver and linux-firmware). Run:\n"
+ "%s\n"
+ "in a terminal to see more information about the issue.", cmd);
+ gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+ g_application_quit(G_APPLICATION(select_window_userdata.app));
+ return;
+ }
+
if(!supported_video_codecs.h264 && !supported_video_codecs.hevc && gpu_inf.vendor != GPU_VENDOR_NVIDIA && config.main_config.codec != "av1") {
if(supported_video_codecs.av1) {
GtkWidget *dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(window), GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK,
@@ -3691,7 +3731,7 @@ static void activate(GtkApplication *app, gpointer) {
}
}
- got_supported_video_codecs = get_supported_video_codecs(&supported_video_codecs);
+ supported_video_codecs_exit_status = get_supported_video_codecs(&supported_video_codecs);
std::string window_title = "GPU Screen Recorder | Running on ";
window_title += gpu_vendor_to_name(gpu_inf.vendor);