polytreewm/src/geom.c

136 lines
2.9 KiB
C
Raw Normal View History

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
/*****************************
* Argument create functions *
*****************************/
struct Position position_create_from_args(const int x, const int y)
{
struct Position position;
position_init_from_args(&position, x, y);
2021-12-04 17:14:07 +00:00
return position;
}
struct Sizes sizes_create_from_args(const int width, const int height)
{
struct Sizes sizes;
sizes_init_from_args(&sizes, width, height);
2021-12-04 17:14:07 +00:00
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
) {
struct BasicGeom basic_geom;
basic_geom_init_from_args(&basic_geom, x, y, 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
}
/************************
* 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
}
/***********************
* 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
}
}