forge
Explore
Log in

Don't you dare go Hollow

Restructure things and add tty backend

Browse files at this commit

396ab935859f4eb46b3cf7aa36e7b496b5898b72Ivan MolodetskikhParent: b8e79e9

14 changed files +1276 -374

Cargo.lockmodified+381 -1
@@ -2,6 +2,21 @@
2 # It is not intended for manual editing.2 # It is not intended for manual editing.
3 version = 33 version = 3
4 4
5+[[package]]
6+name = "addr2line"
7+version = "0.20.0"
8+source = "registry+https://github.com/rust-lang/crates.io-index"
9+checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3"
10+dependencies = [
11+ "gimli",
12+]
13+
14+[[package]]
15+name = "adler"
16+version = "1.0.2"
17+source = "registry+https://github.com/rust-lang/crates.io-index"
18+checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
19+
5 [[package]]20 [[package]]
6 name = "aho-corasick"21 name = "aho-corasick"
7 version = "1.0.2"22 version = "1.0.2"
@@ -35,6 +50,64 @@ version = "0.2.2"
35 source = "registry+https://github.com/rust-lang/crates.io-index"50 source = "registry+https://github.com/rust-lang/crates.io-index"
36 checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04"51 checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04"
37 52
53+[[package]]
54+name = "anstream"
55+version = "0.3.2"
56+source = "registry+https://github.com/rust-lang/crates.io-index"
57+checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163"
58+dependencies = [
59+ "anstyle",
60+ "anstyle-parse",
61+ "anstyle-query",
62+ "anstyle-wincon",
63+ "colorchoice",
64+ "is-terminal",
65+ "utf8parse",
66+]
67+
68+[[package]]
69+name = "anstyle"
70+version = "1.0.1"
71+source = "registry+https://github.com/rust-lang/crates.io-index"
72+checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd"
73+
74+[[package]]
75+name = "anstyle-parse"
76+version = "0.2.1"
77+source = "registry+https://github.com/rust-lang/crates.io-index"
78+checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333"
79+dependencies = [
80+ "utf8parse",
81+]
82+
83+[[package]]
84+name = "anstyle-query"
85+version = "1.0.0"
86+source = "registry+https://github.com/rust-lang/crates.io-index"
87+checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
88+dependencies = [
89+ "windows-sys 0.48.0",
90+]
91+
92+[[package]]
93+name = "anstyle-wincon"
94+version = "1.0.1"
95+source = "registry+https://github.com/rust-lang/crates.io-index"
96+checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188"
97+dependencies = [
98+ "anstyle",
99+ "windows-sys 0.48.0",
100+]
101+
102+[[package]]
103+name = "anyhow"
104+version = "1.0.72"
105+source = "registry+https://github.com/rust-lang/crates.io-index"
106+checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854"
107+dependencies = [
108+ "backtrace",
109+]
110+
38 [[package]]111 [[package]]
39 name = "appendlist"112 name = "appendlist"
40 version = "1.4.0"113 version = "1.4.0"
@@ -56,6 +129,21 @@ version = "1.1.0"
56 source = "registry+https://github.com/rust-lang/crates.io-index"129 source = "registry+https://github.com/rust-lang/crates.io-index"
57 checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"130 checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
58 131
132+[[package]]
133+name = "backtrace"
134+version = "0.3.68"
135+source = "registry+https://github.com/rust-lang/crates.io-index"
136+checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12"
137+dependencies = [
138+ "addr2line",
139+ "cc",
140+ "cfg-if",
141+ "libc",
142+ "miniz_oxide",
143+ "object",
144+ "rustc-demangle",
145+]
146+
59 [[package]]147 [[package]]
60 name = "bitflags"148 name = "bitflags"
61 version = "1.3.2"149 version = "1.3.2"
@@ -93,6 +181,26 @@ version = "3.13.0"
93 source = "registry+https://github.com/rust-lang/crates.io-index"181 source = "registry+https://github.com/rust-lang/crates.io-index"
94 checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"182 checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
95 183
184+[[package]]
185+name = "bytemuck"
186+version = "1.13.1"
187+source = "registry+https://github.com/rust-lang/crates.io-index"
188+checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea"
189+dependencies = [
190+ "bytemuck_derive",
191+]
192+
193+[[package]]
194+name = "bytemuck_derive"
195+version = "1.4.1"
196+source = "registry+https://github.com/rust-lang/crates.io-index"
197+checksum = "fdde5c9cd29ebd706ce1b35600920a33550e402fc998a2e53ad3b42c3c47a192"
198+dependencies = [
199+ "proc-macro2",
200+ "quote",
201+ "syn 2.0.28",
202+]
203+
96 [[package]]204 [[package]]
97 name = "calloop"205 name = "calloop"
98 version = "0.10.6"206 version = "0.10.6"
@@ -139,6 +247,53 @@ dependencies = [
139 "num-traits",247 "num-traits",
140 ]248 ]
141 249
250+[[package]]
251+name = "clap"
252+version = "4.3.21"
253+source = "registry+https://github.com/rust-lang/crates.io-index"
254+checksum = "c27cdf28c0f604ba3f512b0c9a409f8de8513e4816705deb0498b627e7c3a3fd"
255+dependencies = [
256+ "clap_builder",
257+ "clap_derive",
258+ "once_cell",
259+]
260+
261+[[package]]
262+name = "clap_builder"
263+version = "4.3.21"
264+source = "registry+https://github.com/rust-lang/crates.io-index"
265+checksum = "08a9f1ab5e9f01a9b81f202e8562eb9a10de70abf9eaeac1be465c28b75aa4aa"
266+dependencies = [
267+ "anstream",
268+ "anstyle",
269+ "clap_lex",
270+ "strsim",
271+]
272+
273+[[package]]
274+name = "clap_derive"
275+version = "4.3.12"
276+source = "registry+https://github.com/rust-lang/crates.io-index"
277+checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050"
278+dependencies = [
279+ "heck",
280+ "proc-macro2",
281+ "quote",
282+ "syn 2.0.28",
283+]
284+
285+[[package]]
286+name = "clap_lex"
287+version = "0.5.0"
288+source = "registry+https://github.com/rust-lang/crates.io-index"
289+checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
290+
291+[[package]]
292+name = "colorchoice"
293+version = "1.0.0"
294+source = "registry+https://github.com/rust-lang/crates.io-index"
295+checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
296+
142 [[package]]297 [[package]]
143 name = "core-foundation"298 name = "core-foundation"
144 version = "0.9.3"299 version = "0.9.3"
@@ -200,18 +355,67 @@ version = "1.2.0"
200 source = "registry+https://github.com/rust-lang/crates.io-index"355 source = "registry+https://github.com/rust-lang/crates.io-index"
201 checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"356 checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
202 357
358+[[package]]
359+name = "drm"
360+version = "0.9.0"
361+source = "registry+https://github.com/rust-lang/crates.io-index"
362+checksum = "edf9159ef4bcecd0c5e4cbeb573b8d0037493403d542780dba5d840bbf9df56f"
363+dependencies = [
364+ "bitflags 1.3.2",
365+ "bytemuck",
366+ "drm-ffi",
367+ "drm-fourcc",
368+ "nix 0.26.2",
369+]
370+
371+[[package]]
372+name = "drm-ffi"
373+version = "0.5.0"
374+source = "registry+https://github.com/rust-lang/crates.io-index"
375+checksum = "1352481b7b90e27a8a1bf8ef6b33cf18b98dba7c410e75c24bb3eef2f0d8d525"
376+dependencies = [
377+ "drm-sys",
378+ "nix 0.26.2",
379+]
380+
203 [[package]]381 [[package]]
204 name = "drm-fourcc"382 name = "drm-fourcc"
205 version = "2.2.0"383 version = "2.2.0"
206 source = "registry+https://github.com/rust-lang/crates.io-index"384 source = "registry+https://github.com/rust-lang/crates.io-index"
207 checksum = "0aafbcdb8afc29c1a7ee5fbe53b5d62f4565b35a042a662ca9fecd0b54dae6f4"385 checksum = "0aafbcdb8afc29c1a7ee5fbe53b5d62f4565b35a042a662ca9fecd0b54dae6f4"
208 386
387+[[package]]
388+name = "drm-sys"
389+version = "0.4.0"
390+source = "registry+https://github.com/rust-lang/crates.io-index"
391+checksum = "1369f1679d6b706d234c4c1e0613c415c2c74b598a09ad28080ba2474b72e42d"
392+dependencies = [
393+ "libc",
394+]
395+
396+[[package]]
397+name = "edid-rs"
398+version = "0.1.0"
399+source = "registry+https://github.com/rust-lang/crates.io-index"
400+checksum = "2ab5fa33485cd85ac354df485819a63360fefa312fe04cffe65e6f175be1522c"
401+
209 [[package]]402 [[package]]
210 name = "equivalent"403 name = "equivalent"
211 version = "1.0.1"404 version = "1.0.1"
212 source = "registry+https://github.com/rust-lang/crates.io-index"405 source = "registry+https://github.com/rust-lang/crates.io-index"
213 checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"406 checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
214 407
408+[[package]]
409+name = "errno"
410+version = "0.2.8"
411+source = "registry+https://github.com/rust-lang/crates.io-index"
412+checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
413+dependencies = [
414+ "errno-dragonfly",
415+ "libc",
416+ "winapi",
417+]
418+
215 [[package]]419 [[package]]
216 name = "errno"420 name = "errno"
217 version = "0.3.2"421 version = "0.3.2"
@@ -254,6 +458,30 @@ version = "0.1.1"
254 source = "registry+https://github.com/rust-lang/crates.io-index"458 source = "registry+https://github.com/rust-lang/crates.io-index"
255 checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"459 checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
256 460
461+[[package]]
462+name = "gbm"
463+version = "0.12.0"
464+source = "registry+https://github.com/rust-lang/crates.io-index"
465+checksum = "f2ec389cda876966cf824111bf6e533fb934c711d473498279964a990853b3c6"
466+dependencies = [
467+ "bitflags 1.3.2",
468+ "drm",
469+ "drm-fourcc",
470+ "gbm-sys",
471+ "libc",
472+ "wayland-backend",
473+ "wayland-server",
474+]
475+
476+[[package]]
477+name = "gbm-sys"
478+version = "0.2.2"
479+source = "registry+https://github.com/rust-lang/crates.io-index"
480+checksum = "b63eba9b9b7a231514482deb08759301c9f9f049ac6869403f381834ebfeaf67"
481+dependencies = [
482+ "libc",
483+]
484+
257 [[package]]485 [[package]]
258 name = "getrandom"486 name = "getrandom"
259 version = "0.2.10"487 version = "0.2.10"
@@ -265,6 +493,12 @@ dependencies = [
265 "wasi",493 "wasi",
266 ]494 ]
267 495
496+[[package]]
497+name = "gimli"
498+version = "0.27.3"
499+source = "registry+https://github.com/rust-lang/crates.io-index"
500+checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e"
501+
268 [[package]]502 [[package]]
269 name = "gl_generator"503 name = "gl_generator"
270 version = "0.14.0"504 version = "0.14.0"
@@ -288,6 +522,12 @@ version = "0.14.0"
288 source = "registry+https://github.com/rust-lang/crates.io-index"522 source = "registry+https://github.com/rust-lang/crates.io-index"
289 checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"523 checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
290 524
525+[[package]]
526+name = "heck"
527+version = "0.4.1"
528+source = "registry+https://github.com/rust-lang/crates.io-index"
529+checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
530+
291 [[package]]531 [[package]]
292 name = "hermit-abi"532 name = "hermit-abi"
293 version = "0.3.2"533 version = "0.3.2"
@@ -314,6 +554,28 @@ dependencies = [
314 "hashbrown 0.14.0",554 "hashbrown 0.14.0",
315 ]555 ]
316 556
557+[[package]]
558+name = "input"
559+version = "0.8.3"
560+source = "registry+https://github.com/rust-lang/crates.io-index"
561+checksum = "e6e74cd82cedcd66db78742a8337bdc48f188c4d2c12742cbc5cd85113f0b059"
562+dependencies = [
563+ "bitflags 1.3.2",
564+ "input-sys",
565+ "io-lifetimes",
566+ "libc",
567+ "udev",
568+]
569+
570+[[package]]
571+name = "input-sys"
572+version = "1.17.0"
573+source = "registry+https://github.com/rust-lang/crates.io-index"
574+checksum = "05f6c2a17e8aba7217660e32863af87b0febad811d4b8620ef76b386603fddc2"
575+dependencies = [
576+ "libc",
577+]
578+
317 [[package]]579 [[package]]
318 name = "instant"580 name = "instant"
319 version = "0.1.12"581 version = "0.1.12"
@@ -337,6 +599,17 @@ dependencies = [
337 "windows-sys 0.48.0",599 "windows-sys 0.48.0",
338 ]600 ]
339 601
602+[[package]]
603+name = "is-terminal"
604+version = "0.4.9"
605+source = "registry+https://github.com/rust-lang/crates.io-index"
606+checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b"
607+dependencies = [
608+ "hermit-abi",
609+ "rustix",
610+ "windows-sys 0.48.0",
611+]
612+
340 [[package]]613 [[package]]
341 name = "jni-sys"614 name = "jni-sys"
342 version = "0.3.0"615 version = "0.3.0"
@@ -389,6 +662,36 @@ dependencies = [
389 "windows-sys 0.48.0",662 "windows-sys 0.48.0",
390 ]663 ]
391 664
665+[[package]]
666+name = "libseat"
667+version = "0.1.7"
668+source = "registry+https://github.com/rust-lang/crates.io-index"
669+checksum = "845e5c255462c9bc7c71c17b996766b76e3c66f2ddd5846bfbc83f18382aa648"
670+dependencies = [
671+ "errno 0.2.8",
672+ "libseat-sys",
673+ "slog",
674+]
675+
676+[[package]]
677+name = "libseat-sys"
678+version = "0.1.7"
679+source = "registry+https://github.com/rust-lang/crates.io-index"
680+checksum = "3671cb5e03871f1d6bf0b3b5daa9275549e348fa6359e0f9adb910ca163d4c34"
681+dependencies = [
682+ "pkg-config",
683+]
684+
685+[[package]]
686+name = "libudev-sys"
687+version = "0.1.4"
688+source = "registry+https://github.com/rust-lang/crates.io-index"
689+checksum = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324"
690+dependencies = [
691+ "libc",
692+ "pkg-config",
693+]
694+
392 [[package]]695 [[package]]
393 name = "linux-raw-sys"696 name = "linux-raw-sys"
394 version = "0.4.5"697 version = "0.4.5"
@@ -458,6 +761,15 @@ version = "0.2.1"
458 source = "registry+https://github.com/rust-lang/crates.io-index"761 source = "registry+https://github.com/rust-lang/crates.io-index"
459 checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"762 checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
460 763
764+[[package]]
765+name = "miniz_oxide"
766+version = "0.7.1"
767+source = "registry+https://github.com/rust-lang/crates.io-index"
768+checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"
769+dependencies = [
770+ "adler",
771+]
772+
461 [[package]]773 [[package]]
462 name = "mio"774 name = "mio"
463 version = "0.8.8"775 version = "0.8.8"
@@ -503,8 +815,12 @@ dependencies = [
503 name = "niri"815 name = "niri"
504 version = "0.1.0"816 version = "0.1.0"
505 dependencies = [817 dependencies = [
818+ "anyhow",
506 "bitflags 2.3.3",819 "bitflags 2.3.3",
820+ "clap",
507 "smithay",821 "smithay",
822+ "smithay-drm-extras",
823+ "tracing",
508 "tracing-subscriber",824 "tracing-subscriber",
509 ]825 ]
510 826
@@ -644,6 +960,15 @@ dependencies = [
644 "objc-sys",960 "objc-sys",
645 ]961 ]
646 962
963+[[package]]
964+name = "object"
965+version = "0.31.1"
966+source = "registry+https://github.com/rust-lang/crates.io-index"
967+checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1"
968+dependencies = [
969+ "memchr",
970+]
971+
647 [[package]]972 [[package]]
648 name = "once_cell"973 name = "once_cell"
649 version = "1.18.0"974 version = "1.18.0"
@@ -840,6 +1165,12 @@ version = "0.7.4"
840 source = "registry+https://github.com/rust-lang/crates.io-index"1165 source = "registry+https://github.com/rust-lang/crates.io-index"
841 checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2"1166 checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2"
842 1167
1168+[[package]]
1169+name = "rustc-demangle"
1170+version = "0.1.23"
1171+source = "registry+https://github.com/rust-lang/crates.io-index"
1172+checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
1173+
843 [[package]]1174 [[package]]
844 name = "rustix"1175 name = "rustix"
845 version = "0.38.7"1176 version = "0.38.7"
@@ -847,7 +1178,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
847 checksum = "172891ebdceb05aa0005f533a6cbfca599ddd7d966f6f5d4d9b2e70478e70399"1178 checksum = "172891ebdceb05aa0005f533a6cbfca599ddd7d966f6f5d4d9b2e70478e70399"
848 dependencies = [1179 dependencies = [
849 "bitflags 2.3.3",1180 "bitflags 2.3.3",
850- "errno",1181+ "errno 0.3.2",
851 "libc",1182 "libc",
852 "linux-raw-sys",1183 "linux-raw-sys",
853 "windows-sys 0.48.0",1184 "windows-sys 0.48.0",
@@ -874,6 +1205,12 @@ dependencies = [
874 "lazy_static",1205 "lazy_static",
875 ]1206 ]
876 1207
1208+[[package]]
1209+name = "slog"
1210+version = "2.7.0"
1211+source = "registry+https://github.com/rust-lang/crates.io-index"
1212+checksum = "8347046d4ebd943127157b94d63abb990fcf729dc4e9978927fdf4ac3c998d06"
1213+
877 [[package]]1214 [[package]]
878 name = "slotmap"1215 name = "slotmap"
879 version = "1.0.6"1216 version = "1.0.6"
@@ -897,27 +1234,37 @@ dependencies = [
897 "appendlist",1234 "appendlist",
898 "bitflags 2.3.3",1235 "bitflags 2.3.3",
899 "calloop",1236 "calloop",
1237+ "cc",
900 "cgmath",1238 "cgmath",
901 "downcast-rs",1239 "downcast-rs",
1240+ "drm",
1241+ "drm-ffi",
902 "drm-fourcc",1242 "drm-fourcc",
1243+ "gbm",
903 "gl_generator",1244 "gl_generator",
904 "indexmap 1.9.3",1245 "indexmap 1.9.3",
1246+ "input",
905 "lazy_static",1247 "lazy_static",
906 "libc",1248 "libc",
907 "libloading",1249 "libloading",
1250+ "libseat",
908 "nix 0.26.2",1251 "nix 0.26.2",
909 "once_cell",1252 "once_cell",
1253+ "pkg-config",
910 "profiling",1254 "profiling",
911 "rand",1255 "rand",
912 "scan_fmt",1256 "scan_fmt",
913 "tempfile",1257 "tempfile",
914 "thiserror",1258 "thiserror",
915 "tracing",1259 "tracing",
1260+ "udev",
1261+ "wayland-backend",
916 "wayland-egl",1262 "wayland-egl",
917 "wayland-protocols 0.30.1",1263 "wayland-protocols 0.30.1",
918 "wayland-protocols-misc",1264 "wayland-protocols-misc",
919 "wayland-protocols-wlr",1265 "wayland-protocols-wlr",
920 "wayland-server",1266 "wayland-server",
1267+ "wayland-sys 0.30.1",
921 "winit",1268 "winit",
922 "xkbcommon",1269 "xkbcommon",
923 ]1270 ]
@@ -941,12 +1288,26 @@ dependencies = [
941 "wayland-protocols 0.29.5",1288 "wayland-protocols 0.29.5",
942 ]1289 ]
943 1290
1291+[[package]]
1292+name = "smithay-drm-extras"
1293+version = "0.1.0"
1294+dependencies = [
1295+ "drm",
1296+ "edid-rs",
1297+]
1298+
944 [[package]]1299 [[package]]
945 name = "static_assertions"1300 name = "static_assertions"
946 version = "1.1.0"1301 version = "1.1.0"
947 source = "registry+https://github.com/rust-lang/crates.io-index"1302 source = "registry+https://github.com/rust-lang/crates.io-index"
948 checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"1303 checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
949 1304
1305+[[package]]
1306+name = "strsim"
1307+version = "0.10.0"
1308+source = "registry+https://github.com/rust-lang/crates.io-index"
1309+checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
1310+
950 [[package]]1311 [[package]]
951 name = "syn"1312 name = "syn"
952 version = "1.0.109"1313 version = "1.0.109"
@@ -1091,12 +1452,29 @@ dependencies = [
1091 "tracing-log",1452 "tracing-log",
1092 ]1453 ]
1093 1454
1455+[[package]]
1456+name = "udev"
1457+version = "0.7.0"
1458+source = "registry+https://github.com/rust-lang/crates.io-index"
1459+checksum = "4ebdbbd670373442a12fe9ef7aeb53aec4147a5a27a00bbc3ab639f08f48191a"
1460+dependencies = [
1461+ "libc",
1462+ "libudev-sys",
1463+ "pkg-config",
1464+]
1465+
1094 [[package]]1466 [[package]]
1095 name = "unicode-ident"1467 name = "unicode-ident"
1096 version = "1.0.11"1468 version = "1.0.11"
1097 source = "registry+https://github.com/rust-lang/crates.io-index"1469 source = "registry+https://github.com/rust-lang/crates.io-index"
1098 checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"1470 checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
1099 1471
1472+[[package]]
1473+name = "utf8parse"
1474+version = "0.2.1"
1475+source = "registry+https://github.com/rust-lang/crates.io-index"
1476+checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
1477+
1100 [[package]]1478 [[package]]
1101 name = "valuable"1479 name = "valuable"
1102 version = "0.1.0"1480 version = "0.1.0"
@@ -1343,7 +1721,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1343 checksum = "96b2a02ac608e07132978689a6f9bf4214949c85998c247abadd4f4129b1aa06"1721 checksum = "96b2a02ac608e07132978689a6f9bf4214949c85998c247abadd4f4129b1aa06"
1344 dependencies = [1722 dependencies = [
1345 "dlib",1723 "dlib",
1724+ "libc",
1346 "log",1725 "log",
1726+ "memoffset 0.7.1",
1347 "pkg-config",1727 "pkg-config",
1348 ]1728 ]
1349 1729
Cargo.tomlmodified+19 -4
@@ -1,18 +1,33 @@
1 [package]1 [package]
2 name = "niri"2 name = "niri"
3 version = "0.1.0"3 version = "0.1.0"
4-edition = "2021"4+description = "A Wayland compositor"
5+authors = ["Ivan Molodetskikh <yalterz@gmail.com>"]
5 license = "GPL-3.0-or-later"6 license = "GPL-3.0-or-later"
7+edition = "2021"
6 8
7 [dependencies]9 [dependencies]
8-tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }10+anyhow = { version = "1.0.72", features = ["backtrace"] }
9-bitflags = "2.2.1"11+bitflags = "2.3.3"
12+clap = { version = "4.3.21", features = ["derive"] }
13+smithay-drm-extras = { version = "0.1.0", path = "../smithay/smithay-drm-extras" }
14+tracing = "0.1.37"
15+tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
10 16
11 [dependencies.smithay]17 [dependencies.smithay]
12 git = "https://github.com/Smithay/smithay"18 git = "https://github.com/Smithay/smithay"
13 default-features = false19 default-features = false
14 features = [20 features = [
21+ "backend_drm",
22+ "backend_egl",
23+ "backend_gbm",
24+ "backend_libinput",
25+ "backend_session_libseat",
26+ "backend_udev",
15 "backend_winit",27 "backend_winit",
16- "wayland_frontend",
17 "desktop",28 "desktop",
29+ "renderer_gl",
30+ "renderer_multi",
31+ "use_system_lib",
32+ "wayland_frontend",
18 ]33 ]
src/backend.rsadded+15 -0
@@ -0,0 +1,15 @@
1+use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
2+use smithay::backend::renderer::gles::GlesRenderer;
3+use smithay::desktop::space::SpaceRenderElements;
4+
5+use crate::Niri;
6+
7+pub trait Backend {
8+ fn seat_name(&self) -> String;
9+ fn renderer(&mut self) -> &mut GlesRenderer;
10+ fn render(
11+ &mut self,
12+ niri: &mut Niri,
13+ elements: &[SpaceRenderElements<GlesRenderer, WaylandSurfaceRenderElement<GlesRenderer>>],
14+ );
15+}
src/grabs/move_grab.rsmodified+12 -12
@@ -6,19 +6,19 @@ use smithay::input::pointer::{
6 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;6 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
7 use smithay::utils::{Logical, Point};7 use smithay::utils::{Logical, Point};
8 8
9-use crate::Smallvil;9+use crate::Niri;
10 10
11 pub struct MoveSurfaceGrab {11 pub struct MoveSurfaceGrab {
12- pub start_data: PointerGrabStartData<Smallvil>,12+ pub start_data: PointerGrabStartData<Niri>,
13 pub window: Window,13 pub window: Window,
14 pub initial_window_location: Point<i32, Logical>,14 pub initial_window_location: Point<i32, Logical>,
15 }15 }
16 16
17-impl PointerGrab<Smallvil> for MoveSurfaceGrab {17+impl PointerGrab<Niri> for MoveSurfaceGrab {
18 fn motion(18 fn motion(
19 &mut self,19 &mut self,
20- data: &mut Smallvil,20+ data: &mut Niri,
21- handle: &mut PointerInnerHandle<'_, Smallvil>,21+ handle: &mut PointerInnerHandle<'_, Niri>,
22 _focus: Option<(WlSurface, Point<i32, Logical>)>,22 _focus: Option<(WlSurface, Point<i32, Logical>)>,
23 event: &MotionEvent,23 event: &MotionEvent,
24 ) {24 ) {
@@ -33,8 +33,8 @@ impl PointerGrab<Smallvil> for MoveSurfaceGrab {
33 33
34 fn relative_motion(34 fn relative_motion(
35 &mut self,35 &mut self,
36- data: &mut Smallvil,36+ data: &mut Niri,
37- handle: &mut PointerInnerHandle<'_, Smallvil>,37+ handle: &mut PointerInnerHandle<'_, Niri>,
38 focus: Option<(WlSurface, Point<i32, Logical>)>,38 focus: Option<(WlSurface, Point<i32, Logical>)>,
39 event: &RelativeMotionEvent,39 event: &RelativeMotionEvent,
40 ) {40 ) {
@@ -43,8 +43,8 @@ impl PointerGrab<Smallvil> for MoveSurfaceGrab {
43 43
44 fn button(44 fn button(
45 &mut self,45 &mut self,
46- data: &mut Smallvil,46+ data: &mut Niri,
47- handle: &mut PointerInnerHandle<'_, Smallvil>,47+ handle: &mut PointerInnerHandle<'_, Niri>,
48 event: &ButtonEvent,48 event: &ButtonEvent,
49 ) {49 ) {
50 handle.button(data, event);50 handle.button(data, event);
@@ -61,14 +61,14 @@ impl PointerGrab<Smallvil> for MoveSurfaceGrab {
61 61
62 fn axis(62 fn axis(
63 &mut self,63 &mut self,
64- data: &mut Smallvil,64+ data: &mut Niri,
65- handle: &mut PointerInnerHandle<'_, Smallvil>,65+ handle: &mut PointerInnerHandle<'_, Niri>,
66 details: AxisFrame,66 details: AxisFrame,
67 ) {67 ) {
68 handle.axis(data, details)68 handle.axis(data, details)
69 }69 }
70 70
71- fn start_data(&self) -> &PointerGrabStartData<Smallvil> {71+ fn start_data(&self) -> &PointerGrabStartData<Niri> {
72 &self.start_data72 &self.start_data
73 }73 }
74 }74 }
src/grabs/resize_grab.rsmodified+13 -13
@@ -11,7 +11,7 @@ use smithay::utils::{Logical, Point, Rectangle, Size};
11 use smithay::wayland::compositor;11 use smithay::wayland::compositor;
12 use smithay::wayland::shell::xdg::SurfaceCachedState;12 use smithay::wayland::shell::xdg::SurfaceCachedState;
13 13
14-use crate::Smallvil;14+use crate::Niri;
15 15
16 bitflags::bitflags! {16 bitflags::bitflags! {
17 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]17 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@@ -37,7 +37,7 @@ impl From<xdg_toplevel::ResizeEdge> for ResizeEdge {
37 }37 }
38 38
39 pub struct ResizeSurfaceGrab {39 pub struct ResizeSurfaceGrab {
40- start_data: PointerGrabStartData<Smallvil>,40+ start_data: PointerGrabStartData<Niri>,
41 window: Window,41 window: Window,
42 42
43 edges: ResizeEdge,43 edges: ResizeEdge,
@@ -48,7 +48,7 @@ pub struct ResizeSurfaceGrab {
48 48
49 impl ResizeSurfaceGrab {49 impl ResizeSurfaceGrab {
50 pub fn start(50 pub fn start(
51- start_data: PointerGrabStartData<Smallvil>,51+ start_data: PointerGrabStartData<Niri>,
52 window: Window,52 window: Window,
53 edges: ResizeEdge,53 edges: ResizeEdge,
54 initial_window_rect: Rectangle<i32, Logical>,54 initial_window_rect: Rectangle<i32, Logical>,
@@ -72,11 +72,11 @@ impl ResizeSurfaceGrab {
72 }72 }
73 }73 }
74 74
75-impl PointerGrab<Smallvil> for ResizeSurfaceGrab {75+impl PointerGrab<Niri> for ResizeSurfaceGrab {
76 fn motion(76 fn motion(
77 &mut self,77 &mut self,
78- data: &mut Smallvil,78+ data: &mut Niri,
79- handle: &mut PointerInnerHandle<'_, Smallvil>,79+ handle: &mut PointerInnerHandle<'_, Niri>,
80 _focus: Option<(WlSurface, Point<i32, Logical>)>,80 _focus: Option<(WlSurface, Point<i32, Logical>)>,
81 event: &MotionEvent,81 event: &MotionEvent,
82 ) {82 ) {
@@ -132,8 +132,8 @@ impl PointerGrab<Smallvil> for ResizeSurfaceGrab {
132 132
133 fn relative_motion(133 fn relative_motion(
134 &mut self,134 &mut self,
135- data: &mut Smallvil,135+ data: &mut Niri,
136- handle: &mut PointerInnerHandle<'_, Smallvil>,136+ handle: &mut PointerInnerHandle<'_, Niri>,
137 focus: Option<(WlSurface, Point<i32, Logical>)>,137 focus: Option<(WlSurface, Point<i32, Logical>)>,
138 event: &RelativeMotionEvent,138 event: &RelativeMotionEvent,
139 ) {139 ) {
@@ -142,8 +142,8 @@ impl PointerGrab<Smallvil> for ResizeSurfaceGrab {
142 142
143 fn button(143 fn button(
144 &mut self,144 &mut self,
145- data: &mut Smallvil,145+ data: &mut Niri,
146- handle: &mut PointerInnerHandle<'_, Smallvil>,146+ handle: &mut PointerInnerHandle<'_, Niri>,
147 event: &ButtonEvent,147 event: &ButtonEvent,
148 ) {148 ) {
149 handle.button(data, event);149 handle.button(data, event);
@@ -175,14 +175,14 @@ impl PointerGrab<Smallvil> for ResizeSurfaceGrab {
175 175
176 fn axis(176 fn axis(
177 &mut self,177 &mut self,
178- data: &mut Smallvil,178+ data: &mut Niri,
179- handle: &mut PointerInnerHandle<'_, Smallvil>,179+ handle: &mut PointerInnerHandle<'_, Niri>,
180 details: AxisFrame,180 details: AxisFrame,
181 ) {181 ) {
182 handle.axis(data, details)182 handle.axis(data, details)
183 }183 }
184 184
185- fn start_data(&self) -> &PointerGrabStartData<Smallvil> {185+ fn start_data(&self) -> &PointerGrabStartData<Niri> {
186 &self.start_data186 &self.start_data
187 }187 }
188 }188 }
src/handlers/compositor.rsmodified+7 -7
@@ -11,10 +11,10 @@ use smithay::{delegate_compositor, delegate_shm};
11 11
12 use super::xdg_shell;12 use super::xdg_shell;
13 use crate::grabs::resize_grab;13 use crate::grabs::resize_grab;
14-use crate::state::ClientState;14+use crate::niri::ClientState;
15-use crate::Smallvil;15+use crate::Niri;
16 16
17-impl CompositorHandler for Smallvil {17+impl CompositorHandler for Niri {
18 fn compositor_state(&mut self) -> &mut CompositorState {18 fn compositor_state(&mut self) -> &mut CompositorState {
19 &mut self.compositor_state19 &mut self.compositor_state
20 }20 }
@@ -44,15 +44,15 @@ impl CompositorHandler for Smallvil {
44 }44 }
45 }45 }
46 46
47-impl BufferHandler for Smallvil {47+impl BufferHandler for Niri {
48 fn buffer_destroyed(&mut self, _buffer: &wl_buffer::WlBuffer) {}48 fn buffer_destroyed(&mut self, _buffer: &wl_buffer::WlBuffer) {}
49 }49 }
50 50
51-impl ShmHandler for Smallvil {51+impl ShmHandler for Niri {
52 fn shm_state(&self) -> &ShmState {52 fn shm_state(&self) -> &ShmState {
53 &self.shm_state53 &self.shm_state
54 }54 }
55 }55 }
56 56
57-delegate_compositor!(Smallvil);57+delegate_compositor!(Niri);
58-delegate_shm!(Smallvil);58+delegate_shm!(Niri);
src/handlers/mod.rsmodified+9 -9
@@ -10,13 +10,13 @@ use smithay::wayland::data_device::{
10 };10 };
11 use smithay::{delegate_data_device, delegate_output, delegate_seat};11 use smithay::{delegate_data_device, delegate_output, delegate_seat};
12 12
13-use crate::Smallvil;13+use crate::Niri;
14 14
15-impl SeatHandler for Smallvil {15+impl SeatHandler for Niri {
16 type KeyboardFocus = WlSurface;16 type KeyboardFocus = WlSurface;
17 type PointerFocus = WlSurface;17 type PointerFocus = WlSurface;
18 18
19- fn seat_state(&mut self) -> &mut SeatState<Smallvil> {19+ fn seat_state(&mut self) -> &mut SeatState<Niri> {
20 &mut self.seat_state20 &mut self.seat_state
21 }21 }
22 22
@@ -29,26 +29,26 @@ impl SeatHandler for Smallvil {
29 fn focus_changed(&mut self, _seat: &smithay::input::Seat<Self>, _focused: Option<&WlSurface>) {}29 fn focus_changed(&mut self, _seat: &smithay::input::Seat<Self>, _focused: Option<&WlSurface>) {}
30 }30 }
31 31
32-delegate_seat!(Smallvil);32+delegate_seat!(Niri);
33 33
34 //34 //
35 // Wl Data Device35 // Wl Data Device
36 //36 //
37 37
38-impl DataDeviceHandler for Smallvil {38+impl DataDeviceHandler for Niri {
39 type SelectionUserData = ();39 type SelectionUserData = ();
40 fn data_device_state(&self) -> &smithay::wayland::data_device::DataDeviceState {40 fn data_device_state(&self) -> &smithay::wayland::data_device::DataDeviceState {
41 &self.data_device_state41 &self.data_device_state
42 }42 }
43 }43 }
44 44
45-impl ClientDndGrabHandler for Smallvil {}45+impl ClientDndGrabHandler for Niri {}
46-impl ServerDndGrabHandler for Smallvil {}46+impl ServerDndGrabHandler for Niri {}
47 47
48-delegate_data_device!(Smallvil);48+delegate_data_device!(Niri);
49 49
50 //50 //
51 // Wl Output & Xdg Output51 // Wl Output & Xdg Output
52 //52 //
53 53
54-delegate_output!(Smallvil);54+delegate_output!(Niri);
src/handlers/xdg_shell.rsmodified+5 -5
@@ -14,9 +14,9 @@ use smithay::wayland::shell::xdg::{
14 };14 };
15 15
16 use crate::grabs::{MoveSurfaceGrab, ResizeSurfaceGrab};16 use crate::grabs::{MoveSurfaceGrab, ResizeSurfaceGrab};
17-use crate::Smallvil;17+use crate::Niri;
18 18
19-impl XdgShellHandler for Smallvil {19+impl XdgShellHandler for Niri {
20 fn xdg_shell_state(&mut self) -> &mut XdgShellState {20 fn xdg_shell_state(&mut self) -> &mut XdgShellState {
21 &mut self.xdg_shell_state21 &mut self.xdg_shell_state
22 }22 }
@@ -102,13 +102,13 @@ impl XdgShellHandler for Smallvil {
102 }102 }
103 103
104 // Xdg Shell104 // Xdg Shell
105-delegate_xdg_shell!(Smallvil);105+delegate_xdg_shell!(Niri);
106 106
107 fn check_grab(107 fn check_grab(
108- seat: &Seat<Smallvil>,108+ seat: &Seat<Niri>,
109 surface: &WlSurface,109 surface: &WlSurface,
110 serial: Serial,110 serial: Serial,
111-) -> Option<PointerGrabStartData<Smallvil>> {111+) -> Option<PointerGrabStartData<Niri>> {
112 let pointer = seat.get_pointer()?;112 let pointer = seat.get_pointer()?;
113 113
114 // Check that this surface has a click grab.114 // Check that this surface has a click grab.
src/input.rsmodified+29 -5
@@ -2,28 +2,52 @@ use smithay::backend::input::{
2 AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent,2 AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent,
3 KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent,3 KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent,
4 };4 };
5-use smithay::input::keyboard::FilterResult;5+use smithay::input::keyboard::{keysyms, FilterResult};
6 use smithay::input::pointer::{AxisFrame, ButtonEvent, MotionEvent};6 use smithay::input::pointer::{AxisFrame, ButtonEvent, MotionEvent};
7 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;7 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
8 use smithay::utils::SERIAL_COUNTER;8 use smithay::utils::SERIAL_COUNTER;
9 9
10-use crate::state::Smallvil;10+use crate::niri::Niri;
11 11
12-impl Smallvil {12+enum InputAction {
13+ Quit,
14+ ChangeVt(i32),
15+}
16+
17+impl Niri {
13 pub fn process_input_event<I: InputBackend>(&mut self, event: InputEvent<I>) {18 pub fn process_input_event<I: InputBackend>(&mut self, event: InputEvent<I>) {
19+ trace!("process_input_event");
20+
14 match event {21 match event {
15 InputEvent::Keyboard { event, .. } => {22 InputEvent::Keyboard { event, .. } => {
16 let serial = SERIAL_COUNTER.next_serial();23 let serial = SERIAL_COUNTER.next_serial();
17 let time = Event::time_msec(&event);24 let time = Event::time_msec(&event);
18 25
19- self.seat.get_keyboard().unwrap().input::<(), _>(26+ let action = self.seat.get_keyboard().unwrap().input(
20 self,27 self,
21 event.key_code(),28 event.key_code(),
22 event.state(),29 event.state(),
23 serial,30 serial,
24 time,31 time,
25- |_, _, _| FilterResult::Forward,32+ |_, _, keysym| match keysym.modified_sym() {
33+ keysyms::KEY_Escape => FilterResult::Intercept(InputAction::Quit),
34+ keysym @ keysyms::KEY_XF86Switch_VT_1..=keysyms::KEY_XF86Switch_VT_12 => {
35+ let vt = (keysym - keysyms::KEY_XF86Switch_VT_1 + 1) as i32;
36+ FilterResult::Intercept(InputAction::ChangeVt(vt))
37+ }
38+ _ => FilterResult::Forward,
39+ },
26 );40 );
41+
42+ if let Some(action) = action {
43+ match action {
44+ InputAction::Quit => {
45+ info!("quitting because Esc was pressed");
46+ self.stop_signal.stop()
47+ }
48+ InputAction::ChangeVt(vt) => todo!(),
49+ }
50+ }
27 }51 }
28 InputEvent::PointerMotion { .. } => {}52 InputEvent::PointerMotion { .. } => {}
29 InputEvent::PointerMotionAbsolute { event, .. } => {53 InputEvent::PointerMotionAbsolute { event, .. } => {
src/main.rsmodified+89 -34
@@ -1,54 +1,109 @@
1+#[macro_use]
2+extern crate tracing;
3+
1 mod handlers;4 mod handlers;
2 5
6+mod backend;
3 mod grabs;7 mod grabs;
4 mod input;8 mod input;
5-mod state;9+mod niri;
10+mod tty;
6 mod winit;11 mod winit;
7 12
13+use std::env;
14+use std::ffi::OsString;
15+
16+use backend::Backend;
17+use clap::Parser;
18+use niri::Niri;
8 use smithay::reexports::calloop::EventLoop;19 use smithay::reexports::calloop::EventLoop;
9-use smithay::reexports::wayland_server::Display;20+use smithay::reexports::wayland_server::{Display, DisplayHandle};
10-pub use state::Smallvil;21+use tracing_subscriber::EnvFilter;
22+use tty::Tty;
23+use winit::Winit;
11 24
12-pub struct CalloopData {25+#[derive(Parser)]
13- state: Smallvil,26+#[command(author, version, about, long_about = None)]
14- display: Display<Smallvil>,27+struct Cli {
28+ #[arg(last = true)]
29+ command: Option<OsString>,
15 }30 }
16 31
17-fn main() -> Result<(), Box<dyn std::error::Error>> {32+pub struct LoopData {
18- if let Ok(env_filter) = tracing_subscriber::EnvFilter::try_from_default_env() {33+ niri: Niri,
19- tracing_subscriber::fmt()34+ display_handle: DisplayHandle,
20- .compact()
21- .with_env_filter(env_filter)
22- .init();
23- } else {
24- tracing_subscriber::fmt().compact().init();
25- }
26 35
27- let mut event_loop: EventLoop<CalloopData> = EventLoop::try_new()?;36+ // Last so that it's dropped after the Smithay state in Niri.
37+ display: Display<Niri>,
28 38
29- let mut display: Display<Smallvil> = Display::new()?;39+ tty: Option<Tty>,
30- let state = Smallvil::new(&event_loop, &mut display);40+ winit: Option<Winit>,
41+}
42+
43+fn main() {
44+ env::set_var("RUST_BACKTRACE", "1");
31 45
32- let mut data = CalloopData { state, display };46+ let directives = env::var("RUST_LOG").unwrap_or_else(|_| "niri=debug,info".to_owned());
47+ let env_filter = EnvFilter::builder().parse_lossy(directives);
48+ tracing_subscriber::fmt()
49+ .compact()
50+ .with_env_filter(env_filter)
51+ .init();
33 52
34- crate::winit::init_winit(&event_loop, &mut data)?;53+ let cli = Cli::parse();
35 54
36- let mut args = std::env::args().skip(1);55+ let mut event_loop = EventLoop::try_new().unwrap();
37- let flag = args.next();
38- let arg = args.next();
39 56
40- match (flag.as_deref(), arg) {57+ let has_display = env::var_os("WAYLAND_DISPLAY").is_some() || env::var_os("DISPLAY").is_some();
41- (Some("-c") | Some("--command"), Some(command)) => {58+
42- std::process::Command::new(command).spawn().ok();59+ let mut winit = None;
43- }60+ let mut tty = None;
44- _ => {61+ let backend: &mut dyn Backend = if has_display {
45- std::process::Command::new("weston-terminal").spawn().ok();62+ winit = Some(Winit::new(event_loop.handle()));
46- }63+ winit.as_mut().unwrap()
64+ } else {
65+ tty = Some(Tty::new(event_loop.handle()));
66+ tty.as_mut().unwrap()
67+ };
68+
69+ let mut display = Display::new().unwrap();
70+ let display_handle = display.handle();
71+ let niri = Niri::new(
72+ event_loop.handle(),
73+ event_loop.get_signal(),
74+ &mut display,
75+ backend.seat_name(),
76+ );
77+
78+ let mut data = LoopData {
79+ niri,
80+ display_handle,
81+ display,
82+
83+ tty,
84+ winit,
85+ };
86+
87+ if let Some(tty) = data.tty.as_mut() {
88+ tty.init(&mut data.niri);
89+ }
90+ if let Some(winit) = data.winit.as_mut() {
91+ winit.init(&mut data.niri);
47 }92 }
48 93
49- event_loop.run(None, &mut data, move |_| {94+ let res = if let Some(command) = &cli.command {
50- // Smallvil is running95+ std::process::Command::new(command).spawn()
51- })?;96+ } else {
97+ std::process::Command::new("weston-terminal").spawn()
98+ };
99+ if let Err(err) = res {
100+ warn!("error spawning command: {err}");
101+ }
52 102
53- Ok(())103+ event_loop
104+ .run(None, &mut data, move |data| {
105+ // niri is running.
106+ data.display.flush_clients().unwrap();
107+ })
108+ .unwrap();
54 }109 }
src/niri.rsadded+168 -0
@@ -0,0 +1,168 @@
1+use std::os::unix::io::AsRawFd;
2+use std::sync::Arc;
3+use std::time::Duration;
4+
5+use smithay::desktop::space::space_render_elements;
6+use smithay::desktop::{Space, Window, WindowSurfaceType};
7+use smithay::input::keyboard::XkbConfig;
8+use smithay::input::pointer::PointerHandle;
9+use smithay::input::{Seat, SeatState};
10+use smithay::output::Output;
11+use smithay::reexports::calloop::generic::Generic;
12+use smithay::reexports::calloop::{Interest, LoopHandle, LoopSignal, Mode, PostAction};
13+use smithay::reexports::wayland_server::backend::{ClientData, ClientId, DisconnectReason};
14+use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
15+use smithay::reexports::wayland_server::{Display, DisplayHandle};
16+use smithay::utils::{Logical, Point};
17+use smithay::wayland::compositor::{CompositorClientState, CompositorState};
18+use smithay::wayland::data_device::DataDeviceState;
19+use smithay::wayland::output::OutputManagerState;
20+use smithay::wayland::shell::xdg::XdgShellState;
21+use smithay::wayland::shm::ShmState;
22+use smithay::wayland::socket::ListeningSocketSource;
23+
24+use crate::backend::Backend;
25+use crate::LoopData;
26+
27+pub struct Niri {
28+ pub start_time: std::time::Instant,
29+ pub event_loop: LoopHandle<'static, LoopData>,
30+ pub stop_signal: LoopSignal,
31+ pub display_handle: DisplayHandle,
32+
33+ pub space: Space<Window>,
34+
35+ // Smithay state.
36+ pub compositor_state: CompositorState,
37+ pub xdg_shell_state: XdgShellState,
38+ pub shm_state: ShmState,
39+ pub output_manager_state: OutputManagerState,
40+ pub seat_state: SeatState<Self>,
41+ pub data_device_state: DataDeviceState,
42+
43+ pub seat: Seat<Self>,
44+ pub output: Option<Output>,
45+}
46+
47+impl Niri {
48+ pub fn new(
49+ event_loop: LoopHandle<'static, LoopData>,
50+ stop_signal: LoopSignal,
51+ display: &mut Display<Self>,
52+ seat_name: String,
53+ ) -> Self {
54+ let start_time = std::time::Instant::now();
55+
56+ let display_handle = display.handle();
57+
58+ let compositor_state = CompositorState::new::<Self>(&display_handle);
59+ let xdg_shell_state = XdgShellState::new::<Self>(&display_handle);
60+ let shm_state = ShmState::new::<Self>(&display_handle, vec![]);
61+ let output_manager_state = OutputManagerState::new_with_xdg_output::<Self>(&display_handle);
62+ let mut seat_state = SeatState::new();
63+ let data_device_state = DataDeviceState::new::<Self>(&display_handle);
64+
65+ let mut seat: Seat<Self> = seat_state.new_wl_seat(&display_handle, seat_name);
66+ // FIXME: get Xkb and repeat interval from GNOME dconf.
67+ seat.add_keyboard(XkbConfig::default(), 400, 30).unwrap();
68+ seat.add_pointer();
69+
70+ let space = Space::default();
71+
72+ let socket_source = ListeningSocketSource::new_auto().unwrap();
73+ let socket_name = socket_source.socket_name().to_os_string();
74+ event_loop
75+ .insert_source(socket_source, move |client, _, data| {
76+ if let Err(err) = data
77+ .display_handle
78+ .insert_client(client, Arc::new(ClientState::default()))
79+ {
80+ error!("error inserting client: {err}");
81+ }
82+ })
83+ .unwrap();
84+ std::env::set_var("WAYLAND_DISPLAY", &socket_name);
85+ info!(
86+ "listening on Wayland socket: {}",
87+ socket_name.to_string_lossy()
88+ );
89+
90+ let display_source = Generic::new(
91+ display.backend().poll_fd().as_raw_fd(),
92+ Interest::READ,
93+ Mode::Level,
94+ );
95+ event_loop
96+ .insert_source(display_source, |_, _, data| {
97+ data.display.dispatch_clients(&mut data.niri).unwrap();
98+ Ok(PostAction::Continue)
99+ })
100+ .unwrap();
101+
102+ Self {
103+ start_time,
104+ event_loop,
105+ stop_signal,
106+ display_handle,
107+
108+ space,
109+
110+ compositor_state,
111+ xdg_shell_state,
112+ shm_state,
113+ output_manager_state,
114+ seat_state,
115+ data_device_state,
116+
117+ seat,
118+ output: None,
119+ }
120+ }
121+
122+ pub fn surface_under_pointer(
123+ &self,
124+ pointer: &PointerHandle<Self>,
125+ ) -> Option<(WlSurface, Point<i32, Logical>)> {
126+ let pos = pointer.current_location();
127+ self.space
128+ .element_under(pos)
129+ .and_then(|(window, location)| {
130+ window
131+ .surface_under(pos - location.to_f64(), WindowSurfaceType::ALL)
132+ .map(|(s, p)| (s, p + location))
133+ })
134+ }
135+
136+ pub fn redraw(&mut self, backend: &mut dyn Backend) {
137+ let elements = space_render_elements(
138+ backend.renderer(),
139+ [&self.space],
140+ self.output.as_ref().unwrap(),
141+ 1.,
142+ )
143+ .unwrap();
144+ backend.render(self, &elements);
145+
146+ let output = self.output.as_ref().unwrap();
147+ self.space.elements().for_each(|window| {
148+ window.send_frame(
149+ output,
150+ self.start_time.elapsed(),
151+ Some(Duration::ZERO),
152+ |_, _| Some(output.clone()),
153+ )
154+ });
155+
156+ self.space.refresh();
157+ }
158+}
159+
160+#[derive(Default)]
161+pub struct ClientState {
162+ pub compositor_state: CompositorClientState,
163+}
164+
165+impl ClientData for ClientState {
166+ fn initialized(&self, _client_id: ClientId) {}
167+ fn disconnected(&self, _client_id: ClientId, _reason: DisconnectReason) {}
168+}
src/state.rsdeleted+0 -165
@@ -1,165 +0,0 @@
1-use std::ffi::OsString;
2-use std::os::unix::io::AsRawFd;
3-use std::sync::Arc;
4-
5-use smithay::desktop::{Space, Window, WindowSurfaceType};
6-use smithay::input::pointer::PointerHandle;
7-use smithay::input::{Seat, SeatState};
8-use smithay::reexports::calloop::generic::Generic;
9-use smithay::reexports::calloop::{EventLoop, Interest, LoopSignal, Mode, PostAction};
10-use smithay::reexports::wayland_server::backend::{ClientData, ClientId, DisconnectReason};
11-use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
12-use smithay::reexports::wayland_server::Display;
13-use smithay::utils::{Logical, Point};
14-use smithay::wayland::compositor::{CompositorClientState, CompositorState};
15-use smithay::wayland::data_device::DataDeviceState;
16-use smithay::wayland::output::OutputManagerState;
17-use smithay::wayland::shell::xdg::XdgShellState;
18-use smithay::wayland::shm::ShmState;
19-use smithay::wayland::socket::ListeningSocketSource;
20-
21-use crate::CalloopData;
22-
23-pub struct Smallvil {
24- pub start_time: std::time::Instant,
25- pub socket_name: OsString,
26-
27- pub space: Space<Window>,
28- pub loop_signal: LoopSignal,
29-
30- // Smithay State
31- pub compositor_state: CompositorState,
32- pub xdg_shell_state: XdgShellState,
33- pub shm_state: ShmState,
34- pub output_manager_state: OutputManagerState,
35- pub seat_state: SeatState<Smallvil>,
36- pub data_device_state: DataDeviceState,
37-
38- pub seat: Seat<Self>,
39-}
40-
41-impl Smallvil {
42- pub fn new(event_loop: &EventLoop<CalloopData>, display: &mut Display<Self>) -> Self {
43- let start_time = std::time::Instant::now();
44-
45- let dh = display.handle();
46-
47- let compositor_state = CompositorState::new::<Self>(&dh);
48- let xdg_shell_state = XdgShellState::new::<Self>(&dh);
49- let shm_state = ShmState::new::<Self>(&dh, vec![]);
50- let output_manager_state = OutputManagerState::new_with_xdg_output::<Self>(&dh);
51- let mut seat_state = SeatState::new();
52- let data_device_state = DataDeviceState::new::<Self>(&dh);
53-
54- // A seat is a group of keyboards, pointer and touch devices.
55- // A seat typically has a pointer and maintains a keyboard focus and a pointer focus.
56- let mut seat: Seat<Self> = seat_state.new_wl_seat(&dh, "winit");
57-
58- // Notify clients that we have a keyboard, for the sake of the example we assume that
59- // keyboard is always present. You may want to track keyboard hot-plug in real
60- // compositor.
61- seat.add_keyboard(Default::default(), 200, 200).unwrap();
62-
63- // Notify clients that we have a pointer (mouse)
64- // Here we assume that there is always pointer plugged in
65- seat.add_pointer();
66-
67- // A space represents a two-dimensional plane. Windows and Outputs can be mapped onto it.
68- //
69- // Windows get a position and stacking order through mapping.
70- // Outputs become views of a part of the Space and can be rendered via Space::render_output.
71- let space = Space::default();
72-
73- let socket_name = Self::init_wayland_listener(display, event_loop);
74-
75- // Get the loop signal, used to stop the event loop
76- let loop_signal = event_loop.get_signal();
77-
78- Self {
79- start_time,
80-
81- space,
82- loop_signal,
83- socket_name,
84-
85- compositor_state,
86- xdg_shell_state,
87- shm_state,
88- output_manager_state,
89- seat_state,
90- data_device_state,
91- seat,
92- }
93- }
94-
95- fn init_wayland_listener(
96- display: &mut Display<Smallvil>,
97- event_loop: &EventLoop<CalloopData>,
98- ) -> OsString {
99- // Creates a new listening socket, automatically choosing the next available `wayland`
100- // socket name.
101- let listening_socket = ListeningSocketSource::new_auto().unwrap();
102-
103- // Get the name of the listening socket.
104- // Clients will connect to this socket.
105- let socket_name = listening_socket.socket_name().to_os_string();
106-
107- let handle = event_loop.handle();
108-
109- event_loop
110- .handle()
111- .insert_source(listening_socket, move |client_stream, _, state| {
112- // Inside the callback, you should insert the client into the display.
113- //
114- // You may also associate some data with the client when inserting the client.
115- state
116- .display
117- .handle()
118- .insert_client(client_stream, Arc::new(ClientState::default()))
119- .unwrap();
120- })
121- .expect("Failed to init the wayland event source.");
122-
123- // You also need to add the display itself to the event loop, so that client events will be
124- // processed by wayland-server.
125- handle
126- .insert_source(
127- Generic::new(
128- display.backend().poll_fd().as_raw_fd(),
129- Interest::READ,
130- Mode::Level,
131- ),
132- |_, _, state| {
133- state.display.dispatch_clients(&mut state.state).unwrap();
134- Ok(PostAction::Continue)
135- },
136- )
137- .unwrap();
138-
139- socket_name
140- }
141-
142- pub fn surface_under_pointer(
143- &self,
144- pointer: &PointerHandle<Self>,
145- ) -> Option<(WlSurface, Point<i32, Logical>)> {
146- let pos = pointer.current_location();
147- self.space
148- .element_under(pos)
149- .and_then(|(window, location)| {
150- window
151- .surface_under(pos - location.to_f64(), WindowSurfaceType::ALL)
152- .map(|(s, p)| (s, p + location))
153- })
154- }
155-}
156-
157-#[derive(Default)]
158-pub struct ClientState {
159- pub compositor_state: CompositorClientState,
160-}
161-
162-impl ClientData for ClientState {
163- fn initialized(&self, _client_id: ClientId) {}
164- fn disconnected(&self, _client_id: ClientId, _reason: DisconnectReason) {}
165-}
src/tty.rsadded+423 -0
@@ -0,0 +1,423 @@
1+use std::os::fd::FromRawFd;
2+use std::path::PathBuf;
3+use std::time::Duration;
4+
5+use anyhow::anyhow;
6+use smithay::backend::allocator::dmabuf::Dmabuf;
7+use smithay::backend::allocator::gbm::{GbmAllocator, GbmBufferFlags, GbmDevice};
8+use smithay::backend::allocator::Fourcc;
9+use smithay::backend::drm::compositor::DrmCompositor;
10+use smithay::backend::drm::{DrmDevice, DrmDeviceFd, DrmEvent};
11+use smithay::backend::egl::{EGLContext, EGLDisplay};
12+use smithay::backend::libinput::{LibinputInputBackend, LibinputSessionInterface};
13+use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
14+use smithay::backend::renderer::gles::{GlesRenderbuffer, GlesRenderer};
15+use smithay::backend::renderer::{Bind, ImportEgl};
16+use smithay::backend::session::libseat::LibSeatSession;
17+use smithay::backend::session::{Event as SessionEvent, Session};
18+use smithay::backend::udev::{self, UdevBackend, UdevEvent};
19+use smithay::desktop::space::SpaceRenderElements;
20+use smithay::output::{Mode, Output, OutputModeSource, PhysicalProperties, Subpixel};
21+use smithay::reexports::calloop::timer::{TimeoutAction, Timer};
22+use smithay::reexports::calloop::{LoopHandle, RegistrationToken};
23+use smithay::reexports::drm::control::connector::{
24+ Interface as ConnectorInterface, State as ConnectorState,
25+};
26+use smithay::reexports::drm::control::{Device, ModeTypeFlags};
27+use smithay::reexports::input::Libinput;
28+use smithay::reexports::nix::fcntl::OFlag;
29+use smithay::reexports::nix::libc::dev_t;
30+use smithay::utils::DeviceFd;
31+use smithay_drm_extras::edid::EdidInfo;
32+
33+use crate::backend::Backend;
34+use crate::{LoopData, Niri};
35+
36+const SUPPORTED_COLOR_FORMATS: &[Fourcc] = &[Fourcc::Argb8888, Fourcc::Abgr8888];
37+
38+pub struct Tty {
39+ session: LibSeatSession,
40+ primary_gpu_path: PathBuf,
41+ output_device: Option<OutputDevice>,
42+}
43+
44+type GbmDrmCompositor =
45+ DrmCompositor<GbmAllocator<DrmDeviceFd>, GbmDevice<DrmDeviceFd>, (), DrmDeviceFd>;
46+
47+struct OutputDevice {
48+ id: dev_t,
49+ path: PathBuf,
50+ token: RegistrationToken,
51+ drm: DrmDevice,
52+ gles: GlesRenderer,
53+ drm_compositor: GbmDrmCompositor,
54+}
55+
56+impl Backend for Tty {
57+ fn seat_name(&self) -> String {
58+ self.session.seat()
59+ }
60+
61+ fn renderer(&mut self) -> &mut GlesRenderer {
62+ &mut self.output_device.as_mut().unwrap().gles
63+ }
64+
65+ fn render(
66+ &mut self,
67+ niri: &mut Niri,
68+ elements: &[SpaceRenderElements<GlesRenderer, WaylandSurfaceRenderElement<GlesRenderer>>],
69+ ) {
70+ let output_device = self.output_device.as_mut().unwrap();
71+ let res = output_device
72+ .drm_compositor
73+ .render_frame::<_, _, GlesRenderbuffer>(
74+ &mut output_device.gles,
75+ elements,
76+ [0.1, 0.1, 0.1, 1.],
77+ )
78+ .unwrap();
79+ assert!(!res.needs_sync());
80+ if res.damage.is_some() {
81+ output_device.drm_compositor.queue_frame(()).unwrap();
82+ } else {
83+ niri.event_loop
84+ .insert_source(
85+ Timer::from_duration(Duration::from_millis(6)),
86+ |_, _, data| {
87+ data.niri.redraw(data.tty.as_mut().unwrap());
88+ TimeoutAction::Drop
89+ },
90+ )
91+ .unwrap();
92+ }
93+ }
94+}
95+
96+impl Tty {
97+ pub fn new(event_loop: LoopHandle<LoopData>) -> Self {
98+ let (session, notifier) = LibSeatSession::new().unwrap();
99+ let seat_name = session.seat();
100+
101+ let mut libinput = Libinput::new_with_udev(LibinputSessionInterface::from(session.clone()));
102+ libinput.udev_assign_seat(&seat_name).unwrap();
103+
104+ let input_backend = LibinputInputBackend::new(libinput.clone());
105+ event_loop
106+ .insert_source(input_backend, |event, _, data| {
107+ data.niri.process_input_event(event)
108+ })
109+ .unwrap();
110+
111+ event_loop
112+ .insert_source(notifier, move |event, _, data| {
113+ let tty = data.tty.as_mut().unwrap();
114+ let niri = &mut data.niri;
115+
116+ match event {
117+ SessionEvent::PauseSession => {
118+ libinput.suspend();
119+
120+ if let Some(output_device) = &tty.output_device {
121+ output_device.drm.pause();
122+ }
123+ }
124+ SessionEvent::ActivateSession => {
125+ if libinput.resume().is_err() {
126+ error!("error resuming libinput");
127+ }
128+
129+ if let Some(output_device) = &tty.output_device {
130+ // FIXME: according to Catacomb, resetting DRM+Compositor is preferrable
131+ // here, but currently not possible due to a bug somewhere.
132+ tty.device_changed(output_device.id, niri);
133+ }
134+
135+ niri.redraw(tty);
136+ }
137+ }
138+ })
139+ .unwrap();
140+
141+ let primary_gpu_path = udev::primary_gpu(&seat_name).unwrap().unwrap();
142+
143+ Self {
144+ session,
145+ primary_gpu_path,
146+ output_device: None,
147+ }
148+ }
149+
150+ pub fn init(&mut self, niri: &mut Niri) {
151+ let backend = UdevBackend::new(&self.session.seat()).unwrap();
152+ for (device_id, path) in backend.device_list() {
153+ if let Err(err) = self.device_added(device_id, path.to_owned(), niri) {
154+ warn!("error adding device: {err:?}");
155+ }
156+ }
157+
158+ niri.event_loop
159+ .insert_source(backend, move |event, _, data| {
160+ let tty = data.tty.as_mut().unwrap();
161+ let niri = &mut data.niri;
162+
163+ match event {
164+ UdevEvent::Added { device_id, path } => {
165+ if let Err(err) = tty.device_added(device_id, path, niri) {
166+ warn!("error adding device: {err:?}");
167+ }
168+ niri.redraw(tty);
169+ }
170+ UdevEvent::Changed { device_id } => tty.device_changed(device_id, niri),
171+ UdevEvent::Removed { device_id } => tty.device_removed(device_id, niri),
172+ }
173+ })
174+ .unwrap();
175+
176+ niri.redraw(self);
177+ }
178+
179+ fn device_added(
180+ &mut self,
181+ device_id: dev_t,
182+ path: PathBuf,
183+ niri: &mut Niri,
184+ ) -> anyhow::Result<()> {
185+ if path != self.primary_gpu_path {
186+ debug!("skipping non-primary device {path:?}");
187+ return Ok(());
188+ }
189+
190+ debug!("adding device {path:?}");
191+ assert!(self.output_device.is_none());
192+
193+ let open_flags = OFlag::O_RDWR | OFlag::O_CLOEXEC | OFlag::O_NOCTTY | OFlag::O_NONBLOCK;
194+ let fd = self.session.open(&path, open_flags)?;
195+ let device_fd = unsafe { DrmDeviceFd::new(DeviceFd::from_raw_fd(fd)) };
196+
197+ let (drm, drm_notifier) = DrmDevice::new(device_fd.clone(), true)?;
198+ let gbm = GbmDevice::new(device_fd)?;
199+
200+ let display = EGLDisplay::new(gbm.clone())?;
201+ let egl_context = EGLContext::new(&display)?;
202+
203+ let mut gles = unsafe { GlesRenderer::new(egl_context)? };
204+ gles.bind_wl_display(&niri.display_handle)?;
205+
206+ let drm_compositor = self.create_drm_compositor(&drm, &gbm, &gles, niri)?;
207+
208+ let token = niri
209+ .event_loop
210+ .insert_source(drm_notifier, move |event, metadata, data| {
211+ let tty = data.tty.as_mut().unwrap();
212+ match event {
213+ DrmEvent::VBlank(_crtc) => {
214+ info!("vblank {metadata:?}");
215+
216+ let output_device = tty.output_device.as_mut().unwrap();
217+
218+ // Mark the last frame as submitted.
219+ if let Err(err) = output_device.drm_compositor.frame_submitted() {
220+ error!("error marking frame as submitted: {err}");
221+ }
222+
223+ // Send presentation time feedback.
224+ // catacomb
225+ // .windows
226+ // .mark_presented(&output_device.last_render_states, metadata);
227+
228+ // Request redraw before the next VBlank.
229+ // let frame_interval = catacomb.windows.output().frame_interval();
230+ // let duration = frame_interval - RENDER_TIME_OFFSET;
231+ // catacomb.backend.schedule_redraw(duration);
232+ data.niri.redraw(tty);
233+ }
234+ DrmEvent::Error(error) => error!("DRM error: {error}"),
235+ };
236+ })
237+ .unwrap();
238+
239+ self.output_device = Some(OutputDevice {
240+ id: device_id,
241+ path,
242+ token,
243+ drm,
244+ gles,
245+ drm_compositor,
246+ });
247+
248+ Ok(())
249+ }
250+
251+ fn device_changed(&mut self, device_id: dev_t, niri: &mut Niri) {
252+ if let Some(output_device) = &self.output_device {
253+ if output_device.id == device_id {
254+ debug!("output device changed");
255+
256+ let path = output_device.path.clone();
257+ self.device_removed(device_id, niri);
258+ if let Err(err) = self.device_added(device_id, path, niri) {
259+ warn!("error adding device: {err:?}");
260+ }
261+ }
262+ }
263+ }
264+
265+ fn device_removed(&mut self, device_id: dev_t, niri: &mut Niri) {
266+ if let Some(mut output_device) = self.output_device.take() {
267+ if output_device.id != device_id {
268+ self.output_device = Some(output_device);
269+ return;
270+ }
271+
272+ // FIXME: remove wl_output.
273+ niri.event_loop.remove(output_device.token);
274+ niri.output = None;
275+ output_device.gles.unbind_wl_display();
276+ }
277+ }
278+
279+ fn create_drm_compositor(
280+ &mut self,
281+ drm: &DrmDevice,
282+ gbm: &GbmDevice<DrmDeviceFd>,
283+ gles: &GlesRenderer,
284+ niri: &mut Niri,
285+ ) -> anyhow::Result<GbmDrmCompositor> {
286+ let formats = Bind::<Dmabuf>::supported_formats(gles)
287+ .ok_or_else(|| anyhow!("no supported formats"))?;
288+ let resources = drm.resource_handles()?;
289+
290+ let mut connector = None;
291+ resources
292+ .connectors()
293+ .iter()
294+ .filter_map(|conn| match drm.get_connector(*conn, true) {
295+ Ok(info) => Some(info),
296+ Err(err) => {
297+ warn!("error probing connector: {err}");
298+ None
299+ }
300+ })
301+ .inspect(|conn| {
302+ debug!(
303+ "connector: {}-{}, {:?}, {} modes",
304+ conn.interface().as_str(),
305+ conn.interface_id(),
306+ conn.state(),
307+ conn.modes().len(),
308+ );
309+ })
310+ .filter(|conn| conn.state() == ConnectorState::Connected)
311+ // FIXME: don't hardcode eDP.
312+ .filter(|conn| conn.interface() == ConnectorInterface::EmbeddedDisplayPort)
313+ .for_each(|conn| connector = Some(conn));
314+ let connector = connector.ok_or_else(|| anyhow!("no compatible connector"))?;
315+ info!(
316+ "picking connector: {}-{}",
317+ connector.interface().as_str(),
318+ connector.interface_id(),
319+ );
320+
321+ let mut mode = connector.modes().get(0);
322+ connector.modes().iter().for_each(|m| {
323+ debug!("mode: {m:?}");
324+
325+ if m.mode_type().contains(ModeTypeFlags::PREFERRED) {
326+ // Pick the highest refresh rate.
327+ if mode
328+ .map(|curr| curr.vrefresh() < m.vrefresh())
329+ .unwrap_or(true)
330+ {
331+ mode = Some(m);
332+ }
333+ }
334+ });
335+ let mode = mode.ok_or_else(|| anyhow!("no mode"))?;
336+ info!("picking mode: {mode:?}");
337+
338+ let surface = connector
339+ .encoders()
340+ .iter()
341+ .filter_map(|enc| match drm.get_encoder(*enc) {
342+ Ok(info) => Some(info),
343+ Err(err) => {
344+ warn!("error probing encoder: {err}");
345+ None
346+ }
347+ })
348+ .flat_map(|enc| {
349+ // Get all CRTCs compatible with the encoder.
350+ let mut crtcs = resources.filter_crtcs(enc.possible_crtcs());
351+
352+ // Sort by maximum number of overlay planes.
353+ crtcs.sort_by_cached_key(|crtc| match drm.planes(crtc) {
354+ Ok(planes) => -(planes.overlay.len() as isize),
355+ Err(err) => {
356+ warn!("error probing planes for CRTC: {err}");
357+ 0
358+ }
359+ });
360+
361+ crtcs
362+ })
363+ .find_map(
364+ |crtc| match drm.create_surface(crtc, *mode, &[connector.handle()]) {
365+ Ok(surface) => Some(surface),
366+ Err(err) => {
367+ warn!("error creating DRM surface: {err}");
368+ None
369+ }
370+ },
371+ );
372+ let surface = surface.ok_or_else(|| anyhow!("no surface"))?;
373+
374+ // Create GBM allocator.
375+ let gbm_flags = GbmBufferFlags::RENDERING | GbmBufferFlags::SCANOUT;
376+ let allocator = GbmAllocator::new(gbm.clone(), gbm_flags);
377+
378+ // Update the output mode.
379+ let (physical_width, physical_height) = connector.size().unwrap_or((0, 0));
380+ let output_name = format!(
381+ "{}-{}",
382+ connector.interface().as_str(),
383+ connector.interface_id(),
384+ );
385+
386+ let (make, model) = EdidInfo::for_connector(drm, connector.handle())
387+ .map(|info| (info.manufacturer, info.model))
388+ .unwrap_or_else(|| ("Unknown".into(), "Unknown".into()));
389+
390+ let output = Output::new(
391+ output_name,
392+ PhysicalProperties {
393+ size: (physical_width as i32, physical_height as i32).into(),
394+ subpixel: Subpixel::Unknown,
395+ model,
396+ make,
397+ },
398+ );
399+ let wl_mode = Mode::from(*mode);
400+ output.change_current_state(Some(wl_mode), None, None, Some((0, 0).into()));
401+ output.set_preferred(wl_mode);
402+
403+ // FIXME: store this somewhere to remove on disconnect, etc.
404+ let _global = output.create_global::<Niri>(&niri.display_handle);
405+ niri.space.map_output(&output, (0, 0));
406+ niri.output = Some(output.clone());
407+ // windows.set_output();
408+
409+ // Create the compositor.
410+ let compositor = DrmCompositor::new(
411+ OutputModeSource::Auto(output),
412+ surface,
413+ None,
414+ allocator,
415+ gbm.clone(),
416+ SUPPORTED_COLOR_FORMATS,
417+ formats,
418+ drm.cursor_size(),
419+ Some(gbm.clone()),
420+ )?;
421+ Ok(compositor)
422+ }
423+}
src/winit.rsmodified+106 -119
@@ -4,137 +4,124 @@ use smithay::backend::renderer::damage::OutputDamageTracker;
4 use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;4 use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
5 use smithay::backend::renderer::gles::GlesRenderer;5 use smithay::backend::renderer::gles::GlesRenderer;
6 use smithay::backend::winit::{self, WinitError, WinitEvent, WinitEventLoop, WinitGraphicsBackend};6 use smithay::backend::winit::{self, WinitError, WinitEvent, WinitEventLoop, WinitGraphicsBackend};
7+use smithay::desktop::space::SpaceRenderElements;
7 use smithay::output::{Mode, Output, PhysicalProperties, Subpixel};8 use smithay::output::{Mode, Output, PhysicalProperties, Subpixel};
8 use smithay::reexports::calloop::timer::{TimeoutAction, Timer};9 use smithay::reexports::calloop::timer::{TimeoutAction, Timer};
9-use smithay::reexports::calloop::EventLoop;10+use smithay::reexports::calloop::LoopHandle;
10 use smithay::utils::{Rectangle, Transform};11 use smithay::utils::{Rectangle, Transform};
11 12
12-use crate::{CalloopData, Smallvil};13+use crate::backend::Backend;
13-14+use crate::{LoopData, Niri};
14-pub fn init_winit(
15- event_loop: &EventLoop<CalloopData>,
16- data: &mut CalloopData,
17-) -> Result<(), Box<dyn std::error::Error>> {
18- let display = &mut data.display;
19- let state = &mut data.state;
20-
21- let (mut backend, mut winit) = winit::init()?;
22-
23- let mode = Mode {
24- size: backend.window_size().physical_size,
25- refresh: 60_000,
26- };
27-
28- let output = Output::new(
29- "winit".to_string(),
30- PhysicalProperties {
31- size: (0, 0).into(),
32- subpixel: Subpixel::Unknown,
33- make: "Smithay".into(),
34- model: "Winit".into(),
35- },
36- );
37- let _global = output.create_global::<Smallvil>(&display.handle());
38- output.change_current_state(
39- Some(mode),
40- Some(Transform::Flipped180),
41- None,
42- Some((0, 0).into()),
43- );
44- output.set_preferred(mode);
45-
46- state.space.map_output(&output, (0, 0));
47-
48- let mut damage_tracker = OutputDamageTracker::from_output(&output);
49-
50- std::env::set_var("WAYLAND_DISPLAY", &state.socket_name);
51-
52- let mut full_redraw = 0u8;
53-
54- let timer = Timer::immediate();
55- event_loop
56- .handle()
57- .insert_source(timer, move |_, _, data| {
58- winit_dispatch(
59- &mut backend,
60- &mut winit,
61- data,
62- &output,
63- &mut damage_tracker,
64- &mut full_redraw,
65- )
66- .unwrap();
67- TimeoutAction::ToDuration(Duration::from_millis(16))
68- })?;
69 15
70- Ok(())16+pub struct Winit {
17+ output: Output,
18+ backend: WinitGraphicsBackend<GlesRenderer>,
19+ winit_event_loop: WinitEventLoop,
20+ damage_tracker: OutputDamageTracker,
71 }21 }
72 22
73-pub fn winit_dispatch(23+impl Backend for Winit {
74- backend: &mut WinitGraphicsBackend<GlesRenderer>,24+ fn seat_name(&self) -> String {
75- winit: &mut WinitEventLoop,25+ "winit".to_owned()
76- data: &mut CalloopData,26+ }
77- output: &Output,27+
78- damage_tracker: &mut OutputDamageTracker,28+ fn renderer(&mut self) -> &mut GlesRenderer {
79- full_redraw: &mut u8,29+ self.backend.renderer()
80-) -> Result<(), Box<dyn std::error::Error>> {30+ }
81- let display = &mut data.display;
82- let state = &mut data.state;
83-
84- let res = winit.dispatch_new_events(|event| match event {
85- WinitEvent::Resized { size, .. } => {
86- output.change_current_state(
87- Some(Mode {
88- size,
89- refresh: 60_000,
90- }),
91- None,
92- None,
93- None,
94- );
95- }
96- WinitEvent::Input(event) => state.process_input_event(event),
97- _ => (),
98- });
99 31
100- if let Err(WinitError::WindowClosed) = res {32+ fn render(
101- // Stop the loop33+ &mut self,
102- state.loop_signal.stop();34+ _niri: &mut Niri,
35+ elements: &[SpaceRenderElements<GlesRenderer, WaylandSurfaceRenderElement<GlesRenderer>>],
36+ ) {
37+ let size = self.backend.window_size().physical_size;
38+ let damage = Rectangle::from_loc_and_size((0, 0), size);
103 39
104- return Ok(());40+ self.damage_tracker
105- } else {41+ .render_output(self.backend.renderer(), 0, elements, [0.1, 0.1, 0.1, 1.0])
106- res?;42+ .unwrap();
43+ self.backend.submit(Some(&[damage])).unwrap();
107 }44 }
45+}
108 46
109- *full_redraw = full_redraw.saturating_sub(1);47+impl Winit {
110-48+ pub fn new(event_loop: LoopHandle<LoopData>) -> Self {
111- let size = backend.window_size().physical_size;49+ let (backend, winit_event_loop) = winit::init().unwrap();
112- let damage = Rectangle::from_loc_and_size((0, 0), size);50+
113-51+ let mode = Mode {
114- backend.bind()?;52+ size: backend.window_size().physical_size,
115- smithay::desktop::space::render_output::<_, WaylandSurfaceRenderElement<GlesRenderer>, _, _>(53+ refresh: 60_000,
116- output,54+ };
117- backend.renderer(),55+
118- 1.0,56+ let output = Output::new(
119- 0,57+ "winit".to_string(),
120- [&state.space],58+ PhysicalProperties {
121- &[],59+ size: (0, 0).into(),
122- damage_tracker,60+ subpixel: Subpixel::Unknown,
123- [0.1, 0.1, 0.1, 1.0],61+ make: "Smithay".into(),
124- )?;62+ model: "Winit".into(),
125- backend.submit(Some(&[damage]))?;63+ },
126-64+ );
127- state.space.elements().for_each(|window| {65+ output.change_current_state(
128- window.send_frame(66+ Some(mode),
67+ Some(Transform::Flipped180),
68+ None,
69+ Some((0, 0).into()),
70+ );
71+ output.set_preferred(mode);
72+
73+ let damage_tracker = OutputDamageTracker::from_output(&output);
74+
75+ let timer = Timer::immediate();
76+ event_loop
77+ .insert_source(timer, move |_, _, data| {
78+ let winit = data.winit.as_mut().unwrap();
79+ winit.dispatch(&mut data.niri);
80+ TimeoutAction::ToDuration(Duration::from_millis(16))
81+ })
82+ .unwrap();
83+
84+ Self {
129 output,85 output,
130- state.start_time.elapsed(),86+ backend,
131- Some(Duration::ZERO),87+ winit_event_loop,
132- |_, _| Some(output.clone()),88+ damage_tracker,
133- )89+ }
134- });90+ }
135 91
136- state.space.refresh();92+ pub fn init(&mut self, niri: &mut Niri) {
137- display.flush_clients()?;93+ let _global = self.output.create_global::<Niri>(&niri.display_handle);
94+ niri.space.map_output(&self.output, (0, 0));
95+ niri.output = Some(self.output.clone());
96+ }
138 97
139- Ok(())98+ fn dispatch(&mut self, niri: &mut Niri) {
99+ let res = self
100+ .winit_event_loop
101+ .dispatch_new_events(|event| match event {
102+ WinitEvent::Resized { size, .. } => {
103+ niri.output.as_ref().unwrap().change_current_state(
104+ Some(Mode {
105+ size,
106+ refresh: 60_000,
107+ }),
108+ None,
109+ None,
110+ None,
111+ );
112+ }
113+ WinitEvent::Input(event) => niri.process_input_event(event),
114+ _ => (),
115+ });
116+
117+ if let Err(WinitError::WindowClosed) = res {
118+ niri.stop_signal.stop();
119+ return;
120+ } else {
121+ res.unwrap();
122+ }
123+
124+ self.backend.bind().unwrap();
125+ niri.redraw(self);
126+ }
140 }127 }