From 33346073112bb0192feb2069905307d00b3282f9 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Mon, 15 Nov 2021 09:05:57 +0500 Subject: [PATCH] Add settings "border_width" --- config.def.h | 1 - dwm.c | 59 ++++++++++++++++++++++++++++++++-------------------- settings.c | 12 +++++++++++ settings.h | 3 +++ 4 files changed, 51 insertions(+), 24 deletions(-) diff --git a/config.def.h b/config.def.h index 8f47841..8bb18a3 100644 --- a/config.def.h +++ b/config.def.h @@ -1,7 +1,6 @@ /* See LICENSE file for copyright and license details. */ /* appearance */ -static const unsigned int borderpx = 2; /* border pixel of windows */ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ static const char *fonts[] = { "monospace:size=10" }; diff --git a/dwm.c b/dwm.c index 15c5344..da20a59 100644 --- a/dwm.c +++ b/dwm.c @@ -460,11 +460,22 @@ arrangemon(Monitor *m) if (m->lt[m->sellt]->arrange) m->lt[m->sellt]->arrange(m); - else + else { + const int border_width = settings_get_border_width(); + /* <>< case; rather than providing an arrange function and upsetting other logic that tests for its presence, simply add borders here */ for (Client *c = selmon->clients; c; c = c->next) if (ISVISIBLE(c) && c->bw == 0) - resize(c, c->x, c->y, c->w - 2*borderpx, c->h - 2*borderpx, borderpx, 0); + resize( + c, + c->x, + c->y, + c->w - 2 * border_width, + c->h - 2 * border_width, + border_width, + 0 + ); + } } void @@ -556,7 +567,7 @@ centeredmaster(Monitor *m) const int top_left_half_gap = gap_size / 2; const int bottom_right_half_gap = gap_size - top_left_half_gap; - const unsigned int bw = n == 1 ? 0 : borderpx; + const int border_width = n == 1 ? 0 : settings_get_border_width(); unsigned int oty = 0, ety = 0, my = 0; Client *c = nexttiled(m->clients); @@ -575,9 +586,9 @@ centeredmaster(Monitor *m) c, m->wx + mx + left_gap, m->wy + my + top_gap, - mw - 2 * bw - left_gap - right_gap, - h - 2 * bw - top_gap - bottom_gap, - bw, + mw - 2 * border_width - left_gap - right_gap, + h - 2 * border_width - top_gap - bottom_gap, + border_width, 0 ); @@ -596,9 +607,9 @@ centeredmaster(Monitor *m) c, m->wx + left_gap, m->wy + ety + top_gap, - tw - 2 * bw - left_gap - right_gap, - h - 2 * bw - top_gap - bottom_gap, - bw, + tw - 2 * border_width - left_gap - right_gap, + h - 2 * border_width - top_gap - bottom_gap, + border_width, 0 ); @@ -615,9 +626,9 @@ centeredmaster(Monitor *m) c, m->wx + mx + mw + left_gap, m->wy + oty + top_gap, - tw - 2 * bw - left_gap - right_gap, - h - 2 * bw - top_gap - bottom_gap, - bw, + tw - 2 * border_width - left_gap - right_gap, + h - 2 * border_width - top_gap - bottom_gap, + border_width, 0 ); @@ -1338,7 +1349,7 @@ manage(Window w, XWindowAttributes *wa) : c->mon->my ); - c->bw = borderpx; + c->bw = settings_get_border_width(); { XWindowChanges wc; @@ -2189,7 +2200,7 @@ tile(Monitor *m) const int top_left_half_gap = gap_size / 2; const int bottom_right_half_gap = gap_size - top_left_half_gap; - const unsigned int bw = n == 1 ? 0 : borderpx; + const int border_width = n == 1 ? 0 : settings_get_border_width(); const unsigned int mw = n > m->nmaster ? (m->nmaster ? m->ww * m->mfact : 0) : m->ww; Client *c = nexttiled(m->clients); @@ -2206,9 +2217,9 @@ tile(Monitor *m) c, m->wx + left_gap, m->wy + my + top_gap, - mw - 2 * bw - left_gap - right_gap, - h - 2 * bw - top_gap - bottom_gap, - bw, + mw - 2 * border_width - left_gap - right_gap, + h - 2 * border_width - top_gap - bottom_gap, + border_width, 0 ); @@ -2227,9 +2238,9 @@ tile(Monitor *m) c, m->wx + mw + left_gap, m->wy + ty + top_gap, - m->ww - mw - 2 * bw - left_gap - right_gap, - h - 2 * bw - top_gap - bottom_gap, - bw, + m->ww - mw - 2 * border_width - left_gap - right_gap, + h - 2 * border_width - top_gap - bottom_gap, + border_width, 0 ); @@ -2267,14 +2278,16 @@ togglefloating(const Arg *arg) selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed; + const int border_width = settings_get_border_width(); + if (selmon->sel->isfloating) { resize( selmon->sel, selmon->sel->x, selmon->sel->y, - selmon->sel->w - 2 * (borderpx - selmon->sel->bw), - selmon->sel->h - 2 * (borderpx - selmon->sel->bw), - borderpx, + selmon->sel->w - 2 * (border_width - selmon->sel->bw), + selmon->sel->h - 2 * (border_width - selmon->sel->bw), + border_width, 0 ); } diff --git a/settings.c b/settings.c index 4577d14..bf78c01 100644 --- a/settings.c +++ b/settings.c @@ -1,5 +1,6 @@ #include "settings.h" +static int border_width = 2; static int default_clients_in_master = 1; static bool enable_gap_for_single_window = true; static bool focus_on_wheel = true; @@ -8,6 +9,17 @@ static int max_clients_in_master = 0; // 0 for no maximum static bool respect_resize_hints_in_floating_layout = false; static unsigned int snap_distance = 32; +int settings_get_border_width() +{ + return border_width; +} + +void settings_set_border_width(const int new_border_width) +{ + border_width = new_border_width; + // TODO: notify WM to rearrange clients +} + int settings_get_default_clients_in_master() { return default_clients_in_master >= 1 ? default_clients_in_master : 1; diff --git a/settings.h b/settings.h index 7661c85..9651310 100644 --- a/settings.h +++ b/settings.h @@ -3,6 +3,9 @@ #include +int settings_get_border_width(); +void settings_set_border_width(int new_border_width); + int settings_get_default_clients_in_master(); void settings_set_default_clients_in_master(int new_default_clients_in_master);