st

simple terminal
git clone https://git.parazyd.org/st
Log | Files | Refs | README | LICENSE

commit 6cca7457aa2251ce22e0ce49ad1dbf17bbf50ff0
parent 68d1ad9b54e952e3079356aeab8ab37e44c56c2c
Author: parazyd <parazyd@dyne.org>
Date:   Tue, 26 Apr 2022 20:30:01 +0200

invert

Diffstat:
Mconfig.def.h | 1+
Mx.c | 44+++++++++++++++++++++++++++++++++++++++++---
2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -201,6 +201,7 @@ static Shortcut shortcuts[] = { { TERMMOD, XK_Y, selpaste, {.i = 0} }, { ShiftMask, XK_Insert, selpaste, {.i = 0} }, { TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, + { TERMMOD, XK_X, invert, { } }, }; /* diff --git a/x.c b/x.c @@ -59,6 +59,7 @@ static void zoom(const Arg *); static void zoomabs(const Arg *); static void zoomreset(const Arg *); static void ttysend(const Arg *); +static void invert(const Arg *); /* config.h for applying patches and the configuration. */ #include "config.h" @@ -252,9 +253,32 @@ static char *opt_line = NULL; static char *opt_name = NULL; static char *opt_title = NULL; +static int invertcolors = 0; static uint buttons; /* bit field of pressed buttons */ void +invert(const Arg *dummy) +{ + invertcolors = !invertcolors; + redraw(); +} + +Color +invertedcolor(Color *clr) +{ + XRenderColor rc; + Color inverted; + + rc.red = ~clr->color.red; + rc.green = ~clr->color.green; + rc.blue = ~clr->color.blue; + rc.alpha = clr->color.alpha; + XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &rc, &inverted); + + return inverted; +} + +void clipcopy(const Arg *dummy) { Atom clipboard; @@ -851,9 +875,13 @@ xsetcolorname(int x, const char *name) void xclear(int x1, int y1, int x2, int y2) { - XftDrawRect(xw.draw, - &dc.col[IS_SET(MODE_REVERSE)? defaultfg : defaultbg], - x1, y1, x2-x1, y2-y1); + Color c; + + c = dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg]; + if (invertcolors) + c = invertedcolor(&c); + + XftDrawRect(xw.draw, &c, x1, y1, x2-x1, y2-y1); } void @@ -1463,6 +1491,13 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i if (base.mode & ATTR_INVISIBLE) fg = bg; + if (invertcolors) { + revfg = invertedcolor(fg); + revbg = invertedcolor(bg); + fg = &revfg; + bg = &revbg; + } + /* Intelligent cleaning up of the borders. */ if (x == 0) { xclear(0, (y == 0)? 0 : winy, borderpx, @@ -1555,6 +1590,9 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) drawcol = dc.col[g.bg]; } + if (invertcolors) + drawcol = invertedcolor(&drawcol); + /* draw the new one */ if (IS_SET(MODE_FOCUSED)) { switch (win.cursor) {