Commit a2bd897064734412e26912b56ed99ed74a0b732e

Ryan C. Gordon 2013-10-18T01:36:41

Don't supply duplicate X11 symbols inside SDL. Fixes static linking when something else also uses X11.

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
diff --git a/src/video/x11/SDL_x11clipboard.c b/src/video/x11/SDL_x11clipboard.c
index 970aeaf..e6ca86b 100644
--- a/src/video/x11/SDL_x11clipboard.c
+++ b/src/video/x11/SDL_x11clipboard.c
@@ -31,7 +31,7 @@
 
 /* If you don't support UTF-8, you might use XA_STRING here */
 #ifdef X_HAVE_UTF8_STRING
-#define TEXT_FORMAT XInternAtom(display, "UTF8_STRING", False)
+#define TEXT_FORMAT X11_XInternAtom(display, "UTF8_STRING", False)
 #else
 #define TEXT_FORMAT XA_STRING
 #endif
@@ -55,7 +55,7 @@ X11_SetClipboardText(_THIS, const char *text)
     Display *display = ((SDL_VideoData *) _this->driverdata)->display;
     Atom format;
     Window window;
-    Atom XA_CLIPBOARD = XInternAtom(display, "CLIPBOARD", 0);
+    Atom XA_CLIPBOARD = X11_XInternAtom(display, "CLIPBOARD", 0);
 
     /* Get the SDL window that will own the selection */
     window = GetWindow(_this);
@@ -65,17 +65,17 @@ X11_SetClipboardText(_THIS, const char *text)
 
     /* Save the selection on the root window */
     format = TEXT_FORMAT;
