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
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
419
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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
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
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
|
/*
* panel-profile.c:
*
* Copyright (C) 2003 Sun Microsystems, Inc.
*
* 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; either version 2 of the
* License, or (at your option) any later 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., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
* Authors:
* Mark McLoughlin <mark@skynet.ie>
*/
#include <config.h>
#include <math.h>
#include "panel-profile.h"
#include "panel-layout.h"
#include <string.h>
#include <glib/gi18n.h>
#include <gio/gio.h>
#include <libpanel-util/panel-list.h>
#include <libmate-desktop/mate-dconf.h>
#include <libmate-desktop/mate-gsettings.h>
#include "applet.h"
#include "panel.h"
#include "panel-widget.h"
#include "panel-util.h"
#include "panel-multiscreen.h"
#include "panel-toplevel.h"
#include "panel-lockdown.h"
#include "panel-schemas.h"
typedef struct {
GdkScreen *screen;
int monitor;
int size;
int x;
int x_right;
gboolean x_centered;
int y;
int y_bottom;
gboolean y_centered;
PanelOrientation orientation;
guint screen_changed : 1;
guint monitor_changed : 1;
guint size_changed : 1;
guint x_changed : 1;
guint x_right_changed : 1;
guint x_centered_changed : 1;
guint y_changed : 1;
guint y_bottom_changed : 1;
guint y_centered_changed : 1;
guint orientation_changed : 1;
} ToplevelLocationChange;
typedef const char *(*PanelProfileGetIdFunc) (gpointer object);
typedef gboolean (*PanelProfileOnLoadQueue) (const char *id);
typedef void (*PanelProfileLoadFunc) (const char *id);
typedef void (*PanelProfileDestroyFunc) (const char *id);
static GSettings *profile_settings = NULL;
static GQuark toplevel_id_quark = 0;
#if 0
static GQuark queued_changes_quark = 0;
#endif
static GQuark commit_timeout_quark = 0;
static void panel_profile_object_id_list_update (gchar **objects);
static void panel_profile_ensure_toplevel_per_screen (void);
static void
panel_profile_set_toplevel_id (PanelToplevel *toplevel,
const char *id)
{
if (!toplevel_id_quark)
toplevel_id_quark = g_quark_from_static_string ("panel-toplevel-id");
g_object_set_qdata_full (G_OBJECT (toplevel),
toplevel_id_quark,
g_strdup (id),
g_free);
}
const char *
panel_profile_get_toplevel_id (PanelToplevel *toplevel)
{
if (!toplevel_id_quark)
return NULL;
return g_object_get_qdata (G_OBJECT (toplevel), toplevel_id_quark);
}
PanelToplevel *
panel_profile_get_toplevel_by_id (const char *toplevel_id)
{
GSList *toplevels, *l;
if (!toplevel_id || !toplevel_id [0])
return NULL;
toplevels = panel_toplevel_list_toplevels ();
for (l = toplevels; l; l = l->next)
if (!strcmp (panel_profile_get_toplevel_id (l->data), toplevel_id))
return l->data;
return NULL;
}
char *
panel_profile_find_new_id (PanelGSettingsKeyType type)
{
gchar **existing_ids;
char *retval = NULL;
char *prefix = NULL;
char *dir = NULL;
int i;
int j;
switch (type) {
case PANEL_GSETTINGS_TOPLEVELS:
prefix = PANEL_TOPLEVEL_DEFAULT_PREFIX;
dir = PANEL_TOPLEVEL_PATH;
break;
case PANEL_GSETTINGS_OBJECTS:
prefix = PANEL_OBJECT_DEFAULT_PREFIX;
dir = PANEL_OBJECT_PATH;
break;
default:
g_assert_not_reached ();
break;
}
existing_ids = mate_dconf_list_subdirs (dir, TRUE);
for (i = 0; !retval; i++) {
retval = g_strdup_printf ("%s-%d", prefix, i);
for (j = 0; existing_ids[j] != NULL; j++) {
if (g_strcmp0 (existing_ids[j], retval) == 0) {
g_free (retval);
retval = NULL;
break;
}
}
}
if (existing_ids)
g_strfreev (existing_ids);
g_assert (retval != NULL);
return retval;
}
static void
panel_profile_remove_commit_timeout (guint timeout)
{
g_source_remove (timeout);
}
static void
panel_profile_set_commit_timeout (PanelToplevel *toplevel,
guint timeout)
{
GDestroyNotify destroy_notify;
if (!commit_timeout_quark)
commit_timeout_quark = g_quark_from_static_string ("panel-queued-timeout");
if (timeout)
destroy_notify = (GDestroyNotify) panel_profile_remove_commit_timeout;
else
destroy_notify = NULL;
g_object_set_qdata_full (G_OBJECT (toplevel),
commit_timeout_quark,
GUINT_TO_POINTER (timeout),
destroy_notify);
}
static guint
panel_profile_get_commit_timeout (GObject *object)
{
if (!commit_timeout_quark)
return 0;
return GPOINTER_TO_UINT (g_object_get_qdata (object, commit_timeout_quark));
}
gboolean
panel_profile_key_is_writable (PanelToplevel *toplevel, gchar *key) {
return g_settings_is_writable (toplevel->settings, key);
}
gboolean
panel_profile_background_key_is_writable (PanelToplevel *toplevel, gchar *key) {
return g_settings_is_writable (toplevel->background_settings, key);
}
void
panel_profile_set_background_type (PanelToplevel *toplevel,
PanelBackgroundType background_type)
{
g_settings_set_enum (toplevel->background_settings,
"type",
background_type);
}
PanelBackgroundType
panel_profile_get_background_type (PanelToplevel *toplevel)
{
PanelBackgroundType background_type;
background_type = g_settings_get_enum (toplevel->background_settings,
"type");
return background_type;
}
void
panel_profile_set_background_color (PanelToplevel *toplevel,
#if GTK_CHECK_VERSION (3, 0, 0)
GdkRGBA *color)
#else
PanelColor *color)
#endif
{
#if GTK_CHECK_VERSION (3, 0, 0)
panel_profile_set_background_gdk_rgba (toplevel, color);
#else
panel_profile_set_background_gdk_color (toplevel, &color->gdk);
panel_profile_set_background_opacity (toplevel, color->alpha);
#endif
}
void
panel_profile_get_background_color (PanelToplevel *toplevel,
#if GTK_CHECK_VERSION (3, 0, 0)
GdkRGBA *color)
#else
PanelColor *color)
#endif
{
#if GTK_CHECK_VERSION (3, 0, 0)
panel_profile_get_background_gdk_rgba (toplevel, color);
#else
panel_profile_get_background_gdk_color (toplevel, &(color->gdk));
color->alpha = panel_profile_get_background_opacity (toplevel);
#endif
}
#if GTK_CHECK_VERSION (3, 0, 0)
void
panel_profile_set_background_gdk_rgba (PanelToplevel *toplevel,
GdkRGBA *color)
{
char *color_str;
color_str = gdk_rgba_to_string (color);
g_settings_set_string (toplevel->background_settings, "color", color_str);
g_free (color_str);
}
void
panel_profile_get_background_gdk_rgba (PanelToplevel *toplevel,
GdkRGBA *color)
{
char *color_str;
color_str = g_settings_get_string (toplevel->background_settings, "color");
if (!color_str || !gdk_rgba_parse (color, color_str)) {
color->red = 0.;
color->green = 0.;
color->blue = 0.;
color->alpha = 1.;
}
g_free (color_str);
}
#else
void
panel_profile_set_background_gdk_color (PanelToplevel *toplevel,
GdkColor *gdk_color)
{
char *color_str;
color_str = g_strdup_printf ("#%02x%02x%02x",
gdk_color->red / 256,
gdk_color->green / 256,
gdk_color->blue / 256);
g_settings_set_string (toplevel->background_settings, "color", color_str);
g_free (color_str);
}
void
panel_profile_get_background_gdk_color (PanelToplevel *toplevel,
GdkColor *gdk_color)
{
char *color_str;
color_str = g_settings_get_string (toplevel->background_settings, "color");
if (!color_str || !gdk_color_parse (color_str, gdk_color)) {
gdk_color->red = 0;
gdk_color->green = 0;
gdk_color->blue = 0;
}
g_free (color_str);
}
#endif
void
panel_profile_set_background_opacity (PanelToplevel *toplevel,
guint16 opacity)
{
#if GTK_CHECK_VERSION (3, 0, 0)
GdkRGBA color;
panel_profile_get_background_color (toplevel, &color);
color.alpha = opacity / 65535.0;
panel_profile_set_background_color (toplevel, &color);
#else
g_settings_set_int (toplevel->background_settings, "opacity", opacity);
#endif
}
guint16
panel_profile_get_background_opacity (PanelToplevel *toplevel)
{
#if GTK_CHECK_VERSION (3, 0, 0)
GdkRGBA color;
panel_profile_get_background_color (toplevel, &color);
return (guint16) round (color.alpha * 65535);
#else
guint16 opacity;
opacity = g_settings_get_int (toplevel->background_settings, "opacity");
return opacity;
#endif
}
void
panel_profile_set_background_image (PanelToplevel *toplevel,
const char *image)
{
if (image && image [0])
g_settings_set_string (toplevel->background_settings, "image", image);
else
g_settings_reset (toplevel->background_settings, "image");
}
char *
panel_profile_get_background_image (PanelToplevel *toplevel)
{
return g_settings_get_string (toplevel->background_settings, "image");
}
void
panel_profile_set_toplevel_name (PanelToplevel *toplevel,
const char *name)
{
if (name && name [0])
g_settings_set_string (toplevel->settings, "name", name);
else
g_settings_reset (toplevel->settings, "name");
}
char *
panel_profile_get_toplevel_name (PanelToplevel *toplevel)
{
return g_settings_get_string (toplevel->settings, "name");
}
void
panel_profile_set_toplevel_orientation (PanelToplevel *toplevel,
PanelOrientation orientation)
{
g_settings_set_enum (toplevel->settings, "orientation", orientation);
}
PanelOrientation
panel_profile_get_toplevel_orientation (PanelToplevel *toplevel)
{
PanelOrientation orientation;
orientation = g_settings_get_enum (toplevel->settings, "orientation");
return orientation;
}
#define TOPLEVEL_GET_SET_FUNCS(k, p, t, s, a) \
void \
panel_profile_set_##p##_##s (PanelToplevel *toplevel, a s) \
{ \
g_settings_set_##t (toplevel->settings, k, s); \
} \
a \
panel_profile_get_##p##_##s (PanelToplevel *toplevel) \
{ \
a retval; \
retval = g_settings_get_##t (toplevel->settings, k); \
return retval; \
}
TOPLEVEL_GET_SET_FUNCS ("size", toplevel, int, size, int)
TOPLEVEL_GET_SET_FUNCS ("expand", toplevel, boolean, expand, gboolean)
TOPLEVEL_GET_SET_FUNCS ("auto-hide", toplevel, boolean, auto_hide, gboolean)
TOPLEVEL_GET_SET_FUNCS ("enable-buttons", toplevel, boolean, enable_buttons, gboolean)
TOPLEVEL_GET_SET_FUNCS ("enable-arrows", toplevel, boolean, enable_arrows, gboolean)
#define TOPLEVEL_GET_SET_BG_FUNCS(k, p, t, s, a) \
void \
panel_profile_set_##p##_##s (PanelToplevel *toplevel, a s) \
{ \
g_settings_set_##t (toplevel->background_settings, k, s); \
} \
a \
panel_profile_get_##p##_##s (PanelToplevel *toplevel) \
{ \
a retval; \
retval = g_settings_get_##t (toplevel->background_settings, k); \
return retval; \
}
TOPLEVEL_GET_SET_BG_FUNCS ("fit", background, boolean, fit, gboolean)
TOPLEVEL_GET_SET_BG_FUNCS ("stretch", background, boolean, stretch, gboolean)
TOPLEVEL_GET_SET_BG_FUNCS ("rotate", background, boolean, rotate, gboolean)
GSettings*
panel_profile_get_attached_object_settings (PanelToplevel *toplevel)
{
GtkWidget *attach_widget;
const char *id;
char *path;
GSettings *settings;
attach_widget = panel_toplevel_get_attach_widget (toplevel);
id = mate_panel_applet_get_id_by_widget (attach_widget);
if (!id)
return NULL;
path = g_strdup_printf (PANEL_OBJECT_PATH "%s/", id);
settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, path);
g_free (path);
return settings;
}
void
panel_profile_set_attached_custom_icon (PanelToplevel *toplevel,
const char *custom_icon)
{
GSettings *settings;
settings = panel_profile_get_attached_object_settings (toplevel);
g_settings_set_boolean (settings, PANEL_OBJECT_USE_CUSTOM_ICON_KEY, custom_icon != NULL);
g_settings_set_string (settings, PANEL_OBJECT_CUSTOM_ICON_KEY, sure_string (custom_icon));
g_object_unref (settings);
}
char *
panel_profile_get_attached_custom_icon (PanelToplevel *toplevel)
{
gchar *custom_icon = NULL;
if (panel_toplevel_get_is_attached (toplevel))
{
GSettings *settings;
settings = panel_profile_get_attached_object_settings (toplevel);
if (!g_settings_get_boolean (settings, PANEL_OBJECT_USE_CUSTOM_ICON_KEY))
{
g_object_unref (settings);
return NULL;
}
custom_icon = g_settings_get_string (settings, PANEL_OBJECT_CUSTOM_ICON_KEY);
g_object_unref (settings);
}
return custom_icon;
}
gboolean
panel_profile_is_writable_attached_custom_icon (PanelToplevel *toplevel)
{
gboolean is_writable = FALSE;
if (panel_toplevel_get_is_attached (toplevel))
{
GSettings *settings;
settings = panel_profile_get_attached_object_settings (toplevel);
is_writable = g_settings_is_writable (settings, PANEL_OBJECT_USE_CUSTOM_ICON_KEY) &&
g_settings_is_writable (settings, PANEL_OBJECT_CUSTOM_ICON_KEY);
g_object_unref (settings);
}
return is_writable;
}
void
panel_profile_set_attached_tooltip (PanelToplevel *toplevel,
const char *tooltip)
{
GSettings *settings;
settings = panel_profile_get_attached_object_settings (toplevel);
g_settings_set_string (settings, PANEL_OBJECT_TOOLTIP_KEY, tooltip);
g_object_unref (settings);
}
char *
panel_profile_get_attached_tooltip (PanelToplevel *toplevel)
{
gchar *tooltip = NULL;
if (panel_toplevel_get_is_attached (toplevel))
{
GSettings *settings;
settings = panel_profile_get_attached_object_settings (toplevel);
tooltip = g_settings_get_string (settings, PANEL_OBJECT_TOOLTIP_KEY);
g_object_unref (settings);
}
return tooltip;
}
gboolean
panel_profile_is_writable_attached_tooltip (PanelToplevel *toplevel)
{
gboolean is_writable = FALSE;
if (panel_toplevel_get_is_attached (toplevel))
{
GSettings *settings;
settings = panel_profile_get_attached_object_settings (toplevel);
is_writable = g_settings_is_writable (settings, PANEL_OBJECT_TOOLTIP_KEY);
g_object_unref (settings);
}
return is_writable;
}
static void
get_background_color (PanelToplevel *toplevel,
#if GTK_CHECK_VERSION (3, 0, 0)
GdkRGBA *color)
#else
PanelColor *color)
#endif
{
char *color_str;
color_str = g_settings_get_string (toplevel->background_settings, "color");
#if GTK_CHECK_VERSION (3, 0, 0)
if (!color_str || !gdk_rgba_parse (color, color_str)) {
color->red = 0;
color->green = 0;
color->blue = 0;
color->alpha = 1;
}
#else
if (!color_str || !gdk_color_parse (color_str, &(color->gdk))) {
color->gdk.red = 0;
color->gdk.green = 0;
color->gdk.blue = 0;
}
#endif
g_free (color_str);
#if !GTK_CHECK_VERSION (3, 0, 0)
color->alpha = g_settings_get_int (toplevel->background_settings, "opacity");
#endif
}
static char *
get_background_image (PanelToplevel *toplevel,
gboolean *fit,
gboolean *stretch,
gboolean *rotate)
{
char *image;
image = g_settings_get_string (toplevel->background_settings, "image");
*fit = g_settings_get_boolean (toplevel->background_settings, "fit");
*stretch = g_settings_get_boolean (toplevel->background_settings, "stretch");
*rotate = g_settings_get_boolean (toplevel->background_settings, "rotate");
return image;
}
static void
panel_profile_load_background (PanelToplevel *toplevel)
{
PanelWidget *panel_widget;
PanelBackground *background;
PanelBackgroundType background_type;
#if GTK_CHECK_VERSION (3, 0, 0)
GdkRGBA color;
#else
PanelColor color;
#endif
char *image;
gboolean fit;
gboolean stretch;
gboolean rotate;
panel_widget = panel_toplevel_get_panel_widget (toplevel);
background = &panel_widget->background;
background_type = panel_profile_get_background_type (toplevel);
get_background_color (toplevel, &color);
image = get_background_image (toplevel, &fit, &stretch, &rotate);
panel_background_set (background,
background_type,
&color,
image,
fit,
stretch,
rotate);
g_free (image);
}
static gboolean
panel_profile_commit_toplevel_changes (PanelToplevel *toplevel)
{
if (g_settings_get_has_unapplied (toplevel->queued_settings))
g_settings_apply (toplevel->queued_settings);
panel_profile_set_commit_timeout (toplevel, 0);
return FALSE;
}
static void
panel_profile_queue_toplevel_location_change (PanelToplevel *toplevel,
ToplevelLocationChange *change)
{
guint commit_timeout;
g_settings_delay (toplevel->queued_settings);
if (change->screen_changed)
g_settings_set_int (toplevel->queued_settings,
"screen",
gdk_screen_get_number (change->screen));
if (change->monitor_changed)
g_settings_set_int (toplevel->queued_settings,
"monitor",
change->monitor);
if (change->size_changed)
g_settings_set_int (toplevel->queued_settings,
"size",
change->size);
if (change->orientation_changed)
g_settings_set_enum (toplevel->queued_settings,
"orientation",
change->orientation);
if (change->x_changed)
g_settings_set_int (toplevel->queued_settings,
"x",
change->x);
if (change->x_right_changed)
g_settings_set_int (toplevel->queued_settings,
"x-right",
change->x_right);
if (change->x_centered_changed)
g_settings_set_boolean (toplevel->queued_settings,
"x-centered",
change->x_centered);
if (change->y_changed)
g_settings_set_int (toplevel->queued_settings,
"y",
change->y);
if (change->y_bottom_changed)
g_settings_set_int (toplevel->queued_settings,
"y-bottom",
change->y_bottom);
if (change->y_centered_changed)
g_settings_set_boolean (toplevel->queued_settings,
"y-centered",
change->y_centered);
commit_timeout = panel_profile_get_commit_timeout (G_OBJECT (toplevel));
if (!commit_timeout) {
commit_timeout =
g_timeout_add (500,
(GSourceFunc) panel_profile_commit_toplevel_changes,
toplevel);
panel_profile_set_commit_timeout (toplevel, commit_timeout);
}
}
#define TOPLEVEL_LOCATION_CHANGED_HANDLER(c) \
static void \
panel_profile_toplevel_##c##_changed (PanelToplevel *toplevel) \
{ \
ToplevelLocationChange change = { NULL }; \
change.c##_changed = TRUE; \
change.c = panel_toplevel_get_##c (toplevel); \
panel_profile_queue_toplevel_location_change (toplevel, &change); \
}
TOPLEVEL_LOCATION_CHANGED_HANDLER(monitor)
TOPLEVEL_LOCATION_CHANGED_HANDLER(size)
TOPLEVEL_LOCATION_CHANGED_HANDLER(orientation)
TOPLEVEL_LOCATION_CHANGED_HANDLER(x_centered)
TOPLEVEL_LOCATION_CHANGED_HANDLER(y_centered)
#define TOPLEVEL_POSITION_CHANGED_HANDLER(c) \
static void \
panel_profile_toplevel_##c##_changed (PanelToplevel *toplevel) \
{ \
ToplevelLocationChange change = { NULL }; \
int x, y, x_right, y_bottom; \
change.c##_changed = TRUE; \
panel_toplevel_get_position (toplevel, \
&x, &x_right, \
&y, &y_bottom); \
change.c = c; \
panel_profile_queue_toplevel_location_change (toplevel, &change); \
}
TOPLEVEL_POSITION_CHANGED_HANDLER(x)
TOPLEVEL_POSITION_CHANGED_HANDLER(x_right)
TOPLEVEL_POSITION_CHANGED_HANDLER(y)
TOPLEVEL_POSITION_CHANGED_HANDLER(y_bottom)
static void
panel_profile_toplevel_screen_changed (PanelToplevel *toplevel)
{
ToplevelLocationChange change = { NULL };
change.screen_changed = TRUE;
change.screen = gtk_window_get_screen (GTK_WINDOW (toplevel));
panel_profile_queue_toplevel_location_change (toplevel, &change);
}
static void
panel_profile_connect_to_toplevel (PanelToplevel *toplevel)
{
g_signal_connect (toplevel, "notify::screen",
G_CALLBACK (panel_profile_toplevel_screen_changed), NULL);
g_signal_connect (toplevel, "notify::monitor",
G_CALLBACK (panel_profile_toplevel_monitor_changed), NULL);
g_signal_connect (toplevel, "notify::size",
G_CALLBACK (panel_profile_toplevel_size_changed), NULL);
g_signal_connect (toplevel, "notify::x",
G_CALLBACK (panel_profile_toplevel_x_changed), NULL);
g_signal_connect (toplevel, "notify::x-right",
G_CALLBACK (panel_profile_toplevel_x_right_changed), NULL);
g_signal_connect (toplevel, "notify::x-centered",
G_CALLBACK (panel_profile_toplevel_x_centered_changed), NULL);
g_signal_connect (toplevel, "notify::y",
G_CALLBACK (panel_profile_toplevel_y_changed), NULL);
g_signal_connect (toplevel, "notify::y-bottom",
G_CALLBACK (panel_profile_toplevel_y_bottom_changed), NULL);
g_signal_connect (toplevel, "notify::y-centered",
G_CALLBACK (panel_profile_toplevel_y_centered_changed), NULL);
g_signal_connect (toplevel, "notify::orientation",
G_CALLBACK (panel_profile_toplevel_orientation_changed), NULL);
}
static void
panel_profile_toplevel_change_notify (GSettings *settings,
gchar *key,
PanelToplevel *toplevel)
{
if (toplevel == NULL || !PANEL_IS_TOPLEVEL (toplevel))
return;
#define UPDATE_STRING(k, n) \
if (!strcmp (key, k)) { \
gchar *value = g_settings_get_string (settings, key); \
panel_toplevel_set_##n (toplevel, value); \
g_free (value); \
}
#define UPDATE_ENUM(k, n) \
if (!strcmp (key, k)) { \
panel_toplevel_set_##n (toplevel, \
g_settings_get_enum (settings, key)); \
}
#define UPDATE_INT(k, n) \
if (!strcmp (key, k)) { \
panel_toplevel_set_##n (toplevel, \
g_settings_get_int (settings, key)); \
}
#define UPDATE_BOOL(k, n) \
if (!strcmp (key, k)) { \
panel_toplevel_set_##n (toplevel, \
g_settings_get_boolean (settings, key)); \
}
#define UPDATE_POS(k, n, n2) \
if (!strcmp (key, k)) { \
int x, x_right, y, y_bottom; \
panel_toplevel_get_position (toplevel, &x, &x_right, \
&y, &y_bottom); \
panel_toplevel_set_##n ( \
toplevel, \
g_settings_get_int (settings, key), \
n2, \
panel_toplevel_get_##n##_centered (toplevel)); \
}
#define UPDATE_POS2(k, n, n2) \
if (!strcmp (key, k)) { \
int x, x_right, y, y_bottom; \
panel_toplevel_get_position (toplevel, &x, &x_right, \
&y, &y_bottom); \
panel_toplevel_set_##n ( \
toplevel, \
n, \
g_settings_get_int (settings, key), \
panel_toplevel_get_##n##_centered (toplevel)); \
}
#define UPDATE_CENTERED(k, n, n2) \
if (!strcmp (key, k)) { \
int x, x_right, y, y_bottom; \
panel_toplevel_get_position (toplevel, &x, &x_right, \
&y, &y_bottom); \
panel_toplevel_set_##n ( \
toplevel, n, n2, \
g_settings_get_boolean (settings, key)); \
}
if (!strcmp (key, "screen")) {
GdkScreen *screen;
screen = gdk_display_get_screen (
gdk_display_get_default (),
g_settings_get_int (settings, key));
if (screen)
gtk_window_set_screen (GTK_WINDOW (toplevel), screen);
else
/* Make sure to set the key back to an actual
* available screen so it will get loaded on
* next startup.
*/
panel_profile_toplevel_screen_changed (toplevel);
}
else UPDATE_INT ("monitor", monitor)
else UPDATE_STRING ("name", name)
else UPDATE_BOOL ("expand", expand)
else UPDATE_ENUM ("orientation", orientation)
else UPDATE_INT ("size", size)
else UPDATE_POS ("x", x, x_right)
else UPDATE_POS ("y", y, y_bottom)
else UPDATE_POS2 ("x-right", x, x_right)
else UPDATE_POS2 ("y-bottom", y, y_bottom)
else UPDATE_CENTERED ("x-centered", x, x_right)
else UPDATE_CENTERED ("y-centered", y, y_bottom)
else UPDATE_BOOL ("auto-hide", auto_hide)
else UPDATE_BOOL ("enable-animations", animate)
else UPDATE_BOOL ("enable-buttons", enable_buttons)
else UPDATE_BOOL ("enable-arrows", enable_arrows)
else UPDATE_INT ("hide-delay", hide_delay)
else UPDATE_INT ("unhide-delay", unhide_delay)
else UPDATE_INT ("auto-hide-size", auto_hide_size)
else UPDATE_ENUM ("animation-speed", animation_speed)
}
static void
panel_profile_background_change_notify (GSettings *settings,
gchar *key,
PanelToplevel *toplevel)
{
PanelWidget *panel_widget;
PanelBackground *background;
if (toplevel == NULL || !PANEL_IS_TOPLEVEL (toplevel))
return;
panel_widget = panel_toplevel_get_panel_widget (toplevel);
if (panel_widget == NULL)
return;
background = &panel_widget->background;
if (!strcmp (key, "type")) {
PanelBackgroundType background_type;
background_type = g_settings_get_enum (settings, key);
panel_background_set_type (background, background_type);
panel_toplevel_update_edges (toplevel);
} else if (!strcmp (key, "color")) {
#if GTK_CHECK_VERSION (3, 0, 0)
GdkRGBA color;
gchar *str;
str = g_settings_get_string (settings, key);
if (gdk_rgba_parse (&color, str))
panel_background_set_color (background, &color);
g_free (str);
#else
GdkColor gdk_color;
gchar *str;
str = g_settings_get_string (settings, key);
if (gdk_color_parse (str, &gdk_color))
panel_background_set_gdk_color (background, &gdk_color);
g_free (str);
} else if (!strcmp (key, "opacity")) {
panel_background_set_opacity (background,
g_settings_get_int (settings, key));
#endif
} else if (!strcmp (key, "image")) {
gchar *value = g_settings_get_string (settings, key);
panel_background_set_image (background, value);
g_free (value);
} else if (!strcmp (key, "fit")) {
panel_background_set_fit (background,
g_settings_get_boolean (settings, key));
} else if (!strcmp (key, "stretch")) {
panel_background_set_stretch (background,
g_settings_get_boolean (settings, key));
} else if (!strcmp (key, "rotate")) {
panel_background_set_rotate (background,
g_settings_get_boolean (settings, key));
}
}
static const char *
key_from_type (PanelGSettingsKeyType type) {
if (type == PANEL_GSETTINGS_TOPLEVELS)
return PANEL_TOPLEVEL_ID_LIST_KEY;
else if (type == PANEL_GSETTINGS_OBJECTS)
return PANEL_OBJECT_ID_LIST_KEY;
g_assert_not_reached ();
return NULL;
}
void
panel_profile_add_to_list (PanelGSettingsKeyType type,
const char *id)
{
char *new_id = id ? g_strdup (id) : panel_profile_find_new_id (type);
if (new_id != NULL) {
mate_gsettings_append_strv (profile_settings,
key_from_type (type),
new_id);
g_free (new_id);
}
}
void
panel_profile_remove_from_list (PanelGSettingsKeyType type,
const char *id)
{
mate_gsettings_remove_all_from_strv (profile_settings,
key_from_type (type),
id);
}
static gboolean
panel_profile_id_list_is_writable (PanelGSettingsKeyType type)
{
return g_settings_is_writable (profile_settings, key_from_type (type));
}
gboolean
panel_profile_id_lists_are_writable (void)
{
return
panel_profile_id_list_is_writable (PANEL_GSETTINGS_TOPLEVELS) &&
panel_profile_id_list_is_writable (PANEL_GSETTINGS_OBJECTS);
}
static gboolean
panel_profile_find_empty_spot (GdkScreen *screen,
PanelOrientation *orientation,
int *monitor)
{
GSList *li;
int i;
int *filled_spots;
gboolean found_a_spot = FALSE;
*monitor = 0;
*orientation = PANEL_ORIENTATION_TOP;
filled_spots = g_new0 (int, panel_multiscreen_monitors (screen));
for (li = panel_toplevel_list_toplevels (); li != NULL; li = li->next) {
PanelToplevel *toplevel = li->data;
GdkScreen *toplevel_screen = gtk_window_get_screen (GTK_WINDOW (toplevel));
int toplevel_monitor = panel_toplevel_get_monitor (toplevel);
if (toplevel_screen != screen ||
panel_toplevel_get_is_attached (toplevel) ||
toplevel_monitor < 0)
continue;
filled_spots[toplevel_monitor] |= panel_toplevel_get_orientation (toplevel);
}
for (i = 0; i < panel_multiscreen_monitors (screen); i++) {
/* These are ordered based on "priority" of the
orientation when picking it */
if ( ! (filled_spots[i] & PANEL_ORIENTATION_TOP)) {
*orientation = PANEL_ORIENTATION_TOP;
*monitor = i;
found_a_spot = TRUE;
break;
} else if ( ! (filled_spots[i] & PANEL_ORIENTATION_BOTTOM)) {
*orientation = PANEL_ORIENTATION_BOTTOM;
*monitor = i;
found_a_spot = TRUE;
break;
} else if ( ! (filled_spots[i] & PANEL_ORIENTATION_RIGHT)) {
*orientation = PANEL_ORIENTATION_RIGHT;
*monitor = i;
found_a_spot = TRUE;
break;
} else if ( ! (filled_spots[i] & PANEL_ORIENTATION_LEFT)) {
*orientation = PANEL_ORIENTATION_LEFT;
*monitor = i;
found_a_spot = TRUE;
break;
}
}
g_free (filled_spots);
return found_a_spot;
}
void
panel_profile_create_toplevel (GdkScreen *screen)
{
char *id;
char *path;
PanelOrientation orientation;
int monitor;
GSettings *settings;
g_return_if_fail (screen != NULL);
id = panel_profile_find_new_id (PANEL_GSETTINGS_TOPLEVELS);
path = g_strdup_printf (PANEL_TOPLEVEL_PATH "%s/", id);
settings = g_settings_new_with_path (PANEL_TOPLEVEL_SCHEMA, path);
g_free (path);
g_settings_set_int (settings, PANEL_TOPLEVEL_SCREEN_KEY, gdk_screen_get_number (screen));
if (panel_profile_find_empty_spot (screen, &orientation, &monitor)) {
g_settings_set_int (settings, PANEL_TOPLEVEL_MONITOR_KEY, monitor);
g_settings_set_enum (settings, PANEL_TOPLEVEL_ORIENTATION_KEY, orientation);
}
panel_profile_add_to_list (PANEL_GSETTINGS_TOPLEVELS, id);
g_object_unref (settings);
g_free (id);
}
static void
panel_profile_delete_toplevel_objects (const char *toplevel_id)
{
gchar **list;
GArray *newlist;
int i;
list = g_settings_get_strv (profile_settings, PANEL_OBJECT_ID_LIST_KEY);
newlist = g_array_new (TRUE, TRUE, sizeof (gchar *));
for (i = 0; list[i]; i++) {
char *path;
char *parent_toplevel_id;
GSettings *settings;
path = g_strdup_printf (PANEL_OBJECT_PATH "%s/", list[i]);
settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, path);
parent_toplevel_id = g_settings_get_string (settings, PANEL_OBJECT_TOPLEVEL_ID_KEY);
g_free (path);
g_object_unref (settings);
if (parent_toplevel_id && !strcmp (toplevel_id, parent_toplevel_id)) {
g_free (parent_toplevel_id);
continue;
}
newlist = g_array_append_val (newlist, list[i]);
g_free (parent_toplevel_id);
}
g_settings_set_strv (profile_settings, PANEL_OBJECT_ID_LIST_KEY, (const gchar **) newlist->data);
g_array_free (newlist, TRUE);
g_strfreev (list);
}
void
panel_profile_delete_toplevel (PanelToplevel *toplevel)
{
const char *toplevel_id;
toplevel_id = panel_profile_get_toplevel_id (toplevel);
/* disable GSettings signals */
if (toplevel->settings) {
g_object_unref (toplevel->settings);
toplevel->settings = NULL;
}
if (toplevel->background_settings) {
g_object_unref (toplevel->background_settings);
toplevel->background_settings = NULL;
}
panel_profile_delete_toplevel_objects (toplevel_id);
panel_profile_remove_from_list (PANEL_GSETTINGS_TOPLEVELS, toplevel_id);
}
static GdkScreen *
get_toplevel_screen (char *toplevel_path)
{
GdkDisplay *display;
GSettings *settings;
int screen_n;
settings = g_settings_new_with_path (PANEL_TOPLEVEL_SCHEMA, toplevel_path);
screen_n = g_settings_get_int (settings, "screen");
g_object_unref (settings);
display = gdk_display_get_default ();
if (screen_n < 0 || screen_n >= gdk_display_get_n_screens (display)) {
#if 0
g_warning (_("Panel '%s' is set to be displayed on screen %d which "
"is not currently available. Not loading this panel."),
toplevel_dir, screen_n);
#endif
return NULL;
}
return gdk_display_get_screen (display, screen_n);
}
PanelToplevel *
panel_profile_load_toplevel (const char *toplevel_id)
{
PanelToplevel *toplevel;
GdkScreen *screen;
char *toplevel_path;
char *toplevel_background_path;
if (!toplevel_id || !toplevel_id [0])
return NULL;
toplevel_path = g_strdup_printf ("%s%s/", PANEL_TOPLEVEL_PATH, toplevel_id);
if (!(screen = get_toplevel_screen (toplevel_path))) {
g_free (toplevel_path);
return NULL;
}
toplevel = g_object_new (PANEL_TYPE_TOPLEVEL,
"screen", screen,
NULL);
panel_toplevel_set_settings_path (toplevel, toplevel_path);
toplevel->settings = g_settings_new_with_path (PANEL_TOPLEVEL_SCHEMA, toplevel_path);
toplevel->queued_settings = g_settings_new_with_path (PANEL_TOPLEVEL_SCHEMA, toplevel_path);
toplevel_background_path = g_strdup_printf ("%sbackground/", toplevel_path);
toplevel->background_settings = g_settings_new_with_path (PANEL_TOPLEVEL_BACKGROUND_SCHEMA, toplevel_background_path);
#define GET_INT(k, fn) \
{ \
int val; \
val = g_settings_get_int (toplevel->settings, k); \
panel_toplevel_set_##fn (toplevel, val); \
}
#define GET_BOOL(k, fn) \
{ \
gboolean val; \
val = g_settings_get_boolean (toplevel->settings, k); \
panel_toplevel_set_##fn (toplevel, val); \
}
#define GET_STRING(k, fn) \
{ \
char *val; \
val = g_settings_get_string (toplevel->settings, k); \
panel_toplevel_set_##fn (toplevel, val); \
g_free (val); \
}
#define GET_ENUM(k, fn) \
{ \
int val; \
val = g_settings_get_enum (toplevel->settings, k); \
panel_toplevel_set_##fn (toplevel, val); \
}
GET_STRING ("name", name);
GET_INT ("monitor", monitor);
GET_BOOL ("expand", expand);
GET_ENUM ("orientation", orientation);
GET_INT ("size", size);
GET_BOOL ("auto-hide", auto_hide);
GET_BOOL ("enable-animations", animate);
GET_BOOL ("enable-buttons", enable_buttons);
GET_BOOL ("enable-arrows", enable_arrows);
GET_INT ("hide-delay", hide_delay);
GET_INT ("unhide-delay", unhide_delay);
GET_INT ("auto-hide-size", auto_hide_size);
GET_ENUM ("animation-speed", animation_speed);
#define GET_POSITION(a, b, c, fn) \
{ \
gboolean centered; \
int position; \
int position2; \
centered = g_settings_get_boolean (toplevel->settings, c); \
position = g_settings_get_int (toplevel->settings, a); \
position2 = g_settings_get_int (toplevel->settings, b); \
panel_toplevel_set_##fn (toplevel, position, position2, centered); \
}
GET_POSITION ("x", "x-right", "x-centered", x);
GET_POSITION ("y", "y-bottom", "y-centered", y);
panel_profile_load_background (toplevel);
panel_profile_set_toplevel_id (toplevel, toplevel_id);
panel_profile_connect_to_toplevel (toplevel);
g_signal_connect (toplevel->settings,
"changed",
G_CALLBACK (panel_profile_toplevel_change_notify),
toplevel);
g_signal_connect (toplevel->background_settings,
"changed",
G_CALLBACK (panel_profile_background_change_notify),
toplevel);
g_free (toplevel_path);
g_free (toplevel_background_path);
panel_setup (toplevel);
return toplevel;
}
static void
panel_profile_load_and_show_toplevel (char *toplevel_id)
{
PanelToplevel *toplevel;
gchar **objects;
gboolean loading_queued_applets;
toplevel = panel_profile_load_toplevel (toplevel_id);
if (!toplevel)
return;
gtk_widget_show (GTK_WIDGET (toplevel));
loading_queued_applets = FALSE;
/* reload list of objects to get those that might be on the new
* toplevel */
GSettings *panel_settings;
panel_settings = g_settings_new (PANEL_SCHEMA);
objects = g_settings_get_strv (panel_settings, PANEL_OBJECT_ID_LIST_KEY);
if (objects) {
panel_profile_object_id_list_update (objects);
loading_queued_applets = TRUE;
}
if (!loading_queued_applets)
mate_panel_applet_load_queued_applets (FALSE);
g_strfreev (objects);
g_object_unref (panel_settings);
}
static void
panel_profile_load_and_show_toplevel_startup (const char *toplevel_id)
{
PanelToplevel *toplevel;
toplevel = panel_profile_load_toplevel (toplevel_id);
if (toplevel)
gtk_widget_show (GTK_WIDGET (toplevel));
}
static void
panel_profile_destroy_toplevel (const char *id)
{
PanelToplevel *toplevel;
if (!(toplevel = panel_profile_get_toplevel_by_id (id)))
return;
gtk_widget_destroy (GTK_WIDGET (toplevel));
}
char *
panel_profile_prepare_object_with_id (PanelObjectType object_type,
const char *toplevel_id,
int position,
gboolean right_stick)
{
PanelGSettingsKeyType key_type;
char *id;
char *settings_path;
GSettings *settings;
key_type = PANEL_GSETTINGS_OBJECTS;
id = panel_profile_find_new_id (key_type);
settings_path = g_strdup_printf (PANEL_OBJECT_PATH "%s/", id);
settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, settings_path);
g_settings_set_enum (settings, PANEL_OBJECT_TYPE_KEY, object_type);
g_settings_set_string (settings, PANEL_OBJECT_TOPLEVEL_ID_KEY, toplevel_id);
g_settings_set_int (settings, PANEL_OBJECT_POSITION_KEY, position);
g_settings_set_boolean (settings, PANEL_OBJECT_PANEL_RIGHT_STICK_KEY, right_stick);
g_free (settings_path);
g_object_unref (settings);
return id;
}
char *
panel_profile_prepare_object (PanelObjectType object_type,
PanelToplevel *toplevel,
int position,
gboolean right_stick)
{
return panel_profile_prepare_object_with_id (object_type,
panel_profile_get_toplevel_id (toplevel),
position,
right_stick);
}
void
panel_profile_delete_object (AppletInfo *applet_info)
{
PanelGSettingsKeyType type;
const char *id;
type = PANEL_GSETTINGS_OBJECTS;
id = mate_panel_applet_get_id (applet_info);
panel_profile_remove_from_list (type, id);
}
static void
panel_profile_load_object (char *id)
{
PanelObjectType object_type;
char *object_path;
char *toplevel_id;
int position;
gboolean right_stick;
gboolean locked;
GSettings *settings;
object_path = g_strdup_printf (PANEL_OBJECT_PATH "%s/", id);
settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, object_path);
object_type = g_settings_get_enum (settings, PANEL_OBJECT_TYPE_KEY);
position = g_settings_get_int (settings, PANEL_OBJECT_POSITION_KEY);
toplevel_id = g_settings_get_string (settings, PANEL_OBJECT_TOPLEVEL_ID_KEY);
right_stick = g_settings_get_boolean (settings, PANEL_OBJECT_PANEL_RIGHT_STICK_KEY);
locked = g_settings_get_boolean (settings, PANEL_OBJECT_LOCKED_KEY);
mate_panel_applet_queue_applet_to_load (id,
object_type,
toplevel_id,
position,
right_stick,
locked);
g_free (toplevel_id);
g_free (object_path);
g_object_unref (settings);
}
static void
panel_profile_destroy_object (const char *id)
{
AppletInfo *info;
info = mate_panel_applet_get_by_id (id);
mate_panel_applet_clean (info);
}
static void
panel_profile_delete_dir (PanelGSettingsKeyType type,
const char *id)
{
gchar *dir = NULL;
switch (type) {
case PANEL_GSETTINGS_TOPLEVELS:
dir = g_strdup_printf (PANEL_TOPLEVEL_PATH "%s/", id);
break;
case PANEL_GSETTINGS_OBJECTS:
dir = g_strdup_printf (PANEL_OBJECT_PATH "%s/", id);
break;
default:
g_assert_not_reached ();
break;
}
if (type == PANEL_GSETTINGS_TOPLEVELS) {
gchar *subdir;
subdir = g_strdup_printf (PANEL_TOPLEVEL_PATH "%s/background/", id);
mate_dconf_recursive_reset (subdir, NULL);
g_free (subdir);
}
else if (type == PANEL_GSETTINGS_OBJECTS) {
gchar *subdir;
subdir = g_strdup_printf (PANEL_TOPLEVEL_PATH "%s/prefs/", id);
mate_dconf_recursive_reset (subdir, NULL);
g_free (subdir);
}
if (dir != NULL) {
mate_dconf_recursive_reset (dir, NULL);
g_free (dir);
}
}
static gboolean
panel_profile_object_exists (GSList *list,
const char *id,
PanelProfileGetIdFunc get_id_func)
{
GSList *l;
if (!list || !id)
return FALSE;
for (l = list; l; l = l->next) {
const char *check_id;
check_id = get_id_func (l->data);
g_assert (check_id != NULL);
if (!strcmp (check_id, id))
return TRUE;
}
return FALSE;
}
static gboolean
panel_profile_id_exists (GSList *id_list,
const char *id)
{
GSList *l;
if (!id_list || !id)
return FALSE;
for (l = id_list; l; l = l->next) {
const char *check_id = l->data;
if (!strcmp (id, check_id))
return TRUE;
}
return FALSE;
}
static void
panel_profile_load_added_ids (GSList *list,
GSList *id_list,
PanelProfileGetIdFunc get_id_func,
PanelProfileLoadFunc load_handler,
PanelProfileOnLoadQueue on_load_queue)
{
GSList *added_ids = NULL;
GSList *l;
for (l = id_list; l; l = l->next) {
const char *id = l->data;
if (!panel_profile_object_exists (list, id, get_id_func) &&
(on_load_queue == NULL || !on_load_queue (id)))
added_ids = g_slist_prepend (added_ids, g_strdup (id));
}
for (l = added_ids; l; l = l->next) {
char *id;
id = (char *) l->data;
if (id && id[0])
load_handler (id);
g_free (l->data);
l->data = NULL;
}
g_slist_free (added_ids);
}
static void
panel_profile_delete_removed_ids (PanelGSettingsKeyType type,
GSList *list,
GSList *id_list,
PanelProfileGetIdFunc get_id_func,
PanelProfileDestroyFunc destroy_handler)
{
GSList *removed_ids = NULL;
GSList *l;
for (l = list; l; l = l->next) {
const char *id;
id = get_id_func (l->data);
if (!panel_profile_id_exists (id_list, id))
removed_ids = g_slist_prepend (removed_ids, g_strdup (id));
}
for (l = removed_ids; l; l = l->next) {
const char *id = l->data;
panel_profile_delete_dir (type, id);
destroy_handler (id);
g_free (l->data);
l->data = NULL;
}
g_slist_free (removed_ids);
}
static void
panel_profile_toplevel_id_list_notify (GSettings *settings,
gchar *key,
gpointer user_data)
{
GSList *l, *existing_toplevels;
GSList *toplevel_ids;
gchar **toplevel_ids_strv;
toplevel_ids_strv = g_settings_get_strv (settings, key);
toplevel_ids = mate_gsettings_strv_to_gslist (toplevel_ids_strv);
toplevel_ids = panel_g_slist_make_unique (toplevel_ids,
(GCompareFunc) g_strcmp0,
FALSE);
g_strfreev (toplevel_ids_strv);
existing_toplevels = NULL;
for (l = panel_toplevel_list_toplevels (); l; l = l->next) {
PanelToplevel *toplevel = l->data;
/* Attached toplevels aren't on the id list */
if (panel_toplevel_get_is_attached (toplevel))
continue;
existing_toplevels = g_slist_prepend (existing_toplevels, toplevel);
}
panel_profile_load_added_ids (existing_toplevels,
toplevel_ids,
(PanelProfileGetIdFunc) panel_profile_get_toplevel_id,
(PanelProfileLoadFunc) panel_profile_load_and_show_toplevel,
(PanelProfileOnLoadQueue) NULL);
panel_profile_delete_removed_ids (PANEL_GSETTINGS_TOPLEVELS,
existing_toplevels,
toplevel_ids,
(PanelProfileGetIdFunc) panel_profile_get_toplevel_id,
(PanelProfileDestroyFunc) panel_profile_destroy_toplevel);
/* if there are no panels, reset layout to default */
if (g_slist_length (toplevel_ids) == 0)
panel_profile_ensure_toplevel_per_screen ();
g_slist_free (existing_toplevels);
g_slist_free (toplevel_ids);
}
static void
panel_profile_object_id_list_update (gchar **objects)
{
GSList *existing_applets;
GSList *sublist = NULL, *l;
GSList *object_ids;
object_ids = mate_gsettings_strv_to_gslist (objects);
object_ids = panel_g_slist_make_unique (object_ids,
(GCompareFunc) g_strcmp0,
FALSE);
existing_applets = mate_panel_applet_list_applets ();
for (l = existing_applets; l; l = l->next) {
AppletInfo *info = l->data;
sublist = g_slist_prepend (sublist, info);
}
panel_profile_load_added_ids (sublist,
object_ids,
(PanelProfileGetIdFunc) mate_panel_applet_get_id,
(PanelProfileLoadFunc) panel_profile_load_object,
(PanelProfileOnLoadQueue) mate_panel_applet_on_load_queue);
panel_profile_delete_removed_ids (PANEL_GSETTINGS_OBJECTS,
sublist,
object_ids,
(PanelProfileGetIdFunc) mate_panel_applet_get_id,
(PanelProfileDestroyFunc) panel_profile_destroy_object);
g_slist_free (sublist);
g_slist_free (object_ids);
mate_panel_applet_load_queued_applets (FALSE);
}
static void
panel_profile_object_id_list_notify (GSettings *settings,
gchar *key,
gpointer data)
{
gchar **objects;
objects = g_settings_get_strv (settings, key);
panel_profile_object_id_list_update (objects);
g_strfreev (objects);
}
static void
panel_profile_load_list (GSettings *settings,
PanelGSettingsKeyType type,
PanelProfileLoadFunc load_handler,
GCallback notify_handler)
{
const gchar *key = key_from_type (type);
gchar *changed_signal;
gchar **list;
gint i;
changed_signal = g_strdup_printf ("changed::%s", key);
g_signal_connect (settings, changed_signal, G_CALLBACK (notify_handler), NULL);
g_free (changed_signal);
list = g_settings_get_strv (settings, key);
for (i = 0; list[i]; i++) {
load_handler (list[i]);
}
if (list)
g_strfreev (list);
}
static void
panel_profile_ensure_toplevel_per_screen ()
{
GSList *toplevels;
GSList *empty_screens = NULL;
GSList *l;
GdkDisplay *display;
int n_screens, i;
toplevels = panel_toplevel_list_toplevels ();
display = gdk_display_get_default ();
n_screens = gdk_display_get_n_screens (display);
for (i = 0; i < n_screens; i++) {
GdkScreen *screen;
screen = gdk_display_get_screen (display, i);
for (l = toplevels; l; l = l->next)
if (gtk_window_get_screen (l->data) == screen)
break;
if (!l)
empty_screens = g_slist_prepend (empty_screens, screen);
}
for (l = empty_screens; l; l = l->next)
panel_layout_apply_default_from_gkeyfile (l->data);
g_slist_free (empty_screens);
}
void
panel_profile_settings_load (void)
{
profile_settings = g_settings_new ("org.mate.panel");
}
void
panel_profile_load (void)
{
panel_profile_settings_load();
panel_profile_load_list (profile_settings,
PANEL_GSETTINGS_TOPLEVELS,
(PanelProfileLoadFunc)panel_profile_load_and_show_toplevel_startup,
G_CALLBACK (panel_profile_toplevel_id_list_notify));
panel_profile_load_list (profile_settings,
PANEL_GSETTINGS_OBJECTS,
(PanelProfileLoadFunc)panel_profile_load_object,
G_CALLBACK (panel_profile_object_id_list_notify));
panel_profile_ensure_toplevel_per_screen ();
mate_panel_applet_load_queued_applets (TRUE);
}
static gboolean
get_program_listing_setting (const char *key)
{
gboolean retval;
retval = g_settings_get_boolean (profile_settings, key);
return retval;
}
gboolean
panel_profile_get_show_program_list (void)
{
return get_program_listing_setting ("show-program-list");
}
gboolean
panel_profile_get_enable_program_list (void)
{
return get_program_listing_setting ("enable-program-list");
}
gboolean
panel_profile_get_enable_autocompletion (void)
{
return get_program_listing_setting ("enable-autocompletion");
}
void
panel_profile_set_show_program_list (gboolean show_program_list)
{
g_settings_set_boolean (profile_settings, "show-program-list", show_program_list);
}
gboolean
panel_profile_is_writable_show_program_list (void)
{
return g_settings_is_writable (profile_settings, "show-program-list");
}
gboolean
panel_profile_can_be_moved_freely (PanelToplevel *toplevel)
{
if (panel_lockdown_get_locked_down () ||
!g_settings_is_writable (toplevel->settings, PANEL_TOPLEVEL_ORIENTATION_KEY))
return FALSE;
if (!g_settings_is_writable (toplevel->settings, PANEL_TOPLEVEL_SCREEN_KEY))
return FALSE;
if (!g_settings_is_writable (toplevel->settings, PANEL_TOPLEVEL_MONITOR_KEY))
return FALSE;
/* For expanded panels we don't really have to check
x and y */
if (panel_toplevel_get_expand (toplevel))
return TRUE;
if (!g_settings_is_writable (toplevel->settings, PANEL_TOPLEVEL_X_KEY))
return FALSE;
if (!g_settings_is_writable (toplevel->settings, PANEL_TOPLEVEL_X_RIGHT_KEY))
return FALSE;
if (!g_settings_is_writable (toplevel->settings, PANEL_TOPLEVEL_X_CENTERED_KEY))
return FALSE;
if (!g_settings_is_writable (toplevel->settings, PANEL_TOPLEVEL_Y_KEY))
return FALSE;
if (!g_settings_is_writable (toplevel->settings, PANEL_TOPLEVEL_Y_BOTTOM_KEY))
return FALSE;
if (!g_settings_is_writable (toplevel->settings, PANEL_TOPLEVEL_Y_CENTERED_KEY))
return FALSE;
return TRUE;
}
|