Create module "src/geom.c"

This commit is contained in:
Alex Kotov 2021-12-04 22:14:07 +05:00
parent 0481b87645
commit 3bbf3488a2
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
5 changed files with 181 additions and 147 deletions

View file

@ -22,6 +22,7 @@ MODULES_SRC = \
src/constraints.c \
src/drw.c \
src/dwm.c \
src/geom.c \
src/helpers.c \
src/layouts.c \
src/settings.c \

104
src/geom.c Normal file
View file

@ -0,0 +1,104 @@
#include "geom.h"
/****************************
* Default create functions *
****************************/
struct Position position_create()
{
struct Position position;
position_init(&position);
return position;
}
struct Sizes sizes_create()
{
struct Sizes sizes;
sizes_init(&sizes);
return sizes;
}
struct BasicGeometry basic_geometry_create()
{
struct BasicGeometry basic_geometry;
basic_geometry_init(&basic_geometry);
return basic_geometry;
}
/**************************
* Default init functions *
**************************/
void position_init(const Position position)
{
position->x = 0;
position->y = 0;
}
void sizes_init(const Sizes sizes)
{
sizes->w = 0;
sizes->h = 0;
}
void basic_geometry_init(const BasicGeometry basic_geometry)
{
position_init(&basic_geometry->position);
sizes_init(&basic_geometry->sizes);
}
/*****************************
* Argument create functions *
*****************************/
struct Position position_create_from_args(const int x, const int y)
{
const struct Position position = { .x = x, .y = y };
return position;
}
struct Sizes sizes_create_from_args(const int width, const int height)
{
const struct Sizes sizes = { .w = width, .h = height };
return sizes;
}
struct BasicGeometry basic_geometry_create_from_args(
const int x,
const int y,
const int width,
const int height
) {
const struct BasicGeometry basic_geometry = {
.position = position_create_from_args(x, y),
.sizes = sizes_create_from_args(width, height),
};
return basic_geometry;
}
/***************************
* Argument init functions *
***************************/
void position_init_from_args(const Position position, const int x, const int y)
{
position->x = x;
position->y = y;
}
void sizes_init_from_args(const Sizes sizes, const int width, const int height)
{
sizes->w = width;
sizes->h = height;
}
void basic_geometry_init_from_args(
const BasicGeometry basic_geometry,
const int x,
const int y,
const int width,
const int height
) {
position_init_from_args(&basic_geometry->position, x, y);
sizes_init_from_args(&basic_geometry->sizes, width, height);
}

74
src/geom.h Normal file
View file

@ -0,0 +1,74 @@
#ifndef _GEOM_H
#define _GEOM_H
/*****************
* Pointer types *
*****************/
typedef struct Position *Position;
typedef struct Sizes *Sizes;
typedef struct BasicGeometry *BasicGeometry;
/**************
* Structures *
**************/
struct Position {
int x, y;
};
struct Sizes {
int w, h;
};
struct BasicGeometry {
struct Position position;
struct Sizes sizes;
};
/****************************
* Default create functions *
****************************/
struct Position position_create();
struct Sizes sizes_create();
struct BasicGeometry basic_geometry_create();
/**************************
* Default init functions *
**************************/
void position_init(Position position);
void sizes_init(Sizes sizes);
void basic_geometry_init(BasicGeometry basic_geometry);
/*****************************
* Argument create functions *
*****************************/
struct Position position_create_from_args(int x, int y);
struct Sizes sizes_create_from_args(int width, int height);
struct BasicGeometry basic_geometry_create_from_args(
int x,
int y,
int width,
int height
);
/***************************
* Argument init functions *
***************************/
void position_init_from_args(Position position, int x, int y);
void sizes_init_from_args(Sizes sizes, int width, int height);
void basic_geometry_init_from_args(
BasicGeometry basic_geometry,
int x,
int y,
int width,
int height
);
#endif // _GEOM_H

View file

