From 2d0b454389cc1d5cb702dcb03dff78e637f0f0a1 Mon Sep 17 00:00:00 2001 From: maxstrb Date: Tue, 2 Dec 2025 07:26:51 +0100 Subject: [PATCH] dunno --- Cargo.lock | 211 ++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 10 +++ src/main.rs | 51 ++--------- src/rendering.rs | 11 ++- src/simple_layer.rs | 53 +++++++---- 5 files changed, 270 insertions(+), 66 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d831b4..e38d7d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "anstyle" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" + [[package]] name = "bitflags" version = "2.10.0" @@ -69,6 +75,43 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "clap" +version = "4.5.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.5.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" +dependencies = [ + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_lex" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" + +[[package]] +name = "codespan-reporting" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af491d569909a7e4dee0ad7db7f5341fef5c614d5b8ec8cf765732aba3cff681" +dependencies = [ + "serde", + "termcolor", + "unicode-width", +] + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -90,12 +133,80 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f" +[[package]] +name = "cxx" +version = "1.0.190" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7620f6cfc4dcca21f2b085b7a890e16c60fd66f560cd69ee60594908dc72ab1" +dependencies = [ + "cc", + "cxx-build", + "cxxbridge-cmd", + "cxxbridge-flags", + "cxxbridge-macro", + "foldhash", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.190" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a9bc1a22964ff6a355fbec24cf68266a0ed28f8b84c0864c386474ea3d0e479" +dependencies = [ + "cc", + "codespan-reporting", + "indexmap", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-cmd" +version = "1.0.190" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f29a879d35f7906e3c9b77d7a1005a6a0787d330c09dfe4ffb5f617728cb44" +dependencies = [ + "clap", + "codespan-reporting", + "indexmap", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.190" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d67109015f93f683e364085aa6489a5b2118b4a40058482101d699936a7836d6" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.190" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d187e019e7b05a1f3e69a8396b70800ee867aa9fc2ab972761173ccee03742df" +dependencies = [ + "indexmap", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "downcast-rs" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + [[package]] name = "errno" version = "0.3.14" @@ -116,22 +227,56 @@ checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844" name = "floating-calculator" version = "0.1.0" dependencies = [ + "cxx", + "cxx-build", + "pkg-config", "smithay-client-toolkit", "wayland-client", ] +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + [[package]] name = "hermit-abi" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" +[[package]] +name = "indexmap" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ad4bb2b565bca0645f4d68c5c9af97fba094e9791da685bf83cb5f3ce74acf2" +dependencies = [ + "equivalent", + "hashbrown", +] + [[package]] name = "libc" version = "0.2.177" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" +[[package]] +name = "link-cplusplus" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f78c730aaa7d0b9336a299029ea49f9ee53b0ed06e9202e8cb7db9bae7b8c82" +dependencies = [ + "cc", +] + [[package]] name = "linux-raw-sys" version = "0.11.0" @@ -225,6 +370,42 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "scratch" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d68f2ec51b097e4c1a75b681a8bec621909b5e91f15bb7b840c4f2f7b01148b2" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "shlex" version = "1.3.0" @@ -273,6 +454,12 @@ dependencies = [ "xkeysym", ] +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "syn" version = "2.0.111" @@ -284,6 +471,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "2.0.17" @@ -327,6 +523,12 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +[[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + [[package]] name = "wayland-backend" version = "0.3.11" @@ -445,6 +647,15 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys", +] + [[package]] name = "windows-link" version = "0.2.1" diff --git a/flake.nix b/flake.nix index 559cdb0..4fa1235 100644 --- a/flake.nix +++ b/flake.nix @@ -18,12 +18,22 @@ default = pkgs.mkShell { buildInputs = with pkgs; [ gcc + clang gnumake rust-bin.stable.latest.default evcxr libxkbcommon wayland rusty-man + libqalculate + pkg-config # Add this + ]; + nativeBuildInputs = with pkgs; [ + pkg-config # Add this here too + ]; + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ + pkgs.libxkbcommon + pkgs.libqalculate # Add this ]; }; }; diff --git a/src/main.rs b/src/main.rs index 02fa4d8..38eac33 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +mod calculator; mod compositor_handler; mod keyboard_handler; mod layer_shell_handler; @@ -9,64 +10,26 @@ mod seat_handling; mod shm_handler; mod simple_layer; +use crate::calculator::Calculator; use crate::simple_layer::SimpleLayer; use smithay_client_toolkit::{ - compositor::CompositorState, delegate_compositor, delegate_keyboard, delegate_layer, delegate_output, delegate_pointer, delegate_registry, delegate_seat, delegate_shm, - output::OutputState, - registry::RegistryState, - seat::SeatState, - shell::{ - WaylandSurface, - wlr_layer::{Anchor, KeyboardInteractivity, Layer, LayerShell}, - }, - shm::{Shm, slot::SlotPool}, }; use wayland_client::{Connection, globals::registry_queue_init}; fn main() { + let calc = Calculator::new(); + + println!("{:#?}", calc.evaluate("\\")); + let conn = Connection::connect_to_env().expect("wayland environment not found"); let (globals, mut event_queue) = registry_queue_init(&conn).unwrap(); let qh = event_queue.handle(); - let compositor = CompositorState::bind(&globals, &qh).expect("wl_compositor is not available"); - let layer_shell = LayerShell::bind(&globals, &qh).expect("layer shell is not available"); - let shm = Shm::bind(&globals, &qh).expect("wl_shm is not available"); - - let surface = compositor.create_surface(&qh); - - let output_state = OutputState::new(&globals, &qh); - let layer = layer_shell.create_layer_surface( - &qh, - surface, - Layer::Top, - Some("simple_layer"), - output_state.outputs().nth(1).as_ref(), - ); - layer.set_anchor(Anchor::TOP); - layer.set_exclusive_zone(-1); - layer.set_keyboard_interactivity(KeyboardInteractivity::OnDemand); - layer.set_size(256, 256); - - layer.commit(); - - let pool = SlotPool::new(256 * 256 * 4, &shm).expect("Failed to create pool"); - - let mut simple_layer = SimpleLayer::new( - RegistryState::new(&globals), - SeatState::new(&globals, &qh), - output_state, - shm, - pool, - 256, - 256, - layer, - None, - None, - ); + let mut simple_layer = SimpleLayer::new(&globals, &qh, 256, 256); loop { event_queue.blocking_dispatch(&mut simple_layer).unwrap(); diff --git a/src/rendering.rs b/src/rendering.rs index 52dd6ff..e2108e0 100644 --- a/src/rendering.rs +++ b/src/rendering.rs @@ -29,14 +29,13 @@ impl SimpleLayer { let x = ((index + shift as usize) % width as usize) as u32; let y = (index / width as usize) as u32; - let a = 0xFF; - let r = u32::min(((width - x) * 0xFF) / width, ((height - y) * 0xFF) / height); - let g = u32::min((x * 0xFF) / width, ((height - y) * 0xFF) / height); - let b = u32::min(((width - x) * 0xFF) / width, (y * 0xFF) / height); - let color = (a << 24) + (r << 16) + (g << 8) + b; + let a: u8 = 0xFF; + let r: u8 = 0xFF; + let g: u8 = 0; + let b: u8 = 0; let array: &mut [u8; 4] = chunk.try_into().unwrap(); - *array = color.to_le_bytes(); + *array = [b, g, r, a]; }); } diff --git a/src/simple_layer.rs b/src/simple_layer.rs index 8b0927d..0207eb7 100644 --- a/src/simple_layer.rs +++ b/src/simple_layer.rs @@ -1,11 +1,19 @@ use smithay_client_toolkit::{ + compositor::CompositorState, output::OutputState, registry::RegistryState, seat::SeatState, - shell::wlr_layer::LayerSurface, + shell::{ + WaylandSurface, + wlr_layer::{KeyboardInteractivity, Layer, LayerShell, LayerSurface}, + }, shm::{Shm, slot::SlotPool}, }; -use wayland_client::protocol::{wl_keyboard, wl_pointer}; +use wayland_client::{ + QueueHandle, + globals::GlobalList, + protocol::{wl_keyboard, wl_pointer}, +}; pub struct SimpleLayer { pub registry_state: RegistryState, @@ -26,31 +34,44 @@ pub struct SimpleLayer { impl SimpleLayer { pub fn new( - registry_state: RegistryState, - seat_state: SeatState, - output_state: OutputState, - shm: Shm, - pool: SlotPool, + globals: &GlobalList, + qh: &QueueHandle, width: u32, height: u32, - layer: LayerSurface, - keyboard: Option, - pointer: Option, ) -> Self { + let shared_memory = Shm::bind(globals, qh).expect("wl_shm is not avaiable"); + + let compositor = + CompositorState::bind(globals, qh).expect("wl_compositor is not available"); + let layer_shell = LayerShell::bind(globals, qh).expect("layer shell is not available"); + + let surface = compositor.create_surface(qh); + + let layer = + layer_shell.create_layer_surface(qh, surface, Layer::Top, Some("simple_layer"), None); + + layer.set_exclusive_zone(-1); + layer.set_keyboard_interactivity(KeyboardInteractivity::OnDemand); + layer.set_size(256, 256); + + layer.commit(); + + let pool = SlotPool::new(256 * 256 * 4, &shared_memory).expect("Failed to create pool"); + Self { - registry_state, - seat_state, - output_state, - shm, + registry_state: RegistryState::new(globals), + seat_state: SeatState::new(globals, qh), + output_state: OutputState::new(globals, qh), + shm: shared_memory, exit: false, first_configure: true, pool, width, height, layer, - keyboard, + keyboard: None, keyboard_focus: false, - pointer, + pointer: None, } } }