From a3deb9b0293a3185ed37bf23c6d9b5be43fb782f Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 21 Nov 2021 02:00:39 +0500 Subject: [PATCH] Replace macros WIDTH and HEIGHT --- src/dwm.c | 96 ++++++++++++++++++++++++++++++---------------- src/dwm/handlers.c | 12 +++++- src/dwm/layouts.c | 43 +++++++++++++++------ src/state.c | 12 ++++++ src/state.h | 3 ++ 5 files changed, 120 insertions(+), 46 deletions(-) diff --git a/src/dwm.c b/src/dwm.c index 7919539..aec605f 100644 --- a/src/dwm.c +++ b/src/dwm.c @@ -39,11 +39,6 @@ #define LENGTH(X) (sizeof(X) / sizeof(X[0])) #define MOUSEMASK (BUTTONMASK | PointerMotionMask) -#define WIDTH(X) \ - ((X)->state.geometry.basic.w + 2 * (X)->state.geometry.border_width) -#define HEIGHT(X) \ - ((X)->state.geometry.basic.h + 2 * (X)->state.geometry.border_width) - #define CLEANMASK(mask) ( \ (mask) & \ ~(numlockmask | LockMask) & \ @@ -308,10 +303,10 @@ int applysizehints( if (interact) { if (*x > sw) { - *x = sw - WIDTH(c); + *x = sw - client_geometry_total_width(&c->state.geometry); } if (*y > sh) { - *y = sh - HEIGHT(c); + *y = sh - client_geometry_total_height(&c->state.geometry); } if (*x + *w + 2 * bw < 0) { *x = 0; @@ -326,7 +321,7 @@ int applysizehints( + m->window_area_geometry.w - - WIDTH(c); + client_geometry_total_width(&c->state.geometry); } if (*y >= m->window_area_geometry.y + m->window_area_geometry.h) { *y = @@ -334,7 +329,7 @@ int applysizehints( + m->window_area_geometry.h - - HEIGHT(c); + client_geometry_total_height(&c->state.geometry); } if (*x + *w + 2 * bw <= m->window_area_geometry.x) { *x = m->window_area_geometry.x; @@ -889,22 +884,37 @@ void manage(Window w, XWindowAttributes *wa) } } - if ( - c->state.geometry.basic.x + WIDTH(c) - > - c->mon->screen_geometry.x + c->mon->screen_geometry.w - ) { - c->state.geometry.basic.x = - c->mon->screen_geometry.x + c->mon->screen_geometry.w - WIDTH(c); - } + { + const int total_width = client_geometry_total_width(&c->state.geometry); - if ( - c->state.geometry.basic.y + HEIGHT(c) - > - c->mon->screen_geometry.y + c->mon->screen_geometry.h - ) { - c->state.geometry.basic.y = - c->mon->screen_geometry.y + c->mon->screen_geometry.h - HEIGHT(c); + if ( + c->state.geometry.basic.x + total_width + > + c->mon->screen_geometry.x + c->mon->screen_geometry.w + ) { + c->state.geometry.basic.x = + c->mon->screen_geometry.x + + + c->mon->screen_geometry.w + - + total_width; + } + + const int total_height = + client_geometry_total_height(&c->state.geometry); + + if ( + c->state.geometry.basic.y + total_height + > + c->mon->screen_geometry.y + c->mon->screen_geometry.h + ) { + c->state.geometry.basic.y = + c->mon->screen_geometry.y + + + c->mon->screen_geometry.h + - + total_height; + } } c->state.geometry.basic.x = @@ -927,10 +937,20 @@ void manage(Window w, XWindowAttributes *wa) updatesizehints(c); updatewmhints(c); - c->state.geometry.basic.x = - c->mon->screen_geometry.x + (c->mon->screen_geometry.w - WIDTH(c)) / 2; - c->state.geometry.basic.y = - c->mon->screen_geometry.y + (c->mon->screen_geometry.h - HEIGHT(c)) / 2; + { + const int total_width = client_geometry_total_width(&c->state.geometry); + const int total_height = + client_geometry_total_height(&c->state.geometry); + + c->state.geometry.basic.x = + c->mon->screen_geometry.x + + + (c->mon->screen_geometry.w - total_width) / 2; + c->state.geometry.basic.y = + c->mon->screen_geometry.y + + + (c->mon->screen_geometry.h - total_height) / 2; + } XSelectInput( dpy, @@ -1044,12 +1064,17 @@ void movemouse(__attribute__((unused)) const Arg *arg) selmon->window_area_geometry.w ) - - (nx + WIDTH(c)) + (nx + client_geometry_total_width(&c->state.geometry)) ) < snap_distance ) { - nx = selmon->window_area_geometry.x + selmon->window_area_geometry.w - WIDTH(c); + nx = + selmon->window_area_geometry.x + + + selmon->window_area_geometry.w + - + client_geometry_total_width(&c->state.geometry); } if (abs(selmon->window_area_geometry.y - ny) < snap_distance) { @@ -1060,7 +1085,7 @@ void movemouse(__attribute__((unused)) const Arg *arg) selmon->window_area_geometry.y + selmon->window_area_geometry.h - ) - (ny + HEIGHT(c)) + ) - (ny + client_geometry_total_height(&c->state.geometry)) ) < snap_distance @@ -1070,7 +1095,7 @@ void movemouse(__attribute__((unused)) const Arg *arg) + selmon->window_area_geometry.h - - HEIGHT(c); + client_geometry_total_height(&c->state.geometry); } if (!c->state.is_floating && @@ -1710,7 +1735,12 @@ void showhide(Client *c) } else { /* hide clients bottom up */ showhide(c->snext); - XMoveWindow(dpy, c->win, WIDTH(c) * -2, c->state.geometry.basic.y); + XMoveWindow( + dpy, + c->win, + client_geometry_total_width(&c->state.geometry) * -2, + c->state.geometry.basic.y + ); } } diff --git a/src/dwm/handlers.c b/src/dwm/handlers.c index 1a13c93..71022da 100644 --- a/src/dwm/handlers.c +++ b/src/dwm/handlers.c @@ -99,7 +99,11 @@ void on_configure_request(XEvent *e) c->state.geometry.basic.x = m->screen_geometry.x + - (m->screen_geometry.w / 2 - WIDTH(c) / 2); + ( + m->screen_geometry.w / 2 + - + client_geometry_total_width(&c->state.geometry) / 2 + ); } if ( (c->state.geometry.basic.y + c->state.geometry.basic.h) @@ -112,7 +116,11 @@ void on_configure_request(XEvent *e) c->state.geometry.basic.y = m->screen_geometry.y + - (m->screen_geometry.h / 2 - HEIGHT(c) / 2); + ( + m->screen_geometry.h / 2 + - + client_geometry_total_height(&c->state.geometry) / 2 + ); } if ((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight))) { configure(c); diff --git a/src/dwm/layouts.c b/src/dwm/layouts.c index 845fa8d..2843524 100644 --- a/src/dwm/layouts.c +++ b/src/dwm/layouts.c @@ -57,7 +57,10 @@ void centeredmaster(Monitor *m) 0 ); - my += HEIGHT(c) + top_gap + bottom_gap; + const int total_height = + client_geometry_total_height(&c->state.geometry); + + my += total_height + top_gap + bottom_gap; } else { // stack clients are stacked vertically if ((i - m->nmaster) % 2) { @@ -79,7 +82,10 @@ void centeredmaster(Monitor *m) 0 ); - ety += HEIGHT(c) + top_gap + bottom_gap; + const int total_height = + client_geometry_total_height(&c->state.geometry); + + ety += total_height + top_gap + bottom_gap; } else { const unsigned int h = (m->window_area_geometry.h - oty) / ((1 + n - i) / 2); @@ -99,7 +105,10 @@ void centeredmaster(Monitor *m) 0 ); - oty += HEIGHT(c) + top_gap + bottom_gap; + const int total_height = + client_geometry_total_height(&c->state.geometry); + + oty += total_height + top_gap + bottom_gap; } } } @@ -169,9 +178,12 @@ void horizontile(Monitor *m) 0 ); + const int total_width = + client_geometry_total_width(&c->state.geometry); + // FIXME: maybe need + left_gap + right_gap - if (mx + WIDTH(c) < m->window_area_geometry.w) { - mx += WIDTH(c) + left_gap + right_gap; + if (mx + total_width < m->window_area_geometry.w) { + mx += total_width + left_gap + right_gap; } } else { const unsigned int w = (m->window_area_geometry.w - tx) / (n - i); @@ -191,9 +203,12 @@ void horizontile(Monitor *m) 0 ); + const int total_width = + client_geometry_total_width(&c->state.geometry); + // FIXME: maybe need + left_gap + right_gap - if (tx + WIDTH(c) < m->window_area_geometry.w) { - tx += WIDTH(c) + left_gap + right_gap; + if (tx + total_width < m->window_area_geometry.w) { + tx += total_width + left_gap + right_gap; } } } @@ -269,9 +284,12 @@ void tile(Monitor *m) 0 ); + const int total_height = + client_geometry_total_height(&c->state.geometry); + // FIXME: maybe need + top_gap + bottom_gap - if (my + HEIGHT(c) < m->window_area_geometry.h) { - my += HEIGHT(c) + top_gap + bottom_gap; + if (my + total_height < m->window_area_geometry.h) { + my += total_height + top_gap + bottom_gap; } } else { const unsigned int h = (m->window_area_geometry.h - ty) / (n - i); @@ -291,9 +309,12 @@ void tile(Monitor *m) 0 ); + const int total_height = + client_geometry_total_height(&c->state.geometry); + // FIXME: maybe need + top_gap + bottom_gap - if (ty + HEIGHT(c) < m->window_area_geometry.h) { - ty += HEIGHT(c) + top_gap + bottom_gap; + if (ty + total_height < m->window_area_geometry.h) { + ty += total_height + top_gap + bottom_gap; } } } diff --git a/src/state.c b/src/state.c index ad0d8e3..4cca6f6 100644 --- a/src/state.c +++ b/src/state.c @@ -41,6 +41,18 @@ void client_state_init(const ClientState client_state) client_state->is_fullscreen = false; } +int client_geometry_total_width( + const struct ClientGeometry *const client_geometry +) { + return client_geometry->basic.w + 2 * client_geometry->border_width; +} + +int client_geometry_total_height( + const struct ClientGeometry *const client_geometry +) { + return client_geometry->basic.h + 2 * client_geometry->border_width; +} + void client_size_hints_update( const ClientSizeHints size_hints, const XSizeHints *const size diff --git a/src/state.h b/src/state.h index 122e014..cd24f58 100644 --- a/src/state.h +++ b/src/state.h @@ -44,6 +44,9 @@ void client_geometry_init(ClientGeometry client_geometry); void client_size_hints_init(ClientSizeHints client_size_hints); 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_size_hints_update( ClientSizeHints size_hints, const XSizeHints *size