Split Rust API

This commit is contained in:
Alex Kotov 2022-09-08 15:43:55 +04:00
parent ed910c1fff
commit 1357b10495
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 69 additions and 74 deletions

46
src/api/constraints.rs Normal file
View file

@ -0,0 +1,46 @@
use crate::*;
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)
}

View file

@ -2,80 +2,6 @@ use crate::*;
use std::os::raw::*; use std::os::raw::*;
use ctor::ctor;
/************
* Settings *
************/
static mut SETTINGS: Option<Settings> = None;
#[ctor]
unsafe fn ctor() {
SETTINGS = Some(Default::default());
}
#[no_mangle]
unsafe extern "C" fn settings_get_bar_on_top_by_default() -> bool {
SETTINGS.unwrap().bar_on_top_by_default()
}
#[no_mangle]
unsafe extern "C" fn settings_set_bar_on_top_by_default(value: bool) {
SETTINGS.unwrap().bar_on_top_by_default_set(value);
}
/***************
* Constraints *
***************/
#[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)
}
/********
* Geom *
********/
#[no_mangle] #[no_mangle]
unsafe extern "C" fn position_init(position: *mut geom::Position) { unsafe extern "C" fn position_init(position: *mut geom::Position) {
*position = Default::default(); *position = Default::default();

3
src/api/mod.rs Normal file
View file

@ -0,0 +1,3 @@
mod constraints;
mod geom;
mod settings;

20
src/api/settings.rs Normal file
View file

@ -0,0 +1,20 @@
use crate::*;
use ctor::ctor;
static mut SETTINGS: Option<Settings> = None;
#[ctor]
unsafe fn ctor() {
SETTINGS = Some(Default::default());
}
#[no_mangle]
unsafe extern "C" fn settings_get_bar_on_top_by_default() -> bool {
SETTINGS.unwrap().bar_on_top_by_default()
}
#[no_mangle]
unsafe extern "C" fn settings_set_bar_on_top_by_default(value: bool) {
SETTINGS.unwrap().bar_on_top_by_default_set(value);
}