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 defaultcs = 256;
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
unsigned int const currentBg = 6, buffSize = 2048;

View File

@ -293,6 +293,13 @@
*/
#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
* 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.

3
st.h
View File

@ -62,6 +62,9 @@ enum glyph_attribute {
ATTR_SIXEL = 1 << 13,
#endif // SIXEL_PATCH
ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
#if SELECTION_COLORS_PATCH
ATTR_SELECTED = 1 << 14,
#endif // SELECTION_COLORS_PATCH
#if UNDERCURL_PATCH
ATTR_DIRTYUNDERLINE = 1 << 15,
#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
}
#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)
fg = bg;
@ -2605,7 +2613,11 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
/* remove the old cursor */
if (selected(ox, oy))
#if SELECTION_COLORS_PATCH
og.mode |= ATTR_SELECTED;
#else
og.mode ^= ATTR_REVERSE;
#endif // SELECTION_COLORS_PATCH
#if LIGATURES_PATCH
/* Redraw the line where cursor was previously.
* 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)) {
g.mode |= ATTR_REVERSE;
g.bg = defaultfg;
#if SELECTION_COLORS_PATCH
g.fg = defaultcs;
drawcol = dc.col[defaultrcs];
#else
if (selected(cx, cy)) {
drawcol = dc.col[defaultcs];
g.fg = defaultrcs;
@ -2641,7 +2657,13 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
drawcol = dc.col[defaultrcs];
g.fg = defaultcs;
}
#endif // SELECTION_COLORS_PATCH
} else {
#if SELECTION_COLORS_PATCH
g.fg = defaultbg;
g.bg = defaultcs;
drawcol = dc.col[defaultcs];
#else
if (selected(cx, cy)) {
g.fg = defaultfg;
g.bg = defaultrcs;
@ -2669,6 +2691,7 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
} else
drawcol = dc.col[g.bg];
#endif // DYNAMIC_CURSOR_COLOR_PATCH
#endif // SELECTION_COLORS_PATCH
}
/* draw the new one */
@ -2898,7 +2921,11 @@ xdrawline(Line line, int x1, int y1, int x2)
if (new.mode == ATTR_WDUMMY)
continue;
if (selected(x, y1))
#if SELECTION_COLORS_PATCH
new.mode |= ATTR_SELECTED;
#else
new.mode ^= ATTR_REVERSE;
#endif // SELECTION_COLORS_PATCH
if (i > 0 && ATTRCMP(base, new)) {
xdrawglyphfontspecs(specs, base, i, ox, y1, dmode);
specs += i;
@ -2927,7 +2954,11 @@ xdrawline(Line line, int x1, int y1, int x2)
if (new.mode == ATTR_WDUMMY)
continue;
if (selected(x, y1))
#if SELECTION_COLORS_PATCH
new.mode |= ATTR_SELECTED;
#else
new.mode ^= ATTR_REVERSE;
#endif // SELECTION_COLORS_PATCH
if (i > 0 && ATTRCMP(base, new)) {
xdrawglyphfontspecs(specs, base, i, ox, y1);
specs += i;