Skip to content

Commit

Permalink
add module functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jovanlanik committed Oct 11, 2022
1 parent 1df3996 commit 1ba86fd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ void module_on_output_change(struct GtkLock *gtklock);
void module_on_focus_change(struct GtkLock *gtklock, struct Window *win, struct Window *old);
void module_on_idle_hide(struct GtkLock *gtklock);
void module_on_idle_show(struct GtkLock *gtklock);
void module_on_window_create(struct GtkLock *gtklock, struct Window *win);
void module_on_window_destroy(struct GtkLock *gtklock, struct Window *win);

16 changes: 16 additions & 0 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,19 @@ void module_on_idle_show(struct GtkLock *gtklock) {
}
}

void module_on_window_create(struct GtkLock *gtklock, struct Window *win) {
for(guint idx = 0; idx < gtklock->modules->len; idx++) {
void (*fn)(struct GtkLock *, struct Window *) = NULL;
GModule *module = g_array_index(gtklock->modules, GModule *, idx);
if(g_module_symbol(module, "on_window_create", (gpointer *)&fn)) fn(gtklock, win);
}
}

void module_on_window_destroy(struct GtkLock *gtklock, struct Window *win) {
for(guint idx = 0; idx < gtklock->modules->len; idx++) {
void (*fn)(struct GtkLock *, struct Window *) = NULL;
GModule *module = g_array_index(gtklock->modules, GModule *, idx);
if(g_module_symbol(module, "on_window_destroy", (gpointer *)&fn)) fn(gtklock, win);
}
}

5 changes: 3 additions & 2 deletions src/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ void window_pw_toggle_vis(GtkEntry* entry, GtkEntryIconPosition icon_pos) {

static void window_destroy_notify(GtkWidget *widget, gpointer data) {
struct Window *win = window_by_widget(widget);
module_on_window_destroy(gtklock, win);
gtk_widget_destroy(widget);
gtklock_remove_window(gtklock, win);
}
Expand Down Expand Up @@ -341,11 +342,11 @@ struct Window *create_window(GdkMonitor *monitor) {
w->clock_label = GTK_WIDGET(gtk_builder_get_object(builder, "clock-label"));
window_update_clock(w);

g_object_unref(builder);

if(gtklock->hidden) window_idle_hide(w);
module_on_window_create(gtklock, w);
gtk_widget_show_all(w->window);

g_object_unref(builder);
return w;
}

0 comments on commit 1ba86fd

Please sign in to comment.