@ -2,53 +2,10 @@
#include <string.h>
/****************************
* Default create functions *
****************************/
struct Position position_create()
{
struct Position position;
position_init(&position);
return position;
}
struct Sizes sizes_create()
{
struct Sizes sizes;
sizes_init(&sizes);
return sizes;
}
struct BasicGeometry basic_geometry_create()
{
struct BasicGeometry basic_geometry;
basic_geometry_init(&basic_geometry);
return basic_geometry;
}
/**************************
* Default init functions *
**************************/
void position_init(const Position position)
{
position->x = 0;
position->y = 0;
}
void sizes_init(const Sizes sizes)
{
sizes->w = 0;
sizes->h = 0;
}
void basic_geometry_init(const BasicGeometry basic_geometry)
{
position_init(&basic_geometry->position);
sizes_init(&basic_geometry->sizes);
}
void client_geometry_init(const ClientGeometry client_geometry)
{
basic_geometry_init(&client_geometry->basic);
@ -80,62 +37,10 @@ void client_state_init(const ClientState client_state)
client_state->is_fullscreen = false;
}
/*****************************
* Argument create functions *
*****************************/
struct Position position_create_from_args(const int x, const int y)
{
const struct Position position = { .x = x, .y = y };
return position;
}
struct Sizes sizes_create_from_args(const int width, const int height)
{
const struct Sizes sizes = { .w = width, .h = height };
return sizes;
}
struct BasicGeometry basic_geometry_create_from_args(
const int x,
const int y,
const int width,
const int height
) {
const struct BasicGeometry basic_geometry = {
.position = position_create_from_args(x, y),
.sizes = sizes_create_from_args(width, height),
};
return basic_geometry;
}
/***************************
* Argument init functions *
***************************/
void position_init_from_args(const Position position, const int x, const int y)
{
position->x = x;
position->y = y;
}
void sizes_init_from_args(const Sizes sizes, const int width, const int height)
{
sizes->w = width;
sizes->h = height;
}
void basic_geometry_init_from_args(
const BasicGeometry basic_geometry,
const int x,
const int y,
const int width,
const int height
) {
position_init_from_args(&basic_geometry->position, x, y);
sizes_init_from_args(&basic_geometry->sizes, width, height);
}
void client_geometry_init_from_args(
const ClientGeometry client_geometry,
const int x,

View file

@ -1,6 +1,8 @@
#ifndef _STATE_H
#define _STATE_H
#include "geom.h"
#include <stdbool.h>
#include <X11/Xutil.h>
@ -8,9 +10,6 @@
* Pointer types *
*****************/
typedef struct Position *Position;
typedef struct Sizes *Sizes;
typedef struct BasicGeometry *BasicGeometry;
typedef struct ClientGeometry *ClientGeometry;
typedef struct ClientSizeHints *ClientSizeHints;
typedef struct ClientState *ClientState;
@ -19,19 +18,6 @@ typedef struct ClientState *ClientState;
* Structures *
**************/
struct Position {
int x, y;
};
struct Sizes {
int w, h;
};
struct BasicGeometry {
struct Position position;
struct Sizes sizes;
};
struct ClientGeometry {
struct BasicGeometry basic;
int border_width;
@ -48,54 +34,18 @@ struct ClientState {
bool is_fixed, is_floating, is_urgent, never_focus, is_fullscreen;
};
/****************************
* Default create functions *
****************************/
struct Position position_create();
struct Sizes sizes_create();
struct BasicGeometry basic_geometry_create();
/**************************
* Default init functions *
**************************/
void position_init(Position position);
void sizes_init(Sizes sizes);
void basic_geometry_init(BasicGeometry basic_geometry);
void client_geometry_init(ClientGeometry client_geometry);
void client_size_hints_init(ClientSizeHints client_size_hints);
void client_state_init(ClientState client_state);
/*****************************
* Argument create functions *
*****************************/
struct Position position_create_from_args(int x, int y);
struct Sizes sizes_create_from_args(int width, int height);
struct BasicGeometry basic_geometry_create_from_args(
int x,
int y,
int width,
int height
);
/***************************
* Argument init functions *
***************************/
void position_init_from_args(Position position, int x, int y);
void sizes_init_from_args(Sizes sizes, int width, int height);
void basic_geometry_init_from_args(
BasicGeometry basic_geometry,
int x,
int y,
int width,
int height
);
void client_geometry_init_from_args(
ClientGeometry client_geometry,
int x,