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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
/*
* Copyright (C) 2008 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by Neil Jagdish Patel <neil.patel@canonical.com>
*
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#define WNCK_I_KNOW_THIS_IS_UNSTABLE
#include <libwnck/libwnck.h>
#include <gio/gio.h>
#include <mate-panel-applet.h>
#include <mate-panel-applet-gsettings.h>
#include "task-list.h"
#include "task-title.h"
#define APPLET_SCHEMA "org.mate.panel.applet.mate-window-picker-applet"
#define SHOW_WIN_KEY "show-all-windows"
#define SHOW_HOME_TITLE_KEY "show-home-title"
#define BOLD_WINDOW_TITLE_KEY "bold-window-title"
typedef struct
{
GtkWidget *tasks;
GtkWidget *applet;
GtkWidget *title;
GSettings *settings;
} WinPickerApp;
static WinPickerApp *mainapp;
static gpointer parent_class;
static void display_about_dialog (GtkAction *action,
WinPickerApp *applet);
static void display_prefs_dialog (GtkAction *action,
WinPickerApp *applet);
static const GtkActionEntry window_picker_menu_actions [] = {
{ "MenuPrefs", GTK_STOCK_PREFERENCES, N_("_Preferences"),
NULL, NULL,
G_CALLBACK (display_prefs_dialog) },
{ "MenuAbout", GTK_STOCK_ABOUT, N_("_About"),
NULL, NULL,
G_CALLBACK (display_about_dialog) }
};
static const gchar *close_window_authors [] = {
"Neil J. Patel <neil.patel@canonical.com>",
"Stefano Karapetsas <stefano@karapetsas.com>",
NULL
};
static void
on_show_all_windows_changed (GSettings *settings,
gchar *key,
gpointer data)
{
WinPickerApp *app;
gboolean show_windows = TRUE;
app = (WinPickerApp*)data;
show_windows = g_settings_get_boolean (settings, SHOW_WIN_KEY);
g_object_set (app->tasks, "show_all_windows", show_windows, NULL);
}
static void
on_show_home_title_changed (GSettings *settings,
gchar *key,
gpointer data)
{
WinPickerApp *app;
gboolean show_home = FALSE;
app = (WinPickerApp*)data;
show_home = g_settings_get_boolean (settings, SHOW_HOME_TITLE_KEY);
g_object_set (app->title, "show_home_title", show_home, NULL);
}
static void
on_bold_window_title_changed (GSettings *settings,
gchar *key,
gpointer data)
{
WinPickerApp *app;
gboolean bold_win = TRUE;
app = (WinPickerApp*)data;
bold_win = g_settings_get_boolean (settings, BOLD_WINDOW_TITLE_KEY);
g_object_set (app->title, "bold_window_title", bold_win, NULL);
}
static inline void
force_no_focus_padding (GtkWidget *widget)
{
static gboolean first_time = TRUE;
if (first_time)
{
gtk_rc_parse_string ("\n"
" style \"na-tray-style\"\n"
" {\n"
" GtkWidget::focus-line-width=0\n"
" GtkWidget::focus-padding=0\n"
" }\n"
"\n"
" widget \"*.na-tray\" style \"na-tray-style\"\n"
"\n");
first_time = FALSE;
}
gtk_widget_set_name (widget, "na-tray");
}
static void
cw_applet_finalize (GObject *object)
{
if (G_OBJECT_CLASS (parent_class)->finalize)
(* G_OBJECT_CLASS (parent_class)->finalize) (object);
}
static gboolean
cw_applet_fill (MatePanelApplet *applet,
const gchar *iid,
gpointer data)
{
WnckScreen *screen;
WinPickerApp *app;
GtkWidget *eb, *tasks, *title;
gchar *ui_path;
GtkActionGroup *action_group;
GObjectClass *object_class;
if (strcmp (iid, "MateWindowPicker") != 0)
return FALSE;
bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
/* Have our background automatically painted. */
mate_panel_applet_set_background_widget (MATE_PANEL_APPLET (applet), GTK_WIDGET (applet));
wnck_set_client_type (WNCK_CLIENT_TYPE_PAGER);
app = g_slice_new0 (WinPickerApp);
mainapp = app;
screen = wnck_screen_get_default ();
object_class = G_OBJECT_GET_CLASS (G_OBJECT(applet));
object_class->finalize = cw_applet_finalize;
parent_class = g_type_class_peek_parent (object_class);
/* gsettings prefs */
app->settings = mate_panel_applet_settings_new (applet, APPLET_SCHEMA);
g_signal_connect (app->settings, "changed::" SHOW_WIN_KEY,
G_CALLBACK (on_show_all_windows_changed), app);
g_signal_connect (app->settings, "changed::" SHOW_HOME_TITLE_KEY,
G_CALLBACK (on_show_home_title_changed), app);
g_signal_connect (app->settings, "changed::" BOLD_WINDOW_TITLE_KEY,
G_CALLBACK (on_bold_window_title_changed), app);
app->applet = GTK_WIDGET (applet);
force_no_focus_padding (GTK_WIDGET (applet));
gtk_container_set_border_width (GTK_CONTAINER (applet), 0);
eb = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_container_add (GTK_CONTAINER (applet), eb);
gtk_container_set_border_width (GTK_CONTAINER (eb), 0);
tasks = app->tasks = task_list_get_default ();
gtk_box_pack_start (GTK_BOX (eb), tasks, FALSE, FALSE, 0);
title = app->title = task_title_new ();
gtk_box_pack_start (GTK_BOX (eb), title, TRUE, TRUE, 0);
gtk_widget_show_all (GTK_WIDGET (applet));
on_show_all_windows_changed (app->settings, SHOW_WIN_KEY, app);
on_show_home_title_changed (app->settings, SHOW_HOME_TITLE_KEY, app);
on_bold_window_title_changed (app->settings, BOLD_WINDOW_TITLE_KEY, app);
action_group = gtk_action_group_new ("MateWindowPicker Applet Actions");
gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
gtk_action_group_add_actions (action_group,
window_picker_menu_actions,
G_N_ELEMENTS (window_picker_menu_actions),
app);
ui_path = g_build_filename (MATEWINDOWPICKER_MENU_UI_DIR, "mate-window-picker-applet-menu.xml", NULL);
mate_panel_applet_setup_menu_from_file (MATE_PANEL_APPLET (app->applet),
ui_path, action_group);
g_free (ui_path);
g_object_unref (action_group);
mate_panel_applet_set_flags (MATE_PANEL_APPLET (applet),
MATE_PANEL_APPLET_EXPAND_MAJOR
| MATE_PANEL_APPLET_EXPAND_MINOR
| MATE_PANEL_APPLET_HAS_HANDLE);
return TRUE;
}
MATE_PANEL_APPLET_OUT_PROCESS_FACTORY ("MateWindowPickerFactory",
PANEL_TYPE_APPLET,
"MateWindowPicker",
cw_applet_fill,
NULL);
static void
display_about_dialog (GtkAction *action,
WinPickerApp *applet)
{
GtkWidget *panel_about_dialog;
panel_about_dialog = gtk_about_dialog_new ();
g_object_set (panel_about_dialog,
"name", _("Window Picker"),
"comments", _("Window Picker"),
"version", PACKAGE_VERSION,
"authors", close_window_authors,
"icon-name", "preferences-system-windows",
"logo-icon-name", "preferences-system-windows",
"copyright", "Copyright \xc2\xa9 2008 Canonical Ltd\n"
"Copyright \xc2\xa9 2013-2014 Stefano Karapetsas\n"
"Copyright \xc2\xa9 2015-2018 MATE developers",
NULL);
gtk_widget_show (panel_about_dialog);
g_signal_connect (panel_about_dialog, "response",
G_CALLBACK (gtk_widget_destroy), NULL);
gtk_window_present (GTK_WINDOW (panel_about_dialog));
}
static void
on_show_win_key_checkbox_toggled (GtkToggleButton *check, gpointer null)
{
gboolean is_active;
is_active = gtk_toggle_button_get_active (check);
g_settings_set_boolean (mainapp->settings, SHOW_WIN_KEY, is_active);
}
static void
on_show_home_title_checkbox_toggled (GtkToggleButton *check, gpointer null)
{
gboolean is_active;
is_active = gtk_toggle_button_get_active (check);
g_settings_set_boolean (mainapp->settings, SHOW_HOME_TITLE_KEY, is_active);
}
static void
on_bold_window_title_checkbox_toggled (GtkToggleButton *check, gpointer null)
{
gboolean is_active;
is_active = gtk_toggle_button_get_active (check);
g_settings_set_boolean (mainapp->settings, BOLD_WINDOW_TITLE_KEY, is_active);
}
static void
display_prefs_dialog (GtkAction *action,
WinPickerApp *applet)
{
GtkWidget *window, *box, *vbox, *nb, *hbox, *label, *check, *button;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), _("Preferences"));
gtk_window_set_icon_name (GTK_WINDOW (window), "preferences-system-windows");
gtk_window_set_type_hint (GTK_WINDOW (window),
GDK_WINDOW_TYPE_HINT_DIALOG);
gtk_container_set_border_width (GTK_CONTAINER (window), 12);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
gtk_container_add (GTK_CONTAINER (window), box);
nb = gtk_notebook_new ();
g_object_set (nb, "show-tabs", FALSE, "show-border", TRUE, NULL);
gtk_box_pack_start (GTK_BOX (box), nb, TRUE, TRUE, 0);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
gtk_notebook_append_page (GTK_NOTEBOOK (nb), vbox, NULL);
check = gtk_check_button_new_with_label (_("Show all windows"));
gtk_widget_set_tooltip_text (GTK_WIDGET (check),
_("Show windows from all workspaces."));
gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, TRUE, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check),
g_settings_get_boolean (mainapp->settings, SHOW_WIN_KEY));
g_signal_connect (check, "toggled",
G_CALLBACK (on_show_win_key_checkbox_toggled), NULL);
check = gtk_check_button_new_with_label (_("Show desktop title and logout button"));
gtk_widget_set_tooltip_text (GTK_WIDGET (check),
_("Show a title for the desktop when no window is selected, and append a logout button."));
gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, TRUE, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check),
g_settings_get_boolean (mainapp->settings, SHOW_HOME_TITLE_KEY));
g_signal_connect (check, "toggled",
G_CALLBACK (on_show_home_title_checkbox_toggled), NULL);
check = gtk_check_button_new_with_label (_("Bold windows title"));
gtk_widget_set_tooltip_text (GTK_WIDGET (check),
_("Show windows title with a bold face."));
gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, TRUE, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check),
g_settings_get_boolean (mainapp->settings, BOLD_WINDOW_TITLE_KEY));
g_signal_connect (check, "toggled",
G_CALLBACK (on_bold_window_title_checkbox_toggled), NULL);
check = gtk_label_new (" ");
gtk_box_pack_start (GTK_BOX (vbox), check, TRUE, TRUE, 0);
gtk_widget_set_size_request (nb, -1, 100);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start (GTK_BOX (box), hbox, FALSE, FALSE, 0);
label = gtk_label_new (" ");
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_widget_show_all (window);
g_signal_connect (window, "delete-event",
G_CALLBACK (gtk_widget_destroy), window);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroy), window);
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (gtk_widget_destroy), window);
gtk_window_present (GTK_WINDOW (window));
}
|