Add function "client_geometry_adjust_to_boundary"

This commit is contained in:
Alex Kotov 2021-11-21 03:18:37 +05:00
parent bb17fab590
commit 86f72bc0d5
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
3 changed files with 50 additions and 40 deletions

View File

@ -915,46 +915,9 @@ void manage(Window w, XWindowAttributes *wa)
}
}
{
const int total_width = client_geometry_total_width(&c->state.geometry);
if (
c->state.geometry.basic.position.x + total_width
>
c->mon->screen_geometry.position.x + c->mon->screen_geometry.sizes.w
) {
c->state.geometry.basic.position.x =
c->mon->screen_geometry.position.x
+
c->mon->screen_geometry.sizes.w
-
total_width;
}
const int total_height =
client_geometry_total_height(&c->state.geometry);
if (
c->state.geometry.basic.position.y + total_height
>
c->mon->screen_geometry.position.y + c->mon->screen_geometry.sizes.h
) {
c->state.geometry.basic.position.y =
c->mon->screen_geometry.position.y
+
c->mon->screen_geometry.sizes.h
-
total_height;
}
}
c->state.geometry.basic.position.x = MAX(
c->state.geometry.basic.position.x,
c->mon->screen_geometry.position.x
);
c->state.geometry.basic.position.y = MAX(
c->state.geometry.basic.position.y,
c->mon->screen_geometry.position.y
client_geometry_adjust_to_boundary(
&c->state.geometry,
&c->mon->screen_geometry
);
c->state.geometry.border_width = settings_get_border_width();

View File

@ -63,6 +63,48 @@ int client_geometry_total_height(
return client_geometry->basic.sizes.h + 2 * client_geometry->border_width;
}
void client_geometry_adjust_to_boundary(
const ClientGeometry client_geometry,
const struct BasicGeometry *const boundary_geometry
) {
const int total_width = client_geometry_total_width(client_geometry);
const int total_height = client_geometry_total_height(client_geometry);
if (
client_geometry->basic.position.x + total_width
>
boundary_geometry->position.x + boundary_geometry->sizes.w
) {
client_geometry->basic.position.x =
boundary_geometry->position.x
+
boundary_geometry->sizes.w
-
total_width;
}
if (
client_geometry->basic.position.y + total_height
>
boundary_geometry->position.y + boundary_geometry->sizes.h
) {
client_geometry->basic.position.y =
boundary_geometry->position.y
+
boundary_geometry->sizes.h
-
total_height;
}
if (client_geometry->basic.position.x < boundary_geometry->position.x) {
client_geometry->basic.position.x = boundary_geometry->position.x;
}
if (client_geometry->basic.position.y < boundary_geometry->position.y) {
client_geometry->basic.position.y = boundary_geometry->position.y;
}
}
void client_size_hints_update(
const ClientSizeHints size_hints,
const XSizeHints *const size

View File

@ -62,6 +62,11 @@ void client_state_init(ClientState client_state);
int client_geometry_total_width(const struct ClientGeometry *client_geometry);
int client_geometry_total_height(const struct ClientGeometry *client_geometry);
void client_geometry_adjust_to_boundary(
ClientGeometry client_geometry,
const struct BasicGeometry *boundary_geometry
);
void client_size_hints_update(
ClientSizeHints size_hints,
const XSizeHints *size