5
#include "ubuntu-tweak.h"
7
static const gchar *keys_of_plugins_with_edge[]={
8
"/apps/compiz/plugins/expo/allscreens/options/expo_edge",
9
"/apps/compiz/plugins/scale/allscreens/options/initiate_edge",
10
"/apps/compiz/plugins/rotate/allscreens/options/rotate_flip_left_edge",
11
"/apps/compiz/plugins/rotate/allscreens/options/rotate_flip_right_edge",
14
static const gchar *names_of_plugins_with_edge[]={
17
"rotate_flip_left_edge",
18
"rotate_flip_right_edge",
21
static GtkWidget *create_checkbutton_wobby_menu(gchar *label,gchar *key);
22
static GtkWidget *create_checkbutton_snap_windows(gchar *label);
23
static GSList *get_active_plugins(GConfClient *client);
25
static void wobby_checkbutton_toggeled(GtkWidget *checkbutton,gchar *key);
26
static void snap_checkbutton_toggeled(GtkWidget *checkbutton, gpointer data);
27
static void cb_combo_box_changed(GtkWidget *combobox,gchar *edge);
28
static void remove_edge(gchar *keys_of_plugins_with_edge,gchar *edge);
29
static void add_edge_base(gchar *keys_of_plugins_with_edge,gchar *edge);
30
static void change_edge(GtkWidget *combobox,gchar *edge);
31
static void add_edge(GtkWidget *combobox,gchar *edge);
33
GtkWidget *create_edge_combo_box(gchar *edge)
37
GSList *edge_list=NULL;
38
GSList *plugins_list=NULL;
44
combobox=gtk_combo_box_new_text();
45
//g_object_set_data(G_OBJECT(combobox),"previous","NULL");
46
gtk_combo_box_append_text(GTK_COMBO_BOX(combobox),"展示桌面");
47
gtk_combo_box_append_text(GTK_COMBO_BOX(combobox),"排列窗口");
48
gtk_combo_box_append_text(GTK_COMBO_BOX(combobox),"转到上一面");
49
gtk_combo_box_append_text(GTK_COMBO_BOX(combobox),"转到下一面");
50
gtk_combo_box_append_text(GTK_COMBO_BOX(combobox),"----");
52
gtk_combo_box_set_active(GTK_COMBO_BOX(combobox),4);
54
client=gconf_client_get_default();
56
plugins_list=get_active_plugins(client);
61
edge_list=gconf_client_get_list(client,
62
keys_of_plugins_with_edge[i],
68
/*将获得的列表与传入的edge值进行对比,吻合则设置combobox为活动状态*/
69
for(length=g_slist_length(edge_list),j=0;j<length;j++)
71
gchar *temp=g_slist_nth_data(edge_list,j);
73
if(!g_ascii_strcasecmp(edge,temp)){
75
gtk_combo_box_set_active(GTK_COMBO_BOX(combobox),i);
76
g_print("稳合了%s!\n",edge);
77
g_object_set_data(G_OBJECT(combobox),"previous",names_of_plugins_with_edge[i]);
88
g_print("设置好了,现在的设定是%s!\n",g_object_get_data(G_OBJECT(combobox),"previous"));
90
g_signal_connect(G_OBJECT(combobox),"changed",G_CALLBACK(cb_combo_box_changed),edge);
92
g_slist_free(edge_list);
93
g_object_unref(client);
98
GtkWidget *create_compiz_page()
103
GtkWidget *main_vbox;
107
GtkWidget *snapping_checkbutton;
108
GtkWidget *movewobby_checkbutton;
109
GtkWidget *checkbutton;
113
main_vbox=gtk_vbox_new(FALSE,10);
114
gtk_widget_show(main_vbox);
115
gtk_container_set_border_width(GTK_CONTAINER(main_vbox),5);
117
label=gtk_label_new(NULL);
118
gtk_label_set_markup(GTK_LABEL(label),_("<b>System Security options</b>"));
119
gtk_misc_set_alignment(GTK_MISC(label),0,0);
120
gtk_widget_show(label);
121
gtk_box_pack_start(GTK_BOX(main_vbox),label,FALSE,FALSE,0);
123
hbox=gtk_hbox_new(FALSE,0);
124
gtk_box_pack_start(GTK_BOX(main_vbox),hbox,FALSE,FALSE,0);
126
vbox=gtk_vbox_new(FALSE,0);
127
gtk_box_pack_start(GTK_BOX(hbox),vbox,FALSE,FALSE,0);
129
combobox=create_edge_combo_box("TopLeft");
130
gtk_box_pack_start(GTK_BOX(vbox),combobox,FALSE,FALSE,0);
132
combobox=create_edge_combo_box("BottomLeft");
133
gtk_box_pack_end(GTK_BOX(vbox),combobox,FALSE,FALSE,0);
135
client=gconf_client_get_default();
136
wallpaper=gconf_client_get_string(client,
137
"/desktop/gnome/background/picture_filename",
140
if(!g_ascii_strcasecmp("",wallpaper)){
141
pixbuf=gdk_pixbuf_new_from_file_at_size("/usr/share/backgrounds/warty-final-ubuntu.png",
145
g_message("wallpaper is %s\n",wallpaper);
147
pixbuf=gdk_pixbuf_new_from_file_at_size(wallpaper,
153
image=gtk_image_new_from_pixbuf(pixbuf);
154
gtk_box_pack_start(GTK_BOX(hbox),image,FALSE,FALSE,0);
156
vbox=gtk_vbox_new(FALSE,0);
157
gtk_box_pack_start(GTK_BOX(hbox),vbox,FALSE,FALSE,0);
159
combobox=create_edge_combo_box("TopRight");
160
gtk_box_pack_start(GTK_BOX(vbox),combobox,FALSE,FALSE,0);
162
combobox=create_edge_combo_box("BottomRight");
163
gtk_box_pack_end(GTK_BOX(vbox),combobox,FALSE,FALSE,0);
165
vbox=gtk_vbox_new(FALSE,0);
166
gtk_box_pack_start(GTK_BOX(main_vbox),vbox,FALSE,FALSE,0);
168
snapping_checkbutton=create_checkbutton_snap_windows("开启粘性窗口");
169
gtk_box_pack_start(GTK_BOX(vbox),snapping_checkbutton,TRUE,TRUE,0);
171
checkbutton=create_checkbutton_wobby_menu("开启弹性菜单","/apps/compiz/plugins/wobbly/screen0/options/map_effect");
172
gtk_box_pack_start(GTK_BOX(vbox),checkbutton,TRUE,TRUE,0);
174
checkbutton=create_checkbutton_wobby_menu("最大化时弹性效果","/apps/compiz/plugins/wobbly/screen0/options/maximize_effect");
175
gtk_box_pack_start(GTK_BOX(vbox),checkbutton,TRUE,TRUE,0);
177
movewobby_checkbutton=create_checkbutton_wobby_menu("移动窗口时启用摇晃","/apps/compiz/plugins/wobbly/screen0/options/move_window_match");
178
g_object_set_data(G_OBJECT(movewobby_checkbutton),"disable",snapping_checkbutton);
179
gtk_box_pack_start(GTK_BOX(vbox),movewobby_checkbutton,TRUE,TRUE,0);
181
vbox=gtk_vbox_new(FALSE,0);
182
gtk_box_pack_start(GTK_BOX(main_vbox),vbox,FALSE,FALSE,0);
184
GtkWidget *radio1, *radio2;
186
/* Create a radio button with a GtkEntry widget */
187
radio1 = gtk_radio_button_new_with_label(NULL,"使用桌面墙");
189
/* Create a radio button with a label */
190
radio2 = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio1),"使用桌面立方体.");
192
/* Pack them into a box, then show all the widgets */
193
gtk_box_pack_start (GTK_BOX (vbox), radio1, TRUE, TRUE, 2);
194
gtk_box_pack_start (GTK_BOX (vbox), radio2, TRUE, TRUE, 2);
196
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio2),TRUE);
198
checkbutton=gtk_check_button_new_with_label("开启立方体倒影");
199
gtk_box_pack_start(GTK_BOX(vbox),checkbutton,TRUE,TRUE,0);
201
g_object_unref(client);
206
GtkWidget *create_checkbutton_wobby_menu(gchar *label,gchar *key)
208
GtkWidget *checkbutton;
216
checkbutton=gtk_check_button_new_with_label(label);
217
g_signal_connect(G_OBJECT(checkbutton),"toggled",G_CALLBACK(wobby_checkbutton_toggeled),key);
219
client=gconf_client_get_default();
221
list=get_active_plugins(client);
223
for(length=g_slist_length(list),j=0;j<length;j++)
225
gchar *temp=g_slist_nth_data(list,j);
227
if(!g_ascii_strcasecmp("wobbly",temp)){
231
value=gconf_client_get(client,key,NULL);
233
if(value->type==GCONF_VALUE_INT){
235
map_effect=gconf_value_get_int(value);
237
match=g_string_new(gconf_client_get_string(client,
238
"/apps/compiz/plugins/wobbly/screen0/options/map_window_match",
241
if(map_effect==1&&match->len>=4){
243
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton),TRUE);
246
g_string_free(match,TRUE);
248
else if(value->type==GCONF_VALUE_BOOL){
250
bool=gconf_value_get_bool(value);
254
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton),TRUE);
257
else if(value->type == GCONF_VALUE_STRING){
259
match = g_string_new(gconf_value_get_string(value));
263
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton),TRUE);
276
g_object_unref(client);
281
void wobby_checkbutton_toggeled(GtkWidget *checkbutton,
290
bool=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton));
291
client=gconf_client_get_default();
292
list=gconf_client_get_list(client,
293
"/apps/compiz/general/allscreens/options/active_plugins",
297
if(g_object_get_data(G_OBJECT(checkbutton),"disable")){
298
g_message("哈哈!我要关掉某个选项了!\n");
301
gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data(G_OBJECT(checkbutton),"disable")),FALSE);
303
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_object_get_data(G_OBJECT(checkbutton),"disable")))){
305
length=g_slist_length(list);
307
for(j=0;j<length;j++)
309
gconstpointer temp=g_slist_nth_data(list,j);
311
if(!g_ascii_strcasecmp("snap",temp)){
313
list=g_slist_remove(list,temp);
315
gconf_client_set_list(client,
316
"/apps/compiz/general/allscreens/options/active_plugins",
328
gtk_widget_set_sensitive(GTK_WIDGET(g_object_get_data(G_OBJECT(checkbutton),"disable")),TRUE);
334
list=g_slist_append(list,"wobbly");
335
gconf_client_set_list(client,
336
"/apps/compiz/general/allscreens/options/active_plugins",
341
value=gconf_client_get(client,key,NULL);
343
if(value->type==GCONF_VALUE_INT){
345
gconf_client_set_int(client,key,1,NULL);
346
gconf_client_set_string(client,
347
"/apps/compiz/plugins/wobbly/screen0/options/map_window_match",
348
"Splash | DropdownMenu | PopupMenu | Tooltip | Notification | Combo | Dnd | Unknown",NULL);
351
else if(value->type==GCONF_VALUE_BOOL){
353
gconf_client_set_bool(client,key,TRUE,NULL);
356
else if(value->type == GCONF_VALUE_STRING){
358
gconf_client_set_string(client,key,"Toolbar | Menu | Utility | Dialog | Normal | Unknown",NULL);
361
list=g_slist_remove(list,"wobbly");
362
gconf_client_set_list(client,
363
"/apps/compiz/general/allscreens/options/active_plugins",
368
value=gconf_client_get(client,key,NULL);
370
if(value->type==GCONF_VALUE_INT){
372
gconf_client_set_int(client,key,0,NULL);
375
else if(value->type==GCONF_VALUE_BOOL){
377
gconf_client_set_bool(client,key,FALSE,NULL);
380
else if(value->type == GCONF_VALUE_STRING){
382
gconf_client_set_string(client,key,"",NULL);
387
g_object_unref(client);
390
GtkWidget *create_checkbutton_snap_windows(gchar *label)
392
GtkWidget *checkbutton;
397
checkbutton=gtk_check_button_new_with_label(label);
398
client=gconf_client_get_default();
400
list=gconf_client_get_list(client,
401
"/apps/compiz/general/allscreens/options/active_plugins",
404
length=g_slist_length(list);
406
for(j=0;j<length;j++)
408
gchar *temp=g_slist_nth_data(list,j);
410
if(!g_ascii_strcasecmp("snap",temp)){
412
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton),TRUE);
416
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton),FALSE);
422
g_signal_connect(G_OBJECT(checkbutton),"toggled",G_CALLBACK(snap_checkbutton_toggeled),NULL);
425
g_object_unref(client);
430
void snap_checkbutton_toggeled(GtkWidget *checkbutton,
436
gconstpointer snap="snap";
439
bool=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton));
440
client=gconf_client_get_default();
441
list=gconf_client_get_list(client,
442
"/apps/compiz/general/allscreens/options/active_plugins",
446
g_print("操作前的长度:%d\n",g_slist_length(list));
447
/* for(j=0;j<length;j++)
449
gchar *temp=g_slist_nth_data(list,j);
451
if(!g_ascii_strcasecmp("snap",temp)){
453
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton),TRUE);
454
g_print("连接信号,原来是toggled!");
458
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton),FALSE);
465
//g_message("你叫我开启这个插件\n");
467
list=g_slist_append(list,snap);
469
gconf_client_set_list(client,
470
"/apps/compiz/general/allscreens/options/active_plugins",
475
//g_message("你叫我关闭这个插件\n");
477
length=g_slist_length(list);
479
for(j=0;j<length;j++)
481
gconstpointer temp=g_slist_nth_data(list,j);
483
if(!g_ascii_strcasecmp("snap",temp)){
485
list=g_slist_remove(list,temp);
487
// g_message("the element is %s\n",temp);
489
gconf_client_set_list(client,
490
"/apps/compiz/general/allscreens/options/active_plugins",
501
list=g_slist_remove(list,snap);
503
gconf_client_set_list(client,
504
"/apps/compiz/general/allscreens/options/active_plugins",
511
// g_print("操作后的长度:%d\n",g_slist_length(list));
513
g_object_unref(client);
516
void cb_combo_box_changed(GtkWidget *combobox,gchar *edge)
518
if(g_object_get_data(combobox,"previous")){
519
g_message("先前的值是是%s,将把其删除,然后替换成新的\n",g_object_get_data(combobox,"previous"));
521
change_edge(combobox,edge);
523
g_message("先前的值为空,将直接加入新的值\n");
524
add_edge(combobox,edge);
528
void change_edge(GtkWidget *combobox,gchar *edge)
530
gchar *previous=g_object_get_data(combobox,"previous");
532
g_print("锁定%s,开始移除....\n",previous);
534
if(!g_ascii_strcasecmp("expo",previous)){
535
remove_edge(keys_of_plugins_with_edge[0],edge);
536
add_edge(combobox,edge);
538
else if(!g_ascii_strcasecmp("initiate",previous)){
539
remove_edge(keys_of_plugins_with_edge[1],edge);
540
add_edge(combobox,edge);
542
else if(!g_ascii_strcasecmp("rotate_flip_left_edge",previous)){
543
remove_edge(keys_of_plugins_with_edge[2],edge);
544
add_edge(combobox,edge);
546
else if(!g_ascii_strcasecmp("rotate_flip_right_edge",previous)){
547
remove_edge(keys_of_plugins_with_edge[3],edge);
548
add_edge(combobox,edge);
553
void remove_edge(gchar *keys_of_plugins_with_edge,gchar *edge)
556
GSList *edge_list=NULL;
560
client=gconf_client_get_default();
562
edge_list=gconf_client_get_list(client,
563
keys_of_plugins_with_edge,
567
length=g_slist_length(edge_list);
569
for(j=0;j<length;j++)
571
gconstpointer temp=g_slist_nth_data(edge_list,j);
573
if(!g_ascii_strcasecmp(edge,temp)){
575
g_message("出来了!!!\n");
577
edge_list=g_slist_remove(edge_list,temp);
579
gconf_client_set_list(client,
580
keys_of_plugins_with_edge,
591
g_object_unref(client);
592
g_slist_free(edge_list);
595
void add_edge(GtkWidget *combobox,gchar *edge)
599
i=gtk_combo_box_get_active(GTK_COMBO_BOX(combobox));
602
add_edge_base(keys_of_plugins_with_edge[0],edge);
603
g_object_set_data(G_OBJECT(combobox),"previous",names_of_plugins_with_edge[0]);
606
add_edge_base(keys_of_plugins_with_edge[1],edge);
607
g_object_set_data(G_OBJECT(combobox),"previous",names_of_plugins_with_edge[1]);
610
add_edge_base(keys_of_plugins_with_edge[2],edge);
611
g_object_set_data(G_OBJECT(combobox),"previous",names_of_plugins_with_edge[2]);
614
add_edge_base(keys_of_plugins_with_edge[3],edge);
615
g_object_set_data(G_OBJECT(combobox),"previous",names_of_plugins_with_edge[3]);
618
g_object_set_data(G_OBJECT(combobox),"previous",NULL);
622
void add_edge_base(gchar *keys_of_plugins_with_edge,gchar *edge)
625
GSList *edge_list=NULL;
627
client=gconf_client_get_default();
629
edge_list=gconf_client_get_list(client,
630
keys_of_plugins_with_edge,
634
edge_list=g_slist_append(edge_list,edge);
636
gconf_client_set_list(client,
637
keys_of_plugins_with_edge,
642
g_object_unref(client);
643
g_slist_free(edge_list);
646
GSList *get_active_plugins(GConfClient *client)
650
list=gconf_client_get_list(client,
651
"/apps/compiz/general/allscreens/options/active_plugins",