Move func "helpers_gap_size" to Rust

This commit is contained in:
Alex Kotov 2022-09-09 01:02:02 +04:00
parent 77e2218575
commit b2d677d39f
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 44 additions and 26 deletions

View file

@ -15,7 +15,7 @@ CONFIGMKS = \
config/3-defvars.mk config/3-defvars.mk
RUST_SRC = src/*.rs src/**/*.rs RUST_SRC = src/*.rs src/**/*.rs
RUST_APIS = src/constraints.h src/geom.h src/settings.h RUST_APIS = src/constraints.h src/geom.h src/helpers.h src/settings.h
MODULES_SRC = \ MODULES_SRC = \
src/atoms.c \ src/atoms.c \

View file

@ -184,3 +184,16 @@ unsafe extern "C" fn settings_get_swallow_floatting() -> bool {
unsafe extern "C" fn settings_set_swallow_floating(value: bool) { unsafe extern "C" fn settings_set_swallow_floating(value: bool) {
SETTINGS.unwrap().swallow_floating_set(value); SETTINGS.unwrap().swallow_floating_set(value);
} }
#[no_mangle]
unsafe extern "C" fn helpers_gap_size(
displayed_clients: c_uint,
selected_is_fullscreen: bool,
any_is_fullscreen: bool,
) -> c_int {
SETTINGS.unwrap().gap_size_helper(
displayed_clients,
selected_is_fullscreen,
any_is_fullscreen,
)
}

View file

@ -2,31 +2,6 @@
#include "settings.h" #include "settings.h"
int helpers_gap_size(
const unsigned int displayed_clients,
const bool selected_is_fullscreen,
const bool any_is_fullscreen
) {
const SettingsForSingleWindow gap_for_single_window = settings_get_gap_for_single_window();
const int gap_size = settings_get_gap_size();
if (displayed_clients > 1) return gap_size;
switch (gap_for_single_window) {
case SETTINGS_FOR_SINGLE_WINDOW_NEVER:
return 0;
case SETTINGS_FOR_SINGLE_WINDOW_ALWAYS:
return gap_size;
case SETTINGS_FOR_SINGLE_WINDOW_NOT_IN_FULLSCREEN:
return selected_is_fullscreen ? 0 : gap_size;
case SETTINGS_FOR_SINGLE_WINDOW_NOBODY_IS_FULLSCREEN:
return (selected_is_fullscreen || any_is_fullscreen) ? 0 : gap_size;
default:
// TODO: maybe we should assert here
return 0;
}
}
int helpers_border_width( int helpers_border_width(
const unsigned int displayed_clients, const unsigned int displayed_clients,
const bool selected_is_fullscreen, const bool selected_is_fullscreen,

View file

@ -162,6 +162,36 @@ impl Settings {
self.gap_size = constraints::gap_size(value); self.gap_size = constraints::gap_size(value);
} }
pub fn gap_size_helper(
&self,
displayed_clients: c_uint,
selected_is_fullscreen: bool,
any_is_fullscreen: bool,
) -> c_int {
if displayed_clients > 1 {
return self.gap_size;
}
match self.gap_for_single_window {
ForSingleWindow::Never => 0,
ForSingleWindow::Always => self.gap_size,
ForSingleWindow::NotInFullscreen => {
if selected_is_fullscreen {
0
} else {
self.gap_size
}
}
ForSingleWindow::NobodyIsFullscreen => {
if selected_is_fullscreen || any_is_fullscreen {
0
} else {
self.gap_size
}
}
}
}
pub fn master_area_factor_per_unit(&self) -> unit::Kind { pub fn master_area_factor_per_unit(&self) -> unit::Kind {
self.master_area_factor_per_unit self.master_area_factor_per_unit
} }