Move func "settings_(get|set)_border_width" to Rust

This commit is contained in:
Alex Kotov 2022-09-08 15:50:44 +04:00
parent 1357b10495
commit 275076396e
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
5 changed files with 29 additions and 20 deletions

View file

@ -2,11 +2,6 @@ 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,

View file

@ -1,5 +1,7 @@
use crate::*;
use std::os::raw::*;
use ctor::ctor;
static mut SETTINGS: Option<Settings> = None;
@ -18,3 +20,13 @@ unsafe extern "C" fn settings_get_bar_on_top_by_default() -> bool {
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

@ -3,7 +3,6 @@
#include "constraints.h"
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;
@ -29,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;

View file

@ -1,12 +1,18 @@
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,
}
}
}
@ -16,7 +22,16 @@ impl Settings {
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;
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);
}
}