From 59983981c21e3b655c6d1d523d4dd637e274c7d0 Mon Sep 17 00:00:00 2001 From: speedie Date: Fri, 23 Jun 2023 03:49:23 +0200 Subject: [PATCH] Rename libdrw functions to simply "draw" --- libs/define.c | 4 +- libs/draw.c | 58 ++++++------- libs/draw/draw.c | 206 +++++++++++++++++++++++----------------------- libs/draw/draw.h | 36 ++++---- libs/img.c | 20 ++--- libs/stream.c | 2 +- libs/wl/init.c | 4 +- libs/wl/wayland.c | 14 ++-- libs/x11/client.c | 4 +- libs/x11/event.c | 2 +- libs/x11/init.c | 8 +- spmenu.c | 10 +-- 12 files changed, 184 insertions(+), 184 deletions(-) diff --git a/libs/define.c b/libs/define.c index 3379a7d..08d9c40 100644 --- a/libs/define.c +++ b/libs/define.c @@ -3,8 +3,8 @@ #define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \ && MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org))) #define LENGTH(X) (sizeof X / sizeof X[0]) -#define TEXTW(X) (drw_font_getwidth(drw, (X), False) + sp.lrpad) -#define TEXTWM(X) (drw_font_getwidth(drw, (X), True) + sp.lrpad) +#define TEXTW(X) (draw_font_getwidth(draw, (X), False) + sp.lrpad) +#define TEXTWM(X) (draw_font_getwidth(draw, (X), True) + sp.lrpad) #define NUMBERSMAXDIGITS 100 #define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1 #define MAXITEMLENGTH 1024 diff --git a/libs/draw.c b/libs/draw.c index 44243aa..f62c4c4 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -21,8 +21,8 @@ void drawhighlights(struct item *item, int x, int y, int w, int p, const char *i // highlight character c = highlight[1]; highlight[1] = '\0'; - drw_text( - drw, + draw_text( + draw, x + indent + (p), y, MIN(w - indent - sp.lrpad, TEXTW(highlight) - sp.lrpad), @@ -118,9 +118,9 @@ int drawitemtext(struct item *item, int x, int y, int w) { if (!hidepowerline && powerlineitems && selitem) { if (itempwlstyle == 2) { - drw_circle(drw, x - sp.plw, y, sp.plw, sp.bh, 0, col_menu, bgcol, alpha_menu, bga); + draw_circle(draw, x - sp.plw, y, sp.plw, sp.bh, 0, col_menu, bgcol, alpha_menu, bga); } else { - drw_arrow(drw, x - sp.plw, y, sp.plw, sp.bh, 0, itempwlstyle, col_menu, bgcol, alpha_menu, bga); + draw_arrow(draw, x - sp.plw, y, sp.plw, sp.bh, 0, itempwlstyle, col_menu, bgcol, alpha_menu, bga); } } @@ -136,7 +136,7 @@ int drawitemtext(struct item *item, int x, int y, int w) { } apply_fribidi(buffer); - drw_text(drw, x, y, MIN(w, TEXTW(buffer) - sp.lrpad) + leftpadding, sp.bh, leftpadding, isrtl ? fribidi_text : buffer, 0, pango_item ? True : False, fgcol, bgcol, fga, bga); + draw_text(draw, x, y, MIN(w, TEXTW(buffer) - sp.lrpad) + leftpadding, sp.bh, leftpadding, isrtl ? fribidi_text : buffer, 0, pango_item ? True : False, fgcol, bgcol, fga, bga); drawhighlights(item, x, y, MIN(w, TEXTW(buffer) - sp.lrpad) + leftpadding, leftpadding, isrtl ? fribidi_text : buffer); // position and width @@ -255,7 +255,7 @@ int drawitemtext(struct item *item, int x, int y, int w) { // now draw any non-colored text apply_fribidi(buffer); - int r = drw_text(drw, x, y, w, sp.bh, leftpadding, isrtl ? fribidi_text : buffer, 0, pango_item ? True : False, fgcol, bgcol, fga, bga); + int r = draw_text(draw, x, y, w, sp.bh, leftpadding, isrtl ? fribidi_text : buffer, 0, pango_item ? True : False, fgcol, bgcol, fga, bga); if (!hidehighlight) drawhighlights(item, x, y, w, leftpadding, buffer); // copy current buffer to item->clntext instead of item->text, this way SGR sequences aren't drawn @@ -264,9 +264,9 @@ int drawitemtext(struct item *item, int x, int y, int w) { if (!hidepowerline && powerlineitems && selitem) { if (itempwlstyle == 2) { - drw_circle(drw, r, y, sp.plw, sp.bh, 1, col_menu, bgcol, alpha_menu, bga); + draw_circle(draw, r, y, sp.plw, sp.bh, 1, col_menu, bgcol, alpha_menu, bga); } else { - drw_arrow(drw, r, y, sp.plw, sp.bh, 1, itempwlstyle, col_menu, bgcol, alpha_menu, bga); + draw_arrow(draw, r, y, sp.plw, sp.bh, 1, itempwlstyle, col_menu, bgcol, alpha_menu, bga); } } @@ -378,13 +378,13 @@ int drawitem(int x, int y, int w) { int drawprompt(int x, int y, int w) { if (prompt && *prompt && !hideprompt) { - x = drw_text(drw, x, y, w, sp.bh, sp.lrpad / 2, prompt, 0, pango_prompt ? True : False, col_promptfg, col_promptbg, alpha_promptfg, alpha_promptbg); + x = draw_text(draw, x, y, w, sp.bh, sp.lrpad / 2, prompt, 0, pango_prompt ? True : False, col_promptfg, col_promptbg, alpha_promptfg, alpha_promptbg); if (!hidepowerline && powerlineprompt) { if (promptpwlstyle == 2) { - drw_circle(drw, x, y, sp.plw, sp.bh, 1, col_menu, col_promptbg, alpha_menu, alpha_promptbg); + draw_circle(draw, x, y, sp.plw, sp.bh, 1, col_menu, col_promptbg, alpha_menu, alpha_promptbg); } else { - drw_arrow(drw, x, y, sp.plw, sp.bh, 1, promptpwlstyle, col_menu, col_promptbg, alpha_menu, alpha_promptbg); + draw_arrow(draw, x, y, sp.plw, sp.bh, 1, promptpwlstyle, col_menu, col_promptbg, alpha_menu, alpha_promptbg); } x += sp.plw; @@ -404,7 +404,7 @@ int drawinput(int x, int y, int w) { if (fh > sp.bh) { fh = sp.bh; } else if (!fh) { - fh = drw->font->h; + fh = draw->font->h; } if (passwd) { @@ -414,21 +414,21 @@ int drawinput(int x, int y, int w) { memcpy(&censort[i], password, strlen(tx.text)); apply_fribidi(censort); - drw_text(drw, x, y, w, sp.bh, sp.lrpad / 2, isrtl ? fribidi_text : censort, 0, pango_password ? True : False, col_inputfg, col_inputbg, alpha_inputfg, alpha_inputbg); + draw_text(draw, x, y, w, sp.bh, sp.lrpad / 2, isrtl ? fribidi_text : censort, 0, pango_password ? True : False, col_inputfg, col_inputbg, alpha_inputfg, alpha_inputbg); curpos = TEXTW(censort) - TEXTW(&tx.text[sp.cursor]); free(censort); } else if (!passwd) { apply_fribidi(tx.text); - drw_text(drw, x, y, w, sp.bh, sp.lrpad / 2, isrtl ? fribidi_text : tx.text, 0, pango_input ? True : False, col_inputfg, col_inputbg, alpha_inputfg, alpha_inputbg); + draw_text(draw, x, y, w, sp.bh, sp.lrpad / 2, isrtl ? fribidi_text : tx.text, 0, pango_input ? True : False, col_inputfg, col_inputbg, alpha_inputfg, alpha_inputbg); curpos = TEXTW(tx.text) - TEXTW(&tx.text[sp.cursor]); } if ((curpos += sp.lrpad / 2 - 1) < w && !hidecaret) { curpos += fp; - drw_rect(drw, x + curpos, 2 + (sp.bh - fh) / 2 + y, fw, fh - 4, 1, 0, col_caretfg, col_caretbg, alpha_caretfg, alpha_caretbg); + draw_rect(draw, x + curpos, 2 + (sp.bh - fh) / 2 + y, fw, fh - 4, 1, 0, col_caretfg, col_caretbg, alpha_caretfg, alpha_caretbg); } return x; @@ -438,7 +438,7 @@ int drawlarrow(int x, int y, int w) { if (hidelarrow) return x; if (curr->left) { // draw left arrow - drw_text(drw, x, y, w, sp.bh, sp.lrpad / 2, leftarrow, 0, pango_leftarrow ? True : False, col_larrowfg, col_larrowbg, alpha_larrowfg, alpha_larrowbg); + draw_text(draw, x, y, w, sp.bh, sp.lrpad / 2, leftarrow, 0, pango_leftarrow ? True : False, col_larrowfg, col_larrowbg, alpha_larrowfg, alpha_larrowbg); x += w; } @@ -449,7 +449,7 @@ int drawrarrow(int x, int y, int w) { if (hiderarrow) return x; if (next) { // draw right arrow - drw_text(drw, sp.mw - w, y, w, sp.bh, sp.lrpad / 2, rightarrow, 0, pango_rightarrow ? True : False, col_rarrowfg, col_rarrowbg, alpha_rarrowfg, alpha_rarrowbg); + draw_text(draw, sp.mw - w, y, w, sp.bh, sp.lrpad / 2, rightarrow, 0, pango_rightarrow ? True : False, col_rarrowfg, col_rarrowbg, alpha_rarrowfg, alpha_rarrowbg); x += w; } @@ -465,14 +465,14 @@ int drawnumber(int x, int y, int w) { powerlinewidth = sp.plw / 2; } - drw_text(drw, x, y, w, sp.bh, sp.lrpad / 2 + powerlinewidth, tx.numbers, 0, pango_numbers ? True : False, col_numfg, col_numbg, alpha_numfg, alpha_numbg); + draw_text(draw, x, y, w, sp.bh, sp.lrpad / 2 + powerlinewidth, tx.numbers, 0, pango_numbers ? True : False, col_numfg, col_numbg, alpha_numfg, alpha_numbg); // draw powerline for match count if (!hidepowerline && powerlinecount) { if (matchcountpwlstyle == 2) { - drw_circle(drw, x, y, sp.plw, sp.bh, 0, col_menu, col_numbg, alpha_menu, alpha_numbg); + draw_circle(draw, x, y, sp.plw, sp.bh, 0, col_menu, col_numbg, alpha_menu, alpha_numbg); } else { - drw_arrow(drw, x, y, sp.plw, sp.bh, 0, matchcountpwlstyle, col_menu, col_numbg, alpha_menu, alpha_numbg); + draw_arrow(draw, x, y, sp.plw, sp.bh, 0, matchcountpwlstyle, col_menu, col_numbg, alpha_menu, alpha_numbg); } x += sp.plw; @@ -489,16 +489,16 @@ int drawmode(int x, int y, int w) { powerlinewidth = sp.plw / 2; } - drw_text(drw, x, y, w, sp.bh, sp.lrpad / 2 + powerlinewidth, tx.modetext, 0, pango_mode ? True : False, col_modefg, col_modebg, alpha_modefg, alpha_modebg); + draw_text(draw, x, y, w, sp.bh, sp.lrpad / 2 + powerlinewidth, tx.modetext, 0, pango_mode ? True : False, col_modefg, col_modebg, alpha_modefg, alpha_modebg); // draw powerline for match count if (!hidepowerline && powerlinemode) { if (modepwlstyle == 2) { - drw_circle(drw, x, y, sp.plw, sp.bh, 0, + draw_circle(draw, x, y, sp.plw, sp.bh, 0, hidematchcount ? col_menu : col_numbg, col_modebg, hidematchcount ? alpha_menu : alpha_numbg, alpha_modebg); } else { - drw_arrow(drw, x, y, sp.plw, sp.bh, 0, modepwlstyle, + draw_arrow(draw, x, y, sp.plw, sp.bh, 0, modepwlstyle, hidematchcount ? col_menu : col_numbg, col_modebg, hidematchcount ? alpha_menu : alpha_numbg, alpha_modebg); } @@ -520,16 +520,16 @@ int drawcaps(int x, int y, int w) { powerlinewidth = sp.plw / 2; } - drw_text(drw, x, y, w, sp.bh, sp.lrpad / 2 + powerlinewidth, tx.capstext, 0, pango_caps ? True : False, col_capsfg, col_capsbg, alpha_capsfg, alpha_capsbg); + draw_text(draw, x, y, w, sp.bh, sp.lrpad / 2 + powerlinewidth, tx.capstext, 0, pango_caps ? True : False, col_capsfg, col_capsbg, alpha_capsfg, alpha_capsbg); // draw powerline for caps lock indicator if (!hidepowerline && powerlinecaps) { if (capspwlstyle == 2) { - drw_circle(drw, x, y, sp.plw, sp.bh, 0, + draw_circle(draw, x, y, sp.plw, sp.bh, 0, hidemode ? hidematchcount ? col_menu : col_numbg : col_modebg, col_capsbg, hidemode ? hidematchcount ? alpha_menu : alpha_numbg : alpha_modebg, alpha_capsbg); } else { - drw_arrow(drw, x, y, sp.plw, sp.bh, 0, capspwlstyle, + draw_arrow(draw, x, y, sp.plw, sp.bh, 0, capspwlstyle, hidemode ? hidematchcount ? col_menu : col_numbg : col_modebg, col_capsbg, hidemode ? hidematchcount ? alpha_menu : alpha_numbg : alpha_modebg, alpha_capsbg); } @@ -580,10 +580,10 @@ void drawmenu(void) { void drawmenu_layer(void) { int x = 0, y = 0, w = 0; - sp.plw = hidepowerline ? 0 : drw->font->h / 2 + 1; // powerline size + sp.plw = hidepowerline ? 0 : draw->font->h / 2 + 1; // powerline size // draw menu first using menu scheme - drw_rect(drw, 0, 0, sp.mw, sp.mh, 1, 1, col_menu, col_menu, alpha_menu, alpha_menu); + draw_rect(draw, 0, 0, sp.mw, sp.mh, 1, 1, col_menu, col_menu, alpha_menu, alpha_menu); int numberWidth = 0; int modeWidth = 0; @@ -647,6 +647,6 @@ void drawmenu_layer(void) { #if USEIMAGE drawimage(); #endif - drw_map(drw, win, 0, 0, sp.mw, sp.mh); + draw_map(draw, win, 0, 0, sp.mw, sp.mh); #endif } diff --git a/libs/draw/draw.c b/libs/draw/draw.c index 879924f..6a513be 100644 --- a/libs/draw/draw.c +++ b/libs/draw/draw.c @@ -39,72 +39,72 @@ void cairo_set_source_hex(cairo_t* cr, const char *col, int alpha) { } #if USEX -Drw *drw_create_x11(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap, int protocol) { - Drw *drw = ecalloc(1, sizeof(Drw)); +Draw_t *draw_create_x11(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap, int protocol) { + Draw_t *draw = ecalloc(1, sizeof(Draw_t)); - drw->protocol = protocol; - drw->dpy = dpy; - drw->screen = screen; - drw->root = root; - drw->w = w; - drw->h = h; - drw->visual = visual; - drw->depth = depth; - drw->cmap = cmap; - drw->drawable = XCreatePixmap(dpy, root, w, h, depth); - drw->gc = XCreateGC(dpy, drw->drawable, 0, NULL); - XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter); + draw->protocol = protocol; + draw->dpy = dpy; + draw->screen = screen; + draw->root = root; + draw->w = w; + draw->h = h; + draw->visual = visual; + draw->depth = depth; + draw->cmap = cmap; + draw->drawable = XCreatePixmap(dpy, root, w, h, depth); + draw->gc = XCreateGC(dpy, draw->drawable, 0, NULL); + XSetLineAttributes(dpy, draw->gc, 1, LineSolid, CapButt, JoinMiter); - return drw; + return draw; } #endif #if USEWAYLAND -Drw *drw_create_wl(int protocol) { - Drw *drw = ecalloc(1, sizeof(Drw)); +Draw_t *draw_create_wl(int protocol) { + Draw_t *draw = ecalloc(1, sizeof(Draw_t)); - drw->protocol = protocol; + draw->protocol = protocol; - return drw; + return draw; } -void drw_create_surface_wl(Drw *drw, void *data, int32_t w, int32_t h) { - drw->data = data; - drw->w = w; - drw->h = h; - drw->surface = cairo_image_surface_create_for_data(drw->data, CAIRO_FORMAT_ARGB32, drw->w, drw->h, drw->w * 4); - drw->d = cairo_create(drw->surface); +void draw_create_surface_wl(Draw_t *draw, void *data, int32_t w, int32_t h) { + draw->data = data; + draw->w = w; + draw->h = h; + draw->surface = cairo_image_surface_create_for_data(draw->data, CAIRO_FORMAT_ARGB32, draw->w, draw->h, draw->w * 4); + draw->d = cairo_create(draw->surface); } #endif -void drw_resize(Drw *drw, unsigned int w, unsigned int h) { - if (!drw) +void draw_resize(Draw_t *draw, unsigned int w, unsigned int h) { + if (!draw) return; - drw->w = w; - drw->h = h; + draw->w = w; + draw->h = h; #if USEX - if (drw->drawable) - XFreePixmap(drw->dpy, drw->drawable); + if (draw->drawable) + XFreePixmap(draw->dpy, draw->drawable); - drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth); + draw->drawable = XCreatePixmap(draw->dpy, draw->root, w, h, draw->depth); #endif } -void drw_free(Drw *drw) { +void draw_free(Draw_t *draw) { #if USEX - if (!drw->protocol) { - XFreePixmap(drw->dpy, drw->drawable); - XFreeGC(drw->dpy, drw->gc); + if (!draw->protocol) { + XFreePixmap(draw->dpy, draw->drawable); + XFreeGC(draw->dpy, draw->gc); } #endif - drw_font_free(drw->font); - free(drw); + draw_font_free(draw->font); + free(draw); } -static Fnt *font_create(Drw *drw, const char *fontname) { +static Fnt *font_create(Draw_t *draw, const char *fontname) { Fnt *font; PangoFontMap *fontmap; PangoContext *context; @@ -116,7 +116,7 @@ static Fnt *font_create(Drw *drw, const char *fontname) { } font = ecalloc(1, sizeof(Fnt)); - font->dpy = drw->dpy; + font->dpy = draw->dpy; fontmap = pango_cairo_font_map_new(); context = pango_font_map_create_context(fontmap); @@ -141,25 +141,25 @@ void font_free(Fnt *font) { free(font); } -Fnt* drw_font_create(Drw* drw, char *font[], size_t fontcount) { - if (!drw || !font) +Fnt* draw_font_create(Draw_t* draw, char *font[], size_t fontcount) { + if (!draw || !font) return NULL; Fnt *fnt = NULL; - fnt = font_create(drw, *font); + fnt = font_create(draw, *font); - return (drw->font = fnt); + return (draw->font = fnt); } -void drw_font_free(Fnt *font) { +void draw_font_free(Fnt *font) { if (font) { font_free(font); } } -void drw_arrow(Drw *drw, int x, int y, unsigned int w, unsigned int h, int direction, int slash, char *prevcol, char *nextcol, int prevalpha, int nextalpha) { - if (!drw) +void draw_arrow(Draw_t *draw, int x, int y, unsigned int w, unsigned int h, int direction, int slash, char *prevcol, char *nextcol, int prevalpha, int nextalpha) { + if (!draw) return; x = direction ? x : x + w; @@ -169,10 +169,10 @@ void drw_arrow(Drw *drw, int x, int y, unsigned int w, unsigned int h, int direc cairo_surface_t *sf = NULL; - if (drw->protocol) { - sf = cairo_image_surface_create_for_data(drw->data, CAIRO_FORMAT_ARGB32, drw->w, drw->h, drw->w * 4); + if (draw->protocol) { + sf = cairo_image_surface_create_for_data(draw->data, CAIRO_FORMAT_ARGB32, draw->w, draw->h, draw->w * 4); } else { - sf = cairo_xlib_surface_create(drw->dpy, drw->drawable, drw->visual, drw->w, drw->h); + sf = cairo_xlib_surface_create(draw->dpy, draw->drawable, draw->visual, draw->w, draw->h); } cairo_t *cr = cairo_create(sf); @@ -194,16 +194,16 @@ void drw_arrow(Drw *drw, int x, int y, unsigned int w, unsigned int h, int direc cairo_surface_destroy(sf); } -void drw_circle(Drw *drw, int x, int y, unsigned int w, unsigned int h, int direction, char *prevcol, char *nextcol, int prevalpha, int nextalpha) { - if (!drw) +void draw_circle(Draw_t *draw, int x, int y, unsigned int w, unsigned int h, int direction, char *prevcol, char *nextcol, int prevalpha, int nextalpha) { + if (!draw) return; cairo_surface_t *sf = NULL; - if (drw->protocol) { - sf = cairo_image_surface_create_for_data(drw->data, CAIRO_FORMAT_ARGB32, drw->w, drw->h, drw->w * 4); + if (draw->protocol) { + sf = cairo_image_surface_create_for_data(draw->data, CAIRO_FORMAT_ARGB32, draw->w, draw->h, draw->w * 4); } else { - sf = cairo_xlib_surface_create(drw->dpy, drw->drawable, drw->visual, drw->w, drw->h); + sf = cairo_xlib_surface_create(draw->dpy, draw->drawable, draw->visual, draw->w, draw->h); } cairo_t *cr = cairo_create(sf); @@ -233,17 +233,17 @@ void drw_circle(Drw *drw, int x, int y, unsigned int w, unsigned int h, int dire cairo_surface_destroy(sf); } -void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert, char *fgcol, char *bgcol, int fgalpha, int bgalpha) { - if (!drw) { +void draw_rect(Draw_t *draw, int x, int y, unsigned int w, unsigned int h, int filled, int invert, char *fgcol, char *bgcol, int fgalpha, int bgalpha) { + if (!draw) { return; } cairo_surface_t *sf; - if (drw->protocol) { - sf = cairo_image_surface_create_for_data(drw->data, CAIRO_FORMAT_ARGB32, drw->w, drw->h, drw->w * 4); + if (draw->protocol) { + sf = cairo_image_surface_create_for_data(draw->data, CAIRO_FORMAT_ARGB32, draw->w, draw->h, draw->w * 4); } else { - sf = cairo_xlib_surface_create(drw->dpy, drw->drawable, drw->visual, drw->w, drw->h); + sf = cairo_xlib_surface_create(draw->dpy, draw->drawable, draw->visual, draw->w, draw->h); } cairo_t *cr = cairo_create(sf); @@ -266,7 +266,7 @@ void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled cairo_surface_destroy(sf); } -int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, Bool markup, char *fgcol, char *bgcol, int fgalpha, int bgalpha) { +int draw_text(Draw_t *draw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, Bool markup, char *fgcol, char *bgcol, int fgalpha, int bgalpha) { char buf[1024]; unsigned int ew = 0; @@ -274,7 +274,7 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned in int render = x || y || w || h; char *t; - if (!drw || !text || !drw->font) { + if (!draw || !text || !draw->font) { return 0; } @@ -284,28 +284,28 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned in x += lpad; w -= lpad; - if (drw->protocol) { - drw->surface = cairo_image_surface_create_for_data(drw->data, CAIRO_FORMAT_ARGB32, drw->w, drw->h, drw->w * 4); + if (draw->protocol) { + draw->surface = cairo_image_surface_create_for_data(draw->data, CAIRO_FORMAT_ARGB32, draw->w, draw->h, draw->w * 4); } else { - drw->surface = cairo_xlib_surface_create(drw->dpy, drw->drawable, drw->visual, drw->w, drw->h); + draw->surface = cairo_xlib_surface_create(draw->dpy, draw->drawable, draw->visual, draw->w, draw->h); } - drw->d = cairo_create(drw->surface); + draw->d = cairo_create(draw->surface); // draw bg - cairo_set_source_hex(drw->d, invert ? fgcol : bgcol, invert ? fgalpha : bgalpha); - cairo_set_operator(drw->d, CAIRO_OPERATOR_SOURCE); - cairo_rectangle(drw->d, x - lpad, y, w + lpad, h); - cairo_fill(drw->d); + cairo_set_source_hex(draw->d, invert ? fgcol : bgcol, invert ? fgalpha : bgalpha); + cairo_set_operator(draw->d, CAIRO_OPERATOR_SOURCE); + cairo_rectangle(draw->d, x - lpad, y, w + lpad, h); + cairo_fill(draw->d); } t = strdup(text); len = strlen(t); if (len) { - drw_font_getexts(drw->font, t, len, &ew, NULL, markup); + draw_font_getexts(draw->font, t, len, &ew, NULL, markup); // shorten text if necessary - for (len = MIN(len, sizeof(buf) - 1); len && ew > w; drw_font_getexts(drw->font, t, len, &ew, NULL, markup)) + for (len = MIN(len, sizeof(buf) - 1); len && ew > w; draw_font_getexts(draw->font, t, len, &ew, NULL, markup)) len--; if (len) { @@ -320,25 +320,25 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned in if (render) { if (markup) { - pango_layout_set_markup(drw->font->layout, buf, len); + pango_layout_set_markup(draw->font->layout, buf, len); } else { - pango_layout_set_text(drw->font->layout, buf, len); + pango_layout_set_text(draw->font->layout, buf, len); } - pango_layout_set_single_paragraph_mode(drw->font->layout, True); + pango_layout_set_single_paragraph_mode(draw->font->layout, True); // draw fg - cairo_set_source_hex(drw->d, fgcol, fgalpha); - cairo_move_to(drw->d, x, y + (h - drw->font->h) / 2); + cairo_set_source_hex(draw->d, fgcol, fgalpha); + cairo_move_to(draw->d, x, y + (h - draw->font->h) / 2); // update and show layout - pango_cairo_update_layout(drw->d, drw->font->layout); - pango_cairo_show_layout(drw->d, drw->font->layout); + pango_cairo_update_layout(draw->d, draw->font->layout); + pango_cairo_show_layout(draw->d, draw->font->layout); - cairo_set_operator(drw->d, CAIRO_OPERATOR_SOURCE); + cairo_set_operator(draw->d, CAIRO_OPERATOR_SOURCE); if (markup) // clear markup attributes - pango_layout_set_attributes(drw->font->layout, NULL); + pango_layout_set_attributes(draw->font->layout, NULL); } x += ew; @@ -349,25 +349,25 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned in return x + (render ? w : 0); } -void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) { - if (!drw) +void draw_map(Draw_t *draw, Window win, int x, int y, unsigned int w, unsigned int h) { + if (!draw) return; #if USEX - if (!drw->protocol) { - XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y); - XSync(drw->dpy, False); + if (!draw->protocol) { + XCopyArea(draw->dpy, draw->drawable, win, draw->gc, x, y, w, h, x, y); + XSync(draw->dpy, False); } #endif } -unsigned int drw_font_getwidth(Drw *drw, const char *text, Bool markup) { - if (!drw || !drw->font || !text) +unsigned int draw_font_getwidth(Draw_t *draw, const char *text, Bool markup) { + if (!draw || !draw->font || !text) return 0; - return drw_text(drw, 0, 0, 0, 0, 0, text, 0, markup, "#000000", "#000000", 255, 255); + return draw_text(draw, 0, 0, 0, 0, 0, text, 0, markup, "#000000", "#000000", 255, 255); } -void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h, Bool markup) { +void draw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h, Bool markup) { if (!font || !text) return; @@ -395,31 +395,31 @@ void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned in *h = font->h; } -void drw_set_img(Drw *drw, void *data, int w, int h) { - if (!w || !h || !drw) { +void draw_set_img(Draw_t *draw, void *data, int w, int h) { + if (!w || !h || !draw) { return; } - drw->img_data = data; - drw->img_surface = cairo_image_surface_create_for_data(drw->img_data, CAIRO_FORMAT_ARGB32, w, h, w * 4); + draw->img_data = data; + draw->img_surface = cairo_image_surface_create_for_data(draw->img_data, CAIRO_FORMAT_ARGB32, w, h, w * 4); } -void drw_img(Drw *drw, int x, int y) { - if (!drw) { +void draw_img(Draw_t *draw, int x, int y) { + if (!draw) { return; } - cairo_set_operator(drw->d, CAIRO_OPERATOR_OVER); + cairo_set_operator(draw->d, CAIRO_OPERATOR_OVER); - cairo_set_source_surface(drw->d, drw->img_surface, x, y); - cairo_mask_surface(drw->d, drw->img_surface, x, y); + cairo_set_source_surface(draw->d, draw->img_surface, x, y); + cairo_mask_surface(draw->d, draw->img_surface, x, y); - cairo_set_source_surface(drw->d, drw->surface, drw->w, drw->h); + cairo_set_source_surface(draw->d, draw->surface, draw->w, draw->h); } -unsigned int drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n, Bool markup) { +unsigned int draw_fontset_getwidth_clamp(Draw_t *draw, const char *text, unsigned int n, Bool markup) { unsigned int tmp = 0; - if (drw && drw->font && text && n) - tmp = drw_text(drw, 0, 0, 0, 0, 0, text, n, markup, "#000000", "#000000", 255, 255); + if (draw && draw->font && text && n) + tmp = draw_text(draw, 0, 0, 0, 0, 0, text, n, markup, "#000000", "#000000", 255, 255); return MIN(n, tmp); } diff --git a/libs/draw/draw.h b/libs/draw/draw.h index 3a08788..c1d953a 100644 --- a/libs/draw/draw.h +++ b/libs/draw/draw.h @@ -30,37 +30,37 @@ typedef struct { cairo_surface_t *img_surface; cairo_t *d; cairo_t *img_d; -} Drw; +} Draw_t; /* Cairo color convertion */ void cairo_set_source_hex(cairo_t* cr, const char *col, int alpha); /* Cairo image drawing */ -void drw_img(Drw *drw, int x, int y); -void drw_set_img(Drw *drw, void *data, int w, int h); +void draw_img(Draw_t *draw, int x, int y); +void draw_set_img(Draw_t *draw, void *data, int w, int h); /* Drawable abstraction */ -Drw *drw_create_x11(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap, int protocol); -Drw *drw_create_wl(int protocol); -void drw_create_surface_wl(Drw *drw, void *data, int32_t w, int32_t h); +Draw_t *draw_create_x11(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap, int protocol); +Draw_t *draw_create_wl(int protocol); +void draw_create_surface_wl(Draw_t *draw, void *data, int32_t w, int32_t h); -void drw_resize(Drw *drw, unsigned int w, unsigned int h); -void drw_free(Drw *drw); +void draw_resize(Draw_t *draw, unsigned int w, unsigned int h); +void draw_free(Draw_t *draw); /* Fnt abstraction */ -Fnt *drw_font_create(Drw* drw, char *font[], size_t fontcount); -void drw_font_free(Fnt* set); -unsigned int drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n, Bool markup); -unsigned int drw_font_getwidth(Drw *drw, const char *text, Bool markup); -void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h, Bool markup); +Fnt *draw_font_create(Draw_t* draw, char *font[], size_t fontcount); +void draw_font_free(Fnt* set); +unsigned int draw_fontset_getwidth_clamp(Draw_t *draw, const char *text, unsigned int n, Bool markup); +unsigned int draw_font_getwidth(Draw_t *draw, const char *text, Bool markup); +void draw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h, Bool markup); /* Drawing functions */ -void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert, char *fgcol, char *bgcol, int fgalpha, int bgalpha); -int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, Bool markup, char *fgcol, char *bgcol, int fgalpha, int bgalpha); +void draw_rect(Draw_t *draw, int x, int y, unsigned int w, unsigned int h, int filled, int invert, char *fgcol, char *bgcol, int fgalpha, int bgalpha); +int draw_text(Draw_t *draw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, Bool markup, char *fgcol, char *bgcol, int fgalpha, int bgalpha); /* Map functions */ -void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h); +void draw_map(Draw_t *draw, Window win, int x, int y, unsigned int w, unsigned int h); /* Powerline functions */ -void drw_arrow(Drw *drw, int x, int y, unsigned int w, unsigned int h, int direction, int slash, char *prevcol, char *nextcol, int prevalpha, int nextalpha); -void drw_circle(Drw *drw, int x, int y, unsigned int w, unsigned int h, int direction, char *prevcol, char *nextcol, int prevalpha, int nextalpha); +void draw_arrow(Draw_t *draw, int x, int y, unsigned int w, unsigned int h, int direction, int slash, char *prevcol, char *nextcol, int prevalpha, int nextalpha); +void draw_circle(Draw_t *draw, int x, int y, unsigned int w, unsigned int h, int direction, char *prevcol, char *nextcol, int prevalpha, int nextalpha); diff --git a/libs/img.c b/libs/img.c index 211bbd8..7fa63e1 100644 --- a/libs/img.c +++ b/libs/img.c @@ -68,11 +68,11 @@ void drawimage(void) { resizetoimageheight(width, imlib_image_get_height() - (fullscreen ? 2 * menumarginv : 0)); } - drw_set_img(drw, imlib_image_get_data(), width, height); + draw_set_img(draw, imlib_image_get_data(), width, height); if (fullscreen) { xta = wta = leftmargin = 0; - drw_img(drw, (imagewidth - width) / 2, 0); + draw_img(draw, (imagewidth - width) / 2, 0); if (sel) { limg = sel->image; @@ -88,17 +88,17 @@ void drawimage(void) { if (height > width) width = height; - drw_img(drw, leftmargin + (imagewidth - width) / 2 + xta, wta + leftmargin); + draw_img(draw, leftmargin + (imagewidth - width) / 2 + xta, wta + leftmargin); } else if (imageposition == 1 && image) { // bottom mode = 1 if (height > width) width = height; - drw_img(drw, leftmargin + (imagewidth - width) / 2 + xta, sp.mh - height - leftmargin); + draw_img(draw, leftmargin + (imagewidth - width) / 2 + xta, sp.mh - height - leftmargin); } else if (imageposition == 2 && image) { // center mode = 2 - drw_img(drw, leftmargin + (imagewidth - width) / 2 + xta, (sp.mh - wta - height) / 2 + wta); + draw_img(draw, leftmargin + (imagewidth - width) / 2 + xta, (sp.mh - wta - height) / 2 + wta); } else if (image) { // top center int minh = MIN(height, sp.mh - sp.bh - leftmargin * 2); - drw_img(drw, leftmargin + (imagewidth - width) / 2 + xta, (minh - height) / 2 + wta + leftmargin); + draw_img(draw, leftmargin + (imagewidth - width) / 2 + xta, (minh - height) / 2 + wta + leftmargin); } } @@ -424,7 +424,7 @@ void resizetoimageheight_x11(int imageheight) { } XMoveResizeWindow(dpy, win, x + sp.sp, y + sp.vp, sp.mw - 2 * sp.sp - borderwidth * 2, sp.mh); - drw_resize(drw, sp.mw - 2 * sp.sp - borderwidth, sp.mh); + draw_resize(draw, sp.mw - 2 * sp.sp - borderwidth, sp.mh); if (olines != lines) { struct item *item; @@ -476,8 +476,8 @@ void resizetoimageheight_wl(int imageheight) { state.buffer = create_buffer(&state); - if (drw == NULL) { - die("spmenu: drw == NULL"); + if (draw == NULL) { + die("spmenu: draw == NULL"); } if (state.buffer == NULL) { @@ -485,7 +485,7 @@ void resizetoimageheight_wl(int imageheight) { } set_layer_size(&state, state.width, state.height); - drw_create_surface_wl(drw, state.data, state.width, state.height); + draw_create_surface_wl(draw, state.data, state.width, state.height); drawmenu(); diff --git a/libs/stream.c b/libs/stream.c index 263f5f6..e448682 100644 --- a/libs/stream.c +++ b/libs/stream.c @@ -29,7 +29,7 @@ void readstdin(void) { if (!(items[i].text = strdup(buf))) die("spmenu: cannot strdup %u bytes:", strlen(buf) + 1); items[i].hp = arrayhas(hpitems, hplength, items[i].text); - drw_font_getexts(drw->font, buf, strlen(buf), &tmpmax, NULL, True); + draw_font_getexts(draw->font, buf, strlen(buf), &tmpmax, NULL, True); if (tmpmax > sp.inputw) { sp.inputw = tmpmax; } diff --git a/libs/wl/init.c b/libs/wl/init.c index 79429ec..9e2a487 100644 --- a/libs/wl/init.c +++ b/libs/wl/init.c @@ -4,13 +4,13 @@ void prepare_window_size_wl(void) { sp.sp = menupaddingh; sp.vp = (menuposition == 1) ? menupaddingv : - menupaddingv; - sp.bh = MAX(drw->font->h, drw->font->h + 2 + lineheight); + sp.bh = MAX(draw->font->h, draw->font->h + 2 + lineheight); lines = MAX(lines, 0); #if USEIMAGE img.setlines = lines; #endif - sp.lrpad = drw->font->h + textpadding; + sp.lrpad = draw->font->h + textpadding; return; } diff --git a/libs/wl/wayland.c b/libs/wl/wayland.c index edbface..75e774b 100644 --- a/libs/wl/wayland.c +++ b/libs/wl/wayland.c @@ -429,15 +429,15 @@ void draw_sf(struct state *state) { // create buffer to draw on state->buffer = create_buffer(state); - if (drw == NULL) { - die("spmenu: drw == NULL"); + if (draw == NULL) { + die("spmenu: draw == NULL"); } if (state->buffer == NULL) { die("state->buffer == NULL"); } - drw_create_surface_wl(drw, state->data, state->width, state->height); + draw_create_surface_wl(draw, state->data, state->width, state->height); drawmenu_layer(); @@ -540,7 +540,7 @@ void resizeclient_wl(struct state *state) { for (item = items; item && item->text; item++) ic++; - sp.bh = MAX(drw->font->h, drw->font->h + 2 + lineheight); + sp.bh = MAX(draw->font->h, draw->font->h + 2 + lineheight); lines = MIN(ic, MAX(lines, 0)); #if USEIMAGE img.setlines = lines; @@ -560,15 +560,15 @@ void resizeclient_wl(struct state *state) { state->buffer = create_buffer(state); - if (drw == NULL) { - die("spmenu: drw == NULL"); + if (draw == NULL) { + die("spmenu: draw == NULL"); } if (state->buffer == NULL) { die("state->buffer == null"); } - drw_create_surface_wl(drw, state->data, state->width, state->height); + draw_create_surface_wl(draw, state->data, state->width, state->height); set_layer_size(state, state->width, state->height); wl_surface_set_buffer_scale(state->surface, 1); diff --git a/libs/x11/client.c b/libs/x11/client.c index d9247c4..9c9636b 100644 --- a/libs/x11/client.c +++ b/libs/x11/client.c @@ -87,7 +87,7 @@ void resizeclient_x11(void) { for (item = items; item && item->text; item++) ic++; - sp.bh = MAX(drw->font->h, drw->font->h + 2 + lineheight); + sp.bh = MAX(draw->font->h, draw->font->h + 2 + lineheight); lines = MIN(ic, MAX(lines, 0)); #if USEIMAGE img.setlines = lines; @@ -165,7 +165,7 @@ void resizeclient_x11(void) { if (!win || mh == sp.mh) return; XMoveResizeWindow(dpy, win, x + sp.sp, y + sp.vp, sp.mw - 2 * sp.sp - borderwidth * 2, sp.mh); - drw_resize(drw, sp.mw - 2 * sp.sp - borderwidth * 2, sp.mh); + draw_resize(draw, sp.mw - 2 * sp.sp - borderwidth * 2, sp.mh); } void xinitvisual(void) { diff --git a/libs/x11/event.c b/libs/x11/event.c index 7737f58..ff11309 100644 --- a/libs/x11/event.c +++ b/libs/x11/event.c @@ -19,7 +19,7 @@ void eventloop_x11(void) { break; case Expose: if (ev.xexpose.count == 0) - drw_map(drw, win, 0, 0, sp.mw, sp.mh); + draw_map(draw, win, 0, 0, sp.mw, sp.mh); break; case FocusIn: // regrab focus from parent window diff --git a/libs/x11/init.c b/libs/x11/init.c index ef84423..8d15188 100644 --- a/libs/x11/init.c +++ b/libs/x11/init.c @@ -119,7 +119,7 @@ void setupdisplay_x11(void) { } // resize window and draw - drw_resize(drw, sp.mw - 2 * sp.sp - borderwidth * 2, sp.mh); + draw_resize(draw, sp.mw - 2 * sp.sp - borderwidth * 2, sp.mh); match(); drawmenu(); @@ -129,13 +129,13 @@ void prepare_window_size_x11(void) { sp.sp = menupaddingh; sp.vp = (menuposition == 1) ? menupaddingv : - menupaddingv; - sp.bh = MAX(drw->font->h, drw->font->h + 2 + lineheight); + sp.bh = MAX(draw->font->h, draw->font->h + 2 + lineheight); lines = MAX(lines, 0); #if USEIMAGE img.setlines = lines; #endif - sp.lrpad = drw->font->h + textpadding; + sp.lrpad = draw->font->h + textpadding; get_mh(); return; @@ -174,7 +174,7 @@ void handle_x11(void) { } xinitvisual(); // init visual and create drawable after - drw = drw_create_x11(dpy, x11.screen, root, wa.width, wa.height, x11.visual, x11.depth, x11.cmap, protocol); + draw = draw_create_x11(dpy, x11.screen, root, wa.width, wa.height, x11.visual, x11.depth, x11.cmap, protocol); } void cleanup_x11(Display *disp) { diff --git a/spmenu.c b/spmenu.c index 52c4417..22aaec0 100644 --- a/spmenu.c +++ b/spmenu.c @@ -190,7 +190,7 @@ static struct item *prev, *curr, *next, *sel; #include "libs/sort.h" #include "libs/history.h" -static Drw *drw; +static Draw_t *draw; // high priority static int hplength = 0; @@ -382,7 +382,7 @@ void cleanup(void) { free(hpitems[i]); // free drawing and close the display - drw_free(drw); + draw_free(draw); #if USEX if (!protocol) { @@ -509,7 +509,7 @@ void handle(void) { #if USEX handle_x11(); - if (!drw_font_create(drw, fonts, LENGTH(fonts))) { + if (!draw_font_create(draw, fonts, LENGTH(fonts))) { die("no fonts could be loaded."); } @@ -547,9 +547,9 @@ void handle(void) { borderwidth = 0; managed = 0; - drw = drw_create_wl(protocol); + draw = draw_create_wl(protocol); - if (!drw_font_create(drw, fonts, LENGTH(fonts))) { + if (!draw_font_create(draw, fonts, LENGTH(fonts))) { die("no fonts could be loaded."); }