From bd4b49c5e118fd306cfa64db3ddd82f6a609c2b3 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 7 Sep 2022 17:59:07 +0400 Subject: [PATCH] Move func "constraints_border_width" to Rust --- src/constraints.c | 9 --------- src/lib.rs | 11 +++++++++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/constraints.c b/src/constraints.c index 1825f12..cdc312d 100644 --- a/src/constraints.c +++ b/src/constraints.c @@ -1,7 +1,5 @@ #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 @@ -15,13 +13,6 @@ #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; diff --git a/src/lib.rs b/src/lib.rs index b18c736..9dc5ba6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,11 @@ +use std::os::raw::*; + +const MIN_BORDER_WIDTH: c_int = 0; +const MAX_BORDER_WIDTH: c_int = 10000; + #[no_mangle] -pub extern "C" fn foo() -> u32 { - 123 +pub extern "C" fn constraints_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 }