From f1249c90c7017da0ecd5ee4c4361650024aae33f Mon Sep 17 00:00:00 2001 From: Arthur Beck Date: Thu, 6 Mar 2025 21:54:50 +0000 Subject: [PATCH] Added example and did some work --- example.nua | 40 ++++++++++++++++++++++++++++++++++++++++ src/config.rs | 24 ++++++++++++++++++++++++ src/main.rs | 24 +++++++++++++++--------- src/state.rs | 29 +++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 9 deletions(-) create mode 100644 example.nua create mode 100644 src/config.rs create mode 100644 src/state.rs diff --git a/example.nua b/example.nua new file mode 100644 index 0000000..0cbfdf7 --- /dev/null +++ b/example.nua @@ -0,0 +1,40 @@ +tiling { + tiling_factor = 180; +} +keybinds { + $act = meta; + + select_left = $act+left; + select_right = $act+right; + select_down = $act+down; + select_up = $act+up; + # or: + #select_all = $act+arrow; + + # valid general keysets: + # arrow number letter 1strow + # 2ndrow 3rdrow mod symbol + # function special + # you can also add the prefix + # "non" to the start of any + # keyset to get any key except + # that keyset. keyset special + # is keys including modifiers, + # backspace, tab, enter + + expand_all = $act+shift+arrow; + + move_all = $act+alt+arrow; + + select_workspace_all = $act+W+arrow; + + move_workspace_all = $act+W+alt+arrow; + + bookmark_workspace_all = $act+B+shift+number; + + jump_workspace_all = $act+B+number; +} + +include = file2.nua; + +env = WINDOW_MANAGER=nuarth; \ No newline at end of file diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..2e79fa8 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,24 @@ +//! Config parsing. + +use std::path::PathBuf; + +/// Gets Nuarth's config directory. +fn get_config_dir() -> PathBuf { + let env = std::env::var("XDG_CONFIG_HOME"); + if let Ok(env) = env { + return PathBuf::from(env).join("nuarth"); + } + #[allow(deprecated, clippy::unwrap_used)] + std::env::home_dir().unwrap().join(".config").join("nuarth") +} + +/// Configuration for tiling. +pub struct TilingConfig { + /// The tiling factor used to calculate how many tiles in a screen. + pub tiling_factor: f64 +} + +/// Nuarth configuration. +pub struct Config { + pub tiling: TilingConfig +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 3babeaf..96525a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,29 +1,35 @@ //! The main code for Nuarth. -#![warn(missing_docs, clippy::missing_docs_in_private_items)] +#![warn(missing_docs, clippy::missing_docs_in_private_items, clippy::unwrap_used)] use polling::{Event, Poller}; -/// The state of Nuarth. -struct State {} +mod state; +mod config; +use state::DelegationState; fn main() { - let display = wayland_server::Display::::new(); + let display = wayland_server::Display::::new(); if display.is_err() { println!("[FATAL] Cannot load libwayland-server.so, exiting."); println!("[HINT] Compile Nuarth with wayland_server's dlopen feature disabled\n[HINT] to not require this library"); std::process::exit(1); } - let mut display = display.unwrap(); // Error state is checked above + + #[allow(clippy::unwrap_used)] // Error state checked above + let mut display = display.unwrap(); let polling_fd = display.backend().poll_fd(); - let poller = Poller::new().unwrap(); // At the moment, this method cannot return an error. - unsafe { poller.add(&polling_fd, Event::readable(0)).unwrap(); } // At the moment, this method cannot return an error. + + let poller = Poller::new().expect("failed to create poller for polling file descriptor"); + + unsafe { poller.add(&polling_fd, Event::readable(0)).expect("failed to initalize polling file descriptor"); } let mut events = polling::Events::new(); loop { // Event loop events.clear(); - poller.wait(&mut events, None).unwrap(); // At the moment, this method cannot return an error. - display.dispatch_clients(&mut State { }).unwrap(); // At the moment, this method cannot return an error. + poller.wait(&mut events, None).expect("failed waiting for wayland events"); + + display.dispatch_clients(&mut DelegationState { }).expect("failed to dispatch event handlers for clients"); } } diff --git a/src/state.rs b/src/state.rs new file mode 100644 index 0000000..31e39b5 --- /dev/null +++ b/src/state.rs @@ -0,0 +1,29 @@ +//! Stuff related to state and dispatch methods. + +use wayland_server::{Dispatch, protocol::*}; + +/// The state of Nuarth. +pub struct DelegationState { + +} + +/// The state of Nuarth for a client. +struct ClientState {} + +impl Dispatch for DelegationState { + fn request( + state: &mut DelegationState, + client: &wayland_server::Client, + resource: &wl_output::WlOutput, + request: ::Request, + data: &ClientState, + dhandle: &wayland_server::DisplayHandle, + data_init: &mut wayland_server::DataInit<'_, DelegationState>, + ) { + if let wl_output::Request::Release = request { + + } else { + println!("[ERROR] Unknown wl_output request!"); + } + } +}