Compare commits

...

3 Commits

10 changed files with 168 additions and 75 deletions

48
Cargo.lock generated
View File

@ -2,6 +2,54 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "ctor"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb"
dependencies = [
"quote",
"syn",
]
[[package]]
name = "polytreewm"
version = "0.0.0"
dependencies = [
"ctor",
]
[[package]]
name = "proc-macro2"
version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
dependencies = [
"proc-macro2",
]
[[package]]
name = "syn"
version = "1.0.99"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf"

View File

@ -15,3 +15,6 @@ publish = false
[lib]
name = "polytreewm"
crate-type = ["staticlib"]
[dependencies]
ctor = "0.1.23"

41
src/api/constraints.rs Normal file
View File

@ -0,0 +1,41 @@
use crate::*;
use std::os::raw::*;
#[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,57 +2,6 @@ use crate::*;
use std::os::raw::*;
/***************
* 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]
unsafe extern "C" fn position_init(position: *mut geom::Position) {
*position = Default::default();

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

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

32
src/api/settings.rs Normal file
View File

@ -0,0 +1,32 @@
use crate::*;
use std::os::raw::*;
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);
}
#[no_mangle]
unsafe extern "C" fn settings_get_border_width() -> c_int {
SETTINGS.unwrap().border_width()
}
#[no_mangle]
unsafe extern "C" fn settings_set_border_width(value: c_int) {
SETTINGS.unwrap().border_width_set(value);
}

View File

@ -1,7 +1,6 @@
#ifndef _CONSTRAINTS_H
#define _CONSTRAINTS_H
int constraints_border_width(int border_width);
int constraints_default_clients_in_master(int default_clients_in_master);
float constraints_default_master_area_factor(float default_master_area_factor);
int constraints_gap_size(int gap_size);

View File

@ -1,3 +1,7 @@
mod api;
mod constraints;
mod settings;
pub mod geom;
pub use settings::Settings;

View File

@ -2,9 +2,7 @@
#include "constraints.h"
static bool bar_on_top_by_default = true;
static SettingsForSingleWindow border_for_single_window = SETTINGS_FOR_SINGLE_WINDOW_NOBODY_IS_FULLSCREEN;
static int border_width = 2;
static int default_clients_in_master = 1;
static float default_master_area_factor = 0.6;
static SettingsForSingleWindow gap_for_single_window = SETTINGS_FOR_SINGLE_WINDOW_NOBODY_IS_FULLSCREEN;
@ -19,16 +17,6 @@ static UnitKind show_bar_per_unit = UNIT_MONITOR;
static unsigned int snap_distance = 32;
static bool swallow_floating = false;
bool settings_get_bar_on_top_by_default()
{
return bar_on_top_by_default;
}
void settings_set_bar_on_top_by_default(bool new_bar_on_top_by_default)
{
bar_on_top_by_default = new_bar_on_top_by_default;
}
SettingsForSingleWindow settings_get_border_for_single_window()
{
return border_for_single_window;
@ -40,17 +28,6 @@ void settings_set_border_for_single_window(const SettingsForSingleWindow new_bor
// TODO: notify WM to rearrange clients
}
int settings_get_border_width()
{
return border_width;
}
void settings_set_border_width(const int new_border_width)
{
border_width = constraints_border_width(new_border_width);
// TODO: notify WM to rearrange clients
}
int settings_get_default_clients_in_master()
{
return default_clients_in_master;

37
src/settings.rs Normal file
View File

@ -0,0 +1,37 @@
use crate::constraints;
use std::os::raw::*;
#[derive(Clone, Copy, Debug)]
pub struct Settings {
bar_on_top_by_default: bool,
border_width: c_int,
}
impl Default for Settings {
fn default() -> Self {
Self {
bar_on_top_by_default: true,
border_width: 2,
}
}
}
impl Settings {
pub fn bar_on_top_by_default(&self) -> bool {
self.bar_on_top_by_default
}
pub fn bar_on_top_by_default_set(&mut self, value: bool) {
self.bar_on_top_by_default = value;
}
pub fn border_width(&self) -> c_int {
self.border_width
}
// TODO: notify WM to rearrange clients
pub fn border_width_set(&mut self, value: c_int) {
self.border_width = constraints::border_width(value);
}
}