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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
#include <gtk/gtk.h>
#include <libxfce4panel/xfce-panel-plugin.h>
#include <libxfce4panel/libxfce4panel.h>
#include <libwnck/libwnck.h>
#include <glib.h>
#include <glib-object.h>
typedef struct {
XfcePanelPlugin *plugin;
GtkWidget *button;
GtkWidget *label;
GtkWidget *menu;
WnckScreen *screen;
WnckWindow *window;
gint screen_id;
gint wnck_screen_id;
gint wnck_window_id;
} TitlePlugin;
static void title_construct(XfcePanelPlugin *plugin);
XFCE_PANEL_PLUGIN_REGISTER(title_construct);
static void title_free(XfcePanelPlugin *plugin, TitlePlugin *title)
{
if (title->screen_id != 0)
g_signal_handler_disconnect(plugin, title->screen_id);
if (title->wnck_screen_id != 0)
g_signal_handler_disconnect(title->screen, title->wnck_screen_id);
if (title->wnck_window_id != 0)
g_signal_handler_disconnect(title->window, title->wnck_window_id);
if (title->menu != NULL)
gtk_widget_destroy(title->menu);
title->screen_id = 0;
title->wnck_screen_id = 0;
title->wnck_window_id = 0;
gtk_widget_destroy(title->button);
g_slice_free(TitlePlugin, title);
}
static gboolean title_size_changed(XfcePanelPlugin *plugin,
gint size,
G_GNUC_UNUSED TitlePlugin *title)
{
GtkOrientation orientation;
orientation = xfce_panel_plugin_get_orientation(plugin);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
gtk_widget_set_size_request(GTK_WIDGET(plugin), -1, size);
else
gtk_widget_set_size_request(GTK_WIDGET(plugin), size, -1);
return TRUE;
}
static void title_update_label(TitlePlugin *title, const char *label)
{
gtk_label_set_label(GTK_LABEL(title->label), label);
gtk_widget_set_tooltip_text(title->button, label);
}
static void title_window_name_changed(WnckWindow *window,
TitlePlugin *title)
{
const gchar *name = wnck_window_get_name(window);
title_update_label(title, name);
}
static int title_check_type(WnckWindow *window)
{
WnckWindowType type = wnck_window_get_window_type(window);
switch (type) {
case WNCK_WINDOW_NORMAL:
case WNCK_WINDOW_DIALOG:
return 0;
default:
break;
}
return 1;
}
static void title_window_changed(WnckScreen *screen,
G_GNUC_UNUSED WnckWindow *window_,
TitlePlugin *title)
{
WnckWindow *window;
const gchar *name = NULL;
if (title->wnck_window_id != 0) {
g_signal_handler_disconnect(title->window, title->wnck_window_id);
title->wnck_window_id = 0;
title->window = NULL;
}
window = wnck_screen_get_active_window(screen);
if (window == NULL || title_check_type(window))
gtk_widget_hide(title->button);
else {
title->window = window;
name = wnck_window_get_name(window);
title->wnck_window_id = g_signal_connect(
window, "name-changed",
G_CALLBACK(title_window_name_changed), title
);
gtk_widget_show(title->button);
}
title_update_label(title, name);
}
static void title_screen_changed(XfcePanelPlugin *plugin,
GdkScreen *screen,
TitlePlugin *title)
{
if (title->wnck_screen_id != 0) {
g_signal_handler_disconnect(title->screen, title->wnck_screen_id);
title->wnck_screen_id = 0;
}
if (title->wnck_window_id != 0) {
g_signal_handler_disconnect(title->window, title->wnck_window_id);
title->wnck_window_id = 0;
title->window = NULL;
}
screen = gtk_widget_get_screen(GTK_WIDGET(plugin));
if (screen != NULL) {
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
title->screen = wnck_screen_get(gdk_screen_get_number(screen));
G_GNUC_END_IGNORE_DEPRECATIONS
title->wnck_screen_id = g_signal_connect(
title->screen, "active-window-changed",
G_CALLBACK(title_window_changed), title
);
title_window_changed(title->screen, NULL, title);
}
}
static void title_menu_destroy(GtkWidget *menu, TitlePlugin *title)
{
gtk_widget_destroy(menu);
title->menu = NULL;
}
static void title_pressed(GtkButton *button, TitlePlugin *title)
{
if (title->menu != NULL)
gtk_widget_destroy(title->menu);
if (title->window != NULL) {
GtkWidget *menu = wnck_action_menu_new(title->window);
title->menu = menu;
g_signal_connect(G_OBJECT(menu), "selection-done", G_CALLBACK(title_menu_destroy), title);
gtk_menu_attach_to_widget(GTK_MENU(menu), GTK_WIDGET(button), NULL);
gtk_menu_popup_at_pointer(GTK_MENU(menu), NULL);
}
}
static TitlePlugin *title_new(XfcePanelPlugin *plugin)
{
TitlePlugin *title;
title = g_slice_new0(TitlePlugin);
title->plugin = plugin;
title->button = xfce_panel_create_button();
gtk_widget_show(title->button);
title->label = gtk_label_new(NULL);
gtk_label_set_ellipsize(GTK_LABEL(title->label), PANGO_ELLIPSIZE_END);
gtk_widget_show(title->label);
gtk_container_add(GTK_CONTAINER(title->button), title->label);
return title;
}
static void title_construct(XfcePanelPlugin *plugin)
{
TitlePlugin *title;
title = title_new(plugin);
gtk_container_add(GTK_CONTAINER(plugin), title->button);
xfce_panel_plugin_add_action_widget(plugin, title->button);
xfce_panel_plugin_set_expand(plugin, TRUE);
g_signal_connect(plugin, "free-data",
G_CALLBACK(title_free), title);
g_signal_connect(plugin, "size-changed",
G_CALLBACK(title_size_changed), NULL);
g_signal_connect(title->button, "pressed",
G_CALLBACK(title_pressed), title);
title_screen_changed(plugin, gtk_widget_get_screen(title->button),
title);
title->screen_id = g_signal_connect(
plugin, "screen-changed",
G_CALLBACK(title_screen_changed), title
);
}
|