diff --git a/docs/code-docs.md b/docs/code-docs.md index c0dc65e..48e93e6 100644 --- a/docs/code-docs.md +++ b/docs/code-docs.md @@ -46,6 +46,8 @@ codebase easier to understand and make changes to. Also note that this is - Width of the prompt text, this is going to be the same as `TEXTW(prompt)`. - `inputw` - Width of the input text. +- `fh` + - Font height. Used to calculate the height of the cursor. See `drawcaret()`. - `menuposition` - Integer the user is meant to configure. If it's set to `0`, spmenu will be put on the bottom of the screen. If it's set to `1` it will be put on the @@ -89,3 +91,77 @@ codebase easier to understand and make changes to. Also note that this is - `curpos` - Cursor/caret position. When text is added to the input, the width of that text is added to this. + +## Drawable abstraction functions + +Most of these are in `libs/sl/draw.c` and `libs/sl/draw.h`. + +- `drw_create(Display *dpy, int screen, Window win, unsigned int w, +unsigned int h, Visual *visual, unsigned int depth, Colormap cmap);` + - This function creates a drawable from `Display *dpy`, `Drw`. Think of + it as a canvas. +- `drw_resize(Drw *drw, unsigned int w, unsigned int h)` + - This function resizes the drawable to the dimensions passed as + arguments (`w`, `h`). +- `drw_free(Drw *drw);` + - This function will free the drawable from memory. It is *usually* called in + cleanup functions like `cleanup()` so most of the time you don't need to use this. + +## Font abstraction functions + +Most of these are in `libs/sl/draw.c` and `libs/sl/draw.h`. +NOTE: These will differ slightly depending on if Pango is enabled or not. + +- `drw_font_create(Drw* drw, char *font[], size_t fontcount);` + - This function will return a font libXft can use. +- `drw_font_free(Fnt *set);` + - This function will free the font from memory. +- `drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n, Bool markup);` + - This function returns the smallest value out of the passed argument `n` + and the length of the text drawn. The text is not actually drawn though. +- `drw_font_getwidth(Drw *drw, const char *text, Bool markup);` + - This function returns the width of drawn text. The text is not actually + drawn though. +- `drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned + int *w, unsigned int *h, Bool markup);` + - This function returns the length of the text with the used font. + +## Colorscheme abstraction functions + +- `drw_clr_create(Drw *drw, Clr *dest, char *clrname, unsigned int alpha);` + - This function allocates space for a color. +- `drw_scm_create(Drw *drw, char *clrnames[], unsigned int alphas[], +size_t clrcount);` + - This function returns a color scheme from an array of colors and alpha. + +## Cursor abstraction functions + +- `drw_cur_create(Drw *drw, int shape);` + - This function creates and returns a cursor. +- `drw_cur_free(Drw *drw, Cur *cursor);` + - This function will free the cursor from memory. + +## Drawable context functions + +- ~~`drw_setfont(Drw *drw, Fnt *set);` + - Sets the font. + - NOTE: Applies only if Pango is disabled.~~ + - Removed, no longer necessary. +- `drw_setscheme(Drw *drw, Clr *scm);` + - Sets the color scheme to `*scm` created by `drw_scm_create()` + +## Drawing functions + +- `drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled +, int invert);` + - Draws a simple rectangle. Used in other functions to create more useful + shapes, such as a cursor. +- `drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned +int lpad, const char *text, int invert, Bool markup);` + - Draws text on the drawable using the font created. `const char *text` + contains the text itself. + +## Map functions + +- `drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h);` + - Maps the drawable. (makes it visible) diff --git a/libs/sl/draw.c b/libs/sl/draw.c index 131ba7b..2e79b20 100644 --- a/libs/sl/draw.c +++ b/libs/sl/draw.c @@ -128,7 +128,7 @@ xfont_create(Drw *drw, const char *fontname) PangoFontMetrics *metrics; if (!fontname) { - die("no font specified."); + die("spmenu: no font specified."); } font = ecalloc(1, sizeof(Fnt)); @@ -189,11 +189,11 @@ xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) } } else if (fontpattern) { if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) { - fprintf(stderr, "error, cannot load font from pattern.\n"); + fprintf(stderr, "spmenu: cannot load font from pattern.\n"); return NULL; } } else { - die("no font specified."); + die("spmenu: no font specified."); } font = ecalloc(1, sizeof(Fnt)); @@ -261,7 +261,7 @@ drw_clr_create(Drw *drw, Clr *dest, char *clrname, unsigned int alpha) if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap, clrname, dest)) - die("error, cannot allocate color '%s'", clrname); + die("spmenu: cannot allocate color '%s'", clrname); dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24); } @@ -493,7 +493,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp if (!drw->font->pattern) { /* Refer to the comment in xfont_create for more information. */ - die("the first font in the cache must be loaded from a font string."); + die("spmenu: the first font in the cache must be loaded from a font string."); } fcpattern = FcPatternDuplicate(drw->font->pattern); @@ -562,7 +562,7 @@ drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, else pango_layout_set_text(font->layout, text, len); pango_layout_get_extents(font->layout, 0, &r); - if(markup) /* clear markup attributes */ + if(markup) // clear markup attributes pango_layout_set_attributes(font->layout, NULL); #else XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext); diff --git a/scripts/make/generate-code-docs.sh b/scripts/make/generate-code-docs.sh new file mode 100755 index 0000000..5849696 --- /dev/null +++ b/scripts/make/generate-code-docs.sh @@ -0,0 +1,6 @@ +#!/bin/sh +VERSION="$([ -f "Makefile" ] && grep "VERSION" Makefile | head -n 1 | awk '{ print $3 }' || printf "unknown\n")" +[ ! -f "$1" ] && printf "You must specify an input file.\n" && exit 1 +[ -z "$2" ] && printf "You must specify an output file.\n" && exit 1 +pandoc -f markdown -t html5 --metadata title="spmenu documentation $VERSION" -s --toc -o "$2" "$1" || exit 1 +exit 0