diff --git a/src/dwm.c b/src/dwm.c index b7487d0..d61ce91 100644 --- a/src/dwm.c +++ b/src/dwm.c @@ -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(); diff --git a/src/state.c b/src/state.c index ea9197a..de42720 100644 --- a/src/state.c +++ b/src/state.c @@ -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 diff --git a/src/state.h b/src/state.h index 6283791..f197182 100644 --- a/src/state.h +++ b/src/state.h @@ -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