Skip to content

Commit 1ba86fd

Browse files
committed
add module functions
1 parent 1df3996 commit 1ba86fd

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

include/module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ void module_on_output_change(struct GtkLock *gtklock);
1515
void module_on_focus_change(struct GtkLock *gtklock, struct Window *win, struct Window *old);
1616
void module_on_idle_hide(struct GtkLock *gtklock);
1717
void module_on_idle_show(struct GtkLock *gtklock);
18+
void module_on_window_create(struct GtkLock *gtklock, struct Window *win);
19+
void module_on_window_destroy(struct GtkLock *gtklock, struct Window *win);
1820

src/module.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,19 @@ void module_on_idle_show(struct GtkLock *gtklock) {
109109
}
110110
}
111111

112+
void module_on_window_create(struct GtkLock *gtklock, struct Window *win) {
113+
for(guint idx = 0; idx < gtklock->modules->len; idx++) {
114+
void (*fn)(struct GtkLock *, struct Window *) = NULL;
115+
GModule *module = g_array_index(gtklock->modules, GModule *, idx);
116+
if(g_module_symbol(module, "on_window_create", (gpointer *)&fn)) fn(gtklock, win);
117+
}
118+
}
119+
120+
void module_on_window_destroy(struct GtkLock *gtklock, struct Window *win) {
121+
for(guint idx = 0; idx < gtklock->modules->len; idx++) {
122+
void (*fn)(struct GtkLock *, struct Window *) = NULL;
123+
GModule *module = g_array_index(gtklock->modules, GModule *, idx);
124+
if(g_module_symbol(module, "on_window_destroy", (gpointer *)&fn)) fn(gtklock, win);
125+
}
126+
}
127+

src/window.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ void window_pw_toggle_vis(GtkEntry* entry, GtkEntryIconPosition icon_pos) {
205205

206206
static void window_destroy_notify(GtkWidget *widget, gpointer data) {
207207
struct Window *win = window_by_widget(widget);
208+
module_on_window_destroy(gtklock, win);
208209
gtk_widget_destroy(widget);
209210
gtklock_remove_window(gtklock, win);
210211
}
@@ -341,11 +342,11 @@ struct Window *create_window(GdkMonitor *monitor) {
341342
w->clock_label = GTK_WIDGET(gtk_builder_get_object(builder, "clock-label"));
342343
window_update_clock(w);
343344

344-
g_object_unref(builder);
345-
346345
if(gtklock->hidden) window_idle_hide(w);
346+
module_on_window_create(gtklock, w);
347347
gtk_widget_show_all(w->window);
348348

349+
g_object_unref(builder);
349350
return w;
350351
}
351352

0 commit comments

Comments
 (0)