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
|
//===========================================================================
//
// This file is part of the KDE project
//
// Copyright (c) 1999 Martin R. Jones <mjones@kde.org>
// Copyright (c) 2003 Oswald Buddenhagen <ossi@kde.org>
// Copyright (c) 2010-2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
//
//kdesktop keeps running and checks user inactivity
//when it should show screensaver (and maybe lock the session),
//it starts kdesktop_lock, who does all the locking and who
//actually starts the screensaver
//It's done this way to prevent screen unlocking when kdesktop
//crashes (e.g. because it's set to multiple wallpapers and
//some image will be corrupted).
#define protected public
#include <tqwidget.h>
#undef protected
#include <config.h>
#include <execinfo.h>
#include "lockprocess.h"
#include "lockdlg.h"
#include "infodlg.h"
#include "querydlg.h"
#include "sakdlg.h"
#include "securedlg.h"
#include "autologout.h"
#include "kdesktopsettings.h"
#include <dmctl.h>
#include <dcopref.h>
#include <kstandarddirs.h>
#include <tdeapplication.h>
#include <kservicegroup.h>
#include <kdebug.h>
#include <tdemessagebox.h>
#include <tdeglobalsettings.h>
#include <tdelocale.h>
#include <klibloader.h>
#include <kpushbutton.h>
#include <kstdguiitem.h>
#include <kpixmapeffect.h>
#include <kpixmap.h>
#include <twin.h>
#include <twinmodule.h>
#include <kdialog.h>
#include <tqframe.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqcursor.h>
#include <tqtimer.h>
#include <tqfile.h>
#include <tqsocketnotifier.h>
#include <tqvaluevector.h>
#include <tqtooltip.h>
#include <tqimage.h>
#include <tqregexp.h>
#include <tqpainter.h>
#include <tqeventloop.h>
#include <tqdatetime.h>
#include <stdlib.h>
#include <assert.h>
#include <signal.h>
#ifdef HAVE_SETPRIORITY
#include <sys/time.h>
#include <sys/resource.h>
#endif
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <ctype.h>
#include <sys/types.h>
#include <fcntl.h>
#include <kcrash.h>
#include <linux/stat.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/Intrinsic.h>
#ifdef HAVE_DPMS
extern "C" {
#include <X11/Xmd.h>
#ifndef Bool
#define Bool BOOL
#endif
#include <X11/extensions/dpms.h>
#ifndef HAVE_DPMSINFO_PROTO
Status DPMSInfo ( Display *, CARD16 *, BOOL * );
#endif
}
#endif
#ifdef HAVE_XF86MISC
#include <X11/extensions/xf86misc.h>
#endif
#ifdef HAVE_GLXCHOOSEVISUAL
#include <GL/glx.h>
#endif
#define LOCK_GRACE_DEFAULT 5000
#define AUTOLOGOUT_DEFAULT 600
#define DESKTOP_WALLPAPER_OBTAIN_TIMEOUT_MS 3000
// Setting this define is INSECURE
// Use it for debugging purposes ONLY
// #define KEEP_MOUSE_UNGRABBED 1
// These lines are taken on 10/2009 from X.org (X11/XF86keysym.h), defining some special multimedia keys
#define XF86XK_AudioMute 0x1008FF12
#define XF86XK_AudioRaiseVolume 0x1008FF13
#define XF86XK_AudioLowerVolume 0x1008FF11
#define XF86XK_Display 0x1008FF59
static Window gVRoot = 0;
static Window gVRootData = 0;
static Atom gXA_VROOT;
static Atom gXA_SCREENSAVER_VERSION;
void print_trace()
{
#ifdef WITH_KDESKTOP_LOCK_BACKTRACE
void *array[10];
size_t size;
char **strings;
size_t i;
size = backtrace (array, 10);
strings = backtrace_symbols (array, size);
printf ("[kdesktop_lock] Obtained %zd stack frames.\n\r", size);
for (i = 0; i < size; i++) {
printf ("[kdesktop_lock] %s\n\r", strings[i]);
}
free (strings);
#endif
}
static void segv_handler(int)
{
printf("[kdesktop_lock] WARNING: A fatal exception was encountered. Trapping and ignoring it so as not to compromise desktop security...\n\r");
print_trace();
sleep(1);
}
extern Atom tqt_wm_state;
extern bool trinity_desktop_lock_use_system_modal_dialogs;
extern bool trinity_desktop_lock_delay_screensaver_start;
extern bool trinity_desktop_lock_use_sak;
extern bool trinity_desktop_lock_hide_active_windows;
extern bool trinity_desktop_lock_forced;
extern TQXLibWindowList trinity_desktop_lock_hidden_window_list;
bool trinity_desktop_lock_autohide_lockdlg = TRUE;
bool trinity_desktop_lock_closing_windows = FALSE;
bool trinity_desktop_lock_in_sec_dlg = FALSE;
bool trinity_desktop_hack_active = FALSE;
#define ENABLE_CONTINUOUS_LOCKDLG_DISPLAY \
if (!mForceContinualLockDisplayTimer->isActive()) mForceContinualLockDisplayTimer->start(100, FALSE); \
trinity_desktop_lock_autohide_lockdlg = FALSE; \
mHackDelayStartupTimer->stop();
#define DISABLE_CONTINUOUS_LOCKDLG_DISPLAY \
mForceContinualLockDisplayTimer->stop(); \
trinity_desktop_lock_autohide_lockdlg = TRUE; \
mHackDelayStartupTimer->stop();
//===========================================================================
//
// Screen saver handling process. Handles screensaver window,
// starting screensaver hacks, and password entry.
//
LockProcess::LockProcess()
: TQWidget(0L, "saver window", ((WFlags)(WStyle_StaysOnTop|WStyle_Customize|WStyle_NoBorder))),
mOpenGLVisual(0),
mParent(0),
mShowLockDateTime(false),
mSuspended(false),
mVisibility(false),
mRestoreXF86Lock(false),
mForbidden(false),
mAutoLogout(false),
resizeTimer(NULL),
hackResumeTimer(NULL),
mVkbdProcess(NULL),
mKWinModule(NULL),
mPipeOpen(false),
mPipeOpen_out(false),
mInfoMessageDisplayed(false),
mDialogControlLock(false),
mForceReject(false),
currentDialog(NULL),
mEnsureScreenHiddenTimer(NULL),
mForceContinualLockDisplayTimer(NULL),
mEnsureVRootWindowSecurityTimer(NULL),
mHackDelayStartupTimer(NULL),
mHackDelayStartupTimeout(0),
mHackStartupEnabled(true),
mResizingDesktopLock(false),
m_rootPixmap(NULL),
mBackingStartupDelayTimer(0),
m_startupStatusDialog(NULL),
m_mouseDown(0),
m_mousePrevX(0),
m_mousePrevY(0),
m_dialogPrevX(0),
m_dialogPrevY(0),
m_maskWidget(NULL)
{
#ifdef KEEP_MOUSE_UNGRABBED
setNFlags(WX11DisableMove|WX11DisableClose|WX11DisableShade|WX11DisableMinimize|WX11DisableMaximize);
#endif
setupSignals();
setupPipe();
kapp->installX11EventFilter(this);
mForceContinualLockDisplayTimer = new TQTimer( this );
mHackDelayStartupTimer = new TQTimer( this );
mEnsureVRootWindowSecurityTimer = new TQTimer( this );
// Try to get the root pixmap
if (!m_rootPixmap) m_rootPixmap = new KRootPixmap(this);
connect(m_rootPixmap, TQT_SIGNAL(backgroundUpdated(const TQPixmap &)), this, TQT_SLOT(slotPaintBackground(const TQPixmap &)));
m_rootPixmap->setCustomPainting(true);
m_rootPixmap->start();
// Get root window attributes
XWindowAttributes rootAttr;
XGetWindowAttributes(tqt_xdisplay(), RootWindow(tqt_xdisplay(), tqt_xscreen()), &rootAttr);
{ // trigger creation of QToolTipManager, it does XSelectInput() on the root window
TQWidget w;
TQToolTip::add( &w, "foo" );
}
XSelectInput( tqt_xdisplay(), tqt_xrootwin(), SubstructureNotifyMask | rootAttr.your_event_mask );
// Add non-TDE path
TDEGlobal::dirs()->addResourceType("scrsav",
TDEGlobal::dirs()->kde_default("apps") +
"System/ScreenSavers/");
// Add KDE specific screensaver path
TQString relPath="System/ScreenSavers/";
KServiceGroup::Ptr servGroup = KServiceGroup::baseGroup( "screensavers");
if (servGroup)
{
relPath=servGroup->relPath();
kdDebug(1204) << "relPath=" << relPath << endl;
}
TDEGlobal::dirs()->addResourceType("scrsav",
TDEGlobal::dirs()->kde_default("apps") +
relPath);
// virtual root property
gXA_VROOT = XInternAtom (tqt_xdisplay(), "__SWM_VROOT", False);
gXA_SCREENSAVER_VERSION = XInternAtom (tqt_xdisplay(), "_SCREENSAVER_VERSION", False);
TQStringList dmopt =
TQStringList::split(TQChar(','),
TQString::fromLatin1( ::getenv( "XDM_MANAGED" )));
for (TQStringList::ConstIterator it = dmopt.begin(); it != dmopt.end(); ++it)
if ((*it).startsWith("method="))
mMethod = (*it).mid(7);
#ifdef KEEP_MOUSE_UNGRABBED
setEnabled(false);
#endif
greetPlugin.library = 0;
TDECrash::setCrashHandler(segv_handler);
}
//---------------------------------------------------------------------------
//
// Destructor - usual cleanups.
//
LockProcess::~LockProcess()
{
if (resizeTimer != NULL) {
resizeTimer->stop();
delete resizeTimer;
}
if (hackResumeTimer != NULL) {
hackResumeTimer->stop();
delete hackResumeTimer;
}
if (mEnsureScreenHiddenTimer != NULL) {
mEnsureScreenHiddenTimer->stop();
delete mEnsureScreenHiddenTimer;
}
if (mForceContinualLockDisplayTimer != NULL) {
mForceContinualLockDisplayTimer->stop();
delete mForceContinualLockDisplayTimer;
}
if (mHackDelayStartupTimer != NULL) {
mHackDelayStartupTimer->stop();
delete mHackDelayStartupTimer;
}
if (mEnsureVRootWindowSecurityTimer != NULL) {
mEnsureVRootWindowSecurityTimer->stop();
delete mEnsureVRootWindowSecurityTimer;
}
if (greetPlugin.library) {
if (greetPlugin.info->done)
greetPlugin.info->done();
greetPlugin.library->unload();
}
if (m_rootPixmap) {
m_rootPixmap->stop();
delete m_rootPixmap;
}
mPipeOpen = false;
mPipeOpen_out = false;
}
//---------------------------------------------------------------------------
//
// Initialization for startup
// This is where instance settings should be set--all objects should have already been created in the constructor above
//
void LockProcess::init(bool child, bool useBlankOnly)
{
// Get root window size
XWindowAttributes rootAttr;
XGetWindowAttributes(tqt_xdisplay(), RootWindow(tqt_xdisplay(), tqt_xscreen()), &rootAttr);
mRootWidth = rootAttr.width;
mRootHeight = rootAttr.height;
// Connect all signals
connect( mForceContinualLockDisplayTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(displayLockDialogIfNeeded()) );
connect( mHackDelayStartupTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(closeDialogAndStartHack()) );
connect( mEnsureVRootWindowSecurityTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(repaintRootWindowIfNeeded()) );
connect(tqApp, TQT_SIGNAL(mouseInteraction(XEvent *)), TQT_SLOT(slotMouseActivity(XEvent *)));
connect(&mHackProc, TQT_SIGNAL(processExited(TDEProcess *)), TQT_SLOT(hackExited(TDEProcess *)));
connect(&mSuspendTimer, TQT_SIGNAL(timeout()), TQT_SLOT(suspend()));
#ifdef HAVE_DPMS
if (mDPMSDepend) {
BOOL on;
CARD16 state;
DPMSInfo(tqt_xdisplay(), &state, &on);
if (on)
{
connect(&mCheckDPMS, TQT_SIGNAL(timeout()), TQT_SLOT(checkDPMSActive()));
// we can save CPU if we stop it as quickly as possible
// but we waste CPU if we check too often -> so take 10s
mCheckDPMS.start(10000);
}
}
#endif
#if (TQT_VERSION-0 >= 0x030200) // XRANDR support
connect( kapp->desktop(), TQT_SIGNAL( resized( int )), TQT_SLOT( desktopResized()));
#endif
if (!trinity_desktop_lock_use_system_modal_dialogs) {
setWFlags((WFlags)WX11BypassWM);
}
child_saver = child;
mUseBlankOnly = useBlankOnly;
mShowLockDateTime = KDesktopSettings::showLockDateTime();
mlockDateTime = TQDateTime::currentDateTime();
mHackDelayStartupTimeout = trinity_desktop_lock_delay_screensaver_start?KDesktopSettings::timeout()*1000:10*1000;
mHackStartupEnabled = trinity_desktop_lock_use_system_modal_dialogs?KDesktopSettings::screenSaverEnabled():true;
configure();
}
static int signal_pipe[2];
static void sigterm_handler(int)
{
if (!trinity_desktop_lock_in_sec_dlg) {
// Exit uncleanly
exit(1);
}
}
static void sighup_handler(int)
{
char tmp = 'H';
if (::write( signal_pipe[1], &tmp, 1) == -1) {
// Error handler to shut up gcc warnings
}
}
bool LockProcess::closeCurrentWindow()
{
trinity_desktop_lock_closing_windows = TRUE;
if (currentDialog != NULL) {
mForceReject = true;
if (dynamic_cast<SAKDlg*>(currentDialog)) {
dynamic_cast<SAKDlg*>(currentDialog)->closeDialogForced();
}
else if (dynamic_cast<SecureDlg*>(currentDialog)) {
dynamic_cast<SecureDlg*>(currentDialog)->closeDialogForced();
}
else {
currentDialog->close();
}
}
if( mDialogs.isEmpty() ) {
trinity_desktop_lock_closing_windows = FALSE;
mForceReject = false;
return false;
}
else {
trinity_desktop_lock_closing_windows = TRUE;
return true;
}
}
void LockProcess::timerEvent(TQTimerEvent *ev)
{
if (mAutoLogout && ev->timerId() == mAutoLogoutTimerId)
{
killTimer(mAutoLogoutTimerId);
AutoLogout autologout(this);
execDialog(&autologout);
}
}
void LockProcess::resizeEvent(TQResizeEvent *)
{
//
}
void LockProcess::setupPipe()
{
/* Create the FIFOs if they do not exist */
umask(0);
mkdir(FIFO_DIR,0644);
mknod(FIFO_FILE, S_IFIFO|0644, 0);
chmod(FIFO_FILE, 0644);
mPipe_fd = open(FIFO_FILE, O_RDONLY | O_NONBLOCK);
if (mPipe_fd > -1) {
mPipeOpen = true;
TQTimer::singleShot( PIPE_CHECK_INTERVAL, this, TQT_SLOT(checkPipe()) );
}
mknod(FIFO_FILE_OUT, S_IFIFO|0600, 0);
chmod(FIFO_FILE_OUT, 0600);
mPipe_fd_out = open(FIFO_FILE_OUT, O_RDWR | O_NONBLOCK);
if (mPipe_fd_out > -1) {
mPipeOpen_out = true;
}
}
void LockProcess::checkPipe()
{
char readbuf[128];
int numread;
TQString to_display;
const char * pin_entry;
if (mPipeOpen == true) {
readbuf[0]=' ';
numread = read(mPipe_fd, readbuf, 128);
readbuf[numread] = 0;
if (numread > 0) {
if (readbuf[0] == 'C') {
mInfoMessageDisplayed=false;
while (mDialogControlLock == true) usleep(100000);
mDialogControlLock = true;
if (currentDialog != NULL) {
mForceReject = true;
closeCurrentWindow();
}
mDialogControlLock = false;
}
if (readbuf[0] == 'T') {
to_display = readbuf;
to_display = to_display.remove(0,1);
// Lock out password dialogs and close any active dialog
mInfoMessageDisplayed=true;
while (mDialogControlLock == true) usleep(100000);
mDialogControlLock = true;
if (currentDialog != NULL) {
mForceReject = true;
closeCurrentWindow();
}
mDialogControlLock = false;
// Display info message dialog
TQTimer::singleShot( PIPE_CHECK_INTERVAL, this, TQT_SLOT(checkPipe()) );
InfoDlg inDlg( this );
inDlg.updateLabel(to_display);
inDlg.setUnlockIcon();
execDialog( &inDlg );
mForceReject = false;
return;
}
if ((readbuf[0] == 'E') || (readbuf[0] == 'W') || (readbuf[0] == 'I') || (readbuf[0] == 'K')) {
to_display = readbuf;
to_display = to_display.remove(0,1);
// Lock out password dialogs and close any active dialog
mInfoMessageDisplayed=true;
while (mDialogControlLock == true) usleep(100000);
mDialogControlLock = true;
if (currentDialog != NULL) {
mForceReject = true;
closeCurrentWindow();
}
mDialogControlLock = false;
// Display info message dialog
TQTimer::singleShot( PIPE_CHECK_INTERVAL, this, TQT_SLOT(checkPipe()) );
InfoDlg inDlg( this );
inDlg.updateLabel(to_display);
if (readbuf[0] == 'K') inDlg.setKDEIcon();
if (readbuf[0] == 'I') inDlg.setInfoIcon();
if (readbuf[0] == 'W') inDlg.setWarningIcon();
if (readbuf[0] == 'E') inDlg.setErrorIcon();
execDialog( &inDlg );
mForceReject = false;
return;
}
if (readbuf[0] == 'Q') {
to_display = readbuf;
to_display = to_display.remove(0,1);
// Lock out password dialogs and close any active dialog
mInfoMessageDisplayed=true;
while (mDialogControlLock == true) usleep(100000);
mDialogControlLock = true;
if (currentDialog != NULL) {
mForceReject = true;
closeCurrentWindow();
}
mDialogControlLock = false;
// Display query dialog
TQTimer::singleShot( PIPE_CHECK_INTERVAL, this, TQT_SLOT(checkPipe()) );
QueryDlg qryDlg( this );
qryDlg.updateLabel(to_display);
qryDlg.setUnlockIcon();
mForceReject = false;
execDialog( &qryDlg );
if (mForceReject == false) {
pin_entry = qryDlg.getEntry();
mInfoMessageDisplayed=false;
if (mPipeOpen_out == true) {
if (write(mPipe_fd_out, pin_entry, strlen(pin_entry)+1) == -1) {
// Error handler to shut up gcc warnings
}
if (write(mPipe_fd_out, "\n\r", 3) == -1) {
// Error handler to shut up gcc warnings
}
}
}
mForceReject = false;
return;
}
}
TQTimer::singleShot( PIPE_CHECK_INTERVAL, this, TQT_SLOT(checkPipe()) );
}
}
void LockProcess::setupSignals()
{
struct sigaction act;
// ignore SIGINT
act.sa_handler=SIG_IGN;
sigemptyset(&(act.sa_mask));
sigaddset(&(act.sa_mask), SIGINT);
act.sa_flags = 0;
sigaction(SIGINT, &act, 0L);
// ignore SIGQUIT
act.sa_handler=SIG_IGN;
sigemptyset(&(act.sa_mask));
sigaddset(&(act.sa_mask), SIGQUIT);
act.sa_flags = 0;
sigaction(SIGQUIT, &act, 0L);
// exit uncleanly on SIGTERM
act.sa_handler= sigterm_handler;
sigemptyset(&(act.sa_mask));
sigaddset(&(act.sa_mask), SIGTERM);
act.sa_flags = 0;
sigaction(SIGTERM, &act, 0L);
// SIGHUP forces lock
act.sa_handler= sighup_handler;
sigemptyset(&(act.sa_mask));
sigaddset(&(act.sa_mask), SIGHUP);
act.sa_flags = 0;
sigaction(SIGHUP, &act, 0L);
if (pipe(signal_pipe) == -1) {
// Error handler to shut up gcc warnings
}
TQSocketNotifier* notif = new TQSocketNotifier(signal_pipe[0],
TQSocketNotifier::Read, TQT_TQOBJECT(this) );
connect( notif, TQT_SIGNAL(activated(int)), TQT_SLOT(signalPipeSignal()));
}
void LockProcess::signalPipeSignal()
{
char tmp;
if (::read( signal_pipe[0], &tmp, 1) == -1) {
// Error handler to shut up gcc warnings
}
if( tmp == 'T' )
quitSaver();
else if( tmp == 'H' ) {
if( !mLocked )
startLock();
}
}
//---------------------------------------------------------------------------
bool LockProcess::lock()
{
#ifdef USE_SECURING_DESKTOP_NOTIFICATION
m_startupStatusDialog = new KSMModalDialog(this);
m_startupStatusDialog->setStatusMessage(i18n("Securing desktop session").append("..."));
m_startupStatusDialog->show();
m_startupStatusDialog->setActiveWindow();
tqApp->processEvents();
#endif
if (startSaver()) {
// In case of a forced lock we don't react to events during
// the dead-time to give the screensaver some time to activate.
// That way we don't accidentally show the password dialog before
// the screensaver kicks in because the user moved the mouse after
// selecting "lock screen", that looks really untidy.
mBusy = true;
if (startLock())
{
TQTimer::singleShot(1000, this, TQT_SLOT(slotDeadTimePassed()));
return true;
}
stopSaver();
mBusy = false;
}
return false;
}
//---------------------------------------------------------------------------
void LockProcess::slotDeadTimePassed()
{
mBusy = false;
}
//---------------------------------------------------------------------------
bool LockProcess::defaultSave()
{
mLocked = false;
if (startSaver()) {
if (mLockGrace >= 0)
TQTimer::singleShot(mLockGrace, this, TQT_SLOT(startLock()));
return true;
}
return false;
}
//---------------------------------------------------------------------------
bool LockProcess::dontLock()
{
mLocked = false;
return startSaver();
}
//---------------------------------------------------------------------------
void LockProcess::quitSaver()
{
DISABLE_CONTINUOUS_LOCKDLG_DISPLAY
if (closeCurrentWindow()) {
TQTimer::singleShot( 0, this, SLOT(quitSaver()) );
return;
}
stopSaver();
kapp->quit();
}
//---------------------------------------------------------------------------
void LockProcess::startSecureDialog()
{
if ((backingPixmap.isNull()) && (mBackingStartupDelayTimer < 100)) {
TQTimer::singleShot(10, this, TQT_SLOT(startSecureDialog()));
mBackingStartupDelayTimer++;
return;
}
setGeometry(0, 0, mRootWidth, mRootHeight);
int ret;
SecureDlg inDlg( this );
inDlg.setRetInt(&ret);
mBusy = true;
execDialog( &inDlg );
mBusy = false;
bool forcecontdisp = mForceContinualLockDisplayTimer->isActive();
if (forcecontdisp) {
DISABLE_CONTINUOUS_LOCKDLG_DISPLAY
}
trinity_desktop_lock_in_sec_dlg = false;
if (ret == 0) {
trinity_desktop_lock_closing_windows = 1;
kapp->quit();
}
if (ret == 1) {
// In case of a forced lock we don't react to events during
// the dead-time to give the screensaver some time to activate.
// That way we don't accidentally show the password dialog before
// the screensaver kicks in because the user moved the mouse after
// selecting "lock screen", that looks really untidy.
mBusy = true;
trinity_desktop_lock_forced = true;
// Make sure the cursor is not showing busy status
setCursor( tqarrowCursor );
if (startLock())
{
if (trinity_desktop_lock_delay_screensaver_start) {
mBusy = false;
}
else {
TQTimer::singleShot(1000, this, TQT_SLOT(slotDeadTimePassed()));
}
if (trinity_desktop_lock_delay_screensaver_start && trinity_desktop_lock_forced && trinity_desktop_lock_use_system_modal_dialogs) {
ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
}
else {
if (mHackStartupEnabled == true) {
startHack();
}
else {
if (trinity_desktop_lock_use_system_modal_dialogs == true) {
ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
}
else {
startHack();
}
}
}
return;
}
stopSaver();
mBusy = false;
return;
}
if (ret == 2) {
trinity_desktop_lock_closing_windows = 1;
if (system("ksysguard &") == -1) {
// Error handler to shut up gcc warnings
}
kapp->quit();
}
if (ret == 3) {
trinity_desktop_lock_closing_windows = 1;
DCOPRef("ksmserver","ksmserver").send("logout", (int)TDEApplication::ShutdownConfirmYes, (int)TDEApplication::ShutdownTypeNone, (int)TDEApplication::ShutdownModeInteractive);
kapp->quit();
}
// FIXME
// Handle remaining case (switch user)
if (forcecontdisp) {
ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
}
stopSaver();
}
bool LockProcess::runSecureDialog()
{
#ifdef USE_SECURING_DESKTOP_NOTIFICATION
m_startupStatusDialog = new KSMModalDialog(this);
m_startupStatusDialog->setStatusMessage(i18n("Securing desktop session").append("..."));
m_startupStatusDialog->show();
m_startupStatusDialog->setActiveWindow();
tqApp->processEvents();
#endif
trinity_desktop_lock_in_sec_dlg = true;
if (startSaver()) {
mBackingStartupDelayTimer = 0;
TQTimer::singleShot(0, this, TQT_SLOT(startSecureDialog()));
return true;
}
else {
return false;
}
}
//---------------------------------------------------------------------------
//
// Read and apply configuration.
//
void LockProcess::configure()
{
// the configuration is stored in kdesktop's config file
if( KDesktopSettings::lock() )
{
mLockGrace = KDesktopSettings::lockGrace();
if (mLockGrace < 0)
mLockGrace = 0;
else if (mLockGrace > 300000)
mLockGrace = 300000; // 5 minutes, keep the value sane
}
else
mLockGrace = -1;
if ( KDesktopSettings::autoLogout() )
{
mAutoLogout = true;
mAutoLogoutTimeout = KDesktopSettings::autoLogoutTimeout();
mAutoLogoutTimerId = startTimer(mAutoLogoutTimeout * 1000); // in milliseconds
}
#ifdef HAVE_DPMS
//if the user decided that the screensaver should run independent from
//dpms, we shouldn't check for it, aleXXX
mDPMSDepend = KDesktopSettings::dpmsDependent();
#endif
mPriority = KDesktopSettings::priority();
if (mPriority < 0) mPriority = 0;
if (mPriority > 19) mPriority = 19;
mSaver = KDesktopSettings::saver();
if (mSaver.isEmpty() || mUseBlankOnly) {
mSaver = "KBlankscreen.desktop";
}
if (KDesktopSettings::screenSaverEnabled() == false) {
mSaver = "";
mSaverExec = "";
}
readSaver();
mPlugins = KDesktopSettings::pluginsUnlock();
if (mPlugins.isEmpty())
mPlugins = TQStringList("classic");
mPluginOptions = KDesktopSettings::pluginOptions();
}
//---------------------------------------------------------------------------
//
// Read the command line needed to run the screensaver given a .desktop file.
//
void LockProcess::readSaver()
{
if (!mSaver.isEmpty())
{
TQString file = locate("scrsav", mSaver);
bool opengl = kapp->authorize("opengl_screensavers");
bool manipulatescreen = kapp->authorize("manipulatescreen_screensavers");
KDesktopFile config(file, true);
if (config.readEntry("X-TDE-Type").utf8() != 0)
{
TQString saverType = config.readEntry("X-TDE-Type").utf8();
TQStringList saverTypes = TQStringList::split(";", saverType);
for (uint i = 0; i < saverTypes.count(); i++)
{
if ((saverTypes[i] == "ManipulateScreen") && !manipulatescreen)
{
kdDebug(1204) << "Screensaver is type ManipulateScreen and ManipulateScreen is forbidden" << endl;
mForbidden = true;
}
if ((saverTypes[i] == "OpenGL") && !opengl)
{
kdDebug(1204) << "Screensaver is type OpenGL and OpenGL is forbidden" << endl;
mForbidden = true;
}
if (saverTypes[i] == "OpenGL")
{
mOpenGLVisual = true;
}
}
}
kdDebug(1204) << "mForbidden: " << (mForbidden ? "true" : "false") << endl;
if (trinity_desktop_lock_use_system_modal_dialogs) {
if (config.hasActionGroup("InWindow"))
{
config.setActionGroup("InWindow");
mSaverExec = config.readPathEntry("Exec");
}
}
else {
if (config.hasActionGroup("Root"))
{
config.setActionGroup("Root");
mSaverExec = config.readPathEntry("Exec");
}
}
}
}
//---------------------------------------------------------------------------
//
// Create a window to draw our screen saver on.
//
void LockProcess::createSaverWindow()
{
Visual* visual = CopyFromParent;
XSetWindowAttributes attrs;
int flags = trinity_desktop_lock_use_system_modal_dialogs?0:CWOverrideRedirect;
#ifdef HAVE_GLXCHOOSEVISUAL
if( mOpenGLVisual )
{
static int attribs[][ 15 ] =
{
#define R GLX_RED_SIZE
#define G GLX_GREEN_SIZE
#define B GLX_BLUE_SIZE
{ GLX_RGBA, R, 8, G, 8, B, 8, GLX_DEPTH_SIZE, 8, GLX_DOUBLEBUFFER, GLX_STENCIL_SIZE, 1, None },
{ GLX_RGBA, R, 4, G, 4, B, 4, GLX_DEPTH_SIZE, 4, GLX_DOUBLEBUFFER, GLX_STENCIL_SIZE, 1, None },
{ GLX_RGBA, R, 8, G, 8, B, 8, GLX_DEPTH_SIZE, 8, GLX_DOUBLEBUFFER, None },
{ GLX_RGBA, R, 4, G, 4, B, 4, GLX_DEPTH_SIZE, 4, GLX_DOUBLEBUFFER, None },
{ GLX_RGBA, R, 8, G, 8, B, 8, GLX_DEPTH_SIZE, 8, GLX_STENCIL_SIZE, 1, None },
{ GLX_RGBA, R, 4, G, 4, B, 4, GLX_DEPTH_SIZE, 4, GLX_STENCIL_SIZE, 1, None },
{ GLX_RGBA, R, 8, G, 8, B, 8, GLX_DEPTH_SIZE, 8, None },
{ GLX_RGBA, R, 4, G, 4, B, 4, GLX_DEPTH_SIZE, 4, None },
{ GLX_RGBA, GLX_DEPTH_SIZE, 8, GLX_DOUBLEBUFFER, GLX_STENCIL_SIZE, 1, None },
{ GLX_RGBA, GLX_DEPTH_SIZE, 8, GLX_DOUBLEBUFFER, None },
{ GLX_RGBA, GLX_DEPTH_SIZE, 8, GLX_STENCIL_SIZE, 1, None },
{ GLX_RGBA, GLX_DEPTH_SIZE, 8, None }
#undef R
#undef G
#undef B
};
for( unsigned int i = 0;
i < sizeof( attribs ) / sizeof( attribs[ 0 ] );
++i )
{
if( XVisualInfo* info = glXChooseVisual( x11Display(), x11Screen(), attribs[ i ] ))
{
visual = info->visual;
static Colormap colormap = 0;
if( colormap != 0 )
XFreeColormap( x11Display(), colormap );
colormap = XCreateColormap( x11Display(), RootWindow( x11Display(), x11Screen()), visual, AllocNone );
attrs.colormap = colormap;
flags |= CWColormap;
XFree( info );
break;
}
}
}
#endif
attrs.override_redirect = 1;
hide();
Window w = XCreateWindow( x11Display(), RootWindow( x11Display(), x11Screen()),
x(), y(), width(), height(), 0, x11Depth(), InputOutput, visual, flags, &attrs );
create( w );
// Some xscreensaver hacks check for this property
const char *version = "KDE 2.0";
XChangeProperty (tqt_xdisplay(), winId(),
gXA_SCREENSAVER_VERSION, XA_STRING, 8, PropModeReplace,
(unsigned char *) version, strlen(version));
XSetWindowAttributes attr;
attr.event_mask = KeyPressMask | ButtonPressMask | PointerMotionMask |
VisibilityChangeMask | ExposureMask;
XChangeWindowAttributes(tqt_xdisplay(), winId(),
CWEventMask, &attr);
// erase();
// set NoBackground so that the saver can capture the current
// screen state if necessary
// this is a security risk and has been deactivated--welcome to the 21st century folks!
// setBackgroundMode(TQWidget::NoBackground);
setGeometry(0, 0, mRootWidth, mRootHeight);
// HACK
// Hide all tooltips and notification windows
{
Window rootWindow = RootWindow(x11Display(), x11Screen());
Window parent;
Window* children = NULL;
unsigned int noOfChildren = 0;
XWindowAttributes childAttr;
Window childTransient;
if (XQueryTree(x11Display(), rootWindow, &rootWindow, &parent, &children, &noOfChildren) && noOfChildren>0 ) {
for (unsigned int i=0; i<noOfChildren; i++) {
if (XGetWindowAttributes(x11Display(), children[i], &childAttr) && XGetTransientForHint(x11Display(), children[i], &childTransient)) {
if ((childAttr.map_state == IsViewable) && (childAttr.override_redirect) && (childTransient)) {
if (!trinity_desktop_lock_hidden_window_list.contains(children[i])) {
trinity_desktop_lock_hidden_window_list.append(children[i]);
}
XLowerWindow(x11Display(), children[i]);
XFlush(x11Display());
}
}
}
}
}
kdDebug(1204) << "Saver window Id: " << winId() << endl;
}
void LockProcess::desktopResized()
{
// Get root window size
XWindowAttributes rootAttr;
XGetWindowAttributes(tqt_xdisplay(), RootWindow(tqt_xdisplay(), tqt_xscreen()), &rootAttr);
if ((rootAttr.width == mRootWidth) && (rootAttr.height == mRootHeight)) {
return;
}
mRootWidth = rootAttr.width;
mRootHeight = rootAttr.height;
mBusy = true;
mHackDelayStartupTimer->stop();
stopHack();
DISABLE_CONTINUOUS_LOCKDLG_DISPLAY
mResizingDesktopLock = true;
backingPixmap = TQPixmap();
if (trinity_desktop_lock_use_system_modal_dialogs) {
// Temporarily hide the entire screen with a new override redirect window
if (m_maskWidget) {
m_maskWidget->setGeometry(0, 0, mRootWidth, mRootHeight);
}
else {
int flags = CWOverrideRedirect;
Visual* visual = CopyFromParent;
XSetWindowAttributes attrs;
attrs.override_redirect = 1;
Window maskWindow = XCreateWindow(x11Display(), RootWindow( x11Display(), x11Screen()), 0, 0, mRootWidth, mRootHeight, 0, x11Depth(), InputOutput, visual, flags, &attrs);
m_maskWidget = new TQWidget();
m_maskWidget->create(maskWindow);
m_maskWidget->setBackgroundColor(TQt::black);
m_maskWidget->erase();
m_maskWidget->show();
}
XSync(tqt_xdisplay(), False);
if (mEnsureScreenHiddenTimer) {
mEnsureScreenHiddenTimer->stop();
}
else {
mEnsureScreenHiddenTimer = new TQTimer( this );
connect( mEnsureScreenHiddenTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotForcePaintBackground()) );
}
mEnsureScreenHiddenTimer->start(DESKTOP_WALLPAPER_OBTAIN_TIMEOUT_MS, true);
}
// Resize the background widget
setGeometry(0, 0, mRootWidth, mRootHeight);
XSync(tqt_xdisplay(), False);
// Black out the background widget to hide ugly resize tiling artifacts
setBackgroundColor(black);
erase();
// This slot needs to be able to execute very rapidly so as to prevent the user's desktop from ever
// being displayed, so we finish the hack restarting/display prettying operations in a separate timed slot
if (resizeTimer == NULL) {
resizeTimer = new TQTimer( this );
connect( resizeTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(doDesktopResizeFinish()) );
}
resizeTimer->start( 100, TRUE ); // 100 millisecond single shot timer; should allow display switching operations to finish before hack is started
}
void LockProcess::doDesktopResizeFinish()
{
while (mDialogControlLock == true) {
usleep(100000);
}
mDialogControlLock = true;
if (closeCurrentWindow()) {
TQTimer::singleShot( 0, this, SLOT(doDesktopResizeFinish()) );
mDialogControlLock = false;
return;
}
mDialogControlLock = false;
// Restart the hack as the window size is now different
if (trinity_desktop_lock_delay_screensaver_start && trinity_desktop_lock_use_system_modal_dialogs) {
ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
}
else {
if (mHackStartupEnabled == true) {
startHack();
}
else {
if (trinity_desktop_lock_use_system_modal_dialogs == true) {
ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
}
else {
startHack();
}
}
}
mResizingDesktopLock = false;
mBusy = false;
}
//---------------------------------------------------------------------------
//
// Hide the screensaver window
//
void LockProcess::hideSaverWindow()
{
hide();
lower();
removeVRoot(winId());
XDeleteProperty(tqt_xdisplay(), winId(), gXA_SCREENSAVER_VERSION);
if ( gVRoot ) {
unsigned long vroot_data[1] = { gVRootData };
XChangeProperty(tqt_xdisplay(), gVRoot, gXA_VROOT, XA_WINDOW, 32,
PropModeReplace, (unsigned char *)vroot_data, 1);
gVRoot = 0;
}
XSync(tqt_xdisplay(), False);
}
//---------------------------------------------------------------------------
static int ignoreXError(Display *, XErrorEvent *)
{
return 0;
}
//---------------------------------------------------------------------------
//
// Save the current virtual root window
//
void LockProcess::saveVRoot()
{
Window rootReturn, parentReturn, *children;
unsigned int numChildren;
Window root = RootWindowOfScreen(ScreenOfDisplay(tqt_xdisplay(), tqt_xscreen()));
gVRoot = 0;
gVRootData = 0;
int (*oldHandler)(Display *, XErrorEvent *);
oldHandler = XSetErrorHandler(ignoreXError);
if (XQueryTree(tqt_xdisplay(), root, &rootReturn, &parentReturn,
&children, &numChildren))
{
for (unsigned int i = 0; i < numChildren; i++)
{
Atom actual_type;
int actual_format;
unsigned long nitems, bytesafter;
unsigned char *newRoot = 0;
if ((XGetWindowProperty(tqt_xdisplay(), children[i], gXA_VROOT, 0, 1,
False, XA_WINDOW, &actual_type, &actual_format, &nitems, &bytesafter,
&newRoot) == Success) && newRoot)
{
gVRoot = children[i];
Window *dummy = (Window*)newRoot;
gVRootData = *dummy;
XFree ((char*) newRoot);
break;
}
}
if (children)
{
XFree((char *)children);
}
}
XSetErrorHandler(oldHandler);
}
//---------------------------------------------------------------------------
//
// Set the virtual root property
//
void LockProcess::setVRoot(Window win, Window vr)
{
if (gVRoot)
removeVRoot(gVRoot);
unsigned long rw = RootWindowOfScreen(ScreenOfDisplay(tqt_xdisplay(), tqt_xscreen()));
unsigned long vroot_data[1] = { vr };
Window rootReturn, parentReturn, *children;
unsigned int numChildren;
Window top = win;
while (1) {
XQueryTree(tqt_xdisplay(), top , &rootReturn, &parentReturn,
&children, &numChildren);
if (children)
XFree((char *)children);
if (parentReturn == rw) {
break;
} else
top = parentReturn;
}
XChangeProperty(tqt_xdisplay(), top, gXA_VROOT, XA_WINDOW, 32,
PropModeReplace, (unsigned char *)vroot_data, 1);
}
//---------------------------------------------------------------------------
//
// Remove the virtual root property
//
void LockProcess::removeVRoot(Window win)
{
XDeleteProperty (tqt_xdisplay(), win, gXA_VROOT);
}
//---------------------------------------------------------------------------
//
// Grab the keyboard. Returns true on success
//
bool LockProcess::grabKeyboard()
{
int rv = XGrabKeyboard( tqt_xdisplay(), TQApplication::desktop()->winId(),
True, GrabModeAsync, GrabModeAsync, CurrentTime );
return (rv == GrabSuccess);
}
#define GRABEVENTS ButtonPressMask | ButtonReleaseMask | PointerMotionMask | \
EnterWindowMask | LeaveWindowMask
//---------------------------------------------------------------------------
//
// Grab the mouse. Returns true on success
//
bool LockProcess::grabMouse()
{
HANDLE cursorHandle;
if (trinity_desktop_hack_active) {
cursorHandle = TQCursor(tqblankCursor).handle();
}
else {
cursorHandle = TQCursor(tqbusyCursor).handle();
}
int rv = XGrabPointer( tqt_xdisplay(), TQApplication::desktop()->winId(),
True, GRABEVENTS, GrabModeAsync, GrabModeAsync, None,
cursorHandle, CurrentTime );
return (rv == GrabSuccess);
}
//---------------------------------------------------------------------------
//
// Grab keyboard and mouse. Returns true on success.
//
bool LockProcess::grabInput()
{
XSync(tqt_xdisplay(), False);
if (!grabKeyboard())
{
usleep(100000);
if (!grabKeyboard())
{
return false;
}
}
#ifndef KEEP_MOUSE_UNGRABBED
if (!grabMouse())
{
usleep(100000);
if (!grabMouse())
{
XUngrabKeyboard(tqt_xdisplay(), CurrentTime);
return false;
}
}
#endif
lockXF86();
return true;
}
//---------------------------------------------------------------------------
//
// Release mouse an keyboard grab.
//
void LockProcess::ungrabInput()
{
XUngrabKeyboard(tqt_xdisplay(), CurrentTime);
XUngrabPointer(tqt_xdisplay(), CurrentTime);
unlockXF86();
}
//---------------------------------------------------------------------------
//
// Start the screen saver.
//
bool LockProcess::startSaver()
{
if (!child_saver && !grabInput())
{
kdWarning(1204) << "LockProcess::startSaver() grabInput() failed!!!!" << endl;
return false;
}
mBusy = false;
// eliminate nasty flicker on first show
TQImage m_grayImage = TQImage( TQApplication::desktop()->width(), TQApplication::desktop()->height(), 32 );
m_grayImage = m_grayImage.convertDepth(32);
m_grayImage.setAlphaBuffer(false);
m_grayImage.fill(0); // Set the alpha buffer to 0 (fully transparent)
m_grayImage.setAlphaBuffer(true);
TQPixmap m_root;
m_root.resize(mRootWidth, mRootHeight);
TQPainter p;
p.begin( &m_root );
m_grayImage.setAlphaBuffer(false);
p.drawImage( 0, 0, m_grayImage );
p.end();
setBackgroundPixmap( m_root );
saveVRoot();
if (mParent) {
TQSocketNotifier *notifier = new TQSocketNotifier(mParent, TQSocketNotifier::Read, TQT_TQOBJECT(this), "notifier");
connect(notifier, TQT_SIGNAL( activated (int)), TQT_SLOT( quitSaver()));
}
createSaverWindow();
move(0, 0);
show();
raise();
XSync(tqt_xdisplay(), False);
setVRoot( winId(), winId() );
if (!trinity_desktop_lock_hide_active_windows) {
if (m_rootPixmap) m_rootPixmap->stop();
TQPixmap rootWinSnapShot = TQPixmap::grabWindow(TQApplication::desktop()->winId());
slotPaintBackground(rootWinSnapShot);
}
else {
// Sometimes KRootPixmap fails...make sure the desktop is hidden regardless
if (backingPixmap.isNull()) {
if (!mEnsureScreenHiddenTimer) {
mEnsureScreenHiddenTimer = new TQTimer( this );
connect( mEnsureScreenHiddenTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotForcePaintBackground()) );
mEnsureScreenHiddenTimer->start(DESKTOP_WALLPAPER_OBTAIN_TIMEOUT_MS, true);
}
int exitTimer = 0;
while ((backingPixmap.isNull()) && (mEnsureScreenHiddenTimer->isActive())) {
kapp->eventLoop()->processEvents(TQEventLoop::ExcludeUserInput);
// HACK
// Work around an issue with the underlying system whereby the TQTimer sometimes fails to time out!
// This issue was reported in Bug #1288
usleep(100);
exitTimer++;
if (exitTimer > (DESKTOP_WALLPAPER_OBTAIN_TIMEOUT_MS*10)) {
printf("[WARNING] The TQt3 timer event loop appears to have hung. Aborting wait for desktop background!\n\r"); fflush(stdout);
break;
}
}
}
}
if (((!(trinity_desktop_lock_delay_screensaver_start && trinity_desktop_lock_forced)) && (!trinity_desktop_lock_in_sec_dlg)) && mHackStartupEnabled) {
if (backingPixmap.isNull()) {
setBackgroundColor(black);
}
else {
setBackgroundPixmap(backingPixmap);
}
setGeometry(0, 0, mRootWidth, mRootHeight);
erase();
}
if (trinity_desktop_lock_in_sec_dlg == FALSE) {
if (trinity_desktop_lock_delay_screensaver_start && trinity_desktop_lock_forced && trinity_desktop_lock_use_system_modal_dialogs) {
ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
}
else {
if (mHackStartupEnabled == true) {
startHack();
}
else {
if (trinity_desktop_lock_use_system_modal_dialogs == true) {
ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
}
else {
startHack();
}
}
}
}
return true;
}
//---------------------------------------------------------------------------
//
// Stop the screen saver.
//
void LockProcess::stopSaver()
{
kdDebug(1204) << "LockProcess: stopping saver" << endl;
mHackProc.kill(SIGCONT);
stopHack();
mSuspended = false;
hideSaverWindow();
mVisibility = false;
if (!child_saver) {
if (mLocked)
DM().setLock( false );
ungrabInput();
const char *out = "GOAWAY!";
for (TQValueList<int>::ConstIterator it = child_sockets.begin(); it != child_sockets.end(); ++it)
if (write(*it, out, sizeof(out)) == -1) {
// Error handler to shut up gcc warnings
}
}
}
// private static
TQVariant LockProcess::getConf(void *ctx, const char *key, const TQVariant &dflt)
{
LockProcess *that = (LockProcess *)ctx;
TQString fkey = TQString::fromLatin1( key ) + '=';
for (TQStringList::ConstIterator it = that->mPluginOptions.begin();
it != that->mPluginOptions.end(); ++it)
if ((*it).startsWith( fkey ))
return (*it).mid( fkey.length() );
return dflt;
}
void LockProcess::cantLock( const TQString &txt)
{
msgBox( TQMessageBox::Critical, i18n("Will not lock the session, as unlocking would be impossible:\n") + txt );
}
#if 0 // placeholders for later
i18n("Cannot start <i>kcheckpass</i>.");
i18n("<i>kcheckpass</i> is unable to operate. Possibly it is not SetUID root.");
#endif
//---------------------------------------------------------------------------
//
// Make the screen saver password protected.
//
bool LockProcess::startLock()
{
for (TQStringList::ConstIterator it = mPlugins.begin(); it != mPlugins.end(); ++it) {
GreeterPluginHandle plugin;
TQString path = KLibLoader::self()->findLibrary(
((*it)[0] == '/' ? *it : "kgreet_" + *it ).latin1() );
if (path.isEmpty()) {
kdWarning(1204) << "GreeterPlugin " << *it << " does not exist" << endl;
continue;
}
if (!(plugin.library = KLibLoader::self()->library( path.latin1() ))) {
kdWarning(1204) << "Cannot load GreeterPlugin " << *it << " (" << path << ")" << endl;
continue;
}
if (!plugin.library->hasSymbol( "kgreeterplugin_info" )) {
kdWarning(1204) << "GreeterPlugin " << *it << " (" << path << ") is no valid greet widget plugin" << endl;
plugin.library->unload();
continue;
}
plugin.info = (kgreeterplugin_info*)plugin.library->symbol( "kgreeterplugin_info" );
if (plugin.info->method && !mMethod.isEmpty() && mMethod != plugin.info->method) {
kdDebug(1204) << "GreeterPlugin " << *it << " (" << path << ") serves " << plugin.info->method << ", not " << mMethod << endl;
plugin.library->unload();
continue;
}
if (!plugin.info->init( mMethod, getConf, this )) {
kdDebug(1204) << "GreeterPlugin " << *it << " (" << path << ") refuses to serve " << mMethod << endl;
plugin.library->unload();
continue;
}
kdDebug(1204) << "GreeterPlugin " << *it << " (" << plugin.info->method << ", " << plugin.info->name << ") loaded" << endl;
greetPlugin = plugin;
mLocked = true;
DM().setLock( true );
return true;
}
cantLock( i18n("No appropriate greeter plugin configured.") );
return false;
}
//---------------------------------------------------------------------------
//
void LockProcess::closeDialogAndStartHack()
{
// Close any active dialogs
DISABLE_CONTINUOUS_LOCKDLG_DISPLAY
mSuspended = true;
if (closeCurrentWindow()) {
TQTimer::singleShot( 0, this, SLOT(closeDialogAndStartHack()) );
}
else {
resume(true);
}
}
void LockProcess::repaintRootWindowIfNeeded()
{
if (trinity_desktop_lock_use_system_modal_dialogs) {
if (!mHackProc.isRunning()) {
if (backingPixmap.isNull()) {
setBackgroundColor(black);
setGeometry(0, 0, mRootWidth, mRootHeight);
erase();
}
else {
bitBlt(this, 0, 0, &backingPixmap);
}
}
if (currentDialog == NULL) {
raise();
}
}
}
bool LockProcess::startHack()
{
trinity_desktop_hack_active = TRUE;
setCursor( tqblankCursor );
XChangeActivePointerGrab( tqt_xdisplay(), GRABEVENTS, TQCursor(tqblankCursor).handle(), CurrentTime);
if ((mEnsureVRootWindowSecurityTimer) && (!mEnsureVRootWindowSecurityTimer->isActive())) mEnsureVRootWindowSecurityTimer->start(250, FALSE);
if (currentDialog || (!mDialogs.isEmpty()))
{
// no resuming with dialog visible or when not visible
if (backingPixmap.isNull()) {
setBackgroundColor(black);
}
else {
setBackgroundPixmap(backingPixmap);
}
setGeometry(0, 0, mRootWidth, mRootHeight);
erase();
return false;
}
if (mSaverExec.isEmpty())
{
return false;
}
if (mHackProc.isRunning())
{
stopHack();
}
mHackProc.clearArguments();
TQTextStream ts(&mSaverExec, IO_ReadOnly);
TQString word;
ts >> word;
TQString path = TDEStandardDirs::findExe(word);
if (!path.isEmpty())
{
mHackProc << path;
kdDebug(1204) << "Starting hack: " << path << endl;
while (!ts.atEnd())
{
ts >> word;
if (word == "%w")
{
word = word.setNum(winId());
}
mHackProc << word;
}
if (!mForbidden)
{
if (trinity_desktop_lock_use_system_modal_dialogs) {
// Make sure we have a nice clean display to start with!
if (backingPixmap.isNull()) {
setBackgroundColor(black);
}
else {
setBackgroundPixmap(backingPixmap);
}
setGeometry(0, 0, mRootWidth, mRootHeight);
erase();
mSuspended = false;
}
if (mHackProc.start() == true)
{
#ifdef HAVE_SETPRIORITY
setpriority(PRIO_PROCESS, mHackProc.pid(), mPriority);
#endif
//bitBlt(this, 0, 0, &mOriginal);
DISABLE_CONTINUOUS_LOCKDLG_DISPLAY
if (trinity_desktop_lock_delay_screensaver_start && trinity_desktop_lock_forced) {
// Close any active dialogs
if (closeCurrentWindow()) {
TQTimer::singleShot( 0, this, SLOT(closeCurrentWindow()) );
}
}
if (m_startupStatusDialog) { m_startupStatusDialog->closeSMDialog(); m_startupStatusDialog=NULL; }
return true;
}
}
else
// we aren't allowed to start the specified screensaver either because it didn't run for some reason
// according to the kiosk restrictions forbid it
{
usleep(100);
TQApplication::syncX();
if (!trinity_desktop_lock_use_system_modal_dialogs) {
if (backingPixmap.isNull()) {
setBackgroundColor(black);
}
else {
setBackgroundPixmap(backingPixmap);
}
}
if (backingPixmap.isNull()) {
setGeometry(0, 0, mRootWidth, mRootHeight);
erase();
}
else bitBlt(this, 0, 0, &backingPixmap);
if (trinity_desktop_lock_use_system_modal_dialogs) {
ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
}
}
}
if (m_startupStatusDialog) { m_startupStatusDialog->closeSMDialog(); m_startupStatusDialog=NULL; }
return false;
}
//---------------------------------------------------------------------------
//
void LockProcess::stopHack()
{
if (mHackProc.isRunning())
{
mHackProc.kill();
if (!mHackProc.wait(10))
{
mHackProc.kill(SIGKILL);
}
}
setCursor( tqarrowCursor );
trinity_desktop_hack_active = FALSE;
}
//---------------------------------------------------------------------------
//
void LockProcess::hackExited(TDEProcess *)
{
// Hack exited while we're supposed to be saving the screen.
// Make sure the saver window is black.
trinity_desktop_hack_active = FALSE;
usleep(100);
TQApplication::syncX();
if (!trinity_desktop_lock_use_system_modal_dialogs) {
if (backingPixmap.isNull()) {
setBackgroundColor(black);
}
else {
setBackgroundPixmap(backingPixmap);
}
}
if (backingPixmap.isNull()) {
setGeometry(0, 0, mRootWidth, mRootHeight);
erase();
}
else bitBlt(this, 0, 0, &backingPixmap);
if (!mSuspended) {
if (trinity_desktop_lock_use_system_modal_dialogs) {
ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
}
}
}
void LockProcess::displayLockDialogIfNeeded()
{
if (m_startupStatusDialog) {
m_startupStatusDialog->closeSMDialog(); m_startupStatusDialog=NULL;
}
if (!trinity_desktop_lock_in_sec_dlg) {
if (trinity_desktop_lock_use_system_modal_dialogs) {
if (!mBusy) {
mBusy = true;
if (mLocked) {
if (checkPass()) {
trinity_desktop_lock_closing_windows = true;
stopSaver();
kapp->quit();
}
}
mBusy = false;
}
}
}
}
void LockProcess::suspend()
{
if(!mSuspended)
{
if (trinity_desktop_lock_use_system_modal_dialogs) {
mSuspended = true;
stopHack();
ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
}
else {
TQString hackStatus;
mHackProc.kill(SIGSTOP);
mSuspended = true;
#if 0
// wait for the stop signal to take effect
while (hackStatus != "T") {
char hackstat[8192];
FILE *fp = fopen(TQString("/proc/%1/stat").arg(mHackProc.pid()).ascii(),"r");
if (fp != NULL) {
fgets (hackstat, 8192, fp);
fclose (fp);
}
hackstat[8191] = 0;
hackStatus = hackstat;
hackStatus = hackStatus.remove(TQRegExp("(*) ", TRUE, TRUE));
TQStringList hackStatusList = TQStringList::split(" ", hackStatus);
hackStatus = (*(hackStatusList.at(1)));
}
#endif
TQApplication::syncX();
usleep(100000); // Allow certain bad graphics drivers (*cough* fglrx *cough*) time to actually sync up the display
}
TQApplication::syncX();
mSavedScreen = TQPixmap::grabWindow( winId());
}
}
void LockProcess::resume( bool force )
{
if (trinity_desktop_lock_use_sak && (mHackDelayStartupTimer->isActive() || !mHackStartupEnabled)) {
return;
}
if( !force && (!mDialogs.isEmpty() || !mVisibility )) {
// no resuming with dialog visible or when not visible
if (trinity_desktop_lock_use_system_modal_dialogs) {
if (backingPixmap.isNull()) {
setBackgroundColor(black);
}
else {
setBackgroundPixmap(backingPixmap);
}
setGeometry(0, 0, mRootWidth, mRootHeight);
erase();
}
else {
setGeometry(0, 0, mRootWidth, mRootHeight);
}
return;
}
if ((mSuspended) && (mHackProc.isRunning()))
{
XForceScreenSaver(tqt_xdisplay(), ScreenSaverReset );
bitBlt( this, 0, 0, &mSavedScreen );
TQApplication::syncX();
mHackProc.kill(SIGCONT);
mSuspended = false;
}
else if (mSuspended && trinity_desktop_lock_use_system_modal_dialogs) {
startHack();
}
}
//---------------------------------------------------------------------------
//
// Show the password dialog
// This is called only in the master process
//
bool LockProcess::checkPass()
{
if (!mDialogs.isEmpty()) {
// Another dialog is already shown
// Abort!
return 0;
}
if (mInfoMessageDisplayed == false) {
if (mAutoLogout) {
killTimer(mAutoLogoutTimerId);
}
// Make sure we never launch the SAK or login dialog if windows are being closed down
// Otherwise we can get stuck in an irrecoverable state where any attempt to show the login screen is instantly aborted
if (trinity_desktop_lock_closing_windows)
return 0;
if (trinity_desktop_lock_use_sak) {
// Verify SAK operational status
TDEProcess* checkSATDEProcess = new TDEProcess;
*checkSATDEProcess << "tdmtsak" << "check";
checkSATDEProcess->start(TDEProcess::Block, TDEProcess::NoCommunication);
int retcode = checkSATDEProcess->exitStatus();
delete checkSATDEProcess;
if (retcode != 0) {
trinity_desktop_lock_use_sak = false;
}
}
if (trinity_desktop_lock_use_sak) {
// Wait for SAK press before continuing...
SAKDlg inDlg( this );
execDialog( &inDlg );
if (trinity_desktop_lock_closing_windows) {
return 0;
}
}
showVkbd();
PasswordDlg passDlg( this, &greetPlugin, (mShowLockDateTime)?mlockDateTime:TQDateTime());
int ret = execDialog( &passDlg );
hideVkbd();
if (mForceReject == true) {
ret = TQDialog::Rejected;
}
mForceReject = false;
XWindowAttributes rootAttr;
XGetWindowAttributes(tqt_xdisplay(), RootWindow(tqt_xdisplay(),
tqt_xscreen()), &rootAttr);
if(( rootAttr.your_event_mask & SubstructureNotifyMask ) == 0 )
{
kdWarning() << "ERROR: Something removed SubstructureNotifyMask from the root window!!!" << endl;
XSelectInput( tqt_xdisplay(), tqt_xrootwin(),
SubstructureNotifyMask | rootAttr.your_event_mask );
}
return ret == TQDialog::Accepted;
}
else {
return 0;
}
}
static void fakeFocusIn( WId window )
{
// We have keyboard grab, so this application will
// get keyboard events even without having focus.
// Fake FocusIn to make Qt realize it has the active
// window, so that it will correctly show cursor in the dialog.
XEvent ev;
memset(&ev, 0, sizeof(ev));
ev.xfocus.display = tqt_xdisplay();
ev.xfocus.type = FocusIn;
ev.xfocus.window = window;
ev.xfocus.mode = NotifyNormal;
ev.xfocus.detail = NotifyAncestor;
XSendEvent( tqt_xdisplay(), window, False, NoEventMask, &ev );
}
void LockProcess::resumeUnforced()
{
resume( false );
}
int LockProcess::execDialog( TQDialog *dlg )
{
currentDialog=dlg;
dlg->adjustSize();
TQRect rect = dlg->geometry();
rect.moveCenter(TDEGlobalSettings::desktopGeometry(TQCursor::pos()).center());
dlg->move( rect.topLeft() );
if (mDialogs.isEmpty())
{
suspend();
XChangeActivePointerGrab( tqt_xdisplay(), GRABEVENTS,
TQCursor(tqarrowCursor).handle(), CurrentTime);
}
mDialogs.prepend( dlg );
fakeFocusIn( dlg->winId());
if (trinity_desktop_lock_use_system_modal_dialogs) {
if (backingPixmap.isNull()) {
setGeometry(0, 0, mRootWidth, mRootHeight);
erase();
}
else {
bitBlt(this, 0, 0, &backingPixmap);
}
}
// dlg->exec may generate BadMatch errors, so make sure they are silently ignored
int (*oldHandler)(Display *, XErrorEvent *);
oldHandler = XSetErrorHandler(ignoreXError);
int rt = dlg->exec();
XSetErrorHandler(oldHandler);
while (mDialogControlLock == true) usleep(100000);
currentDialog = NULL;
mDialogs.remove( dlg );
if( mDialogs.isEmpty() ) {
HANDLE cursorHandle;
if (trinity_desktop_hack_active) {
cursorHandle = TQCursor(tqblankCursor).handle();
}
else {
cursorHandle = TQCursor(tqbusyCursor).handle();
}
XChangeActivePointerGrab( tqt_xdisplay(), GRABEVENTS,
cursorHandle, CurrentTime);
if (trinity_desktop_lock_use_system_modal_dialogs) {
// Slight delay before screensaver resume to allow the dialog window to fully disappear
if (hackResumeTimer == NULL) {
hackResumeTimer = new TQTimer( this );
connect( hackResumeTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(resumeUnforced()) );
}
if (mResizingDesktopLock == false) {
hackResumeTimer->start( 10, TRUE );
}
}
else {
resume( false );
}
} else {
fakeFocusIn( mDialogs.first()->winId());
currentDialog = dynamic_cast<TQDialog*>(mDialogs.first());
}
return rt;
}
void LockProcess::slotForcePaintBackground()
{
TQPixmap blankPixmap(mRootWidth, mRootHeight);
blankPixmap.fill(Qt::black);
slotPaintBackground(blankPixmap);
printf("[WARNING] Unable to obtain desktop wallpaper in a timely manner. High system load or possibly a TDE bug!\n\r"); fflush(stdout);
}
void LockProcess::slotPaintBackground(const TQPixmap &rpm)
{
if (mEnsureScreenHiddenTimer) {
mEnsureScreenHiddenTimer->stop();
}
else {
mEnsureScreenHiddenTimer = new TQTimer( this );
connect( mEnsureScreenHiddenTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotForcePaintBackground()) );
}
// Only remove the mask widget once the resize is 100% complete!
if (m_maskWidget) {
delete m_maskWidget;
m_maskWidget = NULL;
XSync(tqt_xdisplay(), False);
}
TQPixmap pm = rpm;
if (TQPaintDevice::x11AppDepth() == 32) {
// Remove the alpha components from the image
TQImage correctedImage = pm.convertToImage();
correctedImage = correctedImage.convertDepth(32);
correctedImage.setAlphaBuffer(true);
int w = correctedImage.width();
int h = correctedImage.height();
for (int y = 0; y < h; ++y) {
TQRgb *ls = (TQRgb *)correctedImage.scanLine( y );
for (int x = 0; x < w; ++x) {
TQRgb l = ls[x];
int r = int( tqRed( l ) );
int g = int( tqGreen( l ) );
int b = int( tqBlue( l ) );
int a = int( 255 );
ls[x] = tqRgba( r, g, b, a );
}
}
pm.convertFromImage(correctedImage);
}
backingPixmap = pm;
if ((trinity_desktop_lock_delay_screensaver_start && trinity_desktop_lock_forced) || (!mHackStartupEnabled)) {
setBackgroundPixmap(backingPixmap);
setGeometry(0, 0, mRootWidth, mRootHeight);
erase();
}
}
void LockProcess::preparePopup()
{
TQWidget *dlg = (TQWidget *)sender();
mDialogs.prepend( dlg );
fakeFocusIn( dlg->winId() );
}
void LockProcess::cleanupPopup()
{
TQWidget *dlg = (TQWidget *)sender();
mDialogs.remove( dlg );
if ( mDialogs.isEmpty() ) {
fakeFocusIn( mDialogs.first()->winId() );
}
}
void LockProcess::doFunctionKeyBroadcast() {
// Provide a clean, pretty display switch by hiding the password dialog here
// This does NOT work with the SAK or system modal dialogs!
if ((!trinity_desktop_lock_use_system_modal_dialogs) && (!trinity_desktop_lock_use_sak)) {
mBusy=true;
TQTimer::singleShot(1000, this, TQT_SLOT(slotDeadTimePassed()));
if (mkeyCode == XKeysymToKeycode(tqt_xdisplay(), XF86XK_Display)) {
while (mDialogControlLock == true) usleep(100000);
mDialogControlLock = true;
currentDialog->close(); // DO NOT use closeCurrentWindow() here!
mDialogControlLock = false;
}
}
DCOPRef ref( "*", "MainApplication-Interface");
ref.send("sendFakeKey", DCOPArg(mkeyCode , "unsigned int"));
}
//---------------------------------------------------------------------------
//
// X11 Event.
//
bool LockProcess::x11Event(XEvent *event)
{
// Allow certain very specific keypresses through
// Key: Reason:
// XF86Display You need to be able to see the screen when unlocking your computer
// XF86AudioMute Would be nice to be able to shut your computer up in an emergency while it is locked
// XF86AudioRaiseVolume Ditto
// XF86AudioLowerVolume Ditto
//if ((event->type == KeyPress) || (event->type == KeyRelease)) {
if (event->type == KeyPress) {
if ((event->xkey.keycode == XKeysymToKeycode(event->xkey.display, XF86XK_Display)) || \
(event->xkey.keycode == XKeysymToKeycode(event->xkey.display, XF86XK_AudioMute)) || \
(event->xkey.keycode == XKeysymToKeycode(event->xkey.display, XF86XK_AudioRaiseVolume)) || \
(event->xkey.keycode == XKeysymToKeycode(event->xkey.display, XF86XK_AudioLowerVolume))) {
mkeyCode = event->xkey.keycode;
TQTimer::singleShot( 100, this, TQT_SLOT(doFunctionKeyBroadcast()) );
return true;
}
}
switch (event->type)
{
case ButtonPress:
case MotionNotify:
case ButtonRelease:
if( forwardVkbdEvent( event ))
return true; // filter out
// fall through
case KeyPress:
if ((mHackDelayStartupTimer) && (mHackDelayStartupTimer->isActive())) {
if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
}
if (mBusy || !mDialogs.isEmpty())
break;
mBusy = true;
if (trinity_desktop_lock_delay_screensaver_start) {
if (mLocked) {
ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
}
if ((!mLocked) && (!trinity_desktop_lock_in_sec_dlg))
{
stopSaver();
kapp->quit();
}
if (mAutoLogout) // we need to restart the auto logout countdown
{
killTimer(mAutoLogoutTimerId);
mAutoLogoutTimerId = startTimer(mAutoLogoutTimeout);
}
}
else {
if (!mLocked || checkPass())
{
trinity_desktop_lock_closing_windows = true;
stopSaver();
kapp->quit();
}
else if (mAutoLogout) // we need to restart the auto logout countdown
{
killTimer(mAutoLogoutTimerId);
mAutoLogoutTimerId = startTimer(mAutoLogoutTimeout);
}
}
mBusy = false;
return true;
case VisibilityNotify:
if( event->xvisibility.window == winId())
{ // mVisibility == false means the screensaver is not visible at all
// e.g. when switched to text console
mVisibility = !(event->xvisibility.state == VisibilityFullyObscured);
if(!mVisibility) {
mSuspendTimer.start(2000, true);
}
else
{
mSuspendTimer.stop();
if (mResizingDesktopLock == false) {
if (trinity_desktop_lock_delay_screensaver_start && trinity_desktop_lock_forced && trinity_desktop_lock_use_system_modal_dialogs) {
// Do nothing
}
else {
if (mHackStartupEnabled == true) {
resume( false );
}
else {
if (trinity_desktop_lock_use_system_modal_dialogs == true) {
ENABLE_CONTINUOUS_LOCKDLG_DISPLAY
if (mHackStartupEnabled) mHackDelayStartupTimer->start(mHackDelayStartupTimeout, TRUE);
}
else {
resume( false );
}
}
}
}
}
if (event->xvisibility.state != VisibilityUnobscured) {
stayOnTop();
}
}
break;
case ConfigureNotify: // from SubstructureNotifyMask on the root window
if(event->xconfigure.event == tqt_xrootwin()) {
stayOnTop();
}
for( TQValueList< VkbdWindow >::Iterator it = mVkbdWindows.begin();
it != mVkbdWindows.end();
++it ) {
if( (*it).id == event->xconfigure.window ) {
(*it).rect = TQRect( event->xconfigure.x, event->xconfigure.y,
event->xconfigure.width, event->xconfigure.height );
break;
}
}
break;
case MapNotify: // from SubstructureNotifyMask on the root window
windowAdded( event->xmap.window, false );
if( event->xmap.event == tqt_xrootwin())
stayOnTop();
break;
case DestroyNotify:
for( TQValueList< VkbdWindow >::Iterator it = mVkbdWindows.begin();
it != mVkbdWindows.end();
++it )
if( (*it).id == event->xdestroywindow.window ) {
mVkbdWindows.remove( it );
break;
}
break;
}
// We have grab with the grab window being the root window.
// This results in key events being sent to the root window,
// but they should be sent to the dialog if it's visible.
// It could be solved by setFocus() call, but that would mess
// the focus after this process exits.
// Qt seems to be quite hard to persuade to redirect the event,
// so let's simply dupe it with correct destination window,
// and ignore the original one.
if(!mDialogs.isEmpty() && ( event->type == KeyPress || event->type == KeyRelease)
&& event->xkey.window != mDialogs.first()->winId())
{
XEvent ev2 = *event;
ev2.xkey.window = ev2.xkey.subwindow = mDialogs.first()->winId();
tqApp->x11ProcessEvent( &ev2 );
return true;
}
return false;
}
void LockProcess::stayOnTop()
{
if(!mDialogs.isEmpty() || !mVkbdWindows.isEmpty())
{
// this restacking is written in a way so that
// if the stacking positions actually don't change,
// all restacking operations will be no-op,
// and no ConfigureNotify will be generated,
// thus avoiding possible infinite loops
if( !mVkbdWindows.isEmpty())
XRaiseWindow( tqt_xdisplay(), mVkbdWindows.first().id );
else
XRaiseWindow( tqt_xdisplay(), mDialogs.first()->winId()); // raise topmost
// and stack others below it
Window* stack = new Window[ mDialogs.count() + mVkbdWindows.count() + 1 ];
int count = 0;
for( TQValueList< VkbdWindow >::ConstIterator it = mVkbdWindows.begin();
it != mVkbdWindows.end();
++it )
stack[ count++ ] = (*it).id;
for( TQValueList< TQWidget* >::ConstIterator it = mDialogs.begin();
it != mDialogs.end();
++it )
stack[ count++ ] = (*it)->winId();
stack[ count++ ] = winId();
XRestackWindows( x11Display(), stack, count );
delete[] stack;
}
else
XRaiseWindow(tqt_xdisplay(), winId());
}
void LockProcess::checkDPMSActive()
{
#ifdef HAVE_DPMS
BOOL on;
CARD16 state;
DPMSInfo(tqt_xdisplay(), &state, &on);
//kdDebug() << "checkDPMSActive " << on << " " << state << endl;
if (state == DPMSModeStandby || state == DPMSModeSuspend || state == DPMSModeOff)
{
suspend();
} else if ( mSuspended )
{
if (mResizingDesktopLock == false) {
resume( true );
}
}
#endif
}
#if defined(HAVE_XF86MISC) && defined(HAVE_XF86MISCSETGRABKEYSSTATE)
// see http://cvsweb.xfree86.org/cvsweb/xc/programs/Xserver/hw/xfree86/common/xf86Events.c#rev3.113
// This allows enabling the "Allow{Deactivate/Closedown}Grabs" options in XF86Config,
// and kdesktop_lock will still lock the session.
static enum { Unknown, Yes, No } can_do_xf86_lock = Unknown;
void LockProcess::lockXF86()
{
if( can_do_xf86_lock == Unknown )
{
int major, minor;
if( XF86MiscQueryVersion( tqt_xdisplay(), &major, &minor )
&& major >= 0 && minor >= 5 )
can_do_xf86_lock = Yes;
else
can_do_xf86_lock = No;
}
if( can_do_xf86_lock != Yes )
return;
if( mRestoreXF86Lock )
return;
if( XF86MiscSetGrabKeysState( tqt_xdisplay(), False ) != MiscExtGrabStateSuccess )
return;
// success
mRestoreXF86Lock = true;
}
void LockProcess::unlockXF86()
{
if( can_do_xf86_lock != Yes )
return;
if( !mRestoreXF86Lock )
return;
XF86MiscSetGrabKeysState( tqt_xdisplay(), True );
mRestoreXF86Lock = false;
}
#else
void LockProcess::lockXF86()
{
}
void LockProcess::unlockXF86()
{
}
#endif
void LockProcess::msgBox( TQMessageBox::Icon type, const TQString &txt )
{
TQDialog box( 0, "messagebox", true, (trinity_desktop_lock_use_system_modal_dialogs?((WFlags)WStyle_StaysOnTop):((WFlags)WX11BypassWM)) );
if (trinity_desktop_lock_use_system_modal_dialogs) {
// Signal that we do not want any window controls to be shown at all
Atom kde_wm_system_modal_notification;
kde_wm_system_modal_notification = XInternAtom(tqt_xdisplay(), "_KDE_WM_MODAL_SYS_NOTIFICATION", False);
XChangeProperty(tqt_xdisplay(), box.winId(), kde_wm_system_modal_notification, XA_INTEGER, 32, PropModeReplace, (unsigned char *) "TRUE", 1L);
}
box.setCaption(i18n("Authentication Subsystem Notice"));
TQFrame *winFrame = new TQFrame( &box );
if (trinity_desktop_lock_use_system_modal_dialogs)
winFrame->setFrameStyle( TQFrame::NoFrame );
else
winFrame->setFrameStyle( TQFrame::WinPanel | TQFrame::Raised );
winFrame->setLineWidth( 2 );
TQLabel *label1 = new TQLabel( winFrame );
label1->setPixmap( TQMessageBox::standardIcon( type ) );
TQLabel *label2 = new TQLabel( txt, winFrame );
KPushButton *button = new KPushButton( KStdGuiItem::ok(), winFrame );
button->setDefault( true );
button->setSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Preferred ) );
connect( button, TQT_SIGNAL( clicked() ), &box, TQT_SLOT( accept() ) );
TQVBoxLayout *vbox = new TQVBoxLayout( &box );
vbox->addWidget( winFrame );
TQGridLayout *grid = new TQGridLayout( winFrame, 2, 2, 10 );
grid->addWidget( label1, 0, 0, Qt::AlignCenter );
grid->addWidget( label2, 0, 1, Qt::AlignCenter );
grid->addMultiCellWidget( button, 1,1, 0,1, Qt::AlignCenter );
execDialog( &box );
}
static int run_vkbd = -1;
void LockProcess::showVkbd()
{
if( run_vkbd == - 1 ) {
int status = system( "hal-find-by-property --key system.formfactor.subtype --string tabletpc" );
// status = 0; // enable for testing
run_vkbd = ( WIFEXITED( status ) && WEXITSTATUS( status ) == 0
&& !TDEStandardDirs::findExe( "xvkbd" ).isEmpty()) ? 1 : 0;
}
if( run_vkbd ) {
mVkbdWindows.clear();
mVkbdLastEventWindow = None;
mKWinModule = new KWinModule( NULL, KWinModule::INFO_WINDOWS );
connect( mKWinModule, TQT_SIGNAL( windowAdded( WId )), TQT_SLOT( windowAdded( WId )));
mVkbdProcess = new TDEProcess;
*mVkbdProcess << "xvkbd" << "-compact" << "-geometry" << "-0-0" << "-xdm";
mVkbdProcess->start();
}
}
void LockProcess::hideVkbd()
{
if( mVkbdProcess != NULL ) {
mVkbdProcess->kill();
delete mVkbdProcess;
mVkbdProcess = NULL;
delete mKWinModule;
mKWinModule = NULL;
mVkbdWindows.clear();
}
}
void LockProcess::windowAdded( WId w )
{
windowAdded( w, true );
}
void LockProcess::windowAdded( WId w, bool managed )
{
// KWin::windowInfo may generate BadWindow errors, so make sure they are silently ignored
int (*oldHandler)(Display *, XErrorEvent *);
oldHandler = XSetErrorHandler(ignoreXError);
KWin::WindowInfo info = KWin::windowInfo( w, 0, NET::WM2WindowClass );
XSetErrorHandler(oldHandler);
if( info.windowClassClass().lower() != "xvkbd" )
return;
// Unmanaged windows (i.e. popups) don't currently work anyway, since they
// don't have WM_CLASS set anyway. I could perhaps try tricks with X id
// ranges if really needed.
if( managed ) {
// withdraw the window, wait for it to be withdrawn, reparent it directly
// to root at the right position
XWithdrawWindow( tqt_xdisplay(), w, tqt_xscreen());
for(;;) {
Atom type;
int format;
unsigned long length, after;
unsigned char *data;
int r = XGetWindowProperty( tqt_xdisplay(), w, tqt_wm_state, 0, 2,
false, AnyPropertyType, &type, &format,
&length, &after, &data );
bool withdrawn = true;
if ( r == Success && data && format == 32 ) {
TQ_UINT32 *wstate = (TQ_UINT32*)data;
withdrawn = (*wstate == WithdrawnState );
XFree( (char *)data );
}
if( withdrawn )
break;
}
}
XSelectInput( tqt_xdisplay(), w, StructureNotifyMask );
XWindowAttributes attr_geom;
if( !XGetWindowAttributes( tqt_xdisplay(), w, &attr_geom ))
return;
int x = XDisplayWidth( tqt_xdisplay(), tqt_xscreen()) - attr_geom.width;
int y = XDisplayHeight( tqt_xdisplay(), tqt_xscreen()) - attr_geom.height;
if( managed ) {
XSetWindowAttributes attr;
if (!trinity_desktop_lock_use_system_modal_dialogs) {
attr.override_redirect = True;
XChangeWindowAttributes( tqt_xdisplay(), w, CWOverrideRedirect, &attr );
}
XReparentWindow( tqt_xdisplay(), w, tqt_xrootwin(), x, y );
XMapWindow( tqt_xdisplay(), w );
}
VkbdWindow data;
data.id = w;
data.rect = TQRect( x, y, attr_geom.width, attr_geom.height );
mVkbdWindows.prepend( data );
}
bool LockProcess::forwardVkbdEvent( XEvent* event )
{
if( mVkbdProcess == NULL )
return false;
TQPoint pos;
Time time;
switch( event->type )
{
case ButtonPress:
case ButtonRelease:
pos = TQPoint( event->xbutton.x, event->xbutton.y );
time = event->xbutton.time;
break;
case MotionNotify:
pos = TQPoint( event->xmotion.x, event->xmotion.y );
time = event->xmotion.time;
break;
default:
return false;
}
// vkbd windows are kept topmost, so just find the first one in the position
for( TQValueList< VkbdWindow >::ConstIterator it = mVkbdWindows.begin();
it != mVkbdWindows.end();
++it ) {
if( TQT_TQRECT_OBJECT((*it).rect).contains( pos )) {
// Find the subwindow where the event should actually go.
// Not exactly cheap in the number of X roundtrips but oh well.
Window window = (*it).id;
Window root, child;
int root_x, root_y, x, y;
unsigned int mask;
for(;;) {
if( !XQueryPointer( tqt_xdisplay(), window, &root, &child, &root_x, &root_y, &x, &y, &mask ))
return false;
if( child == None )
break;
window = child;
}
switch( event->type )
{
case ButtonPress:
case ButtonRelease:
event->xbutton.x = x;
event->xbutton.y = y;
event->xbutton.subwindow = None;
break;
case MotionNotify:
event->xmotion.x = x;
event->xmotion.y = y;
event->xmotion.subwindow = None;
break;
}
event->xany.window = window;
sendVkbdFocusInOut( window, time );
XSendEvent( tqt_xdisplay(), window, False, 0, event );
return true;
}
}
sendVkbdFocusInOut( None, time );
return false;
}
// Fake EnterNotify/LeaveNotify events as the mouse moves. They're not sent by X
// because of the grab and having them makes xvkbd highlight the buttons (but
// not needed otherwise it seems).
void LockProcess::sendVkbdFocusInOut( WId window, Time t )
{
if( mVkbdLastEventWindow == window )
return;
if( mVkbdLastEventWindow != None ) {
XEvent e;
e.xcrossing.type = LeaveNotify;
e.xcrossing.display = tqt_xdisplay();
e.xcrossing.window = mVkbdLastEventWindow;
e.xcrossing.root = tqt_xrootwin();
e.xcrossing.subwindow = None;
e.xcrossing.time = t;
e.xcrossing.x = 0;
e.xcrossing.y = 0;
e.xcrossing.x_root = -1;
e.xcrossing.y_root = -1;
e.xcrossing.mode = NotifyNormal;
e.xcrossing.detail = NotifyAncestor;
e.xcrossing.same_screen = True;
e.xcrossing.focus = False;
e.xcrossing.state = 0;
XSendEvent( tqt_xdisplay(), mVkbdLastEventWindow, False, 0, &e );
}
mVkbdLastEventWindow = window;
if( mVkbdLastEventWindow != None ) {
XEvent e;
e.xcrossing.type = EnterNotify;
e.xcrossing.display = tqt_xdisplay();
e.xcrossing.window = mVkbdLastEventWindow;
e.xcrossing.root = tqt_xrootwin();
e.xcrossing.subwindow = None;
e.xcrossing.time = t;
e.xcrossing.x = 0;
e.xcrossing.y = 0;
e.xcrossing.x_root = 0;
e.xcrossing.y_root = 0;
e.xcrossing.mode = NotifyNormal;
e.xcrossing.detail = NotifyAncestor;
e.xcrossing.same_screen = True;
e.xcrossing.focus = False;
e.xcrossing.state = 0;
XSendEvent( tqt_xdisplay(), mVkbdLastEventWindow, False, 0, &e );
}
}
void LockProcess::slotMouseActivity(XEvent *event)
{
bool inFrame = 0;
bool inDialog = 0;
XButtonEvent *be = (XButtonEvent *) event;
XMotionEvent *me = (XMotionEvent *) event;
if ((event->type == ButtonPress) && (!mDialogs.isEmpty())) {
// Get geometry including window frame/titlebar
TQRect fgeom = mDialogs.first()->frameGeometry();
TQRect wgeom = mDialogs.first()->geometry();
if (((be->x_root > fgeom.x()) && (be->y_root > fgeom.y())) && ((be->x_root < (fgeom.x()+fgeom.width())) && (be->y_root < (fgeom.y()+fgeom.height())))) {
inFrame = 1;
}
if (((be->x_root > wgeom.x()) && (be->y_root > wgeom.y())) && ((be->x_root < (wgeom.x()+wgeom.width())) && (be->y_root < (wgeom.y()+wgeom.height())))) {
inDialog = 1;
}
// Clicked inside dialog; set focus
if (inFrame == TRUE) {
WId window = mDialogs.first()->winId();
XSetInputFocus(tqt_xdisplay(), window, RevertToParent, CurrentTime);
fakeFocusIn(window);
// Why this needs to be repeated I have no idea...
XSetInputFocus(tqt_xdisplay(), window, RevertToParent, CurrentTime);
fakeFocusIn(window);
}
// Clicked inside window handle (or border); drag window
if ((inFrame == TRUE) && (inDialog == FALSE)) {
TQPoint oldPoint = mDialogs.first()->pos();
m_mouseDown = 1;
m_dialogPrevX = oldPoint.x();
m_dialogPrevY = oldPoint.y();
m_mousePrevX = be->x_root;
m_mousePrevY = be->y_root;
XChangeActivePointerGrab( tqt_xdisplay(), GRABEVENTS, TQCursor(tqsizeAllCursor).handle(), CurrentTime);
}
}
// Drag the window...
if (event->type == MotionNotify) {
if (m_mouseDown == TRUE) {
int deltaX = me->x_root - m_mousePrevX;
int deltaY = me->y_root - m_mousePrevY;
m_dialogPrevX = m_dialogPrevX + deltaX;
m_dialogPrevY = m_dialogPrevY + deltaY;
if (!mDialogs.isEmpty()) mDialogs.first()->move(m_dialogPrevX, m_dialogPrevY);
m_mousePrevX = me->x_root;
m_mousePrevY = me->y_root;
}
}
if (event->type == ButtonRelease) {
m_mouseDown = 0;
XChangeActivePointerGrab( tqt_xdisplay(), GRABEVENTS, TQCursor(tqarrowCursor).handle(), CurrentTime);
}
}
#include "lockprocess.moc"
|