From 32db3bc238580391c4d2ee341dd8f4f145ac152e Mon Sep 17 00:00:00 2001 From: Seaotatop Date: Sun, 11 Jun 2023 17:56:34 -0500 Subject: [PATCH] Project restructure to prepare for config API --- Cargo.toml | 37 ++----------- pinnacle/Cargo.toml | 35 ++++++++++++ {resources => pinnacle/resources}/cursor.rgba | Bin {resources => pinnacle/resources}/numbers.png | Bin {src => pinnacle/src}/backend.rs | 0 {src => pinnacle/src}/backend/udev.rs | 0 {src => pinnacle/src}/backend/winit.rs | 0 {src => pinnacle/src}/cursor.rs | 0 {src => pinnacle/src}/grab.rs | 0 {src => pinnacle/src}/grab/move_grab.rs | 0 {src => pinnacle/src}/grab/resize_grab.rs | 0 {src => pinnacle/src}/handlers.rs | 0 {src => pinnacle/src}/input.rs | 33 ++++++++---- {src => pinnacle/src}/layout.rs | 0 {src => pinnacle/src}/layout/automatic.rs | 0 {src => pinnacle/src}/layout/manual.rs | 0 pinnacle/src/main.rs | 34 ++++++++++++ {src => pinnacle/src}/pointer.rs | 0 {src => pinnacle/src}/render.rs | 0 {src => pinnacle/src}/render/pointer.rs | 0 {src => pinnacle/src}/state.rs | 20 +++---- {src => pinnacle/src}/window.rs | 0 {src => pinnacle/src}/window/window_state.rs | 0 {src => pinnacle/src}/xdg.rs | 0 {src => pinnacle/src}/xdg/request.rs | 0 pinnacle_api/Cargo.toml | 9 ++++ pinnacle_api/src/lib.rs | 51 ++++++++++++++++++ pinnacle_api_lua/init.lua | 1 + src/main.rs | 32 ----------- 29 files changed, 166 insertions(+), 86 deletions(-) create mode 100644 pinnacle/Cargo.toml rename {resources => pinnacle/resources}/cursor.rgba (100%) rename {resources => pinnacle/resources}/numbers.png (100%) rename {src => pinnacle/src}/backend.rs (100%) rename {src => pinnacle/src}/backend/udev.rs (100%) rename {src => pinnacle/src}/backend/winit.rs (100%) rename {src => pinnacle/src}/cursor.rs (100%) rename {src => pinnacle/src}/grab.rs (100%) rename {src => pinnacle/src}/grab/move_grab.rs (100%) rename {src => pinnacle/src}/grab/resize_grab.rs (100%) rename {src => pinnacle/src}/handlers.rs (100%) rename {src => pinnacle/src}/input.rs (94%) rename {src => pinnacle/src}/layout.rs (100%) rename {src => pinnacle/src}/layout/automatic.rs (100%) rename {src => pinnacle/src}/layout/manual.rs (100%) create mode 100644 pinnacle/src/main.rs rename {src => pinnacle/src}/pointer.rs (100%) rename {src => pinnacle/src}/render.rs (100%) rename {src => pinnacle/src}/render/pointer.rs (100%) rename {src => pinnacle/src}/state.rs (93%) rename {src => pinnacle/src}/window.rs (100%) rename {src => pinnacle/src}/window/window_state.rs (100%) rename {src => pinnacle/src}/xdg.rs (100%) rename {src => pinnacle/src}/xdg/request.rs (100%) create mode 100644 pinnacle_api/Cargo.toml create mode 100644 pinnacle_api/src/lib.rs create mode 100644 pinnacle_api_lua/init.lua delete mode 100644 src/main.rs diff --git a/Cargo.toml b/Cargo.toml index e80af25..b11db37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,34 +1,5 @@ -[package] -name = "pinnacle" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -tracing = "0.1.37" -tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } -smithay = { git = "https://github.com/Smithay/smithay" } -smithay-drm-extras = { git = "https://github.com/Smithay/smithay", optional = true } -thiserror = "1.0.40" -xcursor = {version = "0.3.4", optional = true } -image = {version = "0.24.0", default-features = false, optional = true} - -[features] -default = ["egl", "winit", "udev"] -egl = ["smithay/use_system_lib", "smithay/backend_egl"] -udev = [ - "smithay-drm-extras", - "smithay/backend_libinput", - "smithay/backend_udev", - "smithay/backend_drm", - "smithay/backend_gbm", - "smithay/backend_vulkan", - "smithay/backend_egl", - "smithay/backend_session_libseat", - "image", - "smithay/renderer_gl", - "smithay/renderer_multi", - "xcursor", +[workspace] +members = [ + "pinnacle", + "pinnacle_api" ] -winit = ["smithay/backend_winit", "smithay/backend_drm"] diff --git a/pinnacle/Cargo.toml b/pinnacle/Cargo.toml new file mode 100644 index 0000000..16a1801 --- /dev/null +++ b/pinnacle/Cargo.toml @@ -0,0 +1,35 @@ +[package] +name = "pinnacle" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +pinnacle_api = { path = "../pinnacle_api" } +tracing = "0.1.37" +tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } +smithay = { git = "https://github.com/Smithay/smithay" } +smithay-drm-extras = { git = "https://github.com/Smithay/smithay", optional = true } +thiserror = "1.0.40" +xcursor = {version = "0.3.4", optional = true } +image = {version = "0.24.0", default-features = false, optional = true} + +[features] +default = ["egl", "winit", "udev"] +egl = ["smithay/use_system_lib", "smithay/backend_egl"] +udev = [ + "smithay-drm-extras", + "smithay/backend_libinput", + "smithay/backend_udev", + "smithay/backend_drm", + "smithay/backend_gbm", + "smithay/backend_vulkan", + "smithay/backend_egl", + "smithay/backend_session_libseat", + "image", + "smithay/renderer_gl", + "smithay/renderer_multi", + "xcursor", +] +winit = ["smithay/backend_winit", "smithay/backend_drm"] diff --git a/resources/cursor.rgba b/pinnacle/resources/cursor.rgba similarity index 100% rename from resources/cursor.rgba rename to pinnacle/resources/cursor.rgba diff --git a/resources/numbers.png b/pinnacle/resources/numbers.png similarity index 100% rename from resources/numbers.png rename to pinnacle/resources/numbers.png diff --git a/src/backend.rs b/pinnacle/src/backend.rs similarity index 100% rename from src/backend.rs rename to pinnacle/src/backend.rs diff --git a/src/backend/udev.rs b/pinnacle/src/backend/udev.rs similarity index 100% rename from src/backend/udev.rs rename to pinnacle/src/backend/udev.rs diff --git a/src/backend/winit.rs b/pinnacle/src/backend/winit.rs similarity index 100% rename from src/backend/winit.rs rename to pinnacle/src/backend/winit.rs diff --git a/src/cursor.rs b/pinnacle/src/cursor.rs similarity index 100% rename from src/cursor.rs rename to pinnacle/src/cursor.rs diff --git a/src/grab.rs b/pinnacle/src/grab.rs similarity index 100% rename from src/grab.rs rename to pinnacle/src/grab.rs diff --git a/src/grab/move_grab.rs b/pinnacle/src/grab/move_grab.rs similarity index 100% rename from src/grab/move_grab.rs rename to pinnacle/src/grab/move_grab.rs diff --git a/src/grab/resize_grab.rs b/pinnacle/src/grab/resize_grab.rs similarity index 100% rename from src/grab/resize_grab.rs rename to pinnacle/src/grab/resize_grab.rs diff --git a/src/handlers.rs b/pinnacle/src/handlers.rs similarity index 100% rename from src/handlers.rs rename to pinnacle/src/handlers.rs diff --git a/src/input.rs b/pinnacle/src/input.rs similarity index 94% rename from src/input.rs rename to pinnacle/src/input.rs index fa15188..7a7cc4a 100644 --- a/src/input.rs +++ b/pinnacle/src/input.rs @@ -3,13 +3,14 @@ use smithay::{ AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent, KeyState, KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent, PointerMotionEvent, }, - desktop::WindowSurfaceType, + desktop::{Window, WindowSurfaceType}, input::{ keyboard::{keysyms, FilterResult}, pointer::{AxisFrame, ButtonEvent, MotionEvent, RelativeMotionEvent}, }, reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::ResizeEdge, utils::{Logical, Point, SERIAL_COUNTER}, + wayland::seat::WaylandFocus, }; use crate::{ @@ -18,6 +19,16 @@ use crate::{ }; impl State { + pub fn surface_under

(&self, point: P) -> Option<(Window, Point)> + where + P: Into>, + { + // TODO: layer map, popups, fullscreen + self.space + .element_under(point) + .map(|(window, loc)| (window.clone(), loc)) + } + fn pointer_button(&mut self, event: I::PointerButtonEvent) { let pointer = self.seat.get_pointer().unwrap(); let keyboard = self.seat.get_keyboard().unwrap(); @@ -39,11 +50,7 @@ impl State { // If the button was clicked, focus on the window below if exists, else // unfocus on windows. if ButtonState::Pressed == button_state { - if let Some((window, window_loc)) = self - .space - .element_under(pointer_loc) - .map(|(w, l)| (w.clone(), l)) - { + if let Some((window, window_loc)) = self.surface_under(pointer_loc) { const BUTTON_LEFT: u32 = 0x110; const BUTTON_RIGHT: u32 = 0x111; if self.move_mode { @@ -305,11 +312,15 @@ impl State { // this event is never generated by winit self.pointer_location = self.clamp_coords(self.pointer_location); + let surface_under = self + .surface_under(self.pointer_location) + .and_then(|(window, loc)| window.wl_surface().map(|surface| (surface, loc))); + // tracing::info!("{:?}", self.pointer_location); if let Some(ptr) = self.seat.get_pointer() { ptr.motion( self, - None, + surface_under, &MotionEvent { location: self.pointer_location, serial, @@ -347,16 +358,16 @@ impl State { self.pointer_location.x = event.x_transformed(max_x); self.pointer_location.y = event.y_transformed(max_y); - // clamp to screen limits self.pointer_location = self.clamp_coords(self.pointer_location); - // tracing::info!("{:?}", self.pointer_location); + let surface_under = self + .surface_under(self.pointer_location) + .and_then(|(window, loc)| window.wl_surface().map(|surface| (surface, loc))); - // let under = self.surface_under(); if let Some(ptr) = self.seat.get_pointer() { ptr.motion( self, - None, + surface_under, &MotionEvent { location: self.pointer_location, serial, diff --git a/src/layout.rs b/pinnacle/src/layout.rs similarity index 100% rename from src/layout.rs rename to pinnacle/src/layout.rs diff --git a/src/layout/automatic.rs b/pinnacle/src/layout/automatic.rs similarity index 100% rename from src/layout/automatic.rs rename to pinnacle/src/layout/automatic.rs diff --git a/src/layout/manual.rs b/pinnacle/src/layout/manual.rs similarity index 100% rename from src/layout/manual.rs rename to pinnacle/src/layout/manual.rs diff --git a/pinnacle/src/main.rs b/pinnacle/src/main.rs new file mode 100644 index 0000000..f3e3cff --- /dev/null +++ b/pinnacle/src/main.rs @@ -0,0 +1,34 @@ +mod backend; +mod cursor; +mod grab; +mod handlers; +mod input; +mod layout; +mod pointer; +mod render; +mod state; +mod window; +mod xdg; + +use std::error::Error; + +fn main() -> Result<(), Box> { + pinnacle_api::start(); + + // match tracing_subscriber::EnvFilter::try_from_default_env() { + // Ok(env_filter) => { + // tracing_subscriber::fmt() + // .compact() + // .with_env_filter(env_filter) + // .init(); + // } + // Err(_) => { + // tracing_subscriber::fmt().compact().init(); + // } + // } + // + // tracing::info!("Starting winit backend"); + // // crate::backend::winit::run_winit()?; + // crate::backend::udev::run_udev()?; + Ok(()) +} diff --git a/src/pointer.rs b/pinnacle/src/pointer.rs similarity index 100% rename from src/pointer.rs rename to pinnacle/src/pointer.rs diff --git a/src/render.rs b/pinnacle/src/render.rs similarity index 100% rename from src/render.rs rename to pinnacle/src/render.rs diff --git a/src/render/pointer.rs b/pinnacle/src/render/pointer.rs similarity index 100% rename from src/render/pointer.rs rename to pinnacle/src/render/pointer.rs diff --git a/src/state.rs b/pinnacle/src/state.rs similarity index 93% rename from src/state.rs rename to pinnacle/src/state.rs index 8dd53dc..22e9e3b 100644 --- a/src/state.rs +++ b/pinnacle/src/state.rs @@ -181,16 +181,16 @@ pub fn take_presentation_feedback( ); } }); - let map = smithay::desktop::layer_map_for_output(output); - for layer_surface in map.layers() { - layer_surface.take_presentation_feedback( - &mut output_presentation_feedback, - surface_primary_scanout_output, - |surface, _| { - surface_presentation_feedback_flags_from_states(surface, render_element_states) - }, - ); - } + // let map = smithay::desktop::layer_map_for_output(output); + // for layer_surface in map.layers() { + // layer_surface.take_presentation_feedback( + // &mut output_presentation_feedback, + // surface_primary_scanout_output, + // |surface, _| { + // surface_presentation_feedback_flags_from_states(surface, render_element_states) + // }, + // ); + // } output_presentation_feedback } diff --git a/src/window.rs b/pinnacle/src/window.rs similarity index 100% rename from src/window.rs rename to pinnacle/src/window.rs diff --git a/src/window/window_state.rs b/pinnacle/src/window/window_state.rs similarity index 100% rename from src/window/window_state.rs rename to pinnacle/src/window/window_state.rs diff --git a/src/xdg.rs b/pinnacle/src/xdg.rs similarity index 100% rename from src/xdg.rs rename to pinnacle/src/xdg.rs diff --git a/src/xdg/request.rs b/pinnacle/src/xdg/request.rs similarity index 100% rename from src/xdg/request.rs rename to pinnacle/src/xdg/request.rs diff --git a/pinnacle_api/Cargo.toml b/pinnacle_api/Cargo.toml new file mode 100644 index 0000000..445a706 --- /dev/null +++ b/pinnacle_api/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "pinnacle_api" +version = "0.1.0" +edition = "2021" + +[dependencies] +tracing = "0.1.37" +tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } +rkyv = { version = "0.7.42", features = ["validation", "strict"] } diff --git a/pinnacle_api/src/lib.rs b/pinnacle_api/src/lib.rs new file mode 100644 index 0000000..7c3e715 --- /dev/null +++ b/pinnacle_api/src/lib.rs @@ -0,0 +1,51 @@ +use std::{ + io::Read, + mem::size_of, + os::unix::net::{UnixDatagram, UnixListener, UnixStream}, +}; + +const SOCKET_PATH: &str = "/tmp/pinnacle_socket"; + +pub fn new_socket() { + let socket = UnixDatagram::bind("/something/other").unwrap(); + let socket2 = UnixStream::connect("/fsalkfhgtew").unwrap(); +} + +pub fn start() { + let listener = match UnixListener::bind(SOCKET_PATH) { + Ok(socket) => socket, + Err(err) => { + eprintln!("Failed to create UnixListener: {}", err); + return; + } + }; + + for stream in listener.incoming() { + match stream { + Ok(stream) => { + std::thread::spawn(|| handle_client(stream)); + } + Err(err) => { + eprintln!("Incoming stream error: {}", err); + } + } + } +} + +fn handle_client(mut stream: UnixStream) { + let mut buf = [0u8; size_of::()]; + stream.read_exact(&mut buf).unwrap(); + + let thing = rkyv::check_archived_root::(&buf).unwrap(); + println!("{}", thing.msg); +} + +#[repr(C)] +#[derive(rkyv::Archive)] +#[archive(check_bytes)] +struct Message { + number: u32, + msg: String, + num2: u64, + num3: u8, +} diff --git a/pinnacle_api_lua/init.lua b/pinnacle_api_lua/init.lua new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/pinnacle_api_lua/init.lua @@ -0,0 +1 @@ + diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 835be08..0000000 --- a/src/main.rs +++ /dev/null @@ -1,32 +0,0 @@ -mod backend; -mod cursor; -mod grab; -mod handlers; -mod input; -mod layout; -mod pointer; -mod render; -mod state; -mod window; -mod xdg; - -use std::error::Error; - -fn main() -> Result<(), Box> { - match tracing_subscriber::EnvFilter::try_from_default_env() { - Ok(env_filter) => { - tracing_subscriber::fmt() - .compact() - .with_env_filter(env_filter) - .init(); - } - Err(_) => { - tracing_subscriber::fmt().compact().init(); - } - } - - tracing::info!("Starting winit backend"); - // crate::backend::winit::run_winit()?; - crate::backend::udev::run_udev()?; - Ok(()) -}