diff options
Diffstat (limited to 'libmenu/menu-layout.c')
-rw-r--r-- | libmenu/menu-layout.c | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/libmenu/menu-layout.c b/libmenu/menu-layout.c index 89e9752..30d11b3 100644 --- a/libmenu/menu-layout.c +++ b/libmenu/menu-layout.c @@ -64,7 +64,10 @@ struct MenuLayoutNodeRoot char *basedir; char *name; + GMainContext *main_context; + GSList *monitors; + GSource *monitors_idle_handler; }; struct MenuLayoutNodeMenu @@ -133,16 +136,14 @@ node_next (MenuLayoutNode *node) return node->next; } -static void -handle_entry_directory_changed (EntryDirectory *dir, - MenuLayoutNode *node) +static gboolean +menu_layout_invoke_monitors (MenuLayoutNodeRoot *nr) { - MenuLayoutNodeRoot *nr; - GSList *tmp; + GSList *tmp; - g_assert (node->type == MENU_LAYOUT_NODE_MENU); + g_assert (nr->node.type == MENU_LAYOUT_NODE_ROOT); - nr = (MenuLayoutNodeRoot *) menu_layout_node_get_root (node); + nr->monitors_idle_handler = NULL; tmp = nr->monitors; while (tmp != NULL) @@ -154,6 +155,28 @@ handle_entry_directory_changed (EntryDirectory *dir, tmp = next; } + + return FALSE; +} + +static void +handle_entry_directory_changed (EntryDirectory *dir, + MenuLayoutNode *node) +{ + MenuLayoutNodeRoot *nr; + + g_assert (node->type == MENU_LAYOUT_NODE_MENU); + + nr = (MenuLayoutNodeRoot *) menu_layout_node_get_root (node); + + if (nr->monitors_idle_handler == NULL) + { + nr->monitors_idle_handler = g_idle_source_new (); + g_source_set_callback (nr->monitors_idle_handler, + (GSourceFunc) menu_layout_invoke_monitors, nr, NULL); + g_source_attach (nr->monitors_idle_handler, nr->main_context); + g_source_unref (nr->monitors_idle_handler); + } } static void @@ -224,6 +247,14 @@ menu_layout_node_unref (MenuLayoutNode *node) g_slist_foreach (nr->monitors, (GFunc) g_free, NULL); g_slist_free (nr->monitors); + if (nr->monitors_idle_handler != NULL) + g_source_destroy (nr->monitors_idle_handler); + nr->monitors_idle_handler = NULL; + + if (nr->main_context != NULL) + g_main_context_unref (nr->main_context); + nr->main_context = NULL; + g_free (nr->basedir); g_free (nr->name); } @@ -2266,6 +2297,7 @@ menu_layout_load (const char *filename, const char *non_prefixed_basename, GError **err) { + GMainContext *main_context; GMarkupParseContext *context; MenuLayoutNodeRoot *root; MenuLayoutNode *retval; @@ -2281,6 +2313,8 @@ menu_layout_load (const char *filename, retval = NULL; context = NULL; + main_context = g_main_context_get_thread_default (); + menu_verbose ("Loading \"%s\" from disk\n", filename); if (!g_file_get_contents (filename, @@ -2328,6 +2362,8 @@ menu_layout_load (const char *filename, error = NULL; g_markup_parse_context_end_parse (context, &error); + root->main_context = main_context ? g_main_context_ref (main_context) : NULL; + out: if (context) g_markup_parse_context_free (context); |