st-invert-0.8.2.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       st-invert-0.8.2.diff (2653B)
       ---
            1 From 1e4f29c34c3631e1d7350b02a199ae6000b33f6d Mon Sep 17 00:00:00 2001
            2 From: Miles Alan <m@milesalan.com>
            3 Date: Wed, 25 Mar 2020 21:40:10 -0500
            4 Subject: [PATCH] Add invert function which changes the current colors' RGB
            5  values to be inversed
            6 
            7 Bind invert function in example config.def.h to Ctrl-Shift-x
            8 ---
            9  config.def.h |  1 +
           10  x.c          | 37 ++++++++++++++++++++++++++++++++++---
           11  2 files changed, 35 insertions(+), 3 deletions(-)
           12 
           13 diff --git a/config.def.h b/config.def.h
           14 index 0e01717..6c7293c 100644
           15 --- a/config.def.h
           16 +++ b/config.def.h
           17 @@ -178,6 +178,7 @@ static Shortcut shortcuts[] = {
           18          { TERMMOD,              XK_Y,           selpaste,       {.i =  0} },
           19          { ShiftMask,            XK_Insert,      selpaste,       {.i =  0} },
           20          { TERMMOD,              XK_Num_Lock,    numlock,        {.i =  0} },
           21 +        { TERMMOD,              XK_X,           invert,         { }       },
           22  };
           23  
           24  /*
           25 diff --git a/x.c b/x.c
           26 index 0422421..7379969 100644
           27 --- a/x.c
           28 +++ b/x.c
           29 @@ -56,6 +56,7 @@ static void selpaste(const Arg *);
           30  static void zoom(const Arg *);
           31  static void zoomabs(const Arg *);
           32  static void zoomreset(const Arg *);
           33 +static void invert(const Arg *);
           34  
           35  /* config.h for applying patches and the configuration. */
           36  #include "config.h"
           37 @@ -238,8 +239,28 @@ static char *opt_line  = NULL;
           38  static char *opt_name  = NULL;
           39  static char *opt_title = NULL;
           40  
           41 +static int invertcolors = 0;
           42  static int oldbutton = 3; /* button event on startup: 3 = release */
           43  
           44 +void
           45 +invert(const Arg *dummy)
           46 +{
           47 +        invertcolors = !invertcolors;
           48 +        redraw();
           49 +}
           50 +
           51 +Color
           52 +invertedcolor(Color *clr) {
           53 +        XRenderColor rc;
           54 +        Color inverted;
           55 +        rc.red = ~clr->color.red;
           56 +        rc.green = ~clr->color.green;
           57 +        rc.blue = ~clr->color.blue;
           58 +        rc.alpha = clr->color.alpha;
           59 +        XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &rc, &inverted);
           60 +        return inverted;
           61 +}
           62 +
           63  void
           64  clipcopy(const Arg *dummy)
           65  {
           66 @@ -775,9 +796,12 @@ xsetcolorname(int x, const char *name)
           67  void
           68  xclear(int x1, int y1, int x2, int y2)
           69  {
           70 -        XftDrawRect(xw.draw,
           71 -                        &dc.col[IS_SET(MODE_REVERSE)? defaultfg : defaultbg],
           72 -                        x1, y1, x2-x1, y2-y1);
           73 +        Color c;
           74 +        c = dc.col[IS_SET(MODE_REVERSE)? defaultfg : defaultbg];
           75 +        if (invertcolors) {
           76 +                c = invertedcolor(&c);
           77 +        }
           78 +        XftDrawRect(xw.draw, &c, x1, y1, x2-x1, y2-y1);
           79  }
           80  
           81  void
           82 @@ -1347,6 +1371,13 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
           83          if (base.mode & ATTR_INVISIBLE)
           84                  fg = bg;
           85  
           86 +        if (invertcolors) {
           87 +                revfg = invertedcolor(fg);
           88 +                revbg = invertedcolor(bg);
           89 +                fg = &revfg;
           90 +                bg = &revbg;
           91 +        }
           92 +
           93          /* Intelligent cleaning up of the borders. */
           94          if (x == 0) {
           95                  xclear(0, (y == 0)? 0 : winy, borderpx,
           96 -- 
           97 2.23.1
           98