sites

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

st-focus-20230610-68d1ad9.diff (14084B)


      1 From e08d495aaa29c53273942985f40212ef72715604 Mon Sep 17 00:00:00 2001
      2 From: Julius Huelsmann <juliusHuelsmann@gmail.com>
      3 Date: Sat, 30 May 2020 01:11:42 +0200
      4 Subject: [PATCH 1/7] chore: add alpha patch
      5 
      6 ---
      7  config.def.h | 11 +++++++----
      8  config.mk    |  2 +-
      9  st.h         |  1 +
     10  x.c          | 40 ++++++++++++++++++++++++++++++----------
     11  4 files changed, 39 insertions(+), 15 deletions(-)
     12 
     13 diff --git a/config.def.h b/config.def.h
     14 index 91ab8ca..6bd6e8d 100644
     15 --- a/config.def.h
     16 +++ b/config.def.h
     17 @@ -93,6 +93,9 @@ char *termname = "st-256color";
     18   */
     19  unsigned int tabspaces = 8;
     20  
     21 +/* bg opacity */
     22 +float alpha = 0.8;
     23 +
     24  /* Terminal colors (16 first used in escape sequence) */
     25  static const char *colorname[] = {
     26  	/* 8 normal colors */
     27 @@ -120,8 +123,7 @@ static const char *colorname[] = {
     28  	/* more colors can be added after 255 to use with DefaultXX */
     29  	"#cccccc",
     30  	"#555555",
     31 -	"gray90", /* default foreground colour */
     32 -	"black", /* default background colour */
     33 +	"black",
     34  };
     35  
     36  
     37 @@ -129,8 +131,9 @@ static const char *colorname[] = {
     38   * Default colors (colorname index)
     39   * foreground, background, cursor, reverse cursor
     40   */
     41 -unsigned int defaultfg = 258;
     42 -unsigned int defaultbg = 259;
     43 +unsigned int defaultfg = 7;
     44 +unsigned int defaultbg = 258;
     45 +//static 
     46  unsigned int defaultcs = 256;
     47  static unsigned int defaultrcs = 257;
     48  
     49 diff --git a/config.mk b/config.mk
     50 index 1e306f8..47c615e 100644
     51 --- a/config.mk
     52 +++ b/config.mk
     53 @@ -16,7 +16,7 @@ PKG_CONFIG = pkg-config
     54  INCS = -I$(X11INC) \
     55         `$(PKG_CONFIG) --cflags fontconfig` \
     56         `$(PKG_CONFIG) --cflags freetype2`
     57 -LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
     58 +LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender\
     59         `$(PKG_CONFIG) --libs fontconfig` \
     60         `$(PKG_CONFIG) --libs freetype2`
     61  
     62 diff --git a/st.h b/st.h
     63 index fd3b0d8..9f91e2a 100644
     64 --- a/st.h
     65 +++ b/st.h
     66 @@ -124,3 +124,4 @@ extern unsigned int tabspaces;
     67  extern unsigned int defaultfg;
     68  extern unsigned int defaultbg;
     69  extern unsigned int defaultcs;
     70 +extern float alpha;
     71 diff --git a/x.c b/x.c
     72 index 2a3bd38..27e81d1 100644
     73 --- a/x.c
     74 +++ b/x.c
     75 @@ -105,6 +105,7 @@ typedef struct {
     76  	XSetWindowAttributes attrs;
     77  	int scr;
     78  	int isfixed; /* is fixed geometry? */
     79 +	int depth; /* bit depth */
     80  	int l, t; /* left and top offset */
     81  	int gm; /* geometry mask */
     82  } XWindow;
     83 @@ -243,6 +244,7 @@ static char *usedfont = NULL;
     84  static double usedfontsize = 0;
     85  static double defaultfontsize = 0;
     86  
     87 +static char *opt_alpha = NULL;
     88  static char *opt_class = NULL;
     89  static char **opt_cmd  = NULL;
     90  static char *opt_embed = NULL;
     91 @@ -752,7 +754,7 @@ xresize(int col, int row)
     92  
     93  	XFreePixmap(xw.dpy, xw.buf);
     94  	xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
     95 -			DefaultDepth(xw.dpy, xw.scr));
     96 +			xw.depth);
     97  	XftDrawChange(xw.draw, xw.buf);
     98  	xclear(0, 0, win.w, win.h);
     99  
    100 @@ -812,6 +814,13 @@ xloadcols(void)
    101  			else
    102  				die("could not allocate color %d\n", i);
    103  		}
    104 +
    105 +	/* set alpha value of bg color */
    106 +	if (opt_alpha)
    107 +		alpha = strtof(opt_alpha, NULL);
    108 +	dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
    109 +	dc.col[defaultbg].pixel &= 0x00FFFFFF;
    110 +	dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
    111  	loaded = 1;
    112  }
    113  
    114 @@ -1134,11 +1143,23 @@ xinit(int cols, int rows)
    115  	Window parent;
    116  	pid_t thispid = getpid();
    117  	XColor xmousefg, xmousebg;
    118 +	XWindowAttributes attr;
    119 +	XVisualInfo vis;
    120  
    121  	if (!(xw.dpy = XOpenDisplay(NULL)))
    122  		die("can't open display\n");
    123  	xw.scr = XDefaultScreen(xw.dpy);
    124 -	xw.vis = XDefaultVisual(xw.dpy, xw.scr);
    125 +
    126 +	if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) {
    127 +		parent = XRootWindow(xw.dpy, xw.scr);
    128 +		xw.depth = 32;
    129 +	} else {
    130 +		XGetWindowAttributes(xw.dpy, parent, &attr);
    131 +		xw.depth = attr.depth;
    132 +	}
    133 +
    134 +	XMatchVisualInfo(xw.dpy, xw.scr, xw.depth, TrueColor, &vis);
    135 +	xw.vis = vis.visual;
    136  
    137  	/* font */
    138  	if (!FcInit())
    139 @@ -1148,7 +1169,7 @@ xinit(int cols, int rows)
    140  	xloadfonts(usedfont, 0);
    141  
    142  	/* colors */
    143 -	xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
    144 +	xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
    145  	xloadcols();
    146  
    147  	/* adjust fixed window geometry */
    148 @@ -1168,19 +1189,15 @@ xinit(int cols, int rows)
    149  		| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
    150  	xw.attrs.colormap = xw.cmap;
    151  
    152 -	if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
    153 -		parent = XRootWindow(xw.dpy, xw.scr);
    154  	xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
    155 -			win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
    156 +			win.w, win.h, 0, xw.depth, InputOutput,
    157  			xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
    158  			| CWEventMask | CWColormap, &xw.attrs);
    159  
    160  	memset(&gcvalues, 0, sizeof(gcvalues));
    161  	gcvalues.graphics_exposures = False;
    162 -	dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
    163 -			&gcvalues);
    164 -	xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
    165 -			DefaultDepth(xw.dpy, xw.scr));
    166 +	xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
    167 +	dc.gc = XCreateGC(xw.dpy, xw.buf, GCGraphicsExposures, &gcvalues);
    168  	XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
    169  	XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
    170  
    171 @@ -2035,6 +2052,9 @@ main(int argc, char *argv[])
    172  	case 'a':
    173  		allowaltscreen = 0;
    174  		break;
    175 +	case 'A':
    176 +		opt_alpha = EARGF(usage());
    177 +		break;
    178  	case 'c':
    179  		opt_class = EARGF(usage());
    180  		break;
    181 -- 
    182 2.34.1
    183 
    184 
    185 From 292b70d7b9976e624931f8ec264a8875e29d2f3c Mon Sep 17 00:00:00 2001
    186 From: Julius Huelsmann <juliusHuelsmann@gmail.com>
    187 Date: Sat, 30 May 2020 01:13:35 +0200
    188 Subject: [PATCH 2/7] [patch:focus] add initial patch
    189 
    190 ---
    191  config.def.h |  6 +++---
    192  st.h         |  2 +-
    193  x.c          | 33 +++++++++++++++++++--------------
    194  3 files changed, 23 insertions(+), 18 deletions(-)
    195 
    196 diff --git a/config.def.h b/config.def.h
    197 index 6bd6e8d..cdfbaf1 100644
    198 --- a/config.def.h
    199 +++ b/config.def.h
    200 @@ -94,7 +94,7 @@ char *termname = "st-256color";
    201  unsigned int tabspaces = 8;
    202  
    203  /* bg opacity */
    204 -float alpha = 0.8;
    205 +float alpha = 0.8, alphaUnfocused = 0.6;
    206  
    207  /* Terminal colors (16 first used in escape sequence) */
    208  static const char *colorname[] = {
    209 @@ -132,10 +132,10 @@ static const char *colorname[] = {
    210   * foreground, background, cursor, reverse cursor
    211   */
    212  unsigned int defaultfg = 7;
    213 -unsigned int defaultbg = 258;
    214 -//static 
    215 +unsigned int defaultbg = 0;
    216  unsigned int defaultcs = 256;
    217  static unsigned int defaultrcs = 257;
    218 +unsigned int bg = 17, bgUnfocused = 16;
    219  
    220  /*
    221   * Default shape of cursor
    222 diff --git a/st.h b/st.h
    223 index 9f91e2a..62e3486 100644
    224 --- a/st.h
    225 +++ b/st.h
    226 @@ -124,4 +124,4 @@ extern unsigned int tabspaces;
    227  extern unsigned int defaultfg;
    228  extern unsigned int defaultbg;
    229  extern unsigned int defaultcs;
    230 -extern float alpha;
    231 +extern float alpha, alphaUnfocused;
    232 diff --git a/x.c b/x.c
    233 index 27e81d1..05d6e2e 100644
    234 --- a/x.c
    235 +++ b/x.c
    236 @@ -255,6 +255,7 @@ static char *opt_name  = NULL;
    237  static char *opt_title = NULL;
    238  
    239  static uint buttons; /* bit field of pressed buttons */
    240 +static int focused = 0;
    241  
    242  void
    243  clipcopy(const Arg *dummy)
    244 @@ -792,35 +793,38 @@ xloadcolor(int i, const char *name, Color *ncolor)
    245  	return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
    246  }
    247  
    248 +void
    249 +xloadalpha(void)
    250 +{
    251 +	float const usedAlpha = focused ? alpha : alphaUnfocused;
    252 +	if (opt_alpha) alpha = strtof(opt_alpha, NULL);
    253 +	dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * usedAlpha);
    254 +	dc.col[defaultbg].pixel &= 0x00FFFFFF;
    255 +	dc.col[defaultbg].pixel |= (unsigned char)(0xff * usedAlpha) << 24;
    256 +}
    257 +
    258  void
    259  xloadcols(void)
    260  {
    261 -	int i;
    262  	static int loaded;
    263  	Color *cp;
    264  
    265 -	if (loaded) {
    266 -		for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
    267 -			XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
    268 -	} else {
    269 -		dc.collen = MAX(LEN(colorname), 256);
    270 -		dc.col = xmalloc(dc.collen * sizeof(Color));
    271 +	if (!loaded) {
    272 +		dc.collen = 1 + (defaultbg = MAX(LEN(colorname), 256));
    273 +		dc.col = xmalloc((dc.collen) * sizeof(Color));
    274  	}
    275  
    276 -	for (i = 0; i < dc.collen; i++)
    277 +	for (int i = 0; i+1 < dc.collen; ++i)
    278  		if (!xloadcolor(i, NULL, &dc.col[i])) {
    279  			if (colorname[i])
    280  				die("could not allocate color '%s'\n", colorname[i]);
    281  			else
    282  				die("could not allocate color %d\n", i);
    283  		}
    284 +	if (dc.collen) // cannot die, as the color is already loaded.
    285 +		xloadcolor(focused ?bg :bgUnfocused, NULL, &dc.col[defaultbg]);
    286  
    287 -	/* set alpha value of bg color */
    288 -	if (opt_alpha)
    289 -		alpha = strtof(opt_alpha, NULL);
    290 -	dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
    291 -	dc.col[defaultbg].pixel &= 0x00FFFFFF;
    292 -	dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
    293 +	xloadalpha();
    294  	loaded = 1;
    295  }
    296  
    297 @@ -2106,6 +2110,7 @@ run:
    298  	XSetLocaleModifiers("");
    299  	cols = MAX(cols, 1);
    300  	rows = MAX(rows, 1);
    301 +	defaultbg = MAX(LEN(colorname), 256);
    302  	tnew(cols, rows);
    303  	xinit(cols, rows);
    304  	xsetenv();
    305 -- 
    306 2.34.1
    307 
    308 
    309 From 9bb6788325306d9ec2bead559dacd031287a2b8c Mon Sep 17 00:00:00 2001
    310 From: Julius Huelsmann <juliusHuelsmann@gmail.com>
    311 Date: Fri, 5 Jun 2020 20:48:06 +0200
    312 Subject: [PATCH 3/7] [patch:focus]: fix
    313 
    314 ---
    315  x.c | 10 ++++++++++
    316  1 file changed, 10 insertions(+)
    317 
    318 diff --git a/x.c b/x.c
    319 index 05d6e2e..97481ba 100644
    320 --- a/x.c
    321 +++ b/x.c
    322 @@ -1798,12 +1798,22 @@ focus(XEvent *ev)
    323  		xseturgency(0);
    324  		if (IS_SET(MODE_FOCUS))
    325  			ttywrite("\033[I", 3, 0);
    326 +		if (!focused) {
    327 +			xloadcols();
    328 +			redraw();
    329 +		}
    330 +		focused = 1;
    331  	} else {
    332  		if (xw.ime.xic)
    333  			XUnsetICFocus(xw.ime.xic);
    334  		win.mode &= ~MODE_FOCUSED;
    335  		if (IS_SET(MODE_FOCUS))
    336  			ttywrite("\033[O", 3, 0);
    337 +		if (focused) {
    338 +			xloadcols();
    339 +			redraw();
    340 +		}
    341 +		focused = 0;
    342  	}
    343  }
    344  
    345 -- 
    346 2.34.1
    347 
    348 
    349 From 62b6683ddf40aff222b59d5e074770d8d7336342 Mon Sep 17 00:00:00 2001
    350 From: Julius Huelsmann <juliusHuelsmann@gmail.com>
    351 Date: Sat, 6 Jun 2020 12:57:43 +0200
    352 Subject: [PATCH 4/7] [patch:focus]: fix
    353 
    354 ---
    355  x.c | 4 ++--
    356  1 file changed, 2 insertions(+), 2 deletions(-)
    357 
    358 diff --git a/x.c b/x.c
    359 index 97481ba..c4a4b00 100644
    360 --- a/x.c
    361 +++ b/x.c
    362 @@ -1799,10 +1799,10 @@ focus(XEvent *ev)
    363  		if (IS_SET(MODE_FOCUS))
    364  			ttywrite("\033[I", 3, 0);
    365  		if (!focused) {
    366 +			focused = 1;
    367  			xloadcols();
    368  			redraw();
    369  		}
    370 -		focused = 1;
    371  	} else {
    372  		if (xw.ime.xic)
    373  			XUnsetICFocus(xw.ime.xic);
    374 @@ -1810,10 +1810,10 @@ focus(XEvent *ev)
    375  		if (IS_SET(MODE_FOCUS))
    376  			ttywrite("\033[O", 3, 0);
    377  		if (focused) {
    378 +			focused = 0;
    379  			xloadcols();
    380  			redraw();
    381  		}
    382 -		focused = 0;
    383  	}
    384  }
    385  
    386 -- 
    387 2.34.1
    388 
    389 
    390 From dc6c039192e887e70a2e6f07ac55c317e6b1c3be Mon Sep 17 00:00:00 2001
    391 From: Julius Huelsmann <juliusHuelsmann@gmail.com>
    392 Date: Thu, 23 Jul 2020 18:17:50 +0200
    393 Subject: [PATCH 5/7] potential fix: exchange redraw with tfulldirt
    394 
    395 ---
    396  st.c | 1 -
    397  st.h | 1 +
    398  x.c  | 4 ++--
    399  3 files changed, 3 insertions(+), 3 deletions(-)
    400 
    401 diff --git a/st.c b/st.c
    402 index 62def59..8ee76a3 100644
    403 --- a/st.c
    404 +++ b/st.c
    405 @@ -194,7 +194,6 @@ static void tsetscroll(int, int);
    406  static void tswapscreen(void);
    407  static void tsetmode(int, int, const int *, int);
    408  static int twrite(const char *, int, int);
    409 -static void tfulldirt(void);
    410  static void tcontrolcode(uchar );
    411  static void tdectest(char );
    412  static void tdefutf8(char);
    413 diff --git a/st.h b/st.h
    414 index 62e3486..13be339 100644
    415 --- a/st.h
    416 +++ b/st.h
    417 @@ -79,6 +79,7 @@ typedef union {
    418  
    419  void die(const char *, ...);
    420  void redraw(void);
    421 +void tfulldirt(void);
    422  void draw(void);
    423  
    424  void printscreen(const Arg *);
    425 diff --git a/x.c b/x.c
    426 index c4a4b00..92c87b4 100644
    427 --- a/x.c
    428 +++ b/x.c
    429 @@ -1801,7 +1801,7 @@ focus(XEvent *ev)
    430  		if (!focused) {
    431  			focused = 1;
    432  			xloadcols();
    433 -			redraw();
    434 +			tfulldirt();
    435  		}
    436  	} else {
    437  		if (xw.ime.xic)
    438 @@ -1812,7 +1812,7 @@ focus(XEvent *ev)
    439  		if (focused) {
    440  			focused = 0;
    441  			xloadcols();
    442 -			redraw();
    443 +			tfulldirt();
    444  		}
    445  	}
    446  }
    447 -- 
    448 2.34.1
    449 
    450 
    451 From 4da97936d57e3528ef7cf36c254c0985f6640132 Mon Sep 17 00:00:00 2001
    452 From: Wim Stockman <wim@yasendfile.org>
    453 Date: Sat, 4 Feb 2023 13:46:02 +0100
    454 Subject: [PATCH 6/7] Performs upgrade avoid reloading all the colors again and
    455  again also avoids problem when colors are set dynamically when focus in and
    456  out that the colourpallette is not reset each time.
    457 
    458 ---
    459  x.c | 7 +++----
    460  1 file changed, 3 insertions(+), 4 deletions(-)
    461 
    462 diff --git a/x.c b/x.c
    463 index 92c87b4..879bf0e 100644
    464 --- a/x.c
    465 +++ b/x.c
    466 @@ -796,6 +796,7 @@ xloadcolor(int i, const char *name, Color *ncolor)
    467  void
    468  xloadalpha(void)
    469  {
    470 +	xloadcolor(focused ?bg :bgUnfocused, NULL, &dc.col[defaultbg]);
    471  	float const usedAlpha = focused ? alpha : alphaUnfocused;
    472  	if (opt_alpha) alpha = strtof(opt_alpha, NULL);
    473  	dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * usedAlpha);
    474 @@ -821,8 +822,6 @@ xloadcols(void)
    475  			else
    476  				die("could not allocate color %d\n", i);
    477  		}
    478 -	if (dc.collen) // cannot die, as the color is already loaded.
    479 -		xloadcolor(focused ?bg :bgUnfocused, NULL, &dc.col[defaultbg]);
    480  
    481  	xloadalpha();
    482  	loaded = 1;
    483 @@ -1800,7 +1799,7 @@ focus(XEvent *ev)
    484  			ttywrite("\033[I", 3, 0);
    485  		if (!focused) {
    486  			focused = 1;
    487 -			xloadcols();
    488 +			xloadalpha();
    489  			tfulldirt();
    490  		}
    491  	} else {
    492 @@ -1811,7 +1810,7 @@ focus(XEvent *ev)
    493  			ttywrite("\033[O", 3, 0);
    494  		if (focused) {
    495  			focused = 0;
    496 -			xloadcols();
    497 +			xloadalpha();
    498  			tfulldirt();
    499  		}
    500  	}
    501 -- 
    502 2.34.1
    503 
    504 
    505 From ec16984d95e0ff9ac33b2b3d30f292c3a327c473 Mon Sep 17 00:00:00 2001
    506 From: Julius Huelsmann <juliusHuelsmann@gmail.com>
    507 Date: Sat, 10 Jun 2023 13:16:11 +0200
    508 Subject: [PATCH 7/7] changed default config a bit
    509 
    510 ---
    511  config.def.h | 4 ++--
    512  1 file changed, 2 insertions(+), 2 deletions(-)
    513 
    514 diff --git a/config.def.h b/config.def.h
    515 index cdfbaf1..779178f 100644
    516 --- a/config.def.h
    517 +++ b/config.def.h
    518 @@ -94,7 +94,7 @@ char *termname = "st-256color";
    519  unsigned int tabspaces = 8;
    520  
    521  /* bg opacity */
    522 -float alpha = 0.8, alphaUnfocused = 0.6;
    523 +float alpha = 0.93, alphaUnfocused = 0.6;
    524  
    525  /* Terminal colors (16 first used in escape sequence) */
    526  static const char *colorname[] = {
    527 @@ -135,7 +135,7 @@ unsigned int defaultfg = 7;
    528  unsigned int defaultbg = 0;
    529  unsigned int defaultcs = 256;
    530  static unsigned int defaultrcs = 257;
    531 -unsigned int bg = 17, bgUnfocused = 16;
    532 +unsigned int bg = 0, bgUnfocused = 16;
    533  
    534  /*
    535   * Default shape of cursor
    536 -- 
    537 2.34.1
    538