From d26b46ffa78e0562aed6c10911ff43cd8bcf8f2b Mon Sep 17 00:00:00 2001 From: bakkeby Date: Sun, 29 Mar 2020 15:38:16 +0200 Subject: [PATCH] Adding invert patch --- README.md | 6 ++++++ config.def.h | 3 +++ patch/invert.c | 21 +++++++++++++++++++++ patch/invert.h | 1 + patch/x_include.c | 3 +++ patch/x_include.h | 3 +++ patches.def.h | 7 +++++++ x.c | 18 ++++++++++++++++++ 8 files changed, 62 insertions(+) create mode 100644 patch/invert.c create mode 100644 patch/invert.h diff --git a/README.md b/README.md index 2d2f3a4..2e45d54 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the ### Changelog: +2020-03-29 - Added invert patch + 2020-03-24 - Upgraded to latest (master) of st (commit 51e19ea11dd42eefed1ca136ee3f6be975f618b1 at the time of writing). Custom changes to make the altscreen mouse scollback patch working. 2020-03-21 - Added font2 patch @@ -69,6 +71,10 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the - [hidecursor](https://st.suckless.org/patches/hidecursor/) - hides the X cursor whenever a key is pressed and show it back when the mouse is moved in the terminal window + - [invert](https://st.suckless.org/patches/invert/) + - adds a keybinding that lets you invert the current colorscheme of st + - this provides a simple way to temporarily switch to a light colorscheme if you use a dark colorscheme or visa-versa + - [iso14755](https://st.suckless.org/patches/iso14755/) - pressing the default binding Ctrl+Shift-i will popup dmenu, asking you to enter a unicode codepoint that will be converted to a glyph and then pushed to st diff --git a/config.def.h b/config.def.h index 4fd5bfc..959a90c 100644 --- a/config.def.h +++ b/config.def.h @@ -358,6 +358,9 @@ static Shortcut shortcuts[] = { #if ISO14755_PATCH { TERMMOD, XK_I, iso14755, {.i = 0} }, #endif // ISO14755_PATCH + #if INVERT_PATCH + { TERMMOD, XK_X, invert, { 0 } }, + #endif // INVERT_PATCH }; /* diff --git a/patch/invert.c b/patch/invert.c new file mode 100644 index 0000000..2260b5d --- /dev/null +++ b/patch/invert.c @@ -0,0 +1,21 @@ +static int invertcolors = 0; + +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; +} \ No newline at end of file diff --git a/patch/invert.h b/patch/invert.h new file mode 100644 index 0000000..0b0931f --- /dev/null +++ b/patch/invert.h @@ -0,0 +1 @@ +static void invert(const Arg *); \ No newline at end of file diff --git a/patch/x_include.c b/patch/x_include.c index bd32652..32373cc 100644 --- a/patch/x_include.c +++ b/patch/x_include.c @@ -11,6 +11,9 @@ #if FONT2_PATCH #include "font2.c" #endif +#if INVERT_PATCH +#include "invert.c" +#endif #if KEYBOARDSELECT_PATCH #include "keyboardselect_x.c" #endif diff --git a/patch/x_include.h b/patch/x_include.h index 7115db2..3e2ea0d 100644 --- a/patch/x_include.h +++ b/patch/x_include.h @@ -8,6 +8,9 @@ #if FONT2_PATCH #include "font2.h" #endif +#if INVERT_PATCH +#include "invert.h" +#endif #if KEYBOARDSELECT_PATCH #include "keyboardselect_x.h" #endif diff --git a/patches.def.h b/patches.def.h index 9f55d48..92ac931 100644 --- a/patches.def.h +++ b/patches.def.h @@ -88,6 +88,13 @@ */ #define HIDECURSOR_PATCH 0 +/* This patch adds a keybinding that lets you invert the current colorscheme of st. + * This provides a simple way to temporarily switch to a light colorscheme if you use a dark + * colorscheme or visa-versa. + * https://st.suckless.org/patches/invert/ + */ +#define INVERT_PATCH 0 + /* Pressing the default binding Ctrl+Shift-i will popup dmenu, asking you to enter a unicode * codepoint that will be converted to a glyph and then pushed to st. * https://st.suckless.org/patches/iso14755/ diff --git a/x.c b/x.c index b71764f..ab8daf0 100644 --- a/x.c +++ b/x.c @@ -904,9 +904,18 @@ xsetcolorname(int x, const char *name) void xclear(int x1, int y1, int x2, int y2) { + #if INVERT_PATCH + 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); + #else XftDrawRect(xw.draw, &dc.col[IS_SET(MODE_REVERSE)? defaultfg : defaultbg], x1, y1, x2-x1, y2-y1); + #endif // INVERT_PATCH } void @@ -1657,6 +1666,15 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i if (base.mode & ATTR_INVISIBLE) fg = bg; + #if INVERT_PATCH + if (invertcolors) { + revfg = invertedcolor(fg); + revbg = invertedcolor(bg); + fg = &revfg; + bg = &revbg; + } + #endif // INVERT_PATCH + /* Intelligent cleaning up of the borders. */ #if ANYSIZE_PATCH if (x == 0) {