aboutsummaryrefslogtreecommitdiff
path: root/module/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'module/data.c')
-rw-r--r--module/data.c156
1 files changed, 156 insertions, 0 deletions
diff --git a/module/data.c b/module/data.c
new file mode 100644
index 0000000..9225d01
--- /dev/null
+++ b/module/data.c
@@ -0,0 +1,156 @@
+#include "../libtopmenu-client/topmenu-monitor.h"
+
+#include "data.h"
+#include "appmenu.h"
+
+G_DEFINE_QUARK(topmenu-window-data, window_data)
+G_DEFINE_QUARK(topmenu-menu-shell-data, menu_shell_data)
+G_DEFINE_QUARK(topmenu-menu-item-data, menu_item_data)
+
+gboolean
+topmenu_is_blacklisted (void)
+{
+ return FALSE;
+}
+
+gboolean
+topmenu_is_window_blacklisted (GtkWindow *window)
+{
+ if (gtk_window_get_window_type (window) != GTK_WINDOW_TOPLEVEL)
+ return TRUE;
+
+ if (GTK_IS_PLUG (window))
+ return TRUE;
+
+ return FALSE;
+}
+
+static WindowData *
+window_data_new (void)
+{
+ return g_slice_new0 (WindowData);
+}
+
+static void
+window_data_free (gpointer data)
+{
+ WindowData *window_data = data;
+
+ if (window_data != NULL)
+ {
+ if (window_data->menus != NULL)
+ g_slist_free_full (window_data->menus, g_object_unref);
+
+ if (window_data->monitor_connection_id)
+ g_signal_handler_disconnect(topmenu_monitor_get_instance(),
+ window_data->monitor_connection_id);
+
+ if (window_data->appmenu.menu)
+ topmenu_appmenu_destroy(&window_data->appmenu);
+
+ if (window_data->appmenubar)
+ gtk_widget_destroy(GTK_WIDGET(window_data->appmenubar));
+
+ g_slice_free (WindowData, window_data);
+ }
+}
+
+static MenuShellData *
+menu_shell_data_new (void)
+{
+ return g_slice_new0 (MenuShellData);
+}
+
+static void
+menu_shell_data_free (gpointer data)
+{
+ if (data != NULL)
+ g_slice_free (MenuShellData, data);
+}
+
+static MenuItemData *
+menu_item_data_new (void)
+{
+ return g_slice_new0 (MenuItemData);
+}
+
+static void
+menu_item_data_free (gpointer data)
+{
+ if (data != NULL) {
+ MenuItemData *item_data = data;
+
+ if (item_data->proxy)
+ gtk_widget_destroy (GTK_WIDGET (item_data->proxy));
+
+ g_slice_free (MenuItemData, data);
+ }
+}
+
+MenuItemData *
+topmenu_get_menu_item_data (GtkMenuItem *menu_item)
+{
+ MenuItemData *menu_item_data;
+
+ g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), NULL);
+
+ menu_item_data = g_object_get_qdata (G_OBJECT (menu_item), menu_item_data_quark ());
+
+ if (menu_item_data == NULL)
+ {
+ menu_item_data = menu_item_data_new ();
+
+ g_object_set_qdata_full (G_OBJECT (menu_item), menu_item_data_quark (), menu_item_data, menu_item_data_free);
+ }
+
+ return menu_item_data;
+}
+
+MenuShellData *
+topmenu_get_menu_shell_data (GtkMenuShell *menu_shell)
+{
+ MenuShellData *menu_shell_data;
+
+ g_return_val_if_fail (GTK_IS_MENU_SHELL (menu_shell), NULL);
+
+ menu_shell_data = g_object_get_qdata (G_OBJECT (menu_shell), menu_shell_data_quark ());
+
+ if (menu_shell_data == NULL)
+ {
+ menu_shell_data = menu_shell_data_new ();
+
+ g_object_set_qdata_full (G_OBJECT (menu_shell), menu_shell_data_quark (), menu_shell_data, menu_shell_data_free);
+ }
+
+ return menu_shell_data;
+}
+
+WindowData *
+topmenu_get_window_data (GtkWindow *window)
+{
+ WindowData *window_data;
+
+ g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
+
+ window_data = g_object_get_qdata (G_OBJECT (window), window_data_quark ());
+
+ if (window_data == NULL)
+ {
+ if (topmenu_is_window_blacklisted (window))
+ return NULL;
+
+ window_data = window_data_new ();
+
+ // Nothing to initialize right now.
+
+ g_object_set_qdata_full (G_OBJECT (window), window_data_quark (), window_data, window_data_free);
+ }
+
+ return window_data;
+}
+
+void
+topmenu_remove_window_data (GtkWindow *window)
+{
+ g_object_set_qdata (G_OBJECT (window), window_data_quark (), NULL);
+}