Move funcs "constraints_[default_]master_area_factor" to Rust

This commit is contained in:
Alex Kotov 2022-09-07 18:55:19 +04:00
parent c77e47796c
commit 2d356cd473
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 23 additions and 18 deletions

View file

@ -16,7 +16,6 @@ CONFIGMKS = \
MODULES_SRC = \ MODULES_SRC = \
src/atoms.c \ src/atoms.c \
src/constraints.c \
src/drw.c \ src/drw.c \
src/dwm.c \ src/dwm.c \
src/geom.c \ src/geom.c \
@ -43,7 +42,7 @@ TEST_SRC = \
MAIN_SRC = $(MODULES_SRC) src/main.c 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) DWM_HDR = $(DWM_SRC:.c=.h)
MAIN_HDR = $(MODULES_HDR) src/main.h MAIN_HDR = $(MODULES_HDR) src/main.h

View file

@ -1,16 +0,0 @@
#include "constraints.h"
#define MIN_MASTER_AREA_FACTOR 0.05
#define MAX_MASTER_AREA_FACTOR 0.95
float constraints_default_master_area_factor(const float default_master_area_factor)
{
return constraints_master_area_factor(default_master_area_factor);
}
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;
}

View file

@ -6,6 +6,8 @@ const MIN_DEFAULT_CLIENTS_IN_MASTER: c_int = 1;
const MAX_DEFAULT_CLIENTS_IN_MASTER: c_int = 10000; const MAX_DEFAULT_CLIENTS_IN_MASTER: c_int = 10000;
const MIN_GAP_SIZE: c_int = 0; const MIN_GAP_SIZE: c_int = 0;
const MAX_GAP_SIZE: c_int = 10000; 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 MIN_MAX_CLIENTS_IN_MASTER: c_int = 1;
const MAX_MAX_CLIENTS_IN_MASTER: c_int = 10000; const MAX_MAX_CLIENTS_IN_MASTER: c_int = 10000;
const MIN_SNAP_DISTANCE: c_uint = 1; const MIN_SNAP_DISTANCE: c_uint = 1;
@ -27,12 +29,22 @@ pub fn default_clients_in_master(default_clients_in_master: c_int) -> c_int {
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 { pub fn gap_size(gap_size: c_int) -> c_int {
if gap_size < MIN_GAP_SIZE { return MIN_GAP_SIZE } if gap_size < MIN_GAP_SIZE { return MIN_GAP_SIZE }
if gap_size > MAX_GAP_SIZE { return MAX_GAP_SIZE } if gap_size > MAX_GAP_SIZE { return MAX_GAP_SIZE }
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 { pub fn max_clients_in_master(max_clients_in_master: c_int) -> c_int {
if max_clients_in_master < MIN_MAX_CLIENTS_IN_MASTER { if max_clients_in_master < MIN_MAX_CLIENTS_IN_MASTER {
return MIN_MAX_CLIENTS_IN_MASTER return MIN_MAX_CLIENTS_IN_MASTER

View file

@ -12,11 +12,21 @@ extern "C" fn constraints_default_clients_in_master(default_clients_in_master: c
constraints::default_clients_in_master(default_clients_in_master) 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] #[no_mangle]
extern "C" fn constraints_gap_size(gap_size: c_int) -> c_int { extern "C" fn constraints_gap_size(gap_size: c_int) -> c_int {
constraints::gap_size(gap_size) 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] #[no_mangle]
extern "C" fn constraints_max_clients_in_master(max_clients_in_master: c_int) -> c_int { 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) constraints::max_clients_in_master(max_clients_in_master)