diff --git a/src/dwm.c b/src/dwm.c index 36ddb6d..0b38b62 100644 --- a/src/dwm.c +++ b/src/dwm.c @@ -10,7 +10,6 @@ #include "unit.h" #include "util.h" -#include #include #include #include @@ -268,20 +267,20 @@ static void (*handler[LASTEvent])(XEvent*) = { #include "config.h" -/**************************** - * function implementations * - ****************************/ +/************************************ + * Private function implementations * + ************************************/ #include "dwm/handlers.c" #include "dwm/layouts.c" #include "dwm/xerror.c" +/*********************************** + * Public function implementations * + ***********************************/ + int dwm_main() { - if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) { - fputs("warning: no locale support\n", stderr); - } - if (!(dpy = XOpenDisplay(NULL))) { die("polytreewm: cannot open display"); } @@ -306,6 +305,15 @@ int dwm_main() return EXIT_SUCCESS; } +bool dwm_has_locale_support() +{ + return XSupportsLocale(); +} + +/************************************ + * Private function implementations * + ************************************/ + int applysizehints( Client *c, ClientGeometry client_geometry, diff --git a/src/dwm.h b/src/dwm.h index 988888b..49e987e 100644 --- a/src/dwm.h +++ b/src/dwm.h @@ -1,6 +1,9 @@ #ifndef _DWM_H #define _DWM_H +#include + int dwm_main(); +bool dwm_has_locale_support(); #endif // _DWM_H diff --git a/src/main.c b/src/main.c index fcf2689..7c14dae 100644 --- a/src/main.c +++ b/src/main.c @@ -2,6 +2,7 @@ #include "dwm.h" +#include #include #include #include @@ -18,6 +19,10 @@ int main(int argc, char *argv[]) die("usage: polytreewm [-v]"); } + if (!setlocale(LC_CTYPE, "") || !dwm_has_locale_support()) { + warning("no locale support"); + } + return dwm_main(argc, argv); } @@ -45,3 +50,15 @@ void die_perror(const char *const fmt, ...) exit(EXIT_FAILURE); } + +void warning(const char *const fmt, ...) +{ + fputs("WARN: ", stderr); + + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + fputc('\n', stderr); +} diff --git a/src/main.h b/src/main.h index 79699f8..f9a0d82 100644 --- a/src/main.h +++ b/src/main.h @@ -3,5 +3,6 @@ void die(const char *fmt, ...); void die_perror(const char *fmt, ...); +void warning(const char *fmt, ...); #endif // _MAIN_H