Added example and did some work

This commit is contained in:
Arthur Beck 2025-03-06 21:54:50 +00:00
parent 031c6076f1
commit f1249c90c7
4 changed files with 108 additions and 9 deletions

40
example.nua Normal file
View file

@ -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;

24
src/config.rs Normal file
View file

@ -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
}

View file

@ -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::<State>::new();
let display = wayland_server::Display::<DelegationState>::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");
}
}

29
src/state.rs Normal file
View file

@ -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<wl_output::WlOutput, ClientState, DelegationState> for DelegationState {
fn request(
state: &mut DelegationState,
client: &wayland_server::Client,
resource: &wl_output::WlOutput,
request: <wl_output::WlOutput as wayland_server::Resource>::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!");
}
}
}