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
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* panel-toplevel.c: The panel's toplevel window object.
*
* Copyright (C) 2003 Sun Microsystems, Inc.
* Copyright (C) 2004 Rob Adams
*
* 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 "panel-toplevel.h"
#include <stdlib.h>
#include <string.h>
#include <ctk/ctk.h>
#include <cdk/cdkkeysyms.h>
#include <glib/gi18n.h>
#ifdef HAVE_X11
#include <cdk/cdkx.h>
#endif
#include "panel-util.h"
#include "panel-profile.h"
#include "panel-frame.h"
#include "panel-multimonitor.h"
#include "panel-a11y.h"
#include "panel-typebuiltins.h"
#include "panel-marshal.h"
#include "panel-widget.h"
#include "panel-bindings.h"
#include "panel-config-global.h"
#include "panel-lockdown.h"
#include "panel-schemas.h"
#ifdef HAVE_X11
#include "xstuff.h"
#include "panel-xutils.h"
#include "panel-struts.h"
#endif
#ifdef HAVE_WAYLAND
#include "wayland-backend.h"
#endif
#define DEFAULT_SIZE 48
#define DEFAULT_AUTO_HIDE_SIZE 1
#define DEFAULT_HIDE_DELAY 300
#define DEFAULT_UNHIDE_DELAY 100
#define DEFAULT_DND_THRESHOLD 8
#define MINIMUM_WIDTH 100
#define MAXIMUM_SIZE_SCREEN_RATIO 5
#define SNAP_TOLERANCE_FACTOR 6
#define DEFAULT_ARROW_SIZE 20
#define HANDLE_SIZE 10
#define N_ATTACH_TOPLEVEL_SIGNALS 5
#define N_ATTACH_WIDGET_SIGNALS 5
typedef enum {
PANEL_GRAB_OP_NONE,
PANEL_GRAB_OP_MOVE,
PANEL_GRAB_OP_RESIZE,
PANEL_GRAB_OP_RESIZE_UP,
PANEL_GRAB_OP_RESIZE_DOWN,
PANEL_GRAB_OP_RESIZE_LEFT,
PANEL_GRAB_OP_RESIZE_RIGHT
} PanelGrabOpType;
struct _PanelToplevelPrivate {
gchar *settings_path;
gboolean expand;
PanelOrientation orientation;
int size;
gint scale;
/* relative to the monitor origin */
int x;
int y;
/* relative to the bottom right corner, -1 to ignore and use x, y*/
int x_right;
int y_bottom;
int monitor;
/* this is used when the configured monitor is missing. We keep it so
* we can move the toplevel to the right monitor when it becomes
* available */
int configured_monitor;
int hide_delay;
int unhide_delay;
int auto_hide_size;
PanelAnimationSpeed animation_speed;
int snap_tolerance;
CtkSettings *ctk_settings;
PanelState state;
char *name;
char *description;
guint hide_timeout;
guint unhide_timeout;
CdkRectangle geometry;
PanelFrameEdge edges;
int original_width;
int original_height;
PanelGrabOpType grab_op;
/* The offset within the panel from which the panel
* drag was initiated relative to the screen origin.
*/
int drag_offset_x;
int drag_offset_y;
/* Saved state before for cancelled grab op */
int orig_monitor;
int orig_x;
int orig_y;
int orig_x_right;
int orig_y_bottom;
int orig_size;
int orig_orientation;
/* relative to the monitor origin */
int animation_end_x;
int animation_end_y;
int animation_end_width;
int animation_end_height;
GTimeVal animation_start_time;
GTimeVal animation_end_time;
guint animation_timeout;
PanelWidget *panel_widget;
PanelFrame *inner_frame;
CtkWidget *grid;
CtkWidget *hide_button_top;
CtkWidget *hide_button_bottom;
CtkWidget *hide_button_left;
CtkWidget *hide_button_right;
PanelToplevel *attach_toplevel;
gulong attach_toplevel_signals [N_ATTACH_TOPLEVEL_SIGNALS];
CtkWidget *attach_widget;
gulong attach_widget_signals [N_ATTACH_WIDGET_SIGNALS];
gint n_autohide_disablers;
guint auto_hide : 1;
guint anicafe : 1;
guint buttons_enabled : 1;
guint arrows_enabled : 1;
/* The co-ordinates are relative to center screen */
guint x_centered : 1;
guint y_centered : 1;
/* The panel is not lined up with th screen edge */
guint floating : 1;
/* We are currently animating a hide/show */
guint animating : 1;
/* This is a keyboard initiated grab operation */
guint grab_is_keyboard : 1;
/* The x-y co-ordinates temporarily specify the panel center.
* This is used when the panel is rotating, because the width/height
* of the toplevel might change, so we need to compute new values for
* those. */
guint position_centered : 1;
/* The toplevel is "attached" to another widget */
guint attached : 1;
/* Hidden temporarily because the attach_toplevel was hidden */
guint attach_hidden : 1;
/* More saved grab op state */
guint orig_x_centered : 1;
guint orig_y_centered : 1;
/* flag to see if we have already done geometry updating,
if not then we're still loading and can ignore many things */
guint updated_geometry_initial : 1;
/* flag to see if we have done the initial animation */
guint initial_animation_done : 1;
};
enum {
HIDE_SIGNAL,
UNHIDE_SIGNAL,
POPUP_PANEL_MENU_SIGNAL,
TOGGLE_EXPAND_SIGNAL,
EXPAND_SIGNAL,
UNEXPAND_SIGNAL,
TOGGLE_HIDDEN_SIGNAL,
BEGIN_MOVE_SIGNAL,
BEGIN_RESIZE_SIGNAL,
LAST_SIGNAL
};
enum {
PROP_0,
PROP_NAME,
PROP_SETTINGS_PATH,
PROP_EXPAND,
PROP_ORIENTATION,
PROP_SIZE,
PROP_X,
PROP_X_RIGHT,
PROP_X_CENTERED,
PROP_Y,
PROP_Y_BOTTOM,
PROP_Y_CENTERED,
PROP_MONITOR,
PROP_AUTOHIDE,
PROP_HIDE_DELAY,
PROP_UNHIDE_DELAY,
PROP_AUTOHIDE_SIZE,
PROP_ANICAFE,
PROP_ANIMATION_SPEED,
PROP_BUTTONS_ENABLED,
PROP_ARROWS_ENABLED
};
G_DEFINE_TYPE_WITH_PRIVATE (PanelToplevel, panel_toplevel, CTK_TYPE_WINDOW)<--- There is an unknown macro here somewhere. Configuration is required. If G_DEFINE_TYPE_WITH_PRIVATE is a macro then please configure it.
static guint toplevel_signals[LAST_SIGNAL] = {0};
static GSList* toplevel_list = NULL;
static void panel_toplevel_calculate_animation_end_geometry(PanelToplevel *toplevel);
static void panel_toplevel_update_monitor(PanelToplevel* toplevel);
static void panel_toplevel_set_monitor_internal(PanelToplevel* toplevel, int monitor, gboolean force_resize);
static void panel_toplevel_drag_threshold_changed (PanelToplevel *toplevel);
static void
update_style_classes (PanelToplevel *toplevel)
{
CtkStyleContext *context;
context = ctk_widget_get_style_context (CTK_WIDGET (toplevel));
/*ensure the panel BG can always be themed*/
/*Without this ctk3.19/20 cannot set the BG color and resetting the bg to system is not immediately applied*/
ctk_style_context_add_class(context,"gnome-panel-menu-bar");
ctk_style_context_add_class(context,"cafe-panel-menu-bar");
ctk_style_context_remove_class (context, CTK_STYLE_CLASS_HORIZONTAL);
ctk_style_context_remove_class (context, CTK_STYLE_CLASS_VERTICAL);
ctk_style_context_remove_class (context, CTK_STYLE_CLASS_RIGHT);
ctk_style_context_remove_class (context, CTK_STYLE_CLASS_LEFT);
ctk_style_context_remove_class (context, CTK_STYLE_CLASS_TOP);
ctk_style_context_remove_class (context, CTK_STYLE_CLASS_BOTTOM);
switch (toplevel->priv->orientation) {
case PANEL_ORIENTATION_TOP:
ctk_style_context_add_class (context, CTK_STYLE_CLASS_HORIZONTAL);
ctk_style_context_add_class (context, CTK_STYLE_CLASS_TOP);
break;
case PANEL_ORIENTATION_LEFT:
ctk_style_context_add_class (context, CTK_STYLE_CLASS_VERTICAL);
ctk_style_context_add_class (context, CTK_STYLE_CLASS_LEFT);
break;
case PANEL_ORIENTATION_BOTTOM:
ctk_style_context_add_class (context, CTK_STYLE_CLASS_HORIZONTAL);
ctk_style_context_add_class (context, CTK_STYLE_CLASS_BOTTOM);
break;
case PANEL_ORIENTATION_RIGHT:
ctk_style_context_add_class (context, CTK_STYLE_CLASS_VERTICAL);
ctk_style_context_add_class (context, CTK_STYLE_CLASS_RIGHT);
break;
default:
g_assert_not_reached ();
break;
}
}
GSList* panel_toplevel_list_toplevels(void)
{
return toplevel_list;
}
/* Is this the last un-attached toplevel? */
gboolean panel_toplevel_is_last_unattached(PanelToplevel* toplevel)
{
GSList* l;
if (panel_toplevel_get_is_attached(toplevel))
{
return FALSE;
}
for (l = toplevel_list; l; l = l->next)
{
PanelToplevel* t = l->data;
if (t != toplevel && !panel_toplevel_get_is_attached(t))
{
return FALSE;
}
}
return TRUE;
}
static void panel_toplevel_get_monitor_geometry(PanelToplevel* toplevel, CdkRectangle *geom)
{
g_return_if_fail(PANEL_IS_TOPLEVEL(toplevel));
g_return_if_fail(geom);
geom->x = panel_multimonitor_x(toplevel->priv->monitor);
geom->y = panel_multimonitor_y(toplevel->priv->monitor);
geom->width = panel_multimonitor_width(toplevel->priv->monitor);
geom->height = panel_multimonitor_height(toplevel->priv->monitor);
}
static CdkCursorType panel_toplevel_grab_op_cursor(PanelToplevel* toplevel, PanelGrabOpType grab_op)
{
CdkCursorType retval = -1;
switch (grab_op) {
case PANEL_GRAB_OP_MOVE:
case PANEL_GRAB_OP_RESIZE:
if (toplevel->priv->grab_is_keyboard)
retval = CDK_CROSS;
else
retval = CDK_FLEUR;
break;
case PANEL_GRAB_OP_RESIZE_UP:
retval = CDK_TOP_SIDE;
break;
case PANEL_GRAB_OP_RESIZE_DOWN:
retval = CDK_BOTTOM_SIDE;
break;
case PANEL_GRAB_OP_RESIZE_LEFT:
retval = CDK_LEFT_SIDE;
break;
case PANEL_GRAB_OP_RESIZE_RIGHT:
retval = CDK_RIGHT_SIDE;
break;
default:
g_assert_not_reached ();
break;
}
return retval;
}
#ifdef HAVE_X11
static void panel_toplevel_init_resize_drag_offsets(PanelToplevel* toplevel, PanelGrabOpType grab_op)
{
g_assert (CDK_IS_X11_DISPLAY (ctk_widget_get_display (CTK_WIDGET (toplevel))));
toplevel->priv->drag_offset_x = 0;
toplevel->priv->drag_offset_y = 0;
switch (grab_op) {
case PANEL_GRAB_OP_RESIZE_DOWN:
toplevel->priv->drag_offset_y = toplevel->priv->geometry.y;
break;
case PANEL_GRAB_OP_RESIZE_UP:
toplevel->priv->drag_offset_y =
toplevel->priv->geometry.y + toplevel->priv->geometry.height;
break;
case PANEL_GRAB_OP_RESIZE_RIGHT:
toplevel->priv->drag_offset_x = toplevel->priv->geometry.x;
break;
case PANEL_GRAB_OP_RESIZE_LEFT:
toplevel->priv->drag_offset_x =
toplevel->priv->geometry.x + toplevel->priv->geometry.width;
break;
default:
g_assert_not_reached ();
break;
}
}
static void panel_toplevel_warp_pointer(PanelToplevel* toplevel)
{
CtkWidget *widget;
CdkRectangle geometry;
int x, y;
widget = CTK_WIDGET (toplevel);
g_return_if_fail (CDK_IS_X11_DISPLAY (ctk_widget_get_display (widget)));
geometry = toplevel->priv->geometry;
x = y = 0;
switch (toplevel->priv->grab_op) {
case PANEL_GRAB_OP_MOVE:
case PANEL_GRAB_OP_RESIZE:
x = (geometry.width / 2);
y = (geometry.height / 2);
break;
case PANEL_GRAB_OP_RESIZE_UP:
x = (geometry.width / 2);
break;
case PANEL_GRAB_OP_RESIZE_DOWN:
x = (geometry.width / 2);
y = geometry.height;
break;
case PANEL_GRAB_OP_RESIZE_LEFT:
y = (geometry.height / 2);
break;
case PANEL_GRAB_OP_RESIZE_RIGHT:
x = geometry.width;
y = (geometry.height / 2);
break;
default:
g_assert_not_reached ();
break;
}
if (toplevel->priv->grab_op == PANEL_GRAB_OP_MOVE ||
toplevel->priv->grab_op == PANEL_GRAB_OP_RESIZE) {
toplevel->priv->drag_offset_x = x;
toplevel->priv->drag_offset_y = y;
} else
panel_toplevel_init_resize_drag_offsets (toplevel, toplevel->priv->grab_op);
panel_warp_pointer (ctk_widget_get_window (widget), x, y);
}
#endif // HAVE_X11
static void panel_toplevel_begin_attached_move(PanelToplevel* toplevel, gboolean is_keyboard, guint32 time_)
{
PanelWidget *attached_panel_widget;
attached_panel_widget = panel_toplevel_get_panel_widget (toplevel->priv->attach_toplevel);
panel_widget_applet_drag_start (attached_panel_widget,
toplevel->priv->attach_widget,
is_keyboard ? PW_DRAG_OFF_CENTER : PW_DRAG_OFF_CURSOR,
time_);
}
static void panel_toplevel_begin_grab_op(PanelToplevel* toplevel, PanelGrabOpType op_type, gboolean grab_keyboard, guint32 time_)
{
CtkWidget *widget;
CdkWindow *window;
CdkCursorType cursor_type;
CdkCursor *cursor;
CdkDisplay *display;
CdkSeat *seat;
CdkSeatCapabilities capabilities;
if (toplevel->priv->state != PANEL_STATE_NORMAL ||
toplevel->priv->grab_op != PANEL_GRAB_OP_NONE)
return;
if (panel_lockdown_get_locked_down ())
return;
/* If any of the position/orientation are not writable,
then we can't really move freely */
if (op_type == PANEL_GRAB_OP_MOVE &&
! panel_profile_can_be_moved_freely (toplevel))
return;
/* If size is not writable, then we can't resize */
if ((op_type == PANEL_GRAB_OP_RESIZE ||
op_type == PANEL_GRAB_OP_RESIZE_UP ||
op_type == PANEL_GRAB_OP_RESIZE_DOWN ||
op_type == PANEL_GRAB_OP_RESIZE_LEFT ||
op_type == PANEL_GRAB_OP_RESIZE_RIGHT) &&
! panel_profile_key_is_writable (toplevel, PANEL_TOPLEVEL_SIZE_KEY))
return;
if (toplevel->priv->attached && op_type == PANEL_GRAB_OP_MOVE) {
panel_toplevel_begin_attached_move (toplevel, grab_keyboard, time_);
return;
}
widget = CTK_WIDGET (toplevel);
window = ctk_widget_get_window (widget);
toplevel->priv->grab_op = op_type;
toplevel->priv->grab_is_keyboard = grab_keyboard;
toplevel->priv->orig_monitor = toplevel->priv->monitor;
toplevel->priv->orig_x = toplevel->priv->x;
toplevel->priv->orig_x_right = toplevel->priv->x_right;
toplevel->priv->orig_x_centered = toplevel->priv->x_centered;
toplevel->priv->orig_y = toplevel->priv->y;
toplevel->priv->orig_y_bottom = toplevel->priv->y_bottom;
toplevel->priv->orig_y_centered = toplevel->priv->y_centered;
toplevel->priv->orig_size = toplevel->priv->size;
toplevel->priv->orig_orientation = toplevel->priv->orientation;
ctk_grab_add (widget);
#ifdef HAVE_X11
if (CDK_IS_X11_DISPLAY (ctk_widget_get_display (widget)) &&
toplevel->priv->grab_is_keyboard) {
panel_toplevel_warp_pointer (toplevel);
}
#endif // HAVE_X11
cursor_type = panel_toplevel_grab_op_cursor (
toplevel, toplevel->priv->grab_op);
cursor = cdk_cursor_new_for_display (cdk_display_get_default (),
cursor_type);
display = cdk_window_get_display (window);
seat = cdk_display_get_default_seat (display);
capabilities = CDK_SEAT_CAPABILITY_POINTER;
if (grab_keyboard)
capabilities |= CDK_SEAT_CAPABILITY_KEYBOARD;
cdk_seat_grab (seat, window, capabilities, FALSE, cursor,
NULL, NULL, NULL);
g_object_unref (cursor);
}
static void panel_toplevel_end_grab_op (PanelToplevel* toplevel, guint32 time_)
{
CtkWidget *widget;
CdkDisplay *display;
CdkSeat *seat;
g_return_if_fail (toplevel->priv->grab_op != PANEL_GRAB_OP_NONE);
widget = CTK_WIDGET (toplevel);
toplevel->priv->grab_op = PANEL_GRAB_OP_NONE;
toplevel->priv->grab_is_keyboard = FALSE;
ctk_grab_remove (widget);
display = ctk_widget_get_display (widget);
seat = cdk_display_get_default_seat (display);
cdk_seat_ungrab (seat);
}
static void panel_toplevel_cancel_grab_op(PanelToplevel* toplevel, guint32 time_)
{
panel_toplevel_set_orientation (toplevel, toplevel->priv->orig_orientation);
panel_toplevel_set_monitor (toplevel, toplevel->priv->orig_monitor);
panel_toplevel_set_size (toplevel, toplevel->priv->orig_size);
panel_toplevel_set_x (toplevel,
toplevel->priv->orig_x,
toplevel->priv->orig_x_right,
toplevel->priv->orig_x_centered);
panel_toplevel_set_y (toplevel,
toplevel->priv->orig_y,
toplevel->priv->orig_y_bottom,
toplevel->priv->orig_y_centered);
}
static void panel_toplevel_resize_to_pointer(PanelToplevel* toplevel, int x, int y)
{
int new_size;
int new_x, new_y;
int new_x_right, new_y_bottom;
int new_x_centered, new_y_centered;
CdkRectangle monitor_geom;
new_size = toplevel->priv->size;
new_x = toplevel->priv->x;
new_y = toplevel->priv->y;
new_x_right = toplevel->priv->x_right;
new_y_bottom = toplevel->priv->y_bottom;
new_x_centered = toplevel->priv->x_centered;
new_y_centered = toplevel->priv->y_centered;
panel_toplevel_get_monitor_geometry (toplevel, &monitor_geom);
switch (toplevel->priv->grab_op) {
case PANEL_GRAB_OP_RESIZE_UP:
new_size = toplevel->priv->drag_offset_y - y;
new_size = CLAMP (new_size, 0, monitor_geom.height / 4);
new_y -= (new_size - toplevel->priv->size);
if (!toplevel->priv->y_centered && (new_y + new_size / 2) > monitor_geom.height / 2)
new_y_bottom = monitor_geom.height - (new_y + new_size);
else
new_y_bottom = -1;
break;
case PANEL_GRAB_OP_RESIZE_DOWN:
new_size = y - toplevel->priv->drag_offset_y;
new_size = CLAMP (new_size, 0, monitor_geom.height / 4);
if (!toplevel->priv->y_centered && (new_y + new_size / 2) > monitor_geom.height / 2)
new_y_bottom = monitor_geom.height - (new_y + new_size);
else
new_y_bottom = -1;
break;
case PANEL_GRAB_OP_RESIZE_LEFT:
new_size = toplevel->priv->drag_offset_x - x;
new_size = CLAMP (new_size, 0, monitor_geom.width / 4);
new_x -= (new_size - toplevel->priv->size);
if (!toplevel->priv->x_centered && (new_x + new_size / 2) > monitor_geom.width / 2)
new_x_right = monitor_geom.width - (new_x + new_size);
else
new_x_right = -1;
break;
case PANEL_GRAB_OP_RESIZE_RIGHT:
new_size = x - toplevel->priv->drag_offset_x;
new_size = CLAMP (new_size, 0, monitor_geom.width / 4);
if (!toplevel->priv->x_centered && (new_x + new_size / 2) > monitor_geom.width / 2)
new_x_right = monitor_geom.width - (new_x + new_size);
else
new_x_right = -1;
break;
default:
g_assert_not_reached ();
break;
}
if (new_size == 0)
return;
panel_toplevel_set_x (toplevel, new_x, new_x_right, new_x_centered);
panel_toplevel_set_y (toplevel, new_y, new_y_bottom, new_y_centered);
panel_toplevel_set_size (toplevel, new_size);
}
/* this is called for expanded panels that are dragged around */
static void panel_toplevel_calc_new_orientation(PanelToplevel* toplevel, int pointer_x, int pointer_y)
{
PanelOrientation new_orientation;
int hborder, vborder;
int monitor;
int monitor_width, monitor_height;
int new_x, new_y;
monitor = panel_multimonitor_get_monitor_at_point (pointer_x, pointer_y);
if (toplevel->priv->geometry.height < toplevel->priv->geometry.width)
vborder = hborder = (3 * toplevel->priv->geometry.height) >> 1;
else
vborder = hborder = (3 * toplevel->priv->geometry.width) >> 1;
new_x = pointer_x - panel_multimonitor_x (monitor);
new_y = pointer_y - panel_multimonitor_y (monitor);
monitor_width = panel_multimonitor_width (monitor);
monitor_height = panel_multimonitor_height (monitor);
new_orientation = toplevel->priv->orientation;
switch (toplevel->priv->orientation) {
case PANEL_ORIENTATION_TOP:
if (new_y > (monitor_height - hborder))
new_orientation = PANEL_ORIENTATION_BOTTOM;
else if (new_y > hborder) {
if (new_x > (monitor_width - vborder))
new_orientation = PANEL_ORIENTATION_RIGHT;
else if (new_x < vborder)
new_orientation = PANEL_ORIENTATION_LEFT;
}
break;
case PANEL_ORIENTATION_BOTTOM:
if (new_y < hborder)
new_orientation = PANEL_ORIENTATION_TOP;
else if (new_y < (monitor_height - hborder)) {
if (new_x > (monitor_width - vborder))
new_orientation = PANEL_ORIENTATION_RIGHT;
else if (new_x < vborder)
new_orientation = PANEL_ORIENTATION_LEFT;
}
break;
case PANEL_ORIENTATION_LEFT:
if (new_x > (monitor_width - vborder))
new_orientation = PANEL_ORIENTATION_RIGHT;
else if (new_x > vborder) {
if (new_y > (monitor_height - hborder))
new_orientation = PANEL_ORIENTATION_BOTTOM;
else if (new_y < hborder)
new_orientation = PANEL_ORIENTATION_TOP;
}
break;
case PANEL_ORIENTATION_RIGHT:
if (new_x < vborder)
new_orientation = PANEL_ORIENTATION_LEFT;
else if (new_x < (monitor_width - vborder)) {
if (new_y > (monitor_height - hborder))
new_orientation = PANEL_ORIENTATION_BOTTOM;
else if (new_y < hborder)
new_orientation = PANEL_ORIENTATION_TOP;
}
break;
default:
g_assert_not_reached ();
break;
}
panel_toplevel_set_monitor (toplevel, monitor);
panel_toplevel_set_orientation (toplevel, new_orientation);
}
static void panel_toplevel_move_to(PanelToplevel* toplevel, int new_x, int new_y)
{
PanelOrientation new_orientation;
gboolean x_centered, y_centered;
CdkPoint display_min, display_max;
CdkRectangle monitor_geom;
int width, height;
int new_monitor;
int x, y, x_right, y_bottom;
int snap_tolerance;
panel_multimonitor_get_bounds (&display_min, &display_max);
width = toplevel->priv->geometry.width;
height = toplevel->priv->geometry.height;
snap_tolerance = toplevel->priv->snap_tolerance;
new_x = CLAMP (new_x, 0, display_max.x - width);
new_y = CLAMP (new_y, 0, display_max.y - height);
new_orientation = toplevel->priv->orientation;
if (new_x <= (display_min.x + snap_tolerance) &&
toplevel->priv->orientation & PANEL_VERTICAL_MASK)
new_orientation = PANEL_ORIENTATION_LEFT;
else if ((new_x + width) >= (display_max.x - snap_tolerance) &&
toplevel->priv->orientation & PANEL_VERTICAL_MASK)
new_orientation = PANEL_ORIENTATION_RIGHT;
if (new_y <= (display_min.y + snap_tolerance) &&
toplevel->priv->orientation & PANEL_HORIZONTAL_MASK)
new_orientation = PANEL_ORIENTATION_TOP;
else if ((new_y + height) >= (display_max.y - snap_tolerance) &&
toplevel->priv->orientation & PANEL_HORIZONTAL_MASK)
new_orientation = PANEL_ORIENTATION_BOTTOM;
new_monitor = panel_multimonitor_get_monitor_at_point (new_x, new_y);
panel_toplevel_get_monitor_geometry (toplevel, &monitor_geom);
x_centered = toplevel->priv->x_centered;
y_centered = toplevel->priv->y_centered;
x = new_x - panel_multimonitor_x (new_monitor);
y = new_y - panel_multimonitor_y (new_monitor);
if (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK) {
y_centered = FALSE;
if (new_y <= display_min.y + snap_tolerance ||
new_y + height >= display_max.y - snap_tolerance)
x_centered = abs (x - ((monitor_geom.width - width) / 2))
<= snap_tolerance;
else
x_centered = FALSE;
} else {
x_centered = FALSE;
if (new_x <= display_min.x + snap_tolerance ||
new_x + width >= display_max.x - snap_tolerance)
y_centered = abs (y - ((monitor_geom.height - height) / 2))
<= snap_tolerance;
else
y_centered = FALSE;
}
if (x_centered)
x = (monitor_geom.width - width) / 2;
if (y_centered)
y = (monitor_geom.height - height) / 2;
if (!x_centered && (x + width / 2) > monitor_geom.width / 2)
x_right = monitor_geom.width - (x + width);
else
x_right = -1;
if (!y_centered && (y + height / 2) > monitor_geom.height / 2)
y_bottom = monitor_geom.height - (y + height);
else
y_bottom = -1;
panel_toplevel_set_monitor (toplevel, new_monitor);
panel_toplevel_set_orientation (toplevel, new_orientation);
panel_toplevel_set_x (toplevel, x, x_right, x_centered);
panel_toplevel_set_y (toplevel, y, y_bottom, y_centered);
}
static void panel_toplevel_move_to_pointer(PanelToplevel* toplevel, int pointer_x, int pointer_y)
{
int new_x, new_y;
new_x = pointer_x - toplevel->priv->drag_offset_x;
new_y = pointer_y - toplevel->priv->drag_offset_y;
panel_toplevel_move_to (toplevel, new_x, new_y);
}
static void panel_toplevel_rotate_to_pointer(PanelToplevel* toplevel, int pointer_x, int pointer_y)
{
int x_diff, y_diff;
int x, y;
int snap_tolerance;
x = toplevel->priv->geometry.x;
y = toplevel->priv->geometry.y;
snap_tolerance = toplevel->priv->snap_tolerance;
x_diff = pointer_x - (x + toplevel->priv->geometry.width / 2);
y_diff = pointer_y - (y + toplevel->priv->geometry.height / 2);
if (((-y_diff > x_diff + snap_tolerance) && x_diff > 0 && y_diff < 0) ||
(( y_diff < x_diff + snap_tolerance) && x_diff < 0 && y_diff < 0))
panel_toplevel_set_orientation (toplevel, PANEL_ORIENTATION_RIGHT);
else if (((-x_diff < y_diff - snap_tolerance) && x_diff > 0 && y_diff < 0) ||
(( x_diff > y_diff - snap_tolerance) && x_diff > 0 && y_diff > 0))
panel_toplevel_set_orientation (toplevel, PANEL_ORIENTATION_BOTTOM);
else if ((( y_diff > x_diff + snap_tolerance) && x_diff > 0 && y_diff > 0) ||
((-y_diff < x_diff + snap_tolerance) && x_diff < 0 && y_diff > 0))
panel_toplevel_set_orientation (toplevel, PANEL_ORIENTATION_LEFT);
else if (((-x_diff > y_diff - snap_tolerance) && x_diff < 0 && y_diff > 0) ||
(( x_diff < y_diff - snap_tolerance) && x_diff < 0 && y_diff < 0))
panel_toplevel_set_orientation (toplevel, PANEL_ORIENTATION_TOP);
}
#ifdef HAVE_X11
static gboolean panel_toplevel_warp_pointer_increment(PanelToplevel* toplevel, int keyval, int increment)
{
CdkScreen *screen;
CdkWindow *root_window;
CdkDevice *device;
int new_x, new_y;
screen = ctk_window_get_screen (CTK_WINDOW (toplevel));
g_return_val_if_fail (CDK_IS_X11_SCREEN (screen), FALSE);
root_window = cdk_screen_get_root_window (screen);
device = cdk_seat_get_pointer (cdk_display_get_default_seat (ctk_widget_get_display (CTK_WIDGET(root_window))));
cdk_window_get_device_position (ctk_widget_get_window (CTK_WIDGET (root_window)), device, &new_x, &new_y, NULL);
switch (keyval) {
case CDK_KEY_Up:
case CDK_KEY_KP_Up:
new_y -= increment;
break;
case CDK_KEY_Left:
case CDK_KEY_KP_Left:
new_x -= increment;
break;
case CDK_KEY_Down:
case CDK_KEY_KP_Down:
new_y += increment;
break;
case CDK_KEY_Right:
case CDK_KEY_KP_Right:
new_x += increment;
break;
default:
g_assert_not_reached ();
return FALSE;
}
panel_warp_pointer (root_window, new_x, new_y);
return TRUE;
}
static gboolean panel_toplevel_move_keyboard_floating(PanelToplevel* toplevel, CdkEventKey* event)
{
#define SMALL_INCREMENT 1
#define NORMAL_INCREMENT 10
int increment = NORMAL_INCREMENT;
if ((event->state & ctk_accelerator_get_default_mod_mask ()) == CDK_SHIFT_MASK)
increment = SMALL_INCREMENT;
return panel_toplevel_warp_pointer_increment (
toplevel, event->keyval, increment);
#undef SMALL_INCREMENT
#undef NORMAL_INCREMENT
}
#endif // HAVE_X11
static gboolean panel_toplevel_move_keyboard_expanded(PanelToplevel* toplevel, CdkEventKey* event)
{
PanelOrientation new_orientation;
switch (event->keyval) {
case CDK_KEY_Up:
case CDK_KEY_KP_Up:
new_orientation = PANEL_ORIENTATION_TOP;
break;
case CDK_KEY_Left:
case CDK_KEY_KP_Left:
new_orientation = PANEL_ORIENTATION_LEFT;
break;
case CDK_KEY_Down:
case CDK_KEY_KP_Down:
new_orientation = PANEL_ORIENTATION_BOTTOM;
break;
case CDK_KEY_Right:
case CDK_KEY_KP_Right:
new_orientation = PANEL_ORIENTATION_RIGHT;
break;
default:
g_assert_not_reached ();
return FALSE;
}
panel_toplevel_set_orientation (toplevel, new_orientation);
return TRUE;
}
static gboolean panel_toplevel_initial_resize_keypress(PanelToplevel* toplevel, CdkEventKey* event)
{
PanelGrabOpType grab_op;
switch (event->keyval) {
case CDK_KEY_Up:
case CDK_KEY_KP_Up:
if (!(toplevel->priv->orientation & PANEL_HORIZONTAL_MASK))
return FALSE;
grab_op = PANEL_GRAB_OP_RESIZE_UP;
break;
case CDK_KEY_Left:
case CDK_KEY_KP_Left:
if (!(toplevel->priv->orientation & PANEL_VERTICAL_MASK))
return FALSE;
grab_op = PANEL_GRAB_OP_RESIZE_LEFT;
break;
case CDK_KEY_Down:
case CDK_KEY_KP_Down:
if (!(toplevel->priv->orientation & PANEL_HORIZONTAL_MASK))
return FALSE;
grab_op = PANEL_GRAB_OP_RESIZE_DOWN;
break;
case CDK_KEY_Right:
case CDK_KEY_KP_Right:
if (!(toplevel->priv->orientation & PANEL_VERTICAL_MASK))
return FALSE;
grab_op = PANEL_GRAB_OP_RESIZE_RIGHT;
break;
default:
g_assert_not_reached ();
return FALSE;
}
panel_toplevel_end_grab_op (toplevel, event->time);
panel_toplevel_begin_grab_op (toplevel, grab_op, TRUE, event->time);
return TRUE;
}
static gboolean panel_toplevel_handle_grab_op_key_event(PanelToplevel* toplevel, CdkEventKey* event)
{
gboolean retval = FALSE;
switch (event->keyval) {
case CDK_KEY_Up:
case CDK_KEY_KP_Up:
case CDK_KEY_Left:
case CDK_KEY_KP_Left:
case CDK_KEY_Down:
case CDK_KEY_KP_Down:
case CDK_KEY_Right:
case CDK_KEY_KP_Right:
switch (toplevel->priv->grab_op) {
case PANEL_GRAB_OP_MOVE:
if (toplevel->priv->expand) {
retval = panel_toplevel_move_keyboard_expanded (
toplevel, event);
}
#ifdef HAVE_X11
else if (CDK_IS_X11_DISPLAY (ctk_widget_get_display (CTK_WIDGET (toplevel)))) {
retval = panel_toplevel_move_keyboard_floating (
toplevel, event);
}
#endif // HAVE_X11
break;
case PANEL_GRAB_OP_RESIZE:
retval = panel_toplevel_initial_resize_keypress (toplevel, event);
break;
case PANEL_GRAB_OP_RESIZE_UP:
case PANEL_GRAB_OP_RESIZE_DOWN:
case PANEL_GRAB_OP_RESIZE_LEFT:
case PANEL_GRAB_OP_RESIZE_RIGHT:
#ifdef HAVE_X11
if (CDK_IS_X11_DISPLAY (ctk_widget_get_display (CTK_WIDGET (toplevel))))
retval = panel_toplevel_warp_pointer_increment (toplevel, event->keyval, 1);
#endif // HAVE_X11
break;
default:
g_assert_not_reached ();
break;
}
break;
case CDK_KEY_Escape:
panel_toplevel_cancel_grab_op (toplevel, event->time);
case CDK_KEY_Return: /* drop through*/
case CDK_KEY_KP_Enter:
case CDK_KEY_space:
case CDK_KEY_KP_Space:
panel_toplevel_end_grab_op (toplevel, event->time);
retval = TRUE;
default: /* drop through*/
break;
}
return retval;
}
static gboolean panel_toplevel_handle_grab_op_motion_event(PanelToplevel* toplevel, CdkEventMotion* event)
{
switch (toplevel->priv->grab_op) {
case PANEL_GRAB_OP_MOVE:
if (toplevel->priv->expand)
panel_toplevel_calc_new_orientation (
toplevel, event->x_root, event->y_root);
else if ((event->state & ctk_accelerator_get_default_mod_mask ()) == CDK_CONTROL_MASK)
panel_toplevel_rotate_to_pointer (
toplevel, event->x_root, event->y_root);
else
panel_toplevel_move_to_pointer (
toplevel, event->x_root, event->y_root);
return TRUE;
case PANEL_GRAB_OP_RESIZE_UP:
case PANEL_GRAB_OP_RESIZE_DOWN:
case PANEL_GRAB_OP_RESIZE_LEFT:
case PANEL_GRAB_OP_RESIZE_RIGHT:
panel_toplevel_resize_to_pointer (toplevel, event->x_root, event->y_root);
return TRUE;
default:
break;
}
return FALSE;
}
static void panel_toplevel_calc_floating(PanelToplevel* toplevel)
{
CdkRectangle monitor_geom;
CdkPoint position_on_monitor;
int snap_tolerance;
if (toplevel->priv->expand) {
toplevel->priv->floating = FALSE;
return;
}
panel_toplevel_get_monitor_geometry (toplevel, &monitor_geom);
if (toplevel->priv->x_right == -1)
position_on_monitor.x = toplevel->priv->x;
else
position_on_monitor.x = monitor_geom.width - (toplevel->priv->x_right + toplevel->priv->geometry.width);
if (toplevel->priv->y_bottom == -1)
position_on_monitor.y = toplevel->priv->y;
else
position_on_monitor.y = monitor_geom.height - (toplevel->priv->y_bottom + toplevel->priv->geometry.height);
snap_tolerance = toplevel->priv->snap_tolerance;
if (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK)
toplevel->priv->floating =
(position_on_monitor.y > snap_tolerance) &&
(position_on_monitor.y < (monitor_geom.height - toplevel->priv->geometry.height - snap_tolerance));
else
toplevel->priv->floating =
(position_on_monitor.x > snap_tolerance) &&
(position_on_monitor.x < (monitor_geom.width - toplevel->priv->geometry.width - snap_tolerance));
}
void panel_toplevel_push_autohide_disabler(PanelToplevel* toplevel)
{
g_return_if_fail (toplevel != NULL);
if (!toplevel->priv->n_autohide_disablers++)
panel_toplevel_queue_auto_hide (toplevel);
}
void panel_toplevel_pop_autohide_disabler(PanelToplevel* toplevel)
{
g_return_if_fail (toplevel != NULL);
g_return_if_fail (toplevel->priv->n_autohide_disablers > 0);
if (!--toplevel->priv->n_autohide_disablers)
panel_toplevel_queue_auto_hide (toplevel);
}
static gboolean panel_toplevel_get_autohide_disabled(PanelToplevel* toplevel)
{
return toplevel->priv->n_autohide_disablers > 0 ? TRUE : FALSE;
}
static gboolean panel_toplevel_hide_button_event(PanelToplevel* toplevel, CdkEventButton* event, CtkButton* button)
{
if (event->button == 1)
return FALSE;
return ctk_widget_event (CTK_WIDGET (toplevel), (CdkEvent *) event);
}
static void panel_toplevel_hide_button_clicked(PanelToplevel* toplevel, CtkButton* button)
{
CtkArrowType arrow_type;
gboolean ltr;
if (toplevel->priv->animating ||
toplevel->priv->state == PANEL_STATE_AUTO_HIDDEN)
return;
ltr = ctk_widget_get_direction (CTK_WIDGET (toplevel)) == CTK_TEXT_DIR_LTR;
arrow_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "arrow-type"));
if (toplevel->priv->state == PANEL_STATE_NORMAL) {
CtkDirectionType direction = -1;
switch (arrow_type) {
case CTK_ARROW_UP:
direction = CTK_DIR_UP;
break;
case CTK_ARROW_DOWN:
direction = CTK_DIR_DOWN;
break;
case CTK_ARROW_LEFT:
direction = ltr ? CTK_DIR_LEFT : CTK_DIR_RIGHT;
break;
case CTK_ARROW_RIGHT:
direction = ltr ? CTK_DIR_RIGHT : CTK_DIR_LEFT;
break;
default:
g_assert_not_reached ();
break;
}
panel_toplevel_hide (toplevel, FALSE, direction);
} else
panel_toplevel_unhide (toplevel);
}
static void
set_arrow_type (CtkImage *image,
CtkArrowType arrow_type)
{
switch (arrow_type)
{
case CTK_ARROW_NONE:
case CTK_ARROW_DOWN:
ctk_image_set_from_icon_name (image, "pan-down-symbolic", CTK_ICON_SIZE_BUTTON);
break;
case CTK_ARROW_UP:
ctk_image_set_from_icon_name (image, "pan-up-symbolic", CTK_ICON_SIZE_BUTTON);
break;
case CTK_ARROW_LEFT:
ctk_image_set_from_icon_name (image, "pan-start-symbolic", CTK_ICON_SIZE_BUTTON);
break;
case CTK_ARROW_RIGHT:
ctk_image_set_from_icon_name (image, "pan-end-symbolic", CTK_ICON_SIZE_BUTTON);
break;
}
}
static CtkWidget *
panel_toplevel_add_hide_button (PanelToplevel *toplevel,
CtkArrowType arrow_type,
int left,
int top)
{
CtkWidget *button;
AtkObject *obj;
CtkWidget *arrow;
button = ctk_button_new ();
obj = ctk_widget_get_accessible (button);
atk_object_set_name (obj, _("Hide Panel"));
ctk_widget_set_can_default (button, FALSE);
arrow = ctk_image_new ();
set_arrow_type (CTK_IMAGE (arrow), arrow_type);
ctk_container_add (CTK_CONTAINER (button), arrow);
ctk_widget_show (arrow);
g_object_set_data (G_OBJECT (button),
"arrow-type",
GINT_TO_POINTER (arrow_type));
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (panel_toplevel_hide_button_clicked), toplevel);
g_signal_connect_swapped (button, "button_press_event",
G_CALLBACK (panel_toplevel_hide_button_event), toplevel);
g_signal_connect_swapped (button, "button_release_event",
G_CALLBACK (panel_toplevel_hide_button_event), toplevel);
ctk_grid_attach (CTK_GRID (toplevel->priv->grid), button, left, top, 1, 1);
return button;
}
static void panel_toplevel_update_buttons_showing(PanelToplevel* toplevel)
{
if (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK) {
ctk_widget_hide (toplevel->priv->hide_button_top);
ctk_widget_hide (toplevel->priv->hide_button_bottom);
ctk_widget_show (toplevel->priv->hide_button_left);
ctk_widget_show (toplevel->priv->hide_button_right);
} else {
ctk_widget_show (toplevel->priv->hide_button_top);
ctk_widget_show (toplevel->priv->hide_button_bottom);
ctk_widget_hide (toplevel->priv->hide_button_left);
ctk_widget_hide (toplevel->priv->hide_button_right);
}
if (toplevel->priv->attached) {
switch (panel_toplevel_get_orientation (toplevel->priv->attach_toplevel)) {
case PANEL_ORIENTATION_TOP:
ctk_widget_hide (toplevel->priv->hide_button_top);
break;
case PANEL_ORIENTATION_BOTTOM:
ctk_widget_hide (toplevel->priv->hide_button_bottom);
break;
case PANEL_ORIENTATION_LEFT:
ctk_widget_hide (toplevel->priv->hide_button_left);
break;
case PANEL_ORIENTATION_RIGHT:
ctk_widget_hide (toplevel->priv->hide_button_right);
break;
default:
g_assert_not_reached ();
break;
}
}
}
/* force set hide button size on panel size < 30px */
static void panel_toplevel_update_hide_buttons_size (CtkWidget *button, int panel_size)
{
CtkCssProvider *css_provider;
CtkStyleContext *context;
CtkWidget *arrow;
CtkSettings *settings;
gchar *ctk_theme_name = NULL;
context = ctk_widget_get_style_context (button);
ctk_style_context_add_class (context, "panel-button");
/* get defaults from theme */
settings = ctk_settings_get_default ();
g_object_get (settings, "ctk-theme-name", &ctk_theme_name, NULL);
css_provider = ctk_css_provider_get_named (ctk_theme_name, NULL);
g_free (ctk_theme_name);
/* set custom css by adding our custom code to the default theme css
*
* NOTE that contriary to the documentation:
* https://developer.gnome.org/ctk3/stable/CtkCssProvider.html#ctk-css-provider-load-from-data
* the previously loaded theme is NOT cleared from the css_provider. (reason unknown)
* In other words, this works exactly, how we need it here.
* ALSO NOTE that using ctk_css_provider_to_string () to convert the theme css data into a string
* and then adding the custom css, then adding this updated css to a css_provider
* with the ctk_css_provider_load_from_data () also works,
* however some themes can't be easily converted to strings, beacuse of the binary data
* they contain. This causes a delay of minutes in loading the cafe-panel,
* and so this approach is not viable. */
if (panel_size < 30) {
ctk_css_provider_load_from_data (css_provider, ".panel-button {min-height: 13px; min-width: 13px; padding: 0px;}", -1, NULL);
}
ctk_style_context_add_provider (context, CTK_STYLE_PROVIDER (css_provider), CTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
/* get arrow image */
arrow = ctk_bin_get_child (CTK_BIN (button));
/* set image size */
if (panel_size < 20) {
ctk_image_set_pixel_size (CTK_IMAGE (arrow), 12);
} else if (panel_size < 40) {
ctk_image_set_pixel_size (CTK_IMAGE (arrow), 16);
} else if (panel_size < 60) {
ctk_image_set_pixel_size (CTK_IMAGE (arrow), 22);
} else {
ctk_image_set_pixel_size (CTK_IMAGE (arrow), 24);
}
}
static void panel_toplevel_update_hide_buttons(PanelToplevel* toplevel)
{
int panel_size = toplevel->priv->size;
int hb_size = 0;
if (toplevel->priv->buttons_enabled) {
panel_toplevel_update_buttons_showing (toplevel);
panel_toplevel_update_hide_buttons_size (toplevel->priv->hide_button_top, panel_size);
panel_toplevel_update_hide_buttons_size (toplevel->priv->hide_button_bottom, panel_size);
panel_toplevel_update_hide_buttons_size (toplevel->priv->hide_button_left, panel_size);
panel_toplevel_update_hide_buttons_size (toplevel->priv->hide_button_right, panel_size);
} else {
g_object_set (
G_OBJECT (toplevel->priv->hide_button_top),
"visible", toplevel->priv->state == PANEL_STATE_HIDDEN_DOWN,
NULL);
g_object_set (
G_OBJECT (toplevel->priv->hide_button_bottom),
"visible", toplevel->priv->state == PANEL_STATE_HIDDEN_UP,
NULL);
g_object_set (
G_OBJECT (toplevel->priv->hide_button_left),
"visible", toplevel->priv->state == PANEL_STATE_HIDDEN_RIGHT,
NULL);
g_object_set (
G_OBJECT (toplevel->priv->hide_button_right),
"visible", toplevel->priv->state == PANEL_STATE_HIDDEN_LEFT,
NULL);
}
if (toplevel->priv->arrows_enabled) {
ctk_widget_show (ctk_bin_get_child (CTK_BIN (toplevel->priv->hide_button_top)));
ctk_widget_show (ctk_bin_get_child (CTK_BIN (toplevel->priv->hide_button_bottom)));
ctk_widget_show (ctk_bin_get_child (CTK_BIN (toplevel->priv->hide_button_left)));
ctk_widget_show (ctk_bin_get_child (CTK_BIN (toplevel->priv->hide_button_right)));
} else {
ctk_widget_hide (ctk_bin_get_child (CTK_BIN (toplevel->priv->hide_button_top)));
ctk_widget_hide (ctk_bin_get_child (CTK_BIN (toplevel->priv->hide_button_bottom)));
ctk_widget_hide (ctk_bin_get_child (CTK_BIN (toplevel->priv->hide_button_left)));
ctk_widget_hide (ctk_bin_get_child (CTK_BIN (toplevel->priv->hide_button_right)));
}
/* set size after setting the arrow */
if (toplevel->priv->buttons_enabled) {
if ( panel_size < 20) { hb_size = 16; }
else if ( panel_size < 40) { hb_size = 20; }
else if ( panel_size < 60) { hb_size = 26; }
else { hb_size = 30; }
ctk_widget_set_size_request (toplevel->priv->hide_button_top, panel_size, hb_size);
ctk_widget_set_size_request (toplevel->priv->hide_button_bottom, panel_size, hb_size);
ctk_widget_set_size_request (toplevel->priv->hide_button_left, hb_size, panel_size);
ctk_widget_set_size_request (toplevel->priv->hide_button_right, hb_size, panel_size);
}
}
static gboolean panel_toplevel_contains_pointer(PanelToplevel* toplevel)
{
CdkDisplay *display;
CdkScreen *screen;
CtkWidget *widget;
CdkSeat *seat;
CdkDevice *pointer;
int x, y;
display = cdk_display_get_default ();
seat = cdk_display_get_default_seat (display);
pointer = cdk_seat_get_pointer (seat);
widget = CTK_WIDGET (toplevel);
if (!ctk_widget_get_realized (widget))
return FALSE;
screen = NULL;
x = y = -1;
cdk_device_get_position (pointer, &screen, &x, &y);
if (screen != ctk_window_get_screen (CTK_WINDOW (toplevel)))
return FALSE;
if (x == -1 || y == -1)
return FALSE;
if (x < toplevel->priv->geometry.x || x >= (toplevel->priv->geometry.x + toplevel->priv->geometry.width) ||
y < toplevel->priv->geometry.y || y >= (toplevel->priv->geometry.y + toplevel->priv->geometry.height))
return FALSE;
return TRUE;
}
static inline int panel_toplevel_get_effective_auto_hide_size(PanelToplevel* toplevel)
{
int size;
if (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK)
size = CLAMP (toplevel->priv->auto_hide_size,
1, toplevel->priv->original_height / 2);
else
size = CLAMP (toplevel->priv->auto_hide_size,
1, toplevel->priv->original_width / 2);
/* paranoia */
return (size <= 0) ? DEFAULT_AUTO_HIDE_SIZE : size;
}
static gboolean panel_toplevel_update_struts(PanelToplevel* toplevel, gboolean end_of_animation)
{
PanelOrientation orientation;
gboolean geometry_changed = FALSE;
int strut, strut_start, strut_end;
int x, y, width, height;
CdkRectangle monitor_geom;
if (!toplevel->priv->updated_geometry_initial)
return FALSE;
#ifdef HAVE_X11
if (CDK_IS_X11_DISPLAY (ctk_widget_get_display (CTK_WIDGET (toplevel))) && toplevel->priv->attached) {
panel_struts_unregister_strut (toplevel);
panel_struts_set_window_hint (toplevel);
return FALSE;
}
#endif // HAVE_X11
/* In the case of the initial animation, we really want the struts to
* represent what is at the end of the animation, to avoid desktop
* icons jumping around. */
if (!toplevel->priv->initial_animation_done) {
end_of_animation = TRUE;
/* We've not started the animation yet, so we have to compute
* where we want to end. Note that we don't want to compute
* this everytime, since the struts conflict resolution will be
* overridden if we do so */
if (!toplevel->priv->animating)
panel_toplevel_calculate_animation_end_geometry (toplevel);
}
panel_toplevel_get_monitor_geometry (toplevel, &monitor_geom);
if (end_of_animation) {
x = toplevel->priv->animation_end_x;
y = toplevel->priv->animation_end_y;
x += panel_multimonitor_x (toplevel->priv->monitor);
y += panel_multimonitor_y (toplevel->priv->monitor);
if (toplevel->priv->animation_end_width != -1)
width = toplevel->priv->animation_end_width;
else
width = toplevel->priv->geometry.width;
if (toplevel->priv->animation_end_height != -1)
height = toplevel->priv->animation_end_height;
else
height = toplevel->priv->geometry.height;
} else {
x = toplevel->priv->geometry.x;
y = toplevel->priv->geometry.y;
width = toplevel->priv->geometry.width;
height = toplevel->priv->geometry.height;
}
orientation = toplevel->priv->orientation;
strut = strut_start = strut_end = 0;
if (orientation & PANEL_HORIZONTAL_MASK) {
if (y <= monitor_geom.y) {
orientation = PANEL_ORIENTATION_TOP;
strut = y + height - monitor_geom.y;
} else if (y >= monitor_geom.y + monitor_geom.height - height) {
orientation = PANEL_ORIENTATION_BOTTOM;
strut = monitor_geom.y + monitor_geom.height - y;
}
if (strut > 0) {
strut_start = MAX (x, monitor_geom.x);
strut_end = MIN (x + width, monitor_geom.x + monitor_geom.width) - 1;
}
} else {
if (x <= monitor_geom.x) {
orientation = PANEL_ORIENTATION_LEFT;
strut = x + width - monitor_geom.x;
} else if (x >= monitor_geom.x + monitor_geom.width - width) {
orientation = PANEL_ORIENTATION_RIGHT;
strut = monitor_geom.x + monitor_geom.width - x;
}
if (strut > 0) {
strut_start = MAX (y, monitor_geom.y);
strut_end = MIN (y + height, monitor_geom.y + monitor_geom.height) - 1;
}
}
/* Adjust strut size based on scale factor */
if (strut > 0)
strut += toplevel->priv->size * (toplevel->priv->scale - 1);
if (orientation != toplevel->priv->orientation) {
toplevel->priv->orientation = orientation;
g_object_notify (G_OBJECT (toplevel), "orientation");
}
if (toplevel->priv->auto_hide && strut > 0)
strut = panel_toplevel_get_effective_auto_hide_size (toplevel);
#ifdef HAVE_X11
if (CDK_IS_X11_DISPLAY (ctk_widget_get_display (CTK_WIDGET (toplevel)))) {
if (strut > 0) {
CdkScreen *screen;
screen = ctk_widget_get_screen (CTK_WIDGET (toplevel));
geometry_changed = panel_struts_register_strut (toplevel,
screen,
toplevel->priv->monitor,
orientation,
strut,
strut_start,
strut_end,
toplevel->priv->scale);
}
else {
panel_struts_unregister_strut (toplevel);
}
if (toplevel->priv->state == PANEL_STATE_NORMAL ||
toplevel->priv->state == PANEL_STATE_AUTO_HIDDEN ||
toplevel->priv->animating)
panel_struts_set_window_hint (toplevel);
else
panel_struts_unset_window_hint (toplevel);
}
#endif // HAVE_X11
#ifdef HAVE_WAYLAND
if (CDK_IS_WAYLAND_DISPLAY (ctk_widget_get_display (CTK_WIDGET (toplevel)))) {
wayland_panel_toplevel_update_placement (toplevel);
}
#endif // HAVE_WAYLAND
return geometry_changed;
}
void panel_toplevel_update_edges(PanelToplevel* toplevel)
{
CtkWidget *widget;
PanelFrameEdge edges;
PanelFrameEdge inner_edges;
PanelFrameEdge outer_edges;
CdkRectangle monitor_geom;
int width, height;
gboolean inner_frame = FALSE;
widget = CTK_WIDGET (toplevel);
panel_toplevel_get_monitor_geometry (toplevel, &monitor_geom);
width = toplevel->priv->geometry.width;
height = toplevel->priv->geometry.height;
edges = PANEL_EDGE_NONE;
/* We don't want any bevels with a color/image background */
if (toplevel->priv->geometry.y > 0)
edges |= PANEL_EDGE_TOP;
if (toplevel->priv->geometry.x > 0)
edges |= PANEL_EDGE_LEFT;
if (toplevel->priv->geometry.y < (monitor_geom.height - height))
edges |= PANEL_EDGE_BOTTOM;
if (toplevel->priv->geometry.x < (monitor_geom.width - width))
edges |= PANEL_EDGE_RIGHT;
/* There is a conflict in the position algorithm when a
* non-expanded centered panel is nearly the size of the
* screen. This is similar to the one we have in
* panel_toplevel_update_position(). A simple solution is
* to keep the bevels in this case. */
if (!toplevel->priv->expand &&
toplevel->priv->orientation & PANEL_HORIZONTAL_MASK &&
toplevel->priv->x_centered)
edges |= PANEL_EDGE_LEFT | PANEL_EDGE_RIGHT;
if (!toplevel->priv->expand &&
toplevel->priv->orientation & PANEL_VERTICAL_MASK &&
toplevel->priv->y_centered)
edges |= PANEL_EDGE_TOP | PANEL_EDGE_BOTTOM;
if (ctk_widget_get_visible (toplevel->priv->hide_button_left) ||
ctk_widget_get_visible (toplevel->priv->hide_button_right)) {
inner_frame = TRUE;
edges |= PANEL_EDGE_LEFT | PANEL_EDGE_RIGHT;
}
if (ctk_widget_get_visible (toplevel->priv->hide_button_top) ||
ctk_widget_get_visible (toplevel->priv->hide_button_bottom)) {
inner_frame = TRUE;
edges |= PANEL_EDGE_TOP | PANEL_EDGE_BOTTOM;
}
if (!inner_frame) {
inner_edges = PANEL_EDGE_NONE;
outer_edges = edges;
} else {
inner_edges = edges;
outer_edges = PANEL_EDGE_NONE;
}
panel_frame_set_edges (toplevel->priv->inner_frame, inner_edges);
if (toplevel->priv->edges != outer_edges) {
toplevel->priv->edges = outer_edges;
ctk_widget_queue_resize (widget);
}
}
static const char* panel_toplevel_construct_description(PanelToplevel *toplevel)
{
if (toplevel->priv->attached)
return _("Drawer");
switch (toplevel->priv->orientation) {
case PANEL_ORIENTATION_TOP:
/* translators: these string will be shown in MetaCity's switch window
* popup when you pass the focus to a panel */
return _("Top Panel");
case PANEL_ORIENTATION_BOTTOM:
return _("Bottom Panel");
case PANEL_ORIENTATION_LEFT:
return _("Left Panel");
case PANEL_ORIENTATION_RIGHT:
return _("Right Panel");
}
g_assert_not_reached ();
return _("Top Panel");
}
static void panel_toplevel_update_description(PanelToplevel* toplevel)
{
const char *description;
description = panel_toplevel_construct_description (toplevel);
if (toplevel->priv->description &&
!strcmp (toplevel->priv->description, description))
return;
if (toplevel->priv->description)
g_free (toplevel->priv->description);
toplevel->priv->description = g_strdup (description);
if (!toplevel->priv->name)
ctk_window_set_title (CTK_WINDOW (toplevel),
toplevel->priv->description);
panel_a11y_set_atk_name_desc (
CTK_WIDGET (toplevel),
toplevel->priv->name ? toplevel->priv->name :
toplevel->priv->description,
toplevel->priv->description);
}
static void panel_toplevel_update_attached_position(PanelToplevel* toplevel, gboolean hidden, int* x, int* y, int* w, int* h)
{
CtkAllocation attach_allocation;
PanelOrientation attach_orientation;
CdkRectangle toplevel_box;
CdkRectangle parent_box;
CdkRectangle attach_box;
int x_origin = 0, y_origin = 0;
CdkRectangle monitor_geom;
if (!ctk_widget_get_realized (CTK_WIDGET (toplevel->priv->attach_toplevel)) ||
!ctk_widget_get_realized (toplevel->priv->attach_widget))
return;
ctk_widget_get_allocation (CTK_WIDGET (toplevel->priv->attach_widget), &attach_allocation);
toplevel_box = toplevel->priv->geometry;
parent_box = toplevel->priv->attach_toplevel->priv->geometry;
attach_box = attach_allocation;
if (attach_box.x != -1) {
cdk_window_get_origin (ctk_widget_get_window (CTK_WIDGET (toplevel->priv->attach_widget)),
&x_origin, &y_origin);
attach_box.x += x_origin;
attach_box.y += y_origin;
} else {
/* attach_widget isn't allocated. Put the toplevel
* off screen.
*/
attach_box.x = -toplevel_box.width;
attach_box.y = -toplevel_box.height;
}
attach_orientation = panel_toplevel_get_orientation (
toplevel->priv->attach_toplevel);
if (attach_orientation & PANEL_HORIZONTAL_MASK)
*x = attach_box.x + attach_box.width / 2 - toplevel_box.width / 2;
else
*y = attach_box.y + attach_box.height / 2 - toplevel_box.height / 2;
switch (attach_orientation) {
case PANEL_ORIENTATION_TOP:
*y = parent_box.y;
if (!hidden)
*y += parent_box.height;
else
*h = parent_box.height;
break;
case PANEL_ORIENTATION_BOTTOM:
*y = parent_box.y;
if (!hidden)
*y -= toplevel_box.height;
else
*h = parent_box.height;
break;
case PANEL_ORIENTATION_LEFT:
*x = parent_box.x;
if (!hidden)
*x += parent_box.width;
else
*w = parent_box.width;
break;
case PANEL_ORIENTATION_RIGHT:
*x = parent_box.x;
if (!hidden)
*x -= toplevel_box.width;
else
*w = parent_box.width;
break;
default:
g_assert_not_reached ();
break;
}
panel_toplevel_get_monitor_geometry (toplevel, &monitor_geom);
*x -= monitor_geom.x;
*y -= monitor_geom.y;
if (toplevel->priv->orientation & PANEL_VERTICAL_MASK)
*x = CLAMP (*x, 0, monitor_geom.width - toplevel->priv->original_width);
else
*y = CLAMP (*y, 0, monitor_geom.height - toplevel->priv->original_height);
}
static void panel_toplevel_update_normal_position(PanelToplevel* toplevel, int* x, int* y, int* w, int* h)
{
CdkRectangle monitor_geom;
int width, height;
int snap_tolerance;
g_assert (x != NULL && y != NULL);
if (toplevel->priv->attached) {
panel_toplevel_update_attached_position (toplevel, FALSE, x, y, w, h);
return;
}
panel_toplevel_get_monitor_geometry (toplevel, &monitor_geom);
width = toplevel->priv->original_width;
height = toplevel->priv->original_height;
snap_tolerance = toplevel->priv->snap_tolerance;
*x = CLAMP (*x, 0, monitor_geom.width - width);
*y = CLAMP (*y, 0, monitor_geom.height - height);
if (toplevel->priv->x <= snap_tolerance &&
toplevel->priv->x_right == -1 &&
!toplevel->priv->x_centered)
*x = 0;
else if (toplevel->priv->x_right != -1 &&
toplevel->priv->x_right <= snap_tolerance &&
!toplevel->priv->x_centered)
*x = monitor_geom.width - width;
if (toplevel->priv->y <= snap_tolerance &&
toplevel->priv->y_bottom == -1 &&
!toplevel->priv->y_centered)
*y = 0;
else if (toplevel->priv->y_bottom != -1 &&
toplevel->priv->y_bottom <= snap_tolerance &&
!toplevel->priv->y_centered)
*y = monitor_geom.height - height;
}
static void
panel_toplevel_update_auto_hide_position (PanelToplevel *toplevel,
int *x,
int *y,
int *w,
int *h,
gboolean for_end_position)
{
int width, height;
CdkRectangle monitor_geom;
int auto_hide_size;
int snap_tolerance;
g_assert (x != NULL && y != NULL);
if (toplevel->priv->floating) {
panel_toplevel_update_normal_position (toplevel, x, y, w, h);
return;
}
panel_toplevel_get_monitor_geometry (toplevel, &monitor_geom);
width = toplevel->priv->original_width;
height = toplevel->priv->original_height;
snap_tolerance = toplevel->priv->snap_tolerance;
/* For the initial animation, we anicafe from outside the screen, and
* so we don't want the toplevel to be visible at all. But when the
* request is for the end position, then we give the real result (it's
* useful for struts) */
if (for_end_position || toplevel->priv->initial_animation_done) {
auto_hide_size = panel_toplevel_get_effective_auto_hide_size (toplevel);
} else {
auto_hide_size = 0;
}
switch (toplevel->priv->orientation) {
case PANEL_ORIENTATION_TOP:
*y = - (height - auto_hide_size);
break;
case PANEL_ORIENTATION_BOTTOM:
*y = monitor_geom.height - auto_hide_size;
break;
case PANEL_ORIENTATION_LEFT:
*x = - (width - auto_hide_size);
break;
case PANEL_ORIENTATION_RIGHT:
*x = monitor_geom.width - auto_hide_size;
break;
default:
g_assert_not_reached ();
break;
}
if (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK) {
if (toplevel->priv->x <= snap_tolerance &&
toplevel->priv->x_right == -1 &&
!toplevel->priv->x_centered)
*x = 0;
else if (toplevel->priv->x_right != -1 &&
toplevel->priv->x_right <= snap_tolerance &&
!toplevel->priv->x_centered)
*x = monitor_geom.width - width;
} else /* if (toplevel->priv->orientation & PANEL_VERTICAL_MASK) */ {
if (toplevel->priv->y <= snap_tolerance &&
toplevel->priv->y_bottom == -1 &&
!toplevel->priv->y_centered)
*y = 0;
else if (toplevel->priv->y_bottom != -1 &&
toplevel->priv->y_bottom <= snap_tolerance &&
!toplevel->priv->y_centered)
*y = monitor_geom.height - height;
}
}
/* FIXME: this is wrong for Xinerama. In the Xinerama case
* I think if hiding it requires it to go onto the
* next monitor then it should just move it on to
* the next monitor and set its state back to normal
*/
static void
panel_toplevel_update_hidden_position (PanelToplevel *toplevel,
int *x,
int *y,
int *w,
int *h)
{
int width, height;
int min_hide_size;
CdkRectangle monitor_geom;
CtkAllocation hide_allocation;
g_assert (x != NULL && y != NULL);
g_assert (toplevel->priv->state == PANEL_STATE_HIDDEN_UP ||
toplevel->priv->state == PANEL_STATE_HIDDEN_DOWN ||
toplevel->priv->state == PANEL_STATE_HIDDEN_LEFT ||
toplevel->priv->state == PANEL_STATE_HIDDEN_RIGHT);
if (toplevel->priv->attached) {
panel_toplevel_update_attached_position (toplevel, TRUE, x, y, w, h);
return;
}
panel_toplevel_get_monitor_geometry (toplevel, &monitor_geom);
width = toplevel->priv->original_width;
height = toplevel->priv->original_height;
//FIXME should find a better default
min_hide_size = DEFAULT_AUTO_HIDE_SIZE;
switch (toplevel->priv->state) {
case PANEL_STATE_HIDDEN_UP:
ctk_widget_get_allocation (toplevel->priv->hide_button_bottom,
&hide_allocation);
*y = - (height - MAX (hide_allocation.height, min_hide_size));
break;
case PANEL_STATE_HIDDEN_DOWN:
ctk_widget_get_allocation (toplevel->priv->hide_button_top,
&hide_allocation);
*y = monitor_geom.height - MAX (hide_allocation.height, min_hide_size);
break;
case PANEL_STATE_HIDDEN_LEFT:
ctk_widget_get_allocation (toplevel->priv->hide_button_right,
&hide_allocation);
*x = - (width - MAX (hide_allocation.width, min_hide_size));
break;
case PANEL_STATE_HIDDEN_RIGHT:
ctk_widget_get_allocation (toplevel->priv->hide_button_left,
&hide_allocation);
*x = monitor_geom.width - MAX (hide_allocation.width, min_hide_size);
break;
default:
g_assert_not_reached ();
break;
}
}
/*
* This is "almost" like the double sine movement
* from the original panel except that it uses
* a cubic (twice again). I suppose it looks less
* mathematical now :) -- _v_
*/
static int
get_delta (int src,
int dest,
GTimeVal *start_time,
GTimeVal *end_time,
GTimeVal *cur_time)
{
double x, s, n, d, percentage;
s = start_time->tv_sec + ((double)start_time->tv_usec / G_USEC_PER_SEC);
n = cur_time->tv_sec + ((double)cur_time->tv_usec / G_USEC_PER_SEC);
d = end_time->tv_sec + ((double)end_time->tv_usec / G_USEC_PER_SEC);
n -= s;
d -= s;
if (abs (dest - src) <= 1 || n >= d)
return dest - src;
/* The cubic is: p(x) = (-2) x^2 (x-1.5) */
/* running p(p(x)) to make it more "pronounced",
* effectively making it a ninth-degree polynomial */
x = (double)n/d;
x = -2 * (x*x) * (x-1.5);
/* run it again */
percentage = -2 * (x*x) * (x-1.5);
percentage = CLAMP (percentage, 0.0, 1.0);
return ((dest - src) * percentage);
}
static void
panel_toplevel_update_animating_position (PanelToplevel *toplevel)
{
GTimeVal time_val;
int deltax, deltay, deltaw = 0, deltah = 0;
int monitor_offset_x, monitor_offset_y;
g_get_current_time (&time_val);
monitor_offset_x = panel_multimonitor_x (toplevel->priv->monitor);
monitor_offset_y = panel_multimonitor_y (toplevel->priv->monitor);
if (toplevel->priv->animation_end_width != -1)
deltaw = get_delta (toplevel->priv->geometry.width,
toplevel->priv->animation_end_width,
&toplevel->priv->animation_start_time,
&toplevel->priv->animation_end_time,
&time_val);
if (toplevel->priv->animation_end_height != -1)
deltah = get_delta (toplevel->priv->geometry.height,
toplevel->priv->animation_end_height,
&toplevel->priv->animation_start_time,
&toplevel->priv->animation_end_time,
&time_val);
deltax = get_delta (toplevel->priv->geometry.x - monitor_offset_x,
toplevel->priv->animation_end_x,
&toplevel->priv->animation_start_time,
&toplevel->priv->animation_end_time,
&time_val);
deltay = get_delta (toplevel->priv->geometry.y - monitor_offset_y,
toplevel->priv->animation_end_y,
&toplevel->priv->animation_start_time,
&toplevel->priv->animation_end_time,
&time_val);
if (deltaw != 0 && abs (deltaw) > abs (deltax))
deltax = deltaw;
if (deltah != 0 && abs (deltah) > abs (deltay))
deltay = deltah;
toplevel->priv->geometry.x += deltax;
toplevel->priv->geometry.y += deltay;
toplevel->priv->geometry.width += deltaw;
toplevel->priv->geometry.height += deltah;
if (toplevel->priv->geometry.x - monitor_offset_x == toplevel->priv->animation_end_x &&
toplevel->priv->geometry.y - monitor_offset_y == toplevel->priv->animation_end_y) {
toplevel->priv->animating = FALSE;
/* Note: it's important to set initial_animation_done to TRUE
* as soon as possible (hence, here) since we don't want to
* have a wrong value in a size request event */
toplevel->priv->initial_animation_done = TRUE;
if (toplevel->priv->attached && panel_toplevel_get_is_hidden (toplevel))
ctk_widget_unmap (CTK_WIDGET (toplevel));
else
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
if (toplevel->priv->state == PANEL_STATE_NORMAL)
g_signal_emit (toplevel, toplevel_signals [UNHIDE_SIGNAL], 0);
}
}
static void
panel_toplevel_update_expanded_position (PanelToplevel *toplevel)
{
CdkRectangle monitor_geom;
int x, y;
int x_right, y_bottom;
int monitor;
if (!toplevel->priv->expand)
return;
panel_toplevel_get_monitor_geometry (toplevel, &monitor_geom);
x = -1;
y = -1;
x_right = -1;
y_bottom = -1;
switch (toplevel->priv->orientation) {
case PANEL_ORIENTATION_TOP:
x = monitor_geom.x;
y = monitor_geom.y;
break;
case PANEL_ORIENTATION_LEFT:
x = monitor_geom.x;
y = monitor_geom.y;
break;
case PANEL_ORIENTATION_BOTTOM:
x = monitor_geom.x;
y = monitor_geom.y + monitor_geom.height - toplevel->priv->geometry.height;
y_bottom = 0;
break;
case PANEL_ORIENTATION_RIGHT:
x = monitor_geom.x + monitor_geom.width - toplevel->priv->geometry.width;
y = monitor_geom.y;
x_right = 0;
break;
default:
g_assert_not_reached ();
break;
}
monitor = panel_multimonitor_get_monitor_at_point (x, y);
panel_toplevel_set_monitor_internal (toplevel, monitor, TRUE);
x -= panel_multimonitor_x (monitor);
y -= panel_multimonitor_y (monitor);
g_object_freeze_notify (G_OBJECT (toplevel));
if (toplevel->priv->x != x) {
toplevel->priv->x = x;
g_object_notify (G_OBJECT (toplevel), "x");
}
if (toplevel->priv->y != y) {
toplevel->priv->y = y;
g_object_notify (G_OBJECT (toplevel), "y");
}
if (toplevel->priv->x_right != x_right) {
toplevel->priv->x_right = x_right;
g_object_notify (G_OBJECT (toplevel), "x_right");
}
if (toplevel->priv->y_bottom != y_bottom) {
toplevel->priv->y_bottom = y_bottom;
g_object_notify (G_OBJECT (toplevel), "y_bottom");
}
g_object_thaw_notify (G_OBJECT (toplevel));
}
static void
panel_toplevel_update_position (PanelToplevel *toplevel)
{
PanelBackground *background;
int x, y;
int w, h;
CdkRectangle monitor_geom;
panel_toplevel_get_monitor_geometry (toplevel, &monitor_geom);
if (toplevel->priv->animating) {
panel_toplevel_update_animating_position (toplevel);
return;
}
if (toplevel->priv->position_centered) {
toplevel->priv->position_centered = FALSE;
g_object_freeze_notify (G_OBJECT (toplevel));
if (!toplevel->priv->x_centered) {
int x_right;
toplevel->priv->x -= toplevel->priv->geometry.width / 2;
g_object_notify (G_OBJECT (toplevel), "x");
if ((toplevel->priv->x + toplevel->priv->geometry.width / 2) > monitor_geom.width / 2)
x_right = monitor_geom.width - (toplevel->priv->x + toplevel->priv->geometry.width);
else
x_right = -1;
if (toplevel->priv->x_right != x_right) {
toplevel->priv->x_right = x_right;
g_object_notify (G_OBJECT (toplevel),
"x-right");
}
}
if (!toplevel->priv->y_centered) {
int y_bottom;
toplevel->priv->y -= toplevel->priv->geometry.height / 2;
g_object_notify (G_OBJECT (toplevel), "y");
if ((toplevel->priv->y + toplevel->priv->geometry.height / 2) > monitor_geom.height / 2)
y_bottom = monitor_geom.height - (toplevel->priv->y + toplevel->priv->geometry.height);
else
y_bottom = -1;
if (toplevel->priv->y_bottom != y_bottom) {
toplevel->priv->y_bottom = y_bottom;
g_object_notify (G_OBJECT (toplevel),
"y-bottom");
}
}
g_object_thaw_notify (G_OBJECT (toplevel));
}
panel_toplevel_update_expanded_position (toplevel);
panel_toplevel_calc_floating (toplevel); //FIXME should probably be done after panel_toplevel_update_normal_position() too
if (toplevel->priv->x_right == -1)
x = toplevel->priv->x;
else
x = monitor_geom.width - (toplevel->priv->x_right + toplevel->priv->geometry.width);
if (toplevel->priv->y_bottom == -1)
y = toplevel->priv->y;
else
y = monitor_geom.height - (toplevel->priv->y_bottom + toplevel->priv->geometry.height);
if (!toplevel->priv->expand) {
if (toplevel->priv->x_centered)
x = (monitor_geom.width - toplevel->priv->geometry.width) / 2;
if (toplevel->priv->y_centered)
y = (monitor_geom.height - toplevel->priv->geometry.height) / 2;
}
w = h = -1;
if (toplevel->priv->state == PANEL_STATE_NORMAL)
panel_toplevel_update_normal_position (toplevel, &x, &y, &w, &h);
else if (toplevel->priv->state == PANEL_STATE_AUTO_HIDDEN)
panel_toplevel_update_auto_hide_position (toplevel, &x, &y, &w, &h, FALSE);
else
panel_toplevel_update_hidden_position (toplevel, &x, &y, &w, &h);
if (w != -1)
toplevel->priv->geometry.width = w;
if (h != -1)
toplevel->priv->geometry.height = h;
/* This is some kind of snap: there's a possibility of an infinite loop
* because of the bevels of the frame that are set in
* panel_toplevel_update_edges(). The bevels change the width/height of
* the toplevel. The typical loop is:
* x = 1 => outer bevel => x = 0 => no outer bevel = > x = 1 => ...
* FIXME: maybe the real bug is that we enter into this loop (see bug
* #160748 to learn how to reproduce.) */
background = &toplevel->background;
/* There's no bevels with a color/image background */
if (panel_background_effective_type (background) == PANEL_BACK_NONE) {
CtkStyleContext *context;
CtkStateFlags state;
CdkRectangle *geometry;
CtkBorder padding;
int max_size;
state = ctk_widget_get_state_flags (CTK_WIDGET (toplevel->priv->inner_frame));
context = ctk_widget_get_style_context (CTK_WIDGET (toplevel->priv->inner_frame));
ctk_style_context_get_padding (context, state, &padding);
geometry = &toplevel->priv->geometry;
if (x <= padding.left && x > 0 &&
!toplevel->priv->x_centered)
x = 0;
if (y <= padding.top && y > 0 &&
!toplevel->priv->y_centered)
y = 0;
max_size = monitor_geom.width - geometry->width - padding.right;
if (x + padding.left >= max_size && x < max_size &&
!toplevel->priv->x_centered)
x = max_size;
max_size = monitor_geom.height - geometry->height - padding.bottom;
if (y + padding.top >= max_size && y < max_size &&
!toplevel->priv->y_centered)
y = max_size;
}
x += panel_multimonitor_x (toplevel->priv->monitor);
y += panel_multimonitor_y (toplevel->priv->monitor);
toplevel->priv->geometry.x = x;
toplevel->priv->geometry.y = y;
}
static int
calculate_minimum_height (CtkWidget *widget,
PanelOrientation orientation)
{
CtkStateFlags state;
CtkStyleContext *style_context;
PangoFontDescription *font_desc;
CtkBorder padding;
PangoContext *pango_context;
PangoFontMetrics *metrics;
int ascent;
int descent;
int thickness;
state = ctk_widget_get_state_flags (widget);
style_context = ctk_widget_get_style_context (widget);
ctk_style_context_get(style_context, state, CTK_STYLE_PROPERTY_FONT, &font_desc, NULL);
pango_context = ctk_widget_get_pango_context (widget);
metrics = pango_context_get_metrics (pango_context,
font_desc,
pango_context_get_language (pango_context));
ctk_style_context_get_padding (style_context, state, &padding);
ascent = pango_font_metrics_get_ascent (metrics);
descent = pango_font_metrics_get_descent (metrics);
pango_font_description_free (font_desc);
pango_font_metrics_unref (metrics);
thickness = (orientation & PANEL_HORIZONTAL_MASK) ?
padding.top + padding.bottom :
padding.left + padding.right;
return PANGO_PIXELS (ascent + descent) + thickness;
}
static int
panel_toplevel_update_size_from_hints (PanelToplevel *toplevel,
int requisition_size,
int monitor_size,
int non_panel_widget_size)
{
int nb_size_hints;
AppletSizeHints *applets_hints;
AppletSizeHintsAlloc *using_hint;
int i;
int total_size;
int full_hints;
/* Scale down the size so that the panel only takes what it needs for the applets it has. */
total_size = non_panel_widget_size + (requisition_size / toplevel->priv->scale);
nb_size_hints = toplevel->priv->panel_widget->nb_applets_size_hints;
if (nb_size_hints <= 0)
return total_size;
applets_hints = toplevel->priv->panel_widget->applets_hints;
using_hint = toplevel->priv->panel_widget->applets_using_hint;
for (i = 0; i < nb_size_hints; i++) {
using_hint[i].index = applets_hints[i].len - 2;
using_hint[i].size = applets_hints[i].hints[applets_hints[i].len - 1];
total_size += using_hint[i].size;
}
if (total_size > monitor_size)
return monitor_size;
full_hints = 0;
while (full_hints != nb_size_hints && total_size < monitor_size) {
int bonus;
int extra_bonus;
bonus = (monitor_size - total_size)
/ (nb_size_hints - full_hints);
extra_bonus = (monitor_size - total_size)
% (nb_size_hints - full_hints);
full_hints = 0;
for (i = 0; i < nb_size_hints; i++) {
int new_size;
int current_bonus;
current_bonus = bonus;
while (using_hint[i].index > 0 && applets_hints[i].hints[using_hint[i].index - 1] < using_hint[i].size + current_bonus) {
new_size = applets_hints[i].hints[using_hint[i].index - 1];
current_bonus = using_hint[i].size
+ current_bonus - new_size;
total_size = total_size - using_hint[i].size
+ new_size;
using_hint[i].index -= 2;
using_hint[i].size = new_size;
}
new_size = MIN (applets_hints[i].hints[using_hint[i].index],
using_hint[i].size + current_bonus);
if (new_size > using_hint[i].size) {
total_size += (new_size - using_hint[i].size);
using_hint[i].size = new_size;
}
if (extra_bonus > 0) {
new_size = MIN (applets_hints[i].hints[using_hint[i].index],
using_hint[i].size + extra_bonus);
if (new_size > using_hint[i].size) {
total_size += (new_size
- using_hint[i].size);
extra_bonus -= (new_size
- using_hint[i].size);
using_hint[i].size = new_size;
}
}
if (using_hint[i].size == applets_hints[i].hints[using_hint[i].index])
full_hints++;
}
}
return total_size;
}
static void
panel_toplevel_update_size (PanelToplevel *toplevel,
CtkRequisition *requisition)
{
CtkWidget *widget;
CtkStyleContext *context;
CtkStateFlags state;
CtkBorder padding;
CdkRectangle monitor_geom;
int width, height;
int minimum_height;
int non_panel_widget_size;
if (toplevel->priv->animating)
return;
widget = CTK_WIDGET (toplevel);
context = ctk_widget_get_style_context (widget);
state = ctk_widget_get_state_flags (widget);
ctk_style_context_get_padding (context, state, &padding);
panel_toplevel_get_monitor_geometry (toplevel, &monitor_geom);
width = requisition->width;
height = requisition->height;
if (!toplevel->priv->expand &&
!toplevel->priv->buttons_enabled && !toplevel->priv->attached)
non_panel_widget_size = 2 * HANDLE_SIZE;
else
non_panel_widget_size = 0;
minimum_height = calculate_minimum_height (CTK_WIDGET (toplevel),
toplevel->priv->orientation);
if (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK) {
height = MAX (MIN (MAX (height, toplevel->priv->size),
panel_toplevel_get_maximum_size (toplevel)),
minimum_height);
if (toplevel->priv->expand)
width = monitor_geom.width;
else {
int max_width;
if (!toplevel->priv->attached)
max_width = monitor_geom.width;
else {
if (panel_toplevel_get_orientation (toplevel->priv->attach_toplevel) == PANEL_ORIENTATION_LEFT)
max_width = monitor_geom.width
- toplevel->priv->geometry.x;
else
max_width = toplevel->priv->geometry.x +
toplevel->priv->geometry.width;
}
width = panel_toplevel_update_size_from_hints (
toplevel,
requisition->width,
max_width,
non_panel_widget_size);
}
width = MAX (MINIMUM_WIDTH, width);
} else {
width = MAX (MIN (MAX (width, toplevel->priv->size),
panel_toplevel_get_maximum_size (toplevel)),
minimum_height);
if (toplevel->priv->expand)
height = monitor_geom.height;
else {
int max_height;
if (!toplevel->priv->attached)
max_height = monitor_geom.height;
else {
if (panel_toplevel_get_orientation (toplevel->priv->attach_toplevel) == PANEL_ORIENTATION_TOP)
max_height = monitor_geom.height
- toplevel->priv->geometry.y;
else
max_height = toplevel->priv->geometry.y +
toplevel->priv->geometry.height;
}
height = panel_toplevel_update_size_from_hints (
toplevel,
requisition->height,
max_height,
non_panel_widget_size);
}
height = MAX (MINIMUM_WIDTH, height);
}
if (toplevel->priv->edges & PANEL_EDGE_TOP)
height += padding.top;
if (toplevel->priv->edges & PANEL_EDGE_BOTTOM)
height += padding.bottom;
if (toplevel->priv->edges & PANEL_EDGE_LEFT)
width += padding.left;
if (toplevel->priv->edges & PANEL_EDGE_RIGHT)
width += padding.right;
toplevel->priv->geometry.width = CLAMP (width, 0, monitor_geom.width);
toplevel->priv->geometry.height = CLAMP (height, 0, monitor_geom.height);
toplevel->priv->original_width = toplevel->priv->geometry.width;
toplevel->priv->original_height = toplevel->priv->geometry.height;
}
static void
panel_toplevel_update_geometry (PanelToplevel *toplevel,
CtkRequisition *requisition)
{
toplevel->priv->updated_geometry_initial = TRUE;
panel_toplevel_update_size (toplevel, requisition);
panel_toplevel_update_position (toplevel);
panel_toplevel_update_struts (toplevel, FALSE);
#ifdef HAVE_X11
if (CDK_IS_X11_DISPLAY (ctk_widget_get_display (CTK_WIDGET (toplevel)))) {
if (toplevel->priv->state == PANEL_STATE_NORMAL ||
toplevel->priv->state == PANEL_STATE_AUTO_HIDDEN) {
panel_struts_update_toplevel_geometry (toplevel,
&toplevel->priv->geometry.x,
&toplevel->priv->geometry.y,
&toplevel->priv->geometry.width,
&toplevel->priv->geometry.height);
} else {
panel_struts_update_toplevel_geometry (toplevel,
&toplevel->priv->geometry.x,
&toplevel->priv->geometry.y,
NULL, NULL);
}
}
#endif // HAVE_X11
panel_toplevel_update_edges (toplevel);
panel_toplevel_update_description (toplevel);
}
static void
panel_toplevel_attach_widget_destroyed (PanelToplevel *toplevel)
{
panel_toplevel_detach (toplevel);
}
static gboolean
panel_toplevel_attach_widget_configure (PanelToplevel *toplevel)
{
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
return FALSE;
}
static void
panel_toplevel_update_attach_orientation (PanelToplevel *toplevel)
{
PanelOrientation attach_orientation;
PanelOrientation orientation;
attach_orientation =
panel_toplevel_get_orientation (toplevel->priv->attach_toplevel);
orientation = toplevel->priv->orientation;
switch (attach_orientation) {
case PANEL_ORIENTATION_TOP:
orientation = PANEL_ORIENTATION_LEFT;
break;
case PANEL_ORIENTATION_BOTTOM:
orientation = PANEL_ORIENTATION_RIGHT;
break;
case PANEL_ORIENTATION_LEFT:
orientation = PANEL_ORIENTATION_TOP;
break;
case PANEL_ORIENTATION_RIGHT:
orientation = PANEL_ORIENTATION_BOTTOM;
break;
default:
g_assert_not_reached ();
break;
}
panel_toplevel_set_orientation (toplevel, orientation);
}
static void
panel_toplevel_attach_widget_parent_set (PanelToplevel *toplevel,
CtkWidget *previous_parent,
CtkWidget *attach_widget)
{
CtkWidget *panel_widget;
panel_widget = ctk_widget_get_parent (CTK_WIDGET (attach_widget));
if (!panel_widget)
return;
g_assert (PANEL_IS_WIDGET (panel_widget));
toplevel->priv->attach_toplevel = PANEL_WIDGET (panel_widget)->toplevel;
panel_toplevel_update_attach_orientation (toplevel);
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
}
static void
panel_toplevel_attach_toplevel_hiding (PanelToplevel *toplevel)
{
if (!panel_toplevel_get_is_hidden (toplevel)) {
panel_toplevel_hide (toplevel, FALSE, -1);
toplevel->priv->attach_hidden = TRUE;
}
}
static void
panel_toplevel_attach_toplevel_unhiding (PanelToplevel *toplevel)
{
if (!toplevel->priv->attach_hidden)
return;
toplevel->priv->attach_hidden = FALSE;
panel_toplevel_unhide (toplevel);
}
static void
panel_toplevel_reverse_arrow (PanelToplevel *toplevel,
CtkWidget *button)
{
CtkArrowType arrow_type;
arrow_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "arrow-type"));
switch (arrow_type) {
case CTK_ARROW_UP:
arrow_type = CTK_ARROW_DOWN;
break;
case CTK_ARROW_DOWN:
arrow_type = CTK_ARROW_UP;
break;
case CTK_ARROW_LEFT:
arrow_type = CTK_ARROW_RIGHT;
break;
case CTK_ARROW_RIGHT:
arrow_type = CTK_ARROW_LEFT;
break;
default:
g_assert_not_reached ();
break;
}
g_object_set_data (G_OBJECT (button), "arrow-type", GINT_TO_POINTER (arrow_type));
set_arrow_type (CTK_IMAGE (ctk_bin_get_child (CTK_BIN (button))), arrow_type);
}
static void
panel_toplevel_reverse_arrows (PanelToplevel *toplevel)
{
panel_toplevel_reverse_arrow (toplevel, toplevel->priv->hide_button_top);
panel_toplevel_reverse_arrow (toplevel, toplevel->priv->hide_button_bottom);
panel_toplevel_reverse_arrow (toplevel, toplevel->priv->hide_button_left);
panel_toplevel_reverse_arrow (toplevel, toplevel->priv->hide_button_right);
}
static void
panel_toplevel_disconnect_attached (PanelToplevel *toplevel)
{
int i;
for (i = 0; i < N_ATTACH_TOPLEVEL_SIGNALS; i++) {
if (!toplevel->priv->attach_toplevel_signals [i])
continue;
g_signal_handler_disconnect (
toplevel->priv->attach_toplevel,
toplevel->priv->attach_toplevel_signals [i]);
toplevel->priv->attach_toplevel_signals [i] = 0;
}
for (i = 0; i < N_ATTACH_WIDGET_SIGNALS; i++) {
if (!toplevel->priv->attach_widget_signals [i])
continue;
g_signal_handler_disconnect (
toplevel->priv->attach_widget,
toplevel->priv->attach_widget_signals [i]);
toplevel->priv->attach_widget_signals [i] = 0;
}
}
static void
panel_toplevel_connect_attached (PanelToplevel *toplevel)
{
gulong *signals;
int i = 0;
signals = toplevel->priv->attach_toplevel_signals;
signals [i++] = g_signal_connect_swapped (
toplevel->priv->attach_toplevel, "destroy",
G_CALLBACK (panel_toplevel_attach_widget_destroyed), toplevel);
signals [i++] = g_signal_connect_swapped (
toplevel->priv->attach_toplevel, "notify::orientation",
G_CALLBACK (panel_toplevel_update_attach_orientation), toplevel);
signals [i++] = g_signal_connect_swapped (
toplevel->priv->attach_toplevel, "configure-event",
G_CALLBACK (panel_toplevel_attach_widget_configure), toplevel);
signals [i++] = g_signal_connect_swapped (
toplevel->priv->attach_toplevel, "hiding",
G_CALLBACK (panel_toplevel_attach_toplevel_hiding), toplevel);
signals [i++] = g_signal_connect_swapped (
toplevel->priv->attach_toplevel, "unhiding",
G_CALLBACK (panel_toplevel_attach_toplevel_unhiding), toplevel);
g_assert (i == N_ATTACH_TOPLEVEL_SIGNALS);
signals = toplevel->priv->attach_widget_signals;
i = 0;
signals [i++] = g_signal_connect_swapped (
toplevel->priv->attach_widget, "destroy",
G_CALLBACK (panel_toplevel_attach_widget_destroyed), toplevel);
signals [i++] = g_signal_connect_swapped (
toplevel->priv->attach_widget, "configure-event",
G_CALLBACK (panel_toplevel_attach_widget_configure), toplevel);
signals [i++] = g_signal_connect_swapped (
toplevel->priv->attach_widget, "parent-set",
G_CALLBACK (panel_toplevel_attach_widget_parent_set), toplevel);
signals [i++] = g_signal_connect_swapped (
toplevel->priv->attach_widget, "show",
G_CALLBACK (ctk_widget_show), toplevel);
signals [i++] = g_signal_connect_swapped (
toplevel->priv->attach_widget, "hide",
G_CALLBACK (ctk_widget_hide), toplevel);
g_assert (i == N_ATTACH_WIDGET_SIGNALS);
}
void
panel_toplevel_attach_to_widget (PanelToplevel *toplevel,
PanelToplevel *attach_toplevel,
CtkWidget *attach_widget)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
g_return_if_fail (PANEL_IS_TOPLEVEL (attach_toplevel));
g_return_if_fail (CTK_IS_WIDGET (attach_widget));
if (toplevel->priv->attached)
panel_toplevel_disconnect_attached (toplevel);
toplevel->priv->attached = TRUE;
/* Cancelling the initial animation for drawers in
* panel_toplevel_initially_hide() is not enough, since this will
* happen only when the toplevel is realized, which might be too late
* for drawers (since it's realized when the drawer is clicked) */
toplevel->priv->initial_animation_done = TRUE;
toplevel->priv->attach_toplevel = attach_toplevel;
toplevel->priv->attach_widget = attach_widget;
panel_toplevel_connect_attached (toplevel);
panel_toplevel_reverse_arrows (toplevel);
panel_toplevel_set_expand (toplevel, FALSE);
panel_toplevel_update_attach_orientation (toplevel);
panel_toplevel_update_hide_buttons (toplevel);
ctk_window_set_screen (CTK_WINDOW (toplevel),
ctk_widget_get_screen (CTK_WIDGET (attach_toplevel)));
panel_toplevel_set_monitor (toplevel,
panel_toplevel_get_monitor (attach_toplevel));
if (toplevel->priv->state == PANEL_STATE_NORMAL)
panel_toplevel_push_autohide_disabler (toplevel->priv->attach_toplevel);
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
}
void
panel_toplevel_detach (PanelToplevel *toplevel)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
if (!toplevel->priv->attached)
return;
if (toplevel->priv->state == PANEL_STATE_NORMAL)
panel_toplevel_pop_autohide_disabler (toplevel->priv->attach_toplevel);
panel_toplevel_disconnect_attached (toplevel);
panel_toplevel_reverse_arrows (toplevel);
toplevel->priv->attached = FALSE;
toplevel->priv->attach_toplevel = NULL;
toplevel->priv->attach_widget = NULL;
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
}
gboolean
panel_toplevel_get_is_attached (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), FALSE);
return toplevel->priv->attached;
}
PanelToplevel *
panel_toplevel_get_attach_toplevel (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), NULL);
return toplevel->priv->attach_toplevel;
}
CtkWidget *
panel_toplevel_get_attach_widget (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), NULL);
return toplevel->priv->attach_widget;
}
static gboolean
panel_toplevel_popup_panel_menu (PanelToplevel *toplevel)
{
gboolean retval = FALSE;
g_signal_emit_by_name (toplevel, "popup_menu", &retval);
return retval;
}
static gboolean
panel_toplevel_toggle_expand (PanelToplevel *toplevel)
{
panel_toplevel_set_expand (toplevel, !toplevel->priv->expand);
return TRUE;
}
static gboolean
panel_toplevel_expand (PanelToplevel *toplevel)
{
panel_toplevel_set_expand (toplevel, TRUE);
return TRUE;
}
static gboolean
panel_toplevel_unexpand (PanelToplevel *toplevel)
{
panel_toplevel_set_expand (toplevel, FALSE);
return TRUE;
}
static gboolean
panel_toplevel_toggle_hidden (PanelToplevel *toplevel)
{
if (toplevel->priv->state == PANEL_STATE_NORMAL)
panel_toplevel_hide (toplevel, toplevel->priv->auto_hide, -1);
else
panel_toplevel_unhide (toplevel);
return FALSE;
}
static gboolean
panel_toplevel_begin_move (PanelToplevel *toplevel)
{
if (toplevel->priv->grab_op != PANEL_GRAB_OP_NONE)
return FALSE;
panel_toplevel_begin_grab_op (
toplevel, PANEL_GRAB_OP_MOVE, TRUE, CDK_CURRENT_TIME);
return TRUE;
}
static gboolean
panel_toplevel_begin_resize (PanelToplevel *toplevel)
{
if (toplevel->priv->grab_op != PANEL_GRAB_OP_NONE)
return FALSE;
panel_toplevel_begin_grab_op (
toplevel, PANEL_GRAB_OP_RESIZE, TRUE, CDK_CURRENT_TIME);
return TRUE;
}
static void
panel_toplevel_move_resize_window (PanelToplevel *toplevel,
gboolean move,
gboolean resize)
{
CtkWidget *widget;
GList *list;
const char *id;
int position;
gboolean stick;
widget = CTK_WIDGET (toplevel);
g_assert (ctk_widget_get_realized (widget));
if (move && resize)
cdk_window_move_resize (ctk_widget_get_window (widget),
toplevel->priv->geometry.x,
toplevel->priv->geometry.y,
toplevel->priv->geometry.width,
toplevel->priv->geometry.height);
else if (move)
cdk_window_move (ctk_widget_get_window (widget),
toplevel->priv->geometry.x,
toplevel->priv->geometry.y);
else if (resize)
cdk_window_resize (ctk_widget_get_window (widget),
toplevel->priv->geometry.width,
toplevel->priv->geometry.height);
if (resize || move) {
for (list = toplevel->priv->panel_widget->applet_list; list != NULL; list = g_list_next (list)) {
AppletData *ad = list->data;
id = cafe_panel_applet_get_id_by_widget (ad->applet);
if (!id)
return;
AppletInfo *info;
info = cafe_panel_applet_get_by_id (id);
stick = g_settings_get_boolean (info->settings, PANEL_OBJECT_PANEL_RIGHT_STICK_KEY);
if (stick) {
position = g_settings_get_int (info->settings, PANEL_OBJECT_POSITION_KEY);
if (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK) {
ad->pos = toplevel->priv->geometry.width - position;
} else {
ad->pos = toplevel->priv->geometry.height - position;
}
}
}
}
}
static void
panel_toplevel_initially_hide (PanelToplevel *toplevel)
{
if (!toplevel->priv->attached) {
toplevel->priv->initial_animation_done = FALSE;
/* We start the panel off hidden until all the applets are
* loaded, and then finally slide it down when it's ready to be
* used */
toplevel->priv->state = PANEL_STATE_AUTO_HIDDEN;
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
} else
toplevel->priv->initial_animation_done = TRUE;
}
static void
set_background_default_style (CtkWidget *widget)
{
PanelToplevel *toplevel;
CtkStyleContext *context;
CtkStateFlags state;
CdkRGBA *bg_color;
cairo_pattern_t *bg_image;
if (!ctk_widget_get_realized (widget))
return;
toplevel = PANEL_TOPLEVEL (widget);
context = ctk_widget_get_style_context (widget);
state = ctk_style_context_get_state (context);
ctk_style_context_get (context, state,
"background-color", &bg_color,
"background-image", &bg_image,
NULL);
panel_background_set_default_style (&toplevel->background,
bg_color, bg_image);
if (bg_color)
cdk_rgba_free (bg_color);
if (bg_image)
cairo_pattern_destroy (bg_image);
}
static void
panel_toplevel_realize (CtkWidget *widget)
{
PanelToplevel *toplevel;
CdkScreen *screen;
CdkVisual *visual;
CdkWindow *window;
toplevel = PANEL_TOPLEVEL (widget);
screen = ctk_widget_get_screen (widget);
visual = cdk_screen_get_rgba_visual (screen);
if (visual == NULL)
visual = cdk_screen_get_system_visual (screen);
ctk_widget_set_visual (widget, visual);
ctk_window_stick (CTK_WINDOW (widget));
ctk_window_set_decorated (CTK_WINDOW (widget), FALSE);
ctk_window_stick (CTK_WINDOW (widget));
ctk_window_set_type_hint (CTK_WINDOW (widget), CDK_WINDOW_TYPE_HINT_DOCK);
CTK_WIDGET_CLASS (panel_toplevel_parent_class)->realize (widget);
window = ctk_widget_get_window (widget);
set_background_default_style (widget);
panel_background_realized (&toplevel->background, window);
#ifdef HAVE_X11
if (CDK_IS_X11_WINDOW (window)) {
panel_struts_set_window_hint (toplevel);
cdk_window_set_geometry_hints (window, NULL, 0);
}
#endif // HAVE_X11
cdk_window_set_group (window, window);
panel_toplevel_initially_hide (toplevel);
panel_toplevel_move_resize_window (toplevel, TRUE, TRUE);
}
static void
panel_toplevel_disconnect_timeouts (PanelToplevel *toplevel)
{
if (toplevel->priv->hide_timeout)
g_source_remove (toplevel->priv->hide_timeout);
toplevel->priv->hide_timeout = 0;
if (toplevel->priv->unhide_timeout)
g_source_remove (toplevel->priv->unhide_timeout);
toplevel->priv->unhide_timeout = 0;
if (toplevel->priv->animation_timeout)
g_source_remove (toplevel->priv->animation_timeout);
toplevel->priv->animation_timeout = 0;
}
static void
panel_toplevel_unrealize (CtkWidget *widget)
{
PanelToplevel *toplevel;
toplevel = PANEL_TOPLEVEL (widget);
panel_toplevel_disconnect_timeouts (toplevel);
panel_background_unrealized (&toplevel->background);
CTK_WIDGET_CLASS (panel_toplevel_parent_class)->unrealize (widget);
}
static void
panel_toplevel_dispose (GObject *widget)
{
PanelToplevel *toplevel = (PanelToplevel *) widget;
if (toplevel->priv->settings_path) {
g_free (toplevel->priv->settings_path);
toplevel->priv->settings_path = NULL;
}
if (toplevel->settings) {
g_signal_handlers_disconnect_by_data (toplevel->settings, toplevel);
g_object_unref (toplevel->settings);
toplevel->settings = NULL;
}
if (toplevel->queued_settings) {
g_object_unref (toplevel->queued_settings);
toplevel->queued_settings = NULL;
}
if (toplevel->background_settings) {
g_signal_handlers_disconnect_by_data (toplevel->background_settings, toplevel);
g_object_unref (toplevel->background_settings);
toplevel->background_settings = NULL;
}
if (toplevel->priv->ctk_settings) {
g_signal_handlers_disconnect_by_func (toplevel->priv->ctk_settings,
G_CALLBACK (panel_toplevel_drag_threshold_changed),
toplevel);
toplevel->priv->ctk_settings = NULL;
panel_background_free (&toplevel->background);
}
if (toplevel->priv->attached) {
panel_toplevel_disconnect_attached (toplevel);
toplevel->priv->attached = FALSE;
toplevel->priv->attach_toplevel = NULL;
toplevel->priv->attach_widget = NULL;
}
if (toplevel->priv->description) {
g_free (toplevel->priv->description);
toplevel->priv->description = NULL;
}
if (toplevel->priv->name) {
g_free (toplevel->priv->name);
toplevel->priv->name = NULL;
}
panel_toplevel_disconnect_timeouts (toplevel);
G_OBJECT_CLASS (panel_toplevel_parent_class)->dispose (widget);
}
static void
panel_toplevel_check_resize (CtkContainer *container)
{
CtkAllocation allocation;
CtkRequisition requisition;
CtkWidget *widget;
widget = CTK_WIDGET (container);
if (!ctk_widget_get_visible (widget))
return;
requisition.width = -1;
requisition.height = -1;
ctk_widget_get_preferred_size (widget, &requisition, NULL);
ctk_widget_get_allocation (widget, &allocation);
allocation.width = requisition.width;
allocation.height = requisition.height;
ctk_widget_size_allocate (widget, &allocation);
}
static void
panel_toplevel_size_request (CtkWidget *widget,
CtkRequisition *requisition)
{
PanelToplevel *toplevel;
CtkBin *bin;
CtkWidget *child;
CdkRectangle old_geometry;
int position_changed = FALSE;
int size_changed = FALSE;
toplevel = PANEL_TOPLEVEL (widget);
bin = CTK_BIN (widget);
/* we get a size request when there are new monitors, so first try to
* see if we need to move to a new monitor */
panel_toplevel_update_monitor (toplevel);
child = ctk_bin_get_child (bin);
if (child && ctk_widget_get_visible (child))
ctk_widget_get_preferred_size (child, requisition, NULL);
old_geometry = toplevel->priv->geometry;
panel_toplevel_update_geometry (toplevel, requisition);
requisition->width = toplevel->priv->geometry.width;
requisition->height = toplevel->priv->geometry.height;
if (!ctk_widget_get_realized (widget))
return;
if (old_geometry.width != toplevel->priv->geometry.width ||
old_geometry.height != toplevel->priv->geometry.height)
size_changed = TRUE;
if (old_geometry.x != toplevel->priv->geometry.x ||
old_geometry.y != toplevel->priv->geometry.y)
position_changed = TRUE;
panel_toplevel_move_resize_window (toplevel, position_changed, size_changed);
}
static void
panel_toplevel_get_preferred_width (CtkWidget *widget,
gint *minimum_width,
gint *natural_width)
{
CtkRequisition req;
panel_toplevel_size_request (widget, &req);
*minimum_width = *natural_width = req.width;
}
static void
panel_toplevel_get_preferred_height (CtkWidget *widget,
gint *minimum_height,
gint *natural_height)
{
CtkRequisition req;
panel_toplevel_size_request (widget, &req);
*minimum_height = *natural_height = req.height;
}
static void
set_background_region (PanelToplevel *toplevel)
{
CtkWidget *widget;
CdkWindow *window;
gint origin_x;
gint origin_y;
CtkAllocation allocation;
CtkOrientation orientation;
widget = CTK_WIDGET (toplevel);
if (!ctk_widget_get_realized (widget))
return;
window = ctk_widget_get_window (widget);
origin_x = -1;
origin_y = -1;
cdk_window_get_origin (window, &origin_x, &origin_y);
ctk_widget_get_allocation (widget, &allocation);
orientation = CTK_ORIENTATION_HORIZONTAL;
if (toplevel->priv->orientation & PANEL_VERTICAL_MASK)
orientation = CTK_ORIENTATION_VERTICAL;
panel_background_change_region (&toplevel->background, orientation,
origin_x, origin_y,
allocation.width, allocation.height);
}
static void
panel_toplevel_size_allocate (CtkWidget *widget,
CtkAllocation *allocation)
{
PanelToplevel *toplevel = (PanelToplevel *) widget;
CtkBin *bin = (CtkBin *) widget;
CtkStyleContext *context;
CtkStateFlags state;
CtkBorder padding;
CtkWidget *child;
CtkAllocation challoc;
CtkAllocation child_allocation;
ctk_widget_set_allocation (widget, allocation);
if (toplevel->priv->expand ||
toplevel->priv->buttons_enabled ||
toplevel->priv->attached)
challoc = *allocation;
else {
if (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK) {
challoc.x = HANDLE_SIZE;
challoc.y = 0;
challoc.width = allocation->width - 2 * HANDLE_SIZE;
challoc.height = allocation->height;
} else {
challoc.x = 0;
challoc.y = HANDLE_SIZE;
challoc.width = allocation->width;
challoc.height = allocation->height - 2 * HANDLE_SIZE;
}
}
state = ctk_widget_get_state_flags (widget);
context = ctk_widget_get_style_context (widget);
ctk_style_context_get_padding (context, state, &padding);
if (toplevel->priv->edges & PANEL_EDGE_TOP) {
challoc.y += padding.top;
challoc.height -= padding.top;
}
if (toplevel->priv->edges & PANEL_EDGE_LEFT) {
challoc.x += padding.left;
challoc.width -= padding.left;
}
if (toplevel->priv->edges & PANEL_EDGE_BOTTOM)
challoc.height -= padding.bottom;
if (toplevel->priv->edges & PANEL_EDGE_RIGHT)
challoc.width -= padding.right;
challoc.width = MAX (1, challoc.width);
challoc.height = MAX (1, challoc.height);
child = ctk_bin_get_child (bin);
ctk_widget_get_allocation (child, &child_allocation);
if (ctk_widget_get_mapped (widget) &&
(challoc.x != child_allocation.x ||
challoc.y != child_allocation.y ||
challoc.width != child_allocation.width ||
challoc.height != child_allocation.height)) {
CtkAllocation allocation;
ctk_widget_get_allocation (widget, &allocation);
cdk_window_invalidate_rect (ctk_widget_get_window (widget), &allocation, FALSE);
}
if (child && ctk_widget_get_visible (child))
ctk_widget_size_allocate (child, &challoc);
set_background_region (toplevel);
}
static gboolean panel_toplevel_draw(CtkWidget* widget, cairo_t* cr)
{
PanelToplevel* toplevel = (PanelToplevel*) widget;
PanelFrameEdge edges;
gboolean retval = FALSE;
int awidth;
int aheight;
CtkStyleContext *context;
CtkStateFlags state;
CtkBorder padding;
if (!ctk_widget_is_drawable (widget))
return retval;
if (CTK_WIDGET_CLASS (panel_toplevel_parent_class)->draw)
retval = CTK_WIDGET_CLASS (panel_toplevel_parent_class)->draw (widget, cr);
edges = toplevel->priv->edges;
panel_frame_draw (widget, cr, edges);
if (toplevel->priv->expand ||
toplevel->priv->buttons_enabled ||
toplevel->priv->attached)
return retval;
state = ctk_widget_get_state_flags (widget);
awidth = ctk_widget_get_allocated_width (widget);
aheight = ctk_widget_get_allocated_height (widget);
context = ctk_widget_get_style_context (widget);
ctk_style_context_get_padding (context, state, &padding);
ctk_style_context_save (context);
ctk_style_context_set_state (context, state);
if (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK) {
int x, y, width, height;
x = 0;
y = 0;
height = aheight;
width = HANDLE_SIZE;
if (edges & PANEL_EDGE_TOP) {
y += padding.top;
height -= padding.top;
}
if (edges & PANEL_EDGE_BOTTOM)
height -= padding.bottom;
if (edges & PANEL_EDGE_LEFT)
x += padding.left;
cairo_save (cr);
ctk_render_handle (context, cr, x, y, width, height);
cairo_restore (cr);
x = awidth - HANDLE_SIZE;
if (edges & PANEL_EDGE_RIGHT)
x -= padding.right;
cairo_save (cr);
ctk_render_handle (context, cr, x, y, width, height);
cairo_restore (cr);
} else {
int x, y, width, height;
x = 0;
y = 0;
width = awidth;
height = HANDLE_SIZE;
if (edges & PANEL_EDGE_LEFT) {
x += padding.left;
width -= padding.left;
}
if (edges & PANEL_EDGE_RIGHT)
width -= padding.right;
if (edges & PANEL_EDGE_TOP)
y += padding.top;
cairo_save (cr);
ctk_render_handle (context, cr, x, y, width, height);
cairo_restore (cr);
y = aheight - HANDLE_SIZE;
if (edges & PANEL_EDGE_BOTTOM)
y -= padding.bottom;
cairo_save (cr);
ctk_render_handle (context, cr, x, y, width, height);
cairo_restore (cr);
}
ctk_style_context_restore (context);
return retval;
}
static gboolean
panel_toplevel_button_press_event (CtkWidget *widget,
CdkEventButton *event)
{
PanelToplevel *toplevel;
CtkWidget *event_widget;
g_return_val_if_fail (PANEL_IS_TOPLEVEL (widget), FALSE);
toplevel = PANEL_TOPLEVEL (widget);
if (event->button != 1 && event->button != 2)
return FALSE;
if (toplevel->priv->animating)
return FALSE;
/* Get the mouse-button modifier from croma so that only intentional
* moves are considered. We don't this for non-expanded panels since we
* only have the handles that the user can grab. */
if ((toplevel->priv->expand || toplevel->priv->attached) &&
(event->state & CDK_MODIFIER_MASK) != panel_bindings_get_mouse_button_modifier_keymask ())
return FALSE;
cdk_window_get_user_data (event->window, (gpointer)&event_widget);
g_assert (CTK_IS_WIDGET (event_widget));
ctk_widget_translate_coordinates (event_widget,
widget,
event->x,
event->y,
&toplevel->priv->drag_offset_x,
&toplevel->priv->drag_offset_y);
panel_toplevel_begin_grab_op (toplevel, PANEL_GRAB_OP_MOVE, FALSE, event->time);
return TRUE;
}
static gboolean
panel_toplevel_button_release_event (CtkWidget *widget,
CdkEventButton *event)
{
PanelToplevel *toplevel;
if (event->button != 1 && event->button != 2)
return FALSE;
toplevel = PANEL_TOPLEVEL (widget);
if (toplevel->priv->grab_op == PANEL_GRAB_OP_NONE)
return FALSE;
if (toplevel->priv->grab_is_keyboard)
return FALSE;
panel_toplevel_end_grab_op (toplevel, event->time);
return TRUE;
}
static gboolean
panel_toplevel_configure_event (CtkWidget *widget,
CdkEventConfigure *event)
{
PanelToplevel *toplevel;
toplevel = PANEL_TOPLEVEL (widget);
set_background_region (toplevel);
return TRUE;
}
static gboolean
panel_toplevel_key_press_event (CtkWidget *widget,
CdkEventKey *event)
{
PanelToplevel *toplevel = (PanelToplevel *) widget;
if (toplevel->priv->grab_op != PANEL_GRAB_OP_NONE &&
panel_toplevel_handle_grab_op_key_event (toplevel, event))
return TRUE;
if (CTK_WIDGET_CLASS (panel_toplevel_parent_class)->key_press_event)
return CTK_WIDGET_CLASS (panel_toplevel_parent_class)->key_press_event (widget, event);
return FALSE;
}
static void
panel_toplevel_state_flags_changed (CtkWidget *widget,
CtkStateFlags previous_state)
{
CTK_WIDGET_CLASS (panel_toplevel_parent_class)->state_flags_changed (widget,
previous_state);
set_background_default_style (widget);
}
static gboolean
panel_toplevel_motion_notify_event (CtkWidget *widget,
CdkEventMotion *event)
{
if (cdk_event_get_screen ((CdkEvent *)event) ==
ctk_window_get_screen (CTK_WINDOW (widget)))
return panel_toplevel_handle_grab_op_motion_event (
PANEL_TOPLEVEL (widget), event);
else
return FALSE;
}
static gboolean
panel_toplevel_animation_timeout (PanelToplevel *toplevel)
{
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
if (!toplevel->priv->animating) {
toplevel->priv->animation_end_x = 0xdead;
toplevel->priv->animation_end_y = 0xdead;
toplevel->priv->animation_end_width = 0xdead;
toplevel->priv->animation_end_height = 0xdead;
toplevel->priv->animation_start_time.tv_sec = 0xdead;
toplevel->priv->animation_start_time.tv_usec = 0xdead;
toplevel->priv->animation_end_time.tv_sec = 0xdead;
toplevel->priv->animation_end_time.tv_usec = 0xdead;
toplevel->priv->animation_timeout = 0;
toplevel->priv->initial_animation_done = TRUE;
}
return toplevel->priv->animating;
}
static long
panel_toplevel_get_animation_time (PanelToplevel *toplevel)
{
/* The number of seconds to complete the animation.
*/
#define ANIMATION_TIME_FAST 0.4
#define ANIMATION_TIME_MEDIUM 1.2
#define ANIMATION_TIME_SLOW 2.0
long t;
switch (toplevel->priv->animation_speed) {
case PANEL_ANIMATION_SLOW:
t = ANIMATION_TIME_SLOW * G_USEC_PER_SEC;
break;
case PANEL_ANIMATION_MEDIUM:
t = ANIMATION_TIME_MEDIUM * G_USEC_PER_SEC;
break;
case PANEL_ANIMATION_FAST:
t = ANIMATION_TIME_FAST * G_USEC_PER_SEC;
break;
default:
g_assert_not_reached ();
break;
}
return t;
#undef ANIMATION_TIME_FAST
#undef ANIMATION_TIME_MEDIUM
#undef ANIMATION_TIME_SLOW
}
static void
panel_toplevel_calculate_animation_end_geometry (PanelToplevel *toplevel)
{
CdkRectangle monitor_geom;
toplevel->priv->animation_end_x = toplevel->priv->x;
toplevel->priv->animation_end_y = toplevel->priv->y;
toplevel->priv->animation_end_width = -1;
toplevel->priv->animation_end_height = -1;
panel_toplevel_get_monitor_geometry (toplevel, &monitor_geom);
if (!toplevel->priv->expand) {
if (toplevel->priv->x_centered)
toplevel->priv->animation_end_x =
(monitor_geom.width - toplevel->priv->geometry.width) / 2;
if (toplevel->priv->y_centered)
toplevel->priv->animation_end_y =
(monitor_geom.height - toplevel->priv->geometry.height) / 2;
}
/* we consider the toplevels which are in the initial animation stage
* as in a normal state */
if (toplevel->priv->state == PANEL_STATE_NORMAL ||
(!toplevel->priv->initial_animation_done &&
!toplevel->priv->auto_hide))
panel_toplevel_update_normal_position (toplevel,
&toplevel->priv->animation_end_x,
&toplevel->priv->animation_end_y,
&toplevel->priv->animation_end_width,
&toplevel->priv->animation_end_height);
else if (toplevel->priv->state == PANEL_STATE_AUTO_HIDDEN)
panel_toplevel_update_auto_hide_position (toplevel,
&toplevel->priv->animation_end_x,
&toplevel->priv->animation_end_y,
&toplevel->priv->animation_end_width,
&toplevel->priv->animation_end_height,
TRUE);
else
panel_toplevel_update_hidden_position (toplevel,
&toplevel->priv->animation_end_x,
&toplevel->priv->animation_end_y,
&toplevel->priv->animation_end_width,
&toplevel->priv->animation_end_height);
}
static void
panel_toplevel_start_animation (PanelToplevel *toplevel)
{
CtkRequisition requisition;
int deltax, deltay, deltaw = 0, deltah = 0;
int cur_x = -1, cur_y = -1;
long t;
panel_toplevel_calculate_animation_end_geometry (toplevel);
toplevel->priv->animating = TRUE;
panel_toplevel_update_struts (toplevel, TRUE);
#ifdef HAVE_X11
if (CDK_IS_X11_DISPLAY (ctk_widget_get_display (CTK_WIDGET (toplevel)))) {
panel_struts_update_toplevel_geometry (toplevel,
&toplevel->priv->animation_end_x,
&toplevel->priv->animation_end_y,
&toplevel->priv->animation_end_width,
&toplevel->priv->animation_end_height);
}
#endif // HAVE_X11
panel_toplevel_update_struts (toplevel, FALSE);
cdk_window_get_origin (ctk_widget_get_window (CTK_WIDGET (toplevel)), &cur_x, &cur_y);
cur_x -= panel_multimonitor_x (toplevel->priv->monitor);
cur_y -= panel_multimonitor_y (toplevel->priv->monitor);
deltax = toplevel->priv->animation_end_x - cur_x;
deltay = toplevel->priv->animation_end_y - cur_y;
ctk_widget_get_preferred_size (CTK_WIDGET (toplevel), &requisition, NULL);
if (toplevel->priv->animation_end_width != -1)
deltaw = toplevel->priv->animation_end_width - requisition.width;
if (toplevel->priv->animation_end_height != -1)
deltah = toplevel->priv->animation_end_height - requisition.height;
if (deltax == 0 && deltay == 0 && deltaw == 0 && deltah == 0) {
toplevel->priv->animation_end_x = -1;
toplevel->priv->animation_end_y = -1;
toplevel->priv->animation_end_width = -1;
toplevel->priv->animation_end_height = -1;
toplevel->priv->animating = FALSE;
return;
}
if (toplevel->priv->attached) {
/* Re-map unmapped attached toplevels */
if (!ctk_widget_get_visible (CTK_WIDGET (toplevel)))
ctk_widget_set_visible (CTK_WIDGET (toplevel), TRUE);
if (!ctk_widget_get_mapped (CTK_WIDGET (toplevel)))
ctk_widget_map (CTK_WIDGET (toplevel));
ctk_window_present (CTK_WINDOW (toplevel->priv->attach_toplevel));
}
g_get_current_time (&toplevel->priv->animation_start_time);
t = panel_toplevel_get_animation_time (toplevel);
g_get_current_time (&toplevel->priv->animation_end_time);
g_time_val_add (&toplevel->priv->animation_end_time, t);
if (!toplevel->priv->animation_timeout)
toplevel->priv->animation_timeout =
g_timeout_add (20, (GSourceFunc) panel_toplevel_animation_timeout, toplevel);
}
void
panel_toplevel_hide (PanelToplevel *toplevel,
gboolean auto_hide,
CtkDirectionType direction)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
if (toplevel->priv->state != PANEL_STATE_NORMAL)
return;
g_signal_emit (toplevel, toplevel_signals [HIDE_SIGNAL], 0);
if (toplevel->priv->attach_toplevel)
panel_toplevel_pop_autohide_disabler (toplevel->priv->attach_toplevel);
if (auto_hide)
toplevel->priv->state = PANEL_STATE_AUTO_HIDDEN;
else {
if (direction == -1) {
if (toplevel->priv->orientation & PANEL_VERTICAL_MASK)
direction = CTK_DIR_UP;
else
direction = CTK_DIR_LEFT;
}
switch (direction) {
case CTK_DIR_UP:
g_return_if_fail (toplevel->priv->orientation & PANEL_VERTICAL_MASK);
toplevel->priv->state = PANEL_STATE_HIDDEN_UP;
break;
case CTK_DIR_DOWN:
g_return_if_fail (toplevel->priv->orientation & PANEL_VERTICAL_MASK);
toplevel->priv->state = PANEL_STATE_HIDDEN_DOWN;
break;
case CTK_DIR_LEFT:
g_return_if_fail (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK);
toplevel->priv->state = PANEL_STATE_HIDDEN_LEFT;
break;
case CTK_DIR_RIGHT:
g_return_if_fail (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK);
toplevel->priv->state = PANEL_STATE_HIDDEN_RIGHT;
break;
default:
g_assert_not_reached ();
break;
}
panel_toplevel_update_hide_buttons (toplevel);
}
if (toplevel->priv->anicafe && ctk_widget_get_realized (CTK_WIDGET (toplevel))) {
panel_toplevel_start_animation (toplevel);
}
/* if the toplevel is attached (-> drawer), hide it after the animation
* this hides the hide button properly as well */
if (toplevel->priv->attached) {
ctk_widget_hide (CTK_WIDGET (toplevel));
}
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
}
static gboolean
panel_toplevel_auto_hide_timeout_handler (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), FALSE);
if (panel_toplevel_get_autohide_disabled (toplevel)) {
toplevel->priv->hide_timeout = 0;
return FALSE;
}
/* keep coming back until the animation has finished.
* FIXME: we should really remove the timeout/idle
* completely and re-instate it when the
* animation has finished.
*/
if (toplevel->priv->animating)
return TRUE;
panel_toplevel_hide (toplevel, TRUE, -1);
toplevel->priv->hide_timeout = 0;
return FALSE;
}
void
panel_toplevel_unhide (PanelToplevel *toplevel)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
if (toplevel->priv->state == PANEL_STATE_NORMAL)
return;
toplevel->priv->state = PANEL_STATE_NORMAL;
panel_toplevel_update_hide_buttons (toplevel);
if (toplevel->priv->attach_toplevel)
panel_toplevel_push_autohide_disabler (toplevel->priv->attach_toplevel);
if (toplevel->priv->anicafe && ctk_widget_get_realized (CTK_WIDGET (toplevel))) {
panel_toplevel_start_animation (toplevel);
}
/* if the toplevel is attached (-> drawer), unhide it after the animation
* (same as for hide) */
if (toplevel->priv->attached) {
ctk_widget_show (CTK_WIDGET (toplevel));
}
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
if (!toplevel->priv->anicafe)
g_signal_emit (toplevel, toplevel_signals [UNHIDE_SIGNAL], 0);
}
static gboolean
panel_toplevel_auto_unhide_timeout_handler (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), FALSE);
/* keep coming back until the animation has finished.
* FIXME: we should really remove the timeout/idle
* completely and re-instate it when the
* animation has finished.
*/
if (toplevel->priv->animating)
return TRUE;
if (!toplevel->priv->anicafe)
toplevel->priv->initial_animation_done = TRUE;
/* initial animation for auto-hidden panels: we need to unhide and hide
* again to get at the right size */
if (!toplevel->priv->initial_animation_done &&
toplevel->priv->auto_hide) {
toplevel->priv->unhide_timeout = 0;
panel_toplevel_unhide (toplevel);
panel_toplevel_hide (toplevel, TRUE, -1);
return FALSE;
}
if (!panel_toplevel_contains_pointer (toplevel) &&
toplevel->priv->auto_hide) {
toplevel->priv->unhide_timeout = 0;
return FALSE;
}
panel_toplevel_unhide (toplevel);
toplevel->priv->unhide_timeout = 0;
return FALSE;
}
void
panel_toplevel_queue_auto_hide (PanelToplevel *toplevel)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
if (!toplevel->priv->auto_hide ||
panel_toplevel_contains_pointer (toplevel) ||
panel_toplevel_get_autohide_disabled (toplevel))
return;
if (toplevel->priv->unhide_timeout)
g_source_remove (toplevel->priv->unhide_timeout);
toplevel->priv->unhide_timeout = 0;
if (toplevel->priv->hide_timeout ||
toplevel->priv->state != PANEL_STATE_NORMAL)
return;
if (toplevel->priv->hide_delay > 0)
toplevel->priv->hide_timeout =
g_timeout_add (toplevel->priv->hide_delay,
(GSourceFunc) panel_toplevel_auto_hide_timeout_handler,
toplevel);
else
toplevel->priv->hide_timeout =
g_idle_add ((GSourceFunc) panel_toplevel_auto_hide_timeout_handler,
toplevel);
}
void
panel_toplevel_queue_auto_unhide (PanelToplevel *toplevel)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
if (toplevel->priv->unhide_timeout)
return;
if (toplevel->priv->hide_timeout)
g_source_remove (toplevel->priv->hide_timeout);
toplevel->priv->hide_timeout = 0;
if (toplevel->priv->state != PANEL_STATE_AUTO_HIDDEN)
return;
if (toplevel->priv->unhide_delay > 0)
toplevel->priv->unhide_timeout =
g_timeout_add (toplevel->priv->unhide_delay,
(GSourceFunc) panel_toplevel_auto_unhide_timeout_handler,
toplevel);
else
toplevel->priv->unhide_timeout =
g_idle_add ((GSourceFunc) panel_toplevel_auto_unhide_timeout_handler,
toplevel);
}
void
panel_toplevel_queue_initial_unhide (PanelToplevel *toplevel)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
if (toplevel->priv->initial_animation_done)
return;
if (toplevel->priv->unhide_timeout)
return;
toplevel->priv->unhide_timeout =
g_idle_add ((GSourceFunc) panel_toplevel_auto_unhide_timeout_handler,
toplevel);
}
static gboolean
panel_toplevel_enter_notify_event (CtkWidget *widget,
CdkEventCrossing *event)
{
PanelToplevel *toplevel;
g_return_val_if_fail (PANEL_IS_TOPLEVEL (widget), FALSE);
toplevel = PANEL_TOPLEVEL (widget);
if (toplevel->priv->auto_hide && event->detail != CDK_NOTIFY_INFERIOR)
panel_toplevel_queue_auto_unhide (toplevel);
if (CTK_WIDGET_CLASS (panel_toplevel_parent_class)->enter_notify_event)
return CTK_WIDGET_CLASS (panel_toplevel_parent_class)->enter_notify_event (widget, event);
return FALSE;
}
static gboolean
panel_toplevel_leave_notify_event (CtkWidget *widget,
CdkEventCrossing *event)
{
PanelToplevel *toplevel;
g_return_val_if_fail (PANEL_IS_TOPLEVEL (widget), FALSE);
toplevel = PANEL_TOPLEVEL (widget);
if (toplevel->priv->auto_hide && event->detail != CDK_NOTIFY_INFERIOR)
panel_toplevel_queue_auto_hide (toplevel);
if (CTK_WIDGET_CLASS (panel_toplevel_parent_class)->leave_notify_event)
return CTK_WIDGET_CLASS (panel_toplevel_parent_class)->leave_notify_event (widget, event);
return FALSE;
}
static gboolean
panel_toplevel_focus_in_event (CtkWidget *widget,
CdkEventFocus *event)
{
PanelToplevel *toplevel = PANEL_TOPLEVEL (widget);
if (toplevel->priv->state == PANEL_STATE_AUTO_HIDDEN)
panel_toplevel_unhide (toplevel);
if (CTK_WIDGET_CLASS (panel_toplevel_parent_class)->focus_in_event)
return CTK_WIDGET_CLASS (panel_toplevel_parent_class)->focus_in_event (widget, event);
return FALSE;
}
static gboolean
panel_toplevel_focus_out_event (CtkWidget *widget,
CdkEventFocus *event)
{
PanelToplevel *toplevel = PANEL_TOPLEVEL (widget);
/* It appears that sometimes we don't get a leave notify event,
but just a focus in/out, so queue the autohide in that case.
If the pointer is inside the panel then obviously we won't hide */
if (toplevel->priv->auto_hide)
panel_toplevel_queue_auto_hide (toplevel);
if (CTK_WIDGET_CLASS (panel_toplevel_parent_class)->focus_out_event)
return CTK_WIDGET_CLASS (panel_toplevel_parent_class)->focus_out_event (widget, event);
return FALSE;
}
static void
panel_toplevel_style_updated (CtkWidget *widget)
{
panel_toplevel_update_hide_buttons (PANEL_TOPLEVEL (widget));
if (CTK_WIDGET_CLASS (panel_toplevel_parent_class)->style_updated)
CTK_WIDGET_CLASS (panel_toplevel_parent_class)->style_updated (widget);
set_background_default_style (widget);
}
static void
panel_toplevel_drag_threshold_changed (PanelToplevel *toplevel)
{
int threshold;
threshold = 0;
g_object_get (G_OBJECT (toplevel->priv->ctk_settings),
"ctk-dnd-drag-threshold", &threshold,
NULL);
if (threshold)
toplevel->priv->snap_tolerance = threshold * SNAP_TOLERANCE_FACTOR;
}
static void
panel_toplevel_update_ctk_settings (PanelToplevel *toplevel)
{
if (toplevel->priv->ctk_settings)
g_signal_handlers_disconnect_by_func (toplevel->priv->ctk_settings,
G_CALLBACK (panel_toplevel_drag_threshold_changed),
toplevel);
toplevel->priv->ctk_settings = ctk_widget_get_settings (CTK_WIDGET (toplevel->priv->panel_widget));
g_signal_connect_swapped (G_OBJECT (toplevel->priv->ctk_settings),
"notify::ctk-dnd-drag-threshold",
G_CALLBACK (panel_toplevel_drag_threshold_changed),
toplevel);
panel_toplevel_drag_threshold_changed (toplevel);
}
static void
panel_toplevel_screen_changed (CtkWidget *widget,
CdkScreen *previous_screen)
{
panel_toplevel_update_ctk_settings (PANEL_TOPLEVEL (widget));
if (CTK_WIDGET_CLASS (panel_toplevel_parent_class)->screen_changed)
CTK_WIDGET_CLASS (panel_toplevel_parent_class)->screen_changed (widget, previous_screen);
ctk_widget_queue_resize (widget);
}
static void
panel_toplevel_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
PanelToplevel *toplevel;
g_return_if_fail (PANEL_IS_TOPLEVEL (object));
toplevel = PANEL_TOPLEVEL (object);
switch (prop_id) {
case PROP_NAME:
panel_toplevel_set_name (toplevel, g_value_get_string (value));
break;
case PROP_SETTINGS_PATH:
panel_toplevel_set_settings_path (toplevel, g_value_get_string (value));
break;
case PROP_EXPAND:
panel_toplevel_set_expand (toplevel, g_value_get_boolean (value));
break;
case PROP_ORIENTATION:
panel_toplevel_set_orientation (toplevel, g_value_get_enum (value));
break;
case PROP_SIZE:
panel_toplevel_set_size (toplevel, g_value_get_int (value));
break;
case PROP_X:
panel_toplevel_set_x (toplevel,
g_value_get_int (value),
toplevel->priv->x_right,
toplevel->priv->x_centered);
break;
case PROP_X_RIGHT:
panel_toplevel_set_x (toplevel,
toplevel->priv->x,
g_value_get_int (value),
toplevel->priv->x_centered);
break;
case PROP_X_CENTERED:
panel_toplevel_set_x (toplevel,
toplevel->priv->x,
toplevel->priv->x_right,
g_value_get_boolean (value));
break;
case PROP_Y:
panel_toplevel_set_y (toplevel,
g_value_get_int (value),
toplevel->priv->y_bottom,
toplevel->priv->y_centered);
break;
case PROP_Y_BOTTOM:
panel_toplevel_set_y (toplevel,
toplevel->priv->y,
g_value_get_int (value),
toplevel->priv->y_centered);
break;
case PROP_Y_CENTERED:
panel_toplevel_set_y (toplevel,
toplevel->priv->y,
toplevel->priv->y_bottom,
g_value_get_boolean (value));
break;
case PROP_MONITOR:
panel_toplevel_set_monitor (toplevel, g_value_get_int (value));
break;
case PROP_AUTOHIDE:
panel_toplevel_set_auto_hide (toplevel, g_value_get_boolean (value));
break;
case PROP_HIDE_DELAY:
panel_toplevel_set_hide_delay (toplevel, g_value_get_int (value));
break;
case PROP_UNHIDE_DELAY:
panel_toplevel_set_unhide_delay (toplevel, g_value_get_int (value));
break;
case PROP_AUTOHIDE_SIZE:
panel_toplevel_set_auto_hide_size (toplevel, g_value_get_int (value));
break;
case PROP_ANICAFE:
panel_toplevel_set_anicafe (toplevel, g_value_get_boolean (value));
break;
case PROP_ANIMATION_SPEED:
panel_toplevel_set_animation_speed (toplevel, g_value_get_enum (value));
break;
case PROP_BUTTONS_ENABLED:
panel_toplevel_set_enable_buttons (toplevel, g_value_get_boolean (value));
break;
case PROP_ARROWS_ENABLED:
panel_toplevel_set_enable_arrows (toplevel, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
panel_toplevel_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
PanelToplevel *toplevel;
g_return_if_fail (PANEL_IS_TOPLEVEL (object));
toplevel = PANEL_TOPLEVEL (object);
switch (prop_id) {
case PROP_NAME:
g_value_set_string (value, panel_toplevel_get_name (toplevel));
break;
case PROP_SETTINGS_PATH:
g_value_set_string (value, toplevel->priv->settings_path);
break;
case PROP_EXPAND:
g_value_set_boolean (value, toplevel->priv->expand);
break;
case PROP_ORIENTATION:
g_value_set_enum (value, toplevel->priv->orientation);
break;
case PROP_SIZE:
g_value_set_int (value, toplevel->priv->size);
break;
case PROP_X:
g_value_set_int (value, toplevel->priv->x);
break;
case PROP_X_RIGHT:
g_value_set_int (value, toplevel->priv->x_right);
break;
case PROP_X_CENTERED:
g_value_set_boolean (value, toplevel->priv->x_centered);
break;
case PROP_Y:
g_value_set_int (value, toplevel->priv->y);
break;
case PROP_Y_BOTTOM:
g_value_set_int (value, toplevel->priv->y_bottom);
break;
case PROP_Y_CENTERED:
g_value_set_boolean (value, toplevel->priv->y_centered);
break;
case PROP_MONITOR:
g_value_set_int (value, toplevel->priv->monitor);
break;
case PROP_AUTOHIDE:
g_value_set_boolean (value, toplevel->priv->auto_hide);
break;
case PROP_HIDE_DELAY:
g_value_set_int (value, toplevel->priv->hide_delay);
break;
case PROP_UNHIDE_DELAY:
g_value_set_int (value, toplevel->priv->unhide_delay);
break;
case PROP_AUTOHIDE_SIZE:
g_value_set_int (value, toplevel->priv->auto_hide_size);
break;
case PROP_ANICAFE:
g_value_set_boolean (value, toplevel->priv->anicafe);
break;
case PROP_ANIMATION_SPEED:
g_value_set_enum (value, toplevel->priv->animation_speed);
break;
case PROP_BUTTONS_ENABLED:
g_value_set_boolean (value, toplevel->priv->buttons_enabled);
break;
case PROP_ARROWS_ENABLED:
g_value_set_boolean (value, toplevel->priv->arrows_enabled);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static GObject*
panel_toplevel_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties)
{
GObject *object;
object = G_OBJECT_CLASS (panel_toplevel_parent_class)->constructor (type,
n_construct_properties,
construct_properties);
PanelToplevel *toplevel = PANEL_TOPLEVEL(object);
CdkScreen *screen = ctk_widget_get_screen(CTK_WIDGET(toplevel));
CdkVisual *visual = cdk_screen_get_rgba_visual(screen);
ctk_widget_set_visual(CTK_WIDGET(toplevel), visual);
return object;
}
static void
panel_toplevel_finalize (GObject *object)
{
PanelToplevel *toplevel = (PanelToplevel *) object;
#ifdef HAVE_X11
if (CDK_IS_X11_DISPLAY (ctk_widget_get_display (CTK_WIDGET (toplevel))))
panel_struts_unregister_strut (toplevel);
#endif // HAVE_X11
toplevel_list = g_slist_remove (toplevel_list, toplevel);
G_OBJECT_CLASS (panel_toplevel_parent_class)->finalize (object);
}
static void
panel_toplevel_class_init (PanelToplevelClass *klass)
{
GObjectClass *gobject_class = (GObjectClass *) klass;
CtkWidgetClass *widget_class = (CtkWidgetClass *) klass;
CtkContainerClass *container_class = (CtkContainerClass *) klass;
CtkBindingSet *binding_set;
binding_set = ctk_binding_set_by_class (klass);
gobject_class->constructor = panel_toplevel_constructor;
gobject_class->set_property = panel_toplevel_set_property;
gobject_class->get_property = panel_toplevel_get_property;
gobject_class->finalize = panel_toplevel_finalize;
gobject_class->dispose = panel_toplevel_dispose;
widget_class->realize = panel_toplevel_realize;
widget_class->unrealize = panel_toplevel_unrealize;
widget_class->state_flags_changed = panel_toplevel_state_flags_changed;
widget_class->draw = panel_toplevel_draw;
widget_class->get_preferred_width = panel_toplevel_get_preferred_width;
widget_class->get_preferred_height = panel_toplevel_get_preferred_height;
widget_class->style_updated = panel_toplevel_style_updated;
widget_class->size_allocate = panel_toplevel_size_allocate;
widget_class->button_press_event = panel_toplevel_button_press_event;
widget_class->button_release_event = panel_toplevel_button_release_event;
widget_class->configure_event = panel_toplevel_configure_event;
widget_class->key_press_event = panel_toplevel_key_press_event;
widget_class->motion_notify_event = panel_toplevel_motion_notify_event;
widget_class->enter_notify_event = panel_toplevel_enter_notify_event;
widget_class->leave_notify_event = panel_toplevel_leave_notify_event;
widget_class->screen_changed = panel_toplevel_screen_changed;
widget_class->focus_in_event = panel_toplevel_focus_in_event;
widget_class->focus_out_event = panel_toplevel_focus_out_event;
ctk_widget_class_set_css_name (widget_class, "PanelToplevel");
container_class->check_resize = panel_toplevel_check_resize;
klass->hiding = NULL;
klass->unhiding = NULL;
klass->popup_panel_menu = panel_toplevel_popup_panel_menu;
klass->toggle_expand = panel_toplevel_toggle_expand;
klass->expand = panel_toplevel_expand;
klass->unexpand = panel_toplevel_unexpand;
klass->toggle_hidden = panel_toplevel_toggle_hidden;
klass->begin_move = panel_toplevel_begin_move;
klass->begin_resize = panel_toplevel_begin_resize;
g_object_class_install_property (
gobject_class,
PROP_NAME,
g_param_spec_string (
"name",
"Name",
"The name of this panel",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_SETTINGS_PATH,
g_param_spec_string (
"settings-path",
"GSettings path",
"The GSettings path used for this panel",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_EXPAND,
g_param_spec_boolean (
"expand",
"Expand",
"Expand to take up the full monitor width/height",
TRUE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_ORIENTATION,
g_param_spec_enum (
"orientation",
"Orientation",
"The orientation of the panel",
PANEL_TYPE_ORIENTATION,
PANEL_ORIENTATION_TOP,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_SIZE,
g_param_spec_int (
"size",
"Size",
"The height (or width when vertical) of the panel",
0,
G_MAXINT,
DEFAULT_SIZE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_X,
g_param_spec_int (
"x",
"X position",
"The X position of the panel",
0,
G_MAXINT,
0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_X_RIGHT,
g_param_spec_int (
"x-right",
"X position, from the right",
"The X position of the panel, starting from the right of the screen",
-1,
G_MAXINT,
-1,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_X_CENTERED,
g_param_spec_boolean (
"x-centered",
"X centered",
"The x co-ordinate is relative to center screen",
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_Y,
g_param_spec_int (
"y",
"Y position",
"The Y position of the panel",
0,
G_MAXINT,
0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_Y_BOTTOM,
g_param_spec_int (
"y_bottom",
"Y position, from the bottom",
"The Y position of the panel, starting from the bottom of the screen",
-1,
G_MAXINT,
-1,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_Y_CENTERED,
g_param_spec_boolean (
"y-centered",
"Y centered",
"The y co-ordinate is relative to center screen",
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_MONITOR,
g_param_spec_int (
"monitor",
"Xinerama monitor",
"The monitor (in terms of Xinerama) which the panel is on",
0,
G_MAXINT,
0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_AUTOHIDE,
g_param_spec_boolean (
"auto-hide",
"Auto hide",
"Automatically hide the panel when the mouse leaves the panel",
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_HIDE_DELAY,
g_param_spec_int (
"hide-delay",
"Hide delay",
"The number of milliseconds to delay before automatically hiding",
0,
G_MAXINT,
DEFAULT_HIDE_DELAY,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_UNHIDE_DELAY,
g_param_spec_int (
"unhide-delay",
"Un-hide delay",
"The number of milliseconds to delay before automatically un-hiding",
0,
G_MAXINT,
DEFAULT_UNHIDE_DELAY,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_AUTOHIDE_SIZE,
g_param_spec_int (
"auto-hide-size",
"Auto-hide size",
"The number of pixels visible when the panel has been automatically hidden",
1,
G_MAXINT,
DEFAULT_AUTO_HIDE_SIZE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_ANICAFE,
g_param_spec_boolean (
"anicafe",
"Anicafe",
"Enable hiding/showing animations",
TRUE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_ANIMATION_SPEED,
g_param_spec_enum (
"animation-speed",
"Animation Speed",
"The speed at which to anicafe panel hiding/showing",
PANEL_TYPE_ANIMATION_SPEED,
PANEL_ANIMATION_MEDIUM,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_BUTTONS_ENABLED,
g_param_spec_boolean (
"buttons-enabled",
"Buttons Enabled",
"Enable hide/show buttons",
TRUE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (
gobject_class,
PROP_ARROWS_ENABLED,
g_param_spec_boolean (
"arrows-enabled",
"Arrows Enabled",
"Enable arrows on hide/show buttons",
TRUE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
ctk_widget_class_install_style_property (
widget_class,
g_param_spec_int (
"arrow-size",
"Arrow Size",
"The size of the arrows on the hide/show buttons",
0,
G_MAXINT,
DEFAULT_ARROW_SIZE,
G_PARAM_READABLE));
toplevel_signals [HIDE_SIGNAL] =
g_signal_new ("hiding",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (PanelToplevelClass, hiding),
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
toplevel_signals [UNHIDE_SIGNAL] =
g_signal_new ("unhiding",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (PanelToplevelClass, unhiding),
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
toplevel_signals [POPUP_PANEL_MENU_SIGNAL] =
g_signal_new ("popup-panel-menu",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (PanelToplevelClass, popup_panel_menu),
NULL,
NULL,
panel_marshal_BOOLEAN__VOID,
G_TYPE_BOOLEAN,
0);
toplevel_signals [TOGGLE_EXPAND_SIGNAL] =
g_signal_new ("toggle-expand",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (PanelToplevelClass, toggle_expand),
NULL,
NULL,
panel_marshal_BOOLEAN__VOID,
G_TYPE_BOOLEAN,
0);
toplevel_signals [EXPAND_SIGNAL] =
g_signal_new ("expand",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (PanelToplevelClass, expand),
NULL,
NULL,
panel_marshal_BOOLEAN__VOID,
G_TYPE_BOOLEAN,
0);
toplevel_signals [UNEXPAND_SIGNAL] =
g_signal_new ("unexpand",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (PanelToplevelClass, unexpand),
NULL,
NULL,
panel_marshal_BOOLEAN__VOID,
G_TYPE_BOOLEAN,
0);
toplevel_signals [TOGGLE_HIDDEN_SIGNAL] =
g_signal_new ("toggle-hidden",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (PanelToplevelClass, toggle_hidden),
NULL,
NULL,
panel_marshal_BOOLEAN__VOID,
G_TYPE_BOOLEAN,
0);
toplevel_signals [BEGIN_MOVE_SIGNAL] =
g_signal_new ("begin-move",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (PanelToplevelClass, begin_move),
NULL,
NULL,
panel_marshal_BOOLEAN__VOID,
G_TYPE_BOOLEAN,
0);
toplevel_signals [BEGIN_RESIZE_SIGNAL] =
g_signal_new ("begin-resize",
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (PanelToplevelClass, begin_resize),
NULL,
NULL,
panel_marshal_BOOLEAN__VOID,
G_TYPE_BOOLEAN,
0);
ctk_binding_entry_add_signal (binding_set, CDK_KEY_F10, CDK_CONTROL_MASK,
"popup_panel_menu", 0);
panel_bindings_set_entries (binding_set);
}
static void
panel_toplevel_setup_widgets (PanelToplevel *toplevel)
{
CtkWidget* container;
toplevel->priv->grid = ctk_grid_new ();
toplevel->priv->hide_button_top = panel_toplevel_add_hide_button (toplevel, CTK_ARROW_UP, 1, 0);
toplevel->priv->hide_button_bottom = panel_toplevel_add_hide_button (toplevel, CTK_ARROW_DOWN, 1, 2);
toplevel->priv->hide_button_left = panel_toplevel_add_hide_button (toplevel, CTK_ARROW_LEFT, 0, 1);
toplevel->priv->hide_button_right = panel_toplevel_add_hide_button (toplevel, CTK_ARROW_RIGHT, 2, 1);
if (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK)
{
ctk_widget_show(toplevel->priv->hide_button_left);
ctk_widget_show(toplevel->priv->hide_button_right);
}
else
{
ctk_widget_show(toplevel->priv->hide_button_top);
ctk_widget_show(toplevel->priv->hide_button_bottom);
}
toplevel->priv->inner_frame = g_object_new(PANEL_TYPE_FRAME, NULL);
ctk_widget_set_hexpand (CTK_WIDGET (toplevel->priv->inner_frame), TRUE);
ctk_widget_set_vexpand (CTK_WIDGET (toplevel->priv->inner_frame), TRUE);
ctk_grid_attach (CTK_GRID (toplevel->priv->grid), CTK_WIDGET (toplevel->priv->inner_frame), 1, 1, 1, 1);
ctk_widget_show (CTK_WIDGET (toplevel->priv->inner_frame));
container = panel_widget_new (toplevel,
!toplevel->priv->expand,
(toplevel->priv->orientation & PANEL_HORIZONTAL_MASK) ?
CTK_ORIENTATION_HORIZONTAL :
CTK_ORIENTATION_VERTICAL,
toplevel->priv->size);
toplevel->priv->panel_widget = PANEL_WIDGET(container);
ctk_container_add(CTK_CONTAINER(toplevel->priv->inner_frame), container);
ctk_widget_show(container);
ctk_container_add (CTK_CONTAINER (toplevel), toplevel->priv->grid);
ctk_widget_show (toplevel->priv->grid);
}
static void
background_changed (PanelBackground *background,
PanelToplevel *toplevel)
{
panel_toplevel_update_edges (toplevel);
panel_widget_emit_background_changed (toplevel->priv->panel_widget);
}
static void
panel_toplevel_init (PanelToplevel *toplevel)
{
CtkWidget *widget;
int i;
toplevel->priv = panel_toplevel_get_instance_private (toplevel);
toplevel->priv->expand = TRUE;
toplevel->priv->orientation = PANEL_ORIENTATION_BOTTOM;
toplevel->priv->size = DEFAULT_SIZE;
toplevel->priv->scale = ctk_widget_get_scale_factor (CTK_WIDGET (toplevel));
toplevel->priv->x = 0;
toplevel->priv->y = 0;
toplevel->priv->x_right = -1;
toplevel->priv->y_bottom = -1;
toplevel->priv->monitor = 0;
toplevel->priv->configured_monitor = -1;
toplevel->priv->hide_delay = DEFAULT_HIDE_DELAY;
toplevel->priv->unhide_delay = DEFAULT_UNHIDE_DELAY;
toplevel->priv->auto_hide_size = DEFAULT_AUTO_HIDE_SIZE;
toplevel->priv->animation_speed = PANEL_ANIMATION_FAST;
toplevel->priv->snap_tolerance = DEFAULT_DND_THRESHOLD * SNAP_TOLERANCE_FACTOR;
toplevel->priv->ctk_settings = NULL;
toplevel->priv->state = PANEL_STATE_NORMAL;
toplevel->priv->name = NULL;
toplevel->priv->description = NULL;
toplevel->priv->hide_timeout = 0;
toplevel->priv->unhide_timeout = 0;
toplevel->priv->geometry.x = -1;
toplevel->priv->geometry.y = -1;
toplevel->priv->geometry.width = -1;
toplevel->priv->geometry.height = -1;
toplevel->priv->original_width = -1;
toplevel->priv->original_height = -1;
toplevel->priv->grab_op = PANEL_GRAB_OP_NONE;
toplevel->priv->drag_offset_x = 0;
toplevel->priv->drag_offset_y = 0;
toplevel->priv->animation_end_x = 0;
toplevel->priv->animation_end_y = 0;
toplevel->priv->animation_end_width = 0;
toplevel->priv->animation_end_height = 0;
toplevel->priv->animation_start_time.tv_sec = 0;
toplevel->priv->animation_start_time.tv_usec = 0;
toplevel->priv->animation_end_time.tv_sec = 0;
toplevel->priv->animation_end_time.tv_usec = 0;
toplevel->priv->animation_timeout = 0;
toplevel->priv->panel_widget = NULL;
toplevel->priv->inner_frame = NULL;
toplevel->priv->grid = NULL;
toplevel->priv->hide_button_top = NULL;
toplevel->priv->hide_button_bottom = NULL;
toplevel->priv->hide_button_left = NULL;
toplevel->priv->hide_button_right = NULL;
toplevel->priv->attach_toplevel = NULL;
toplevel->priv->attach_widget = NULL;
toplevel->priv->n_autohide_disablers = 0;
for (i = 0; i < N_ATTACH_TOPLEVEL_SIGNALS; i++)
toplevel->priv->attach_toplevel_signals [i] = 0;
for (i = 0; i < N_ATTACH_WIDGET_SIGNALS; i++)
toplevel->priv->attach_widget_signals [i] = 0;
toplevel->priv->auto_hide = FALSE;
toplevel->priv->buttons_enabled = TRUE;
toplevel->priv->arrows_enabled = TRUE;
toplevel->priv->x_centered = FALSE;
toplevel->priv->y_centered = FALSE;
toplevel->priv->animating = FALSE;
toplevel->priv->grab_is_keyboard = FALSE;
toplevel->priv->position_centered = FALSE;
toplevel->priv->attached = FALSE;
toplevel->priv->attach_hidden = FALSE;
toplevel->priv->updated_geometry_initial = FALSE;
toplevel->priv->initial_animation_done = FALSE;
widget = CTK_WIDGET (toplevel);
ctk_widget_add_events (widget,
CDK_BUTTON_PRESS_MASK |
CDK_BUTTON_RELEASE_MASK |
CDK_POINTER_MOTION_MASK |
CDK_ENTER_NOTIFY_MASK |
CDK_LEAVE_NOTIFY_MASK);
ctk_widget_set_app_paintable (widget, TRUE);
panel_toplevel_setup_widgets (toplevel);
panel_toplevel_update_description (toplevel);
panel_toplevel_update_ctk_settings (toplevel);
toplevel_list = g_slist_prepend (toplevel_list, toplevel);
/* Prevent the window from being deleted via Alt+F4 by accident. This
* happens with "alternative" window managers such as Sawfish or XFWM4.
*/
g_signal_connect(CTK_WIDGET(toplevel), "delete-event", G_CALLBACK(ctk_true), NULL);
panel_background_init (&toplevel->background,
(PanelBackgroundChangedNotify) background_changed,
toplevel);
update_style_classes (toplevel);
#ifdef HAVE_WAYLAND
if (CDK_IS_WAYLAND_DISPLAY (cdk_display_get_default ())) {
wayland_panel_toplevel_init (toplevel);
}
#endif // HAVE_WAYLAND
}
PanelWidget *
panel_toplevel_get_panel_widget (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), NULL);
return toplevel->priv->panel_widget;
}
static void
panel_toplevel_update_name (PanelToplevel *toplevel)
{
char *title;
g_assert (toplevel->priv->description != NULL);
title = toplevel->priv->name ? toplevel->priv->name : toplevel->priv->description;
ctk_window_set_title (CTK_WINDOW (toplevel), title);
panel_a11y_set_atk_name_desc (
CTK_WIDGET (toplevel),
title, toplevel->priv->description);
}
void
panel_toplevel_set_name (PanelToplevel *toplevel,
const char *name)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
if (!toplevel->priv->name && (!name || !name [0]))
return;
if (toplevel->priv->name && name && name [0] &&
!strcmp (toplevel->priv->name, name))
return;
if (toplevel->priv->name)
g_free (toplevel->priv->name);
toplevel->priv->name = NULL;
if (name && name [0])
toplevel->priv->name = g_strdup (name);
panel_toplevel_update_name (toplevel);
g_object_notify (G_OBJECT (toplevel), "name");
}
void
panel_toplevel_set_settings_path (PanelToplevel *toplevel,
const char *settings_path)
{
toplevel->priv->settings_path = g_strdup (settings_path);
}
const char* panel_toplevel_get_name(PanelToplevel* toplevel)
{
g_return_val_if_fail(PANEL_IS_TOPLEVEL(toplevel), NULL);
return toplevel->priv->name;
}
const char* panel_toplevel_get_description(PanelToplevel* toplevel)
{
g_return_val_if_fail(PANEL_IS_TOPLEVEL(toplevel), NULL);
return toplevel->priv->description;
}
void
panel_toplevel_set_expand (PanelToplevel *toplevel,
gboolean expand)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
if (toplevel->priv->attached && expand) {
g_warning ("attempt to expand attached toplevel; ignoring");
return;
}
expand = expand != FALSE;
if (toplevel->priv->expand == expand)
return;
toplevel->priv->expand = expand;
if (!toplevel->priv->expand && toplevel->priv->updated_geometry_initial) {
switch (toplevel->priv->orientation) {
case PANEL_ORIENTATION_TOP:
panel_toplevel_set_x (toplevel, 0, -1, TRUE);
break;
case PANEL_ORIENTATION_BOTTOM:
panel_toplevel_set_x (toplevel, 0, 0, TRUE);
break;
case PANEL_ORIENTATION_LEFT:
panel_toplevel_set_y (toplevel, 0, -1, TRUE);
break;
case PANEL_ORIENTATION_RIGHT:
panel_toplevel_set_y (toplevel, 0, 0, TRUE);
break;
default:
g_assert_not_reached ();
break;
}
}
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
panel_widget_set_packed (toplevel->priv->panel_widget, !toplevel->priv->expand);
g_object_notify (G_OBJECT (toplevel), "expand");
}
gboolean
panel_toplevel_get_expand (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), TRUE);
return toplevel->priv->expand;
}
gboolean
panel_toplevel_get_is_floating (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), TRUE);
return toplevel->priv->floating;
}
void
panel_toplevel_set_orientation (PanelToplevel *toplevel,
PanelOrientation orientation)
{
gboolean rotate;
CdkRectangle monitor_geom;
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
if (toplevel->priv->orientation == orientation)
return;
g_object_freeze_notify (G_OBJECT (toplevel));
panel_toplevel_get_monitor_geometry (toplevel, &monitor_geom);
/* Un-snap from center if no longer along screen edge */
if (toplevel->priv->x_centered &&
(orientation & PANEL_VERTICAL_MASK)) {
toplevel->priv->x_centered = FALSE;
toplevel->priv->x = (monitor_geom.width - toplevel->priv->geometry.width) / 2;
g_object_notify (G_OBJECT (toplevel), "x");
g_object_notify (G_OBJECT (toplevel), "x-centered");
if (toplevel->priv->x_right != -1) {
toplevel->priv->x_right = -1;
g_object_notify (G_OBJECT (toplevel), "x-right");
}
}
if (toplevel->priv->y_centered &&
(orientation & PANEL_HORIZONTAL_MASK)) {
toplevel->priv->y_centered = FALSE;
toplevel->priv->y = (monitor_geom.height - toplevel->priv->geometry.height) / 2;
g_object_notify (G_OBJECT (toplevel), "y");
g_object_notify (G_OBJECT (toplevel), "y-centered");
if (toplevel->priv->y_bottom != -1) {
toplevel->priv->y_bottom = -1;
g_object_notify (G_OBJECT (toplevel), "y-bottom");
}
}
rotate = FALSE;
if ((orientation & PANEL_HORIZONTAL_MASK) &&
(toplevel->priv->orientation & PANEL_VERTICAL_MASK))
rotate = TRUE;
else if ((orientation & PANEL_VERTICAL_MASK) &&
(toplevel->priv->orientation & PANEL_HORIZONTAL_MASK))
rotate = TRUE;
/* rotate around the center */
if (rotate && !toplevel->priv->position_centered && !toplevel->priv->expand &&
toplevel->priv->updated_geometry_initial) {
toplevel->priv->position_centered = TRUE;
/* x, y temporary refer to the panel center, so we don't care
* about x_right, y_bottom. Those will get updated in
* panel_toplevel_update_position() accordingly. */
if (!toplevel->priv->x_centered) {
toplevel->priv->x += toplevel->priv->geometry.width / 2;
g_object_notify (G_OBJECT (toplevel), "x");
}
if (!toplevel->priv->y_centered) {
toplevel->priv->y += toplevel->priv->geometry.height / 2;
g_object_notify (G_OBJECT (toplevel), "y");
}
}
toplevel->priv->orientation = orientation;
update_style_classes (toplevel);
ctk_widget_reset_style (CTK_WIDGET (toplevel));
panel_toplevel_update_hide_buttons (toplevel);
panel_widget_set_orientation (
toplevel->priv->panel_widget,
(toplevel->priv->orientation & PANEL_HORIZONTAL_MASK) ?
CTK_ORIENTATION_HORIZONTAL :
CTK_ORIENTATION_VERTICAL);
switch (toplevel->priv->state) {
case PANEL_STATE_HIDDEN_UP:
if (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK)
toplevel->priv->state = PANEL_STATE_HIDDEN_LEFT;
break;
case PANEL_STATE_HIDDEN_DOWN:
if (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK)
toplevel->priv->state = PANEL_STATE_HIDDEN_RIGHT;
break;
case PANEL_STATE_HIDDEN_LEFT:
if (toplevel->priv->orientation & PANEL_VERTICAL_MASK)
toplevel->priv->state = PANEL_STATE_HIDDEN_UP;
break;
case PANEL_STATE_HIDDEN_RIGHT:
if (toplevel->priv->orientation & PANEL_VERTICAL_MASK)
toplevel->priv->state = PANEL_STATE_HIDDEN_DOWN;
break;
default:
break;
}
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
g_object_notify (G_OBJECT (toplevel), "orientation");
g_object_thaw_notify (G_OBJECT (toplevel));
#ifdef HAVE_WAYLAND
if (CDK_IS_WAYLAND_DISPLAY (ctk_widget_get_display (CTK_WIDGET (toplevel)))) {
wayland_panel_toplevel_update_placement (toplevel);
}
#endif // HAVE_WAYLAND
}
PanelOrientation
panel_toplevel_get_orientation (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), CTK_ORIENTATION_HORIZONTAL);
return toplevel->priv->orientation;
}
void
panel_toplevel_set_size (PanelToplevel *toplevel,
int size)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
g_return_if_fail (size >= 0);
if (toplevel->priv->size == size)
return;
toplevel->priv->size = size;
panel_widget_set_size (toplevel->priv->panel_widget, toplevel->priv->size);
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
panel_toplevel_update_hide_buttons (toplevel);
g_object_notify (G_OBJECT (toplevel), "size");
}
int
panel_toplevel_get_size (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), DEFAULT_SIZE);
return toplevel->priv->size;
}
void
panel_toplevel_set_auto_hide_size (PanelToplevel *toplevel,
int auto_hide_size)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
if (toplevel->priv->auto_hide_size == auto_hide_size)
return;
toplevel->priv->auto_hide_size = auto_hide_size;
if (toplevel->priv->state == PANEL_STATE_AUTO_HIDDEN) {
if (panel_toplevel_update_struts (toplevel, FALSE)) {
if (toplevel->priv->anicafe) {
panel_toplevel_unhide (toplevel);
panel_toplevel_hide (toplevel, TRUE, -1);
} else
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
}
}
g_object_notify (G_OBJECT (toplevel), "auto-hide-size");
}
int
panel_toplevel_get_auto_hide_size (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), DEFAULT_AUTO_HIDE_SIZE);
return toplevel->priv->auto_hide_size;
}
void
panel_toplevel_set_x (PanelToplevel *toplevel,
int x,
int x_right,
gboolean x_centered)
{
gboolean changed = FALSE;
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
x_centered = x_centered != FALSE;
g_object_freeze_notify (G_OBJECT (toplevel));
if (toplevel->priv->x != x) {
toplevel->priv->x = x;
changed = TRUE;
g_object_notify (G_OBJECT (toplevel), "x");
}
if (toplevel->priv->x_right != x_right) {
toplevel->priv->x_right = x_right;
changed = TRUE;
g_object_notify (G_OBJECT (toplevel), "x-right");
}
if (toplevel->priv->x_centered != x_centered) {
toplevel->priv->x_centered = x_centered;
changed = TRUE;
g_object_notify (G_OBJECT (toplevel), "x-centered");
}
if (changed)
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
g_object_thaw_notify (G_OBJECT (toplevel));
}
void
panel_toplevel_set_y (PanelToplevel *toplevel,
int y,
int y_bottom,
gboolean y_centered)
{
gboolean changed = FALSE;
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
y_centered = y_centered != FALSE;
g_object_freeze_notify (G_OBJECT (toplevel));
if (toplevel->priv->y != y) {
toplevel->priv->y = y;
changed = TRUE;
g_object_notify (G_OBJECT (toplevel), "y");
}
if (toplevel->priv->y_bottom != y_bottom) {
toplevel->priv->y_bottom = y_bottom;
changed = TRUE;
g_object_notify (G_OBJECT (toplevel), "y-bottom");
}
if (toplevel->priv->y_centered != y_centered) {
toplevel->priv->y_centered = y_centered;
changed = TRUE;
g_object_notify (G_OBJECT (toplevel), "y-centered");
}
if (changed)
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
g_object_thaw_notify (G_OBJECT (toplevel));
}
void
panel_toplevel_get_position (PanelToplevel *toplevel,
int *x,
int *x_right,
int *y,
int *y_bottom)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
if (x)
*x = toplevel->priv->x;
if (y)
*y = toplevel->priv->y;
if (x_right)
*x_right = toplevel->priv->x_right;
if (y_bottom)
*y_bottom = toplevel->priv->y_bottom;
}
gboolean
panel_toplevel_get_x_centered (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), FALSE);
return toplevel->priv->x_centered;
}
gboolean
panel_toplevel_get_y_centered (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), FALSE);
return toplevel->priv->y_centered;
}
/**
* panel_toplevel_set_monitor_internal:
*
* Sets the monitor of the toplevel, but only the internal state. We need to
* make the difference between the internal state and the configuration of the
* user because internal constraints might affect the monitor of the toplevel.
*
* panel_toplevel_set_monitor_internal() won't update the configuration of the
* user.
**/
static void
panel_toplevel_set_monitor_internal (PanelToplevel *toplevel,
int monitor,
gboolean force_resize)
{
if (toplevel->priv->monitor == monitor)
return;
toplevel->priv->monitor = monitor;
if (force_resize)
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
}
/**
* panel_toplevel_update_monitor:
*
* Moves the toplevel to its configured monitor or the first one, if needed.
* This generally happens when the configured monitor was non-existing before,
* and it appeared at runtime, or if it was existing and disappeared.
*
* This must only be called at the beginning of the size request of the
* toplevel because it doesn't queue a size request.
**/
static void
panel_toplevel_update_monitor (PanelToplevel *toplevel)
{
/* If we were not using the configured monitor, can we use it now? */
if ((toplevel->priv->configured_monitor != -1) &&
(toplevel->priv->configured_monitor != toplevel->priv->monitor) &&
toplevel->priv->configured_monitor < panel_multimonitor_monitors ()) {
panel_toplevel_set_monitor_internal (toplevel,
toplevel->priv->configured_monitor,
FALSE);
/* else, can we still use the monitor we were using? */
} else if (toplevel->priv->monitor >= panel_multimonitor_monitors ()) {
panel_toplevel_set_monitor_internal (toplevel,
0,
FALSE);
}
}
void
panel_toplevel_set_monitor (PanelToplevel *toplevel,
int monitor)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
if (toplevel->priv->configured_monitor == monitor)
return;
toplevel->priv->configured_monitor = monitor;
/* Only use the configured monitor if it's existing. Else, we ignore
* the non-existing monitor, and keep the old one. The main use case is
* when logging in after having used a multimonitor environment.
* We will put the panel on the monitor 0 for this session, and it will
* move back to the right monitor next time. */
if (monitor < panel_multimonitor_monitors ())
panel_toplevel_set_monitor_internal (toplevel, monitor, TRUE);
g_object_notify (G_OBJECT (toplevel), "monitor");
}
int
panel_toplevel_get_monitor (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), -1);
return toplevel->priv->monitor;
}
void
panel_toplevel_set_auto_hide (PanelToplevel *toplevel,
gboolean auto_hide)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
auto_hide = auto_hide != FALSE;
if (toplevel->priv->auto_hide == auto_hide)
return;
toplevel->priv->auto_hide = auto_hide;
if (toplevel->priv->auto_hide)
panel_toplevel_queue_auto_hide (toplevel);
else
panel_toplevel_queue_auto_unhide (toplevel);
if (panel_toplevel_update_struts (toplevel, FALSE))
ctk_widget_queue_resize (CTK_WIDGET (toplevel));
g_object_notify (G_OBJECT (toplevel), "auto-hide");
}
gboolean
panel_toplevel_get_auto_hide (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), FALSE);
return toplevel->priv->auto_hide;
}
void
panel_toplevel_set_hide_delay (PanelToplevel *toplevel,
int hide_delay)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
if (toplevel->priv->hide_delay == hide_delay)
return;
toplevel->priv->hide_delay = hide_delay;
g_object_notify (G_OBJECT (toplevel), "hide-delay");
}
int
panel_toplevel_get_hide_delay (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), -1);
return toplevel->priv->hide_delay;
}
void
panel_toplevel_set_unhide_delay (PanelToplevel *toplevel,
int unhide_delay)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
if (toplevel->priv->unhide_delay == unhide_delay)
return;
toplevel->priv->unhide_delay = unhide_delay;
g_object_notify (G_OBJECT (toplevel), "unhide-delay");
}
int
panel_toplevel_get_unhide_delay (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), -1);
return toplevel->priv->unhide_delay;
}
void
panel_toplevel_set_anicafe (PanelToplevel *toplevel,
gboolean anicafe)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
anicafe = anicafe != FALSE;
if (toplevel->priv->anicafe == anicafe)
return;
toplevel->priv->anicafe = anicafe;
g_object_notify (G_OBJECT (toplevel), "anicafe");
}
gboolean
panel_toplevel_get_anicafe (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), FALSE);
return toplevel->priv->anicafe;
}
void
panel_toplevel_set_animation_speed (PanelToplevel *toplevel,
PanelAnimationSpeed animation_speed)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
if (toplevel->priv->animation_speed == animation_speed)
return;
toplevel->priv->animation_speed = animation_speed;
g_object_notify (G_OBJECT (toplevel), "animation-speed");
}
PanelAnimationSpeed
panel_toplevel_get_animation_speed (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), 0);
return toplevel->priv->animation_speed;
}
void
panel_toplevel_set_enable_buttons (PanelToplevel *toplevel,
gboolean enable_buttons)
{
enable_buttons = enable_buttons != FALSE;
if (toplevel->priv->buttons_enabled == enable_buttons)
return;
toplevel->priv->buttons_enabled = enable_buttons;
panel_toplevel_update_hide_buttons (toplevel);
g_object_notify (G_OBJECT (toplevel), "buttons-enabled");
}
gboolean
panel_toplevel_get_enable_buttons (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), FALSE);
return toplevel->priv->buttons_enabled;
}
void
panel_toplevel_set_enable_arrows (PanelToplevel *toplevel,
gboolean enable_arrows)
{
g_return_if_fail (PANEL_IS_TOPLEVEL (toplevel));
enable_arrows = enable_arrows != FALSE;
if (toplevel->priv->arrows_enabled == enable_arrows)
return;
toplevel->priv->arrows_enabled = enable_arrows;
panel_toplevel_update_hide_buttons (toplevel);
g_object_notify (G_OBJECT (toplevel), "arrows-enabled");
}
gboolean
panel_toplevel_get_enable_arrows (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), FALSE);
return toplevel->priv->arrows_enabled;
}
void
panel_toplevel_rotate (PanelToplevel *toplevel,
gboolean clockwise)
{
PanelOrientation orientation;
/* Relies on PanelOrientation definition:
*
* typedef enum {
* PANEL_ORIENTATION_TOP = 1 << 0,
* PANEL_ORIENTATION_RIGHT = 1 << 1,
* PANEL_ORIENTATION_BOTTOM = 1 << 2,
* PANEL_ORIENTATION_LEFT = 1 << 3
* } PanelOrientation;
*/
orientation = toplevel->priv->orientation;
if (clockwise)
orientation <<= 1;
else
orientation >>= 1;
if (orientation == 0)
orientation = PANEL_ORIENTATION_LEFT;
else if (orientation > PANEL_ORIENTATION_LEFT)
orientation = PANEL_ORIENTATION_TOP;
panel_toplevel_set_orientation (toplevel, orientation);
}
PanelState
panel_toplevel_get_state (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), 0);
return toplevel->priv->state;
}
gboolean
panel_toplevel_get_is_hidden (PanelToplevel *toplevel)
{
g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), FALSE);
if (toplevel->priv->state == PANEL_STATE_HIDDEN_UP ||
toplevel->priv->state == PANEL_STATE_HIDDEN_DOWN ||
toplevel->priv->state == PANEL_STATE_HIDDEN_LEFT ||
toplevel->priv->state == PANEL_STATE_HIDDEN_RIGHT)
return TRUE;
return FALSE;
}
int
panel_toplevel_get_minimum_size (PanelToplevel *toplevel)
{
return calculate_minimum_height (CTK_WIDGET (toplevel),
toplevel->priv->orientation);
}
int
panel_toplevel_get_maximum_size (PanelToplevel *toplevel)
{
CdkRectangle monitor_geom;
panel_toplevel_get_monitor_geometry (toplevel, &monitor_geom);
if (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK)
return monitor_geom.height / MAXIMUM_SIZE_SCREEN_RATIO;
else
return monitor_geom.width / MAXIMUM_SIZE_SCREEN_RATIO;
}
|