Compare commits
12 commits
e674a2da7e
...
d49ff190d9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d49ff190d9 | ||
|
|
2d356cd473 | ||
|
|
c77e47796c | ||
|
|
f8198f75ec | ||
|
|
a30288acb6 | ||
|
|
f492071f45 | ||
|
|
6cea72c2c9 | ||
|
|
5e564e7903 | ||
|
|
098a5bc54c | ||
|
|
162ce1dff8 | ||
|
|
bd4b49c5e1 | ||
|
|
2664eca633 |
10 changed files with 238 additions and 68 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,5 +2,6 @@
|
|||
/config/2-conditionals.mk
|
||||
/polytreewm
|
||||
/src/*.o
|
||||
/target/
|
||||
/tests/*.o
|
||||
/tests/*.test
|
||||
|
|
|
|||
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "polytreewm"
|
||||
version = "0.0.0"
|
||||
17
Cargo.toml
Normal file
17
Cargo.toml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
[package]
|
||||
name = "polytreewm"
|
||||
version = "0.0.0"
|
||||
authors = ["Alex Kotov <kotovalexarian@gmail.com>"]
|
||||
edition = "2021"
|
||||
description = "PolytreeWM is an extremely fast, small, and dynamic tiling window manager for X"
|
||||
readme = true
|
||||
homepage = "https://github.com/PolytreeDE/polytreewm"
|
||||
repository = "https://github.com/PolytreeDE/polytreewm.git"
|
||||
license = "MIT"
|
||||
keywords = []
|
||||
categories = []
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
name = "polytreewm"
|
||||
crate-type = ["staticlib"]
|
||||
13
Makefile
13
Makefile
|
|
@ -16,7 +16,6 @@ CONFIGMKS = \
|
|||
|
||||
MODULES_SRC = \
|
||||
src/atoms.c \
|
||||
src/constraints.c \
|
||||
src/drw.c \
|
||||
src/dwm.c \
|
||||
src/geom.c \
|
||||
|
|
@ -43,7 +42,7 @@ TEST_SRC = \
|
|||
|
||||
MAIN_SRC = $(MODULES_SRC) src/main.c
|
||||
|
||||
MODULES_HDR = $(MODULES_SRC:.c=.h)
|
||||
MODULES_HDR = $(MODULES_SRC:.c=.h) src/constraints.h
|
||||
DWM_HDR = $(DWM_SRC:.c=.h)
|
||||
MAIN_HDR = $(MODULES_HDR) src/main.h
|
||||
|
||||
|
|
@ -58,10 +57,10 @@ ALL_EXE = polytreewm $(TEST_EXE)
|
|||
# Executables #
|
||||
###############
|
||||
|
||||
polytreewm: src/main.o $(MODULES_OBJ)
|
||||
polytreewm: src/main.o $(MODULES_OBJ) target/debug/libpolytreewm.a
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
%.test: %.o tests/main.o $(MODULES_OBJ)
|
||||
%.test: %.o tests/main.o $(MODULES_OBJ) target/debug/libpolytreewm.a
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
################
|
||||
|
|
@ -73,15 +72,21 @@ polytreewm: src/main.o $(MODULES_OBJ)
|
|||
|
||||
dwm.o: $(DWM_SRC) $(DWM_HDR)
|
||||
|
||||
target/debug/libpolytreewm.a:
|
||||
$(CARGO) build
|
||||
|
||||
#########
|
||||
# Tasks #
|
||||
#########
|
||||
|
||||
test: $(TEST_EXE)
|
||||
@echo "$(TEST_EXE)" | awk '{ OFS="\n"; $$1=$$1 } 1' | /bin/sh
|
||||
$(CARGO) test
|
||||
$(CARGO) fmt --check
|
||||
|
||||
clean:
|
||||
rm -f $(ALL_OBJ) $(ALL_EXE)
|
||||
$(CARGO) clean
|
||||
|
||||
distclean: clean
|
||||
rm -f $(CONFIGMKS_TO_REMOVE)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ PolytreeWM is an extremely fast, small, and dynamic tiling window manager for X.
|
|||
Requirements
|
||||
------------
|
||||
|
||||
In order to build PolytreeWM you need the Xlib header files.
|
||||
In order to build PolytreeWM you need Cargo for Rust and the Xlib header files.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
CARGO = cargo
|
||||
CC = cc
|
||||
PKGCONFIG = pkg-config
|
||||
|
||||
|
|
|
|||
1
rustfmt.toml
Normal file
1
rustfmt.toml
Normal file
|
|
@ -0,0 +1 @@
|
|||
max_width = 80
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
#include "constraints.h"
|
||||
|
||||
#define MIN_BORDER_WIDTH 0
|
||||
#define MAX_BORDER_WIDTH 10000
|
||||
#define MIN_DEFAULT_CLIENTS_IN_MASTER 1
|
||||
#define MAX_DEFAULT_CLIENTS_IN_MASTER 10000
|
||||
#define MIN_DEFAULT_MASTER_AREA_FACTOR 0.05
|
||||
#define MAX_DEFAULT_MASTER_AREA_FACTOR 0.95
|
||||
#define MIN_GAP_SIZE 0
|
||||
#define MAX_GAP_SIZE 10000
|
||||
#define MIN_MASTER_AREA_FACTOR 0.05
|
||||
#define MAX_MASTER_AREA_FACTOR 0.95
|
||||
#define MIN_MAX_CLIENTS_IN_MASTER 1
|
||||
#define MAX_MAX_CLIENTS_IN_MASTER 10000
|
||||
#define MIN_SNAP_DISTANCE 1
|
||||
#define MAX_SNAP_DISTANCE 10000
|
||||
|
||||
int constraints_border_width(const int border_width)
|
||||
{
|
||||
if (border_width < MIN_BORDER_WIDTH) return MIN_BORDER_WIDTH;
|
||||
if (border_width > MAX_BORDER_WIDTH) return MAX_BORDER_WIDTH;
|
||||
return border_width;
|
||||
}
|
||||
|
||||
int constraints_default_clients_in_master(const int default_clients_in_master)
|
||||
{
|
||||
if (default_clients_in_master < MIN_DEFAULT_CLIENTS_IN_MASTER) return MIN_DEFAULT_CLIENTS_IN_MASTER;
|
||||
if (default_clients_in_master > MAX_DEFAULT_CLIENTS_IN_MASTER) return MAX_DEFAULT_CLIENTS_IN_MASTER;
|
||||
return default_clients_in_master;
|
||||
}
|
||||
|
||||
float constraints_default_master_area_factor(const float default_master_area_factor)
|
||||
{
|
||||
return constraints_master_area_factor(default_master_area_factor);
|
||||
}
|
||||
|
||||
int constraints_gap_size(const int gap_size)
|
||||
{
|
||||
if (gap_size < MIN_GAP_SIZE) return MIN_GAP_SIZE;
|
||||
if (gap_size < MAX_GAP_SIZE) return MAX_GAP_SIZE;
|
||||
return gap_size;
|
||||
}
|
||||
|
||||
float constraints_master_area_factor(const float master_area_factor)
|
||||
{
|
||||
if (master_area_factor < MIN_MASTER_AREA_FACTOR) return MIN_MASTER_AREA_FACTOR;
|
||||
if (master_area_factor > MAX_MASTER_AREA_FACTOR) return MAX_MASTER_AREA_FACTOR;
|
||||
return master_area_factor;
|
||||
}
|
||||
|
||||
int constraints_max_clients_in_master(const int max_clients_in_master)
|
||||
{
|
||||
if (max_clients_in_master < MIN_MAX_CLIENTS_IN_MASTER) return MIN_MAX_CLIENTS_IN_MASTER;
|
||||
if (max_clients_in_master > MAX_MAX_CLIENTS_IN_MASTER) return MAX_MAX_CLIENTS_IN_MASTER;
|
||||
return max_clients_in_master;
|
||||
}
|
||||
|
||||
unsigned int constraints_snap_distance(const unsigned int snap_distance)
|
||||
{
|
||||
if (snap_distance < MIN_SNAP_DISTANCE) return MIN_SNAP_DISTANCE;
|
||||
if (snap_distance > MAX_SNAP_DISTANCE) return MAX_SNAP_DISTANCE;
|
||||
return snap_distance;
|
||||
}
|
||||
155
src/constraints.rs
Normal file
155
src/constraints.rs
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
use std::os::raw::*;
|
||||
|
||||
const MIN_BORDER_WIDTH: c_int = 0;
|
||||
const MAX_BORDER_WIDTH: c_int = 10000;
|
||||
const MIN_DEFAULT_CLIENTS_IN_MASTER: c_int = 1;
|
||||
const MAX_DEFAULT_CLIENTS_IN_MASTER: c_int = 10000;
|
||||
const MIN_GAP_SIZE: c_int = 0;
|
||||
const MAX_GAP_SIZE: c_int = 10000;
|
||||
const MIN_MASTER_AREA_FACTOR: c_float = 0.05;
|
||||
const MAX_MASTER_AREA_FACTOR: c_float = 0.95;
|
||||
const MIN_MAX_CLIENTS_IN_MASTER: c_int = 1;
|
||||
const MAX_MAX_CLIENTS_IN_MASTER: c_int = 10000;
|
||||
const MIN_SNAP_DISTANCE: c_uint = 1;
|
||||
const MAX_SNAP_DISTANCE: c_uint = 10000;
|
||||
|
||||
pub fn border_width(border_width: c_int) -> c_int {
|
||||
if border_width < MIN_BORDER_WIDTH {
|
||||
return MIN_BORDER_WIDTH;
|
||||
}
|
||||
if border_width > MAX_BORDER_WIDTH {
|
||||
return MAX_BORDER_WIDTH;
|
||||
}
|
||||
border_width
|
||||
}
|
||||
|
||||
pub fn default_clients_in_master(default_clients_in_master: c_int) -> c_int {
|
||||
if default_clients_in_master < MIN_DEFAULT_CLIENTS_IN_MASTER {
|
||||
return MIN_DEFAULT_CLIENTS_IN_MASTER;
|
||||
}
|
||||
if default_clients_in_master > MAX_DEFAULT_CLIENTS_IN_MASTER {
|
||||
return MAX_DEFAULT_CLIENTS_IN_MASTER;
|
||||
}
|
||||
default_clients_in_master
|
||||
}
|
||||
|
||||
pub fn default_master_area_factor(
|
||||
default_master_area_factor: c_float,
|
||||
) -> c_float {
|
||||
master_area_factor(default_master_area_factor)
|
||||
}
|
||||
|
||||
pub fn gap_size(gap_size: c_int) -> c_int {
|
||||
if gap_size < MIN_GAP_SIZE {
|
||||
return MIN_GAP_SIZE;
|
||||
}
|
||||
if gap_size > MAX_GAP_SIZE {
|
||||
return MAX_GAP_SIZE;
|
||||
}
|
||||
gap_size
|
||||
}
|
||||
|
||||
pub fn master_area_factor(master_area_factor: c_float) -> c_float {
|
||||
if master_area_factor < MIN_MASTER_AREA_FACTOR {
|
||||
return MIN_MASTER_AREA_FACTOR;
|
||||
}
|
||||
if master_area_factor > MAX_MASTER_AREA_FACTOR {
|
||||
return MAX_MASTER_AREA_FACTOR;
|
||||
}
|
||||
master_area_factor
|
||||
}
|
||||
|
||||
pub fn max_clients_in_master(max_clients_in_master: c_int) -> c_int {
|
||||
if max_clients_in_master < MIN_MAX_CLIENTS_IN_MASTER {
|
||||
return MIN_MAX_CLIENTS_IN_MASTER;
|
||||
}
|
||||
if max_clients_in_master > MAX_MAX_CLIENTS_IN_MASTER {
|
||||
return MAX_MAX_CLIENTS_IN_MASTER;
|
||||
}
|
||||
max_clients_in_master
|
||||
}
|
||||
|
||||
pub fn snap_distance(snap_distance: c_uint) -> c_uint {
|
||||
if snap_distance < MIN_SNAP_DISTANCE {
|
||||
return MIN_SNAP_DISTANCE;
|
||||
}
|
||||
if snap_distance > MAX_SNAP_DISTANCE {
|
||||
return MAX_SNAP_DISTANCE;
|
||||
}
|
||||
snap_distance
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_border_width() {
|
||||
assert_eq!(border_width(-1), 0);
|
||||
|
||||
assert_eq!(border_width(0), 0);
|
||||
assert_eq!(border_width(10), 10);
|
||||
assert_eq!(border_width(10_000), 10_000);
|
||||
|
||||
assert_eq!(border_width(10_001), 10_000);
|
||||
assert_eq!(border_width(20_000), 10_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_clients_in_master() {
|
||||
assert_eq!(default_clients_in_master(-1), 1);
|
||||
assert_eq!(default_clients_in_master(0), 1);
|
||||
|
||||
assert_eq!(default_clients_in_master(1), 1);
|
||||
assert_eq!(default_clients_in_master(2), 2);
|
||||
assert_eq!(default_clients_in_master(9999), 9999);
|
||||
assert_eq!(default_clients_in_master(10_000), 10_000);
|
||||
|
||||
assert_eq!(default_clients_in_master(10_001), 10_000);
|
||||
assert_eq!(default_clients_in_master(20_000), 10_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gap_size() {
|
||||
assert_eq!(gap_size(-2), 0);
|
||||
assert_eq!(gap_size(-1), 0);
|
||||
|
||||
assert_eq!(gap_size(0), 0);
|
||||
assert_eq!(gap_size(1), 1);
|
||||
assert_eq!(gap_size(100), 100);
|
||||
assert_eq!(gap_size(9999), 9999);
|
||||
assert_eq!(gap_size(10_000), 10_000);
|
||||
|
||||
assert_eq!(gap_size(10_001), 10_000);
|
||||
assert_eq!(gap_size(20_000), 10_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_max_clients_in_master() {
|
||||
assert_eq!(max_clients_in_master(-1), 1);
|
||||
assert_eq!(max_clients_in_master(0), 1);
|
||||
|
||||
assert_eq!(max_clients_in_master(1), 1);
|
||||
assert_eq!(max_clients_in_master(2), 2);
|
||||
assert_eq!(max_clients_in_master(100), 100);
|
||||
assert_eq!(max_clients_in_master(9999), 9999);
|
||||
assert_eq!(max_clients_in_master(10_000), 10_000);
|
||||
|
||||
assert_eq!(max_clients_in_master(10_001), 10_000);
|
||||
assert_eq!(max_clients_in_master(20_000), 10_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_snap_distance() {
|
||||
assert_eq!(snap_distance(0), 1);
|
||||
|
||||
assert_eq!(snap_distance(1), 1);
|
||||
assert_eq!(snap_distance(2), 2);
|
||||
assert_eq!(snap_distance(100), 100);
|
||||
assert_eq!(snap_distance(9999), 9999);
|
||||
assert_eq!(snap_distance(10_000), 10_000);
|
||||
|
||||
assert_eq!(snap_distance(10_001), 10_000);
|
||||
assert_eq!(snap_distance(20_000), 10_000);
|
||||
}
|
||||
}
|
||||
46
src/lib.rs
Normal file
46
src/lib.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
mod constraints;
|
||||
|
||||
use std::os::raw::*;
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn constraints_border_width(border_width: c_int) -> c_int {
|
||||
constraints::border_width(border_width)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn constraints_default_clients_in_master(
|
||||
default_clients_in_master: c_int,
|
||||
) -> c_int {
|
||||
constraints::default_clients_in_master(default_clients_in_master)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn constraints_default_master_area_factor(
|
||||
default_master_area_factor: c_float,
|
||||
) -> c_float {
|
||||
constraints::default_master_area_factor(default_master_area_factor)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn constraints_gap_size(gap_size: c_int) -> c_int {
|
||||
constraints::gap_size(gap_size)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn constraints_master_area_factor(
|
||||
master_area_factor: c_float,
|
||||
) -> c_float {
|
||||
constraints::master_area_factor(master_area_factor)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn constraints_max_clients_in_master(
|
||||
max_clients_in_master: c_int,
|
||||
) -> c_int {
|
||||
constraints::max_clients_in_master(max_clients_in_master)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn constraints_snap_distance(snap_distance: c_uint) -> c_uint {
|
||||
constraints::snap_distance(snap_distance)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue