mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-27 15:13:13 -04:00
Compare commits
1332 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27e17e3f29 | ||
|
|
56fde0791b | ||
|
|
4ef144b519 | ||
|
|
7fe8c206ae | ||
|
|
fb78ecbb03 | ||
|
|
850d5f59a7 | ||
|
|
81b2729765 | ||
|
|
c4afadbfab | ||
|
|
b5252f1366 | ||
|
|
f93a223da9 | ||
|
|
d75a0dada0 | ||
|
|
9bf46af6f7 | ||
|
|
464c37a94e | ||
|
|
557d285170 | ||
|
|
ba856e127a | ||
|
|
0ffd303db6 | ||
|
|
5a74bf0aab | ||
|
|
117ec364f9 | ||
|
|
9f789e56ee | ||
|
|
91558169d2 | ||
|
|
4998cb990f | ||
|
|
98692641c4 | ||
|
|
a630b5333c | ||
|
|
ca7735f10b | ||
|
|
7adb805011 | ||
|
|
a8c7d809b9 | ||
|
|
4d81f4aa62 | ||
|
|
4f29aed5ee | ||
|
|
7864d02077 | ||
|
|
0f2d59cbba | ||
|
|
f0c4adc58c | ||
|
|
8e38112ad3 | ||
|
|
6f3d763650 | ||
|
|
7a11ff8766 | ||
|
|
211ae8f6c7 | ||
|
|
0b6b794f01 | ||
|
|
5e2f421e34 | ||
|
|
41f4265957 | ||
|
|
c535968128 | ||
|
|
85ff2fa093 | ||
|
|
44865be79d | ||
|
|
f3fb2fe3a6 | ||
|
|
fa10ca1764 | ||
|
|
4fda048729 | ||
|
|
983e50971d | ||
|
|
cf9daedb18 | ||
|
|
5218e11e55 | ||
|
|
b8f28efd04 | ||
|
|
eced28824b | ||
|
|
b3c7635bba | ||
|
|
4aac778d2a | ||
|
|
043c8635a9 | ||
|
|
da6220060e | ||
|
|
50f9b84f6b | ||
|
|
56333064ac | ||
|
|
de78ffdfed | ||
|
|
2d56ed1099 | ||
|
|
7b1dd52ad1 | ||
|
|
6a46610632 | ||
|
|
27233f575f | ||
|
|
f2ba68771f | ||
|
|
cc23fbf3be | ||
|
|
c98d880a1c | ||
|
|
165c163f01 | ||
|
|
0a59e4b905 | ||
|
|
d837c88855 | ||
|
|
82eab465e0 | ||
|
|
a9c189a423 | ||
|
|
9d9d21cfdb | ||
|
|
779f52a21f | ||
|
|
7a21858d29 | ||
|
|
a3f7e6566a | ||
|
|
f41897cfa4 | ||
|
|
bd6fef1d80 | ||
|
|
42d256e926 | ||
|
|
03dad26c43 | ||
|
|
1e7ab0cd25 | ||
|
|
c333003514 | ||
|
|
10f21090ce | ||
|
|
5575f51483 | ||
|
|
2ede84ab2f | ||
|
|
f046e778aa | ||
|
|
ffcdf80192 | ||
|
|
b811e9d878 | ||
|
|
d815bc089c | ||
|
|
66283a79bd | ||
|
|
3be30affe4 | ||
|
|
a68f1a664b | ||
|
|
6de5041a94 | ||
|
|
014fb68a26 | ||
|
|
9a03dacbde | ||
|
|
4d9302b33c | ||
|
|
488c036a05 | ||
|
|
a4af50ec13 | ||
|
|
317d62fb93 | ||
|
|
b13b39aa0b | ||
|
|
abea6e64e4 | ||
|
|
d6f7a28499 | ||
|
|
bd98561b38 | ||
|
|
ca6f523924 | ||
|
|
d7fdfb1bca | ||
|
|
120f21a010 | ||
|
|
5904529ba1 | ||
|
|
e7a6034b55 | ||
|
|
eb66c25980 | ||
|
|
0ccb8a9f87 | ||
|
|
abed32eb80 | ||
|
|
08907148ec | ||
|
|
fa0795a50c | ||
|
|
fe1eab07ae | ||
|
|
552c7a6252 | ||
|
|
50c0180af3 | ||
|
|
4f33643509 | ||
|
|
0b21c55b72 | ||
|
|
e1bccb68d8 | ||
|
|
e540062ac0 | ||
|
|
f1e0f6c646 | ||
|
|
3218316420 | ||
|
|
2900ecab93 | ||
|
|
3a84da6951 | ||
|
|
478427b0bd | ||
|
|
b0f26c79ff | ||
|
|
969237f422 | ||
|
|
e542a78deb | ||
|
|
2d4b9938f0 | ||
|
|
8ad016362a | ||
|
|
5f2c7350e9 | ||
|
|
256bbe949e | ||
|
|
1126e9ea2f | ||
|
|
927af44aa4 | ||
|
|
0adc0898f0 | ||
|
|
3b986f5583 | ||
|
|
b1f8d778a1 | ||
|
|
04482d5a2e | ||
|
|
3e50911adb | ||
|
|
f51a470872 | ||
|
|
47b938dbe7 | ||
|
|
e2b883d215 | ||
|
|
38fd3c6a99 | ||
|
|
5190472bee | ||
|
|
eab03dca80 | ||
|
|
59e3dda89f | ||
|
|
c846f67bcb | ||
|
|
03c01e038b | ||
|
|
ed4ebd4242 | ||
|
|
b5921d89f2 | ||
|
|
b5a6a4e616 | ||
|
|
9598eb371c | ||
|
|
634b9baea2 | ||
|
|
cf5e422dc8 | ||
|
|
276597e009 | ||
|
|
c0b737de4a | ||
|
|
79fa4061cb | ||
|
|
056421546a | ||
|
|
b4c5b76155 | ||
|
|
c8b9a86885 | ||
|
|
fe2df61884 | ||
|
|
446482367b | ||
|
|
cbb29ab526 | ||
|
|
a491c2abed | ||
|
|
3142355417 | ||
|
|
3493a20173 | ||
|
|
bf0bde8067 | ||
|
|
519947463f | ||
|
|
8c36ed4900 | ||
|
|
7b2c9d42b4 | ||
|
|
587ade844d | ||
|
|
6756549ac9 | ||
|
|
17666e3171 | ||
|
|
f6ca06cd58 | ||
|
|
e634cc609f | ||
|
|
aa83726c72 | ||
|
|
1800fa1670 | ||
|
|
a5e6d0aaaf | ||
|
|
4fe4ce3d77 | ||
|
|
078c4c0c4f | ||
|
|
c8579a1882 | ||
|
|
ab96fa8395 | ||
|
|
6461cfa9b1 | ||
|
|
6c214e71ae | ||
|
|
ecc884ac91 | ||
|
|
24e2c6914a | ||
|
|
ed4d70fdd4 | ||
|
|
07c25b9703 | ||
|
|
cdbdd974fb | ||
|
|
7e13248be3 | ||
|
|
b15a40cd14 | ||
|
|
8db4a9cc61 | ||
|
|
a4ab7dc64c | ||
|
|
afb731bb52 | ||
|
|
ef37b1d5dd | ||
|
|
2b4e8ef916 | ||
|
|
ae28eea406 | ||
|
|
a0464ae83b | ||
|
|
16d5f46db1 | ||
|
|
5cada36ae8 | ||
|
|
b3dcfa1275 | ||
|
|
f1c5afd84e | ||
|
|
be1baf164c | ||
|
|
39c0862198 | ||
|
|
aa8ebdc795 | ||
|
|
ea68916055 | ||
|
|
e26b831f23 | ||
|
|
8c3e69c08b | ||
|
|
46879429ed | ||
|
|
0c89ea7386 | ||
|
|
6c0e3c3b15 | ||
|
|
675582bd46 | ||
|
|
4d6fe7e35c | ||
|
|
f9912baf09 | ||
|
|
f290619dce | ||
|
|
23011c6b0a | ||
|
|
3a39a6ddb0 | ||
|
|
90cf9a3398 | ||
|
|
05d8fa0b91 | ||
|
|
d7d20507ed | ||
|
|
f6e66a71f8 | ||
|
|
c09160d1a8 | ||
|
|
2230e71093 | ||
|
|
5e6350d142 | ||
|
|
a6998af997 | ||
|
|
5c48ec7977 | ||
|
|
953d9b4268 | ||
|
|
f5dcd2aabe | ||
|
|
77f1c73f06 | ||
|
|
24c226416e | ||
|
|
69382fda9a | ||
|
|
ee245c569d | ||
|
|
5462f27dda | ||
|
|
927deb030f | ||
|
|
5ea81efc74 | ||
|
|
6896de5b73 | ||
|
|
d736763216 | ||
|
|
e316a89847 | ||
|
|
f0d8689039 | ||
|
|
4d5e68c6e2 | ||
|
|
5835c9102e | ||
|
|
e47081e385 | ||
|
|
171d53c042 | ||
|
|
35379f305a | ||
|
|
4d2a0dd2b3 | ||
|
|
4a8b659228 | ||
|
|
f314cd2b9a | ||
|
|
3657506f6e | ||
|
|
edca3ebc41 | ||
|
|
ca46e29203 | ||
|
|
132fbe14d5 | ||
|
|
164bf85b5b | ||
|
|
cfa8f027cc | ||
|
|
2e5db75101 | ||
|
|
19e5bee3d1 | ||
|
|
fc6cf89ac0 | ||
|
|
dbcdb6f1b4 | ||
|
|
d0c6c34eaa | ||
|
|
f2688d94ea | ||
|
|
f6b20852bf | ||
|
|
59b1eb5410 | ||
|
|
f781e13166 | ||
|
|
9f8ac8feb5 | ||
|
|
74958ecc6f | ||
|
|
3a60cbaba5 | ||
|
|
ae4c449670 | ||
|
|
b2896d7408 | ||
|
|
edfb4b03f4 | ||
|
|
c8c1eca3c7 | ||
|
|
d3207a8d76 | ||
|
|
9d347b72d9 | ||
|
|
13bb51c7e0 | ||
|
|
bb4aa22cf9 | ||
|
|
3e9b80d47a | ||
|
|
c913cdab0b | ||
|
|
a5f5ce6a3d | ||
|
|
fb6b1d487b | ||
|
|
7d77ccfad3 | ||
|
|
c23bed20b8 | ||
|
|
8fe2b62adf | ||
|
|
4e3165f3d8 | ||
|
|
da2268ae22 | ||
|
|
eccd9e415d | ||
|
|
32cd1ad9a7 | ||
|
|
6e1b9fa24d | ||
|
|
380eea0072 | ||
|
|
a18658284c | ||
|
|
8ddd10a7f9 | ||
|
|
4f1c5b6129 | ||
|
|
7e819bb2ce | ||
|
|
dfea49f488 | ||
|
|
b674d20edf | ||
|
|
8db3e0e043 | ||
|
|
d37c591378 | ||
|
|
9419e4e1a7 | ||
|
|
241b7a80bb | ||
|
|
e716adcc0a | ||
|
|
aee95114db | ||
|
|
8f4a8efa99 | ||
|
|
1e1f0fd7e9 | ||
|
|
6e008b39e9 | ||
|
|
6c4da19197 | ||
|
|
a61e7bb4f4 | ||
|
|
7fbc2118b6 | ||
|
|
a96491f302 | ||
|
|
d96fd02f33 | ||
|
|
92e9bfe0fc | ||
|
|
3392e9c1de | ||
|
|
038ef5c3ad | ||
|
|
70c54ee0ff | ||
|
|
3bab4ef4fb | ||
|
|
58142680ce | ||
|
|
0ffcfd8a3a | ||
|
|
2e53533cc1 | ||
|
|
1168cd4113 | ||
|
|
9dff801f93 | ||
|
|
f07153b8e0 | ||
|
|
f5304815a1 | ||
|
|
29e1041987 | ||
|
|
15b79b18e1 | ||
|
|
54ff9c3bb5 | ||
|
|
546962c904 | ||
|
|
b7a7f59298 | ||
|
|
586255ac0a | ||
|
|
42ba0a74e0 | ||
|
|
34a37b8747 | ||
|
|
02a0a91a94 | ||
|
|
e3fbfb81d7 | ||
|
|
0909bf3d9d | ||
|
|
3398ebe467 | ||
|
|
21c121f9b3 | ||
|
|
ce0d1dfe1b | ||
|
|
7892e86731 | ||
|
|
7b0104b54c | ||
|
|
facb809f12 | ||
|
|
4e2e764e4a | ||
|
|
a0bc3e5dc8 | ||
|
|
2e97ab3d4f | ||
|
|
ef580b817d | ||
|
|
5ec934b1b0 | ||
|
|
c9c260ca08 | ||
|
|
b6109d4a17 | ||
|
|
eef2848c98 | ||
|
|
73c01fff96 | ||
|
|
88bbdb33da | ||
|
|
652ff7576c | ||
|
|
d741c58ac3 | ||
|
|
944ab60eda | ||
|
|
8e23d1608a | ||
|
|
dc99920612 | ||
|
|
ee3ab33a7c | ||
|
|
5b8f5cb54a | ||
|
|
bf97def398 | ||
|
|
d5fd8682eb | ||
|
|
39a7d5b738 | ||
|
|
2665c12098 | ||
|
|
936da131c2 | ||
|
|
850dd97177 | ||
|
|
1170554dbd | ||
|
|
75ce71f05a | ||
|
|
a0d69c782a | ||
|
|
2e93e48a3b | ||
|
|
82d9bbe559 | ||
|
|
8bdd4d620e | ||
|
|
9d5412ffe1 | ||
|
|
ecb887e5c3 | ||
|
|
7d1287958f | ||
|
|
c0c14aaf00 | ||
|
|
10dc0674bb | ||
|
|
4f59796e8a | ||
|
|
32097d75c7 | ||
|
|
c6c4395c3b | ||
|
|
38e6f9ad84 | ||
|
|
3e6092b8ed | ||
|
|
b4e83a5966 | ||
|
|
db2c97a995 | ||
|
|
1552eb21f7 | ||
|
|
d8ffd4bb26 | ||
|
|
34c15608e0 | ||
|
|
eef6977f45 | ||
|
|
078b46720b | ||
|
|
3b4e064a07 | ||
|
|
39bc139500 | ||
|
|
9522670081 | ||
|
|
9a1ef49dc3 | ||
|
|
3a624e0f52 | ||
|
|
279e3edc54 | ||
|
|
0e74d37ff5 | ||
|
|
2d1382f7d6 | ||
|
|
5d8091fc7f | ||
|
|
d7abe0316e | ||
|
|
5ea20fc905 | ||
|
|
e108fa2fbf | ||
|
|
fff6788c12 | ||
|
|
3e8fa41073 | ||
|
|
2b1c8cea1b | ||
|
|
ab33fb8eda | ||
|
|
b0b64a9a15 | ||
|
|
d5d202d60e | ||
|
|
cb39ab29f4 | ||
|
|
0a3cacd577 | ||
|
|
16fd2baba0 | ||
|
|
7f8771a362 | ||
|
|
337d50779c | ||
|
|
fd477986de | ||
|
|
94664ff687 | ||
|
|
0fc8c37721 | ||
|
|
ec29c81ad2 | ||
|
|
304a585493 | ||
|
|
1682703b5c | ||
|
|
bdd80c8af2 | ||
|
|
7b0c7b6cb2 | ||
|
|
7006c7ceca | ||
|
|
2491f2bbd6 | ||
|
|
babbb715c5 | ||
|
|
be79e8979a | ||
|
|
9ab4c03e89 | ||
|
|
4f47a4e793 | ||
|
|
c15fa6e433 | ||
|
|
24faacf497 | ||
|
|
080556f2c8 | ||
|
|
259e868c05 | ||
|
|
575d978202 | ||
|
|
7dd7dc1fc8 | ||
|
|
df7c496a5d | ||
|
|
0086d7153b | ||
|
|
b79acd8a5a | ||
|
|
c2951e0194 | ||
|
|
8998e36994 | ||
|
|
5a7169c7a6 | ||
|
|
4cd6877e8e | ||
|
|
44aabdddcc | ||
|
|
c4415009c0 | ||
|
|
63a7c02492 | ||
|
|
7b0ef160fc | ||
|
|
962241e2a0 | ||
|
|
3efa6d855d | ||
|
|
9067426dca | ||
|
|
ba10c35240 | ||
|
|
baf10de958 | ||
|
|
c10f9c32d3 | ||
|
|
975cf068c7 | ||
|
|
8e69a8fa40 | ||
|
|
fedb944d57 | ||
|
|
a63b04385a | ||
|
|
06f4e28de9 | ||
|
|
249d5d8bff | ||
|
|
66df2c22ba | ||
|
|
359a38844b | ||
|
|
563b0bf5e3 | ||
|
|
b2f9fad654 | ||
|
|
4ade1a7518 | ||
|
|
e06ecf4d72 | ||
|
|
4a8050289d | ||
|
|
99e238065e | ||
|
|
d123cd2f8e | ||
|
|
fc8a008b25 | ||
|
|
f6f1c45a72 | ||
|
|
388c40b1e0 | ||
|
|
7a40aa43dc | ||
|
|
944347696a | ||
|
|
96172693fe | ||
|
|
32004405ee | ||
|
|
22e932b5ab | ||
|
|
3d4c53459a | ||
|
|
f0b4889227 | ||
|
|
c81448e0b8 | ||
|
|
f498ff0369 | ||
|
|
c4e6e94b80 | ||
|
|
a5dbd3ee52 | ||
|
|
a4480a0652 | ||
|
|
e41f0eabb1 | ||
|
|
7e28d7615e | ||
|
|
010787a430 | ||
|
|
352e70b8ac | ||
|
|
990bbf178f | ||
|
|
97cfdd4b09 | ||
|
|
a127bd6f66 | ||
|
|
4a8648be57 | ||
|
|
a8c7109e89 | ||
|
|
7abd427216 | ||
|
|
3fb93b4f83 | ||
|
|
19190a95a0 | ||
|
|
c4310af83c | ||
|
|
542d1938ce | ||
|
|
31f8b816bd | ||
|
|
e61a7320a2 | ||
|
|
db41938deb | ||
|
|
2bc1943188 | ||
|
|
385c4b3c88 | ||
|
|
ea70f773d3 | ||
|
|
83012f4c1c | ||
|
|
6825fed073 | ||
|
|
273984a385 | ||
|
|
dbe0f852da | ||
|
|
d1902aa15a | ||
|
|
4112fccc12 | ||
|
|
bd6ce32860 | ||
|
|
8936fe1acd | ||
|
|
fedb86ea5a | ||
|
|
20687fef1c | ||
|
|
56035e1f13 | ||
|
|
08fc4099e8 | ||
|
|
4d4d6e5052 | ||
|
|
cf5f4de19e | ||
|
|
21df84b7f4 | ||
|
|
dd13ccda4c | ||
|
|
df8805c0d2 | ||
|
|
db1ca45a17 | ||
|
|
ff731197dc | ||
|
|
f526a47152 | ||
|
|
f204467838 | ||
|
|
6641dfa412 | ||
|
|
c1168b4f58 | ||
|
|
f8b7c4b78f | ||
|
|
3830b492c4 | ||
|
|
8862ce0163 | ||
|
|
569c44a632 | ||
|
|
ef2ec904ce | ||
|
|
98d3391f2d | ||
|
|
d0a1917603 | ||
|
|
b36d8d1e52 | ||
|
|
a5b08fc48c | ||
|
|
0482d9cfce | ||
|
|
10a785019c | ||
|
|
0cc19716f3 | ||
|
|
572d7ee77c | ||
|
|
b0c59c8416 | ||
|
|
d7c7ba1d6c | ||
|
|
aec608f93c | ||
|
|
d1717b6a01 | ||
|
|
6b29253797 | ||
|
|
30775f4982 | ||
|
|
41070d7c67 | ||
|
|
6df972d108 | ||
|
|
73910d20cc | ||
|
|
16d860736b | ||
|
|
2ee44246ae | ||
|
|
14b418a3a7 | ||
|
|
c86b0daf7f | ||
|
|
40b61d2d92 | ||
|
|
22311802b5 | ||
|
|
169cd39f93 | ||
|
|
bdeb2574dc | ||
|
|
4fe38d8067 | ||
|
|
816798bfd1 | ||
|
|
f99c810bec | ||
|
|
d39528aa69 | ||
|
|
787b2d7362 | ||
|
|
37b6243289 | ||
|
|
8ea1da7879 | ||
|
|
b1209bc253 | ||
|
|
021fd23c34 | ||
|
|
dd127463c5 | ||
|
|
ac247cd081 | ||
|
|
ea1bfd254d | ||
|
|
178f5fda05 | ||
|
|
42dbc4748e | ||
|
|
8b3de7cedf | ||
|
|
8b0ffb7e7d | ||
|
|
c55a2c779b | ||
|
|
c5a422eed6 | ||
|
|
1893b0ec42 | ||
|
|
5e106b4dbb | ||
|
|
5a1d3e4656 | ||
|
|
8f6de4ef4b | ||
|
|
ad1843aea6 | ||
|
|
ca1674519a | ||
|
|
f78edc7ef1 | ||
|
|
4f295e0c94 | ||
|
|
658f49b014 | ||
|
|
34e42ff94d | ||
|
|
ba654bb61e | ||
|
|
f5c691467b | ||
|
|
a87cfb62c3 | ||
|
|
25d6a1d46d | ||
|
|
e0fea25b06 | ||
|
|
843d7904d6 | ||
|
|
28a811bbba | ||
|
|
61a873d79a | ||
|
|
be4a660011 | ||
|
|
34dd2cdba9 | ||
|
|
775c8ece70 | ||
|
|
c12c7b82e8 | ||
|
|
8cc5cb9d9b | ||
|
|
9a28bb4b49 | ||
|
|
4f6fd44c6c | ||
|
|
5a43ea8cd6 | ||
|
|
e9a25a4c91 | ||
|
|
674657efb6 | ||
|
|
7d5bee767c | ||
|
|
745cfaab2c | ||
|
|
a8f49dc8ef | ||
|
|
e5310ade08 | ||
|
|
37946e0a3a | ||
|
|
86b737f5e7 | ||
|
|
e37585e5bc | ||
|
|
4aeeb24745 | ||
|
|
8cd3aaa8a2 | ||
|
|
2c15de7cf9 | ||
|
|
0a7ea61834 | ||
|
|
4ee11018c2 | ||
|
|
4f669ebbd2 | ||
|
|
7761b2b16c | ||
|
|
ae41e3265f | ||
|
|
8702a09333 | ||
|
|
8b5c84f404 | ||
|
|
a676d0018b | ||
|
|
04ca85a909 | ||
|
|
cc33212479 | ||
|
|
f2c5127f27 | ||
|
|
af93167237 | ||
|
|
7f6b16a6af | ||
|
|
bf5806a9b2 | ||
|
|
2a9c593e01 | ||
|
|
becdd0dbd2 | ||
|
|
3eea505440 | ||
|
|
b863283c38 | ||
|
|
73718c9f2f | ||
|
|
f735f028a1 | ||
|
|
da947992ac | ||
|
|
e9784127df | ||
|
|
0be2bb0a8c | ||
|
|
075996b1fa | ||
|
|
a7241b3db3 | ||
|
|
17296e9878 | ||
|
|
b3c87caa7c | ||
|
|
81a1d9c396 | ||
|
|
5612626944 | ||
|
|
d3ca685b77 | ||
|
|
7bed5eecfd | ||
|
|
14140607d1 | ||
|
|
eab982c402 | ||
|
|
21701a33de | ||
|
|
c89e6df758 | ||
|
|
e9210555c1 | ||
|
|
0994b5ceb8 | ||
|
|
bcce5134e1 | ||
|
|
d333dd8664 | ||
|
|
52af1b4a77 | ||
|
|
3c9f9da19e | ||
|
|
075dfcea19 | ||
|
|
92b7dcccc1 | ||
|
|
5a3be586f4 | ||
|
|
12dbbf8012 | ||
|
|
53ca5af48f | ||
|
|
c235bd154a | ||
|
|
f4e71a1d9c | ||
|
|
62ed51a138 | ||
|
|
b2a2ec91ae | ||
|
|
d37d1a03b2 | ||
|
|
772b21ce09 | ||
|
|
2edcd09704 | ||
|
|
d35c3bea42 | ||
|
|
89a184ed84 | ||
|
|
36d4907da8 | ||
|
|
98b3508aca | ||
|
|
c0db53a516 | ||
|
|
52b7205b75 | ||
|
|
41dbbc27a0 | ||
|
|
c346fb7e61 | ||
|
|
6a041f84ba | ||
|
|
acfeff5327 | ||
|
|
b9e1e96eaa | ||
|
|
880238a24f | ||
|
|
f5b4d6938f | ||
|
|
c65e2247a1 | ||
|
|
801fddbfcf | ||
|
|
3ad64fb811 | ||
|
|
9bf4493a21 | ||
|
|
48f6582eb4 | ||
|
|
ef34692148 | ||
|
|
c48116a8fd | ||
|
|
b938fe9df5 | ||
|
|
b7e3649e8b | ||
|
|
844269d017 | ||
|
|
e41fac825c | ||
|
|
bbeacc46d5 | ||
|
|
61581ebb4f | ||
|
|
93f1000a05 | ||
|
|
1ea41a2ee2 | ||
|
|
42c9b7e40e | ||
|
|
0960635895 | ||
|
|
789a497980 | ||
|
|
fac6110cb6 | ||
|
|
0363be4776 | ||
|
|
f5dd1c008c | ||
|
|
48a1e84906 | ||
|
|
ee0db52ac4 | ||
|
|
c7cf0cfd83 | ||
|
|
8393d98940 | ||
|
|
af247eac0f | ||
|
|
b2b4564a5f | ||
|
|
cb58c49a90 | ||
|
|
ffb46dd61f | ||
|
|
8c8fb39fcd | ||
|
|
2422ea39d0 | ||
|
|
878d832d24 | ||
|
|
e2e01e1fc6 | ||
|
|
c8b685ddbc | ||
|
|
f10ae52385 | ||
|
|
e731041c15 | ||
|
|
9df7fc47a1 | ||
|
|
992aeb0ca0 | ||
|
|
0caba93b51 | ||
|
|
c00c1e9eb7 | ||
|
|
83950acd5a | ||
|
|
b99403b1b9 | ||
|
|
4f0ce7201d | ||
|
|
e648169861 | ||
|
|
8fdd81ecef | ||
|
|
7a2a2341c2 | ||
|
|
d68d9eab38 | ||
|
|
a06ea45c0f | ||
|
|
67b041e231 | ||
|
|
6dfc78fb50 | ||
|
|
477619c0a7 | ||
|
|
5f1a4b65ad | ||
|
|
bb9b629bc3 | ||
|
|
0c8cf94a70 | ||
|
|
1dfca5a395 | ||
|
|
7541220a41 | ||
|
|
7e11912d22 | ||
|
|
86baa1c99a | ||
|
|
d9f04780cc | ||
|
|
67d3fd28f7 | ||
|
|
a3cba838ea | ||
|
|
48abf52aac | ||
|
|
68ef9f707e | ||
|
|
9979441c82 | ||
|
|
309e6aa85a | ||
|
|
8b8556798e | ||
|
|
2d96480a89 | ||
|
|
6caff77abb | ||
|
|
af6c343d0e | ||
|
|
119462795a | ||
|
|
f801c4a00b | ||
|
|
f9758528f6 | ||
|
|
778d70c001 | ||
|
|
dc973883c9 | ||
|
|
2233edb9a0 | ||
|
|
bd2f1e8312 | ||
|
|
e9ebf1e5f4 | ||
|
|
5f7955cb2b | ||
|
|
793c535b01 | ||
|
|
ed26dd58fd | ||
|
|
584aab4cd0 | ||
|
|
8100a6a584 | ||
|
|
cad3277550 | ||
|
|
3c3a863cc9 | ||
|
|
8a7e18aaf0 | ||
|
|
57fad2ce15 | ||
|
|
7a58fe58ce | ||
|
|
38f28d5836 | ||
|
|
189a0080a6 | ||
|
|
b5aa96bea4 | ||
|
|
19e3906369 | ||
|
|
9ac3259a79 | ||
|
|
2b2dd6b65d | ||
|
|
75173118b0 | ||
|
|
e33d2bee6c | ||
|
|
ae7497e18f | ||
|
|
935146d299 | ||
|
|
755c533b08 | ||
|
|
ae9b02e097 | ||
|
|
e6c7cc297d | ||
|
|
b74cee8df1 | ||
|
|
e5eb253698 | ||
|
|
ec11b4877f | ||
|
|
9e46dffcc5 | ||
|
|
7501039d57 | ||
|
|
289ce32d77 | ||
|
|
0d366ffbda | ||
|
|
a6f414d732 | ||
|
|
c47d0846fa | ||
|
|
461efaf99f | ||
|
|
420840278b | ||
|
|
f5e73b0af4 | ||
|
|
f40b5f0dad | ||
|
|
c91402efb9 | ||
|
|
43acf7f42f | ||
|
|
c62e64060b | ||
|
|
f7a84a5b50 | ||
|
|
89aa7cc06e | ||
|
|
b166e1ff13 | ||
|
|
97434d8d80 | ||
|
|
06fb089633 | ||
|
|
4d6dbea74c | ||
|
|
c5941d105f | ||
|
|
b63164645b | ||
|
|
5b5ebc25d8 | ||
|
|
d7ec899d69 | ||
|
|
5379d60e4d | ||
|
|
44e2f95331 | ||
|
|
3b2d1a7643 | ||
|
|
50b17a3907 | ||
|
|
af26f01b95 | ||
|
|
c4d70d75c1 | ||
|
|
db8de03142 | ||
|
|
ff0ce9d065 | ||
|
|
42e492cde8 | ||
|
|
5e0e1e96bc | ||
|
|
bd890e69aa | ||
|
|
bca57ed0b4 | ||
|
|
4652d48105 | ||
|
|
96c0b267e2 | ||
|
|
81fd39485f | ||
|
|
6178acede8 | ||
|
|
a320702a71 | ||
|
|
b0106898f7 | ||
|
|
924f3323b5 | ||
|
|
b97df599c5 | ||
|
|
0defd747c8 | ||
|
|
e23186db8e | ||
|
|
059abb06fc | ||
|
|
bc216b8f67 | ||
|
|
864a1d5924 | ||
|
|
05444628e6 | ||
|
|
66ff52b012 | ||
|
|
7929999c1c | ||
|
|
7094a223af | ||
|
|
b2a46d0439 | ||
|
|
4748890935 | ||
|
|
6300cf915e | ||
|
|
9a9c9b15ba | ||
|
|
7ce86c3d2a | ||
|
|
a444637b18 | ||
|
|
f0d88c52a3 | ||
|
|
e17977d7c7 | ||
|
|
a7a8ff0bbb | ||
|
|
fc046add78 | ||
|
|
ab4a4a89e6 | ||
|
|
f7a400ddf6 | ||
|
|
07d39abddd | ||
|
|
0c8bf25ae4 | ||
|
|
b5785ba785 | ||
|
|
9797ed86f0 | ||
|
|
e220a75556 | ||
|
|
29d3729ac8 | ||
|
|
4a36741f9c | ||
|
|
ab46aa5b79 | ||
|
|
12fb37d827 | ||
|
|
c88a4ab221 | ||
|
|
8f7f3efc0d | ||
|
|
eb2d3894ef | ||
|
|
3f4f580181 | ||
|
|
d3aeff8838 | ||
|
|
0786d534f4 | ||
|
|
b4b2389d0a | ||
|
|
964e342f69 | ||
|
|
a134a59917 | ||
|
|
fbba203c4a | ||
|
|
61bd8b8254 | ||
|
|
587fa67571 | ||
|
|
7500a88230 | ||
|
|
82d0380ea6 | ||
|
|
642ce2bfa7 | ||
|
|
5bbe87960e | ||
|
|
cf77f82ae3 | ||
|
|
72cf4e577f | ||
|
|
4f3eacf01e | ||
|
|
31ebc5caf4 | ||
|
|
d273518ce9 | ||
|
|
2ade772ab0 | ||
|
|
4ac2006cbc | ||
|
|
ba5ad3be13 | ||
|
|
8092fa2440 | ||
|
|
8bb004a1d9 | ||
|
|
de5327477a | ||
|
|
8f959714cc | ||
|
|
035eebb19a | ||
|
|
b5af6bb266 | ||
|
|
1805124c54 | ||
|
|
0f64589dba | ||
|
|
5438a2a524 | ||
|
|
918430979f | ||
|
|
f3f46cb3f6 | ||
|
|
3c3be71a77 | ||
|
|
a7986b077f | ||
|
|
8a0edde5c8 | ||
|
|
a9e168e10d | ||
|
|
bd9cc2a9da | ||
|
|
596c0edf0f | ||
|
|
92592ec605 | ||
|
|
25c4e2e451 | ||
|
|
ad52c72e41 | ||
|
|
d15feb5cfa | ||
|
|
9938327066 | ||
|
|
f980ed7b83 | ||
|
|
2496098890 | ||
|
|
60e91b187a | ||
|
|
2486f0f1a1 | ||
|
|
fbea75d31f | ||
|
|
d4c9535af9 | ||
|
|
f0fcb346b0 | ||
|
|
77f8e511e9 | ||
|
|
3217eaa416 | ||
|
|
b18295a1ce | ||
|
|
fb9695d56d | ||
|
|
08bdca19b1 | ||
|
|
79ac236721 | ||
|
|
b870a11a99 | ||
|
|
2af1550bbb | ||
|
|
ed796dcd15 | ||
|
|
a006cd7dc8 | ||
|
|
a31f71ee07 | ||
|
|
0f89aac9f6 | ||
|
|
82df9531f4 | ||
|
|
265152355e | ||
|
|
37c0f615cf | ||
|
|
5ba6bdef49 | ||
|
|
69d6076310 | ||
|
|
7029ce6ecd | ||
|
|
1eb1a13a77 | ||
|
|
3fd73848dd | ||
|
|
4e1c46fe9e | ||
|
|
180a4c7a16 | ||
|
|
13613931cf | ||
|
|
483c1d40ae | ||
|
|
1b4045dcb2 | ||
|
|
8f8da0f8bb | ||
|
|
23b821285c | ||
|
|
c984476687 | ||
|
|
42c395e49d | ||
|
|
422c6b1987 | ||
|
|
b457329003 | ||
|
|
930df0ec45 | ||
|
|
e1b7fda409 | ||
|
|
e423802ed3 | ||
|
|
a82f66826b | ||
|
|
0f2fbe373b | ||
|
|
7341ee80ea | ||
|
|
d448d3e14f | ||
|
|
a867032e1e | ||
|
|
b711a11549 | ||
|
|
809162fbd0 | ||
|
|
de782504ab | ||
|
|
1886949efe | ||
|
|
b1a5fae1f5 | ||
|
|
a88d2e079d | ||
|
|
067535eb38 | ||
|
|
7d626d9dfd | ||
|
|
62ce14a013 | ||
|
|
6f60c7a6cc | ||
|
|
6cf0bf76da | ||
|
|
9225b2812e | ||
|
|
08ce3af3e1 | ||
|
|
490abcad14 | ||
|
|
4b22ca8daf | ||
|
|
66ca445caa | ||
|
|
2f52c23fa9 | ||
|
|
ee88e38f13 | ||
|
|
5e77d70245 | ||
|
|
58ec458877 | ||
|
|
94e4c394e7 | ||
|
|
f43ce2a131 | ||
|
|
402cbd55f9 | ||
|
|
da7422c6e1 | ||
|
|
8934d2765d | ||
|
|
89eea64a4a | ||
|
|
9f781bc422 | ||
|
|
4ed4e918f3 | ||
|
|
2e4d79f57a | ||
|
|
bf92f3e97b | ||
|
|
2a58b785fe | ||
|
|
32784af3c4 | ||
|
|
94688a62f0 | ||
|
|
28e34c2e1b | ||
|
|
9ae7498a8a | ||
|
|
1786c877ec | ||
|
|
101ac8908c | ||
|
|
ba4bf03675 | ||
|
|
a63b066ed5 | ||
|
|
f77f858e9b | ||
|
|
6d0cf6a275 | ||
|
|
12df8b6c0c | ||
|
|
65baae75c4 | ||
|
|
418cc44e93 | ||
|
|
ce6c6e8c95 | ||
|
|
bdcbd7d1f9 | ||
|
|
05484c5888 | ||
|
|
50bbc85dc3 | ||
|
|
8669c2e8df | ||
|
|
97d4c7b303 | ||
|
|
08f9e374e0 | ||
|
|
a7a7cc64cd | ||
|
|
04d9e081b8 | ||
|
|
8fc24c959a | ||
|
|
2fb15dbe8a | ||
|
|
92fdf5ba85 | ||
|
|
4f06cfcf5b | ||
|
|
462bb4d324 | ||
|
|
f6ca8515ab | ||
|
|
71094e5703 | ||
|
|
bb0f965c57 | ||
|
|
4d48c76da9 | ||
|
|
fafdedfb7d | ||
|
|
25b129362f | ||
|
|
48b843e42d | ||
|
|
58f2455aa9 | ||
|
|
155f1f9720 | ||
|
|
3b56b0e76f | ||
|
|
5d2aca90bd | ||
|
|
ba49db2cb9 | ||
|
|
a4695c5397 | ||
|
|
92ddb3483e | ||
|
|
fec52b028e | ||
|
|
d8c0ee733b | ||
|
|
fb248eaadc | ||
|
|
da7bf8e29b | ||
|
|
a6a8b12537 | ||
|
|
340f951d10 | ||
|
|
05dd31b8ea | ||
|
|
0fca8b088d | ||
|
|
ab56e9f57d | ||
|
|
97d2aaa953 | ||
|
|
29419d6c38 | ||
|
|
e517e468f8 | ||
|
|
d67c928120 | ||
|
|
112965b4ff | ||
|
|
e0018d0710 | ||
|
|
1ca8b65e85 | ||
|
|
a43a15b4a0 | ||
|
|
66aa6c945d | ||
|
|
dfecdc5762 | ||
|
|
8729119536 | ||
|
|
ec7e935248 | ||
|
|
fd72000a9a | ||
|
|
e91ee811cb | ||
|
|
b3b80166ce | ||
|
|
f9b41fd819 | ||
|
|
0d9c39029c | ||
|
|
da2cef97a3 | ||
|
|
76f158d310 | ||
|
|
2e4338bb8d | ||
|
|
ec2888b8b7 | ||
|
|
fa83bace12 | ||
|
|
ee7dc48e3b | ||
|
|
11d4a301e4 | ||
|
|
ad41eaf151 | ||
|
|
9b71df9f97 | ||
|
|
b1c9e4a6fa | ||
|
|
cdbaf4816a | ||
|
|
6b7ceedc91 | ||
|
|
c53a574bff | ||
|
|
95246d81c1 | ||
|
|
bf537009d9 | ||
|
|
50035643f7 | ||
|
|
64c22f9075 | ||
|
|
4895a29e92 | ||
|
|
6cdb3179c8 | ||
|
|
4fd52af682 | ||
|
|
5a0bad130d | ||
|
|
08d025968e | ||
|
|
1cd0e94c26 | ||
|
|
1ec976f95e | ||
|
|
f10ef5f331 | ||
|
|
653bc59813 | ||
|
|
3e991e13dc | ||
|
|
5397b53e04 | ||
|
|
f09259f6de | ||
|
|
430a49ebc2 | ||
|
|
1091a8ba1a | ||
|
|
9116b6c8cd | ||
|
|
990e34a129 | ||
|
|
472d7b9376 | ||
|
|
50dd7881b1 | ||
|
|
aa8f8db305 | ||
|
|
cdd9b1e1eb | ||
|
|
2d2ce70edc | ||
|
|
78f1d1df38 | ||
|
|
a06bb3f992 | ||
|
|
e289f30e5d | ||
|
|
4b10993970 | ||
|
|
d78a870e66 | ||
|
|
cb41c58f21 | ||
|
|
c55d97183d | ||
|
|
8646cbc9f5 | ||
|
|
64c1d4c5bb | ||
|
|
76b949c196 | ||
|
|
c93ef47b9b | ||
|
|
2b414cd825 | ||
|
|
ac42447459 | ||
|
|
401d20fa1f | ||
|
|
6b5b570b45 | ||
|
|
9e6f666616 | ||
|
|
8ef9fe44c7 | ||
|
|
3e0a544eb8 | ||
|
|
6474891f1e | ||
|
|
40abb526cc | ||
|
|
c532d910c0 | ||
|
|
44288f6280 | ||
|
|
eec84ade86 | ||
|
|
10419ff441 | ||
|
|
57981b533d | ||
|
|
c5eaa0ab69 | ||
|
|
2c01e9e747 | ||
|
|
4c39b3188c | ||
|
|
224872ce03 | ||
|
|
f10a984ba3 | ||
|
|
c7f7181388 | ||
|
|
92530299eb | ||
|
|
58cd23d1ac | ||
|
|
5d85c10a2c | ||
|
|
f11270dac0 | ||
|
|
bcd76d4718 | ||
|
|
4dd2b66aaa | ||
|
|
829a140d9b | ||
|
|
f04fa5d54f | ||
|
|
b4175c1454 | ||
|
|
0728105b2b | ||
|
|
ea09d1d10e | ||
|
|
e7f88588bf | ||
|
|
ce890c3455 | ||
|
|
cbba00d360 | ||
|
|
bf366cb99d | ||
|
|
142d55ff24 | ||
|
|
a58400a82c | ||
|
|
aac28d24ac | ||
|
|
d624a3e648 | ||
|
|
c57294b41a | ||
|
|
485e82dcb1 | ||
|
|
e8d910ffd3 | ||
|
|
ab1f636960 | ||
|
|
52c4670237 | ||
|
|
2ae12fb0a0 | ||
|
|
6c1d3c4fd8 | ||
|
|
08de2b3fc4 | ||
|
|
945a9e3122 | ||
|
|
6e28ba8927 | ||
|
|
7369551c02 | ||
|
|
e22c76b3ac | ||
|
|
a438091266 | ||
|
|
85baf79d17 | ||
|
|
1c68be0631 | ||
|
|
b222dde835 | ||
|
|
78e5a395da | ||
|
|
7846e6a31e | ||
|
|
b7e7755edd | ||
|
|
40f48cbeb4 | ||
|
|
fb8313aa97 | ||
|
|
f9643917d3 | ||
|
|
ac1c9b1218 | ||
|
|
daf0d6b9a7 | ||
|
|
fa14863284 | ||
|
|
cd9ec0afc7 | ||
|
|
f3f6f1008a | ||
|
|
0e52672f4a | ||
|
|
bc1dc1fd63 | ||
|
|
f93f2c158b | ||
|
|
9229e2d88b | ||
|
|
51bb6b751e | ||
|
|
2cc87cab65 | ||
|
|
7cd273ae58 | ||
|
|
001fb7ef60 | ||
|
|
cf4660841a | ||
|
|
a52f755ce8 | ||
|
|
2a2abc4843 | ||
|
|
8af222c1e3 | ||
|
|
d3e6949007 | ||
|
|
a033b25ecb | ||
|
|
39dd30c239 | ||
|
|
c5c99d2357 | ||
|
|
25ff30ee8c | ||
|
|
6b250a74f8 | ||
|
|
5331397c6c | ||
|
|
0b39024133 | ||
|
|
438d286fd5 | ||
|
|
18a61f1058 | ||
|
|
20d012ae3f | ||
|
|
efc54ab8ba | ||
|
|
ea1c031b54 | ||
|
|
11a44081df | ||
|
|
5eb9c9504b | ||
|
|
29a078f65c | ||
|
|
be61ca13fe | ||
|
|
e9d5b2007a | ||
|
|
f2de8475fc | ||
|
|
3ecbea3c39 | ||
|
|
c4df7ad7a5 | ||
|
|
387567a917 | ||
|
|
cfbe8462cc | ||
|
|
5f4df54895 | ||
|
|
ed698f2462 | ||
|
|
b4774861db | ||
|
|
9768f73bb7 | ||
|
|
805249e27e | ||
|
|
5f24c40d05 | ||
|
|
1b3b82a3c1 | ||
|
|
9e72396709 | ||
|
|
125ee0b446 | ||
|
|
3bfb580d7a | ||
|
|
b54d47796d | ||
|
|
b5d0d6ff3e | ||
|
|
c9520deef8 | ||
|
|
ceab0f8c40 | ||
|
|
b87757c552 | ||
|
|
1972eb952d | ||
|
|
f92803d80e | ||
|
|
8afeb910bd | ||
|
|
f16ed98af4 | ||
|
|
2a9916103b | ||
|
|
63ad47a7bf | ||
|
|
27e6548343 | ||
|
|
8c91986dd3 | ||
|
|
5a65347c4e | ||
|
|
635180c8be | ||
|
|
019ce9862f | ||
|
|
c7f46876a7 | ||
|
|
c916eb6137 | ||
|
|
67cca71524 | ||
|
|
1eff7ae004 | ||
|
|
982ad46c83 | ||
|
|
657b4fd59e | ||
|
|
b371b406d5 | ||
|
|
91591c4e94 | ||
|
|
078b9719cc | ||
|
|
41d9826ee9 | ||
|
|
0152508a39 | ||
|
|
cdeb1c3828 | ||
|
|
0986fae066 | ||
|
|
277515636d | ||
|
|
45aacd8407 | ||
|
|
e8cdf8b092 | ||
|
|
1c4d6e7613 | ||
|
|
04b4e48265 | ||
|
|
dabcb1834d | ||
|
|
629cd86c7c | ||
|
|
ba704c4eb4 | ||
|
|
0487876826 | ||
|
|
ca9c05368e | ||
|
|
0d634a0061 | ||
|
|
86748fbc68 | ||
|
|
599477d754 | ||
|
|
889258f538 | ||
|
|
ffe2143d14 | ||
|
|
98470393d1 | ||
|
|
4192d04a53 | ||
|
|
3571dcd68c | ||
|
|
952edcb804 | ||
|
|
10a94c0794 | ||
|
|
dd32ace9ab | ||
|
|
7e0c6ee097 | ||
|
|
b1be34c6a0 | ||
|
|
b9307a9967 | ||
|
|
b1d353180b | ||
|
|
bd99eb1347 | ||
|
|
f79c01b0cf | ||
|
|
3f1e09ec0e | ||
|
|
05125029c6 | ||
|
|
05fe983757 | ||
|
|
d1a7749df5 | ||
|
|
9d63fc7ca0 | ||
|
|
38fccebe1f | ||
|
|
c05952b813 | ||
|
|
932cbe40bf | ||
|
|
39573d65d0 | ||
|
|
6db308f1e9 | ||
|
|
6f70fd90b9 | ||
|
|
db038d943c | ||
|
|
c5620efc9c | ||
|
|
8fb7aa5cef | ||
|
|
6ddee9a8ac | ||
|
|
5700359a61 | ||
|
|
0861a353d6 | ||
|
|
f79efec7ef | ||
|
|
77d5d20391 | ||
|
|
165e51d850 | ||
|
|
1c38f113b3 | ||
|
|
66859607a3 | ||
|
|
edf396b1a4 | ||
|
|
cbeb51b436 | ||
|
|
45e4fd6ec1 | ||
|
|
3a077ff211 | ||
|
|
be850e483a | ||
|
|
33fb62bb25 | ||
|
|
66c117e599 | ||
|
|
8aa1be8336 | ||
|
|
037d4121a1 | ||
|
|
fbd3918d3a | ||
|
|
7c543a43a9 | ||
|
|
ee3996cac6 | ||
|
|
96809ac659 | ||
|
|
6343059bc0 | ||
|
|
5a78fe33e8 | ||
|
|
676fb947f2 | ||
|
|
d18afb4a50 | ||
|
|
fc336a76bf | ||
|
|
b9f3d333e4 | ||
|
|
3d85af04be | ||
|
|
471b1e003a | ||
|
|
be2e17d605 | ||
|
|
9d6b9797c0 | ||
|
|
3cd6a18048 | ||
|
|
c9558c5f0e | ||
|
|
71e3d25422 | ||
|
|
644dc13e00 | ||
|
|
47e7aa4209 | ||
|
|
1c97a310b1 | ||
|
|
d612a1b5a1 | ||
|
|
386ead15a3 | ||
|
|
83c95e774d | ||
|
|
e4754999b7 | ||
|
|
c66489dbb1 | ||
|
|
21f9aefc7e | ||
|
|
d103dc2631 | ||
|
|
cac627ed05 | ||
|
|
e2cf2a5754 | ||
|
|
658a9a4ea8 | ||
|
|
a2db4c0a32 | ||
|
|
02a34a167a | ||
|
|
bea60930b6 | ||
|
|
0f7c82d38f | ||
|
|
6ba583d198 | ||
|
|
89d4c06dec | ||
|
|
9c72cc2a98 | ||
|
|
412bd94ea4 | ||
|
|
514ab043f2 | ||
|
|
68100102be | ||
|
|
05fdcb5b27 | ||
|
|
7a49c88200 | ||
|
|
40232d48ba | ||
|
|
55dff53a98 | ||
|
|
6919c2fb2d | ||
|
|
3d5d05eac7 | ||
|
|
dd866a74a6 | ||
|
|
b1e22aa559 | ||
|
|
2191e9ecd5 | ||
|
|
bf62103417 | ||
|
|
4b1b314ce2 | ||
|
|
c1ea0dde92 | ||
|
|
5a6cfc314e | ||
|
|
a4121a2c2e | ||
|
|
03335cef85 | ||
|
|
ff66bdda7c | ||
|
|
6cfddfea21 |
9
.cargo/config.toml
Normal file
9
.cargo/config.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Allow rust-analyzer and local `cargo doc` invocations to pick up unreleased changelog entries
|
||||||
|
#
|
||||||
|
# Note that these flags are (intentionally) not included when building from the downloaded crate.
|
||||||
|
[build]
|
||||||
|
rustdocflags = ["--cfg=unreleased_changelogs"]
|
||||||
|
rustflags = ["--cfg=unreleased_changelogs"]
|
||||||
|
|
||||||
|
[target.wasm32-unknown-unknown]
|
||||||
|
runner = "wasm-bindgen-test-runner"
|
||||||
8
.git-blame-ignore-revs
Normal file
8
.git-blame-ignore-revs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs
|
||||||
|
|
||||||
|
# chore(rustfmt): use nightly
|
||||||
|
7b0c7b6cb2c62767ca0c73c857b299883f55a883
|
||||||
|
# Rustfmt: use `group_imports`
|
||||||
|
2665c120981af548433645c6383b3580dd8f8fc4
|
||||||
|
# Use Taplo for TOML formatting
|
||||||
|
3398ebe467c43ccfd91916c5b81ff3c68f598556
|
||||||
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -20,5 +20,3 @@
|
|||||||
*.PDF diff=astextplain
|
*.PDF diff=astextplain
|
||||||
*.rtf diff=astextplain
|
*.rtf diff=astextplain
|
||||||
*.RTF diff=astextplain
|
*.RTF diff=astextplain
|
||||||
|
|
||||||
/CHANGELOG.md merge=union
|
|
||||||
|
|||||||
26
.github/CODEOWNERS
vendored
Normal file
26
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# Android
|
||||||
|
/winit-android @MarijnS95
|
||||||
|
|
||||||
|
# Apple (AppKit + UIKit)
|
||||||
|
/winit-appkit @madsmtm
|
||||||
|
/winit-uikit @madsmtm
|
||||||
|
/winit-common/src/core_foundation @madsmtm
|
||||||
|
/winit-common/src/event_handler.rs @madsmtm
|
||||||
|
|
||||||
|
# XKB
|
||||||
|
/winit-common/src/xkb @kchibisov
|
||||||
|
|
||||||
|
# Wayland
|
||||||
|
/winit-wayland @kchibisov
|
||||||
|
|
||||||
|
# X11
|
||||||
|
/winit-x11 @kchibisov
|
||||||
|
|
||||||
|
# Web
|
||||||
|
/winit-web @daxpedda
|
||||||
|
|
||||||
|
# Windows (Win32) (UNOWNED)
|
||||||
|
#/winit-win32
|
||||||
|
|
||||||
|
# Orbital (Redox OS)
|
||||||
|
/winit-orbital @jackpot51
|
||||||
4
.github/ISSUE_TEMPLATE/blank_issue.md
vendored
Normal file
4
.github/ISSUE_TEMPLATE/blank_issue.md
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
name: Blank Issue
|
||||||
|
about: Create a blank issue.
|
||||||
|
---
|
||||||
36
.github/ISSUE_TEMPLATE/bug_android.yml
vendored
Normal file
36
.github/ISSUE_TEMPLATE/bug_android.yml
vendored
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
name: Android bug
|
||||||
|
description: Create an Android-specific bug report
|
||||||
|
labels:
|
||||||
|
- B - bug
|
||||||
|
- DS - android
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for taking the time to fill out this bug report!
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Description
|
||||||
|
description: Description of the problem you're having
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: device
|
||||||
|
attributes:
|
||||||
|
label: Device and Android version
|
||||||
|
description: Which devices and Android versions are you seeing the problem on?
|
||||||
|
placeholder: |
|
||||||
|
Samsung Galaxy Z running Android Pie (API level 28),
|
||||||
|
Samsung Galaxy Z running Android 14 (API level 34),
|
||||||
|
Pixel 8 running Android 14 (API level 34)
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: winit-version
|
||||||
|
attributes:
|
||||||
|
label: Winit version
|
||||||
|
description: What version of Winit are you using?
|
||||||
|
placeholder: 0.29.11
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
37
.github/ISSUE_TEMPLATE/bug_appkit.yml
vendored
Normal file
37
.github/ISSUE_TEMPLATE/bug_appkit.yml
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
name: macOS bug
|
||||||
|
description: Create a macOS-specific bug report
|
||||||
|
labels:
|
||||||
|
- B - bug
|
||||||
|
- DS - appkit
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for taking the time to fill out this bug report!
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Description
|
||||||
|
description: Description of the problem you're having
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: os-version
|
||||||
|
attributes:
|
||||||
|
label: macOS version
|
||||||
|
description: What version of macOS are you using? Please paste in the output of `sw_vers`.
|
||||||
|
placeholder: |
|
||||||
|
ProductName: macOS
|
||||||
|
ProductVersion: 14.2.1
|
||||||
|
BuildVersion: 23C71
|
||||||
|
render: shell
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: winit-version
|
||||||
|
attributes:
|
||||||
|
label: Winit version
|
||||||
|
description: What version of Winit are you using?
|
||||||
|
placeholder: 0.29.11
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
37
.github/ISSUE_TEMPLATE/bug_uikit.yml
vendored
Normal file
37
.github/ISSUE_TEMPLATE/bug_uikit.yml
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
name: iOS bug
|
||||||
|
description: Create an iOS/UIKit-specific bug report
|
||||||
|
labels:
|
||||||
|
- B - bug
|
||||||
|
- DS - uikit
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for taking the time to fill out this bug report!
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Description
|
||||||
|
description: Description of the problem you're having
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: device
|
||||||
|
attributes:
|
||||||
|
label: Device and iOS version
|
||||||
|
description: Which devices and iOS versions are you seeing the problem on?
|
||||||
|
placeholder: |
|
||||||
|
iPhone 15 running iOS 14.0,
|
||||||
|
iPhone 15 running iOS 17.0,
|
||||||
|
MacBook Pro M2 Mac Catalyst running macOS 14.2,
|
||||||
|
iPhone simulator running iOS 17.0
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: winit-version
|
||||||
|
attributes:
|
||||||
|
label: Winit version
|
||||||
|
description: What version of Winit are you using?
|
||||||
|
placeholder: 0.29.11
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
41
.github/ISSUE_TEMPLATE/bug_wayland.yml
vendored
Normal file
41
.github/ISSUE_TEMPLATE/bug_wayland.yml
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
name: Wayland bug
|
||||||
|
description: Create a Wayland-specific bug report
|
||||||
|
labels:
|
||||||
|
- B - bug
|
||||||
|
- DS - wayland
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for taking the time to fill out this bug report!
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Description
|
||||||
|
description: Description of the problem you're having
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: debug
|
||||||
|
attributes:
|
||||||
|
label: Debugging output
|
||||||
|
description: Output of a binary run with `WAYLAND_DEBUG=1`
|
||||||
|
placeholder: |
|
||||||
|
[1234.5678] -> wl_display@1.get_registry(new id wl_registry@2)
|
||||||
|
[1234.5678] -> wl_display@1.sync(new id wl_callback@3)
|
||||||
|
...
|
||||||
|
render: shell
|
||||||
|
- type: checkboxes
|
||||||
|
attributes:
|
||||||
|
label: Window isn't shown unless you draw
|
||||||
|
options:
|
||||||
|
- label: I understand that windows aren't shown on Wayland unless I draw and present to them.
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: winit-version
|
||||||
|
attributes:
|
||||||
|
label: Winit version
|
||||||
|
description: What version of Winit are you using?
|
||||||
|
placeholder: 0.29.11
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
51
.github/ISSUE_TEMPLATE/bug_web.yml
vendored
Normal file
51
.github/ISSUE_TEMPLATE/bug_web.yml
vendored
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
name: Web bug
|
||||||
|
description: Create a Web-specific bug report
|
||||||
|
labels:
|
||||||
|
- B - bug
|
||||||
|
- DS - web
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for taking the time to fill out this bug report!
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Description
|
||||||
|
description: Description of the problem you're having
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: dropdown
|
||||||
|
id: browsers
|
||||||
|
attributes:
|
||||||
|
label: Tested browsers
|
||||||
|
description: What browsers are you seeing the problem on?
|
||||||
|
options:
|
||||||
|
- Firefox
|
||||||
|
- Chrome
|
||||||
|
- Microsoft Edge
|
||||||
|
- Safari 13
|
||||||
|
- Safari 14
|
||||||
|
- Safari 15
|
||||||
|
- Safari 16
|
||||||
|
- Safari 17
|
||||||
|
- Safari (newer than listed)
|
||||||
|
multiple: true
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: device
|
||||||
|
attributes:
|
||||||
|
label: Tested devices
|
||||||
|
description: Which device(s) are you using?
|
||||||
|
placeholder: 'iPhone 15, Lenovo ThinkPad X1, MacBook Pro M2, Samsung Galaxy Z, ...'
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: winit-version
|
||||||
|
attributes:
|
||||||
|
label: Winit version
|
||||||
|
description: What version of Winit are you using?
|
||||||
|
placeholder: 0.29.11
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
35
.github/ISSUE_TEMPLATE/bug_win32.yml
vendored
Normal file
35
.github/ISSUE_TEMPLATE/bug_win32.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
name: Windows bug
|
||||||
|
description: Create a Windows-specific bug report
|
||||||
|
labels:
|
||||||
|
- B - bug
|
||||||
|
- DS - win32
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for taking the time to fill out this bug report!
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Description
|
||||||
|
description: Description of the problem you're having
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: os-version
|
||||||
|
attributes:
|
||||||
|
label: Windows version
|
||||||
|
description: What version of Windows are you using? Please paste in the output of the `ver` command.
|
||||||
|
placeholder: |
|
||||||
|
Microsoft Windows [Version 10.0.19042.2251]
|
||||||
|
render: shell
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: winit-version
|
||||||
|
attributes:
|
||||||
|
label: Winit version
|
||||||
|
description: What version of Winit are you using?
|
||||||
|
placeholder: 0.29.11
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
32
.github/ISSUE_TEMPLATE/bug_x11.yml
vendored
Normal file
32
.github/ISSUE_TEMPLATE/bug_x11.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
name: X11 bug
|
||||||
|
description: Create a X11-specific bug report
|
||||||
|
labels:
|
||||||
|
- B - bug
|
||||||
|
- DS - x11
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
Thanks for taking the time to fill out this bug report!
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Description
|
||||||
|
description: Description of the problem you're having
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: os-info
|
||||||
|
attributes:
|
||||||
|
label: OS and window mananger
|
||||||
|
description: Which operating system and window manager are you using?
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: winit-version
|
||||||
|
attributes:
|
||||||
|
label: Winit version
|
||||||
|
description: What version of Winit are you using?
|
||||||
|
placeholder: 0.29.11
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
blank_issues_enabled: true
|
||||||
|
contact_links:
|
||||||
|
- name: Question
|
||||||
|
url: https://matrix.to/#/#rust-windowing:matrix.org
|
||||||
|
about: Please ask questions on the Matrix channel.
|
||||||
26
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
26
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
name: Feature request
|
||||||
|
description: Propose a new feature
|
||||||
|
labels:
|
||||||
|
- S - enhancement
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Description
|
||||||
|
description: Description of the problem does this solve or what need does it fill? Please be mindful of the [scope](https://github.com/rust-windowing/winit/blob/master/FEATURES.md) of Winit.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: dropdown
|
||||||
|
id: platforms
|
||||||
|
attributes:
|
||||||
|
label: Relevant platforms
|
||||||
|
description: On which platforms is this feature relevant?
|
||||||
|
options:
|
||||||
|
- Windows
|
||||||
|
- macOS
|
||||||
|
- Wayland
|
||||||
|
- X11
|
||||||
|
- Web
|
||||||
|
- iOS
|
||||||
|
- Android
|
||||||
|
multiple: true
|
||||||
6
.github/PULL_REQUEST_TEMPLATE.md
vendored
6
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -1,8 +1,4 @@
|
|||||||
- [ ] Tested on all platforms changed
|
- [ ] Tested on all platforms changed
|
||||||
- [ ] Compilation warnings were addressed
|
- [ ] Added an entry to the `changelog` module if knowledge of this change could be valuable to users
|
||||||
- [ ] `cargo fmt` has been run on this branch
|
|
||||||
- [ ] `cargo doc` builds successfully
|
|
||||||
- [ ] Added an entry to `CHANGELOG.md` if knowledge of this change could be valuable to users
|
|
||||||
- [ ] Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
|
- [ ] Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
|
||||||
- [ ] Created or updated an example program if it would help users understand this functionality
|
- [ ] Created or updated an example program if it would help users understand this functionality
|
||||||
- [ ] Updated [feature matrix](https://github.com/rust-windowing/winit/blob/master/FEATURES.md), if new features were added or implemented
|
|
||||||
|
|||||||
22
.github/dependabot.yaml
vendored
Normal file
22
.github/dependabot.yaml
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
version: 2
|
||||||
|
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: github-actions
|
||||||
|
directory: /
|
||||||
|
schedule:
|
||||||
|
interval: daily
|
||||||
|
groups:
|
||||||
|
github-actions:
|
||||||
|
patterns:
|
||||||
|
- "*"
|
||||||
|
|
||||||
|
- package-ecosystem: npm
|
||||||
|
directory: src/platform_impl/web/script
|
||||||
|
schedule:
|
||||||
|
interval: daily
|
||||||
|
groups:
|
||||||
|
github-actions:
|
||||||
|
patterns:
|
||||||
|
- '*'
|
||||||
|
labels:
|
||||||
|
- "DS - web"
|
||||||
360
.github/workflows/ci.yml
vendored
360
.github/workflows/ci.yml
vendored
@@ -2,115 +2,333 @@ name: CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
|
||||||
- '**.rs'
|
|
||||||
- '**.toml'
|
|
||||||
- '.github/workflows/ci.yml'
|
|
||||||
push:
|
push:
|
||||||
branches: [master]
|
branches: [master]
|
||||||
paths:
|
|
||||||
- '**.rs'
|
|
||||||
- '**.toml'
|
|
||||||
- '.github/workflows/ci.yml'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Check_Formatting:
|
fmt:
|
||||||
|
name: Check formatting
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: taiki-e/checkout-action@v1
|
||||||
- uses: hecrj/setup-rust-action@v1
|
- uses: dtolnay/rust-toolchain@nightly
|
||||||
with:
|
with:
|
||||||
rust-version: stable
|
|
||||||
components: rustfmt
|
components: rustfmt
|
||||||
- name: Check Formatting
|
- name: Check Formatting
|
||||||
run: cargo +stable fmt --all -- --check
|
run: cargo fmt -- --check
|
||||||
|
|
||||||
|
taplo:
|
||||||
|
name: Taplo
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: taiki-e/checkout-action@v1
|
||||||
|
- name: Install Taplo
|
||||||
|
uses: taiki-e/install-action@v2
|
||||||
|
with:
|
||||||
|
tool: taplo-cli
|
||||||
|
- name: Run Taplo
|
||||||
|
run: taplo fmt --check
|
||||||
|
|
||||||
|
typos:
|
||||||
|
name: Check for typos
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 30
|
||||||
|
steps:
|
||||||
|
- uses: taiki-e/checkout-action@v1
|
||||||
|
- uses: taiki-e/install-action@v2
|
||||||
|
with:
|
||||||
|
tool: typos-cli
|
||||||
|
- name: run typos
|
||||||
|
run: typos
|
||||||
|
- name: Typos info
|
||||||
|
if: failure()
|
||||||
|
run: |
|
||||||
|
echo 'To fix typos, please run `typos -w`'
|
||||||
|
echo 'To check for a diff, run `typos`'
|
||||||
|
echo 'You can find typos here: https://crates.io/crates/typos'
|
||||||
|
|
||||||
|
tests:
|
||||||
|
name: Test ${{ matrix.toolchain }} ${{ matrix.platform.name }}
|
||||||
|
runs-on: ${{ matrix.platform.os }}
|
||||||
|
|
||||||
Tests:
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
rust_version: [stable, nightly]
|
toolchain: [stable, nightly, '1.85']
|
||||||
platform:
|
platform:
|
||||||
- { target: x86_64-pc-windows-msvc, os: windows-latest, }
|
# Note: Make sure that we test all the `docs.rs` targets defined in Cargo.toml!
|
||||||
- { target: i686-pc-windows-msvc, os: windows-latest, }
|
- { name: 'Windows 64bit MSVC', target: x86_64-pc-windows-msvc, os: windows-latest, }
|
||||||
- { target: x86_64-pc-windows-gnu, os: windows-latest, host: -x86_64-pc-windows-gnu }
|
- { name: 'Windows 32bit MSVC', target: i686-pc-windows-msvc, os: windows-latest, }
|
||||||
- { target: i686-pc-windows-gnu, os: windows-latest, host: -i686-pc-windows-gnu }
|
- { name: 'Windows 64bit GNU', target: x86_64-pc-windows-gnu, os: windows-latest, host: -x86_64-pc-windows-gnu }
|
||||||
- { target: i686-unknown-linux-gnu, os: ubuntu-latest, }
|
- { name: 'Windows 32bit GNU', target: i686-pc-windows-gnu, os: windows-latest, host: -i686-pc-windows-gnu }
|
||||||
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest, }
|
- { name: 'Linux 32bit', target: i686-unknown-linux-gnu, os: ubuntu-latest, }
|
||||||
- { target: aarch64-linux-android, os: ubuntu-latest, cmd: 'apk --' }
|
- { name: 'Linux 64bit', target: x86_64-unknown-linux-gnu, os: ubuntu-latest, }
|
||||||
- { target: x86_64-apple-darwin, os: macos-latest, }
|
- { name: 'X11', target: x86_64-unknown-linux-gnu, os: ubuntu-latest, options: '--no-default-features --features=x11' }
|
||||||
- { target: x86_64-apple-ios, os: macos-latest, }
|
- { name: 'Wayland', target: x86_64-unknown-linux-gnu, os: ubuntu-latest, options: '--no-default-features --features=wayland,wayland-dlopen' }
|
||||||
- { target: aarch64-apple-ios, os: macos-latest, }
|
- { name: 'Android', target: aarch64-linux-android, os: ubuntu-latest, options: '--package winit --features=android-native-activity', cmd: 'apk -- ' }
|
||||||
# We're using Windows rather than Ubuntu to run the wasm tests because caching cargo-web
|
- { name: 'Redox OS', target: x86_64-unknown-redox, os: ubuntu-latest, }
|
||||||
# doesn't currently work on Linux.
|
- { name: 'macOS x86_64', target: x86_64-apple-darwin, os: macos-latest, }
|
||||||
- { target: wasm32-unknown-unknown, os: windows-latest, features: stdweb, cmd: web }
|
- { name: 'macOS Aarch64', target: aarch64-apple-darwin, os: macos-latest, }
|
||||||
- { target: wasm32-unknown-unknown, os: windows-latest, features: web-sys, cmd: web }
|
- { name: 'iOS x86_64', target: x86_64-apple-ios, os: macos-latest, }
|
||||||
|
- { name: 'iOS Aarch64', target: aarch64-apple-ios, os: macos-latest, }
|
||||||
|
- { name: 'Web', target: wasm32-unknown-unknown, os: ubuntu-latest, }
|
||||||
|
exclude:
|
||||||
|
# Web on nightly needs extra arguments
|
||||||
|
|
||||||
|
- toolchain: nightly
|
||||||
|
platform: { name: 'Web' }
|
||||||
|
# Rustup is broken.
|
||||||
|
- toolchain: nightly
|
||||||
|
platform: { name: 'Windows 32bit GNU' }
|
||||||
|
# Android is tested on stable-3
|
||||||
|
- toolchain: '1.85'
|
||||||
|
platform: { name: 'Android' }
|
||||||
|
# Redox OS doesn't follow MSRV
|
||||||
|
- toolchain: '1.85'
|
||||||
|
platform: { name: 'Redox OS' }
|
||||||
|
include:
|
||||||
|
- toolchain: '1.85'
|
||||||
|
platform: { name: 'Android', target: aarch64-linux-android, os: ubuntu-latest, options: '--package winit --features=android-native-activity', cmd: 'apk -- ' }
|
||||||
|
- toolchain: 'nightly'
|
||||||
|
platform: { name: 'Web', target: wasm32-unknown-unknown, os: ubuntu-latest, test-options: -Zdoctest-xcompile }
|
||||||
|
- toolchain: 'nightly'
|
||||||
|
platform: {
|
||||||
|
name: 'Web Atomic',
|
||||||
|
target: wasm32-unknown-unknown,
|
||||||
|
os: ubuntu-latest,
|
||||||
|
options: '-Zbuild-std=panic_abort,std',
|
||||||
|
test-options: -Zdoctest-xcompile,
|
||||||
|
rustflags: '-Ctarget-feature=+atomics,+bulk-memory',
|
||||||
|
components: rust-src,
|
||||||
|
}
|
||||||
|
|
||||||
env:
|
env:
|
||||||
|
# Set more verbose terminal output
|
||||||
|
CARGO_TERM_VERBOSE: true
|
||||||
RUST_BACKTRACE: 1
|
RUST_BACKTRACE: 1
|
||||||
CARGO_INCREMENTAL: 0
|
|
||||||
RUSTFLAGS: "-C debuginfo=0"
|
# Faster compilation and error on warnings
|
||||||
FEATURES: ${{ format(',{0}', matrix.platform.features ) }}
|
RUSTFLAGS: '--codegen=debuginfo=0 --deny=warnings ${{ matrix.platform.rustflags }}'
|
||||||
|
RUSTDOCFLAGS: ${{ matrix.platform.rustflags }}
|
||||||
|
|
||||||
|
OPTIONS: --target=${{ matrix.platform.target }} ${{ matrix.platform.options }}
|
||||||
|
TEST_OPTIONS: ${{ matrix.platform.test-options }}
|
||||||
CMD: ${{ matrix.platform.cmd }}
|
CMD: ${{ matrix.platform.cmd }}
|
||||||
|
|
||||||
runs-on: ${{ matrix.platform.os }}
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: taiki-e/checkout-action@v1
|
||||||
# Used to cache cargo-web
|
|
||||||
- name: Cache cargo folder
|
|
||||||
uses: actions/cache@v1
|
|
||||||
with:
|
|
||||||
path: ~/.cargo
|
|
||||||
key: ${{ matrix.platform.target }}-cargo-${{ matrix.rust_version }}
|
|
||||||
|
|
||||||
- uses: hecrj/setup-rust-action@v1
|
- name: Restore cache of cargo folder
|
||||||
|
# We use `restore` and later `save`, so that we can create the key after
|
||||||
|
# the cache has been downloaded.
|
||||||
|
#
|
||||||
|
# This could be avoided if we added Cargo.lock to the repository.
|
||||||
|
uses: actions/cache/restore@v5
|
||||||
with:
|
with:
|
||||||
rust-version: ${{ matrix.rust_version }}${{ matrix.platform.host }}
|
# https://doc.rust-lang.org/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci
|
||||||
targets: ${{ matrix.platform.target }}
|
path: |
|
||||||
|
~/.cargo/registry/index/
|
||||||
|
~/.cargo/registry/cache/
|
||||||
|
~/.cargo/git/db/
|
||||||
|
key: cargo-${{ matrix.toolchain }}-${{ matrix.platform.name }}-never-intended-to-be-found
|
||||||
|
restore-keys: cargo-${{ matrix.toolchain }}-${{ matrix.platform.name }}
|
||||||
|
|
||||||
|
- name: Generate lockfile
|
||||||
|
# Also updates the crates.io index
|
||||||
|
run: cargo generate-lockfile && cargo update -p smol_str --precise 0.3.2 && cargo update -p unicode-segmentation --precise 1.12.0 && cargo update -p wayland-protocols --precise 0.32.12
|
||||||
|
|
||||||
- name: Install GCC Multilib
|
- name: Install GCC Multilib
|
||||||
if: (matrix.platform.os == 'ubuntu-latest') && contains(matrix.platform.target, 'i686')
|
if: (matrix.platform.os == 'ubuntu-latest') && contains(matrix.platform.target, 'i686')
|
||||||
run: sudo apt-get update && sudo apt-get install gcc-multilib
|
run: sudo apt-get update && sudo apt-get install gcc-multilib
|
||||||
- name: Install cargo-apk
|
|
||||||
|
- name: Cache cargo-apk
|
||||||
if: contains(matrix.platform.target, 'android')
|
if: contains(matrix.platform.target, 'android')
|
||||||
run: cargo install cargo-apk
|
id: cargo-apk-cache
|
||||||
- name: Install cargo-web
|
uses: actions/cache@v5
|
||||||
continue-on-error: true
|
with:
|
||||||
if: contains(matrix.platform.target, 'wasm32')
|
path: ~/.cargo/bin/cargo-apk
|
||||||
run: cargo install cargo-web
|
# Change this key if we update the required cargo-apk version
|
||||||
|
key: cargo-apk-v0-9-7
|
||||||
|
|
||||||
|
- uses: dtolnay/rust-toolchain@master
|
||||||
|
if: contains(matrix.platform.target, 'android') && (steps.cargo-apk-cache.outputs.cache-hit != 'true')
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
|
||||||
|
- name: Install cargo-apk
|
||||||
|
if: contains(matrix.platform.target, 'android') && (steps.cargo-apk-cache.outputs.cache-hit != 'true')
|
||||||
|
run: cargo install cargo-apk --version=^0.9.7 --locked
|
||||||
|
|
||||||
|
- uses: taiki-e/cache-cargo-install-action@v3
|
||||||
|
if: contains(matrix.platform.target, 'wasm32') && matrix.toolchain == 'nightly'
|
||||||
|
with:
|
||||||
|
tool: wasm-bindgen-cli
|
||||||
|
|
||||||
|
- uses: dtolnay/rust-toolchain@master
|
||||||
|
with:
|
||||||
|
toolchain: ${{ matrix.toolchain }}${{ matrix.platform.host }}
|
||||||
|
targets: ${{ matrix.platform.target }}
|
||||||
|
components: clippy, ${{ matrix.platform.components }}
|
||||||
|
|
||||||
- name: Check documentation
|
- name: Check documentation
|
||||||
shell: bash
|
run: cargo doc --no-deps $OPTIONS --document-private-items
|
||||||
if: matrix.platform.target != 'wasm32-unknown-unknown'
|
env:
|
||||||
run: cargo $CMD doc --no-deps --target ${{ matrix.platform.target }} --features $FEATURES
|
RUSTDOCFLAGS: '--deny=warnings ${{ matrix.platform.rustflags }}'
|
||||||
|
|
||||||
- name: Build
|
- name: Build crate
|
||||||
shell: bash
|
run: cargo $CMD build $OPTIONS
|
||||||
run: cargo $CMD build --verbose --target ${{ matrix.platform.target }} --features $FEATURES
|
|
||||||
|
- name: Test winit core
|
||||||
|
run: cargo test -p winit-core
|
||||||
|
|
||||||
|
- name: Test winit Android
|
||||||
|
if: contains(matrix.platform.target, 'android')
|
||||||
|
run: cargo $CMD test -p winit-android --features native-activity --no-run
|
||||||
|
|
||||||
|
- name: Test winit Common (EventHandler)
|
||||||
|
run: cargo $CMD test -p winit-common --features event-handler --no-run
|
||||||
|
|
||||||
|
- name: Test winit Common (CF)
|
||||||
|
if: contains(matrix.platform.target, 'apple')
|
||||||
|
run: cargo $CMD test -p winit-common --features core-foundation --no-run
|
||||||
|
|
||||||
|
- name: Test winit Common (XKB)
|
||||||
|
if: contains(matrix.platform.target, 'linux-gnu')
|
||||||
|
run: cargo $CMD test -p winit-common --features xkb,x11,wayland --no-run
|
||||||
|
|
||||||
|
- name: Test winit AppKit
|
||||||
|
if: contains(matrix.platform.target, 'macos')
|
||||||
|
run: cargo $CMD test -p winit-appkit $OPTIONS
|
||||||
|
|
||||||
|
- name: Test winit Orbital
|
||||||
|
if: contains(matrix.platform.target, 'redox')
|
||||||
|
run: cargo test -p winit-orbital
|
||||||
|
|
||||||
|
- name: Test winit UIKit
|
||||||
|
if: contains(matrix.platform.target, 'ios')
|
||||||
|
# TODO: Run on Simulator
|
||||||
|
run: cargo $CMD test -p winit-uikit $OPTIONS --no-run
|
||||||
|
|
||||||
|
- name: Test winit Web
|
||||||
|
if: contains(matrix.platform.target, 'wasm')
|
||||||
|
run: cargo $CMD test -p winit-web $OPTIONS --no-run
|
||||||
|
|
||||||
|
- name: Test winit Win32
|
||||||
|
if: contains(matrix.platform.target, 'windows')
|
||||||
|
run: cargo $CMD test -p winit-win32 $OPTIONS
|
||||||
|
|
||||||
|
- name: Test winit X11
|
||||||
|
if: contains(matrix.platform.target, 'linux-gnu')
|
||||||
|
run: cargo $CMD test -p winit-x11 --target=${{ matrix.platform.target }}
|
||||||
|
|
||||||
|
- name: Test winit Wayland
|
||||||
|
if: contains(matrix.platform.target, 'linux-gnu')
|
||||||
|
run: cargo $CMD test -p winit-wayland --target=${{ matrix.platform.target }}
|
||||||
|
|
||||||
|
# Test only on Linux x86_64, so we avoid spending unnecessary CI hours.
|
||||||
|
- name: Test dpi crate
|
||||||
|
if: >
|
||||||
|
contains(matrix.platform.name, 'Linux 64bit') &&
|
||||||
|
matrix.toolchain != '1.85'
|
||||||
|
run: cargo test -p dpi
|
||||||
|
|
||||||
|
- name: Check dpi crate (no_std)
|
||||||
|
if: >
|
||||||
|
contains(matrix.platform.name, 'Linux 64bit') &&
|
||||||
|
matrix.toolchain != '1.85'
|
||||||
|
run: cargo check -p dpi --no-default-features
|
||||||
|
|
||||||
- name: Build tests
|
- name: Build tests
|
||||||
shell: bash
|
if: >
|
||||||
run: cargo $CMD test --no-run --verbose --target ${{ matrix.platform.target }} --features $FEATURES
|
!contains(matrix.platform.target, 'redox') &&
|
||||||
|
matrix.toolchain != '1.85'
|
||||||
|
run: cargo $CMD test --no-run $OPTIONS
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
shell: bash
|
if: >
|
||||||
if: (
|
|
||||||
!contains(matrix.platform.target, 'android') &&
|
!contains(matrix.platform.target, 'android') &&
|
||||||
!contains(matrix.platform.target, 'ios') &&
|
!contains(matrix.platform.target, 'ios') &&
|
||||||
!contains(matrix.platform.target, 'wasm32'))
|
(!contains(matrix.platform.target, 'wasm32') || matrix.toolchain == 'nightly') &&
|
||||||
run: cargo $CMD test --verbose --target ${{ matrix.platform.target }} --features $FEATURES
|
!contains(matrix.platform.target, 'redox') &&
|
||||||
|
matrix.toolchain != '1.85'
|
||||||
|
run: cargo $CMD test $OPTIONS
|
||||||
|
|
||||||
|
- name: Lint with clippy
|
||||||
- name: Build with serde enabled
|
if: (matrix.toolchain == 'stable') && !contains(matrix.platform.options, '--no-default-features')
|
||||||
shell: bash
|
run: cargo clippy --all-targets $OPTIONS $TEST_OPTIONS -- -Dwarnings
|
||||||
run: cargo $CMD build --verbose --target ${{ matrix.platform.target }} --features serde,$FEATURES
|
|
||||||
|
|
||||||
- name: Build tests with serde enabled
|
- name: Build tests with serde enabled
|
||||||
shell: bash
|
if: >
|
||||||
run: cargo $CMD test --no-run --verbose --target ${{ matrix.platform.target }} --features serde,$FEATURES
|
!contains(matrix.platform.target, 'redox') &&
|
||||||
|
matrix.toolchain != '1.85'
|
||||||
|
run: cargo $CMD test --no-run $OPTIONS $TEST_OPTIONS --features serde
|
||||||
|
|
||||||
- name: Run tests with serde enabled
|
- name: Run tests with serde enabled
|
||||||
shell: bash
|
if: >
|
||||||
if: (
|
|
||||||
!contains(matrix.platform.target, 'android') &&
|
!contains(matrix.platform.target, 'android') &&
|
||||||
!contains(matrix.platform.target, 'ios') &&
|
!contains(matrix.platform.target, 'ios') &&
|
||||||
!contains(matrix.platform.target, 'wasm32'))
|
(!contains(matrix.platform.target, 'wasm32') || matrix.toolchain == 'nightly') &&
|
||||||
run: cargo $CMD test --verbose --target ${{ matrix.platform.target }} --features serde,$FEATURES
|
!contains(matrix.platform.target, 'redox') &&
|
||||||
|
matrix.toolchain != '1.85'
|
||||||
|
run: cargo $CMD test $OPTIONS $TEST_OPTIONS --features serde
|
||||||
|
|
||||||
|
- name: Check docs.rs documentation
|
||||||
|
if: matrix.toolchain == 'nightly'
|
||||||
|
run: cargo doc --no-deps $OPTIONS --features=serde,mint,android-native-activity
|
||||||
|
env:
|
||||||
|
RUSTDOCFLAGS: '--deny=warnings ${{ matrix.platform.rustflags }} --cfg=docsrs --cfg=unreleased_changelogs'
|
||||||
|
|
||||||
|
# See restore step above
|
||||||
|
- name: Save cache of cargo folder
|
||||||
|
uses: actions/cache/save@v5
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cargo/registry/index/
|
||||||
|
~/.cargo/registry/cache/
|
||||||
|
~/.cargo/git/db/
|
||||||
|
key: cargo-${{ matrix.toolchain }}-${{ matrix.platform.name }}-${{ hashFiles('Cargo.lock') }}
|
||||||
|
|
||||||
|
cargo-deny:
|
||||||
|
name: Run cargo-deny
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: taiki-e/checkout-action@v1
|
||||||
|
- uses: EmbarkStudios/cargo-deny-action@v2
|
||||||
|
with:
|
||||||
|
log-level: error
|
||||||
|
|
||||||
|
eslint:
|
||||||
|
name: ESLint
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ./winit-web/src/script
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: taiki-e/checkout-action@v1
|
||||||
|
- name: Setup NPM
|
||||||
|
run: npm install
|
||||||
|
- name: Run ESLint
|
||||||
|
run: npx eslint@9.38.0
|
||||||
|
|
||||||
|
swc:
|
||||||
|
name: Minimize JavaScript
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ./winit-web/src/script
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: taiki-e/checkout-action@v1
|
||||||
|
- name: Install SWC
|
||||||
|
run: sudo npm i -g @swc/cli
|
||||||
|
- name: Run SWC
|
||||||
|
run: |
|
||||||
|
swc . --ignore node_modules,**/*.d.ts --only **/*.ts -d . --out-file-extension min.js
|
||||||
|
- name: Check for diff
|
||||||
|
run: |
|
||||||
|
[[ -z $(git status -s) ]]
|
||||||
|
|||||||
50
.github/workflows/docs.yml
vendored
Normal file
50
.github/workflows/docs.yml
vendored
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
name: Docs
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docs:
|
||||||
|
name: Documentation
|
||||||
|
environment:
|
||||||
|
name: github-pages
|
||||||
|
url: ${{ steps.deployment.outputs.page_url }}winit
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pages: write
|
||||||
|
id-token: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
|
- uses: dtolnay/rust-toolchain@master
|
||||||
|
with:
|
||||||
|
toolchain: nightly
|
||||||
|
|
||||||
|
- name: Run Rustdoc
|
||||||
|
env:
|
||||||
|
RUSTDOCFLAGS: --crate-version master --cfg=docsrs --cfg=unreleased_changelogs
|
||||||
|
run: |
|
||||||
|
cargo doc --no-deps -Z rustdoc-map -Z rustdoc-scrape-examples --features=serde,mint,android-native-activity
|
||||||
|
|
||||||
|
- name: Setup Pages
|
||||||
|
uses: actions/configure-pages@v6
|
||||||
|
|
||||||
|
- name: Fix permissions
|
||||||
|
run: |
|
||||||
|
chmod -c -R +rX "target/doc" | while read line; do
|
||||||
|
echo "::warning title=Invalid file permissions automatically fixed::$line"
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-pages-artifact@v4
|
||||||
|
with:
|
||||||
|
path: target/doc
|
||||||
|
|
||||||
|
- name: Deploy to GitHub Pages
|
||||||
|
id: deployment
|
||||||
|
uses: actions/deploy-pages@v5
|
||||||
18
.github/workflows/publish.yml
vendored
18
.github/workflows/publish.yml
vendored
@@ -1,18 +0,0 @@
|
|||||||
name: Publish
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [master]
|
|
||||||
paths: "Cargo.toml"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
Publish:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- uses: hecrj/setup-rust-action@v1
|
|
||||||
with:
|
|
||||||
rust-version: stable
|
|
||||||
components: rustfmt
|
|
||||||
- name: Publish to crates.io
|
|
||||||
run: cargo publish --token ${{ secrets.cratesio_token }}
|
|
||||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -3,7 +3,8 @@ target/
|
|||||||
rls/
|
rls/
|
||||||
.vscode/
|
.vscode/
|
||||||
*~
|
*~
|
||||||
*.wasm
|
|
||||||
*.ts
|
|
||||||
*.js
|
|
||||||
#*#
|
#*#
|
||||||
|
.DS_Store
|
||||||
|
# NPM package used to run ESLint.
|
||||||
|
/src/platform_impl/web/script/node_modules
|
||||||
|
/src/platform_impl/web/script/package-lock.json
|
||||||
|
|||||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
|||||||
[submodule "deps/apk-builder"]
|
|
||||||
path = deps/apk-builder
|
|
||||||
url = https://github.com/rust-windowing/android-rs-glue
|
|
||||||
593
CHANGELOG.md
593
CHANGELOG.md
@@ -1,589 +1,8 @@
|
|||||||
# Unreleased
|
Changelog entries should be put in the [`changelog::unreleased`].
|
||||||
|
|
||||||
# 0.22.2 (2020-05-16)
|
The changelog can also be viewed [on docs.rs][docs_rs] or [on the current
|
||||||
|
master docs][master_docs].
|
||||||
|
|
||||||
- Added Clone implementation for 'static events.
|
[`changelog::unreleased`]: winit/src/changelog/unreleased.md
|
||||||
- On Windows, fix window intermittently hanging when `ControlFlow` was set to `Poll`.
|
[docs_rs]: https://docs.rs/winit/latest/winit/changelog/index.html
|
||||||
- On Windows, fix `WindowBuilder::with_maximized` being ignored.
|
[master_docs]: https://rust-windowing.github.io/winit/winit/changelog/index.html
|
||||||
- On Android, minimal platform support.
|
|
||||||
- On iOS, touch positions are now properly converted to physical pixels.
|
|
||||||
- On macOS, updated core-* dependencies and cocoa
|
|
||||||
|
|
||||||
# 0.22.1 (2020-04-16)
|
|
||||||
|
|
||||||
- On X11, fix `ResumeTimeReached` being fired too early.
|
|
||||||
- On Web, replaced zero timeout for `ControlFlow::Poll` with `requestAnimationFrame`
|
|
||||||
- On Web, fix a possible panic during event handling
|
|
||||||
- On macOS, fix `EventLoopProxy` leaking memory for every instance.
|
|
||||||
|
|
||||||
# 0.22.0 (2020-03-09)
|
|
||||||
|
|
||||||
- On Windows, fix minor timing issue in wait_until_time_or_msg
|
|
||||||
- On Windows, rework handling of request_redraw() to address panics.
|
|
||||||
- On macOS, fix `set_simple_screen` to remember frame excluding title bar.
|
|
||||||
- On Wayland, fix coordinates in touch events when scale factor isn't 1.
|
|
||||||
- On Wayland, fix color from `close_button_icon_color` not applying.
|
|
||||||
- Ignore locale if unsupported by X11 backend
|
|
||||||
- On Wayland, Add HiDPI cursor support
|
|
||||||
- On Web, add the ability to query "Light" or "Dark" system theme send `ThemeChanged` on change.
|
|
||||||
- Fix `Event::to_static` returning `None` for user events.
|
|
||||||
- On Wayland, Hide CSD for fullscreen windows.
|
|
||||||
- On Windows, ignore spurious mouse move messages.
|
|
||||||
- **Breaking:** Move `ModifiersChanged` variant from `DeviceEvent` to `WindowEvent`.
|
|
||||||
- On Windows, add `IconExtWindows` trait which exposes creating an `Icon` from an external file or embedded resource
|
|
||||||
- Add `BadIcon::OsError` variant for when OS icon functionality fails
|
|
||||||
- On Windows, fix crash at startup on systems that do not properly support Windows' Dark Mode
|
|
||||||
- Revert On macOS, fix not sending ReceivedCharacter event for specific keys combinations.
|
|
||||||
- on macOS, fix incorrect ReceivedCharacter events for some key combinations.
|
|
||||||
- **Breaking:** Use `i32` instead of `u32` for position type in `WindowEvent::Moved`.
|
|
||||||
- On macOS, a mouse motion event is now generated before every mouse click.
|
|
||||||
|
|
||||||
# 0.21.0 (2020-02-04)
|
|
||||||
|
|
||||||
- On Windows, fixed "error: linking with `link.exe` failed: exit code: 1120" error on older versions of windows.
|
|
||||||
- On macOS, fix set_minimized(true) works only with decorations.
|
|
||||||
- On macOS, add `hide_application` to `EventLoopWindowTarget` via a new `EventLoopWindowTargetExtMacOS` trait. `hide_application` will hide the entire application by calling `-[NSApplication hide: nil]`.
|
|
||||||
- On macOS, fix not sending ReceivedCharacter event for specific keys combinations.
|
|
||||||
- On macOS, fix `CursorMoved` event reporting the cursor position using logical coordinates.
|
|
||||||
- On macOS, fix issue where unbundled applications would sometimes open without being focused.
|
|
||||||
- On macOS, fix `run_return` does not return unless it receives a message.
|
|
||||||
- On Windows, fix bug where `RedrawRequested` would only get emitted every other iteration of the event loop.
|
|
||||||
- On X11, fix deadlock on window state when handling certain window events.
|
|
||||||
- `WindowBuilder` now implements `Default`.
|
|
||||||
- **Breaking:** `WindowEvent::CursorMoved` changed to `f64` units, preserving high-precision data supplied by most backends
|
|
||||||
- On Wayland, fix coordinates in mouse events when scale factor isn't 1
|
|
||||||
- On Web, add the ability to provide a custom canvas
|
|
||||||
- **Breaking:** On Wayland, the `WaylandTheme` struct has been replaced with a `Theme` trait, allowing for extra configuration
|
|
||||||
|
|
||||||
# 0.20.0 (2020-01-05)
|
|
||||||
|
|
||||||
- On X11, fix `ModifiersChanged` emitting incorrect modifier change events
|
|
||||||
- **Breaking**: Overhaul how Winit handles DPI:
|
|
||||||
+ Window functions and events now return `PhysicalSize` instead of `LogicalSize`.
|
|
||||||
+ Functions that take `Size` or `Position` types can now take either `Logical` or `Physical` types.
|
|
||||||
+ `hidpi_factor` has been renamed to `scale_factor`.
|
|
||||||
+ `HiDpiFactorChanged` has been renamed to `ScaleFactorChanged`, and lets you control how the OS
|
|
||||||
resizes the window in response to the change.
|
|
||||||
+ On X11, deprecate `WINIT_HIDPI_FACTOR` environment variable in favor of `WINIT_X11_SCALE_FACTOR`.
|
|
||||||
+ `Size` and `Position` types are now generic over their exact pixel type.
|
|
||||||
|
|
||||||
# 0.20.0 Alpha 6 (2020-01-03)
|
|
||||||
|
|
||||||
- On macOS, fix `set_cursor_visible` hides cursor outside of window.
|
|
||||||
- On macOS, fix `CursorEntered` and `CursorLeft` events fired at old window size.
|
|
||||||
- On macOS, fix error when `set_fullscreen` is called during fullscreen transition.
|
|
||||||
- On all platforms except mobile and WASM, implement `Window::set_minimized`.
|
|
||||||
- On X11, fix `CursorEntered` event being generated for non-winit windows.
|
|
||||||
- On macOS, fix crash when starting maximized without decorations.
|
|
||||||
- On macOS, fix application not terminating on `run_return`.
|
|
||||||
- On Wayland, fix cursor icon updates on window borders when using CSD.
|
|
||||||
- On Wayland, under mutter(GNOME Wayland), fix CSD being behind the status bar, when starting window in maximized mode.
|
|
||||||
- On Windows, theme the title bar according to whether the system theme is "Light" or "Dark".
|
|
||||||
- Added `WindowEvent::ThemeChanged` variant to handle changes to the system theme. Currently only implemented on Windows.
|
|
||||||
- **Breaking**: Changes to the `RedrawRequested` event (#1041):
|
|
||||||
- `RedrawRequested` has been moved from `WindowEvent` to `Event`.
|
|
||||||
- `EventsCleared` has been renamed to `MainEventsCleared`.
|
|
||||||
- `RedrawRequested` is now issued only after `MainEventsCleared`.
|
|
||||||
- `RedrawEventsCleared` is issued after each set of `RedrawRequested` events.
|
|
||||||
- Implement synthetic window focus key events on Windows.
|
|
||||||
- **Breaking**: Change `ModifiersState` to a `bitflags` struct.
|
|
||||||
- On Windows, implement `VirtualKeyCode` translation for `LWin` and `RWin`.
|
|
||||||
- On Windows, fix closing the last opened window causing `DeviceEvent`s to stop getting emitted.
|
|
||||||
- On Windows, fix `Window::set_visible` not setting internal flags correctly. This resulted in some weird behavior.
|
|
||||||
- Add `DeviceEvent::ModifiersChanged`.
|
|
||||||
- Deprecate `modifiers` fields in other events in favor of `ModifiersChanged`.
|
|
||||||
- On X11, `WINIT_HIDPI_FACTOR` now dominates `Xft.dpi` when picking DPI factor for output.
|
|
||||||
- On X11, add special value `randr` for `WINIT_HIDPI_FACTOR` to make winit use self computed DPI factor instead of the one from `Xft.dpi`.
|
|
||||||
|
|
||||||
# 0.20.0 Alpha 5 (2019-12-09)
|
|
||||||
|
|
||||||
- On macOS, fix application termination on `ControlFlow::Exit`
|
|
||||||
- On Windows, fix missing `ReceivedCharacter` events when Alt is held.
|
|
||||||
- On macOS, stop emitting private corporate characters in `ReceivedCharacter` events.
|
|
||||||
- On X11, fix misreporting DPI factor at startup.
|
|
||||||
- On X11, fix events not being reported when using `run_return`.
|
|
||||||
- On X11, fix key modifiers being incorrectly reported.
|
|
||||||
- On X11, fix window creation hanging when another window is fullscreen.
|
|
||||||
- On Windows, fix focusing unfocused windows when switching from fullscreen to windowed.
|
|
||||||
- On X11, fix reporting incorrect DPI factor when waking from suspend.
|
|
||||||
- Change `EventLoopClosed` to contain the original event.
|
|
||||||
- **Breaking**: Add `is_synthetic` field to `WindowEvent` variant `KeyboardInput`,
|
|
||||||
indicating that the event is generated by winit.
|
|
||||||
- On X11, generate synthetic key events for keys held when a window gains or loses focus.
|
|
||||||
- On X11, issue a `CursorMoved` event when a `Touch` event occurs,
|
|
||||||
as X11 implicitly moves the cursor for such events.
|
|
||||||
|
|
||||||
# 0.20.0 Alpha 4 (2019-10-18)
|
|
||||||
|
|
||||||
- Add web support via the 'stdweb' or 'web-sys' features
|
|
||||||
- On Windows, implemented function to get HINSTANCE
|
|
||||||
- On macOS, implement `run_return`.
|
|
||||||
- On iOS, fix inverted parameter in `set_prefers_home_indicator_hidden`.
|
|
||||||
- On X11, performance is improved when rapidly calling `Window::set_cursor_icon`.
|
|
||||||
- On iOS, fix improper `msg_send` usage that was UB and/or would break if `!` is stabilized.
|
|
||||||
- On Windows, unset `maximized` when manually changing the window's position or size.
|
|
||||||
- On Windows, add touch pressure information for touch events.
|
|
||||||
- On macOS, differentiate between `CursorIcon::Grab` and `CursorIcon::Grabbing`.
|
|
||||||
- On Wayland, fix event processing sometimes stalling when using OpenGL with vsync.
|
|
||||||
- Officially remove the Emscripten backend.
|
|
||||||
- On Windows, fix handling of surrogate pairs when dispatching `ReceivedCharacter`.
|
|
||||||
- On macOS 10.15, fix freeze upon exiting exclusive fullscreen mode.
|
|
||||||
- On iOS, fix panic upon closing the app.
|
|
||||||
- On X11, allow setting mulitple `XWindowType`s.
|
|
||||||
- On iOS, fix null window on initial `HiDpiFactorChanged` event.
|
|
||||||
- On Windows, fix fullscreen window shrinking upon getting restored to a normal window.
|
|
||||||
- On macOS, fix events not being emitted during modal loops, such as when windows are being resized
|
|
||||||
by the user.
|
|
||||||
- On Windows, fix hovering the mouse over the active window creating an endless stream of CursorMoved events.
|
|
||||||
- Always dispatch a `RedrawRequested` event after creating a new window.
|
|
||||||
- On X11, return dummy monitor data to avoid panicking when no monitors exist.
|
|
||||||
- On X11, prevent stealing input focus when creating a new window.
|
|
||||||
Only steal input focus when entering fullscreen mode.
|
|
||||||
- On Wayland, fixed DeviceEvents for relative mouse movement is not always produced
|
|
||||||
- On Wayland, add support for set_cursor_visible and set_cursor_grab.
|
|
||||||
- On Wayland, fixed DeviceEvents for relative mouse movement is not always produced.
|
|
||||||
- Removed `derivative` crate dependency.
|
|
||||||
- On Wayland, add support for set_cursor_icon.
|
|
||||||
- Use `impl Iterator<Item = MonitorHandle>` instead of `AvailableMonitorsIter` consistently.
|
|
||||||
- On macOS, fix fullscreen state being updated after entering fullscreen instead of before,
|
|
||||||
resulting in `Window::fullscreen` returning the old state in `Resized` events instead of
|
|
||||||
reflecting the new fullscreen state
|
|
||||||
- On X11, fix use-after-free during window creation
|
|
||||||
- On Windows, disable monitor change keyboard shortcut while in exclusive fullscreen.
|
|
||||||
- On Windows, ensure that changing a borderless fullscreen window's monitor via keyboard shortcuts keeps the window fullscreen on the new monitor.
|
|
||||||
- Prevent `EventLoop::new` and `EventLoop::with_user_event` from getting called outside the main thread.
|
|
||||||
- This is because some platforms cannot run the event loop outside the main thread. Preventing this
|
|
||||||
reduces the potential for cross-platform compatibility gotchyas.
|
|
||||||
- On Windows and Linux X11/Wayland, add platform-specific functions for creating an `EventLoop` outside the main thread.
|
|
||||||
- On Wayland, drop resize events identical to the current window size.
|
|
||||||
- On Windows, fix window rectangle not getting set correctly on high-DPI systems.
|
|
||||||
|
|
||||||
# 0.20.0 Alpha 3 (2019-08-14)
|
|
||||||
|
|
||||||
- On macOS, drop the run closure on exit.
|
|
||||||
- On Windows, location of `WindowEvent::Touch` are window client coordinates instead of screen coordinates.
|
|
||||||
- On X11, fix delayed events after window redraw.
|
|
||||||
- On macOS, add `WindowBuilderExt::with_disallow_hidpi` to have the option to turn off best resolution openGL surface.
|
|
||||||
- On Windows, screen saver won't start if the window is in fullscreen mode.
|
|
||||||
- Change all occurrences of the `new_user_event` method to `with_user_event`.
|
|
||||||
- On macOS, the dock and the menu bar are now hidden in fullscreen mode.
|
|
||||||
- `Window::set_fullscreen` now takes `Option<Fullscreen>` where `Fullscreen`
|
|
||||||
consists of `Fullscreen::Exclusive(VideoMode)` and
|
|
||||||
`Fullscreen::Borderless(MonitorHandle)` variants.
|
|
||||||
- Adds support for exclusive fullscreen mode.
|
|
||||||
- On iOS, add support for hiding the home indicator.
|
|
||||||
- On iOS, add support for deferring system gestures.
|
|
||||||
- On iOS, fix a crash that occurred while acquiring a monitor's name.
|
|
||||||
- On iOS, fix armv7-apple-ios compile target.
|
|
||||||
- Removed the `T: Clone` requirement from the `Clone` impl of `EventLoopProxy<T>`.
|
|
||||||
- On iOS, disable overscan compensation for external displays (removes black
|
|
||||||
bars surrounding the image).
|
|
||||||
- On Linux, the functions `is_wayland`, `is_x11`, `xlib_xconnection` and `wayland_display` have been moved to a new `EventLoopWindowTargetExtUnix` trait.
|
|
||||||
- On iOS, add `set_prefers_status_bar_hidden` extension function instead of
|
|
||||||
hijacking `set_decorations` for this purpose.
|
|
||||||
- On macOS and iOS, corrected the auto trait impls of `EventLoopProxy`.
|
|
||||||
- On iOS, add touch pressure information for touch events.
|
|
||||||
- Implement `raw_window_handle::HasRawWindowHandle` for `Window` type on all supported platforms.
|
|
||||||
- On macOS, fix the signature of `-[NSView drawRect:]`.
|
|
||||||
- On iOS, fix the behavior of `ControlFlow::Poll`. It wasn't polling if that was the only mode ever used by the application.
|
|
||||||
- On iOS, fix DPI sent out by views on creation was `0.0` - now it gives a reasonable number.
|
|
||||||
- On iOS, RedrawRequested now works for gl/metal backed views.
|
|
||||||
- On iOS, RedrawRequested is generally ordered after EventsCleared.
|
|
||||||
|
|
||||||
# 0.20.0 Alpha 2 (2019-07-09)
|
|
||||||
|
|
||||||
- On X11, non-resizable windows now have maximize explicitly disabled.
|
|
||||||
- On Windows, support paths longer than MAX_PATH (260 characters) in `WindowEvent::DroppedFile`
|
|
||||||
and `WindowEvent::HoveredFile`.
|
|
||||||
- On Mac, implement `DeviceEvent::Button`.
|
|
||||||
- Change `Event::Suspended(true / false)` to `Event::Suspended` and `Event::Resumed`.
|
|
||||||
- On X11, fix sanity check which checks that a monitor's reported width and height (in millimeters) are non-zero when calculating the DPI factor.
|
|
||||||
- Revert the use of invisible surfaces in Wayland, which introduced graphical glitches with OpenGL (#835)
|
|
||||||
- On X11, implement `_NET_WM_PING` to allow desktop environment to kill unresponsive programs.
|
|
||||||
- On Windows, when a window is initially invisible, it won't take focus from the existing visible windows.
|
|
||||||
- On Windows, fix multiple calls to `request_redraw` during `EventsCleared` sending multiple `RedrawRequested events.`
|
|
||||||
- On Windows, fix edge case where `RedrawRequested` could be dispatched before input events in event loop iteration.
|
|
||||||
- On Windows, fix timing issue that could cause events to be improperly dispatched after `RedrawRequested` but before `EventsCleared`.
|
|
||||||
- On macOS, drop unused Metal dependency.
|
|
||||||
- On Windows, fix the trail effect happening on transparent decorated windows. Borderless (or un-decorated) windows were not affected.
|
|
||||||
- On Windows, fix `with_maximized` not properly setting window size to entire window.
|
|
||||||
- On macOS, change `WindowExtMacOS::request_user_attention()` to take an `enum` instead of a `bool`.
|
|
||||||
|
|
||||||
# 0.20.0 Alpha 1 (2019-06-21)
|
|
||||||
|
|
||||||
- Changes below are considered **breaking**.
|
|
||||||
- Change all occurrences of `EventsLoop` to `EventLoop`.
|
|
||||||
- Previously flat API is now exposed through `event`, `event_loop`, `monitor`, and `window` modules.
|
|
||||||
- `os` module changes:
|
|
||||||
- Renamed to `platform`.
|
|
||||||
- All traits now have platform-specific suffixes.
|
|
||||||
- Exposes new `desktop` module on Windows, Mac, and Linux.
|
|
||||||
- Changes to event loop types:
|
|
||||||
- `EventLoopProxy::wakeup` has been removed in favor of `send_event`.
|
|
||||||
- **Major:** New `run` method drives winit event loop.
|
|
||||||
- Returns `!` to ensure API behaves identically across all supported platforms.
|
|
||||||
- This allows `emscripten` implementation to work without lying about the API.
|
|
||||||
- `ControlFlow`'s variants have been replaced with `Wait`, `WaitUntil(Instant)`, `Poll`, and `Exit`.
|
|
||||||
- Is read after `EventsCleared` is processed.
|
|
||||||
- `Wait` waits until new events are available.
|
|
||||||
- `WaitUntil` waits until either new events are available or the provided time has been reached.
|
|
||||||
- `Poll` instantly resumes the event loop.
|
|
||||||
- `Exit` aborts the event loop.
|
|
||||||
- Takes a closure that implements `'static + FnMut(Event<T>, &EventLoop<T>, &mut ControlFlow)`.
|
|
||||||
- `&EventLoop<T>` is provided to allow new `Window`s to be created.
|
|
||||||
- **Major:** `platform::desktop` module exposes `EventLoopExtDesktop` trait with `run_return` method.
|
|
||||||
- Behaves identically to `run`, but returns control flow to the calling context and can take non-`'static` closures.
|
|
||||||
- `EventLoop`'s `poll_events` and `run_forever` methods have been removed in favor of `run` and `run_return`.
|
|
||||||
- Changes to events:
|
|
||||||
- Remove `Event::Awakened` in favor of `Event::UserEvent(T)`.
|
|
||||||
- Can be sent with `EventLoopProxy::send_event`.
|
|
||||||
- Rename `WindowEvent::Refresh` to `WindowEvent::RedrawRequested`.
|
|
||||||
- `RedrawRequested` can be sent by the user with the `Window::request_redraw` method.
|
|
||||||
- `EventLoop`, `EventLoopProxy`, and `Event` are now generic over `T`, for use in `UserEvent`.
|
|
||||||
- **Major:** Add `NewEvents(StartCause)`, `EventsCleared`, and `LoopDestroyed` variants to `Event`.
|
|
||||||
- `NewEvents` is emitted when new events are ready to be processed by event loop.
|
|
||||||
- `StartCause` describes why new events are available, with `ResumeTimeReached`, `Poll`, `WaitCancelled`, and `Init` (sent once at start of loop).
|
|
||||||
- `EventsCleared` is emitted when all available events have been processed.
|
|
||||||
- Can be used to perform logic that depends on all events being processed (e.g. an iteration of a game loop).
|
|
||||||
- `LoopDestroyed` is emitted when the `run` or `run_return` method is about to exit.
|
|
||||||
- Rename `MonitorId` to `MonitorHandle`.
|
|
||||||
- Removed `serde` implementations from `ControlFlow`.
|
|
||||||
- Rename several functions to improve both internal consistency and compliance with Rust API guidelines.
|
|
||||||
- Remove `WindowBuilder::multitouch` field, since it was only implemented on a few platforms. Multitouch is always enabled now.
|
|
||||||
- **Breaking:** On macOS, change `ns` identifiers to use snake_case for consistency with iOS's `ui` identifiers.
|
|
||||||
- Add `MonitorHandle::video_modes` method for retrieving supported video modes for the given monitor.
|
|
||||||
- On Wayland, the window now exists even if nothing has been drawn.
|
|
||||||
- On Windows, fix initial dimensions of a fullscreen window.
|
|
||||||
- On Windows, Fix transparent borderless windows rendering wrong.
|
|
||||||
|
|
||||||
# Version 0.19.1 (2019-04-08)
|
|
||||||
|
|
||||||
- On Wayland, added a `get_wayland_display` function to `EventsLoopExt`.
|
|
||||||
- On Windows, fix `CursorMoved(0, 0)` getting dispatched on window focus.
|
|
||||||
- On macOS, fix command key event left and right reverse.
|
|
||||||
- On FreeBSD, NetBSD, and OpenBSD, fix build of X11 backend.
|
|
||||||
- On Linux, the numpad's add, subtract and divide keys are now mapped to the `Add`, `Subtract` and `Divide` virtual key codes
|
|
||||||
- On macOS, the numpad's subtract key has been added to the `Subtract` mapping
|
|
||||||
- On Wayland, the numpad's home, end, page up and page down keys are now mapped to the `Home`, `End`, `PageUp` and `PageDown` virtual key codes
|
|
||||||
- On Windows, fix icon not showing up in corner of window.
|
|
||||||
- On X11, change DPI scaling factor behavior. First, winit tries to read it from "Xft.dpi" XResource, and uses DPI calculation from xrandr dimensions as fallback behavior.
|
|
||||||
|
|
||||||
# Version 0.19.0 (2019-03-06)
|
|
||||||
|
|
||||||
- On X11, we will use the faster `XRRGetScreenResourcesCurrent` function instead of `XRRGetScreenResources` when available.
|
|
||||||
- On macOS, fix keycodes being incorrect when using a non-US keyboard layout.
|
|
||||||
- On Wayland, fix `with_title()` not setting the windows title
|
|
||||||
- On Wayland, add `set_wayland_theme()` to control client decoration color theme
|
|
||||||
- Added serde serialization to `os::unix::XWindowType`.
|
|
||||||
- **Breaking:** Remove the `icon_loading` feature and the associated `image` dependency.
|
|
||||||
- On X11, make event loop thread safe by replacing XNextEvent with select(2) and XCheckIfEvent
|
|
||||||
- On Windows, fix malformed function pointer typecast that could invoke undefined behavior.
|
|
||||||
- Refactored Windows state/flag-setting code.
|
|
||||||
- On Windows, hiding the cursor no longer hides the cursor for all Winit windows - just the one `hide_cursor` was called on.
|
|
||||||
- On Windows, cursor grabs used to get perpetually canceled when the grabbing window lost focus. Now, cursor grabs automatically get re-initialized when the window regains focus and the mouse moves over the client area.
|
|
||||||
- On Windows, only vertical mouse wheel events were handled. Now, horizontal mouse wheel events are also handled.
|
|
||||||
- On Windows, ignore the AltGr key when populating the `ModifersState` type.
|
|
||||||
|
|
||||||
# Version 0.18.1 (2018-12-30)
|
|
||||||
|
|
||||||
- On macOS, fix `Yen` (JIS) so applications receive the event.
|
|
||||||
- On X11 with a tiling WM, fixed high CPU usage when moving windows across monitors.
|
|
||||||
- On X11, fixed panic caused by dropping the window before running the event loop.
|
|
||||||
- on macOS, added `WindowExt::set_simple_fullscreen` which does not require a separate space
|
|
||||||
- Introduce `WindowBuilderExt::with_app_id` to allow setting the application ID on Wayland.
|
|
||||||
- On Windows, catch panics in event loop child thread and forward them to the parent thread. This prevents an invocation of undefined behavior due to unwinding into foreign code.
|
|
||||||
- On Windows, fix issue where resizing or moving window combined with grabbing the cursor would freeze program.
|
|
||||||
- On Windows, fix issue where resizing or moving window would eat `Awakened` events.
|
|
||||||
- On Windows, exiting fullscreen after entering fullscreen with disabled decorations no longer shrinks window.
|
|
||||||
- On X11, fixed a segfault when using virtual monitors with XRandR.
|
|
||||||
- Derive `Ord` and `PartialOrd` for `VirtualKeyCode` enum.
|
|
||||||
- On Windows, fix issue where hovering or dropping a non file item would create a panic.
|
|
||||||
- On Wayland, fix resizing and DPI calculation when a `wl_output` is removed without sending a `leave` event to the `wl_surface`, such as disconnecting a monitor from a laptop.
|
|
||||||
- On Wayland, DPI calculation is handled by smithay-client-toolkit.
|
|
||||||
- On X11, `WindowBuilder::with_min_dimensions` and `WindowBuilder::with_max_dimensions` now correctly account for DPI.
|
|
||||||
- Added support for generating dummy `DeviceId`s and `WindowId`s to better support unit testing.
|
|
||||||
- On macOS, fixed unsoundness in drag-and-drop that could result in drops being rejected.
|
|
||||||
- On macOS, implemented `WindowEvent::Refresh`.
|
|
||||||
- On macOS, all `MouseCursor` variants are now implemented and the cursor will no longer reset after unfocusing.
|
|
||||||
- Removed minimum supported Rust version guarantee.
|
|
||||||
|
|
||||||
# Version 0.18.0 (2018-11-07)
|
|
||||||
|
|
||||||
- **Breaking:** `image` crate upgraded to 0.20. This is exposed as part of the `icon_loading` API.
|
|
||||||
- On Wayland, pointer events will now provide the current modifiers state.
|
|
||||||
- On Wayland, titles will now be displayed in the window header decoration.
|
|
||||||
- On Wayland, key repetition is now ended when keyboard loses focus.
|
|
||||||
- On Wayland, windows will now use more stylish and modern client side decorations.
|
|
||||||
- On Wayland, windows will use server-side decorations when available.
|
|
||||||
- **Breaking:** Added support for F16-F24 keys (variants were added to the `VirtualKeyCode` enum).
|
|
||||||
- Fixed graphical glitches when resizing on Wayland.
|
|
||||||
- On Windows, fix freezes when performing certain actions after a window resize has been triggered. Reintroduces some visual artifacts when resizing.
|
|
||||||
- Updated window manager hints under X11 to v1.5 of [Extended Window Manager Hints](https://specifications.freedesktop.org/wm-spec/wm-spec-1.5.html#idm140200472629520).
|
|
||||||
- Added `WindowBuilderExt::with_gtk_theme_variant` to X11-specific `WindowBuilder` functions.
|
|
||||||
- Fixed UTF8 handling bug in X11 `set_title` function.
|
|
||||||
- On Windows, `Window::set_cursor` now applies immediately instead of requiring specific events to occur first.
|
|
||||||
- On Windows, the `HoveredFile` and `HoveredFileCancelled` events are now implemented.
|
|
||||||
- On Windows, fix `Window::set_maximized`.
|
|
||||||
- On Windows 10, fix transparency (#260).
|
|
||||||
- On macOS, fix modifiers during key repeat.
|
|
||||||
- Implemented the `Debug` trait for `Window`, `EventsLoop`, `EventsLoopProxy` and `WindowBuilder`.
|
|
||||||
- On X11, now a `Resized` event will always be generated after a DPI change to ensure the window's logical size is consistent with the new DPI.
|
|
||||||
- Added further clarifications to the DPI docs.
|
|
||||||
- On Linux, if neither X11 nor Wayland manage to initialize, the corresponding panic now consists of a single line only.
|
|
||||||
- Add optional `serde` feature with implementations of `Serialize`/`Deserialize` for DPI types and various event types.
|
|
||||||
- Add `PartialEq`, `Eq`, and `Hash` implementations on public types that could have them but were missing them.
|
|
||||||
- On X11, drag-and-drop receiving an unsupported drop type can no longer cause the WM to freeze.
|
|
||||||
- Fix issue whereby the OpenGL context would not appear at startup on macOS Mojave (#1069).
|
|
||||||
- **Breaking:** Removed `From<NSApplicationActivationPolicy>` impl from `ActivationPolicy` on macOS.
|
|
||||||
- On macOS, the application can request the user's attention with `WindowExt::request_user_attention`.
|
|
||||||
|
|
||||||
# Version 0.17.2 (2018-08-19)
|
|
||||||
|
|
||||||
- On macOS, fix `<C-Tab>` so applications receive the event.
|
|
||||||
- On macOS, fix `<Cmd-{key}>` so applications receive the event.
|
|
||||||
- On Wayland, key press events will now be repeated.
|
|
||||||
|
|
||||||
# Version 0.17.1 (2018-08-05)
|
|
||||||
|
|
||||||
- On X11, prevent a compilation failure in release mode for versions of Rust greater than or equal to 1.30.
|
|
||||||
- Fixed deadlock that broke fullscreen mode on Windows.
|
|
||||||
|
|
||||||
# Version 0.17.0 (2018-08-02)
|
|
||||||
|
|
||||||
- Cocoa and core-graphics updates.
|
|
||||||
- Fixed thread-safety issues in several `Window` functions on Windows.
|
|
||||||
- On MacOS, the key state for modifiers key events is now properly set.
|
|
||||||
- On iOS, the view is now set correctly. This makes it possible to render things (instead of being stuck on a black screen), and touch events work again.
|
|
||||||
- Added NetBSD support.
|
|
||||||
- **Breaking:** On iOS, `UIView` is now the default root view. `WindowBuilderExt::with_root_view_class` can be used to set the root view objective-c class to `GLKView` (OpenGLES) or `MTKView` (Metal/MoltenVK).
|
|
||||||
- On iOS, the `UIApplication` is not started until `Window::new` is called.
|
|
||||||
- Fixed thread unsafety with cursor hiding on macOS.
|
|
||||||
- On iOS, fixed the size of the `JmpBuf` type used for `setjmp`/`longjmp` calls. Previously this was a buffer overflow on most architectures.
|
|
||||||
- On Windows, use cached window DPI instead of repeatedly querying the system. This fixes sporadic crashes on Windows 7.
|
|
||||||
|
|
||||||
# Version 0.16.2 (2018-07-07)
|
|
||||||
|
|
||||||
- On Windows, non-resizable windows now have the maximization button disabled. This is consistent with behavior on macOS and popular X11 WMs.
|
|
||||||
- Corrected incorrect `unreachable!` usage when guessing the DPI factor with no detected monitors.
|
|
||||||
|
|
||||||
# Version 0.16.1 (2018-07-02)
|
|
||||||
|
|
||||||
- Added logging through `log`. Logging will become more extensive over time.
|
|
||||||
- On X11 and Windows, the window's DPI factor is guessed before creating the window. This *greatly* cuts back on unsightly auto-resizing that would occur immediately after window creation.
|
|
||||||
- Fixed X11 backend compilation for environments where `c_char` is unsigned.
|
|
||||||
|
|
||||||
# Version 0.16.0 (2018-06-25)
|
|
||||||
|
|
||||||
- Windows additionally has `WindowBuilderExt::with_no_redirection_bitmap`.
|
|
||||||
- **Breaking:** Removed `VirtualKeyCode::LMenu` and `VirtualKeyCode::RMenu`; Windows now generates `VirtualKeyCode::LAlt` and `VirtualKeyCode::RAlt` instead.
|
|
||||||
- On X11, exiting fullscreen no longer leaves the window in the monitor's top left corner.
|
|
||||||
- **Breaking:** `Window::hidpi_factor` has been renamed to `Window::get_hidpi_factor` for better consistency. `WindowEvent::HiDPIFactorChanged` has been renamed to `WindowEvent::HiDpiFactorChanged`. DPI factors are always represented as `f64` instead of `f32` now.
|
|
||||||
- The Windows backend is now DPI aware. `WindowEvent::HiDpiFactorChanged` is implemented, and `MonitorId::get_hidpi_factor` and `Window::hidpi_factor` return accurate values.
|
|
||||||
- Implemented `WindowEvent::HiDpiFactorChanged` on X11.
|
|
||||||
- On macOS, `Window::set_cursor_position` is now relative to the client area.
|
|
||||||
- On macOS, setting the maximum and minimum dimensions now applies to the client area dimensions rather than to the window dimensions.
|
|
||||||
- On iOS, `MonitorId::get_dimensions` has been implemented and both `MonitorId::get_hidpi_factor` and `Window::get_hidpi_factor` return accurate values.
|
|
||||||
- On Emscripten, `MonitorId::get_hidpi_factor` now returns the same value as `Window::get_hidpi_factor` (it previously would always return 1.0).
|
|
||||||
- **Breaking:** The entire API for sizes, positions, etc. has changed. In the majority of cases, winit produces and consumes positions and sizes as `LogicalPosition` and `LogicalSize`, respectively. The notable exception is `MonitorId` methods, which deal in `PhysicalPosition` and `PhysicalSize`. See the documentation for specifics and explanations of the types. Additionally, winit automatically conserves logical size when the DPI factor changes.
|
|
||||||
- **Breaking:** All deprecated methods have been removed. For `Window::platform_display` and `Window::platform_window`, switch to the appropriate platform-specific `WindowExt` methods. For `Window::get_inner_size_points` and `Window::get_inner_size_pixels`, use the `LogicalSize` returned by `Window::get_inner_size` and convert as needed.
|
|
||||||
- HiDPI support for Wayland.
|
|
||||||
- `EventsLoop::get_available_monitors` and `EventsLoop::get_primary_monitor` now have identical counterparts on `Window`, so this information can be acquired without an `EventsLoop` borrow.
|
|
||||||
- `AvailableMonitorsIter` now implements `Debug`.
|
|
||||||
- Fixed quirk on macOS where certain keys would generate characters at twice the normal rate when held down.
|
|
||||||
- On X11, all event loops now share the same `XConnection`.
|
|
||||||
- **Breaking:** `Window::set_cursor_state` and `CursorState` enum removed in favor of the more composable `Window::grab_cursor` and `Window::hide_cursor`. As a result, grabbing the cursor no longer automatically hides it; you must call both methods to retain the old behavior on Windows and macOS. `Cursor::NoneCursor` has been removed, as it's no longer useful.
|
|
||||||
- **Breaking:** `Window::set_cursor_position` now returns `Result<(), String>`, thus allowing for `Box<Error>` conversion via `?`.
|
|
||||||
|
|
||||||
# Version 0.15.1 (2018-06-13)
|
|
||||||
|
|
||||||
- On X11, the `Moved` event is no longer sent when the window is resized without changing position.
|
|
||||||
- `MouseCursor` and `CursorState` now implement `Default`.
|
|
||||||
- `WindowBuilder::with_resizable` implemented for Windows, X11, Wayland, and macOS.
|
|
||||||
- `Window::set_resizable` implemented for Windows, X11, Wayland, and macOS.
|
|
||||||
- On X11, if the monitor's width or height in millimeters is reported as 0, the DPI is now 1.0 instead of +inf.
|
|
||||||
- On X11, the environment variable `WINIT_HIDPI_FACTOR` has been added for overriding DPI factor.
|
|
||||||
- On X11, enabling transparency no longer causes the window contents to flicker when resizing.
|
|
||||||
- On X11, `with_override_redirect` now actually enables override redirect.
|
|
||||||
- macOS now generates `VirtualKeyCode::LAlt` and `VirtualKeyCode::RAlt` instead of `None` for both.
|
|
||||||
- On macOS, `VirtualKeyCode::RWin` and `VirtualKeyCode::LWin` are no longer switched.
|
|
||||||
- On macOS, windows without decorations can once again be resized.
|
|
||||||
- Fixed race conditions when creating an `EventsLoop` on X11, most commonly manifesting as "[xcb] Unknown sequence number while processing queue".
|
|
||||||
- On macOS, `CursorMoved` and `MouseInput` events are only generated if they occurs within the window's client area.
|
|
||||||
- On macOS, resizing the window no longer generates a spurious `MouseInput` event.
|
|
||||||
|
|
||||||
# Version 0.15.0 (2018-05-22)
|
|
||||||
|
|
||||||
- `Icon::to_cardinals` is no longer public, since it was never supposed to be.
|
|
||||||
- Wayland: improve diagnostics if initialization fails
|
|
||||||
- Fix some system event key doesn't work when focused, do not block keyevent forward to system on macOS
|
|
||||||
- On X11, the scroll wheel position is now correctly reset on i3 and other WMs that have the same quirk.
|
|
||||||
- On X11, `Window::get_current_monitor` now reliably returns the correct monitor.
|
|
||||||
- On X11, `Window::hidpi_factor` returns values from XRandR rather than the inaccurate values previously queried from the core protocol.
|
|
||||||
- On X11, the primary monitor is detected correctly even when using versions of XRandR less than 1.5.
|
|
||||||
- `MonitorId` now implements `Debug`.
|
|
||||||
- Fixed bug on macOS where using `with_decorations(false)` would cause `set_decorations(true)` to produce a transparent titlebar with no title.
|
|
||||||
- Implemented `MonitorId::get_position` on macOS.
|
|
||||||
- On macOS, `Window::get_current_monitor` now returns accurate values.
|
|
||||||
- Added `WindowBuilderExt::with_resize_increments` to macOS.
|
|
||||||
- **Breaking:** On X11, `WindowBuilderExt::with_resize_increments` and `WindowBuilderExt::with_base_size` now take `u32` values rather than `i32`.
|
|
||||||
- macOS keyboard handling has been overhauled, allowing for the use of dead keys, IME, etc. Right modifier keys are also no longer reported as being left.
|
|
||||||
- Added the `Window::set_ime_spot(x: i32, y: i32)` method, which is implemented on X11 and macOS.
|
|
||||||
- **Breaking**: `os::unix::WindowExt::send_xim_spot(x: i16, y: i16)` no longer exists. Switch to the new `Window::set_ime_spot(x: i32, y: i32)`, which has equivalent functionality.
|
|
||||||
- Fixed detection of `Pause` and `Scroll` keys on Windows.
|
|
||||||
- On Windows, alt-tabbing while the cursor is grabbed no longer makes it impossible to re-grab the cursor.
|
|
||||||
- On Windows, using `CursorState::Hide` when the cursor is grabbed now ungrabs the cursor first.
|
|
||||||
- Implemented `MouseCursor::NoneCursor` on Windows.
|
|
||||||
- Added `WindowBuilder::with_always_on_top` and `Window::set_always_on_top`. Implemented on Windows, macOS, and X11.
|
|
||||||
- On X11, `WindowBuilderExt` now has `with_class`, `with_override_redirect`, and `with_x11_window_type` to allow for more control over window creation. `WindowExt` additionally has `set_urgent`.
|
|
||||||
- More hints are set by default on X11, including `_NET_WM_PID` and `WM_CLIENT_MACHINE`. Note that prior to this, the `WM_CLASS` hint was automatically set to whatever value was passed to `with_title`. It's now set to the executable name to better conform to expectations and the specification; if this is undesirable, you must explicitly use `WindowBuilderExt::with_class`.
|
|
||||||
|
|
||||||
# Version 0.14.0 (2018-05-09)
|
|
||||||
|
|
||||||
- Created the `Copy`, `Paste` and `Cut` `VirtualKeyCode`s and added support for them on X11 and Wayland
|
|
||||||
- Fix `.with_decorations(false)` in macOS
|
|
||||||
- On Mac, `NSWindow` and supporting objects might be alive long after they were `closed` which resulted in apps consuming more heap then needed. Mainly it was affecting multi window applications. Not expecting any user visible change of behaviour after the fix.
|
|
||||||
- Fix regression of Window platform extensions for macOS where `NSFullSizeContentViewWindowMask` was not being correctly applied to `.fullsize_content_view`.
|
|
||||||
- Corrected `get_position` on Windows to be relative to the screen rather than to the taskbar.
|
|
||||||
- Corrected `Moved` event on Windows to use position values equivalent to those returned by `get_position`. It previously supplied client area positions instead of window positions, and would additionally interpret negative values as being very large (around `u16::MAX`).
|
|
||||||
- Implemented `Moved` event on macOS.
|
|
||||||
- On X11, the `Moved` event correctly use window positions rather than client area positions. Additionally, a stray `Moved` that unconditionally accompanied `Resized` with the client area position relative to the parent has been eliminated; `Moved` is still received alongside `Resized`, but now only once and always correctly.
|
|
||||||
- On Windows, implemented all variants of `DeviceEvent` other than `Text`. Mouse `DeviceEvent`s are now received even if the window isn't in the foreground.
|
|
||||||
- `DeviceId` on Windows is no longer a unit struct, and now contains a `u32`. For `WindowEvent`s, this will always be 0, but on `DeviceEvent`s it will be the handle to that device. `DeviceIdExt::get_persistent_identifier` can be used to acquire a unique identifier for that device that persists across replugs/reboots/etc.
|
|
||||||
- Corrected `run_forever` on X11 to stop discarding `Awakened` events.
|
|
||||||
- Various safety and correctness improvements to the X11 backend internals.
|
|
||||||
- Fixed memory leak on X11 every time the mouse entered the window.
|
|
||||||
- On X11, drag and drop now works reliably in release mode.
|
|
||||||
- Added `WindowBuilderExt::with_resize_increments` and `WindowBuilderExt::with_base_size` to X11, allowing for more optional hints to be set.
|
|
||||||
- Rework of the wayland backend, migrating it to use [Smithay's Client Toolkit](https://github.com/Smithay/client-toolkit).
|
|
||||||
- Added `WindowBuilder::with_window_icon` and `Window::set_window_icon`, finally making it possible to set the window icon on Windows and X11. The `icon_loading` feature can be enabled to allow for icons to be easily loaded; see example program `window_icon.rs` for usage.
|
|
||||||
- Windows additionally has `WindowBuilderExt::with_taskbar_icon` and `WindowExt::set_taskbar_icon`.
|
|
||||||
- On Windows, fix panic when trying to call `set_fullscreen(None)` on a window that has not been fullscreened prior.
|
|
||||||
|
|
||||||
# Version 0.13.1 (2018-04-26)
|
|
||||||
|
|
||||||
- Ensure necessary `x11-dl` version is used.
|
|
||||||
|
|
||||||
# Version 0.13.0 (2018-04-25)
|
|
||||||
|
|
||||||
- Implement `WindowBuilder::with_maximized`, `Window::set_fullscreen`, `Window::set_maximized` and `Window::set_decorations` for MacOS.
|
|
||||||
- Implement `WindowBuilder::with_maximized`, `Window::set_fullscreen`, `Window::set_maximized` and `Window::set_decorations` for Windows.
|
|
||||||
- On Windows, `WindowBuilder::with_fullscreen` no longer changing monitor display resolution.
|
|
||||||
- Overhauled X11 window geometry calculations. `get_position` and `set_position` are more universally accurate across different window managers, and `get_outer_size` actually works now.
|
|
||||||
- Fixed SIGSEGV/SIGILL crashes on macOS caused by stabilization of the `!` (never) type.
|
|
||||||
- Implement `WindowEvent::HiDPIFactorChanged` for macOS
|
|
||||||
- On X11, input methods now work completely out of the box, no longer requiring application developers to manually call `setlocale`. Additionally, when input methods are started, stopped, or restarted on the server end, it's correctly handled.
|
|
||||||
- Implemented `Refresh` event on Windows.
|
|
||||||
- Properly calculate the minimum and maximum window size on Windows, including window decorations.
|
|
||||||
- Map more `MouseCursor` variants to cursor icons on Windows.
|
|
||||||
- Corrected `get_position` on macOS to return outer frame position, not content area position.
|
|
||||||
- Corrected `set_position` on macOS to set outer frame position, not content area position.
|
|
||||||
- Added `get_inner_position` method to `Window`, which gets the position of the window's client area. This is implemented on all applicable platforms (all desktop platforms other than Wayland, where this isn't possible).
|
|
||||||
- **Breaking:** the `Closed` event has been replaced by `CloseRequested` and `Destroyed`. To migrate, you typically just need to replace all usages of `Closed` with `CloseRequested`; see example programs for more info. The exception is iOS, where `Closed` must be replaced by `Destroyed`.
|
|
||||||
|
|
||||||
# Version 0.12.0 (2018-04-06)
|
|
||||||
|
|
||||||
- Added subclass to macos windows so they can be made resizable even with no decorations.
|
|
||||||
- Dead keys now work properly on X11, no longer resulting in a panic.
|
|
||||||
- On X11, input method creation first tries to use the value from the user's `XMODIFIERS` environment variable, so application developers should no longer need to manually call `XSetLocaleModifiers`. If that fails, fallbacks are tried, which should prevent input method initialization from ever outright failing.
|
|
||||||
- Fixed thread safety issues with input methods on X11.
|
|
||||||
- Add support for `Touch` for win32 backend.
|
|
||||||
- Fixed `Window::get_inner_size` and friends to return the size in pixels instead of points when using HIDPI displays on OSX.
|
|
||||||
|
|
||||||
# Version 0.11.3 (2018-03-28)
|
|
||||||
|
|
||||||
- Added `set_min_dimensions` and `set_max_dimensions` methods to `Window`, and implemented on Windows, X11, Wayland, and OSX.
|
|
||||||
- On X11, dropping a `Window` actually closes it now, and clicking the window's × button (or otherwise having the WM signal to close it) will result in the window closing.
|
|
||||||
- Added `WindowBuilderExt` methods for macos: `with_titlebar_transparent`,
|
|
||||||
`with_title_hidden`, `with_titlebar_buttons_hidden`,
|
|
||||||
`with_fullsize_content_view`.
|
|
||||||
- Mapped X11 numpad keycodes (arrows, Home, End, PageUp, PageDown, Insert and Delete) to corresponding virtual keycodes
|
|
||||||
|
|
||||||
# Version 0.11.2 (2018-03-06)
|
|
||||||
|
|
||||||
- Impl `Hash`, `PartialEq`, and `Eq` for `events::ModifiersState`.
|
|
||||||
- Implement `MonitorId::get_hidpi_factor` for MacOS.
|
|
||||||
- Added method `os::macos::MonitorIdExt::get_nsscreen() -> *mut c_void` that gets a `NSScreen` object matching the monitor ID.
|
|
||||||
- Send `Awakened` event on Android when event loop is woken up.
|
|
||||||
|
|
||||||
# Version 0.11.1 (2018-02-19)
|
|
||||||
|
|
||||||
- Fixed windows not receiving mouse events when click-dragging the mouse outside the client area of a window, on Windows platforms.
|
|
||||||
- Added method `os::android::EventsLoopExt:set_suspend_callback(Option<Box<Fn(bool) -> ()>>)` that allows glutin to register a callback when a suspend event happens
|
|
||||||
|
|
||||||
# Version 0.11.0 (2018-02-09)
|
|
||||||
|
|
||||||
- Implement `MonitorId::get_dimensions` for Android.
|
|
||||||
- Added method `os::macos::WindowBuilderExt::with_movable_by_window_background(bool)` that allows to move a window without a titlebar - `with_decorations(false)`
|
|
||||||
- Implement `Window::set_fullscreen`, `Window::set_maximized` and `Window::set_decorations` for Wayland.
|
|
||||||
- Added `Caret` as VirtualKeyCode and support OSX ^-Key with german input.
|
|
||||||
|
|
||||||
# Version 0.10.1 (2018-02-05)
|
|
||||||
|
|
||||||
*Yanked*
|
|
||||||
|
|
||||||
# Version 0.10.0 (2017-12-27)
|
|
||||||
|
|
||||||
- Add support for `Touch` for emscripten backend.
|
|
||||||
- Added support for `DroppedFile`, `HoveredFile`, and `HoveredFileCancelled` to X11 backend.
|
|
||||||
- **Breaking:** `unix::WindowExt` no longer returns pointers for things that aren't actually pointers; `get_xlib_window` now returns `Option<std::os::raw::c_ulong>` and `get_xlib_screen_id` returns `Option<std::os::raw::c_int>`. Additionally, methods that previously returned `libc::c_void` have been changed to return `std::os::raw::c_void`, which are not interchangeable types, so users wanting the former will need to explicitly cast.
|
|
||||||
- Added `set_decorations` method to `Window` to allow decorations to be toggled after the window is built. Presently only implemented on X11.
|
|
||||||
- Raised the minimum supported version of Rust to 1.20 on MacOS due to usage of associated constants in new versions of cocoa and core-graphics.
|
|
||||||
- Added `modifiers` field to `MouseInput`, `MouseWheel`, and `CursorMoved` events to track the modifiers state (`ModifiersState`).
|
|
||||||
- Fixed the emscripten backend to return the size of the canvas instead of the size of the window.
|
|
||||||
|
|
||||||
# Version 0.9.0 (2017-12-01)
|
|
||||||
|
|
||||||
- Added event `WindowEvent::HiDPIFactorChanged`.
|
|
||||||
- Added method `MonitorId::get_hidpi_factor`.
|
|
||||||
- Deprecated `get_inner_size_pixels` and `get_inner_size_points` methods of `Window` in favor of
|
|
||||||
`get_inner_size`.
|
|
||||||
- **Breaking:** `EventsLoop` is `!Send` and `!Sync` because of platform-dependant constraints,
|
|
||||||
but `Window`, `WindowId`, `DeviceId` and `MonitorId` guaranteed to be `Send`.
|
|
||||||
- `MonitorId::get_position` now returns `(i32, i32)` instead of `(u32, u32)`.
|
|
||||||
- Rewrite of the wayland backend to use wayland-client-0.11
|
|
||||||
- Support for dead keys on wayland for keyboard utf8 input
|
|
||||||
- Monitor enumeration on Windows is now implemented using `EnumDisplayMonitors` instead of
|
|
||||||
`EnumDisplayDevices`. This changes the value returned by `MonitorId::get_name()`.
|
|
||||||
- On Windows added `MonitorIdExt::hmonitor` method
|
|
||||||
- Impl `Clone` for `EventsLoopProxy`
|
|
||||||
- `EventsLoop::get_primary_monitor()` on X11 will fallback to any available monitor if no primary is found
|
|
||||||
- Support for touch event on wayland
|
|
||||||
- `WindowEvent`s `MouseMoved`, `MouseEntered`, and `MouseLeft` have been renamed to
|
|
||||||
`CursorMoved`, `CursorEntered`, and `CursorLeft`.
|
|
||||||
- New `DeviceEvent`s added, `MouseMotion` and `MouseWheel`.
|
|
||||||
- Send `CursorMoved` event after `CursorEntered` and `Focused` events.
|
|
||||||
- Add support for `ModifiersState`, `MouseMove`, `MouseInput`, `MouseMotion` for emscripten backend.
|
|
||||||
|
|
||||||
# Version 0.8.3 (2017-10-11)
|
|
||||||
|
|
||||||
- Fixed issue of calls to `set_inner_size` blocking on Windows.
|
|
||||||
- Mapped `ISO_Left_Tab` to `VirtualKeyCode::Tab` to make the key work with modifiers
|
|
||||||
- Fixed the X11 backed on 32bit targets
|
|
||||||
|
|
||||||
# Version 0.8.2 (2017-09-28)
|
|
||||||
|
|
||||||
- Uniformize keyboard scancode values accross Wayland and X11 (#297).
|
|
||||||
- Internal rework of the wayland event loop
|
|
||||||
- Added method `os::linux::WindowExt::is_ready`
|
|
||||||
|
|
||||||
# Version 0.8.1 (2017-09-22)
|
|
||||||
|
|
||||||
- Added various methods to `os::linux::EventsLoopExt`, plus some hidden items necessary to make
|
|
||||||
glutin work.
|
|
||||||
|
|
||||||
# Version 0.8.0 (2017-09-21)
|
|
||||||
|
|
||||||
- Added `Window::set_maximized`, `WindowAttributes::maximized` and `WindowBuilder::with_maximized`.
|
|
||||||
- Added `Window::set_fullscreen`.
|
|
||||||
- Changed `with_fullscreen` to take a `Option<MonitorId>` instead of a `MonitorId`.
|
|
||||||
- Removed `MonitorId::get_native_identifer()` in favor of platform-specific traits in the `os`
|
|
||||||
module.
|
|
||||||
- Changed `get_available_monitors()` and `get_primary_monitor()` to be methods of `EventsLoop`
|
|
||||||
instead of stand-alone methods.
|
|
||||||
- Changed `EventsLoop` to be tied to a specific X11 or Wayland connection.
|
|
||||||
- Added a `os::linux::EventsLoopExt` trait that makes it possible to configure the connection.
|
|
||||||
- Fixed the emscripten code, which now compiles.
|
|
||||||
- Changed the X11 fullscreen code to use `xrandr` instead of `xxf86vm`.
|
|
||||||
- Fixed the Wayland backend to produce `Refresh` event after window creation.
|
|
||||||
- Changed the `Suspended` event to be outside of `WindowEvent`.
|
|
||||||
- Fixed the X11 backend sometimes reporting the wrong virtual key (#273).
|
|
||||||
|
|||||||
6
CODE_OF_CONDUCT.md
Normal file
6
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# Code of Conduct
|
||||||
|
|
||||||
|
The `rust-windowing` project adheres to the [Rust Code of Conduct]. This
|
||||||
|
describes the minimum behavior expected from all contributors.
|
||||||
|
|
||||||
|
[Rust Code of Conduct]: https://www.rust-lang.org/policies/code-of-conduct
|
||||||
180
CONTRIBUTING.md
180
CONTRIBUTING.md
@@ -1,42 +1,162 @@
|
|||||||
# Winit Contributing Guidelines
|
# Contribution Guidelines
|
||||||
|
|
||||||
## Scope
|
This document contains guidelines for contributing code to winit. It has to be
|
||||||
[See `FEATURES.md`](./FEATURES.md). When requesting or implementing a new Winit feature, you should
|
followed in order for your patch to be approved and applied.
|
||||||
consider whether or not it's directly related to window creation or input handling. If it isn't, it
|
|
||||||
may be worth creating a separate crate that extends Winit's API to add that functionality.
|
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
## Reporting an issue
|
Anyone can contribute to winit, however given that it's a cross platform
|
||||||
|
windowing toolkit getting certain changes incorporated could be challenging.
|
||||||
|
|
||||||
When reporting an issue, in order to help the maintainers understand what the problem is, please make
|
To save your time it's wise to check already opened [pull requests][prs] and
|
||||||
your description of the issue as detailed as possible:
|
[issues][issues]. In general, bug fixes and missing implementations are always
|
||||||
|
accepted, however larger new API proposals should go into the issue first. When
|
||||||
|
in doubt contact us on [Matrix][matrix] or via opening an issue.
|
||||||
|
|
||||||
- if it is a bug, please provide clear explanation of what happens, what should happen, and how to
|
### Windows
|
||||||
reproduce the issue, ideally by providing a minimal program exhibiting the problem
|
|
||||||
- if it is a feature request, please provide a clear argumentation about why you believe this feature
|
|
||||||
should be supported by winit
|
|
||||||
|
|
||||||
## Making a pull request
|
To run the examples on Windows, you must have symlinks enabled, see
|
||||||
|
[this][git-windows-symlinks].
|
||||||
|
|
||||||
When making a code contribution to winit, before opening your pull request, please make sure that:
|
[git-windows-symlinks]: https://gitforwindows.org/symbolic-links.html
|
||||||
|
|
||||||
- you tested your modifications on all the platforms impacted, or if not possible detail which platforms
|
### Submitting your work and handling review
|
||||||
were not tested, and what should be tested, so that a maintainer or another contributor can test them
|
|
||||||
- you updated any relevant documentation in winit
|
|
||||||
- you left comments in your code explaining any part that is not straightforward, so that the
|
|
||||||
maintainers and future contributors don't have to try to guess what your code is supposed to do
|
|
||||||
- your PR adds an entry to the changelog file if the introduced change is relevant to winit users
|
|
||||||
- if your PR affects the platform compatibility of one or more features or adds another feature, the
|
|
||||||
relevant sections in [`FEATURES.md`](https://github.com/rust-windowing/winit/blob/master/FEATURES.md#features)
|
|
||||||
should be updated.
|
|
||||||
|
|
||||||
Once your PR is open, you can ask for review by a maintainer of your platform. Winit's merging policy
|
All patches have to be sent on Github as [pull requests][prs]. To simplify your
|
||||||
is that a PR must be approved by at least two maintainers of winit before being merged, including
|
life during review it's recommended to check the "give contributors write access
|
||||||
at least a maintainer of the platform (a maintainer making a PR themselves counts as approving it).
|
to the branch" checkbox.
|
||||||
|
|
||||||
## Maintainers & Testers
|
We use unstable Rustfmt options across the project, so please run
|
||||||
|
`cargo +nightly fmt` before submitting your work. If you are unable to do so,
|
||||||
|
the maintainers can do it for you before merging, just state so in your pull
|
||||||
|
request description. For details on how to use nightly, consult [the
|
||||||
|
documentation][toolchains].
|
||||||
|
|
||||||
The current [list of testers and contributors](https://github.com/rust-windowing/winit/wiki/Testers-and-Contributors)
|
When editing markdown files (`.md`) they must be wrapped at 80 characters.
|
||||||
can be found on the Wiki.
|
|
||||||
|
|
||||||
If you are interested in contributing or testing on a platform, please add yourself to that table!
|
[toolchains]: https://rust-lang.github.io/rustup/concepts/toolchains.html
|
||||||
|
|
||||||
|
#### Handling review
|
||||||
|
|
||||||
|
During the review process certain events could require an action from your side,
|
||||||
|
common patterns and reactions are described below.
|
||||||
|
|
||||||
|
_Event:_ The CI fails to build, but it looks like it is not your fault. Not
|
||||||
|
communicating so could result in maintainers not looking into your patch,
|
||||||
|
since they may assume that you're still working on it.\
|
||||||
|
_Desired behaviour:_ Write a message saying roughly the following "The CI
|
||||||
|
failure is unrelated", so that the maintainers will fix it for you.
|
||||||
|
|
||||||
|
_Event:_ Maintainer requested changes to your PR.\
|
||||||
|
_Desired behavior:_ Once you address the request, you should re-request a review
|
||||||
|
with GitHub's UI. If you don't agree with what maintainer suggested, you
|
||||||
|
should state your objections and re-request the review. That will indicate that
|
||||||
|
the ball is on maintainer's side.
|
||||||
|
|
||||||
|
_Event:_ You've opened a PR, but maintainer shortly after commented that they
|
||||||
|
want to work on that themselves.\
|
||||||
|
_Desired behavior:_ Discuss with the maintainer regarding their plans if they
|
||||||
|
were not outlined in the initial response, because such response means that they
|
||||||
|
are not interested in reviewing your code. Such thing could happen when
|
||||||
|
underestimating complexity of the task you're solving or when your patch
|
||||||
|
mandate certain downstream designs. In general, the maintainer will likely
|
||||||
|
close your PR in order to prevent work being done on it.
|
||||||
|
|
||||||
|
[prs]: https://github.com/rust-windowing/winit/pulls
|
||||||
|
[issues]: https://github.com/rust-windowing/winit/issues
|
||||||
|
[matrix]: https://matrix.to/#/#rust-windowing:matrix.org
|
||||||
|
|
||||||
|
## Maintainers
|
||||||
|
|
||||||
|
Winit has plenty of maintainers with different backgrounds, different time
|
||||||
|
available to work on Winit, and reasons to be winit maintainer in the first
|
||||||
|
place. To ensure that Winit's code quality does not decrease over time and to
|
||||||
|
make it easier to teach new maintainers the "winit way of doing things" the
|
||||||
|
common policies and routines are defined in this section.
|
||||||
|
|
||||||
|
The current maintainers for each platform are listed in [this file][CODEOWNERS].
|
||||||
|
|
||||||
|
### Contributions handling
|
||||||
|
|
||||||
|
The maintainers must ensure that the external contributions meet Winit's
|
||||||
|
quality standards. If it's not, it **is the maintainer's responsibility** to
|
||||||
|
bring it on par, which includes:
|
||||||
|
|
||||||
|
- Ensure that formatting is consistent and `CHANGELOG` messages are clear
|
||||||
|
for the end users.
|
||||||
|
- Improve the commit message, so it'll be easier for other maintainers to
|
||||||
|
understand the motivation without going through all the discussions on the
|
||||||
|
particular patch/PR.
|
||||||
|
- Ensure that the proposed patch doesn't break platform parity. If the
|
||||||
|
breakage is desired by contributor, an issue should be opened to discuss
|
||||||
|
with other maintainers before merging.
|
||||||
|
- Always fix CI issues before merging if they don't originate from the
|
||||||
|
submitted work.
|
||||||
|
|
||||||
|
However, maintainers should give some leeway for external contributors, so they
|
||||||
|
don't feel discouraged contributing, for example:
|
||||||
|
|
||||||
|
- Suggest a patch to resolve style issues, if it's the only issue with the
|
||||||
|
submitted work. Keep in mind that pushing the resolution yourself is not
|
||||||
|
desired, because the contributor might not agree with what you did.
|
||||||
|
- Be more explicit on how things should be done if you don't like the
|
||||||
|
approach.
|
||||||
|
- Suggest to finish the PR for them if they're absent for a while and you need
|
||||||
|
the proposed changes to move forward with something. In such cases the
|
||||||
|
maintainer must preserve attribution with `Co-authored-by`, `Suggested-by`,
|
||||||
|
or keep the original committer.
|
||||||
|
- Rebase their work for them when massive changes to the Winit codebase were
|
||||||
|
introduced.
|
||||||
|
|
||||||
|
When reviewing code of other maintainers all of the above is on the maintainer
|
||||||
|
who submitted the patch. Interested maintainers could help push the work over
|
||||||
|
the finish line, but teaching other maintainers should be preferred.
|
||||||
|
|
||||||
|
For a _regular_ contributor to winit, the maintainer should slowly start
|
||||||
|
requiring contributor to match *maintainer* quality standards when writing
|
||||||
|
patches and commit messages.
|
||||||
|
|
||||||
|
### Contributing
|
||||||
|
|
||||||
|
When submitting a patch, the maintainer should follow the general contributing
|
||||||
|
guidelines, however greater attention to detail is expected in this case.
|
||||||
|
|
||||||
|
To make life simpler for other maintainers it's suggested to create your branch
|
||||||
|
under the project repository instead of your own fork. The naming scheme is
|
||||||
|
`github_user_name/branch_name`. Doing so will make your work easier to rebase
|
||||||
|
for other maintainers when you're absent.
|
||||||
|
|
||||||
|
### Administrative Actions
|
||||||
|
|
||||||
|
Some things (such as changing required CI steps, adding contributors, ...)
|
||||||
|
require administrative permissions. If you don't have those, ask about the
|
||||||
|
change in an issue. If you have the permissions, discuss it with at least one
|
||||||
|
other admin before making the change.
|
||||||
|
|
||||||
|
### Release process
|
||||||
|
|
||||||
|
Given that winit is a widely used library, we should be able to make a patch
|
||||||
|
releases at any time we want without blocking the development of new features.
|
||||||
|
|
||||||
|
To achieve these goals, a new branch is created for every new release. Releases
|
||||||
|
and later patch releases are committed and tagged in this branch.
|
||||||
|
|
||||||
|
The exact steps for an exemplary `0.2.0` release might look like this:
|
||||||
|
1. Initially, the version on the latest master is `0.1.0`
|
||||||
|
2. A new `v0.2.x` branch is created for the release
|
||||||
|
3. Update released `cfg_attr` in `src/changelog/mod.rs` to `v0.2.md`
|
||||||
|
4. Move entries from `src/changelog/unreleased.md` into
|
||||||
|
`src/changelog/v0.2.md`
|
||||||
|
5. In the branch, the version is bumped to `v0.2.0`
|
||||||
|
6. The new commit in the branch is tagged `v0.2.0`
|
||||||
|
7. The version is pushed to crates.io
|
||||||
|
8. A GitHub release is created for the `v0.2.0` tag
|
||||||
|
9. On master, the version is bumped to `0.2.0`, and the changelog is updated
|
||||||
|
|
||||||
|
When doing a patch release, the process is similar:
|
||||||
|
1. Initially, the version of the latest release is `0.2.0`
|
||||||
|
2. Checkout the `v0.2.x` branch
|
||||||
|
3. Cherry-pick the required non-breaking changes into the `v0.2.x`
|
||||||
|
4. Follow steps 4-9 of the regular release example
|
||||||
|
|
||||||
|
[CODEOWNERS]: .github/CODEOWNERS
|
||||||
|
|||||||
207
Cargo.toml
207
Cargo.toml
@@ -1,128 +1,97 @@
|
|||||||
[package]
|
[workspace]
|
||||||
name = "winit"
|
default-members = ["winit"]
|
||||||
version = "0.22.2"
|
members = ["dpi", "winit*"]
|
||||||
authors = ["The winit contributors", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
|
resolver = "2"
|
||||||
description = "Cross-platform window creation library."
|
|
||||||
edition = "2018"
|
[workspace.package]
|
||||||
keywords = ["windowing"]
|
edition = "2024"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
readme = "README.md"
|
|
||||||
repository = "https://github.com/rust-windowing/winit"
|
repository = "https://github.com/rust-windowing/winit"
|
||||||
documentation = "https://docs.rs/winit"
|
rust-version = "1.85"
|
||||||
categories = ["gui"]
|
version = "0.31.0-beta.2"
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[workspace.dependencies]
|
||||||
features = ["serde", "web-sys"]
|
# Workspace dependencies.
|
||||||
default-target = "x86_64-unknown-linux-gnu"
|
# `winit` has no version here to allow using it in dev deps for docs.
|
||||||
targets = ["i686-pc-windows-msvc", "x86_64-pc-windows-msvc", "i686-unknown-linux-gnu", "x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "wasm32-unknown-unknown"]
|
winit = { path = "winit" }
|
||||||
|
winit-android = { version = "=0.31.0-beta.2", path = "winit-android" }
|
||||||
|
winit-appkit = { version = "=0.31.0-beta.2", path = "winit-appkit" }
|
||||||
|
winit-common = { version = "=0.31.0-beta.2", path = "winit-common" }
|
||||||
|
winit-core = { version = "=0.31.0-beta.2", path = "winit-core" }
|
||||||
|
winit-orbital = { version = "=0.31.0-beta.2", path = "winit-orbital" }
|
||||||
|
winit-uikit = { version = "=0.31.0-beta.2", path = "winit-uikit" }
|
||||||
|
winit-wayland = { version = "=0.31.0-beta.2", path = "winit-wayland", default-features = false }
|
||||||
|
winit-web = { version = "=0.31.0-beta.2", path = "winit-web" }
|
||||||
|
winit-win32 = { version = "=0.31.0-beta.2", path = "winit-win32" }
|
||||||
|
winit-x11 = { version = "=0.31.0-beta.2", path = "winit-x11" }
|
||||||
|
|
||||||
[features]
|
# Core dependencies.
|
||||||
web-sys = ["web_sys", "wasm-bindgen", "instant/wasm-bindgen"]
|
bitflags = "2"
|
||||||
stdweb = ["std_web", "instant/stdweb"]
|
cfg_aliases = "0.2.1"
|
||||||
|
cursor-icon = "1.1.0"
|
||||||
|
dpi = { version = "0.1.2", path = "dpi" }
|
||||||
|
keyboard-types = "0.8.0"
|
||||||
|
mint = "0.5.6"
|
||||||
|
rwh_06 = { package = "raw-window-handle", version = "0.6", features = ["std"] }
|
||||||
|
serde = { version = "1", features = ["serde_derive"] }
|
||||||
|
smol_str = "0.3"
|
||||||
|
tracing = { version = "0.1.40", default-features = false }
|
||||||
|
|
||||||
[dependencies]
|
# Dev dependencies.
|
||||||
instant = "0.1"
|
image = { version = "0.25.0", default-features = false }
|
||||||
lazy_static = "1"
|
softbuffer = { version = "0.4.8", default-features = false, features = [
|
||||||
|
"x11",
|
||||||
|
"x11-dlopen",
|
||||||
|
"wayland",
|
||||||
|
"wayland-dlopen",
|
||||||
|
] }
|
||||||
|
tracing-subscriber = "0.3.18"
|
||||||
|
|
||||||
|
# Android dependencies.
|
||||||
|
android-activity = "0.6.0"
|
||||||
|
ndk = { version = "0.9.0", features = ["rwh_06"], default-features = false }
|
||||||
|
|
||||||
|
# Apple dependencies.
|
||||||
|
block2 = "0.6.1"
|
||||||
|
dispatch2 = { version = "0.3.0", default-features = false, features = ["std", "objc2"] }
|
||||||
|
objc2 = { version = "0.6.1", features = ["relax-sign-encoding"] }
|
||||||
|
objc2-app-kit = { version = "0.3.2", default-features = false }
|
||||||
|
objc2-core-foundation = { version = "0.3.2", default-features = false }
|
||||||
|
objc2-core-graphics = { version = "0.3.2", default-features = false }
|
||||||
|
objc2-core-video = { version = "0.3.2", default-features = false }
|
||||||
|
objc2-foundation = { version = "0.3.2", default-features = false }
|
||||||
|
objc2-ui-kit = { version = "0.3.2", default-features = false }
|
||||||
|
|
||||||
|
# Windows dependencies.
|
||||||
|
unicode-segmentation = "1.7.1"
|
||||||
|
windows-sys = "0.61"
|
||||||
|
|
||||||
|
# Linux dependencies.
|
||||||
|
bytemuck = { version = "1.13.1", default-features = false }
|
||||||
|
calloop = "0.14.3"
|
||||||
|
foldhash = { version = "0.2.0", default-features = false, features = ["std"] }
|
||||||
libc = "0.2.64"
|
libc = "0.2.64"
|
||||||
log = "0.4"
|
memmap2 = "0.9.0"
|
||||||
serde = { version = "1", optional = true, features = ["serde_derive"] }
|
|
||||||
raw-window-handle = "0.3"
|
|
||||||
bitflags = "1"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
image = "0.23"
|
|
||||||
simple_logger = "1"
|
|
||||||
|
|
||||||
[target.'cfg(target_os = "android")'.dependencies]
|
|
||||||
ndk = "0.1.0"
|
|
||||||
ndk-sys = "0.1.0"
|
|
||||||
ndk-glue = "0.1.0"
|
|
||||||
|
|
||||||
[target.'cfg(target_os = "ios")'.dependencies]
|
|
||||||
objc = "0.2.3"
|
|
||||||
|
|
||||||
[target.'cfg(target_os = "macos")'.dependencies]
|
|
||||||
cocoa = "0.20"
|
|
||||||
core-foundation = "0.7"
|
|
||||||
core-graphics = "0.19"
|
|
||||||
dispatch = "0.2.0"
|
|
||||||
objc = "0.2.6"
|
|
||||||
|
|
||||||
[target.'cfg(target_os = "macos")'.dependencies.core-video-sys]
|
|
||||||
version = "0.1.4"
|
|
||||||
default_features = false
|
|
||||||
features = ["display_link"]
|
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies.winapi]
|
|
||||||
version = "0.3.6"
|
|
||||||
features = [
|
|
||||||
"combaseapi",
|
|
||||||
"commctrl",
|
|
||||||
"dwmapi",
|
|
||||||
"errhandlingapi",
|
|
||||||
"hidusage",
|
|
||||||
"libloaderapi",
|
|
||||||
"objbase",
|
|
||||||
"ole2",
|
|
||||||
"processthreadsapi",
|
|
||||||
"shellapi",
|
|
||||||
"shellscalingapi",
|
|
||||||
"shobjidl_core",
|
|
||||||
"unknwnbase",
|
|
||||||
"winbase",
|
|
||||||
"windowsx",
|
|
||||||
"winerror",
|
|
||||||
"wingdi",
|
|
||||||
"winnt",
|
|
||||||
"winuser",
|
|
||||||
]
|
|
||||||
|
|
||||||
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))'.dependencies]
|
|
||||||
wayland-client = { version = "0.23.0", features = [ "dlopen", "egl", "cursor", "eventloop"] }
|
|
||||||
mio = "0.6"
|
|
||||||
mio-extras = "2.0"
|
|
||||||
smithay-client-toolkit = "^0.6.6"
|
|
||||||
x11-dl = "2.18.5"
|
|
||||||
percent-encoding = "2.0"
|
percent-encoding = "2.0"
|
||||||
|
rustix = { version = "1.0.7", default-features = false }
|
||||||
|
x11-dl = "2.19.1"
|
||||||
|
x11rb = { version = "0.13.0", default-features = false }
|
||||||
|
xkbcommon-dl = "0.4.2"
|
||||||
|
|
||||||
[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "windows"))'.dependencies.parking_lot]
|
# Orbital dependencies.
|
||||||
version = "0.10"
|
libredox = "0.1.12"
|
||||||
|
orbclient = { version = "0.3.47", default-features = false }
|
||||||
|
redox_event = { package = "redox_event", version = "0.4.5" }
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies.web_sys]
|
# Web dependencies.
|
||||||
package = "web-sys"
|
atomic-waker = "1"
|
||||||
version = "0.3.22"
|
concurrent-queue = { version = "2", default-features = false }
|
||||||
optional = true
|
console_error_panic_hook = "0.1"
|
||||||
features = [
|
js-sys = "0.3.70"
|
||||||
'console',
|
pin-project = "1"
|
||||||
'CssStyleDeclaration',
|
tracing-web = "0.1"
|
||||||
'BeforeUnloadEvent',
|
wasm-bindgen = "0.2.93"
|
||||||
'Document',
|
wasm-bindgen-futures = "0.4.43"
|
||||||
'DomRect',
|
wasm-bindgen-test = "0.3"
|
||||||
'Element',
|
web-time = "1"
|
||||||
'Event',
|
web_sys = { package = "web-sys", version = "0.3.70" }
|
||||||
'EventTarget',
|
|
||||||
'FocusEvent',
|
|
||||||
'HtmlCanvasElement',
|
|
||||||
'HtmlElement',
|
|
||||||
'KeyboardEvent',
|
|
||||||
'MediaQueryList',
|
|
||||||
'MediaQueryListEvent',
|
|
||||||
'MouseEvent',
|
|
||||||
'Node',
|
|
||||||
'PointerEvent',
|
|
||||||
'Window',
|
|
||||||
'WheelEvent'
|
|
||||||
]
|
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies.wasm-bindgen]
|
|
||||||
version = "0.2.45"
|
|
||||||
optional = true
|
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies.std_web]
|
|
||||||
package = "stdweb"
|
|
||||||
version = "=0.4.20"
|
|
||||||
optional = true
|
|
||||||
features = ["experimental_features_which_may_break_on_minor_version_bumps"]
|
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
|
|
||||||
console_log = "0.1"
|
|
||||||
|
|||||||
198
FEATURES.md
198
FEATURES.md
@@ -1,18 +1,18 @@
|
|||||||
# Winit Scope
|
# Winit Scope
|
||||||
|
|
||||||
Winit aims to expose an interface that abstracts over window creation and input handling, and can
|
Winit aims to expose an interface that abstracts over window creation and input handling and can
|
||||||
be used to create both games and applications. It supports the main graphical platforms:
|
be used to create both games and applications. It supports the following main graphical platforms:
|
||||||
- Desktop
|
- Desktop
|
||||||
- Windows
|
- Windows
|
||||||
- macOS
|
- macOS
|
||||||
- Unix
|
- Unix
|
||||||
- via X11
|
- via X11
|
||||||
- via Wayland
|
- via Wayland
|
||||||
|
- Redox OS, via Orbital
|
||||||
- Mobile
|
- Mobile
|
||||||
- iOS
|
- iOS
|
||||||
- Android
|
- Android
|
||||||
- Web
|
- Web
|
||||||
- via WASM
|
|
||||||
|
|
||||||
Most platforms expose capabilities that cannot be meaningfully transposed onto others. Winit does not
|
Most platforms expose capabilities that cannot be meaningfully transposed onto others. Winit does not
|
||||||
aim to support every single feature of every platform, but rather to abstract over the common features
|
aim to support every single feature of every platform, but rather to abstract over the common features
|
||||||
@@ -42,196 +42,8 @@ be released and the library will enter maintenance mode. For the most part, new
|
|||||||
be added past this point. New platform features may be accepted and exposed through point releases.
|
be added past this point. New platform features may be accepted and exposed through point releases.
|
||||||
|
|
||||||
### Tier upgrades
|
### Tier upgrades
|
||||||
Some platform features could in theory be exposed across multiple platforms, but have not gone
|
Some platform features could, in theory, be exposed across multiple platforms, but have not gone
|
||||||
through the implementation work necessary to function on all platforms. When one of these features
|
through the implementation work necessary to function on all platforms. When one of these features
|
||||||
gets implemented across all platforms, a PR can be opened to upgrade the feature to a core feature.
|
gets implemented across all platforms, a PR can be opened to upgrade the feature to a core feature.
|
||||||
If that gets accepted, the platform-specific functions gets deprecated and become permanently
|
If that gets accepted, the platform-specific functions get deprecated and become permanently
|
||||||
exposed through the core, cross-platform API.
|
exposed through the core, cross-platform API.
|
||||||
|
|
||||||
# Features
|
|
||||||
|
|
||||||
## Extending this section
|
|
||||||
|
|
||||||
If your PR makes notable changes to Winit's features, please update this section as follows:
|
|
||||||
|
|
||||||
- If your PR adds a new feature, add a brief description to the relevant section. If the feature is a core
|
|
||||||
feature, add a row to the feature matrix and describe what platforms the feature has been implemented on.
|
|
||||||
|
|
||||||
- If your PR begins a new API rework, add a row to the `Pending API Reworks` table. If the PR implements the
|
|
||||||
API rework on all relevant platforms, please move it to the `Completed API Reworks` table.
|
|
||||||
|
|
||||||
- If your PR implements an already-existing feature on a new platform, either mark the feature as *completed*,
|
|
||||||
or mark it as *mostly completed* and link to an issue describing the problems with the implementation.
|
|
||||||
|
|
||||||
## Core
|
|
||||||
|
|
||||||
### Windowing
|
|
||||||
- **Window initialization**: Winit allows the creation of a window
|
|
||||||
- **Providing pointer to init OpenGL**: Winit provides the necessary pointers to initialize a working opengl context
|
|
||||||
- **Providing pointer to init Vulkan**: Same as OpenGL but for Vulkan
|
|
||||||
- **Window decorations**: The windows created by winit are properly decorated, and the decorations can
|
|
||||||
be deactivated
|
|
||||||
- **Window decorations toggle**: Decorations can be turned on or off after window creation
|
|
||||||
- **Window resizing**: The windows created by winit can be resized and generate the appropriate events
|
|
||||||
when they are. The application can precisely control its window size if desired.
|
|
||||||
- **Window resize increments**: When the window gets resized, the application can choose to snap the window's
|
|
||||||
size to specific values.
|
|
||||||
- **Window transparency**: Winit allows the creation of windows with a transparent background.
|
|
||||||
- **Window maximization**: The windows created by winit can be maximized upon creation.
|
|
||||||
- **Window maximization toggle**: The windows created by winit can be maximized and unmaximized after
|
|
||||||
creation.
|
|
||||||
- **Window minimization**: The windows created by winit can be minimized after creation.
|
|
||||||
- **Fullscreen**: The windows created by winit can be put into fullscreen mode.
|
|
||||||
- **Fullscreen toggle**: The windows created by winit can be switched to and from fullscreen after
|
|
||||||
creation.
|
|
||||||
- **Exclusive fullscreen**: Winit allows changing the video mode of the monitor
|
|
||||||
for fullscreen windows, and if applicable, captures the monitor for exclusive
|
|
||||||
use by this application.
|
|
||||||
- **HiDPI support**: Winit assists developers in appropriately scaling HiDPI content.
|
|
||||||
- **Popup / modal windows**: Windows can be created relative to the client area of other windows, and parent
|
|
||||||
windows can be disabled in favor of popup windows. This feature also guarantees that popup windows
|
|
||||||
get drawn above their owner.
|
|
||||||
|
|
||||||
|
|
||||||
### System Information
|
|
||||||
- **Monitor list**: Retrieve the list of monitors and their metadata, including which one is primary.
|
|
||||||
- **Video mode query**: Monitors can be queried for their supported fullscreen video modes (consisting of resolution, refresh rate, and bit depth).
|
|
||||||
|
|
||||||
### Input Handling
|
|
||||||
- **Mouse events**: Generating mouse events associated with pointer motion, click, and scrolling events.
|
|
||||||
- **Mouse set location**: Forcibly changing the location of the pointer.
|
|
||||||
- **Cursor grab**: Locking the cursor so it cannot exit the client area of a window.
|
|
||||||
- **Cursor icon**: Changing the cursor icon, or hiding the cursor.
|
|
||||||
- **Touch events**: Single-touch events.
|
|
||||||
- **Touch pressure**: Touch events contain information about the amount of force being applied.
|
|
||||||
- **Multitouch**: Multi-touch events, including cancellation of a gesture.
|
|
||||||
- **Keyboard events**: Properly processing keyboard events using the user-specified keymap and
|
|
||||||
translating keypresses into UTF-8 characters, handling dead keys and IMEs.
|
|
||||||
- **Drag & Drop**: Dragging content into winit, detecting when content enters, drops, or if the drop is cancelled.
|
|
||||||
- **Raw Device Events**: Capturing input from input devices without any OS filtering.
|
|
||||||
- **Gamepad/Joystick events**: Capturing input from gamepads and joysticks.
|
|
||||||
- **Device movement events**: Capturing input from the device gyroscope and accelerometer.
|
|
||||||
|
|
||||||
## Platform
|
|
||||||
### Windows
|
|
||||||
* Setting the taskbar icon
|
|
||||||
* Setting the parent window
|
|
||||||
* `WS_EX_NOREDIRECTIONBITMAP` support
|
|
||||||
* Theme the title bar according to Windows 10 Dark Mode setting
|
|
||||||
|
|
||||||
### macOS
|
|
||||||
* Window activation policy
|
|
||||||
* Window movable by background
|
|
||||||
* Transparent titlebar
|
|
||||||
* Hidden titlebar
|
|
||||||
* Hidden titlebar buttons
|
|
||||||
* Full-size content view
|
|
||||||
|
|
||||||
### Unix
|
|
||||||
* Window urgency
|
|
||||||
* X11 Window Class
|
|
||||||
* X11 Override Redirect Flag
|
|
||||||
* GTK Theme Variant
|
|
||||||
* Base window size
|
|
||||||
|
|
||||||
### iOS
|
|
||||||
* `winit` has a minimum OS requirement of iOS 8
|
|
||||||
* Get the `UIWindow` object pointer
|
|
||||||
* Get the `UIViewController` object pointer
|
|
||||||
* Get the `UIView` object pointer
|
|
||||||
* Get the `UIScreen` object pointer
|
|
||||||
* Setting the `UIView` hidpi factor
|
|
||||||
* Valid orientations
|
|
||||||
* Home indicator visibility
|
|
||||||
* Status bar visibility
|
|
||||||
* Deferrring system gestures
|
|
||||||
* Support for custom `UIView` derived class
|
|
||||||
* Getting the device idiom
|
|
||||||
* Getting the preferred video mode
|
|
||||||
|
|
||||||
### Web
|
|
||||||
* Get if systems preferred color scheme is "dark"
|
|
||||||
|
|
||||||
## Usability
|
|
||||||
* `serde`: Enables serialization/deserialization of certain types with Serde. (Maintainer: @Osspial)
|
|
||||||
|
|
||||||
## Compatibility Matrix
|
|
||||||
|
|
||||||
Legend:
|
|
||||||
|
|
||||||
- ✔️: Works as intended
|
|
||||||
- ▢: Mostly works but some bugs are known
|
|
||||||
- ❌: Missing feature or large bugs making it unusable
|
|
||||||
- **N/A**: Not applicable for this platform
|
|
||||||
- ❓: Unknown status
|
|
||||||
|
|
||||||
### Windowing
|
|
||||||
|Feature |Windows|MacOS |Linux x11 |Linux Wayland |Android|iOS |WASM |
|
|
||||||
|-------------------------------- | ----- | ---- | ------- | ----------- | ----- | ----- | -------- |
|
|
||||||
|Window initialization |✔️ |✔️ |▢[#5] |✔️ |▢[#33]|▢[#33] |✔️ |
|
|
||||||
|Providing pointer to init OpenGL |✔️ |✔️ |✔️ |✔️ |✔️ |✔️ |**N/A**|
|
|
||||||
|Providing pointer to init Vulkan |✔️ |✔️ |✔️ |✔️ |✔️ |❓ |**N/A**|
|
|
||||||
|Window decorations |✔️ |✔️ |✔️ |▢[#306] |**N/A**|**N/A**|**N/A**|
|
|
||||||
|Window decorations toggle |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A**|
|
|
||||||
|Window resizing |✔️ |▢[#219]|✔️ |▢[#306] |**N/A**|**N/A**|✔️ |
|
|
||||||
|Window resize increments |❌ |❌ |❌ |❌ |❌ |❌ |**N/A**|
|
|
||||||
|Window transparency |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|N/A |
|
|
||||||
|Window maximization |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A**|
|
|
||||||
|Window maximization toggle |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A**|
|
|
||||||
|Window minimization |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|**N/A**|
|
|
||||||
|Fullscreen |✔️ |✔️ |✔️ |✔️ |**N/A**|✔️ |✔️ |
|
|
||||||
|Fullscreen toggle |✔️ |✔️ |✔️ |✔️ |**N/A**|✔️ |✔️ |
|
|
||||||
|Exclusive fullscreen |✔️ |✔️ |✔️ |**N/A** |❌ |✔️ |**N/A**|
|
|
||||||
|HiDPI support |✔️ |✔️ |✔️ |✔️ |▢[#721]|✔️ |**N/A**|
|
|
||||||
|Popup windows |❌ |❌ |❌ |❌ |❌ |❌ |**N/A**|
|
|
||||||
|
|
||||||
### System information
|
|
||||||
|Feature |Windows|MacOS |Linux x11|Linux Wayland|Android|iOS |WASM |
|
|
||||||
|---------------- | ----- | ---- | ------- | ----------- | ----- | ------- | -------- |
|
|
||||||
|Monitor list |✔️ |✔️ |✔️ |✔️ |**N/A**|✔️ |**N/A**|
|
|
||||||
|Video mode query |✔️ |✔️ |✔️ |✔️ |❌ |✔️ |**N/A**|
|
|
||||||
|
|
||||||
### Input handling
|
|
||||||
|Feature |Windows |MacOS |Linux x11|Linux Wayland|Android|iOS |WASM |
|
|
||||||
|----------------------- | ----- | ---- | ------- | ----------- | ----- | ----- | -------- |
|
|
||||||
|Mouse events |✔️ |▢[#63] |✔️ |✔️ |**N/A**|**N/A**|✔️ |
|
|
||||||
|Mouse set location |✔️ |✔️ |✔️ |❓ |**N/A**|**N/A**|**N/A**|
|
|
||||||
|Cursor grab |✔️ |▢[#165] |▢[#242] |✔️ |**N/A**|**N/A**|❓ |
|
|
||||||
|Cursor icon |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|✔️ |
|
|
||||||
|Touch events |✔️ |❌ |✔️ |✔️ |✔️ |✔️ |✔️ |
|
|
||||||
|Touch pressure |✔️ |❌ |❌ |❌ |❌ |✔️ |✔️ |
|
|
||||||
|Multitouch |✔️ |❌ |✔️ |✔️ |❓ |✔️ |✔️ |
|
|
||||||
|Keyboard events |✔️ |✔️ |✔️ |✔️ |❓ |❌ |✔️ |
|
|
||||||
|Drag & Drop |▢[#720] |▢[#720] |▢[#720] |❌[#306] |**N/A**|**N/A**|❓ |
|
|
||||||
|Raw Device Events |▢[#750] |▢[#750] |▢[#750] |❌ |❌ |❌ |❓ |
|
|
||||||
|Gamepad/Joystick events |❌[#804] |❌ |❌ |❌ |❌ |❌ |❓ |
|
|
||||||
|Device movement events |❓ |❓ |❓ |❓ |❌ |❌ |❓ |
|
|
||||||
|
|
||||||
### Pending API Reworks
|
|
||||||
Changes in the API that have been agreed upon but aren't implemented across all platforms.
|
|
||||||
|
|
||||||
|Feature |Windows|MacOS |Linux x11|Linux Wayland|Android|iOS |WASM |
|
|
||||||
|------------------------------ | ----- | ---- | ------- | ----------- | ----- | ----- | -------- |
|
|
||||||
|New API for HiDPI ([#315] [#319]) |✔️ |✔️ |✔️ |✔️ |▢[#721]|✔️ |❓ |
|
|
||||||
|Event Loop 2.0 ([#459]) |✔️ |✔️ |❌ |✔️ |❌ |✔️ |❓ |
|
|
||||||
|Keyboard Input ([#812]) |❌ |❌ |❌ |❌ |❌ |❌ |❓ |
|
|
||||||
|
|
||||||
### Completed API Reworks
|
|
||||||
|Feature |Windows|MacOS |Linux x11|Linux Wayland|Android|iOS |WASM |
|
|
||||||
|------------------------------ | ----- | ---- | ------- | ----------- | ----- | ----- | -------- |
|
|
||||||
|
|
||||||
[#165]: https://github.com/rust-windowing/winit/issues/165
|
|
||||||
[#219]: https://github.com/rust-windowing/winit/issues/219
|
|
||||||
[#242]: https://github.com/rust-windowing/winit/issues/242
|
|
||||||
[#306]: https://github.com/rust-windowing/winit/issues/306
|
|
||||||
[#315]: https://github.com/rust-windowing/winit/issues/315
|
|
||||||
[#319]: https://github.com/rust-windowing/winit/issues/319
|
|
||||||
[#33]: https://github.com/rust-windowing/winit/issues/33
|
|
||||||
[#459]: https://github.com/rust-windowing/winit/issues/459
|
|
||||||
[#5]: https://github.com/rust-windowing/winit/issues/5
|
|
||||||
[#63]: https://github.com/rust-windowing/winit/issues/63
|
|
||||||
[#720]: https://github.com/rust-windowing/winit/issues/720
|
|
||||||
[#721]: https://github.com/rust-windowing/winit/issues/721
|
|
||||||
[#750]: https://github.com/rust-windowing/winit/issues/750
|
|
||||||
[#804]: https://github.com/rust-windowing/winit/issues/804
|
|
||||||
[#812]: https://github.com/rust-windowing/winit/issues/812
|
|
||||||
|
|||||||
@@ -1,14 +1,25 @@
|
|||||||
# Hall of Champions
|
# Hall of Champions
|
||||||
|
|
||||||
The Winit maintainers would like to recognize the following former Winit
|
The winit maintainers would like to recognize the following former winit
|
||||||
contributors, without whom Winit would not exist in its current form. We thank
|
contributors, without whom winit would not exist in its current form. We thank
|
||||||
them deeply for their time and efforts, and wish them best of luck in their
|
them deeply for their time and efforts and wish them the best of luck in their
|
||||||
future endeavors:
|
future endeavors:
|
||||||
|
|
||||||
* [@tomaka]: For creating the Winit project and guiding it through its early
|
* [@tomaka]: For creating the winit project and guiding it through its early
|
||||||
years of existence.
|
years of existence.
|
||||||
|
* [@vberger]: For diligently creating the Wayland backend and being its
|
||||||
|
extremely helpful and benevolent maintainer for years.
|
||||||
* [@francesca64]: For taking over the responsibility of maintaining almost every
|
* [@francesca64]: For taking over the responsibility of maintaining almost every
|
||||||
Winit backend, and standardizing HiDPI support across all of them
|
winit backend and standardizing HiDPI support across all of them.
|
||||||
|
* [@Osspial]: For heroically landing EventLoop 2.0 and valiantly ushering in a
|
||||||
|
vastly more sustainable era of winit.
|
||||||
|
* [@goddessfreya]: For selflessly taking over maintainership of glutin and her
|
||||||
|
stellar dedication to improving both winit and glutin.
|
||||||
|
* [@ArturKovacs]: For consistently maintaining the macOS backend and for his immense involvement in designing and implementing the new keyboard API.
|
||||||
|
|
||||||
[@tomaka]: https://github.com/tomaka
|
[@tomaka]: https://github.com/tomaka
|
||||||
|
[@vberger]: https://github.com/vberger
|
||||||
[@francesca64]: https://github.com/francesca64
|
[@francesca64]: https://github.com/francesca64
|
||||||
|
[@Osspial]: https://github.com/Osspial
|
||||||
|
[@goddessfreya]: https://github.com/goddessfreya
|
||||||
|
[@ArturKovacs]: https://github.com/ArturKovacs
|
||||||
|
|||||||
96
README.md
96
README.md
@@ -2,96 +2,78 @@
|
|||||||
|
|
||||||
[](https://crates.io/crates/winit)
|
[](https://crates.io/crates/winit)
|
||||||
[](https://docs.rs/winit)
|
[](https://docs.rs/winit)
|
||||||
|
[](https://rust-windowing.github.io/winit/winit/index.html)
|
||||||
[](https://github.com/rust-windowing/winit/actions)
|
[](https://github.com/rust-windowing/winit/actions)
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
winit = "0.22.2"
|
winit = "0.31.0-beta.2"
|
||||||
```
|
```
|
||||||
|
|
||||||
## [Documentation](https://docs.rs/winit)
|
## [Documentation](https://docs.rs/winit)
|
||||||
|
|
||||||
For features _within_ the scope of winit, see [FEATURES.md](FEATURES.md).
|
For features _within_ the scope of winit, see [FEATURES.md](FEATURES.md).
|
||||||
|
|
||||||
For features _outside_ the scope of winit, see [Missing features provided by other crates](https://github.com/rust-windowing/winit/wiki/Missing-features-provided-by-other-crates) in the wiki.
|
For features _outside_ the scope of winit, see [Are we GUI Yet?](https://areweguiyet.com/) and [Are we game yet?](https://arewegameyet.rs/), depending on what kind of project you're looking to do.
|
||||||
|
|
||||||
## Contact Us
|
## Contact Us
|
||||||
|
|
||||||
Join us in any of these:
|
Join us in our [](https://matrix.to/#/#rust-windowing:matrix.org) room.
|
||||||
|
|
||||||
[](http://webchat.freenode.net?channels=%23glutin&uio=MTY9dHJ1ZSYyPXRydWUmND10cnVlJjExPTE4NSYxMj10cnVlJjE1PXRydWU7a)
|
The maintainers have a meeting every friday at UTC 15. The meeting notes can be found [here](https://hackmd.io/@winit-meetings).
|
||||||
[](https://matrix.to/#/#Glutin:matrix.org)
|
|
||||||
[](https://gitter.im/tomaka/glutin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Winit is a window creation and management library. It can create windows and lets you handle
|
Winit is a window creation and management library. It can create windows and lets you handle
|
||||||
events (for example: the window being resized, a key being pressed, a mouse movement, etc.)
|
events (for example: the window being resized, a key being pressed, a mouse movement, etc.)
|
||||||
produced by window.
|
produced by the window.
|
||||||
|
|
||||||
Winit is designed to be a low-level brick in a hierarchy of libraries. Consequently, in order to
|
Winit is designed to be a low-level brick in a hierarchy of libraries. Consequently, in order to
|
||||||
show something on the window you need to use the platform-specific getters provided by winit, or
|
show something on the window you need to use the platform-specific getters provided by winit, or
|
||||||
another library.
|
another library.
|
||||||
|
|
||||||
```rust
|
## CONTRIBUTING
|
||||||
use winit::{
|
|
||||||
event::{Event, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::WindowBuilder,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
For contributing guidelines see [CONTRIBUTING.md](./CONTRIBUTING.md).
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
## MSRV Policy
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
|
|
||||||
match event {
|
This crate's Minimum Supported Rust Version (MSRV) is **1.85**. Changes to
|
||||||
Event::WindowEvent {
|
the MSRV will be accompanied by a minor version bump.
|
||||||
event: WindowEvent::CloseRequested,
|
|
||||||
window_id,
|
As a **tentative** policy, the upper bound of the MSRV is given by the following
|
||||||
} if window_id == window.id() => *control_flow = ControlFlow::Exit,
|
formula:
|
||||||
_ => (),
|
|
||||||
}
|
```
|
||||||
});
|
min(sid, stable - 3)
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Winit is only officially supported on the latest stable version of the Rust compiler.
|
Where `sid` is the current version of `rustc` provided by [Debian Sid], and
|
||||||
|
`stable` is the latest stable version of Rust. This bound may be broken in case of a major ecosystem shift or a security vulnerability.
|
||||||
|
|
||||||
### Cargo Features
|
[Debian Sid]: https://packages.debian.org/sid/rustc
|
||||||
|
|
||||||
Winit provides the following features, which can be enabled in your `Cargo.toml` file:
|
An exception is made for the Android platform, where a higher Rust version
|
||||||
* `serde`: Enables serialization/deserialization of certain types with [Serde](https://crates.io/crates/serde).
|
must be used for certain Android features. In this case, the MSRV will be
|
||||||
|
capped at the latest stable version of Rust minus three. This inconsistency is
|
||||||
|
not reflected in Cargo metadata, as it is not powerful enough to expose this
|
||||||
|
restriction.
|
||||||
|
|
||||||
|
Redox OS is also not covered by this MSRV policy, as it requires a Rust nightly
|
||||||
|
toolchain to compile.
|
||||||
|
|
||||||
|
All crates in the [`rust-windowing`] organizations have the
|
||||||
|
same MSRV policy.
|
||||||
|
|
||||||
|
[`rust-windowing`]: https://github.com/rust-windowing
|
||||||
|
|
||||||
### Platform-specific usage
|
### Platform-specific usage
|
||||||
|
|
||||||
#### WebAssembly
|
Check out the [`winit::platform`](https://docs.rs/winit/latest/winit/platform/index.html) module for platform-specific usage.
|
||||||
|
|
||||||
Building a binary will yield a `.js` file. In order to use it in an HTML file, you need to:
|
### Repository License
|
||||||
|
|
||||||
- Put a `<canvas id="my_id"></canvas>` element somewhere. A canvas corresponds to a winit "window".
|
Note that the license in `LICENSE` doesn't apply in full to the DPI package [./dpi](./dpi).
|
||||||
- Write a Javascript code that creates a global variable named `Module`. Set `Module.canvas` to
|
Full details can be found in that folder's README.
|
||||||
the element of the `<canvas>` element (in the example you would retrieve it via `document.getElementById("my_id")`).
|
<!-- This doesn't apply to users of the Winit crate, but this is also the repository level README -->
|
||||||
More information [here](https://kripken.github.io/emscripten-site/docs/api_reference/module.html).
|
|
||||||
- Make sure that you insert the `.js` file generated by Rust after the `Module` variable is created.
|
|
||||||
|
|
||||||
#### Android
|
|
||||||
|
|
||||||
This library makes use of the [ndk-rs](https://github.com/rust-windowing/android-ndk-rs) crates, refer to that repo for more documentation.
|
|
||||||
|
|
||||||
Running on an Android device needs a dynamic system library, add this to Cargo.toml:
|
|
||||||
```toml
|
|
||||||
[[example]]
|
|
||||||
name = "request_redraw_threaded"
|
|
||||||
crate-type = ["cdylib"]
|
|
||||||
```
|
|
||||||
|
|
||||||
And add this to the example file to add the native activity glue:
|
|
||||||
```rust
|
|
||||||
#[cfg(target_os = "android")]
|
|
||||||
ndk_glue::ndk_glue!(main);
|
|
||||||
```
|
|
||||||
|
|
||||||
And run the application with `cargo apk run --example request_redraw_threaded`
|
|
||||||
|
|||||||
27
clippy.toml
Normal file
27
clippy.toml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Using allow-invalid because this is platform-specific code
|
||||||
|
disallowed-macros = [
|
||||||
|
{ path = "std::print", reason = "works badly on web", replacement = "tracing::info" },
|
||||||
|
{ path = "std::println", reason = "works badly on web", replacement = "tracing::info" },
|
||||||
|
{ path = "std::eprint", reason = "works badly on web", replacement = "tracing::error" },
|
||||||
|
{ path = "std::eprintln", reason = "works badly on web", replacement = "tracing::error" },
|
||||||
|
{ path = "std::dbg", reason = "leftover debugging aid, remove it or use tracing" },
|
||||||
|
]
|
||||||
|
disallowed-methods = [
|
||||||
|
{ allow-invalid = true, path = "objc2_app_kit::NSView::visibleRect", reason = "We expose a render target to the user, and visibility is not really relevant to that (and can break if you don't use the rectangle position as well). Use `frame` instead." },
|
||||||
|
{ allow-invalid = true, path = "objc2_app_kit::NSWindow::setFrameTopLeftPoint", reason = "Not sufficient when working with Winit's coordinate system, use `flip_window_screen_coordinates` instead" },
|
||||||
|
{ allow-invalid = true, path = "web_sys::Document::exit_fullscreen", reason = "Doesn't account for compatibility with Safari" },
|
||||||
|
{ allow-invalid = true, path = "web_sys::Document::fullscreen_element", reason = "Doesn't account for compatibility with Safari" },
|
||||||
|
{ allow-invalid = true, path = "web_sys::Element::request_fullscreen", reason = "Doesn't account for compatibility with Safari" },
|
||||||
|
{ allow-invalid = true, path = "web_sys::HtmlCanvasElement::height", reason = "Winit shouldn't touch the internal canvas size" },
|
||||||
|
{ allow-invalid = true, path = "web_sys::HtmlCanvasElement::set_height", reason = "Winit shouldn't touch the internal canvas size" },
|
||||||
|
{ allow-invalid = true, path = "web_sys::HtmlCanvasElement::set_width", reason = "Winit shouldn't touch the internal canvas size" },
|
||||||
|
{ allow-invalid = true, path = "web_sys::HtmlCanvasElement::width", reason = "Winit shouldn't touch the internal canvas size" },
|
||||||
|
{ allow-invalid = true, path = "web_sys::HtmlElement::style", reason = "cache this to reduce calls to JS" },
|
||||||
|
{ allow-invalid = true, path = "web_sys::MouseEvent::buttons", reason = "Use `backend::event::cursor_buttons()` to avoid wrong conversions" },
|
||||||
|
{ allow-invalid = true, path = "web_sys::MouseEvent::button", reason = "Use `backend::event::cursor_button()` to avoid wrong conversions" },
|
||||||
|
{ allow-invalid = true, path = "web_sys::PointerEvent::pointer_type", reason = "Use `WebPointerType` to emit warnings" },
|
||||||
|
{ allow-invalid = true, path = "web_sys::Window::document", reason = "cache this to reduce calls to JS" },
|
||||||
|
{ allow-invalid = true, path = "web_sys::Window::get_computed_style", reason = "cache this to reduce calls to JS" },
|
||||||
|
{ allow-invalid = true, path = "web_sys::Window::navigator", reason = "cache this to reduce calls to JS" },
|
||||||
|
{ allow-invalid = true, path = "web_sys::window", reason = "is not available in every context" },
|
||||||
|
]
|
||||||
61
deny.toml
Normal file
61
deny.toml
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
# https://embarkstudios.github.io/cargo-deny
|
||||||
|
# cargo install cargo-deny
|
||||||
|
# cargo update && cargo deny check
|
||||||
|
[graph]
|
||||||
|
all-features = true
|
||||||
|
exclude-dev = true
|
||||||
|
targets = [
|
||||||
|
"aarch64-apple-darwin",
|
||||||
|
"aarch64-apple-ios",
|
||||||
|
"aarch64-linux-android",
|
||||||
|
"i686-pc-windows-gnu",
|
||||||
|
"i686-pc-windows-msvc",
|
||||||
|
"i686-unknown-linux-gnu",
|
||||||
|
{ triple = "wasm32-unknown-unknown", features = [
|
||||||
|
"atomics",
|
||||||
|
] },
|
||||||
|
"x86_64-apple-darwin",
|
||||||
|
"x86_64-apple-ios",
|
||||||
|
"x86_64-pc-windows-gnu",
|
||||||
|
"x86_64-pc-windows-msvc",
|
||||||
|
"x86_64-unknown-linux-gnu",
|
||||||
|
"x86_64-unknown-redox",
|
||||||
|
]
|
||||||
|
|
||||||
|
[licenses]
|
||||||
|
allow = [
|
||||||
|
"Apache-2.0", # https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)
|
||||||
|
"BSD-2-Clause", # https://tldrlegal.com/license/bsd-2-clause-license-(freebsd)
|
||||||
|
"BSD-3-Clause", # https://tldrlegal.com/license/bsd-3-clause-license-(revised)
|
||||||
|
"ISC", # https://tldrlegal.com/license/isc-license
|
||||||
|
"MIT", # https://tldrlegal.com/license/mit-license
|
||||||
|
"Unicode-3.0", # https://spdx.org/licenses/Unicode-3.0.html
|
||||||
|
"Zlib", # https://spdx.org/licenses/Zlib.html
|
||||||
|
"MPL-2.0", # https://www.mozilla.org/en-US/MPL/2.0/
|
||||||
|
]
|
||||||
|
confidence-threshold = 1.0
|
||||||
|
private = { ignore = true }
|
||||||
|
|
||||||
|
[bans]
|
||||||
|
multiple-versions = "deny"
|
||||||
|
skip = [
|
||||||
|
{ crate = "jni-sys@0.3", reason = "uses the semver trick to depend on v0.4, but `ndk` hasn't been updated to v0.4 yet" },
|
||||||
|
{ crate = "thiserror@1.0", reason = "dep of `ndk` crate, yet to be updated" },
|
||||||
|
{ crate = "thiserror-impl@1.0", reason = "dep of `thiserror`" },
|
||||||
|
{ crate = "objc2@0.5", reason = "used by crossfont" },
|
||||||
|
{ crate = "objc2-foundation@0.2", reason = "used by crossfont" },
|
||||||
|
]
|
||||||
|
skip-tree = [
|
||||||
|
{ crate = "windows-sys", reason = "foundational but bumps fairly often, nothing we can do about it not having a shared version" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[bans.build]
|
||||||
|
bypass = [
|
||||||
|
{ crate = "android-activity", allow-globs = ["android-games-sdk/import-games-sdk.sh"] },
|
||||||
|
{ crate = "freetype-sys", allow-globs = ["freetype2/*"] },
|
||||||
|
# `crossfont` still depends (partially transitively) on `winapi`.
|
||||||
|
{ crate = "winapi-i686-pc-windows-gnu", allow-globs = ["lib/lib*.a"] },
|
||||||
|
{ crate = "winapi-x86_64-pc-windows-gnu", allow-globs = ["lib/lib*.a"] },
|
||||||
|
]
|
||||||
|
include-archives = true
|
||||||
|
interpreted = "deny"
|
||||||
25
dpi/CHANGELOG.md
Normal file
25
dpi/CHANGELOG.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
Please keep one empty line before and after all headers. (This is required for
|
||||||
|
`git` to produce a conflict when a release is made while a PR is open and the
|
||||||
|
PR's changelog entry would go into the wrong section).
|
||||||
|
|
||||||
|
And please only add new entries to the top of this list, right below the `#
|
||||||
|
Unreleased` header.
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
## 0.1.2
|
||||||
|
|
||||||
|
- Added `Insets`, `LogicalInsets` and `PhysicalInsets` types.
|
||||||
|
- Make `no_std` compatible. If you use this functionality, DPI's license has changed.
|
||||||
|
|
||||||
|
## 0.1.1
|
||||||
|
|
||||||
|
- Derive `Debug`, `Copy`, `Clone`, `PartialEq`, `Serialize`, `Deserialize` traits for `PixelUnit`.
|
||||||
|
|
||||||
|
## 0.1.0
|
||||||
|
|
||||||
|
- Add `LogicalUnit`, `PhysicalUnit` and `PixelUnit` types and related functions.
|
||||||
46
dpi/Cargo.toml
Normal file
46
dpi/Cargo.toml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
[package]
|
||||||
|
categories = ["gui"]
|
||||||
|
description = "Types for handling UI scaling"
|
||||||
|
edition.workspace = true
|
||||||
|
keywords = ["DPI", "HiDPI", "scale-factor"]
|
||||||
|
# N.B. This is "AND", because of the imported libm code.
|
||||||
|
license = "Apache-2.0 AND MIT"
|
||||||
|
name = "dpi"
|
||||||
|
repository.workspace = true
|
||||||
|
rust-version.workspace = true
|
||||||
|
version = "0.1.2"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["std"]
|
||||||
|
|
||||||
|
mint = ["dep:mint"]
|
||||||
|
serde = ["dep:serde"]
|
||||||
|
|
||||||
|
# Access mathematical functions using the standard library implementations
|
||||||
|
std = []
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
mint = { workspace = true, optional = true }
|
||||||
|
serde = { workspace = true, optional = true }
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
features = ["mint", "serde"]
|
||||||
|
# These are all tested in CI
|
||||||
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
targets = [
|
||||||
|
# Windows
|
||||||
|
"i686-pc-windows-msvc",
|
||||||
|
"x86_64-pc-windows-msvc",
|
||||||
|
# macOS
|
||||||
|
"aarch64-apple-darwin",
|
||||||
|
"x86_64-apple-darwin",
|
||||||
|
# Unix (X11 & Wayland)
|
||||||
|
"i686-unknown-linux-gnu",
|
||||||
|
"x86_64-unknown-linux-gnu",
|
||||||
|
# iOS
|
||||||
|
"aarch64-apple-ios",
|
||||||
|
# Android
|
||||||
|
"aarch64-linux-android",
|
||||||
|
# Web
|
||||||
|
"wasm32-unknown-unknown",
|
||||||
|
]
|
||||||
1
dpi/LICENSE
Symbolic link
1
dpi/LICENSE
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE
|
||||||
51
dpi/LICENSE-LIBM-MIT
Normal file
51
dpi/LICENSE-LIBM-MIT
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
rust-lang/libm as a whole is available for use under the MIT license:
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This Rust library contains the following copyrights:
|
||||||
|
|
||||||
|
Copyright (c) 2018 Jorge Aparicio
|
||||||
|
|
||||||
|
Portions of this software are derived from third-party works licensed under
|
||||||
|
terms compatible with the above MIT license:
|
||||||
|
|
||||||
|
* musl libc https://www.musl-libc.org/. This library contains the following
|
||||||
|
copyright:
|
||||||
|
|
||||||
|
Copyright © 2005-2020 Rich Felker, et al.
|
||||||
|
|
||||||
|
* The CORE-MATH project https://core-math.gitlabpages.inria.fr/. CORE-MATH
|
||||||
|
routines are available under the MIT license on a per-file basis.
|
||||||
|
|
||||||
|
The musl libc COPYRIGHT file also includes the following notice relevant to
|
||||||
|
math portions of the library:
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
Much of the math library code (src/math/* and src/complex/*) is
|
||||||
|
Copyright © 1993,2004 Sun Microsystems or
|
||||||
|
Copyright © 2003-2011 David Schultz or
|
||||||
|
Copyright © 2003-2009 Steven G. Kargl or
|
||||||
|
Copyright © 2003-2009 Bruce D. Evans or
|
||||||
|
Copyright © 2008 Stephen L. Moshier or
|
||||||
|
Copyright © 2017-2018 Arm Limited
|
||||||
|
and labelled as such in comments in the individual source files. All
|
||||||
|
have been licensed under extremely permissive terms.
|
||||||
|
------------------------------------------------------------------------------
|
||||||
18
dpi/README.md
Normal file
18
dpi/README.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# DPI
|
||||||
|
|
||||||
|
Full docs can be found on docs.rs.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Most of DPI is licensed under the Apache License, Version 2.0 ([LICENSE](LICENSE)).
|
||||||
|
All files except for `src/libm.rs` (and `LICENSE-LIBM-MIT`) are available solely under that license.
|
||||||
|
|
||||||
|
For its `no_std` support, DPI uses code from the [libm](https://crates.io/crates/libm) crate.
|
||||||
|
This is in the `libm.rs` file, and is licensed solely under the MIT Licence ([LICENSE-LIBM-MIT](LICENSE-LIBM-MIT)).
|
||||||
|
That file contains details of all potentially applicable copyright notices.
|
||||||
|
This is feature gated to only be included if you disable the `std` feature, otherwise it will not be compiled into your final binary
|
||||||
|
(and so these license terms will not apply).
|
||||||
|
|
||||||
|
Overall, this means that the license for this crate depends on what features you have enabled.
|
||||||
|
If you enable the `std` feature, then DPI uses only code available under the Apache-2.0 license, and so can be used under the terms of that license.
|
||||||
|
However, if you disable the `std` feature, then both these licenses must be followed to use the crate as a whole.
|
||||||
1223
dpi/src/lib.rs
Normal file
1223
dpi/src/lib.rs
Normal file
File diff suppressed because it is too large
Load Diff
56
dpi/src/libm.rs
Normal file
56
dpi/src/libm.rs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
// Copyright (c) 2018 Jorge Aparicio
|
||||||
|
// Copyright © 2005-2020 Rich Felker, et al.
|
||||||
|
// Copyright © 1993,2004 Sun Microsystems or
|
||||||
|
// Copyright © 2003-2011 David Schultz or
|
||||||
|
// Copyright © 2003-2009 Steven G. Kargl or
|
||||||
|
// Copyright © 2003-2009 Bruce D. Evans or
|
||||||
|
// Copyright © 2008 Stephen L. Moshier or
|
||||||
|
// Copyright © 2017-2018 Arm Limited
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// This file is licensed solely under the terms discussed in LICENSE-LIBM-MIT at the crate root.
|
||||||
|
// See the package-level README for full details.
|
||||||
|
|
||||||
|
// Taken from https://github.com/rust-lang/libm/blob/master/src/math/mod.rs#L1
|
||||||
|
macro_rules! force_eval {
|
||||||
|
($e:expr) => {
|
||||||
|
unsafe { ::core::ptr::read_volatile(&$e) }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Taken from https://github.com/rust-lang/libm/blob/libm-v0.2.11/src/math/round.rs
|
||||||
|
pub(crate) fn round(x: f64) -> f64 {
|
||||||
|
trunc(x + copysign(0.5 - 0.25 * f64::EPSILON, x))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adapted from: https://github.com/rust-lang/libm/blob/libm-v0.2.11/src/math/trunc.rs#L8-L12
|
||||||
|
#[allow(clippy::needless_late_init /*, reason = "The original libm code uses this style" */)]
|
||||||
|
fn trunc(x: f64) -> f64 {
|
||||||
|
let x1p120 = f64::from_bits(0x4770000000000000); // 0x1p120f === 2 ^ 120
|
||||||
|
|
||||||
|
let mut i: u64 = x.to_bits();
|
||||||
|
let mut e: i64 = ((i >> 52) & 0x7ff) as i64 - 0x3ff + 12;
|
||||||
|
let m: u64;
|
||||||
|
|
||||||
|
if e >= 52 + 12 {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
if e < 12 {
|
||||||
|
e = 1;
|
||||||
|
}
|
||||||
|
m = -1i64 as u64 >> e;
|
||||||
|
if (i & m) == 0 {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
force_eval!(x + x1p120);
|
||||||
|
i &= !m;
|
||||||
|
f64::from_bits(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Taken from https://github.com/rust-lang/libm/blob/libm-v0.2.11/src/math/copysign.rs
|
||||||
|
fn copysign(x: f64, y: f64) -> f64 {
|
||||||
|
let mut ux = x.to_bits();
|
||||||
|
let uy = y.to_bits();
|
||||||
|
ux &= (!0) >> 1;
|
||||||
|
ux |= uy & (1 << 63);
|
||||||
|
f64::from_bits(ux)
|
||||||
|
}
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
use std::{thread, time};
|
|
||||||
|
|
||||||
use winit::{
|
|
||||||
event::{Event, KeyboardInput, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::WindowBuilder,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
||||||
enum Mode {
|
|
||||||
Wait,
|
|
||||||
WaitUntil,
|
|
||||||
Poll,
|
|
||||||
}
|
|
||||||
|
|
||||||
const WAIT_TIME: time::Duration = time::Duration::from_millis(100);
|
|
||||||
const POLL_SLEEP_TIME: time::Duration = time::Duration::from_millis(100);
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
|
|
||||||
println!("Press '1' to switch to Wait mode.");
|
|
||||||
println!("Press '2' to switch to WaitUntil mode.");
|
|
||||||
println!("Press '3' to switch to Poll mode.");
|
|
||||||
println!("Press 'R' to toggle request_redraw() calls.");
|
|
||||||
println!("Press 'Esc' to close the window.");
|
|
||||||
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
let window = WindowBuilder::new()
|
|
||||||
.with_title("Press 1, 2, 3 to change control flow mode. Press R to toggle redraw requests.")
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut mode = Mode::Wait;
|
|
||||||
let mut request_redraw = false;
|
|
||||||
let mut wait_cancelled = false;
|
|
||||||
let mut close_requested = false;
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
use winit::event::{ElementState, StartCause, VirtualKeyCode};
|
|
||||||
println!("{:?}", event);
|
|
||||||
match event {
|
|
||||||
Event::NewEvents(start_cause) => {
|
|
||||||
wait_cancelled = match start_cause {
|
|
||||||
StartCause::WaitCancelled { .. } => mode == Mode::WaitUntil,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Event::WindowEvent { event, .. } => match event {
|
|
||||||
WindowEvent::CloseRequested => {
|
|
||||||
close_requested = true;
|
|
||||||
}
|
|
||||||
WindowEvent::KeyboardInput {
|
|
||||||
input:
|
|
||||||
KeyboardInput {
|
|
||||||
virtual_keycode: Some(virtual_code),
|
|
||||||
state: ElementState::Pressed,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} => match virtual_code {
|
|
||||||
VirtualKeyCode::Key1 => {
|
|
||||||
mode = Mode::Wait;
|
|
||||||
println!("\nmode: {:?}\n", mode);
|
|
||||||
}
|
|
||||||
VirtualKeyCode::Key2 => {
|
|
||||||
mode = Mode::WaitUntil;
|
|
||||||
println!("\nmode: {:?}\n", mode);
|
|
||||||
}
|
|
||||||
VirtualKeyCode::Key3 => {
|
|
||||||
mode = Mode::Poll;
|
|
||||||
println!("\nmode: {:?}\n", mode);
|
|
||||||
}
|
|
||||||
VirtualKeyCode::R => {
|
|
||||||
request_redraw = !request_redraw;
|
|
||||||
println!("\nrequest_redraw: {}\n", request_redraw);
|
|
||||||
}
|
|
||||||
VirtualKeyCode::Escape => {
|
|
||||||
close_requested = true;
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
Event::MainEventsCleared => {
|
|
||||||
if request_redraw && !wait_cancelled && !close_requested {
|
|
||||||
window.request_redraw();
|
|
||||||
}
|
|
||||||
if close_requested {
|
|
||||||
*control_flow = ControlFlow::Exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Event::RedrawRequested(_window_id) => {}
|
|
||||||
Event::RedrawEventsCleared => {
|
|
||||||
*control_flow = match mode {
|
|
||||||
Mode::Wait => ControlFlow::Wait,
|
|
||||||
Mode::WaitUntil => {
|
|
||||||
if wait_cancelled {
|
|
||||||
*control_flow
|
|
||||||
} else {
|
|
||||||
ControlFlow::WaitUntil(time::Instant::now() + WAIT_TIME)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Mode::Poll => {
|
|
||||||
thread::sleep(POLL_SLEEP_TIME);
|
|
||||||
ControlFlow::Poll
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
use winit::{
|
|
||||||
event::{ElementState, Event, KeyboardInput, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::{CursorIcon, WindowBuilder},
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
|
||||||
window.set_title("A fantastic window!");
|
|
||||||
|
|
||||||
let mut cursor_idx = 0;
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent {
|
|
||||||
event:
|
|
||||||
WindowEvent::KeyboardInput {
|
|
||||||
input:
|
|
||||||
KeyboardInput {
|
|
||||||
state: ElementState::Pressed,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
println!("Setting cursor to \"{:?}\"", CURSORS[cursor_idx]);
|
|
||||||
window.set_cursor_icon(CURSORS[cursor_idx]);
|
|
||||||
if cursor_idx < CURSORS.len() - 1 {
|
|
||||||
cursor_idx += 1;
|
|
||||||
} else {
|
|
||||||
cursor_idx = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::CloseRequested,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
*control_flow = ControlFlow::Exit;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const CURSORS: &[CursorIcon] = &[
|
|
||||||
CursorIcon::Default,
|
|
||||||
CursorIcon::Crosshair,
|
|
||||||
CursorIcon::Hand,
|
|
||||||
CursorIcon::Arrow,
|
|
||||||
CursorIcon::Move,
|
|
||||||
CursorIcon::Text,
|
|
||||||
CursorIcon::Wait,
|
|
||||||
CursorIcon::Help,
|
|
||||||
CursorIcon::Progress,
|
|
||||||
CursorIcon::NotAllowed,
|
|
||||||
CursorIcon::ContextMenu,
|
|
||||||
CursorIcon::Cell,
|
|
||||||
CursorIcon::VerticalText,
|
|
||||||
CursorIcon::Alias,
|
|
||||||
CursorIcon::Copy,
|
|
||||||
CursorIcon::NoDrop,
|
|
||||||
CursorIcon::Grab,
|
|
||||||
CursorIcon::Grabbing,
|
|
||||||
CursorIcon::AllScroll,
|
|
||||||
CursorIcon::ZoomIn,
|
|
||||||
CursorIcon::ZoomOut,
|
|
||||||
CursorIcon::EResize,
|
|
||||||
CursorIcon::NResize,
|
|
||||||
CursorIcon::NeResize,
|
|
||||||
CursorIcon::NwResize,
|
|
||||||
CursorIcon::SResize,
|
|
||||||
CursorIcon::SeResize,
|
|
||||||
CursorIcon::SwResize,
|
|
||||||
CursorIcon::WResize,
|
|
||||||
CursorIcon::EwResize,
|
|
||||||
CursorIcon::NsResize,
|
|
||||||
CursorIcon::NeswResize,
|
|
||||||
CursorIcon::NwseResize,
|
|
||||||
CursorIcon::ColResize,
|
|
||||||
CursorIcon::RowResize,
|
|
||||||
];
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
use winit::{
|
|
||||||
event::{DeviceEvent, ElementState, Event, KeyboardInput, ModifiersState, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::WindowBuilder,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
|
||||||
.with_title("Super Cursor Grab'n'Hide Simulator 9000")
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut modifiers = ModifiersState::default();
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent { event, .. } => match event {
|
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
|
||||||
WindowEvent::KeyboardInput {
|
|
||||||
input:
|
|
||||||
KeyboardInput {
|
|
||||||
state: ElementState::Released,
|
|
||||||
virtual_keycode: Some(key),
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
use winit::event::VirtualKeyCode::*;
|
|
||||||
match key {
|
|
||||||
Escape => *control_flow = ControlFlow::Exit,
|
|
||||||
G => window.set_cursor_grab(!modifiers.shift()).unwrap(),
|
|
||||||
H => window.set_cursor_visible(modifiers.shift()),
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
WindowEvent::ModifiersChanged(m) => modifiers = m,
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
Event::DeviceEvent { event, .. } => match event {
|
|
||||||
DeviceEvent::MouseMotion { delta } => println!("mouse moved: {:?}", delta),
|
|
||||||
DeviceEvent::Button { button, state } => match state {
|
|
||||||
ElementState::Pressed => println!("mouse button {} pressed", button),
|
|
||||||
ElementState::Released => println!("mouse button {} released", button),
|
|
||||||
},
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
fn main() {
|
|
||||||
use winit::{
|
|
||||||
event::{Event, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::WindowBuilder,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
enum CustomEvent {
|
|
||||||
Timer,
|
|
||||||
}
|
|
||||||
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::<CustomEvent>::with_user_event();
|
|
||||||
|
|
||||||
let _window = WindowBuilder::new()
|
|
||||||
.with_title("A fantastic window!")
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// `EventLoopProxy` allows you to dispatch custom events to the main Winit event
|
|
||||||
// loop from any thread.
|
|
||||||
let event_loop_proxy = event_loop.create_proxy();
|
|
||||||
|
|
||||||
std::thread::spawn(move || {
|
|
||||||
// Wake up the `event_loop` once every second and dispatch a custom event
|
|
||||||
// from a different thread.
|
|
||||||
loop {
|
|
||||||
std::thread::sleep(std::time::Duration::from_secs(1));
|
|
||||||
event_loop_proxy.send_event(CustomEvent::Timer).ok();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::UserEvent(event) => println!("user event: {:?}", event),
|
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::CloseRequested,
|
|
||||||
..
|
|
||||||
} => *control_flow = ControlFlow::Exit,
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
fn main() {
|
|
||||||
panic!("This example is not supported on web.");
|
|
||||||
}
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
use std::io::{stdin, stdout, Write};
|
|
||||||
use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent};
|
|
||||||
use winit::event_loop::{ControlFlow, EventLoop};
|
|
||||||
use winit::monitor::{MonitorHandle, VideoMode};
|
|
||||||
use winit::window::{Fullscreen, WindowBuilder};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
print!("Please choose the fullscreen mode: (1) exclusive, (2) borderless: ");
|
|
||||||
stdout().flush().unwrap();
|
|
||||||
|
|
||||||
let mut num = String::new();
|
|
||||||
stdin().read_line(&mut num).unwrap();
|
|
||||||
let num = num.trim().parse().ok().expect("Please enter a number");
|
|
||||||
|
|
||||||
let fullscreen = Some(match num {
|
|
||||||
1 => Fullscreen::Exclusive(prompt_for_video_mode(&prompt_for_monitor(&event_loop))),
|
|
||||||
2 => Fullscreen::Borderless(prompt_for_monitor(&event_loop)),
|
|
||||||
_ => panic!("Please enter a valid number"),
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut is_maximized = false;
|
|
||||||
let mut decorations = true;
|
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
|
||||||
.with_title("Hello world!")
|
|
||||||
.with_fullscreen(fullscreen.clone())
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent { event, .. } => match event {
|
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
|
||||||
WindowEvent::KeyboardInput {
|
|
||||||
input:
|
|
||||||
KeyboardInput {
|
|
||||||
virtual_keycode: Some(virtual_code),
|
|
||||||
state,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} => match (virtual_code, state) {
|
|
||||||
(VirtualKeyCode::Escape, _) => *control_flow = ControlFlow::Exit,
|
|
||||||
(VirtualKeyCode::F, ElementState::Pressed) => {
|
|
||||||
if window.fullscreen().is_some() {
|
|
||||||
window.set_fullscreen(None);
|
|
||||||
} else {
|
|
||||||
window.set_fullscreen(fullscreen.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(VirtualKeyCode::S, ElementState::Pressed) => {
|
|
||||||
println!("window.fullscreen {:?}", window.fullscreen());
|
|
||||||
}
|
|
||||||
(VirtualKeyCode::M, ElementState::Pressed) => {
|
|
||||||
is_maximized = !is_maximized;
|
|
||||||
window.set_maximized(is_maximized);
|
|
||||||
}
|
|
||||||
(VirtualKeyCode::D, ElementState::Pressed) => {
|
|
||||||
decorations = !decorations;
|
|
||||||
window.set_decorations(decorations);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enumerate monitors and prompt user to choose one
|
|
||||||
fn prompt_for_monitor(event_loop: &EventLoop<()>) -> MonitorHandle {
|
|
||||||
for (num, monitor) in event_loop.available_monitors().enumerate() {
|
|
||||||
println!("Monitor #{}: {:?}", num, monitor.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
print!("Please write the number of the monitor to use: ");
|
|
||||||
stdout().flush().unwrap();
|
|
||||||
|
|
||||||
let mut num = String::new();
|
|
||||||
stdin().read_line(&mut num).unwrap();
|
|
||||||
let num = num.trim().parse().ok().expect("Please enter a number");
|
|
||||||
let monitor = event_loop
|
|
||||||
.available_monitors()
|
|
||||||
.nth(num)
|
|
||||||
.expect("Please enter a valid ID");
|
|
||||||
|
|
||||||
println!("Using {:?}", monitor.name());
|
|
||||||
|
|
||||||
monitor
|
|
||||||
}
|
|
||||||
|
|
||||||
fn prompt_for_video_mode(monitor: &MonitorHandle) -> VideoMode {
|
|
||||||
for (i, video_mode) in monitor.video_modes().enumerate() {
|
|
||||||
println!("Video mode #{}: {}", i, video_mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
print!("Please write the number of the video mode to use: ");
|
|
||||||
stdout().flush().unwrap();
|
|
||||||
|
|
||||||
let mut num = String::new();
|
|
||||||
stdin().read_line(&mut num).unwrap();
|
|
||||||
let num = num.trim().parse().ok().expect("Please enter a number");
|
|
||||||
let video_mode = monitor
|
|
||||||
.video_modes()
|
|
||||||
.nth(num)
|
|
||||||
.expect("Please enter a valid ID");
|
|
||||||
|
|
||||||
println!("Using {}", video_mode);
|
|
||||||
|
|
||||||
video_mode
|
|
||||||
}
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
use winit::{
|
|
||||||
event::{Event, KeyboardInput, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::WindowBuilder,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
let _window = WindowBuilder::new()
|
|
||||||
.with_title("Your faithful window")
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut close_requested = false;
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
use winit::event::{
|
|
||||||
ElementState::Released,
|
|
||||||
VirtualKeyCode::{N, Y},
|
|
||||||
};
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent { event, .. } => {
|
|
||||||
match event {
|
|
||||||
WindowEvent::CloseRequested => {
|
|
||||||
// `CloseRequested` is sent when the close button on the window is pressed (or
|
|
||||||
// through whatever other mechanisms the window manager provides for closing a
|
|
||||||
// window). If you don't handle this event, the close button won't actually do
|
|
||||||
// anything.
|
|
||||||
|
|
||||||
// A common thing to do here is prompt the user if they have unsaved work.
|
|
||||||
// Creating a proper dialog box for that is far beyond the scope of this
|
|
||||||
// example, so here we'll just respond to the Y and N keys.
|
|
||||||
println!("Are you ready to bid your window farewell? [Y/N]");
|
|
||||||
close_requested = true;
|
|
||||||
|
|
||||||
// In applications where you can safely close the window without further
|
|
||||||
// action from the user, this is generally where you'd handle cleanup before
|
|
||||||
// closing the window. How to close the window is detailed in the handler for
|
|
||||||
// the Y key.
|
|
||||||
}
|
|
||||||
WindowEvent::KeyboardInput {
|
|
||||||
input:
|
|
||||||
KeyboardInput {
|
|
||||||
virtual_keycode: Some(virtual_code),
|
|
||||||
state: Released,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
match virtual_code {
|
|
||||||
Y => {
|
|
||||||
if close_requested {
|
|
||||||
// This is where you'll want to do any cleanup you need.
|
|
||||||
println!("Buh-bye!");
|
|
||||||
|
|
||||||
// For a single-window application like this, you'd normally just
|
|
||||||
// break out of the event loop here. If you wanted to keep running the
|
|
||||||
// event loop (i.e. if it's a multi-window application), you need to
|
|
||||||
// drop the window. That closes it, and results in `Destroyed` being
|
|
||||||
// sent.
|
|
||||||
*control_flow = ControlFlow::Exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
N => {
|
|
||||||
if close_requested {
|
|
||||||
println!("Your window will continue to stay by your side.");
|
|
||||||
close_requested = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
use winit::{
|
|
||||||
dpi::LogicalSize,
|
|
||||||
event::{Event, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::WindowBuilder,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
|
||||||
|
|
||||||
window.set_min_inner_size(Some(LogicalSize::new(400.0, 200.0)));
|
|
||||||
window.set_max_inner_size(Some(LogicalSize::new(800.0, 400.0)));
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
println!("{:?}", event);
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::CloseRequested,
|
|
||||||
..
|
|
||||||
} => *control_flow = ControlFlow::Exit,
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
extern crate winit;
|
|
||||||
|
|
||||||
use winit::event::{Event, VirtualKeyCode, WindowEvent};
|
|
||||||
use winit::event_loop::{ControlFlow, EventLoop};
|
|
||||||
use winit::window::WindowBuilder;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
|
||||||
.with_title("A fantastic window!")
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::CloseRequested,
|
|
||||||
..
|
|
||||||
} => *control_flow = ControlFlow::Exit,
|
|
||||||
|
|
||||||
// Keyboard input event to handle minimize via a hotkey
|
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::KeyboardInput { input, .. },
|
|
||||||
window_id,
|
|
||||||
} => {
|
|
||||||
if window_id == window.id() {
|
|
||||||
// Pressing the 'M' key will minimize the window
|
|
||||||
if input.virtual_keycode == Some(VirtualKeyCode::M) {
|
|
||||||
window.set_minimized(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
use winit::{event_loop::EventLoop, window::WindowBuilder};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
|
||||||
|
|
||||||
dbg!(window.available_monitors().collect::<Vec<_>>());
|
|
||||||
dbg!(window.primary_monitor());
|
|
||||||
}
|
|
||||||
@@ -1,185 +0,0 @@
|
|||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
fn main() {
|
|
||||||
use std::{collections::HashMap, sync::mpsc, thread, time::Duration};
|
|
||||||
|
|
||||||
use winit::{
|
|
||||||
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
|
|
||||||
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::{CursorIcon, Fullscreen, WindowBuilder},
|
|
||||||
};
|
|
||||||
|
|
||||||
const WINDOW_COUNT: usize = 3;
|
|
||||||
const WINDOW_SIZE: PhysicalSize<u32> = PhysicalSize::new(600, 400);
|
|
||||||
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
let mut window_senders = HashMap::with_capacity(WINDOW_COUNT);
|
|
||||||
for _ in 0..WINDOW_COUNT {
|
|
||||||
let window = WindowBuilder::new()
|
|
||||||
.with_inner_size(WINDOW_SIZE)
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut video_modes: Vec<_> = window.current_monitor().video_modes().collect();
|
|
||||||
let mut video_mode_id = 0usize;
|
|
||||||
|
|
||||||
let (tx, rx) = mpsc::channel();
|
|
||||||
window_senders.insert(window.id(), tx);
|
|
||||||
thread::spawn(move || {
|
|
||||||
while let Ok(event) = rx.recv() {
|
|
||||||
match event {
|
|
||||||
WindowEvent::Moved { .. } => {
|
|
||||||
// We need to update our chosen video mode if the window
|
|
||||||
// was moved to an another monitor, so that the window
|
|
||||||
// appears on this monitor instead when we go fullscreen
|
|
||||||
let previous_video_mode = video_modes.iter().cloned().nth(video_mode_id);
|
|
||||||
video_modes = window.current_monitor().video_modes().collect();
|
|
||||||
video_mode_id = video_mode_id.min(video_modes.len());
|
|
||||||
let video_mode = video_modes.iter().nth(video_mode_id);
|
|
||||||
|
|
||||||
// Different monitors may support different video modes,
|
|
||||||
// and the index we chose previously may now point to a
|
|
||||||
// completely different video mode, so notify the user
|
|
||||||
if video_mode != previous_video_mode.as_ref() {
|
|
||||||
println!(
|
|
||||||
"Window moved to another monitor, picked video mode: {}",
|
|
||||||
video_modes.iter().nth(video_mode_id).unwrap()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[allow(deprecated)]
|
|
||||||
WindowEvent::KeyboardInput {
|
|
||||||
input:
|
|
||||||
KeyboardInput {
|
|
||||||
state: ElementState::Released,
|
|
||||||
virtual_keycode: Some(key),
|
|
||||||
modifiers,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
window.set_title(&format!("{:?}", key));
|
|
||||||
let state = !modifiers.shift();
|
|
||||||
use VirtualKeyCode::*;
|
|
||||||
match key {
|
|
||||||
A => window.set_always_on_top(state),
|
|
||||||
C => window.set_cursor_icon(match state {
|
|
||||||
true => CursorIcon::Progress,
|
|
||||||
false => CursorIcon::Default,
|
|
||||||
}),
|
|
||||||
D => window.set_decorations(!state),
|
|
||||||
// Cycle through video modes
|
|
||||||
Right | Left => {
|
|
||||||
video_mode_id = match key {
|
|
||||||
Left => video_mode_id.saturating_sub(1),
|
|
||||||
Right => (video_modes.len() - 1).min(video_mode_id + 1),
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
println!(
|
|
||||||
"Picking video mode: {}",
|
|
||||||
video_modes.iter().nth(video_mode_id).unwrap()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
F => window.set_fullscreen(match (state, modifiers.alt()) {
|
|
||||||
(true, false) => {
|
|
||||||
Some(Fullscreen::Borderless(window.current_monitor()))
|
|
||||||
}
|
|
||||||
(true, true) => Some(Fullscreen::Exclusive(
|
|
||||||
video_modes.iter().nth(video_mode_id).unwrap().clone(),
|
|
||||||
)),
|
|
||||||
(false, _) => None,
|
|
||||||
}),
|
|
||||||
G => window.set_cursor_grab(state).unwrap(),
|
|
||||||
H => window.set_cursor_visible(!state),
|
|
||||||
I => {
|
|
||||||
println!("Info:");
|
|
||||||
println!("-> outer_position : {:?}", window.outer_position());
|
|
||||||
println!("-> inner_position : {:?}", window.inner_position());
|
|
||||||
println!("-> outer_size : {:?}", window.outer_size());
|
|
||||||
println!("-> inner_size : {:?}", window.inner_size());
|
|
||||||
println!("-> fullscreen : {:?}", window.fullscreen());
|
|
||||||
}
|
|
||||||
L => window.set_min_inner_size(match state {
|
|
||||||
true => Some(WINDOW_SIZE),
|
|
||||||
false => None,
|
|
||||||
}),
|
|
||||||
M => window.set_maximized(state),
|
|
||||||
P => window.set_outer_position({
|
|
||||||
let mut position = window.outer_position().unwrap();
|
|
||||||
let sign = if state { 1 } else { -1 };
|
|
||||||
position.x += 10 * sign;
|
|
||||||
position.y += 10 * sign;
|
|
||||||
position
|
|
||||||
}),
|
|
||||||
Q => window.request_redraw(),
|
|
||||||
R => window.set_resizable(state),
|
|
||||||
S => window.set_inner_size(match state {
|
|
||||||
true => PhysicalSize::new(
|
|
||||||
WINDOW_SIZE.width + 100,
|
|
||||||
WINDOW_SIZE.height + 100,
|
|
||||||
),
|
|
||||||
false => WINDOW_SIZE,
|
|
||||||
}),
|
|
||||||
W => {
|
|
||||||
if let Size::Physical(size) = WINDOW_SIZE.into() {
|
|
||||||
window
|
|
||||||
.set_cursor_position(Position::Physical(
|
|
||||||
PhysicalPosition::new(
|
|
||||||
size.width as i32 / 2,
|
|
||||||
size.height as i32 / 2,
|
|
||||||
),
|
|
||||||
))
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Z => {
|
|
||||||
window.set_visible(false);
|
|
||||||
thread::sleep(Duration::from_secs(1));
|
|
||||||
window.set_visible(true);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
event_loop.run(move |event, _event_loop, control_flow| {
|
|
||||||
*control_flow = match !window_senders.is_empty() {
|
|
||||||
true => ControlFlow::Wait,
|
|
||||||
false => ControlFlow::Exit,
|
|
||||||
};
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent { event, window_id } => match event {
|
|
||||||
WindowEvent::CloseRequested
|
|
||||||
| WindowEvent::Destroyed
|
|
||||||
| WindowEvent::KeyboardInput {
|
|
||||||
input:
|
|
||||||
KeyboardInput {
|
|
||||||
state: ElementState::Released,
|
|
||||||
virtual_keycode: Some(VirtualKeyCode::Escape),
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
window_senders.remove(&window_id);
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
if let Some(tx) = window_senders.get(&window_id) {
|
|
||||||
if let Some(event) = event.to_static() {
|
|
||||||
tx.send(event).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
|
||||||
fn main() {
|
|
||||||
panic!("Example not supported on Wasm");
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
use winit::{
|
|
||||||
event::{ElementState, Event, KeyboardInput, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::Window,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
let mut windows = HashMap::new();
|
|
||||||
for _ in 0..3 {
|
|
||||||
let window = Window::new(&event_loop).unwrap();
|
|
||||||
windows.insert(window.id(), window);
|
|
||||||
}
|
|
||||||
|
|
||||||
event_loop.run(move |event, event_loop, control_flow| {
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent { event, window_id } => {
|
|
||||||
match event {
|
|
||||||
WindowEvent::CloseRequested => {
|
|
||||||
println!("Window {:?} has received the signal to close", window_id);
|
|
||||||
|
|
||||||
// This drops the window, causing it to close.
|
|
||||||
windows.remove(&window_id);
|
|
||||||
|
|
||||||
if windows.is_empty() {
|
|
||||||
*control_flow = ControlFlow::Exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
WindowEvent::KeyboardInput {
|
|
||||||
input:
|
|
||||||
KeyboardInput {
|
|
||||||
state: ElementState::Pressed,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
let window = Window::new(&event_loop).unwrap();
|
|
||||||
windows.insert(window.id(), window);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
use winit::{
|
|
||||||
event::{ElementState, Event, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::WindowBuilder,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
|
||||||
.with_title("A fantastic window!")
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
println!("{:?}", event);
|
|
||||||
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent { event, .. } => match event {
|
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
|
||||||
WindowEvent::MouseInput {
|
|
||||||
state: ElementState::Released,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
window.request_redraw();
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
println!("\nredrawing!\n");
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
use std::{thread, time};
|
|
||||||
|
|
||||||
use winit::{
|
|
||||||
event::{Event, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::WindowBuilder,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
|
||||||
.with_title("A fantastic window!")
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
thread::spawn(move || loop {
|
|
||||||
thread::sleep(time::Duration::from_secs(1));
|
|
||||||
window.request_redraw();
|
|
||||||
});
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
println!("{:?}", event);
|
|
||||||
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent { event, .. } => match event {
|
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
Event::RedrawRequested(_) => {
|
|
||||||
println!("\nredrawing!\n");
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
use winit::{
|
|
||||||
dpi::LogicalSize,
|
|
||||||
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::WindowBuilder,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
let mut resizable = false;
|
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
|
||||||
.with_title("Hit space to toggle resizability.")
|
|
||||||
.with_inner_size(LogicalSize::new(400.0, 200.0))
|
|
||||||
.with_resizable(resizable)
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent { event, .. } => match event {
|
|
||||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
|
||||||
WindowEvent::KeyboardInput {
|
|
||||||
input:
|
|
||||||
KeyboardInput {
|
|
||||||
virtual_keycode: Some(VirtualKeyCode::Space),
|
|
||||||
state: ElementState::Released,
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
resizable = !resizable;
|
|
||||||
println!("Resizable: {}", resizable);
|
|
||||||
window.set_resizable(resizable);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
_ => (),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
use instant::Instant;
|
|
||||||
use std::time::Duration;
|
|
||||||
use winit::{
|
|
||||||
event::{Event, StartCause, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::WindowBuilder,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
let _window = WindowBuilder::new()
|
|
||||||
.with_title("A fantastic window!")
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let timer_length = Duration::new(1, 0);
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
println!("{:?}", event);
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::NewEvents(StartCause::Init) => {
|
|
||||||
*control_flow = ControlFlow::WaitUntil(Instant::now() + timer_length)
|
|
||||||
}
|
|
||||||
Event::NewEvents(StartCause::ResumeTimeReached { .. }) => {
|
|
||||||
*control_flow = ControlFlow::WaitUntil(Instant::now() + timer_length);
|
|
||||||
println!("\nTimer\n");
|
|
||||||
}
|
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::CloseRequested,
|
|
||||||
..
|
|
||||||
} => *control_flow = ControlFlow::Exit,
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
use winit::{
|
|
||||||
event::{Event, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::WindowBuilder,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
|
||||||
.with_decorations(false)
|
|
||||||
.with_transparent(true)
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
window.set_title("A fantastic window!");
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
println!("{:?}", event);
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::CloseRequested,
|
|
||||||
..
|
|
||||||
} => *control_flow = ControlFlow::Exit,
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
use winit::event_loop::EventLoop;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
let monitor = event_loop.primary_monitor();
|
|
||||||
|
|
||||||
println!("Listing available video modes:");
|
|
||||||
|
|
||||||
for mode in monitor.video_modes() {
|
|
||||||
println!("{}", mode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
use winit::{
|
|
||||||
event::{Event, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::WindowBuilder,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
|
||||||
.with_title("A fantastic window!")
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
#[cfg(feature = "web-sys")]
|
|
||||||
{
|
|
||||||
use winit::platform::web::WindowExtWebSys;
|
|
||||||
|
|
||||||
let canvas = window.canvas();
|
|
||||||
|
|
||||||
let window = web_sys::window().unwrap();
|
|
||||||
let document = window.document().unwrap();
|
|
||||||
let body = document.body().unwrap();
|
|
||||||
|
|
||||||
body.append_child(&canvas)
|
|
||||||
.expect("Append canvas to HTML body");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "stdweb")]
|
|
||||||
{
|
|
||||||
use std_web::web::INode;
|
|
||||||
use winit::platform::web::WindowExtStdweb;
|
|
||||||
|
|
||||||
let canvas = window.canvas();
|
|
||||||
|
|
||||||
let document = std_web::web::document();
|
|
||||||
let body: std_web::web::Node = document.body().expect("Get HTML body").into();
|
|
||||||
|
|
||||||
body.append_child(&canvas);
|
|
||||||
}
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
|
|
||||||
#[cfg(feature = "web-sys")]
|
|
||||||
log::debug!("{:?}", event);
|
|
||||||
|
|
||||||
#[cfg(feature = "stdweb")]
|
|
||||||
std_web::console!(log, "%s", format!("{:?}", event));
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::CloseRequested,
|
|
||||||
window_id,
|
|
||||||
} if window_id == window.id() => *control_flow = ControlFlow::Exit,
|
|
||||||
Event::MainEventsCleared => {
|
|
||||||
window.request_redraw();
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "web-sys")]
|
|
||||||
mod wasm {
|
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
|
|
||||||
#[wasm_bindgen(start)]
|
|
||||||
pub fn run() {
|
|
||||||
console_log::init_with_level(log::Level::Debug);
|
|
||||||
|
|
||||||
super::main();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
use winit::{
|
|
||||||
event::{Event, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::WindowBuilder,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
|
||||||
.with_title("A fantastic window!")
|
|
||||||
.with_inner_size(winit::dpi::LogicalSize::new(128.0, 128.0))
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
println!("{:?}", event);
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::CloseRequested,
|
|
||||||
window_id,
|
|
||||||
} if window_id == window.id() => *control_flow = ControlFlow::Exit,
|
|
||||||
Event::MainEventsCleared => {
|
|
||||||
window.request_redraw();
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
// This example is used by developers to test various window functions.
|
|
||||||
|
|
||||||
use winit::{
|
|
||||||
dpi::{LogicalSize, PhysicalSize},
|
|
||||||
event::{DeviceEvent, ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::{Fullscreen, WindowBuilder},
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
|
||||||
.with_title("A fantastic window!")
|
|
||||||
.with_inner_size(LogicalSize::new(100.0, 100.0))
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
eprintln!("debugging keys:");
|
|
||||||
eprintln!(" (E) Enter exclusive fullscreen");
|
|
||||||
eprintln!(" (F) Toggle borderless fullscreen");
|
|
||||||
eprintln!(" (M) Toggle minimized");
|
|
||||||
eprintln!(" (Q) Quit event loop");
|
|
||||||
eprintln!(" (V) Toggle visibility");
|
|
||||||
eprintln!(" (X) Toggle maximized");
|
|
||||||
|
|
||||||
let mut minimized = false;
|
|
||||||
let mut maximized = false;
|
|
||||||
let mut visible = true;
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::DeviceEvent {
|
|
||||||
event:
|
|
||||||
DeviceEvent::Key(KeyboardInput {
|
|
||||||
virtual_keycode: Some(key),
|
|
||||||
state: ElementState::Pressed,
|
|
||||||
..
|
|
||||||
}),
|
|
||||||
..
|
|
||||||
} => match key {
|
|
||||||
VirtualKeyCode::M => {
|
|
||||||
if minimized {
|
|
||||||
minimized = !minimized;
|
|
||||||
window.set_minimized(minimized);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VirtualKeyCode::V => {
|
|
||||||
if !visible {
|
|
||||||
visible = !visible;
|
|
||||||
window.set_visible(visible);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::KeyboardInput { input, .. },
|
|
||||||
..
|
|
||||||
} => match input {
|
|
||||||
KeyboardInput {
|
|
||||||
virtual_keycode: Some(key),
|
|
||||||
state: ElementState::Pressed,
|
|
||||||
..
|
|
||||||
} => match key {
|
|
||||||
VirtualKeyCode::E => {
|
|
||||||
fn area(size: PhysicalSize<u32>) -> u32 {
|
|
||||||
size.width * size.height
|
|
||||||
}
|
|
||||||
|
|
||||||
let monitor = window.current_monitor();
|
|
||||||
if let Some(mode) = monitor
|
|
||||||
.video_modes()
|
|
||||||
.max_by(|a, b| area(a.size()).cmp(&area(b.size())))
|
|
||||||
{
|
|
||||||
window.set_fullscreen(Some(Fullscreen::Exclusive(mode)));
|
|
||||||
} else {
|
|
||||||
eprintln!("no video modes available");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VirtualKeyCode::F => {
|
|
||||||
if window.fullscreen().is_some() {
|
|
||||||
window.set_fullscreen(None);
|
|
||||||
} else {
|
|
||||||
let monitor = window.current_monitor();
|
|
||||||
window.set_fullscreen(Some(Fullscreen::Borderless(monitor)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VirtualKeyCode::M => {
|
|
||||||
minimized = !minimized;
|
|
||||||
window.set_minimized(minimized);
|
|
||||||
}
|
|
||||||
VirtualKeyCode::Q => {
|
|
||||||
*control_flow = ControlFlow::Exit;
|
|
||||||
}
|
|
||||||
VirtualKeyCode::V => {
|
|
||||||
visible = !visible;
|
|
||||||
window.set_visible(visible);
|
|
||||||
}
|
|
||||||
VirtualKeyCode::X => {
|
|
||||||
maximized = !maximized;
|
|
||||||
window.set_maximized(maximized);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::CloseRequested,
|
|
||||||
window_id,
|
|
||||||
} if window_id == window.id() => *control_flow = ControlFlow::Exit,
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
extern crate image;
|
|
||||||
use std::path::Path;
|
|
||||||
use winit::{
|
|
||||||
event::Event,
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
window::{Icon, WindowBuilder},
|
|
||||||
};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
|
|
||||||
// You'll have to choose an icon size at your own discretion. On X11, the desired size varies
|
|
||||||
// by WM, and on Windows, you still have to account for screen scaling. Here we use 32px,
|
|
||||||
// since it seems to work well enough in most cases. Be careful about going too high, or
|
|
||||||
// you'll be bitten by the low-quality downscaling built into the WM.
|
|
||||||
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/icon.png");
|
|
||||||
|
|
||||||
let icon = load_icon(Path::new(path));
|
|
||||||
|
|
||||||
let event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
|
||||||
.with_title("An iconic window!")
|
|
||||||
// At present, this only does anything on Windows and X11, so if you want to save load
|
|
||||||
// time, you can put icon loading behind a function that returns `None` on other platforms.
|
|
||||||
.with_window_icon(Some(icon))
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
|
|
||||||
if let Event::WindowEvent { event, .. } = event {
|
|
||||||
use winit::event::WindowEvent::*;
|
|
||||||
match event {
|
|
||||||
CloseRequested => *control_flow = ControlFlow::Exit,
|
|
||||||
DroppedFile(path) => {
|
|
||||||
window.set_window_icon(Some(load_icon(&path)));
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_icon(path: &Path) -> Icon {
|
|
||||||
let (icon_rgba, icon_width, icon_height) = {
|
|
||||||
let image = image::open(path)
|
|
||||||
.expect("Failed to open icon path")
|
|
||||||
.into_rgba();
|
|
||||||
let (width, height) = image.dimensions();
|
|
||||||
let rgba = image.into_raw();
|
|
||||||
(rgba, width, height)
|
|
||||||
};
|
|
||||||
Icon::from_rgba(icon_rgba, icon_width, icon_height).expect("Failed to open icon")
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
// Limit this example to only compatible platforms.
|
|
||||||
#[cfg(any(
|
|
||||||
target_os = "windows",
|
|
||||||
target_os = "macos",
|
|
||||||
target_os = "linux",
|
|
||||||
target_os = "dragonfly",
|
|
||||||
target_os = "freebsd",
|
|
||||||
target_os = "netbsd",
|
|
||||||
target_os = "openbsd"
|
|
||||||
))]
|
|
||||||
fn main() {
|
|
||||||
use std::{thread::sleep, time::Duration};
|
|
||||||
use winit::{
|
|
||||||
event::{Event, WindowEvent},
|
|
||||||
event_loop::{ControlFlow, EventLoop},
|
|
||||||
platform::desktop::EventLoopExtDesktop,
|
|
||||||
window::WindowBuilder,
|
|
||||||
};
|
|
||||||
let mut event_loop = EventLoop::new();
|
|
||||||
|
|
||||||
simple_logger::init().unwrap();
|
|
||||||
let _window = WindowBuilder::new()
|
|
||||||
.with_title("A fantastic window!")
|
|
||||||
.build(&event_loop)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut quit = false;
|
|
||||||
|
|
||||||
while !quit {
|
|
||||||
event_loop.run_return(|event, _, control_flow| {
|
|
||||||
*control_flow = ControlFlow::Wait;
|
|
||||||
|
|
||||||
if let Event::WindowEvent { event, .. } = &event {
|
|
||||||
// Print only Window events to reduce noise
|
|
||||||
println!("{:?}", event);
|
|
||||||
}
|
|
||||||
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::CloseRequested,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
quit = true;
|
|
||||||
}
|
|
||||||
Event::MainEventsCleared => {
|
|
||||||
*control_flow = ControlFlow::Exit;
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Sleep for 1/60 second to simulate rendering
|
|
||||||
println!("rendering");
|
|
||||||
sleep(Duration::from_millis(16));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(target_os = "ios", target_os = "android", target_arch = "wasm32"))]
|
|
||||||
fn main() {
|
|
||||||
println!("This platform doesn't support run_return.");
|
|
||||||
}
|
|
||||||
23
rustfmt.toml
23
rustfmt.toml
@@ -1,3 +1,20 @@
|
|||||||
force_explicit_abi=true
|
comment_width = 100
|
||||||
use_field_init_shorthand=true
|
condense_wildcard_suffixes = true
|
||||||
# merge_imports=true
|
error_on_unformatted = true
|
||||||
|
format_code_in_doc_comments = true
|
||||||
|
format_macro_bodies = true
|
||||||
|
format_macro_matchers = true
|
||||||
|
format_strings = true
|
||||||
|
group_imports = "StdExternalCrate"
|
||||||
|
hex_literal_case = "Lower"
|
||||||
|
imports_granularity = "Module"
|
||||||
|
match_block_trailing_comma = true
|
||||||
|
newline_style = "Unix"
|
||||||
|
normalize_comments = true
|
||||||
|
normalize_doc_attributes = true
|
||||||
|
overflow_delimited_expr = true
|
||||||
|
# Some macros break with this.
|
||||||
|
reorder_impl_items = false
|
||||||
|
use_field_init_shorthand = true
|
||||||
|
use_small_heuristics = "Max"
|
||||||
|
wrap_comments = true
|
||||||
|
|||||||
501
src/dpi.rs
501
src/dpi.rs
@@ -1,501 +0,0 @@
|
|||||||
//! UI scaling is important, so read the docs for this module if you don't want to be confused.
|
|
||||||
//!
|
|
||||||
//! ## Why should I care about UI scaling?
|
|
||||||
//!
|
|
||||||
//! Modern computer screens don't have a consistent relationship between resolution and size.
|
|
||||||
//! 1920x1080 is a common resolution for both desktop and mobile screens, despite mobile screens
|
|
||||||
//! normally being less than a quarter the size of their desktop counterparts. What's more, neither
|
|
||||||
//! desktop nor mobile screens are consistent resolutions within their own size classes - common
|
|
||||||
//! mobile screens range from below 720p to above 1440p, and desktop screens range from 720p to 5K
|
|
||||||
//! and beyond.
|
|
||||||
//!
|
|
||||||
//! Given that, it's a mistake to assume that 2D content will only be displayed on screens with
|
|
||||||
//! a consistent pixel density. If you were to render a 96-pixel-square image on a 1080p screen,
|
|
||||||
//! then render the same image on a similarly-sized 4K screen, the 4K rendition would only take up
|
|
||||||
//! about a quarter of the physical space as it did on the 1080p screen. That issue is especially
|
|
||||||
//! problematic with text rendering, where quarter-sized text becomes a significant legibility
|
|
||||||
//! problem.
|
|
||||||
//!
|
|
||||||
//! Failure to account for the scale factor can create a significantly degraded user experience.
|
|
||||||
//! Most notably, it can make users feel like they have bad eyesight, which will potentially cause
|
|
||||||
//! them to think about growing elderly, resulting in them having an existential crisis. Once users
|
|
||||||
//! enter that state, they will no longer be focused on your application.
|
|
||||||
//!
|
|
||||||
//! ## How should I handle it?
|
|
||||||
//!
|
|
||||||
//! The solution to this problem is to account for the device's *scale factor*. The scale factor is
|
|
||||||
//! the factor UI elements should be scaled by to be consistent with the rest of the user's system -
|
|
||||||
//! for example, a button that's normally 50 pixels across would be 100 pixels across on a device
|
|
||||||
//! with a scale factor of `2.0`, or 75 pixels across with a scale factor of `1.5`.
|
|
||||||
//!
|
|
||||||
//! Many UI systems, such as CSS, expose DPI-dependent units like [points] or [picas]. That's
|
|
||||||
//! usually a mistake, since there's no consistent mapping between the scale factor and the screen's
|
|
||||||
//! actual DPI. Unless you're printing to a physical medium, you should work in scaled pixels rather
|
|
||||||
//! than any DPI-dependent units.
|
|
||||||
//!
|
|
||||||
//! ### Position and Size types
|
|
||||||
//!
|
|
||||||
//! Winit's `Physical(Position|Size)` types correspond with the actual pixels on the device, and the
|
|
||||||
//! `Logical(Position|Size)` types correspond to the physical pixels divided by the scale factor.
|
|
||||||
//! All of Winit's functions return physical types, but can take either logical or physical
|
|
||||||
//! coordinates as input, allowing you to use the most convenient coordinate system for your
|
|
||||||
//! particular application.
|
|
||||||
//!
|
|
||||||
//! Winit's position and size types types are generic over their exact pixel type, `P`, to allow the
|
|
||||||
//! API to have integer precision where appropriate (e.g. most window manipulation functions) and
|
|
||||||
//! floating precision when necessary (e.g. logical sizes for fractional scale factors and touch
|
|
||||||
//! input). If `P` is a floating-point type, please do not cast the values with `as {int}`. Doing so
|
|
||||||
//! will truncate the fractional part of the float, rather than properly round to the nearest
|
|
||||||
//! integer. Use the provided `cast` function or `From`/`Into` conversions, which handle the
|
|
||||||
//! rounding properly. Note that precision loss will still occur when rounding from a float to an
|
|
||||||
//! int, although rounding lessens the problem.
|
|
||||||
//!
|
|
||||||
//! ### Events
|
|
||||||
//!
|
|
||||||
//! Winit will dispatch a [`ScaleFactorChanged`](crate::event::WindowEvent::ScaleFactorChanged)
|
|
||||||
//! event whenever a window's scale factor has changed. This can happen if the user drags their
|
|
||||||
//! window from a standard-resolution monitor to a high-DPI monitor, or if the user changes their
|
|
||||||
//! DPI settings. This gives you a chance to rescale your application's UI elements and adjust how
|
|
||||||
//! the platform changes the window's size to reflect the new scale factor. If a window hasn't
|
|
||||||
//! received a [`ScaleFactorChanged`](crate::event::WindowEvent::ScaleFactorChanged) event,
|
|
||||||
//! then its scale factor is `1.0`.
|
|
||||||
//!
|
|
||||||
//! ## How is the scale factor calculated?
|
|
||||||
//!
|
|
||||||
//! Scale factor is calculated differently on different platforms:
|
|
||||||
//!
|
|
||||||
//! - **Windows:** On Windows 8 and 10, per-monitor scaling is readily configured by users from the
|
|
||||||
//! display settings. While users are free to select any option they want, they're only given a
|
|
||||||
//! selection of "nice" scale factors, i.e. 1.0, 1.25, 1.5... on Windows 7, the scale factor is
|
|
||||||
//! global and changing it requires logging out. See [this article][windows_1] for technical
|
|
||||||
//! details.
|
|
||||||
//! - **macOS:** "retina displays" have a scale factor of 2.0. Otherwise, the scale factor is 1.0.
|
|
||||||
//! Intermediate scale factors are never used. It's possible for any display to use that 2.0 scale
|
|
||||||
//! factor, given the use of the command line.
|
|
||||||
//! - **X11:** Many man-hours have been spent trying to figure out how to handle DPI in X11. Winit
|
|
||||||
//! currently uses a three-pronged approach:
|
|
||||||
//! + Use the value in the `WINIT_X11_SCALE_FACTOR` environment variable, if present.
|
|
||||||
//! + If not present, use the value set in `Xft.dpi` in Xresources.
|
|
||||||
//! + Otherwise, calcuate the scale factor based on the millimeter monitor dimensions provided by XRandR.
|
|
||||||
//!
|
|
||||||
//! If `WINIT_X11_SCALE_FACTOR` is set to `randr`, it'll ignore the `Xft.dpi` field and use the
|
|
||||||
//! XRandR scaling method. Generally speaking, you should try to configure the standard system
|
|
||||||
//! variables to do what you want before resorting to `WINIT_X11_SCALE_FACTOR`.
|
|
||||||
//! - **Wayland:** On Wayland, scale factors are set per-screen by the server, and are always
|
|
||||||
//! integers (most often 1 or 2).
|
|
||||||
//! - **iOS:** Scale factors are set by Apple to the value that best suits the device, and range
|
|
||||||
//! from `1.0` to `3.0`. See [this article][apple_1] and [this article][apple_2] for more
|
|
||||||
//! information.
|
|
||||||
//! - **Android:** Scale factors are set by the manufacturer to the value that best suits the
|
|
||||||
//! device, and range from `1.0` to `4.0`. See [this article][android_1] for more information.
|
|
||||||
//! - **Web:** The scale factor is the ratio between CSS pixels and the physical device pixels.
|
|
||||||
//!
|
|
||||||
//! [points]: https://en.wikipedia.org/wiki/Point_(typography)
|
|
||||||
//! [picas]: https://en.wikipedia.org/wiki/Pica_(typography)
|
|
||||||
//! [windows_1]: https://docs.microsoft.com/en-us/windows/win32/hidpi/high-dpi-desktop-application-development-on-windows
|
|
||||||
//! [apple_1]: https://developer.apple.com/library/archive/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Displays/Displays.html
|
|
||||||
//! [apple_2]: https://developer.apple.com/design/human-interface-guidelines/macos/icons-and-images/image-size-and-resolution/
|
|
||||||
//! [android_1]: https://developer.android.com/training/multiscreen/screendensities
|
|
||||||
|
|
||||||
pub trait Pixel: Copy + Into<f64> {
|
|
||||||
fn from_f64(f: f64) -> Self;
|
|
||||||
fn cast<P: Pixel>(self) -> P {
|
|
||||||
P::from_f64(self.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Pixel for u8 {
|
|
||||||
fn from_f64(f: f64) -> Self {
|
|
||||||
f.round() as u8
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Pixel for u16 {
|
|
||||||
fn from_f64(f: f64) -> Self {
|
|
||||||
f.round() as u16
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Pixel for u32 {
|
|
||||||
fn from_f64(f: f64) -> Self {
|
|
||||||
f.round() as u32
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Pixel for i8 {
|
|
||||||
fn from_f64(f: f64) -> Self {
|
|
||||||
f.round() as i8
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Pixel for i16 {
|
|
||||||
fn from_f64(f: f64) -> Self {
|
|
||||||
f.round() as i16
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Pixel for i32 {
|
|
||||||
fn from_f64(f: f64) -> Self {
|
|
||||||
f.round() as i32
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Pixel for f32 {
|
|
||||||
fn from_f64(f: f64) -> Self {
|
|
||||||
f as f32
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Pixel for f64 {
|
|
||||||
fn from_f64(f: f64) -> Self {
|
|
||||||
f
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks that the scale factor is a normal positive `f64`.
|
|
||||||
///
|
|
||||||
/// All functions that take a scale factor assert that this will return `true`. If you're sourcing scale factors from
|
|
||||||
/// anywhere other than winit, it's recommended to validate them using this function before passing them to winit;
|
|
||||||
/// otherwise, you risk panics.
|
|
||||||
#[inline]
|
|
||||||
pub fn validate_scale_factor(scale_factor: f64) -> bool {
|
|
||||||
scale_factor.is_sign_positive() && scale_factor.is_normal()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A position represented in logical pixels.
|
|
||||||
///
|
|
||||||
/// The position is stored as floats, so please be careful. Casting floats to integers truncates the
|
|
||||||
/// fractional part, which can cause noticable issues. To help with that, an `Into<(i32, i32)>`
|
|
||||||
/// implementation is provided which does the rounding for you.
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
||||||
pub struct LogicalPosition<P> {
|
|
||||||
pub x: P,
|
|
||||||
pub y: P,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> LogicalPosition<P> {
|
|
||||||
#[inline]
|
|
||||||
pub const fn new(x: P, y: P) -> Self {
|
|
||||||
LogicalPosition { x, y }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel> LogicalPosition<P> {
|
|
||||||
#[inline]
|
|
||||||
pub fn from_physical<T: Into<PhysicalPosition<X>>, X: Pixel>(
|
|
||||||
physical: T,
|
|
||||||
scale_factor: f64,
|
|
||||||
) -> Self {
|
|
||||||
physical.into().to_logical(scale_factor)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn to_physical<X: Pixel>(&self, scale_factor: f64) -> PhysicalPosition<X> {
|
|
||||||
assert!(validate_scale_factor(scale_factor));
|
|
||||||
let x = self.x.into() * scale_factor;
|
|
||||||
let y = self.y.into() * scale_factor;
|
|
||||||
PhysicalPosition::new(x, y).cast()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn cast<X: Pixel>(&self) -> LogicalPosition<X> {
|
|
||||||
LogicalPosition {
|
|
||||||
x: self.x.cast(),
|
|
||||||
y: self.y.cast(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> From<(X, X)> for LogicalPosition<P> {
|
|
||||||
fn from((x, y): (X, X)) -> LogicalPosition<P> {
|
|
||||||
LogicalPosition::new(x.cast(), y.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> Into<(X, X)> for LogicalPosition<P> {
|
|
||||||
fn into(self: Self) -> (X, X) {
|
|
||||||
(self.x.cast(), self.y.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> From<[X; 2]> for LogicalPosition<P> {
|
|
||||||
fn from([x, y]: [X; 2]) -> LogicalPosition<P> {
|
|
||||||
LogicalPosition::new(x.cast(), y.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> Into<[X; 2]> for LogicalPosition<P> {
|
|
||||||
fn into(self: Self) -> [X; 2] {
|
|
||||||
[self.x.cast(), self.y.cast()]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A position represented in physical pixels.
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
||||||
pub struct PhysicalPosition<P> {
|
|
||||||
pub x: P,
|
|
||||||
pub y: P,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> PhysicalPosition<P> {
|
|
||||||
#[inline]
|
|
||||||
pub const fn new(x: P, y: P) -> Self {
|
|
||||||
PhysicalPosition { x, y }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel> PhysicalPosition<P> {
|
|
||||||
#[inline]
|
|
||||||
pub fn from_logical<T: Into<LogicalPosition<X>>, X: Pixel>(
|
|
||||||
logical: T,
|
|
||||||
scale_factor: f64,
|
|
||||||
) -> Self {
|
|
||||||
logical.into().to_physical(scale_factor)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn to_logical<X: Pixel>(&self, scale_factor: f64) -> LogicalPosition<X> {
|
|
||||||
assert!(validate_scale_factor(scale_factor));
|
|
||||||
let x = self.x.into() / scale_factor;
|
|
||||||
let y = self.y.into() / scale_factor;
|
|
||||||
LogicalPosition::new(x, y).cast()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn cast<X: Pixel>(&self) -> PhysicalPosition<X> {
|
|
||||||
PhysicalPosition {
|
|
||||||
x: self.x.cast(),
|
|
||||||
y: self.y.cast(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> From<(X, X)> for PhysicalPosition<P> {
|
|
||||||
fn from((x, y): (X, X)) -> PhysicalPosition<P> {
|
|
||||||
PhysicalPosition::new(x.cast(), y.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> Into<(X, X)> for PhysicalPosition<P> {
|
|
||||||
fn into(self: Self) -> (X, X) {
|
|
||||||
(self.x.cast(), self.y.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> From<[X; 2]> for PhysicalPosition<P> {
|
|
||||||
fn from([x, y]: [X; 2]) -> PhysicalPosition<P> {
|
|
||||||
PhysicalPosition::new(x.cast(), y.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> Into<[X; 2]> for PhysicalPosition<P> {
|
|
||||||
fn into(self: Self) -> [X; 2] {
|
|
||||||
[self.x.cast(), self.y.cast()]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A size represented in logical pixels.
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
||||||
pub struct LogicalSize<P> {
|
|
||||||
pub width: P,
|
|
||||||
pub height: P,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> LogicalSize<P> {
|
|
||||||
#[inline]
|
|
||||||
pub const fn new(width: P, height: P) -> Self {
|
|
||||||
LogicalSize { width, height }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel> LogicalSize<P> {
|
|
||||||
#[inline]
|
|
||||||
pub fn from_physical<T: Into<PhysicalSize<X>>, X: Pixel>(
|
|
||||||
physical: T,
|
|
||||||
scale_factor: f64,
|
|
||||||
) -> Self {
|
|
||||||
physical.into().to_logical(scale_factor)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn to_physical<X: Pixel>(&self, scale_factor: f64) -> PhysicalSize<X> {
|
|
||||||
assert!(validate_scale_factor(scale_factor));
|
|
||||||
let width = self.width.into() * scale_factor;
|
|
||||||
let height = self.height.into() * scale_factor;
|
|
||||||
PhysicalSize::new(width, height).cast()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn cast<X: Pixel>(&self) -> LogicalSize<X> {
|
|
||||||
LogicalSize {
|
|
||||||
width: self.width.cast(),
|
|
||||||
height: self.height.cast(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> From<(X, X)> for LogicalSize<P> {
|
|
||||||
fn from((x, y): (X, X)) -> LogicalSize<P> {
|
|
||||||
LogicalSize::new(x.cast(), y.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> Into<(X, X)> for LogicalSize<P> {
|
|
||||||
fn into(self: LogicalSize<P>) -> (X, X) {
|
|
||||||
(self.width.cast(), self.height.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> From<[X; 2]> for LogicalSize<P> {
|
|
||||||
fn from([x, y]: [X; 2]) -> LogicalSize<P> {
|
|
||||||
LogicalSize::new(x.cast(), y.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> Into<[X; 2]> for LogicalSize<P> {
|
|
||||||
fn into(self: Self) -> [X; 2] {
|
|
||||||
[self.width.cast(), self.height.cast()]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A size represented in physical pixels.
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
||||||
pub struct PhysicalSize<P> {
|
|
||||||
pub width: P,
|
|
||||||
pub height: P,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P> PhysicalSize<P> {
|
|
||||||
#[inline]
|
|
||||||
pub const fn new(width: P, height: P) -> Self {
|
|
||||||
PhysicalSize { width, height }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel> PhysicalSize<P> {
|
|
||||||
#[inline]
|
|
||||||
pub fn from_logical<T: Into<LogicalSize<X>>, X: Pixel>(logical: T, scale_factor: f64) -> Self {
|
|
||||||
logical.into().to_physical(scale_factor)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn to_logical<X: Pixel>(&self, scale_factor: f64) -> LogicalSize<X> {
|
|
||||||
assert!(validate_scale_factor(scale_factor));
|
|
||||||
let width = self.width.into() / scale_factor;
|
|
||||||
let height = self.height.into() / scale_factor;
|
|
||||||
LogicalSize::new(width, height).cast()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn cast<X: Pixel>(&self) -> PhysicalSize<X> {
|
|
||||||
PhysicalSize {
|
|
||||||
width: self.width.cast(),
|
|
||||||
height: self.height.cast(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> From<(X, X)> for PhysicalSize<P> {
|
|
||||||
fn from((x, y): (X, X)) -> PhysicalSize<P> {
|
|
||||||
PhysicalSize::new(x.cast(), y.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> Into<(X, X)> for PhysicalSize<P> {
|
|
||||||
fn into(self: Self) -> (X, X) {
|
|
||||||
(self.width.cast(), self.height.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> From<[X; 2]> for PhysicalSize<P> {
|
|
||||||
fn from([x, y]: [X; 2]) -> PhysicalSize<P> {
|
|
||||||
PhysicalSize::new(x.cast(), y.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel, X: Pixel> Into<[X; 2]> for PhysicalSize<P> {
|
|
||||||
fn into(self: Self) -> [X; 2] {
|
|
||||||
[self.width.cast(), self.height.cast()]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A size that's either physical or logical.
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
||||||
pub enum Size {
|
|
||||||
Physical(PhysicalSize<u32>),
|
|
||||||
Logical(LogicalSize<f64>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Size {
|
|
||||||
pub fn new<S: Into<Size>>(size: S) -> Size {
|
|
||||||
size.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_logical<P: Pixel>(&self, scale_factor: f64) -> LogicalSize<P> {
|
|
||||||
match *self {
|
|
||||||
Size::Physical(size) => size.to_logical(scale_factor),
|
|
||||||
Size::Logical(size) => size.cast(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_physical<P: Pixel>(&self, scale_factor: f64) -> PhysicalSize<P> {
|
|
||||||
match *self {
|
|
||||||
Size::Physical(size) => size.cast(),
|
|
||||||
Size::Logical(size) => size.to_physical(scale_factor),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel> From<PhysicalSize<P>> for Size {
|
|
||||||
#[inline]
|
|
||||||
fn from(size: PhysicalSize<P>) -> Size {
|
|
||||||
Size::Physical(size.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel> From<LogicalSize<P>> for Size {
|
|
||||||
#[inline]
|
|
||||||
fn from(size: LogicalSize<P>) -> Size {
|
|
||||||
Size::Logical(size.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A position that's either physical or logical.
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
||||||
pub enum Position {
|
|
||||||
Physical(PhysicalPosition<i32>),
|
|
||||||
Logical(LogicalPosition<f64>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Position {
|
|
||||||
pub fn new<S: Into<Position>>(position: S) -> Position {
|
|
||||||
position.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_logical<P: Pixel>(&self, scale_factor: f64) -> LogicalPosition<P> {
|
|
||||||
match *self {
|
|
||||||
Position::Physical(position) => position.to_logical(scale_factor),
|
|
||||||
Position::Logical(position) => position.cast(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_physical<P: Pixel>(&self, scale_factor: f64) -> PhysicalPosition<P> {
|
|
||||||
match *self {
|
|
||||||
Position::Physical(position) => position.cast(),
|
|
||||||
Position::Logical(position) => position.to_physical(scale_factor),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel> From<PhysicalPosition<P>> for Position {
|
|
||||||
#[inline]
|
|
||||||
fn from(position: PhysicalPosition<P>) -> Position {
|
|
||||||
Position::Physical(position.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<P: Pixel> From<LogicalPosition<P>> for Position {
|
|
||||||
#[inline]
|
|
||||||
fn from(position: LogicalPosition<P>) -> Position {
|
|
||||||
Position::Logical(position.cast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
82
src/error.rs
82
src/error.rs
@@ -1,82 +0,0 @@
|
|||||||
use std::{error, fmt};
|
|
||||||
|
|
||||||
use crate::platform_impl;
|
|
||||||
|
|
||||||
/// An error whose cause it outside Winit's control.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum ExternalError {
|
|
||||||
/// The operation is not supported by the backend.
|
|
||||||
NotSupported(NotSupportedError),
|
|
||||||
/// The OS cannot perform the operation.
|
|
||||||
Os(OsError),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The error type for when the requested operation is not supported by the backend.
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct NotSupportedError {
|
|
||||||
_marker: (),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The error type for when the OS cannot perform the requested operation.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct OsError {
|
|
||||||
line: u32,
|
|
||||||
file: &'static str,
|
|
||||||
error: platform_impl::OsError,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NotSupportedError {
|
|
||||||
#[inline]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn new() -> NotSupportedError {
|
|
||||||
NotSupportedError { _marker: () }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl OsError {
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn new(line: u32, file: &'static str, error: platform_impl::OsError) -> OsError {
|
|
||||||
OsError { line, file, error }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
|
||||||
macro_rules! os_error {
|
|
||||||
($error:expr) => {{
|
|
||||||
crate::error::OsError::new(line!(), file!(), $error)
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for OsError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
|
||||||
f.pad(&format!(
|
|
||||||
"os error at {}:{}: {}",
|
|
||||||
self.file, self.line, self.error
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for ExternalError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
|
||||||
match self {
|
|
||||||
ExternalError::NotSupported(e) => e.fmt(f),
|
|
||||||
ExternalError::Os(e) => e.fmt(f),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for NotSupportedError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
|
||||||
f.debug_struct("NotSupportedError").finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for NotSupportedError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
|
||||||
f.pad("the requested operation is not supported by Winit")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl error::Error for OsError {}
|
|
||||||
impl error::Error for ExternalError {}
|
|
||||||
impl error::Error for NotSupportedError {}
|
|
||||||
1066
src/event.rs
1066
src/event.rs
File diff suppressed because it is too large
Load Diff
@@ -1,225 +0,0 @@
|
|||||||
//! The `EventLoop` struct and assorted supporting types, including `ControlFlow`.
|
|
||||||
//!
|
|
||||||
//! If you want to send custom events to the event loop, use [`EventLoop::create_proxy()`][create_proxy]
|
|
||||||
//! to acquire an [`EventLoopProxy`][event_loop_proxy] and call its [`send_event`][send_event] method.
|
|
||||||
//!
|
|
||||||
//! See the root-level documentation for information on how to create and use an event loop to
|
|
||||||
//! handle events.
|
|
||||||
//!
|
|
||||||
//! [create_proxy]: crate::event_loop::EventLoop::create_proxy
|
|
||||||
//! [event_loop_proxy]: crate::event_loop::EventLoopProxy
|
|
||||||
//! [send_event]: crate::event_loop::EventLoopProxy::send_event
|
|
||||||
use instant::Instant;
|
|
||||||
use std::ops::Deref;
|
|
||||||
use std::{error, fmt};
|
|
||||||
|
|
||||||
use crate::{event::Event, monitor::MonitorHandle, platform_impl};
|
|
||||||
|
|
||||||
/// Provides a way to retrieve events from the system and from the windows that were registered to
|
|
||||||
/// the events loop.
|
|
||||||
///
|
|
||||||
/// An `EventLoop` can be seen more or less as a "context". Calling `EventLoop::new()`
|
|
||||||
/// initializes everything that will be required to create windows. For example on Linux creating
|
|
||||||
/// an event loop opens a connection to the X or Wayland server.
|
|
||||||
///
|
|
||||||
/// To wake up an `EventLoop` from a another thread, see the `EventLoopProxy` docs.
|
|
||||||
///
|
|
||||||
/// Note that the `EventLoop` cannot be shared across threads (due to platform-dependant logic
|
|
||||||
/// forbidding it), as such it is neither `Send` nor `Sync`. If you need cross-thread access, the
|
|
||||||
/// `Window` created from this `EventLoop` _can_ be sent to an other thread, and the
|
|
||||||
/// `EventLoopProxy` allows you to wake up an `EventLoop` from another thread.
|
|
||||||
///
|
|
||||||
pub struct EventLoop<T: 'static> {
|
|
||||||
pub(crate) event_loop: platform_impl::EventLoop<T>,
|
|
||||||
pub(crate) _marker: ::std::marker::PhantomData<*mut ()>, // Not Send nor Sync
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Target that associates windows with an `EventLoop`.
|
|
||||||
///
|
|
||||||
/// This type exists to allow you to create new windows while Winit executes
|
|
||||||
/// your callback. `EventLoop` will coerce into this type (`impl<T> Deref for
|
|
||||||
/// EventLoop<T>`), so functions that take this as a parameter can also take
|
|
||||||
/// `&EventLoop`.
|
|
||||||
pub struct EventLoopWindowTarget<T: 'static> {
|
|
||||||
pub(crate) p: platform_impl::EventLoopWindowTarget<T>,
|
|
||||||
pub(crate) _marker: ::std::marker::PhantomData<*mut ()>, // Not Send nor Sync
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> fmt::Debug for EventLoop<T> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.pad("EventLoop { .. }")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> fmt::Debug for EventLoopWindowTarget<T> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.pad("EventLoopWindowTarget { .. }")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set by the user callback given to the `EventLoop::run` method.
|
|
||||||
///
|
|
||||||
/// Indicates the desired behavior of the event loop after [`Event::RedrawEventsCleared`][events_cleared]
|
|
||||||
/// is emitted. Defaults to `Poll`.
|
|
||||||
///
|
|
||||||
/// ## Persistency
|
|
||||||
/// Almost every change is persistent between multiple calls to the event loop closure within a
|
|
||||||
/// given run loop. The only exception to this is `Exit` which, once set, cannot be unset. Changes
|
|
||||||
/// are **not** persistent between multiple calls to `run_return` - issuing a new call will reset
|
|
||||||
/// the control flow to `Poll`.
|
|
||||||
///
|
|
||||||
/// [events_cleared]: crate::event::Event::RedrawEventsCleared
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub enum ControlFlow {
|
|
||||||
/// When the current loop iteration finishes, immediately begin a new iteration regardless of
|
|
||||||
/// whether or not new events are available to process. For web, events are sent when
|
|
||||||
/// `requestAnimationFrame` fires.
|
|
||||||
Poll,
|
|
||||||
/// When the current loop iteration finishes, suspend the thread until another event arrives.
|
|
||||||
Wait,
|
|
||||||
/// When the current loop iteration finishes, suspend the thread until either another event
|
|
||||||
/// arrives or the given time is reached.
|
|
||||||
WaitUntil(Instant),
|
|
||||||
/// Send a `LoopDestroyed` event and stop the event loop. This variant is *sticky* - once set,
|
|
||||||
/// `control_flow` cannot be changed from `Exit`, and any future attempts to do so will result
|
|
||||||
/// in the `control_flow` parameter being reset to `Exit`.
|
|
||||||
Exit,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for ControlFlow {
|
|
||||||
#[inline(always)]
|
|
||||||
fn default() -> ControlFlow {
|
|
||||||
ControlFlow::Poll
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EventLoop<()> {
|
|
||||||
/// Builds a new event loop with a `()` as the user event type.
|
|
||||||
///
|
|
||||||
/// ***For cross-platform compatibility, the `EventLoop` must be created on the main thread.***
|
|
||||||
/// Attempting to create the event loop on a different thread will panic. This restriction isn't
|
|
||||||
/// strictly necessary on all platforms, but is imposed to eliminate any nasty surprises when
|
|
||||||
/// porting to platforms that require it. `EventLoopExt::new_any_thread` functions are exposed
|
|
||||||
/// in the relevant `platform` module if the target platform supports creating an event loop on
|
|
||||||
/// any thread.
|
|
||||||
///
|
|
||||||
/// Usage will result in display backend initialisation, this can be controlled on linux
|
|
||||||
/// using an environment variable `WINIT_UNIX_BACKEND`. Legal values are `x11` and `wayland`.
|
|
||||||
/// If it is not set, winit will try to connect to a wayland connection, and if it fails will
|
|
||||||
/// fallback on x11. If this variable is set with any other value, winit will panic.
|
|
||||||
///
|
|
||||||
/// ## Platform-specific
|
|
||||||
///
|
|
||||||
/// - **iOS:** Can only be called on the main thread.
|
|
||||||
pub fn new() -> EventLoop<()> {
|
|
||||||
EventLoop::<()>::with_user_event()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> EventLoop<T> {
|
|
||||||
/// Builds a new event loop.
|
|
||||||
///
|
|
||||||
/// All caveats documented in [`EventLoop::new`] apply to this function.
|
|
||||||
///
|
|
||||||
/// ## Platform-specific
|
|
||||||
///
|
|
||||||
/// - **iOS:** Can only be called on the main thread.
|
|
||||||
pub fn with_user_event() -> EventLoop<T> {
|
|
||||||
EventLoop {
|
|
||||||
event_loop: platform_impl::EventLoop::new(),
|
|
||||||
_marker: ::std::marker::PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Hijacks the calling thread and initializes the winit event loop with the provided
|
|
||||||
/// closure. Since the closure is `'static`, it must be a `move` closure if it needs to
|
|
||||||
/// access any data from the calling context.
|
|
||||||
///
|
|
||||||
/// See the [`ControlFlow`] docs for information on how changes to `&mut ControlFlow` impact the
|
|
||||||
/// event loop's behavior.
|
|
||||||
///
|
|
||||||
/// Any values not passed to this function will *not* be dropped.
|
|
||||||
///
|
|
||||||
/// [`ControlFlow`]: crate::event_loop::ControlFlow
|
|
||||||
#[inline]
|
|
||||||
pub fn run<F>(self, event_handler: F) -> !
|
|
||||||
where
|
|
||||||
F: 'static + FnMut(Event<'_, T>, &EventLoopWindowTarget<T>, &mut ControlFlow),
|
|
||||||
{
|
|
||||||
self.event_loop.run(event_handler)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates an `EventLoopProxy` that can be used to dispatch user events to the main event loop.
|
|
||||||
pub fn create_proxy(&self) -> EventLoopProxy<T> {
|
|
||||||
EventLoopProxy {
|
|
||||||
event_loop_proxy: self.event_loop.create_proxy(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the list of all the monitors available on the system.
|
|
||||||
#[inline]
|
|
||||||
pub fn available_monitors(&self) -> impl Iterator<Item = MonitorHandle> {
|
|
||||||
self.event_loop
|
|
||||||
.available_monitors()
|
|
||||||
.into_iter()
|
|
||||||
.map(|inner| MonitorHandle { inner })
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the primary monitor of the system.
|
|
||||||
#[inline]
|
|
||||||
pub fn primary_monitor(&self) -> MonitorHandle {
|
|
||||||
MonitorHandle {
|
|
||||||
inner: self.event_loop.primary_monitor(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Deref for EventLoop<T> {
|
|
||||||
type Target = EventLoopWindowTarget<T>;
|
|
||||||
fn deref(&self) -> &EventLoopWindowTarget<T> {
|
|
||||||
self.event_loop.window_target()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Used to send custom events to `EventLoop`.
|
|
||||||
pub struct EventLoopProxy<T: 'static> {
|
|
||||||
event_loop_proxy: platform_impl::EventLoopProxy<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: 'static> Clone for EventLoopProxy<T> {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
Self {
|
|
||||||
event_loop_proxy: self.event_loop_proxy.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: 'static> EventLoopProxy<T> {
|
|
||||||
/// Send an event to the `EventLoop` from which this proxy was created. This emits a
|
|
||||||
/// `UserEvent(event)` event in the event loop, where `event` is the value passed to this
|
|
||||||
/// function.
|
|
||||||
///
|
|
||||||
/// Returns an `Err` if the associated `EventLoop` no longer exists.
|
|
||||||
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
|
|
||||||
self.event_loop_proxy.send_event(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: 'static> fmt::Debug for EventLoopProxy<T> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.pad("EventLoopProxy { .. }")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The error that is returned when an `EventLoopProxy` attempts to wake up an `EventLoop` that
|
|
||||||
/// no longer exists. Contains the original event given to `send_event`.
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub struct EventLoopClosed<T>(pub T);
|
|
||||||
|
|
||||||
impl<T> fmt::Display for EventLoopClosed<T> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.write_str("Tried to wake up a closed `EventLoop`")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: fmt::Debug> error::Error for EventLoopClosed<T> {}
|
|
||||||
135
src/icon.rs
135
src/icon.rs
@@ -1,135 +0,0 @@
|
|||||||
use crate::platform_impl::PlatformIcon;
|
|
||||||
use std::{error::Error, fmt, io, mem};
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub(crate) struct Pixel {
|
|
||||||
pub(crate) r: u8,
|
|
||||||
pub(crate) g: u8,
|
|
||||||
pub(crate) b: u8,
|
|
||||||
pub(crate) a: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) const PIXEL_SIZE: usize = mem::size_of::<Pixel>();
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
/// An error produced when using `Icon::from_rgba` with invalid arguments.
|
|
||||||
pub enum BadIcon {
|
|
||||||
/// Produced when the length of the `rgba` argument isn't divisible by 4, thus `rgba` can't be
|
|
||||||
/// safely interpreted as 32bpp RGBA pixels.
|
|
||||||
ByteCountNotDivisibleBy4 { byte_count: usize },
|
|
||||||
/// Produced when the number of pixels (`rgba.len() / 4`) isn't equal to `width * height`.
|
|
||||||
/// At least one of your arguments is incorrect.
|
|
||||||
DimensionsVsPixelCount {
|
|
||||||
width: u32,
|
|
||||||
height: u32,
|
|
||||||
width_x_height: usize,
|
|
||||||
pixel_count: usize,
|
|
||||||
},
|
|
||||||
/// Produced when underlying OS functionality failed to create the icon
|
|
||||||
OsError(io::Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for BadIcon {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
BadIcon::ByteCountNotDivisibleBy4 { byte_count } => write!(f,
|
|
||||||
"The length of the `rgba` argument ({:?}) isn't divisible by 4, making it impossible to interpret as 32bpp RGBA pixels.",
|
|
||||||
byte_count,
|
|
||||||
),
|
|
||||||
BadIcon::DimensionsVsPixelCount {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
width_x_height,
|
|
||||||
pixel_count,
|
|
||||||
} => write!(f,
|
|
||||||
"The specified dimensions ({:?}x{:?}) don't match the number of pixels supplied by the `rgba` argument ({:?}). For those dimensions, the expected pixel count is {:?}.",
|
|
||||||
width, height, pixel_count, width_x_height,
|
|
||||||
),
|
|
||||||
BadIcon::OsError(e) => write!(f, "OS error when instantiating the icon: {:?}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Error for BadIcon {
|
|
||||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
|
||||||
Some(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
pub(crate) struct RgbaIcon {
|
|
||||||
pub(crate) rgba: Vec<u8>,
|
|
||||||
pub(crate) width: u32,
|
|
||||||
pub(crate) height: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// For platforms which don't have window icons (e.g. web)
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
pub(crate) struct NoIcon;
|
|
||||||
|
|
||||||
#[allow(dead_code)] // These are not used on every platform
|
|
||||||
mod constructors {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
impl RgbaIcon {
|
|
||||||
/// Creates an `Icon` from 32bpp RGBA data.
|
|
||||||
///
|
|
||||||
/// The length of `rgba` must be divisible by 4, and `width * height` must equal
|
|
||||||
/// `rgba.len() / 4`. Otherwise, this will return a `BadIcon` error.
|
|
||||||
pub fn from_rgba(rgba: Vec<u8>, width: u32, height: u32) -> Result<Self, BadIcon> {
|
|
||||||
if rgba.len() % PIXEL_SIZE != 0 {
|
|
||||||
return Err(BadIcon::ByteCountNotDivisibleBy4 {
|
|
||||||
byte_count: rgba.len(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
let pixel_count = rgba.len() / PIXEL_SIZE;
|
|
||||||
if pixel_count != (width * height) as usize {
|
|
||||||
Err(BadIcon::DimensionsVsPixelCount {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
width_x_height: (width * height) as usize,
|
|
||||||
pixel_count,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Ok(RgbaIcon {
|
|
||||||
rgba,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NoIcon {
|
|
||||||
pub fn from_rgba(rgba: Vec<u8>, width: u32, height: u32) -> Result<Self, BadIcon> {
|
|
||||||
// Create the rgba icon anyway to validate the input
|
|
||||||
let _ = RgbaIcon::from_rgba(rgba, width, height)?;
|
|
||||||
Ok(NoIcon)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An icon used for the window titlebar, taskbar, etc.
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Icon {
|
|
||||||
pub(crate) inner: PlatformIcon,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for Icon {
|
|
||||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
|
||||||
fmt::Debug::fmt(&self.inner, formatter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Icon {
|
|
||||||
/// Creates an `Icon` from 32bpp RGBA data.
|
|
||||||
///
|
|
||||||
/// The length of `rgba` must be divisible by 4, and `width * height` must equal
|
|
||||||
/// `rgba.len() / 4`. Otherwise, this will return a `BadIcon` error.
|
|
||||||
pub fn from_rgba(rgba: Vec<u8>, width: u32, height: u32) -> Result<Self, BadIcon> {
|
|
||||||
Ok(Icon {
|
|
||||||
inner: PlatformIcon::from_rgba(rgba, width, height)?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
162
src/lib.rs
162
src/lib.rs
@@ -1,162 +0,0 @@
|
|||||||
//! Winit is a cross-platform window creation and event loop management library.
|
|
||||||
//!
|
|
||||||
//! # Building windows
|
|
||||||
//!
|
|
||||||
//! Before you can build a [`Window`], you first need to build an [`EventLoop`]. This is done with the
|
|
||||||
//! [`EventLoop::new()`] function.
|
|
||||||
//!
|
|
||||||
//! ```no_run
|
|
||||||
//! use winit::event_loop::EventLoop;
|
|
||||||
//! let event_loop = EventLoop::new();
|
|
||||||
//! ```
|
|
||||||
//!
|
|
||||||
//! Once this is done there are two ways to create a [`Window`]:
|
|
||||||
//!
|
|
||||||
//! - Calling [`Window::new(&event_loop)`][window_new].
|
|
||||||
//! - Calling [`let builder = WindowBuilder::new()`][window_builder_new] then [`builder.build(&event_loop)`][window_builder_build].
|
|
||||||
//!
|
|
||||||
//! The first method is the simplest, and will give you default values for everything. The second
|
|
||||||
//! method allows you to customize the way your [`Window`] will look and behave by modifying the
|
|
||||||
//! fields of the [`WindowBuilder`] object before you create the [`Window`].
|
|
||||||
//!
|
|
||||||
//! # Event handling
|
|
||||||
//!
|
|
||||||
//! Once a [`Window`] has been created, it will generate different *events*. A [`Window`] object can
|
|
||||||
//! generate [`WindowEvent`]s when certain input events occur, such as a cursor moving over the
|
|
||||||
//! window or a key getting pressed while the window is focused. Devices can generate
|
|
||||||
//! [`DeviceEvent`]s, which contain unfiltered event data that isn't specific to a certain window.
|
|
||||||
//! Some user activity, like mouse movement, can generate both a [`WindowEvent`] *and* a
|
|
||||||
//! [`DeviceEvent`]. You can also create and handle your own custom [`UserEvent`]s, if desired.
|
|
||||||
//!
|
|
||||||
//! You can retreive events by calling [`EventLoop::run`][event_loop_run]. This function will
|
|
||||||
//! dispatch events for every [`Window`] that was created with that particular [`EventLoop`], and
|
|
||||||
//! will run until the `control_flow` argument given to the closure is set to
|
|
||||||
//! [`ControlFlow`]`::`[`Exit`], at which point [`Event`]`::`[`LoopDestroyed`] is emitted and the
|
|
||||||
//! entire program terminates.
|
|
||||||
//!
|
|
||||||
//! Winit no longer uses a `EventLoop::poll_events() -> impl Iterator<Event>`-based event loop
|
|
||||||
//! model, since that can't be implemented properly on web and mobile platforms and works poorly on
|
|
||||||
//! most desktop platforms. However, this model can be re-implemented to an extent on desktops with
|
|
||||||
//! [`EventLoopExtDesktop::run_return`]. See that method's documentation for more reasons about why
|
|
||||||
//! it's discouraged, beyond mobile/web compatibility reasons.
|
|
||||||
//!
|
|
||||||
//!
|
|
||||||
//! ```no_run
|
|
||||||
//! use winit::{
|
|
||||||
//! event::{Event, WindowEvent},
|
|
||||||
//! event_loop::{ControlFlow, EventLoop},
|
|
||||||
//! window::WindowBuilder,
|
|
||||||
//! };
|
|
||||||
//!
|
|
||||||
//! let event_loop = EventLoop::new();
|
|
||||||
//! let window = WindowBuilder::new().build(&event_loop).unwrap();
|
|
||||||
//!
|
|
||||||
//! event_loop.run(move |event, _, control_flow| {
|
|
||||||
//! // ControlFlow::Poll continuously runs the event loop, even if the OS hasn't
|
|
||||||
//! // dispatched any events. This is ideal for games and similar applications.
|
|
||||||
//! *control_flow = ControlFlow::Poll;
|
|
||||||
//!
|
|
||||||
//! // ControlFlow::Wait pauses the event loop if no events are available to process.
|
|
||||||
//! // This is ideal for non-game applications that only update in response to user
|
|
||||||
//! // input, and uses significantly less power/CPU time than ControlFlow::Poll.
|
|
||||||
//! *control_flow = ControlFlow::Wait;
|
|
||||||
//!
|
|
||||||
//! match event {
|
|
||||||
//! Event::WindowEvent {
|
|
||||||
//! event: WindowEvent::CloseRequested,
|
|
||||||
//! ..
|
|
||||||
//! } => {
|
|
||||||
//! println!("The close button was pressed; stopping");
|
|
||||||
//! *control_flow = ControlFlow::Exit
|
|
||||||
//! },
|
|
||||||
//! Event::MainEventsCleared => {
|
|
||||||
//! // Application update code.
|
|
||||||
//!
|
|
||||||
//! // Queue a RedrawRequested event.
|
|
||||||
//! //
|
|
||||||
//! // You only need to call this if you've determined that you need to redraw, in
|
|
||||||
//! // applications which do not always need to. Applications that redraw continuously
|
|
||||||
//! // can just render here instead.
|
|
||||||
//! window.request_redraw();
|
|
||||||
//! },
|
|
||||||
//! Event::RedrawRequested(_) => {
|
|
||||||
//! // Redraw the application.
|
|
||||||
//! //
|
|
||||||
//! // It's preferable for applications that do not render continuously to render in
|
|
||||||
//! // this event rather than in MainEventsCleared, since rendering in here allows
|
|
||||||
//! // the program to gracefully handle redraws requested by the OS.
|
|
||||||
//! },
|
|
||||||
//! _ => ()
|
|
||||||
//! }
|
|
||||||
//! });
|
|
||||||
//! ```
|
|
||||||
//!
|
|
||||||
//! [`Event`]`::`[`WindowEvent`] has a [`WindowId`] member. In multi-window environments, it should be
|
|
||||||
//! compared to the value returned by [`Window::id()`][window_id_fn] to determine which [`Window`]
|
|
||||||
//! dispatched the event.
|
|
||||||
//!
|
|
||||||
//! # Drawing on the window
|
|
||||||
//!
|
|
||||||
//! Winit doesn't directly provide any methods for drawing on a [`Window`]. However it allows you to
|
|
||||||
//! retrieve the raw handle of the window (see the [`platform`] module and/or the
|
|
||||||
//! [`raw_window_handle`] method), which in turn allows you to create an
|
|
||||||
//! OpenGL/Vulkan/DirectX/Metal/etc. context that can be used to render graphics.
|
|
||||||
//!
|
|
||||||
//! Note that many platforms will display garbage data in the window's client area if the
|
|
||||||
//! application doesn't render anything to the window by the time the desktop compositor is ready to
|
|
||||||
//! display the window to the user. If you notice this happening, you should create the window with
|
|
||||||
//! [`visible` set to `false`](crate::window::WindowBuilder::with_visible) and explicitly make the
|
|
||||||
//! window visible only once you're ready to render into it.
|
|
||||||
//!
|
|
||||||
//! [`EventLoop`]: event_loop::EventLoop
|
|
||||||
//! [`EventLoopExtDesktop::run_return`]: ./platform/desktop/trait.EventLoopExtDesktop.html#tymethod.run_return
|
|
||||||
//! [`EventLoop::new()`]: event_loop::EventLoop::new
|
|
||||||
//! [event_loop_run]: event_loop::EventLoop::run
|
|
||||||
//! [`ControlFlow`]: event_loop::ControlFlow
|
|
||||||
//! [`Exit`]: event_loop::ControlFlow::Exit
|
|
||||||
//! [`Window`]: window::Window
|
|
||||||
//! [`WindowId`]: window::WindowId
|
|
||||||
//! [`WindowBuilder`]: window::WindowBuilder
|
|
||||||
//! [window_new]: window::Window::new
|
|
||||||
//! [window_builder_new]: window::WindowBuilder::new
|
|
||||||
//! [window_builder_build]: window::WindowBuilder::build
|
|
||||||
//! [window_id_fn]: window::Window::id
|
|
||||||
//! [`Event`]: event::Event
|
|
||||||
//! [`WindowEvent`]: event::WindowEvent
|
|
||||||
//! [`DeviceEvent`]: event::DeviceEvent
|
|
||||||
//! [`UserEvent`]: event::Event::UserEvent
|
|
||||||
//! [`LoopDestroyed`]: event::Event::LoopDestroyed
|
|
||||||
//! [`platform`]: platform
|
|
||||||
//! [`raw_window_handle`]: ./window/struct.Window.html#method.raw_window_handle
|
|
||||||
|
|
||||||
#![deny(rust_2018_idioms)]
|
|
||||||
#![deny(intra_doc_link_resolution_failure)]
|
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate lazy_static;
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
#[cfg(feature = "serde")]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate serde;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate bitflags;
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate objc;
|
|
||||||
#[cfg(all(target_arch = "wasm32", feature = "std_web"))]
|
|
||||||
extern crate std_web as stdweb;
|
|
||||||
|
|
||||||
pub mod dpi;
|
|
||||||
#[macro_use]
|
|
||||||
pub mod error;
|
|
||||||
pub mod event;
|
|
||||||
pub mod event_loop;
|
|
||||||
mod icon;
|
|
||||||
pub mod monitor;
|
|
||||||
mod platform_impl;
|
|
||||||
pub mod window;
|
|
||||||
|
|
||||||
pub mod platform;
|
|
||||||
174
src/monitor.rs
174
src/monitor.rs
@@ -1,174 +0,0 @@
|
|||||||
//! Types useful for interacting with a user's monitors.
|
|
||||||
//!
|
|
||||||
//! If you want to get basic information about a monitor, you can use the [`MonitorHandle`][monitor_handle]
|
|
||||||
//! type. This is retreived from one of the following methods, which return an iterator of
|
|
||||||
//! [`MonitorHandle`][monitor_handle]:
|
|
||||||
//! - [`EventLoop::available_monitors`][loop_get]
|
|
||||||
//! - [`Window::available_monitors`][window_get].
|
|
||||||
//!
|
|
||||||
//! [monitor_handle]: crate::monitor::MonitorHandle
|
|
||||||
//! [loop_get]: crate::event_loop::EventLoop::available_monitors
|
|
||||||
//! [window_get]: crate::window::Window::available_monitors
|
|
||||||
use crate::{
|
|
||||||
dpi::{PhysicalPosition, PhysicalSize},
|
|
||||||
platform_impl,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Describes a fullscreen video mode of a monitor.
|
|
||||||
///
|
|
||||||
/// Can be acquired with:
|
|
||||||
/// - [`MonitorHandle::video_modes`][monitor_get].
|
|
||||||
///
|
|
||||||
/// [monitor_get]: crate::monitor::MonitorHandle::video_modes
|
|
||||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub struct VideoMode {
|
|
||||||
pub(crate) video_mode: platform_impl::VideoMode,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Debug for VideoMode {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
self.video_mode.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialOrd for VideoMode {
|
|
||||||
fn partial_cmp(&self, other: &VideoMode) -> Option<std::cmp::Ordering> {
|
|
||||||
Some(self.cmp(other))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Ord for VideoMode {
|
|
||||||
fn cmp(&self, other: &VideoMode) -> std::cmp::Ordering {
|
|
||||||
// TODO: we can impl `Ord` for `PhysicalSize` once we switch from `f32`
|
|
||||||
// to `u32` there
|
|
||||||
let size: (u32, u32) = self.size().into();
|
|
||||||
let other_size: (u32, u32) = other.size().into();
|
|
||||||
self.monitor().cmp(&other.monitor()).then(
|
|
||||||
size.cmp(&other_size)
|
|
||||||
.then(
|
|
||||||
self.refresh_rate()
|
|
||||||
.cmp(&other.refresh_rate())
|
|
||||||
.then(self.bit_depth().cmp(&other.bit_depth())),
|
|
||||||
)
|
|
||||||
.reverse(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VideoMode {
|
|
||||||
/// Returns the resolution of this video mode.
|
|
||||||
#[inline]
|
|
||||||
pub fn size(&self) -> PhysicalSize<u32> {
|
|
||||||
self.video_mode.size()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the bit depth of this video mode, as in how many bits you have
|
|
||||||
/// available per color. This is generally 24 bits or 32 bits on modern
|
|
||||||
/// systems, depending on whether the alpha channel is counted or not.
|
|
||||||
///
|
|
||||||
/// ## Platform-specific
|
|
||||||
///
|
|
||||||
/// - **Wayland:** Always returns 32.
|
|
||||||
/// - **iOS:** Always returns 32.
|
|
||||||
#[inline]
|
|
||||||
pub fn bit_depth(&self) -> u16 {
|
|
||||||
self.video_mode.bit_depth()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the refresh rate of this video mode. **Note**: the returned
|
|
||||||
/// refresh rate is an integer approximation, and you shouldn't rely on this
|
|
||||||
/// value to be exact.
|
|
||||||
#[inline]
|
|
||||||
pub fn refresh_rate(&self) -> u16 {
|
|
||||||
self.video_mode.refresh_rate()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the monitor that this video mode is valid for. Each monitor has
|
|
||||||
/// a separate set of valid video modes.
|
|
||||||
#[inline]
|
|
||||||
pub fn monitor(&self) -> MonitorHandle {
|
|
||||||
self.video_mode.monitor()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Display for VideoMode {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"{}x{} @ {} Hz ({} bpp)",
|
|
||||||
self.size().width,
|
|
||||||
self.size().height,
|
|
||||||
self.refresh_rate(),
|
|
||||||
self.bit_depth()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Handle to a monitor.
|
|
||||||
///
|
|
||||||
/// Allows you to retrieve information about a given monitor and can be used in [`Window`] creation.
|
|
||||||
///
|
|
||||||
/// [`Window`]: crate::window::Window
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
|
||||||
pub struct MonitorHandle {
|
|
||||||
pub(crate) inner: platform_impl::MonitorHandle,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MonitorHandle {
|
|
||||||
/// Returns a human-readable name of the monitor.
|
|
||||||
///
|
|
||||||
/// Returns `None` if the monitor doesn't exist anymore.
|
|
||||||
///
|
|
||||||
/// ## Platform-specific
|
|
||||||
///
|
|
||||||
/// - **Web:** Always returns None
|
|
||||||
#[inline]
|
|
||||||
pub fn name(&self) -> Option<String> {
|
|
||||||
self.inner.name()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the monitor's resolution.
|
|
||||||
///
|
|
||||||
/// ## Platform-specific
|
|
||||||
///
|
|
||||||
/// - **Web:** Always returns (0,0)
|
|
||||||
#[inline]
|
|
||||||
pub fn size(&self) -> PhysicalSize<u32> {
|
|
||||||
self.inner.size()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the top-left corner position of the monitor relative to the larger full
|
|
||||||
/// screen area.
|
|
||||||
///
|
|
||||||
/// ## Platform-specific
|
|
||||||
///
|
|
||||||
/// - **Web:** Always returns (0,0)
|
|
||||||
#[inline]
|
|
||||||
pub fn position(&self) -> PhysicalPosition<i32> {
|
|
||||||
self.inner.position()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the scale factor that can be used to map logical pixels to physical pixels, and vice versa.
|
|
||||||
///
|
|
||||||
/// See the [`dpi`](crate::dpi) module for more information.
|
|
||||||
///
|
|
||||||
/// ## Platform-specific
|
|
||||||
///
|
|
||||||
/// - **X11:** Can be overridden using the `WINIT_X11_SCALE_FACTOR` environment variable.
|
|
||||||
/// - **Android:** Always returns 1.0.
|
|
||||||
/// - **Web:** Always returns 1.0
|
|
||||||
#[inline]
|
|
||||||
pub fn scale_factor(&self) -> f64 {
|
|
||||||
self.inner.scale_factor()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns all fullscreen video modes supported by this monitor.
|
|
||||||
///
|
|
||||||
/// ## Platform-specific
|
|
||||||
///
|
|
||||||
/// - **Web:** Always returns an empty iterator
|
|
||||||
#[inline]
|
|
||||||
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> {
|
|
||||||
self.inner.video_modes()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
#![cfg(any(target_os = "android"))]
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
event_loop::{EventLoop, EventLoopWindowTarget},
|
|
||||||
window::{Window, WindowBuilder},
|
|
||||||
};
|
|
||||||
use ndk::configuration::Configuration;
|
|
||||||
use ndk_glue::Rect;
|
|
||||||
|
|
||||||
/// Additional methods on `EventLoop` that are specific to Android.
|
|
||||||
pub trait EventLoopExtAndroid {}
|
|
||||||
|
|
||||||
impl<T> EventLoopExtAndroid for EventLoop<T> {}
|
|
||||||
|
|
||||||
/// Additional methods on `EventLoopWindowTarget` that are specific to Android.
|
|
||||||
pub trait EventLoopWindowTargetExtAndroid {}
|
|
||||||
|
|
||||||
/// Additional methods on `Window` that are specific to Android.
|
|
||||||
pub trait WindowExtAndroid {
|
|
||||||
fn content_rect(&self) -> Rect;
|
|
||||||
|
|
||||||
fn config(&self) -> Configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WindowExtAndroid for Window {
|
|
||||||
fn content_rect(&self) -> Rect {
|
|
||||||
self.window.content_rect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn config(&self) -> Configuration {
|
|
||||||
self.window.config()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> EventLoopWindowTargetExtAndroid for EventLoopWindowTarget<T> {}
|
|
||||||
|
|
||||||
/// Additional methods on `WindowBuilder` that are specific to Android.
|
|
||||||
pub trait WindowBuilderExtAndroid {}
|
|
||||||
|
|
||||||
impl WindowBuilderExtAndroid for WindowBuilder {}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
#![cfg(any(
|
|
||||||
target_os = "windows",
|
|
||||||
target_os = "macos",
|
|
||||||
target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"
|
|
||||||
))]
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
event::Event,
|
|
||||||
event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Additional methods on `EventLoop` that are specific to desktop platforms.
|
|
||||||
pub trait EventLoopExtDesktop {
|
|
||||||
/// A type provided by the user that can be passed through `Event::UserEvent`.
|
|
||||||
type UserEvent;
|
|
||||||
|
|
||||||
/// Initializes the `winit` event loop.
|
|
||||||
///
|
|
||||||
/// Unlike `run`, this function accepts non-`'static` (i.e. non-`move`) closures and returns
|
|
||||||
/// control flow to the caller when `control_flow` is set to `ControlFlow::Exit`.
|
|
||||||
///
|
|
||||||
/// # Caveats
|
|
||||||
/// Despite its apperance at first glance, this is *not* a perfect replacement for
|
|
||||||
/// `poll_events`. For example, this function will not return on Windows or macOS while a
|
|
||||||
/// window is getting resized, resulting in all application logic outside of the
|
|
||||||
/// `event_handler` closure not running until the resize operation ends. Other OS operations
|
|
||||||
/// may also result in such freezes. This behavior is caused by fundamental limitations in the
|
|
||||||
/// underyling OS APIs, which cannot be hidden by Winit without severe stability reprecussions.
|
|
||||||
///
|
|
||||||
/// You are strongly encouraged to use `run`, unless the use of this is absolutely necessary.
|
|
||||||
fn run_return<F>(&mut self, event_handler: F)
|
|
||||||
where
|
|
||||||
F: FnMut(
|
|
||||||
Event<'_, Self::UserEvent>,
|
|
||||||
&EventLoopWindowTarget<Self::UserEvent>,
|
|
||||||
&mut ControlFlow,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> EventLoopExtDesktop for EventLoop<T> {
|
|
||||||
type UserEvent = T;
|
|
||||||
|
|
||||||
fn run_return<F>(&mut self, event_handler: F)
|
|
||||||
where
|
|
||||||
F: FnMut(
|
|
||||||
Event<'_, Self::UserEvent>,
|
|
||||||
&EventLoopWindowTarget<Self::UserEvent>,
|
|
||||||
&mut ControlFlow,
|
|
||||||
),
|
|
||||||
{
|
|
||||||
self.event_loop.run_return(event_handler)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,317 +0,0 @@
|
|||||||
#![cfg(target_os = "ios")]
|
|
||||||
|
|
||||||
use std::os::raw::c_void;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
event_loop::EventLoop,
|
|
||||||
monitor::{MonitorHandle, VideoMode},
|
|
||||||
window::{Window, WindowBuilder},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Additional methods on [`EventLoop`] that are specific to iOS.
|
|
||||||
pub trait EventLoopExtIOS {
|
|
||||||
/// Returns the [`Idiom`] (phone/tablet/tv/etc) for the current device.
|
|
||||||
fn idiom(&self) -> Idiom;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: 'static> EventLoopExtIOS for EventLoop<T> {
|
|
||||||
fn idiom(&self) -> Idiom {
|
|
||||||
self.event_loop.idiom()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on [`Window`] that are specific to iOS.
|
|
||||||
pub trait WindowExtIOS {
|
|
||||||
/// Returns a pointer to the [`UIWindow`] that is used by this window.
|
|
||||||
///
|
|
||||||
/// The pointer will become invalid when the [`Window`] is destroyed.
|
|
||||||
///
|
|
||||||
/// [`UIWindow`]: https://developer.apple.com/documentation/uikit/uiwindow?language=objc
|
|
||||||
fn ui_window(&self) -> *mut c_void;
|
|
||||||
|
|
||||||
/// Returns a pointer to the [`UIViewController`] that is used by this window.
|
|
||||||
///
|
|
||||||
/// The pointer will become invalid when the [`Window`] is destroyed.
|
|
||||||
///
|
|
||||||
/// [`UIViewController`]: https://developer.apple.com/documentation/uikit/uiviewcontroller?language=objc
|
|
||||||
fn ui_view_controller(&self) -> *mut c_void;
|
|
||||||
|
|
||||||
/// Returns a pointer to the [`UIView`] that is used by this window.
|
|
||||||
///
|
|
||||||
/// The pointer will become invalid when the [`Window`] is destroyed.
|
|
||||||
///
|
|
||||||
/// [`UIView`]: https://developer.apple.com/documentation/uikit/uiview?language=objc
|
|
||||||
fn ui_view(&self) -> *mut c_void;
|
|
||||||
|
|
||||||
/// Sets the [`contentScaleFactor`] of the underlying [`UIWindow`] to `scale_factor`.
|
|
||||||
///
|
|
||||||
/// The default value is device dependent, and it's recommended GLES or Metal applications set
|
|
||||||
/// this to [`MonitorHandle::scale_factor()`].
|
|
||||||
///
|
|
||||||
/// [`UIWindow`]: https://developer.apple.com/documentation/uikit/uiwindow?language=objc
|
|
||||||
/// [`contentScaleFactor`]: https://developer.apple.com/documentation/uikit/uiview/1622657-contentscalefactor?language=objc
|
|
||||||
fn set_scale_factor(&self, scale_factor: f64);
|
|
||||||
|
|
||||||
/// Sets the valid orientations for the [`Window`].
|
|
||||||
///
|
|
||||||
/// The default value is [`ValidOrientations::LandscapeAndPortrait`].
|
|
||||||
///
|
|
||||||
/// This changes the value returned by
|
|
||||||
/// [`-[UIViewController supportedInterfaceOrientations]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations?language=objc),
|
|
||||||
/// and then calls
|
|
||||||
/// [`-[UIViewController attemptRotationToDeviceOrientation]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/1621400-attemptrotationtodeviceorientati?language=objc).
|
|
||||||
fn set_valid_orientations(&self, valid_orientations: ValidOrientations);
|
|
||||||
|
|
||||||
/// Sets whether the [`Window`] prefers the home indicator hidden.
|
|
||||||
///
|
|
||||||
/// The default is to prefer showing the home indicator.
|
|
||||||
///
|
|
||||||
/// This changes the value returned by
|
|
||||||
/// [`-[UIViewController prefersHomeIndicatorAutoHidden]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/2887510-prefershomeindicatorautohidden?language=objc),
|
|
||||||
/// and then calls
|
|
||||||
/// [`-[UIViewController setNeedsUpdateOfHomeIndicatorAutoHidden]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/2887509-setneedsupdateofhomeindicatoraut?language=objc).
|
|
||||||
///
|
|
||||||
/// This only has an effect on iOS 11.0+.
|
|
||||||
fn set_prefers_home_indicator_hidden(&self, hidden: bool);
|
|
||||||
|
|
||||||
/// Sets the screen edges for which the system gestures will take a lower priority than the
|
|
||||||
/// application's touch handling.
|
|
||||||
///
|
|
||||||
/// This changes the value returned by
|
|
||||||
/// [`-[UIViewController preferredScreenEdgesDeferringSystemGestures]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/2887512-preferredscreenedgesdeferringsys?language=objc),
|
|
||||||
/// and then calls
|
|
||||||
/// [`-[UIViewController setNeedsUpdateOfScreenEdgesDeferringSystemGestures]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/2887507-setneedsupdateofscreenedgesdefer?language=objc).
|
|
||||||
///
|
|
||||||
/// This only has an effect on iOS 11.0+.
|
|
||||||
fn set_preferred_screen_edges_deferring_system_gestures(&self, edges: ScreenEdge);
|
|
||||||
|
|
||||||
/// Sets whether the [`Window`] prefers the status bar hidden.
|
|
||||||
///
|
|
||||||
/// The default is to prefer showing the status bar.
|
|
||||||
///
|
|
||||||
/// This changes the value returned by
|
|
||||||
/// [`-[UIViewController prefersStatusBarHidden]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/1621440-prefersstatusbarhidden?language=objc),
|
|
||||||
/// and then calls
|
|
||||||
/// [`-[UIViewController setNeedsStatusBarAppearanceUpdate]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/1621354-setneedsstatusbarappearanceupdat?language=objc).
|
|
||||||
fn set_prefers_status_bar_hidden(&self, hidden: bool);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WindowExtIOS for Window {
|
|
||||||
#[inline]
|
|
||||||
fn ui_window(&self) -> *mut c_void {
|
|
||||||
self.window.ui_window() as _
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn ui_view_controller(&self) -> *mut c_void {
|
|
||||||
self.window.ui_view_controller() as _
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn ui_view(&self) -> *mut c_void {
|
|
||||||
self.window.ui_view() as _
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn set_scale_factor(&self, scale_factor: f64) {
|
|
||||||
self.window.set_scale_factor(scale_factor)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn set_valid_orientations(&self, valid_orientations: ValidOrientations) {
|
|
||||||
self.window.set_valid_orientations(valid_orientations)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn set_prefers_home_indicator_hidden(&self, hidden: bool) {
|
|
||||||
self.window.set_prefers_home_indicator_hidden(hidden)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn set_preferred_screen_edges_deferring_system_gestures(&self, edges: ScreenEdge) {
|
|
||||||
self.window
|
|
||||||
.set_preferred_screen_edges_deferring_system_gestures(edges)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn set_prefers_status_bar_hidden(&self, hidden: bool) {
|
|
||||||
self.window.set_prefers_status_bar_hidden(hidden)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on [`WindowBuilder`] that are specific to iOS.
|
|
||||||
pub trait WindowBuilderExtIOS {
|
|
||||||
/// Sets the root view class used by the [`Window`], otherwise a barebones [`UIView`] is provided.
|
|
||||||
///
|
|
||||||
/// An instance of the class will be initialized by calling [`-[UIView initWithFrame:]`](https://developer.apple.com/documentation/uikit/uiview/1622488-initwithframe?language=objc).
|
|
||||||
///
|
|
||||||
/// [`UIView`]: https://developer.apple.com/documentation/uikit/uiview?language=objc
|
|
||||||
fn with_root_view_class(self, root_view_class: *const c_void) -> WindowBuilder;
|
|
||||||
|
|
||||||
/// Sets the [`contentScaleFactor`] of the underlying [`UIWindow`] to `scale_factor`.
|
|
||||||
///
|
|
||||||
/// The default value is device dependent, and it's recommended GLES or Metal applications set
|
|
||||||
/// this to [`MonitorHandle::scale_factor()`].
|
|
||||||
///
|
|
||||||
/// [`UIWindow`]: https://developer.apple.com/documentation/uikit/uiwindow?language=objc
|
|
||||||
/// [`contentScaleFactor`]: https://developer.apple.com/documentation/uikit/uiview/1622657-contentscalefactor?language=objc
|
|
||||||
fn with_scale_factor(self, scale_factor: f64) -> WindowBuilder;
|
|
||||||
|
|
||||||
/// Sets the valid orientations for the [`Window`].
|
|
||||||
///
|
|
||||||
/// The default value is [`ValidOrientations::LandscapeAndPortrait`].
|
|
||||||
///
|
|
||||||
/// This sets the initial value returned by
|
|
||||||
/// [`-[UIViewController supportedInterfaceOrientations]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations?language=objc).
|
|
||||||
fn with_valid_orientations(self, valid_orientations: ValidOrientations) -> WindowBuilder;
|
|
||||||
|
|
||||||
/// Sets whether the [`Window`] prefers the home indicator hidden.
|
|
||||||
///
|
|
||||||
/// The default is to prefer showing the home indicator.
|
|
||||||
///
|
|
||||||
/// This sets the initial value returned by
|
|
||||||
/// [`-[UIViewController prefersHomeIndicatorAutoHidden]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/2887510-prefershomeindicatorautohidden?language=objc).
|
|
||||||
///
|
|
||||||
/// This only has an effect on iOS 11.0+.
|
|
||||||
fn with_prefers_home_indicator_hidden(self, hidden: bool) -> WindowBuilder;
|
|
||||||
|
|
||||||
/// Sets the screen edges for which the system gestures will take a lower priority than the
|
|
||||||
/// application's touch handling.
|
|
||||||
///
|
|
||||||
/// This sets the initial value returned by
|
|
||||||
/// [`-[UIViewController preferredScreenEdgesDeferringSystemGestures]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/2887512-preferredscreenedgesdeferringsys?language=objc).
|
|
||||||
///
|
|
||||||
/// This only has an effect on iOS 11.0+.
|
|
||||||
fn with_preferred_screen_edges_deferring_system_gestures(
|
|
||||||
self,
|
|
||||||
edges: ScreenEdge,
|
|
||||||
) -> WindowBuilder;
|
|
||||||
|
|
||||||
/// Sets whether the [`Window`] prefers the status bar hidden.
|
|
||||||
///
|
|
||||||
/// The default is to prefer showing the status bar.
|
|
||||||
///
|
|
||||||
/// This sets the initial value returned by
|
|
||||||
/// [`-[UIViewController prefersStatusBarHidden]`](https://developer.apple.com/documentation/uikit/uiviewcontroller/1621440-prefersstatusbarhidden?language=objc).
|
|
||||||
fn with_prefers_status_bar_hidden(self, hidden: bool) -> WindowBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WindowBuilderExtIOS for WindowBuilder {
|
|
||||||
#[inline]
|
|
||||||
fn with_root_view_class(mut self, root_view_class: *const c_void) -> WindowBuilder {
|
|
||||||
self.platform_specific.root_view_class = unsafe { &*(root_view_class as *const _) };
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_scale_factor(mut self, scale_factor: f64) -> WindowBuilder {
|
|
||||||
self.platform_specific.scale_factor = Some(scale_factor);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_valid_orientations(mut self, valid_orientations: ValidOrientations) -> WindowBuilder {
|
|
||||||
self.platform_specific.valid_orientations = valid_orientations;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_prefers_home_indicator_hidden(mut self, hidden: bool) -> WindowBuilder {
|
|
||||||
self.platform_specific.prefers_home_indicator_hidden = hidden;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_preferred_screen_edges_deferring_system_gestures(
|
|
||||||
mut self,
|
|
||||||
edges: ScreenEdge,
|
|
||||||
) -> WindowBuilder {
|
|
||||||
self.platform_specific
|
|
||||||
.preferred_screen_edges_deferring_system_gestures = edges;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_prefers_status_bar_hidden(mut self, hidden: bool) -> WindowBuilder {
|
|
||||||
self.platform_specific.prefers_status_bar_hidden = hidden;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on [`MonitorHandle`] that are specific to iOS.
|
|
||||||
pub trait MonitorHandleExtIOS {
|
|
||||||
/// Returns a pointer to the [`UIScreen`] that is used by this monitor.
|
|
||||||
///
|
|
||||||
/// [`UIScreen`]: https://developer.apple.com/documentation/uikit/uiscreen?language=objc
|
|
||||||
fn ui_screen(&self) -> *mut c_void;
|
|
||||||
|
|
||||||
/// Returns the preferred [`VideoMode`] for this monitor.
|
|
||||||
///
|
|
||||||
/// This translates to a call to [`-[UIScreen preferredMode]`](https://developer.apple.com/documentation/uikit/uiscreen/1617823-preferredmode?language=objc).
|
|
||||||
fn preferred_video_mode(&self) -> VideoMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MonitorHandleExtIOS for MonitorHandle {
|
|
||||||
#[inline]
|
|
||||||
fn ui_screen(&self) -> *mut c_void {
|
|
||||||
self.inner.ui_screen() as _
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn preferred_video_mode(&self) -> VideoMode {
|
|
||||||
self.inner.preferred_video_mode()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Valid orientations for a particular [`Window`].
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub enum ValidOrientations {
|
|
||||||
/// Excludes `PortraitUpsideDown` on iphone
|
|
||||||
LandscapeAndPortrait,
|
|
||||||
|
|
||||||
Landscape,
|
|
||||||
|
|
||||||
/// Excludes `PortraitUpsideDown` on iphone
|
|
||||||
Portrait,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for ValidOrientations {
|
|
||||||
#[inline]
|
|
||||||
fn default() -> ValidOrientations {
|
|
||||||
ValidOrientations::LandscapeAndPortrait
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The device [idiom].
|
|
||||||
///
|
|
||||||
/// [idiom]: https://developer.apple.com/documentation/uikit/uidevice/1620037-userinterfaceidiom?language=objc
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
||||||
pub enum Idiom {
|
|
||||||
Unspecified,
|
|
||||||
|
|
||||||
/// iPhone and iPod touch.
|
|
||||||
Phone,
|
|
||||||
|
|
||||||
/// iPad.
|
|
||||||
Pad,
|
|
||||||
|
|
||||||
/// tvOS and Apple TV.
|
|
||||||
TV,
|
|
||||||
CarPlay,
|
|
||||||
}
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
/// The [edges] of a screen.
|
|
||||||
///
|
|
||||||
/// [edges]: https://developer.apple.com/documentation/uikit/uirectedge?language=objc
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct ScreenEdge: u8 {
|
|
||||||
const NONE = 0;
|
|
||||||
const TOP = 1 << 0;
|
|
||||||
const LEFT = 1 << 1;
|
|
||||||
const BOTTOM = 1 << 2;
|
|
||||||
const RIGHT = 1 << 3;
|
|
||||||
const ALL = ScreenEdge::TOP.bits | ScreenEdge::LEFT.bits
|
|
||||||
| ScreenEdge::BOTTOM.bits | ScreenEdge::RIGHT.bits;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,226 +0,0 @@
|
|||||||
#![cfg(target_os = "macos")]
|
|
||||||
|
|
||||||
use std::os::raw::c_void;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
dpi::LogicalSize,
|
|
||||||
event_loop::EventLoopWindowTarget,
|
|
||||||
monitor::MonitorHandle,
|
|
||||||
window::{Window, WindowBuilder},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Corresponds to `NSRequestUserAttentionType`.
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
||||||
pub enum RequestUserAttentionType {
|
|
||||||
/// Corresponds to `NSCriticalRequest`.
|
|
||||||
///
|
|
||||||
/// Dock icon will bounce until the application is focused.
|
|
||||||
Critical,
|
|
||||||
|
|
||||||
/// Corresponds to `NSInformationalRequest`.
|
|
||||||
///
|
|
||||||
/// Dock icon will bounce once.
|
|
||||||
Informational,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for RequestUserAttentionType {
|
|
||||||
fn default() -> Self {
|
|
||||||
RequestUserAttentionType::Critical
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on `Window` that are specific to MacOS.
|
|
||||||
pub trait WindowExtMacOS {
|
|
||||||
/// Returns a pointer to the cocoa `NSWindow` that is used by this window.
|
|
||||||
///
|
|
||||||
/// The pointer will become invalid when the `Window` is destroyed.
|
|
||||||
fn ns_window(&self) -> *mut c_void;
|
|
||||||
|
|
||||||
/// Returns a pointer to the cocoa `NSView` that is used by this window.
|
|
||||||
///
|
|
||||||
/// The pointer will become invalid when the `Window` is destroyed.
|
|
||||||
fn ns_view(&self) -> *mut c_void;
|
|
||||||
|
|
||||||
/// Request user attention, causing the application's dock icon to bounce.
|
|
||||||
/// Note that this has no effect if the application is already focused.
|
|
||||||
fn request_user_attention(&self, request_type: RequestUserAttentionType);
|
|
||||||
|
|
||||||
/// Returns whether or not the window is in simple fullscreen mode.
|
|
||||||
fn simple_fullscreen(&self) -> bool;
|
|
||||||
|
|
||||||
/// Toggles a fullscreen mode that doesn't require a new macOS space.
|
|
||||||
/// Returns a boolean indicating whether the transition was successful (this
|
|
||||||
/// won't work if the window was already in the native fullscreen).
|
|
||||||
///
|
|
||||||
/// This is how fullscreen used to work on macOS in versions before Lion.
|
|
||||||
/// And allows the user to have a fullscreen window without using another
|
|
||||||
/// space or taking control over the entire monitor.
|
|
||||||
fn set_simple_fullscreen(&self, fullscreen: bool) -> bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WindowExtMacOS for Window {
|
|
||||||
#[inline]
|
|
||||||
fn ns_window(&self) -> *mut c_void {
|
|
||||||
self.window.ns_window()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn ns_view(&self) -> *mut c_void {
|
|
||||||
self.window.ns_view()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn request_user_attention(&self, request_type: RequestUserAttentionType) {
|
|
||||||
self.window.request_user_attention(request_type)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn simple_fullscreen(&self) -> bool {
|
|
||||||
self.window.simple_fullscreen()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn set_simple_fullscreen(&self, fullscreen: bool) -> bool {
|
|
||||||
self.window.set_simple_fullscreen(fullscreen)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Corresponds to `NSApplicationActivationPolicy`.
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
||||||
pub enum ActivationPolicy {
|
|
||||||
/// Corresponds to `NSApplicationActivationPolicyRegular`.
|
|
||||||
Regular,
|
|
||||||
/// Corresponds to `NSApplicationActivationPolicyAccessory`.
|
|
||||||
Accessory,
|
|
||||||
/// Corresponds to `NSApplicationActivationPolicyProhibited`.
|
|
||||||
Prohibited,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for ActivationPolicy {
|
|
||||||
fn default() -> Self {
|
|
||||||
ActivationPolicy::Regular
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on `WindowBuilder` that are specific to MacOS.
|
|
||||||
///
|
|
||||||
/// **Note:** Properties dealing with the titlebar will be overwritten by the `with_decorations` method
|
|
||||||
/// on the base `WindowBuilder`:
|
|
||||||
///
|
|
||||||
/// - `with_titlebar_transparent`
|
|
||||||
/// - `with_title_hidden`
|
|
||||||
/// - `with_titlebar_hidden`
|
|
||||||
/// - `with_titlebar_buttons_hidden`
|
|
||||||
/// - `with_fullsize_content_view`
|
|
||||||
pub trait WindowBuilderExtMacOS {
|
|
||||||
/// Sets the activation policy for the window being built.
|
|
||||||
fn with_activation_policy(self, activation_policy: ActivationPolicy) -> WindowBuilder;
|
|
||||||
/// Enables click-and-drag behavior for the entire window, not just the titlebar.
|
|
||||||
fn with_movable_by_window_background(self, movable_by_window_background: bool)
|
|
||||||
-> WindowBuilder;
|
|
||||||
/// Makes the titlebar transparent and allows the content to appear behind it.
|
|
||||||
fn with_titlebar_transparent(self, titlebar_transparent: bool) -> WindowBuilder;
|
|
||||||
/// Hides the window title.
|
|
||||||
fn with_title_hidden(self, title_hidden: bool) -> WindowBuilder;
|
|
||||||
/// Hides the window titlebar.
|
|
||||||
fn with_titlebar_hidden(self, titlebar_hidden: bool) -> WindowBuilder;
|
|
||||||
/// Hides the window titlebar buttons.
|
|
||||||
fn with_titlebar_buttons_hidden(self, titlebar_buttons_hidden: bool) -> WindowBuilder;
|
|
||||||
/// Makes the window content appear behind the titlebar.
|
|
||||||
fn with_fullsize_content_view(self, fullsize_content_view: bool) -> WindowBuilder;
|
|
||||||
/// Build window with `resizeIncrements` property. Values must not be 0.
|
|
||||||
fn with_resize_increments(self, increments: LogicalSize<f64>) -> WindowBuilder;
|
|
||||||
fn with_disallow_hidpi(self, disallow_hidpi: bool) -> WindowBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WindowBuilderExtMacOS for WindowBuilder {
|
|
||||||
#[inline]
|
|
||||||
fn with_activation_policy(mut self, activation_policy: ActivationPolicy) -> WindowBuilder {
|
|
||||||
self.platform_specific.activation_policy = activation_policy;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_movable_by_window_background(
|
|
||||||
mut self,
|
|
||||||
movable_by_window_background: bool,
|
|
||||||
) -> WindowBuilder {
|
|
||||||
self.platform_specific.movable_by_window_background = movable_by_window_background;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_titlebar_transparent(mut self, titlebar_transparent: bool) -> WindowBuilder {
|
|
||||||
self.platform_specific.titlebar_transparent = titlebar_transparent;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_titlebar_hidden(mut self, titlebar_hidden: bool) -> WindowBuilder {
|
|
||||||
self.platform_specific.titlebar_hidden = titlebar_hidden;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_titlebar_buttons_hidden(mut self, titlebar_buttons_hidden: bool) -> WindowBuilder {
|
|
||||||
self.platform_specific.titlebar_buttons_hidden = titlebar_buttons_hidden;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_title_hidden(mut self, title_hidden: bool) -> WindowBuilder {
|
|
||||||
self.platform_specific.title_hidden = title_hidden;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_fullsize_content_view(mut self, fullsize_content_view: bool) -> WindowBuilder {
|
|
||||||
self.platform_specific.fullsize_content_view = fullsize_content_view;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_resize_increments(mut self, increments: LogicalSize<f64>) -> WindowBuilder {
|
|
||||||
self.platform_specific.resize_increments = Some(increments.into());
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_disallow_hidpi(mut self, disallow_hidpi: bool) -> WindowBuilder {
|
|
||||||
self.platform_specific.disallow_hidpi = disallow_hidpi;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on `MonitorHandle` that are specific to MacOS.
|
|
||||||
pub trait MonitorHandleExtMacOS {
|
|
||||||
/// Returns the identifier of the monitor for Cocoa.
|
|
||||||
fn native_id(&self) -> u32;
|
|
||||||
/// Returns a pointer to the NSScreen representing this monitor.
|
|
||||||
fn ns_screen(&self) -> Option<*mut c_void>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MonitorHandleExtMacOS for MonitorHandle {
|
|
||||||
#[inline]
|
|
||||||
fn native_id(&self) -> u32 {
|
|
||||||
self.inner.native_identifier()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ns_screen(&self) -> Option<*mut c_void> {
|
|
||||||
self.inner.ns_screen().map(|s| s as *mut c_void)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on `EventLoopWindowTarget` that are specific to macOS.
|
|
||||||
pub trait EventLoopWindowTargetExtMacOS {
|
|
||||||
/// Hide the entire application. In most applications this is typically triggered with Command-H.
|
|
||||||
fn hide_application(&self);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> EventLoopWindowTargetExtMacOS for EventLoopWindowTarget<T> {
|
|
||||||
fn hide_application(&self) {
|
|
||||||
let cls = objc::runtime::Class::get("NSApplication").unwrap();
|
|
||||||
let app: cocoa::base::id = unsafe { msg_send![cls, sharedApplication] };
|
|
||||||
unsafe { msg_send![app, hide: 0] }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
//! Contains traits with platform-specific methods in them.
|
|
||||||
//!
|
|
||||||
//! Contains the follow OS-specific modules:
|
|
||||||
//!
|
|
||||||
//! - `android`
|
|
||||||
//! - `ios`
|
|
||||||
//! - `macos`
|
|
||||||
//! - `unix`
|
|
||||||
//! - `windows`
|
|
||||||
//! - `web`
|
|
||||||
//!
|
|
||||||
//! And the following platform-specific module:
|
|
||||||
//!
|
|
||||||
//! - `desktop` (available on `windows`, `unix`, and `macos`)
|
|
||||||
//!
|
|
||||||
//! However only the module corresponding to the platform you're compiling to will be available.
|
|
||||||
|
|
||||||
pub mod android;
|
|
||||||
pub mod ios;
|
|
||||||
pub mod macos;
|
|
||||||
pub mod unix;
|
|
||||||
pub mod windows;
|
|
||||||
|
|
||||||
pub mod desktop;
|
|
||||||
pub mod web;
|
|
||||||
@@ -1,489 +0,0 @@
|
|||||||
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
|
|
||||||
|
|
||||||
use std::{os::raw, ptr, sync::Arc};
|
|
||||||
|
|
||||||
use smithay_client_toolkit::window::{ButtonState as SCTKButtonState, Theme as SCTKTheme};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
dpi::Size,
|
|
||||||
event_loop::{EventLoop, EventLoopWindowTarget},
|
|
||||||
monitor::MonitorHandle,
|
|
||||||
window::{Window, WindowBuilder},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::platform_impl::{
|
|
||||||
x11::{ffi::XVisualInfo, XConnection},
|
|
||||||
EventLoop as LinuxEventLoop, EventLoopWindowTarget as LinuxEventLoopWindowTarget,
|
|
||||||
Window as LinuxWindow,
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: stupid hack so that glutin can do its work
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub use crate::platform_impl::x11;
|
|
||||||
|
|
||||||
pub use crate::platform_impl::{x11::util::WindowType as XWindowType, XNotSupported};
|
|
||||||
|
|
||||||
/// Additional methods on `EventLoopWindowTarget` that are specific to Unix.
|
|
||||||
pub trait EventLoopWindowTargetExtUnix {
|
|
||||||
/// True if the `EventLoopWindowTarget` uses Wayland.
|
|
||||||
fn is_wayland(&self) -> bool;
|
|
||||||
///
|
|
||||||
/// True if the `EventLoopWindowTarget` uses X11.
|
|
||||||
fn is_x11(&self) -> bool;
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
fn xlib_xconnection(&self) -> Option<Arc<XConnection>>;
|
|
||||||
|
|
||||||
/// Returns a pointer to the `wl_display` object of wayland that is used by this
|
|
||||||
/// `EventLoopWindowTarget`.
|
|
||||||
///
|
|
||||||
/// Returns `None` if the `EventLoop` doesn't use wayland (if it uses xlib for example).
|
|
||||||
///
|
|
||||||
/// The pointer will become invalid when the winit `EventLoop` is destroyed.
|
|
||||||
fn wayland_display(&self) -> Option<*mut raw::c_void>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> EventLoopWindowTargetExtUnix for EventLoopWindowTarget<T> {
|
|
||||||
#[inline]
|
|
||||||
fn is_wayland(&self) -> bool {
|
|
||||||
self.p.is_wayland()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn is_x11(&self) -> bool {
|
|
||||||
!self.p.is_wayland()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[doc(hidden)]
|
|
||||||
fn xlib_xconnection(&self) -> Option<Arc<XConnection>> {
|
|
||||||
match self.p {
|
|
||||||
LinuxEventLoopWindowTarget::X(ref e) => Some(e.x_connection().clone()),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn wayland_display(&self) -> Option<*mut raw::c_void> {
|
|
||||||
match self.p {
|
|
||||||
LinuxEventLoopWindowTarget::Wayland(ref p) => {
|
|
||||||
Some(p.display().get_display_ptr() as *mut _)
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on `EventLoop` that are specific to Unix.
|
|
||||||
pub trait EventLoopExtUnix {
|
|
||||||
/// Builds a new `EventLoop` that is forced to use X11.
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// If called outside the main thread. To initialize an X11 event loop outside
|
|
||||||
/// the main thread, use [`new_x11_any_thread`](#tymethod.new_x11_any_thread).
|
|
||||||
fn new_x11() -> Result<Self, XNotSupported>
|
|
||||||
where
|
|
||||||
Self: Sized;
|
|
||||||
|
|
||||||
/// Builds a new `EventLoop` that is forced to use Wayland.
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// If called outside the main thread. To initialize a Wayland event loop outside
|
|
||||||
/// the main thread, use [`new_wayland_any_thread`](#tymethod.new_wayland_any_thread).
|
|
||||||
fn new_wayland() -> Self
|
|
||||||
where
|
|
||||||
Self: Sized;
|
|
||||||
|
|
||||||
/// Builds a new `EventLoop` on any thread.
|
|
||||||
///
|
|
||||||
/// This method bypasses the cross-platform compatibility requirement
|
|
||||||
/// that `EventLoop` be created on the main thread.
|
|
||||||
fn new_any_thread() -> Self
|
|
||||||
where
|
|
||||||
Self: Sized;
|
|
||||||
|
|
||||||
/// Builds a new X11 `EventLoop` on any thread.
|
|
||||||
///
|
|
||||||
/// This method bypasses the cross-platform compatibility requirement
|
|
||||||
/// that `EventLoop` be created on the main thread.
|
|
||||||
fn new_x11_any_thread() -> Result<Self, XNotSupported>
|
|
||||||
where
|
|
||||||
Self: Sized;
|
|
||||||
|
|
||||||
/// Builds a new Wayland `EventLoop` on any thread.
|
|
||||||
///
|
|
||||||
/// This method bypasses the cross-platform compatibility requirement
|
|
||||||
/// that `EventLoop` be created on the main thread.
|
|
||||||
fn new_wayland_any_thread() -> Self
|
|
||||||
where
|
|
||||||
Self: Sized;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn wrap_ev<T>(event_loop: LinuxEventLoop<T>) -> EventLoop<T> {
|
|
||||||
EventLoop {
|
|
||||||
event_loop,
|
|
||||||
_marker: std::marker::PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> EventLoopExtUnix for EventLoop<T> {
|
|
||||||
#[inline]
|
|
||||||
fn new_any_thread() -> Self {
|
|
||||||
wrap_ev(LinuxEventLoop::new_any_thread())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn new_x11_any_thread() -> Result<Self, XNotSupported> {
|
|
||||||
LinuxEventLoop::new_x11_any_thread().map(wrap_ev)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn new_wayland_any_thread() -> Self {
|
|
||||||
wrap_ev(
|
|
||||||
LinuxEventLoop::new_wayland_any_thread()
|
|
||||||
// TODO: propagate
|
|
||||||
.expect("failed to open Wayland connection"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn new_x11() -> Result<Self, XNotSupported> {
|
|
||||||
LinuxEventLoop::new_x11().map(wrap_ev)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn new_wayland() -> Self {
|
|
||||||
wrap_ev(
|
|
||||||
LinuxEventLoop::new_wayland()
|
|
||||||
// TODO: propagate
|
|
||||||
.expect("failed to open Wayland connection"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on `Window` that are specific to Unix.
|
|
||||||
pub trait WindowExtUnix {
|
|
||||||
/// Returns the ID of the `Window` xlib object that is used by this window.
|
|
||||||
///
|
|
||||||
/// Returns `None` if the window doesn't use xlib (if it uses wayland for example).
|
|
||||||
fn xlib_window(&self) -> Option<raw::c_ulong>;
|
|
||||||
|
|
||||||
/// Returns a pointer to the `Display` object of xlib that is used by this window.
|
|
||||||
///
|
|
||||||
/// Returns `None` if the window doesn't use xlib (if it uses wayland for example).
|
|
||||||
///
|
|
||||||
/// The pointer will become invalid when the glutin `Window` is destroyed.
|
|
||||||
fn xlib_display(&self) -> Option<*mut raw::c_void>;
|
|
||||||
|
|
||||||
fn xlib_screen_id(&self) -> Option<raw::c_int>;
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
fn xlib_xconnection(&self) -> Option<Arc<XConnection>>;
|
|
||||||
|
|
||||||
/// Set window urgency hint (`XUrgencyHint`). Only relevant on X.
|
|
||||||
fn set_urgent(&self, is_urgent: bool);
|
|
||||||
|
|
||||||
/// This function returns the underlying `xcb_connection_t` of an xlib `Display`.
|
|
||||||
///
|
|
||||||
/// Returns `None` if the window doesn't use xlib (if it uses wayland for example).
|
|
||||||
///
|
|
||||||
/// The pointer will become invalid when the glutin `Window` is destroyed.
|
|
||||||
fn xcb_connection(&self) -> Option<*mut raw::c_void>;
|
|
||||||
|
|
||||||
/// Returns a pointer to the `wl_surface` object of wayland that is used by this window.
|
|
||||||
///
|
|
||||||
/// Returns `None` if the window doesn't use wayland (if it uses xlib for example).
|
|
||||||
///
|
|
||||||
/// The pointer will become invalid when the glutin `Window` is destroyed.
|
|
||||||
fn wayland_surface(&self) -> Option<*mut raw::c_void>;
|
|
||||||
|
|
||||||
/// Returns a pointer to the `wl_display` object of wayland that is used by this window.
|
|
||||||
///
|
|
||||||
/// Returns `None` if the window doesn't use wayland (if it uses xlib for example).
|
|
||||||
///
|
|
||||||
/// The pointer will become invalid when the glutin `Window` is destroyed.
|
|
||||||
fn wayland_display(&self) -> Option<*mut raw::c_void>;
|
|
||||||
|
|
||||||
/// Sets the color theme of the client side window decorations on wayland
|
|
||||||
fn set_wayland_theme<T: Theme>(&self, theme: T);
|
|
||||||
|
|
||||||
/// Check if the window is ready for drawing
|
|
||||||
///
|
|
||||||
/// It is a remnant of a previous implementation detail for the
|
|
||||||
/// wayland backend, and is no longer relevant.
|
|
||||||
///
|
|
||||||
/// Always return true.
|
|
||||||
#[deprecated]
|
|
||||||
fn is_ready(&self) -> bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WindowExtUnix for Window {
|
|
||||||
#[inline]
|
|
||||||
fn xlib_window(&self) -> Option<raw::c_ulong> {
|
|
||||||
match self.window {
|
|
||||||
LinuxWindow::X(ref w) => Some(w.xlib_window()),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn xlib_display(&self) -> Option<*mut raw::c_void> {
|
|
||||||
match self.window {
|
|
||||||
LinuxWindow::X(ref w) => Some(w.xlib_display()),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn xlib_screen_id(&self) -> Option<raw::c_int> {
|
|
||||||
match self.window {
|
|
||||||
LinuxWindow::X(ref w) => Some(w.xlib_screen_id()),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[doc(hidden)]
|
|
||||||
fn xlib_xconnection(&self) -> Option<Arc<XConnection>> {
|
|
||||||
match self.window {
|
|
||||||
LinuxWindow::X(ref w) => Some(w.xlib_xconnection()),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn set_urgent(&self, is_urgent: bool) {
|
|
||||||
if let LinuxWindow::X(ref w) = self.window {
|
|
||||||
w.set_urgent(is_urgent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn xcb_connection(&self) -> Option<*mut raw::c_void> {
|
|
||||||
match self.window {
|
|
||||||
LinuxWindow::X(ref w) => Some(w.xcb_connection()),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn wayland_surface(&self) -> Option<*mut raw::c_void> {
|
|
||||||
match self.window {
|
|
||||||
LinuxWindow::Wayland(ref w) => Some(w.surface().as_ref().c_ptr() as *mut _),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn wayland_display(&self) -> Option<*mut raw::c_void> {
|
|
||||||
match self.window {
|
|
||||||
LinuxWindow::Wayland(ref w) => Some(w.display().as_ref().c_ptr() as *mut _),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn set_wayland_theme<T: Theme>(&self, theme: T) {
|
|
||||||
match self.window {
|
|
||||||
LinuxWindow::Wayland(ref w) => w.set_theme(WaylandTheme(theme)),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn is_ready(&self) -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on `WindowBuilder` that are specific to Unix.
|
|
||||||
pub trait WindowBuilderExtUnix {
|
|
||||||
fn with_x11_visual<T>(self, visual_infos: *const T) -> Self;
|
|
||||||
fn with_x11_screen(self, screen_id: i32) -> Self;
|
|
||||||
|
|
||||||
/// Build window with `WM_CLASS` hint; defaults to the name of the binary. Only relevant on X11.
|
|
||||||
fn with_class(self, class: String, instance: String) -> Self;
|
|
||||||
/// Build window with override-redirect flag; defaults to false. Only relevant on X11.
|
|
||||||
fn with_override_redirect(self, override_redirect: bool) -> Self;
|
|
||||||
/// Build window with `_NET_WM_WINDOW_TYPE` hints; defaults to `Normal`. Only relevant on X11.
|
|
||||||
fn with_x11_window_type(self, x11_window_type: Vec<XWindowType>) -> Self;
|
|
||||||
/// Build window with `_GTK_THEME_VARIANT` hint set to the specified value. Currently only relevant on X11.
|
|
||||||
fn with_gtk_theme_variant(self, variant: String) -> Self;
|
|
||||||
/// Build window with resize increment hint. Only implemented on X11.
|
|
||||||
fn with_resize_increments<S: Into<Size>>(self, increments: S) -> Self;
|
|
||||||
/// Build window with base size hint. Only implemented on X11.
|
|
||||||
fn with_base_size<S: Into<Size>>(self, base_size: S) -> Self;
|
|
||||||
|
|
||||||
/// Build window with a given application ID. It should match the `.desktop` file distributed with
|
|
||||||
/// your program. Only relevant on Wayland.
|
|
||||||
///
|
|
||||||
/// For details about application ID conventions, see the
|
|
||||||
/// [Desktop Entry Spec](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#desktop-file-id)
|
|
||||||
fn with_app_id(self, app_id: String) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WindowBuilderExtUnix for WindowBuilder {
|
|
||||||
#[inline]
|
|
||||||
fn with_x11_visual<T>(mut self, visual_infos: *const T) -> Self {
|
|
||||||
self.platform_specific.visual_infos =
|
|
||||||
Some(unsafe { ptr::read(visual_infos as *const XVisualInfo) });
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_x11_screen(mut self, screen_id: i32) -> Self {
|
|
||||||
self.platform_specific.screen_id = Some(screen_id);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_class(mut self, instance: String, class: String) -> Self {
|
|
||||||
self.platform_specific.class = Some((instance, class));
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_override_redirect(mut self, override_redirect: bool) -> Self {
|
|
||||||
self.platform_specific.override_redirect = override_redirect;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_x11_window_type(mut self, x11_window_types: Vec<XWindowType>) -> Self {
|
|
||||||
self.platform_specific.x11_window_types = x11_window_types;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_gtk_theme_variant(mut self, variant: String) -> Self {
|
|
||||||
self.platform_specific.gtk_theme_variant = Some(variant);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_resize_increments<S: Into<Size>>(mut self, increments: S) -> Self {
|
|
||||||
self.platform_specific.resize_increments = Some(increments.into());
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_base_size<S: Into<Size>>(mut self, base_size: S) -> Self {
|
|
||||||
self.platform_specific.base_size = Some(base_size.into());
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_app_id(mut self, app_id: String) -> Self {
|
|
||||||
self.platform_specific.app_id = Some(app_id);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on `MonitorHandle` that are specific to Linux.
|
|
||||||
pub trait MonitorHandleExtUnix {
|
|
||||||
/// Returns the inner identifier of the monitor.
|
|
||||||
fn native_id(&self) -> u32;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MonitorHandleExtUnix for MonitorHandle {
|
|
||||||
#[inline]
|
|
||||||
fn native_id(&self) -> u32 {
|
|
||||||
self.inner.native_identifier()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Wrapper for implementing SCTK's theme trait.
|
|
||||||
struct WaylandTheme<T: Theme>(T);
|
|
||||||
|
|
||||||
pub trait Theme: Send + 'static {
|
|
||||||
/// Primary color of the scheme.
|
|
||||||
fn primary_color(&self, window_active: bool) -> [u8; 4];
|
|
||||||
|
|
||||||
/// Secondary color of the scheme.
|
|
||||||
fn secondary_color(&self, window_active: bool) -> [u8; 4];
|
|
||||||
|
|
||||||
/// Color for the close button.
|
|
||||||
fn close_button_color(&self, status: ButtonState) -> [u8; 4];
|
|
||||||
|
|
||||||
/// Icon color for the close button, defaults to the secondary color.
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
fn close_button_icon_color(&self, status: ButtonState) -> [u8; 4] {
|
|
||||||
self.secondary_color(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Background color for the maximize button.
|
|
||||||
fn maximize_button_color(&self, status: ButtonState) -> [u8; 4];
|
|
||||||
|
|
||||||
/// Icon color for the maximize button, defaults to the secondary color.
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
fn maximize_button_icon_color(&self, status: ButtonState) -> [u8; 4] {
|
|
||||||
self.secondary_color(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Background color for the minimize button.
|
|
||||||
fn minimize_button_color(&self, status: ButtonState) -> [u8; 4];
|
|
||||||
|
|
||||||
/// Icon color for the minimize button, defaults to the secondary color.
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
fn minimize_button_icon_color(&self, status: ButtonState) -> [u8; 4] {
|
|
||||||
self.secondary_color(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Theme> SCTKTheme for WaylandTheme<T> {
|
|
||||||
fn get_primary_color(&self, active: bool) -> [u8; 4] {
|
|
||||||
self.0.primary_color(active)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_secondary_color(&self, active: bool) -> [u8; 4] {
|
|
||||||
self.0.secondary_color(active)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_close_button_color(&self, status: SCTKButtonState) -> [u8; 4] {
|
|
||||||
self.0.close_button_color(ButtonState::from_sctk(status))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_close_button_icon_color(&self, status: SCTKButtonState) -> [u8; 4] {
|
|
||||||
self.0
|
|
||||||
.close_button_icon_color(ButtonState::from_sctk(status))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_maximize_button_color(&self, status: SCTKButtonState) -> [u8; 4] {
|
|
||||||
self.0.maximize_button_color(ButtonState::from_sctk(status))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_maximize_button_icon_color(&self, status: SCTKButtonState) -> [u8; 4] {
|
|
||||||
self.0
|
|
||||||
.maximize_button_icon_color(ButtonState::from_sctk(status))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_minimize_button_color(&self, status: SCTKButtonState) -> [u8; 4] {
|
|
||||||
self.0.minimize_button_color(ButtonState::from_sctk(status))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_minimize_button_icon_color(&self, status: SCTKButtonState) -> [u8; 4] {
|
|
||||||
self.0
|
|
||||||
.minimize_button_icon_color(ButtonState::from_sctk(status))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum ButtonState {
|
|
||||||
/// Button is being hovered over by pointer.
|
|
||||||
Hovered,
|
|
||||||
/// Button is not being hovered over by pointer.
|
|
||||||
Idle,
|
|
||||||
/// Button is disabled.
|
|
||||||
Disabled,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ButtonState {
|
|
||||||
fn from_sctk(button_state: SCTKButtonState) -> Self {
|
|
||||||
match button_state {
|
|
||||||
SCTKButtonState::Hovered => Self::Hovered,
|
|
||||||
SCTKButtonState::Idle => Self::Idle,
|
|
||||||
SCTKButtonState::Disabled => Self::Disabled,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
#![cfg(target_arch = "wasm32")]
|
|
||||||
|
|
||||||
//! The web target does not automatically insert the canvas element object into the web page, to
|
|
||||||
//! allow end users to determine how the page should be laid out. Use the `WindowExtStdweb` or
|
|
||||||
//! `WindowExtWebSys` traits (depending on your web backend) to retrieve the canvas from the
|
|
||||||
//! Window. Alternatively, use the `WindowBuilderExtStdweb` or `WindowBuilderExtWebSys` to provide
|
|
||||||
//! your own canvas.
|
|
||||||
|
|
||||||
use crate::window::WindowBuilder;
|
|
||||||
|
|
||||||
#[cfg(feature = "stdweb")]
|
|
||||||
use stdweb::web::html_element::CanvasElement;
|
|
||||||
|
|
||||||
#[cfg(feature = "stdweb")]
|
|
||||||
pub trait WindowExtStdweb {
|
|
||||||
fn canvas(&self) -> CanvasElement;
|
|
||||||
|
|
||||||
/// Whether the browser reports the preferred color scheme to be "dark".
|
|
||||||
fn is_dark_mode(&self) -> bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "web-sys")]
|
|
||||||
use web_sys::HtmlCanvasElement;
|
|
||||||
|
|
||||||
#[cfg(feature = "web-sys")]
|
|
||||||
pub trait WindowExtWebSys {
|
|
||||||
fn canvas(&self) -> HtmlCanvasElement;
|
|
||||||
|
|
||||||
/// Whether the browser reports the preferred color scheme to be "dark".
|
|
||||||
fn is_dark_mode(&self) -> bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "stdweb")]
|
|
||||||
pub trait WindowBuilderExtStdweb {
|
|
||||||
fn with_canvas(self, canvas: Option<CanvasElement>) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "stdweb")]
|
|
||||||
impl WindowBuilderExtStdweb for WindowBuilder {
|
|
||||||
fn with_canvas(mut self, canvas: Option<CanvasElement>) -> Self {
|
|
||||||
self.platform_specific.canvas = canvas;
|
|
||||||
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "web-sys")]
|
|
||||||
pub trait WindowBuilderExtWebSys {
|
|
||||||
fn with_canvas(self, canvas: Option<HtmlCanvasElement>) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "web-sys")]
|
|
||||||
impl WindowBuilderExtWebSys for WindowBuilder {
|
|
||||||
fn with_canvas(mut self, canvas: Option<HtmlCanvasElement>) -> Self {
|
|
||||||
self.platform_specific.canvas = canvas;
|
|
||||||
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,213 +0,0 @@
|
|||||||
#![cfg(target_os = "windows")]
|
|
||||||
|
|
||||||
use std::os::raw::c_void;
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use libc;
|
|
||||||
use winapi::shared::minwindef::WORD;
|
|
||||||
use winapi::shared::windef::HWND;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
dpi::PhysicalSize,
|
|
||||||
event::DeviceId,
|
|
||||||
event_loop::EventLoop,
|
|
||||||
monitor::MonitorHandle,
|
|
||||||
platform_impl::{EventLoop as WindowsEventLoop, WinIcon},
|
|
||||||
window::{BadIcon, Icon, Window, WindowBuilder},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Additional methods on `EventLoop` that are specific to Windows.
|
|
||||||
pub trait EventLoopExtWindows {
|
|
||||||
/// Creates an event loop off of the main thread.
|
|
||||||
///
|
|
||||||
/// # `Window` caveats
|
|
||||||
///
|
|
||||||
/// Note that any `Window` created on the new thread will be destroyed when the thread
|
|
||||||
/// terminates. Attempting to use a `Window` after its parent thread terminates has
|
|
||||||
/// unspecified, although explicitly not undefined, behavior.
|
|
||||||
fn new_any_thread() -> Self
|
|
||||||
where
|
|
||||||
Self: Sized;
|
|
||||||
|
|
||||||
/// By default, winit on Windows will attempt to enable process-wide DPI awareness. If that's
|
|
||||||
/// undesirable, you can create an `EventLoop` using this function instead.
|
|
||||||
fn new_dpi_unaware() -> Self
|
|
||||||
where
|
|
||||||
Self: Sized;
|
|
||||||
|
|
||||||
/// Creates a DPI-unaware event loop off of the main thread.
|
|
||||||
///
|
|
||||||
/// The `Window` caveats in [`new_any_thread`](EventLoopExtWindows::new_any_thread) also apply here.
|
|
||||||
fn new_dpi_unaware_any_thread() -> Self
|
|
||||||
where
|
|
||||||
Self: Sized;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> EventLoopExtWindows for EventLoop<T> {
|
|
||||||
#[inline]
|
|
||||||
fn new_any_thread() -> Self {
|
|
||||||
EventLoop {
|
|
||||||
event_loop: WindowsEventLoop::new_any_thread(),
|
|
||||||
_marker: ::std::marker::PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn new_dpi_unaware() -> Self {
|
|
||||||
EventLoop {
|
|
||||||
event_loop: WindowsEventLoop::new_dpi_unaware(),
|
|
||||||
_marker: ::std::marker::PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn new_dpi_unaware_any_thread() -> Self {
|
|
||||||
EventLoop {
|
|
||||||
event_loop: WindowsEventLoop::new_dpi_unaware_any_thread(),
|
|
||||||
_marker: ::std::marker::PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on `Window` that are specific to Windows.
|
|
||||||
pub trait WindowExtWindows {
|
|
||||||
/// Returns the HINSTANCE of the window
|
|
||||||
fn hinstance(&self) -> *mut libc::c_void;
|
|
||||||
/// Returns the native handle that is used by this window.
|
|
||||||
///
|
|
||||||
/// The pointer will become invalid when the native window was destroyed.
|
|
||||||
fn hwnd(&self) -> *mut libc::c_void;
|
|
||||||
|
|
||||||
/// This sets `ICON_BIG`. A good ceiling here is 256x256.
|
|
||||||
fn set_taskbar_icon(&self, taskbar_icon: Option<Icon>);
|
|
||||||
|
|
||||||
/// Whether the system theme is currently Windows 10's "Dark Mode".
|
|
||||||
fn is_dark_mode(&self) -> bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WindowExtWindows for Window {
|
|
||||||
#[inline]
|
|
||||||
fn hinstance(&self) -> *mut libc::c_void {
|
|
||||||
self.window.hinstance() as *mut _
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn hwnd(&self) -> *mut libc::c_void {
|
|
||||||
self.window.hwnd() as *mut _
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn set_taskbar_icon(&self, taskbar_icon: Option<Icon>) {
|
|
||||||
self.window.set_taskbar_icon(taskbar_icon)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn is_dark_mode(&self) -> bool {
|
|
||||||
self.window.is_dark_mode()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on `WindowBuilder` that are specific to Windows.
|
|
||||||
pub trait WindowBuilderExtWindows {
|
|
||||||
/// Sets a parent to the window to be created.
|
|
||||||
fn with_parent_window(self, parent: HWND) -> WindowBuilder;
|
|
||||||
|
|
||||||
/// This sets `ICON_BIG`. A good ceiling here is 256x256.
|
|
||||||
fn with_taskbar_icon(self, taskbar_icon: Option<Icon>) -> WindowBuilder;
|
|
||||||
|
|
||||||
/// This sets `WS_EX_NOREDIRECTIONBITMAP`.
|
|
||||||
fn with_no_redirection_bitmap(self, flag: bool) -> WindowBuilder;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WindowBuilderExtWindows for WindowBuilder {
|
|
||||||
#[inline]
|
|
||||||
fn with_parent_window(mut self, parent: HWND) -> WindowBuilder {
|
|
||||||
self.platform_specific.parent = Some(parent);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_taskbar_icon(mut self, taskbar_icon: Option<Icon>) -> WindowBuilder {
|
|
||||||
self.platform_specific.taskbar_icon = taskbar_icon;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn with_no_redirection_bitmap(mut self, flag: bool) -> WindowBuilder {
|
|
||||||
self.platform_specific.no_redirection_bitmap = flag;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on `MonitorHandle` that are specific to Windows.
|
|
||||||
pub trait MonitorHandleExtWindows {
|
|
||||||
/// Returns the name of the monitor adapter specific to the Win32 API.
|
|
||||||
fn native_id(&self) -> String;
|
|
||||||
|
|
||||||
/// Returns the handle of the monitor - `HMONITOR`.
|
|
||||||
fn hmonitor(&self) -> *mut c_void;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MonitorHandleExtWindows for MonitorHandle {
|
|
||||||
#[inline]
|
|
||||||
fn native_id(&self) -> String {
|
|
||||||
self.inner.native_identifier()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn hmonitor(&self) -> *mut c_void {
|
|
||||||
self.inner.hmonitor() as *mut _
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on `DeviceId` that are specific to Windows.
|
|
||||||
pub trait DeviceIdExtWindows {
|
|
||||||
/// Returns an identifier that persistently refers to this specific device.
|
|
||||||
///
|
|
||||||
/// Will return `None` if the device is no longer available.
|
|
||||||
fn persistent_identifier(&self) -> Option<String>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DeviceIdExtWindows for DeviceId {
|
|
||||||
#[inline]
|
|
||||||
fn persistent_identifier(&self) -> Option<String> {
|
|
||||||
self.0.persistent_identifier()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Additional methods on `Icon` that are specific to Windows.
|
|
||||||
pub trait IconExtWindows: Sized {
|
|
||||||
/// Create an icon from a file path.
|
|
||||||
///
|
|
||||||
/// Specify `size` to load a specific icon size from the file, or `None` to load the default
|
|
||||||
/// icon size from the file.
|
|
||||||
///
|
|
||||||
/// In cases where the specified size does not exist in the file, Windows may perform scaling
|
|
||||||
/// to get an icon of the desired size.
|
|
||||||
fn from_path<P: AsRef<Path>>(path: P, size: Option<PhysicalSize<u32>>)
|
|
||||||
-> Result<Self, BadIcon>;
|
|
||||||
|
|
||||||
/// Create an icon from a resource embedded in this executable or library.
|
|
||||||
///
|
|
||||||
/// Specify `size` to load a specific icon size from the file, or `None` to load the default
|
|
||||||
/// icon size from the file.
|
|
||||||
///
|
|
||||||
/// In cases where the specified size does not exist in the file, Windows may perform scaling
|
|
||||||
/// to get an icon of the desired size.
|
|
||||||
fn from_resource(ordinal: WORD, size: Option<PhysicalSize<u32>>) -> Result<Self, BadIcon>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IconExtWindows for Icon {
|
|
||||||
fn from_path<P: AsRef<Path>>(
|
|
||||||
path: P,
|
|
||||||
size: Option<PhysicalSize<u32>>,
|
|
||||||
) -> Result<Self, BadIcon> {
|
|
||||||
let win_icon = WinIcon::from_path(path, size)?;
|
|
||||||
Ok(Icon { inner: win_icon })
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_resource(ordinal: WORD, size: Option<PhysicalSize<u32>>) -> Result<Self, BadIcon> {
|
|
||||||
let win_icon = WinIcon::from_resource(ordinal, size)?;
|
|
||||||
Ok(Icon { inner: win_icon })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,519 +0,0 @@
|
|||||||
#![cfg(target_os = "android")]
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
|
|
||||||
error, event,
|
|
||||||
event_loop::{self, ControlFlow},
|
|
||||||
monitor, window,
|
|
||||||
};
|
|
||||||
use ndk::{
|
|
||||||
configuration::Configuration,
|
|
||||||
event::{InputEvent, MotionAction},
|
|
||||||
looper::{ForeignLooper, Poll, ThreadLooper},
|
|
||||||
};
|
|
||||||
use ndk_glue::{Event, Rect};
|
|
||||||
use std::{
|
|
||||||
collections::VecDeque,
|
|
||||||
sync::{Arc, Mutex, RwLock},
|
|
||||||
time::{Duration, Instant},
|
|
||||||
};
|
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
static ref CONFIG: RwLock<Configuration> = RwLock::new(Configuration::new());
|
|
||||||
}
|
|
||||||
|
|
||||||
enum EventSource {
|
|
||||||
Callback,
|
|
||||||
InputQueue,
|
|
||||||
User,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn poll(poll: Poll) -> Option<EventSource> {
|
|
||||||
match poll {
|
|
||||||
Poll::Event { data, .. } => match data as usize {
|
|
||||||
0 => Some(EventSource::Callback),
|
|
||||||
1 => Some(EventSource::InputQueue),
|
|
||||||
_ => unreachable!(),
|
|
||||||
},
|
|
||||||
Poll::Timeout => None,
|
|
||||||
Poll::Wake => Some(EventSource::User),
|
|
||||||
Poll::Callback => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct EventLoop<T: 'static> {
|
|
||||||
window_target: event_loop::EventLoopWindowTarget<T>,
|
|
||||||
user_queue: Arc<Mutex<VecDeque<T>>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: 'static> EventLoop<T> {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
window_target: event_loop::EventLoopWindowTarget {
|
|
||||||
p: EventLoopWindowTarget {
|
|
||||||
_marker: std::marker::PhantomData,
|
|
||||||
},
|
|
||||||
_marker: std::marker::PhantomData,
|
|
||||||
},
|
|
||||||
user_queue: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run<F>(self, mut event_handler: F) -> !
|
|
||||||
where
|
|
||||||
F: 'static
|
|
||||||
+ FnMut(event::Event<'_, T>, &event_loop::EventLoopWindowTarget<T>, &mut ControlFlow),
|
|
||||||
{
|
|
||||||
let mut cf = ControlFlow::default();
|
|
||||||
let mut first_event = None;
|
|
||||||
let mut start_cause = event::StartCause::Init;
|
|
||||||
let looper = ThreadLooper::for_thread().unwrap();
|
|
||||||
let mut running = false;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
event_handler(
|
|
||||||
event::Event::NewEvents(start_cause),
|
|
||||||
self.window_target(),
|
|
||||||
&mut cf,
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut redraw = false;
|
|
||||||
let mut resized = false;
|
|
||||||
|
|
||||||
match first_event.take() {
|
|
||||||
Some(EventSource::Callback) => match ndk_glue::poll_events().unwrap() {
|
|
||||||
Event::WindowCreated => {
|
|
||||||
event_handler(event::Event::Resumed, self.window_target(), &mut cf);
|
|
||||||
}
|
|
||||||
Event::WindowResized => resized = true,
|
|
||||||
Event::WindowRedrawNeeded => redraw = true,
|
|
||||||
Event::WindowDestroyed => {
|
|
||||||
event_handler(event::Event::Suspended, self.window_target(), &mut cf);
|
|
||||||
}
|
|
||||||
Event::Pause => running = false,
|
|
||||||
Event::Resume => running = true,
|
|
||||||
Event::ConfigChanged => {
|
|
||||||
let am = ndk_glue::native_activity().asset_manager();
|
|
||||||
let config = Configuration::from_asset_manager(&am);
|
|
||||||
let old_scale_factor = MonitorHandle.scale_factor();
|
|
||||||
*CONFIG.write().unwrap() = config;
|
|
||||||
let scale_factor = MonitorHandle.scale_factor();
|
|
||||||
if (scale_factor - old_scale_factor).abs() < f64::EPSILON {
|
|
||||||
let mut size = MonitorHandle.size();
|
|
||||||
let event = event::Event::WindowEvent {
|
|
||||||
window_id: window::WindowId(WindowId),
|
|
||||||
event: event::WindowEvent::ScaleFactorChanged {
|
|
||||||
new_inner_size: &mut size,
|
|
||||||
scale_factor,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
event_handler(event, self.window_target(), &mut cf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
},
|
|
||||||
Some(EventSource::InputQueue) => {
|
|
||||||
if let Some(input_queue) = ndk_glue::input_queue().as_ref() {
|
|
||||||
while let Some(event) = input_queue.get_event() {
|
|
||||||
println!("event {:?}", event);
|
|
||||||
if let Some(event) = input_queue.pre_dispatch(event) {
|
|
||||||
let window_id = window::WindowId(WindowId);
|
|
||||||
let device_id = event::DeviceId(DeviceId);
|
|
||||||
match &event {
|
|
||||||
InputEvent::MotionEvent(motion_event) => {
|
|
||||||
let phase = match motion_event.action() {
|
|
||||||
MotionAction::Down => Some(event::TouchPhase::Started),
|
|
||||||
MotionAction::Up => Some(event::TouchPhase::Ended),
|
|
||||||
MotionAction::Move => Some(event::TouchPhase::Moved),
|
|
||||||
MotionAction::Cancel => {
|
|
||||||
Some(event::TouchPhase::Cancelled)
|
|
||||||
}
|
|
||||||
_ => None, // TODO mouse events
|
|
||||||
};
|
|
||||||
let pointer = motion_event.pointer_at_index(0);
|
|
||||||
let location = PhysicalPosition {
|
|
||||||
x: pointer.x() as _,
|
|
||||||
y: pointer.y() as _,
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(phase) = phase {
|
|
||||||
let event = event::Event::WindowEvent {
|
|
||||||
window_id,
|
|
||||||
event: event::WindowEvent::Touch(event::Touch {
|
|
||||||
device_id,
|
|
||||||
phase,
|
|
||||||
location,
|
|
||||||
id: 0,
|
|
||||||
force: None,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
event_handler(event, self.window_target(), &mut cf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
InputEvent::KeyEvent(_) => {} // TODO
|
|
||||||
};
|
|
||||||
input_queue.finish_event(event, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(EventSource::User) => {
|
|
||||||
let mut user_queue = self.user_queue.lock().unwrap();
|
|
||||||
while let Some(event) = user_queue.pop_front() {
|
|
||||||
event_handler(
|
|
||||||
event::Event::UserEvent(event),
|
|
||||||
self.window_target(),
|
|
||||||
&mut cf,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
event_handler(
|
|
||||||
event::Event::MainEventsCleared,
|
|
||||||
self.window_target(),
|
|
||||||
&mut cf,
|
|
||||||
);
|
|
||||||
|
|
||||||
if resized && running {
|
|
||||||
let size = MonitorHandle.size();
|
|
||||||
let event = event::Event::WindowEvent {
|
|
||||||
window_id: window::WindowId(WindowId),
|
|
||||||
event: event::WindowEvent::Resized(size),
|
|
||||||
};
|
|
||||||
event_handler(event, self.window_target(), &mut cf);
|
|
||||||
}
|
|
||||||
|
|
||||||
if redraw && running {
|
|
||||||
let event = event::Event::RedrawRequested(window::WindowId(WindowId));
|
|
||||||
event_handler(event, self.window_target(), &mut cf);
|
|
||||||
}
|
|
||||||
|
|
||||||
event_handler(
|
|
||||||
event::Event::RedrawEventsCleared,
|
|
||||||
self.window_target(),
|
|
||||||
&mut cf,
|
|
||||||
);
|
|
||||||
|
|
||||||
match cf {
|
|
||||||
ControlFlow::Exit => panic!(),
|
|
||||||
ControlFlow::Poll => {
|
|
||||||
start_cause = event::StartCause::Poll;
|
|
||||||
}
|
|
||||||
ControlFlow::Wait => {
|
|
||||||
first_event = poll(looper.poll_all().unwrap());
|
|
||||||
start_cause = event::StartCause::WaitCancelled {
|
|
||||||
start: Instant::now(),
|
|
||||||
requested_resume: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ControlFlow::WaitUntil(instant) => {
|
|
||||||
let start = Instant::now();
|
|
||||||
let duration = if instant <= start {
|
|
||||||
Duration::default()
|
|
||||||
} else {
|
|
||||||
instant - start
|
|
||||||
};
|
|
||||||
first_event = poll(looper.poll_all_timeout(duration).unwrap());
|
|
||||||
start_cause = if first_event.is_some() {
|
|
||||||
event::StartCause::WaitCancelled {
|
|
||||||
start,
|
|
||||||
requested_resume: Some(instant),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
event::StartCause::ResumeTimeReached {
|
|
||||||
start,
|
|
||||||
requested_resume: instant,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn window_target(&self) -> &event_loop::EventLoopWindowTarget<T> {
|
|
||||||
&self.window_target
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn primary_monitor(&self) -> MonitorHandle {
|
|
||||||
MonitorHandle
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
|
|
||||||
let mut v = VecDeque::with_capacity(1);
|
|
||||||
v.push_back(self.primary_monitor());
|
|
||||||
v
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create_proxy(&self) -> EventLoopProxy<T> {
|
|
||||||
EventLoopProxy {
|
|
||||||
queue: self.user_queue.clone(),
|
|
||||||
looper: ForeignLooper::for_thread().expect("called from event loop thread"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct EventLoopProxy<T: 'static> {
|
|
||||||
queue: Arc<Mutex<VecDeque<T>>>,
|
|
||||||
looper: ForeignLooper,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> EventLoopProxy<T> {
|
|
||||||
pub fn send_event(&self, event: T) -> Result<(), event_loop::EventLoopClosed<T>> {
|
|
||||||
self.queue.lock().unwrap().push_back(event);
|
|
||||||
self.looper.wake();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Clone for EventLoopProxy<T> {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
EventLoopProxy {
|
|
||||||
queue: self.queue.clone(),
|
|
||||||
looper: self.looper.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct EventLoopWindowTarget<T: 'static> {
|
|
||||||
_marker: std::marker::PhantomData<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
|
||||||
pub struct WindowId;
|
|
||||||
|
|
||||||
impl WindowId {
|
|
||||||
pub fn dummy() -> Self {
|
|
||||||
WindowId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
|
||||||
pub struct DeviceId;
|
|
||||||
|
|
||||||
impl DeviceId {
|
|
||||||
pub fn dummy() -> Self {
|
|
||||||
DeviceId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
|
||||||
pub struct PlatformSpecificWindowBuilderAttributes;
|
|
||||||
|
|
||||||
pub struct Window;
|
|
||||||
|
|
||||||
impl Window {
|
|
||||||
pub fn new<T: 'static>(
|
|
||||||
_el: &EventLoopWindowTarget<T>,
|
|
||||||
_window_attrs: window::WindowAttributes,
|
|
||||||
_: PlatformSpecificWindowBuilderAttributes,
|
|
||||||
) -> Result<Self, error::OsError> {
|
|
||||||
// FIXME this ignores requested window attributes
|
|
||||||
Ok(Self)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn id(&self) -> WindowId {
|
|
||||||
WindowId
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn primary_monitor(&self) -> MonitorHandle {
|
|
||||||
MonitorHandle
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
|
|
||||||
let mut v = VecDeque::with_capacity(1);
|
|
||||||
v.push_back(MonitorHandle);
|
|
||||||
v
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn current_monitor(&self) -> monitor::MonitorHandle {
|
|
||||||
monitor::MonitorHandle {
|
|
||||||
inner: MonitorHandle,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn scale_factor(&self) -> f64 {
|
|
||||||
MonitorHandle.scale_factor()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn request_redraw(&self) {
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, error::NotSupportedError> {
|
|
||||||
Err(error::NotSupportedError::new())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, error::NotSupportedError> {
|
|
||||||
Err(error::NotSupportedError::new())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_outer_position(&self, _position: Position) {
|
|
||||||
// no effect
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn inner_size(&self) -> PhysicalSize<u32> {
|
|
||||||
self.outer_size()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_inner_size(&self, _size: Size) {
|
|
||||||
panic!("Cannot set window size on Android");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn outer_size(&self) -> PhysicalSize<u32> {
|
|
||||||
MonitorHandle.size()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_min_inner_size(&self, _: Option<Size>) {}
|
|
||||||
|
|
||||||
pub fn set_max_inner_size(&self, _: Option<Size>) {}
|
|
||||||
|
|
||||||
pub fn set_title(&self, _title: &str) {}
|
|
||||||
|
|
||||||
pub fn set_visible(&self, _visibility: bool) {}
|
|
||||||
|
|
||||||
pub fn set_resizable(&self, _resizeable: bool) {}
|
|
||||||
|
|
||||||
pub fn set_minimized(&self, _minimized: bool) {}
|
|
||||||
|
|
||||||
pub fn set_maximized(&self, _maximized: bool) {}
|
|
||||||
|
|
||||||
pub fn set_fullscreen(&self, _monitor: Option<window::Fullscreen>) {
|
|
||||||
panic!("Cannot set fullscreen on Android");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn fullscreen(&self) -> Option<window::Fullscreen> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_decorations(&self, _decorations: bool) {}
|
|
||||||
|
|
||||||
pub fn set_always_on_top(&self, _always_on_top: bool) {}
|
|
||||||
|
|
||||||
pub fn set_window_icon(&self, _window_icon: Option<crate::icon::Icon>) {}
|
|
||||||
|
|
||||||
pub fn set_ime_position(&self, _position: Position) {}
|
|
||||||
|
|
||||||
pub fn set_cursor_icon(&self, _: window::CursorIcon) {}
|
|
||||||
|
|
||||||
pub fn set_cursor_position(&self, _: Position) -> Result<(), error::ExternalError> {
|
|
||||||
Err(error::ExternalError::NotSupported(
|
|
||||||
error::NotSupportedError::new(),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_cursor_grab(&self, _: bool) -> Result<(), error::ExternalError> {
|
|
||||||
Err(error::ExternalError::NotSupported(
|
|
||||||
error::NotSupportedError::new(),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_cursor_visible(&self, _: bool) {}
|
|
||||||
|
|
||||||
pub fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
|
|
||||||
let a_native_window = if let Some(native_window) = ndk_glue::native_window().as_ref() {
|
|
||||||
unsafe { native_window.ptr().as_mut() as *mut _ as *mut _ }
|
|
||||||
} else {
|
|
||||||
panic!("native window null");
|
|
||||||
};
|
|
||||||
let mut handle = raw_window_handle::android::AndroidHandle::empty();
|
|
||||||
handle.a_native_window = a_native_window;
|
|
||||||
raw_window_handle::RawWindowHandle::Android(handle)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn config(&self) -> Configuration {
|
|
||||||
CONFIG.read().unwrap().clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn content_rect(&self) -> Rect {
|
|
||||||
ndk_glue::content_rect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default, Clone, Debug)]
|
|
||||||
pub struct OsError;
|
|
||||||
|
|
||||||
use std::fmt::{self, Display, Formatter};
|
|
||||||
impl Display for OsError {
|
|
||||||
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), fmt::Error> {
|
|
||||||
write!(fmt, "Android OS Error")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) use crate::icon::NoIcon as PlatformIcon;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
|
||||||
pub struct MonitorHandle;
|
|
||||||
|
|
||||||
impl MonitorHandle {
|
|
||||||
pub fn name(&self) -> Option<String> {
|
|
||||||
Some("Android Device".to_owned())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn size(&self) -> PhysicalSize<u32> {
|
|
||||||
if let Some(native_window) = ndk_glue::native_window().as_ref() {
|
|
||||||
let width = native_window.width() as _;
|
|
||||||
let height = native_window.height() as _;
|
|
||||||
PhysicalSize::new(width, height)
|
|
||||||
} else {
|
|
||||||
PhysicalSize::new(0, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn position(&self) -> PhysicalPosition<i32> {
|
|
||||||
(0, 0).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn scale_factor(&self) -> f64 {
|
|
||||||
let config = CONFIG.read().unwrap();
|
|
||||||
config
|
|
||||||
.density()
|
|
||||||
.map(|dpi| dpi as f64 / 160.0)
|
|
||||||
.unwrap_or(1.0)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn video_modes(&self) -> impl Iterator<Item = monitor::VideoMode> {
|
|
||||||
let size = self.size().into();
|
|
||||||
let mut v = Vec::new();
|
|
||||||
// FIXME this is not the real refresh rate
|
|
||||||
// (it is guarunteed to support 32 bit color though)
|
|
||||||
v.push(monitor::VideoMode {
|
|
||||||
video_mode: VideoMode {
|
|
||||||
size,
|
|
||||||
bit_depth: 32,
|
|
||||||
refresh_rate: 60,
|
|
||||||
monitor: self.clone(),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
v.into_iter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
|
||||||
pub struct VideoMode {
|
|
||||||
size: (u32, u32),
|
|
||||||
bit_depth: u16,
|
|
||||||
refresh_rate: u16,
|
|
||||||
monitor: MonitorHandle,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VideoMode {
|
|
||||||
pub fn size(&self) -> PhysicalSize<u32> {
|
|
||||||
self.size.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bit_depth(&self) -> u16 {
|
|
||||||
self.bit_depth
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn refresh_rate(&self) -> u16 {
|
|
||||||
self.refresh_rate
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn monitor(&self) -> monitor::MonitorHandle {
|
|
||||||
monitor::MonitorHandle {
|
|
||||||
inner: self.monitor.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,338 +0,0 @@
|
|||||||
use std::{
|
|
||||||
collections::VecDeque,
|
|
||||||
ffi::c_void,
|
|
||||||
fmt::{self, Debug},
|
|
||||||
marker::PhantomData,
|
|
||||||
mem, ptr,
|
|
||||||
sync::mpsc::{self, Receiver, Sender},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
dpi::LogicalSize,
|
|
||||||
event::Event,
|
|
||||||
event_loop::{
|
|
||||||
ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootEventLoopWindowTarget,
|
|
||||||
},
|
|
||||||
platform::ios::Idiom,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::platform_impl::platform::{
|
|
||||||
app_state,
|
|
||||||
ffi::{
|
|
||||||
id, kCFRunLoopAfterWaiting, kCFRunLoopBeforeWaiting, kCFRunLoopCommonModes,
|
|
||||||
kCFRunLoopDefaultMode, kCFRunLoopEntry, kCFRunLoopExit, nil, CFIndex, CFRelease,
|
|
||||||
CFRunLoopActivity, CFRunLoopAddObserver, CFRunLoopAddSource, CFRunLoopGetMain,
|
|
||||||
CFRunLoopObserverCreate, CFRunLoopObserverRef, CFRunLoopSourceContext,
|
|
||||||
CFRunLoopSourceCreate, CFRunLoopSourceInvalidate, CFRunLoopSourceRef,
|
|
||||||
CFRunLoopSourceSignal, CFRunLoopWakeUp, NSString, UIApplicationMain, UIUserInterfaceIdiom,
|
|
||||||
},
|
|
||||||
monitor, view, MonitorHandle,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum EventWrapper {
|
|
||||||
StaticEvent(Event<'static, Never>),
|
|
||||||
EventProxy(EventProxy),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub enum EventProxy {
|
|
||||||
DpiChangedProxy {
|
|
||||||
window_id: id,
|
|
||||||
suggested_size: LogicalSize<f64>,
|
|
||||||
scale_factor: f64,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct EventLoopWindowTarget<T: 'static> {
|
|
||||||
receiver: Receiver<T>,
|
|
||||||
sender_to_clone: Sender<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct EventLoop<T: 'static> {
|
|
||||||
window_target: RootEventLoopWindowTarget<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: 'static> EventLoop<T> {
|
|
||||||
pub fn new() -> EventLoop<T> {
|
|
||||||
static mut SINGLETON_INIT: bool = false;
|
|
||||||
unsafe {
|
|
||||||
assert_main_thread!("`EventLoop` can only be created on the main thread on iOS");
|
|
||||||
assert!(
|
|
||||||
!SINGLETON_INIT,
|
|
||||||
"Only one `EventLoop` is supported on iOS. \
|
|
||||||
`EventLoopProxy` might be helpful"
|
|
||||||
);
|
|
||||||
SINGLETON_INIT = true;
|
|
||||||
view::create_delegate_class();
|
|
||||||
}
|
|
||||||
|
|
||||||
let (sender_to_clone, receiver) = mpsc::channel();
|
|
||||||
|
|
||||||
// this line sets up the main run loop before `UIApplicationMain`
|
|
||||||
setup_control_flow_observers();
|
|
||||||
|
|
||||||
EventLoop {
|
|
||||||
window_target: RootEventLoopWindowTarget {
|
|
||||||
p: EventLoopWindowTarget {
|
|
||||||
receiver,
|
|
||||||
sender_to_clone,
|
|
||||||
},
|
|
||||||
_marker: PhantomData,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run<F>(self, event_handler: F) -> !
|
|
||||||
where
|
|
||||||
F: 'static + FnMut(Event<'_, T>, &RootEventLoopWindowTarget<T>, &mut ControlFlow),
|
|
||||||
{
|
|
||||||
unsafe {
|
|
||||||
let application: *mut c_void = msg_send![class!(UIApplication), sharedApplication];
|
|
||||||
assert_eq!(
|
|
||||||
application,
|
|
||||||
ptr::null_mut(),
|
|
||||||
"\
|
|
||||||
`EventLoop` cannot be `run` after a call to `UIApplicationMain` on iOS\n\
|
|
||||||
Note: `EventLoop::run` calls `UIApplicationMain` on iOS"
|
|
||||||
);
|
|
||||||
app_state::will_launch(Box::new(EventLoopHandler {
|
|
||||||
f: event_handler,
|
|
||||||
event_loop: self.window_target,
|
|
||||||
}));
|
|
||||||
|
|
||||||
UIApplicationMain(
|
|
||||||
0,
|
|
||||||
ptr::null(),
|
|
||||||
nil,
|
|
||||||
NSString::alloc(nil).init_str("AppDelegate"),
|
|
||||||
);
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create_proxy(&self) -> EventLoopProxy<T> {
|
|
||||||
EventLoopProxy::new(self.window_target.p.sender_to_clone.clone())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
|
|
||||||
// guaranteed to be on main thread
|
|
||||||
unsafe { monitor::uiscreens() }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn primary_monitor(&self) -> MonitorHandle {
|
|
||||||
// guaranteed to be on main thread
|
|
||||||
unsafe { monitor::main_uiscreen() }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn window_target(&self) -> &RootEventLoopWindowTarget<T> {
|
|
||||||
&self.window_target
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// EventLoopExtIOS
|
|
||||||
impl<T: 'static> EventLoop<T> {
|
|
||||||
pub fn idiom(&self) -> Idiom {
|
|
||||||
// guaranteed to be on main thread
|
|
||||||
unsafe { self::get_idiom() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct EventLoopProxy<T> {
|
|
||||||
sender: Sender<T>,
|
|
||||||
source: CFRunLoopSourceRef,
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl<T: Send> Send for EventLoopProxy<T> {}
|
|
||||||
|
|
||||||
impl<T> Clone for EventLoopProxy<T> {
|
|
||||||
fn clone(&self) -> EventLoopProxy<T> {
|
|
||||||
EventLoopProxy::new(self.sender.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Drop for EventLoopProxy<T> {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
unsafe {
|
|
||||||
CFRunLoopSourceInvalidate(self.source);
|
|
||||||
CFRelease(self.source as _);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> EventLoopProxy<T> {
|
|
||||||
fn new(sender: Sender<T>) -> EventLoopProxy<T> {
|
|
||||||
unsafe {
|
|
||||||
// just wake up the eventloop
|
|
||||||
extern "C" fn event_loop_proxy_handler(_: *mut c_void) {}
|
|
||||||
|
|
||||||
// adding a Source to the main CFRunLoop lets us wake it up and
|
|
||||||
// process user events through the normal OS EventLoop mechanisms.
|
|
||||||
let rl = CFRunLoopGetMain();
|
|
||||||
// we want all the members of context to be zero/null, except one
|
|
||||||
let mut context: CFRunLoopSourceContext = mem::zeroed();
|
|
||||||
context.perform = Some(event_loop_proxy_handler);
|
|
||||||
let source =
|
|
||||||
CFRunLoopSourceCreate(ptr::null_mut(), CFIndex::max_value() - 1, &mut context);
|
|
||||||
CFRunLoopAddSource(rl, source, kCFRunLoopCommonModes);
|
|
||||||
CFRunLoopWakeUp(rl);
|
|
||||||
|
|
||||||
EventLoopProxy { sender, source }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
|
|
||||||
self.sender
|
|
||||||
.send(event)
|
|
||||||
.map_err(|::std::sync::mpsc::SendError(x)| EventLoopClosed(x))?;
|
|
||||||
unsafe {
|
|
||||||
// let the main thread know there's a new event
|
|
||||||
CFRunLoopSourceSignal(self.source);
|
|
||||||
let rl = CFRunLoopGetMain();
|
|
||||||
CFRunLoopWakeUp(rl);
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn setup_control_flow_observers() {
|
|
||||||
unsafe {
|
|
||||||
// begin is queued with the highest priority to ensure it is processed before other observers
|
|
||||||
extern "C" fn control_flow_begin_handler(
|
|
||||||
_: CFRunLoopObserverRef,
|
|
||||||
activity: CFRunLoopActivity,
|
|
||||||
_: *mut c_void,
|
|
||||||
) {
|
|
||||||
unsafe {
|
|
||||||
#[allow(non_upper_case_globals)]
|
|
||||||
match activity {
|
|
||||||
kCFRunLoopAfterWaiting => app_state::handle_wakeup_transition(),
|
|
||||||
kCFRunLoopEntry => unimplemented!(), // not expected to ever happen
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Core Animation registers its `CFRunLoopObserver` that performs drawing operations in
|
|
||||||
// `CA::Transaction::ensure_implicit` with a priority of `0x1e8480`. We set the main_end
|
|
||||||
// priority to be 0, in order to send MainEventsCleared before RedrawRequested. This value was
|
|
||||||
// chosen conservatively to guard against apple using different priorities for their redraw
|
|
||||||
// observers in different OS's or on different devices. If it so happens that it's too
|
|
||||||
// conservative, the main symptom would be non-redraw events coming in after `MainEventsCleared`.
|
|
||||||
//
|
|
||||||
// The value of `0x1e8480` was determined by inspecting stack traces and the associated
|
|
||||||
// registers for every `CFRunLoopAddObserver` call on an iPad Air 2 running iOS 11.4.
|
|
||||||
//
|
|
||||||
// Also tested to be `0x1e8480` on iPhone 8, iOS 13 beta 4.
|
|
||||||
extern "C" fn control_flow_main_end_handler(
|
|
||||||
_: CFRunLoopObserverRef,
|
|
||||||
activity: CFRunLoopActivity,
|
|
||||||
_: *mut c_void,
|
|
||||||
) {
|
|
||||||
unsafe {
|
|
||||||
#[allow(non_upper_case_globals)]
|
|
||||||
match activity {
|
|
||||||
kCFRunLoopBeforeWaiting => app_state::handle_main_events_cleared(),
|
|
||||||
kCFRunLoopExit => unimplemented!(), // not expected to ever happen
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// end is queued with the lowest priority to ensure it is processed after other observers
|
|
||||||
extern "C" fn control_flow_end_handler(
|
|
||||||
_: CFRunLoopObserverRef,
|
|
||||||
activity: CFRunLoopActivity,
|
|
||||||
_: *mut c_void,
|
|
||||||
) {
|
|
||||||
unsafe {
|
|
||||||
#[allow(non_upper_case_globals)]
|
|
||||||
match activity {
|
|
||||||
kCFRunLoopBeforeWaiting => app_state::handle_events_cleared(),
|
|
||||||
kCFRunLoopExit => unimplemented!(), // not expected to ever happen
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let main_loop = CFRunLoopGetMain();
|
|
||||||
|
|
||||||
let begin_observer = CFRunLoopObserverCreate(
|
|
||||||
ptr::null_mut(),
|
|
||||||
kCFRunLoopEntry | kCFRunLoopAfterWaiting,
|
|
||||||
1, // repeat = true
|
|
||||||
CFIndex::min_value(),
|
|
||||||
control_flow_begin_handler,
|
|
||||||
ptr::null_mut(),
|
|
||||||
);
|
|
||||||
CFRunLoopAddObserver(main_loop, begin_observer, kCFRunLoopDefaultMode);
|
|
||||||
|
|
||||||
let main_end_observer = CFRunLoopObserverCreate(
|
|
||||||
ptr::null_mut(),
|
|
||||||
kCFRunLoopExit | kCFRunLoopBeforeWaiting,
|
|
||||||
1, // repeat = true
|
|
||||||
0, // see comment on `control_flow_main_end_handler`
|
|
||||||
control_flow_main_end_handler,
|
|
||||||
ptr::null_mut(),
|
|
||||||
);
|
|
||||||
CFRunLoopAddObserver(main_loop, main_end_observer, kCFRunLoopDefaultMode);
|
|
||||||
|
|
||||||
let end_observer = CFRunLoopObserverCreate(
|
|
||||||
ptr::null_mut(),
|
|
||||||
kCFRunLoopExit | kCFRunLoopBeforeWaiting,
|
|
||||||
1, // repeat = true
|
|
||||||
CFIndex::max_value(),
|
|
||||||
control_flow_end_handler,
|
|
||||||
ptr::null_mut(),
|
|
||||||
);
|
|
||||||
CFRunLoopAddObserver(main_loop, end_observer, kCFRunLoopDefaultMode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Never {}
|
|
||||||
|
|
||||||
pub trait EventHandler: Debug {
|
|
||||||
fn handle_nonuser_event(&mut self, event: Event<'_, Never>, control_flow: &mut ControlFlow);
|
|
||||||
fn handle_user_events(&mut self, control_flow: &mut ControlFlow);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct EventLoopHandler<F, T: 'static> {
|
|
||||||
f: F,
|
|
||||||
event_loop: RootEventLoopWindowTarget<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<F, T: 'static> Debug for EventLoopHandler<F, T> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.debug_struct("EventLoopHandler")
|
|
||||||
.field("event_loop", &self.event_loop)
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<F, T> EventHandler for EventLoopHandler<F, T>
|
|
||||||
where
|
|
||||||
F: 'static + FnMut(Event<'_, T>, &RootEventLoopWindowTarget<T>, &mut ControlFlow),
|
|
||||||
T: 'static,
|
|
||||||
{
|
|
||||||
fn handle_nonuser_event(&mut self, event: Event<'_, Never>, control_flow: &mut ControlFlow) {
|
|
||||||
(self.f)(
|
|
||||||
event.map_nonuser_event().unwrap(),
|
|
||||||
&self.event_loop,
|
|
||||||
control_flow,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_user_events(&mut self, control_flow: &mut ControlFlow) {
|
|
||||||
for event in self.event_loop.p.receiver.try_iter() {
|
|
||||||
(self.f)(Event::UserEvent(event), &self.event_loop, control_flow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// must be called on main thread
|
|
||||||
pub unsafe fn get_idiom() -> Idiom {
|
|
||||||
let device: id = msg_send![class!(UIDevice), currentDevice];
|
|
||||||
let raw_idiom: UIUserInterfaceIdiom = msg_send![device, userInterfaceIdiom];
|
|
||||||
raw_idiom.into()
|
|
||||||
}
|
|
||||||
@@ -1,390 +0,0 @@
|
|||||||
#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
|
|
||||||
|
|
||||||
use std::{convert::TryInto, ffi::CString, ops::BitOr, os::raw::*};
|
|
||||||
|
|
||||||
use objc::{runtime::Object, Encode, Encoding};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
dpi::LogicalSize,
|
|
||||||
platform::ios::{Idiom, ScreenEdge, ValidOrientations},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub type id = *mut Object;
|
|
||||||
pub const nil: id = 0 as id;
|
|
||||||
|
|
||||||
#[cfg(target_pointer_width = "32")]
|
|
||||||
pub type CGFloat = f32;
|
|
||||||
#[cfg(target_pointer_width = "64")]
|
|
||||||
pub type CGFloat = f64;
|
|
||||||
|
|
||||||
pub type NSInteger = isize;
|
|
||||||
pub type NSUInteger = usize;
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct NSOperatingSystemVersion {
|
|
||||||
pub major: NSInteger,
|
|
||||||
pub minor: NSInteger,
|
|
||||||
pub patch: NSInteger,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct CGPoint {
|
|
||||||
pub x: CGFloat,
|
|
||||||
pub y: CGFloat,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct CGSize {
|
|
||||||
pub width: CGFloat,
|
|
||||||
pub height: CGFloat,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CGSize {
|
|
||||||
pub fn new(size: LogicalSize<f64>) -> CGSize {
|
|
||||||
CGSize {
|
|
||||||
width: size.width as _,
|
|
||||||
height: size.height as _,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct CGRect {
|
|
||||||
pub origin: CGPoint,
|
|
||||||
pub size: CGSize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CGRect {
|
|
||||||
pub fn new(origin: CGPoint, size: CGSize) -> CGRect {
|
|
||||||
CGRect { origin, size }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl Encode for CGRect {
|
|
||||||
fn encode() -> Encoding {
|
|
||||||
unsafe {
|
|
||||||
if cfg!(target_pointer_width = "32") {
|
|
||||||
Encoding::from_str("{CGRect={CGPoint=ff}{CGSize=ff}}")
|
|
||||||
} else if cfg!(target_pointer_width = "64") {
|
|
||||||
Encoding::from_str("{CGRect={CGPoint=dd}{CGSize=dd}}")
|
|
||||||
} else {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[derive(Debug)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[repr(isize)]
|
|
||||||
pub enum UITouchPhase {
|
|
||||||
Began = 0,
|
|
||||||
Moved,
|
|
||||||
Stationary,
|
|
||||||
Ended,
|
|
||||||
Cancelled,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[repr(isize)]
|
|
||||||
pub enum UIForceTouchCapability {
|
|
||||||
Unknown = 0,
|
|
||||||
Unavailable,
|
|
||||||
Available,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[repr(isize)]
|
|
||||||
pub enum UITouchType {
|
|
||||||
Direct = 0,
|
|
||||||
Indirect,
|
|
||||||
Pencil,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct UIEdgeInsets {
|
|
||||||
pub top: CGFloat,
|
|
||||||
pub left: CGFloat,
|
|
||||||
pub bottom: CGFloat,
|
|
||||||
pub right: CGFloat,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(transparent)]
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
||||||
pub struct UIUserInterfaceIdiom(NSInteger);
|
|
||||||
|
|
||||||
unsafe impl Encode for UIUserInterfaceIdiom {
|
|
||||||
fn encode() -> Encoding {
|
|
||||||
NSInteger::encode()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UIUserInterfaceIdiom {
|
|
||||||
pub const Unspecified: UIUserInterfaceIdiom = UIUserInterfaceIdiom(-1);
|
|
||||||
pub const Phone: UIUserInterfaceIdiom = UIUserInterfaceIdiom(0);
|
|
||||||
pub const Pad: UIUserInterfaceIdiom = UIUserInterfaceIdiom(1);
|
|
||||||
pub const TV: UIUserInterfaceIdiom = UIUserInterfaceIdiom(2);
|
|
||||||
pub const CarPlay: UIUserInterfaceIdiom = UIUserInterfaceIdiom(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Idiom> for UIUserInterfaceIdiom {
|
|
||||||
fn from(idiom: Idiom) -> UIUserInterfaceIdiom {
|
|
||||||
match idiom {
|
|
||||||
Idiom::Unspecified => UIUserInterfaceIdiom::Unspecified,
|
|
||||||
Idiom::Phone => UIUserInterfaceIdiom::Phone,
|
|
||||||
Idiom::Pad => UIUserInterfaceIdiom::Pad,
|
|
||||||
Idiom::TV => UIUserInterfaceIdiom::TV,
|
|
||||||
Idiom::CarPlay => UIUserInterfaceIdiom::CarPlay,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<Idiom> for UIUserInterfaceIdiom {
|
|
||||||
fn into(self) -> Idiom {
|
|
||||||
match self {
|
|
||||||
UIUserInterfaceIdiom::Unspecified => Idiom::Unspecified,
|
|
||||||
UIUserInterfaceIdiom::Phone => Idiom::Phone,
|
|
||||||
UIUserInterfaceIdiom::Pad => Idiom::Pad,
|
|
||||||
UIUserInterfaceIdiom::TV => Idiom::TV,
|
|
||||||
UIUserInterfaceIdiom::CarPlay => Idiom::CarPlay,
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(transparent)]
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub struct UIInterfaceOrientationMask(NSUInteger);
|
|
||||||
|
|
||||||
unsafe impl Encode for UIInterfaceOrientationMask {
|
|
||||||
fn encode() -> Encoding {
|
|
||||||
NSUInteger::encode()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UIInterfaceOrientationMask {
|
|
||||||
pub const Portrait: UIInterfaceOrientationMask = UIInterfaceOrientationMask(1 << 1);
|
|
||||||
pub const PortraitUpsideDown: UIInterfaceOrientationMask = UIInterfaceOrientationMask(1 << 2);
|
|
||||||
pub const LandscapeLeft: UIInterfaceOrientationMask = UIInterfaceOrientationMask(1 << 4);
|
|
||||||
pub const LandscapeRight: UIInterfaceOrientationMask = UIInterfaceOrientationMask(1 << 3);
|
|
||||||
pub const Landscape: UIInterfaceOrientationMask =
|
|
||||||
UIInterfaceOrientationMask(Self::LandscapeLeft.0 | Self::LandscapeRight.0);
|
|
||||||
pub const AllButUpsideDown: UIInterfaceOrientationMask =
|
|
||||||
UIInterfaceOrientationMask(Self::Landscape.0 | Self::Portrait.0);
|
|
||||||
pub const All: UIInterfaceOrientationMask =
|
|
||||||
UIInterfaceOrientationMask(Self::AllButUpsideDown.0 | Self::PortraitUpsideDown.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BitOr for UIInterfaceOrientationMask {
|
|
||||||
type Output = Self;
|
|
||||||
|
|
||||||
fn bitor(self, rhs: Self) -> Self {
|
|
||||||
UIInterfaceOrientationMask(self.0 | rhs.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UIInterfaceOrientationMask {
|
|
||||||
pub fn from_valid_orientations_idiom(
|
|
||||||
valid_orientations: ValidOrientations,
|
|
||||||
idiom: Idiom,
|
|
||||||
) -> UIInterfaceOrientationMask {
|
|
||||||
match (valid_orientations, idiom) {
|
|
||||||
(ValidOrientations::LandscapeAndPortrait, Idiom::Phone) => {
|
|
||||||
UIInterfaceOrientationMask::AllButUpsideDown
|
|
||||||
}
|
|
||||||
(ValidOrientations::LandscapeAndPortrait, _) => UIInterfaceOrientationMask::All,
|
|
||||||
(ValidOrientations::Landscape, _) => UIInterfaceOrientationMask::Landscape,
|
|
||||||
(ValidOrientations::Portrait, Idiom::Phone) => UIInterfaceOrientationMask::Portrait,
|
|
||||||
(ValidOrientations::Portrait, _) => {
|
|
||||||
UIInterfaceOrientationMask::Portrait
|
|
||||||
| UIInterfaceOrientationMask::PortraitUpsideDown
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(transparent)]
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
||||||
pub struct UIRectEdge(NSUInteger);
|
|
||||||
|
|
||||||
unsafe impl Encode for UIRectEdge {
|
|
||||||
fn encode() -> Encoding {
|
|
||||||
NSUInteger::encode()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ScreenEdge> for UIRectEdge {
|
|
||||||
fn from(screen_edge: ScreenEdge) -> UIRectEdge {
|
|
||||||
assert_eq!(
|
|
||||||
screen_edge.bits() & !ScreenEdge::ALL.bits(),
|
|
||||||
0,
|
|
||||||
"invalid `ScreenEdge`"
|
|
||||||
);
|
|
||||||
UIRectEdge(screen_edge.bits().into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<ScreenEdge> for UIRectEdge {
|
|
||||||
fn into(self) -> ScreenEdge {
|
|
||||||
let bits: u8 = self.0.try_into().expect("invalid `UIRectEdge`");
|
|
||||||
ScreenEdge::from_bits(bits).expect("invalid `ScreenEdge`")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(transparent)]
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
||||||
pub struct UIScreenOverscanCompensation(NSInteger);
|
|
||||||
|
|
||||||
unsafe impl Encode for UIScreenOverscanCompensation {
|
|
||||||
fn encode() -> Encoding {
|
|
||||||
NSInteger::encode()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
impl UIScreenOverscanCompensation {
|
|
||||||
pub const Scale: UIScreenOverscanCompensation = UIScreenOverscanCompensation(0);
|
|
||||||
pub const InsetBounds: UIScreenOverscanCompensation = UIScreenOverscanCompensation(1);
|
|
||||||
pub const None: UIScreenOverscanCompensation = UIScreenOverscanCompensation(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[link(name = "UIKit", kind = "framework")]
|
|
||||||
#[link(name = "CoreFoundation", kind = "framework")]
|
|
||||||
extern "C" {
|
|
||||||
pub static kCFRunLoopDefaultMode: CFRunLoopMode;
|
|
||||||
pub static kCFRunLoopCommonModes: CFRunLoopMode;
|
|
||||||
|
|
||||||
pub fn UIApplicationMain(
|
|
||||||
argc: c_int,
|
|
||||||
argv: *const c_char,
|
|
||||||
principalClassName: id,
|
|
||||||
delegateClassName: id,
|
|
||||||
) -> c_int;
|
|
||||||
|
|
||||||
pub fn CFRunLoopGetMain() -> CFRunLoopRef;
|
|
||||||
pub fn CFRunLoopWakeUp(rl: CFRunLoopRef);
|
|
||||||
|
|
||||||
pub fn CFRunLoopObserverCreate(
|
|
||||||
allocator: CFAllocatorRef,
|
|
||||||
activities: CFOptionFlags,
|
|
||||||
repeats: Boolean,
|
|
||||||
order: CFIndex,
|
|
||||||
callout: CFRunLoopObserverCallBack,
|
|
||||||
context: *mut CFRunLoopObserverContext,
|
|
||||||
) -> CFRunLoopObserverRef;
|
|
||||||
pub fn CFRunLoopAddObserver(
|
|
||||||
rl: CFRunLoopRef,
|
|
||||||
observer: CFRunLoopObserverRef,
|
|
||||||
mode: CFRunLoopMode,
|
|
||||||
);
|
|
||||||
|
|
||||||
pub fn CFRunLoopTimerCreate(
|
|
||||||
allocator: CFAllocatorRef,
|
|
||||||
fireDate: CFAbsoluteTime,
|
|
||||||
interval: CFTimeInterval,
|
|
||||||
flags: CFOptionFlags,
|
|
||||||
order: CFIndex,
|
|
||||||
callout: CFRunLoopTimerCallBack,
|
|
||||||
context: *mut CFRunLoopTimerContext,
|
|
||||||
) -> CFRunLoopTimerRef;
|
|
||||||
pub fn CFRunLoopAddTimer(rl: CFRunLoopRef, timer: CFRunLoopTimerRef, mode: CFRunLoopMode);
|
|
||||||
pub fn CFRunLoopTimerSetNextFireDate(timer: CFRunLoopTimerRef, fireDate: CFAbsoluteTime);
|
|
||||||
pub fn CFRunLoopTimerInvalidate(time: CFRunLoopTimerRef);
|
|
||||||
|
|
||||||
pub fn CFRunLoopSourceCreate(
|
|
||||||
allocator: CFAllocatorRef,
|
|
||||||
order: CFIndex,
|
|
||||||
context: *mut CFRunLoopSourceContext,
|
|
||||||
) -> CFRunLoopSourceRef;
|
|
||||||
pub fn CFRunLoopAddSource(rl: CFRunLoopRef, source: CFRunLoopSourceRef, mode: CFRunLoopMode);
|
|
||||||
pub fn CFRunLoopSourceInvalidate(source: CFRunLoopSourceRef);
|
|
||||||
pub fn CFRunLoopSourceSignal(source: CFRunLoopSourceRef);
|
|
||||||
|
|
||||||
pub fn CFAbsoluteTimeGetCurrent() -> CFAbsoluteTime;
|
|
||||||
pub fn CFRelease(cftype: *const c_void);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type Boolean = u8;
|
|
||||||
pub enum CFAllocator {}
|
|
||||||
pub type CFAllocatorRef = *mut CFAllocator;
|
|
||||||
pub enum CFRunLoop {}
|
|
||||||
pub type CFRunLoopRef = *mut CFRunLoop;
|
|
||||||
pub type CFRunLoopMode = CFStringRef;
|
|
||||||
pub enum CFRunLoopObserver {}
|
|
||||||
pub type CFRunLoopObserverRef = *mut CFRunLoopObserver;
|
|
||||||
pub enum CFRunLoopTimer {}
|
|
||||||
pub type CFRunLoopTimerRef = *mut CFRunLoopTimer;
|
|
||||||
pub enum CFRunLoopSource {}
|
|
||||||
pub type CFRunLoopSourceRef = *mut CFRunLoopSource;
|
|
||||||
pub enum CFString {}
|
|
||||||
pub type CFStringRef = *const CFString;
|
|
||||||
|
|
||||||
pub type CFHashCode = c_ulong;
|
|
||||||
pub type CFIndex = c_long;
|
|
||||||
pub type CFOptionFlags = c_ulong;
|
|
||||||
pub type CFRunLoopActivity = CFOptionFlags;
|
|
||||||
|
|
||||||
pub type CFAbsoluteTime = CFTimeInterval;
|
|
||||||
pub type CFTimeInterval = f64;
|
|
||||||
|
|
||||||
pub const kCFRunLoopEntry: CFRunLoopActivity = 0;
|
|
||||||
pub const kCFRunLoopBeforeWaiting: CFRunLoopActivity = 1 << 5;
|
|
||||||
pub const kCFRunLoopAfterWaiting: CFRunLoopActivity = 1 << 6;
|
|
||||||
pub const kCFRunLoopExit: CFRunLoopActivity = 1 << 7;
|
|
||||||
|
|
||||||
pub type CFRunLoopObserverCallBack =
|
|
||||||
extern "C" fn(observer: CFRunLoopObserverRef, activity: CFRunLoopActivity, info: *mut c_void);
|
|
||||||
pub type CFRunLoopTimerCallBack = extern "C" fn(timer: CFRunLoopTimerRef, info: *mut c_void);
|
|
||||||
|
|
||||||
pub enum CFRunLoopObserverContext {}
|
|
||||||
pub enum CFRunLoopTimerContext {}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct CFRunLoopSourceContext {
|
|
||||||
pub version: CFIndex,
|
|
||||||
pub info: *mut c_void,
|
|
||||||
pub retain: Option<extern "C" fn(*const c_void) -> *const c_void>,
|
|
||||||
pub release: Option<extern "C" fn(*const c_void)>,
|
|
||||||
pub copyDescription: Option<extern "C" fn(*const c_void) -> CFStringRef>,
|
|
||||||
pub equal: Option<extern "C" fn(*const c_void, *const c_void) -> Boolean>,
|
|
||||||
pub hash: Option<extern "C" fn(*const c_void) -> CFHashCode>,
|
|
||||||
pub schedule: Option<extern "C" fn(*mut c_void, CFRunLoopRef, CFRunLoopMode)>,
|
|
||||||
pub cancel: Option<extern "C" fn(*mut c_void, CFRunLoopRef, CFRunLoopMode)>,
|
|
||||||
pub perform: Option<extern "C" fn(*mut c_void)>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait NSString: Sized {
|
|
||||||
unsafe fn alloc(_: Self) -> id {
|
|
||||||
msg_send![class!(NSString), alloc]
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn initWithUTF8String_(self, c_string: *const c_char) -> id;
|
|
||||||
unsafe fn stringByAppendingString_(self, other: id) -> id;
|
|
||||||
unsafe fn init_str(self, string: &str) -> Self;
|
|
||||||
unsafe fn UTF8String(self) -> *const c_char;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NSString for id {
|
|
||||||
unsafe fn initWithUTF8String_(self, c_string: *const c_char) -> id {
|
|
||||||
msg_send![self, initWithUTF8String: c_string as id]
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn stringByAppendingString_(self, other: id) -> id {
|
|
||||||
msg_send![self, stringByAppendingString: other]
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn init_str(self, string: &str) -> id {
|
|
||||||
let cstring = CString::new(string).unwrap();
|
|
||||||
self.initWithUTF8String_(cstring.as_ptr())
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn UTF8String(self) -> *const c_char {
|
|
||||||
msg_send![self, UTF8String]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
//! iOS support
|
|
||||||
//!
|
|
||||||
//! # Building app
|
|
||||||
//! To build ios app you will need rustc built for this targets:
|
|
||||||
//!
|
|
||||||
//! - armv7-apple-ios
|
|
||||||
//! - armv7s-apple-ios
|
|
||||||
//! - i386-apple-ios
|
|
||||||
//! - aarch64-apple-ios
|
|
||||||
//! - x86_64-apple-ios
|
|
||||||
//!
|
|
||||||
//! Then
|
|
||||||
//!
|
|
||||||
//! ```
|
|
||||||
//! cargo build --target=...
|
|
||||||
//! ```
|
|
||||||
//! The simplest way to integrate your app into xcode environment is to build it
|
|
||||||
//! as a static library. Wrap your main function and export it.
|
|
||||||
//!
|
|
||||||
//! ```rust, ignore
|
|
||||||
//! #[no_mangle]
|
|
||||||
//! pub extern fn start_winit_app() {
|
|
||||||
//! start_inner()
|
|
||||||
//! }
|
|
||||||
//!
|
|
||||||
//! fn start_inner() {
|
|
||||||
//! ...
|
|
||||||
//! }
|
|
||||||
//! ```
|
|
||||||
//!
|
|
||||||
//! Compile project and then drag resulting .a into Xcode project. Add winit.h to xcode.
|
|
||||||
//!
|
|
||||||
//! ```ignore
|
|
||||||
//! void start_winit_app();
|
|
||||||
//! ```
|
|
||||||
//!
|
|
||||||
//! Use start_winit_app inside your xcode's main function.
|
|
||||||
//!
|
|
||||||
//!
|
|
||||||
//! # App lifecycle and events
|
|
||||||
//!
|
|
||||||
//! iOS environment is very different from other platforms and you must be very
|
|
||||||
//! careful with it's events. Familiarize yourself with
|
|
||||||
//! [app lifecycle](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/).
|
|
||||||
//!
|
|
||||||
//!
|
|
||||||
//! This is how those event are represented in winit:
|
|
||||||
//!
|
|
||||||
//! - applicationDidBecomeActive is Resumed
|
|
||||||
//! - applicationWillResignActive is Suspended
|
|
||||||
//! - applicationWillTerminate is LoopDestroyed
|
|
||||||
//!
|
|
||||||
//! Keep in mind that after LoopDestroyed event is received every attempt to draw with
|
|
||||||
//! opengl will result in segfault.
|
|
||||||
//!
|
|
||||||
//! Also note that app may not receive the LoopDestroyed event if suspended; it might be SIGKILL'ed.
|
|
||||||
|
|
||||||
#![cfg(target_os = "ios")]
|
|
||||||
|
|
||||||
// TODO: (mtak-) UIKit requires main thread for virtually all function/method calls. This could be
|
|
||||||
// worked around in the future by using GCD (grand central dispatch) and/or caching of values like
|
|
||||||
// window size/position.
|
|
||||||
macro_rules! assert_main_thread {
|
|
||||||
($($t:tt)*) => {
|
|
||||||
if !msg_send![class!(NSThread), isMainThread] {
|
|
||||||
panic!($($t)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
mod app_state;
|
|
||||||
mod event_loop;
|
|
||||||
mod ffi;
|
|
||||||
mod monitor;
|
|
||||||
mod view;
|
|
||||||
mod window;
|
|
||||||
|
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
pub use self::{
|
|
||||||
event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget},
|
|
||||||
monitor::{MonitorHandle, VideoMode},
|
|
||||||
window::{PlatformSpecificWindowBuilderAttributes, Window, WindowId},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub(crate) use crate::icon::NoIcon as PlatformIcon;
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub struct DeviceId {
|
|
||||||
uiscreen: ffi::id,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DeviceId {
|
|
||||||
pub unsafe fn dummy() -> Self {
|
|
||||||
DeviceId {
|
|
||||||
uiscreen: std::ptr::null_mut(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl Send for DeviceId {}
|
|
||||||
unsafe impl Sync for DeviceId {}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum OsError {}
|
|
||||||
|
|
||||||
impl fmt::Display for OsError {
|
|
||||||
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,299 +0,0 @@
|
|||||||
use std::{
|
|
||||||
collections::{BTreeSet, VecDeque},
|
|
||||||
fmt,
|
|
||||||
ops::{Deref, DerefMut},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
dpi::{PhysicalPosition, PhysicalSize},
|
|
||||||
monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode},
|
|
||||||
platform_impl::platform::{
|
|
||||||
app_state,
|
|
||||||
ffi::{id, nil, CGFloat, CGRect, CGSize, NSInteger, NSUInteger},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub struct VideoMode {
|
|
||||||
pub(crate) size: (u32, u32),
|
|
||||||
pub(crate) bit_depth: u16,
|
|
||||||
pub(crate) refresh_rate: u16,
|
|
||||||
pub(crate) screen_mode: NativeDisplayMode,
|
|
||||||
pub(crate) monitor: MonitorHandle,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
|
||||||
pub struct NativeDisplayMode(pub id);
|
|
||||||
|
|
||||||
unsafe impl Send for NativeDisplayMode {}
|
|
||||||
|
|
||||||
impl Drop for NativeDisplayMode {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
unsafe {
|
|
||||||
let () = msg_send![self.0, release];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clone for NativeDisplayMode {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
unsafe {
|
|
||||||
let _: id = msg_send![self.0, retain];
|
|
||||||
}
|
|
||||||
NativeDisplayMode(self.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clone for VideoMode {
|
|
||||||
fn clone(&self) -> VideoMode {
|
|
||||||
VideoMode {
|
|
||||||
size: self.size,
|
|
||||||
bit_depth: self.bit_depth,
|
|
||||||
refresh_rate: self.refresh_rate,
|
|
||||||
screen_mode: self.screen_mode.clone(),
|
|
||||||
monitor: self.monitor.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VideoMode {
|
|
||||||
unsafe fn retained_new(uiscreen: id, screen_mode: id) -> VideoMode {
|
|
||||||
assert_main_thread!("`VideoMode` can only be created on the main thread on iOS");
|
|
||||||
let os_capabilities = app_state::os_capabilities();
|
|
||||||
let refresh_rate: NSInteger = if os_capabilities.maximum_frames_per_second {
|
|
||||||
msg_send![uiscreen, maximumFramesPerSecond]
|
|
||||||
} else {
|
|
||||||
// https://developer.apple.com/library/archive/technotes/tn2460/_index.html
|
|
||||||
// https://en.wikipedia.org/wiki/IPad_Pro#Model_comparison
|
|
||||||
//
|
|
||||||
// All iOS devices support 60 fps, and on devices where `maximumFramesPerSecond` is not
|
|
||||||
// supported, they are all guaranteed to have 60hz refresh rates. This does not
|
|
||||||
// correctly handle external displays. ProMotion displays support 120fps, but they were
|
|
||||||
// introduced at the same time as the `maximumFramesPerSecond` API.
|
|
||||||
//
|
|
||||||
// FIXME: earlier OSs could calculate the refresh rate using
|
|
||||||
// `-[CADisplayLink duration]`.
|
|
||||||
os_capabilities.maximum_frames_per_second_err_msg("defaulting to 60 fps");
|
|
||||||
60
|
|
||||||
};
|
|
||||||
let size: CGSize = msg_send![screen_mode, size];
|
|
||||||
let screen_mode: id = msg_send![screen_mode, retain];
|
|
||||||
let screen_mode = NativeDisplayMode(screen_mode);
|
|
||||||
VideoMode {
|
|
||||||
size: (size.width as u32, size.height as u32),
|
|
||||||
bit_depth: 32,
|
|
||||||
refresh_rate: refresh_rate as u16,
|
|
||||||
screen_mode,
|
|
||||||
monitor: MonitorHandle::retained_new(uiscreen),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn size(&self) -> PhysicalSize<u32> {
|
|
||||||
self.size.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bit_depth(&self) -> u16 {
|
|
||||||
self.bit_depth
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn refresh_rate(&self) -> u16 {
|
|
||||||
self.refresh_rate
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn monitor(&self) -> RootMonitorHandle {
|
|
||||||
RootMonitorHandle {
|
|
||||||
inner: self.monitor.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Hash, PartialOrd, Ord)]
|
|
||||||
pub struct Inner {
|
|
||||||
uiscreen: id,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for Inner {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
unsafe {
|
|
||||||
let () = msg_send![self.uiscreen, release];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Hash, PartialOrd, Ord)]
|
|
||||||
pub struct MonitorHandle {
|
|
||||||
inner: Inner,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Deref for MonitorHandle {
|
|
||||||
type Target = Inner;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Inner {
|
|
||||||
unsafe {
|
|
||||||
assert_main_thread!(
|
|
||||||
"`MonitorHandle` methods can only be run on the main thread on iOS"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
&self.inner
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DerefMut for MonitorHandle {
|
|
||||||
fn deref_mut(&mut self) -> &mut Inner {
|
|
||||||
unsafe {
|
|
||||||
assert_main_thread!(
|
|
||||||
"`MonitorHandle` methods can only be run on the main thread on iOS"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
&mut self.inner
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl Send for MonitorHandle {}
|
|
||||||
unsafe impl Sync for MonitorHandle {}
|
|
||||||
|
|
||||||
impl Clone for MonitorHandle {
|
|
||||||
fn clone(&self) -> MonitorHandle {
|
|
||||||
MonitorHandle::retained_new(self.uiscreen)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for MonitorHandle {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
unsafe {
|
|
||||||
assert_main_thread!("`MonitorHandle` can only be dropped on the main thread on iOS");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Debug for MonitorHandle {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct MonitorHandle {
|
|
||||||
name: Option<String>,
|
|
||||||
size: PhysicalSize<u32>,
|
|
||||||
position: PhysicalPosition<i32>,
|
|
||||||
scale_factor: f64,
|
|
||||||
}
|
|
||||||
|
|
||||||
let monitor_id_proxy = MonitorHandle {
|
|
||||||
name: self.name(),
|
|
||||||
size: self.size(),
|
|
||||||
position: self.position(),
|
|
||||||
scale_factor: self.scale_factor(),
|
|
||||||
};
|
|
||||||
|
|
||||||
monitor_id_proxy.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MonitorHandle {
|
|
||||||
pub fn retained_new(uiscreen: id) -> MonitorHandle {
|
|
||||||
unsafe {
|
|
||||||
assert_main_thread!("`MonitorHandle` can only be cloned on the main thread on iOS");
|
|
||||||
let () = msg_send![uiscreen, retain];
|
|
||||||
}
|
|
||||||
MonitorHandle {
|
|
||||||
inner: Inner { uiscreen },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Inner {
|
|
||||||
pub fn name(&self) -> Option<String> {
|
|
||||||
unsafe {
|
|
||||||
let main = main_uiscreen();
|
|
||||||
if self.uiscreen == main.uiscreen {
|
|
||||||
Some("Primary".to_string())
|
|
||||||
} else if self.uiscreen == mirrored_uiscreen(&main).uiscreen {
|
|
||||||
Some("Mirrored".to_string())
|
|
||||||
} else {
|
|
||||||
uiscreens()
|
|
||||||
.iter()
|
|
||||||
.position(|rhs| rhs.uiscreen == self.uiscreen)
|
|
||||||
.map(|idx| idx.to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn size(&self) -> PhysicalSize<u32> {
|
|
||||||
unsafe {
|
|
||||||
let bounds: CGRect = msg_send![self.ui_screen(), nativeBounds];
|
|
||||||
PhysicalSize::new(bounds.size.width as u32, bounds.size.height as u32)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn position(&self) -> PhysicalPosition<i32> {
|
|
||||||
unsafe {
|
|
||||||
let bounds: CGRect = msg_send![self.ui_screen(), nativeBounds];
|
|
||||||
(bounds.origin.x as f64, bounds.origin.y as f64).into()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn scale_factor(&self) -> f64 {
|
|
||||||
unsafe {
|
|
||||||
let scale: CGFloat = msg_send![self.ui_screen(), nativeScale];
|
|
||||||
scale as f64
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn video_modes(&self) -> impl Iterator<Item = RootVideoMode> {
|
|
||||||
let mut modes = BTreeSet::new();
|
|
||||||
unsafe {
|
|
||||||
let available_modes: id = msg_send![self.uiscreen, availableModes];
|
|
||||||
let available_mode_count: NSUInteger = msg_send![available_modes, count];
|
|
||||||
|
|
||||||
for i in 0..available_mode_count {
|
|
||||||
let mode: id = msg_send![available_modes, objectAtIndex: i];
|
|
||||||
modes.insert(RootVideoMode {
|
|
||||||
video_mode: VideoMode::retained_new(self.uiscreen, mode),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
modes.into_iter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MonitorHandleExtIOS
|
|
||||||
impl Inner {
|
|
||||||
pub fn ui_screen(&self) -> id {
|
|
||||||
self.uiscreen
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn preferred_video_mode(&self) -> RootVideoMode {
|
|
||||||
unsafe {
|
|
||||||
let mode: id = msg_send![self.uiscreen, preferredMode];
|
|
||||||
RootVideoMode {
|
|
||||||
video_mode: VideoMode::retained_new(self.uiscreen, mode),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// requires being run on main thread
|
|
||||||
pub unsafe fn main_uiscreen() -> MonitorHandle {
|
|
||||||
let uiscreen: id = msg_send![class!(UIScreen), mainScreen];
|
|
||||||
MonitorHandle::retained_new(uiscreen)
|
|
||||||
}
|
|
||||||
|
|
||||||
// requires being run on main thread
|
|
||||||
unsafe fn mirrored_uiscreen(monitor: &MonitorHandle) -> MonitorHandle {
|
|
||||||
let uiscreen: id = msg_send![monitor.uiscreen, mirroredScreen];
|
|
||||||
MonitorHandle::retained_new(uiscreen)
|
|
||||||
}
|
|
||||||
|
|
||||||
// requires being run on main thread
|
|
||||||
pub unsafe fn uiscreens() -> VecDeque<MonitorHandle> {
|
|
||||||
let screens: id = msg_send![class!(UIScreen), screens];
|
|
||||||
let count: NSUInteger = msg_send![screens, count];
|
|
||||||
let mut result = VecDeque::with_capacity(count as _);
|
|
||||||
let screens_enum: id = msg_send![screens, objectEnumerator];
|
|
||||||
loop {
|
|
||||||
let screen: id = msg_send![screens_enum, nextObject];
|
|
||||||
if screen == nil {
|
|
||||||
break result;
|
|
||||||
}
|
|
||||||
result.push_back(MonitorHandle::retained_new(screen));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,607 +0,0 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use objc::{
|
|
||||||
declare::ClassDecl,
|
|
||||||
runtime::{Class, Object, Sel, BOOL, NO, YES},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
dpi::PhysicalPosition,
|
|
||||||
event::{DeviceId as RootDeviceId, Event, Force, Touch, TouchPhase, WindowEvent},
|
|
||||||
platform::ios::MonitorHandleExtIOS,
|
|
||||||
platform_impl::platform::{
|
|
||||||
app_state::{self, OSCapabilities},
|
|
||||||
event_loop::{self, EventProxy, EventWrapper},
|
|
||||||
ffi::{
|
|
||||||
id, nil, CGFloat, CGPoint, CGRect, UIForceTouchCapability, UIInterfaceOrientationMask,
|
|
||||||
UIRectEdge, UITouchPhase, UITouchType,
|
|
||||||
},
|
|
||||||
window::PlatformSpecificWindowBuilderAttributes,
|
|
||||||
DeviceId,
|
|
||||||
},
|
|
||||||
window::{Fullscreen, WindowAttributes, WindowId as RootWindowId},
|
|
||||||
};
|
|
||||||
|
|
||||||
macro_rules! add_property {
|
|
||||||
(
|
|
||||||
$decl:ident,
|
|
||||||
$name:ident: $t:ty,
|
|
||||||
$setter_name:ident: |$object:ident| $after_set:expr,
|
|
||||||
$getter_name:ident,
|
|
||||||
) => {
|
|
||||||
add_property!(
|
|
||||||
$decl,
|
|
||||||
$name: $t,
|
|
||||||
$setter_name: true, |_, _|{}; |$object| $after_set,
|
|
||||||
$getter_name,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
(
|
|
||||||
$decl:ident,
|
|
||||||
$name:ident: $t:ty,
|
|
||||||
$setter_name:ident: $capability:expr, $err:expr; |$object:ident| $after_set:expr,
|
|
||||||
$getter_name:ident,
|
|
||||||
) => {
|
|
||||||
{
|
|
||||||
const VAR_NAME: &'static str = concat!("_", stringify!($name));
|
|
||||||
$decl.add_ivar::<$t>(VAR_NAME);
|
|
||||||
let setter = if $capability {
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
extern "C" fn $setter_name($object: &mut Object, _: Sel, value: $t) {
|
|
||||||
unsafe {
|
|
||||||
$object.set_ivar::<$t>(VAR_NAME, value);
|
|
||||||
}
|
|
||||||
$after_set
|
|
||||||
}
|
|
||||||
$setter_name
|
|
||||||
} else {
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
extern "C" fn $setter_name($object: &mut Object, _: Sel, value: $t) {
|
|
||||||
unsafe {
|
|
||||||
$object.set_ivar::<$t>(VAR_NAME, value);
|
|
||||||
}
|
|
||||||
$err(&app_state::os_capabilities(), "ignoring")
|
|
||||||
}
|
|
||||||
$setter_name
|
|
||||||
};
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
extern "C" fn $getter_name($object: &Object, _: Sel) -> $t {
|
|
||||||
unsafe { *$object.get_ivar::<$t>(VAR_NAME) }
|
|
||||||
}
|
|
||||||
$decl.add_method(
|
|
||||||
sel!($setter_name:),
|
|
||||||
setter as extern "C" fn(&mut Object, Sel, $t),
|
|
||||||
);
|
|
||||||
$decl.add_method(
|
|
||||||
sel!($getter_name),
|
|
||||||
$getter_name as extern "C" fn(&Object, Sel) -> $t,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// requires main thread
|
|
||||||
unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class {
|
|
||||||
static mut CLASSES: Option<HashMap<*const Class, &'static Class>> = None;
|
|
||||||
static mut ID: usize = 0;
|
|
||||||
|
|
||||||
if CLASSES.is_none() {
|
|
||||||
CLASSES = Some(HashMap::default());
|
|
||||||
}
|
|
||||||
|
|
||||||
let classes = CLASSES.as_mut().unwrap();
|
|
||||||
|
|
||||||
classes.entry(root_view_class).or_insert_with(move || {
|
|
||||||
let uiview_class = class!(UIView);
|
|
||||||
let is_uiview: BOOL = msg_send![root_view_class, isSubclassOfClass: uiview_class];
|
|
||||||
assert_eq!(
|
|
||||||
is_uiview, YES,
|
|
||||||
"`root_view_class` must inherit from `UIView`"
|
|
||||||
);
|
|
||||||
|
|
||||||
extern "C" fn draw_rect(object: &Object, _: Sel, rect: CGRect) {
|
|
||||||
unsafe {
|
|
||||||
let window: id = msg_send![object, window];
|
|
||||||
assert!(!window.is_null());
|
|
||||||
app_state::handle_nonuser_events(
|
|
||||||
std::iter::once(EventWrapper::StaticEvent(Event::RedrawRequested(
|
|
||||||
RootWindowId(window.into()),
|
|
||||||
)))
|
|
||||||
.chain(std::iter::once(EventWrapper::StaticEvent(
|
|
||||||
Event::RedrawEventsCleared,
|
|
||||||
))),
|
|
||||||
);
|
|
||||||
let superclass: &'static Class = msg_send![object, superclass];
|
|
||||||
let () = msg_send![super(object, superclass), drawRect: rect];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" fn layout_subviews(object: &Object, _: Sel) {
|
|
||||||
unsafe {
|
|
||||||
let superclass: &'static Class = msg_send![object, superclass];
|
|
||||||
let () = msg_send![super(object, superclass), layoutSubviews];
|
|
||||||
|
|
||||||
let window: id = msg_send![object, window];
|
|
||||||
assert!(!window.is_null());
|
|
||||||
let bounds: CGRect = msg_send![window, bounds];
|
|
||||||
let screen: id = msg_send![window, screen];
|
|
||||||
let screen_space: id = msg_send![screen, coordinateSpace];
|
|
||||||
let screen_frame: CGRect =
|
|
||||||
msg_send![object, convertRect:bounds toCoordinateSpace:screen_space];
|
|
||||||
let scale_factor: CGFloat = msg_send![screen, scale];
|
|
||||||
let size = crate::dpi::LogicalSize {
|
|
||||||
width: screen_frame.size.width as f64,
|
|
||||||
height: screen_frame.size.height as f64,
|
|
||||||
}
|
|
||||||
.to_physical(scale_factor.into());
|
|
||||||
app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::WindowEvent {
|
|
||||||
window_id: RootWindowId(window.into()),
|
|
||||||
event: WindowEvent::Resized(size),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" fn set_content_scale_factor(
|
|
||||||
object: &mut Object,
|
|
||||||
_: Sel,
|
|
||||||
untrusted_scale_factor: CGFloat,
|
|
||||||
) {
|
|
||||||
unsafe {
|
|
||||||
let superclass: &'static Class = msg_send![object, superclass];
|
|
||||||
let () = msg_send![
|
|
||||||
super(object, superclass),
|
|
||||||
setContentScaleFactor: untrusted_scale_factor
|
|
||||||
];
|
|
||||||
|
|
||||||
let window: id = msg_send![object, window];
|
|
||||||
// `window` is null when `setContentScaleFactor` is invoked prior to `[UIWindow
|
|
||||||
// makeKeyAndVisible]` at window creation time (either manually or internally by
|
|
||||||
// UIKit when the `UIView` is first created), in which case we send no events here
|
|
||||||
if window.is_null() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// `setContentScaleFactor` may be called with a value of 0, which means "reset the
|
|
||||||
// content scale factor to a device-specific default value", so we can't use the
|
|
||||||
// parameter here. We can query the actual factor using the getter
|
|
||||||
let scale_factor: CGFloat = msg_send![object, contentScaleFactor];
|
|
||||||
assert!(
|
|
||||||
!scale_factor.is_nan()
|
|
||||||
&& scale_factor.is_finite()
|
|
||||||
&& scale_factor.is_sign_positive()
|
|
||||||
&& scale_factor > 0.0,
|
|
||||||
"invalid scale_factor set on UIView",
|
|
||||||
);
|
|
||||||
let scale_factor: f64 = scale_factor.into();
|
|
||||||
let bounds: CGRect = msg_send![object, bounds];
|
|
||||||
let screen: id = msg_send![window, screen];
|
|
||||||
let screen_space: id = msg_send![screen, coordinateSpace];
|
|
||||||
let screen_frame: CGRect =
|
|
||||||
msg_send![object, convertRect:bounds toCoordinateSpace:screen_space];
|
|
||||||
let size = crate::dpi::LogicalSize {
|
|
||||||
width: screen_frame.size.width as _,
|
|
||||||
height: screen_frame.size.height as _,
|
|
||||||
};
|
|
||||||
app_state::handle_nonuser_events(
|
|
||||||
std::iter::once(EventWrapper::EventProxy(EventProxy::DpiChangedProxy {
|
|
||||||
window_id: window,
|
|
||||||
scale_factor,
|
|
||||||
suggested_size: size,
|
|
||||||
}))
|
|
||||||
.chain(std::iter::once(EventWrapper::StaticEvent(
|
|
||||||
Event::WindowEvent {
|
|
||||||
window_id: RootWindowId(window.into()),
|
|
||||||
event: WindowEvent::Resized(size.to_physical(scale_factor)),
|
|
||||||
},
|
|
||||||
))),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" fn handle_touches(object: &Object, _: Sel, touches: id, _: id) {
|
|
||||||
unsafe {
|
|
||||||
let window: id = msg_send![object, window];
|
|
||||||
assert!(!window.is_null());
|
|
||||||
let uiscreen: id = msg_send![window, screen];
|
|
||||||
let touches_enum: id = msg_send![touches, objectEnumerator];
|
|
||||||
let mut touch_events = Vec::new();
|
|
||||||
let os_supports_force = app_state::os_capabilities().force_touch;
|
|
||||||
loop {
|
|
||||||
let touch: id = msg_send![touches_enum, nextObject];
|
|
||||||
if touch == nil {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
let logical_location: CGPoint = msg_send![touch, locationInView: nil];
|
|
||||||
let touch_type: UITouchType = msg_send![touch, type];
|
|
||||||
let force = if os_supports_force {
|
|
||||||
let trait_collection: id = msg_send![object, traitCollection];
|
|
||||||
let touch_capability: UIForceTouchCapability =
|
|
||||||
msg_send![trait_collection, forceTouchCapability];
|
|
||||||
// Both the OS _and_ the device need to be checked for force touch support.
|
|
||||||
if touch_capability == UIForceTouchCapability::Available {
|
|
||||||
let force: CGFloat = msg_send![touch, force];
|
|
||||||
let max_possible_force: CGFloat =
|
|
||||||
msg_send![touch, maximumPossibleForce];
|
|
||||||
let altitude_angle: Option<f64> = if touch_type == UITouchType::Pencil {
|
|
||||||
let angle: CGFloat = msg_send![touch, altitudeAngle];
|
|
||||||
Some(angle as _)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
Some(Force::Calibrated {
|
|
||||||
force: force as _,
|
|
||||||
max_possible_force: max_possible_force as _,
|
|
||||||
altitude_angle,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
let touch_id = touch as u64;
|
|
||||||
let phase: UITouchPhase = msg_send![touch, phase];
|
|
||||||
let phase = match phase {
|
|
||||||
UITouchPhase::Began => TouchPhase::Started,
|
|
||||||
UITouchPhase::Moved => TouchPhase::Moved,
|
|
||||||
// 2 is UITouchPhase::Stationary and is not expected here
|
|
||||||
UITouchPhase::Ended => TouchPhase::Ended,
|
|
||||||
UITouchPhase::Cancelled => TouchPhase::Cancelled,
|
|
||||||
_ => panic!("unexpected touch phase: {:?}", phase as i32),
|
|
||||||
};
|
|
||||||
|
|
||||||
let physical_location = {
|
|
||||||
let scale_factor: CGFloat = msg_send![object, contentScaleFactor];
|
|
||||||
PhysicalPosition::from_logical::<(f64, f64), f64>(
|
|
||||||
(logical_location.x as _, logical_location.y as _),
|
|
||||||
scale_factor,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
touch_events.push(EventWrapper::StaticEvent(Event::WindowEvent {
|
|
||||||
window_id: RootWindowId(window.into()),
|
|
||||||
event: WindowEvent::Touch(Touch {
|
|
||||||
device_id: RootDeviceId(DeviceId { uiscreen }),
|
|
||||||
id: touch_id,
|
|
||||||
location: physical_location,
|
|
||||||
force,
|
|
||||||
phase,
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
app_state::handle_nonuser_events(touch_events);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut decl = ClassDecl::new(&format!("WinitUIView{}", ID), root_view_class)
|
|
||||||
.expect("Failed to declare class `WinitUIView`");
|
|
||||||
ID += 1;
|
|
||||||
decl.add_method(
|
|
||||||
sel!(drawRect:),
|
|
||||||
draw_rect as extern "C" fn(&Object, Sel, CGRect),
|
|
||||||
);
|
|
||||||
decl.add_method(
|
|
||||||
sel!(layoutSubviews),
|
|
||||||
layout_subviews as extern "C" fn(&Object, Sel),
|
|
||||||
);
|
|
||||||
decl.add_method(
|
|
||||||
sel!(setContentScaleFactor:),
|
|
||||||
set_content_scale_factor as extern "C" fn(&mut Object, Sel, CGFloat),
|
|
||||||
);
|
|
||||||
|
|
||||||
decl.add_method(
|
|
||||||
sel!(touchesBegan:withEvent:),
|
|
||||||
handle_touches as extern "C" fn(this: &Object, _: Sel, _: id, _: id),
|
|
||||||
);
|
|
||||||
decl.add_method(
|
|
||||||
sel!(touchesMoved:withEvent:),
|
|
||||||
handle_touches as extern "C" fn(this: &Object, _: Sel, _: id, _: id),
|
|
||||||
);
|
|
||||||
decl.add_method(
|
|
||||||
sel!(touchesEnded:withEvent:),
|
|
||||||
handle_touches as extern "C" fn(this: &Object, _: Sel, _: id, _: id),
|
|
||||||
);
|
|
||||||
decl.add_method(
|
|
||||||
sel!(touchesCancelled:withEvent:),
|
|
||||||
handle_touches as extern "C" fn(this: &Object, _: Sel, _: id, _: id),
|
|
||||||
);
|
|
||||||
|
|
||||||
decl.register()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// requires main thread
|
|
||||||
unsafe fn get_view_controller_class() -> &'static Class {
|
|
||||||
static mut CLASS: Option<&'static Class> = None;
|
|
||||||
if CLASS.is_none() {
|
|
||||||
let os_capabilities = app_state::os_capabilities();
|
|
||||||
|
|
||||||
let uiviewcontroller_class = class!(UIViewController);
|
|
||||||
|
|
||||||
extern "C" fn should_autorotate(_: &Object, _: Sel) -> BOOL {
|
|
||||||
YES
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut decl = ClassDecl::new("WinitUIViewController", uiviewcontroller_class)
|
|
||||||
.expect("Failed to declare class `WinitUIViewController`");
|
|
||||||
decl.add_method(
|
|
||||||
sel!(shouldAutorotate),
|
|
||||||
should_autorotate as extern "C" fn(&Object, Sel) -> BOOL,
|
|
||||||
);
|
|
||||||
add_property! {
|
|
||||||
decl,
|
|
||||||
prefers_status_bar_hidden: BOOL,
|
|
||||||
setPrefersStatusBarHidden: |object| {
|
|
||||||
unsafe {
|
|
||||||
let () = msg_send![object, setNeedsStatusBarAppearanceUpdate];
|
|
||||||
}
|
|
||||||
},
|
|
||||||
prefersStatusBarHidden,
|
|
||||||
}
|
|
||||||
add_property! {
|
|
||||||
decl,
|
|
||||||
prefers_home_indicator_auto_hidden: BOOL,
|
|
||||||
setPrefersHomeIndicatorAutoHidden:
|
|
||||||
os_capabilities.home_indicator_hidden,
|
|
||||||
OSCapabilities::home_indicator_hidden_err_msg;
|
|
||||||
|object| {
|
|
||||||
unsafe {
|
|
||||||
let () = msg_send![object, setNeedsUpdateOfHomeIndicatorAutoHidden];
|
|
||||||
}
|
|
||||||
},
|
|
||||||
prefersHomeIndicatorAutoHidden,
|
|
||||||
}
|
|
||||||
add_property! {
|
|
||||||
decl,
|
|
||||||
supported_orientations: UIInterfaceOrientationMask,
|
|
||||||
setSupportedInterfaceOrientations: |object| {
|
|
||||||
unsafe {
|
|
||||||
let () = msg_send![class!(UIViewController), attemptRotationToDeviceOrientation];
|
|
||||||
}
|
|
||||||
},
|
|
||||||
supportedInterfaceOrientations,
|
|
||||||
}
|
|
||||||
add_property! {
|
|
||||||
decl,
|
|
||||||
preferred_screen_edges_deferring_system_gestures: UIRectEdge,
|
|
||||||
setPreferredScreenEdgesDeferringSystemGestures:
|
|
||||||
os_capabilities.defer_system_gestures,
|
|
||||||
OSCapabilities::defer_system_gestures_err_msg;
|
|
||||||
|object| {
|
|
||||||
unsafe {
|
|
||||||
let () = msg_send![object, setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
|
|
||||||
}
|
|
||||||
},
|
|
||||||
preferredScreenEdgesDeferringSystemGestures,
|
|
||||||
}
|
|
||||||
CLASS = Some(decl.register());
|
|
||||||
}
|
|
||||||
CLASS.unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
// requires main thread
|
|
||||||
unsafe fn get_window_class() -> &'static Class {
|
|
||||||
static mut CLASS: Option<&'static Class> = None;
|
|
||||||
if CLASS.is_none() {
|
|
||||||
let uiwindow_class = class!(UIWindow);
|
|
||||||
|
|
||||||
extern "C" fn become_key_window(object: &Object, _: Sel) {
|
|
||||||
unsafe {
|
|
||||||
app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::WindowEvent {
|
|
||||||
window_id: RootWindowId(object.into()),
|
|
||||||
event: WindowEvent::Focused(true),
|
|
||||||
}));
|
|
||||||
let () = msg_send![super(object, class!(UIWindow)), becomeKeyWindow];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" fn resign_key_window(object: &Object, _: Sel) {
|
|
||||||
unsafe {
|
|
||||||
app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::WindowEvent {
|
|
||||||
window_id: RootWindowId(object.into()),
|
|
||||||
event: WindowEvent::Focused(false),
|
|
||||||
}));
|
|
||||||
let () = msg_send![super(object, class!(UIWindow)), resignKeyWindow];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut decl = ClassDecl::new("WinitUIWindow", uiwindow_class)
|
|
||||||
.expect("Failed to declare class `WinitUIWindow`");
|
|
||||||
decl.add_method(
|
|
||||||
sel!(becomeKeyWindow),
|
|
||||||
become_key_window as extern "C" fn(&Object, Sel),
|
|
||||||
);
|
|
||||||
decl.add_method(
|
|
||||||
sel!(resignKeyWindow),
|
|
||||||
resign_key_window as extern "C" fn(&Object, Sel),
|
|
||||||
);
|
|
||||||
|
|
||||||
CLASS = Some(decl.register());
|
|
||||||
}
|
|
||||||
CLASS.unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
// requires main thread
|
|
||||||
pub unsafe fn create_view(
|
|
||||||
_window_attributes: &WindowAttributes,
|
|
||||||
platform_attributes: &PlatformSpecificWindowBuilderAttributes,
|
|
||||||
frame: CGRect,
|
|
||||||
) -> id {
|
|
||||||
let class = get_view_class(platform_attributes.root_view_class);
|
|
||||||
|
|
||||||
let view: id = msg_send![class, alloc];
|
|
||||||
assert!(!view.is_null(), "Failed to create `UIView` instance");
|
|
||||||
let view: id = msg_send![view, initWithFrame: frame];
|
|
||||||
assert!(!view.is_null(), "Failed to initialize `UIView` instance");
|
|
||||||
let () = msg_send![view, setMultipleTouchEnabled: YES];
|
|
||||||
if let Some(scale_factor) = platform_attributes.scale_factor {
|
|
||||||
let () = msg_send![view, setContentScaleFactor: scale_factor as CGFloat];
|
|
||||||
}
|
|
||||||
|
|
||||||
view
|
|
||||||
}
|
|
||||||
|
|
||||||
// requires main thread
|
|
||||||
pub unsafe fn create_view_controller(
|
|
||||||
_window_attributes: &WindowAttributes,
|
|
||||||
platform_attributes: &PlatformSpecificWindowBuilderAttributes,
|
|
||||||
view: id,
|
|
||||||
) -> id {
|
|
||||||
let class = get_view_controller_class();
|
|
||||||
|
|
||||||
let view_controller: id = msg_send![class, alloc];
|
|
||||||
assert!(
|
|
||||||
!view_controller.is_null(),
|
|
||||||
"Failed to create `UIViewController` instance"
|
|
||||||
);
|
|
||||||
let view_controller: id = msg_send![view_controller, init];
|
|
||||||
assert!(
|
|
||||||
!view_controller.is_null(),
|
|
||||||
"Failed to initialize `UIViewController` instance"
|
|
||||||
);
|
|
||||||
let status_bar_hidden = if platform_attributes.prefers_status_bar_hidden {
|
|
||||||
YES
|
|
||||||
} else {
|
|
||||||
NO
|
|
||||||
};
|
|
||||||
let idiom = event_loop::get_idiom();
|
|
||||||
let supported_orientations = UIInterfaceOrientationMask::from_valid_orientations_idiom(
|
|
||||||
platform_attributes.valid_orientations,
|
|
||||||
idiom,
|
|
||||||
);
|
|
||||||
let prefers_home_indicator_hidden = if platform_attributes.prefers_home_indicator_hidden {
|
|
||||||
YES
|
|
||||||
} else {
|
|
||||||
NO
|
|
||||||
};
|
|
||||||
let edges: UIRectEdge = platform_attributes
|
|
||||||
.preferred_screen_edges_deferring_system_gestures
|
|
||||||
.into();
|
|
||||||
let () = msg_send![
|
|
||||||
view_controller,
|
|
||||||
setPrefersStatusBarHidden: status_bar_hidden
|
|
||||||
];
|
|
||||||
let () = msg_send![
|
|
||||||
view_controller,
|
|
||||||
setSupportedInterfaceOrientations: supported_orientations
|
|
||||||
];
|
|
||||||
let () = msg_send![
|
|
||||||
view_controller,
|
|
||||||
setPrefersHomeIndicatorAutoHidden: prefers_home_indicator_hidden
|
|
||||||
];
|
|
||||||
let () = msg_send![
|
|
||||||
view_controller,
|
|
||||||
setPreferredScreenEdgesDeferringSystemGestures: edges
|
|
||||||
];
|
|
||||||
let () = msg_send![view_controller, setView: view];
|
|
||||||
view_controller
|
|
||||||
}
|
|
||||||
|
|
||||||
// requires main thread
|
|
||||||
pub unsafe fn create_window(
|
|
||||||
window_attributes: &WindowAttributes,
|
|
||||||
_platform_attributes: &PlatformSpecificWindowBuilderAttributes,
|
|
||||||
frame: CGRect,
|
|
||||||
view_controller: id,
|
|
||||||
) -> id {
|
|
||||||
let class = get_window_class();
|
|
||||||
|
|
||||||
let window: id = msg_send![class, alloc];
|
|
||||||
assert!(!window.is_null(), "Failed to create `UIWindow` instance");
|
|
||||||
let window: id = msg_send![window, initWithFrame: frame];
|
|
||||||
assert!(
|
|
||||||
!window.is_null(),
|
|
||||||
"Failed to initialize `UIWindow` instance"
|
|
||||||
);
|
|
||||||
let () = msg_send![window, setRootViewController: view_controller];
|
|
||||||
match window_attributes.fullscreen {
|
|
||||||
Some(Fullscreen::Exclusive(ref video_mode)) => {
|
|
||||||
let uiscreen = video_mode.monitor().ui_screen() as id;
|
|
||||||
let () = msg_send![uiscreen, setCurrentMode: video_mode.video_mode.screen_mode.0];
|
|
||||||
msg_send![window, setScreen:video_mode.monitor().ui_screen()]
|
|
||||||
}
|
|
||||||
Some(Fullscreen::Borderless(ref monitor)) => {
|
|
||||||
msg_send![window, setScreen:monitor.ui_screen()]
|
|
||||||
}
|
|
||||||
None => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
window
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create_delegate_class() {
|
|
||||||
extern "C" fn did_finish_launching(_: &mut Object, _: Sel, _: id, _: id) -> BOOL {
|
|
||||||
unsafe {
|
|
||||||
app_state::did_finish_launching();
|
|
||||||
}
|
|
||||||
YES
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" fn did_become_active(_: &Object, _: Sel, _: id) {
|
|
||||||
unsafe { app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::Resumed)) }
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" fn will_resign_active(_: &Object, _: Sel, _: id) {
|
|
||||||
unsafe { app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::Suspended)) }
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" fn will_enter_foreground(_: &Object, _: Sel, _: id) {}
|
|
||||||
extern "C" fn did_enter_background(_: &Object, _: Sel, _: id) {}
|
|
||||||
|
|
||||||
extern "C" fn will_terminate(_: &Object, _: Sel, _: id) {
|
|
||||||
unsafe {
|
|
||||||
let app: id = msg_send![class!(UIApplication), sharedApplication];
|
|
||||||
let windows: id = msg_send![app, windows];
|
|
||||||
let windows_enum: id = msg_send![windows, objectEnumerator];
|
|
||||||
let mut events = Vec::new();
|
|
||||||
loop {
|
|
||||||
let window: id = msg_send![windows_enum, nextObject];
|
|
||||||
if window == nil {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
let is_winit_window: BOOL = msg_send![window, isKindOfClass: class!(WinitUIWindow)];
|
|
||||||
if is_winit_window == YES {
|
|
||||||
events.push(EventWrapper::StaticEvent(Event::WindowEvent {
|
|
||||||
window_id: RootWindowId(window.into()),
|
|
||||||
event: WindowEvent::Destroyed,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
app_state::handle_nonuser_events(events);
|
|
||||||
app_state::terminated();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let ui_responder = class!(UIResponder);
|
|
||||||
let mut decl =
|
|
||||||
ClassDecl::new("AppDelegate", ui_responder).expect("Failed to declare class `AppDelegate`");
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
decl.add_method(
|
|
||||||
sel!(application:didFinishLaunchingWithOptions:),
|
|
||||||
did_finish_launching as extern "C" fn(&mut Object, Sel, id, id) -> BOOL,
|
|
||||||
);
|
|
||||||
|
|
||||||
decl.add_method(
|
|
||||||
sel!(applicationDidBecomeActive:),
|
|
||||||
did_become_active as extern "C" fn(&Object, Sel, id),
|
|
||||||
);
|
|
||||||
decl.add_method(
|
|
||||||
sel!(applicationWillResignActive:),
|
|
||||||
will_resign_active as extern "C" fn(&Object, Sel, id),
|
|
||||||
);
|
|
||||||
decl.add_method(
|
|
||||||
sel!(applicationWillEnterForeground:),
|
|
||||||
will_enter_foreground as extern "C" fn(&Object, Sel, id),
|
|
||||||
);
|
|
||||||
decl.add_method(
|
|
||||||
sel!(applicationDidEnterBackground:),
|
|
||||||
did_enter_background as extern "C" fn(&Object, Sel, id),
|
|
||||||
);
|
|
||||||
|
|
||||||
decl.add_method(
|
|
||||||
sel!(applicationWillTerminate:),
|
|
||||||
will_terminate as extern "C" fn(&Object, Sel, id),
|
|
||||||
);
|
|
||||||
|
|
||||||
decl.register();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,638 +0,0 @@
|
|||||||
use raw_window_handle::{ios::IOSHandle, RawWindowHandle};
|
|
||||||
use std::{
|
|
||||||
collections::VecDeque,
|
|
||||||
ops::{Deref, DerefMut},
|
|
||||||
};
|
|
||||||
|
|
||||||
use objc::runtime::{Class, Object, BOOL, NO, YES};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
dpi::{self, LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size},
|
|
||||||
error::{ExternalError, NotSupportedError, OsError as RootOsError},
|
|
||||||
event::{Event, WindowEvent},
|
|
||||||
icon::Icon,
|
|
||||||
monitor::MonitorHandle as RootMonitorHandle,
|
|
||||||
platform::ios::{MonitorHandleExtIOS, ScreenEdge, ValidOrientations},
|
|
||||||
platform_impl::platform::{
|
|
||||||
app_state,
|
|
||||||
event_loop::{self, EventProxy, EventWrapper},
|
|
||||||
ffi::{
|
|
||||||
id, CGFloat, CGPoint, CGRect, CGSize, UIEdgeInsets, UIInterfaceOrientationMask,
|
|
||||||
UIRectEdge, UIScreenOverscanCompensation,
|
|
||||||
},
|
|
||||||
monitor, view, EventLoopWindowTarget, MonitorHandle,
|
|
||||||
},
|
|
||||||
window::{CursorIcon, Fullscreen, WindowAttributes, WindowId as RootWindowId},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct Inner {
|
|
||||||
pub window: id,
|
|
||||||
pub view_controller: id,
|
|
||||||
pub view: id,
|
|
||||||
gl_or_metal_backed: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for Inner {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
unsafe {
|
|
||||||
let () = msg_send![self.view, release];
|
|
||||||
let () = msg_send![self.view_controller, release];
|
|
||||||
let () = msg_send![self.window, release];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Inner {
|
|
||||||
pub fn set_title(&self, _title: &str) {
|
|
||||||
debug!("`Window::set_title` is ignored on iOS")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_visible(&self, visible: bool) {
|
|
||||||
match visible {
|
|
||||||
true => unsafe {
|
|
||||||
let () = msg_send![self.window, setHidden: NO];
|
|
||||||
},
|
|
||||||
false => unsafe {
|
|
||||||
let () = msg_send![self.window, setHidden: YES];
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn request_redraw(&self) {
|
|
||||||
unsafe {
|
|
||||||
if self.gl_or_metal_backed {
|
|
||||||
// `setNeedsDisplay` does nothing on UIViews which are directly backed by CAEAGLLayer or CAMetalLayer.
|
|
||||||
// Ordinarily the OS sets up a bunch of UIKit state before calling drawRect: on a UIView, but when using
|
|
||||||
// raw or gl/metal for drawing this work is completely avoided.
|
|
||||||
//
|
|
||||||
// The docs for `setNeedsDisplay` don't mention `CAMetalLayer`; however, this has been confirmed via
|
|
||||||
// testing.
|
|
||||||
//
|
|
||||||
// https://developer.apple.com/documentation/uikit/uiview/1622437-setneedsdisplay?language=objc
|
|
||||||
app_state::queue_gl_or_metal_redraw(self.window);
|
|
||||||
} else {
|
|
||||||
let () = msg_send![self.view, setNeedsDisplay];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
|
||||||
unsafe {
|
|
||||||
let safe_area = self.safe_area_screen_space();
|
|
||||||
let position = LogicalPosition {
|
|
||||||
x: safe_area.origin.x as f64,
|
|
||||||
y: safe_area.origin.y as f64,
|
|
||||||
};
|
|
||||||
let scale_factor = self.scale_factor();
|
|
||||||
Ok(position.to_physical(scale_factor))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
|
||||||
unsafe {
|
|
||||||
let screen_frame = self.screen_frame();
|
|
||||||
let position = LogicalPosition {
|
|
||||||
x: screen_frame.origin.x as f64,
|
|
||||||
y: screen_frame.origin.y as f64,
|
|
||||||
};
|
|
||||||
let scale_factor = self.scale_factor();
|
|
||||||
Ok(position.to_physical(scale_factor))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_outer_position(&self, physical_position: Position) {
|
|
||||||
unsafe {
|
|
||||||
let scale_factor = self.scale_factor();
|
|
||||||
let position = physical_position.to_logical::<f64>(scale_factor);
|
|
||||||
let screen_frame = self.screen_frame();
|
|
||||||
let new_screen_frame = CGRect {
|
|
||||||
origin: CGPoint {
|
|
||||||
x: position.x as _,
|
|
||||||
y: position.y as _,
|
|
||||||
},
|
|
||||||
size: screen_frame.size,
|
|
||||||
};
|
|
||||||
let bounds = self.from_screen_space(new_screen_frame);
|
|
||||||
let () = msg_send![self.window, setBounds: bounds];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn inner_size(&self) -> PhysicalSize<u32> {
|
|
||||||
unsafe {
|
|
||||||
let scale_factor = self.scale_factor();
|
|
||||||
let safe_area = self.safe_area_screen_space();
|
|
||||||
let size = LogicalSize {
|
|
||||||
width: safe_area.size.width as f64,
|
|
||||||
height: safe_area.size.height as f64,
|
|
||||||
};
|
|
||||||
size.to_physical(scale_factor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn outer_size(&self) -> PhysicalSize<u32> {
|
|
||||||
unsafe {
|
|
||||||
let scale_factor = self.scale_factor();
|
|
||||||
let screen_frame = self.screen_frame();
|
|
||||||
let size = LogicalSize {
|
|
||||||
width: screen_frame.size.width as f64,
|
|
||||||
height: screen_frame.size.height as f64,
|
|
||||||
};
|
|
||||||
size.to_physical(scale_factor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_inner_size(&self, _size: Size) {
|
|
||||||
unimplemented!("not clear what `Window::set_inner_size` means on iOS");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_min_inner_size(&self, _dimensions: Option<Size>) {
|
|
||||||
warn!("`Window::set_min_inner_size` is ignored on iOS")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_max_inner_size(&self, _dimensions: Option<Size>) {
|
|
||||||
warn!("`Window::set_max_inner_size` is ignored on iOS")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_resizable(&self, _resizable: bool) {
|
|
||||||
warn!("`Window::set_resizable` is ignored on iOS")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn scale_factor(&self) -> f64 {
|
|
||||||
unsafe {
|
|
||||||
let hidpi: CGFloat = msg_send![self.view, contentScaleFactor];
|
|
||||||
hidpi as _
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_cursor_icon(&self, _cursor: CursorIcon) {
|
|
||||||
debug!("`Window::set_cursor_icon` ignored on iOS")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_cursor_position(&self, _position: Position) -> Result<(), ExternalError> {
|
|
||||||
Err(ExternalError::NotSupported(NotSupportedError::new()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_cursor_grab(&self, _grab: bool) -> Result<(), ExternalError> {
|
|
||||||
Err(ExternalError::NotSupported(NotSupportedError::new()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_cursor_visible(&self, _visible: bool) {
|
|
||||||
debug!("`Window::set_cursor_visible` is ignored on iOS")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_minimized(&self, _minimized: bool) {
|
|
||||||
warn!("`Window::set_minimized` is ignored on iOS")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_maximized(&self, _maximized: bool) {
|
|
||||||
warn!("`Window::set_maximized` is ignored on iOS")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_fullscreen(&self, monitor: Option<Fullscreen>) {
|
|
||||||
unsafe {
|
|
||||||
let uiscreen = match monitor {
|
|
||||||
Some(Fullscreen::Exclusive(video_mode)) => {
|
|
||||||
let uiscreen = video_mode.video_mode.monitor.ui_screen() as id;
|
|
||||||
let () = msg_send![uiscreen, setCurrentMode: video_mode.video_mode.screen_mode];
|
|
||||||
uiscreen
|
|
||||||
}
|
|
||||||
Some(Fullscreen::Borderless(monitor)) => monitor.ui_screen() as id,
|
|
||||||
None => {
|
|
||||||
warn!("`Window::set_fullscreen(None)` ignored on iOS");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// this is pretty slow on iOS, so avoid doing it if we can
|
|
||||||
let current: id = msg_send![self.window, screen];
|
|
||||||
if uiscreen != current {
|
|
||||||
let () = msg_send![self.window, setScreen: uiscreen];
|
|
||||||
}
|
|
||||||
|
|
||||||
let bounds: CGRect = msg_send![uiscreen, bounds];
|
|
||||||
let () = msg_send![self.window, setFrame: bounds];
|
|
||||||
|
|
||||||
// For external displays, we must disable overscan compensation or
|
|
||||||
// the displayed image will have giant black bars surrounding it on
|
|
||||||
// each side
|
|
||||||
let () = msg_send![
|
|
||||||
uiscreen,
|
|
||||||
setOverscanCompensation: UIScreenOverscanCompensation::None
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn fullscreen(&self) -> Option<Fullscreen> {
|
|
||||||
unsafe {
|
|
||||||
let monitor = self.current_monitor();
|
|
||||||
let uiscreen = monitor.inner.ui_screen();
|
|
||||||
let screen_space_bounds = self.screen_frame();
|
|
||||||
let screen_bounds: CGRect = msg_send![uiscreen, bounds];
|
|
||||||
|
|
||||||
// TODO: track fullscreen instead of relying on brittle float comparisons
|
|
||||||
if screen_space_bounds.origin.x == screen_bounds.origin.x
|
|
||||||
&& screen_space_bounds.origin.y == screen_bounds.origin.y
|
|
||||||
&& screen_space_bounds.size.width == screen_bounds.size.width
|
|
||||||
&& screen_space_bounds.size.height == screen_bounds.size.height
|
|
||||||
{
|
|
||||||
Some(Fullscreen::Borderless(monitor))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_decorations(&self, _decorations: bool) {
|
|
||||||
warn!("`Window::set_decorations` is ignored on iOS")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_always_on_top(&self, _always_on_top: bool) {
|
|
||||||
warn!("`Window::set_always_on_top` is ignored on iOS")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_window_icon(&self, _icon: Option<Icon>) {
|
|
||||||
warn!("`Window::set_window_icon` is ignored on iOS")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_ime_position(&self, _position: Position) {
|
|
||||||
warn!("`Window::set_ime_position` is ignored on iOS")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn current_monitor(&self) -> RootMonitorHandle {
|
|
||||||
unsafe {
|
|
||||||
let uiscreen: id = msg_send![self.window, screen];
|
|
||||||
RootMonitorHandle {
|
|
||||||
inner: MonitorHandle::retained_new(uiscreen),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
|
|
||||||
unsafe { monitor::uiscreens() }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn primary_monitor(&self) -> MonitorHandle {
|
|
||||||
unsafe { monitor::main_uiscreen() }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn id(&self) -> WindowId {
|
|
||||||
self.window.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn raw_window_handle(&self) -> RawWindowHandle {
|
|
||||||
let handle = IOSHandle {
|
|
||||||
ui_window: self.window as _,
|
|
||||||
ui_view: self.view as _,
|
|
||||||
ui_view_controller: self.view_controller as _,
|
|
||||||
..IOSHandle::empty()
|
|
||||||
};
|
|
||||||
RawWindowHandle::IOS(handle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Window {
|
|
||||||
pub inner: Inner,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for Window {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
unsafe {
|
|
||||||
assert_main_thread!("`Window::drop` can only be run on the main thread on iOS");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl Send for Window {}
|
|
||||||
unsafe impl Sync for Window {}
|
|
||||||
|
|
||||||
impl Deref for Window {
|
|
||||||
type Target = Inner;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Inner {
|
|
||||||
unsafe {
|
|
||||||
assert_main_thread!("`Window` methods can only be run on the main thread on iOS");
|
|
||||||
}
|
|
||||||
&self.inner
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DerefMut for Window {
|
|
||||||
fn deref_mut(&mut self) -> &mut Inner {
|
|
||||||
unsafe {
|
|
||||||
assert_main_thread!("`Window` methods can only be run on the main thread on iOS");
|
|
||||||
}
|
|
||||||
&mut self.inner
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Window {
|
|
||||||
pub fn new<T>(
|
|
||||||
_event_loop: &EventLoopWindowTarget<T>,
|
|
||||||
window_attributes: WindowAttributes,
|
|
||||||
platform_attributes: PlatformSpecificWindowBuilderAttributes,
|
|
||||||
) -> Result<Window, RootOsError> {
|
|
||||||
if let Some(_) = window_attributes.min_inner_size {
|
|
||||||
warn!("`WindowAttributes::min_inner_size` is ignored on iOS");
|
|
||||||
}
|
|
||||||
if let Some(_) = window_attributes.max_inner_size {
|
|
||||||
warn!("`WindowAttributes::max_inner_size` is ignored on iOS");
|
|
||||||
}
|
|
||||||
if window_attributes.always_on_top {
|
|
||||||
warn!("`WindowAttributes::always_on_top` is unsupported on iOS");
|
|
||||||
}
|
|
||||||
// TODO: transparency, visible
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
let screen = match window_attributes.fullscreen {
|
|
||||||
Some(Fullscreen::Exclusive(ref video_mode)) => {
|
|
||||||
video_mode.video_mode.monitor.ui_screen() as id
|
|
||||||
}
|
|
||||||
Some(Fullscreen::Borderless(ref monitor)) => monitor.ui_screen() as id,
|
|
||||||
None => monitor::main_uiscreen().ui_screen(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let screen_bounds: CGRect = msg_send![screen, bounds];
|
|
||||||
|
|
||||||
let frame = match window_attributes.inner_size {
|
|
||||||
Some(dim) => {
|
|
||||||
let scale_factor = msg_send![screen, scale];
|
|
||||||
let size = dim.to_logical::<f64>(scale_factor);
|
|
||||||
CGRect {
|
|
||||||
origin: screen_bounds.origin,
|
|
||||||
size: CGSize {
|
|
||||||
width: size.width as _,
|
|
||||||
height: size.height as _,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => screen_bounds,
|
|
||||||
};
|
|
||||||
|
|
||||||
let view = view::create_view(&window_attributes, &platform_attributes, frame.clone());
|
|
||||||
|
|
||||||
let gl_or_metal_backed = {
|
|
||||||
let view_class: id = msg_send![view, class];
|
|
||||||
let layer_class: id = msg_send![view_class, layerClass];
|
|
||||||
let is_metal: BOOL =
|
|
||||||
msg_send![layer_class, isSubclassOfClass: class!(CAMetalLayer)];
|
|
||||||
let is_gl: BOOL = msg_send![layer_class, isSubclassOfClass: class!(CAEAGLLayer)];
|
|
||||||
is_metal == YES || is_gl == YES
|
|
||||||
};
|
|
||||||
|
|
||||||
let view_controller =
|
|
||||||
view::create_view_controller(&window_attributes, &platform_attributes, view);
|
|
||||||
let window = view::create_window(
|
|
||||||
&window_attributes,
|
|
||||||
&platform_attributes,
|
|
||||||
frame,
|
|
||||||
view_controller,
|
|
||||||
);
|
|
||||||
|
|
||||||
let result = Window {
|
|
||||||
inner: Inner {
|
|
||||||
window,
|
|
||||||
view_controller,
|
|
||||||
view,
|
|
||||||
gl_or_metal_backed,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
app_state::set_key_window(window);
|
|
||||||
|
|
||||||
// Like the Windows and macOS backends, we send a `ScaleFactorChanged` and `Resized`
|
|
||||||
// event on window creation if the DPI factor != 1.0
|
|
||||||
let scale_factor: CGFloat = msg_send![view, contentScaleFactor];
|
|
||||||
let scale_factor: f64 = scale_factor.into();
|
|
||||||
if scale_factor != 1.0 {
|
|
||||||
let bounds: CGRect = msg_send![view, bounds];
|
|
||||||
let screen: id = msg_send![window, screen];
|
|
||||||
let screen_space: id = msg_send![screen, coordinateSpace];
|
|
||||||
let screen_frame: CGRect =
|
|
||||||
msg_send![view, convertRect:bounds toCoordinateSpace:screen_space];
|
|
||||||
let size = crate::dpi::LogicalSize {
|
|
||||||
width: screen_frame.size.width as _,
|
|
||||||
height: screen_frame.size.height as _,
|
|
||||||
};
|
|
||||||
app_state::handle_nonuser_events(
|
|
||||||
std::iter::once(EventWrapper::EventProxy(EventProxy::DpiChangedProxy {
|
|
||||||
window_id: window,
|
|
||||||
scale_factor,
|
|
||||||
suggested_size: size,
|
|
||||||
}))
|
|
||||||
.chain(std::iter::once(EventWrapper::StaticEvent(
|
|
||||||
Event::WindowEvent {
|
|
||||||
window_id: RootWindowId(window.into()),
|
|
||||||
event: WindowEvent::Resized(size.to_physical(scale_factor)),
|
|
||||||
},
|
|
||||||
))),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WindowExtIOS
|
|
||||||
impl Inner {
|
|
||||||
pub fn ui_window(&self) -> id {
|
|
||||||
self.window
|
|
||||||
}
|
|
||||||
pub fn ui_view_controller(&self) -> id {
|
|
||||||
self.view_controller
|
|
||||||
}
|
|
||||||
pub fn ui_view(&self) -> id {
|
|
||||||
self.view
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_scale_factor(&self, scale_factor: f64) {
|
|
||||||
unsafe {
|
|
||||||
assert!(
|
|
||||||
dpi::validate_scale_factor(scale_factor),
|
|
||||||
"`WindowExtIOS::set_scale_factor` received an invalid hidpi factor"
|
|
||||||
);
|
|
||||||
let scale_factor = scale_factor as CGFloat;
|
|
||||||
let () = msg_send![self.view, setContentScaleFactor: scale_factor];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_valid_orientations(&self, valid_orientations: ValidOrientations) {
|
|
||||||
unsafe {
|
|
||||||
let idiom = event_loop::get_idiom();
|
|
||||||
let supported_orientations = UIInterfaceOrientationMask::from_valid_orientations_idiom(
|
|
||||||
valid_orientations,
|
|
||||||
idiom,
|
|
||||||
);
|
|
||||||
msg_send![
|
|
||||||
self.view_controller,
|
|
||||||
setSupportedInterfaceOrientations: supported_orientations
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_prefers_home_indicator_hidden(&self, hidden: bool) {
|
|
||||||
unsafe {
|
|
||||||
let prefers_home_indicator_hidden = if hidden { YES } else { NO };
|
|
||||||
let () = msg_send![
|
|
||||||
self.view_controller,
|
|
||||||
setPrefersHomeIndicatorAutoHidden: prefers_home_indicator_hidden
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_preferred_screen_edges_deferring_system_gestures(&self, edges: ScreenEdge) {
|
|
||||||
let edges: UIRectEdge = edges.into();
|
|
||||||
unsafe {
|
|
||||||
let () = msg_send![
|
|
||||||
self.view_controller,
|
|
||||||
setPreferredScreenEdgesDeferringSystemGestures: edges
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_prefers_status_bar_hidden(&self, hidden: bool) {
|
|
||||||
unsafe {
|
|
||||||
let status_bar_hidden = if hidden { YES } else { NO };
|
|
||||||
let () = msg_send![
|
|
||||||
self.view_controller,
|
|
||||||
setPrefersStatusBarHidden: status_bar_hidden
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Inner {
|
|
||||||
// requires main thread
|
|
||||||
unsafe fn screen_frame(&self) -> CGRect {
|
|
||||||
self.to_screen_space(msg_send![self.window, bounds])
|
|
||||||
}
|
|
||||||
|
|
||||||
// requires main thread
|
|
||||||
unsafe fn to_screen_space(&self, rect: CGRect) -> CGRect {
|
|
||||||
let screen: id = msg_send![self.window, screen];
|
|
||||||
if !screen.is_null() {
|
|
||||||
let screen_space: id = msg_send![screen, coordinateSpace];
|
|
||||||
msg_send![self.window, convertRect:rect toCoordinateSpace:screen_space]
|
|
||||||
} else {
|
|
||||||
rect
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// requires main thread
|
|
||||||
unsafe fn from_screen_space(&self, rect: CGRect) -> CGRect {
|
|
||||||
let screen: id = msg_send![self.window, screen];
|
|
||||||
if !screen.is_null() {
|
|
||||||
let screen_space: id = msg_send![screen, coordinateSpace];
|
|
||||||
msg_send![self.window, convertRect:rect fromCoordinateSpace:screen_space]
|
|
||||||
} else {
|
|
||||||
rect
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// requires main thread
|
|
||||||
unsafe fn safe_area_screen_space(&self) -> CGRect {
|
|
||||||
let bounds: CGRect = msg_send![self.window, bounds];
|
|
||||||
if app_state::os_capabilities().safe_area {
|
|
||||||
let safe_area: UIEdgeInsets = msg_send![self.window, safeAreaInsets];
|
|
||||||
let safe_bounds = CGRect {
|
|
||||||
origin: CGPoint {
|
|
||||||
x: bounds.origin.x + safe_area.left,
|
|
||||||
y: bounds.origin.y + safe_area.top,
|
|
||||||
},
|
|
||||||
size: CGSize {
|
|
||||||
width: bounds.size.width - safe_area.left - safe_area.right,
|
|
||||||
height: bounds.size.height - safe_area.top - safe_area.bottom,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
self.to_screen_space(safe_bounds)
|
|
||||||
} else {
|
|
||||||
let screen_frame = self.to_screen_space(bounds);
|
|
||||||
let status_bar_frame: CGRect = {
|
|
||||||
let app: id = msg_send![class!(UIApplication), sharedApplication];
|
|
||||||
assert!(
|
|
||||||
!app.is_null(),
|
|
||||||
"`Window::get_inner_position` cannot be called before `EventLoop::run` on iOS"
|
|
||||||
);
|
|
||||||
msg_send![app, statusBarFrame]
|
|
||||||
};
|
|
||||||
let (y, height) = if screen_frame.origin.y > status_bar_frame.size.height {
|
|
||||||
(screen_frame.origin.y, screen_frame.size.height)
|
|
||||||
} else {
|
|
||||||
let y = status_bar_frame.size.height;
|
|
||||||
let height = screen_frame.size.height
|
|
||||||
- (status_bar_frame.size.height - screen_frame.origin.y);
|
|
||||||
(y, height)
|
|
||||||
};
|
|
||||||
CGRect {
|
|
||||||
origin: CGPoint {
|
|
||||||
x: screen_frame.origin.x,
|
|
||||||
y,
|
|
||||||
},
|
|
||||||
size: CGSize {
|
|
||||||
width: screen_frame.size.width,
|
|
||||||
height,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub struct WindowId {
|
|
||||||
window: id,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WindowId {
|
|
||||||
pub unsafe fn dummy() -> Self {
|
|
||||||
WindowId {
|
|
||||||
window: std::ptr::null_mut(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl Send for WindowId {}
|
|
||||||
unsafe impl Sync for WindowId {}
|
|
||||||
|
|
||||||
impl From<&Object> for WindowId {
|
|
||||||
fn from(window: &Object) -> WindowId {
|
|
||||||
WindowId {
|
|
||||||
window: window as *const _ as _,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&mut Object> for WindowId {
|
|
||||||
fn from(window: &mut Object) -> WindowId {
|
|
||||||
WindowId {
|
|
||||||
window: window as _,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<id> for WindowId {
|
|
||||||
fn from(window: id) -> WindowId {
|
|
||||||
WindowId { window }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct PlatformSpecificWindowBuilderAttributes {
|
|
||||||
pub root_view_class: &'static Class,
|
|
||||||
pub scale_factor: Option<f64>,
|
|
||||||
pub valid_orientations: ValidOrientations,
|
|
||||||
pub prefers_home_indicator_hidden: bool,
|
|
||||||
pub prefers_status_bar_hidden: bool,
|
|
||||||
pub preferred_screen_edges_deferring_system_gestures: ScreenEdge,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for PlatformSpecificWindowBuilderAttributes {
|
|
||||||
fn default() -> PlatformSpecificWindowBuilderAttributes {
|
|
||||||
PlatformSpecificWindowBuilderAttributes {
|
|
||||||
root_view_class: class!(UIView),
|
|
||||||
scale_factor: None,
|
|
||||||
valid_orientations: Default::default(),
|
|
||||||
prefers_home_indicator_hidden: false,
|
|
||||||
prefers_status_bar_hidden: false,
|
|
||||||
preferred_screen_edges_deferring_system_gestures: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,731 +0,0 @@
|
|||||||
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
|
|
||||||
|
|
||||||
use std::{collections::VecDeque, env, ffi::CStr, fmt, mem::MaybeUninit, os::raw::*, sync::Arc};
|
|
||||||
|
|
||||||
use parking_lot::Mutex;
|
|
||||||
use raw_window_handle::RawWindowHandle;
|
|
||||||
use smithay_client_toolkit::reexports::client::ConnectError;
|
|
||||||
|
|
||||||
pub use self::x11::XNotSupported;
|
|
||||||
use self::x11::{ffi::XVisualInfo, util::WindowType as XWindowType, XConnection, XError};
|
|
||||||
use crate::{
|
|
||||||
dpi::{PhysicalPosition, PhysicalSize, Position, Size},
|
|
||||||
error::{ExternalError, NotSupportedError, OsError as RootOsError},
|
|
||||||
event::Event,
|
|
||||||
event_loop::{ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootELW},
|
|
||||||
icon::Icon,
|
|
||||||
monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode},
|
|
||||||
window::{CursorIcon, Fullscreen, WindowAttributes},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub(crate) use crate::icon::RgbaIcon as PlatformIcon;
|
|
||||||
|
|
||||||
pub mod wayland;
|
|
||||||
pub mod x11;
|
|
||||||
|
|
||||||
/// Environment variable specifying which backend should be used on unix platform.
|
|
||||||
///
|
|
||||||
/// Legal values are x11 and wayland. If this variable is set only the named backend
|
|
||||||
/// will be tried by winit. If it is not set, winit will try to connect to a wayland connection,
|
|
||||||
/// and if it fails will fallback on x11.
|
|
||||||
///
|
|
||||||
/// If this variable is set with any other value, winit will panic.
|
|
||||||
const BACKEND_PREFERENCE_ENV_VAR: &str = "WINIT_UNIX_BACKEND";
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct PlatformSpecificWindowBuilderAttributes {
|
|
||||||
pub visual_infos: Option<XVisualInfo>,
|
|
||||||
pub screen_id: Option<i32>,
|
|
||||||
pub resize_increments: Option<Size>,
|
|
||||||
pub base_size: Option<Size>,
|
|
||||||
pub class: Option<(String, String)>,
|
|
||||||
pub override_redirect: bool,
|
|
||||||
pub x11_window_types: Vec<XWindowType>,
|
|
||||||
pub gtk_theme_variant: Option<String>,
|
|
||||||
pub app_id: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for PlatformSpecificWindowBuilderAttributes {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
visual_infos: None,
|
|
||||||
screen_id: None,
|
|
||||||
resize_increments: None,
|
|
||||||
base_size: None,
|
|
||||||
class: None,
|
|
||||||
override_redirect: false,
|
|
||||||
x11_window_types: vec![XWindowType::Normal],
|
|
||||||
gtk_theme_variant: None,
|
|
||||||
app_id: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
pub static ref X11_BACKEND: Mutex<Result<Arc<XConnection>, XNotSupported>> =
|
|
||||||
Mutex::new(XConnection::new(Some(x_error_callback)).map(Arc::new));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum OsError {
|
|
||||||
XError(XError),
|
|
||||||
XMisc(&'static str),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for OsError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
|
||||||
match self {
|
|
||||||
OsError::XError(e) => f.pad(&e.description),
|
|
||||||
OsError::XMisc(e) => f.pad(e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum Window {
|
|
||||||
X(x11::Window),
|
|
||||||
Wayland(wayland::Window),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub enum WindowId {
|
|
||||||
X(x11::WindowId),
|
|
||||||
Wayland(wayland::WindowId),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WindowId {
|
|
||||||
pub unsafe fn dummy() -> Self {
|
|
||||||
WindowId::Wayland(wayland::WindowId::dummy())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub enum DeviceId {
|
|
||||||
X(x11::DeviceId),
|
|
||||||
Wayland(wayland::DeviceId),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DeviceId {
|
|
||||||
pub unsafe fn dummy() -> Self {
|
|
||||||
DeviceId::Wayland(wayland::DeviceId::dummy())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
|
||||||
pub enum MonitorHandle {
|
|
||||||
X(x11::MonitorHandle),
|
|
||||||
Wayland(wayland::MonitorHandle),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MonitorHandle {
|
|
||||||
#[inline]
|
|
||||||
pub fn name(&self) -> Option<String> {
|
|
||||||
match self {
|
|
||||||
&MonitorHandle::X(ref m) => m.name(),
|
|
||||||
&MonitorHandle::Wayland(ref m) => m.name(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn native_identifier(&self) -> u32 {
|
|
||||||
match self {
|
|
||||||
&MonitorHandle::X(ref m) => m.native_identifier(),
|
|
||||||
&MonitorHandle::Wayland(ref m) => m.native_identifier(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn size(&self) -> PhysicalSize<u32> {
|
|
||||||
match self {
|
|
||||||
&MonitorHandle::X(ref m) => m.size(),
|
|
||||||
&MonitorHandle::Wayland(ref m) => m.size(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn position(&self) -> PhysicalPosition<i32> {
|
|
||||||
match self {
|
|
||||||
&MonitorHandle::X(ref m) => m.position(),
|
|
||||||
&MonitorHandle::Wayland(ref m) => m.position(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn scale_factor(&self) -> f64 {
|
|
||||||
match self {
|
|
||||||
&MonitorHandle::X(ref m) => m.scale_factor(),
|
|
||||||
&MonitorHandle::Wayland(ref m) => m.scale_factor() as f64,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn video_modes(&self) -> Box<dyn Iterator<Item = RootVideoMode>> {
|
|
||||||
match self {
|
|
||||||
MonitorHandle::X(m) => Box::new(m.video_modes()),
|
|
||||||
MonitorHandle::Wayland(m) => Box::new(m.video_modes()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub enum VideoMode {
|
|
||||||
X(x11::VideoMode),
|
|
||||||
Wayland(wayland::VideoMode),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VideoMode {
|
|
||||||
#[inline]
|
|
||||||
pub fn size(&self) -> PhysicalSize<u32> {
|
|
||||||
match self {
|
|
||||||
&VideoMode::X(ref m) => m.size(),
|
|
||||||
&VideoMode::Wayland(ref m) => m.size(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn bit_depth(&self) -> u16 {
|
|
||||||
match self {
|
|
||||||
&VideoMode::X(ref m) => m.bit_depth(),
|
|
||||||
&VideoMode::Wayland(ref m) => m.bit_depth(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn refresh_rate(&self) -> u16 {
|
|
||||||
match self {
|
|
||||||
&VideoMode::X(ref m) => m.refresh_rate(),
|
|
||||||
&VideoMode::Wayland(ref m) => m.refresh_rate(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn monitor(&self) -> RootMonitorHandle {
|
|
||||||
match self {
|
|
||||||
&VideoMode::X(ref m) => m.monitor(),
|
|
||||||
&VideoMode::Wayland(ref m) => m.monitor(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Window {
|
|
||||||
#[inline]
|
|
||||||
pub fn new<T>(
|
|
||||||
window_target: &EventLoopWindowTarget<T>,
|
|
||||||
attribs: WindowAttributes,
|
|
||||||
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
|
||||||
) -> Result<Self, RootOsError> {
|
|
||||||
match *window_target {
|
|
||||||
EventLoopWindowTarget::Wayland(ref window_target) => {
|
|
||||||
wayland::Window::new(window_target, attribs, pl_attribs).map(Window::Wayland)
|
|
||||||
}
|
|
||||||
EventLoopWindowTarget::X(ref window_target) => {
|
|
||||||
x11::Window::new(window_target, attribs, pl_attribs).map(Window::X)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn id(&self) -> WindowId {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => WindowId::X(w.id()),
|
|
||||||
&Window::Wayland(ref w) => WindowId::Wayland(w.id()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_title(&self, title: &str) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_title(title),
|
|
||||||
&Window::Wayland(ref w) => w.set_title(title),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_visible(&self, visible: bool) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_visible(visible),
|
|
||||||
&Window::Wayland(ref w) => w.set_visible(visible),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.outer_position(),
|
|
||||||
&Window::Wayland(ref w) => w.outer_position(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref m) => m.inner_position(),
|
|
||||||
&Window::Wayland(ref m) => m.inner_position(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_outer_position(&self, position: Position) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_outer_position(position),
|
|
||||||
&Window::Wayland(ref w) => w.set_outer_position(position),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn inner_size(&self) -> PhysicalSize<u32> {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.inner_size(),
|
|
||||||
&Window::Wayland(ref w) => w.inner_size(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn outer_size(&self) -> PhysicalSize<u32> {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.outer_size(),
|
|
||||||
&Window::Wayland(ref w) => w.outer_size(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_inner_size(&self, size: Size) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_inner_size(size),
|
|
||||||
&Window::Wayland(ref w) => w.set_inner_size(size),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_min_inner_size(&self, dimensions: Option<Size>) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_min_inner_size(dimensions),
|
|
||||||
&Window::Wayland(ref w) => w.set_min_inner_size(dimensions),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_max_inner_size(&self, dimensions: Option<Size>) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_max_inner_size(dimensions),
|
|
||||||
&Window::Wayland(ref w) => w.set_max_inner_size(dimensions),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_resizable(&self, resizable: bool) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_resizable(resizable),
|
|
||||||
&Window::Wayland(ref w) => w.set_resizable(resizable),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_cursor_icon(&self, cursor: CursorIcon) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_cursor_icon(cursor),
|
|
||||||
&Window::Wayland(ref w) => w.set_cursor_icon(cursor),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_cursor_grab(&self, grab: bool) -> Result<(), ExternalError> {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref window) => window.set_cursor_grab(grab),
|
|
||||||
&Window::Wayland(ref window) => window.set_cursor_grab(grab),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_cursor_visible(&self, visible: bool) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref window) => window.set_cursor_visible(visible),
|
|
||||||
&Window::Wayland(ref window) => window.set_cursor_visible(visible),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn scale_factor(&self) -> f64 {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.scale_factor(),
|
|
||||||
&Window::Wayland(ref w) => w.scale_factor() as f64,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_cursor_position(&self, position: Position) -> Result<(), ExternalError> {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_cursor_position(position),
|
|
||||||
&Window::Wayland(ref w) => w.set_cursor_position(position),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_maximized(&self, maximized: bool) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_maximized(maximized),
|
|
||||||
&Window::Wayland(ref w) => w.set_maximized(maximized),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_minimized(&self, minimized: bool) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_minimized(minimized),
|
|
||||||
&Window::Wayland(ref w) => w.set_minimized(minimized),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn fullscreen(&self) -> Option<Fullscreen> {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.fullscreen(),
|
|
||||||
&Window::Wayland(ref w) => w.fullscreen(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_fullscreen(&self, monitor: Option<Fullscreen>) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_fullscreen(monitor),
|
|
||||||
&Window::Wayland(ref w) => w.set_fullscreen(monitor),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_decorations(&self, decorations: bool) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_decorations(decorations),
|
|
||||||
&Window::Wayland(ref w) => w.set_decorations(decorations),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_always_on_top(&self, always_on_top: bool) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_always_on_top(always_on_top),
|
|
||||||
&Window::Wayland(_) => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_window_icon(&self, window_icon: Option<Icon>) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_window_icon(window_icon),
|
|
||||||
&Window::Wayland(_) => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_ime_position(&self, position: Position) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.set_ime_position(position),
|
|
||||||
&Window::Wayland(_) => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn request_redraw(&self) {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref w) => w.request_redraw(),
|
|
||||||
&Window::Wayland(ref w) => w.request_redraw(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn current_monitor(&self) -> RootMonitorHandle {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref window) => RootMonitorHandle {
|
|
||||||
inner: MonitorHandle::X(window.current_monitor()),
|
|
||||||
},
|
|
||||||
&Window::Wayland(ref window) => RootMonitorHandle {
|
|
||||||
inner: MonitorHandle::Wayland(window.current_monitor()),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref window) => window
|
|
||||||
.available_monitors()
|
|
||||||
.into_iter()
|
|
||||||
.map(MonitorHandle::X)
|
|
||||||
.collect(),
|
|
||||||
&Window::Wayland(ref window) => window
|
|
||||||
.available_monitors()
|
|
||||||
.into_iter()
|
|
||||||
.map(MonitorHandle::Wayland)
|
|
||||||
.collect(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn primary_monitor(&self) -> MonitorHandle {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref window) => MonitorHandle::X(window.primary_monitor()),
|
|
||||||
&Window::Wayland(ref window) => MonitorHandle::Wayland(window.primary_monitor()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn raw_window_handle(&self) -> RawWindowHandle {
|
|
||||||
match self {
|
|
||||||
&Window::X(ref window) => RawWindowHandle::Xlib(window.raw_window_handle()),
|
|
||||||
&Window::Wayland(ref window) => RawWindowHandle::Wayland(window.raw_window_handle()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe extern "C" fn x_error_callback(
|
|
||||||
display: *mut x11::ffi::Display,
|
|
||||||
event: *mut x11::ffi::XErrorEvent,
|
|
||||||
) -> c_int {
|
|
||||||
let xconn_lock = X11_BACKEND.lock();
|
|
||||||
if let Ok(ref xconn) = *xconn_lock {
|
|
||||||
// `assume_init` is safe here because the array consists of `MaybeUninit` values,
|
|
||||||
// which do not require initialization.
|
|
||||||
let mut buf: [MaybeUninit<c_char>; 1024] = MaybeUninit::uninit().assume_init();
|
|
||||||
(xconn.xlib.XGetErrorText)(
|
|
||||||
display,
|
|
||||||
(*event).error_code as c_int,
|
|
||||||
buf.as_mut_ptr() as *mut c_char,
|
|
||||||
buf.len() as c_int,
|
|
||||||
);
|
|
||||||
let description = CStr::from_ptr(buf.as_ptr() as *const c_char).to_string_lossy();
|
|
||||||
|
|
||||||
let error = XError {
|
|
||||||
description: description.into_owned(),
|
|
||||||
error_code: (*event).error_code,
|
|
||||||
request_code: (*event).request_code,
|
|
||||||
minor_code: (*event).minor_code,
|
|
||||||
};
|
|
||||||
|
|
||||||
error!("X11 error: {:#?}", error);
|
|
||||||
|
|
||||||
*xconn.latest_error.lock() = Some(error);
|
|
||||||
}
|
|
||||||
// Fun fact: this return value is completely ignored.
|
|
||||||
0
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum EventLoop<T: 'static> {
|
|
||||||
Wayland(wayland::EventLoop<T>),
|
|
||||||
X(x11::EventLoop<T>),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum EventLoopProxy<T: 'static> {
|
|
||||||
X(x11::EventLoopProxy<T>),
|
|
||||||
Wayland(wayland::EventLoopProxy<T>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: 'static> Clone for EventLoopProxy<T> {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
match self {
|
|
||||||
EventLoopProxy::X(proxy) => EventLoopProxy::X(proxy.clone()),
|
|
||||||
EventLoopProxy::Wayland(proxy) => EventLoopProxy::Wayland(proxy.clone()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: 'static> EventLoop<T> {
|
|
||||||
pub fn new() -> EventLoop<T> {
|
|
||||||
assert_is_main_thread("new_any_thread");
|
|
||||||
|
|
||||||
EventLoop::new_any_thread()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_any_thread() -> EventLoop<T> {
|
|
||||||
if let Ok(env_var) = env::var(BACKEND_PREFERENCE_ENV_VAR) {
|
|
||||||
match env_var.as_str() {
|
|
||||||
"x11" => {
|
|
||||||
// TODO: propagate
|
|
||||||
return EventLoop::new_x11_any_thread()
|
|
||||||
.expect("Failed to initialize X11 backend");
|
|
||||||
}
|
|
||||||
"wayland" => {
|
|
||||||
return EventLoop::new_wayland_any_thread()
|
|
||||||
.expect("Failed to initialize Wayland backend");
|
|
||||||
}
|
|
||||||
_ => panic!(
|
|
||||||
"Unknown environment variable value for {}, try one of `x11`,`wayland`",
|
|
||||||
BACKEND_PREFERENCE_ENV_VAR,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let wayland_err = match EventLoop::new_wayland_any_thread() {
|
|
||||||
Ok(event_loop) => return event_loop,
|
|
||||||
Err(err) => err,
|
|
||||||
};
|
|
||||||
|
|
||||||
let x11_err = match EventLoop::new_x11_any_thread() {
|
|
||||||
Ok(event_loop) => return event_loop,
|
|
||||||
Err(err) => err,
|
|
||||||
};
|
|
||||||
|
|
||||||
let err_string = format!(
|
|
||||||
"Failed to initialize any backend! Wayland status: {:?} X11 status: {:?}",
|
|
||||||
wayland_err, x11_err,
|
|
||||||
);
|
|
||||||
panic!(err_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_wayland() -> Result<EventLoop<T>, ConnectError> {
|
|
||||||
assert_is_main_thread("new_wayland_any_thread");
|
|
||||||
|
|
||||||
EventLoop::new_wayland_any_thread()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_wayland_any_thread() -> Result<EventLoop<T>, ConnectError> {
|
|
||||||
wayland::EventLoop::new().map(EventLoop::Wayland)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_x11() -> Result<EventLoop<T>, XNotSupported> {
|
|
||||||
assert_is_main_thread("new_x11_any_thread");
|
|
||||||
|
|
||||||
EventLoop::new_x11_any_thread()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_x11_any_thread() -> Result<EventLoop<T>, XNotSupported> {
|
|
||||||
let xconn = match X11_BACKEND.lock().as_ref() {
|
|
||||||
Ok(xconn) => xconn.clone(),
|
|
||||||
Err(err) => return Err(err.clone()),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(EventLoop::X(x11::EventLoop::new(xconn)))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
|
|
||||||
match *self {
|
|
||||||
EventLoop::Wayland(ref evlp) => evlp
|
|
||||||
.available_monitors()
|
|
||||||
.into_iter()
|
|
||||||
.map(MonitorHandle::Wayland)
|
|
||||||
.collect(),
|
|
||||||
EventLoop::X(ref evlp) => evlp
|
|
||||||
.x_connection()
|
|
||||||
.available_monitors()
|
|
||||||
.into_iter()
|
|
||||||
.map(MonitorHandle::X)
|
|
||||||
.collect(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn primary_monitor(&self) -> MonitorHandle {
|
|
||||||
match *self {
|
|
||||||
EventLoop::Wayland(ref evlp) => MonitorHandle::Wayland(evlp.primary_monitor()),
|
|
||||||
EventLoop::X(ref evlp) => MonitorHandle::X(evlp.x_connection().primary_monitor()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create_proxy(&self) -> EventLoopProxy<T> {
|
|
||||||
match *self {
|
|
||||||
EventLoop::Wayland(ref evlp) => EventLoopProxy::Wayland(evlp.create_proxy()),
|
|
||||||
EventLoop::X(ref evlp) => EventLoopProxy::X(evlp.create_proxy()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run_return<F>(&mut self, callback: F)
|
|
||||||
where
|
|
||||||
F: FnMut(crate::event::Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
|
||||||
{
|
|
||||||
match *self {
|
|
||||||
EventLoop::Wayland(ref mut evlp) => evlp.run_return(callback),
|
|
||||||
EventLoop::X(ref mut evlp) => evlp.run_return(callback),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run<F>(self, callback: F) -> !
|
|
||||||
where
|
|
||||||
F: 'static + FnMut(crate::event::Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
|
||||||
{
|
|
||||||
match self {
|
|
||||||
EventLoop::Wayland(evlp) => evlp.run(callback),
|
|
||||||
EventLoop::X(evlp) => evlp.run(callback),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn window_target(&self) -> &crate::event_loop::EventLoopWindowTarget<T> {
|
|
||||||
match *self {
|
|
||||||
EventLoop::Wayland(ref evl) => evl.window_target(),
|
|
||||||
EventLoop::X(ref evl) => evl.window_target(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: 'static> EventLoopProxy<T> {
|
|
||||||
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
|
|
||||||
match *self {
|
|
||||||
EventLoopProxy::Wayland(ref proxy) => proxy.send_event(event),
|
|
||||||
EventLoopProxy::X(ref proxy) => proxy.send_event(event),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum EventLoopWindowTarget<T> {
|
|
||||||
Wayland(wayland::EventLoopWindowTarget<T>),
|
|
||||||
X(x11::EventLoopWindowTarget<T>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> EventLoopWindowTarget<T> {
|
|
||||||
#[inline]
|
|
||||||
pub fn is_wayland(&self) -> bool {
|
|
||||||
match *self {
|
|
||||||
EventLoopWindowTarget::Wayland(_) => true,
|
|
||||||
EventLoopWindowTarget::X(_) => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sticky_exit_callback<T, F>(
|
|
||||||
evt: Event<'_, T>,
|
|
||||||
target: &RootELW<T>,
|
|
||||||
control_flow: &mut ControlFlow,
|
|
||||||
callback: &mut F,
|
|
||||||
) where
|
|
||||||
F: FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
|
||||||
{
|
|
||||||
// make ControlFlow::Exit sticky by providing a dummy
|
|
||||||
// control flow reference if it is already Exit.
|
|
||||||
let mut dummy = ControlFlow::Exit;
|
|
||||||
let cf = if *control_flow == ControlFlow::Exit {
|
|
||||||
&mut dummy
|
|
||||||
} else {
|
|
||||||
control_flow
|
|
||||||
};
|
|
||||||
// user callback
|
|
||||||
callback(evt, target, cf)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn assert_is_main_thread(suggested_method: &str) {
|
|
||||||
if !is_main_thread() {
|
|
||||||
panic!(
|
|
||||||
"Initializing the event loop outside of the main thread is a significant \
|
|
||||||
cross-platform compatibility hazard. If you really, absolutely need to create an \
|
|
||||||
EventLoop on a different thread, please use the `EventLoopExtUnix::{}` function.",
|
|
||||||
suggested_method
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
fn is_main_thread() -> bool {
|
|
||||||
use libc::{c_long, getpid, syscall, SYS_gettid};
|
|
||||||
|
|
||||||
unsafe { syscall(SYS_gettid) == getpid() as c_long }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))]
|
|
||||||
fn is_main_thread() -> bool {
|
|
||||||
use libc::pthread_main_np;
|
|
||||||
|
|
||||||
unsafe { pthread_main_np() == 1 }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "netbsd")]
|
|
||||||
fn is_main_thread() -> bool {
|
|
||||||
use libc::_lwp_self;
|
|
||||||
|
|
||||||
unsafe { _lwp_self() == 1 }
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,397 +0,0 @@
|
|||||||
use std::sync::{Arc, Mutex};
|
|
||||||
|
|
||||||
use super::{event_loop::EventsSink, make_wid, DeviceId};
|
|
||||||
use smithay_client_toolkit::{
|
|
||||||
keyboard::{
|
|
||||||
self, map_keyboard_auto_with_repeat, Event as KbEvent, KeyRepeatEvent, KeyRepeatKind,
|
|
||||||
},
|
|
||||||
reexports::client::protocol::{wl_keyboard, wl_seat},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::event::{ElementState, KeyboardInput, ModifiersState, VirtualKeyCode, WindowEvent};
|
|
||||||
|
|
||||||
pub fn init_keyboard(
|
|
||||||
seat: &wl_seat::WlSeat,
|
|
||||||
sink: EventsSink,
|
|
||||||
modifiers_tracker: Arc<Mutex<ModifiersState>>,
|
|
||||||
) -> wl_keyboard::WlKeyboard {
|
|
||||||
// { variables to be captured by the closures
|
|
||||||
let target = Arc::new(Mutex::new(None));
|
|
||||||
let my_sink = sink.clone();
|
|
||||||
let repeat_sink = sink.clone();
|
|
||||||
let repeat_target = target.clone();
|
|
||||||
let my_modifiers = modifiers_tracker.clone();
|
|
||||||
// }
|
|
||||||
let ret = map_keyboard_auto_with_repeat(
|
|
||||||
seat,
|
|
||||||
KeyRepeatKind::System,
|
|
||||||
move |evt: KbEvent<'_>, _| {
|
|
||||||
match evt {
|
|
||||||
KbEvent::Enter { surface, .. } => {
|
|
||||||
let wid = make_wid(&surface);
|
|
||||||
my_sink.send_window_event(WindowEvent::Focused(true), wid);
|
|
||||||
*target.lock().unwrap() = Some(wid);
|
|
||||||
|
|
||||||
let modifiers = *modifiers_tracker.lock().unwrap();
|
|
||||||
|
|
||||||
if !modifiers.is_empty() {
|
|
||||||
my_sink.send_window_event(WindowEvent::ModifiersChanged(modifiers), wid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
KbEvent::Leave { surface, .. } => {
|
|
||||||
let wid = make_wid(&surface);
|
|
||||||
let modifiers = *modifiers_tracker.lock().unwrap();
|
|
||||||
|
|
||||||
if !modifiers.is_empty() {
|
|
||||||
my_sink.send_window_event(
|
|
||||||
WindowEvent::ModifiersChanged(ModifiersState::empty()),
|
|
||||||
wid,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
my_sink.send_window_event(WindowEvent::Focused(false), wid);
|
|
||||||
*target.lock().unwrap() = None;
|
|
||||||
}
|
|
||||||
KbEvent::Key {
|
|
||||||
rawkey,
|
|
||||||
keysym,
|
|
||||||
state,
|
|
||||||
utf8,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
if let Some(wid) = *target.lock().unwrap() {
|
|
||||||
let state = match state {
|
|
||||||
wl_keyboard::KeyState::Pressed => ElementState::Pressed,
|
|
||||||
wl_keyboard::KeyState::Released => ElementState::Released,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
let vkcode = key_to_vkey(rawkey, keysym);
|
|
||||||
my_sink.send_window_event(
|
|
||||||
#[allow(deprecated)]
|
|
||||||
WindowEvent::KeyboardInput {
|
|
||||||
device_id: crate::event::DeviceId(
|
|
||||||
crate::platform_impl::DeviceId::Wayland(DeviceId),
|
|
||||||
),
|
|
||||||
input: KeyboardInput {
|
|
||||||
state,
|
|
||||||
scancode: rawkey,
|
|
||||||
virtual_keycode: vkcode,
|
|
||||||
modifiers: modifiers_tracker.lock().unwrap().clone(),
|
|
||||||
},
|
|
||||||
is_synthetic: false,
|
|
||||||
},
|
|
||||||
wid,
|
|
||||||
);
|
|
||||||
// send char event only on key press, not release
|
|
||||||
if let ElementState::Released = state {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if let Some(txt) = utf8 {
|
|
||||||
for chr in txt.chars() {
|
|
||||||
my_sink.send_window_event(WindowEvent::ReceivedCharacter(chr), wid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
KbEvent::RepeatInfo { .. } => { /* Handled by smithay client toolkit */ }
|
|
||||||
KbEvent::Modifiers {
|
|
||||||
modifiers: event_modifiers,
|
|
||||||
} => {
|
|
||||||
let modifiers = ModifiersState::from_wayland(event_modifiers);
|
|
||||||
|
|
||||||
*modifiers_tracker.lock().unwrap() = modifiers;
|
|
||||||
|
|
||||||
if let Some(wid) = *target.lock().unwrap() {
|
|
||||||
my_sink.send_window_event(WindowEvent::ModifiersChanged(modifiers), wid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
move |repeat_event: KeyRepeatEvent, _| {
|
|
||||||
if let Some(wid) = *repeat_target.lock().unwrap() {
|
|
||||||
let state = ElementState::Pressed;
|
|
||||||
let vkcode = key_to_vkey(repeat_event.rawkey, repeat_event.keysym);
|
|
||||||
repeat_sink.send_window_event(
|
|
||||||
#[allow(deprecated)]
|
|
||||||
WindowEvent::KeyboardInput {
|
|
||||||
device_id: crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(
|
|
||||||
DeviceId,
|
|
||||||
)),
|
|
||||||
input: KeyboardInput {
|
|
||||||
state,
|
|
||||||
scancode: repeat_event.rawkey,
|
|
||||||
virtual_keycode: vkcode,
|
|
||||||
modifiers: my_modifiers.lock().unwrap().clone(),
|
|
||||||
},
|
|
||||||
is_synthetic: false,
|
|
||||||
},
|
|
||||||
wid,
|
|
||||||
);
|
|
||||||
if let Some(txt) = repeat_event.utf8 {
|
|
||||||
for chr in txt.chars() {
|
|
||||||
repeat_sink.send_window_event(WindowEvent::ReceivedCharacter(chr), wid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
match ret {
|
|
||||||
Ok(keyboard) => keyboard,
|
|
||||||
Err(_) => {
|
|
||||||
// This is a fallback impl if libxkbcommon was not available
|
|
||||||
// This case should probably never happen, as most wayland
|
|
||||||
// compositors _need_ libxkbcommon anyway...
|
|
||||||
//
|
|
||||||
// In this case, we don't have the keymap information (it is
|
|
||||||
// supposed to be serialized by the compositor using libxkbcommon)
|
|
||||||
|
|
||||||
seat.get_keyboard(|keyboard| {
|
|
||||||
// { variables to be captured by the closure
|
|
||||||
let mut target = None;
|
|
||||||
let my_sink = sink;
|
|
||||||
// }
|
|
||||||
|
|
||||||
keyboard.implement_closure(
|
|
||||||
move |evt, _| match evt {
|
|
||||||
wl_keyboard::Event::Enter { surface, .. } => {
|
|
||||||
let wid = make_wid(&surface);
|
|
||||||
my_sink.send_window_event(WindowEvent::Focused(true), wid);
|
|
||||||
target = Some(wid);
|
|
||||||
}
|
|
||||||
wl_keyboard::Event::Leave { surface, .. } => {
|
|
||||||
let wid = make_wid(&surface);
|
|
||||||
my_sink.send_window_event(WindowEvent::Focused(false), wid);
|
|
||||||
target = None;
|
|
||||||
}
|
|
||||||
wl_keyboard::Event::Key { key, state, .. } => {
|
|
||||||
if let Some(wid) = target {
|
|
||||||
let state = match state {
|
|
||||||
wl_keyboard::KeyState::Pressed => ElementState::Pressed,
|
|
||||||
wl_keyboard::KeyState::Released => ElementState::Released,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
my_sink.send_window_event(
|
|
||||||
#[allow(deprecated)]
|
|
||||||
WindowEvent::KeyboardInput {
|
|
||||||
device_id: crate::event::DeviceId(
|
|
||||||
crate::platform_impl::DeviceId::Wayland(DeviceId),
|
|
||||||
),
|
|
||||||
input: KeyboardInput {
|
|
||||||
state,
|
|
||||||
scancode: key,
|
|
||||||
virtual_keycode: None,
|
|
||||||
modifiers: ModifiersState::default(),
|
|
||||||
},
|
|
||||||
is_synthetic: false,
|
|
||||||
},
|
|
||||||
wid,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
(),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn key_to_vkey(rawkey: u32, keysym: u32) -> Option<VirtualKeyCode> {
|
|
||||||
match rawkey {
|
|
||||||
1 => Some(VirtualKeyCode::Escape),
|
|
||||||
2 => Some(VirtualKeyCode::Key1),
|
|
||||||
3 => Some(VirtualKeyCode::Key2),
|
|
||||||
4 => Some(VirtualKeyCode::Key3),
|
|
||||||
5 => Some(VirtualKeyCode::Key4),
|
|
||||||
6 => Some(VirtualKeyCode::Key5),
|
|
||||||
7 => Some(VirtualKeyCode::Key6),
|
|
||||||
8 => Some(VirtualKeyCode::Key7),
|
|
||||||
9 => Some(VirtualKeyCode::Key8),
|
|
||||||
10 => Some(VirtualKeyCode::Key9),
|
|
||||||
11 => Some(VirtualKeyCode::Key0),
|
|
||||||
_ => keysym_to_vkey(keysym),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn keysym_to_vkey(keysym: u32) -> Option<VirtualKeyCode> {
|
|
||||||
use smithay_client_toolkit::keyboard::keysyms;
|
|
||||||
match keysym {
|
|
||||||
// letters
|
|
||||||
keysyms::XKB_KEY_A | keysyms::XKB_KEY_a => Some(VirtualKeyCode::A),
|
|
||||||
keysyms::XKB_KEY_B | keysyms::XKB_KEY_b => Some(VirtualKeyCode::B),
|
|
||||||
keysyms::XKB_KEY_C | keysyms::XKB_KEY_c => Some(VirtualKeyCode::C),
|
|
||||||
keysyms::XKB_KEY_D | keysyms::XKB_KEY_d => Some(VirtualKeyCode::D),
|
|
||||||
keysyms::XKB_KEY_E | keysyms::XKB_KEY_e => Some(VirtualKeyCode::E),
|
|
||||||
keysyms::XKB_KEY_F | keysyms::XKB_KEY_f => Some(VirtualKeyCode::F),
|
|
||||||
keysyms::XKB_KEY_G | keysyms::XKB_KEY_g => Some(VirtualKeyCode::G),
|
|
||||||
keysyms::XKB_KEY_H | keysyms::XKB_KEY_h => Some(VirtualKeyCode::H),
|
|
||||||
keysyms::XKB_KEY_I | keysyms::XKB_KEY_i => Some(VirtualKeyCode::I),
|
|
||||||
keysyms::XKB_KEY_J | keysyms::XKB_KEY_j => Some(VirtualKeyCode::J),
|
|
||||||
keysyms::XKB_KEY_K | keysyms::XKB_KEY_k => Some(VirtualKeyCode::K),
|
|
||||||
keysyms::XKB_KEY_L | keysyms::XKB_KEY_l => Some(VirtualKeyCode::L),
|
|
||||||
keysyms::XKB_KEY_M | keysyms::XKB_KEY_m => Some(VirtualKeyCode::M),
|
|
||||||
keysyms::XKB_KEY_N | keysyms::XKB_KEY_n => Some(VirtualKeyCode::N),
|
|
||||||
keysyms::XKB_KEY_O | keysyms::XKB_KEY_o => Some(VirtualKeyCode::O),
|
|
||||||
keysyms::XKB_KEY_P | keysyms::XKB_KEY_p => Some(VirtualKeyCode::P),
|
|
||||||
keysyms::XKB_KEY_Q | keysyms::XKB_KEY_q => Some(VirtualKeyCode::Q),
|
|
||||||
keysyms::XKB_KEY_R | keysyms::XKB_KEY_r => Some(VirtualKeyCode::R),
|
|
||||||
keysyms::XKB_KEY_S | keysyms::XKB_KEY_s => Some(VirtualKeyCode::S),
|
|
||||||
keysyms::XKB_KEY_T | keysyms::XKB_KEY_t => Some(VirtualKeyCode::T),
|
|
||||||
keysyms::XKB_KEY_U | keysyms::XKB_KEY_u => Some(VirtualKeyCode::U),
|
|
||||||
keysyms::XKB_KEY_V | keysyms::XKB_KEY_v => Some(VirtualKeyCode::V),
|
|
||||||
keysyms::XKB_KEY_W | keysyms::XKB_KEY_w => Some(VirtualKeyCode::W),
|
|
||||||
keysyms::XKB_KEY_X | keysyms::XKB_KEY_x => Some(VirtualKeyCode::X),
|
|
||||||
keysyms::XKB_KEY_Y | keysyms::XKB_KEY_y => Some(VirtualKeyCode::Y),
|
|
||||||
keysyms::XKB_KEY_Z | keysyms::XKB_KEY_z => Some(VirtualKeyCode::Z),
|
|
||||||
// F--
|
|
||||||
keysyms::XKB_KEY_F1 => Some(VirtualKeyCode::F1),
|
|
||||||
keysyms::XKB_KEY_F2 => Some(VirtualKeyCode::F2),
|
|
||||||
keysyms::XKB_KEY_F3 => Some(VirtualKeyCode::F3),
|
|
||||||
keysyms::XKB_KEY_F4 => Some(VirtualKeyCode::F4),
|
|
||||||
keysyms::XKB_KEY_F5 => Some(VirtualKeyCode::F5),
|
|
||||||
keysyms::XKB_KEY_F6 => Some(VirtualKeyCode::F6),
|
|
||||||
keysyms::XKB_KEY_F7 => Some(VirtualKeyCode::F7),
|
|
||||||
keysyms::XKB_KEY_F8 => Some(VirtualKeyCode::F8),
|
|
||||||
keysyms::XKB_KEY_F9 => Some(VirtualKeyCode::F9),
|
|
||||||
keysyms::XKB_KEY_F10 => Some(VirtualKeyCode::F10),
|
|
||||||
keysyms::XKB_KEY_F11 => Some(VirtualKeyCode::F11),
|
|
||||||
keysyms::XKB_KEY_F12 => Some(VirtualKeyCode::F12),
|
|
||||||
keysyms::XKB_KEY_F13 => Some(VirtualKeyCode::F13),
|
|
||||||
keysyms::XKB_KEY_F14 => Some(VirtualKeyCode::F14),
|
|
||||||
keysyms::XKB_KEY_F15 => Some(VirtualKeyCode::F15),
|
|
||||||
keysyms::XKB_KEY_F16 => Some(VirtualKeyCode::F16),
|
|
||||||
keysyms::XKB_KEY_F17 => Some(VirtualKeyCode::F17),
|
|
||||||
keysyms::XKB_KEY_F18 => Some(VirtualKeyCode::F18),
|
|
||||||
keysyms::XKB_KEY_F19 => Some(VirtualKeyCode::F19),
|
|
||||||
keysyms::XKB_KEY_F20 => Some(VirtualKeyCode::F20),
|
|
||||||
keysyms::XKB_KEY_F21 => Some(VirtualKeyCode::F21),
|
|
||||||
keysyms::XKB_KEY_F22 => Some(VirtualKeyCode::F22),
|
|
||||||
keysyms::XKB_KEY_F23 => Some(VirtualKeyCode::F23),
|
|
||||||
keysyms::XKB_KEY_F24 => Some(VirtualKeyCode::F24),
|
|
||||||
// flow control
|
|
||||||
keysyms::XKB_KEY_Print => Some(VirtualKeyCode::Snapshot),
|
|
||||||
keysyms::XKB_KEY_Scroll_Lock => Some(VirtualKeyCode::Scroll),
|
|
||||||
keysyms::XKB_KEY_Pause => Some(VirtualKeyCode::Pause),
|
|
||||||
keysyms::XKB_KEY_Insert => Some(VirtualKeyCode::Insert),
|
|
||||||
keysyms::XKB_KEY_Home => Some(VirtualKeyCode::Home),
|
|
||||||
keysyms::XKB_KEY_Delete => Some(VirtualKeyCode::Delete),
|
|
||||||
keysyms::XKB_KEY_End => Some(VirtualKeyCode::End),
|
|
||||||
keysyms::XKB_KEY_Page_Down => Some(VirtualKeyCode::PageDown),
|
|
||||||
keysyms::XKB_KEY_Page_Up => Some(VirtualKeyCode::PageUp),
|
|
||||||
// arrows
|
|
||||||
keysyms::XKB_KEY_Left => Some(VirtualKeyCode::Left),
|
|
||||||
keysyms::XKB_KEY_Up => Some(VirtualKeyCode::Up),
|
|
||||||
keysyms::XKB_KEY_Right => Some(VirtualKeyCode::Right),
|
|
||||||
keysyms::XKB_KEY_Down => Some(VirtualKeyCode::Down),
|
|
||||||
//
|
|
||||||
keysyms::XKB_KEY_BackSpace => Some(VirtualKeyCode::Back),
|
|
||||||
keysyms::XKB_KEY_Return => Some(VirtualKeyCode::Return),
|
|
||||||
keysyms::XKB_KEY_space => Some(VirtualKeyCode::Space),
|
|
||||||
// keypad
|
|
||||||
keysyms::XKB_KEY_Num_Lock => Some(VirtualKeyCode::Numlock),
|
|
||||||
keysyms::XKB_KEY_KP_0 => Some(VirtualKeyCode::Numpad0),
|
|
||||||
keysyms::XKB_KEY_KP_1 => Some(VirtualKeyCode::Numpad1),
|
|
||||||
keysyms::XKB_KEY_KP_2 => Some(VirtualKeyCode::Numpad2),
|
|
||||||
keysyms::XKB_KEY_KP_3 => Some(VirtualKeyCode::Numpad3),
|
|
||||||
keysyms::XKB_KEY_KP_4 => Some(VirtualKeyCode::Numpad4),
|
|
||||||
keysyms::XKB_KEY_KP_5 => Some(VirtualKeyCode::Numpad5),
|
|
||||||
keysyms::XKB_KEY_KP_6 => Some(VirtualKeyCode::Numpad6),
|
|
||||||
keysyms::XKB_KEY_KP_7 => Some(VirtualKeyCode::Numpad7),
|
|
||||||
keysyms::XKB_KEY_KP_8 => Some(VirtualKeyCode::Numpad8),
|
|
||||||
keysyms::XKB_KEY_KP_9 => Some(VirtualKeyCode::Numpad9),
|
|
||||||
// misc
|
|
||||||
// => Some(VirtualKeyCode::AbntC1),
|
|
||||||
// => Some(VirtualKeyCode::AbntC2),
|
|
||||||
keysyms::XKB_KEY_plus => Some(VirtualKeyCode::Add),
|
|
||||||
keysyms::XKB_KEY_apostrophe => Some(VirtualKeyCode::Apostrophe),
|
|
||||||
// => Some(VirtualKeyCode::Apps),
|
|
||||||
// => Some(VirtualKeyCode::At),
|
|
||||||
// => Some(VirtualKeyCode::Ax),
|
|
||||||
keysyms::XKB_KEY_backslash => Some(VirtualKeyCode::Backslash),
|
|
||||||
// => Some(VirtualKeyCode::Calculator),
|
|
||||||
// => Some(VirtualKeyCode::Capital),
|
|
||||||
keysyms::XKB_KEY_colon => Some(VirtualKeyCode::Colon),
|
|
||||||
keysyms::XKB_KEY_comma => Some(VirtualKeyCode::Comma),
|
|
||||||
// => Some(VirtualKeyCode::Convert),
|
|
||||||
// => Some(VirtualKeyCode::Decimal),
|
|
||||||
// => Some(VirtualKeyCode::Divide),
|
|
||||||
keysyms::XKB_KEY_equal => Some(VirtualKeyCode::Equals),
|
|
||||||
// => Some(VirtualKeyCode::Grave),
|
|
||||||
// => Some(VirtualKeyCode::Kana),
|
|
||||||
// => Some(VirtualKeyCode::Kanji),
|
|
||||||
keysyms::XKB_KEY_Alt_L => Some(VirtualKeyCode::LAlt),
|
|
||||||
// => Some(VirtualKeyCode::LBracket),
|
|
||||||
keysyms::XKB_KEY_Control_L => Some(VirtualKeyCode::LControl),
|
|
||||||
keysyms::XKB_KEY_Shift_L => Some(VirtualKeyCode::LShift),
|
|
||||||
// => Some(VirtualKeyCode::LWin),
|
|
||||||
// => Some(VirtualKeyCode::Mail),
|
|
||||||
// => Some(VirtualKeyCode::MediaSelect),
|
|
||||||
// => Some(VirtualKeyCode::MediaStop),
|
|
||||||
keysyms::XKB_KEY_minus => Some(VirtualKeyCode::Minus),
|
|
||||||
keysyms::XKB_KEY_asterisk => Some(VirtualKeyCode::Multiply),
|
|
||||||
// => Some(VirtualKeyCode::Mute),
|
|
||||||
// => Some(VirtualKeyCode::MyComputer),
|
|
||||||
// => Some(VirtualKeyCode::NextTrack),
|
|
||||||
// => Some(VirtualKeyCode::NoConvert),
|
|
||||||
keysyms::XKB_KEY_KP_Separator => Some(VirtualKeyCode::NumpadComma),
|
|
||||||
keysyms::XKB_KEY_KP_Enter => Some(VirtualKeyCode::NumpadEnter),
|
|
||||||
keysyms::XKB_KEY_KP_Equal => Some(VirtualKeyCode::NumpadEquals),
|
|
||||||
keysyms::XKB_KEY_KP_Add => Some(VirtualKeyCode::Add),
|
|
||||||
keysyms::XKB_KEY_KP_Subtract => Some(VirtualKeyCode::Subtract),
|
|
||||||
keysyms::XKB_KEY_KP_Divide => Some(VirtualKeyCode::Divide),
|
|
||||||
keysyms::XKB_KEY_KP_Page_Up => Some(VirtualKeyCode::PageUp),
|
|
||||||
keysyms::XKB_KEY_KP_Page_Down => Some(VirtualKeyCode::PageDown),
|
|
||||||
keysyms::XKB_KEY_KP_Home => Some(VirtualKeyCode::Home),
|
|
||||||
keysyms::XKB_KEY_KP_End => Some(VirtualKeyCode::End),
|
|
||||||
// => Some(VirtualKeyCode::OEM102),
|
|
||||||
// => Some(VirtualKeyCode::Period),
|
|
||||||
// => Some(VirtualKeyCode::Playpause),
|
|
||||||
// => Some(VirtualKeyCode::Power),
|
|
||||||
// => Some(VirtualKeyCode::Prevtrack),
|
|
||||||
keysyms::XKB_KEY_Alt_R => Some(VirtualKeyCode::RAlt),
|
|
||||||
// => Some(VirtualKeyCode::RBracket),
|
|
||||||
keysyms::XKB_KEY_Control_R => Some(VirtualKeyCode::RControl),
|
|
||||||
keysyms::XKB_KEY_Shift_R => Some(VirtualKeyCode::RShift),
|
|
||||||
// => Some(VirtualKeyCode::RWin),
|
|
||||||
keysyms::XKB_KEY_semicolon => Some(VirtualKeyCode::Semicolon),
|
|
||||||
keysyms::XKB_KEY_slash => Some(VirtualKeyCode::Slash),
|
|
||||||
// => Some(VirtualKeyCode::Sleep),
|
|
||||||
// => Some(VirtualKeyCode::Stop),
|
|
||||||
// => Some(VirtualKeyCode::Subtract),
|
|
||||||
// => Some(VirtualKeyCode::Sysrq),
|
|
||||||
keysyms::XKB_KEY_Tab => Some(VirtualKeyCode::Tab),
|
|
||||||
keysyms::XKB_KEY_ISO_Left_Tab => Some(VirtualKeyCode::Tab),
|
|
||||||
// => Some(VirtualKeyCode::Underline),
|
|
||||||
// => Some(VirtualKeyCode::Unlabeled),
|
|
||||||
keysyms::XKB_KEY_XF86AudioLowerVolume => Some(VirtualKeyCode::VolumeDown),
|
|
||||||
keysyms::XKB_KEY_XF86AudioRaiseVolume => Some(VirtualKeyCode::VolumeUp),
|
|
||||||
// => Some(VirtualKeyCode::Wake),
|
|
||||||
// => Some(VirtualKeyCode::Webback),
|
|
||||||
// => Some(VirtualKeyCode::WebFavorites),
|
|
||||||
// => Some(VirtualKeyCode::WebForward),
|
|
||||||
// => Some(VirtualKeyCode::WebHome),
|
|
||||||
// => Some(VirtualKeyCode::WebRefresh),
|
|
||||||
// => Some(VirtualKeyCode::WebSearch),
|
|
||||||
// => Some(VirtualKeyCode::WebStop),
|
|
||||||
// => Some(VirtualKeyCode::Yen),
|
|
||||||
keysyms::XKB_KEY_XF86Copy => Some(VirtualKeyCode::Copy),
|
|
||||||
keysyms::XKB_KEY_XF86Paste => Some(VirtualKeyCode::Paste),
|
|
||||||
keysyms::XKB_KEY_XF86Cut => Some(VirtualKeyCode::Cut),
|
|
||||||
// fallback
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ModifiersState {
|
|
||||||
pub(crate) fn from_wayland(mods: keyboard::ModifiersState) -> ModifiersState {
|
|
||||||
let mut m = ModifiersState::empty();
|
|
||||||
m.set(ModifiersState::SHIFT, mods.shift);
|
|
||||||
m.set(ModifiersState::CTRL, mods.ctrl);
|
|
||||||
m.set(ModifiersState::ALT, mods.alt);
|
|
||||||
m.set(ModifiersState::LOGO, mods.logo);
|
|
||||||
m
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd",
|
|
||||||
target_os = "netbsd", target_os = "openbsd"))]
|
|
||||||
|
|
||||||
pub use self::{
|
|
||||||
event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget, MonitorHandle, VideoMode},
|
|
||||||
window::Window,
|
|
||||||
};
|
|
||||||
|
|
||||||
use smithay_client_toolkit::reexports::client::protocol::wl_surface;
|
|
||||||
|
|
||||||
mod event_loop;
|
|
||||||
mod keyboard;
|
|
||||||
mod pointer;
|
|
||||||
mod touch;
|
|
||||||
mod window;
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub struct DeviceId;
|
|
||||||
|
|
||||||
impl DeviceId {
|
|
||||||
pub unsafe fn dummy() -> Self {
|
|
||||||
DeviceId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub struct WindowId(usize);
|
|
||||||
|
|
||||||
impl WindowId {
|
|
||||||
pub unsafe fn dummy() -> Self {
|
|
||||||
WindowId(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn make_wid(s: &wl_surface::WlSurface) -> WindowId {
|
|
||||||
WindowId(s.as_ref().c_ptr() as usize)
|
|
||||||
}
|
|
||||||
@@ -1,289 +0,0 @@
|
|||||||
use std::sync::{Arc, Mutex};
|
|
||||||
|
|
||||||
use crate::dpi::LogicalPosition;
|
|
||||||
use crate::event::{
|
|
||||||
DeviceEvent, ElementState, ModifiersState, MouseButton, MouseScrollDelta, TouchPhase,
|
|
||||||
WindowEvent,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{
|
|
||||||
event_loop::{CursorManager, EventsSink},
|
|
||||||
make_wid,
|
|
||||||
window::WindowStore,
|
|
||||||
DeviceId,
|
|
||||||
};
|
|
||||||
|
|
||||||
use smithay_client_toolkit::surface;
|
|
||||||
|
|
||||||
use smithay_client_toolkit::reexports::client::protocol::{
|
|
||||||
wl_pointer::{self, Event as PtrEvent, WlPointer},
|
|
||||||
wl_seat,
|
|
||||||
};
|
|
||||||
|
|
||||||
use smithay_client_toolkit::reexports::protocols::unstable::relative_pointer::v1::client::{
|
|
||||||
zwp_relative_pointer_manager_v1::ZwpRelativePointerManagerV1, zwp_relative_pointer_v1::Event,
|
|
||||||
zwp_relative_pointer_v1::ZwpRelativePointerV1,
|
|
||||||
};
|
|
||||||
|
|
||||||
use smithay_client_toolkit::reexports::protocols::unstable::pointer_constraints::v1::client::{
|
|
||||||
zwp_locked_pointer_v1::ZwpLockedPointerV1, zwp_pointer_constraints_v1::Lifetime,
|
|
||||||
zwp_pointer_constraints_v1::ZwpPointerConstraintsV1,
|
|
||||||
};
|
|
||||||
|
|
||||||
use smithay_client_toolkit::reexports::client::protocol::wl_surface::WlSurface;
|
|
||||||
|
|
||||||
pub fn implement_pointer(
|
|
||||||
seat: &wl_seat::WlSeat,
|
|
||||||
sink: EventsSink,
|
|
||||||
store: Arc<Mutex<WindowStore>>,
|
|
||||||
modifiers_tracker: Arc<Mutex<ModifiersState>>,
|
|
||||||
cursor_manager: Arc<Mutex<CursorManager>>,
|
|
||||||
) -> WlPointer {
|
|
||||||
seat.get_pointer(|pointer| {
|
|
||||||
// Currently focused winit surface
|
|
||||||
let mut mouse_focus = None;
|
|
||||||
let mut axis_buffer = None;
|
|
||||||
let mut axis_discrete_buffer = None;
|
|
||||||
let mut axis_state = TouchPhase::Ended;
|
|
||||||
|
|
||||||
pointer.implement_closure(
|
|
||||||
move |evt, pointer| {
|
|
||||||
let store = store.lock().unwrap();
|
|
||||||
let mut cursor_manager = cursor_manager.lock().unwrap();
|
|
||||||
match evt {
|
|
||||||
PtrEvent::Enter {
|
|
||||||
surface,
|
|
||||||
surface_x,
|
|
||||||
surface_y,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
let wid = store.find_wid(&surface);
|
|
||||||
|
|
||||||
if let Some(wid) = wid {
|
|
||||||
let scale_factor = surface::get_dpi_factor(&surface) as f64;
|
|
||||||
mouse_focus = Some(surface);
|
|
||||||
|
|
||||||
// Reload cursor style only when we enter winit's surface. Calling
|
|
||||||
// this function every time on `PtrEvent::Enter` could interfere with
|
|
||||||
// SCTK CSD handling, since it changes cursor icons when you hover
|
|
||||||
// cursor over the window borders.
|
|
||||||
cursor_manager.reload_cursor_style();
|
|
||||||
|
|
||||||
sink.send_window_event(
|
|
||||||
WindowEvent::CursorEntered {
|
|
||||||
device_id: crate::event::DeviceId(
|
|
||||||
crate::platform_impl::DeviceId::Wayland(DeviceId),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
wid,
|
|
||||||
);
|
|
||||||
|
|
||||||
let position = LogicalPosition::new(surface_x, surface_y)
|
|
||||||
.to_physical(scale_factor);
|
|
||||||
|
|
||||||
sink.send_window_event(
|
|
||||||
WindowEvent::CursorMoved {
|
|
||||||
device_id: crate::event::DeviceId(
|
|
||||||
crate::platform_impl::DeviceId::Wayland(DeviceId),
|
|
||||||
),
|
|
||||||
position,
|
|
||||||
modifiers: modifiers_tracker.lock().unwrap().clone(),
|
|
||||||
},
|
|
||||||
wid,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PtrEvent::Leave { surface, .. } => {
|
|
||||||
mouse_focus = None;
|
|
||||||
let wid = store.find_wid(&surface);
|
|
||||||
if let Some(wid) = wid {
|
|
||||||
sink.send_window_event(
|
|
||||||
WindowEvent::CursorLeft {
|
|
||||||
device_id: crate::event::DeviceId(
|
|
||||||
crate::platform_impl::DeviceId::Wayland(DeviceId),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
wid,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PtrEvent::Motion {
|
|
||||||
surface_x,
|
|
||||||
surface_y,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
if let Some(surface) = mouse_focus.as_ref() {
|
|
||||||
let wid = make_wid(surface);
|
|
||||||
|
|
||||||
let scale_factor = surface::get_dpi_factor(&surface) as f64;
|
|
||||||
let position = LogicalPosition::new(surface_x, surface_y)
|
|
||||||
.to_physical(scale_factor);
|
|
||||||
|
|
||||||
sink.send_window_event(
|
|
||||||
WindowEvent::CursorMoved {
|
|
||||||
device_id: crate::event::DeviceId(
|
|
||||||
crate::platform_impl::DeviceId::Wayland(DeviceId),
|
|
||||||
),
|
|
||||||
position,
|
|
||||||
modifiers: modifiers_tracker.lock().unwrap().clone(),
|
|
||||||
},
|
|
||||||
wid,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PtrEvent::Button { button, state, .. } => {
|
|
||||||
if let Some(surface) = mouse_focus.as_ref() {
|
|
||||||
let state = match state {
|
|
||||||
wl_pointer::ButtonState::Pressed => ElementState::Pressed,
|
|
||||||
wl_pointer::ButtonState::Released => ElementState::Released,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
let button = match button {
|
|
||||||
0x110 => MouseButton::Left,
|
|
||||||
0x111 => MouseButton::Right,
|
|
||||||
0x112 => MouseButton::Middle,
|
|
||||||
// TODO figure out the translation ?
|
|
||||||
_ => return,
|
|
||||||
};
|
|
||||||
sink.send_window_event(
|
|
||||||
WindowEvent::MouseInput {
|
|
||||||
device_id: crate::event::DeviceId(
|
|
||||||
crate::platform_impl::DeviceId::Wayland(DeviceId),
|
|
||||||
),
|
|
||||||
state,
|
|
||||||
button,
|
|
||||||
modifiers: modifiers_tracker.lock().unwrap().clone(),
|
|
||||||
},
|
|
||||||
make_wid(surface),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PtrEvent::Axis { axis, value, .. } => {
|
|
||||||
if let Some(surface) = mouse_focus.as_ref() {
|
|
||||||
let wid = make_wid(surface);
|
|
||||||
if pointer.as_ref().version() < 5 {
|
|
||||||
let (mut x, mut y) = (0.0, 0.0);
|
|
||||||
// old seat compatibility
|
|
||||||
match axis {
|
|
||||||
// wayland vertical sign convention is the inverse of winit
|
|
||||||
wl_pointer::Axis::VerticalScroll => y -= value as f32,
|
|
||||||
wl_pointer::Axis::HorizontalScroll => x += value as f32,
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
sink.send_window_event(
|
|
||||||
WindowEvent::MouseWheel {
|
|
||||||
device_id: crate::event::DeviceId(
|
|
||||||
crate::platform_impl::DeviceId::Wayland(DeviceId),
|
|
||||||
),
|
|
||||||
delta: MouseScrollDelta::PixelDelta(
|
|
||||||
(x as f64, y as f64).into(),
|
|
||||||
),
|
|
||||||
phase: TouchPhase::Moved,
|
|
||||||
modifiers: modifiers_tracker.lock().unwrap().clone(),
|
|
||||||
},
|
|
||||||
wid,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
let (mut x, mut y) = axis_buffer.unwrap_or((0.0, 0.0));
|
|
||||||
match axis {
|
|
||||||
// wayland vertical sign convention is the inverse of winit
|
|
||||||
wl_pointer::Axis::VerticalScroll => y -= value as f32,
|
|
||||||
wl_pointer::Axis::HorizontalScroll => x += value as f32,
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
axis_buffer = Some((x, y));
|
|
||||||
axis_state = match axis_state {
|
|
||||||
TouchPhase::Started | TouchPhase::Moved => TouchPhase::Moved,
|
|
||||||
_ => TouchPhase::Started,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PtrEvent::Frame => {
|
|
||||||
let axis_buffer = axis_buffer.take();
|
|
||||||
let axis_discrete_buffer = axis_discrete_buffer.take();
|
|
||||||
if let Some(surface) = mouse_focus.as_ref() {
|
|
||||||
let wid = make_wid(surface);
|
|
||||||
if let Some((x, y)) = axis_discrete_buffer {
|
|
||||||
sink.send_window_event(
|
|
||||||
WindowEvent::MouseWheel {
|
|
||||||
device_id: crate::event::DeviceId(
|
|
||||||
crate::platform_impl::DeviceId::Wayland(DeviceId),
|
|
||||||
),
|
|
||||||
delta: MouseScrollDelta::LineDelta(x as f32, y as f32),
|
|
||||||
phase: axis_state,
|
|
||||||
modifiers: modifiers_tracker.lock().unwrap().clone(),
|
|
||||||
},
|
|
||||||
wid,
|
|
||||||
);
|
|
||||||
} else if let Some((x, y)) = axis_buffer {
|
|
||||||
sink.send_window_event(
|
|
||||||
WindowEvent::MouseWheel {
|
|
||||||
device_id: crate::event::DeviceId(
|
|
||||||
crate::platform_impl::DeviceId::Wayland(DeviceId),
|
|
||||||
),
|
|
||||||
delta: MouseScrollDelta::PixelDelta(
|
|
||||||
(x as f64, y as f64).into(),
|
|
||||||
),
|
|
||||||
phase: axis_state,
|
|
||||||
modifiers: modifiers_tracker.lock().unwrap().clone(),
|
|
||||||
},
|
|
||||||
wid,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PtrEvent::AxisSource { .. } => (),
|
|
||||||
PtrEvent::AxisStop { .. } => {
|
|
||||||
axis_state = TouchPhase::Ended;
|
|
||||||
}
|
|
||||||
PtrEvent::AxisDiscrete { axis, discrete } => {
|
|
||||||
let (mut x, mut y) = axis_discrete_buffer.unwrap_or((0, 0));
|
|
||||||
match axis {
|
|
||||||
// wayland vertical sign convention is the inverse of winit
|
|
||||||
wl_pointer::Axis::VerticalScroll => y -= discrete,
|
|
||||||
wl_pointer::Axis::HorizontalScroll => x += discrete,
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
axis_discrete_buffer = Some((x, y));
|
|
||||||
axis_state = match axis_state {
|
|
||||||
TouchPhase::Started | TouchPhase::Moved => TouchPhase::Moved,
|
|
||||||
_ => TouchPhase::Started,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
(),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn implement_relative_pointer(
|
|
||||||
sink: EventsSink,
|
|
||||||
pointer: &WlPointer,
|
|
||||||
manager: &ZwpRelativePointerManagerV1,
|
|
||||||
) -> Result<ZwpRelativePointerV1, ()> {
|
|
||||||
manager.get_relative_pointer(pointer, |rel_pointer| {
|
|
||||||
rel_pointer.implement_closure(
|
|
||||||
move |evt, _rel_pointer| match evt {
|
|
||||||
Event::RelativeMotion { dx, dy, .. } => {
|
|
||||||
sink.send_device_event(DeviceEvent::MouseMotion { delta: (dx, dy) }, DeviceId)
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
},
|
|
||||||
(),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn implement_locked_pointer(
|
|
||||||
surface: &WlSurface,
|
|
||||||
pointer: &WlPointer,
|
|
||||||
constraints: &ZwpPointerConstraintsV1,
|
|
||||||
) -> Result<ZwpLockedPointerV1, ()> {
|
|
||||||
constraints.lock_pointer(surface, pointer, None, Lifetime::Persistent.to_raw(), |c| {
|
|
||||||
c.implement_closure(|_, _| (), ())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
use std::sync::{Arc, Mutex};
|
|
||||||
|
|
||||||
use crate::dpi::LogicalPosition;
|
|
||||||
use crate::event::{TouchPhase, WindowEvent};
|
|
||||||
|
|
||||||
use super::{event_loop::EventsSink, make_wid, window::WindowStore, DeviceId};
|
|
||||||
|
|
||||||
use smithay_client_toolkit::surface;
|
|
||||||
|
|
||||||
use smithay_client_toolkit::reexports::client::protocol::{
|
|
||||||
wl_seat,
|
|
||||||
wl_surface::WlSurface,
|
|
||||||
wl_touch::{Event as TouchEvent, WlTouch},
|
|
||||||
};
|
|
||||||
|
|
||||||
// location is in logical coordinates.
|
|
||||||
struct TouchPoint {
|
|
||||||
surface: WlSurface,
|
|
||||||
position: LogicalPosition<f64>,
|
|
||||||
id: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn implement_touch(
|
|
||||||
seat: &wl_seat::WlSeat,
|
|
||||||
sink: EventsSink,
|
|
||||||
store: Arc<Mutex<WindowStore>>,
|
|
||||||
) -> WlTouch {
|
|
||||||
let mut pending_ids = Vec::new();
|
|
||||||
seat.get_touch(|touch| {
|
|
||||||
touch.implement_closure(
|
|
||||||
move |evt, _| {
|
|
||||||
let store = store.lock().unwrap();
|
|
||||||
match evt {
|
|
||||||
TouchEvent::Down {
|
|
||||||
surface, id, x, y, ..
|
|
||||||
} => {
|
|
||||||
let wid = store.find_wid(&surface);
|
|
||||||
if let Some(wid) = wid {
|
|
||||||
let scale_factor = surface::get_dpi_factor(&surface) as f64;
|
|
||||||
let position = LogicalPosition::new(x, y);
|
|
||||||
|
|
||||||
sink.send_window_event(
|
|
||||||
WindowEvent::Touch(crate::event::Touch {
|
|
||||||
device_id: crate::event::DeviceId(
|
|
||||||
crate::platform_impl::DeviceId::Wayland(DeviceId),
|
|
||||||
),
|
|
||||||
phase: TouchPhase::Started,
|
|
||||||
location: position.to_physical(scale_factor),
|
|
||||||
force: None, // TODO
|
|
||||||
id: id as u64,
|
|
||||||
}),
|
|
||||||
wid,
|
|
||||||
);
|
|
||||||
pending_ids.push(TouchPoint {
|
|
||||||
surface,
|
|
||||||
position,
|
|
||||||
id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TouchEvent::Up { id, .. } => {
|
|
||||||
let idx = pending_ids.iter().position(|p| p.id == id);
|
|
||||||
if let Some(idx) = idx {
|
|
||||||
let pt = pending_ids.remove(idx);
|
|
||||||
|
|
||||||
let scale_factor = surface::get_dpi_factor(&pt.surface) as f64;
|
|
||||||
let location = pt.position.to_physical(scale_factor);
|
|
||||||
|
|
||||||
sink.send_window_event(
|
|
||||||
WindowEvent::Touch(crate::event::Touch {
|
|
||||||
device_id: crate::event::DeviceId(
|
|
||||||
crate::platform_impl::DeviceId::Wayland(DeviceId),
|
|
||||||
),
|
|
||||||
phase: TouchPhase::Ended,
|
|
||||||
location,
|
|
||||||
force: None, // TODO
|
|
||||||
id: id as u64,
|
|
||||||
}),
|
|
||||||
make_wid(&pt.surface),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TouchEvent::Motion { id, x, y, .. } => {
|
|
||||||
let pt = pending_ids.iter_mut().find(|p| p.id == id);
|
|
||||||
if let Some(pt) = pt {
|
|
||||||
pt.position = LogicalPosition::new(x, y);
|
|
||||||
|
|
||||||
let scale_factor = surface::get_dpi_factor(&pt.surface) as f64;
|
|
||||||
let location = pt.position.to_physical(scale_factor);
|
|
||||||
|
|
||||||
sink.send_window_event(
|
|
||||||
WindowEvent::Touch(crate::event::Touch {
|
|
||||||
device_id: crate::event::DeviceId(
|
|
||||||
crate::platform_impl::DeviceId::Wayland(DeviceId),
|
|
||||||
),
|
|
||||||
phase: TouchPhase::Moved,
|
|
||||||
location,
|
|
||||||
force: None, // TODO
|
|
||||||
id: id as u64,
|
|
||||||
}),
|
|
||||||
make_wid(&pt.surface),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TouchEvent::Frame => (),
|
|
||||||
TouchEvent::Cancel => {
|
|
||||||
for pt in pending_ids.drain(..) {
|
|
||||||
let scale_factor = surface::get_dpi_factor(&pt.surface) as f64;
|
|
||||||
let location = pt.position.to_physical(scale_factor);
|
|
||||||
|
|
||||||
sink.send_window_event(
|
|
||||||
WindowEvent::Touch(crate::event::Touch {
|
|
||||||
device_id: crate::event::DeviceId(
|
|
||||||
crate::platform_impl::DeviceId::Wayland(DeviceId),
|
|
||||||
),
|
|
||||||
phase: TouchPhase::Cancelled,
|
|
||||||
location,
|
|
||||||
force: None, // TODO
|
|
||||||
id: pt.id as u64,
|
|
||||||
}),
|
|
||||||
make_wid(&pt.surface),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
(),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
@@ -1,560 +0,0 @@
|
|||||||
use raw_window_handle::unix::WaylandHandle;
|
|
||||||
use std::{
|
|
||||||
collections::VecDeque,
|
|
||||||
mem::replace,
|
|
||||||
sync::{Arc, Mutex, Weak},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Position, Size},
|
|
||||||
error::{ExternalError, NotSupportedError, OsError as RootOsError},
|
|
||||||
monitor::MonitorHandle as RootMonitorHandle,
|
|
||||||
platform_impl::{
|
|
||||||
platform::wayland::event_loop::{available_monitors, primary_monitor},
|
|
||||||
MonitorHandle as PlatformMonitorHandle,
|
|
||||||
PlatformSpecificWindowBuilderAttributes as PlAttributes,
|
|
||||||
},
|
|
||||||
window::{CursorIcon, Fullscreen, WindowAttributes},
|
|
||||||
};
|
|
||||||
|
|
||||||
use smithay_client_toolkit::{
|
|
||||||
output::OutputMgr,
|
|
||||||
reexports::client::{
|
|
||||||
protocol::{wl_seat, wl_surface},
|
|
||||||
Display,
|
|
||||||
},
|
|
||||||
surface::{get_dpi_factor, get_outputs},
|
|
||||||
window::{ConceptFrame, Event as WEvent, State as WState, Theme, Window as SWindow},
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{event_loop::CursorManager, make_wid, EventLoopWindowTarget, MonitorHandle, WindowId};
|
|
||||||
|
|
||||||
pub struct Window {
|
|
||||||
surface: wl_surface::WlSurface,
|
|
||||||
frame: Arc<Mutex<SWindow<ConceptFrame>>>,
|
|
||||||
cursor_manager: Arc<Mutex<CursorManager>>,
|
|
||||||
outputs: OutputMgr, // Access to info for all monitors
|
|
||||||
size: Arc<Mutex<(u32, u32)>>,
|
|
||||||
kill_switch: (Arc<Mutex<bool>>, Arc<Mutex<bool>>),
|
|
||||||
display: Arc<Display>,
|
|
||||||
need_frame_refresh: Arc<Mutex<bool>>,
|
|
||||||
need_refresh: Arc<Mutex<bool>>,
|
|
||||||
fullscreen: Arc<Mutex<bool>>,
|
|
||||||
cursor_grab_changed: Arc<Mutex<Option<bool>>>, // Update grab state
|
|
||||||
decorated: Arc<Mutex<bool>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub enum DecorationsAction {
|
|
||||||
Hide,
|
|
||||||
Show,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Window {
|
|
||||||
pub fn new<T>(
|
|
||||||
evlp: &EventLoopWindowTarget<T>,
|
|
||||||
attributes: WindowAttributes,
|
|
||||||
pl_attribs: PlAttributes,
|
|
||||||
) -> Result<Window, RootOsError> {
|
|
||||||
// Create the surface first to get initial DPI
|
|
||||||
let window_store = evlp.store.clone();
|
|
||||||
let cursor_manager = evlp.cursor_manager.clone();
|
|
||||||
let surface = evlp.env.create_surface(move |scale_factor, surface| {
|
|
||||||
window_store
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.scale_factor_change(&surface, scale_factor);
|
|
||||||
surface.set_buffer_scale(scale_factor);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Always 1.
|
|
||||||
let scale_factor = get_dpi_factor(&surface);
|
|
||||||
|
|
||||||
let (width, height) = attributes
|
|
||||||
.inner_size
|
|
||||||
.map(|size| size.to_logical::<f64>(scale_factor as f64).into())
|
|
||||||
.unwrap_or((800, 600));
|
|
||||||
|
|
||||||
// Create the window
|
|
||||||
let size = Arc::new(Mutex::new((width, height)));
|
|
||||||
let fullscreen = Arc::new(Mutex::new(false));
|
|
||||||
|
|
||||||
let window_store = evlp.store.clone();
|
|
||||||
|
|
||||||
let decorated = Arc::new(Mutex::new(attributes.decorations));
|
|
||||||
let pending_decorations_action = Arc::new(Mutex::new(None));
|
|
||||||
|
|
||||||
let my_surface = surface.clone();
|
|
||||||
let mut frame = SWindow::<ConceptFrame>::init_from_env(
|
|
||||||
&evlp.env,
|
|
||||||
surface.clone(),
|
|
||||||
(width, height),
|
|
||||||
move |event| match event {
|
|
||||||
WEvent::Configure { new_size, states } => {
|
|
||||||
let mut store = window_store.lock().unwrap();
|
|
||||||
let is_fullscreen = states.contains(&WState::Fullscreen);
|
|
||||||
|
|
||||||
for window in &mut store.windows {
|
|
||||||
if window.surface.as_ref().equals(&my_surface.as_ref()) {
|
|
||||||
window.new_size = new_size;
|
|
||||||
*(window.need_refresh.lock().unwrap()) = true;
|
|
||||||
{
|
|
||||||
// Get whether we're in fullscreen
|
|
||||||
let mut fullscreen = window.fullscreen.lock().unwrap();
|
|
||||||
// Fullscreen state was changed, so update decorations
|
|
||||||
if *fullscreen != is_fullscreen {
|
|
||||||
let decorated = { *window.decorated.lock().unwrap() };
|
|
||||||
if decorated {
|
|
||||||
*window.pending_decorations_action.lock().unwrap() =
|
|
||||||
if is_fullscreen {
|
|
||||||
Some(DecorationsAction::Hide)
|
|
||||||
} else {
|
|
||||||
Some(DecorationsAction::Show)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*fullscreen = is_fullscreen;
|
|
||||||
}
|
|
||||||
*(window.need_frame_refresh.lock().unwrap()) = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
WEvent::Refresh => {
|
|
||||||
let store = window_store.lock().unwrap();
|
|
||||||
for window in &store.windows {
|
|
||||||
if window.surface.as_ref().equals(&my_surface.as_ref()) {
|
|
||||||
*(window.need_frame_refresh.lock().unwrap()) = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
WEvent::Close => {
|
|
||||||
let mut store = window_store.lock().unwrap();
|
|
||||||
for window in &mut store.windows {
|
|
||||||
if window.surface.as_ref().equals(&my_surface.as_ref()) {
|
|
||||||
window.closed = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
if let Some(app_id) = pl_attribs.app_id {
|
|
||||||
frame.set_app_id(app_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
for &(_, ref seat) in evlp.seats.lock().unwrap().iter() {
|
|
||||||
frame.new_seat(seat);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for fullscreen requirements
|
|
||||||
match attributes.fullscreen {
|
|
||||||
Some(Fullscreen::Exclusive(_)) => {
|
|
||||||
panic!("Wayland doesn't support exclusive fullscreen")
|
|
||||||
}
|
|
||||||
Some(Fullscreen::Borderless(RootMonitorHandle {
|
|
||||||
inner: PlatformMonitorHandle::Wayland(ref monitor_id),
|
|
||||||
})) => frame.set_fullscreen(Some(&monitor_id.proxy)),
|
|
||||||
Some(Fullscreen::Borderless(_)) => unreachable!(),
|
|
||||||
None => {
|
|
||||||
if attributes.maximized {
|
|
||||||
frame.set_maximized();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
frame.set_resizable(attributes.resizable);
|
|
||||||
|
|
||||||
// set decorations
|
|
||||||
frame.set_decorate(attributes.decorations);
|
|
||||||
|
|
||||||
// set title
|
|
||||||
frame.set_title(attributes.title);
|
|
||||||
|
|
||||||
// min-max dimensions
|
|
||||||
frame.set_min_size(
|
|
||||||
attributes
|
|
||||||
.min_inner_size
|
|
||||||
.map(|size| size.to_logical::<f64>(scale_factor as f64).into()),
|
|
||||||
);
|
|
||||||
frame.set_max_size(
|
|
||||||
attributes
|
|
||||||
.max_inner_size
|
|
||||||
.map(|size| size.to_logical::<f64>(scale_factor as f64).into()),
|
|
||||||
);
|
|
||||||
|
|
||||||
let kill_switch = Arc::new(Mutex::new(false));
|
|
||||||
let need_frame_refresh = Arc::new(Mutex::new(true));
|
|
||||||
let frame = Arc::new(Mutex::new(frame));
|
|
||||||
let need_refresh = Arc::new(Mutex::new(true));
|
|
||||||
let cursor_grab_changed = Arc::new(Mutex::new(None));
|
|
||||||
|
|
||||||
evlp.store.lock().unwrap().windows.push(InternalWindow {
|
|
||||||
closed: false,
|
|
||||||
new_size: None,
|
|
||||||
size: size.clone(),
|
|
||||||
need_refresh: need_refresh.clone(),
|
|
||||||
fullscreen: fullscreen.clone(),
|
|
||||||
cursor_grab_changed: cursor_grab_changed.clone(),
|
|
||||||
need_frame_refresh: need_frame_refresh.clone(),
|
|
||||||
surface: surface.clone(),
|
|
||||||
kill_switch: kill_switch.clone(),
|
|
||||||
frame: Arc::downgrade(&frame),
|
|
||||||
current_scale_factor: scale_factor,
|
|
||||||
new_scale_factor: None,
|
|
||||||
decorated: decorated.clone(),
|
|
||||||
pending_decorations_action: pending_decorations_action.clone(),
|
|
||||||
});
|
|
||||||
evlp.evq.borrow_mut().sync_roundtrip().unwrap();
|
|
||||||
|
|
||||||
Ok(Window {
|
|
||||||
display: evlp.display.clone(),
|
|
||||||
surface,
|
|
||||||
frame,
|
|
||||||
outputs: evlp.env.outputs.clone(),
|
|
||||||
size,
|
|
||||||
kill_switch: (kill_switch, evlp.cleanup_needed.clone()),
|
|
||||||
need_frame_refresh,
|
|
||||||
need_refresh,
|
|
||||||
cursor_manager,
|
|
||||||
fullscreen,
|
|
||||||
cursor_grab_changed,
|
|
||||||
decorated,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn id(&self) -> WindowId {
|
|
||||||
make_wid(&self.surface)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_title(&self, title: &str) {
|
|
||||||
self.frame.lock().unwrap().set_title(title.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_visible(&self, _visible: bool) {
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
|
||||||
Err(NotSupportedError::new())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
|
|
||||||
Err(NotSupportedError::new())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_outer_position(&self, _pos: Position) {
|
|
||||||
// Not possible with wayland
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn inner_size(&self) -> PhysicalSize<u32> {
|
|
||||||
let scale_factor = self.scale_factor() as f64;
|
|
||||||
let size = LogicalSize::<f64>::from(*self.size.lock().unwrap());
|
|
||||||
size.to_physical(scale_factor)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn request_redraw(&self) {
|
|
||||||
*self.need_refresh.lock().unwrap() = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn outer_size(&self) -> PhysicalSize<u32> {
|
|
||||||
let scale_factor = self.scale_factor() as f64;
|
|
||||||
let (w, h) = self.size.lock().unwrap().clone();
|
|
||||||
// let (w, h) = super::wayland_window::add_borders(w as i32, h as i32);
|
|
||||||
let size = LogicalSize::<f64>::from((w, h));
|
|
||||||
size.to_physical(scale_factor)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
// NOTE: This will only resize the borders, the contents must be updated by the user
|
|
||||||
pub fn set_inner_size(&self, size: Size) {
|
|
||||||
let scale_factor = self.scale_factor() as f64;
|
|
||||||
let (w, h) = size.to_logical::<u32>(scale_factor).into();
|
|
||||||
self.frame.lock().unwrap().resize(w, h);
|
|
||||||
*(self.size.lock().unwrap()) = (w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_min_inner_size(&self, dimensions: Option<Size>) {
|
|
||||||
let scale_factor = self.scale_factor() as f64;
|
|
||||||
self.frame
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_min_size(dimensions.map(|dim| dim.to_logical::<f64>(scale_factor).into()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_max_inner_size(&self, dimensions: Option<Size>) {
|
|
||||||
let scale_factor = self.scale_factor() as f64;
|
|
||||||
self.frame
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_max_size(dimensions.map(|dim| dim.to_logical::<f64>(scale_factor).into()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_resizable(&self, resizable: bool) {
|
|
||||||
self.frame.lock().unwrap().set_resizable(resizable);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn scale_factor(&self) -> i32 {
|
|
||||||
get_dpi_factor(&self.surface)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_decorations(&self, decorate: bool) {
|
|
||||||
*(self.decorated.lock().unwrap()) = decorate;
|
|
||||||
self.frame.lock().unwrap().set_decorate(decorate);
|
|
||||||
*(self.need_frame_refresh.lock().unwrap()) = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_minimized(&self, minimized: bool) {
|
|
||||||
// An app cannot un-minimize itself on Wayland
|
|
||||||
if minimized {
|
|
||||||
self.frame.lock().unwrap().set_minimized();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_maximized(&self, maximized: bool) {
|
|
||||||
if maximized {
|
|
||||||
self.frame.lock().unwrap().set_maximized();
|
|
||||||
} else {
|
|
||||||
self.frame.lock().unwrap().unset_maximized();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn fullscreen(&self) -> Option<Fullscreen> {
|
|
||||||
if *(self.fullscreen.lock().unwrap()) {
|
|
||||||
Some(Fullscreen::Borderless(RootMonitorHandle {
|
|
||||||
inner: PlatformMonitorHandle::Wayland(self.current_monitor()),
|
|
||||||
}))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) {
|
|
||||||
match fullscreen {
|
|
||||||
Some(Fullscreen::Exclusive(_)) => {
|
|
||||||
panic!("Wayland doesn't support exclusive fullscreen")
|
|
||||||
}
|
|
||||||
Some(Fullscreen::Borderless(RootMonitorHandle {
|
|
||||||
inner: PlatformMonitorHandle::Wayland(ref monitor_id),
|
|
||||||
})) => {
|
|
||||||
self.frame
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.set_fullscreen(Some(&monitor_id.proxy));
|
|
||||||
}
|
|
||||||
Some(Fullscreen::Borderless(_)) => unreachable!(),
|
|
||||||
None => self.frame.lock().unwrap().unset_fullscreen(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_theme<T: Theme>(&self, theme: T) {
|
|
||||||
self.frame.lock().unwrap().set_theme(theme)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_cursor_icon(&self, cursor: CursorIcon) {
|
|
||||||
let mut cursor_manager = self.cursor_manager.lock().unwrap();
|
|
||||||
cursor_manager.set_cursor_icon(cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_cursor_visible(&self, visible: bool) {
|
|
||||||
let mut cursor_manager = self.cursor_manager.lock().unwrap();
|
|
||||||
cursor_manager.set_cursor_visible(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_cursor_grab(&self, grab: bool) -> Result<(), ExternalError> {
|
|
||||||
*self.cursor_grab_changed.lock().unwrap() = Some(grab);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn set_cursor_position(&self, _pos: Position) -> Result<(), ExternalError> {
|
|
||||||
Err(ExternalError::NotSupported(NotSupportedError::new()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn display(&self) -> &Display {
|
|
||||||
&*self.display
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn surface(&self) -> &wl_surface::WlSurface {
|
|
||||||
&self.surface
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn current_monitor(&self) -> MonitorHandle {
|
|
||||||
let output = get_outputs(&self.surface).last().unwrap().clone();
|
|
||||||
MonitorHandle {
|
|
||||||
proxy: output,
|
|
||||||
mgr: self.outputs.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
|
|
||||||
available_monitors(&self.outputs)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn primary_monitor(&self) -> MonitorHandle {
|
|
||||||
primary_monitor(&self.outputs)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn raw_window_handle(&self) -> WaylandHandle {
|
|
||||||
WaylandHandle {
|
|
||||||
surface: self.surface().as_ref().c_ptr() as *mut _,
|
|
||||||
display: self.display().as_ref().c_ptr() as *mut _,
|
|
||||||
..WaylandHandle::empty()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for Window {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
*(self.kill_switch.0.lock().unwrap()) = true;
|
|
||||||
*(self.kill_switch.1.lock().unwrap()) = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Internal store for windows
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct InternalWindow {
|
|
||||||
surface: wl_surface::WlSurface,
|
|
||||||
// TODO: CONVERT TO LogicalSize<u32>s
|
|
||||||
new_size: Option<(u32, u32)>,
|
|
||||||
size: Arc<Mutex<(u32, u32)>>,
|
|
||||||
need_refresh: Arc<Mutex<bool>>,
|
|
||||||
fullscreen: Arc<Mutex<bool>>,
|
|
||||||
need_frame_refresh: Arc<Mutex<bool>>,
|
|
||||||
cursor_grab_changed: Arc<Mutex<Option<bool>>>,
|
|
||||||
closed: bool,
|
|
||||||
kill_switch: Arc<Mutex<bool>>,
|
|
||||||
frame: Weak<Mutex<SWindow<ConceptFrame>>>,
|
|
||||||
current_scale_factor: i32,
|
|
||||||
new_scale_factor: Option<i32>,
|
|
||||||
decorated: Arc<Mutex<bool>>,
|
|
||||||
pending_decorations_action: Arc<Mutex<Option<DecorationsAction>>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct WindowStore {
|
|
||||||
windows: Vec<InternalWindow>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct WindowStoreForEach<'a> {
|
|
||||||
pub new_size: Option<(u32, u32)>,
|
|
||||||
pub size: &'a Mutex<(u32, u32)>,
|
|
||||||
pub prev_scale_factor: i32,
|
|
||||||
pub new_scale_factor: Option<i32>,
|
|
||||||
pub closed: bool,
|
|
||||||
pub grab_cursor: Option<bool>,
|
|
||||||
pub surface: &'a wl_surface::WlSurface,
|
|
||||||
pub wid: WindowId,
|
|
||||||
pub frame: Option<&'a mut SWindow<ConceptFrame>>,
|
|
||||||
pub decorations_action: Option<DecorationsAction>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WindowStore {
|
|
||||||
pub fn new() -> WindowStore {
|
|
||||||
WindowStore {
|
|
||||||
windows: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn find_wid(&self, surface: &wl_surface::WlSurface) -> Option<WindowId> {
|
|
||||||
for window in &self.windows {
|
|
||||||
if surface.as_ref().equals(&window.surface.as_ref()) {
|
|
||||||
return Some(make_wid(surface));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn cleanup(&mut self) -> Vec<WindowId> {
|
|
||||||
let mut pruned = Vec::new();
|
|
||||||
self.windows.retain(|w| {
|
|
||||||
if *w.kill_switch.lock().unwrap() {
|
|
||||||
// window is dead, cleanup
|
|
||||||
pruned.push(make_wid(&w.surface));
|
|
||||||
w.surface.destroy();
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
pruned
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_seat(&self, seat: &wl_seat::WlSeat) {
|
|
||||||
for window in &self.windows {
|
|
||||||
if let Some(w) = window.frame.upgrade() {
|
|
||||||
w.lock().unwrap().new_seat(seat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn scale_factor_change(&mut self, surface: &wl_surface::WlSurface, new: i32) {
|
|
||||||
for window in &mut self.windows {
|
|
||||||
if surface.as_ref().equals(&window.surface.as_ref()) {
|
|
||||||
window.new_scale_factor = Some(new);
|
|
||||||
*(window.need_refresh.lock().unwrap()) = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn for_each<F>(&mut self, mut f: F)
|
|
||||||
where
|
|
||||||
F: FnMut(WindowStoreForEach<'_>),
|
|
||||||
{
|
|
||||||
for window in &mut self.windows {
|
|
||||||
let prev_scale_factor = window.current_scale_factor;
|
|
||||||
if let Some(scale_factor) = window.new_scale_factor {
|
|
||||||
window.current_scale_factor = scale_factor;
|
|
||||||
}
|
|
||||||
let opt_arc = window.frame.upgrade();
|
|
||||||
let mut opt_mutex_lock = opt_arc.as_ref().map(|m| m.lock().unwrap());
|
|
||||||
let decorations_action = { window.pending_decorations_action.lock().unwrap().take() };
|
|
||||||
f(WindowStoreForEach {
|
|
||||||
new_size: window.new_size.take(),
|
|
||||||
size: &window.size,
|
|
||||||
prev_scale_factor,
|
|
||||||
new_scale_factor: window.new_scale_factor.take(),
|
|
||||||
closed: window.closed,
|
|
||||||
grab_cursor: window.cursor_grab_changed.lock().unwrap().take(),
|
|
||||||
surface: &window.surface,
|
|
||||||
wid: make_wid(&window.surface),
|
|
||||||
frame: opt_mutex_lock.as_mut().map(|m| &mut **m),
|
|
||||||
decorations_action,
|
|
||||||
});
|
|
||||||
// avoid re-spamming the event
|
|
||||||
window.closed = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn for_each_redraw_trigger<F>(&mut self, mut f: F)
|
|
||||||
where
|
|
||||||
F: FnMut(bool, bool, WindowId, Option<&mut SWindow<ConceptFrame>>),
|
|
||||||
{
|
|
||||||
for window in &mut self.windows {
|
|
||||||
let opt_arc = window.frame.upgrade();
|
|
||||||
let mut opt_mutex_lock = opt_arc.as_ref().map(|m| m.lock().unwrap());
|
|
||||||
f(
|
|
||||||
replace(&mut *window.need_refresh.lock().unwrap(), false),
|
|
||||||
replace(&mut *window.need_frame_refresh.lock().unwrap(), false),
|
|
||||||
make_wid(&window.surface),
|
|
||||||
opt_mutex_lock.as_mut().map(|m| &mut **m),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,219 +0,0 @@
|
|||||||
use std::{
|
|
||||||
io,
|
|
||||||
os::raw::*,
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
str::Utf8Error,
|
|
||||||
sync::Arc,
|
|
||||||
};
|
|
||||||
|
|
||||||
use percent_encoding::percent_decode;
|
|
||||||
|
|
||||||
use super::{ffi, util, XConnection, XError};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct DndAtoms {
|
|
||||||
pub aware: ffi::Atom,
|
|
||||||
pub enter: ffi::Atom,
|
|
||||||
pub leave: ffi::Atom,
|
|
||||||
pub drop: ffi::Atom,
|
|
||||||
pub position: ffi::Atom,
|
|
||||||
pub status: ffi::Atom,
|
|
||||||
pub action_private: ffi::Atom,
|
|
||||||
pub selection: ffi::Atom,
|
|
||||||
pub finished: ffi::Atom,
|
|
||||||
pub type_list: ffi::Atom,
|
|
||||||
pub uri_list: ffi::Atom,
|
|
||||||
pub none: ffi::Atom,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DndAtoms {
|
|
||||||
pub fn new(xconn: &Arc<XConnection>) -> Result<Self, XError> {
|
|
||||||
let names = [
|
|
||||||
b"XdndAware\0".as_ptr() as *mut c_char,
|
|
||||||
b"XdndEnter\0".as_ptr() as *mut c_char,
|
|
||||||
b"XdndLeave\0".as_ptr() as *mut c_char,
|
|
||||||
b"XdndDrop\0".as_ptr() as *mut c_char,
|
|
||||||
b"XdndPosition\0".as_ptr() as *mut c_char,
|
|
||||||
b"XdndStatus\0".as_ptr() as *mut c_char,
|
|
||||||
b"XdndActionPrivate\0".as_ptr() as *mut c_char,
|
|
||||||
b"XdndSelection\0".as_ptr() as *mut c_char,
|
|
||||||
b"XdndFinished\0".as_ptr() as *mut c_char,
|
|
||||||
b"XdndTypeList\0".as_ptr() as *mut c_char,
|
|
||||||
b"text/uri-list\0".as_ptr() as *mut c_char,
|
|
||||||
b"None\0".as_ptr() as *mut c_char,
|
|
||||||
];
|
|
||||||
let atoms = unsafe { xconn.get_atoms(&names) }?;
|
|
||||||
Ok(DndAtoms {
|
|
||||||
aware: atoms[0],
|
|
||||||
enter: atoms[1],
|
|
||||||
leave: atoms[2],
|
|
||||||
drop: atoms[3],
|
|
||||||
position: atoms[4],
|
|
||||||
status: atoms[5],
|
|
||||||
action_private: atoms[6],
|
|
||||||
selection: atoms[7],
|
|
||||||
finished: atoms[8],
|
|
||||||
type_list: atoms[9],
|
|
||||||
uri_list: atoms[10],
|
|
||||||
none: atoms[11],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub enum DndState {
|
|
||||||
Accepted,
|
|
||||||
Rejected,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum DndDataParseError {
|
|
||||||
EmptyData,
|
|
||||||
InvalidUtf8(Utf8Error),
|
|
||||||
HostnameSpecified(String),
|
|
||||||
UnexpectedProtocol(String),
|
|
||||||
UnresolvablePath(io::Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Utf8Error> for DndDataParseError {
|
|
||||||
fn from(e: Utf8Error) -> Self {
|
|
||||||
DndDataParseError::InvalidUtf8(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<io::Error> for DndDataParseError {
|
|
||||||
fn from(e: io::Error) -> Self {
|
|
||||||
DndDataParseError::UnresolvablePath(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Dnd {
|
|
||||||
xconn: Arc<XConnection>,
|
|
||||||
pub atoms: DndAtoms,
|
|
||||||
// Populated by XdndEnter event handler
|
|
||||||
pub version: Option<c_long>,
|
|
||||||
pub type_list: Option<Vec<c_ulong>>,
|
|
||||||
// Populated by XdndPosition event handler
|
|
||||||
pub source_window: Option<c_ulong>,
|
|
||||||
// Populated by SelectionNotify event handler (triggered by XdndPosition event handler)
|
|
||||||
pub result: Option<Result<Vec<PathBuf>, DndDataParseError>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Dnd {
|
|
||||||
pub fn new(xconn: Arc<XConnection>) -> Result<Self, XError> {
|
|
||||||
let atoms = DndAtoms::new(&xconn)?;
|
|
||||||
Ok(Dnd {
|
|
||||||
xconn,
|
|
||||||
atoms,
|
|
||||||
version: None,
|
|
||||||
type_list: None,
|
|
||||||
source_window: None,
|
|
||||||
result: None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reset(&mut self) {
|
|
||||||
self.version = None;
|
|
||||||
self.type_list = None;
|
|
||||||
self.source_window = None;
|
|
||||||
self.result = None;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn send_status(
|
|
||||||
&self,
|
|
||||||
this_window: c_ulong,
|
|
||||||
target_window: c_ulong,
|
|
||||||
state: DndState,
|
|
||||||
) -> Result<(), XError> {
|
|
||||||
let (accepted, action) = match state {
|
|
||||||
DndState::Accepted => (1, self.atoms.action_private as c_long),
|
|
||||||
DndState::Rejected => (0, self.atoms.none as c_long),
|
|
||||||
};
|
|
||||||
self.xconn
|
|
||||||
.send_client_msg(
|
|
||||||
target_window,
|
|
||||||
target_window,
|
|
||||||
self.atoms.status,
|
|
||||||
None,
|
|
||||||
[this_window as c_long, accepted, 0, 0, action],
|
|
||||||
)
|
|
||||||
.flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn send_finished(
|
|
||||||
&self,
|
|
||||||
this_window: c_ulong,
|
|
||||||
target_window: c_ulong,
|
|
||||||
state: DndState,
|
|
||||||
) -> Result<(), XError> {
|
|
||||||
let (accepted, action) = match state {
|
|
||||||
DndState::Accepted => (1, self.atoms.action_private as c_long),
|
|
||||||
DndState::Rejected => (0, self.atoms.none as c_long),
|
|
||||||
};
|
|
||||||
self.xconn
|
|
||||||
.send_client_msg(
|
|
||||||
target_window,
|
|
||||||
target_window,
|
|
||||||
self.atoms.finished,
|
|
||||||
None,
|
|
||||||
[this_window as c_long, accepted, action, 0, 0],
|
|
||||||
)
|
|
||||||
.flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn get_type_list(
|
|
||||||
&self,
|
|
||||||
source_window: c_ulong,
|
|
||||||
) -> Result<Vec<ffi::Atom>, util::GetPropertyError> {
|
|
||||||
self.xconn
|
|
||||||
.get_property(source_window, self.atoms.type_list, ffi::XA_ATOM)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn convert_selection(&self, window: c_ulong, time: c_ulong) {
|
|
||||||
(self.xconn.xlib.XConvertSelection)(
|
|
||||||
self.xconn.display,
|
|
||||||
self.atoms.selection,
|
|
||||||
self.atoms.uri_list,
|
|
||||||
self.atoms.selection,
|
|
||||||
window,
|
|
||||||
time,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn read_data(
|
|
||||||
&self,
|
|
||||||
window: c_ulong,
|
|
||||||
) -> Result<Vec<c_uchar>, util::GetPropertyError> {
|
|
||||||
self.xconn
|
|
||||||
.get_property(window, self.atoms.selection, self.atoms.uri_list)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse_data(&self, data: &mut Vec<c_uchar>) -> Result<Vec<PathBuf>, DndDataParseError> {
|
|
||||||
if !data.is_empty() {
|
|
||||||
let mut path_list = Vec::new();
|
|
||||||
let decoded = percent_decode(data).decode_utf8()?.into_owned();
|
|
||||||
for uri in decoded.split("\r\n").filter(|u| !u.is_empty()) {
|
|
||||||
// The format is specified as protocol://host/path
|
|
||||||
// However, it's typically simply protocol:///path
|
|
||||||
let path_str = if uri.starts_with("file://") {
|
|
||||||
let path_str = uri.replace("file://", "");
|
|
||||||
if !path_str.starts_with('/') {
|
|
||||||
// A hostname is specified
|
|
||||||
// Supporting this case is beyond the scope of my mental health
|
|
||||||
return Err(DndDataParseError::HostnameSpecified(path_str));
|
|
||||||
}
|
|
||||||
path_str
|
|
||||||
} else {
|
|
||||||
// Only the file protocol is supported
|
|
||||||
return Err(DndDataParseError::UnexpectedProtocol(uri.to_owned()));
|
|
||||||
};
|
|
||||||
|
|
||||||
let path = Path::new(&path_str).canonicalize()?;
|
|
||||||
path_list.push(path);
|
|
||||||
}
|
|
||||||
Ok(path_list)
|
|
||||||
} else {
|
|
||||||
Err(DndDataParseError::EmptyData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,4 +0,0 @@
|
|||||||
pub use x11_dl::{
|
|
||||||
error::OpenError, keysym::*, xcursor::*, xinput::*, xinput2::*, xlib::*, xlib_xcb::*,
|
|
||||||
xrandr::*, xrender::*,
|
|
||||||
};
|
|
||||||
@@ -1,175 +0,0 @@
|
|||||||
use std::{collections::HashMap, os::raw::c_char, ptr, sync::Arc};
|
|
||||||
|
|
||||||
use super::{ffi, XConnection, XError};
|
|
||||||
|
|
||||||
use super::{
|
|
||||||
context::{ImeContext, ImeContextCreationError},
|
|
||||||
inner::{close_im, ImeInner},
|
|
||||||
input_method::PotentialInputMethods,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub unsafe fn xim_set_callback(
|
|
||||||
xconn: &Arc<XConnection>,
|
|
||||||
xim: ffi::XIM,
|
|
||||||
field: *const c_char,
|
|
||||||
callback: *mut ffi::XIMCallback,
|
|
||||||
) -> Result<(), XError> {
|
|
||||||
// It's advisable to wrap variadic FFI functions in our own functions, as we want to minimize
|
|
||||||
// access that isn't type-checked.
|
|
||||||
(xconn.xlib.XSetIMValues)(xim, field, callback, ptr::null_mut::<()>());
|
|
||||||
xconn.check_errors()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set a callback for when an input method matching the current locale modifiers becomes
|
|
||||||
// available. Note that this has nothing to do with what input methods are open or able to be
|
|
||||||
// opened, and simply uses the modifiers that are set when the callback is set.
|
|
||||||
// * This is called per locale modifier, not per input method opened with that locale modifier.
|
|
||||||
// * Trying to set this for multiple locale modifiers causes problems, i.e. one of the rebuilt
|
|
||||||
// input contexts would always silently fail to use the input method.
|
|
||||||
pub unsafe fn set_instantiate_callback(
|
|
||||||
xconn: &Arc<XConnection>,
|
|
||||||
client_data: ffi::XPointer,
|
|
||||||
) -> Result<(), XError> {
|
|
||||||
(xconn.xlib.XRegisterIMInstantiateCallback)(
|
|
||||||
xconn.display,
|
|
||||||
ptr::null_mut(),
|
|
||||||
ptr::null_mut(),
|
|
||||||
ptr::null_mut(),
|
|
||||||
Some(xim_instantiate_callback),
|
|
||||||
client_data,
|
|
||||||
);
|
|
||||||
xconn.check_errors()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn unset_instantiate_callback(
|
|
||||||
xconn: &Arc<XConnection>,
|
|
||||||
client_data: ffi::XPointer,
|
|
||||||
) -> Result<(), XError> {
|
|
||||||
(xconn.xlib.XUnregisterIMInstantiateCallback)(
|
|
||||||
xconn.display,
|
|
||||||
ptr::null_mut(),
|
|
||||||
ptr::null_mut(),
|
|
||||||
ptr::null_mut(),
|
|
||||||
Some(xim_instantiate_callback),
|
|
||||||
client_data,
|
|
||||||
);
|
|
||||||
xconn.check_errors()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn set_destroy_callback(
|
|
||||||
xconn: &Arc<XConnection>,
|
|
||||||
im: ffi::XIM,
|
|
||||||
inner: &ImeInner,
|
|
||||||
) -> Result<(), XError> {
|
|
||||||
xim_set_callback(
|
|
||||||
&xconn,
|
|
||||||
im,
|
|
||||||
ffi::XNDestroyCallback_0.as_ptr() as *const _,
|
|
||||||
&inner.destroy_callback as *const _ as *mut _,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
enum ReplaceImError {
|
|
||||||
MethodOpenFailed(PotentialInputMethods),
|
|
||||||
ContextCreationFailed(ImeContextCreationError),
|
|
||||||
SetDestroyCallbackFailed(XError),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to replace current IM (which may or may not be presently valid) with a new one. This
|
|
||||||
// includes replacing all existing input contexts and free'ing resources as necessary. This only
|
|
||||||
// modifies existing state if all operations succeed.
|
|
||||||
unsafe fn replace_im(inner: *mut ImeInner) -> Result<(), ReplaceImError> {
|
|
||||||
let xconn = &(*inner).xconn;
|
|
||||||
|
|
||||||
let (new_im, is_fallback) = {
|
|
||||||
let new_im = (*inner).potential_input_methods.open_im(xconn, None);
|
|
||||||
let is_fallback = new_im.is_fallback();
|
|
||||||
(
|
|
||||||
new_im.ok().ok_or_else(|| {
|
|
||||||
ReplaceImError::MethodOpenFailed((*inner).potential_input_methods.clone())
|
|
||||||
})?,
|
|
||||||
is_fallback,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
// It's important to always set a destroy callback, since there's otherwise potential for us
|
|
||||||
// to try to use or free a resource that's already been destroyed on the server.
|
|
||||||
{
|
|
||||||
let result = set_destroy_callback(xconn, new_im.im, &*inner);
|
|
||||||
if result.is_err() {
|
|
||||||
let _ = close_im(xconn, new_im.im);
|
|
||||||
}
|
|
||||||
result
|
|
||||||
}
|
|
||||||
.map_err(ReplaceImError::SetDestroyCallbackFailed)?;
|
|
||||||
|
|
||||||
let mut new_contexts = HashMap::new();
|
|
||||||
for (window, old_context) in (*inner).contexts.iter() {
|
|
||||||
let spot = old_context.as_ref().map(|old_context| old_context.ic_spot);
|
|
||||||
let new_context = {
|
|
||||||
let result = ImeContext::new(xconn, new_im.im, *window, spot);
|
|
||||||
if result.is_err() {
|
|
||||||
let _ = close_im(xconn, new_im.im);
|
|
||||||
}
|
|
||||||
result.map_err(ReplaceImError::ContextCreationFailed)?
|
|
||||||
};
|
|
||||||
new_contexts.insert(*window, Some(new_context));
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we've made it this far, everything succeeded.
|
|
||||||
let _ = (*inner).destroy_all_contexts_if_necessary();
|
|
||||||
let _ = (*inner).close_im_if_necessary();
|
|
||||||
(*inner).im = new_im.im;
|
|
||||||
(*inner).contexts = new_contexts;
|
|
||||||
(*inner).is_destroyed = false;
|
|
||||||
(*inner).is_fallback = is_fallback;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe extern "C" fn xim_instantiate_callback(
|
|
||||||
_display: *mut ffi::Display,
|
|
||||||
client_data: ffi::XPointer,
|
|
||||||
// This field is unsupplied.
|
|
||||||
_call_data: ffi::XPointer,
|
|
||||||
) {
|
|
||||||
let inner: *mut ImeInner = client_data as _;
|
|
||||||
if !inner.is_null() {
|
|
||||||
let xconn = &(*inner).xconn;
|
|
||||||
let result = replace_im(inner);
|
|
||||||
if result.is_ok() {
|
|
||||||
let _ = unset_instantiate_callback(xconn, client_data);
|
|
||||||
(*inner).is_fallback = false;
|
|
||||||
} else if result.is_err() && (*inner).is_destroyed {
|
|
||||||
// We have no usable input methods!
|
|
||||||
result.expect("Failed to reopen input method");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This callback is triggered when the input method is closed on the server end. When this
|
|
||||||
// happens, XCloseIM/XDestroyIC doesn't need to be called, as the resources have already been
|
|
||||||
// free'd (attempting to do so causes our connection to freeze).
|
|
||||||
pub unsafe extern "C" fn xim_destroy_callback(
|
|
||||||
_xim: ffi::XIM,
|
|
||||||
client_data: ffi::XPointer,
|
|
||||||
// This field is unsupplied.
|
|
||||||
_call_data: ffi::XPointer,
|
|
||||||
) {
|
|
||||||
let inner: *mut ImeInner = client_data as _;
|
|
||||||
if !inner.is_null() {
|
|
||||||
(*inner).is_destroyed = true;
|
|
||||||
let xconn = &(*inner).xconn;
|
|
||||||
if !(*inner).is_fallback {
|
|
||||||
let _ = set_instantiate_callback(xconn, client_data);
|
|
||||||
// Attempt to open fallback input method.
|
|
||||||
let result = replace_im(inner);
|
|
||||||
if result.is_ok() {
|
|
||||||
(*inner).is_fallback = true;
|
|
||||||
} else {
|
|
||||||
// We have no usable input methods!
|
|
||||||
result.expect("Failed to open fallback input method");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,139 +0,0 @@
|
|||||||
use std::{
|
|
||||||
os::raw::{c_short, c_void},
|
|
||||||
ptr,
|
|
||||||
sync::Arc,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{ffi, util, XConnection, XError};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum ImeContextCreationError {
|
|
||||||
XError(XError),
|
|
||||||
Null,
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn create_pre_edit_attr<'a>(
|
|
||||||
xconn: &'a Arc<XConnection>,
|
|
||||||
ic_spot: &'a ffi::XPoint,
|
|
||||||
) -> util::XSmartPointer<'a, c_void> {
|
|
||||||
util::XSmartPointer::new(
|
|
||||||
xconn,
|
|
||||||
(xconn.xlib.XVaCreateNestedList)(
|
|
||||||
0,
|
|
||||||
ffi::XNSpotLocation_0.as_ptr() as *const _,
|
|
||||||
ic_spot,
|
|
||||||
ptr::null_mut::<()>(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.expect("XVaCreateNestedList returned NULL")
|
|
||||||
}
|
|
||||||
|
|
||||||
// WARNING: this struct doesn't destroy its XIC resource when dropped.
|
|
||||||
// This is intentional, as it doesn't have enough information to know whether or not the context
|
|
||||||
// still exists on the server. Since `ImeInner` has that awareness, destruction must be handled
|
|
||||||
// through `ImeInner`.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ImeContext {
|
|
||||||
pub ic: ffi::XIC,
|
|
||||||
pub ic_spot: ffi::XPoint,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ImeContext {
|
|
||||||
pub unsafe fn new(
|
|
||||||
xconn: &Arc<XConnection>,
|
|
||||||
im: ffi::XIM,
|
|
||||||
window: ffi::Window,
|
|
||||||
ic_spot: Option<ffi::XPoint>,
|
|
||||||
) -> Result<Self, ImeContextCreationError> {
|
|
||||||
let ic = if let Some(ic_spot) = ic_spot {
|
|
||||||
ImeContext::create_ic_with_spot(xconn, im, window, ic_spot)
|
|
||||||
} else {
|
|
||||||
ImeContext::create_ic(xconn, im, window)
|
|
||||||
};
|
|
||||||
|
|
||||||
let ic = ic.ok_or(ImeContextCreationError::Null)?;
|
|
||||||
xconn
|
|
||||||
.check_errors()
|
|
||||||
.map_err(ImeContextCreationError::XError)?;
|
|
||||||
|
|
||||||
Ok(ImeContext {
|
|
||||||
ic,
|
|
||||||
ic_spot: ic_spot.unwrap_or_else(|| ffi::XPoint { x: 0, y: 0 }),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn create_ic(
|
|
||||||
xconn: &Arc<XConnection>,
|
|
||||||
im: ffi::XIM,
|
|
||||||
window: ffi::Window,
|
|
||||||
) -> Option<ffi::XIC> {
|
|
||||||
let ic = (xconn.xlib.XCreateIC)(
|
|
||||||
im,
|
|
||||||
ffi::XNInputStyle_0.as_ptr() as *const _,
|
|
||||||
ffi::XIMPreeditNothing | ffi::XIMStatusNothing,
|
|
||||||
ffi::XNClientWindow_0.as_ptr() as *const _,
|
|
||||||
window,
|
|
||||||
ptr::null_mut::<()>(),
|
|
||||||
);
|
|
||||||
if ic.is_null() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(ic)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn create_ic_with_spot(
|
|
||||||
xconn: &Arc<XConnection>,
|
|
||||||
im: ffi::XIM,
|
|
||||||
window: ffi::Window,
|
|
||||||
ic_spot: ffi::XPoint,
|
|
||||||
) -> Option<ffi::XIC> {
|
|
||||||
let pre_edit_attr = create_pre_edit_attr(xconn, &ic_spot);
|
|
||||||
let ic = (xconn.xlib.XCreateIC)(
|
|
||||||
im,
|
|
||||||
ffi::XNInputStyle_0.as_ptr() as *const _,
|
|
||||||
ffi::XIMPreeditNothing | ffi::XIMStatusNothing,
|
|
||||||
ffi::XNClientWindow_0.as_ptr() as *const _,
|
|
||||||
window,
|
|
||||||
ffi::XNPreeditAttributes_0.as_ptr() as *const _,
|
|
||||||
pre_edit_attr.ptr,
|
|
||||||
ptr::null_mut::<()>(),
|
|
||||||
);
|
|
||||||
if ic.is_null() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(ic)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn focus(&self, xconn: &Arc<XConnection>) -> Result<(), XError> {
|
|
||||||
unsafe {
|
|
||||||
(xconn.xlib.XSetICFocus)(self.ic);
|
|
||||||
}
|
|
||||||
xconn.check_errors()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn unfocus(&self, xconn: &Arc<XConnection>) -> Result<(), XError> {
|
|
||||||
unsafe {
|
|
||||||
(xconn.xlib.XUnsetICFocus)(self.ic);
|
|
||||||
}
|
|
||||||
xconn.check_errors()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_spot(&mut self, xconn: &Arc<XConnection>, x: c_short, y: c_short) {
|
|
||||||
if self.ic_spot.x == x && self.ic_spot.y == y {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.ic_spot = ffi::XPoint { x, y };
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
let pre_edit_attr = create_pre_edit_attr(xconn, &self.ic_spot);
|
|
||||||
(xconn.xlib.XSetICValues)(
|
|
||||||
self.ic,
|
|
||||||
ffi::XNPreeditAttributes_0.as_ptr() as *const _,
|
|
||||||
pre_edit_attr.ptr,
|
|
||||||
ptr::null_mut::<()>(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
use std::{collections::HashMap, mem, ptr, sync::Arc};
|
|
||||||
|
|
||||||
use super::{ffi, XConnection, XError};
|
|
||||||
|
|
||||||
use super::{context::ImeContext, input_method::PotentialInputMethods};
|
|
||||||
|
|
||||||
pub unsafe fn close_im(xconn: &Arc<XConnection>, im: ffi::XIM) -> Result<(), XError> {
|
|
||||||
(xconn.xlib.XCloseIM)(im);
|
|
||||||
xconn.check_errors()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn destroy_ic(xconn: &Arc<XConnection>, ic: ffi::XIC) -> Result<(), XError> {
|
|
||||||
(xconn.xlib.XDestroyIC)(ic);
|
|
||||||
xconn.check_errors()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ImeInner {
|
|
||||||
pub xconn: Arc<XConnection>,
|
|
||||||
// WARNING: this is initially null!
|
|
||||||
pub im: ffi::XIM,
|
|
||||||
pub potential_input_methods: PotentialInputMethods,
|
|
||||||
pub contexts: HashMap<ffi::Window, Option<ImeContext>>,
|
|
||||||
// WARNING: this is initially zeroed!
|
|
||||||
pub destroy_callback: ffi::XIMCallback,
|
|
||||||
// Indicates whether or not the the input method was destroyed on the server end
|
|
||||||
// (i.e. if ibus/fcitx/etc. was terminated/restarted)
|
|
||||||
pub is_destroyed: bool,
|
|
||||||
pub is_fallback: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ImeInner {
|
|
||||||
pub fn new(xconn: Arc<XConnection>, potential_input_methods: PotentialInputMethods) -> Self {
|
|
||||||
ImeInner {
|
|
||||||
xconn,
|
|
||||||
im: ptr::null_mut(),
|
|
||||||
potential_input_methods,
|
|
||||||
contexts: HashMap::new(),
|
|
||||||
destroy_callback: unsafe { mem::zeroed() },
|
|
||||||
is_destroyed: false,
|
|
||||||
is_fallback: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn close_im_if_necessary(&self) -> Result<bool, XError> {
|
|
||||||
if !self.is_destroyed {
|
|
||||||
close_im(&self.xconn, self.im).map(|_| true)
|
|
||||||
} else {
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn destroy_ic_if_necessary(&self, ic: ffi::XIC) -> Result<bool, XError> {
|
|
||||||
if !self.is_destroyed {
|
|
||||||
destroy_ic(&self.xconn, ic).map(|_| true)
|
|
||||||
} else {
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn destroy_all_contexts_if_necessary(&self) -> Result<bool, XError> {
|
|
||||||
for context in self.contexts.values() {
|
|
||||||
if let &Some(ref context) = context {
|
|
||||||
self.destroy_ic_if_necessary(context.ic)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(!self.is_destroyed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,696 +0,0 @@
|
|||||||
#![cfg(any(
|
|
||||||
target_os = "linux",
|
|
||||||
target_os = "dragonfly",
|
|
||||||
target_os = "freebsd",
|
|
||||||
target_os = "netbsd",
|
|
||||||
target_os = "openbsd"
|
|
||||||
))]
|
|
||||||
|
|
||||||
mod dnd;
|
|
||||||
mod event_processor;
|
|
||||||
mod events;
|
|
||||||
pub mod ffi;
|
|
||||||
mod ime;
|
|
||||||
mod monitor;
|
|
||||||
pub mod util;
|
|
||||||
mod window;
|
|
||||||
mod xdisplay;
|
|
||||||
|
|
||||||
pub use self::{
|
|
||||||
monitor::{MonitorHandle, VideoMode},
|
|
||||||
window::UnownedWindow,
|
|
||||||
xdisplay::{XConnection, XError, XNotSupported},
|
|
||||||
};
|
|
||||||
|
|
||||||
use std::{
|
|
||||||
cell::RefCell,
|
|
||||||
collections::{HashMap, HashSet},
|
|
||||||
ffi::CStr,
|
|
||||||
mem::{self, MaybeUninit},
|
|
||||||
ops::Deref,
|
|
||||||
os::raw::*,
|
|
||||||
ptr,
|
|
||||||
rc::Rc,
|
|
||||||
slice,
|
|
||||||
sync::{mpsc, Arc, Mutex, Weak},
|
|
||||||
time::{Duration, Instant},
|
|
||||||
};
|
|
||||||
|
|
||||||
use libc::{self, setlocale, LC_CTYPE};
|
|
||||||
|
|
||||||
use mio::{unix::EventedFd, Events, Poll, PollOpt, Ready, Token};
|
|
||||||
|
|
||||||
use mio_extras::channel::{channel, Receiver, SendError, Sender};
|
|
||||||
|
|
||||||
use self::{
|
|
||||||
dnd::{Dnd, DndState},
|
|
||||||
event_processor::EventProcessor,
|
|
||||||
ime::{Ime, ImeCreationError, ImeReceiver, ImeSender},
|
|
||||||
util::modifiers::ModifierKeymap,
|
|
||||||
};
|
|
||||||
use crate::{
|
|
||||||
error::OsError as RootOsError,
|
|
||||||
event::{Event, StartCause},
|
|
||||||
event_loop::{ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootELW},
|
|
||||||
platform_impl::{platform::sticky_exit_callback, PlatformSpecificWindowBuilderAttributes},
|
|
||||||
window::WindowAttributes,
|
|
||||||
};
|
|
||||||
|
|
||||||
const X_TOKEN: Token = Token(0);
|
|
||||||
const USER_TOKEN: Token = Token(1);
|
|
||||||
|
|
||||||
pub struct EventLoopWindowTarget<T> {
|
|
||||||
xconn: Arc<XConnection>,
|
|
||||||
wm_delete_window: ffi::Atom,
|
|
||||||
net_wm_ping: ffi::Atom,
|
|
||||||
ime_sender: ImeSender,
|
|
||||||
root: ffi::Window,
|
|
||||||
ime: RefCell<Ime>,
|
|
||||||
windows: RefCell<HashMap<WindowId, Weak<UnownedWindow>>>,
|
|
||||||
pending_redraws: Arc<Mutex<HashSet<WindowId>>>,
|
|
||||||
_marker: ::std::marker::PhantomData<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct EventLoop<T: 'static> {
|
|
||||||
poll: Poll,
|
|
||||||
event_processor: EventProcessor<T>,
|
|
||||||
user_channel: Receiver<T>,
|
|
||||||
user_sender: Sender<T>,
|
|
||||||
target: Rc<RootELW<T>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct EventLoopProxy<T: 'static> {
|
|
||||||
user_sender: Sender<T>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: 'static> Clone for EventLoopProxy<T> {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
EventLoopProxy {
|
|
||||||
user_sender: self.user_sender.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: 'static> EventLoop<T> {
|
|
||||||
pub fn new(xconn: Arc<XConnection>) -> EventLoop<T> {
|
|
||||||
let root = unsafe { (xconn.xlib.XDefaultRootWindow)(xconn.display) };
|
|
||||||
|
|
||||||
let wm_delete_window = unsafe { xconn.get_atom_unchecked(b"WM_DELETE_WINDOW\0") };
|
|
||||||
|
|
||||||
let net_wm_ping = unsafe { xconn.get_atom_unchecked(b"_NET_WM_PING\0") };
|
|
||||||
|
|
||||||
let dnd = Dnd::new(Arc::clone(&xconn))
|
|
||||||
.expect("Failed to call XInternAtoms when initializing drag and drop");
|
|
||||||
|
|
||||||
let (ime_sender, ime_receiver) = mpsc::channel();
|
|
||||||
// Input methods will open successfully without setting the locale, but it won't be
|
|
||||||
// possible to actually commit pre-edit sequences.
|
|
||||||
unsafe {
|
|
||||||
// Remember default locale to restore it if target locale is unsupported
|
|
||||||
// by Xlib
|
|
||||||
let default_locale = setlocale(LC_CTYPE, ptr::null());
|
|
||||||
setlocale(LC_CTYPE, b"\0".as_ptr() as *const _);
|
|
||||||
|
|
||||||
// Check if set locale is supported by Xlib.
|
|
||||||
// If not, calls to some Xlib functions like `XSetLocaleModifiers`
|
|
||||||
// will fail.
|
|
||||||
let locale_supported = (xconn.xlib.XSupportsLocale)() == 1;
|
|
||||||
if !locale_supported {
|
|
||||||
let unsupported_locale = setlocale(LC_CTYPE, ptr::null());
|
|
||||||
warn!(
|
|
||||||
"Unsupported locale \"{}\". Restoring default locale \"{}\".",
|
|
||||||
CStr::from_ptr(unsupported_locale).to_string_lossy(),
|
|
||||||
CStr::from_ptr(default_locale).to_string_lossy()
|
|
||||||
);
|
|
||||||
// Restore default locale
|
|
||||||
setlocale(LC_CTYPE, default_locale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let ime = RefCell::new({
|
|
||||||
let result = Ime::new(Arc::clone(&xconn));
|
|
||||||
if let Err(ImeCreationError::OpenFailure(ref state)) = result {
|
|
||||||
panic!(format!("Failed to open input method: {:#?}", state));
|
|
||||||
}
|
|
||||||
result.expect("Failed to set input method destruction callback")
|
|
||||||
});
|
|
||||||
|
|
||||||
let randr_event_offset = xconn
|
|
||||||
.select_xrandr_input(root)
|
|
||||||
.expect("Failed to query XRandR extension");
|
|
||||||
|
|
||||||
let xi2ext = unsafe {
|
|
||||||
let mut ext = XExtension::default();
|
|
||||||
|
|
||||||
let res = (xconn.xlib.XQueryExtension)(
|
|
||||||
xconn.display,
|
|
||||||
b"XInputExtension\0".as_ptr() as *const c_char,
|
|
||||||
&mut ext.opcode,
|
|
||||||
&mut ext.first_event_id,
|
|
||||||
&mut ext.first_error_id,
|
|
||||||
);
|
|
||||||
|
|
||||||
if res == ffi::False {
|
|
||||||
panic!("X server missing XInput extension");
|
|
||||||
}
|
|
||||||
|
|
||||||
ext
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
let mut xinput_major_ver = ffi::XI_2_Major;
|
|
||||||
let mut xinput_minor_ver = ffi::XI_2_Minor;
|
|
||||||
if (xconn.xinput2.XIQueryVersion)(
|
|
||||||
xconn.display,
|
|
||||||
&mut xinput_major_ver,
|
|
||||||
&mut xinput_minor_ver,
|
|
||||||
) != ffi::Success as libc::c_int
|
|
||||||
{
|
|
||||||
panic!(
|
|
||||||
"X server has XInput extension {}.{} but does not support XInput2",
|
|
||||||
xinput_major_ver, xinput_minor_ver,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
xconn.update_cached_wm_info(root);
|
|
||||||
|
|
||||||
let pending_redraws: Arc<Mutex<HashSet<WindowId>>> = Default::default();
|
|
||||||
|
|
||||||
let mut mod_keymap = ModifierKeymap::new();
|
|
||||||
mod_keymap.reset_from_x_connection(&xconn);
|
|
||||||
|
|
||||||
let target = Rc::new(RootELW {
|
|
||||||
p: super::EventLoopWindowTarget::X(EventLoopWindowTarget {
|
|
||||||
ime,
|
|
||||||
root,
|
|
||||||
windows: Default::default(),
|
|
||||||
_marker: ::std::marker::PhantomData,
|
|
||||||
ime_sender,
|
|
||||||
xconn,
|
|
||||||
wm_delete_window,
|
|
||||||
net_wm_ping,
|
|
||||||
pending_redraws: pending_redraws.clone(),
|
|
||||||
}),
|
|
||||||
_marker: ::std::marker::PhantomData,
|
|
||||||
});
|
|
||||||
|
|
||||||
let poll = Poll::new().unwrap();
|
|
||||||
|
|
||||||
let (user_sender, user_channel) = channel();
|
|
||||||
|
|
||||||
poll.register(
|
|
||||||
&EventedFd(&get_xtarget(&target).xconn.x11_fd),
|
|
||||||
X_TOKEN,
|
|
||||||
Ready::readable(),
|
|
||||||
PollOpt::level(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
poll.register(
|
|
||||||
&user_channel,
|
|
||||||
USER_TOKEN,
|
|
||||||
Ready::readable(),
|
|
||||||
PollOpt::level(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let event_processor = EventProcessor {
|
|
||||||
target: target.clone(),
|
|
||||||
dnd,
|
|
||||||
devices: Default::default(),
|
|
||||||
randr_event_offset,
|
|
||||||
ime_receiver,
|
|
||||||
xi2ext,
|
|
||||||
mod_keymap,
|
|
||||||
device_mod_state: Default::default(),
|
|
||||||
num_touch: 0,
|
|
||||||
first_touch: None,
|
|
||||||
active_window: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Register for device hotplug events
|
|
||||||
// (The request buffer is flushed during `init_device`)
|
|
||||||
get_xtarget(&target)
|
|
||||||
.xconn
|
|
||||||
.select_xinput_events(root, ffi::XIAllDevices, ffi::XI_HierarchyChangedMask)
|
|
||||||
.queue();
|
|
||||||
|
|
||||||
event_processor.init_device(ffi::XIAllDevices);
|
|
||||||
|
|
||||||
let result = EventLoop {
|
|
||||||
poll,
|
|
||||||
user_channel,
|
|
||||||
user_sender,
|
|
||||||
event_processor,
|
|
||||||
target,
|
|
||||||
};
|
|
||||||
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create_proxy(&self) -> EventLoopProxy<T> {
|
|
||||||
EventLoopProxy {
|
|
||||||
user_sender: self.user_sender.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn window_target(&self) -> &RootELW<T> {
|
|
||||||
&self.target
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn x_connection(&self) -> &Arc<XConnection> {
|
|
||||||
get_xtarget(&self.target).x_connection()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run_return<F>(&mut self, mut callback: F)
|
|
||||||
where
|
|
||||||
F: FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
|
||||||
{
|
|
||||||
let mut control_flow = ControlFlow::default();
|
|
||||||
let mut events = Events::with_capacity(8);
|
|
||||||
let mut cause = StartCause::Init;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
sticky_exit_callback(
|
|
||||||
crate::event::Event::NewEvents(cause),
|
|
||||||
&self.target,
|
|
||||||
&mut control_flow,
|
|
||||||
&mut callback,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Process all pending events
|
|
||||||
self.drain_events(&mut callback, &mut control_flow);
|
|
||||||
|
|
||||||
let wt = get_xtarget(&self.target);
|
|
||||||
|
|
||||||
// Empty the user event buffer
|
|
||||||
{
|
|
||||||
while let Ok(event) = self.user_channel.try_recv() {
|
|
||||||
sticky_exit_callback(
|
|
||||||
crate::event::Event::UserEvent(event),
|
|
||||||
&self.target,
|
|
||||||
&mut control_flow,
|
|
||||||
&mut callback,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// send MainEventsCleared
|
|
||||||
{
|
|
||||||
sticky_exit_callback(
|
|
||||||
crate::event::Event::MainEventsCleared,
|
|
||||||
&self.target,
|
|
||||||
&mut control_flow,
|
|
||||||
&mut callback,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// Empty the redraw requests
|
|
||||||
{
|
|
||||||
// Release the lock to prevent deadlock
|
|
||||||
let windows: Vec<_> = wt.pending_redraws.lock().unwrap().drain().collect();
|
|
||||||
|
|
||||||
for wid in windows {
|
|
||||||
sticky_exit_callback(
|
|
||||||
Event::RedrawRequested(crate::window::WindowId(super::WindowId::X(wid))),
|
|
||||||
&self.target,
|
|
||||||
&mut control_flow,
|
|
||||||
&mut callback,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// send RedrawEventsCleared
|
|
||||||
{
|
|
||||||
sticky_exit_callback(
|
|
||||||
crate::event::Event::RedrawEventsCleared,
|
|
||||||
&self.target,
|
|
||||||
&mut control_flow,
|
|
||||||
&mut callback,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let start = Instant::now();
|
|
||||||
let (deadline, timeout);
|
|
||||||
|
|
||||||
match control_flow {
|
|
||||||
ControlFlow::Exit => break,
|
|
||||||
ControlFlow::Poll => {
|
|
||||||
cause = StartCause::Poll;
|
|
||||||
deadline = None;
|
|
||||||
timeout = Some(Duration::from_millis(0));
|
|
||||||
}
|
|
||||||
ControlFlow::Wait => {
|
|
||||||
cause = StartCause::WaitCancelled {
|
|
||||||
start,
|
|
||||||
requested_resume: None,
|
|
||||||
};
|
|
||||||
deadline = None;
|
|
||||||
timeout = None;
|
|
||||||
}
|
|
||||||
ControlFlow::WaitUntil(wait_deadline) => {
|
|
||||||
cause = StartCause::ResumeTimeReached {
|
|
||||||
start,
|
|
||||||
requested_resume: wait_deadline,
|
|
||||||
};
|
|
||||||
timeout = if wait_deadline > start {
|
|
||||||
Some(wait_deadline - start)
|
|
||||||
} else {
|
|
||||||
Some(Duration::from_millis(0))
|
|
||||||
};
|
|
||||||
deadline = Some(wait_deadline);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the XConnection already contains buffered events, we don't
|
|
||||||
// need to wait for data on the socket.
|
|
||||||
if !self.event_processor.poll() {
|
|
||||||
self.poll.poll(&mut events, timeout).unwrap();
|
|
||||||
events.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
let wait_cancelled = deadline.map_or(false, |deadline| Instant::now() < deadline);
|
|
||||||
|
|
||||||
if wait_cancelled {
|
|
||||||
cause = StartCause::WaitCancelled {
|
|
||||||
start,
|
|
||||||
requested_resume: deadline,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(
|
|
||||||
crate::event::Event::LoopDestroyed,
|
|
||||||
&self.target,
|
|
||||||
&mut control_flow,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run<F>(mut self, callback: F) -> !
|
|
||||||
where
|
|
||||||
F: 'static + FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
|
||||||
{
|
|
||||||
self.run_return(callback);
|
|
||||||
::std::process::exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn drain_events<F>(&mut self, callback: &mut F, control_flow: &mut ControlFlow)
|
|
||||||
where
|
|
||||||
F: FnMut(Event<'_, T>, &RootELW<T>, &mut ControlFlow),
|
|
||||||
{
|
|
||||||
let target = &self.target;
|
|
||||||
let mut xev = MaybeUninit::uninit();
|
|
||||||
|
|
||||||
let wt = get_xtarget(&self.target);
|
|
||||||
|
|
||||||
while unsafe { self.event_processor.poll_one_event(xev.as_mut_ptr()) } {
|
|
||||||
let mut xev = unsafe { xev.assume_init() };
|
|
||||||
self.event_processor.process_event(&mut xev, |event| {
|
|
||||||
sticky_exit_callback(
|
|
||||||
event,
|
|
||||||
target,
|
|
||||||
control_flow,
|
|
||||||
&mut |event, window_target, control_flow| {
|
|
||||||
if let Event::RedrawRequested(crate::window::WindowId(
|
|
||||||
super::WindowId::X(wid),
|
|
||||||
)) = event
|
|
||||||
{
|
|
||||||
wt.pending_redraws.lock().unwrap().insert(wid);
|
|
||||||
} else {
|
|
||||||
callback(event, window_target, control_flow);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_xtarget<T>(target: &RootELW<T>) -> &EventLoopWindowTarget<T> {
|
|
||||||
match target.p {
|
|
||||||
super::EventLoopWindowTarget::X(ref target) => target,
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> EventLoopWindowTarget<T> {
|
|
||||||
/// Returns the `XConnection` of this events loop.
|
|
||||||
#[inline]
|
|
||||||
pub fn x_connection(&self) -> &Arc<XConnection> {
|
|
||||||
&self.xconn
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: 'static> EventLoopProxy<T> {
|
|
||||||
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
|
|
||||||
self.user_sender.send(event).map_err(|e| {
|
|
||||||
EventLoopClosed(if let SendError::Disconnected(x) = e {
|
|
||||||
x
|
|
||||||
} else {
|
|
||||||
unreachable!()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct DeviceInfo<'a> {
|
|
||||||
xconn: &'a XConnection,
|
|
||||||
info: *const ffi::XIDeviceInfo,
|
|
||||||
count: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> DeviceInfo<'a> {
|
|
||||||
fn get(xconn: &'a XConnection, device: c_int) -> Option<Self> {
|
|
||||||
unsafe {
|
|
||||||
let mut count = 0;
|
|
||||||
let info = (xconn.xinput2.XIQueryDevice)(xconn.display, device, &mut count);
|
|
||||||
xconn.check_errors().ok()?;
|
|
||||||
|
|
||||||
if info.is_null() || count == 0 {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(DeviceInfo {
|
|
||||||
xconn,
|
|
||||||
info,
|
|
||||||
count: count as usize,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Drop for DeviceInfo<'a> {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
assert!(!self.info.is_null());
|
|
||||||
unsafe { (self.xconn.xinput2.XIFreeDeviceInfo)(self.info as *mut _) };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Deref for DeviceInfo<'a> {
|
|
||||||
type Target = [ffi::XIDeviceInfo];
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
unsafe { slice::from_raw_parts(self.info, self.count) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub struct WindowId(ffi::Window);
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
pub struct DeviceId(c_int);
|
|
||||||
|
|
||||||
pub struct Window(Arc<UnownedWindow>);
|
|
||||||
|
|
||||||
impl Deref for Window {
|
|
||||||
type Target = UnownedWindow;
|
|
||||||
#[inline]
|
|
||||||
fn deref(&self) -> &UnownedWindow {
|
|
||||||
&*self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Window {
|
|
||||||
pub fn new<T>(
|
|
||||||
event_loop: &EventLoopWindowTarget<T>,
|
|
||||||
attribs: WindowAttributes,
|
|
||||||
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
|
||||||
) -> Result<Self, RootOsError> {
|
|
||||||
let window = Arc::new(UnownedWindow::new(&event_loop, attribs, pl_attribs)?);
|
|
||||||
event_loop
|
|
||||||
.windows
|
|
||||||
.borrow_mut()
|
|
||||||
.insert(window.id(), Arc::downgrade(&window));
|
|
||||||
Ok(Window(window))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for Window {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
let window = self.deref();
|
|
||||||
let xconn = &window.xconn;
|
|
||||||
unsafe {
|
|
||||||
(xconn.xlib.XDestroyWindow)(xconn.display, window.id().0);
|
|
||||||
// If the window was somehow already destroyed, we'll get a `BadWindow` error, which we don't care about.
|
|
||||||
let _ = xconn.check_errors();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// XEvents of type GenericEvent store their actual data in an XGenericEventCookie data structure. This is a wrapper to
|
|
||||||
/// extract the cookie from a GenericEvent XEvent and release the cookie data once it has been processed
|
|
||||||
struct GenericEventCookie<'a> {
|
|
||||||
xconn: &'a XConnection,
|
|
||||||
cookie: ffi::XGenericEventCookie,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> GenericEventCookie<'a> {
|
|
||||||
fn from_event<'b>(
|
|
||||||
xconn: &'b XConnection,
|
|
||||||
event: ffi::XEvent,
|
|
||||||
) -> Option<GenericEventCookie<'b>> {
|
|
||||||
unsafe {
|
|
||||||
let mut cookie: ffi::XGenericEventCookie = From::from(event);
|
|
||||||
if (xconn.xlib.XGetEventData)(xconn.display, &mut cookie) == ffi::True {
|
|
||||||
Some(GenericEventCookie { xconn, cookie })
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Drop for GenericEventCookie<'a> {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
unsafe {
|
|
||||||
(self.xconn.xlib.XFreeEventData)(self.xconn.display, &mut self.cookie);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, Copy, Clone)]
|
|
||||||
struct XExtension {
|
|
||||||
opcode: c_int,
|
|
||||||
first_event_id: c_int,
|
|
||||||
first_error_id: c_int,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mkwid(w: ffi::Window) -> crate::window::WindowId {
|
|
||||||
crate::window::WindowId(crate::platform_impl::WindowId::X(WindowId(w)))
|
|
||||||
}
|
|
||||||
fn mkdid(w: c_int) -> crate::event::DeviceId {
|
|
||||||
crate::event::DeviceId(crate::platform_impl::DeviceId::X(DeviceId(w)))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct Device {
|
|
||||||
name: String,
|
|
||||||
scroll_axes: Vec<(i32, ScrollAxis)>,
|
|
||||||
// For master devices, this is the paired device (pointer <-> keyboard).
|
|
||||||
// For slave devices, this is the master.
|
|
||||||
attachment: c_int,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
struct ScrollAxis {
|
|
||||||
increment: f64,
|
|
||||||
orientation: ScrollOrientation,
|
|
||||||
position: f64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
enum ScrollOrientation {
|
|
||||||
Vertical,
|
|
||||||
Horizontal,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Device {
|
|
||||||
fn new<T: 'static>(el: &EventProcessor<T>, info: &ffi::XIDeviceInfo) -> Self {
|
|
||||||
let name = unsafe { CStr::from_ptr(info.name).to_string_lossy() };
|
|
||||||
let mut scroll_axes = Vec::new();
|
|
||||||
|
|
||||||
let wt = get_xtarget(&el.target);
|
|
||||||
|
|
||||||
if Device::physical_device(info) {
|
|
||||||
// Register for global raw events
|
|
||||||
let mask = ffi::XI_RawMotionMask
|
|
||||||
| ffi::XI_RawButtonPressMask
|
|
||||||
| ffi::XI_RawButtonReleaseMask
|
|
||||||
| ffi::XI_RawKeyPressMask
|
|
||||||
| ffi::XI_RawKeyReleaseMask;
|
|
||||||
// The request buffer is flushed when we poll for events
|
|
||||||
wt.xconn
|
|
||||||
.select_xinput_events(wt.root, info.deviceid, mask)
|
|
||||||
.queue();
|
|
||||||
|
|
||||||
// Identify scroll axes
|
|
||||||
for class_ptr in Device::classes(info) {
|
|
||||||
let class = unsafe { &**class_ptr };
|
|
||||||
match class._type {
|
|
||||||
ffi::XIScrollClass => {
|
|
||||||
let info = unsafe {
|
|
||||||
mem::transmute::<&ffi::XIAnyClassInfo, &ffi::XIScrollClassInfo>(class)
|
|
||||||
};
|
|
||||||
scroll_axes.push((
|
|
||||||
info.number,
|
|
||||||
ScrollAxis {
|
|
||||||
increment: info.increment,
|
|
||||||
orientation: match info.scroll_type {
|
|
||||||
ffi::XIScrollTypeHorizontal => ScrollOrientation::Horizontal,
|
|
||||||
ffi::XIScrollTypeVertical => ScrollOrientation::Vertical,
|
|
||||||
_ => unreachable!(),
|
|
||||||
},
|
|
||||||
position: 0.0,
|
|
||||||
},
|
|
||||||
));
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut device = Device {
|
|
||||||
name: name.into_owned(),
|
|
||||||
scroll_axes,
|
|
||||||
attachment: info.attachment,
|
|
||||||
};
|
|
||||||
device.reset_scroll_position(info);
|
|
||||||
device
|
|
||||||
}
|
|
||||||
|
|
||||||
fn reset_scroll_position(&mut self, info: &ffi::XIDeviceInfo) {
|
|
||||||
if Device::physical_device(info) {
|
|
||||||
for class_ptr in Device::classes(info) {
|
|
||||||
let class = unsafe { &**class_ptr };
|
|
||||||
match class._type {
|
|
||||||
ffi::XIValuatorClass => {
|
|
||||||
let info = unsafe {
|
|
||||||
mem::transmute::<&ffi::XIAnyClassInfo, &ffi::XIValuatorClassInfo>(class)
|
|
||||||
};
|
|
||||||
if let Some(&mut (_, ref mut axis)) = self
|
|
||||||
.scroll_axes
|
|
||||||
.iter_mut()
|
|
||||||
.find(|&&mut (axis, _)| axis == info.number)
|
|
||||||
{
|
|
||||||
axis.position = info.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn physical_device(info: &ffi::XIDeviceInfo) -> bool {
|
|
||||||
info._use == ffi::XISlaveKeyboard
|
|
||||||
|| info._use == ffi::XISlavePointer
|
|
||||||
|| info._use == ffi::XIFloatingSlave
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn classes(info: &ffi::XIDeviceInfo) -> &[*const ffi::XIAnyClassInfo] {
|
|
||||||
unsafe {
|
|
||||||
slice::from_raw_parts(
|
|
||||||
info.classes as *const *const ffi::XIAnyClassInfo,
|
|
||||||
info.num_classes as usize,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,314 +0,0 @@
|
|||||||
use std::os::raw::*;
|
|
||||||
|
|
||||||
use parking_lot::Mutex;
|
|
||||||
|
|
||||||
use super::{
|
|
||||||
ffi::{
|
|
||||||
RRCrtc, RRCrtcChangeNotifyMask, RRMode, RROutputPropertyNotifyMask,
|
|
||||||
RRScreenChangeNotifyMask, True, Window, XRRCrtcInfo, XRRScreenResources,
|
|
||||||
},
|
|
||||||
util, XConnection, XError,
|
|
||||||
};
|
|
||||||
use crate::{
|
|
||||||
dpi::{PhysicalPosition, PhysicalSize},
|
|
||||||
monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode},
|
|
||||||
platform_impl::{MonitorHandle as PlatformMonitorHandle, VideoMode as PlatformVideoMode},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Used for testing. This should always be committed as false.
|
|
||||||
const DISABLE_MONITOR_LIST_CACHING: bool = false;
|
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
static ref MONITORS: Mutex<Option<Vec<MonitorHandle>>> = Mutex::default();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn invalidate_cached_monitor_list() -> Option<Vec<MonitorHandle>> {
|
|
||||||
// We update this lazily.
|
|
||||||
(*MONITORS.lock()).take()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub struct VideoMode {
|
|
||||||
pub(crate) size: (u32, u32),
|
|
||||||
pub(crate) bit_depth: u16,
|
|
||||||
pub(crate) refresh_rate: u16,
|
|
||||||
pub(crate) native_mode: RRMode,
|
|
||||||
pub(crate) monitor: Option<MonitorHandle>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VideoMode {
|
|
||||||
#[inline]
|
|
||||||
pub fn size(&self) -> PhysicalSize<u32> {
|
|
||||||
self.size.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn bit_depth(&self) -> u16 {
|
|
||||||
self.bit_depth
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn refresh_rate(&self) -> u16 {
|
|
||||||
self.refresh_rate
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn monitor(&self) -> RootMonitorHandle {
|
|
||||||
RootMonitorHandle {
|
|
||||||
inner: PlatformMonitorHandle::X(self.monitor.clone().unwrap()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct MonitorHandle {
|
|
||||||
/// The actual id
|
|
||||||
pub(crate) id: RRCrtc,
|
|
||||||
/// The name of the monitor
|
|
||||||
pub(crate) name: String,
|
|
||||||
/// The size of the monitor
|
|
||||||
dimensions: (u32, u32),
|
|
||||||
/// The position of the monitor in the X screen
|
|
||||||
position: (i32, i32),
|
|
||||||
/// If the monitor is the primary one
|
|
||||||
primary: bool,
|
|
||||||
/// The DPI scale factor
|
|
||||||
pub(crate) scale_factor: f64,
|
|
||||||
/// Used to determine which windows are on this monitor
|
|
||||||
pub(crate) rect: util::AaRect,
|
|
||||||
/// Supported video modes on this monitor
|
|
||||||
video_modes: Vec<VideoMode>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialEq for MonitorHandle {
|
|
||||||
fn eq(&self, other: &Self) -> bool {
|
|
||||||
self.id == other.id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Eq for MonitorHandle {}
|
|
||||||
|
|
||||||
impl PartialOrd for MonitorHandle {
|
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
|
||||||
Some(self.cmp(&other))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Ord for MonitorHandle {
|
|
||||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
|
||||||
self.id.cmp(&other.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::hash::Hash for MonitorHandle {
|
|
||||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
|
||||||
self.id.hash(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MonitorHandle {
|
|
||||||
fn new(
|
|
||||||
xconn: &XConnection,
|
|
||||||
resources: *mut XRRScreenResources,
|
|
||||||
id: RRCrtc,
|
|
||||||
crtc: *mut XRRCrtcInfo,
|
|
||||||
primary: bool,
|
|
||||||
) -> Option<Self> {
|
|
||||||
let (name, scale_factor, video_modes) = unsafe { xconn.get_output_info(resources, crtc)? };
|
|
||||||
let dimensions = unsafe { ((*crtc).width as u32, (*crtc).height as u32) };
|
|
||||||
let position = unsafe { ((*crtc).x as i32, (*crtc).y as i32) };
|
|
||||||
let rect = util::AaRect::new(position, dimensions);
|
|
||||||
Some(MonitorHandle {
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
scale_factor,
|
|
||||||
dimensions,
|
|
||||||
position,
|
|
||||||
primary,
|
|
||||||
rect,
|
|
||||||
video_modes,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn dummy() -> Self {
|
|
||||||
MonitorHandle {
|
|
||||||
id: 0,
|
|
||||||
name: "<dummy monitor>".into(),
|
|
||||||
scale_factor: 1.0,
|
|
||||||
dimensions: (1, 1),
|
|
||||||
position: (0, 0),
|
|
||||||
primary: true,
|
|
||||||
rect: util::AaRect::new((0, 0), (1, 1)),
|
|
||||||
video_modes: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn is_dummy(&self) -> bool {
|
|
||||||
// Zero is an invalid XID value; no real monitor will have it
|
|
||||||
self.id == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn name(&self) -> Option<String> {
|
|
||||||
Some(self.name.clone())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn native_identifier(&self) -> u32 {
|
|
||||||
self.id as u32
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn size(&self) -> PhysicalSize<u32> {
|
|
||||||
self.dimensions.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn position(&self) -> PhysicalPosition<i32> {
|
|
||||||
self.position.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn scale_factor(&self) -> f64 {
|
|
||||||
self.scale_factor
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn video_modes(&self) -> impl Iterator<Item = RootVideoMode> {
|
|
||||||
let monitor = self.clone();
|
|
||||||
self.video_modes.clone().into_iter().map(move |mut x| {
|
|
||||||
x.monitor = Some(monitor.clone());
|
|
||||||
RootVideoMode {
|
|
||||||
video_mode: PlatformVideoMode::X(x),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl XConnection {
|
|
||||||
pub fn get_monitor_for_window(&self, window_rect: Option<util::AaRect>) -> MonitorHandle {
|
|
||||||
let monitors = self.available_monitors();
|
|
||||||
|
|
||||||
if monitors.is_empty() {
|
|
||||||
// Return a dummy monitor to avoid panicking
|
|
||||||
return MonitorHandle::dummy();
|
|
||||||
}
|
|
||||||
|
|
||||||
let default = monitors.get(0).unwrap();
|
|
||||||
|
|
||||||
let window_rect = match window_rect {
|
|
||||||
Some(rect) => rect,
|
|
||||||
None => return default.to_owned(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut largest_overlap = 0;
|
|
||||||
let mut matched_monitor = default;
|
|
||||||
for monitor in &monitors {
|
|
||||||
let overlapping_area = window_rect.get_overlapping_area(&monitor.rect);
|
|
||||||
if overlapping_area > largest_overlap {
|
|
||||||
largest_overlap = overlapping_area;
|
|
||||||
matched_monitor = &monitor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
matched_monitor.to_owned()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn query_monitor_list(&self) -> Vec<MonitorHandle> {
|
|
||||||
unsafe {
|
|
||||||
let mut major = 0;
|
|
||||||
let mut minor = 0;
|
|
||||||
(self.xrandr.XRRQueryVersion)(self.display, &mut major, &mut minor);
|
|
||||||
|
|
||||||
let root = (self.xlib.XDefaultRootWindow)(self.display);
|
|
||||||
let resources = if (major == 1 && minor >= 3) || major > 1 {
|
|
||||||
(self.xrandr.XRRGetScreenResourcesCurrent)(self.display, root)
|
|
||||||
} else {
|
|
||||||
// WARNING: this function is supposedly very slow, on the order of hundreds of ms.
|
|
||||||
// Upon failure, `resources` will be null.
|
|
||||||
(self.xrandr.XRRGetScreenResources)(self.display, root)
|
|
||||||
};
|
|
||||||
|
|
||||||
if resources.is_null() {
|
|
||||||
panic!("[winit] `XRRGetScreenResources` returned NULL. That should only happen if the root window doesn't exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut available;
|
|
||||||
let mut has_primary = false;
|
|
||||||
|
|
||||||
let primary = (self.xrandr.XRRGetOutputPrimary)(self.display, root);
|
|
||||||
available = Vec::with_capacity((*resources).ncrtc as usize);
|
|
||||||
for crtc_index in 0..(*resources).ncrtc {
|
|
||||||
let crtc_id = *((*resources).crtcs.offset(crtc_index as isize));
|
|
||||||
let crtc = (self.xrandr.XRRGetCrtcInfo)(self.display, resources, crtc_id);
|
|
||||||
let is_active = (*crtc).width > 0 && (*crtc).height > 0 && (*crtc).noutput > 0;
|
|
||||||
if is_active {
|
|
||||||
let is_primary = *(*crtc).outputs.offset(0) == primary;
|
|
||||||
has_primary |= is_primary;
|
|
||||||
MonitorHandle::new(self, resources, crtc_id, crtc, is_primary)
|
|
||||||
.map(|monitor_id| available.push(monitor_id));
|
|
||||||
}
|
|
||||||
(self.xrandr.XRRFreeCrtcInfo)(crtc);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no monitors were detected as being primary, we just pick one ourselves!
|
|
||||||
if !has_primary {
|
|
||||||
if let Some(ref mut fallback) = available.first_mut() {
|
|
||||||
// Setting this here will come in handy if we ever add an `is_primary` method.
|
|
||||||
fallback.primary = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(self.xrandr.XRRFreeScreenResources)(resources);
|
|
||||||
available
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn available_monitors(&self) -> Vec<MonitorHandle> {
|
|
||||||
let mut monitors_lock = MONITORS.lock();
|
|
||||||
(*monitors_lock)
|
|
||||||
.as_ref()
|
|
||||||
.cloned()
|
|
||||||
.or_else(|| {
|
|
||||||
let monitors = Some(self.query_monitor_list());
|
|
||||||
if !DISABLE_MONITOR_LIST_CACHING {
|
|
||||||
(*monitors_lock) = monitors.clone();
|
|
||||||
}
|
|
||||||
monitors
|
|
||||||
})
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn primary_monitor(&self) -> MonitorHandle {
|
|
||||||
self.available_monitors()
|
|
||||||
.into_iter()
|
|
||||||
.find(|monitor| monitor.primary)
|
|
||||||
.unwrap_or_else(MonitorHandle::dummy)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn select_xrandr_input(&self, root: Window) -> Result<c_int, XError> {
|
|
||||||
let has_xrandr = unsafe {
|
|
||||||
let mut major = 0;
|
|
||||||
let mut minor = 0;
|
|
||||||
(self.xrandr.XRRQueryVersion)(self.display, &mut major, &mut minor)
|
|
||||||
};
|
|
||||||
assert!(
|
|
||||||
has_xrandr == True,
|
|
||||||
"[winit] XRandR extension not available."
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut event_offset = 0;
|
|
||||||
let mut error_offset = 0;
|
|
||||||
let status = unsafe {
|
|
||||||
(self.xrandr.XRRQueryExtension)(self.display, &mut event_offset, &mut error_offset)
|
|
||||||
};
|
|
||||||
|
|
||||||
if status != True {
|
|
||||||
self.check_errors()?;
|
|
||||||
unreachable!("[winit] `XRRQueryExtension` failed but no error was received.");
|
|
||||||
}
|
|
||||||
|
|
||||||
let mask = RRCrtcChangeNotifyMask | RROutputPropertyNotifyMask | RRScreenChangeNotifyMask;
|
|
||||||
unsafe { (self.xrandr.XRRSelectInput)(self.display, root, mask) };
|
|
||||||
|
|
||||||
Ok(event_offset)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user