sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

st-selectioncolors-0.8.4.diff (3746B)


      1 From 0750c0b8c91579ec871c70c8990527bebc86a56e Mon Sep 17 00:00:00 2001
      2 From: Ashish Kumar Yadav <ashishkumar.yadav@students.iiserpune.ac.in>
      3 Date: Sat, 31 Jul 2021 22:21:11 +0530
      4 Subject: [PATCH] Add settings for selection-colors
      5 
      6 This patch adds the two color-settings *selectionfg* and *selectionbg* to
      7 config.def.h. Those define the fore- and background colors which are used when
      8 text on the screen is selected with the mouse. This removes the default
      9 behaviour which would simply reverse the colors.
     10 
     11 Additionally, a third setting *ingnoreselfg* exists. If true then the setting
     12 *selectionfg* is ignored and the original foreground-colors of each cell are
     13 not changed during selection. Basically only the background-color would change.
     14 This might be more visually appealing to some folks.
     15 ---
     16  config.def.h | 11 ++++++++---
     17  st.h         |  1 +
     18  x.c          | 30 +++++++++++++-----------------
     19  3 files changed, 22 insertions(+), 20 deletions(-)
     20 
     21 diff --git a/config.def.h b/config.def.h
     22 index 6f05dce..3679af8 100644
     23 --- a/config.def.h
     24 +++ b/config.def.h
     25 @@ -119,18 +119,23 @@ static const char *colorname[] = {
     26  
     27  	/* more colors can be added after 255 to use with DefaultXX */
     28  	"#cccccc",
     29 -	"#555555",
     30 +	"#2e3440",
     31  };
     32  
     33  
     34  /*
     35   * Default colors (colorname index)
     36 - * foreground, background, cursor, reverse cursor
     37 + * foreground, background, cursor, reverse cursor, selection
     38   */
     39  unsigned int defaultfg = 7;
     40  unsigned int defaultbg = 0;
     41  static unsigned int defaultcs = 256;
     42 -static unsigned int defaultrcs = 257;
     43 +static unsigned int defaultrcs = 256;
     44 +unsigned int selectionbg = 257;
     45 +unsigned int selectionfg = 7;
     46 +/* If 0 use selectionfg as foreground in order to have a uniform foreground-color */
     47 +/* Else if 1 keep original foreground-color of each cell => more colors :) */
     48 +static int ignoreselfg = 1;
     49  
     50  /*
     51   * Default shape of cursor
     52 diff --git a/st.h b/st.h
     53 index 3d351b6..e1a28c3 100644
     54 --- a/st.h
     55 +++ b/st.h
     56 @@ -33,6 +33,7 @@ enum glyph_attribute {
     57  	ATTR_WRAP       = 1 << 8,
     58  	ATTR_WIDE       = 1 << 9,
     59  	ATTR_WDUMMY     = 1 << 10,
     60 +	ATTR_SELECTED   = 1 << 11,
     61  	ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
     62  };
     63  
     64 diff --git a/x.c b/x.c
     65 index 210f184..7a6c70e 100644
     66 --- a/x.c
     67 +++ b/x.c
     68 @@ -1425,6 +1425,12 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
     69  		bg = temp;
     70  	}
     71  
     72 +	if (base.mode & ATTR_SELECTED) {
     73 +		bg = &dc.col[selectionbg];
     74 +		if (!ignoreselfg)
     75 +			fg = &dc.col[selectionfg];
     76 +	}
     77 +
     78  	if (base.mode & ATTR_BLINK && win.mode & MODE_BLINK)
     79  		fg = bg;
     80  
     81 @@ -1491,7 +1497,7 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
     82  
     83  	/* remove the old cursor */
     84  	if (selected(ox, oy))
     85 -		og.mode ^= ATTR_REVERSE;
     86 +		og.mode |= ATTR_SELECTED;
     87  	xdrawglyph(og, ox, oy);
     88  
     89  	if (IS_SET(MODE_HIDE))
     90 @@ -1504,23 +1510,13 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
     91  
     92  	if (IS_SET(MODE_REVERSE)) {
     93  		g.mode |= ATTR_REVERSE;
     94 +		g.fg = defaultcs;
     95  		g.bg = defaultfg;
     96 -		if (selected(cx, cy)) {
     97 -			drawcol = dc.col[defaultcs];
     98 -			g.fg = defaultrcs;
     99 -		} else {
    100 -			drawcol = dc.col[defaultrcs];
    101 -			g.fg = defaultcs;
    102 -		}
    103 +		drawcol = dc.col[defaultrcs];
    104  	} else {
    105 -		if (selected(cx, cy)) {
    106 -			g.fg = defaultfg;
    107 -			g.bg = defaultrcs;
    108 -		} else {
    109 -			g.fg = defaultbg;
    110 -			g.bg = defaultcs;
    111 -		}
    112 -		drawcol = dc.col[g.bg];
    113 +		g.fg = defaultbg;
    114 +		g.bg = defaultcs;
    115 +		drawcol = dc.col[defaultcs];
    116  	}
    117  
    118  	/* draw the new one */
    119 @@ -1612,7 +1608,7 @@ xdrawline(Line line, int x1, int y1, int x2)
    120  		if (new.mode == ATTR_WDUMMY)
    121  			continue;
    122  		if (selected(x, y1))
    123 -			new.mode ^= ATTR_REVERSE;
    124 +			new.mode |= ATTR_SELECTED;
    125  		if (i > 0 && ATTRCMP(base, new)) {
    126  			xdrawglyphfontspecs(specs, base, i, ox, y1);
    127  			specs += i;
    128 -- 
    129 2.32.0
    130