[wiki] [sites] Fix to override xresources values with command line parameters, as already stated in the wiki. || Francesco Minnocci

From: <git_AT_suckless.org>
Date: Sun, 24 May 2020 01:01:45 +0200

commit e958342737fea6864b2de11cea43d671cfbb6c46
Author: Francesco Minnocci <ad17fmin_AT_uwcad.it>
Date: Sun May 24 00:58:21 2020 +0200

    Fix to override xresources values with command line parameters, as already stated in the wiki.

diff --git a/tools.suckless.org/dmenu/patches/xresources/dmenu-xresources-20200302-db6093f.diff b/tools.suckless.org/dmenu/patches/xresources/dmenu-xresources-4.9.diff
similarity index 52%
rename from tools.suckless.org/dmenu/patches/xresources/dmenu-xresources-20200302-db6093f.diff
rename to tools.suckless.org/dmenu/patches/xresources/dmenu-xresources-4.9.diff
index 94304b97..267fb0a6 100644
--- a/tools.suckless.org/dmenu/patches/xresources/dmenu-xresources-20200302-db6093f.diff
+++ b/tools.suckless.org/dmenu/patches/xresources/dmenu-xresources-4.9.diff
_AT_@ -1,26 +1,26 @@
-From 916c4921c4e870f77d91d816272375f90dc49867 Mon Sep 17 00:00:00 2001
-From: Nihal Jere <nihal_AT_nihaljere.xyz>
-Date: Mon, 2 Mar 2020 15:56:12 -0600
-Subject: [PATCH] xresources patch frees memory properly and no longer
- segfaults
-
----
- dmenu.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++---
- 1 file changed, 47 insertions(+), 3 deletions(-)
-
-diff --git a/dmenu.c b/dmenu.c
-index 65f25ce..d444e8c 100644
---- a/dmenu.c
-+++ b/dmenu.c
+diff '--color=auto' -up ../dmenu-4.9/dmenu.c ./dmenu.c
+--- ../dmenu-4.9/dmenu.c	2019-02-02 13:55:02.000000000 +0100
++++ ./dmenu.c	2020-05-24 00:27:58.038586112 +0200
 _AT_@ -15,6 +15,7 @@
  #include <X11/extensions/Xinerama.h>
  #endif
  #include <X11/Xft/Xft.h>
 +#include <X11/Xresource.h>
- 
+
  #include "drw.h"
  #include "util.h"
-_AT_@ -601,8 +602,13 @@ setup(void)
+_AT_@ -53,6 +54,10 @@ static XIC xic;
+ static Drw *drw;
+ static Clr *scheme[SchemeLast];
+
++/* Temporary arrays to allow overriding xresources values */
++static char *colortemp[4];
++static char *tempfonts;
++
+ #include "config.h"
+
+ static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
+_AT_@ -596,8 +601,13 @@ setup(void)
  	int a, di, n, area = 0;
  #endif
  	/* init appearance */
_AT_@ -33,13 +33,13 @@ index 65f25ce..d444e8c 100644
 +		for (i = 0; i < 2; ++i)
 +			free(colors[j][i]);
 +	}
- 
+
  	clip = XInternAtom(dpy, "CLIPBOARD",   False);
  	utf8 = XInternAtom(dpy, "UTF8_STRING", False);
-_AT_@ -694,6 +700,41 @@ usage(void)
+_AT_@ -687,6 +697,41 @@ usage(void)
  	exit(1);
  }
- 
+
 +void
 +readxresources(void) {
 +	XrmInitialize();
_AT_@ -78,19 +78,49 @@ index 65f25ce..d444e8c 100644
  int
  main(int argc, char *argv[])
  {
-_AT_@ -748,8 +789,11 @@ main(int argc, char *argv[])
+_AT_@ -715,15 +760,15 @@ main(int argc, char *argv[])
+ 		else if (!strcmp(argv[i], "-p"))   /* adds prompt to left of input field */
+ 			prompt = argv[++i];
+ 		else if (!strcmp(argv[i], "-fn"))  /* font or font set */
+-			fonts[0] = argv[++i];
++			tempfonts = argv[++i];
+ 		else if (!strcmp(argv[i], "-nb"))  /* normal background color */
+-			colors[SchemeNorm][ColBg] = argv[++i];
++			colortemp[0] = argv[++i];
+ 		else if (!strcmp(argv[i], "-nf"))  /* normal foreground color */
+-			colors[SchemeNorm][ColFg] = argv[++i];
++			colortemp[1] = argv[++i];
+ 		else if (!strcmp(argv[i], "-sb"))  /* selected background color */
+-			colors[SchemeSel][ColBg] = argv[++i];
++			colortemp[2] = argv[++i];
+ 		else if (!strcmp(argv[i], "-sf"))  /* selected foreground color */
+-			colors[SchemeSel][ColFg] = argv[++i];
++			colortemp[3] = argv[++i];
+ 		else if (!strcmp(argv[i], "-w"))   /* embedding window id */
+ 			embed = argv[++i];
+ 		else
+_AT_@ -743,8 +788,23 @@ main(int argc, char *argv[])
  		die("could not get embedding window attributes: 0x%lx",
  		    parentwin);
  	drw = drw_create(dpy, screen, root, wa.width, wa.height);
 -	if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
 +	readxresources();
++	/* Now we check whether to override xresources with commandline parameters */
++	if ( tempfonts )
++	   fonts[0] = strdup(tempfonts);
++	if ( colortemp[0])
++	   colors[SchemeNorm][ColBg] = strdup(colortemp[0]);
++	if ( colortemp[1])
++	   colors[SchemeNorm][ColFg] = strdup(colortemp[1]);
++	if ( colortemp[2])
++	   colors[SchemeSel][ColBg]  = strdup(colortemp[2]);
++	if ( colortemp[3])
++	   colors[SchemeSel][ColFg]  = strdup(colortemp[3]);
++
 +	if (!drw_fontset_create(drw, (const char**)fonts, LENGTH(fonts)))
  		die("no fonts could be loaded.");
 +
 +	free(fonts[0]);
  	lrpad = drw->fonts->h;
- 
- #ifdef __OpenBSD__
--- 
-2.25.1
 
+ #ifdef __OpenBSD__
diff --git a/tools.suckless.org/dmenu/patches/xresources/index.md b/tools.suckless.org/dmenu/patches/xresources/index.md
index 21b8634f..4a638371 100644
--- a/tools.suckless.org/dmenu/patches/xresources/index.md
+++ b/tools.suckless.org/dmenu/patches/xresources/index.md
_AT_@ -21,10 +21,11 @@ overridden by command line arguments.
 
 Download
 --------
-* [dmenu-xresources-20200302-db6093f.diff](dmenu-xresources-20200302-db6093f.diff)
+* [dmenu-xresources-4.9.diff](dmenu-xresources-4.9.diff)
 
 Authors
 -------
 * MichaƂ Lemke - _AT_melek on [Bitbucket](https://bitbucket.org/melek/dmenu2/)
 * Pratik Bhusal - dmenu-xresources-4.9 port
 * Nihal Jere <nihal_AT_nihaljere.xyz> (20200302)
+* Francesco Minnocci <ad17fmin_AT_uwcad.it> - command line parameters fix
Received on Sun May 24 2020 - 01:01:45 CEST

This archive was generated by hypermail 2.3.0 : Sun May 24 2020 - 01:12:51 CEST