2021-12-04 17:14:07 +00:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2021-12-04 17:26:32 +00:00
|
|
|
struct BasicGeom basic_geom_create()
|
2021-12-04 17:14:07 +00:00
|
|
|
{
|
2021-12-04 17:26:32 +00:00
|
|
|
struct BasicGeom basic_geom;
|
|
|
|
basic_geom_init(&basic_geom);
|
|
|
|
return basic_geom;
|
2021-12-04 17:14:07 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 17:44:06 +00:00
|
|
|
struct WinGeom win_geom_create()
|
2021-12-04 17:39:08 +00:00
|
|
|
{
|
2021-12-04 17:44:06 +00:00
|
|
|
struct WinGeom win_geom;
|
|
|
|
win_geom_init(&win_geom);
|
|
|
|
return win_geom;
|
2021-12-04 17:39:08 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 17:14:07 +00:00
|
|
|
/**************************
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2021-12-04 17:26:32 +00:00
|
|
|
void basic_geom_init(const BasicGeom basic_geom)
|
2021-12-04 17:14:07 +00:00
|
|
|
{
|
2021-12-04 17:26:32 +00:00
|
|
|
position_init(&basic_geom->position);
|
|
|
|
sizes_init(&basic_geom->sizes);
|
2021-12-04 17:14:07 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 17:44:06 +00:00
|
|
|
void win_geom_init(const WinGeom win_geom)
|
2021-12-04 17:39:08 +00:00
|
|
|
{
|
2021-12-04 17:44:06 +00:00
|
|
|
basic_geom_init(&win_geom->basic);
|
|
|
|
win_geom->border_width = 0;
|
2021-12-04 17:39:08 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 17:14:07 +00:00
|
|
|
/*****************************
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2021-12-04 17:26:32 +00:00
|
|
|
struct BasicGeom basic_geom_create_from_args(
|
2021-12-04 17:14:07 +00:00
|
|
|
const int x,
|
|
|
|
const int y,
|
|
|
|
const int width,
|
|
|
|
const int height
|
|
|
|
) {
|
2021-12-04 17:26:32 +00:00
|
|
|
const struct BasicGeom basic_geom = {
|
2021-12-04 17:14:07 +00:00
|
|
|
.position = position_create_from_args(x, y),
|
|
|
|
.sizes = sizes_create_from_args(width, height),
|
|
|
|
};
|
2021-12-04 17:26:32 +00:00
|
|
|
return basic_geom;
|
2021-12-04 17:14:07 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 17:44:06 +00:00
|
|
|
struct WinGeom win_geom_create_from_args(
|
2021-12-04 17:39:08 +00:00
|
|
|
const int x,
|
|
|
|
const int y,
|
|
|
|
const int width,
|
|
|
|
const int height,
|
|
|
|
const int border_width
|
|
|
|
) {
|
2021-12-04 17:44:06 +00:00
|
|
|
struct WinGeom win_geom;
|
|
|
|
win_geom_init_from_args(&win_geom, x, y, width, height, border_width);
|
|
|
|
return win_geom;
|
2021-12-04 17:39:08 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 17:14:07 +00:00
|
|
|
/***************************
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2021-12-04 17:26:32 +00:00
|
|
|
void basic_geom_init_from_args(
|
|
|
|
const BasicGeom basic_geom,
|
2021-12-04 17:14:07 +00:00
|
|
|
const int x,
|
|
|
|
const int y,
|
|
|
|
const int width,
|
|
|
|
const int height
|
|
|
|
) {
|
2021-12-04 17:26:32 +00:00
|
|
|
position_init_from_args(&basic_geom->position, x, y);
|
|
|
|
sizes_init_from_args(&basic_geom->sizes, width, height);
|
2021-12-04 17:14:07 +00:00
|
|
|
}
|
2021-12-04 17:39:08 +00:00
|
|
|
|
2021-12-04 17:44:06 +00:00
|
|
|
void win_geom_init_from_args(
|
|
|
|
const WinGeom win_geom,
|
2021-12-04 17:39:08 +00:00
|
|
|
const int x,
|
|
|
|
const int y,
|
|
|
|
const int width,
|
|
|
|
const int height,
|
|
|
|
const int border_width
|
|
|
|
) {
|
2021-12-04 17:44:06 +00:00
|
|
|
basic_geom_init_from_args(&win_geom->basic, x, y, width, height);
|
|
|
|
win_geom->border_width = border_width;
|
2021-12-04 17:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************
|
|
|
|
* Conversion functions *
|
|
|
|
************************/
|
|
|
|
|
2021-12-04 17:44:06 +00:00
|
|
|
void win_geom_convert_to_x_window_changes(
|
|
|
|
const struct WinGeom *const win_geom,
|
2021-12-04 17:39:08 +00:00
|
|
|
XWindowChanges *const x_window_changes
|
|
|
|
) {
|
2021-12-04 17:44:06 +00:00
|
|
|
x_window_changes->x = win_geom->basic.position.x;
|
|
|
|
x_window_changes->y = win_geom->basic.position.y;
|
|
|
|
x_window_changes->width = win_geom->basic.sizes.w;
|
|
|
|
x_window_changes->height = win_geom->basic.sizes.h;
|
|
|
|
x_window_changes->border_width = win_geom->border_width;
|
2021-12-04 17:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* Constant functions *
|
|
|
|
**********************/
|
|
|
|
|
2021-12-04 17:44:06 +00:00
|
|
|
int win_geom_total_width(
|
|
|
|
const struct WinGeom *const win_geom
|
2021-12-04 17:39:08 +00:00
|
|
|
) {
|
2021-12-04 17:44:06 +00:00
|
|
|
return win_geom->basic.sizes.w + 2 * win_geom->border_width;
|
2021-12-04 17:39:08 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 17:44:06 +00:00
|
|
|
int win_geom_total_height(
|
|
|
|
const struct WinGeom *const win_geom
|
2021-12-04 17:39:08 +00:00
|
|
|
) {
|
2021-12-04 17:44:06 +00:00
|
|
|
return win_geom->basic.sizes.h + 2 * win_geom->border_width;
|
2021-12-04 17:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************
|
|
|
|
* Modifying functions *
|
|
|
|
***********************/
|
|
|
|
|
2021-12-04 17:44:06 +00:00
|
|
|
void win_geom_adjust_to_boundary(
|
|
|
|
const WinGeom win_geom,
|
2021-12-04 17:39:08 +00:00
|
|
|
const struct BasicGeom *const boundary_geom
|
|
|
|
) {
|
2021-12-04 17:44:06 +00:00
|
|
|
const int total_width = win_geom_total_width(win_geom);
|
|
|
|
const int total_height = win_geom_total_height(win_geom);
|
2021-12-04 17:39:08 +00:00
|
|
|
|
|
|
|
if (
|
2021-12-04 17:44:06 +00:00
|
|
|
win_geom->basic.position.x + total_width
|
2021-12-04 17:39:08 +00:00
|
|
|
>
|
|
|
|
boundary_geom->position.x + boundary_geom->sizes.w
|
|
|
|
) {
|
2021-12-04 17:44:06 +00:00
|
|
|
win_geom->basic.position.x =
|
2021-12-04 17:39:08 +00:00
|
|
|
boundary_geom->position.x
|
|
|
|
+
|
|
|
|
boundary_geom->sizes.w
|
|
|
|
-
|
|
|
|
total_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
2021-12-04 17:44:06 +00:00
|
|
|
win_geom->basic.position.y + total_height
|
2021-12-04 17:39:08 +00:00
|
|
|
>
|
|
|
|
boundary_geom->position.y + boundary_geom->sizes.h
|
|
|
|
) {
|
2021-12-04 17:44:06 +00:00
|
|
|
win_geom->basic.position.y =
|
2021-12-04 17:39:08 +00:00
|
|
|
boundary_geom->position.y
|
|
|
|
+
|
|
|
|
boundary_geom->sizes.h
|
|
|
|
-
|
|
|
|
total_height;
|
|
|
|
}
|
|
|
|
|
2021-12-04 17:44:06 +00:00
|
|
|
if (win_geom->basic.position.x < boundary_geom->position.x) {
|
|
|
|
win_geom->basic.position.x = boundary_geom->position.x;
|
2021-12-04 17:39:08 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 17:44:06 +00:00
|
|
|
if (win_geom->basic.position.y < boundary_geom->position.y) {
|
|
|
|
win_geom->basic.position.y = boundary_geom->position.y;
|
2021-12-04 17:39:08 +00:00
|
|
|
}
|
|
|
|
}
|