-    XChangeProperty(display, DefaultRootWindow(display),
+    X11_XChangeProperty(display, DefaultRootWindow(display),
         XA_CUT_BUFFER0, format, 8, PropModeReplace,
         (const unsigned char *)text, SDL_strlen(text));
 
     if (XA_CLIPBOARD != None &&
-        XGetSelectionOwner(display, XA_CLIPBOARD) != window) {
-        XSetSelectionOwner(display, XA_CLIPBOARD, window, CurrentTime);
+        X11_XGetSelectionOwner(display, XA_CLIPBOARD) != window) {
+        X11_XSetSelectionOwner(display, XA_CLIPBOARD, window, CurrentTime);
     }
 
-    if (XGetSelectionOwner(display, XA_PRIMARY) != window) {
-        XSetSelectionOwner(display, XA_PRIMARY, window, CurrentTime);
+    if (X11_XGetSelectionOwner(display, XA_PRIMARY) != window) {
+        X11_XSetSelectionOwner(display, XA_PRIMARY, window, CurrentTime);
     }
     return 0;
 }
@@ -97,7 +97,7 @@ X11_GetClipboardText(_THIS)
     char *text;
     Uint32 waitStart;
     Uint32 waitElapsed;
-    Atom XA_CLIPBOARD = XInternAtom(display, "CLIPBOARD", 0);
+    Atom XA_CLIPBOARD = X11_XInternAtom(display, "CLIPBOARD", 0);
     if (XA_CLIPBOARD == None) {
         SDL_SetError("Couldn't access X clipboard");
         return SDL_strdup("");
@@ -108,15 +108,15 @@ X11_GetClipboardText(_THIS)
     /* Get the window that holds the selection */
     window = GetWindow(_this);
     format = TEXT_FORMAT;
-    owner = XGetSelectionOwner(display, XA_CLIPBOARD);
+    owner = X11_XGetSelectionOwner(display, XA_CLIPBOARD);
     if ((owner == None) || (owner == window)) {
         owner = DefaultRootWindow(display);
         selection = XA_CUT_BUFFER0;
     } else {
         /* Request that the selection owner copy the data to our window */
         owner = window;
-        selection = XInternAtom(display, "SDL_SELECTION", False);
-        XConvertSelection(display, XA_CLIPBOARD, format, selection, owner,
+        selection = X11_XInternAtom(display, "SDL_SELECTION", False);
+        X11_XConvertSelection(display, XA_CLIPBOARD, format, selection, owner,
             CurrentTime);
 
         /* When using synergy on Linux and when data has been put in the clipboard
@@ -139,7 +139,7 @@ X11_GetClipboardText(_THIS)
         }
     }
 
-    if (XGetWindowProperty(display, owner, selection, 0, INT_MAX/4, False,
+    if (X11_XGetWindowProperty(display, owner, selection, 0, INT_MAX/4, False,
             format, &seln_type, &seln_format, &nbytes, &overflow, &src)
             == Success) {
         if (seln_type == format) {
@@ -149,7 +149,7 @@ X11_GetClipboardText(_THIS)
                 text[nbytes] = '\0';
             }
         }
-        XFree(src);
+        X11_XFree(src);
     }
 
     if (!text) {
diff --git a/src/video/x11/SDL_x11dyn.c b/src/video/x11/SDL_x11dyn.c
index f9a2fa6..24caea4 100644
--- a/src/video/x11/SDL_x11dyn.c
+++ b/src/video/x11/SDL_x11dyn.c
@@ -103,24 +103,19 @@ X11_GetSym(const char *fnname, int *pHasModule)
     return fn;
 }
 
+#endif /* SDL_VIDEO_DRIVER_X11_DYNAMIC */
 
 /* Define all the function pointers and wrappers... */
 #define SDL_X11_MODULE(modname)
-#define SDL_X11_SYM(rc,fn,params,args,ret) \
-    typedef rc (*SDL_DYNX11FN_##fn) params; \
-    static SDL_DYNX11FN_##fn p##fn = NULL; \
-    rc fn params { ret p##fn args ; }
+#define SDL_X11_SYM(rc,fn,params,args,ret) SDL_DYNX11FN_##fn X11_##fn = NULL;
 #include "SDL_x11sym.h"
 #undef SDL_X11_MODULE
 #undef SDL_X11_SYM
-#endif /* SDL_VIDEO_DRIVER_X11_DYNAMIC */
 
 /* Annoying varargs entry point... */
 #ifdef X_HAVE_UTF8_STRING
-typedef XIC(*SDL_DYNX11FN_XCreateIC) (XIM,...);
-SDL_DYNX11FN_XCreateIC pXCreateIC = NULL;
-typedef char *(*SDL_DYNX11FN_XGetICValues) (XIC, ...);
-SDL_DYNX11FN_XGetICValues pXGetICValues = NULL;
+SDL_DYNX11FN_XCreateIC X11_XCreateIC = NULL;
+SDL_DYNX11FN_XGetICValues X11_XGetICValues = NULL;
 #endif
 
 /* These SDL_X11_HAVE_* flags are here whether you have dynamic X11 or not. */
@@ -130,15 +125,11 @@ SDL_DYNX11FN_XGetICValues pXGetICValues = NULL;
 #undef SDL_X11_MODULE
 #undef SDL_X11_SYM
 
-
-#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
 static int x11_load_refcount = 0;
-#endif
 
 void
 SDL_X11_UnloadSymbols(void)
 {
-#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
     /* Don't actually unload if more than one module is using the libs... */
     if (x11_load_refcount > 0) {
         if (--x11_load_refcount == 0) {
@@ -146,25 +137,26 @@ SDL_X11_UnloadSymbols(void)
 
             /* set all the function pointers to NULL. */
 #define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 0;
-#define SDL_X11_SYM(rc,fn,params,args,ret) p##fn = NULL;
+#define SDL_X11_SYM(rc,fn,params,args,ret) X11_##fn = NULL;
 #include "SDL_x11sym.h"
 #undef SDL_X11_MODULE
 #undef SDL_X11_SYM
 
 #ifdef X_HAVE_UTF8_STRING
-            pXCreateIC = NULL;
-            pXGetICValues = NULL;
+            X11_XCreateIC = NULL;
+            X11_XGetICValues = NULL;
 #endif
 
+#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
             for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
                 if (x11libs[i].lib != NULL) {
                     SDL_UnloadObject(x11libs[i].lib);
                     x11libs[i].lib = NULL;
                 }
             }
+#endif
         }
     }
-#endif
 }
 
 /* returns non-zero if all needed symbols were loaded. */
@@ -173,9 +165,9 @@ SDL_X11_LoadSymbols(void)
 {
     int rc = 1;                 /* always succeed if not using Dynamic X11 stuff. */
 
-#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
     /* deal with multiple modules (dga, x11, etc) needing these symbols... */
     if (x11_load_refcount++ == 0) {
+#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
         int i;
         int *thismod = NULL;
         for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
@@ -191,15 +183,15 @@ SDL_X11_LoadSymbols(void)
 #undef SDL_X11_SYM
 
 #define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname;
-#define SDL_X11_SYM(a,fn,x,y,z) p##fn = (SDL_DYNX11FN_##fn) X11_GetSym(#fn,thismod);
+#define SDL_X11_SYM(a,fn,x,y,z) X11_##fn = (SDL_DYNX11FN_##fn) X11_GetSym(#fn,thismod);
 #include "SDL_x11sym.h"
 #undef SDL_X11_MODULE
 #undef SDL_X11_SYM
 
 #ifdef X_HAVE_UTF8_STRING
-        pXCreateIC = (SDL_DYNX11FN_XCreateIC)
+        X11_XCreateIC = (SDL_DYNX11FN_XCreateIC)
                         X11_GetSym("XCreateIC", &SDL_X11_HAVE_UTF8);
-        pXGetICValues = (SDL_DYNX11FN_XGetICValues)
+        X11_XGetICValues = (SDL_DYNX11FN_XGetICValues)
                         X11_GetSym("XGetICValues", &SDL_X11_HAVE_UTF8);
 #endif
 
@@ -211,19 +203,21 @@ SDL_X11_LoadSymbols(void)
             SDL_X11_UnloadSymbols();
             rc = 0;
         }
-    }
-#else
+
+#else  /* no dynamic X11 */
+
 #define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; /* default yes */
-#define SDL_X11_SYM(a,fn,x,y,z)
+#define SDL_X11_SYM(a,fn,x,y,z) X11_##fn = fn;
 #include "SDL_x11sym.h"
 #undef SDL_X11_MODULE
 #undef SDL_X11_SYM
 
 #ifdef X_HAVE_UTF8_STRING
-    pXCreateIC = XCreateIC;
-    pXGetICValues = XGetICValues;
+        X11_XCreateIC = XCreateIC;
+        X11_XGetICValues = XGetICValues;
 #endif
 #endif
+    }
 
     return rc;
 }
diff --git a/src/video/x11/SDL_x11dyn.h b/src/video/x11/SDL_x11dyn.h
index 2cebf3b..168c07e 100644
--- a/src/video/x11/SDL_x11dyn.h
+++ b/src/video/x11/SDL_x11dyn.h
@@ -69,35 +69,34 @@
 #include <X11/extensions/xf86vmode.h>
 #endif
 
-/*
- * When using the "dynamic X11" functionality, we duplicate all the Xlib
- *  symbols that would be referenced by SDL inside of SDL itself.
- *  These duplicated symbols just serve as passthroughs to the functions
- *  in Xlib, that was dynamically loaded.
- *
- * This allows us to use Xlib as-is when linking against it directly, but
- *  also handles all the strange cases where there was code in the Xlib
- *  headers that may or may not exist or vary on a given platform.
- */
 #ifdef __cplusplus
 extern "C"
 {
 #endif
 
 /* evil function signatures... */
-    typedef Bool(*SDL_X11_XESetWireToEventRetType) (Display *, XEvent *,
-                                                    xEvent *);
-    typedef int (*SDL_X11_XSynchronizeRetType) (Display *);
-    typedef Status(*SDL_X11_XESetEventToWireRetType) (Display *, XEvent *,
-                                                      xEvent *);
-
-    int SDL_X11_LoadSymbols(void);
-    void SDL_X11_UnloadSymbols(void);
+typedef Bool(*SDL_X11_XESetWireToEventRetType) (Display *, XEvent *, xEvent *);
+typedef int (*SDL_X11_XSynchronizeRetType) (Display *);
+typedef Status(*SDL_X11_XESetEventToWireRetType) (Display *, XEvent *, xEvent *);
+
+int SDL_X11_LoadSymbols(void);
+void SDL_X11_UnloadSymbols(void);
+
+/* Declare all the function pointers and wrappers... */
+#define SDL_X11_MODULE(modname)
+#define SDL_X11_SYM(rc,fn,params,args,ret) \
+    typedef rc (*SDL_DYNX11FN_##fn) params; \
+    extern SDL_DYNX11FN_##fn X11_##fn;
+#include "SDL_x11sym.h"
+#undef SDL_X11_MODULE
+#undef SDL_X11_SYM
 
-/* That's really annoying...make these function pointers no matter what. */
+/* Annoying varargs entry point... */
 #ifdef X_HAVE_UTF8_STRING
-    extern XIC(*pXCreateIC) (XIM, ...);
-    extern char *(*pXGetICValues) (XIC, ...);
+typedef XIC(*SDL_DYNX11FN_XCreateIC) (XIM,...);
+typedef char *(*SDL_DYNX11FN_XGetICValues) (XIC, ...);
+extern SDL_DYNX11FN_XCreateIC X11_XCreateIC;
+extern SDL_DYNX11FN_XGetICValues X11_XGetICValues;
 #endif
 
 /* These SDL_X11_HAVE_* flags are here whether you have dynamic X11 or not. */
@@ -107,7 +106,6 @@ extern "C"
 #undef SDL_X11_MODULE
 #undef SDL_X11_SYM
 
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c
index c260019..593b2be 100644
--- a/src/video/x11/SDL_x11events.c
+++ b/src/video/x11/SDL_x11events.c
@@ -48,7 +48,7 @@ typedef struct {
 } SDL_x11Prop;
 
 /* Reads property
-   Must call XFree on results
+   Must call X11_XFree on results
  */
 static void X11_ReadProperty(SDL_x11Prop *p, Display *disp, Window w, Atom prop)
 {
@@ -60,8 +60,8 @@ static void X11_ReadProperty(SDL_x11Prop *p, Display *disp, Window w, Atom prop)
     int bytes_fetch = 0;
 
     do {
-        if (ret != 0) XFree(ret);
-        XGetWindowProperty(disp, w, prop, 0, bytes_fetch, False, AnyPropertyType, &type, &fmt, &count, &bytes_left, &ret);
+        if (ret != 0) X11_XFree(ret);
+        X11_XGetWindowProperty(disp, w, prop, 0, bytes_fetch, False, AnyPropertyType, &type, &fmt, &count, &bytes_left, &ret);
         bytes_fetch += bytes_left;
     } while (bytes_left != 0);
 
@@ -79,9 +79,9 @@ static Atom X11_PickTarget(Display *disp, Atom list[], int list_count)
     char *name;
     int i;
     for (i=0; i < list_count && request == None; i++) {
-        name = XGetAtomName(disp, list[i]);
+        name = X11_XGetAtomName(disp, list[i]);
         if (strcmp("text/uri-list", name)==0) request = list[i];
-        XFree(name);
+        X11_XFree(name);
     }
     return request;
 }
@@ -125,8 +125,8 @@ static SDL_bool X11_KeyRepeat(Display *display, XEvent *event)
     struct KeyRepeatCheckData d;
     d.event = event;
     d.found = SDL_FALSE;
-    if (XPending(display))
-        XCheckIfEvent(display, &dummyev, X11_KeyRepeatCheckIfEvent,
+    if (X11_XPending(display))
+        X11_XCheckIfEvent(display, &dummyev, X11_KeyRepeatCheckIfEvent,
             (XPointer) &d);
     return d.found;
 }
@@ -147,7 +147,7 @@ static Bool X11_IsWheelCheckIfEvent(Display *display, XEvent *chkev,
 static SDL_bool X11_IsWheelEvent(Display * display,XEvent * event,int * ticks)
 {
     XEvent relevent;
-    if (XPending(display)) {
+    if (X11_XPending(display)) {
         /* according to the xlib docs, no specific mouse wheel events exist.
            however, mouse wheel events trigger a button press and a button release
            immediately. thus, checking if the same button was released at the same
@@ -158,7 +158,7 @@ static SDL_bool X11_IsWheelEvent(Display * display,XEvent * event,int * ticks)
              generated (or synthesised) immediately.
            - False negative: a wheel which, when rolled, doesn't have
              a release event generated immediately. */
-        if (XCheckIfEvent(display, &relevent, X11_IsWheelCheckIfEvent,
+        if (X11_XCheckIfEvent(display, &relevent, X11_IsWheelCheckIfEvent,
             (XPointer) event)) {
 
             /* by default, X11 only knows 5 buttons. on most 3 button + wheel mouse,
@@ -217,9 +217,9 @@ static void X11_HandleGenericEvent(SDL_VideoData *videodata,XEvent event)
 {
     /* event is a union, so cookie == &event, but this is type safe. */
     XGenericEventCookie *cookie = &event.xcookie;
-    if (XGetEventData(videodata->display, cookie)) {
+    if (X11_XGetEventData(videodata->display, cookie)) {
         X11_HandleXinput2Event(videodata, cookie);
-        XFreeEventData(videodata->display, cookie);
+        X11_XFreeEventData(videodata->display, cookie);
     }
 }
 #endif /* SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS */
@@ -234,7 +234,7 @@ X11_DispatchFocusIn(SDL_WindowData *data)
     SDL_SetKeyboardFocus(data->window);
 #ifdef X_HAVE_UTF8_STRING
     if (data->ic) {
-        XSetICFocus(data->ic);
+        X11_XSetICFocus(data->ic);
     }
 #endif
 }
@@ -248,7 +248,7 @@ X11_DispatchFocusOut(SDL_WindowData *data)
     SDL_SetKeyboardFocus(NULL);
 #ifdef X_HAVE_UTF8_STRING
     if (data->ic) {
-        XUnsetICFocus(data->ic);
+        X11_XUnsetICFocus(data->ic);
     }
 #endif
 }
@@ -278,11 +278,11 @@ X11_DispatchEvent(_THIS)
     XClientMessageEvent m;
 
     SDL_zero(xevent);           /* valgrind fix. --ryan. */
-    XNextEvent(display, &xevent);
+    X11_XNextEvent(display, &xevent);
 
     /* filter events catchs XIM events and sends them to the correct
        handler */
-    if (XFilterEvent(&xevent, None) == True) {
+    if (X11_XFilterEvent(&xevent, None) == True) {
 #if 0
         printf("Filtered event type = %d display = %d window = %d\n",
                xevent.type, xevent.xany.display, xevent.xany.window);
@@ -451,23 +451,23 @@ X11_DispatchEvent(_THIS)
 #if 1
             if (videodata->key_layout[keycode] == SDL_SCANCODE_UNKNOWN && keycode) {
                 int min_keycode, max_keycode;
-                XDisplayKeycodes(display, &min_keycode, &max_keycode);
+                X11_XDisplayKeycodes(display, &min_keycode, &max_keycode);
 #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
-                keysym = XkbKeycodeToKeysym(display, keycode, 0, 0);
+                keysym = X11_XkbKeycodeToKeysym(display, keycode, 0, 0);
 #else
                 keysym = XKeycodeToKeysym(display, keycode, 0);
 #endif
                 fprintf(stderr,
                         "The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode %d (%d), X11 KeySym 0x%lX (%s).\n",
                         keycode, keycode - min_keycode, keysym,
-                        XKeysymToString(keysym));
+                        X11_XKeysymToString(keysym));
             }
 #endif
             /* */
             SDL_zero(text);
 #ifdef X_HAVE_UTF8_STRING
             if (data->ic) {
-                Xutf8LookupString(data->ic, &xevent.xkey, text, sizeof(text),
+                X11_Xutf8LookupString(data->ic, &xevent.xkey, text, sizeof(text),
                                   &keysym, &status);
             }
 #else
@@ -549,7 +549,7 @@ X11_DispatchEvent(_THIS)
                     X11_ReadProperty(&p, display, data->xdnd_source, videodata->XdndTypeList);
                     /* pick one */
                     data->xdnd_req = X11_PickTarget(display, (Atom*)p.data, p.count);
-                    XFree(p.data);
+                    X11_XFree(p.data);
                 } else {
                     /* pick from list of three */
                     data->xdnd_req = X11_PickTargetFromAtoms(display, xevent.xclient.data.l[2], xevent.xclient.data.l[3], xevent.xclient.data.l[4]);
@@ -570,8 +570,8 @@ X11_DispatchEvent(_THIS)
                 m.data.l[3] = 0;
                 m.data.l[4] = videodata->XdndActionCopy; /* we only accept copying anyway */
 
-                XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&m);
-                XFlush(display);
+                X11_XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&m);
+                X11_XFlush(display);
             }
             else if(xevent.xclient.message_type == videodata->XdndDrop) {
                 if (data->xdnd_req == None) {
@@ -585,13 +585,13 @@ X11_DispatchEvent(_THIS)
                     m.data.l[0] = data->xwindow;
                     m.data.l[1] = 0;
                     m.data.l[2] = None; /* fail! */
-                    XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&m);
+                    X11_XSendEvent(display, xevent.xclient.data.l[0], False, NoEventMask, (XEvent*)&m);
                 } else {
                     /* convert */
                     if(xdnd_version >= 1) {
-                        XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, xevent.xclient.data.l[2]);
+                        X11_XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, xevent.xclient.data.l[2]);
                     } else {
-                        XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, CurrentTime);
+                        X11_XConvertSelection(display, videodata->XdndSelection, data->xdnd_req, videodata->PRIMARY, data->xwindow, CurrentTime);
                     }
                 }
             }
@@ -604,7 +604,7 @@ X11_DispatchEvent(_THIS)
                 printf("window %p: _NET_WM_PING\n", data);
 #endif
                 xevent.xclient.window = root;
-                XSendEvent(display, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &xevent);
+                X11_XSendEvent(display, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &xevent);
                 break;
             }
 
@@ -664,13 +664,13 @@ X11_DispatchEvent(_THIS)
             Atom real_type;
             unsigned long items_read, items_left, i;
 
-            char *name = XGetAtomName(display, xevent.xproperty.atom);
+            char *name = X11_XGetAtomName(display, xevent.xproperty.atom);
             if (name) {
                 printf("window %p: PropertyNotify: %s %s\n", data, name, (xevent.xproperty.state == PropertyDelete) ? "deleted" : "changed");
-                XFree(name);
+                X11_XFree(name);
             }
 
-            status = XGetWindowProperty(display, data->xwindow, xevent.xproperty.atom, 0L, 8192L, False, AnyPropertyType, &real_type, &real_format, &items_read, &items_left, &propdata);
+            status = X11_XGetWindowProperty(display, data->xwindow, xevent.xproperty.atom, 0L, 8192L, False, AnyPropertyType, &real_type, &real_format, &items_read, &items_left, &propdata);
             if (status == Success && items_read > 0) {
                 if (real_type == XA_INTEGER) {
                     int *values = (int *)propdata;
@@ -714,23 +714,23 @@ X11_DispatchEvent(_THIS)
 
                     printf("{");
                     for (i = 0; i < items_read; i++) {
-                        char *name = XGetAtomName(display, atoms[i]);
+                        char *name = X11_XGetAtomName(display, atoms[i]);
                         if (name) {
                             printf(" %s", name);
-                            XFree(name);
+                            X11_XFree(name);
                         }
                     }
                     printf(" }\n");
                 } else {
-                    char *name = XGetAtomName(display, real_type);
+                    char *name = X11_XGetAtomName(display, real_type);
                     printf("Unknown type: %ld (%s)\n", real_type, name ? name : "UNKNOWN");
                     if (name) {
-                        XFree(name);
+                        X11_XFree(name);
                     }
                 }
             }
             if (status == Success) {
-                XFree(propdata);
+                X11_XFree(propdata);
             }
 #endif /* DEBUG_XEVENTS */
 
@@ -774,28 +774,28 @@ X11_DispatchEvent(_THIS)
             sevent.xselection.property = None;
             sevent.xselection.requestor = req->requestor;
             sevent.xselection.time = req->time;
-            if (XGetWindowProperty(display, DefaultRootWindow(display),
+            if (X11_XGetWindowProperty(display, DefaultRootWindow(display),
                     XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target,
                     &sevent.xselection.target, &seln_format, &nbytes,
                     &overflow, &seln_data) == Success) {
-                Atom XA_TARGETS = XInternAtom(display, "TARGETS", 0);
+                Atom XA_TARGETS = X11_XInternAtom(display, "TARGETS", 0);
                 if (sevent.xselection.target == req->target) {
-                    XChangeProperty(display, req->requestor, req->property,
+                    X11_XChangeProperty(display, req->requestor, req->property,
                         sevent.xselection.target, seln_format, PropModeReplace,
                         seln_data, nbytes);
                     sevent.xselection.property = req->property;
                 } else if (XA_TARGETS == req->target) {
                     Atom SupportedFormats[] = { sevent.xselection.target, XA_TARGETS };
-                    XChangeProperty(display, req->requestor, req->property,
+                    X11_XChangeProperty(display, req->requestor, req->property,
                         XA_ATOM, 32, PropModeReplace,
                         (unsigned char*)SupportedFormats,
                         sizeof(SupportedFormats)/sizeof(*SupportedFormats));
                     sevent.xselection.property = req->property;
                 }
-                XFree(seln_data);
+                X11_XFree(seln_data);
             }
-            XSendEvent(display, req->requestor, False, 0, &sevent);
-            XSync(display, False);
+            X11_XSendEvent(display, req->requestor, False, 0, &sevent);
+            X11_XSync(display, False);
         }
         break;
 
@@ -845,7 +845,7 @@ X11_DispatchEvent(_THIS)
                     }
                 }
 
-                XFree(p.data);
+                X11_XFree(p.data);
 
                 /* send reply */
                 SDL_memset(&m, 0, sizeof(XClientMessageEvent));
@@ -857,9 +857,9 @@ X11_DispatchEvent(_THIS)
                 m.data.l[0] = data->xwindow;
                 m.data.l[1] = 1;
                 m.data.l[2] = videodata->XdndActionCopy;
-                XSendEvent(display, data->xdnd_source, False, NoEventMask, (XEvent*)&m);
+                X11_XSendEvent(display, data->xdnd_source, False, NoEventMask, (XEvent*)&m);
 
-                XSync(display, False);
+                X11_XSync(display, False);
 
             } else {
                 videodata->selection_waiting = SDL_FALSE;
@@ -899,13 +899,13 @@ X11_HandleFocusChanges(_THIS)
         }
     }
 }
-/* Ack!  XPending() actually performs a blocking read if no events available */
+/* Ack!  X11_XPending() actually performs a blocking read if no events available */
 static int
 X11_Pending(Display * display)
 {
     /* Flush the display connection and look to see if events are queued */
-    XFlush(display);
-    if (XEventsQueued(display, QueuedAlready)) {
+    X11_XFlush(display);
+    if (X11_XEventsQueued(display, QueuedAlready)) {
         return (1);
     }
 
@@ -919,7 +919,7 @@ X11_Pending(Display * display)
         FD_ZERO(&fdset);
         FD_SET(x11_fd, &fdset);
         if (select(x11_fd + 1, &fdset, NULL, NULL, &zero_time) == 1) {
-            return (XPending(display));
+            return (X11_XPending(display));
         }
     }
 
@@ -942,7 +942,7 @@ X11_PumpEvents(_THIS)
         Uint32 now = SDL_GetTicks();
         if (!data->screensaver_activity ||
             (int) (now - data->screensaver_activity) >= 30000) {
-            XResetScreenSaver(data->display);
+            X11_XResetScreenSaver(data->display);
 
             #if SDL_USE_LIBDBUS
             SDL_dbus_screensaver_tickle(_this);
@@ -971,16 +971,16 @@ X11_SuspendScreenSaver(_THIS)
     int major_version, minor_version;
 
     if (SDL_X11_HAVE_XSS) {
-        /* XScreenSaverSuspend was introduced in MIT-SCREEN-SAVER 1.1 */
-        if (!XScreenSaverQueryExtension(data->display, &dummy, &dummy) ||
-            !XScreenSaverQueryVersion(data->display,
+        /* X11_XScreenSaverSuspend was introduced in MIT-SCREEN-SAVER 1.1 */
+        if (!X11_XScreenSaverQueryExtension(data->display, &dummy, &dummy) ||
+            !X11_XScreenSaverQueryVersion(data->display,
                                       &major_version, &minor_version) ||
             major_version < 1 || (major_version == 1 && minor_version < 1)) {
             return;
         }
 
-        XScreenSaverSuspend(data->display, _this->suspend_screensaver);
-        XResetScreenSaver(data->display);
+        X11_XScreenSaverSuspend(data->display, _this->suspend_screensaver);
+        X11_XResetScreenSaver(data->display);
     }
 #endif
 
diff --git a/src/video/x11/SDL_x11framebuffer.c b/src/video/x11/SDL_x11framebuffer.c
index 4dfe0d1..af39147 100644
--- a/src/video/x11/SDL_x11framebuffer.c
+++ b/src/video/x11/SDL_x11framebuffer.c
@@ -43,8 +43,8 @@ static int shm_errhandler(Display *d, XErrorEvent *e)
 static SDL_bool have_mitshm(void)
 {
     /* Only use shared memory on local X servers */
-    if ( (SDL_strncmp(XDisplayName(NULL), ":", 1) == 0) ||
-         (SDL_strncmp(XDisplayName(NULL), "unix:", 5) == 0) ) {
+    if ( (SDL_strncmp(X11_XDisplayName(NULL), ":", 1) == 0) ||
+         (SDL_strncmp(X11_XDisplayName(NULL), "unix:", 5) == 0) ) {
         return SDL_X11_HAVE_SHM;
     }
     return SDL_FALSE;
@@ -66,7 +66,7 @@ X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format,
 
     /* Create the graphics context for drawing */
     gcv.graphics_exposures = False;
-    data->gc = XCreateGC(display, data->xwindow, GCGraphicsExposures, &gcv);
+    data->gc = X11_XCreateGC(display, data->xwindow, GCGraphicsExposures, &gcv);
     if (!data->gc) {
         return SDL_SetError("Couldn't create graphics context");
     }
@@ -95,10 +95,10 @@ X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format,
             shminfo->readOnly = False;
             if ( shminfo->shmaddr != (char *)-1 ) {
                 shm_error = False;
-                X_handler = XSetErrorHandler(shm_errhandler);
-                XShmAttach(display, shminfo);
-                XSync(display, True);
-                XSetErrorHandler(X_handler);
+                X_handler = X11_XSetErrorHandler(shm_errhandler);
+                X11_XShmAttach(display, shminfo);
+                X11_XSync(display, True);
+                X11_XSetErrorHandler(X_handler);
                 if ( shm_error )
                     shmdt(shminfo->shmaddr);
             } else {
@@ -109,13 +109,13 @@ X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format,
             shm_error = True;
         }
         if (!shm_error) {
-            data->ximage = XShmCreateImage(display, data->visual,
+            data->ximage = X11_XShmCreateImage(display, data->visual,
                              vinfo.depth, ZPixmap,
                              shminfo->shmaddr, shminfo,
                              window->w, window->h);
             if (!data->ximage) {
-                XShmDetach(display, shminfo);
-                XSync(display, False);
+                X11_XShmDetach(display, shminfo);
+                X11_XSync(display, False);
                 shmdt(shminfo->shmaddr);
             } else {
                 /* Done! */
@@ -132,7 +132,7 @@ X11_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format,
         return SDL_OutOfMemory();
     }
 
-    data->ximage = XCreateImage(display, data->visual,
+    data->ximage = X11_XCreateImage(display, data->visual,
                       vinfo.depth, ZPixmap, 0, (char *)(*pixels),
                       window->w, window->h, 32, 0);
     if (!data->ximage) {
@@ -177,7 +177,7 @@ X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects,
             if (y + h > window->h)
                 h = window->h - y;
 
-            XShmPutImage(display, data->xwindow, data->gc, data->ximage,
+            X11_XShmPutImage(display, data->xwindow, data->gc, data->ximage,
                 x, y, x, y, w, h, False);
         }
     }
@@ -209,12 +209,12 @@ X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects,
             if (y + h > window->h)
                 h = window->h - y;
 
-            XPutImage(display, data->xwindow, data->gc, data->ximage,
+            X11_XPutImage(display, data->xwindow, data->gc, data->ximage,
                 x, y, x, y, w, h);
         }
     }
 
-    XSync(display, False);
+    X11_XSync(display, False);
 
     return 0;
 }
@@ -237,8 +237,8 @@ X11_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
 
 #ifndef NO_SHARED_MEMORY
         if (data->use_mitshm) {
-            XShmDetach(display, &data->shminfo);
-            XSync(display, False);
+            X11_XShmDetach(display, &data->shminfo);
+            X11_XSync(display, False);
             shmdt(data->shminfo.shmaddr);
             data->use_mitshm = SDL_FALSE;
         }
@@ -247,7 +247,7 @@ X11_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
         data->ximage = NULL;
     }
     if (data->gc) {
-        XFreeGC(display, data->gc);
+        X11_XFreeGC(display, data->gc);
         data->gc = NULL;
     }
 }
diff --git a/src/video/x11/SDL_x11keyboard.c b/src/video/x11/SDL_x11keyboard.c
index 6bc7ebb..9a2de45 100644
--- a/src/video/x11/SDL_x11keyboard.c
+++ b/src/video/x11/SDL_x11keyboard.c
@@ -152,7 +152,7 @@ X11_KeyCodeToSDLScancode(Display *display, KeyCode keycode)
     int i;
 
 #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
-    keysym = XkbKeycodeToKeysym(display, keycode, 0, 0);
+    keysym = X11_XkbKeycodeToKeysym(display, keycode, 0, 0);
 #else
     keysym = XKeycodeToKeysym(display, keycode, 0);
 #endif
@@ -182,7 +182,7 @@ X11_KeyCodeToUcs4(Display *display, KeyCode keycode)
     KeySym keysym;
 
 #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
-    keysym = XkbKeycodeToKeysym(display, keycode, 0, 0);
+    keysym = X11_XkbKeycodeToKeysym(display, keycode, 0, 0);
 #else
     keysym = XKeycodeToKeysym(display, keycode, 0);
 #endif
@@ -211,14 +211,14 @@ X11_InitKeyboard(_THIS)
     };
     SDL_bool fingerprint_detected;
 
-    XAutoRepeatOn(data->display);
+    X11_XAutoRepeatOn(data->display);
 
     /* Try to determine which scancodes are being used based on fingerprint */
     fingerprint_detected = SDL_FALSE;
-    XDisplayKeycodes(data->display, &min_keycode, &max_keycode);
+    X11_XDisplayKeycodes(data->display, &min_keycode, &max_keycode);
     for (i = 0; i < SDL_arraysize(fingerprint); ++i) {
         fingerprint[i].value =
-            XKeysymToKeycode(data->display, fingerprint[i].keysym) -
+            X11_XKeysymToKeycode(data->display, fingerprint[i].keysym) -
             min_keycode;
     }
     for (i = 0; i < SDL_arraysize(scancode_set); ++i) {
@@ -258,14 +258,14 @@ X11_InitKeyboard(_THIS)
         for (i = min_keycode; i <= max_keycode; ++i) {
             KeySym sym;
 #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
-            sym = XkbKeycodeToKeysym(data->display, i, 0, 0);
+            sym = X11_XkbKeycodeToKeysym(data->display, i, 0, 0);
 #else
             sym = XKeycodeToKeysym(data->display, i, 0);
 #endif
             if (sym != NoSymbol) {
                 SDL_Scancode scancode;
                 printf("code = %d, sym = 0x%X (%s) ", i - min_keycode,
-                       (unsigned int) sym, XKeysymToString(sym));
+                       (unsigned int) sym, X11_XKeysymToString(sym));
                 scancode = X11_KeyCodeToSDLScancode(data->display, i);
                 data->key_layout[i] = scancode;
                 if (scancode == SDL_SCANCODE_UNKNOWN) {
diff --git a/src/video/x11/SDL_x11messagebox.c b/src/video/x11/SDL_x11messagebox.c
index f938ded..0d0ffb7 100644
--- a/src/video/x11/SDL_x11messagebox.c
+++ b/src/video/x11/SDL_x11messagebox.c
@@ -124,13 +124,13 @@ GetTextWidthHeight( SDL_MessageBoxDataX11 *data, const char *str, int nbytes, in
 {
     if (SDL_X11_HAVE_UTF8) {
         XRectangle overall_ink, overall_logical;
-        Xutf8TextExtents(data->font_set, str, nbytes, &overall_ink, &overall_logical);
+        X11_Xutf8TextExtents(data->font_set, str, nbytes, &overall_ink, &overall_logical);
         *pwidth = overall_logical.width;
         *pheight = overall_logical.height;
     } else {
         XCharStruct text_structure;
         int font_direction, font_ascent, font_descent;
-        XTextExtents( data->font_struct, str, nbytes,
+        X11_XTextExtents( data->font_struct, str, nbytes,
                       &font_direction, &font_ascent, &font_descent,
                       &text_structure );
         *pwidth = text_structure.width;
@@ -180,7 +180,7 @@ X11_MessageBoxInit( SDL_MessageBoxDataX11 *data, const SDL_MessageBoxData * mess
     data->numbuttons = numbuttons;
     data->pbuttonid = pbuttonid;
 
-    data->display = XOpenDisplay( NULL );
+    data->display = X11_XOpenDisplay( NULL );
     if ( !data->display ) {
         return SDL_SetError("Couldn't open X11 display");
     }
@@ -188,16 +188,16 @@ X11_MessageBoxInit( SDL_MessageBoxDataX11 *data, const SDL_MessageBoxData * mess
     if (SDL_X11_HAVE_UTF8) {
         char **missing = NULL;
         int num_missing = 0;
-        data->font_set = XCreateFontSet(data->display, g_MessageBoxFont,
+        data->font_set = X11_XCreateFontSet(data->display, g_MessageBoxFont,
                                         &missing, &num_missing, NULL);
         if ( missing != NULL ) {
-            XFreeStringList(missing);
+            X11_XFreeStringList(missing);
         }
         if ( data->font_set == NULL ) {
             return SDL_SetError("Couldn't load font %s", g_MessageBoxFont);
         }
     } else {
-        data->font_struct = XLoadQueryFont( data->display, g_MessageBoxFontLatin1 );
+        data->font_struct = X11_XLoadQueryFont( data->display, g_MessageBoxFontLatin1 );
         if ( data->font_struct == NULL ) {
             return SDL_SetError("Couldn't load font %s", g_MessageBoxFontLatin1);
         }
@@ -338,23 +338,23 @@ static void
 X11_MessageBoxShutdown( SDL_MessageBoxDataX11 *data )
 {
     if ( data->font_set != NULL ) {
-        XFreeFontSet( data->display, data->font_set );
+        X11_XFreeFontSet( data->display, data->font_set );
         data->font_set = NULL;
     }
 
     if ( data->font_struct != NULL ) {
-        XFreeFont( data->display, data->font_struct );
+        X11_XFreeFont( data->display, data->font_struct );
         data->font_struct = NULL;
     }
 
     if ( data->display ) {
         if ( data->window != None ) {
-            XWithdrawWindow( data->display, data->window, data->screen );
-            XDestroyWindow( data->display, data->window );
+            X11_XWithdrawWindow( data->display, data->window, data->screen );
+            X11_XDestroyWindow( data->display, data->window );
             data->window = None;
         }
 
-        XCloseDisplay( data->display );
+        X11_XCloseDisplay( data->display );
         data->display = NULL;
     }
 }
@@ -384,7 +384,7 @@ X11_MessageBoxCreateWindow( SDL_MessageBoxDataX11 *data )
                        StructureNotifyMask | FocusChangeMask | PointerMotionMask;
     wnd_attr.event_mask = data->event_mask;
 
-    data->window = XCreateWindow(
+    data->window = X11_XCreateWindow(
                        display, RootWindow(display, data->screen),
                        0, 0,
                        data->dialog_width, data->dialog_height,
@@ -396,31 +396,31 @@ X11_MessageBoxCreateWindow( SDL_MessageBoxDataX11 *data )
 
     if ( windowdata ) {
         /* http://tronche.com/gui/x/icccm/sec-4.html#WM_TRANSIENT_FOR */
-        XSetTransientForHint( display, data->window, windowdata->xwindow );
+        X11_XSetTransientForHint( display, data->window, windowdata->xwindow );
     }
 
-    XStoreName( display, data->window, messageboxdata->title );
+    X11_XStoreName( display, data->window, messageboxdata->title );
 
     /* Allow the window to be deleted by the window manager */
-    data->wm_protocols = XInternAtom( display, "WM_PROTOCOLS", False );
-    data->wm_delete_message = XInternAtom( display, "WM_DELETE_WINDOW", False );
-    XSetWMProtocols( display, data->window, &data->wm_delete_message, 1 );
+    data->wm_protocols = X11_XInternAtom( display, "WM_PROTOCOLS", False );
+    data->wm_delete_message = X11_XInternAtom( display, "WM_DELETE_WINDOW", False );
+    X11_XSetWMProtocols( display, data->window, &data->wm_delete_message, 1 );
 
     if ( windowdata ) {
         XWindowAttributes attrib;
         Window dummy;
 
-        XGetWindowAttributes(display, windowdata->xwindow, &attrib);
+        X11_XGetWindowAttributes(display, windowdata->xwindow, &attrib);
         x = attrib.x + ( attrib.width - data->dialog_width ) / 2;
         y = attrib.y + ( attrib.height - data->dialog_height ) / 3 ;
-        XTranslateCoordinates(display, windowdata->xwindow, RootWindow(display, data->screen), x, y, &x, &y, &dummy);
+        X11_XTranslateCoordinates(display, windowdata->xwindow, RootWindow(display, data->screen), x, y, &x, &y, &dummy);
     } else {
         x = ( DisplayWidth( display, data->screen ) - data->dialog_width ) / 2;
         y = ( DisplayHeight( display, data->screen ) - data->dialog_height ) / 3 ;
     }
-    XMoveWindow( display, data->window, x, y );
+    X11_XMoveWindow( display, data->window, x, y );
 
-    sizehints = XAllocSizeHints();
+    sizehints = X11_XAllocSizeHints();
     if ( sizehints ) {
         sizehints->flags = USPosition | USSize | PMaxSize | PMinSize;
         sizehints->x = x;
@@ -431,12 +431,12 @@ X11_MessageBoxCreateWindow( SDL_MessageBoxDataX11 *data )
         sizehints->min_width = sizehints->max_width = data->dialog_width;
         sizehints->min_height = sizehints->max_height = data->dialog_height;
 
-        XSetWMNormalHints( display, data->window, sizehints );
+        X11_XSetWMNormalHints( display, data->window, sizehints );
 
-        XFree( sizehints );
+        X11_XFree( sizehints );
     }
 
-    XMapRaised( display, data->window );
+    X11_XMapRaised( display, data->window );
     return 0;
 }
 
@@ -448,19 +448,19 @@ X11_MessageBoxDraw( SDL_MessageBoxDataX11 *data, GC ctx )
     Window window = data->window;
     Display *display = data->display;
 
-    XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BACKGROUND ] );
-    XFillRectangle( display, window, ctx, 0, 0, data->dialog_width, data->dialog_height );
+    X11_XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BACKGROUND ] );
+    X11_XFillRectangle( display, window, ctx, 0, 0, data->dialog_width, data->dialog_height );
 
-    XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_TEXT ] );
+    X11_XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_TEXT ] );
     for ( i = 0; i < data->numlines; i++ ) {
         TextLineData *plinedata = &data->linedata[ i ];
 
         if (SDL_X11_HAVE_UTF8) {
-            Xutf8DrawString( display, window, data->font_set, ctx,
+            X11_Xutf8DrawString( display, window, data->font_set, ctx,
                              data->xtext, data->ytext + i * data->text_height,
                              plinedata->text, plinedata->length );
         } else {
-            XDrawString( display, window, ctx,
+            X11_XDrawString( display, window, ctx,
                          data->xtext, data->ytext + i * data->text_height,
                          plinedata->text, plinedata->length );
         }
@@ -472,27 +472,27 @@ X11_MessageBoxDraw( SDL_MessageBoxDataX11 *data, GC ctx )
         int border = ( buttondata->flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT ) ? 2 : 0;
         int offset = ( ( data->mouse_over_index == i ) && ( data->button_press_index == data->mouse_over_index ) ) ? 1 : 0;
 
-        XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND ] );
-        XFillRectangle( display, window, ctx,
+        X11_XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND ] );
+        X11_XFillRectangle( display, window, ctx,
                         buttondatax11->rect.x - border, buttondatax11->rect.y - border,
                         buttondatax11->rect.w + 2 * border, buttondatax11->rect.h + 2 * border );
 
-        XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_BORDER ] );
-        XDrawRectangle( display, window, ctx,
+        X11_XSetForeground( display, ctx, data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_BORDER ] );
+        X11_XDrawRectangle( display, window, ctx,
                         buttondatax11->rect.x, buttondatax11->rect.y,
                         buttondatax11->rect.w, buttondatax11->rect.h );
 
-        XSetForeground( display, ctx, ( data->mouse_over_index == i ) ?
+        X11_XSetForeground( display, ctx, ( data->mouse_over_index == i ) ?
                         data->color[ SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED ] :
                         data->color[ SDL_MESSAGEBOX_COLOR_TEXT ] );
 
         if (SDL_X11_HAVE_UTF8) {
-            Xutf8DrawString( display, window, data->font_set, ctx,
+            X11_Xutf8DrawString( display, window, data->font_set, ctx,
                              buttondatax11->x + offset,
                              buttondatax11->y + offset,
                              buttondata->text, buttondatax11->length );
         } else {
-            XDrawString( display, window, ctx,
+            X11_XDrawString( display, window, ctx,
                          buttondatax11->x + offset, buttondatax11->y + offset,
                          buttondata->text, buttondatax11->length );
         }
@@ -519,7 +519,7 @@ X11_MessageBoxLoop( SDL_MessageBoxDataX11 *data )
         ctx_vals.font = data->font_struct->fid;
     }
 
-    ctx = XCreateGC( data->display, data->window, gcflags, &ctx_vals );
+    ctx = X11_XCreateGC( data->display, data->window, gcflags, &ctx_vals );
     if ( ctx == None ) {
         return SDL_SetError("Couldn't create graphics context");
     }
@@ -531,11 +531,11 @@ X11_MessageBoxLoop( SDL_MessageBoxDataX11 *data )
         XEvent e;
         SDL_bool draw = SDL_TRUE;
 
-        XWindowEvent( data->display, data->window, data->event_mask, &e );
+        X11_XWindowEvent( data->display, data->window, data->event_mask, &e );
 
-        /* If XFilterEvent returns True, then some input method has filtered the
+        /* If X11_XFilterEvent returns True, then some input method has filtered the
            event, and the client should discard the event. */
-        if ( ( e.type != Expose ) && XFilterEvent( &e, None ) )
+        if ( ( e.type != Expose ) && X11_XFilterEvent( &e, None ) )
             continue;
 
         switch( e.type ) {
@@ -574,12 +574,12 @@ X11_MessageBoxLoop( SDL_MessageBoxDataX11 *data )
 
         case KeyPress:
             /* Store key press - we make sure in key release that we got both. */
-            last_key_pressed = XLookupKeysym( &e.xkey, 0 );
+            last_key_pressed = X11_XLookupKeysym( &e.xkey, 0 );
             break;
 
         case KeyRelease: {
             Uint32 mask = 0;
-            KeySym key = XLookupKeysym( &e.xkey, 0 );
+            KeySym key = X11_XLookupKeysym( &e.xkey, 0 );
 
             /* If this is a key release for something we didn't get the key down for, then bail. */
             if ( key != last_key_pressed )
@@ -637,7 +637,7 @@ X11_MessageBoxLoop( SDL_MessageBoxDataX11 *data )
         }
     }
 
-    XFreeGC( data->display, ctx );
+    X11_XFreeGC( data->display, ctx );
     return 0;
 }
 
@@ -667,7 +667,7 @@ X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonid)
 #endif
 
     /* This code could get called from multiple threads maybe? */
-    XInitThreads();
+    X11_XInitThreads();
 
     /* Initialize the return buttonid value to -1 (for error or dialogbox closed). */
     *buttonid = -1;
@@ -707,7 +707,7 @@ X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
     int status = 0;
 
     /* Need to flush here in case someone has turned grab off and it hasn't gone through yet, etc. */
-    XFlush(data->display);
+    X11_XFlush(data->display);
 
     if (pipe(fds) == -1) {
         return X11_ShowMessageBoxImpl(messageboxdata, buttonid); /* oh well. */
diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c
index 472416c..a4c242c 100644
--- a/src/video/x11/SDL_x11modes.c
+++ b/src/video/x11/SDL_x11modes.c
@@ -54,20 +54,20 @@ get_visualinfo(Display * display, int screen, XVisualInfo * vinfo)
 
         SDL_zero(template);
         template.visualid = SDL_strtol(visual_id, NULL, 0);
-        vi = XGetVisualInfo(display, VisualIDMask, &template, &nvis);
+        vi = X11_XGetVisualInfo(display, VisualIDMask, &template, &nvis);
         if (vi) {
             *vinfo = *vi;
-            XFree(vi);
+            X11_XFree(vi);
             return 0;
         }
     }
 
     depth = DefaultDepth(display, screen);
     if ((X11_UseDirectColorVisuals() &&
-         XMatchVisualInfo(display, screen, depth, DirectColor, vinfo)) ||
-        XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) ||
-        XMatchVisualInfo(display, screen, depth, PseudoColor, vinfo) ||
-        XMatchVisualInfo(display, screen, depth, StaticColor, vinfo)) {
+         X11_XMatchVisualInfo(display, screen, depth, DirectColor, vinfo)) ||
+        X11_XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) ||
+        X11_XMatchVisualInfo(display, screen, depth, PseudoColor, vinfo) ||
+        X11_XMatchVisualInfo(display, screen, depth, StaticColor, vinfo)) {
         return 0;
     }
     return -1;
@@ -79,11 +79,11 @@ X11_GetVisualInfoFromVisual(Display * display, Visual * visual, XVisualInfo * vi
     XVisualInfo *vi;
     int nvis;
 
-    vinfo->visualid = XVisualIDFromVisual(visual);
-    vi = XGetVisualInfo(display, VisualIDMask, vinfo, &nvis);
+    vinfo->visualid = X11_XVisualIDFromVisual(visual);
+    vi = X11_XGetVisualInfo(display, VisualIDMask, vinfo, &nvis);
     if (vi) {
         *vinfo = *vi;
-        XFree(vi);
+        X11_XFree(vi);
         return 0;
     }
     return -1;
@@ -108,7 +108,7 @@ X11_GetPixelFormatFromVisualInfo(Display * display, XVisualInfo * vinfo)
         bpp = vinfo->depth;
         if (bpp == 24) {
             int i, n;
-            XPixmapFormatValues *p = XListPixmapFormats(display, &n);
+            XPixmapFormatValues *p = X11_XListPixmapFormats(display, &n);
             if (p) {
                 for (i = 0; i < n; ++i) {
                     if (p[i].depth == 24) {
@@ -116,7 +116,7 @@ X11_GetPixelFormatFromVisualInfo(Display * display, XVisualInfo * vinfo)
                         break;
                     }
                 }
-                XFree(p);
+                X11_XFree(p);
             }
         }
 
@@ -178,9 +178,9 @@ CheckXinerama(Display * display, int *major, int *minor)
     }
 
     /* Query the extension version */
-    if (!XineramaQueryExtension(display, &event_base, &error_base) ||
-        !XineramaQueryVersion(display, major, minor) ||
-        !XineramaIsActive(display)) {
+    if (!X11_XineramaQueryExtension(display, &event_base, &error_base) ||
+        !X11_XineramaQueryVersion(display, major, minor) ||
+        !X11_XineramaIsActive(display)) {
 #ifdef X11MODES_DEBUG
         printf("Xinerama not active on the display\n");
 #endif
@@ -228,7 +228,7 @@ CheckXRandR(Display * display, int *major, int *minor)
     }
 
     /* Query the extension version */
-    if (!XRRQueryVersion(display, major, minor)) {
+    if (!X11_XRRQueryVersion(display, major, minor)) {
 #ifdef X11MODES_DEBUG
         printf("XRandR not active on the display\n");
 #endif
@@ -261,10 +261,10 @@ SetXRandRModeInfo(Display *display, XRRScreenResources *res, XRROutputInfo *outp
             Rotation rotation = 0;
             const XRRModeInfo *info = &res->modes[i];
 
-            crtc = XRRGetCrtcInfo(display, res, output_info->crtc);
+            crtc = X11_XRRGetCrtcInfo(display, res, output_info->crtc);
             if (crtc) {
                 rotation = crtc->rotation;
-                XRRFreeCrtcInfo(crtc);
+                X11_XRRFreeCrtcInfo(crtc);
             }
 
             if (rotation & (XRANDR_ROTATION_LEFT|XRANDR_ROTATION_RIGHT)) {
@@ -313,8 +313,8 @@ CheckVidMode(Display * display, int *major, int *minor)
 
     /* Query the extension version */
     vm_error = -1;
-    if (!XF86VidModeQueryExtension(display, &vm_event, &vm_error)
-        || !XF86VidModeQueryVersion(display, major, minor)) {
+    if (!X11_XF86VidModeQueryExtension(display, &vm_event, &vm_error)
+        || !X11_XF86VidModeQueryVersion(display, major, minor)) {
 #ifdef X11MODES_DEBUG
         printf("XVidMode not active on the display\n");
 #endif
@@ -335,7 +335,7 @@ Bool XF86VidModeGetModeInfo(Display * dpy, int scr,
     XF86VidModeModeLine l;
     SDL_zerop(info);
     SDL_zero(l);
-    retval = XF86VidModeGetModeLine(dpy, scr, &dotclock, &l);
+    retval = X11_XF86VidModeGetModeLine(dpy, scr, &dotclock, &l);
     info->dotclock = dotclock;
     info->hdisplay = l.hdisplay;
     info->hsyncstart = l.hsyncstart;
@@ -397,7 +397,7 @@ X11_InitModes(_THIS)
      *       or newer of the Nvidia binary drivers
      */
     if (CheckXinerama(data->display, &xinerama_major, &xinerama_minor)) {
-        xinerama = XineramaQueryScreens(data->display, &screencount);
+        xinerama = X11_XineramaQueryScreens(data->display, &screencount);
         if (xinerama) {
             use_xinerama = xinerama_major * 100 + xinerama_minor;
         }
@@ -501,7 +501,7 @@ X11_InitModes(_THIS)
         displaydata->depth = vinfo.depth;
 
         displaydata->scanline_pad = SDL_BYTESPERPIXEL(mode.format) * 8;
-        pixmapFormats = XListPixmapFormats(data->display, &n);
+        pixmapFormats = X11_XListPixmapFormats(data->display, &n);
         if (pixmapFormats) {
             for (i = 0; i < n; ++i) {
                 if (pixmapFormats[i].depth == displaydata->depth) {
@@ -509,7 +509,7 @@ X11_InitModes(_THIS)
                     break;
                 }
             }
-            XFree(pixmapFormats);
+            X11_XFree(pixmapFormats);
         }
 
 #if SDL_VIDEO_DRIVER_X11_XINERAMA
@@ -526,13 +526,13 @@ X11_InitModes(_THIS)
 
 #if SDL_VIDEO_DRIVER_X11_XRANDR
         if (use_xrandr) {
-            res = XRRGetScreenResources(data->display, RootWindow(data->display, displaydata->screen));
+            res = X11_XRRGetScreenResources(data->display, RootWindow(data->display, displaydata->screen));
         }
         if (res) {
             XRROutputInfo *output_info;
             XRRCrtcInfo *crtc;
             int output;
-            Atom EDID = XInternAtom(data->display, "EDID", False);
+            Atom EDID = X11_XInternAtom(data->display, "EDID", False);
             Atom *props;
             int nprop;
             unsigned long width_mm;
@@ -540,10 +540,10 @@ X11_InitModes(_THIS)
             int inches = 0;
 
             for (output = 0; output < res->noutput; output++) {
-                output_info = XRRGetOutputInfo(data->display, res, res->outputs[output]);
+                output_info = X11_XRRGetOutputInfo(data->display, res, res->outputs[output]);
                 if (!output_info || !output_info->crtc ||
                     output_info->connection == RR_Disconnected) {
-                    XRRFreeOutputInfo(output_info);
+                    X11_XRRFreeOutputInfo(output_info);
                     continue;
                 }
 
@@ -551,10 +551,10 @@ X11_InitModes(_THIS)
                    We're checking the crtc position, but that may not be a valid test
                    in all cases.  Anybody want to give this some love?
                  */
-                crtc = XRRGetCrtcInfo(data->display, res, output_info->crtc);
+                crtc = X11_XRRGetCrtcInfo(data->display, res, output_info->crtc);
                 if (!crtc || crtc->x != displaydata->x || crtc->y != displaydata->y) {
-                    XRRFreeOutputInfo(output_info);
-                    XRRFreeCrtcInfo(crtc);
+                    X11_XRRFreeOutputInfo(output_info);
+                    X11_XRRFreeCrtcInfo(crtc);
                     continue;
                 }
 
@@ -570,7 +570,7 @@ X11_InitModes(_THIS)
                 SDL_strlcpy(display_name, output_info->name, sizeof(display_name));
 
                 /* See if we can get the EDID data for the real monitor name */
-                props = XRRListOutputProperties(data->display, res->outputs[output], &nprop);
+                props = X11_XRRListOutputProperties(data->display, res->outputs[output], &nprop);
                 for (i = 0; i < nprop; ++i) {
                     unsigned char *prop;
                     int actual_format;
@@ -578,7 +578,7 @@ X11_InitModes(_THIS)
                     Atom actual_type;
 
                     if (props[i] == EDID) {
-                        if (XRRGetOutputProperty(data->display,
+                        if (X11_XRRGetOutputProperty(data->display,
                                                  res->outputs[output], props[i],
                                                  0, 100, False, False,
                                                  AnyPropertyType,
@@ -593,13 +593,13 @@ X11_InitModes(_THIS)
                                 SDL_strlcpy(display_name, info->dsc_product_name, sizeof(display_name));
                                 free(info);
                             }
-                            XFree(prop);
+                            X11_XFree(prop);
                         }
                         break;
                     }
                 }
                 if (props) {
-                    XFree(props);
+                    X11_XFree(props);
                 }
 
                 if (*display_name && inches) {
@@ -610,8 +610,8 @@ X11_InitModes(_THIS)
                 printf("Display name: %s\n", display_name);
 #endif
 
-                XRRFreeOutputInfo(output_info);
-                XRRFreeCrtcInfo(crtc);
+                X11_XRRFreeOutputInfo(output_info);
+                X11_XRRFreeCrtcInfo(crtc);
                 break;
             }
 #ifdef X11MODES_DEBUG
@@ -619,7 +619,7 @@ X11_InitModes(_THIS)
                 printf("Couldn't find XRandR CRTC at %d,%d\n", displaydata->x, displaydata->y);
             }
 #endif
-            XRRFreeScreenResources(res);
+            X11_XRRFreeScreenResources(res);
         }
 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
 
@@ -652,7 +652,7 @@ X11_InitModes(_THIS)
     }
 
 #if SDL_VIDEO_DRIVER_X11_XINERAMA
-    if (xinerama) XFree(xinerama);
+    if (xinerama) X11_XFree(xinerama);
 #endif
 
     if (_this->num_displays == 0) {
@@ -725,13 +725,13 @@ X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
     if (data->use_xrandr) {
         XRRScreenResources *res;
 
-        res = XRRGetScreenResources (display, RootWindow(display, data->screen));
+        res = X11_XRRGetScreenResources (display, RootWindow(display, data->screen));
         if (res) {
             SDL_DisplayModeData *modedata;
             XRROutputInfo *output_info;
             int i;
 
-            output_info = XRRGetOutputInfo(display, res, data->xrandr_output);
+            output_info = X11_XRRGetOutputInfo(display, res, data->xrandr_output);
             if (output_info && output_info->connection != RR_Disconnected) {
                 for (i = 0; i < output_info->nmode; ++i) {
                     modedata = (SDL_DisplayModeData *) SDL_calloc(1, sizeof(SDL_DisplayModeData));
@@ -747,8 +747,8 @@ X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
                     }
                 }
             }
-            XRRFreeOutputInfo(output_info);
-            XRRFreeScreenResources(res);
+            X11_XRRFreeOutputInfo(output_info);
+            X11_XRRFreeScreenResources(res);
         }
         return;
     }
@@ -756,7 +756,7 @@ X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
 
 #if SDL_VIDEO_DRIVER_X11_XVIDMODE
     if (data->use_vidmode &&
-        XF86VidModeGetAllModeLines(display, data->vidmode_screen, &nmodes, &modes)) {
+        X11_XF86VidModeGetAllModeLines(display, data->vidmode_screen, &nmodes, &modes)) {
         int i;
 
 #ifdef X11MODES_DEBUG
@@ -780,7 +780,7 @@ X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
                 SDL_free(modedata);
             }
         }
-        XFree(modes);
+        X11_XFree(modes);
         return;
     }
 #endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
@@ -811,41 +811,41 @@ X11_SetDisplayMode(_THIS, SDL_VideoDisplay * sdl_display, SDL_DisplayMode * mode
         XRRCrtcInfo *crtc;
         Status status;
 
-        res = XRRGetScreenResources (display, RootWindow(display, data->screen));
+        res = X11_XRRGetScreenResources (display, RootWindow(display, data->screen));
         if (!res) {
             return SDL_SetError("Couldn't get XRandR screen resources");
         }
 
-        output_info = XRRGetOutputInfo(display, res, data->xrandr_output);
+        output_info = X11_XRRGetOutputInfo(display, res, data->xrandr_output);
         if (!output_info || output_info->connection == RR_Disconnected) {
-            XRRFreeScreenResources(res);
+            X11_XRRFreeScreenResources(res);
             return SDL_SetError("Couldn't get XRandR output info");
         }
 
-        crtc = XRRGetCrtcInfo(display, res, output_info->crtc);
+        crtc = X11_XRRGetCrtcInfo(display, res, output_info->crtc);
         if (!crtc) {
-            XRRFreeOutputInfo(output_info);
-            XRRFreeScreenResources(res);
+            X11_XRRFreeOutputInfo(output_info);
+            X11_XRRFreeScreenResources(res);
             return SDL_SetError("Couldn't get XRandR crtc info");
         }
 
-        status = XRRSetCrtcConfig (display, res, output_info->crtc, CurrentTime,
+        status = X11_XRRSetCrtcConfig (display, res, output_info->crtc, CurrentTime,
           crtc->x, crtc->y, modedata->xrandr_mode, crtc->rotation,
           &data->xrandr_output, 1);
 
-        XRRFreeCrtcInfo(crtc);
-        XRRFreeOutputInfo(output_info);
-        XRRFreeScreenResources(res);
+        X11_XRRFreeCrtcInfo(crtc);
+        X11_XRRFreeOutputInfo(output_info);
+        X11_XRRFreeScreenResources(res);
 
         if (status != Success) {
-            return SDL_SetError("XRRSetCrtcConfig failed");
+            return SDL_SetError("X11_XRRSetCrtcConfig failed");
         }
     }
 #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
 
 #if SDL_VIDEO_DRIVER_X11_XVIDMODE
     if (data->use_vidmode) {
-        XF86VidModeSwitchToMode(display, data->vidmode_screen, &modedata->vm_mode);
+        X11_XF86VidModeSwitchToMode(display, data->vidmode_screen, &modedata->vm_mode);
     }
 #endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
 
@@ -872,11 +872,11 @@ X11_GetDisplayBounds(_THIS, SDL_VideoDisplay * sdl_display, SDL_Rect * rect)
     if (data->use_xinerama) {
         Display *display = ((SDL_VideoData *) _this->driverdata)->display;
         int screencount;
-        XineramaScreenInfo *xinerama = XineramaQueryScreens(display, &screencount);
+        XineramaScreenInfo *xinerama = X11_XineramaQueryScreens(display, &screencount);
         if (xinerama) {
             rect->x = xinerama[data->xinerama_screen].x_org;
             rect->y = xinerama[data->xinerama_screen].y_org;
-            XFree(xinerama);
+            X11_XFree(xinerama);
         }
     }
 #endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
diff --git a/src/video/x11/SDL_x11mouse.c b/src/video/x11/SDL_x11mouse.c
index 441ecdf..4bcd9d6 100644
--- a/src/video/x11/SDL_x11mouse.c
+++ b/src/video/x11/SDL_x11mouse.c
@@ -50,12 +50,12 @@ X11_CreateEmptyCursor()
 
         SDL_zero(data);
         color.red = color.green = color.blue = 0;
-        pixmap = XCreateBitmapFromData(display, DefaultRootWindow(display),
+        pixmap = X11_XCreateBitmapFromData(display, DefaultRootWindow(display),
                                        data, 1, 1);
         if (pixmap) {
-            x11_empty_cursor = XCreatePixmapCursor(display, pixmap, pixmap,
+            x11_empty_cursor = X11_XCreatePixmapCursor(display, pixmap, pixmap,
                                                    &color, &color, 0, 0);
-            XFreePixmap(display, pixmap);
+            X11_XFreePixmap(display, pixmap);
         }
     }
     return x11_empty_cursor;
@@ -65,7 +65,7 @@ static void
 X11_DestroyEmptyCursor(void)
 {
     if (x11_empty_cursor != None) {
-        XFreeCursor(GetDisplay(), x11_empty_cursor);
+        X11_XFreeCursor(GetDisplay(), x11_empty_cursor);
         x11_empty_cursor = None;
     }
 }
@@ -94,7 +94,7 @@ X11_CreateXCursorCursor(SDL_Surface * surface, int hot_x, int hot_y)
     Cursor cursor = None;
     XcursorImage *image;
 
-    image = XcursorImageCreate(surface->w, surface->h);
+    image = X11_XcursorImageCreate(surface->w, surface->h);
     if (!image) {
         SDL_OutOfMemory();
         return None;
@@ -107,9 +107,9 @@ X11_CreateXCursorCursor(SDL_Surface * surface, int hot_x, int hot_y)
     SDL_assert(surface->pitch == surface->w * 4);
     SDL_memcpy(image->pixels, surface->pixels, surface->h * surface->pitch);
 
-    cursor = XcursorImageLoadCursor(display, image);
+    cursor = X11_XcursorImageLoadCursor(display, image);
 
-    XcursorImageDestroy(image);
+    X11_XcursorImageDestroy(image);
 
     return cursor;
 }
@@ -186,16 +186,16 @@ X11_CreatePixmapCursor(SDL_Surface * surface, int hot_x, int hot_y)
     }
     else bg.red = bg.green = bg.blue = 0;
 
-    data_pixmap = XCreateBitmapFromData(display, DefaultRootWindow(display),
+    data_pixmap = X11_XCreateBitmapFromData(display, DefaultRootWindow(display),
                                         (char*)data_bits,
                                         surface->w, surface->h);
-    mask_pixmap = XCreateBitmapFromData(display, DefaultRootWindow(display),
+    mask_pixmap = X11_XCreateBitmapFromData(display, DefaultRootWindow(display),
                                         (char*)mask_bits,
                                         surface->w, surface->h);
-    cursor = XCreatePixmapCursor(display, data_pixmap, mask_pixmap,
+    cursor = X11_XCreatePixmapCursor(display, data_pixmap, mask_pixmap,
                                  &fg, &bg, hot_x, hot_y);
-    XFreePixmap(display, data_pixmap);
-    XFreePixmap(display, mask_pixmap);
+    X11_XFreePixmap(display, data_pixmap);
+    X11_XFreePixmap(display, mask_pixmap);
 
     return cursor;
 }
@@ -256,7 +256,7 @@ X11_CreateSystemCursor(SDL_SystemCursor id)
     if (cursor) {
         Cursor x11_cursor;
 
-        x11_cursor = XCreateFontCursor(GetDisplay(), shape);
+        x11_cursor = X11_XCreateFontCursor(GetDisplay(), shape);
 
         cursor->driverdata = (void*)x11_cursor;
     } else {
@@ -272,7 +272,7 @@ X11_FreeCursor(SDL_Cursor * cursor)
     Cursor x11_cursor = (Cursor)cursor->driverdata;
 
     if (x11_cursor != None) {
-        XFreeCursor(GetDisplay(), x11_cursor);
+        X11_XFreeCursor(GetDisplay(), x11_cursor);
     }
     SDL_free(cursor);
 }
@@ -298,12 +298,12 @@ X11_ShowCursor(SDL_Cursor * cursor)
         for (window = video->windows; window; window = window->next) {
             data = (SDL_WindowData *)window->driverdata;
             if (x11_cursor != None) {
-                XDefineCursor(display, data->xwindow, x11_cursor);
+                X11_XDefineCursor(display, data->xwindow, x11_cursor);
             } else {
-                XUndefineCursor(display, data->xwindow);
+                X11_XUndefineCursor(display, data->xwindow);
             }
         }
-        XFlush(display);
+        X11_XFlush(display);
     }
     return 0;
 }
@@ -314,8 +314,8 @@ X11_WarpMouse(SDL_Window * window, int x, int y)
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     Display *display = data->videodata->display;
 
-    XWarpPointer(display, None, data->xwindow, 0, 0, 0, 0, x, y);
-    XSync(display, False);
+    X11_XWarpPointer(display, None, data->xwindow, 0, 0, 0, 0, x, y);
+    X11_XSync(display, False);
 }
 
 static int
diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c
index 67a4b06..74165f4 100644
--- a/src/video/x11/SDL_x11opengl.c
+++ b/src/video/x11/SDL_x11opengl.c
@@ -320,16 +320,16 @@ X11_GL_InitExtensions(_THIS)
     xattr.background_pixel = 0;
     xattr.border_pixel = 0;
     xattr.colormap =
-        XCreateColormap(display, RootWindow(display, screen), vinfo->visual,
+        X11_XCreateColormap(display, RootWindow(display, screen), vinfo->visual,
                         AllocNone);
-    w = XCreateWindow(display, RootWindow(display, screen), 0, 0, 32, 32, 0,
+    w = X11_XCreateWindow(display, RootWindow(display, screen), 0, 0, 32, 32, 0,
                       vinfo->depth, InputOutput, vinfo->visual,
                       (CWBackPixel | CWBorderPixel | CWColormap), &xattr);
     context = _this->gl_data->glXCreateContext(display, vinfo, NULL, True);
     if (context) {
         _this->gl_data->glXMakeCurrent(display, w, context);
     }
-    XFree(vinfo);
+    X11_XFree(vinfo);
 
     glXQueryExtensionsStringFunc =
         (const char *(*)(Display *, int)) X11_GL_GetProcAddress(_this,
@@ -385,7 +385,7 @@ X11_GL_InitExtensions(_THIS)
         _this->gl_data->glXMakeCurrent(display, None, NULL);
         _this->gl_data->glXDestroyContext(display, context);
     }
-    XDestroyWindow(display, w);
+    X11_XDestroyWindow(display, w);
     X11_PumpEvents(_this);
 }
 
@@ -566,13 +566,13 @@ X11_GL_CreateContext(_THIS, SDL_Window * window)
     }
 
     /* We do this to create a clean separation between X and GLX errors. */
-    XSync(display, False);
+    X11_XSync(display, False);
     errorBase = _this->gl_data->errorBase;
-    handler = XSetErrorHandler(X11_GL_CreateContextErrorHandler);
-    XGetWindowAttributes(display, data->xwindow, &xattr);
+    handler = X11_XSetErrorHandler(X11_GL_CreateContextErrorHandler);
+    X11_XGetWindowAttributes(display, data->xwindow, &xattr);
     v.screen = screen;
-    v.visualid = XVisualIDFromVisual(xattr.visual);
-    vinfo = XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n);
+    v.visualid = X11_XVisualIDFromVisual(xattr.visual);
+    vinfo = X11_XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n);
     if (vinfo) {
         if (_this->gl_config.major_version < 3 &&
             _this->gl_config.profile_mask == 0 &&
@@ -656,10 +656,10 @@ X11_GL_CreateContext(_THIS, SDL_Window * window)
                 }
             }
         }
-        XFree(vinfo);
+        X11_XFree(vinfo);
     }
-    XSync(display, False);
-    XSetErrorHandler(handler);
+    X11_XSync(display, False);
+    X11_XSetErrorHandler(handler);
 
     if (!context) {
         SDL_SetError("Could not create GL context");
@@ -801,7 +801,7 @@ X11_GL_DeleteContext(_THIS, SDL_GLContext context)
         return;
     }
     _this->gl_data->glXDestroyContext(display, glx_context);
-    XSync(display, False);
+    X11_XSync(display, False);
 }
 
 #endif /* SDL_VIDEO_OPENGL_GLX */
diff --git a/src/video/x11/SDL_x11opengles.c b/src/video/x11/SDL_x11opengles.c
index 9818325..f972cee 100644
--- a/src/video/x11/SDL_x11opengles.c
+++ b/src/video/x11/SDL_x11opengles.c
@@ -74,13 +74,13 @@ X11_GLES_GetVisual(_THIS, Display * display, int screen)
                                             &visual_id) == EGL_FALSE || !visual_id) {
         /* Use the default visual when all else fails */
         vi_in.screen = screen;
-        egl_visualinfo = XGetVisualInfo(display,
+        egl_visualinfo = X11_XGetVisualInfo(display,
                                         VisualScreenMask,
                                         &vi_in, &out_count);
     } else {
         vi_in.screen = screen;
         vi_in.visualid = visual_id;
-        egl_visualinfo = XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &vi_in, &out_count);
+        egl_visualinfo = X11_XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &vi_in, &out_count);
     }
 
     return egl_visualinfo;
@@ -93,9 +93,9 @@ X11_GLES_CreateContext(_THIS, SDL_Window * window)
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     Display *display = data->videodata->display;
 
-    XSync(display, False);
+    X11_XSync(display, False);
     context = SDL_EGL_CreateContext(_this, data->egl_surface);
-    XSync(display, False);
+    X11_XSync(display, False);
 
     return context;
 }
diff --git a/src/video/x11/SDL_x11shape.c b/src/video/x11/SDL_x11shape.c
index 67eeade..af89851 100644
--- a/src/video/x11/SDL_x11shape.c
+++ b/src/video/x11/SDL_x11shape.c
@@ -106,12 +106,12 @@ X11_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMo
     SDL_CalculateShapeBitmap(shaper->mode,shape,data->bitmap,8);
 
     windowdata = (SDL_WindowData*)(shaper->window->driverdata);
-    shapemask = XCreateBitmapFromData(windowdata->videodata->display,windowdata->xwindow,data->bitmap,shaper->window->w,shaper->window->h);
+    shapemask = X11_XCreateBitmapFromData(windowdata->videodata->display,windowdata->xwindow,data->bitmap,shaper->window->w,shaper->window->h);
 
-    XShapeCombineMask(windowdata->videodata->display,windowdata->xwindow, ShapeBounding, 0, 0,shapemask, ShapeSet);
-    XSync(windowdata->videodata->display,False);
+    X11_XShapeCombineMask(windowdata->videodata->display,windowdata->xwindow, ShapeBounding, 0, 0,shapemask, ShapeSet);
+    X11_XSync(windowdata->videodata->display,False);
 
-    XFreePixmap(windowdata->videodata->display,shapemask);
+    X11_XFreePixmap(windowdata->videodata->display,shapemask);
 #endif
 
     return 0;
diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c
index 5ed47d5..c84d4ec 100644
--- a/src/video/x11/SDL_x11video.c
+++ b/src/video/x11/SDL_x11video.c
@@ -230,9 +230,9 @@ X11_Available(void)
 {
     Display *display = NULL;
     if (SDL_X11_LoadSymbols()) {
-        display = XOpenDisplay(NULL);
+        display = X11_XOpenDisplay(NULL);
         if (display != NULL) {
-            XCloseDisplay(display);
+            X11_XCloseDisplay(display);
         }
         SDL_X11_UnloadSymbols();
     }
@@ -244,7 +244,7 @@ X11_DeleteDevice(SDL_VideoDevice * device)
 {
     SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
     if (data->display) {
-        XCloseDisplay(data->display);
+        X11_XCloseDisplay(data->display);
     }
     SDL_free(data->windowlist);
     SDL_free(device->driverdata);
@@ -296,7 +296,7 @@ X11_CreateDevice(int devindex)
 
     /* Need for threading gl calls. This is also required for the proprietary
         nVidia driver to be threaded. */
-    XInitThreads();
+    X11_XInitThreads();
 
     /* Initialize all variables that we clean on shutdown */
     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
@@ -313,14 +313,14 @@ X11_CreateDevice(int devindex)
     device->driverdata = data;
 
     /* FIXME: Do we need this?
-       if ( (SDL_strncmp(XDisplayName(display), ":", 1) == 0) ||
-       (SDL_strncmp(XDisplayName(display), "unix:", 5) == 0) ) {
+       if ( (SDL_strncmp(X11_XDisplayName(display), ":", 1) == 0) ||
+       (SDL_strncmp(X11_XDisplayName(display), "unix:", 5) == 0) ) {
        local_X11 = 1;
        } else {
        local_X11 = 0;
        }
      */
-    data->display = XOpenDisplay(display);
+    data->display = X11_XOpenDisplay(display);
 #if defined(__osf__) && defined(SDL_VIDEO_DRIVER_X11_DYNAMIC)
     /* On Tru64 if linking without -lX11, it fails and you get following message.
      * Xlib: connection to ":0.0" refused by server
@@ -331,7 +331,7 @@ X11_CreateDevice(int devindex)
      */
     if (data->display == NULL) {
         SDL_Delay(1000);
-        data->display = XOpenDisplay(display);
+        data->display = X11_XOpenDisplay(display);
     }
 #endif
     if (data->display == NULL) {
@@ -341,12 +341,12 @@ X11_CreateDevice(int devindex)
         return NULL;
     }
 #ifdef X11_DEBUG
-    XSynchronize(data->display, True);
+    X11_XSynchronize(data->display, True);
 #endif
 
     /* Hook up an X11 error handler to recover the desktop resolution. */
     safety_net_triggered = SDL_FALSE;
-    orig_x11_errhandler = XSetErrorHandler(X11_SafetyNetErrHandler);
+    orig_x11_errhandler = X11_XSetErrorHandler(X11_SafetyNetErrHandler);
 
     /* Set the function pointers */
     device->VideoInit = X11_VideoInit;
@@ -448,31 +448,31 @@ X11_CheckWindowManager(_THIS)
 #endif
 
     /* Set up a handler to gracefully catch errors */
-    XSync(display, False);
-    handler = XSetErrorHandler(X11_CheckWindowManagerErrorHandler);
+    X11_XSync(display, False);
+    handler = X11_XSetErrorHandler(X11_CheckWindowManagerErrorHandler);
 
-    _NET_SUPPORTING_WM_CHECK = XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", False);
-    status = XGetWindowProperty(display, DefaultRootWindow(display), _NET_SUPPORTING_WM_CHECK, 0L, 1L, False, XA_WINDOW, &real_type, &real_format, &items_read, &items_left, &propdata);
+    _NET_SUPPORTING_WM_CHECK = X11_XInternAtom(display, "_NET_SUPPORTING_WM_CHECK", False);
+    status = X11_XGetWindowProperty(display, DefaultRootWindow(display), _NET_SUPPORTING_WM_CHECK, 0L, 1L, False, XA_WINDOW, &real_type, &real_format, &items_read, &items_left, &propdata);
     if (status == Success && items_read) {
         wm_window = ((Window*)propdata)[0];
     }
     if (propdata) {
-        XFree(propdata);
+        X11_XFree(propdata);
     }
 
     if (wm_window) {
-        status = XGetWindowProperty(display, wm_window, _NET_SUPPORTING_WM_CHECK, 0L, 1L, False, XA_WINDOW, &real_type, &real_format, &items_read, &items_left, &propdata);
+        status = X11_XGetWindowProperty(display, wm_window, _NET_SUPPORTING_WM_CHECK, 0L, 1L, False, XA_WINDOW, &real_type, &real_format, &items_read, &items_left, &propdata);
         if (status != Success || !items_read || wm_window != ((Window*)propdata)[0]) {
             wm_window = None;
         }
         if (propdata) {
-            XFree(propdata);
+            X11_XFree(propdata);
         }
     }
 
     /* Reset the error handler, we're done checking */
-    XSync(display, False);
-    XSetErrorHandler(handler);
+    X11_XSync(display, False);
+    X11_XSetErrorHandler(handler);
 
     if (!wm_window) {
 #ifdef DEBUG_WINDOW_MANAGER
@@ -505,12 +505,12 @@ X11_VideoInit(_THIS)
 #ifdef X_HAVE_UTF8_STRING
     if (SDL_X11_HAVE_UTF8) {
         data->im =
-            XOpenIM(data->display, NULL, data->classname, data->classname);
+            X11_XOpenIM(data->display, NULL, data->classname, data->classname);
     }
 #endif
 
     /* Look up some useful Atoms */
-#define GET_ATOM(X) data->X = XInternAtom(data->display, #X, False)
+#define GET_ATOM(X) data->X = X11_XInternAtom(data->display, #X, False)
     GET_ATOM(WM_PROTOCOLS);
     GET_ATOM(WM_DELETE_WINDOW);
     GET_ATOM(_NET_WM_STATE);
@@ -568,7 +568,7 @@ X11_VideoQuit(_THIS)
     SDL_free(data->classname);
 #ifdef X_HAVE_UTF8_STRING
     if (data->im) {
-        XCloseIM(data->im);
+        X11_XCloseIM(data->im);
     }
 #endif
 
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index 18ff443..120b803 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -61,11 +61,11 @@ static Bool isConfigureNotify(Display *dpy, XEvent *ev, XPointer win)
 
 /*
 static Bool
-XIfEventTimeout(Display *display, XEvent *event_return, Bool (*predicate)(), XPointer arg, int timeoutMS)
+X11_XIfEventTimeout(Display *display, XEvent *event_return, Bool (*predicate)(), XPointer arg, int timeoutMS)
 {
     Uint32 start = SDL_GetTicks();
 
-    while (!XCheckIfEvent(display, event_return, predicate, arg)) {
+    while (!X11_XCheckIfEvent(display, event_return, predicate, arg)) {
         if ((SDL_GetTicks() - start) >= timeoutMS) {
             return False;
         }
@@ -88,7 +88,7 @@ X11_IsWindowMapped(_THIS, SDL_Window * window)
     SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
     XWindowAttributes attr;
 
-    XGetWindowAttributes(videodata->display, data->xwindow, &attr);
+    X11_XGetWindowAttributes(videodata->display, data->xwindow, &attr);
     if (attr.map_state != IsUnmapped) {
         return SDL_TRUE;
     } else {
@@ -110,7 +110,7 @@ X11_IsActionAllowed(SDL_Window *window, Atom action)
     Atom *list;
     SDL_bool ret = SDL_FALSE;
 
-    if (XGetWindowProperty(display, data->xwindow, _NET_WM_ALLOWED_ACTIONS, 0, 1024, False, XA_ATOM, &type, &form, &len, &remain, (unsigned char **)&list) == Success)
+    if (X11_XGetWindowProperty(display, data->xwindow, _NET_WM_ALLOWED_ACTIONS, 0, 1024, False, XA_ATOM, &type, &form, &len, &remain, (unsigned char **)&list) == Success)
     {
         for (i=0; i<len; ++i)
         {
@@ -119,7 +119,7 @@ X11_IsActionAllowed(SDL_Window *window, Atom action)
                 break;
             }
         }
-        XFree(list);
+        X11_XFree(list);
     }
     return ret;
 }
@@ -141,7 +141,7 @@ X11_SetNetWMState(_THIS, Window xwindow, Uint32 flags)
 
     /* The window manager sets this property, we shouldn't set it.
        If we did, this would indicate to the window manager that we don't
-       actually want to be mapped during XMapRaised(), which would be bad.
+       actually want to be mapped during X11_XMapRaised(), which would be bad.
      *
     if (flags & SDL_WINDOW_HIDDEN) {
         atoms[count++] = _NET_WM_STATE_HIDDEN;
@@ -158,10 +158,10 @@ X11_SetNetWMState(_THIS, Window xwindow, Uint32 flags)
         atoms[count++] = _NET_WM_STATE_FULLSCREEN;
     }
     if (count > 0) {
-        XChangeProperty(display, xwindow, _NET_WM_STATE, XA_ATOM, 32,
+        X11_XChangeProperty(display, xwindow, _NET_WM_STATE, XA_ATOM, 32,
                         PropModeReplace, (unsigned char *)atoms, count);
     } else {
-        XDeleteProperty(display, xwindow, _NET_WM_STATE);
+        X11_XDeleteProperty(display, xwindow, _NET_WM_STATE);
     }
 }
 
@@ -183,7 +183,7 @@ X11_GetNetWMState(_THIS, Window xwindow)
     long maxLength = 1024;
     Uint32 flags = 0;
 
-    if (XGetWindowProperty(display, xwindow, _NET_WM_STATE,
+    if (X11_XGetWindowProperty(display, xwindow, _NET_WM_STATE,
                            0l, maxLength, False, XA_ATOM, &actualType,
                            &actualFormat, &numItems, &bytesAfter,
                            &propertyValue) == Success) {
@@ -209,7 +209,7 @@ X11_GetNetWMState(_THIS, Window xwindow)
         }  else if (fullscreen == 1) {
             flags |= SDL_WINDOW_FULLSCREEN;
         }
-        XFree(propertyValue);
+        X11_XFree(propertyValue);
     }
 
     /* FIXME, check the size hints for resizable */
@@ -237,7 +237,7 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created)
 #ifdef X_HAVE_UTF8_STRING
     if (SDL_X11_HAVE_UTF8 && videodata->im) {
         data->ic =
-            pXCreateIC(videodata->im, XNClientWindow, w, XNFocusWindow, w,
+            X11_XCreateIC(videodata->im, XNClientWindow, w, XNFocusWindow, w,
                        XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
                        XNResourceName, videodata->classname, XNResourceClass,
                        videodata->classname, NULL);
@@ -270,7 +270,7 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created)
     {
         XWindowAttributes attrib;
 
-        XGetWindowAttributes(data->videodata->display, w, &attrib);
+        X11_XGetWindowAttributes(data->videodata->display, w, &attrib);
         window->x = attrib.x;
         window->y = attrib.y;
         window->w = attrib.width;
@@ -289,7 +289,7 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created)
     {
         Window FocalWindow;
         int RevertTo=0;
-        XGetInputFocus(data->videodata->display, &FocalWindow, &RevertTo);
+        X11_XGetInputFocus(data->videodata->display, &FocalWindow, &RevertTo);
         if (FocalWindow==w)
         {
             window->flags |= SDL_WINDOW_INPUT_FOCUS;
@@ -318,7 +318,7 @@ SetWindowBordered(Display *display, int screen, Window window, SDL_bool border)
      *  Gnome is similar: just use the Motif atom.
      */
 
-    Atom WM_HINTS = XInternAtom(display, "_MOTIF_WM_HINTS", True);
+    Atom WM_HINTS = X11_XInternAtom(display, "_MOTIF_WM_HINTS", True);
     if (WM_HINTS != None) {
         /* Hints used by Motif compliant window managers */
         struct
@@ -332,11 +332,11 @@ SetWindowBordered(Display *display, int screen, Window window, SDL_bool border)
             (1L << 1), 0, border ? 1 : 0, 0, 0
         };
 
-        XChangeProperty(display, window, WM_HINTS, WM_HINTS, 32,
+        X11_XChangeProperty(display, window, WM_HINTS, WM_HINTS, 32,
                         PropModeReplace, (unsigned char *) &MWMHints,
                         sizeof(MWMHints) / 4);
     } else {  /* set the transient hints instead, if necessary */
-        XSetTransientForHint(display, window, RootWindow(display, screen));
+        X11_XSetTransientForHint(display, window, RootWindow(display, screen));
     }
 }
 
@@ -389,7 +389,7 @@ X11_CreateWindow(_THIS, SDL_Window * window)
         }
         visual = vinfo->visual;
         depth = vinfo->depth;
-        XFree(vinfo);
+        X11_XFree(vinfo);
     } else
 #endif
     {
@@ -410,7 +410,7 @@ X11_CreateWindow(_THIS, SDL_Window * window)
         int rshift, gshift, bshift;
 
         xattr.colormap =
-            XCreateColormap(display, RootWindow(display, screen),
+            X11_XCreateColormap(display, RootWindow(display, screen),
                             visual, AllocAll);
 
         /* If we can't create a colormap, then we must die */
@@ -471,16 +471,16 @@ X11_CreateWindow(_THIS, SDL_Window * window)
             colorcells[i].flags = DoRed | DoGreen | DoBlue;
         }
 
-        XStoreColors(display, xattr.colormap, colorcells, ncolors);
+        X11_XStoreColors(display, xattr.colormap, colorcells, ncolors);
 
         SDL_free(colorcells);
     } else {
         xattr.colormap =
-            XCreateColormap(display, RootWindow(display, screen),
+            X11_XCreateColormap(display, RootWindow(display, screen),
                             visual, AllocNone);
     }
 
-    w = XCreateWindow(display, RootWindow(display, screen),
+    w = X11_XCreateWindow(display, RootWindow(display, screen),
                       window->x, window->y, window->w, window->h,
                       0, depth, InputOutput, visual,
                       (CWOverrideRedirect | CWBackPixmap | CWBorderPixel |
@@ -492,7 +492,7 @@ X11_CreateWindow(_THIS, SDL_Window * window)
     SetWindowBordered(display, screen, w,
                       (window->flags & SDL_WINDOW_BORDERLESS) == 0);
 
-    sizehints = XAllocSizeHints();
+    sizehints = X11_XAllocSizeHints();
     /* Setup the normal size hints */
     sizehints->flags = 0;
     if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
@@ -505,25 +505,25 @@ X11_CreateWindow(_THIS, SDL_Window * window)
     sizehints->flags |= USPosition;
 
     /* Setup the input hints so we get keyboard input */
-    wmhints = XAllocWMHints();
+    wmhints = X11_XAllocWMHints();
     wmhints->input = True;
     wmhints->flags = InputHint;
 
     /* Setup the class hints so we can get an icon (AfterStep) */
-    classhints = XAllocClassHint();
+    classhints = X11_XAllocClassHint();
     classhints->res_name = data->classname;
     classhints->res_class = data->classname;
 
     /* Set the size, input and class hints, and define WM_CLIENT_MACHINE and WM_LOCALE_NAME */
-    XSetWMProperties(display, w, NULL, NULL, NULL, 0, sizehints, wmhints, classhints);
+    X11_XSetWMProperties(display, w, NULL, NULL, NULL, 0, sizehints, wmhints, classhints);
 
-    XFree(sizehints);
-    XFree(wmhints);
-    XFree(classhints);
+    X11_XFree(sizehints);
+    X11_XFree(wmhints);
+    X11_XFree(classhints);
     /* Set the PID related to the window for the given hostname, if possible */
     if (data->pid > 0) {
-        _NET_WM_PID = XInternAtom(display, "_NET_WM_PID", False);
-        XChangeProperty(display, w, _NET_WM_PID, XA_CARDINAL, 32, PropModeReplace,
+        _NET_WM_PID = X11_XInternAtom(display, "_NET_WM_PID", False);
+        X11_XChangeProperty(display, w, _NET_WM_PID, XA_CARDINAL, 32, PropModeReplace,
                         (unsigned char *)&data->pid, 1);
     }
 
@@ -531,14 +531,14 @@ X11_CreateWindow(_THIS, SDL_Window * window)
     X11_SetNetWMState(_this, w, window->flags);
 
     /* Let the window manager know we're a "normal" window */
-    _NET_WM_WINDOW_TYPE = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
-    _NET_WM_WINDOW_TYPE_NORMAL = XInternAtom(display, "_NET_WM_WINDOW_TYPE_NORMAL", False);
-    XChangeProperty(display, w, _NET_WM_WINDOW_TYPE, XA_ATOM, 32,
+    _NET_WM_WINDOW_TYPE = X11_XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
+    _NET_WM_WINDOW_TYPE_NORMAL = X11_XInternAtom(display, "_NET_WM_WINDOW_TYPE_NORMAL", False);
+    X11_XChangeProperty(display, w, _NET_WM_WINDOW_TYPE, XA_ATOM, 32,
                     PropModeReplace,
                     (unsigned char *)&_NET_WM_WINDOW_TYPE_NORMAL, 1);
 
-    _NET_WM_BYPASS_COMPOSITOR = XInternAtom(display, "_NET_WM_BYPASS_COMPOSITOR", False);
-    XChangeProperty(display, w, _NET_WM_BYPASS_COMPOSITOR, XA_CARDINAL, 32,
+    _NET_WM_BYPASS_COMPOSITOR = X11_XInternAtom(display, "_NET_WM_BYPASS_COMPOSITOR", False);
+    X11_XChangeProperty(display, w, _NET_WM_BYPASS_COMPOSITOR, XA_CARDINAL, 32,
                     PropModeReplace,
                     (unsigned char *)&_NET_WM_BYPASS_COMPOSITOR_HINT_ON, 1);
 
@@ -547,11 +547,11 @@ X11_CreateWindow(_THIS, SDL_Window * window)
             data->WM_DELETE_WINDOW, /* Allow window to be deleted by the WM */
             data->_NET_WM_PING, /* Respond so WM knows we're alive */
         };
-        XSetWMProtocols(display, w, protocols, sizeof (protocols) / sizeof (protocols[0]));
+        X11_XSetWMProtocols(display, w, protocols, sizeof (protocols) / sizeof (protocols[0]));
     }
 
     if (SetupWindowData(_this, window, w, SDL_TRUE) < 0) {
-        XDestroyWindow(display, w);
+        X11_XDestroyWindow(display, w);
         return -1;
     }
     windowdata = (SDL_WindowData *) window->driverdata;
@@ -564,7 +564,7 @@ X11_CreateWindow(_THIS, SDL_Window * window)
 #endif  
     ) {
         if (!_this->egl_data) {
-            XDestroyWindow(display, w);
+            X11_XDestroyWindow(display, w);
             return -1;
         }
 
@@ -572,7 +572,7 @@ X11_CreateWindow(_THIS, SDL_Window * window)
         windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) w);
 
         if (windowdata->egl_surface == EGL_NO_SURFACE) {
-            XDestroyWindow(display, w);
+            X11_XDestroyWindow(display, w);
             return SDL_SetError("Could not create GLES window surface");
         }
     }
@@ -581,25 +581,25 @@ X11_CreateWindow(_THIS, SDL_Window * window)
 
 #ifdef X_HAVE_UTF8_STRING
     if (SDL_X11_HAVE_UTF8 && windowdata->ic) {
-        pXGetICValues(windowdata->ic, XNFilterEvents, &fevent, NULL);
+        X11_XGetICValues(windowdata->ic, XNFilterEvents, &fevent, NULL);
     }
 #endif
 
     X11_Xinput2SelectTouch(_this, window);
 
-    XSelectInput(display, w,
+    X11_XSelectInput(display, w,
                  (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
                  ExposureMask | ButtonPressMask | ButtonReleaseMask |
                  PointerMotionMask | KeyPressMask | KeyReleaseMask |
                  PropertyChangeMask | StructureNotifyMask |
                  KeymapStateMask | fevent));
 
-    XdndAware = XInternAtom(display, "XdndAware", False);
-    XChangeProperty(display, w, XdndAware, XA_ATOM, 32,
+    XdndAware = X11_XInternAtom(display, "XdndAware", False);
+    X11_XChangeProperty(display, w, XdndAware, XA_ATOM, 32,
                  PropModeReplace,
                  (unsigned char*)&xdnd_version, 1);
 
-    XFlush(display);
+    X11_XFlush(display);
 
     return 0;
 }
@@ -628,14 +628,14 @@ X11_GetWindowTitle(_THIS, Window xwindow)
     unsigned char *propdata;
     char *title = NULL;
 
-    status = XGetWindowProperty(display, xwindow, data->_NET_WM_NAME,
+    status = X11_XGetWindowProperty(display, xwindow, data->_NET_WM_NAME,
                 0L, 8192L, False, data->UTF8_STRING, &real_type, &real_format,
                 &items_read, &items_left, &propdata);
     if (status == Success && propdata) {
         title = SDL_strdup(SDL_static_cast(char*, propdata));
-        XFree(propdata);
+        X11_XFree(propdata);
     } else {
-        status = XGetWindowProperty(display, xwindow, XA_WM_NAME,
+        status = X11_XGetWindowProperty(display, xwindow, XA_WM_NAME,
                     0L, 8192L, False, XA_STRING, &real_type, &real_format,
                     &items_read, &items_left, &propdata);
         if (status == Success && propdata) {
@@ -668,21 +668,21 @@ X11_SetWindowTitle(_THIS, SDL_Window * window)
             SDL_OutOfMemory();
             return;
         }
-        status = XStringListToTextProperty(&title_locale, 1, &titleprop);
+        status = X11_XStringListToTextProperty(&title_locale, 1, &titleprop);
         SDL_free(title_locale);
         if (status) {
-            XSetTextProperty(display, data->xwindow, &titleprop, XA_WM_NAME);
-            XFree(titleprop.value);
+            X11_XSetTextProperty(display, data->xwindow, &titleprop, XA_WM_NAME);
+            X11_XFree(titleprop.value);
         }
 #ifdef X_HAVE_UTF8_STRING
         if (SDL_X11_HAVE_UTF8) {
             status =
-                Xutf8TextListToTextProperty(display, (char **) &title, 1,
+                X11_Xutf8TextListToTextProperty(display, (char **) &title, 1,
                                             XUTF8StringStyle, &titleprop);
             if (status == Success) {
-                XSetTextProperty(display, data->xwindow, &titleprop,
+                X11_XSetTextProperty(display, data->xwindow, &titleprop,
                                  _NET_WM_NAME);
-                XFree(titleprop.value);
+                X11_XFree(titleprop.value);
             }
         }
 #endif
@@ -693,27 +693,27 @@ X11_SetWindowTitle(_THIS, SDL_Window * window)
             SDL_OutOfMemory();
             return;
         }
-        status = XStringListToTextProperty(&icon_locale, 1, &iconprop);
+        status = X11_XStringListToTextProperty(&icon_locale, 1, &iconprop);
         SDL_free(icon_locale);
         if (status) {
-            XSetTextProperty(display, data->xwindow, &iconprop,
+            X11_XSetTextProperty(display, data->xwindow, &iconprop,
                              XA_WM_ICON_NAME);
-            XFree(iconprop.value);
+            X11_XFree(iconprop.value);
         }
 #ifdef X_HAVE_UTF8_STRING
         if (SDL_X11_HAVE_UTF8) {
             status =
-                Xutf8TextListToTextProperty(display, (char **) &icon, 1,
+                X11_Xutf8TextListToTextProperty(display, (char **) &icon, 1,
                                             XUTF8StringStyle, &iconprop);
             if (status == Success) {
-                XSetTextProperty(display, data->xwindow, &iconprop,
+                X11_XSetTextProperty(display, data->xwindow, &iconprop,
                                  _NET_WM_ICON_NAME);
-                XFree(iconprop.value);
+                X11_XFree(iconprop.value);
             }
         }
 #endif
     }
-    XFlush(display);
+    X11_XFlush(display);
 }
 
 void
@@ -745,15 +745,15 @@ X11_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
                     *dst++ = *src++;
                 }
             }
-            XChangeProperty(display, data->xwindow, _NET_WM_ICON, XA_CARDINAL,
+            X11_XChangeProperty(display, data->xwindow, _NET_WM_ICON, XA_CARDINAL,
                             32, PropModeReplace, (unsigned char *) propdata,
                             propsize);
         }
         SDL_free(propdata);
     } else {
-        XDeleteProperty(display, data->xwindow, _NET_WM_ICON);
+        X11_XDeleteProperty(display, data->xwindow, _NET_WM_ICON);
     }
-    XFlush(display);
+    X11_XFlush(display);
 }
 
 void
@@ -762,8 +762,8 @@ X11_SetWindowPosition(_THIS, SDL_Window * window)
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     Display *display = data->videodata->display;
 
-    XMoveWindow(display, data->xwindow, window->x, window->y);
-    XFlush(display);
+    X11_XMoveWindow(display, data->xwindow, window->x, window->y);
+    X11_XFlush(display);
 }
 
 void
@@ -773,26 +773,26 @@ X11_SetWindowMinimumSize(_THIS, SDL_Window * window)
     Display *display = data->videodata->display;
 
     if (window->flags & SDL_WINDOW_RESIZABLE) {
-         XSizeHints *sizehints = XAllocSizeHints();
+         XSizeHints *sizehints = X11_XAllocSizeHints();
          long userhints;
 
-         XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
+         X11_XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
 
          sizehints->min_width = window->min_w;
          sizehints->min_height = window->min_h;
          sizehints->flags |= PMinSize;
 
-         XSetWMNormalHints(display, data->xwindow, sizehints);
+         X11_XSetWMNormalHints(display, data->xwindow, sizehints);
 
-         XFree(sizehints);
+         X11_XFree(sizehints);
 
         /* See comment in X11_SetWindowSize. */
-        XResizeWindow(display, data->xwindow, window->w, window->h);
-        XMoveWindow(display, data->xwindow, window->x, window->y);
-        XRaiseWindow(display, data->xwindow);
+        X11_XResizeWindow(display, data->xwindow, window->w, window->h);
+        X11_XMoveWindow(display, data->xwindow, window->x, window->y);
+        X11_XRaiseWindow(display, data->xwindow);
     }
 
-    XFlush(display);
+    X11_XFlush(display);
 }
 
 void
@@ -802,26 +802,26 @@ X11_SetWindowMaximumSize(_THIS, SDL_Window * window)
     Display *display = data->videodata->display;
 
     if (window->flags & SDL_WINDOW_RESIZABLE) {
-         XSizeHints *sizehints = XAllocSizeHints();
+         XSizeHints *sizehints = X11_XAllocSizeHints();
          long userhints;
 
-         XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
+         X11_XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
 
          sizehints->max_width = window->max_w;
          sizehints->max_height = window->max_h;
          sizehints->flags |= PMaxSize;
 
-         XSetWMNormalHints(display, data->xwindow, sizehints);
+         X11_XSetWMNormalHints(display, data->xwindow, sizehints);
 
-         XFree(sizehints);
+         X11_XFree(sizehints);
 
         /* See comment in X11_SetWindowSize. */
-        XResizeWindow(display, data->xwindow, window->w, window->h);
-        XMoveWindow(display, data->xwindow, window->x, window->y);
-        XRaiseWindow(display, data->xwindow);
+        X11_XResizeWindow(display, data->xwindow, window->w, window->h);
+        X11_XMoveWindow(display, data->xwindow, window->x, window->y);
+        X11_XRaiseWindow(display, data->xwindow);
     }
 
-    XFlush(display);
+    X11_XFlush(display);
 }
 
 void
@@ -834,20 +834,20 @@ X11_SetWindowSize(_THIS, SDL_Window * window)
         X11_ResizeWindowShape(window);
     }
     if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
-         /* Apparently, if the X11 Window is set to a 'non-resizable' window, you cannot resize it using the XResizeWindow, thus
+         /* Apparently, if the X11 Window is set to a 'non-resizable' window, you cannot resize it using the X11_XResizeWindow, thus
             we must set the size hints to adjust the window size. */
-         XSizeHints *sizehints = XAllocSizeHints();
+         XSizeHints *sizehints = X11_XAllocSizeHints();
          long userhints;
 
-         XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
+         X11_XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
 
          sizehints->min_width = sizehints->max_width = window->w;
          sizehints->min_height = sizehints->max_height = window->h;
          sizehints->flags |= PMinSize | PMaxSize;
 
-         XSetWMNormalHints(display, data->xwindow, sizehints);
+         X11_XSetWMNormalHints(display, data->xwindow, sizehints);
 
-         XFree(sizehints);
+         X11_XFree(sizehints);
 
         /* From Pierre-Loup:
            WMs each have their little quirks with that.  When you change the
@@ -865,14 +865,14 @@ X11_SetWindowSize(_THIS, SDL_Window * window)
            hide/show, because there are supposedly subtle problems with doing so
            and transitioning from windowed to fullscreen in Unity.
          */
-        XResizeWindow(display, data->xwindow, window->w, window->h);
-        XMoveWindow(display, data->xwindow, window->x, window->y);
-        XRaiseWindow(display, data->xwindow);
+        X11_XResizeWindow(display, data->xwindow, window->w, window->h);
+        X11_XMoveWindow(display, data->xwindow, window->x, window->y);
+        X11_XRaiseWindow(display, data->xwindow);
     } else {
-        XResizeWindow(display, data->xwindow, window->w, window->h);
+        X11_XResizeWindow(display, data->xwindow, window->w, window->h);
     }
 
-    XFlush(display);
+    X11_XFlush(display);
 }
 
 void
@@ -887,25 +887,25 @@ X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
     XEvent event;
 
     SetWindowBordered(display, displaydata->screen, data->xwindow, bordered);
-    XFlush(display);
-    XIfEvent(display, &event, &isConfigureNotify, (XPointer)&data->xwindow);
+    X11_XFlush(display);
+    X11_XIfEvent(display, &event, &isConfigureNotify, (XPointer)&data->xwindow);
 
     if (visible) {
         XWindowAttributes attr;
         do {
-            XSync(display, False);
-            XGetWindowAttributes(display, data->xwindow, &attr);
+            X11_XSync(display, False);
+            X11_XGetWindowAttributes(display, data->xwindow, &attr);
         } while (attr.map_state != IsViewable);
 
         if (focused) {
-            XSetInputFocus(display, data->xwindow, RevertToParent, CurrentTime);
+            X11_XSetInputFocus(display, data->xwindow, RevertToParent, CurrentTime);
         }
     }
 
     /* make sure these don't make it to the real event queue if they fired here. */
-    XSync(display, False);
-    XCheckIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
-    XCheckIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
+    X11_XSync(display, False);
+    X11_XCheckIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
+    X11_XCheckIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
 }
 
 void
@@ -916,12 +916,12 @@ X11_ShowWindow(_THIS, SDL_Window * window)
     XEvent event;
 
     if (!X11_IsWindowMapped(_this, window)) {
-        XMapRaised(display, data->xwindow);
+        X11_XMapRaised(display, data->xwindow);
         /* Blocking wait for "MapNotify" event.
-         * We use XIfEvent because XWindowEvent takes a mask rather than a type,
+         * We use X11_XIfEvent because pXWindowEvent takes a mask rather than a type,
          * and XCheckTypedWindowEvent doesn't block */
-        XIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
-        XFlush(display);
+        X11_XIfEvent(display, &event, &isMapNotify, (XPointer)&data->xwindow);
+        X11_XFlush(display);
     }
 }
 
@@ -934,10 +934,10 @@ X11_HideWindow(_THIS, SDL_Window * window)
     XEvent event;
 
     if (X11_IsWindowMapped(_this, window)) {
-        XWithdrawWindow(display, data->xwindow, displaydata->screen);
+        X11_XWithdrawWindow(display, data->xwindow, displaydata->screen);
         /* Blocking wait for "UnmapNotify" event */
-        XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
-        XFlush(display);
+        X11_XIfEvent(display, &event, &isUnmapNotify, (XPointer)&data->xwindow);
+        X11_XFlush(display);
     }
 }
 
@@ -962,10 +962,10 @@ SetWindowActive(_THIS, SDL_Window * window)
         e.xclient.data.l[1] = CurrentTime;
         e.xclient.data.l[2] = 0;
 
-        XSendEvent(display, RootWindow(display, displaydata->screen), 0,
+        X11_XSendEvent(display, RootWindow(display, displaydata->screen), 0,
                    SubstructureNotifyMask | SubstructureRedirectMask, &e);
 
-        XFlush(display);
+        X11_XFlush(display);
     }
 }
 
