diff --git a/src/dwm.c b/src/dwm.c index d61ce91..df9a81d 100644 --- a/src/dwm.c +++ b/src/dwm.c @@ -180,8 +180,8 @@ static void pop(Client *); static void quit(const Arg *arg); static Monitor *recttomon(int x, int y, int w, int h); static void resetnmaster(const Arg *arg); -static void resize(Client *c, int x, int y, int w, int h, int bw, int interact); -static void resizeclient(Client *c, int x, int y, int w, int h, int bw); +static void resize(Client *c, struct ClientGeometry client_geometry, int interact); +static void resizeclient(Client *c, struct ClientGeometry client_geometry); static void resizemouse(const Arg *arg); static void restack(Monitor *m); static void run(); @@ -1116,15 +1116,9 @@ void movemouse(__attribute__((unused)) const Arg *arg) } if (!selmon->lt[selmon->sellt]->arrange || c->state.is_floating) { - resize( - c, - nx, - ny, - c->state.geometry.basic.sizes.w, - c->state.geometry.basic.sizes.h, - c->state.geometry.border_width, - 1 - ); + struct ClientGeometry client_geometry = c->state.geometry; + position_init_from_args(&client_geometry.basic.position, nx, ny); + resize(c, client_geometry, 1); } break; @@ -1261,21 +1255,29 @@ void resetnmaster(const Arg *arg) arrange(selmon); } -void resize(Client *c, int x, int y, int w, int h, int bw, int interact) +void resize(Client *c, struct ClientGeometry client_geometry, int interact) { - if (applysizehints(c, &x, &y, &w, &h, bw, interact)) - resizeclient(c, x, y, w, h, bw); + if ( + applysizehints( + c, + &client_geometry.basic.position.x, + &client_geometry.basic.position.y, + &client_geometry.basic.sizes.w, + &client_geometry.basic.sizes.h, + client_geometry.border_width, + interact + ) + ) { + resizeclient(c, client_geometry); + } } -void resizeclient(Client *c, int x, int y, int w, int h, int bw) +void resizeclient(Client *c, const struct ClientGeometry client_geometry) { - XWindowChanges wc; + c->state.geometry = client_geometry; - c->state.geometry.basic.position.x = wc.x = x; - c->state.geometry.basic.position.y = wc.y = y; - c->state.geometry.basic.sizes.w = wc.width = w; - c->state.geometry.basic.sizes.h = wc.height = h; - c->state.geometry.border_width = wc.border_width = bw; + XWindowChanges wc = { 0 }; + client_geometry_to_x_window_changes(&client_geometry, &wc); XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc); configure(c); @@ -1392,15 +1394,9 @@ void resizemouse(__attribute__((unused)) const Arg *arg) } if (!selmon->lt[selmon->sellt]->arrange || c->state.is_floating) { - resize( - c, - c->state.geometry.basic.position.x, - c->state.geometry.basic.position.y, - nw, - nh, - c->state.geometry.border_width, - 1 - ); + struct ClientGeometry client_geometry = c->state.geometry; + sizes_init_from_args(&client_geometry.basic.sizes, nw, nh); + resize(c, client_geometry, 1); } break; @@ -1737,15 +1733,7 @@ void showhide(Client *c) ); if (!c->mon->lt[c->mon->sellt]->arrange || c->state.is_floating) { - resize( - c, - c->state.geometry.basic.position.x, - c->state.geometry.basic.position.y, - c->state.geometry.basic.sizes.w, - c->state.geometry.basic.sizes.h, - c->state.geometry.border_width, - 0 - ); + resize(c, c->state.geometry, 0); } showhide(c->snext); } else { @@ -1798,17 +1786,19 @@ void togglefloating(__attribute__((unused)) const Arg *arg) const int border_width = settings_get_border_width(); if (selmon->sel->state.is_floating) { - resize( - selmon->sel, - selmon->sel->state.geometry.basic.position.x, - selmon->sel->state.geometry.basic.position.y, + struct ClientGeometry client_geometry = selmon->sel->state.geometry; + + sizes_init_from_args( + &client_geometry.basic.sizes, selmon->sel->state.geometry.basic.sizes.w - 2 * (border_width - selmon->sel->state.geometry.border_width), selmon->sel->state.geometry.basic.sizes.h - - 2 * (border_width - selmon->sel->state.geometry.border_width), - border_width, - 0 + 2 * (border_width - selmon->sel->state.geometry.border_width) ); + + client_geometry.border_width = border_width; + + resize(selmon->sel, client_geometry, 0); } arrange(selmon); diff --git a/src/dwm/layouts.c b/src/dwm/layouts.c index a7743a2..d015812 100644 --- a/src/dwm/layouts.c +++ b/src/dwm/layouts.c @@ -51,16 +51,18 @@ void centeredmaster(Monitor *m) const int right_gap = n <= m->nmaster ? gap_size : bottom_right_half_gap; const int bottom_gap = (i == m->nmaster - 1 || i == n - 1) ? gap_size : bottom_right_half_gap; - resize( - c, + struct ClientGeometry client_geometry; + client_geometry_init_from_args( + &client_geometry, m->window_area_geometry.position.x + mx + left_gap, m->window_area_geometry.position.y + my + top_gap, mw - 2 * border_width - left_gap - right_gap, h - 2 * border_width - top_gap - bottom_gap, - border_width, - 0 + border_width ); + resize(c, client_geometry, 0); + const int total_height = client_geometry_total_height(&c->state.geometry); @@ -76,16 +78,18 @@ void centeredmaster(Monitor *m) const int right_gap = bottom_right_half_gap; const int bottom_gap = (i == n - 1 || i == n - 2) ? gap_size : bottom_right_half_gap; - resize( - c, + struct ClientGeometry client_geometry; + client_geometry_init_from_args( + &client_geometry, m->window_area_geometry.position.x + left_gap, m->window_area_geometry.position.y + ety + top_gap, tw - 2 * border_width - left_gap - right_gap, h - 2 * border_width - top_gap - bottom_gap, - border_width, - 0 + border_width ); + resize(c, client_geometry, 0); + const int total_height = client_geometry_total_height(&c->state.geometry); @@ -99,16 +103,18 @@ void centeredmaster(Monitor *m) const int right_gap = gap_size; const int bottom_gap = (i == n - 1 || i == n - 2) ? gap_size : bottom_right_half_gap; - resize( - c, + struct ClientGeometry client_geometry; + client_geometry_init_from_args( + &client_geometry, m->window_area_geometry.position.x + mx + mw + left_gap, m->window_area_geometry.position.y + oty + top_gap, tw - 2 * border_width - left_gap - right_gap, h - 2 * border_width - top_gap - bottom_gap, - border_width, - 0 + border_width ); + resize(c, client_geometry, 0); + const int total_height = client_geometry_total_height(&c->state.geometry); @@ -124,15 +130,17 @@ void floating(Monitor *m) for (Client *c = m->clients; c; c = c->next) { if (ISVISIBLE(c) && c->state.geometry.border_width == 0) { - resize( - c, + struct ClientGeometry client_geometry; + client_geometry_init_from_args( + &client_geometry, c->state.geometry.basic.position.x, c->state.geometry.basic.position.y, c->state.geometry.basic.sizes.w - 2 * border_width, c->state.geometry.basic.sizes.h - 2 * border_width, - border_width, - 0 + border_width ); + + resize(c, client_geometry, 0); } } } @@ -174,16 +182,18 @@ void horizontile(Monitor *m) const unsigned int right_gap = (i == m->nmaster - 1 || i == n - 1) ? gap_size : bottom_right_half_gap; const unsigned int bottom_gap = n <= m->nmaster ? gap_size : bottom_right_half_gap; - resize( - c, + struct ClientGeometry client_geometry; + client_geometry_init_from_args( + &client_geometry, m->window_area_geometry.position.x + mx + left_gap, m->window_area_geometry.position.y + top_gap, w - 2 * border_width - left_gap - right_gap, mh - 2 * border_width - top_gap - bottom_gap, - border_width, - 0 + border_width ); + resize(c, client_geometry, 0); + const int total_width = client_geometry_total_width(&c->state.geometry); @@ -199,16 +209,18 @@ void horizontile(Monitor *m) const unsigned int right_gap = (i == n - 1) ? gap_size : bottom_right_half_gap; const unsigned int bottom_gap = gap_size; - resize( - c, + struct ClientGeometry client_geometry; + client_geometry_init_from_args( + &client_geometry, m->window_area_geometry.position.x + tx + left_gap, m->window_area_geometry.position.y + mh + top_gap, w - 2 * border_width - left_gap - right_gap, m->window_area_geometry.sizes.h - mh - 2 * border_width - top_gap - bottom_gap, - border_width, - 0 + border_width ); + resize(c, client_geometry, 0); + const int total_width = client_geometry_total_width(&c->state.geometry); @@ -233,15 +245,17 @@ void monocle(Monitor *m) const int border_width = helpers_border_width(1, is_fullscreen, any_is_fullscreen); for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next)) { - resize( - c, + struct ClientGeometry client_geometry; + client_geometry_init_from_args( + &client_geometry, m->window_area_geometry.position.x + gap_size, m->window_area_geometry.position.y + gap_size, m->window_area_geometry.sizes.w - 2 * border_width - 2 * gap_size, m->window_area_geometry.sizes.h - 2 * border_width - 2 * gap_size, - border_width, - 0 + border_width ); + + resize(c, client_geometry, 0); } } @@ -280,16 +294,18 @@ void tile(Monitor *m) const unsigned int right_gap = n <= m->nmaster ? gap_size : bottom_right_half_gap; const unsigned int bottom_gap = (i == m->nmaster - 1 || i == n - 1) ? gap_size : bottom_right_half_gap; - resize( - c, + struct ClientGeometry client_geometry; + client_geometry_init_from_args( + &client_geometry, m->window_area_geometry.position.x + left_gap, m->window_area_geometry.position.y + my + top_gap, mw - 2 * border_width - left_gap - right_gap, h - 2 * border_width - top_gap - bottom_gap, - border_width, - 0 + border_width ); + resize(c, client_geometry, 0); + const int total_height = client_geometry_total_height(&c->state.geometry); @@ -306,16 +322,18 @@ void tile(Monitor *m) const unsigned int right_gap = gap_size; const unsigned int bottom_gap = (i == n - 1) ? gap_size : bottom_right_half_gap; - resize( - c, + struct ClientGeometry client_geometry; + client_geometry_init_from_args( + &client_geometry, m->window_area_geometry.position.x + mw + left_gap, m->window_area_geometry.position.y + ty + top_gap, m->window_area_geometry.sizes.w - mw - 2 * border_width - left_gap - right_gap, h - 2 * border_width - top_gap - bottom_gap, - border_width, - 0 + border_width ); + resize(c, client_geometry, 0); + const int total_height = client_geometry_total_height(&c->state.geometry); diff --git a/src/state.c b/src/state.c index de42720..7cc3d9e 100644 --- a/src/state.c +++ b/src/state.c @@ -51,6 +51,31 @@ void client_state_init(const ClientState client_state) client_state->is_fullscreen = false; } +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; +} + +void client_geometry_init_from_args( + const ClientGeometry client_geometry, + int x, + int y, + int width, + int height, + int border_width +) { + position_init_from_args(&client_geometry->basic.position, x, y); + sizes_init_from_args(&client_geometry->basic.sizes, width, height); + client_geometry->border_width = border_width; +} + int client_geometry_total_width( const struct ClientGeometry *const client_geometry ) { @@ -63,6 +88,17 @@ int client_geometry_total_height( return client_geometry->basic.sizes.h + 2 * client_geometry->border_width; } +void client_geometry_to_x_window_changes( + const struct ClientGeometry *const client_geometry, + XWindowChanges *const x_window_changes +) { + x_window_changes->x = client_geometry->basic.position.x; + x_window_changes->y = client_geometry->basic.position.y; + x_window_changes->width = client_geometry->basic.sizes.w; + x_window_changes->height = client_geometry->basic.sizes.h; + x_window_changes->border_width = client_geometry->border_width; +} + void client_geometry_adjust_to_boundary( const ClientGeometry client_geometry, const struct BasicGeometry *const boundary_geometry diff --git a/src/state.h b/src/state.h index f197182..01eb04b 100644 --- a/src/state.h +++ b/src/state.h @@ -48,9 +48,9 @@ struct ClientState { bool is_fixed, is_floating, is_urgent, never_focus, is_fullscreen; }; -/************* - * Functions * - *************/ +/****************** + * Init functions * + ******************/ void position_init(Position position); void sizes_init(Sizes sizes); @@ -59,9 +59,30 @@ void client_geometry_init(ClientGeometry client_geometry); void client_size_hints_init(ClientSizeHints client_size_hints); void client_state_init(ClientState client_state); +void position_init_from_args(Position position, int x, int y); +void sizes_init_from_args(Sizes sizes, int width, int height); + +void client_geometry_init_from_args( + ClientGeometry client_geometry, + int x, + int y, + int width, + int height, + int border_width +); + +/************* + * Functions * + *************/ + int client_geometry_total_width(const struct ClientGeometry *client_geometry); int client_geometry_total_height(const struct ClientGeometry *client_geometry); +void client_geometry_to_x_window_changes( + const struct ClientGeometry *client_geometry, + XWindowChanges *x_window_changes +); + void client_geometry_adjust_to_boundary( ClientGeometry client_geometry, const struct BasicGeometry *boundary_geometry