From ed910c1fff3d6c86bcafd25c3a0fbfb7712ccc02 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Thu, 8 Sep 2022 15:41:21 +0400 Subject: [PATCH] Move funcs "settings_(get|set)_bar_on_top_by_default" to Rust --- Cargo.lock | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 +++ src/api.rs | 23 +++++++++++++++++++++++ src/lib.rs | 4 ++++ src/settings.c | 11 ----------- src/settings.rs | 22 ++++++++++++++++++++++ 6 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 src/settings.rs diff --git a/Cargo.lock b/Cargo.lock index e1885ee..e60916b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 3a3104a..8a826b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,6 @@ publish = false [lib] name = "polytreewm" crate-type = ["staticlib"] + +[dependencies] +ctor = "0.1.23" diff --git a/src/api.rs b/src/api.rs index 254dfdd..4cbe511 100644 --- a/src/api.rs +++ b/src/api.rs @@ -2,6 +2,29 @@ use crate::*; use std::os::raw::*; +use ctor::ctor; + +/************ + * Settings * + ************/ + +static mut SETTINGS: Option = 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 * ***************/ diff --git a/src/lib.rs b/src/lib.rs index f980917..de8a83e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,7 @@ mod api; mod constraints; +mod settings; + pub mod geom; + +pub use settings::Settings; diff --git a/src/settings.c b/src/settings.c index bd2dd83..ebd040d 100644 --- a/src/settings.c +++ b/src/settings.c @@ -2,7 +2,6 @@ #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; @@ -19,16 +18,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; diff --git a/src/settings.rs b/src/settings.rs new file mode 100644 index 0000000..b40f9cd --- /dev/null +++ b/src/settings.rs @@ -0,0 +1,22 @@ +#[derive(Clone, Copy, Debug)] +pub struct Settings { + bar_on_top_by_default: bool, +} + +impl Default for Settings { + fn default() -> Self { + Self { + bar_on_top_by_default: true, + } + } +} + +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, bar_on_top_by_default: bool) { + self.bar_on_top_by_default = bar_on_top_by_default; + } +}