Newer
Older
Olivier Fourdan
committed
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
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; You may only use version 2 of the License,
you have no option to use any other version.
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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
xfce4 mcs plugin - (c) 2002 Olivier Fourdan
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <X11/Xlib.h>
#include <libxfce4mcs/mcs-common.h>
#include <libxfce4mcs/mcs-manager.h>
#include <xfce-mcs-manager/manager-plugin.h>
#include <libxfcegui4/libxfcegui4.h>
#include "inline-icon.h"
Olivier Fourdan
committed
#define RCDIR "settings"
Olivier Fourdan
committed
#define RCFILE "xfwm4.xml"
#define CHANNEL "xfwm4"
Olivier Fourdan
committed
#define PLUGIN_NAME "xfwm4"
#define DEFAULT_THEME "microdeck2"
#define DEFAULT_KEY_THEME "default.keys"
#define DEFAULT_LAYOUT "OTS|HMC"
#define DEFAULT_ACTION "maximize"
#define DEFAULT_ALIGN "center"
Olivier Fourdan
committed
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
#define DEFAULT_ICON_SIZE 48
#define MAX_ELEMENTS_BEFORE_SCROLLING 6
#ifndef DATADIR
#define DATADIR "/usr/local/share"
#endif
#define STATES 8
#define STATE_HIDDEN (STATES - 1)
typedef enum
{
DECORATION_THEMES = 0,
KEYBINDING_THEMES = 1
}
ThemeType;
enum
{
TITLE = 0,
MENU,
STICK,
SHADE,
HIDE,
MAXIMIZE,
CLOSE,
END
};
typedef struct _TitleRadioButton TitleRadioButton;
struct _TitleRadioButton
{
GtkWidget *radio_buttons[STATES];
guint active;
GSList *radio_group;
};
typedef struct _TitleButton TitleButton;
struct _TitleButton
{
gchar *label;
gchar code;
};
typedef struct _TitleButtonData TitleButtonData;
struct _TitleButtonData
{
guint row;
guint col;
gpointer data;
};
typedef struct _RadioTmpl RadioTmpl;
struct _RadioTmpl
{
gchar *label;
gchar *action;
GtkWidget *radio_button;
};
TitleButton title_buttons[] = {
{N_("Title"), '|'},
{N_("Menu"), 'O'},
{N_("Stick"), 'T'},
{N_("Shade"), 'S'},
{N_("Hide"), 'H'},
{N_("Maximize"), 'M'},
{N_("Close"), 'C'}
Olivier Fourdan
committed
};
RadioTmpl dbl_click_values[] = {
{N_("Shade window"), "shade", NULL},
{N_("Hide window"), "hide", NULL},
{N_("Maximize window"), "maximize", NULL},
{N_("Nothing"), "none", NULL},
Olivier Fourdan
committed
{NULL, NULL, NULL}
};
RadioTmpl title_align_values[] = {
{N_("Left"), "left", NULL},
{N_("Center"), "center", NULL},
{N_("Right"), "right", NULL},
Olivier Fourdan
committed
{NULL, NULL, NULL}
};
enum
{
THEME_NAME_COLUMN,
N_COLUMNS
};
typedef struct _ThemeInfo ThemeInfo;
struct _ThemeInfo
{
gchar *path;
gchar *name;
gboolean has_decoration;
gboolean has_keybinding;
gboolean set_layout;
gboolean set_align;
gboolean set_font;
gboolean user_writable;
Olivier Fourdan
committed
};
typedef struct _Itf Itf;
struct _Itf
{
McsPlugin *mcs_plugin;
GSList *click_focus_radio_group;
GtkWidget *box_move_check;
GtkWidget *box_resize_check;
GtkWidget *click_focus_radio;
GtkWidget *click_raise_check;
GtkWidget *closebutton1;
GtkWidget *dialog_action_area1;
Olivier Fourdan
committed
GtkWidget *dialog_header;
GtkWidget *dialog_vbox1;
GtkWidget *focus_follow_mouse_radio;
GtkWidget *focus_new_check;
GtkWidget *font_button;
GtkWidget *font_selection;
Olivier Fourdan
committed
GtkWidget *frame1;
GtkWidget *frame2;
GtkWidget *frame3;
GtkWidget *frame4;
GtkWidget *frame5;
GtkWidget *frame6;
GtkWidget *frame8;
GtkWidget *frame9;
GtkWidget *frame10;
GtkWidget *frame11;
GtkWidget *frame12;
GtkWidget *frame13;
GtkWidget *frame14;
GtkWidget *frame15;
GtkWidget *hbox1;
GtkWidget *hbox2;
GtkWidget *hbox3;
GtkWidget *hbox4;
Olivier Fourdan
committed
GtkWidget *hbox5;
GtkWidget *hbox6;
GtkWidget *label1;
GtkWidget *label2;
GtkWidget *label3;
GtkWidget *label4;
GtkWidget *label5;
GtkWidget *label6;
GtkWidget *label7;
GtkWidget *label32;
Olivier Fourdan
committed
GtkWidget *label33;
GtkWidget *label34;
Olivier Fourdan
committed
GtkWidget *label37;
GtkWidget *label38;
GtkWidget *label39;
Olivier Fourdan
committed
GtkWidget *label41;
GtkWidget *label42;
GtkWidget *label43;
GtkWidget *label44;
GtkWidget *label45;
GtkWidget *label46;
GtkWidget *label47;
GtkWidget *label48;
GtkWidget *label49;
GtkWidget *notebook1;
GtkWidget *raise_delay_scale;
GtkWidget *raise_on_focus_check;
GtkWidget *scrolledwindow1;
GtkWidget *scrolledwindow2;
GtkWidget *snap_to_border_check;
GtkWidget *snap_width_scale;
GtkWidget *table2;
GtkWidget *table3;
GtkWidget *treeview1;
GtkWidget *treeview2;
GtkWidget *vbox1;
GtkWidget *vbox2;
GtkWidget *vbox3;
GtkWidget *vbox4;
GtkWidget *vbox5;
GtkWidget *vbox6;
GtkWidget *vbox7;
GtkWidget *wrap_workspaces_check;
GtkWidget *xfwm4_dialog;
Olivier Fourdan
committed
};
static void create_channel(McsPlugin * mcs_plugin);
static gboolean write_options(McsPlugin * mcs_plugin);
static void run_dialog(McsPlugin * mcs_plugin);
static gboolean setting_model = FALSE;
static gboolean is_running = FALSE;
static gchar *current_theme = NULL;
static gchar *current_key_theme = NULL;
static gchar *current_layout = NULL;
Olivier Fourdan
committed
static gchar *dbl_click_action = NULL;
static gchar *title_align = NULL;
static gboolean click_to_focus = TRUE;
static gboolean focus_new = TRUE;
static gboolean focus_raise = FALSE;
static gboolean raise_on_click = TRUE;
static gboolean snap_to_border = TRUE;
static gboolean wrap_workspaces = TRUE;
static gboolean box_move = FALSE;
static gboolean box_resize = FALSE;
static int raise_delay;
static int snap_width;
static TitleRadioButton title_radio_buttons[END];
static GList *decoration_theme_list = NULL;
static GList *keybinding_theme_list = NULL;
Olivier Fourdan
committed
static gboolean glib22_str_has_suffix (const gchar *str, const gchar *suffix)
{
int str_len;
int suffix_len;
g_return_val_if_fail (str != NULL, FALSE);
g_return_val_if_fail (suffix != NULL, FALSE);
str_len = strlen (str);
suffix_len = strlen (suffix);
if (str_len < suffix_len)
return FALSE;
return strcmp (str + str_len - suffix_len, suffix) == 0;
}
static void sensitive_cb(GtkWidget * widget, gpointer user_data)
{
gtk_widget_set_sensitive(widget, (gboolean) GPOINTER_TO_INT(user_data));
}
Olivier Fourdan
committed
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
static void cb_layout_destroy_button(GtkWidget * widget, gpointer user_data)
{
g_free(user_data);
}
static void cb_layout_value_changed(GtkWidget * widget, gpointer user_data)
{
static guint recursive = 0;
guint i, j, k, l, m = 0;
guint col, row;
TitleButtonData *callback_data = (TitleButtonData *) user_data;
McsPlugin *mcs_plugin = (McsPlugin *) callback_data->data;
gchar result[STATES];
if(recursive != 0)
{
return;
}
if(!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
{
return;
}
++recursive;
col = callback_data->col;
row = callback_data->row;
for(i = TITLE; i < END; i++)
{
if((i != row) && (title_radio_buttons[i].active == col))
{
for(j = 0; j < STATES; j++)
{
if((i == TITLE) && (title_radio_buttons[row].active == STATE_HIDDEN))
{
gboolean in_use;
in_use = TRUE;
for(l = 0; (l < STATE_HIDDEN) && in_use; l++)
{
in_use = FALSE;
for(k = TITLE; k < END; k++)
{
if(title_radio_buttons[k].active == l)
{
in_use = TRUE;
}
}
if(!in_use)
{
m = l;
}
}
if(!in_use)
{
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(title_radio_buttons[TITLE].radio_buttons[m]), TRUE);
title_radio_buttons[TITLE].active = m;
break;
}
}
else if((col < STATE_HIDDEN) && title_radio_buttons[row].active == j)
{
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(title_radio_buttons[i].radio_buttons[j]), TRUE);
title_radio_buttons[i].active = j;
break;
}
}
}
}
title_radio_buttons[row].active = col;
j = 0;
for(l = 0; l < STATE_HIDDEN; l++)
{
for(k = TITLE; k < END; k++)
{
if(title_radio_buttons[k].active == l)
{
result[j++] = title_buttons[k].code;
}
}
}
result[j++] = '\0';
if(current_layout)
{
g_free(current_layout);
}
current_layout = g_strdup(result);
mcs_manager_set_string(mcs_plugin->manager, "Xfwm/ButtonLayout", CHANNEL, current_layout);
mcs_manager_notify(mcs_plugin->manager, CHANNEL);
write_options(mcs_plugin);
--recursive;
}
static GtkWidget *create_layout_buttons(gchar * layout, gpointer user_data)
{
GtkWidget *table;
GtkWidget *label;
GtkWidget *label_row;
GtkWidget *radio_button;
GSList *radio_button_group;
TitleButtonData *callback_data;
gchar *temp;
guint i, j, len;
gboolean visible;
g_return_val_if_fail(layout != NULL, NULL);
len = strlen(layout);
g_return_val_if_fail(len > 0, NULL);
table = gtk_table_new(8, 9, FALSE);
gtk_widget_show(table);
gtk_container_set_border_width(GTK_CONTAINER(table), 5);
label = gtk_label_new(_("Layout :"));
gtk_widget_show(label);
gtk_table_attach(GTK_TABLE(table), label, 0, 9, 0, 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
for(i = TITLE; i < END; i++)
{
temp = g_strdup_printf("<small><i>%s :</i></small> ", _(title_buttons[i].label));
Olivier Fourdan
committed
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
label_row = gtk_label_new(temp);
gtk_widget_show(label_row);
gtk_table_attach(GTK_TABLE(table), label_row, 0, 1, i + 1, i + 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
gtk_label_set_use_markup(GTK_LABEL(label_row), TRUE);
gtk_label_set_justify(GTK_LABEL(label_row), GTK_JUSTIFY_LEFT);
gtk_misc_set_alignment(GTK_MISC(label_row), 0, 0.5);
radio_button_group = NULL;
visible = FALSE;
for(j = 0; j < STATES - 1; j++)
{
radio_button = gtk_radio_button_new(NULL);
gtk_widget_show(radio_button);
gtk_table_attach(GTK_TABLE(table), radio_button, j + 1, j + 2, i + 1, i + 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
gtk_radio_button_set_group(GTK_RADIO_BUTTON(radio_button), radio_button_group);
radio_button_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button));
title_radio_buttons[i].radio_buttons[j] = radio_button;
if((j < len) && (layout[j] == title_buttons[i].code))
{
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button), TRUE);
visible = TRUE;
title_radio_buttons[i].active = j;
}
callback_data = g_new(TitleButtonData, 1);
callback_data->row = i;
callback_data->col = j;
callback_data->data = user_data;
g_signal_connect(G_OBJECT(radio_button), "toggled", G_CALLBACK(cb_layout_value_changed), callback_data);
g_signal_connect_after(G_OBJECT(radio_button), "destroy", G_CALLBACK(cb_layout_destroy_button), callback_data);
}
if(i != TITLE)
{
radio_button = gtk_radio_button_new_with_mnemonic(NULL, _("Hidden"));
gtk_widget_show(radio_button);
gtk_table_attach(GTK_TABLE(table), radio_button, STATES, STATES + 1, i + 1, i + 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
gtk_radio_button_set_group(GTK_RADIO_BUTTON(radio_button), radio_button_group);
radio_button_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio_button));
title_radio_buttons[i].radio_buttons[STATES - 1] = radio_button;
if(!visible)
{
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio_button), TRUE);
title_radio_buttons[i].active = (STATES - 1);
}
callback_data = g_new(TitleButtonData, 1);
callback_data->row = i;
callback_data->col = STATES - 1;
callback_data->data = user_data;
g_signal_connect(G_OBJECT(radio_button), "toggled", G_CALLBACK(cb_layout_value_changed), callback_data);
g_signal_connect_after(G_OBJECT(radio_button), "destroy", G_CALLBACK(cb_layout_destroy_button), callback_data);
}
}
return (table);
}
static GtkWidget *create_radio_button_table(RadioTmpl template[], guint size, gchar * display_label, gchar * value, GCallback handler, gpointer user_data)
{
GtkWidget *table;
GtkWidget *label;
GSList *radio_group = NULL;
guint i;
table = gtk_table_new(size, 2, FALSE);
gtk_widget_show(table);
gtk_container_set_border_width(GTK_CONTAINER(table), 5);
label = gtk_label_new(display_label);
gtk_widget_show(label);
gtk_table_attach(GTK_TABLE(table), label, 0, size, 0, 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
for(i = 0; i < size; i++)
{
template[i].radio_button = gtk_radio_button_new_with_mnemonic(NULL, _(template[i].label));
gtk_widget_show(template[i].radio_button);
gtk_table_attach(GTK_TABLE(table), template[i].radio_button, i, i + 1, 1, 2, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
gtk_radio_button_set_group(GTK_RADIO_BUTTON(template[i].radio_button), radio_group);
radio_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(template[i].radio_button));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(template[i].radio_button), strcmp(value, template[i].action) ? FALSE : TRUE);
g_signal_connect(G_OBJECT(template[i].radio_button), "toggled", G_CALLBACK(handler), user_data);
}
return table;
}
static void theme_info_free(ThemeInfo * info)
{
g_free(info->path);
g_free(info->name);
g_free(info);
}
static ThemeInfo *find_theme_info_by_name(const gchar * theme_name, GList * theme_list)
Olivier Fourdan
committed
{
GList *list;
for(list = theme_list; list; list = list->next)
{
ThemeInfo *info = list->data;
if(!strcmp(info->name, theme_name))
Olivier Fourdan
committed
return info;
}
return NULL;
}
static gboolean parserc(const gchar * filename, gboolean *set_layout, gboolean *set_align, gboolean *set_font)
{
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
gchar *lvalue, *rvalue;
FILE *fp;
*set_layout = FALSE;
*set_align = FALSE;
*set_font = FALSE;
fp = fopen(filename, "r");
if(!fp)
{
return FALSE;
}
while(fgets(buf, sizeof(buf), fp))
{
lvalue = strtok(buf, "=");
rvalue = strtok(NULL, "\n");
if((lvalue) && (rvalue))
{
if (!g_ascii_strcasecmp(lvalue, "button_layout"))
{
*set_layout = TRUE;
}
else if (!g_ascii_strcasecmp(lvalue, "title_alignment"))
{
*set_align = TRUE;
}
else if (!g_ascii_strcasecmp(lvalue, "title_font"))
{
*set_font = TRUE;
}
}
}
fclose(fp);
return TRUE;
}
Olivier Fourdan
committed
static GList *update_theme_dir(const gchar * theme_dir, GList * theme_list)
{
ThemeInfo *info = NULL;
gchar *theme_name;
GList *list = theme_list;
Olivier Fourdan
committed
gboolean has_decoration = FALSE;
gboolean has_keybinding = FALSE;
gboolean set_layout = FALSE;
gboolean set_align = FALSE;
gboolean set_font = FALSE;
Olivier Fourdan
committed
gchar *tmp;
if(glib22_str_has_suffix(theme_dir, ".keys"))
Olivier Fourdan
committed
{
tmp = g_build_filename(theme_dir, "keythemerc", NULL);
if(g_file_test(tmp, G_FILE_TEST_IS_REGULAR) && parserc(tmp, &set_layout, &set_align, &set_font))
Olivier Fourdan
committed
{
has_keybinding = TRUE;
}
g_free(tmp);
}
else
{
tmp = g_build_filename(theme_dir, "themerc", NULL);
if(g_file_test(tmp, G_FILE_TEST_IS_REGULAR) && parserc(tmp, &set_layout, &set_align, &set_font))
Olivier Fourdan
committed
{
has_decoration = TRUE;
}
g_free(tmp);
}
theme_name = g_strdup(strrchr(theme_dir, G_DIR_SEPARATOR) + 1);
info = find_theme_info_by_name(theme_name, list);
Olivier Fourdan
committed
if(info)
{
if(!has_decoration && !has_keybinding)
{
list = g_list_remove(list, info);
theme_info_free(info);
}
else if((info->has_keybinding != has_keybinding) || (info->has_decoration != has_decoration) || (info->set_layout != set_layout) || (info->set_align != set_align) || (info->set_font != set_font))
Olivier Fourdan
committed
{
info->has_keybinding = has_keybinding;
info->has_decoration = has_decoration;
info->set_layout = set_layout;
info->set_align = set_align;
info->set_font = set_font;
Olivier Fourdan
committed
}
}
else
{
if(has_decoration || has_keybinding)
{
info = g_new0(ThemeInfo, 1);
info->path = g_strdup(theme_dir);
info->name = g_strdup(theme_name);
Olivier Fourdan
committed
info->has_decoration = has_decoration;
info->has_keybinding = has_keybinding;
info->set_layout = set_layout;
info->set_align = set_align;
info->set_font = set_font;
Olivier Fourdan
committed
list = g_list_prepend(list, info);
}
}
g_free(theme_name);
Olivier Fourdan
committed
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
return list;
}
static GList *themes_common_list_add_dir(const char *dirname, GList * theme_list)
{
DIR *dir;
struct dirent *de;
GList *list = theme_list;
g_return_val_if_fail(dirname != NULL, list);
dir = opendir(dirname);
if(!dir)
return list;
while((de = readdir(dir)))
{
char *tmp;
if(de->d_name[0] == '.')
continue;
tmp = g_build_filename(dirname, de->d_name, NULL);
list = update_theme_dir(tmp, list);
g_free(tmp);
}
closedir(dir);
return list;
}
static GList *theme_common_init(GList * theme_list)
{
gchar *dir;
GList *list = theme_list;
dir = g_build_filename(g_get_home_dir(), ".themes", G_DIR_SEPARATOR_S, "xfwm4", NULL);
list = themes_common_list_add_dir(dir, list);
g_free(dir);
dir = g_build_filename(DATADIR, "themes", NULL);
list = themes_common_list_add_dir(dir, list);
g_free(dir);
return list;
}
static gboolean dialog_update_from_theme(Itf *itf, const gchar * theme_name, GList * theme_list)
{
ThemeInfo *info = NULL;
g_return_val_if_fail (theme_name != NULL, FALSE);
g_return_val_if_fail (theme_list != NULL, FALSE);
info = find_theme_info_by_name(theme_name, theme_list);
if (info)
{
gtk_container_foreach (GTK_CONTAINER(itf->frame2), sensitive_cb, GINT_TO_POINTER((gint) !(info->set_layout)));
gtk_container_foreach (GTK_CONTAINER(itf->frame14), sensitive_cb, GINT_TO_POINTER((gint) !(info->set_align)));
gtk_widget_set_sensitive(itf->font_button, !(info->set_font));
return TRUE;
}
return FALSE;
}
Olivier Fourdan
committed
static void decoration_selection_changed(GtkTreeSelection * selection, gpointer data)
{
GtkTreeModel *model;
gchar *new_theme;
GtkTreeIter iter;
Olivier Fourdan
committed
McsPlugin *mcs_plugin;
g_return_if_fail (data != NULL);
Olivier Fourdan
committed
if(setting_model)
Olivier Fourdan
committed
return;
}
itf = (Itf *) data;
mcs_plugin = itf->mcs_plugin;
Olivier Fourdan
committed
if(gtk_tree_selection_get_selected(selection, &model, &iter))
{
gtk_tree_model_get(model, &iter, THEME_NAME_COLUMN, &new_theme, -1);
}
else
{
new_theme = NULL;
}
if(new_theme != NULL)
{
if(current_theme && strcmp(current_theme, new_theme))
{
g_free(current_theme);
current_theme = new_theme;
dialog_update_from_theme(itf, current_theme, decoration_theme_list);
mcs_manager_set_string(mcs_plugin->manager, "Xfwm/ThemeName", CHANNEL, current_theme);
Olivier Fourdan
committed
mcs_manager_notify(mcs_plugin->manager, CHANNEL);
write_options(mcs_plugin);
}
}
}
static void keybinding_selection_changed(GtkTreeSelection * selection, gpointer data)
{
GtkTreeModel *model;
gchar *new_key_theme;
GtkTreeIter iter;
Olivier Fourdan
committed
McsPlugin *mcs_plugin;
g_return_if_fail (data != NULL);
Olivier Fourdan
committed
if(setting_model)
Olivier Fourdan
committed
return;
}
itf = (Itf *) data;
mcs_plugin = itf->mcs_plugin;
Olivier Fourdan
committed
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if(gtk_tree_selection_get_selected(selection, &model, &iter))
{
gtk_tree_model_get(model, &iter, THEME_NAME_COLUMN, &new_key_theme, -1);
}
else
{
new_key_theme = NULL;
}
if(new_key_theme != NULL)
{
if(current_key_theme && strcmp(current_key_theme, new_key_theme))
{
g_free(current_key_theme);
current_key_theme = new_key_theme;
mcs_manager_set_string(mcs_plugin->manager, "Xfwm/KeyThemeName", CHANNEL, current_key_theme);
mcs_manager_notify(mcs_plugin->manager, CHANNEL);
write_options(mcs_plugin);
}
}
}
static GList *read_themes(GList * theme_list, GtkWidget * treeview, GtkWidget * swindow, ThemeType type, gchar * current_value)
{
GList *list;
GList *new_list = theme_list;
GtkTreeModel *model;
GtkTreeView *tree_view;
gint i = 0;
gboolean current_value_found = FALSE;
GtkTreeRowReference *row_ref = NULL;
new_list = theme_common_init(new_list);
tree_view = GTK_TREE_VIEW(treeview);
model = gtk_tree_view_get_model(tree_view);
setting_model = TRUE;
gtk_list_store_clear(GTK_LIST_STORE(model));
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swindow), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
gtk_widget_set_usize(swindow, -1, -1);
for(list = new_list; list; list = list->next)
{
ThemeInfo *info = list->data;
GtkTreeIter iter;
if(((type == DECORATION_THEMES) && !(info->has_decoration)) || ((type == KEYBINDING_THEMES) && !(info->has_keybinding)))
continue;
gtk_list_store_prepend(GTK_LIST_STORE(model), &iter);
gtk_list_store_set(GTK_LIST_STORE(model), &iter, THEME_NAME_COLUMN, info->name, -1);
if(strcmp(current_value, info->name) == 0)
{
GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
row_ref = gtk_tree_row_reference_new(model, path);
gtk_tree_path_free(path);
current_value_found = TRUE;
}
if(i == MAX_ELEMENTS_BEFORE_SCROLLING)
{
GtkRequisition rectangle;
gtk_widget_size_request(GTK_WIDGET(tree_view), &rectangle);
gtk_widget_set_usize(swindow, -1, rectangle.height);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swindow), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
}
i++;
}
if(!current_value_found)
{
GtkTreeIter iter;
GtkTreePath *path;
gtk_list_store_prepend(GTK_LIST_STORE(model), &iter);
gtk_list_store_set(GTK_LIST_STORE(model), &iter, THEME_NAME_COLUMN, current_value, -1);
path = gtk_tree_model_get_path(model, &iter);
row_ref = gtk_tree_row_reference_new(model, path);
gtk_tree_path_free(path);
}
if(row_ref)
{
GtkTreePath *path;
path = gtk_tree_row_reference_get_path(row_ref);
gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE);
gtk_tree_view_scroll_to_cell(tree_view, path, NULL, TRUE, 0.5, 0.0);
gtk_tree_path_free(path);
gtk_tree_row_reference_free(row_ref);
}
setting_model = FALSE;
return new_list;
}
static gint sort_func(GtkTreeModel * model, GtkTreeIter * a, GtkTreeIter * b, gpointer user_data)
{
gchar *a_str = NULL;
gchar *b_str = NULL;
gtk_tree_model_get(model, a, 0, &a_str, -1);
gtk_tree_model_get(model, b, 0, &b_str, -1);
if(a_str == NULL)
a_str = g_strdup("");
if(b_str == NULL)
b_str = g_strdup("");
if(!strcmp(a_str, DEFAULT_THEME))
return -1;
if(!strcmp(b_str, DEFAULT_THEME))
return 1;
return g_utf8_collate(a_str, b_str);
}
static void cb_click_to_focus_changed(GtkWidget * dialog, gpointer user_data)
{
Itf *itf = (Itf *) user_data;
McsPlugin *mcs_plugin = itf->mcs_plugin;
click_to_focus = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(itf->click_focus_radio));
mcs_manager_set_int(mcs_plugin->manager, "Xfwm/ClickToFocus", CHANNEL, click_to_focus ? 1 : 0);
mcs_manager_notify(mcs_plugin->manager, CHANNEL);
write_options(mcs_plugin);
}
static void cb_focus_new_changed(GtkWidget * dialog, gpointer user_data)
{
Itf *itf = (Itf *) user_data;
McsPlugin *mcs_plugin = itf->mcs_plugin;
focus_new = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(itf->focus_new_check));
mcs_manager_set_int(mcs_plugin->manager, "Xfwm/FocusNewWindow", CHANNEL, focus_new ? 1 : 0);
mcs_manager_notify(mcs_plugin->manager, CHANNEL);
write_options(mcs_plugin);
}
static void cb_raise_on_focus_changed(GtkWidget * dialog, gpointer user_data)
{
Itf *itf = (Itf *) user_data;
McsPlugin *mcs_plugin = itf->mcs_plugin;
focus_raise = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(itf->raise_on_focus_check));
gtk_widget_set_sensitive(itf->raise_delay_scale, focus_raise);
mcs_manager_set_int(mcs_plugin->manager, "Xfwm/FocusRaise", CHANNEL, focus_raise ? 1 : 0);
mcs_manager_notify(mcs_plugin->manager, CHANNEL);
write_options(mcs_plugin);
}
static void cb_raise_delay_changed(GtkWidget * dialog, gpointer user_data)
{
Itf *itf = (Itf *) user_data;
McsPlugin *mcs_plugin = itf->mcs_plugin;
raise_delay = (int)gtk_range_get_value(GTK_RANGE(itf->raise_delay_scale));
mcs_manager_set_int(mcs_plugin->manager, "Xfwm/RaiseDelay", CHANNEL, raise_delay);
mcs_manager_notify(mcs_plugin->manager, CHANNEL);
write_options(mcs_plugin);
}
static void cb_raise_on_click_changed(GtkWidget * dialog, gpointer user_data)
{
Itf *itf = (Itf *) user_data;
McsPlugin *mcs_plugin = itf->mcs_plugin;
raise_on_click = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(itf->click_raise_check));
mcs_manager_set_int(mcs_plugin->manager, "Xfwm/RaiseOnClick", CHANNEL, raise_on_click ? 1 : 0);
mcs_manager_notify(mcs_plugin->manager, CHANNEL);
write_options(mcs_plugin);
}
static void cb_snap_to_border_changed(GtkWidget * dialog, gpointer user_data)
{
Itf *itf = (Itf *) user_data;
McsPlugin *mcs_plugin = itf->mcs_plugin;
snap_to_border = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(itf->snap_to_border_check));
gtk_widget_set_sensitive(itf->snap_width_scale, snap_to_border);
mcs_manager_set_int(mcs_plugin->manager, "Xfwm/SnapToBorder", CHANNEL, snap_to_border ? 1 : 0);
mcs_manager_notify(mcs_plugin->manager, CHANNEL);
write_options(mcs_plugin);
}
static void cb_snap_width_changed(GtkWidget * dialog, gpointer user_data)
{
Itf *itf = (Itf *) user_data;
McsPlugin *mcs_plugin = itf->mcs_plugin;
snap_width = (int)gtk_range_get_value(GTK_RANGE(itf->snap_width_scale));
mcs_manager_set_int(mcs_plugin->manager, "Xfwm/SnapWidth", CHANNEL, snap_width);
mcs_manager_notify(mcs_plugin->manager, CHANNEL);
write_options(mcs_plugin);
}
static void cb_wrap_workspaces_changed(GtkWidget * dialog, gpointer user_data)
{
Itf *itf = (Itf *) user_data;
McsPlugin *mcs_plugin = itf->mcs_plugin;
wrap_workspaces = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(itf->wrap_workspaces_check));
mcs_manager_set_int(mcs_plugin->manager, "Xfwm/WrapWorkspaces", CHANNEL, wrap_workspaces ? 1 : 0);
mcs_manager_notify(mcs_plugin->manager, CHANNEL);
write_options(mcs_plugin);
}
static void cb_box_move_changed(GtkWidget * dialog, gpointer user_data)
{
Itf *itf = (Itf *) user_data;
McsPlugin *mcs_plugin = itf->mcs_plugin;
box_move = !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(itf->box_move_check));
mcs_manager_set_int(mcs_plugin->manager, "Xfwm/BoxMove", CHANNEL, box_move ? 1 : 0);
mcs_manager_notify(mcs_plugin->manager, CHANNEL);
write_options(mcs_plugin);
}
static void cb_box_resize_changed(GtkWidget * dialog, gpointer user_data)
{
Itf *itf = (Itf *) user_data;
McsPlugin *mcs_plugin = itf->mcs_plugin;
box_resize = !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(itf->box_resize_check));