Move ClientGeom to "src/geom.h"

This commit is contained in:
Alex Kotov 2021-12-04 22:39:08 +05:00
parent 6deb8763ed
commit db8f485909
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 169 additions and 140 deletions

View file

@ -25,6 +25,13 @@ struct BasicGeom basic_geom_create()
return basic_geom;
}
struct ClientGeom client_geom_create()
{
struct ClientGeom client_geom;
client_geom_init(&client_geom);
return client_geom;
}
/**************************
* Default init functions *
**************************/
@ -47,6 +54,12 @@ void basic_geom_init(const BasicGeom basic_geom)
sizes_init(&basic_geom->sizes);
}
void client_geom_init(const ClientGeom client_geom)
{
basic_geom_init(&client_geom->basic);
client_geom->border_width = 0;
}
/*****************************
* Argument create functions *
*****************************/
@ -76,6 +89,18 @@ struct BasicGeom basic_geom_create_from_args(
return basic_geom;
}
struct ClientGeom client_geom_create_from_args(
const int x,
const int y,
const int width,
const int height,
const int border_width
) {
struct ClientGeom client_geom;
client_geom_init_from_args(&client_geom, x, y, width, height, border_width);
return client_geom;
}
/***************************
* Argument init functions *
***************************/
@ -102,3 +127,92 @@ void basic_geom_init_from_args(
position_init_from_args(&basic_geom->position, x, y);
sizes_init_from_args(&basic_geom->sizes, width, height);
}
void client_geom_init_from_args(
const ClientGeom client_geom,
const int x,
const int y,
const int width,
const int height,
const int border_width
) {
basic_geom_init_from_args(&client_geom->basic, x, y, width, height);
client_geom->border_width = border_width;
}
/************************
* Conversion functions *
************************/
void client_geom_convert_to_x_window_changes(
const struct ClientGeom *const client_geom,
XWindowChanges *const x_window_changes
) {
x_window_changes->x = client_geom->basic.position.x;
x_window_changes->y = client_geom->basic.position.y;
x_window_changes->width = client_geom->basic.sizes.w;
x_window_changes->height = client_geom->basic.sizes.h;
x_window_changes->border_width = client_geom->border_width;
}
/**********************
* Constant functions *
**********************/
int client_geom_total_width(
const struct ClientGeom *const client_geom
) {
return client_geom->basic.sizes.w + 2 * client_geom->border_width;
}
int client_geom_total_height(
const struct ClientGeom *const client_geom
) {
return client_geom->basic.sizes.h + 2 * client_geom->border_width;
}
/***********************
* Modifying functions *
***********************/
void client_geom_adjust_to_boundary(
const ClientGeom client_geom,
const struct BasicGeom *const boundary_geom
) {
const int total_width = client_geom_total_width(client_geom);
const int total_height = client_geom_total_height(client_geom);
if (
client_geom->basic.position.x + total_width
>
boundary_geom->position.x + boundary_geom->sizes.w
) {
client_geom->basic.position.x =
boundary_geom->position.x
+
boundary_geom->sizes.w
-
total_width;
}
if (
client_geom->basic.position.y + total_height
>
boundary_geom->position.y + boundary_geom->sizes.h
) {
client_geom->basic.position.y =
boundary_geom->position.y
+
boundary_geom->sizes.h
-
total_height;
}
if (client_geom->basic.position.x < boundary_geom->position.x) {
client_geom->basic.position.x = boundary_geom->position.x;
}
if (client_geom->basic.position.y < boundary_geom->position.y) {
client_geom->basic.position.y = boundary_geom->position.y;
}
}

View file

