st-invert-0.8.4.diff - sites - public wiki contents of suckless.org | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
st-invert-0.8.4.diff (2845B) | |
--- | |
1 From 9a6f20cd810e7c556534ba76f379573212c2dc66 Mon Sep 17 00:00:00 2001 | |
2 From: Miles Alan <[email protected]> | |
3 Date: Wed, 24 Mar 2021 20:22:30 -0500 | |
4 Subject: [PATCH] Add invert function which changes the current colors' R… | |
5 values to be inversed | |
6 | |
7 --- | |
8 config.def.h | 1 + | |
9 x.c | 39 ++++++++++++++++++++++++++++++++++++--- | |
10 2 files changed, 37 insertions(+), 3 deletions(-) | |
11 | |
12 diff --git a/config.def.h b/config.def.h | |
13 index 6f05dce..8669717 100644 | |
14 --- a/config.def.h | |
15 +++ b/config.def.h | |
16 @@ -199,6 +199,7 @@ static Shortcut shortcuts[] = { | |
17 { TERMMOD, XK_Y, selpaste, {.i = … | |
18 { ShiftMask, XK_Insert, selpaste, {.i = … | |
19 { TERMMOD, XK_Num_Lock, numlock, {.i = … | |
20 + { TERMMOD, XK_X, invert, { } … | |
21 }; | |
22 | |
23 /* | |
24 diff --git a/x.c b/x.c | |
25 index 210f184..3dd9f3d 100644 | |
26 --- a/x.c | |
27 +++ b/x.c | |
28 @@ -59,6 +59,7 @@ static void zoom(const Arg *); | |
29 static void zoomabs(const Arg *); | |
30 static void zoomreset(const Arg *); | |
31 static void ttysend(const Arg *); | |
32 +static void invert(const Arg *); | |
33 | |
34 /* config.h for applying patches and the configuration. */ | |
35 #include "config.h" | |
36 @@ -252,8 +253,28 @@ static char *opt_line = NULL; | |
37 static char *opt_name = NULL; | |
38 static char *opt_title = NULL; | |
39 | |
40 +static int invertcolors = 0; | |
41 static int oldbutton = 3; /* button event on startup: 3 = release */ | |
42 | |
43 +void | |
44 +invert(const Arg *dummy) | |
45 +{ | |
46 + invertcolors = !invertcolors; | |
47 + redraw(); | |
48 +} | |
49 + | |
50 +Color | |
51 +invertedcolor(Color *clr) { | |
52 + XRenderColor rc; | |
53 + Color inverted; | |
54 + rc.red = ~clr->color.red; | |
55 + rc.green = ~clr->color.green; | |
56 + rc.blue = ~clr->color.blue; | |
57 + rc.alpha = clr->color.alpha; | |
58 + XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &rc, &inverted); | |
59 + return inverted; | |
60 +} | |
61 + | |
62 void | |
63 clipcopy(const Arg *dummy) | |
64 { | |
65 @@ -820,9 +841,11 @@ xsetcolorname(int x, const char *name) | |
66 void | |
67 xclear(int x1, int y1, int x2, int y2) | |
68 { | |
69 - XftDrawRect(xw.draw, | |
70 - &dc.col[IS_SET(MODE_REVERSE)? defaultfg : defau… | |
71 - x1, y1, x2-x1, y2-y1); | |
72 + Color c; | |
73 + c = dc.col[IS_SET(MODE_REVERSE)? defaultfg : defaultbg]; | |
74 + if (invertcolors) | |
75 + c = invertedcolor(&c); | |
76 + XftDrawRect(xw.draw, &c, x1, y1, x2-x1, y2-y1); | |
77 } | |
78 | |
79 void | |
80 @@ -1431,6 +1454,13 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs… | |
81 if (base.mode & ATTR_INVISIBLE) | |
82 fg = bg; | |
83 | |
84 + if (invertcolors) { | |
85 + revfg = invertedcolor(fg); | |
86 + revbg = invertedcolor(bg); | |
87 + fg = &revfg; | |
88 + bg = &revbg; | |
89 + } | |
90 + | |
91 /* Intelligent cleaning up of the borders. */ | |
92 if (x == 0) { | |
93 xclear(0, (y == 0)? 0 : winy, borderpx, | |
94 @@ -1523,6 +1553,9 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int o… | |
95 drawcol = dc.col[g.bg]; | |
96 } | |
97 | |
98 + if (invertcolors) | |
99 + drawcol = invertedcolor(&drawcol); | |
100 + | |
101 /* draw the new one */ | |
102 if (IS_SET(MODE_FOCUSED)) { | |
103 switch (win.cursor) { | |
104 -- | |
105 2.26.2 | |
106 |