Move funcs "win_geom_total_(width|height)" to Rust
This commit is contained in:
parent
21554b3f6f
commit
11f0629a19
5 changed files with 33 additions and 18 deletions
3
Makefile
3
Makefile
|
@ -38,7 +38,8 @@ DWM_SRC = \
|
||||||
TEST_SRC = \
|
TEST_SRC = \
|
||||||
tests/geom_basic_geom.c \
|
tests/geom_basic_geom.c \
|
||||||
tests/geom_position.c \
|
tests/geom_position.c \
|
||||||
tests/geom_sizes.c
|
tests/geom_sizes.c \
|
||||||
|
tests/geom_win_geom.c
|
||||||
|
|
||||||
MAIN_SRC = $(MODULES_SRC) src/main.c
|
MAIN_SRC = $(MODULES_SRC) src/main.c
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ PKGCONFIG = pkg-config
|
||||||
PKGS += fontconfig freetype2 x11 xft
|
PKGS += fontconfig freetype2 x11 xft
|
||||||
|
|
||||||
CFLAGS += `$(PKGCONFIG) --cflags $(PKGS)`
|
CFLAGS += `$(PKGCONFIG) --cflags $(PKGS)`
|
||||||
LDFLAGS += `$(PKGCONFIG) --libs $(PKGS)`
|
LDFLAGS += `$(PKGCONFIG) --libs $(PKGS)` -lpthread -ldl
|
||||||
|
|
||||||
CPPFLAGS += -DVERSION=\"$(VERSION)\" -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L
|
CPPFLAGS += -DVERSION=\"$(VERSION)\" -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L
|
||||||
CFLAGS += $(CPPFLAGS) -std=c99 -Os -pedantic -Wall -Wno-deprecated-declarations
|
CFLAGS += $(CPPFLAGS) -std=c99 -Os -pedantic -Wall -Wno-deprecated-declarations
|
||||||
|
|
16
src/geom.c
16
src/geom.c
|
@ -88,22 +88,6 @@ void win_geom_convert_to_x_window_changes(
|
||||||
x_window_changes->border_width = win_geom->border_width;
|
x_window_changes->border_width = win_geom->border_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**********************
|
|
||||||
* Constant functions *
|
|
||||||
**********************/
|
|
||||||
|
|
||||||
int win_geom_total_width(
|
|
||||||
const struct WinGeom *const win_geom
|
|
||||||
) {
|
|
||||||
return win_geom->basic.sizes.w + 2 * win_geom->border_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
int win_geom_total_height(
|
|
||||||
const struct WinGeom *const win_geom
|
|
||||||
) {
|
|
||||||
return win_geom->basic.sizes.h + 2 * win_geom->border_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************
|
/***********************
|
||||||
* Modifying functions *
|
* Modifying functions *
|
||||||
***********************/
|
***********************/
|
||||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -123,3 +123,17 @@ unsafe extern "C" fn win_geom_init_from_args(
|
||||||
border_width,
|
border_width,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
unsafe extern "C" fn win_geom_total_width(
|
||||||
|
win_geom: *const geom::WinGeom,
|
||||||
|
) -> c_int {
|
||||||
|
(*win_geom).total_width()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
unsafe extern "C" fn win_geom_total_height(
|
||||||
|
win_geom: *const geom::WinGeom,
|
||||||
|
) -> c_int {
|
||||||
|
(*win_geom).total_height()
|
||||||
|
}
|
||||||
|
|
16
tests/geom_win_geom.c
Normal file
16
tests/geom_win_geom.c
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "../src/geom.h"
|
||||||
|
|
||||||
|
static void test_total_width_height();
|
||||||
|
|
||||||
|
void test() {
|
||||||
|
test_total_width_height();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_total_width_height()
|
||||||
|
{
|
||||||
|
const struct WinGeom win_geom = win_geom_create_from_args(0, 0, 34, 56, 12);
|
||||||
|
assert(win_geom_total_width(&win_geom) == 58);
|
||||||
|
assert(win_geom_total_height(&win_geom) == 80);
|
||||||
|
}
|
Loading…
Reference in a new issue