1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079
|
// package wl acts as a client for the wayland wayland protocol.
// generated by wl-scanner
// https://github.com/dkolbly/wl-scanner
// from: https://cgit.freedesktop.org/wayland/wayland/plain/protocol/wayland.xml
// on 2018-02-19 14:50:40 -0600
package wl
import (
"context"
"sync"
)
type DisplayErrorEvent struct {
EventContext context.Context
ObjectId Proxy
Code uint32
Message string
}
type DisplayErrorHandler interface {
HandleDisplayError(DisplayErrorEvent)
}
func (p *Display) AddErrorHandler(h DisplayErrorHandler) {
if h != nil {
p.mu.Lock()
p.errorHandlers = append(p.errorHandlers, h)
p.mu.Unlock()
}
}
func (p *Display) RemoveErrorHandler(h DisplayErrorHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.errorHandlers {
if e == h {
p.errorHandlers = append(p.errorHandlers[:i], p.errorHandlers[i+1:]...)
break
}
}
}
type DisplayDeleteIdEvent struct {
EventContext context.Context
Id uint32
}
type DisplayDeleteIdHandler interface {
HandleDisplayDeleteId(DisplayDeleteIdEvent)
}
func (p *Display) AddDeleteIdHandler(h DisplayDeleteIdHandler) {
if h != nil {
p.mu.Lock()
p.deleteIdHandlers = append(p.deleteIdHandlers, h)
p.mu.Unlock()
}
}
func (p *Display) RemoveDeleteIdHandler(h DisplayDeleteIdHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.deleteIdHandlers {
if e == h {
p.deleteIdHandlers = append(p.deleteIdHandlers[:i], p.deleteIdHandlers[i+1:]...)
break
}
}
}
func (p *Display) Dispatch(ctx context.Context, event *Event) {
switch event.Opcode {
case 0:
if len(p.errorHandlers) > 0 {
ev := DisplayErrorEvent{}
ev.EventContext = ctx
ev.ObjectId = event.Proxy(p.Context())
ev.Code = event.Uint32()
ev.Message = event.String()
p.mu.RLock()
for _, h := range p.errorHandlers {
h.HandleDisplayError(ev)
}
p.mu.RUnlock()
}
case 1:
if len(p.deleteIdHandlers) > 0 {
ev := DisplayDeleteIdEvent{}
ev.EventContext = ctx
ev.Id = event.Uint32()
p.mu.RLock()
for _, h := range p.deleteIdHandlers {
h.HandleDisplayDeleteId(ev)
}
p.mu.RUnlock()
}
}
}
type Display struct {
BaseProxy
mu sync.RWMutex
errorHandlers []DisplayErrorHandler
deleteIdHandlers []DisplayDeleteIdHandler
}
func NewDisplay(ctx *Context) *Display {
ret := new(Display)
ctx.Register(ret)
return ret
}
// Sync will asynchronous roundtrip.
//
//
// The sync request asks the server to emit the 'done' event
// on the returned wl_callback object. Since requests are
// handled in-order and events are delivered in-order, this can
// be used as a barrier to ensure all previous requests and the
// resulting events have been handled.
//
// The object returned by this request will be destroyed by the
// compositor after the callback is fired and as such the client must not
// attempt to use it after that point.
//
// The callback_data passed in the callback is the event serial.
//
func (p *Display) Sync() (*Callback, error) {
ret := NewCallback(p.Context())
return ret, p.Context().SendRequest(p, 0, Proxy(ret))
}
// GetRegistry will get global registry object.
//
//
// This request creates a registry object that allows the client
// to list and bind the global objects available from the
// compositor.
//
// It should be noted that the server side resources consumed in
// response to a get_registry request can only be released when the
// client disconnects, not when the client side proxy is destroyed.
// Therefore, clients should invoke get_registry as infrequently as
// possible to avoid wasting memory.
//
func (p *Display) GetRegistry() (*Registry, error) {
ret := NewRegistry(p.Context())
return ret, p.Context().SendRequest(p, 1, Proxy(ret))
}
const (
DisplayErrorInvalidObject = 0
DisplayErrorInvalidMethod = 1
DisplayErrorNoMemory = 2
)
type RegistryGlobalEvent struct {
EventContext context.Context
Name uint32
Interface string
Version uint32
}
type RegistryGlobalHandler interface {
HandleRegistryGlobal(RegistryGlobalEvent)
}
func (p *Registry) AddGlobalHandler(h RegistryGlobalHandler) {
if h != nil {
p.mu.Lock()
p.globalHandlers = append(p.globalHandlers, h)
p.mu.Unlock()
}
}
func (p *Registry) RemoveGlobalHandler(h RegistryGlobalHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.globalHandlers {
if e == h {
p.globalHandlers = append(p.globalHandlers[:i], p.globalHandlers[i+1:]...)
break
}
}
}
type RegistryGlobalRemoveEvent struct {
EventContext context.Context
Name uint32
}
type RegistryGlobalRemoveHandler interface {
HandleRegistryGlobalRemove(RegistryGlobalRemoveEvent)
}
func (p *Registry) AddGlobalRemoveHandler(h RegistryGlobalRemoveHandler) {
if h != nil {
p.mu.Lock()
p.globalRemoveHandlers = append(p.globalRemoveHandlers, h)
p.mu.Unlock()
}
}
func (p *Registry) RemoveGlobalRemoveHandler(h RegistryGlobalRemoveHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.globalRemoveHandlers {
if e == h {
p.globalRemoveHandlers = append(p.globalRemoveHandlers[:i], p.globalRemoveHandlers[i+1:]...)
break
}
}
}
func (p *Registry) Dispatch(ctx context.Context, event *Event) {
switch event.Opcode {
case 0:
if len(p.globalHandlers) > 0 {
ev := RegistryGlobalEvent{}
ev.EventContext = ctx
ev.Name = event.Uint32()
ev.Interface = event.String()
ev.Version = event.Uint32()
p.mu.RLock()
for _, h := range p.globalHandlers {
h.HandleRegistryGlobal(ev)
}
p.mu.RUnlock()
}
case 1:
if len(p.globalRemoveHandlers) > 0 {
ev := RegistryGlobalRemoveEvent{}
ev.EventContext = ctx
ev.Name = event.Uint32()
p.mu.RLock()
for _, h := range p.globalRemoveHandlers {
h.HandleRegistryGlobalRemove(ev)
}
p.mu.RUnlock()
}
}
}
type Registry struct {
BaseProxy
mu sync.RWMutex
globalHandlers []RegistryGlobalHandler
globalRemoveHandlers []RegistryGlobalRemoveHandler
}
func NewRegistry(ctx *Context) *Registry {
ret := new(Registry)
ctx.Register(ret)
return ret
}
// Bind will bind an object to the display.
//
//
// Binds a new, client-created object to the server using the
// specified name as the identifier.
//
func (p *Registry) Bind(name uint32, iface string, version uint32, id Proxy) error {
return p.Context().SendRequest(p, 0, name, iface, version, id)
}
type CallbackDoneEvent struct {
EventContext context.Context
CallbackData uint32
}
type CallbackDoneHandler interface {
HandleCallbackDone(CallbackDoneEvent)
}
func (p *Callback) AddDoneHandler(h CallbackDoneHandler) {
if h != nil {
p.mu.Lock()
p.doneHandlers = append(p.doneHandlers, h)
p.mu.Unlock()
}
}
func (p *Callback) RemoveDoneHandler(h CallbackDoneHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.doneHandlers {
if e == h {
p.doneHandlers = append(p.doneHandlers[:i], p.doneHandlers[i+1:]...)
break
}
}
}
func (p *Callback) Dispatch(ctx context.Context, event *Event) {
switch event.Opcode {
case 0:
if len(p.doneHandlers) > 0 {
ev := CallbackDoneEvent{}
ev.EventContext = ctx
ev.CallbackData = event.Uint32()
p.mu.RLock()
for _, h := range p.doneHandlers {
h.HandleCallbackDone(ev)
}
p.mu.RUnlock()
}
}
}
type Callback struct {
BaseProxy
mu sync.RWMutex
doneHandlers []CallbackDoneHandler
}
func NewCallback(ctx *Context) *Callback {
ret := new(Callback)
ctx.Register(ret)
return ret
}
type Compositor struct {
BaseProxy
}
func NewCompositor(ctx *Context) *Compositor {
ret := new(Compositor)
ctx.Register(ret)
return ret
}
// CreateSurface will create new surface.
//
//
// Ask the compositor to create a new surface.
//
func (p *Compositor) CreateSurface() (*Surface, error) {
ret := NewSurface(p.Context())
return ret, p.Context().SendRequest(p, 0, Proxy(ret))
}
// CreateRegion will create new region.
//
//
// Ask the compositor to create a new region.
//
func (p *Compositor) CreateRegion() (*Region, error) {
ret := NewRegion(p.Context())
return ret, p.Context().SendRequest(p, 1, Proxy(ret))
}
type ShmPool struct {
BaseProxy
}
func NewShmPool(ctx *Context) *ShmPool {
ret := new(ShmPool)
ctx.Register(ret)
return ret
}
// CreateBuffer will create a buffer from the pool.
//
//
// Create a wl_buffer object from the pool.
//
// The buffer is created offset bytes into the pool and has
// width and height as specified. The stride argument specifies
// the number of bytes from the beginning of one row to the beginning
// of the next. The format is the pixel format of the buffer and
// must be one of those advertised through the wl_shm.format event.
//
// A buffer will keep a reference to the pool it was created from
// so it is valid to destroy the pool immediately after creating
// a buffer from it.
//
func (p *ShmPool) CreateBuffer(offset int32, width int32, height int32, stride int32, format uint32) (*Buffer, error) {
ret := NewBuffer(p.Context())
return ret, p.Context().SendRequest(p, 0, Proxy(ret), offset, width, height, stride, format)
}
// Destroy will destroy the pool.
//
//
// Destroy the shared memory pool.
//
// The mmapped memory will be released when all
// buffers that have been created from this pool
// are gone.
//
func (p *ShmPool) Destroy() error {
return p.Context().SendRequest(p, 1)
}
// Resize will change the size of the pool mapping.
//
//
// This request will cause the server to remap the backing memory
// for the pool from the file descriptor passed when the pool was
// created, but using the new size. This request can only be
// used to make the pool bigger.
//
func (p *ShmPool) Resize(size int32) error {
return p.Context().SendRequest(p, 2, size)
}
type ShmFormatEvent struct {
EventContext context.Context
Format uint32
}
type ShmFormatHandler interface {
HandleShmFormat(ShmFormatEvent)
}
func (p *Shm) AddFormatHandler(h ShmFormatHandler) {
if h != nil {
p.mu.Lock()
p.formatHandlers = append(p.formatHandlers, h)
p.mu.Unlock()
}
}
func (p *Shm) RemoveFormatHandler(h ShmFormatHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.formatHandlers {
if e == h {
p.formatHandlers = append(p.formatHandlers[:i], p.formatHandlers[i+1:]...)
break
}
}
}
func (p *Shm) Dispatch(ctx context.Context, event *Event) {
switch event.Opcode {
case 0:
if len(p.formatHandlers) > 0 {
ev := ShmFormatEvent{}
ev.EventContext = ctx
ev.Format = event.Uint32()
p.mu.RLock()
for _, h := range p.formatHandlers {
h.HandleShmFormat(ev)
}
p.mu.RUnlock()
}
}
}
type Shm struct {
BaseProxy
mu sync.RWMutex
formatHandlers []ShmFormatHandler
}
func NewShm(ctx *Context) *Shm {
ret := new(Shm)
ctx.Register(ret)
return ret
}
// CreatePool will create a shm pool.
//
//
// Create a new wl_shm_pool object.
//
// The pool can be used to create shared memory based buffer
// objects. The server will mmap size bytes of the passed file
// descriptor, to use as backing memory for the pool.
//
func (p *Shm) CreatePool(fd uintptr, size int32) (*ShmPool, error) {
ret := NewShmPool(p.Context())
return ret, p.Context().SendRequest(p, 0, Proxy(ret), fd, size)
}
const (
ShmErrorInvalidFormat = 0
ShmErrorInvalidStride = 1
ShmErrorInvalidFd = 2
)
const (
ShmFormatArgb8888 = 0
ShmFormatXrgb8888 = 1
ShmFormatC8 = 0x20203843
ShmFormatRgb332 = 0x38424752
ShmFormatBgr233 = 0x38524742
ShmFormatXrgb4444 = 0x32315258
ShmFormatXbgr4444 = 0x32314258
ShmFormatRgbx4444 = 0x32315852
ShmFormatBgrx4444 = 0x32315842
ShmFormatArgb4444 = 0x32315241
ShmFormatAbgr4444 = 0x32314241
ShmFormatRgba4444 = 0x32314152
ShmFormatBgra4444 = 0x32314142
ShmFormatXrgb1555 = 0x35315258
ShmFormatXbgr1555 = 0x35314258
ShmFormatRgbx5551 = 0x35315852
ShmFormatBgrx5551 = 0x35315842
ShmFormatArgb1555 = 0x35315241
ShmFormatAbgr1555 = 0x35314241
ShmFormatRgba5551 = 0x35314152
ShmFormatBgra5551 = 0x35314142
ShmFormatRgb565 = 0x36314752
ShmFormatBgr565 = 0x36314742
ShmFormatRgb888 = 0x34324752
ShmFormatBgr888 = 0x34324742
ShmFormatXbgr8888 = 0x34324258
ShmFormatRgbx8888 = 0x34325852
ShmFormatBgrx8888 = 0x34325842
ShmFormatAbgr8888 = 0x34324241
ShmFormatRgba8888 = 0x34324152
ShmFormatBgra8888 = 0x34324142
ShmFormatXrgb2101010 = 0x30335258
ShmFormatXbgr2101010 = 0x30334258
ShmFormatRgbx1010102 = 0x30335852
ShmFormatBgrx1010102 = 0x30335842
ShmFormatArgb2101010 = 0x30335241
ShmFormatAbgr2101010 = 0x30334241
ShmFormatRgba1010102 = 0x30334152
ShmFormatBgra1010102 = 0x30334142
ShmFormatYuyv = 0x56595559
ShmFormatYvyu = 0x55595659
ShmFormatUyvy = 0x59565955
ShmFormatVyuy = 0x59555956
ShmFormatAyuv = 0x56555941
ShmFormatNv12 = 0x3231564e
ShmFormatNv21 = 0x3132564e
ShmFormatNv16 = 0x3631564e
ShmFormatNv61 = 0x3136564e
ShmFormatYuv410 = 0x39565559
ShmFormatYvu410 = 0x39555659
ShmFormatYuv411 = 0x31315559
ShmFormatYvu411 = 0x31315659
ShmFormatYuv420 = 0x32315559
ShmFormatYvu420 = 0x32315659
ShmFormatYuv422 = 0x36315559
ShmFormatYvu422 = 0x36315659
ShmFormatYuv444 = 0x34325559
ShmFormatYvu444 = 0x34325659
)
type BufferReleaseEvent struct {
EventContext context.Context
}
type BufferReleaseHandler interface {
HandleBufferRelease(BufferReleaseEvent)
}
func (p *Buffer) AddReleaseHandler(h BufferReleaseHandler) {
if h != nil {
p.mu.Lock()
p.releaseHandlers = append(p.releaseHandlers, h)
p.mu.Unlock()
}
}
func (p *Buffer) RemoveReleaseHandler(h BufferReleaseHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.releaseHandlers {
if e == h {
p.releaseHandlers = append(p.releaseHandlers[:i], p.releaseHandlers[i+1:]...)
break
}
}
}
func (p *Buffer) Dispatch(ctx context.Context, event *Event) {
switch event.Opcode {
case 0:
if len(p.releaseHandlers) > 0 {
ev := BufferReleaseEvent{}
ev.EventContext = ctx
p.mu.RLock()
for _, h := range p.releaseHandlers {
h.HandleBufferRelease(ev)
}
p.mu.RUnlock()
}
}
}
type Buffer struct {
BaseProxy
mu sync.RWMutex
releaseHandlers []BufferReleaseHandler
}
func NewBuffer(ctx *Context) *Buffer {
ret := new(Buffer)
ctx.Register(ret)
return ret
}
// Destroy will destroy a buffer.
//
//
// Destroy a buffer. If and how you need to release the backing
// storage is defined by the buffer factory interface.
//
// For possible side-effects to a surface, see wl_surface.attach.
//
func (p *Buffer) Destroy() error {
return p.Context().SendRequest(p, 0)
}
type DataOfferOfferEvent struct {
EventContext context.Context
MimeType string
}
type DataOfferOfferHandler interface {
HandleDataOfferOffer(DataOfferOfferEvent)
}
func (p *DataOffer) AddOfferHandler(h DataOfferOfferHandler) {
if h != nil {
p.mu.Lock()
p.offerHandlers = append(p.offerHandlers, h)
p.mu.Unlock()
}
}
func (p *DataOffer) RemoveOfferHandler(h DataOfferOfferHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.offerHandlers {
if e == h {
p.offerHandlers = append(p.offerHandlers[:i], p.offerHandlers[i+1:]...)
break
}
}
}
type DataOfferSourceActionsEvent struct {
EventContext context.Context
SourceActions uint32
}
type DataOfferSourceActionsHandler interface {
HandleDataOfferSourceActions(DataOfferSourceActionsEvent)
}
func (p *DataOffer) AddSourceActionsHandler(h DataOfferSourceActionsHandler) {
if h != nil {
p.mu.Lock()
p.sourceActionsHandlers = append(p.sourceActionsHandlers, h)
p.mu.Unlock()
}
}
func (p *DataOffer) RemoveSourceActionsHandler(h DataOfferSourceActionsHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.sourceActionsHandlers {
if e == h {
p.sourceActionsHandlers = append(p.sourceActionsHandlers[:i], p.sourceActionsHandlers[i+1:]...)
break
}
}
}
type DataOfferActionEvent struct {
EventContext context.Context
DndAction uint32
}
type DataOfferActionHandler interface {
HandleDataOfferAction(DataOfferActionEvent)
}
func (p *DataOffer) AddActionHandler(h DataOfferActionHandler) {
if h != nil {
p.mu.Lock()
p.actionHandlers = append(p.actionHandlers, h)
p.mu.Unlock()
}
}
func (p *DataOffer) RemoveActionHandler(h DataOfferActionHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.actionHandlers {
if e == h {
p.actionHandlers = append(p.actionHandlers[:i], p.actionHandlers[i+1:]...)
break
}
}
}
func (p *DataOffer) Dispatch(ctx context.Context, event *Event) {
switch event.Opcode {
case 0:
if len(p.offerHandlers) > 0 {
ev := DataOfferOfferEvent{}
ev.EventContext = ctx
ev.MimeType = event.String()
p.mu.RLock()
for _, h := range p.offerHandlers {
h.HandleDataOfferOffer(ev)
}
p.mu.RUnlock()
}
case 1:
if len(p.sourceActionsHandlers) > 0 {
ev := DataOfferSourceActionsEvent{}
ev.EventContext = ctx
ev.SourceActions = event.Uint32()
p.mu.RLock()
for _, h := range p.sourceActionsHandlers {
h.HandleDataOfferSourceActions(ev)
}
p.mu.RUnlock()
}
case 2:
if len(p.actionHandlers) > 0 {
ev := DataOfferActionEvent{}
ev.EventContext = ctx
ev.DndAction = event.Uint32()
p.mu.RLock()
for _, h := range p.actionHandlers {
h.HandleDataOfferAction(ev)
}
p.mu.RUnlock()
}
}
}
type DataOffer struct {
BaseProxy
mu sync.RWMutex
offerHandlers []DataOfferOfferHandler
sourceActionsHandlers []DataOfferSourceActionsHandler
actionHandlers []DataOfferActionHandler
}
func NewDataOffer(ctx *Context) *DataOffer {
ret := new(DataOffer)
ctx.Register(ret)
return ret
}
// Accept will accept one of the offered mime types.
//
//
// Indicate that the client can accept the given mime type, or
// NULL for not accepted.
//
// For objects of version 2 or older, this request is used by the
// client to give feedback whether the client can receive the given
// mime type, or NULL if none is accepted; the feedback does not
// determine whether the drag-and-drop operation succeeds or not.
//
// For objects of version 3 or newer, this request determines the
// final result of the drag-and-drop operation. If the end result
// is that no mime types were accepted, the drag-and-drop operation
// will be cancelled and the corresponding drag source will receive
// wl_data_source.cancelled. Clients may still use this event in
// conjunction with wl_data_source.action for feedback.
//
func (p *DataOffer) Accept(serial uint32, mime_type string) error {
return p.Context().SendRequest(p, 0, serial, mime_type)
}
// Receive will request that the data is transferred.
//
//
// To transfer the offered data, the client issues this request
// and indicates the mime type it wants to receive. The transfer
// happens through the passed file descriptor (typically created
// with the pipe system call). The source client writes the data
// in the mime type representation requested and then closes the
// file descriptor.
//
// The receiving client reads from the read end of the pipe until
// EOF and then closes its end, at which point the transfer is
// complete.
//
// This request may happen multiple times for different mime types,
// both before and after wl_data_device.drop. Drag-and-drop destination
// clients may preemptively fetch data or examine it more closely to
// determine acceptance.
//
func (p *DataOffer) Receive(mime_type string, fd uintptr) error {
return p.Context().SendRequest(p, 1, mime_type, fd)
}
// Destroy will destroy data offer.
//
//
// Destroy the data offer.
//
func (p *DataOffer) Destroy() error {
return p.Context().SendRequest(p, 2)
}
// Finish will the offer will no longer be used.
//
//
// Notifies the compositor that the drag destination successfully
// finished the drag-and-drop operation.
//
// Upon receiving this request, the compositor will emit
// wl_data_source.dnd_finished on the drag source client.
//
// It is a client error to perform other requests than
// wl_data_offer.destroy after this one. It is also an error to perform
// this request after a NULL mime type has been set in
// wl_data_offer.accept or no action was received through
// wl_data_offer.action.
//
func (p *DataOffer) Finish() error {
return p.Context().SendRequest(p, 3)
}
// SetActions will set the available/preferred drag-and-drop actions.
//
//
// Sets the actions that the destination side client supports for
// this operation. This request may trigger the emission of
// wl_data_source.action and wl_data_offer.action events if the compositor
// needs to change the selected action.
//
// This request can be called multiple times throughout the
// drag-and-drop operation, typically in response to wl_data_device.enter
// or wl_data_device.motion events.
//
// This request determines the final result of the drag-and-drop
// operation. If the end result is that no action is accepted,
// the drag source will receive wl_drag_source.cancelled.
//
// The dnd_actions argument must contain only values expressed in the
// wl_data_device_manager.dnd_actions enum, and the preferred_action
// argument must only contain one of those values set, otherwise it
// will result in a protocol error.
//
// While managing an "ask" action, the destination drag-and-drop client
// may perform further wl_data_offer.receive requests, and is expected
// to perform one last wl_data_offer.set_actions request with a preferred
// action other than "ask" (and optionally wl_data_offer.accept) before
// requesting wl_data_offer.finish, in order to convey the action selected
// by the user. If the preferred action is not in the
// wl_data_offer.source_actions mask, an error will be raised.
//
// If the "ask" action is dismissed (e.g. user cancellation), the client
// is expected to perform wl_data_offer.destroy right away.
//
// This request can only be made on drag-and-drop offers, a protocol error
// will be raised otherwise.
//
func (p *DataOffer) SetActions(dnd_actions uint32, preferred_action uint32) error {
return p.Context().SendRequest(p, 4, dnd_actions, preferred_action)
}
const (
DataOfferErrorInvalidFinish = 0
DataOfferErrorInvalidActionMask = 1
DataOfferErrorInvalidAction = 2
DataOfferErrorInvalidOffer = 3
)
type DataSourceTargetEvent struct {
EventContext context.Context
MimeType string
}
type DataSourceTargetHandler interface {
HandleDataSourceTarget(DataSourceTargetEvent)
}
func (p *DataSource) AddTargetHandler(h DataSourceTargetHandler) {
if h != nil {
p.mu.Lock()
p.targetHandlers = append(p.targetHandlers, h)
p.mu.Unlock()
}
}
func (p *DataSource) RemoveTargetHandler(h DataSourceTargetHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.targetHandlers {
if e == h {
p.targetHandlers = append(p.targetHandlers[:i], p.targetHandlers[i+1:]...)
break
}
}
}
type DataSourceSendEvent struct {
EventContext context.Context
MimeType string
Fd uintptr
}
type DataSourceSendHandler interface {
HandleDataSourceSend(DataSourceSendEvent)
}
func (p *DataSource) AddSendHandler(h DataSourceSendHandler) {
if h != nil {
p.mu.Lock()
p.sendHandlers = append(p.sendHandlers, h)
p.mu.Unlock()
}
}
func (p *DataSource) RemoveSendHandler(h DataSourceSendHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.sendHandlers {
if e == h {
p.sendHandlers = append(p.sendHandlers[:i], p.sendHandlers[i+1:]...)
break
}
}
}
type DataSourceCancelledEvent struct {
EventContext context.Context
}
type DataSourceCancelledHandler interface {
HandleDataSourceCancelled(DataSourceCancelledEvent)
}
func (p *DataSource) AddCancelledHandler(h DataSourceCancelledHandler) {
if h != nil {
p.mu.Lock()
p.cancelledHandlers = append(p.cancelledHandlers, h)
p.mu.Unlock()
}
}
func (p *DataSource) RemoveCancelledHandler(h DataSourceCancelledHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.cancelledHandlers {
if e == h {
p.cancelledHandlers = append(p.cancelledHandlers[:i], p.cancelledHandlers[i+1:]...)
break
}
}
}
type DataSourceDndDropPerformedEvent struct {
EventContext context.Context
}
type DataSourceDndDropPerformedHandler interface {
HandleDataSourceDndDropPerformed(DataSourceDndDropPerformedEvent)
}
func (p *DataSource) AddDndDropPerformedHandler(h DataSourceDndDropPerformedHandler) {
if h != nil {
p.mu.Lock()
p.dndDropPerformedHandlers = append(p.dndDropPerformedHandlers, h)
p.mu.Unlock()
}
}
func (p *DataSource) RemoveDndDropPerformedHandler(h DataSourceDndDropPerformedHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.dndDropPerformedHandlers {
if e == h {
p.dndDropPerformedHandlers = append(p.dndDropPerformedHandlers[:i], p.dndDropPerformedHandlers[i+1:]...)
break
}
}
}
type DataSourceDndFinishedEvent struct {
EventContext context.Context
}
type DataSourceDndFinishedHandler interface {
HandleDataSourceDndFinished(DataSourceDndFinishedEvent)
}
func (p *DataSource) AddDndFinishedHandler(h DataSourceDndFinishedHandler) {
if h != nil {
p.mu.Lock()
p.dndFinishedHandlers = append(p.dndFinishedHandlers, h)
p.mu.Unlock()
}
}
func (p *DataSource) RemoveDndFinishedHandler(h DataSourceDndFinishedHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.dndFinishedHandlers {
if e == h {
p.dndFinishedHandlers = append(p.dndFinishedHandlers[:i], p.dndFinishedHandlers[i+1:]...)
break
}
}
}
type DataSourceActionEvent struct {
EventContext context.Context
DndAction uint32
}
type DataSourceActionHandler interface {
HandleDataSourceAction(DataSourceActionEvent)
}
func (p *DataSource) AddActionHandler(h DataSourceActionHandler) {
if h != nil {
p.mu.Lock()
p.actionHandlers = append(p.actionHandlers, h)
p.mu.Unlock()
}
}
func (p *DataSource) RemoveActionHandler(h DataSourceActionHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.actionHandlers {
if e == h {
p.actionHandlers = append(p.actionHandlers[:i], p.actionHandlers[i+1:]...)
break
}
}
}
func (p *DataSource) Dispatch(ctx context.Context, event *Event) {
switch event.Opcode {
case 0:
if len(p.targetHandlers) > 0 {
ev := DataSourceTargetEvent{}
ev.EventContext = ctx
ev.MimeType = event.String()
p.mu.RLock()
for _, h := range p.targetHandlers {
h.HandleDataSourceTarget(ev)
}
p.mu.RUnlock()
}
case 1:
if len(p.sendHandlers) > 0 {
ev := DataSourceSendEvent{}
ev.EventContext = ctx
ev.MimeType = event.String()
ev.Fd = event.FD()
p.mu.RLock()
for _, h := range p.sendHandlers {
h.HandleDataSourceSend(ev)
}
p.mu.RUnlock()
}
case 2:
if len(p.cancelledHandlers) > 0 {
ev := DataSourceCancelledEvent{}
ev.EventContext = ctx
p.mu.RLock()
for _, h := range p.cancelledHandlers {
h.HandleDataSourceCancelled(ev)
}
p.mu.RUnlock()
}
case 3:
if len(p.dndDropPerformedHandlers) > 0 {
ev := DataSourceDndDropPerformedEvent{}
ev.EventContext = ctx
p.mu.RLock()
for _, h := range p.dndDropPerformedHandlers {
h.HandleDataSourceDndDropPerformed(ev)
}
p.mu.RUnlock()
}
case 4:
if len(p.dndFinishedHandlers) > 0 {
ev := DataSourceDndFinishedEvent{}
ev.EventContext = ctx
p.mu.RLock()
for _, h := range p.dndFinishedHandlers {
h.HandleDataSourceDndFinished(ev)
}
p.mu.RUnlock()
}
case 5:
if len(p.actionHandlers) > 0 {
ev := DataSourceActionEvent{}
ev.EventContext = ctx
ev.DndAction = event.Uint32()
p.mu.RLock()
for _, h := range p.actionHandlers {
h.HandleDataSourceAction(ev)
}
p.mu.RUnlock()
}
}
}
type DataSource struct {
BaseProxy
mu sync.RWMutex
targetHandlers []DataSourceTargetHandler
sendHandlers []DataSourceSendHandler
cancelledHandlers []DataSourceCancelledHandler
dndDropPerformedHandlers []DataSourceDndDropPerformedHandler
dndFinishedHandlers []DataSourceDndFinishedHandler
actionHandlers []DataSourceActionHandler
}
func NewDataSource(ctx *Context) *DataSource {
ret := new(DataSource)
ctx.Register(ret)
return ret
}
// Offer will add an offered mime type.
//
//
// This request adds a mime type to the set of mime types
// advertised to targets. Can be called several times to offer
// multiple types.
//
func (p *DataSource) Offer(mime_type string) error {
return p.Context().SendRequest(p, 0, mime_type)
}
// Destroy will destroy the data source.
//
//
// Destroy the data source.
//
func (p *DataSource) Destroy() error {
return p.Context().SendRequest(p, 1)
}
// SetActions will set the available drag-and-drop actions.
//
//
// Sets the actions that the source side client supports for this
// operation. This request may trigger wl_data_source.action and
// wl_data_offer.action events if the compositor needs to change the
// selected action.
//
// The dnd_actions argument must contain only values expressed in the
// wl_data_device_manager.dnd_actions enum, otherwise it will result
// in a protocol error.
//
// This request must be made once only, and can only be made on sources
// used in drag-and-drop, so it must be performed before
// wl_data_device.start_drag. Attempting to use the source other than
// for drag-and-drop will raise a protocol error.
//
func (p *DataSource) SetActions(dnd_actions uint32) error {
return p.Context().SendRequest(p, 2, dnd_actions)
}
const (
DataSourceErrorInvalidActionMask = 0
DataSourceErrorInvalidSource = 1
)
type DataDeviceDataOfferEvent struct {
EventContext context.Context
Id *DataOffer
}
type DataDeviceDataOfferHandler interface {
HandleDataDeviceDataOffer(DataDeviceDataOfferEvent)
}
func (p *DataDevice) AddDataOfferHandler(h DataDeviceDataOfferHandler) {
if h != nil {
p.mu.Lock()
p.dataOfferHandlers = append(p.dataOfferHandlers, h)
p.mu.Unlock()
}
}
func (p *DataDevice) RemoveDataOfferHandler(h DataDeviceDataOfferHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.dataOfferHandlers {
if e == h {
p.dataOfferHandlers = append(p.dataOfferHandlers[:i], p.dataOfferHandlers[i+1:]...)
break
}
}
}
type DataDeviceEnterEvent struct {
EventContext context.Context
Serial uint32
Surface *Surface
X float32
Y float32
Id *DataOffer
}
type DataDeviceEnterHandler interface {
HandleDataDeviceEnter(DataDeviceEnterEvent)
}
func (p *DataDevice) AddEnterHandler(h DataDeviceEnterHandler) {
if h != nil {
p.mu.Lock()
p.enterHandlers = append(p.enterHandlers, h)
p.mu.Unlock()
}
}
func (p *DataDevice) RemoveEnterHandler(h DataDeviceEnterHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.enterHandlers {
if e == h {
p.enterHandlers = append(p.enterHandlers[:i], p.enterHandlers[i+1:]...)
break
}
}
}
type DataDeviceLeaveEvent struct {
EventContext context.Context
}
type DataDeviceLeaveHandler interface {
HandleDataDeviceLeave(DataDeviceLeaveEvent)
}
func (p *DataDevice) AddLeaveHandler(h DataDeviceLeaveHandler) {
if h != nil {
p.mu.Lock()
p.leaveHandlers = append(p.leaveHandlers, h)
p.mu.Unlock()
}
}
func (p *DataDevice) RemoveLeaveHandler(h DataDeviceLeaveHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.leaveHandlers {
if e == h {
p.leaveHandlers = append(p.leaveHandlers[:i], p.leaveHandlers[i+1:]...)
break
}
}
}
type DataDeviceMotionEvent struct {
EventContext context.Context
Time uint32
X float32
Y float32
}
type DataDeviceMotionHandler interface {
HandleDataDeviceMotion(DataDeviceMotionEvent)
}
func (p *DataDevice) AddMotionHandler(h DataDeviceMotionHandler) {
if h != nil {
p.mu.Lock()
p.motionHandlers = append(p.motionHandlers, h)
p.mu.Unlock()
}
}
func (p *DataDevice) RemoveMotionHandler(h DataDeviceMotionHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.motionHandlers {
if e == h {
p.motionHandlers = append(p.motionHandlers[:i], p.motionHandlers[i+1:]...)
break
}
}
}
type DataDeviceDropEvent struct {
EventContext context.Context
}
type DataDeviceDropHandler interface {
HandleDataDeviceDrop(DataDeviceDropEvent)
}
func (p *DataDevice) AddDropHandler(h DataDeviceDropHandler) {
if h != nil {
p.mu.Lock()
p.dropHandlers = append(p.dropHandlers, h)
p.mu.Unlock()
}
}
func (p *DataDevice) RemoveDropHandler(h DataDeviceDropHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.dropHandlers {
if e == h {
p.dropHandlers = append(p.dropHandlers[:i], p.dropHandlers[i+1:]...)
break
}
}
}
type DataDeviceSelectionEvent struct {
EventContext context.Context
Id *DataOffer
}
type DataDeviceSelectionHandler interface {
HandleDataDeviceSelection(DataDeviceSelectionEvent)
}
func (p *DataDevice) AddSelectionHandler(h DataDeviceSelectionHandler) {
if h != nil {
p.mu.Lock()
p.selectionHandlers = append(p.selectionHandlers, h)
p.mu.Unlock()
}
}
func (p *DataDevice) RemoveSelectionHandler(h DataDeviceSelectionHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.selectionHandlers {
if e == h {
p.selectionHandlers = append(p.selectionHandlers[:i], p.selectionHandlers[i+1:]...)
break
}
}
}
func (p *DataDevice) Dispatch(ctx context.Context, event *Event) {
switch event.Opcode {
case 0:
if len(p.dataOfferHandlers) > 0 {
ev := DataDeviceDataOfferEvent{}
ev.EventContext = ctx
ev.Id = event.Proxy(p.Context()).(*DataOffer)
p.mu.RLock()
for _, h := range p.dataOfferHandlers {
h.HandleDataDeviceDataOffer(ev)
}
p.mu.RUnlock()
}
case 1:
if len(p.enterHandlers) > 0 {
ev := DataDeviceEnterEvent{}
ev.EventContext = ctx
ev.Serial = event.Uint32()
ev.Surface = event.Proxy(p.Context()).(*Surface)
ev.X = event.Float32()
ev.Y = event.Float32()
ev.Id = event.Proxy(p.Context()).(*DataOffer)
p.mu.RLock()
for _, h := range p.enterHandlers {
h.HandleDataDeviceEnter(ev)
}
p.mu.RUnlock()
}
case 2:
if len(p.leaveHandlers) > 0 {
ev := DataDeviceLeaveEvent{}
ev.EventContext = ctx
p.mu.RLock()
for _, h := range p.leaveHandlers {
h.HandleDataDeviceLeave(ev)
}
p.mu.RUnlock()
}
case 3:
if len(p.motionHandlers) > 0 {
ev := DataDeviceMotionEvent{}
ev.EventContext = ctx
ev.Time = event.Uint32()
ev.X = event.Float32()
ev.Y = event.Float32()
p.mu.RLock()
for _, h := range p.motionHandlers {
h.HandleDataDeviceMotion(ev)
}
p.mu.RUnlock()
}
case 4:
if len(p.dropHandlers) > 0 {
ev := DataDeviceDropEvent{}
ev.EventContext = ctx
p.mu.RLock()
for _, h := range p.dropHandlers {
h.HandleDataDeviceDrop(ev)
}
p.mu.RUnlock()
}
case 5:
if len(p.selectionHandlers) > 0 {
ev := DataDeviceSelectionEvent{}
ev.EventContext = ctx
ev.Id = event.Proxy(p.Context()).(*DataOffer)
p.mu.RLock()
for _, h := range p.selectionHandlers {
h.HandleDataDeviceSelection(ev)
}
p.mu.RUnlock()
}
}
}
type DataDevice struct {
BaseProxy
mu sync.RWMutex
dataOfferHandlers []DataDeviceDataOfferHandler
enterHandlers []DataDeviceEnterHandler
leaveHandlers []DataDeviceLeaveHandler
motionHandlers []DataDeviceMotionHandler
dropHandlers []DataDeviceDropHandler
selectionHandlers []DataDeviceSelectionHandler
}
func NewDataDevice(ctx *Context) *DataDevice {
ret := new(DataDevice)
ctx.Register(ret)
return ret
}
// StartDrag will start drag-and-drop operation.
//
//
// This request asks the compositor to start a drag-and-drop
// operation on behalf of the client.
//
// The source argument is the data source that provides the data
// for the eventual data transfer. If source is NULL, enter, leave
// and motion events are sent only to the client that initiated the
// drag and the client is expected to handle the data passing
// internally.
//
// The origin surface is the surface where the drag originates and
// the client must have an active implicit grab that matches the
// serial.
//
// The icon surface is an optional (can be NULL) surface that
// provides an icon to be moved around with the cursor. Initially,
// the top-left corner of the icon surface is placed at the cursor
// hotspot, but subsequent wl_surface.attach request can move the
// relative position. Attach requests must be confirmed with
// wl_surface.commit as usual. The icon surface is given the role of
// a drag-and-drop icon. If the icon surface already has another role,
// it raises a protocol error.
//
// The current and pending input regions of the icon wl_surface are
// cleared, and wl_surface.set_input_region is ignored until the
// wl_surface is no longer used as the icon surface. When the use
// as an icon ends, the current and pending input regions become
// undefined, and the wl_surface is unmapped.
//
func (p *DataDevice) StartDrag(source *DataSource, origin *Surface, icon *Surface, serial uint32) error {
return p.Context().SendRequest(p, 0, source, origin, icon, serial)
}
// SetSelection will copy data to the selection.
//
//
// This request asks the compositor to set the selection
// to the data from the source on behalf of the client.
//
// To unset the selection, set the source to NULL.
//
func (p *DataDevice) SetSelection(source *DataSource, serial uint32) error {
return p.Context().SendRequest(p, 1, source, serial)
}
// Release will destroy data device.
//
//
// This request destroys the data device.
//
func (p *DataDevice) Release() error {
return p.Context().SendRequest(p, 2)
}
const (
DataDeviceErrorRole = 0
)
type DataDeviceManager struct {
BaseProxy
}
func NewDataDeviceManager(ctx *Context) *DataDeviceManager {
ret := new(DataDeviceManager)
ctx.Register(ret)
return ret
}
// CreateDataSource will create a new data source.
//
//
// Create a new data source.
//
func (p *DataDeviceManager) CreateDataSource() (*DataSource, error) {
ret := NewDataSource(p.Context())
return ret, p.Context().SendRequest(p, 0, Proxy(ret))
}
// GetDataDevice will create a new data device.
//
//
// Create a new data device for a given seat.
//
func (p *DataDeviceManager) GetDataDevice(seat *Seat) (*DataDevice, error) {
ret := NewDataDevice(p.Context())
return ret, p.Context().SendRequest(p, 1, Proxy(ret), seat)
}
const (
DataDeviceManagerDndActionNone = 0
DataDeviceManagerDndActionCopy = 1
DataDeviceManagerDndActionMove = 2
DataDeviceManagerDndActionAsk = 4
)
type Shell struct {
BaseProxy
}
func NewShell(ctx *Context) *Shell {
ret := new(Shell)
ctx.Register(ret)
return ret
}
// GetShellSurface will create a shell surface from a surface.
//
//
// Create a shell surface for an existing surface. This gives
// the wl_surface the role of a shell surface. If the wl_surface
// already has another role, it raises a protocol error.
//
// Only one shell surface can be associated with a given surface.
//
func (p *Shell) GetShellSurface(surface *Surface) (*ShellSurface, error) {
ret := NewShellSurface(p.Context())
return ret, p.Context().SendRequest(p, 0, Proxy(ret), surface)
}
const (
ShellErrorRole = 0
)
type ShellSurfacePingEvent struct {
EventContext context.Context
Serial uint32
}
type ShellSurfacePingHandler interface {
HandleShellSurfacePing(ShellSurfacePingEvent)
}
func (p *ShellSurface) AddPingHandler(h ShellSurfacePingHandler) {
if h != nil {
p.mu.Lock()
p.pingHandlers = append(p.pingHandlers, h)
p.mu.Unlock()
}
}
func (p *ShellSurface) RemovePingHandler(h ShellSurfacePingHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.pingHandlers {
if e == h {
p.pingHandlers = append(p.pingHandlers[:i], p.pingHandlers[i+1:]...)
break
}
}
}
type ShellSurfaceConfigureEvent struct {
EventContext context.Context
Edges uint32
Width int32
Height int32
}
type ShellSurfaceConfigureHandler interface {
HandleShellSurfaceConfigure(ShellSurfaceConfigureEvent)
}
func (p *ShellSurface) AddConfigureHandler(h ShellSurfaceConfigureHandler) {
if h != nil {
p.mu.Lock()
p.configureHandlers = append(p.configureHandlers, h)
p.mu.Unlock()
}
}
func (p *ShellSurface) RemoveConfigureHandler(h ShellSurfaceConfigureHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.configureHandlers {
if e == h {
p.configureHandlers = append(p.configureHandlers[:i], p.configureHandlers[i+1:]...)
break
}
}
}
type ShellSurfacePopupDoneEvent struct {
EventContext context.Context
}
type ShellSurfacePopupDoneHandler interface {
HandleShellSurfacePopupDone(ShellSurfacePopupDoneEvent)
}
func (p *ShellSurface) AddPopupDoneHandler(h ShellSurfacePopupDoneHandler) {
if h != nil {
p.mu.Lock()
p.popupDoneHandlers = append(p.popupDoneHandlers, h)
p.mu.Unlock()
}
}
func (p *ShellSurface) RemovePopupDoneHandler(h ShellSurfacePopupDoneHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.popupDoneHandlers {
if e == h {
p.popupDoneHandlers = append(p.popupDoneHandlers[:i], p.popupDoneHandlers[i+1:]...)
break
}
}
}
func (p *ShellSurface) Dispatch(ctx context.Context, event *Event) {
switch event.Opcode {
case 0:
if len(p.pingHandlers) > 0 {
ev := ShellSurfacePingEvent{}
ev.EventContext = ctx
ev.Serial = event.Uint32()
p.mu.RLock()
for _, h := range p.pingHandlers {
h.HandleShellSurfacePing(ev)
}
p.mu.RUnlock()
}
case 1:
if len(p.configureHandlers) > 0 {
ev := ShellSurfaceConfigureEvent{}
ev.EventContext = ctx
ev.Edges = event.Uint32()
ev.Width = event.Int32()
ev.Height = event.Int32()
p.mu.RLock()
for _, h := range p.configureHandlers {
h.HandleShellSurfaceConfigure(ev)
}
p.mu.RUnlock()
}
case 2:
if len(p.popupDoneHandlers) > 0 {
ev := ShellSurfacePopupDoneEvent{}
ev.EventContext = ctx
p.mu.RLock()
for _, h := range p.popupDoneHandlers {
h.HandleShellSurfacePopupDone(ev)
}
p.mu.RUnlock()
}
}
}
type ShellSurface struct {
BaseProxy
mu sync.RWMutex
pingHandlers []ShellSurfacePingHandler
configureHandlers []ShellSurfaceConfigureHandler
popupDoneHandlers []ShellSurfacePopupDoneHandler
}
func NewShellSurface(ctx *Context) *ShellSurface {
ret := new(ShellSurface)
ctx.Register(ret)
return ret
}
// Pong will respond to a ping event.
//
//
// A client must respond to a ping event with a pong request or
// the client may be deemed unresponsive.
//
func (p *ShellSurface) Pong(serial uint32) error {
return p.Context().SendRequest(p, 0, serial)
}
// Move will start an interactive move.
//
//
// Start a pointer-driven move of the surface.
//
// This request must be used in response to a button press event.
// The server may ignore move requests depending on the state of
// the surface (e.g. fullscreen or maximized).
//
func (p *ShellSurface) Move(seat *Seat, serial uint32) error {
return p.Context().SendRequest(p, 1, seat, serial)
}
// Resize will start an interactive resize.
//
//
// Start a pointer-driven resizing of the surface.
//
// This request must be used in response to a button press event.
// The server may ignore resize requests depending on the state of
// the surface (e.g. fullscreen or maximized).
//
func (p *ShellSurface) Resize(seat *Seat, serial uint32, edges uint32) error {
return p.Context().SendRequest(p, 2, seat, serial, edges)
}
// SetToplevel will make the surface a toplevel surface.
//
//
// Map the surface as a toplevel surface.
//
// A toplevel surface is not fullscreen, maximized or transient.
//
func (p *ShellSurface) SetToplevel() error {
return p.Context().SendRequest(p, 3)
}
// SetTransient will make the surface a transient surface.
//
//
// Map the surface relative to an existing surface.
//
// The x and y arguments specify the location of the upper left
// corner of the surface relative to the upper left corner of the
// parent surface, in surface-local coordinates.
//
// The flags argument controls details of the transient behaviour.
//
func (p *ShellSurface) SetTransient(parent *Surface, x int32, y int32, flags uint32) error {
return p.Context().SendRequest(p, 4, parent, x, y, flags)
}
// SetFullscreen will make the surface a fullscreen surface.
//
//
// Map the surface as a fullscreen surface.
//
// If an output parameter is given then the surface will be made
// fullscreen on that output. If the client does not specify the
// output then the compositor will apply its policy - usually
// choosing the output on which the surface has the biggest surface
// area.
//
// The client may specify a method to resolve a size conflict
// between the output size and the surface size - this is provided
// through the method parameter.
//
// The framerate parameter is used only when the method is set
// to "driver", to indicate the preferred framerate. A value of 0
// indicates that the client does not care about framerate. The
// framerate is specified in mHz, that is framerate of 60000 is 60Hz.
//
// A method of "scale" or "driver" implies a scaling operation of
// the surface, either via a direct scaling operation or a change of
// the output mode. This will override any kind of output scaling, so
// that mapping a surface with a buffer size equal to the mode can
// fill the screen independent of buffer_scale.
//
// A method of "fill" means we don't scale up the buffer, however
// any output scale is applied. This means that you may run into
// an edge case where the application maps a buffer with the same
// size of the output mode but buffer_scale 1 (thus making a
// surface larger than the output). In this case it is allowed to
// downscale the results to fit the screen.
//
// The compositor must reply to this request with a configure event
// with the dimensions for the output on which the surface will
// be made fullscreen.
//
func (p *ShellSurface) SetFullscreen(method uint32, framerate uint32, output *Output) error {
return p.Context().SendRequest(p, 5, method, framerate, output)
}
// SetPopup will make the surface a popup surface.
//
//
// Map the surface as a popup.
//
// A popup surface is a transient surface with an added pointer
// grab.
//
// An existing implicit grab will be changed to owner-events mode,
// and the popup grab will continue after the implicit grab ends
// (i.e. releasing the mouse button does not cause the popup to
// be unmapped).
//
// The popup grab continues until the window is destroyed or a
// mouse button is pressed in any other client's window. A click
// in any of the client's surfaces is reported as normal, however,
// clicks in other clients' surfaces will be discarded and trigger
// the callback.
//
// The x and y arguments specify the location of the upper left
// corner of the surface relative to the upper left corner of the
// parent surface, in surface-local coordinates.
//
func (p *ShellSurface) SetPopup(seat *Seat, serial uint32, parent *Surface, x int32, y int32, flags uint32) error {
return p.Context().SendRequest(p, 6, seat, serial, parent, x, y, flags)
}
// SetMaximized will make the surface a maximized surface.
//
//
// Map the surface as a maximized surface.
//
// If an output parameter is given then the surface will be
// maximized on that output. If the client does not specify the
// output then the compositor will apply its policy - usually
// choosing the output on which the surface has the biggest surface
// area.
//
// The compositor will reply with a configure event telling
// the expected new surface size. The operation is completed
// on the next buffer attach to this surface.
//
// A maximized surface typically fills the entire output it is
// bound to, except for desktop elements such as panels. This is
// the main difference between a maximized shell surface and a
// fullscreen shell surface.
//
// The details depend on the compositor implementation.
//
func (p *ShellSurface) SetMaximized(output *Output) error {
return p.Context().SendRequest(p, 7, output)
}
// SetTitle will set surface title.
//
//
// Set a short title for the surface.
//
// This string may be used to identify the surface in a task bar,
// window list, or other user interface elements provided by the
// compositor.
//
// The string must be encoded in UTF-8.
//
func (p *ShellSurface) SetTitle(title string) error {
return p.Context().SendRequest(p, 8, title)
}
// SetClass will set surface class.
//
//
// Set a class for the surface.
//
// The surface class identifies the general class of applications
// to which the surface belongs. A common convention is to use the
// file name (or the full path if it is a non-standard location) of
// the application's .desktop file as the class.
//
func (p *ShellSurface) SetClass(class_ string) error {
return p.Context().SendRequest(p, 9, class_)
}
const (
ShellSurfaceResizeNone = 0
ShellSurfaceResizeTop = 1
ShellSurfaceResizeBottom = 2
ShellSurfaceResizeLeft = 4
ShellSurfaceResizeTopLeft = 5
ShellSurfaceResizeBottomLeft = 6
ShellSurfaceResizeRight = 8
ShellSurfaceResizeTopRight = 9
ShellSurfaceResizeBottomRight = 10
)
const (
ShellSurfaceTransientInactive = 0x1
)
const (
ShellSurfaceFullscreenMethodDefault = 0
ShellSurfaceFullscreenMethodScale = 1
ShellSurfaceFullscreenMethodDriver = 2
ShellSurfaceFullscreenMethodFill = 3
)
type SurfaceEnterEvent struct {
EventContext context.Context
Output *Output
}
type SurfaceEnterHandler interface {
HandleSurfaceEnter(SurfaceEnterEvent)
}
func (p *Surface) AddEnterHandler(h SurfaceEnterHandler) {
if h != nil {
p.mu.Lock()
p.enterHandlers = append(p.enterHandlers, h)
p.mu.Unlock()
}
}
func (p *Surface) RemoveEnterHandler(h SurfaceEnterHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.enterHandlers {
if e == h {
p.enterHandlers = append(p.enterHandlers[:i], p.enterHandlers[i+1:]...)
break
}
}
}
type SurfaceLeaveEvent struct {
EventContext context.Context
Output *Output
}
type SurfaceLeaveHandler interface {
HandleSurfaceLeave(SurfaceLeaveEvent)
}
func (p *Surface) AddLeaveHandler(h SurfaceLeaveHandler) {
if h != nil {
p.mu.Lock()
p.leaveHandlers = append(p.leaveHandlers, h)
p.mu.Unlock()
}
}
func (p *Surface) RemoveLeaveHandler(h SurfaceLeaveHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.leaveHandlers {
if e == h {
p.leaveHandlers = append(p.leaveHandlers[:i], p.leaveHandlers[i+1:]...)
break
}
}
}
func (p *Surface) Dispatch(ctx context.Context, event *Event) {
switch event.Opcode {
case 0:
if len(p.enterHandlers) > 0 {
ev := SurfaceEnterEvent{}
ev.EventContext = ctx
ev.Output = event.Proxy(p.Context()).(*Output)
p.mu.RLock()
for _, h := range p.enterHandlers {
h.HandleSurfaceEnter(ev)
}
p.mu.RUnlock()
}
case 1:
if len(p.leaveHandlers) > 0 {
ev := SurfaceLeaveEvent{}
ev.EventContext = ctx
ev.Output = event.Proxy(p.Context()).(*Output)
p.mu.RLock()
for _, h := range p.leaveHandlers {
h.HandleSurfaceLeave(ev)
}
p.mu.RUnlock()
}
}
}
type Surface struct {
BaseProxy
mu sync.RWMutex
enterHandlers []SurfaceEnterHandler
leaveHandlers []SurfaceLeaveHandler
}
func NewSurface(ctx *Context) *Surface {
ret := new(Surface)
ctx.Register(ret)
return ret
}
// Destroy will delete surface.
//
//
// Deletes the surface and invalidates its object ID.
//
func (p *Surface) Destroy() error {
return p.Context().SendRequest(p, 0)
}
// Attach will set the surface contents.
//
//
// Set a buffer as the content of this surface.
//
// The new size of the surface is calculated based on the buffer
// size transformed by the inverse buffer_transform and the
// inverse buffer_scale. This means that the supplied buffer
// must be an integer multiple of the buffer_scale.
//
// The x and y arguments specify the location of the new pending
// buffer's upper left corner, relative to the current buffer's upper
// left corner, in surface-local coordinates. In other words, the
// x and y, combined with the new surface size define in which
// directions the surface's size changes.
//
// Surface contents are double-buffered state, see wl_surface.commit.
//
// The initial surface contents are void; there is no content.
// wl_surface.attach assigns the given wl_buffer as the pending
// wl_buffer. wl_surface.commit makes the pending wl_buffer the new
// surface contents, and the size of the surface becomes the size
// calculated from the wl_buffer, as described above. After commit,
// there is no pending buffer until the next attach.
//
// Committing a pending wl_buffer allows the compositor to read the
// pixels in the wl_buffer. The compositor may access the pixels at
// any time after the wl_surface.commit request. When the compositor
// will not access the pixels anymore, it will send the
// wl_buffer.release event. Only after receiving wl_buffer.release,
// the client may reuse the wl_buffer. A wl_buffer that has been
// attached and then replaced by another attach instead of committed
// will not receive a release event, and is not used by the
// compositor.
//
// Destroying the wl_buffer after wl_buffer.release does not change
// the surface contents. However, if the client destroys the
// wl_buffer before receiving the wl_buffer.release event, the surface
// contents become undefined immediately.
//
// If wl_surface.attach is sent with a NULL wl_buffer, the
// following wl_surface.commit will remove the surface content.
//
func (p *Surface) Attach(buffer *Buffer, x int32, y int32) error {
return p.Context().SendRequest(p, 1, buffer, x, y)
}
// Damage will mark part of the surface damaged.
//
//
// This request is used to describe the regions where the pending
// buffer is different from the current surface contents, and where
// the surface therefore needs to be repainted. The compositor
// ignores the parts of the damage that fall outside of the surface.
//
// Damage is double-buffered state, see wl_surface.commit.
//
// The damage rectangle is specified in surface-local coordinates,
// where x and y specify the upper left corner of the damage rectangle.
//
// The initial value for pending damage is empty: no damage.
// wl_surface.damage adds pending damage: the new pending damage
// is the union of old pending damage and the given rectangle.
//
// wl_surface.commit assigns pending damage as the current damage,
// and clears pending damage. The server will clear the current
// damage as it repaints the surface.
//
// Alternatively, damage can be posted with wl_surface.damage_buffer
// which uses buffer coordinates instead of surface coordinates,
// and is probably the preferred and intuitive way of doing this.
//
func (p *Surface) Damage(x int32, y int32, width int32, height int32) error {
return p.Context().SendRequest(p, 2, x, y, width, height)
}
// Frame will request a frame throttling hint.
//
//
// Request a notification when it is a good time to start drawing a new
// frame, by creating a frame callback. This is useful for throttling
// redrawing operations, and driving animations.
//
// When a client is animating on a wl_surface, it can use the 'frame'
// request to get notified when it is a good time to draw and commit the
// next frame of animation. If the client commits an update earlier than
// that, it is likely that some updates will not make it to the display,
// and the client is wasting resources by drawing too often.
//
// The frame request will take effect on the next wl_surface.commit.
// The notification will only be posted for one frame unless
// requested again. For a wl_surface, the notifications are posted in
// the order the frame requests were committed.
//
// The server must send the notifications so that a client
// will not send excessive updates, while still allowing
// the highest possible update rate for clients that wait for the reply
// before drawing again. The server should give some time for the client
// to draw and commit after sending the frame callback events to let it
// hit the next output refresh.
//
// A server should avoid signaling the frame callbacks if the
// surface is not visible in any way, e.g. the surface is off-screen,
// or completely obscured by other opaque surfaces.
//
// The object returned by this request will be destroyed by the
// compositor after the callback is fired and as such the client must not
// attempt to use it after that point.
//
// The callback_data passed in the callback is the current time, in
// milliseconds, with an undefined base.
//
func (p *Surface) Frame() (*Callback, error) {
ret := NewCallback(p.Context())
return ret, p.Context().SendRequest(p, 3, Proxy(ret))
}
// SetOpaqueRegion will set opaque region.
//
//
// This request sets the region of the surface that contains
// opaque content.
//
// The opaque region is an optimization hint for the compositor
// that lets it optimize the redrawing of content behind opaque
// regions. Setting an opaque region is not required for correct
// behaviour, but marking transparent content as opaque will result
// in repaint artifacts.
//
// The opaque region is specified in surface-local coordinates.
//
// The compositor ignores the parts of the opaque region that fall
// outside of the surface.
//
// Opaque region is double-buffered state, see wl_surface.commit.
//
// wl_surface.set_opaque_region changes the pending opaque region.
// wl_surface.commit copies the pending region to the current region.
// Otherwise, the pending and current regions are never changed.
//
// The initial value for an opaque region is empty. Setting the pending
// opaque region has copy semantics, and the wl_region object can be
// destroyed immediately. A NULL wl_region causes the pending opaque
// region to be set to empty.
//
func (p *Surface) SetOpaqueRegion(region *Region) error {
return p.Context().SendRequest(p, 4, region)
}
// SetInputRegion will set input region.
//
//
// This request sets the region of the surface that can receive
// pointer and touch events.
//
// Input events happening outside of this region will try the next
// surface in the server surface stack. The compositor ignores the
// parts of the input region that fall outside of the surface.
//
// The input region is specified in surface-local coordinates.
//
// Input region is double-buffered state, see wl_surface.commit.
//
// wl_surface.set_input_region changes the pending input region.
// wl_surface.commit copies the pending region to the current region.
// Otherwise the pending and current regions are never changed,
// except cursor and icon surfaces are special cases, see
// wl_pointer.set_cursor and wl_data_device.start_drag.
//
// The initial value for an input region is infinite. That means the
// whole surface will accept input. Setting the pending input region
// has copy semantics, and the wl_region object can be destroyed
// immediately. A NULL wl_region causes the input region to be set
// to infinite.
//
func (p *Surface) SetInputRegion(region *Region) error {
return p.Context().SendRequest(p, 5, region)
}
// Commit will commit pending surface state.
//
//
// Surface state (input, opaque, and damage regions, attached buffers,
// etc.) is double-buffered. Protocol requests modify the pending state,
// as opposed to the current state in use by the compositor. A commit
// request atomically applies all pending state, replacing the current
// state. After commit, the new pending state is as documented for each
// related request.
//
// On commit, a pending wl_buffer is applied first, and all other state
// second. This means that all coordinates in double-buffered state are
// relative to the new wl_buffer coming into use, except for
// wl_surface.attach itself. If there is no pending wl_buffer, the
// coordinates are relative to the current surface contents.
//
// All requests that need a commit to become effective are documented
// to affect double-buffered state.
//
// Other interfaces may add further double-buffered surface state.
//
func (p *Surface) Commit() error {
return p.Context().SendRequest(p, 6)
}
// SetBufferTransform will sets the buffer transformation.
//
//
// This request sets an optional transformation on how the compositor
// interprets the contents of the buffer attached to the surface. The
// accepted values for the transform parameter are the values for
// wl_output.transform.
//
// Buffer transform is double-buffered state, see wl_surface.commit.
//
// A newly created surface has its buffer transformation set to normal.
//
// wl_surface.set_buffer_transform changes the pending buffer
// transformation. wl_surface.commit copies the pending buffer
// transformation to the current one. Otherwise, the pending and current
// values are never changed.
//
// The purpose of this request is to allow clients to render content
// according to the output transform, thus permitting the compositor to
// use certain optimizations even if the display is rotated. Using
// hardware overlays and scanning out a client buffer for fullscreen
// surfaces are examples of such optimizations. Those optimizations are
// highly dependent on the compositor implementation, so the use of this
// request should be considered on a case-by-case basis.
//
// Note that if the transform value includes 90 or 270 degree rotation,
// the width of the buffer will become the surface height and the height
// of the buffer will become the surface width.
//
// If transform is not one of the values from the
// wl_output.transform enum the invalid_transform protocol error
// is raised.
//
func (p *Surface) SetBufferTransform(transform int32) error {
return p.Context().SendRequest(p, 7, transform)
}
// SetBufferScale will sets the buffer scaling factor.
//
//
// This request sets an optional scaling factor on how the compositor
// interprets the contents of the buffer attached to the window.
//
// Buffer scale is double-buffered state, see wl_surface.commit.
//
// A newly created surface has its buffer scale set to 1.
//
// wl_surface.set_buffer_scale changes the pending buffer scale.
// wl_surface.commit copies the pending buffer scale to the current one.
// Otherwise, the pending and current values are never changed.
//
// The purpose of this request is to allow clients to supply higher
// resolution buffer data for use on high resolution outputs. It is
// intended that you pick the same buffer scale as the scale of the
// output that the surface is displayed on. This means the compositor
// can avoid scaling when rendering the surface on that output.
//
// Note that if the scale is larger than 1, then you have to attach
// a buffer that is larger (by a factor of scale in each dimension)
// than the desired surface size.
//
// If scale is not positive the invalid_scale protocol error is
// raised.
//
func (p *Surface) SetBufferScale(scale int32) error {
return p.Context().SendRequest(p, 8, scale)
}
// DamageBuffer will mark part of the surface damaged using buffer coordinates.
//
//
// This request is used to describe the regions where the pending
// buffer is different from the current surface contents, and where
// the surface therefore needs to be repainted. The compositor
// ignores the parts of the damage that fall outside of the surface.
//
// Damage is double-buffered state, see wl_surface.commit.
//
// The damage rectangle is specified in buffer coordinates,
// where x and y specify the upper left corner of the damage rectangle.
//
// The initial value for pending damage is empty: no damage.
// wl_surface.damage_buffer adds pending damage: the new pending
// damage is the union of old pending damage and the given rectangle.
//
// wl_surface.commit assigns pending damage as the current damage,
// and clears pending damage. The server will clear the current
// damage as it repaints the surface.
//
// This request differs from wl_surface.damage in only one way - it
// takes damage in buffer coordinates instead of surface-local
// coordinates. While this generally is more intuitive than surface
// coordinates, it is especially desirable when using wp_viewport
// or when a drawing library (like EGL) is unaware of buffer scale
// and buffer transform.
//
// Note: Because buffer transformation changes and damage requests may
// be interleaved in the protocol stream, it is impossible to determine
// the actual mapping between surface and buffer damage until
// wl_surface.commit time. Therefore, compositors wishing to take both
// kinds of damage into account will have to accumulate damage from the
// two requests separately and only transform from one to the other
// after receiving the wl_surface.commit.
//
func (p *Surface) DamageBuffer(x int32, y int32, width int32, height int32) error {
return p.Context().SendRequest(p, 9, x, y, width, height)
}
const (
SurfaceErrorInvalidScale = 0
SurfaceErrorInvalidTransform = 1
)
type SeatCapabilitiesEvent struct {
EventContext context.Context
Capabilities uint32
}
type SeatCapabilitiesHandler interface {
HandleSeatCapabilities(SeatCapabilitiesEvent)
}
func (p *Seat) AddCapabilitiesHandler(h SeatCapabilitiesHandler) {
if h != nil {
p.mu.Lock()
p.capabilitiesHandlers = append(p.capabilitiesHandlers, h)
p.mu.Unlock()
}
}
func (p *Seat) RemoveCapabilitiesHandler(h SeatCapabilitiesHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.capabilitiesHandlers {
if e == h {
p.capabilitiesHandlers = append(p.capabilitiesHandlers[:i], p.capabilitiesHandlers[i+1:]...)
break
}
}
}
type SeatNameEvent struct {
EventContext context.Context
Name string
}
type SeatNameHandler interface {
HandleSeatName(SeatNameEvent)
}
func (p *Seat) AddNameHandler(h SeatNameHandler) {
if h != nil {
p.mu.Lock()
p.nameHandlers = append(p.nameHandlers, h)
p.mu.Unlock()
}
}
func (p *Seat) RemoveNameHandler(h SeatNameHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.nameHandlers {
if e == h {
p.nameHandlers = append(p.nameHandlers[:i], p.nameHandlers[i+1:]...)
break
}
}
}
func (p *Seat) Dispatch(ctx context.Context, event *Event) {
switch event.Opcode {
case 0:
if len(p.capabilitiesHandlers) > 0 {
ev := SeatCapabilitiesEvent{}
ev.EventContext = ctx
ev.Capabilities = event.Uint32()
p.mu.RLock()
for _, h := range p.capabilitiesHandlers {
h.HandleSeatCapabilities(ev)
}
p.mu.RUnlock()
}
case 1:
if len(p.nameHandlers) > 0 {
ev := SeatNameEvent{}
ev.EventContext = ctx
ev.Name = event.String()
p.mu.RLock()
for _, h := range p.nameHandlers {
h.HandleSeatName(ev)
}
p.mu.RUnlock()
}
}
}
type Seat struct {
BaseProxy
mu sync.RWMutex
capabilitiesHandlers []SeatCapabilitiesHandler
nameHandlers []SeatNameHandler
}
func NewSeat(ctx *Context) *Seat {
ret := new(Seat)
ctx.Register(ret)
return ret
}
// GetPointer will return pointer object.
//
//
// The ID provided will be initialized to the wl_pointer interface
// for this seat.
//
// This request only takes effect if the seat has the pointer
// capability, or has had the pointer capability in the past.
// It is a protocol violation to issue this request on a seat that has
// never had the pointer capability.
//
func (p *Seat) GetPointer() (*Pointer, error) {
ret := NewPointer(p.Context())
return ret, p.Context().SendRequest(p, 0, Proxy(ret))
}
// GetKeyboard will return keyboard object.
//
//
// The ID provided will be initialized to the wl_keyboard interface
// for this seat.
//
// This request only takes effect if the seat has the keyboard
// capability, or has had the keyboard capability in the past.
// It is a protocol violation to issue this request on a seat that has
// never had the keyboard capability.
//
func (p *Seat) GetKeyboard() (*Keyboard, error) {
ret := NewKeyboard(p.Context())
return ret, p.Context().SendRequest(p, 1, Proxy(ret))
}
// GetTouch will return touch object.
//
//
// The ID provided will be initialized to the wl_touch interface
// for this seat.
//
// This request only takes effect if the seat has the touch
// capability, or has had the touch capability in the past.
// It is a protocol violation to issue this request on a seat that has
// never had the touch capability.
//
func (p *Seat) GetTouch() (*Touch, error) {
ret := NewTouch(p.Context())
return ret, p.Context().SendRequest(p, 2, Proxy(ret))
}
// Release will release the seat object.
//
//
// Using this request a client can tell the server that it is not going to
// use the seat object anymore.
//
func (p *Seat) Release() error {
return p.Context().SendRequest(p, 3)
}
const (
SeatCapabilityPointer = 1
SeatCapabilityKeyboard = 2
SeatCapabilityTouch = 4
)
type PointerEnterEvent struct {
EventContext context.Context
Serial uint32
Surface *Surface
SurfaceX float32
SurfaceY float32
}
type PointerEnterHandler interface {
HandlePointerEnter(PointerEnterEvent)
}
func (p *Pointer) AddEnterHandler(h PointerEnterHandler) {
if h != nil {
p.mu.Lock()
p.enterHandlers = append(p.enterHandlers, h)
p.mu.Unlock()
}
}
func (p *Pointer) RemoveEnterHandler(h PointerEnterHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.enterHandlers {
if e == h {
p.enterHandlers = append(p.enterHandlers[:i], p.enterHandlers[i+1:]...)
break
}
}
}
type PointerLeaveEvent struct {
EventContext context.Context
Serial uint32
Surface *Surface
}
type PointerLeaveHandler interface {
HandlePointerLeave(PointerLeaveEvent)
}
func (p *Pointer) AddLeaveHandler(h PointerLeaveHandler) {
if h != nil {
p.mu.Lock()
p.leaveHandlers = append(p.leaveHandlers, h)
p.mu.Unlock()
}
}
func (p *Pointer) RemoveLeaveHandler(h PointerLeaveHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.leaveHandlers {
if e == h {
p.leaveHandlers = append(p.leaveHandlers[:i], p.leaveHandlers[i+1:]...)
break
}
}
}
type PointerMotionEvent struct {
EventContext context.Context
Time uint32
SurfaceX float32
SurfaceY float32
}
type PointerMotionHandler interface {
HandlePointerMotion(PointerMotionEvent)
}
func (p *Pointer) AddMotionHandler(h PointerMotionHandler) {
if h != nil {
p.mu.Lock()
p.motionHandlers = append(p.motionHandlers, h)
p.mu.Unlock()
}
}
func (p *Pointer) RemoveMotionHandler(h PointerMotionHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.motionHandlers {
if e == h {
p.motionHandlers = append(p.motionHandlers[:i], p.motionHandlers[i+1:]...)
break
}
}
}
type PointerButtonEvent struct {
EventContext context.Context
Serial uint32
Time uint32
Button uint32
State uint32
}
type PointerButtonHandler interface {
HandlePointerButton(PointerButtonEvent)
}
func (p *Pointer) AddButtonHandler(h PointerButtonHandler) {
if h != nil {
p.mu.Lock()
p.buttonHandlers = append(p.buttonHandlers, h)
p.mu.Unlock()
}
}
func (p *Pointer) RemoveButtonHandler(h PointerButtonHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.buttonHandlers {
if e == h {
p.buttonHandlers = append(p.buttonHandlers[:i], p.buttonHandlers[i+1:]...)
break
}
}
}
type PointerAxisEvent struct {
EventContext context.Context
Time uint32
Axis uint32
Value float32
}
type PointerAxisHandler interface {
HandlePointerAxis(PointerAxisEvent)
}
func (p *Pointer) AddAxisHandler(h PointerAxisHandler) {
if h != nil {
p.mu.Lock()
p.axisHandlers = append(p.axisHandlers, h)
p.mu.Unlock()
}
}
func (p *Pointer) RemoveAxisHandler(h PointerAxisHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.axisHandlers {
if e == h {
p.axisHandlers = append(p.axisHandlers[:i], p.axisHandlers[i+1:]...)
break
}
}
}
type PointerFrameEvent struct {
EventContext context.Context
}
type PointerFrameHandler interface {
HandlePointerFrame(PointerFrameEvent)
}
func (p *Pointer) AddFrameHandler(h PointerFrameHandler) {
if h != nil {
p.mu.Lock()
p.frameHandlers = append(p.frameHandlers, h)
p.mu.Unlock()
}
}
func (p *Pointer) RemoveFrameHandler(h PointerFrameHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.frameHandlers {
if e == h {
p.frameHandlers = append(p.frameHandlers[:i], p.frameHandlers[i+1:]...)
break
}
}
}
type PointerAxisSourceEvent struct {
EventContext context.Context
AxisSource uint32
}
type PointerAxisSourceHandler interface {
HandlePointerAxisSource(PointerAxisSourceEvent)
}
func (p *Pointer) AddAxisSourceHandler(h PointerAxisSourceHandler) {
if h != nil {
p.mu.Lock()
p.axisSourceHandlers = append(p.axisSourceHandlers, h)
p.mu.Unlock()
}
}
func (p *Pointer) RemoveAxisSourceHandler(h PointerAxisSourceHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.axisSourceHandlers {
if e == h {
p.axisSourceHandlers = append(p.axisSourceHandlers[:i], p.axisSourceHandlers[i+1:]...)
break
}
}
}
type PointerAxisStopEvent struct {
EventContext context.Context
Time uint32
Axis uint32
}
type PointerAxisStopHandler interface {
HandlePointerAxisStop(PointerAxisStopEvent)
}
func (p *Pointer) AddAxisStopHandler(h PointerAxisStopHandler) {
if h != nil {
p.mu.Lock()
p.axisStopHandlers = append(p.axisStopHandlers, h)
p.mu.Unlock()
}
}
func (p *Pointer) RemoveAxisStopHandler(h PointerAxisStopHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.axisStopHandlers {
if e == h {
p.axisStopHandlers = append(p.axisStopHandlers[:i], p.axisStopHandlers[i+1:]...)
break
}
}
}
type PointerAxisDiscreteEvent struct {
EventContext context.Context
Axis uint32
Discrete int32
}
type PointerAxisDiscreteHandler interface {
HandlePointerAxisDiscrete(PointerAxisDiscreteEvent)
}
func (p *Pointer) AddAxisDiscreteHandler(h PointerAxisDiscreteHandler) {
if h != nil {
p.mu.Lock()
p.axisDiscreteHandlers = append(p.axisDiscreteHandlers, h)
p.mu.Unlock()
}
}
func (p *Pointer) RemoveAxisDiscreteHandler(h PointerAxisDiscreteHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.axisDiscreteHandlers {
if e == h {
p.axisDiscreteHandlers = append(p.axisDiscreteHandlers[:i], p.axisDiscreteHandlers[i+1:]...)
break
}
}
}
func (p *Pointer) Dispatch(ctx context.Context, event *Event) {
switch event.Opcode {
case 0:
if len(p.enterHandlers) > 0 {
ev := PointerEnterEvent{}
ev.EventContext = ctx
ev.Serial = event.Uint32()
ev.Surface = event.Proxy(p.Context()).(*Surface)
ev.SurfaceX = event.Float32()
ev.SurfaceY = event.Float32()
p.mu.RLock()
for _, h := range p.enterHandlers {
h.HandlePointerEnter(ev)
}
p.mu.RUnlock()
}
case 1:
if len(p.leaveHandlers) > 0 {
ev := PointerLeaveEvent{}
ev.EventContext = ctx
ev.Serial = event.Uint32()
ev.Surface = event.Proxy(p.Context()).(*Surface)
p.mu.RLock()
for _, h := range p.leaveHandlers {
h.HandlePointerLeave(ev)
}
p.mu.RUnlock()
}
case 2:
if len(p.motionHandlers) > 0 {
ev := PointerMotionEvent{}
ev.EventContext = ctx
ev.Time = event.Uint32()
ev.SurfaceX = event.Float32()
ev.SurfaceY = event.Float32()
p.mu.RLock()
for _, h := range p.motionHandlers {
h.HandlePointerMotion(ev)
}
p.mu.RUnlock()
}
case 3:
if len(p.buttonHandlers) > 0 {
ev := PointerButtonEvent{}
ev.EventContext = ctx
ev.Serial = event.Uint32()
ev.Time = event.Uint32()
ev.Button = event.Uint32()
ev.State = event.Uint32()
p.mu.RLock()
for _, h := range p.buttonHandlers {
h.HandlePointerButton(ev)
}
p.mu.RUnlock()
}
case 4:
if len(p.axisHandlers) > 0 {
ev := PointerAxisEvent{}
ev.EventContext = ctx
ev.Time = event.Uint32()
ev.Axis = event.Uint32()
ev.Value = event.Float32()
p.mu.RLock()
for _, h := range p.axisHandlers {
h.HandlePointerAxis(ev)
}
p.mu.RUnlock()
}
case 5:
if len(p.frameHandlers) > 0 {
ev := PointerFrameEvent{}
ev.EventContext = ctx
p.mu.RLock()
for _, h := range p.frameHandlers {
h.HandlePointerFrame(ev)
}
p.mu.RUnlock()
}
case 6:
if len(p.axisSourceHandlers) > 0 {
ev := PointerAxisSourceEvent{}
ev.EventContext = ctx
ev.AxisSource = event.Uint32()
p.mu.RLock()
for _, h := range p.axisSourceHandlers {
h.HandlePointerAxisSource(ev)
}
p.mu.RUnlock()
}
case 7:
if len(p.axisStopHandlers) > 0 {
ev := PointerAxisStopEvent{}
ev.EventContext = ctx
ev.Time = event.Uint32()
ev.Axis = event.Uint32()
p.mu.RLock()
for _, h := range p.axisStopHandlers {
h.HandlePointerAxisStop(ev)
}
p.mu.RUnlock()
}
case 8:
if len(p.axisDiscreteHandlers) > 0 {
ev := PointerAxisDiscreteEvent{}
ev.EventContext = ctx
ev.Axis = event.Uint32()
ev.Discrete = event.Int32()
p.mu.RLock()
for _, h := range p.axisDiscreteHandlers {
h.HandlePointerAxisDiscrete(ev)
}
p.mu.RUnlock()
}
}
}
type Pointer struct {
BaseProxy
mu sync.RWMutex
enterHandlers []PointerEnterHandler
leaveHandlers []PointerLeaveHandler
motionHandlers []PointerMotionHandler
buttonHandlers []PointerButtonHandler
axisHandlers []PointerAxisHandler
frameHandlers []PointerFrameHandler
axisSourceHandlers []PointerAxisSourceHandler
axisStopHandlers []PointerAxisStopHandler
axisDiscreteHandlers []PointerAxisDiscreteHandler
}
func NewPointer(ctx *Context) *Pointer {
ret := new(Pointer)
ctx.Register(ret)
return ret
}
// SetCursor will set the pointer surface.
//
//
// Set the pointer surface, i.e., the surface that contains the
// pointer image (cursor). This request gives the surface the role
// of a cursor. If the surface already has another role, it raises
// a protocol error.
//
// The cursor actually changes only if the pointer
// focus for this device is one of the requesting client's surfaces
// or the surface parameter is the current pointer surface. If
// there was a previous surface set with this request it is
// replaced. If surface is NULL, the pointer image is hidden.
//
// The parameters hotspot_x and hotspot_y define the position of
// the pointer surface relative to the pointer location. Its
// top-left corner is always at (x, y) - (hotspot_x, hotspot_y),
// where (x, y) are the coordinates of the pointer location, in
// surface-local coordinates.
//
// On surface.attach requests to the pointer surface, hotspot_x
// and hotspot_y are decremented by the x and y parameters
// passed to the request. Attach must be confirmed by
// wl_surface.commit as usual.
//
// The hotspot can also be updated by passing the currently set
// pointer surface to this request with new values for hotspot_x
// and hotspot_y.
//
// The current and pending input regions of the wl_surface are
// cleared, and wl_surface.set_input_region is ignored until the
// wl_surface is no longer used as the cursor. When the use as a
// cursor ends, the current and pending input regions become
// undefined, and the wl_surface is unmapped.
//
func (p *Pointer) SetCursor(serial uint32, surface *Surface, hotspot_x int32, hotspot_y int32) error {
return p.Context().SendRequest(p, 0, serial, surface, hotspot_x, hotspot_y)
}
// Release will release the pointer object.
//
//
// Using this request a client can tell the server that it is not going to
// use the pointer object anymore.
//
// This request destroys the pointer proxy object, so clients must not call
// wl_pointer_destroy() after using this request.
//
func (p *Pointer) Release() error {
return p.Context().SendRequest(p, 1)
}
const (
PointerErrorRole = 0
)
const (
PointerButtonStateReleased = 0
PointerButtonStatePressed = 1
)
const (
PointerAxisVerticalScroll = 0
PointerAxisHorizontalScroll = 1
)
const (
PointerAxisSourceWheel = 0
PointerAxisSourceFinger = 1
PointerAxisSourceContinuous = 2
PointerAxisSourceWheelTilt = 3
)
type KeyboardKeymapEvent struct {
EventContext context.Context
Format uint32
Fd uintptr
Size uint32
}
type KeyboardKeymapHandler interface {
HandleKeyboardKeymap(KeyboardKeymapEvent)
}
func (p *Keyboard) AddKeymapHandler(h KeyboardKeymapHandler) {
if h != nil {
p.mu.Lock()
p.keymapHandlers = append(p.keymapHandlers, h)
p.mu.Unlock()
}
}
func (p *Keyboard) RemoveKeymapHandler(h KeyboardKeymapHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.keymapHandlers {
if e == h {
p.keymapHandlers = append(p.keymapHandlers[:i], p.keymapHandlers[i+1:]...)
break
}
}
}
type KeyboardEnterEvent struct {
EventContext context.Context
Serial uint32
Surface *Surface
Keys []int32
}
type KeyboardEnterHandler interface {
HandleKeyboardEnter(KeyboardEnterEvent)
}
func (p *Keyboard) AddEnterHandler(h KeyboardEnterHandler) {
if h != nil {
p.mu.Lock()
p.enterHandlers = append(p.enterHandlers, h)
p.mu.Unlock()
}
}
func (p *Keyboard) RemoveEnterHandler(h KeyboardEnterHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.enterHandlers {
if e == h {
p.enterHandlers = append(p.enterHandlers[:i], p.enterHandlers[i+1:]...)
break
}
}
}
type KeyboardLeaveEvent struct {
EventContext context.Context
Serial uint32
Surface *Surface
}
type KeyboardLeaveHandler interface {
HandleKeyboardLeave(KeyboardLeaveEvent)
}
func (p *Keyboard) AddLeaveHandler(h KeyboardLeaveHandler) {
if h != nil {
p.mu.Lock()
p.leaveHandlers = append(p.leaveHandlers, h)
p.mu.Unlock()
}
}
func (p *Keyboard) RemoveLeaveHandler(h KeyboardLeaveHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.leaveHandlers {
if e == h {
p.leaveHandlers = append(p.leaveHandlers[:i], p.leaveHandlers[i+1:]...)
break
}
}
}
type KeyboardKeyEvent struct {
EventContext context.Context
Serial uint32
Time uint32
Key uint32
State uint32
}
type KeyboardKeyHandler interface {
HandleKeyboardKey(KeyboardKeyEvent)
}
func (p *Keyboard) AddKeyHandler(h KeyboardKeyHandler) {
if h != nil {
p.mu.Lock()
p.keyHandlers = append(p.keyHandlers, h)
p.mu.Unlock()
}
}
func (p *Keyboard) RemoveKeyHandler(h KeyboardKeyHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.keyHandlers {
if e == h {
p.keyHandlers = append(p.keyHandlers[:i], p.keyHandlers[i+1:]...)
break
}
}
}
type KeyboardModifiersEvent struct {
EventContext context.Context
Serial uint32
ModsDepressed uint32
ModsLatched uint32
ModsLocked uint32
Group uint32
}
type KeyboardModifiersHandler interface {
HandleKeyboardModifiers(KeyboardModifiersEvent)
}
func (p *Keyboard) AddModifiersHandler(h KeyboardModifiersHandler) {
if h != nil {
p.mu.Lock()
p.modifiersHandlers = append(p.modifiersHandlers, h)
p.mu.Unlock()
}
}
func (p *Keyboard) RemoveModifiersHandler(h KeyboardModifiersHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.modifiersHandlers {
if e == h {
p.modifiersHandlers = append(p.modifiersHandlers[:i], p.modifiersHandlers[i+1:]...)
break
}
}
}
type KeyboardRepeatInfoEvent struct {
EventContext context.Context
Rate int32
Delay int32
}
type KeyboardRepeatInfoHandler interface {
HandleKeyboardRepeatInfo(KeyboardRepeatInfoEvent)
}
func (p *Keyboard) AddRepeatInfoHandler(h KeyboardRepeatInfoHandler) {
if h != nil {
p.mu.Lock()
p.repeatInfoHandlers = append(p.repeatInfoHandlers, h)
p.mu.Unlock()
}
}
func (p *Keyboard) RemoveRepeatInfoHandler(h KeyboardRepeatInfoHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.repeatInfoHandlers {
if e == h {
p.repeatInfoHandlers = append(p.repeatInfoHandlers[:i], p.repeatInfoHandlers[i+1:]...)
break
}
}
}
func (p *Keyboard) Dispatch(ctx context.Context, event *Event) {
switch event.Opcode {
case 0:
if len(p.keymapHandlers) > 0 {
ev := KeyboardKeymapEvent{}
ev.EventContext = ctx
ev.Format = event.Uint32()
ev.Fd = event.FD()
ev.Size = event.Uint32()
p.mu.RLock()
for _, h := range p.keymapHandlers {
h.HandleKeyboardKeymap(ev)
}
p.mu.RUnlock()
}
case 1:
if len(p.enterHandlers) > 0 {
ev := KeyboardEnterEvent{}
ev.EventContext = ctx
ev.Serial = event.Uint32()
ev.Surface = event.Proxy(p.Context()).(*Surface)
ev.Keys = event.Array()
p.mu.RLock()
for _, h := range p.enterHandlers {
h.HandleKeyboardEnter(ev)
}
p.mu.RUnlock()
}
case 2:
if len(p.leaveHandlers) > 0 {
ev := KeyboardLeaveEvent{}
ev.EventContext = ctx
ev.Serial = event.Uint32()
ev.Surface = event.Proxy(p.Context()).(*Surface)
p.mu.RLock()
for _, h := range p.leaveHandlers {
h.HandleKeyboardLeave(ev)
}
p.mu.RUnlock()
}
case 3:
if len(p.keyHandlers) > 0 {
ev := KeyboardKeyEvent{}
ev.EventContext = ctx
ev.Serial = event.Uint32()
ev.Time = event.Uint32()
ev.Key = event.Uint32()
ev.State = event.Uint32()
p.mu.RLock()
for _, h := range p.keyHandlers {
h.HandleKeyboardKey(ev)
}
p.mu.RUnlock()
}
case 4:
if len(p.modifiersHandlers) > 0 {
ev := KeyboardModifiersEvent{}
ev.EventContext = ctx
ev.Serial = event.Uint32()
ev.ModsDepressed = event.Uint32()
ev.ModsLatched = event.Uint32()
ev.ModsLocked = event.Uint32()
ev.Group = event.Uint32()
p.mu.RLock()
for _, h := range p.modifiersHandlers {
h.HandleKeyboardModifiers(ev)
}
p.mu.RUnlock()
}
case 5:
if len(p.repeatInfoHandlers) > 0 {
ev := KeyboardRepeatInfoEvent{}
ev.EventContext = ctx
ev.Rate = event.Int32()
ev.Delay = event.Int32()
p.mu.RLock()
for _, h := range p.repeatInfoHandlers {
h.HandleKeyboardRepeatInfo(ev)
}
p.mu.RUnlock()
}
}
}
type Keyboard struct {
BaseProxy
mu sync.RWMutex
keymapHandlers []KeyboardKeymapHandler
enterHandlers []KeyboardEnterHandler
leaveHandlers []KeyboardLeaveHandler
keyHandlers []KeyboardKeyHandler
modifiersHandlers []KeyboardModifiersHandler
repeatInfoHandlers []KeyboardRepeatInfoHandler
}
func NewKeyboard(ctx *Context) *Keyboard {
ret := new(Keyboard)
ctx.Register(ret)
return ret
}
// Release will release the keyboard object.
//
//
func (p *Keyboard) Release() error {
return p.Context().SendRequest(p, 0)
}
const (
KeyboardKeymapFormatNoKeymap = 0
KeyboardKeymapFormatXkbV1 = 1
)
const (
KeyboardKeyStateReleased = 0
KeyboardKeyStatePressed = 1
)
type TouchDownEvent struct {
EventContext context.Context
Serial uint32
Time uint32
Surface *Surface
Id int32
X float32
Y float32
}
type TouchDownHandler interface {
HandleTouchDown(TouchDownEvent)
}
func (p *Touch) AddDownHandler(h TouchDownHandler) {
if h != nil {
p.mu.Lock()
p.downHandlers = append(p.downHandlers, h)
p.mu.Unlock()
}
}
func (p *Touch) RemoveDownHandler(h TouchDownHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.downHandlers {
if e == h {
p.downHandlers = append(p.downHandlers[:i], p.downHandlers[i+1:]...)
break
}
}
}
type TouchUpEvent struct {
EventContext context.Context
Serial uint32
Time uint32
Id int32
}
type TouchUpHandler interface {
HandleTouchUp(TouchUpEvent)
}
func (p *Touch) AddUpHandler(h TouchUpHandler) {
if h != nil {
p.mu.Lock()
p.upHandlers = append(p.upHandlers, h)
p.mu.Unlock()
}
}
func (p *Touch) RemoveUpHandler(h TouchUpHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.upHandlers {
if e == h {
p.upHandlers = append(p.upHandlers[:i], p.upHandlers[i+1:]...)
break
}
}
}
type TouchMotionEvent struct {
EventContext context.Context
Time uint32
Id int32
X float32
Y float32
}
type TouchMotionHandler interface {
HandleTouchMotion(TouchMotionEvent)
}
func (p *Touch) AddMotionHandler(h TouchMotionHandler) {
if h != nil {
p.mu.Lock()
p.motionHandlers = append(p.motionHandlers, h)
p.mu.Unlock()
}
}
func (p *Touch) RemoveMotionHandler(h TouchMotionHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.motionHandlers {
if e == h {
p.motionHandlers = append(p.motionHandlers[:i], p.motionHandlers[i+1:]...)
break
}
}
}
type TouchFrameEvent struct {
EventContext context.Context
}
type TouchFrameHandler interface {
HandleTouchFrame(TouchFrameEvent)
}
func (p *Touch) AddFrameHandler(h TouchFrameHandler) {
if h != nil {
p.mu.Lock()
p.frameHandlers = append(p.frameHandlers, h)
p.mu.Unlock()
}
}
func (p *Touch) RemoveFrameHandler(h TouchFrameHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.frameHandlers {
if e == h {
p.frameHandlers = append(p.frameHandlers[:i], p.frameHandlers[i+1:]...)
break
}
}
}
type TouchCancelEvent struct {
EventContext context.Context
}
type TouchCancelHandler interface {
HandleTouchCancel(TouchCancelEvent)
}
func (p *Touch) AddCancelHandler(h TouchCancelHandler) {
if h != nil {
p.mu.Lock()
p.cancelHandlers = append(p.cancelHandlers, h)
p.mu.Unlock()
}
}
func (p *Touch) RemoveCancelHandler(h TouchCancelHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.cancelHandlers {
if e == h {
p.cancelHandlers = append(p.cancelHandlers[:i], p.cancelHandlers[i+1:]...)
break
}
}
}
type TouchShapeEvent struct {
EventContext context.Context
Id int32
Major float32
Minor float32
}
type TouchShapeHandler interface {
HandleTouchShape(TouchShapeEvent)
}
func (p *Touch) AddShapeHandler(h TouchShapeHandler) {
if h != nil {
p.mu.Lock()
p.shapeHandlers = append(p.shapeHandlers, h)
p.mu.Unlock()
}
}
func (p *Touch) RemoveShapeHandler(h TouchShapeHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.shapeHandlers {
if e == h {
p.shapeHandlers = append(p.shapeHandlers[:i], p.shapeHandlers[i+1:]...)
break
}
}
}
type TouchOrientationEvent struct {
EventContext context.Context
Id int32
Orientation float32
}
type TouchOrientationHandler interface {
HandleTouchOrientation(TouchOrientationEvent)
}
func (p *Touch) AddOrientationHandler(h TouchOrientationHandler) {
if h != nil {
p.mu.Lock()
p.orientationHandlers = append(p.orientationHandlers, h)
p.mu.Unlock()
}
}
func (p *Touch) RemoveOrientationHandler(h TouchOrientationHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.orientationHandlers {
if e == h {
p.orientationHandlers = append(p.orientationHandlers[:i], p.orientationHandlers[i+1:]...)
break
}
}
}
func (p *Touch) Dispatch(ctx context.Context, event *Event) {
switch event.Opcode {
case 0:
if len(p.downHandlers) > 0 {
ev := TouchDownEvent{}
ev.EventContext = ctx
ev.Serial = event.Uint32()
ev.Time = event.Uint32()
ev.Surface = event.Proxy(p.Context()).(*Surface)
ev.Id = event.Int32()
ev.X = event.Float32()
ev.Y = event.Float32()
p.mu.RLock()
for _, h := range p.downHandlers {
h.HandleTouchDown(ev)
}
p.mu.RUnlock()
}
case 1:
if len(p.upHandlers) > 0 {
ev := TouchUpEvent{}
ev.EventContext = ctx
ev.Serial = event.Uint32()
ev.Time = event.Uint32()
ev.Id = event.Int32()
p.mu.RLock()
for _, h := range p.upHandlers {
h.HandleTouchUp(ev)
}
p.mu.RUnlock()
}
case 2:
if len(p.motionHandlers) > 0 {
ev := TouchMotionEvent{}
ev.EventContext = ctx
ev.Time = event.Uint32()
ev.Id = event.Int32()
ev.X = event.Float32()
ev.Y = event.Float32()
p.mu.RLock()
for _, h := range p.motionHandlers {
h.HandleTouchMotion(ev)
}
p.mu.RUnlock()
}
case 3:
if len(p.frameHandlers) > 0 {
ev := TouchFrameEvent{}
ev.EventContext = ctx
p.mu.RLock()
for _, h := range p.frameHandlers {
h.HandleTouchFrame(ev)
}
p.mu.RUnlock()
}
case 4:
if len(p.cancelHandlers) > 0 {
ev := TouchCancelEvent{}
ev.EventContext = ctx
p.mu.RLock()
for _, h := range p.cancelHandlers {
h.HandleTouchCancel(ev)
}
p.mu.RUnlock()
}
case 5:
if len(p.shapeHandlers) > 0 {
ev := TouchShapeEvent{}
ev.EventContext = ctx
ev.Id = event.Int32()
ev.Major = event.Float32()
ev.Minor = event.Float32()
p.mu.RLock()
for _, h := range p.shapeHandlers {
h.HandleTouchShape(ev)
}
p.mu.RUnlock()
}
case 6:
if len(p.orientationHandlers) > 0 {
ev := TouchOrientationEvent{}
ev.EventContext = ctx
ev.Id = event.Int32()
ev.Orientation = event.Float32()
p.mu.RLock()
for _, h := range p.orientationHandlers {
h.HandleTouchOrientation(ev)
}
p.mu.RUnlock()
}
}
}
type Touch struct {
BaseProxy
mu sync.RWMutex
downHandlers []TouchDownHandler
upHandlers []TouchUpHandler
motionHandlers []TouchMotionHandler
frameHandlers []TouchFrameHandler
cancelHandlers []TouchCancelHandler
shapeHandlers []TouchShapeHandler
orientationHandlers []TouchOrientationHandler
}
func NewTouch(ctx *Context) *Touch {
ret := new(Touch)
ctx.Register(ret)
return ret
}
// Release will release the touch object.
//
//
func (p *Touch) Release() error {
return p.Context().SendRequest(p, 0)
}
type OutputGeometryEvent struct {
EventContext context.Context
X int32
Y int32
PhysicalWidth int32
PhysicalHeight int32
Subpixel int32
Make string
Model string
Transform int32
}
type OutputGeometryHandler interface {
HandleOutputGeometry(OutputGeometryEvent)
}
func (p *Output) AddGeometryHandler(h OutputGeometryHandler) {
if h != nil {
p.mu.Lock()
p.geometryHandlers = append(p.geometryHandlers, h)
p.mu.Unlock()
}
}
func (p *Output) RemoveGeometryHandler(h OutputGeometryHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.geometryHandlers {
if e == h {
p.geometryHandlers = append(p.geometryHandlers[:i], p.geometryHandlers[i+1:]...)
break
}
}
}
type OutputModeEvent struct {
EventContext context.Context
Flags uint32
Width int32
Height int32
Refresh int32
}
type OutputModeHandler interface {
HandleOutputMode(OutputModeEvent)
}
func (p *Output) AddModeHandler(h OutputModeHandler) {
if h != nil {
p.mu.Lock()
p.modeHandlers = append(p.modeHandlers, h)
p.mu.Unlock()
}
}
func (p *Output) RemoveModeHandler(h OutputModeHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.modeHandlers {
if e == h {
p.modeHandlers = append(p.modeHandlers[:i], p.modeHandlers[i+1:]...)
break
}
}
}
type OutputDoneEvent struct {
EventContext context.Context
}
type OutputDoneHandler interface {
HandleOutputDone(OutputDoneEvent)
}
func (p *Output) AddDoneHandler(h OutputDoneHandler) {
if h != nil {
p.mu.Lock()
p.doneHandlers = append(p.doneHandlers, h)
p.mu.Unlock()
}
}
func (p *Output) RemoveDoneHandler(h OutputDoneHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.doneHandlers {
if e == h {
p.doneHandlers = append(p.doneHandlers[:i], p.doneHandlers[i+1:]...)
break
}
}
}
type OutputScaleEvent struct {
EventContext context.Context
Factor int32
}
type OutputScaleHandler interface {
HandleOutputScale(OutputScaleEvent)
}
func (p *Output) AddScaleHandler(h OutputScaleHandler) {
if h != nil {
p.mu.Lock()
p.scaleHandlers = append(p.scaleHandlers, h)
p.mu.Unlock()
}
}
func (p *Output) RemoveScaleHandler(h OutputScaleHandler) {
p.mu.Lock()
defer p.mu.Unlock()
for i, e := range p.scaleHandlers {
if e == h {
p.scaleHandlers = append(p.scaleHandlers[:i], p.scaleHandlers[i+1:]...)
break
}
}
}
func (p *Output) Dispatch(ctx context.Context, event *Event) {
switch event.Opcode {
case 0:
if len(p.geometryHandlers) > 0 {
ev := OutputGeometryEvent{}
ev.EventContext = ctx
ev.X = event.Int32()
ev.Y = event.Int32()
ev.PhysicalWidth = event.Int32()
ev.PhysicalHeight = event.Int32()
ev.Subpixel = event.Int32()
ev.Make = event.String()
ev.Model = event.String()
ev.Transform = event.Int32()
p.mu.RLock()
for _, h := range p.geometryHandlers {
h.HandleOutputGeometry(ev)
}
p.mu.RUnlock()
}
case 1:
if len(p.modeHandlers) > 0 {
ev := OutputModeEvent{}
ev.EventContext = ctx
ev.Flags = event.Uint32()
ev.Width = event.Int32()
ev.Height = event.Int32()
ev.Refresh = event.Int32()
p.mu.RLock()
for _, h := range p.modeHandlers {
h.HandleOutputMode(ev)
}
p.mu.RUnlock()
}
case 2:
if len(p.doneHandlers) > 0 {
ev := OutputDoneEvent{}
ev.EventContext = ctx
p.mu.RLock()
for _, h := range p.doneHandlers {
h.HandleOutputDone(ev)
}
p.mu.RUnlock()
}
case 3:
if len(p.scaleHandlers) > 0 {
ev := OutputScaleEvent{}
ev.EventContext = ctx
ev.Factor = event.Int32()
p.mu.RLock()
for _, h := range p.scaleHandlers {
h.HandleOutputScale(ev)
}
p.mu.RUnlock()
}
}
}
type Output struct {
BaseProxy
mu sync.RWMutex
geometryHandlers []OutputGeometryHandler
modeHandlers []OutputModeHandler
doneHandlers []OutputDoneHandler
scaleHandlers []OutputScaleHandler
}
func NewOutput(ctx *Context) *Output {
ret := new(Output)
ctx.Register(ret)
return ret
}
// Release will release the output object.
//
//
// Using this request a client can tell the server that it is not going to
// use the output object anymore.
//
func (p *Output) Release() error {
return p.Context().SendRequest(p, 0)
}
const (
OutputSubpixelUnknown = 0
OutputSubpixelNone = 1
OutputSubpixelHorizontalRgb = 2
OutputSubpixelHorizontalBgr = 3
OutputSubpixelVerticalRgb = 4
OutputSubpixelVerticalBgr = 5
)
const (
OutputTransformNormal = 0
OutputTransform90 = 1
OutputTransform180 = 2
OutputTransform270 = 3
OutputTransformFlipped = 4
OutputTransformFlipped90 = 5
OutputTransformFlipped180 = 6
OutputTransformFlipped270 = 7
)
const (
OutputModeCurrent = 0x1
OutputModePreferred = 0x2
)
type Region struct {
BaseProxy
}
func NewRegion(ctx *Context) *Region {
ret := new(Region)
ctx.Register(ret)
return ret
}
// Destroy will destroy region.
//
//
// Destroy the region. This will invalidate the object ID.
//
func (p *Region) Destroy() error {
return p.Context().SendRequest(p, 0)
}
// Add will add rectangle to region.
//
//
// Add the specified rectangle to the region.
//
func (p *Region) Add(x int32, y int32, width int32, height int32) error {
return p.Context().SendRequest(p, 1, x, y, width, height)
}
// Subtract will subtract rectangle from region.
//
//
// Subtract the specified rectangle from the region.
//
func (p *Region) Subtract(x int32, y int32, width int32, height int32) error {
return p.Context().SendRequest(p, 2, x, y, width, height)
}
type Subcompositor struct {
BaseProxy
}
func NewSubcompositor(ctx *Context) *Subcompositor {
ret := new(Subcompositor)
ctx.Register(ret)
return ret
}
// Destroy will unbind from the subcompositor interface.
//
//
// Informs the server that the client will not be using this
// protocol object anymore. This does not affect any other
// objects, wl_subsurface objects included.
//
func (p *Subcompositor) Destroy() error {
return p.Context().SendRequest(p, 0)
}
// GetSubsurface will give a surface the role sub-surface.
//
//
// Create a sub-surface interface for the given surface, and
// associate it with the given parent surface. This turns a
// plain wl_surface into a sub-surface.
//
// The to-be sub-surface must not already have another role, and it
// must not have an existing wl_subsurface object. Otherwise a protocol
// error is raised.
//
// Adding sub-surfaces to a parent is a double-buffered operation on the
// parent (see wl_surface.commit). The effect of adding a sub-surface
// becomes visible on the next time the state of the parent surface is
// applied.
//
// This request modifies the behaviour of wl_surface.commit request on
// the sub-surface, see the documentation on wl_subsurface interface.
//
func (p *Subcompositor) GetSubsurface(surface *Surface, parent *Surface) (*Subsurface, error) {
ret := NewSubsurface(p.Context())
return ret, p.Context().SendRequest(p, 1, Proxy(ret), surface, parent)
}
const (
SubcompositorErrorBadSurface = 0
)
type Subsurface struct {
BaseProxy
}
func NewSubsurface(ctx *Context) *Subsurface {
ret := new(Subsurface)
ctx.Register(ret)
return ret
}
// Destroy will remove sub-surface interface.
//
//
// The sub-surface interface is removed from the wl_surface object
// that was turned into a sub-surface with a
// wl_subcompositor.get_subsurface request. The wl_surface's association
// to the parent is deleted, and the wl_surface loses its role as
// a sub-surface. The wl_surface is unmapped immediately.
//
func (p *Subsurface) Destroy() error {
return p.Context().SendRequest(p, 0)
}
// SetPosition will reposition the sub-surface.
//
//
// This schedules a sub-surface position change.
// The sub-surface will be moved so that its origin (top left
// corner pixel) will be at the location x, y of the parent surface
// coordinate system. The coordinates are not restricted to the parent
// surface area. Negative values are allowed.
//
// The scheduled coordinates will take effect whenever the state of the
// parent surface is applied. When this happens depends on whether the
// parent surface is in synchronized mode or not. See
// wl_subsurface.set_sync and wl_subsurface.set_desync for details.
//
// If more than one set_position request is invoked by the client before
// the commit of the parent surface, the position of a new request always
// replaces the scheduled position from any previous request.
//
// The initial position is 0, 0.
//
func (p *Subsurface) SetPosition(x int32, y int32) error {
return p.Context().SendRequest(p, 1, x, y)
}
// PlaceAbove will restack the sub-surface.
//
//
// This sub-surface is taken from the stack, and put back just
// above the reference surface, changing the z-order of the sub-surfaces.
// The reference surface must be one of the sibling surfaces, or the
// parent surface. Using any other surface, including this sub-surface,
// will cause a protocol error.
//
// The z-order is double-buffered. Requests are handled in order and
// applied immediately to a pending state. The final pending state is
// copied to the active state the next time the state of the parent
// surface is applied. When this happens depends on whether the parent
// surface is in synchronized mode or not. See wl_subsurface.set_sync and
// wl_subsurface.set_desync for details.
//
// A new sub-surface is initially added as the top-most in the stack
// of its siblings and parent.
//
func (p *Subsurface) PlaceAbove(sibling *Surface) error {
return p.Context().SendRequest(p, 2, sibling)
}
// PlaceBelow will restack the sub-surface.
//
//
// The sub-surface is placed just below the reference surface.
// See wl_subsurface.place_above.
//
func (p *Subsurface) PlaceBelow(sibling *Surface) error {
return p.Context().SendRequest(p, 3, sibling)
}
// SetSync will set sub-surface to synchronized mode.
//
//
// Change the commit behaviour of the sub-surface to synchronized
// mode, also described as the parent dependent mode.
//
// In synchronized mode, wl_surface.commit on a sub-surface will
// accumulate the committed state in a cache, but the state will
// not be applied and hence will not change the compositor output.
// The cached state is applied to the sub-surface immediately after
// the parent surface's state is applied. This ensures atomic
// updates of the parent and all its synchronized sub-surfaces.
// Applying the cached state will invalidate the cache, so further
// parent surface commits do not (re-)apply old state.
//
// See wl_subsurface for the recursive effect of this mode.
//
func (p *Subsurface) SetSync() error {
return p.Context().SendRequest(p, 4)
}
// SetDesync will set sub-surface to desynchronized mode.
//
//
// Change the commit behaviour of the sub-surface to desynchronized
// mode, also described as independent or freely running mode.
//
// In desynchronized mode, wl_surface.commit on a sub-surface will
// apply the pending state directly, without caching, as happens
// normally with a wl_surface. Calling wl_surface.commit on the
// parent surface has no effect on the sub-surface's wl_surface
// state. This mode allows a sub-surface to be updated on its own.
//
// If cached state exists when wl_surface.commit is called in
// desynchronized mode, the pending state is added to the cached
// state, and applied as a whole. This invalidates the cache.
//
// Note: even if a sub-surface is set to desynchronized, a parent
// sub-surface may override it to behave as synchronized. For details,
// see wl_subsurface.
//
// If a surface's parent surface behaves as desynchronized, then
// the cached state is applied on set_desync.
//
func (p *Subsurface) SetDesync() error {
return p.Context().SendRequest(p, 5)
}
const (
SubsurfaceErrorBadSurface = 0
)
|