Move border and gap code to separate module "helpers"

This commit is contained in:
Alex Kotov 2021-11-16 06:20:19 +05:00
parent bf0295a721
commit 4992ee09c4
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
5 changed files with 59 additions and 76 deletions

View file

@ -3,7 +3,7 @@
include config.mk include config.mk
SRC = atoms.c drw.c dwm.c layouts.c settings.c spawn.c tags.c util.c SRC = atoms.c drw.c dwm.c helpers.c layouts.c settings.c spawn.c tags.c util.c
OBJ = ${SRC:.c=.o} OBJ = ${SRC:.c=.o}
all: options polytreewm all: options polytreewm
@ -18,7 +18,7 @@ options:
${CC} -c $< -o $@ ${CFLAGS} ${CC} -c $< -o $@ ${CFLAGS}
dwm.o: dwm/layouts.c dwm/swallow.c dwm/systray.c dwm.o: dwm/layouts.c dwm/swallow.c dwm/systray.c
${OBJ}: atoms.h drw.h config.def.h config.mk layouts.h settings.h spawn.h tags.h util.h ${OBJ}: atoms.h drw.h config.def.h config.mk helpers.h layouts.h settings.h spawn.h tags.h util.h
polytreewm: ${OBJ} polytreewm: ${OBJ}
${CC} -o $@ ${OBJ} ${LDFLAGS} ${CC} -o $@ ${OBJ} ${LDFLAGS}

1
dwm.c
View file

@ -48,6 +48,7 @@
#include "atoms.h" #include "atoms.h"
#include "drw.h" #include "drw.h"
#include "helpers.h"
#include "layouts.h" #include "layouts.h"
#include "settings.h" #include "settings.h"
#include "spawn.h" #include "spawn.h"

View file

@ -20,32 +20,8 @@ centeredmaster(Monitor *m)
} }
} }
const SettingsForSingleWindow gap_for_single_window = settings_get_gap_for_single_window(); const int gap_size = helpers_gap_size(n, m->sel->isfullscreen);
const SettingsForSingleWindow border_for_single_window = settings_get_border_for_single_window(); const int border_width = helpers_border_width(n, m->sel->isfullscreen);
const int gap_size = (
n > 1
||
gap_for_single_window == SETTINGS_FOR_SINGLE_WINDOW_ALWAYS
||
(
gap_for_single_window == SETTINGS_FOR_SINGLE_WINDOW_NOT_IN_FULLSCREEN
&&
!m->sel->isfullscreen
)
) ? settings_get_gap_size() : 0;
const int border_width = (
n > 1
||
border_for_single_window == SETTINGS_FOR_SINGLE_WINDOW_ALWAYS
||
(
border_for_single_window == SETTINGS_FOR_SINGLE_WINDOW_NOT_IN_FULLSCREEN
&&
!m->sel->isfullscreen
)
) ? settings_get_border_width() : 0;
const int top_left_half_gap = gap_size / 2; const int top_left_half_gap = gap_size / 2;
const int bottom_right_half_gap = gap_size - top_left_half_gap; const int bottom_right_half_gap = gap_size - top_left_half_gap;
@ -123,28 +99,8 @@ centeredmaster(Monitor *m)
void void
monocle(Monitor *m) monocle(Monitor *m)
{ {
const SettingsForSingleWindow gap_for_single_window = settings_get_gap_for_single_window(); const int gap_size = helpers_gap_size(1, m->sel->isfullscreen);
const SettingsForSingleWindow border_for_single_window = settings_get_border_for_single_window(); const int border_width = helpers_border_width(1, m->sel->isfullscreen);
const int gap_size = (
gap_for_single_window == SETTINGS_FOR_SINGLE_WINDOW_ALWAYS
||
(
gap_for_single_window == SETTINGS_FOR_SINGLE_WINDOW_NOT_IN_FULLSCREEN
&&
!m->sel->isfullscreen
)
) ? settings_get_gap_size() : 0;
const int border_width = (
border_for_single_window == SETTINGS_FOR_SINGLE_WINDOW_ALWAYS
||
(
border_for_single_window == SETTINGS_FOR_SINGLE_WINDOW_NOT_IN_FULLSCREEN
&&
!m->sel->isfullscreen
)
) ? settings_get_border_width() : 0;
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next)) { for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
resize( resize(
@ -166,32 +122,8 @@ tile(Monitor *m)
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n); for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next), ++n);
if (n == 0) return; if (n == 0) return;
const SettingsForSingleWindow gap_for_single_window = settings_get_gap_for_single_window(); const int gap_size = helpers_gap_size(n, m->sel->isfullscreen);
const SettingsForSingleWindow border_for_single_window = settings_get_border_for_single_window(); const int border_width = helpers_border_width(n, m->sel->isfullscreen);
const int gap_size = (
n > 1
||
gap_for_single_window == SETTINGS_FOR_SINGLE_WINDOW_ALWAYS
||
(
gap_for_single_window == SETTINGS_FOR_SINGLE_WINDOW_NOT_IN_FULLSCREEN
&&
!m->sel->isfullscreen
)
) ? settings_get_gap_size() : 0;
const int border_width = (
n > 1
||
border_for_single_window == SETTINGS_FOR_SINGLE_WINDOW_ALWAYS
||
(
border_for_single_window == SETTINGS_FOR_SINGLE_WINDOW_NOT_IN_FULLSCREEN
&&
!m->sel->isfullscreen
)
) ? settings_get_border_width() : 0;
const int top_left_half_gap = gap_size / 2; const int top_left_half_gap = gap_size / 2;
const int bottom_right_half_gap = gap_size - top_left_half_gap; const int bottom_right_half_gap = gap_size - top_left_half_gap;

41
helpers.c Normal file
View file

@ -0,0 +1,41 @@
#include "helpers.h"
#include "settings.h"
int helpers_gap_size(
const unsigned int displayed_clients,
const bool selected_is_fullscreen
) {
const SettingsForSingleWindow gap_for_single_window = settings_get_gap_for_single_window();
const int gap_size = settings_get_gap_size();
if (displayed_clients > 1) return gap_size;
switch (gap_for_single_window) {
case SETTINGS_FOR_SINGLE_WINDOW_NEVER:
return 0;
case SETTINGS_FOR_SINGLE_WINDOW_ALWAYS:
return gap_size;
case SETTINGS_FOR_SINGLE_WINDOW_NOT_IN_FULLSCREEN:
return selected_is_fullscreen ? 0 : gap_size;
}
}
int helpers_border_width(
const unsigned int displayed_clients,
const bool selected_is_fullscreen
) {
const SettingsForSingleWindow border_for_single_window = settings_get_border_for_single_window();
const int border_width = settings_get_border_width();
if (displayed_clients > 1) return border_width;
switch (border_for_single_window) {
case SETTINGS_FOR_SINGLE_WINDOW_NEVER:
return 0;
case SETTINGS_FOR_SINGLE_WINDOW_ALWAYS:
return border_width;
case SETTINGS_FOR_SINGLE_WINDOW_NOT_IN_FULLSCREEN:
return selected_is_fullscreen ? 0 : border_width;
}
}

9
helpers.h Normal file
View file

@ -0,0 +1,9 @@
#ifndef _HELPERS_H
#define _HELPERS_H
#include <stdbool.h>
int helpers_gap_size(unsigned int displayed_clients, bool selected_is_fullscreen);
int helpers_border_width(unsigned int displayed_clients, bool selected_is_fullscreen);
#endif // _HELPERS_H