Add selectioncolors patch (#110)

https://st.suckless.org/patches/selectioncolors/

Closes #91
This commit is contained in:
Jordan Callicoat 2024-02-28 07:34:06 -06:00 committed by GitHub
parent 74f19eafe9
commit 2e0e84d56a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 48 additions and 0 deletions

View File

@ -206,6 +206,13 @@ unsigned int defaultbg = 258;
unsigned int defaultfg = 259; unsigned int defaultfg = 259;
unsigned int defaultcs = 256; unsigned int defaultcs = 256;
unsigned int defaultrcs = 257; unsigned int defaultrcs = 257;
#if SELECTION_COLORS_PATCH
unsigned int selectionfg = 258;
unsigned int selectionbg = 259;
/* If 0 use selectionfg as foreground in order to have a uniform foreground-color */
/* Else if 1 keep original foreground-color of each cell => more colors :) */
static int ignoreselfg = 1;
#endif // SELECTION_COLORS_PATCH
#if VIM_BROWSE_PATCH #if VIM_BROWSE_PATCH
unsigned int const currentBg = 6, buffSize = 2048; unsigned int const currentBg = 6, buffSize = 2048;

View File

@ -293,6 +293,13 @@
*/ */
#define SCROLLBACK_MOUSE_ALTSCREEN_PATCH 0 #define SCROLLBACK_MOUSE_ALTSCREEN_PATCH 0
/* This patch adds the two color-settings selectionfg and selectionbg to config.def.h.
* Those define the fore- and background colors which are used when text on the screen is selected
* with the mouse. This removes the default behaviour which would simply reverse the colors.
* https://st.suckless.org/patches/selectioncolors/
*/
#define SELECTION_COLORS_PATCH 0
/* This is the single drawable buffer patch as outlined in the FAQ to get images /* This is the single drawable buffer patch as outlined in the FAQ to get images
* in w3m to display. While this patch does not break the alpha patch it images * in w3m to display. While this patch does not break the alpha patch it images
* are not shown in w3m if the alpha patch is applied. * are not shown in w3m if the alpha patch is applied.

3
st.h
View File

@ -62,6 +62,9 @@ enum glyph_attribute {
ATTR_SIXEL = 1 << 13, ATTR_SIXEL = 1 << 13,
#endif // SIXEL_PATCH #endif // SIXEL_PATCH
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT, ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
#if SELECTION_COLORS_PATCH
ATTR_SELECTED = 1 << 14,
#endif // SELECTION_COLORS_PATCH
#if UNDERCURL_PATCH #if UNDERCURL_PATCH
ATTR_DIRTYUNDERLINE = 1 << 15, ATTR_DIRTYUNDERLINE = 1 << 15,
#endif // UNDERCURL_PATCH #endif // UNDERCURL_PATCH

31
x.c
View File

@ -2078,6 +2078,14 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
#endif // SPOILER_PATCH #endif // SPOILER_PATCH
} }
#if SELECTION_COLORS_PATCH
if (base.mode & ATTR_SELECTED) {
bg = &dc.col[selectionbg];
if (!ignoreselfg)
fg = &dc.col[selectionfg];
}
#endif // SELECTION_COLORS_PATCH
if (base.mode & ATTR_BLINK && win.mode & MODE_BLINK) if (base.mode & ATTR_BLINK && win.mode & MODE_BLINK)
fg = bg; fg = bg;
@ -2605,7 +2613,11 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
/* remove the old cursor */ /* remove the old cursor */
if (selected(ox, oy)) if (selected(ox, oy))
#if SELECTION_COLORS_PATCH
og.mode |= ATTR_SELECTED;
#else
og.mode ^= ATTR_REVERSE; og.mode ^= ATTR_REVERSE;
#endif // SELECTION_COLORS_PATCH
#if LIGATURES_PATCH #if LIGATURES_PATCH
/* Redraw the line where cursor was previously. /* Redraw the line where cursor was previously.
* It will restore the ligatures broken by the cursor. */ * It will restore the ligatures broken by the cursor. */
@ -2634,6 +2646,10 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
if (IS_SET(MODE_REVERSE)) { if (IS_SET(MODE_REVERSE)) {
g.mode |= ATTR_REVERSE; g.mode |= ATTR_REVERSE;
g.bg = defaultfg; g.bg = defaultfg;
#if SELECTION_COLORS_PATCH
g.fg = defaultcs;
drawcol = dc.col[defaultrcs];
#else
if (selected(cx, cy)) { if (selected(cx, cy)) {
drawcol = dc.col[defaultcs]; drawcol = dc.col[defaultcs];
g.fg = defaultrcs; g.fg = defaultrcs;
@ -2641,7 +2657,13 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
drawcol = dc.col[defaultrcs]; drawcol = dc.col[defaultrcs];
g.fg = defaultcs; g.fg = defaultcs;
} }
#endif // SELECTION_COLORS_PATCH
} else { } else {
#if SELECTION_COLORS_PATCH
g.fg = defaultbg;
g.bg = defaultcs;
drawcol = dc.col[defaultcs];
#else
if (selected(cx, cy)) { if (selected(cx, cy)) {
g.fg = defaultfg; g.fg = defaultfg;
g.bg = defaultrcs; g.bg = defaultrcs;
@ -2669,6 +2691,7 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
} else } else
drawcol = dc.col[g.bg]; drawcol = dc.col[g.bg];
#endif // DYNAMIC_CURSOR_COLOR_PATCH #endif // DYNAMIC_CURSOR_COLOR_PATCH
#endif // SELECTION_COLORS_PATCH
} }
/* draw the new one */ /* draw the new one */
@ -2898,7 +2921,11 @@ xdrawline(Line line, int x1, int y1, int x2)
if (new.mode == ATTR_WDUMMY) if (new.mode == ATTR_WDUMMY)
continue; continue;
if (selected(x, y1)) if (selected(x, y1))
#if SELECTION_COLORS_PATCH
new.mode |= ATTR_SELECTED;
#else
new.mode ^= ATTR_REVERSE; new.mode ^= ATTR_REVERSE;
#endif // SELECTION_COLORS_PATCH
if (i > 0 && ATTRCMP(base, new)) { if (i > 0 && ATTRCMP(base, new)) {
xdrawglyphfontspecs(specs, base, i, ox, y1, dmode); xdrawglyphfontspecs(specs, base, i, ox, y1, dmode);
specs += i; specs += i;
@ -2927,7 +2954,11 @@ xdrawline(Line line, int x1, int y1, int x2)
if (new.mode == ATTR_WDUMMY) if (new.mode == ATTR_WDUMMY)
continue; continue;
if (selected(x, y1)) if (selected(x, y1))
#if SELECTION_COLORS_PATCH
new.mode |= ATTR_SELECTED;
#else
new.mode ^= ATTR_REVERSE; new.mode ^= ATTR_REVERSE;
#endif // SELECTION_COLORS_PATCH
if (i > 0 && ATTRCMP(base, new)) { if (i > 0 && ATTRCMP(base, new)) {
xdrawglyphfontspecs(specs, base, i, ox, y1); xdrawglyphfontspecs(specs, base, i, ox, y1);
specs += i; specs += i;