3
* Copyright (C) 2002 Jasper Huijsmans(huysmans@users.sourceforge.net)
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
/* systembuttons.c : xfce4 panel plugin that shows one or two
21
* 'system buttons'. These are the same buttons also present on
22
* both sides of the switcher plugin:
23
* lock, exit, setup and info.
30
#include <libxfce4util/i18n.h>
31
#include <libxfcegui4/xfce_iconbutton.h>
33
#include <panel/mcs_client.h>
34
#include <panel/plugins.h>
35
#include <panel/xfce.h>
38
#include "mcs_client.h"
45
exec_cmd ("xflock4", FALSE, FALSE);
51
exec_cmd ("xfce4-about", FALSE, FALSE);
57
if (disable_user_config)
60
("Access to the configuration system has been disabled.\n\n"
61
"Ask your system administrator for more information"));
69
mini_power_cb (GtkButton * b, GdkEventButton * ev, gpointer data)
84
{ LOCK, EXIT, SETUP, INFO };
89
int button_types[2]; /* 0, 1, 2 or 3 for lock, exit, setup and info */
92
GtkWidget *buttons[2];
95
GtkWidget *align[2]; /* containers for the actual buttons */
97
GList *callbacks; /* save callbacks for when we change buttons */
107
GtkWidget *two_checkbutton;
108
GtkWidget *option_menu_hbox[2];
109
GtkWidget *option_menus[2];
111
t_systembuttons_dialog;
115
button_update_image (GtkWidget * button, int type)
117
GdkPixbuf *pb = NULL;
122
pb = get_minibutton_pixbuf (MINILOCK_ICON);
125
pb = get_minibutton_pixbuf (MINIPOWER_ICON);
128
pb = get_minibutton_pixbuf (MINIPALET_ICON);
131
pb = get_minibutton_pixbuf (MINIINFO_ICON);
135
xfce_iconbutton_set_pixbuf (XFCE_ICONBUTTON (button), pb);
141
button_set_tip (GtkWidget * button, int type)
143
static const char *tips[4];
144
static gboolean need_init = TRUE;
148
tips[0] = _("Lock the screen");
150
tips[2] = _("Setup");
154
add_tooltip (button, tips[type]);
157
/* creation and destruction */
159
connect_callback(GtkWidget *button, int type)
161
GCallback callback = NULL;
166
callback = G_CALLBACK (mini_lock_cb);
169
callback = G_CALLBACK (mini_power_cb);
172
callback = G_CALLBACK (mini_palet_cb);
175
callback = G_CALLBACK (mini_info_cb);
179
return g_signal_connect (button, "clicked", callback, NULL);
183
create_systembutton (t_systembuttons *sb, int n, int type)
187
button = xfce_iconbutton_new ();
188
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
189
gtk_widget_show (button);
191
button_set_tip (button, type);
192
button_update_image (button, type);
194
sb->cb_ids[n] = connect_callback(button, type);
195
sb->buttons[n] = button;
199
systembuttons_change_type (t_systembuttons * sb, int n, int type)
203
sb->button_types[n] = type;
205
button = sb->buttons[n];
207
g_signal_handler_disconnect(sb->buttons[n], sb->cb_ids[n]);
209
sb->cb_ids[n] = connect_callback(button, type);
210
button_set_tip(button, type);
211
button_update_image(button, type);
215
arrange_systembuttons (t_systembuttons * sb, int orientation)
220
gtk_container_remove (GTK_CONTAINER (sb->box), sb->buttons[0]);
221
gtk_container_remove (GTK_CONTAINER (sb->box), sb->buttons[1]);
223
gtk_widget_destroy (sb->box);
226
/* we need some extra spacing when the panel size <= SMALL
227
* hence the strange code below :) */
228
if (orientation == HORIZONTAL)
230
if (settings.size > SMALL)
231
sb->box = gtk_vbox_new (TRUE, 0);
233
sb->box = gtk_hbox_new (TRUE, 0);
237
if (settings.size > SMALL)
238
sb->box = gtk_hbox_new (TRUE, 0);
240
sb->box = gtk_hbox_new (TRUE, 0);
243
gtk_widget_show (sb->box);
245
gtk_widget_show(sb->buttons[0]);
248
gtk_widget_show(sb->buttons[1]);
250
gtk_widget_hide(sb->buttons[1]);
252
gtk_box_pack_start(GTK_BOX(sb->box), sb->buttons[0], TRUE, TRUE, 0);
253
gtk_box_pack_start(GTK_BOX(sb->box), sb->buttons[1], TRUE, TRUE, 0);
256
static t_systembuttons *
257
systembuttons_new (void)
259
t_systembuttons *sb = g_new0 (t_systembuttons, 1);
263
sb->button_types[0] = 0;
264
create_systembutton (sb,0,0);
266
sb->button_types[1] = 1;
267
create_systembutton (sb,1,1);
269
g_object_ref (sb->buttons[0]);
270
g_object_ref (sb->buttons[1]);
272
arrange_systembuttons (sb, settings.orientation);
278
systembuttons_free (Control * control)
280
t_systembuttons *sb = control->data;
282
g_list_foreach (sb->callbacks, (GFunc) g_free, NULL);
283
g_list_free (sb->callbacks);
289
systembuttons_attach_callback (Control * control, const char *signal,
290
GCallback callback, gpointer data)
292
t_systembuttons *sb = (t_systembuttons *) control->data;
295
cb = g_new0 (SignalCallback, 1);
297
cb->callback = callback;
300
sb->callbacks = g_list_append (sb->callbacks, cb);
302
g_signal_connect (sb->buttons[0], signal, callback, data);
303
g_signal_connect (sb->buttons[1], signal, callback, data);
308
systembuttons_set_size (Control * control, int size)
311
t_systembuttons *sb = control->data;
313
arrange_systembuttons (sb, settings.orientation);
314
gtk_container_add (GTK_CONTAINER (control->base), sb->box);
316
n = sb->show_two ? 2 : 1;
317
s1 = icon_size[size] + border_width;
320
if (settings.orientation == VERTICAL)
323
gtk_widget_set_size_request (sb->box, s1, s2);
325
gtk_widget_set_size_request (sb->box, s1, s1 * n * 0.75);
330
gtk_widget_set_size_request (sb->box, s2, s1);
332
gtk_widget_set_size_request (sb->box, s1 * n * 0.75, s1);
337
systembuttons_set_orientation (Control * control, int orientation)
339
t_systembuttons *sb = control->data;
341
arrange_systembuttons (sb, orientation);
342
gtk_container_add (GTK_CONTAINER (control->base), sb->box);
346
systembuttons_set_theme (Control * control, const char *theme)
352
button_update_image (sb->buttons[0], sb->button_types[0]);
353
button_update_image (sb->buttons[1], sb->button_types[1]);
358
systembuttons_read_config (Control * control, xmlNodePtr node)
362
t_systembuttons *sb = (t_systembuttons *) control->data;
364
value = xmlGetProp (node, (const xmlChar *) "button1");
371
if (n != sb->button_types[0])
372
systembuttons_change_type (sb, 0, n);
375
value = xmlGetProp (node, (const xmlChar *) "button2");
382
if (n != sb->button_types[1])
383
systembuttons_change_type (sb, 1, n);
386
value = xmlGetProp (node, (const xmlChar *) "showtwo");
395
sb->show_two = FALSE;
396
gtk_widget_hide (sb->buttons[1]);
401
gtk_widget_show (sb->buttons[1]);
405
/* Try to resize the systembuttons to fit the user settings */
406
systembuttons_set_size (control, settings.size);
410
systembuttons_write_config (Control * control, xmlNodePtr node)
413
t_systembuttons *sb = control->data;
415
sprintf (prop, "%d", sb->button_types[0]);
417
xmlSetProp (node, (const xmlChar *) "button1", prop);
419
sprintf (prop, "%d", sb->button_types[1]);
421
xmlSetProp (node, (const xmlChar *) "button2", prop);
423
sprintf (prop, "%d", sb->show_two ? 1 : 0);
425
xmlSetProp (node, (const xmlChar *) "showtwo", prop);
430
checkbutton_changed (GtkToggleButton * tb, t_systembuttons_dialog * sbd)
434
show_two = gtk_toggle_button_get_active (tb);
436
if (show_two != sbd->sb->show_two)
438
sbd->sb->show_two = show_two;
442
gtk_widget_show (sbd->sb->buttons[1]);
443
gtk_widget_show (sbd->option_menu_hbox[1]);
447
gtk_widget_hide (sbd->sb->buttons[1]);
448
gtk_widget_hide (sbd->option_menu_hbox[1]);
451
systembuttons_set_size (sbd->control, settings.size);
456
buttons_changed (GtkOptionMenu * om, t_systembuttons_dialog * sbd)
459
int n = gtk_option_menu_get_history (om);
461
i = (GTK_WIDGET (om) == sbd->option_menus[0]) ? 0 : 1;
463
if (n == sbd->sb->button_types[i])
466
systembuttons_change_type (sbd->sb, i, n);
470
systembuttons_create_options (Control * control, GtkContainer * container,
473
GtkWidget *vbox, *hbox, *label, *om = NULL;
474
const char *names[4];
477
t_systembuttons_dialog *sbd;
478
GtkSizeGroup *sg1, *sg2;
480
sg1 = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
481
sg2 = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
483
/* initialize dialog structure */
485
sbd = g_new0 (t_systembuttons_dialog, 1);
487
sbd->control = control;
491
vbox = gtk_vbox_new (FALSE, 8);
492
gtk_widget_show (vbox);
493
gtk_container_add (container, vbox);
495
/* show two checkbutton */
496
hbox = gtk_hbox_new (FALSE, 4);
497
gtk_widget_show (hbox);
498
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
500
label = gtk_label_new (_("Show two buttons:"));
501
gtk_widget_show (label);
502
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
503
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
504
gtk_size_group_add_widget (sg1, label);
506
sbd->two_checkbutton = gtk_check_button_new ();
507
gtk_widget_show (sbd->two_checkbutton);
508
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sbd->two_checkbutton),
510
gtk_box_pack_start (GTK_BOX (hbox), sbd->two_checkbutton, FALSE, FALSE,
513
g_signal_connect (sbd->two_checkbutton, "toggled",
514
G_CALLBACK (checkbutton_changed), sbd);
516
/* set names to use in option menus */
517
names[0] = _("Lock");
518
names[1] = _("Exit");
519
names[2] = _("Setup");
520
names[3] = _("Info");
522
/* two identical option menus */
523
for (i = 0; i < 2; i++)
528
om = sbd->option_menus[i] = gtk_option_menu_new ();
529
menu = gtk_menu_new ();
530
gtk_option_menu_set_menu (GTK_OPTION_MENU (om), menu);
532
for (j = 0; j < 4; j++)
534
mi = gtk_menu_item_new_with_label (names[j]);
535
gtk_widget_show (mi);
536
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
539
gtk_option_menu_set_history (GTK_OPTION_MENU (om),
540
sb->button_types[i]);
541
g_signal_connect (om, "changed", G_CALLBACK (buttons_changed), sbd);
544
/* buttons option menus */
545
hbox = sbd->option_menu_hbox[0] = gtk_hbox_new (FALSE, 4);
546
gtk_widget_show (hbox);
547
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
549
label = gtk_label_new (_("Button 1:"));
550
gtk_widget_show (label);
551
gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
552
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
553
gtk_size_group_add_widget (sg1, label);
555
om = sbd->option_menus[0];
556
gtk_widget_show (om);
557
gtk_box_pack_start (GTK_BOX (hbox), om, FALSE, FALSE, 0);
558
gtk_size_group_add_widget (sg2, om);
560
hbox = sbd->option_menu_hbox[1] = gtk_hbox_new (FALSE, 4);
562
gtk_widget_show (hbox);
563
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
565
label = gtk_label_new (_("Button 2:"));
566
gtk_widget_show (label);
567
gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
568
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
569
gtk_size_group_add_widget (sg1, label);
571
om = sbd->option_menus[1];
572
gtk_widget_show (om);
573
gtk_box_pack_start (GTK_BOX (hbox), om, FALSE, FALSE, 0);
574
gtk_size_group_add_widget (sg2, om);
577
g_signal_connect_swapped (done, "clicked", G_CALLBACK (g_free), sbd);
582
create_systembuttons_control (Control * control)
584
t_systembuttons *sb = systembuttons_new ();
586
gtk_container_add (GTK_CONTAINER (control->base), sb->box);
588
control->data = (gpointer) sb;
589
control->with_popup = FALSE;
591
systembuttons_set_size (control, settings.size);
597
xfce_control_class_init (ControlClass * cc)
599
cc->name = "systembuttons";
600
cc->caption = _("System buttons");
602
cc->create_control = (CreateControlFunc) create_systembuttons_control;
604
cc->free = systembuttons_free;
605
cc->read_config = systembuttons_read_config;
606
cc->write_config = systembuttons_write_config;
607
cc->attach_callback = systembuttons_attach_callback;
609
cc->set_size = systembuttons_set_size;
610
cc->set_orientation = systembuttons_set_orientation;
611
cc->set_theme = systembuttons_set_theme;
612
cc->create_options = systembuttons_create_options;
615
XFCE_PLUGIN_CHECK_INIT