commit 0c8b68e2e53eac6537da5585fe115eb3e70a4bf4
parent dd6f420f7ac13c4ab155d23e21aab2a7d3010bf6
Author: Kipras Melnikovas <kipras@kipras.org>
Date: Thu, 25 Feb 2021 04:26:06 +0200
[st][patch] improve & rename cursor-color (now dynamic-cursor-color)
- removed "magic numbers" (& handled crashes)
- fixed inviside cursor in INSERT mode (shell with vi/editors like vim/emacs)
- renamed from "cursor-color" to "dynamic-cursor-color"
Signed-off-by: Kipras Melnikovas <kipras@kipras.org>
Diffstat:
5 files changed, 105 insertions(+), 75 deletions(-)
diff --git a/st.suckless.org/patches/cursor-color/index.md b/st.suckless.org/patches/cursor-color/index.md
@@ -1,26 +0,0 @@
-color-cursor
-============
-
-![](cursor-color.png)
-
-Description
------------
-Turns your cursor's background into whatever color the character you're currently on is (much like alacritty). Some say the effeect is very appealing:)
-
-Notes
------
-
-~~Might be~~ Is incomplete - I'm new and suggestions are very welcome!
-
-- Default cursor is not shown (e.g. in (neo)vim INSERT mode)
-- Probably not all cases yet covered
-- Magic numbers used - would probably be best to avoid
-- Performance degradation considerations?
-
-Download
---------
-* [st-cursor-color-0.8.4.diff](st-cursor-color-0.8.4.diff)
-
-Authors
--------
-* Kipras Melnikovas <kipras@kipras.org>
diff --git a/st.suckless.org/patches/cursor-color/st-cursor-color-0.8.4.diff b/st.suckless.org/patches/cursor-color/st-cursor-color-0.8.4.diff
@@ -1,49 +0,0 @@
-From 8cda64fed0308533a1e79da9f5bdf2593d25c885 Mon Sep 17 00:00:00 2001
-From: Kipras Melnikovas <kipras@kipras.org>
-Date: Wed, 24 Feb 2021 03:54:42 +0200
-Subject: [PATCH] create initial color-version patch
-
-swaps cursor background with the character you're currently on,
-much like alacritty.
-
-still needs improvements
-
-Signed-off-by: Kipras Melnikovas <kipras@kipras.org>
----
- x.c | 17 +++++++++++++++--
- 1 file changed, 15 insertions(+), 2 deletions(-)
-
-diff --git a/x.c b/x.c
-index 120e495..5a013f8 100644
---- a/x.c
-+++ b/x.c
-@@ -1517,11 +1517,24 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
- if (selected(cx, cy)) {
- g.fg = defaultfg;
- g.bg = defaultrcs;
-+ drawcol = dc.col[g.bg];
- } else {
-+ /** swap background, much like alacritty */
-+ g.bg = g.fg;
- g.fg = defaultbg;
-- g.bg = defaultcs;
-+
-+ /**
-+ * There were times when the `g.fg` value (now updated to `g.bg)
-+ * would jump to a very large one and opening e.g. neovim
-+ * would cause a segfault, thus I'm arbitrarily picking this value
-+ * and it seems to work, but it'd best if this was improved.
-+ */
-+ if (g.bg > 259) {
-+ drawcol = dc.col[g.fg];
-+ } else {
-+ drawcol = dc.col[g.bg];
-+ }
- }
-- drawcol = dc.col[g.bg];
- }
-
- /* draw the new one */
---
-2.30.1
-
diff --git a/st.suckless.org/patches/cursor-color/cursor-color.png b/st.suckless.org/patches/dynamic-cursor-color/dynamic-cursor-color.png
Binary files differ.
diff --git a/st.suckless.org/patches/dynamic-cursor-color/index.md b/st.suckless.org/patches/dynamic-cursor-color/index.md
@@ -0,0 +1,25 @@
+dynamic-cursor-color
+============
+
+![](dynamic-cursor-color.png)
+
+Description
+-----------
+Swaps the colors of your cursor and the character you're currently on (much like alacritty). Some say the effect is very appealing:)
+
+Notes
+-----
+
+Might be incomplete - I'm new and improvements are very welcome!
+
+- Might have some edge cases where it doesn't work properly
+- Performance degradation considerations? More testing & feedback needed
+
+Download
+--------
+* [st-dynamic-cursor-color-0.8.4.diff](st-dynamic-cursor-color-0.8.4.diff)
+
+Authors
+-------
+* Kipras Melnikovas ([kipras.org](http://kipras.org)) <kipras@kipras.org>
+* Stein Gunnar Bakkeby ([github.com/bakkeby](http://github.com/bakkeby))
diff --git a/st.suckless.org/patches/dynamic-cursor-color/st-dynamic-cursor-color-0.8.4.diff b/st.suckless.org/patches/dynamic-cursor-color/st-dynamic-cursor-color-0.8.4.diff
@@ -0,0 +1,80 @@
+From 1115d1d45effebc728891f76b6c8a44568a81bb3 Mon Sep 17 00:00:00 2001
+From: Kipras Melnikovas <kipras@kipras.org>
+Date: Thu, 25 Feb 2021 04:13:49 +0200
+Subject: [PATCH] improve cursor-color patch and add dynamic- prefix
+
+very thankful to Bakkeby [1] for helping out with various improvements,
+crash fixes etc., as seen in [2]!
+
+also renamed the patch (added dynamic- prefix),
+because I think this better describes it.
+
+[1] https://github.com/bakkeby
+[2] https://github.com/bakkeby/st-flexipatch/issues/10
+
+Signed-off-by: Kipras Melnikovas <kipras@kipras.org>
+---
+ x.c | 39 ++++++++++++++++++++++++++++++++++++---
+ 1 file changed, 36 insertions(+), 3 deletions(-)
+
+diff --git a/x.c b/x.c
+index 120e495..e47e236 100644
+--- a/x.c
++++ b/x.c
+@@ -1489,6 +1489,7 @@ void
+ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
+ {
+ Color drawcol;
++ XRenderColor colfg;
+
+ /* remove the old cursor */
+ if (selected(ox, oy))
+@@ -1517,11 +1518,43 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
+ if (selected(cx, cy)) {
+ g.fg = defaultfg;
+ g.bg = defaultrcs;
++ drawcol = dc.col[g.bg];
+ } else {
+- g.fg = defaultbg;
+- g.bg = defaultcs;
++ /** this is the main part of the dynamic cursor color */
++ if (IS_SET(MODE_FOCUSED)) {
++ g.bg = g.fg;
++ g.fg = defaultbg;
++ }
++
++ /**
++ * the following 2 sections are identical,
++ * they differ only by either using `g.fg` or `g.bg`,
++ * and it depends on what background+foreground
++ * the user has configured (light+dark vs dark+light)
++ *
++ * otherwise, in one of the cases, the cursor will be invisible
++ */
++
++ if (IS_TRUECOL(g.fg)) {
++ colfg.alpha = 0xffff;
++ colfg.red = TRUERED(g.fg);
++ colfg.green = TRUEGREEN(g.fg);
++ colfg.blue = TRUEBLUE(g.fg);
++ XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &drawcol);
++ } else {
++ drawcol = dc.col[g.fg];
++ }
++
++ if (IS_TRUECOL(g.bg)) {
++ colfg.alpha = 0xffff;
++ colfg.red = TRUERED(g.bg);
++ colfg.green = TRUEGREEN(g.bg);
++ colfg.blue = TRUEBLUE(g.bg);
++ XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &drawcol);
++ } else {
++ drawcol = dc.col[g.bg];
++ }
+ }
+- drawcol = dc.col[g.bg];
+ }
+
+ /* draw the new one */
+--
+2.30.1