From c6275374b03ac4526a46f255f33ae2f81003d52b Mon Sep 17 00:00:00 2001 From: N-R-K <79544946+N-R-K@users.noreply.github.com> Date: Sat, 20 Nov 2021 09:51:49 +0600 Subject: mark functions and vars as static (#146) the goal here to mark functions and variables not used outside the translation unit as static. main reason for this is cleanliness. however as a side-effect this can help compilers optimize better as it now has guarantee that a certain function won't be called outside of that translation unit. one other side-effect of this is that accessing these vars/function from config.h is now different. if one wants to access a static var/func from different translation unit in config.h, he would have to create a wrapper function under the right ifdef. for static functions one would also need to forward declare it. here's a dummy example of accessing the function `run_key_handler` from config.h under _MAPPINGS_CONFIG ``` static void run_key_handler(const char *, unsigned); bool send_with_ctrl(arg_t key) { run_key_handler(XKeysymToString(key), ControlMask); return false; } ``` --- window.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'window.c') diff --git a/window.c b/window.c index c8c3455..7a04270 100644 --- a/window.c +++ b/window.c @@ -63,7 +63,7 @@ static int barheight; Atom atoms[ATOM_COUNT]; #if HAVE_LIBFONTS -void win_init_font(const win_env_t *e, const char *fontstr) +static void win_init_font(const win_env_t *e, const char *fontstr) { int fontheight = 0; if ((font = XftFontOpenName(e->dpy, e->scr, fontstr)) == NULL) @@ -74,21 +74,21 @@ void win_init_font(const win_env_t *e, const char *fontstr) XftFontClose(e->dpy, font); } -void xft_alloc_color(const win_env_t *e, const char *name, XftColor *col) +static void xft_alloc_color(const win_env_t *e, const char *name, XftColor *col) { if (!XftColorAllocName(e->dpy, e->vis, e->cmap, name, col)) error(EXIT_FAILURE, 0, "Error allocating color '%s'", name); } #endif /* HAVE_LIBFONTS */ -void win_alloc_color(const win_env_t *e, const char *name, XColor *col) +static void win_alloc_color(const win_env_t *e, const char *name, XColor *col) { XColor screen; if (!XAllocNamedColor(e->dpy, e->cmap, name, &screen, col)) error(EXIT_FAILURE, 0, "Error allocating color '%s'", name); } -const char* win_res(XrmDatabase db, const char *name, const char *def) +static const char* win_res(XrmDatabase db, const char *name, const char *def) { char *type; XrmValue ret; @@ -396,8 +396,8 @@ void win_clear(win_t *win) } #if HAVE_LIBFONTS -int win_draw_text(win_t *win, XftDraw *d, const XftColor *color, int x, int y, - char *text, int len, int w) +static int win_draw_text(win_t *win, XftDraw *d, const XftColor *color, + int x, int y, char *text, int len, int w) { int err, tw = 0; char *t, *next; @@ -430,7 +430,7 @@ int win_draw_text(win_t *win, XftDraw *d, const XftColor *color, int x, int y, return tw; } -void win_draw_bar(win_t *win) +static void win_draw_bar(win_t *win) { int len, x, y, w, tw; win_env_t *e; @@ -466,7 +466,7 @@ void win_draw_bar(win_t *win) XftDrawDestroy(d); } #else -void win_draw_bar(win_t *win){} +static void win_draw_bar(win_t *win){} #endif /* HAVE_LIBFONTS */ void win_draw(win_t *win) -- cgit v1.2.3-54-g00ecf