@@ -975,9 +975,9 @@ X11_RaiseWindow(_THIS, SDL_Window * window)
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     Display *display = data->videodata->display;
 
-    XRaiseWindow(display, data->xwindow);
+    X11_XRaiseWindow(display, data->xwindow);
     SetWindowActive(_this, window);
-    XFlush(display);
+    X11_XFlush(display);
 }
 
 static void
@@ -1011,12 +1011,12 @@ SetWindowMaximized(_THIS, SDL_Window * window, SDL_bool maximized)
         e.xclient.data.l[2] = _NET_WM_STATE_MAXIMIZED_HORZ;
         e.xclient.data.l[3] = 0l;
 
-        XSendEvent(display, RootWindow(display, displaydata->screen), 0,
+        X11_XSendEvent(display, RootWindow(display, displaydata->screen), 0,
                    SubstructureNotifyMask | SubstructureRedirectMask, &e);
     } else {
         X11_SetNetWMState(_this, data->xwindow, window->flags);
     }
-    XFlush(display);
+    X11_XFlush(display);
 }
 
 void
@@ -1033,8 +1033,8 @@ X11_MinimizeWindow(_THIS, SDL_Window * window)
         (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
     Display *display = data->videodata->display;
 
-    XIconifyWindow(display, data->xwindow, displaydata->screen);
-    XFlush(display);
+    X11_XIconifyWindow(display, data->xwindow, displaydata->screen);
+    X11_XFlush(display);
 }
 
 void
