aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/narrative_window.c4
-rw-r--r--src/pr_clock.c26
-rw-r--r--src/pr_clock.h6
3 files changed, 21 insertions, 15 deletions
diff --git a/src/narrative_window.c b/src/narrative_window.c
index 70838c7..9727e3c 100644
--- a/src/narrative_window.c
+++ b/src/narrative_window.c
@@ -430,7 +430,8 @@ static void last_para_sig(GSimpleAction *action, GVariant *parameter,
static void open_clock_sig(GSimpleAction *action, GVariant *parameter, gpointer vp)
{
NarrativeWindow *nw = vp;
- nw->pr_clock = pr_clock_new();
+ if ( nw->pr_clock != NULL ) return;
+ nw->pr_clock = pr_clock_new(&nw->pr_clock);
}
@@ -516,6 +517,7 @@ static void scroll_down(NarrativeWindow *nw)
static gboolean nw_destroy_sig(GtkWidget *da, NarrativeWindow *nw)
{
+ if ( nw->pr_clock != NULL ) pr_clock_destroy(nw->pr_clock);
g_application_release(nw->app);
return FALSE;
}
diff --git a/src/pr_clock.c b/src/pr_clock.c
index ce20153..3b134f4 100644
--- a/src/pr_clock.c
+++ b/src/pr_clock.c
@@ -37,8 +37,6 @@
struct pr_clock
{
- int open;
-
GtkWidget *window;
GtkWidget *entry;
GtkWidget *startbutton;
@@ -62,6 +60,8 @@ struct pr_clock
double t;
double tf;
+
+ PRClock **delete_ptr;
};
@@ -132,13 +132,6 @@ static gboolean update_clock(gpointer data)
gint w, h;
char *tmp;
- if ( !n->open ) {
- g_date_time_unref(n->start);
- g_time_zone_unref(n->tz);
- free(n);
- return FALSE;
- }
-
dt = g_date_time_new_now(n->tz);
if ( n->running ) {
@@ -218,6 +211,9 @@ void pr_clock_set_pos(PRClock *n, int pos, int end)
static gint close_clock_sig(GtkWidget *w, PRClock *n)
{
g_source_remove(n->timer_id);
+ *n->delete_ptr = NULL;
+ if ( n->start != NULL ) g_date_time_unref(n->start);
+ g_time_zone_unref(n->tz);
free(n);
return FALSE;
}
@@ -344,7 +340,7 @@ static gboolean start_sig(GtkWidget *w, gpointer data)
}
-PRClock *pr_clock_new()
+PRClock *pr_clock_new(PRClock **delete_ptr)
{
struct pr_clock *n;
GtkWidget *vbox;
@@ -356,8 +352,8 @@ PRClock *pr_clock_new()
n = malloc(sizeof(struct pr_clock));
if ( n == NULL ) return NULL;
- n->open = 1;
+ n->delete_ptr = delete_ptr;
n->tz = g_time_zone_new_local();
n->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
@@ -390,7 +386,7 @@ PRClock *pr_clock_new()
gtk_box_pack_start(GTK_BOX(vbox), n->da, TRUE, TRUE, 0);
g_signal_connect(G_OBJECT(n->da), "draw", G_CALLBACK(clock_draw_sig), n);
g_signal_connect(G_OBJECT(n->window), "destroy",
- G_CALLBACK(close_clock_sig), n); /* FIXME: Uniqueness */
+ G_CALLBACK(close_clock_sig), n);
grid = gtk_grid_new();
gtk_grid_set_row_spacing(GTK_GRID(grid), 10);
@@ -436,3 +432,9 @@ PRClock *pr_clock_new()
gtk_widget_show_all(n->window);
return n;
}
+
+
+void pr_clock_destroy(PRClock *n)
+{
+ gtk_widget_destroy(n->window);
+}
diff --git a/src/pr_clock.h b/src/pr_clock.h
index 97d2d0d..3b971a9 100644
--- a/src/pr_clock.h
+++ b/src/pr_clock.h
@@ -1,7 +1,7 @@
/*
* pr_clock.h
*
- * Copyright © 2013-2018 Thomas White <taw@bitwiz.org.uk>
+ * Copyright © 2013-2019 Thomas White <taw@bitwiz.org.uk>
*
* This file is part of Colloquium.
*
@@ -29,9 +29,11 @@
typedef struct pr_clock PRClock;
-extern PRClock *pr_clock_new(void);
+extern PRClock *pr_clock_new(PRClock **delete_ptr);
extern void pr_clock_set_pos(PRClock *n, int pos, int end);
+extern void pr_clock_destroy(PRClock *n);
+
#endif /* CLOCK_H */