diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gsr-config-page.c | 12 | ||||
| -rw-r--r-- | src/gsr-record-page.c | 6 | ||||
| -rw-r--r-- | src/gsr-replay-page.c | 6 | ||||
| -rw-r--r-- | src/gsr-shortcut-accel-dialog.c | 11 | ||||
| -rw-r--r-- | src/gsr-window.c | 33 | ||||
| -rw-r--r-- | src/main.c | 6 |
6 files changed, 29 insertions, 45 deletions
diff --git a/src/gsr-config-page.c b/src/gsr-config-page.c index 7736bdb..cd17219 100644 --- a/src/gsr-config-page.c +++ b/src/gsr-config-page.c @@ -156,11 +156,10 @@ on_window_picked(const GsrX11WindowPickResult *result, void *userdata) self->selected_window_name = g_strdup(result->name); /* Update the row subtitle */ - char *subtitle = g_strdup_printf("%s (0x%lx)", + g_autofree char *subtitle = g_strdup_printf("%s (0x%lx)", result->name ? result->name : "(no name)", (unsigned long)result->window); adw_action_row_set_subtitle(self->select_window_row, subtitle); - g_free(subtitle); } static void @@ -218,14 +217,13 @@ build_capture_group(GsrConfigPage *self) int first_monitor_idx = self->n_record_area_ids; for (int i = 0; i < info->supported_capture_options.n_monitors; i++) { const GsrMonitor *m = &info->supported_capture_options.monitors[i]; - char *label; + g_autofree char *label = NULL; if (m->width > 0 && m->height > 0) label = g_strdup_printf("Monitor %s (%dx%d)", m->name, m->width, m->height); else label = g_strdup_printf("Monitor %s", m->name); gtk_string_list_append(self->record_area_model, label); ids_array_append(&self->record_area_ids, &self->n_record_area_ids, &cap, m->name); - g_free(label); } /* Desktop portal — only on Wayland with portal support */ @@ -901,10 +899,14 @@ gsr_config_page_apply_config(GsrConfigPage *self, const GsrConfig *config) /* Populate from config audio_input array */ for (int i = 0; i < m->n_audio_input; i++) { + /* borrowed pointer into config-owned memory; nothing to free */ + /* gobject-linter-ignore-next-line: use_auto_cleanup */ const char *input = m->audio_input[i]; if (!input) continue; if (g_str_has_prefix(input, "app:")) { + /* borrowed pointer into config-owned memory; nothing to free */ + /* gobject-linter-ignore-next-line: use_auto_cleanup */ const char *app_name = input + 4; if (!self->info->system_info.supports_app_audio) continue; @@ -934,6 +936,8 @@ gsr_config_page_apply_config(GsrConfigPage *self, const GsrConfig *config) } else { /* "device:xxx" or bare legacy name */ + /* borrowed pointer into config-owned memory; nothing to free */ + /* gobject-linter-ignore-next-line: use_auto_cleanup */ const char *desc = input; if (g_str_has_prefix(input, "device:")) desc = input + 7; diff --git a/src/gsr-record-page.c b/src/gsr-record-page.c index 24247da..745bdcf 100644 --- a/src/gsr-record-page.c +++ b/src/gsr-record-page.c @@ -130,19 +130,17 @@ on_save_dir_activated(AdwActionRow *row G_GNUC_UNUSED, gpointer user_data) { GsrRecordPage *self = GSR_RECORD_PAGE(user_data); - GtkFileDialog *dialog = gtk_file_dialog_new(); + g_autoptr(GtkFileDialog) dialog = gtk_file_dialog_new(); gtk_file_dialog_set_title(dialog, "Select save directory"); if (self->save_directory) { - GFile *initial = g_file_new_for_path(self->save_directory); + g_autoptr(GFile) initial = g_file_new_for_path(self->save_directory); gtk_file_dialog_set_initial_folder(dialog, initial); - g_object_unref(initial); } GtkWindow *win = GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(self))); gtk_file_dialog_select_folder(dialog, win, NULL, on_folder_dialog_finish, self); - g_object_unref(dialog); } /* ── Callbacks ───────────────────────────────────────────────────── */ diff --git a/src/gsr-replay-page.c b/src/gsr-replay-page.c index 3c516a8..ea11ba2 100644 --- a/src/gsr-replay-page.c +++ b/src/gsr-replay-page.c @@ -124,19 +124,17 @@ on_save_dir_activated(AdwActionRow *row G_GNUC_UNUSED, gpointer user_data) { GsrReplayPage *self = GSR_REPLAY_PAGE(user_data); - GtkFileDialog *dialog = gtk_file_dialog_new(); + g_autoptr(GtkFileDialog) dialog = gtk_file_dialog_new(); gtk_file_dialog_set_title(dialog, "Select save directory"); if (self->save_directory) { - GFile *initial = g_file_new_for_path(self->save_directory); + g_autoptr(GFile) initial = g_file_new_for_path(self->save_directory); gtk_file_dialog_set_initial_folder(dialog, initial); - g_object_unref(initial); } GtkWindow *win = GTK_WINDOW(gtk_widget_get_root(GTK_WIDGET(self))); gtk_file_dialog_select_folder(dialog, win, NULL, on_folder_dialog_finish, self); - g_object_unref(dialog); } /* ── Callbacks ───────────────────────────────────────────────────── */ diff --git a/src/gsr-shortcut-accel-dialog.c b/src/gsr-shortcut-accel-dialog.c index 83db23e..038c141 100644 --- a/src/gsr-shortcut-accel-dialog.c +++ b/src/gsr-shortcut-accel-dialog.c @@ -279,16 +279,14 @@ build_dialog_ui(GsrShortcutAccelDialog *self) gtk_widget_add_css_class(GTK_WIDGET(keyboard_icon), "dim-label"); gtk_box_append(capture_box, GTK_WIDGET(keyboard_icon)); - char *escaped_title = g_markup_escape_text( + g_autofree char *escaped_title = g_markup_escape_text( self->shortcut_title ? self->shortcut_title : "Shortcut", -1); - char *label_text = g_strdup_printf( + g_autofree char *label_text = g_strdup_printf( "Enter new shortcut for\n<b>%s</b>", escaped_title); - g_free(escaped_title); self->capture_label = GTK_LABEL(gtk_label_new(NULL)); gtk_label_set_markup(self->capture_label, label_text); gtk_label_set_justify(self->capture_label, GTK_JUSTIFY_CENTER); gtk_label_set_wrap(self->capture_label, TRUE); - g_free(label_text); gtk_box_append(capture_box, GTK_WIDGET(self->capture_label)); self->capture_hint = GTK_LABEL(gtk_label_new( @@ -310,11 +308,10 @@ build_dialog_ui(GsrShortcutAccelDialog *self) gtk_widget_set_margin_bottom(GTK_WIDGET(display_box), 24); GtkLabel *display_title = GTK_LABEL(gtk_label_new(NULL)); - char *escaped_display_title = g_markup_escape_text( + g_autofree char *escaped_display_title = g_markup_escape_text( self->shortcut_title ? self->shortcut_title : "Shortcut", -1); - char *display_text = g_strdup_printf( + g_autofree char *display_text = g_strdup_printf( "Shortcut for <b>%s</b>", escaped_display_title); - g_free(escaped_display_title); gtk_label_set_markup(display_title, display_text); gtk_label_set_justify(display_title, GTK_JUSTIFY_CENTER); gtk_label_set_wrap(display_title, TRUE); diff --git a/src/gsr-window.c b/src/gsr-window.c index 6620b59..76a8a76 100644 --- a/src/gsr-window.c +++ b/src/gsr-window.c @@ -143,7 +143,7 @@ send_notification_full(GsrWindow *self, const char *title, return; /* ── Desktop notification ── */ - GNotification *notif = g_notification_new(title); + g_autoptr(GNotification) notif = g_notification_new(title); g_notification_set_body(notif, body); /* KDE workaround: force urgent while capturing */ @@ -167,7 +167,6 @@ send_notification_full(GsrWindow *self, const char *title, g_application_send_notification(G_APPLICATION(app), "gpu-screen-recorder", notif); self->showing_notification = TRUE; - g_object_unref(notif); /* Auto-withdraw after timeout */ g_clear_handle_id(&self->notification_timeout_id, g_source_remove); @@ -570,22 +569,20 @@ handle_child_death(GsrWindow *self, int exit_status) /* Success */ if (mode == GSR_ACTIVE_MODE_RECORD && self->record_filename) { if (gsr_config_page_get_notify_saved(self->config_page)) { - char *msg = g_strdup_printf("Recording saved to %s", + g_autofree char *msg = g_strdup_printf("Recording saved to %s", self->record_filename); send_notification_full(self, "GPU Screen Recorder", msg, G_NOTIFICATION_PRIORITY_NORMAL, self->record_filename); - g_free(msg); } } else if (gsr_config_page_get_notify_stopped(self->config_page)) { const char *mode_str = active_mode_to_string(mode); - char *msg = g_strdup_printf("Stopped %s", mode_str); + g_autofree char *msg = g_strdup_printf("Stopped %s", mode_str); send_notification(self, "GPU Screen Recorder", msg, G_NOTIFICATION_PRIORITY_NORMAL); - g_free(msg); } } else { /* Error — always notify regardless of user prefs */ - char *msg = NULL; + g_autofree char *msg = NULL; if (exit_status == 10) msg = g_strdup_printf("You need to have pkexec installed and have " "a polkit agent running to record your monitor"); @@ -601,7 +598,6 @@ handle_child_death(GsrWindow *self, int exit_status) "Start GPU Screen Recorder from the terminal for more info"); send_notification(self, "GPU Screen Recorder", msg, G_NOTIFICATION_PRIORITY_URGENT); - g_free(msg); } } @@ -696,29 +692,26 @@ create_primary_menu(GsrWindow *self) /* View mode section (with "View" header label) — kept separate for dynamic insertion/removal based on the active tab. */ self->view_section = g_menu_new(); - GMenuItem *simple_item = g_menu_item_new("Simple", NULL); + g_autoptr(GMenuItem) simple_item = g_menu_item_new("Simple", NULL); g_menu_item_set_action_and_target_value(simple_item, "win.view-mode", g_variant_new_string("simple")); g_menu_append_item(self->view_section, simple_item); - g_object_unref(simple_item); - GMenuItem *advanced_item = g_menu_item_new("Advanced", NULL); + g_autoptr(GMenuItem) advanced_item = g_menu_item_new("Advanced", NULL); g_menu_item_set_action_and_target_value(advanced_item, "win.view-mode", g_variant_new_string("advanced")); g_menu_append_item(self->view_section, advanced_item); - g_object_unref(advanced_item); /* Start with the View section hidden; it will be shown when the Config tab becomes visible. */ self->view_section_visible = FALSE; /* About section (always present) */ - GMenu *about_section = g_menu_new(); + g_autoptr(GMenu) about_section = g_menu_new(); g_menu_append(about_section, "Keyboard Shortcuts", "app.shortcuts"); g_menu_append(about_section, "About", "app.about"); g_menu_append_section(self->primary_menu, NULL, G_MENU_MODEL(about_section)); - g_object_unref(about_section); } /* ── Hotkey: page changed → regrab + register Wayland shortcuts ─── */ @@ -1082,10 +1075,9 @@ gsr_window_start_process(GsrWindow *self, GsrActiveMode mode) if (!ok) { const char *mode_str = active_mode_to_string(mode); - char *msg = g_strdup_printf("Failed to start %s (failed to fork)", mode_str); + g_autofree char *msg = g_strdup_printf("Failed to start %s (failed to fork)", mode_str); send_notification(self, "GPU Screen Recorder", msg, G_NOTIFICATION_PRIORITY_URGENT); - g_free(msg); return FALSE; } @@ -1098,10 +1090,9 @@ gsr_window_start_process(GsrWindow *self, GsrActiveMode mode) /* Show "started" notification */ if (gsr_config_page_get_notify_started(self->config_page)) { const char *mode_str = active_mode_to_string(mode); - char *msg = g_strdup_printf("Started %s", mode_str); + g_autofree char *msg = g_strdup_printf("Started %s", mode_str); send_notification(self, "GPU Screen Recorder", msg, G_NOTIFICATION_PRIORITY_NORMAL); - g_free(msg); } return TRUE; @@ -1131,18 +1122,16 @@ gsr_window_stop_process(GsrWindow *self, gboolean *already_dead) /* Show stop notification (respecting user prefs) */ if (success && mode == GSR_ACTIVE_MODE_RECORD && self->record_filename) { if (gsr_config_page_get_notify_saved(self->config_page)) { - char *msg = g_strdup_printf("Recording saved to %s", + g_autofree char *msg = g_strdup_printf("Recording saved to %s", self->record_filename); send_notification_full(self, "GPU Screen Recorder", msg, G_NOTIFICATION_PRIORITY_NORMAL, self->record_filename); - g_free(msg); } } else if (gsr_config_page_get_notify_stopped(self->config_page)) { const char *mode_str = active_mode_to_string(mode); - char *msg = g_strdup_printf("Stopped %s", mode_str); + g_autofree char *msg = g_strdup_printf("Stopped %s", mode_str); send_notification(self, "GPU Screen Recorder", msg, G_NOTIFICATION_PRIORITY_NORMAL); - g_free(msg); } return success; @@ -121,7 +121,7 @@ on_open_folder_action(GSimpleAction *action, static void load_custom_css(void) { - GtkCssProvider *provider = gtk_css_provider_new(); + g_autoptr(GtkCssProvider) provider = gtk_css_provider_new(); gtk_css_provider_load_from_string(provider, ".recording-active { color: @error_color; }\n" ".recording-paused { color: @warning_color; }\n"); @@ -129,7 +129,6 @@ load_custom_css(void) gdk_display_get_default(), GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - g_object_unref(provider); } static void @@ -155,7 +154,7 @@ on_activate(GtkApplication *app, gpointer user_data) int main(int argc, char *argv[]) { - AdwApplication *app = adw_application_new( + g_autoptr(AdwApplication) app = adw_application_new( "com.dec05eba.gpu_screen_recorder", G_APPLICATION_DEFAULT_FLAGS); @@ -175,6 +174,5 @@ main(int argc, char *argv[]) g_signal_connect(app, "activate", G_CALLBACK(on_activate), NULL); int status = g_application_run(G_APPLICATION(app), argc, argv); - g_object_unref(app); return status; } |