@@ -1061,9 +1061,9 @@ X11_SetWindowFullscreenViaWM(_THIS, SDL_Window * window, SDL_VideoDisplay * _dis
         if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
             /* Compiz refuses fullscreen toggle if we're not resizable, so update the hints so we
                can be resized to the fullscreen resolution (or reset so we're not resizable again) */
-            XSizeHints *sizehints = XAllocSizeHints();
+            XSizeHints *sizehints = X11_XAllocSizeHints();
             long flags = 0;
-            XGetWMNormalHints(display, data->xwindow, sizehints, &flags);
+            X11_XGetWMNormalHints(display, data->xwindow, sizehints, &flags);
             /* set the resize flags on */
             if (fullscreen) {
                 /* we are going fullscreen so turn the flags off */
@@ -1074,8 +1074,8 @@ X11_SetWindowFullscreenViaWM(_THIS, SDL_Window * window, SDL_VideoDisplay * _dis
                 sizehints->min_width = sizehints->max_width = window->windowed.w;
                 sizehints->min_height = sizehints->max_height = window->windowed.h;
             }
-            XSetWMNormalHints(display, data->xwindow, sizehints);
-            XFree(sizehints);
+            X11_XSetWMNormalHints(display, data->xwindow, sizehints);
+            X11_XFree(sizehints);
         }
 
         SDL_zero(e);
@@ -1088,7 +1088,7 @@ X11_SetWindowFullscreenViaWM(_THIS, SDL_Window * window, SDL_VideoDisplay * _dis
         e.xclient.data.l[1] = _NET_WM_STATE_FULLSCREEN;
         e.xclient.data.l[3] = 0l;
 
-        XSendEvent(display, RootWindow(display, displaydata->screen), 0,
+        X11_XSendEvent(display, RootWindow(display, displaydata->screen), 0,
                    SubstructureNotifyMask | SubstructureRedirectMask, &e);
     } else {
         Uint32 flags;
@@ -1104,13 +1104,13 @@ X11_SetWindowFullscreenViaWM(_THIS, SDL_Window * window, SDL_VideoDisplay * _dis
 
     if (data->visual->class == DirectColor) {
         if ( fullscreen ) {
-            XInstallColormap(display, data->colormap);
+            X11_XInstallColormap(display, data->colormap);
         } else {
-            XUninstallColormap(display, data->colormap);
+            X11_XUninstallColormap(display, data->colormap);
         }
     }
 
-    XFlush(display);
+    X11_XFlush(display);
 }
 
 /* This handles fullscreen itself, outside the Window Manager. */
@@ -1145,48 +1145,48 @@ X11_BeginWindowFullscreenLegacy(_THIS, SDL_Window * window, SDL_VideoDisplay * _
     xattr.colormap = data->colormap;
     xattrmask |= CWColormap;
 
-    data->fswindow = XCreateWindow(display, root,
+    data->fswindow = X11_XCreateWindow(display, root,
                                    rect.x, rect.y, rect.w, rect.h, 0,
                                    displaydata->depth, InputOutput,
                                    visual, xattrmask, &xattr);
 
-    XSelectInput(display, data->fswindow, StructureNotifyMask);
-    XSetWindowBackground(display, data->fswindow, 0);
-    XInstallColormap(display, data->colormap);
-    XClearWindow(display, data->fswindow);
-    XMapRaised(display, data->fswindow);
+    X11_XSelectInput(display, data->fswindow, StructureNotifyMask);
+    X11_XSetWindowBackground(display, data->fswindow, 0);
+    X11_XInstallColormap(display, data->colormap);
+    X11_XClearWindow(display, data->fswindow);
+    X11_XMapRaised(display, data->fswindow);
 
     /* Make sure the fswindow is in view by warping mouse to the corner */
-    XUngrabPointer(display, CurrentTime);
-    XWarpPointer(display, None, root, 0, 0, 0, 0, rect.x, rect.y);
+    X11_XUngrabPointer(display, CurrentTime);
+    X11_XWarpPointer(display, None, root, 0, 0, 0, 0, rect.x, rect.y);
 
     /* Wait to be mapped, filter Unmap event out if it arrives. */
-    XIfEvent(display, &ev, &isMapNotify, (XPointer)&data->fswindow);
-    XCheckIfEvent(display, &ev, &isUnmapNotify, (XPointer)&data->fswindow);
+    X11_XIfEvent(display, &ev, &isMapNotify, (XPointer)&data->fswindow);
+    X11_XCheckIfEvent(display, &ev, &isUnmapNotify, (XPointer)&data->fswindow);
 
 #if SDL_VIDEO_DRIVER_X11_XVIDMODE
     if ( displaydata->use_vidmode ) {
-        XF86VidModeLockModeSwitch(display, screen, True);
+        X11_XF86VidModeLockModeSwitch(display, screen, True);
     }
 #endif
 
     SetWindowBordered(display, displaydata->screen, data->xwindow, SDL_FALSE);
 
     /* Center actual window within our cover-the-screen window. */
-    XReparentWindow(display, data->xwindow, data->fswindow,
+    X11_XReparentWindow(display, data->xwindow, data->fswindow,
                     (rect.w - window->w) / 2, (rect.h - window->h) / 2);
 
     /* Move the mouse to the upper left to make sure it's on-screen */
-    XWarpPointer(display, None, root, 0, 0, 0, 0, rect.x, rect.y);
+    X11_XWarpPointer(display, None, root, 0, 0, 0, 0, rect.x, rect.y);
 
     /* Center mouse in the fullscreen window. */
     rect.x += (rect.w / 2);
     rect.y += (rect.h / 2);
-    XWarpPointer(display, None, root, 0, 0, 0, 0, rect.x, rect.y);
+    X11_XWarpPointer(display, None, root, 0, 0, 0, 0, rect.x, rect.y);
 
     /* Wait to be mapped, filter Unmap event out if it arrives. */
-    XIfEvent(display, &ev, &isMapNotify, (XPointer)&data->xwindow);
-    XCheckIfEvent(display, &ev, &isUnmapNotify, (XPointer)&data->xwindow);
+    X11_XIfEvent(display, &ev, &isMapNotify, (XPointer)&data->xwindow);
+    X11_XCheckIfEvent(display, &ev, &isUnmapNotify, (XPointer)&data->xwindow);
 
     SDL_UpdateWindowGrab(window);
 }
@@ -1210,27 +1210,27 @@ X11_EndWindowFullscreenLegacy(_THIS, SDL_Window * window, SDL_VideoDisplay * _di
 
 #if SDL_VIDEO_DRIVER_X11_VIDMODE
     if ( displaydata->use_vidmode ) {
-        XF86VidModeLockModeSwitch(display, screen, False);
+        X11_XF86VidModeLockModeSwitch(display, screen, False);
     }
 #endif
 
     SDL_UpdateWindowGrab(window);
 
-    XReparentWindow(display, data->xwindow, root, window->x, window->y);
+    X11_XReparentWindow(display, data->xwindow, root, window->x, window->y);
 
     /* flush these events so they don't confuse normal event handling */
-    XSync(display, False);
-    XCheckIfEvent(display, &ev, &isMapNotify, (XPointer)&data->xwindow);
-    XCheckIfEvent(display, &ev, &isUnmapNotify, (XPointer)&data->xwindow);
+    X11_XSync(display, False);
+    X11_XCheckIfEvent(display, &ev, &isMapNotify, (XPointer)&data->xwindow);
+    X11_XCheckIfEvent(display, &ev, &isUnmapNotify, (XPointer)&data->xwindow);
 
     SetWindowBordered(display, screen, data->xwindow,
                       (window->flags & SDL_WINDOW_BORDERLESS) == 0);
 
-    XWithdrawWindow(display, fswindow, screen);
+    X11_XWithdrawWindow(display, fswindow, screen);
 
     /* Wait to be unmapped. */
-    XIfEvent(display, &ev, &isUnmapNotify, (XPointer)&fswindow);
-    XDestroyWindow(display, fswindow);
+    X11_XIfEvent(display, &ev, &isUnmapNotify, (XPointer)&fswindow);
+    X11_XDestroyWindow(display, fswindow);
 }
 
 
@@ -1328,8 +1328,8 @@ X11_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
         colorcells[i].flags = DoRed | DoGreen | DoBlue;
     }
 
-    XStoreColors(display, colormap, colorcells, ncolors);
-    XFlush(display);
+    X11_XStoreColors(display, colormap, colorcells, ncolors);
+    X11_XFlush(display);
     SDL_free(colorcells);
 
     return 0;
@@ -1354,7 +1354,7 @@ X11_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
         /* Try to grab the mouse */
         for (;;) {
             int result =
-                XGrabPointer(display, data->xwindow, True, 0, GrabModeAsync,
+                X11_XGrabPointer(display, data->xwindow, True, 0, GrabModeAsync,
                              GrabModeAsync, data->xwindow, None, CurrentTime);
             if (result == GrabSuccess) {
                 break;
@@ -1363,7 +1363,7 @@ X11_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
         }
 
         /* Raise the window if we grab the mouse */
-        XRaiseWindow(display, data->xwindow);
+        X11_XRaiseWindow(display, data->xwindow);
 
         /* Now grab the keyboard */
         hint = SDL_GetHint(SDL_HINT_GRAB_KEYBOARD);
@@ -1376,14 +1376,14 @@ X11_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
             grab_keyboard = oldstyle_fullscreen;
         }
         if (grab_keyboard) {
-            XGrabKeyboard(display, data->xwindow, True, GrabModeAsync,
+            X11_XGrabKeyboard(display, data->xwindow, True, GrabModeAsync,
                           GrabModeAsync, CurrentTime);
         }
     } else {
-        XUngrabPointer(display, CurrentTime);
-        XUngrabKeyboard(display, CurrentTime);
+        X11_XUngrabPointer(display, CurrentTime);
+        X11_XUngrabKeyboard(display, CurrentTime);
     }
-    XSync(display, False);
+    X11_XSync(display, False);
 }
 
 void
@@ -1411,12 +1411,12 @@ X11_DestroyWindow(_THIS, SDL_Window * window)
         }
 #ifdef X_HAVE_UTF8_STRING
         if (data->ic) {
-            XDestroyIC(data->ic);
+            X11_XDestroyIC(data->ic);
         }
 #endif
         if (data->created) {
-            XDestroyWindow(display, data->xwindow);
-            XFlush(display);
+            X11_XDestroyWindow(display, data->xwindow);
+            X11_XFlush(display);
         }
         SDL_free(data);
     }
diff --git a/src/video/x11/SDL_x11xinput2.c b/src/video/x11/SDL_x11xinput2.c
index 10b4228..3f84bbd 100644
--- a/src/video/x11/SDL_x11xinput2.c
+++ b/src/video/x11/SDL_x11xinput2.c
@@ -36,7 +36,7 @@ static int xinput2_initialized = 0;
 static int xinput2_multitouch_supported = 0;
 #endif
 
-/* Opcode returned XQueryExtension
+/* Opcode returned X11_XQueryExtension
  * It will be used in event processing
  * to know that the event came from
  * this extension */
@@ -82,16 +82,16 @@ X11_InitXinput2(_THIS)
     * "As XI2 progresses it becomes important that you use this call as the server may treat the client
     * differently depending on the supported version".
     *
-    * FIXME:event and err are not needed but if not passed XQueryExtension returns SegmentationFault
+    * FIXME:event and err are not needed but if not passed X11_XQueryExtension returns SegmentationFault
     */
     if (!SDL_X11_HAVE_XINPUT2 ||
-        !XQueryExtension(data->display, "XInputExtension", &xinput2_opcode, &event, &err)) {
+        !X11_XQueryExtension(data->display, "XInputExtension", &xinput2_opcode, &event, &err)) {
         return;
     }
 
     outmajor = major;
     outminor = minor;
-    if (XIQueryVersion(data->display, &outmajor, &outminor) != Success) {
+    if (X11_XIQueryVersion(data->display, &outmajor, &outminor) != Success) {
         return;
     }
 
@@ -115,7 +115,7 @@ X11_InitXinput2(_THIS)
 
     XISetMask(mask, XI_RawMotion);
 
-    if (XISelectEvents(data->display,DefaultRootWindow(data->display),&eventmask,1) != Success) {
+    if (X11_XISelectEvents(data->display,DefaultRootWindow(data->display),&eventmask,1) != Success) {
         return;
     }
 #endif
@@ -226,7 +226,7 @@ X11_Xinput2SelectTouch(_THIS, SDL_Window *window)
     XISetMask(mask, XI_TouchUpdate);
     XISetMask(mask, XI_TouchEnd);
 
-    XISelectEvents(data->display,window_data->xwindow,&eventmask,1);
+    X11_XISelectEvents(data->display,window_data->xwindow,&eventmask,1);
 #endif
 }