Adding invert patch

This commit is contained in:
bakkeby 2020-03-29 15:38:16 +02:00
parent 4966f31256
commit d26b46ffa7
8 changed files with 62 additions and 0 deletions

View File

@ -15,6 +15,8 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
### Changelog: ### 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-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 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/) - [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 - 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/) - [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 - 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

View File

@ -358,6 +358,9 @@ static Shortcut shortcuts[] = {
#if ISO14755_PATCH #if ISO14755_PATCH
{ TERMMOD, XK_I, iso14755, {.i = 0} }, { TERMMOD, XK_I, iso14755, {.i = 0} },
#endif // ISO14755_PATCH #endif // ISO14755_PATCH
#if INVERT_PATCH
{ TERMMOD, XK_X, invert, { 0 } },
#endif // INVERT_PATCH
}; };
/* /*

21
patch/invert.c Normal file
View File

@ -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;
}

1
patch/invert.h Normal file
View File

@ -0,0 +1 @@
static void invert(const Arg *);

View File

@ -11,6 +11,9 @@
#if FONT2_PATCH #if FONT2_PATCH
#include "font2.c" #include "font2.c"
#endif #endif
#if INVERT_PATCH
#include "invert.c"
#endif
#if KEYBOARDSELECT_PATCH #if KEYBOARDSELECT_PATCH
#include "keyboardselect_x.c" #include "keyboardselect_x.c"
#endif #endif

View File

@ -8,6 +8,9 @@
#if FONT2_PATCH #if FONT2_PATCH
#include "font2.h" #include "font2.h"
#endif #endif
#if INVERT_PATCH
#include "invert.h"
#endif
#if KEYBOARDSELECT_PATCH #if KEYBOARDSELECT_PATCH
#include "keyboardselect_x.h" #include "keyboardselect_x.h"
#endif #endif

View File

@ -88,6 +88,13 @@
*/ */
#define HIDECURSOR_PATCH 0 #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 /* 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. * codepoint that will be converted to a glyph and then pushed to st.
* https://st.suckless.org/patches/iso14755/ * https://st.suckless.org/patches/iso14755/

18
x.c
View File

@ -904,9 +904,18 @@ xsetcolorname(int x, const char *name)
void void
xclear(int x1, int y1, int x2, int y2) 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, XftDrawRect(xw.draw,
&dc.col[IS_SET(MODE_REVERSE)? defaultfg : defaultbg], &dc.col[IS_SET(MODE_REVERSE)? defaultfg : defaultbg],
x1, y1, x2-x1, y2-y1); x1, y1, x2-x1, y2-y1);
#endif // INVERT_PATCH
} }
void void
@ -1657,6 +1666,15 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
if (base.mode & ATTR_INVISIBLE) if (base.mode & ATTR_INVISIBLE)
fg = bg; 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. */ /* Intelligent cleaning up of the borders. */
#if ANYSIZE_PATCH #if ANYSIZE_PATCH
if (x == 0) { if (x == 0) {