diff options
| -rw-r--r-- | Cargo.lock | 382 | ||||
| -rw-r--r-- | Cargo.toml | 23 | ||||
| -rw-r--r-- | src/backend.rs | 15 | ||||
| -rw-r--r-- | src/grabs/move_grab.rs | 24 | ||||
| -rw-r--r-- | src/grabs/resize_grab.rs | 26 | ||||
| -rw-r--r-- | src/handlers/compositor.rs | 14 | ||||
| -rw-r--r-- | src/handlers/mod.rs | 18 | ||||
| -rw-r--r-- | src/handlers/xdg_shell.rs | 10 | ||||
| -rw-r--r-- | src/input.rs | 34 | ||||
| -rw-r--r-- | src/main.rs | 123 | ||||
| -rw-r--r-- | src/niri.rs | 168 | ||||
| -rw-r--r-- | src/state.rs | 165 | ||||
| -rw-r--r-- | src/tty.rs | 423 | ||||
| -rw-r--r-- | src/winit.rs | 225 |
14 files changed, 1276 insertions, 374 deletions
@@ -3,6 +3,21 @@ version = 3 [[package]] +name = "addr2line" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] name = "aho-corasick" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -36,6 +51,64 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" [[package]] +name = "anstream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +dependencies = [ + "anstyle", + "windows-sys 0.48.0", +] + +[[package]] +name = "anyhow" +version = "1.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b13c32d80ecc7ab747b80c3784bce54ee8a7a0cc4fbda9bf4cda2cf6fe90854" +dependencies = [ + "backtrace", +] + +[[package]] name = "appendlist" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -57,6 +130,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] +name = "backtrace" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -94,6 +182,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" [[package]] +name = "bytemuck" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdde5c9cd29ebd706ce1b35600920a33550e402fc998a2e53ad3b42c3c47a192" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.28", +] + +[[package]] name = "calloop" version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -140,6 +248,53 @@ dependencies = [ ] [[package]] +name = "clap" +version = "4.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c27cdf28c0f604ba3f512b0c9a409f8de8513e4816705deb0498b627e7c3a3fd" +dependencies = [ + "clap_builder", + "clap_derive", + "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08a9f1ab5e9f01a9b81f202e8562eb9a10de70abf9eaeac1be465c28b75aa4aa" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.28", +] + +[[package]] +name = "clap_lex" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] name = "core-foundation" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -201,12 +356,50 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] +name = "drm" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edf9159ef4bcecd0c5e4cbeb573b8d0037493403d542780dba5d840bbf9df56f" +dependencies = [ + "bitflags 1.3.2", + "bytemuck", + "drm-ffi", + "drm-fourcc", + "nix 0.26.2", +] + +[[package]] +name = "drm-ffi" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1352481b7b90e27a8a1bf8ef6b33cf18b98dba7c410e75c24bb3eef2f0d8d525" +dependencies = [ + "drm-sys", + "nix 0.26.2", +] + +[[package]] name = "drm-fourcc" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0aafbcdb8afc29c1a7ee5fbe53b5d62f4565b35a042a662ca9fecd0b54dae6f4" [[package]] +name = "drm-sys" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1369f1679d6b706d234c4c1e0613c415c2c74b598a09ad28080ba2474b72e42d" +dependencies = [ + "libc", +] + +[[package]] +name = "edid-rs" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab5fa33485cd85ac354df485819a63360fefa312fe04cffe65e6f175be1522c" + +[[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -214,6 +407,17 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" @@ -255,6 +459,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] +name = "gbm" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2ec389cda876966cf824111bf6e533fb934c711d473498279964a990853b3c6" +dependencies = [ + "bitflags 1.3.2", + "drm", + "drm-fourcc", + "gbm-sys", + "libc", + "wayland-backend", + "wayland-server", +] + +[[package]] +name = "gbm-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63eba9b9b7a231514482deb08759301c9f9f049ac6869403f381834ebfeaf67" +dependencies = [ + "libc", +] + +[[package]] name = "getrandom" version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -266,6 +494,12 @@ dependencies = [ ] [[package]] +name = "gimli" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" + +[[package]] name = "gl_generator" version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -289,6 +523,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" [[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] name = "hermit-abi" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -315,6 +555,28 @@ dependencies = [ ] [[package]] +name = "input" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e74cd82cedcd66db78742a8337bdc48f188c4d2c12742cbc5cd85113f0b059" +dependencies = [ + "bitflags 1.3.2", + "input-sys", + "io-lifetimes", + "libc", + "udev", +] + +[[package]] +name = "input-sys" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f6c2a17e8aba7217660e32863af87b0febad811d4b8620ef76b386603fddc2" +dependencies = [ + "libc", +] + +[[package]] name = "instant" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -338,6 +600,17 @@ dependencies = [ ] [[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys 0.48.0", +] + +[[package]] name = "jni-sys" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -390,6 +663,36 @@ dependencies = [ ] [[package]] +name = "libseat" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "845e5c255462c9bc7c71c17b996766b76e3c66f2ddd5846bfbc83f18382aa648" +dependencies = [ + "errno 0.2.8", + "libseat-sys", + "slog", +] + +[[package]] +name = "libseat-sys" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3671cb5e03871f1d6bf0b3b5daa9275549e348fa6359e0f9adb910ca163d4c34" +dependencies = [ + "pkg-config", +] + +[[package]] +name = "libudev-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324" +dependencies = [ + "libc", + "pkg-config", +] + +[[package]] name = "linux-raw-sys" version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -459,6 +762,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + +[[package]] name = "mio" version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -503,8 +815,12 @@ dependencies = [ name = "niri" version = "0.1.0" dependencies = [ + "anyhow", "bitflags 2.3.3", + "clap", "smithay", + "smithay-drm-extras", + "tracing", "tracing-subscriber", ] @@ -645,6 +961,15 @@ dependencies = [ ] [[package]] +name = "object" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +dependencies = [ + "memchr", +] + +[[package]] name = "once_cell" version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -841,13 +1166,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" [[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] name = "rustix" version = "0.38.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "172891ebdceb05aa0005f533a6cbfca599ddd7d966f6f5d4d9b2e70478e70399" dependencies = [ "bitflags 2.3.3", - "errno", + "errno 0.3.2", "libc", "linux-raw-sys", "windows-sys 0.48.0", @@ -875,6 +1206,12 @@ dependencies = [ ] [[package]] +name = "slog" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8347046d4ebd943127157b94d63abb990fcf729dc4e9978927fdf4ac3c998d06" + +[[package]] name = "slotmap" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -897,27 +1234,37 @@ dependencies = [ "appendlist", "bitflags 2.3.3", "calloop", + "cc", "cgmath", "downcast-rs", + "drm", + "drm-ffi", "drm-fourcc", + "gbm", "gl_generator", "indexmap 1.9.3", + "input", "lazy_static", "libc", "libloading", + "libseat", "nix 0.26.2", "once_cell", + "pkg-config", "profiling", "rand", "scan_fmt", "tempfile", "thiserror", "tracing", + "udev", + "wayland-backend", "wayland-egl", "wayland-protocols 0.30.1", "wayland-protocols-misc", "wayland-protocols-wlr", "wayland-server", + "wayland-sys 0.30.1", "winit", "xkbcommon", ] @@ -942,12 +1289,26 @@ dependencies = [ ] [[package]] +name = "smithay-drm-extras" +version = "0.1.0" +dependencies = [ + "drm", + "edid-rs", +] + +[[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] name = "syn" version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1092,12 +1453,29 @@ dependencies = [ ] [[package]] +name = "udev" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebdbbd670373442a12fe9ef7aeb53aec4147a5a27a00bbc3ab639f08f48191a" +dependencies = [ + "libc", + "libudev-sys", + "pkg-config", +] + +[[package]] name = "unicode-ident" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" [[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] name = "valuable" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1343,7 +1721,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96b2a02ac608e07132978689a6f9bf4214949c85998c247abadd4f4129b1aa06" dependencies = [ "dlib", + "libc", "log", + "memoffset 0.7.1", "pkg-config", ] @@ -1,18 +1,33 @@ [package] name = "niri" version = "0.1.0" -edition = "2021" +description = "A Wayland compositor" +authors = ["Ivan Molodetskikh <yalterz@gmail.com>"] license = "GPL-3.0-or-later" +edition = "2021" [dependencies] -tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } -bitflags = "2.2.1" +anyhow = { version = "1.0.72", features = ["backtrace"] } +bitflags = "2.3.3" +clap = { version = "4.3.21", features = ["derive"] } +smithay-drm-extras = { version = "0.1.0", path = "../smithay/smithay-drm-extras" } +tracing = "0.1.37" +tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } [dependencies.smithay] git = "https://github.com/Smithay/smithay" default-features = false features = [ + "backend_drm", + "backend_egl", + "backend_gbm", + "backend_libinput", + "backend_session_libseat", + "backend_udev", "backend_winit", - "wayland_frontend", "desktop", + "renderer_gl", + "renderer_multi", + "use_system_lib", + "wayland_frontend", ] diff --git a/src/backend.rs b/src/backend.rs new file mode 100644 index 00000000..e190ed05 --- /dev/null +++ b/src/backend.rs @@ -0,0 +1,15 @@ +use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement; +use smithay::backend::renderer::gles::GlesRenderer; +use smithay::desktop::space::SpaceRenderElements; + +use crate::Niri; + +pub trait Backend { + fn seat_name(&self) -> String; + fn renderer(&mut self) -> &mut GlesRenderer; + fn render( + &mut self, + niri: &mut Niri, + elements: &[SpaceRenderElements<GlesRenderer, WaylandSurfaceRenderElement<GlesRenderer>>], + ); +} diff --git a/src/grabs/move_grab.rs b/src/grabs/move_grab.rs index 63cdb3bd..699921d1 100644 --- a/src/grabs/move_grab.rs +++ b/src/grabs/move_grab.rs @@ -6,19 +6,19 @@ use smithay::input::pointer::{ use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::utils::{Logical, Point}; -use crate::Smallvil; +use crate::Niri; pub struct MoveSurfaceGrab { - pub start_data: PointerGrabStartData<Smallvil>, + pub start_data: PointerGrabStartData<Niri>, pub window: Window, pub initial_window_location: Point<i32, Logical>, } -impl PointerGrab<Smallvil> for MoveSurfaceGrab { +impl PointerGrab<Niri> for MoveSurfaceGrab { fn motion( &mut self, - data: &mut Smallvil, - handle: &mut PointerInnerHandle<'_, Smallvil>, + data: &mut Niri, + handle: &mut PointerInnerHandle<'_, Niri>, _focus: Option<(WlSurface, Point<i32, Logical>)>, event: &MotionEvent, ) { @@ -33,8 +33,8 @@ impl PointerGrab<Smallvil> for MoveSurfaceGrab { fn relative_motion( &mut self, - data: &mut Smallvil, - handle: &mut PointerInnerHandle<'_, Smallvil>, + data: &mut Niri, + handle: &mut PointerInnerHandle<'_, Niri>, focus: Option<(WlSurface, Point<i32, Logical>)>, event: &RelativeMotionEvent, ) { @@ -43,8 +43,8 @@ impl PointerGrab<Smallvil> for MoveSurfaceGrab { fn button( &mut self, - data: &mut Smallvil, - handle: &mut PointerInnerHandle<'_, Smallvil>, + data: &mut Niri, + handle: &mut PointerInnerHandle<'_, Niri>, event: &ButtonEvent, ) { handle.button(data, event); @@ -61,14 +61,14 @@ impl PointerGrab<Smallvil> for MoveSurfaceGrab { fn axis( &mut self, - data: &mut Smallvil, - handle: &mut PointerInnerHandle<'_, Smallvil>, + data: &mut Niri, + handle: &mut PointerInnerHandle<'_, Niri>, details: AxisFrame, ) { handle.axis(data, details) } - fn start_data(&self) -> &PointerGrabStartData<Smallvil> { + fn start_data(&self) -> &PointerGrabStartData<Niri> { &self.start_data } } diff --git a/src/grabs/resize_grab.rs b/src/grabs/resize_grab.rs index ee8aae5d..2bc2f194 100644 --- a/src/grabs/resize_grab.rs +++ b/src/grabs/resize_grab.rs @@ -11,7 +11,7 @@ use smithay::utils::{Logical, Point, Rectangle, Size}; use smithay::wayland::compositor; use smithay::wayland::shell::xdg::SurfaceCachedState; -use crate::Smallvil; +use crate::Niri; bitflags::bitflags! { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -37,7 +37,7 @@ impl From<xdg_toplevel::ResizeEdge> for ResizeEdge { } pub struct ResizeSurfaceGrab { - start_data: PointerGrabStartData<Smallvil>, + start_data: PointerGrabStartData<Niri>, window: Window, edges: ResizeEdge, @@ -48,7 +48,7 @@ pub struct ResizeSurfaceGrab { impl ResizeSurfaceGrab { pub fn start( - start_data: PointerGrabStartData<Smallvil>, + start_data: PointerGrabStartData<Niri>, window: Window, edges: ResizeEdge, initial_window_rect: Rectangle<i32, Logical>, @@ -72,11 +72,11 @@ impl ResizeSurfaceGrab { } } -impl PointerGrab<Smallvil> for ResizeSurfaceGrab { +impl PointerGrab<Niri> for ResizeSurfaceGrab { fn motion( &mut self, - data: &mut Smallvil, - handle: &mut PointerInnerHandle<'_, Smallvil>, + data: &mut Niri, + handle: &mut PointerInnerHandle<'_, Niri>, _focus: Option<(WlSurface, Point<i32, Logical>)>, event: &MotionEvent, ) { @@ -132,8 +132,8 @@ impl PointerGrab<Smallvil> for ResizeSurfaceGrab { fn relative_motion( &mut self, - data: &mut Smallvil, - handle: &mut PointerInnerHandle<'_, Smallvil>, + data: &mut Niri, + handle: &mut PointerInnerHandle<'_, Niri>, focus: Option<(WlSurface, Point<i32, Logical>)>, event: &RelativeMotionEvent, ) { @@ -142,8 +142,8 @@ impl PointerGrab<Smallvil> for ResizeSurfaceGrab { fn button( &mut self, - data: &mut Smallvil, - handle: &mut PointerInnerHandle<'_, Smallvil>, + data: &mut Niri, + handle: &mut PointerInnerHandle<'_, Niri>, event: &ButtonEvent, ) { handle.button(data, event); @@ -175,14 +175,14 @@ impl PointerGrab<Smallvil> for ResizeSurfaceGrab { fn axis( &mut self, - data: &mut Smallvil, - handle: &mut PointerInnerHandle<'_, Smallvil>, + data: &mut Niri, + handle: &mut PointerInnerHandle<'_, Niri>, details: AxisFrame, ) { handle.axis(data, details) } - fn start_data(&self) -> &PointerGrabStartData<Smallvil> { + fn start_data(&self) -> &PointerGrabStartData<Niri> { &self.start_data } } diff --git a/src/handlers/compositor.rs b/src/handlers/compositor.rs index 99041f34..b5f6291d 100644 --- a/src/handlers/compositor.rs +++ b/src/handlers/compositor.rs @@ -11,10 +11,10 @@ use smithay::{delegate_compositor, delegate_shm}; use super::xdg_shell; use crate::grabs::resize_grab; -use crate::state::ClientState; -use crate::Smallvil; +use crate::niri::ClientState; +use crate::Niri; -impl CompositorHandler for Smallvil { +impl CompositorHandler for Niri { fn compositor_state(&mut self) -> &mut CompositorState { &mut self.compositor_state } @@ -44,15 +44,15 @@ impl CompositorHandler for Smallvil { } } -impl BufferHandler for Smallvil { +impl BufferHandler for Niri { fn buffer_destroyed(&mut self, _buffer: &wl_buffer::WlBuffer) {} } -impl ShmHandler for Smallvil { +impl ShmHandler for Niri { fn shm_state(&self) -> &ShmState { &self.shm_state } } -delegate_compositor!(Smallvil); -delegate_shm!(Smallvil); +delegate_compositor!(Niri); +delegate_shm!(Niri); diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 58157b27..ab2a1596 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -10,13 +10,13 @@ use smithay::wayland::data_device::{ }; use smithay::{delegate_data_device, delegate_output, delegate_seat}; -use crate::Smallvil; +use crate::Niri; -impl SeatHandler for Smallvil { +impl SeatHandler for Niri { type KeyboardFocus = WlSurface; type PointerFocus = WlSurface; - fn seat_state(&mut self) -> &mut SeatState<Smallvil> { + fn seat_state(&mut self) -> &mut SeatState<Niri> { &mut self.seat_state } @@ -29,26 +29,26 @@ impl SeatHandler for Smallvil { fn focus_changed(&mut self, _seat: &smithay::input::Seat<Self>, _focused: Option<&WlSurface>) {} } -delegate_seat!(Smallvil); +delegate_seat!(Niri); // // Wl Data Device // -impl DataDeviceHandler for Smallvil { +impl DataDeviceHandler for Niri { type SelectionUserData = (); fn data_device_state(&self) -> &smithay::wayland::data_device::DataDeviceState { &self.data_device_state } } -impl ClientDndGrabHandler for Smallvil {} -impl ServerDndGrabHandler for Smallvil {} +impl ClientDndGrabHandler for Niri {} +impl ServerDndGrabHandler for Niri {} -delegate_data_device!(Smallvil); +delegate_data_device!(Niri); // // Wl Output & Xdg Output // -delegate_output!(Smallvil); +delegate_output!(Niri); diff --git a/src/handlers/xdg_shell.rs b/src/handlers/xdg_shell.rs index 3b7f53ff..e681d0ef 100644 --- a/src/handlers/xdg_shell.rs +++ b/src/handlers/xdg_shell.rs @@ -14,9 +14,9 @@ use smithay::wayland::shell::xdg::{ }; use crate::grabs::{MoveSurfaceGrab, ResizeSurfaceGrab}; -use crate::Smallvil; +use crate::Niri; -impl XdgShellHandler for Smallvil { +impl XdgShellHandler for Niri { fn xdg_shell_state(&mut self) -> &mut XdgShellState { &mut self.xdg_shell_state } @@ -102,13 +102,13 @@ impl XdgShellHandler for Smallvil { } // Xdg Shell -delegate_xdg_shell!(Smallvil); +delegate_xdg_shell!(Niri); fn check_grab( - seat: &Seat<Smallvil>, + seat: &Seat<Niri>, surface: &WlSurface, serial: Serial, -) -> Option<PointerGrabStartData<Smallvil>> { +) -> Option<PointerGrabStartData<Niri>> { let pointer = seat.get_pointer()?; // Check that this surface has a click grab. diff --git a/src/input.rs b/src/input.rs index 9fd894b5..9d167a0a 100644 --- a/src/input.rs +++ b/src/input.rs @@ -2,28 +2,52 @@ use smithay::backend::input::{ AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent, KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent, }; -use smithay::input::keyboard::FilterResult; +use smithay::input::keyboard::{keysyms, FilterResult}; use smithay::input::pointer::{AxisFrame, ButtonEvent, MotionEvent}; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::utils::SERIAL_COUNTER; -use crate::state::Smallvil; +use crate::niri::Niri; -impl Smallvil { +enum InputAction { + Quit, + ChangeVt(i32), +} + +impl Niri { pub fn process_input_event<I: InputBackend>(&mut self, event: InputEvent<I>) { + trace!("process_input_event"); + match event { InputEvent::Keyboard { event, .. } => { let serial = SERIAL_COUNTER.next_serial(); let time = Event::time_msec(&event); - self.seat.get_keyboard().unwrap().input::<(), _>( + let action = self.seat.get_keyboard().unwrap().input( self, event.key_code(), event.state(), serial, time, - |_, _, _| FilterResult::Forward, + |_, _, keysym| match keysym.modified_sym() { + keysyms::KEY_Escape => FilterResult::Intercept(InputAction::Quit), + keysym @ keysyms::KEY_XF86Switch_VT_1..=keysyms::KEY_XF86Switch_VT_12 => { + let vt = (keysym - keysyms::KEY_XF86Switch_VT_1 + 1) as i32; + FilterResult::Intercept(InputAction::ChangeVt(vt)) + } + _ => FilterResult::Forward, + }, ); + + if let Some(action) = action { + match action { + InputAction::Quit => { + info!("quitting because Esc was pressed"); + self.stop_signal.stop() + } + InputAction::ChangeVt(vt) => todo!(), + } + } } InputEvent::PointerMotion { .. } => {} InputEvent::PointerMotionAbsolute { event, .. } => { diff --git a/src/main.rs b/src/main.rs index 3e285536..7a977bd0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,54 +1,109 @@ +#[macro_use] +extern crate tracing; + mod handlers; +mod backend; mod grabs; mod input; -mod state; +mod niri; +mod tty; mod winit; +use std::env; +use std::ffi::OsString; + +use backend::Backend; +use clap::Parser; +use niri::Niri; use smithay::reexports::calloop::EventLoop; -use smithay::reexports::wayland_server::Display; -pub use state::Smallvil; +use smithay::reexports::wayland_server::{Display, DisplayHandle}; +use tracing_subscriber::EnvFilter; +use tty::Tty; +use winit::Winit; -pub struct CalloopData { - state: Smallvil, - display: Display<Smallvil>, +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +struct Cli { + #[arg(last = true)] + command: Option<OsString>, } -fn main() -> Result<(), Box<dyn std::error::Error>> { - if let Ok(env_filter) = tracing_subscriber::EnvFilter::try_from_default_env() { - tracing_subscriber::fmt() - .compact() - .with_env_filter(env_filter) - .init(); - } else { - tracing_subscriber::fmt().compact().init(); - } +pub struct LoopData { + niri: Niri, + display_handle: DisplayHandle, - let mut event_loop: EventLoop<CalloopData> = EventLoop::try_new()?; + // Last so that it's dropped after the Smithay state in Niri. + display: Display<Niri>, - let mut display: Display<Smallvil> = Display::new()?; - let state = Smallvil::new(&event_loop, &mut display); + tty: Option<Tty>, + winit: Option<Winit>, +} + +fn main() { + env::set_var("RUST_BACKTRACE", "1"); - let mut data = CalloopData { state, display }; + let directives = env::var("RUST_LOG").unwrap_or_else(|_| "niri=debug,info".to_owned()); + let env_filter = EnvFilter::builder().parse_lossy(directives); + tracing_subscriber::fmt() + .compact() + .with_env_filter(env_filter) + .init(); - crate::wini |
