Ensure dialog windows can only have one instance open (#356)

* Convert help dialog to singleton

* Convert settings dialog to singleton
This commit is contained in:
Jack Tench 2026-04-09 14:46:14 +01:00 committed by GitHub
parent 3a4f3e0563
commit 2c18bcbf5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View file

@ -3,15 +3,25 @@
#include <gtk/gtk.h>
#include <stdio.h>
static GtkWidget* help_window_singleton = NULL;
static gboolean on_help_window_delete(GtkWidget* widget, GdkEvent* event, gpointer user_data)
{
help_window_singleton = NULL;
gtk_widget_destroy(widget);
return TRUE;
}
static void build_help_dialog(GtkApplication* app, gpointer data)
{
// Show already open window if another one is called.
if (help_window_singleton) {
gtk_window_present(GTK_WINDOW(help_window_singleton));
return;
}
GtkWidget* window = gtk_application_window_new(app);
help_window_singleton = window;
gtk_window_set_title(GTK_WINDOW(window), "About LibreSplit");
gtk_window_set_default_size(GTK_WINDOW(window), 200, 320);
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);

View file

@ -11,6 +11,8 @@
static LSGuiSetting* gui_settings = NULL;
static GtkWidget* settings_window_singleton = NULL;
/**
* Takes the application config and counts how many settings are available.
*
@ -44,6 +46,7 @@ static size_t enumerate_settings(AppConfig cfg)
*/
static gboolean on_help_window_delete(GtkWidget* widget, GdkEvent* event, gpointer user_data)
{
settings_window_singleton = NULL;
gtk_widget_destroy(widget);
free(gui_settings);
gui_settings = NULL;
@ -162,6 +165,12 @@ static void set_widget_defaults(GtkWidget* obj)
static void build_settings_dialog(GtkApplication* app, gpointer data)
{
// Show already open window if another one is called.
if (settings_window_singleton) {
gtk_window_present(GTK_WINDOW(settings_window_singleton));
return;
}
int settings_number = enumerate_settings(cfg);
gui_settings = malloc(settings_number * sizeof(LSGuiSetting));
if (gui_settings == NULL) {
@ -170,6 +179,7 @@ static void build_settings_dialog(GtkApplication* app, gpointer data)
}
GtkWidget* window = gtk_application_window_new(app);
settings_window_singleton = window;
gtk_window_set_title(GTK_WINDOW(window), "LibreSplit Settings");
gtk_window_set_default_size(GTK_WINDOW(window), 500, 500);
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);