@ -1,13 +1,16 @@
#ifndef _GEOM_H
#define _GEOM_H
#include <X11/Xutil.h>
/*****************
* Pointer types *
*****************/
typedef struct Position *Position;
typedef struct Sizes *Sizes;
typedef struct BasicGeom *BasicGeom;
typedef struct Position *Position;
typedef struct Sizes *Sizes;
typedef struct BasicGeom *BasicGeom;
typedef struct ClientGeom *ClientGeom;
/**************
* Structures *
@ -26,6 +29,11 @@ struct BasicGeom {
struct Sizes sizes;
};
struct ClientGeom {
struct BasicGeom basic;
int border_width;
};
/****************************
* Default create functions *
****************************/
@ -33,6 +41,7 @@ struct BasicGeom {
struct Position position_create();
struct Sizes sizes_create();
struct BasicGeom basic_geom_create();
struct ClientGeom client_geom_create();
/**************************
* Default init functions *
@ -41,6 +50,7 @@ struct BasicGeom basic_geom_create();
void position_init(Position position);
void sizes_init(Sizes sizes);
void basic_geom_init(BasicGeom basic_geom);
void client_geom_init(ClientGeom client_geom);
/*****************************
* Argument create functions *
@ -56,6 +66,14 @@ struct BasicGeom basic_geom_create_from_args(
int height
);
struct ClientGeom client_geom_create_from_args(
int x,
int y,
int width,
int height,
int border_width
);
/***************************
* Argument init functions *
***************************/
@ -71,4 +89,38 @@ void basic_geom_init_from_args(
int height
);
void client_geom_init_from_args(
ClientGeom client_geom,
int x,
int y,
int width,
int height,
int border_width
);
/************************
* Conversion functions *
************************/
void client_geom_convert_to_x_window_changes(
const struct ClientGeom *client_geom,
XWindowChanges *x_window_changes
);
/**********************
* Constant functions *
**********************/
int client_geom_total_width(const struct ClientGeom *client_geom);
int client_geom_total_height(const struct ClientGeom *client_geom);
/***********************
* Modifying functions *
***********************/
void client_geom_adjust_to_boundary(
ClientGeom client_geom,
const struct BasicGeom *boundary_geom
);
#endif // _GEOM_H

View file

@ -6,12 +6,6 @@
* Default init functions *
**************************/
void client_geom_init(const ClientGeom client_geom)
{
basic_geom_init(&client_geom->basic);
client_geom->border_width = 0;
}
void client_size_hints_init(const ClientSizeHints client_size_hints)
{
client_size_hints->mina = 0;
@ -37,99 +31,10 @@ void client_state_init(const ClientState client_state)
client_state->is_fullscreen = false;
}
/***************************
* Argument init functions *
***************************/
void client_geom_init_from_args(
const ClientGeom client_geom,
const int x,
const int y,
const int width,
const int height,
const int border_width
) {
basic_geom_init_from_args(&client_geom->basic, x, y, width, height);
client_geom->border_width = border_width;
}
/************************
* Conversion functions *
************************/
void client_geom_convert_to_x_window_changes(
const struct ClientGeom *const client_geom,
XWindowChanges *const x_window_changes
) {
x_window_changes->x = client_geom->basic.position.x;
x_window_changes->y = client_geom->basic.position.y;
x_window_changes->width = client_geom->basic.sizes.w;
x_window_changes->height = client_geom->basic.sizes.h;
x_window_changes->border_width = client_geom->border_width;
}
/**********************
* Constant functions *
**********************/
int client_geom_total_width(
const struct ClientGeom *const client_geom
) {
return client_geom->basic.sizes.w + 2 * client_geom->border_width;
}
int client_geom_total_height(
const struct ClientGeom *const client_geom
) {
return client_geom->basic.sizes.h + 2 * client_geom->border_width;
}
/***********************
* Modifying functions *
***********************/
void client_geom_adjust_to_boundary(
const ClientGeom client_geom,
const struct BasicGeom *const boundary_geom
) {
const int total_width = client_geom_total_width(client_geom);
const int total_height = client_geom_total_height(client_geom);
if (
client_geom->basic.position.x + total_width
>
boundary_geom->position.x + boundary_geom->sizes.w
) {
client_geom->basic.position.x =
boundary_geom->position.x
+
boundary_geom->sizes.w
-
total_width;
}
if (
client_geom->basic.position.y + total_height
>
boundary_geom->position.y + boundary_geom->sizes.h
) {
client_geom->basic.position.y =
boundary_geom->position.y
+
boundary_geom->sizes.h
-
total_height;
}
if (client_geom->basic.position.x < boundary_geom->position.x) {
client_geom->basic.position.x = boundary_geom->position.x;
}
if (client_geom->basic.position.y < boundary_geom->position.y) {
client_geom->basic.position.y = boundary_geom->position.y;
}
}
void client_size_hints_update(
const ClientSizeHints size_hints,
const XSizeHints *const size

View file

@ -4,13 +4,11 @@
#include "geom.h"
#include <stdbool.h>
#include <X11/Xutil.h>
/*****************
* Pointer types *
*****************/
typedef struct ClientGeom *ClientGeom;
typedef struct ClientSizeHints *ClientSizeHints;
typedef struct ClientState *ClientState;
@ -18,11 +16,6 @@ typedef struct ClientState *ClientState;
* Structures *
**************/
struct ClientGeom {
struct BasicGeom basic;
int border_width;
};
struct ClientSizeHints {
float mina, maxa;
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
@ -38,48 +31,13 @@ struct ClientState {
* Default init functions *
**************************/
void client_geom_init(ClientGeom client_geom);
void client_size_hints_init(ClientSizeHints client_size_hints);
void client_state_init(ClientState client_state);
/***************************
* Argument init functions *
***************************/
void client_geom_init_from_args(
ClientGeom client_geom,
int x,
int y,
int width,
int height,
int border_width
);
/************************
* Conversion functions *
************************/
void client_geom_convert_to_x_window_changes(
const struct ClientGeom *client_geom,
XWindowChanges *x_window_changes
);
/**********************
* Constant functions *
**********************/
int client_geom_total_width(const struct ClientGeom *client_geom);
int client_geom_total_height(const struct ClientGeom *client_geom);
/***********************
* Modifying functions *
***********************/
void client_geom_adjust_to_boundary(
ClientGeom client_geom,
const struct BasicGeom *boundary_geom
);
void client_size_hints_update(
ClientSizeHints size_hints,
const XSizeHints *size