Move funcs "settings_(get|set)_bar_on_top_by_default" to Rust

This commit is contained in:
Alex Kotov 2022-09-08 15:41:21 +04:00
parent 363cbfc894
commit ed910c1fff
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
6 changed files with 100 additions and 11 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"

View file

@ -2,6 +2,29 @@ use crate::*;
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 *
***************/

View file

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

View file

@ -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;

22
src/settings.rs Normal file
View file

@ -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;
}
}