aboutsummaryrefslogtreecommitdiff
path: root/module/data.c
blob: 9225d01b1587bb6bd8098de489518c4853307021 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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);
}