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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
/*
* Copyright 2014 Javier S. Pedro <maemo@javispedro.com>
*
* This file is part of TopMenu.
*
* TopMenu is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TopMenu is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with TopMenu. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtk/gtk.h>
#include "../global.h"
#if GTK_MAJOR_VERSION == 3
#include <gtk/gtkx.h>
#endif
#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;
switch (gtk_window_get_type_hint (window)) {
case GDK_WINDOW_TYPE_HINT_MENU:
case GDK_WINDOW_TYPE_HINT_TOOLBAR:
case GDK_WINDOW_TYPE_HINT_SPLASHSCREEN:
case GDK_WINDOW_TYPE_HINT_DOCK:
case GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU:
case GDK_WINDOW_TYPE_HINT_POPUP_MENU:
case GDK_WINDOW_TYPE_HINT_TOOLTIP:
case GDK_WINDOW_TYPE_HINT_NOTIFICATION:
case GDK_WINDOW_TYPE_HINT_COMBO:
case GDK_WINDOW_TYPE_HINT_DND:
return TRUE;
default:
break;
}
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);
}
|