aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Chudnick <sam@chudnick.com>2023-02-25 22:21:00 -0500
committerSam Chudnick <sam@chudnick.com>2023-02-25 22:21:00 -0500
commit31b687a813c5164dcb2cb63805485ccef8974a68 (patch)
tree7024bf1199d6780288fa0b592ada5fab129de25b
parentfff3a11874a0ea6c7e89ab5807a4e2673706c2c2 (diff)
Apply xresources patch
-rwxr-xr-xdmenubin44616 -> 0 bytes
-rw-r--r--dmenu.c75
-rwxr-xr-xstestbin17680 -> 0 bytes
3 files changed, 67 insertions, 8 deletions
diff --git a/dmenu b/dmenu
deleted file mode 100755
index 9595929..0000000
--- a/dmenu
+++ /dev/null
Binary files differ
diff --git a/dmenu.c b/dmenu.c
index c5cce46..431e84f 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -17,6 +17,7 @@
17#include <X11/extensions/Xinerama.h> 17#include <X11/extensions/Xinerama.h>
18#endif 18#endif
19#include <X11/Xft/Xft.h> 19#include <X11/Xft/Xft.h>
20#include <X11/Xresource.h>
20 21
21#include "drw.h" 22#include "drw.h"
22#include "util.h" 23#include "util.h"
@@ -62,6 +63,9 @@ static int useargb = 0;
62static Visual *visual; 63static Visual *visual;
63static int depth; 64static int depth;
64static Colormap cmap; 65static Colormap cmap;
66/* Temporary arrays to allow overriding xresources values */
67static char *colortemp[4];
68static char *tempfonts;
65 69
66#include "config.h" 70#include "config.h"
67 71
@@ -782,8 +786,13 @@ setup(void)
782 int a, di, n, area = 0; 786 int a, di, n, area = 0;
783#endif 787#endif
784 /* init appearance */ 788 /* init appearance */
785 for (j = 0; j < SchemeLast; j++) 789 for (j = 0; j < SchemeLast; j++) {
786 scheme[j] = drw_scm_create(drw, colors[j], alphas[i], 2); 790 scheme[j] = drw_scm_create(drw, (const char**)colors[j], alphas[i], 2);
791 }
792 for (j = 0; j < SchemeOut; ++j) {
793 for (i = 0; i < 2; ++i)
794 free(colors[j][i]);
795 }
787 796
788 clip = XInternAtom(dpy, "CLIPBOARD", False); 797 clip = XInternAtom(dpy, "CLIPBOARD", False);
789 utf8 = XInternAtom(dpy, "UTF8_STRING", False); 798 utf8 = XInternAtom(dpy, "UTF8_STRING", False);
@@ -877,6 +886,41 @@ usage(void)
877 " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]"); 886 " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
878} 887}
879 888
889void
890readxresources(void) {
891 XrmInitialize();
892
893 char* xrm;
894 if ((xrm = XResourceManagerString(drw->dpy))) {
895 char *type;
896 XrmDatabase xdb = XrmGetStringDatabase(xrm);
897 XrmValue xval;
898
899 if (XrmGetResource(xdb, "dmenu.font", "*", &type, &xval))
900 fonts[0] = strdup(xval.addr);
901 else
902 fonts[0] = strdup(fonts[0]);
903 if (XrmGetResource(xdb, "dmenu.background", "*", &type, &xval))
904 colors[SchemeNorm][ColBg] = strdup(xval.addr);
905 else
906 colors[SchemeNorm][ColBg] = strdup(colors[SchemeNorm][ColBg]);
907 if (XrmGetResource(xdb, "dmenu.foreground", "*", &type, &xval))
908 colors[SchemeNorm][ColFg] = strdup(xval.addr);
909 else
910 colors[SchemeNorm][ColFg] = strdup(colors[SchemeNorm][ColFg]);
911 if (XrmGetResource(xdb, "dmenu.selbackground", "*", &type, &xval))
912 colors[SchemeSel][ColBg] = strdup(xval.addr);
913 else
914 colors[SchemeSel][ColBg] = strdup(colors[SchemeSel][ColBg]);
915 if (XrmGetResource(xdb, "dmenu.selforeground", "*", &type, &xval))
916 colors[SchemeSel][ColFg] = strdup(xval.addr);
917 else
918 colors[SchemeSel][ColFg] = strdup(colors[SchemeSel][ColFg]);
919
920 XrmDestroyDatabase(xdb);
921 }
922}
923
880int 924int
881main(int argc, char *argv[]) 925main(int argc, char *argv[])
882{ 926{
@@ -911,15 +955,15 @@ main(int argc, char *argv[])
911 else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */ 955 else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
912 prompt = argv[++i]; 956 prompt = argv[++i];
913 else if (!strcmp(argv[i], "-fn")) /* font or font set */ 957 else if (!strcmp(argv[i], "-fn")) /* font or font set */
914 fonts[0] = argv[++i]; 958 tempfonts = argv[++i];
915 else if (!strcmp(argv[i], "-nb")) /* normal background color */ 959 else if (!strcmp(argv[i], "-nb")) /* normal background color */
916 colors[SchemeNorm][ColBg] = argv[++i]; 960 colortemp[0] = argv[++i];
917 else if (!strcmp(argv[i], "-nf")) /* normal foreground color */ 961 else if (!strcmp(argv[i], "-nf")) /* normal foreground color */
918 colors[SchemeNorm][ColFg] = argv[++i]; 962 colortemp[1] = argv[++i];
919 else if (!strcmp(argv[i], "-sb")) /* selected background color */ 963 else if (!strcmp(argv[i], "-sb")) /* selected background color */
920 colors[SchemeSel][ColBg] = argv[++i]; 964 colortemp[2] = argv[++i];
921 else if (!strcmp(argv[i], "-sf")) /* selected foreground color */ 965 else if (!strcmp(argv[i], "-sf")) /* selected foreground color */
922 colors[SchemeSel][ColFg] = argv[++i]; 966 colortemp[3] = argv[++i];
923 else if (!strcmp(argv[i], "-w")) /* embedding window id */ 967 else if (!strcmp(argv[i], "-w")) /* embedding window id */
924 embed = argv[++i]; 968 embed = argv[++i];
925 else 969 else
@@ -938,8 +982,23 @@ main(int argc, char *argv[])
938 parentwin); 982 parentwin);
939 xinitvisual(); 983 xinitvisual();
940 drw = drw_create(dpy, screen, root, wa.width, wa.height, visual, depth, cmap); 984 drw = drw_create(dpy, screen, root, wa.width, wa.height, visual, depth, cmap);
941 if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) 985 readxresources();
986 /* Now we check whether to override xresources with commandline parameters */
987 if ( tempfonts )
988 fonts[0] = strdup(tempfonts);
989 if ( colortemp[0])
990 colors[SchemeNorm][ColBg] = strdup(colortemp[0]);
991 if ( colortemp[1])
992 colors[SchemeNorm][ColFg] = strdup(colortemp[1]);
993 if ( colortemp[2])
994 colors[SchemeSel][ColBg] = strdup(colortemp[2]);
995 if ( colortemp[3])
996 colors[SchemeSel][ColFg] = strdup(colortemp[3]);
997
998 if (!drw_fontset_create(drw, (const char**)fonts, LENGTH(fonts)))
942 die("no fonts could be loaded."); 999 die("no fonts could be loaded.");
1000
1001 free(fonts[0]);
943 lrpad = drw->fonts->h; 1002 lrpad = drw->fonts->h;
944 1003
945#ifdef __OpenBSD__ 1004#ifdef __OpenBSD__
diff --git a/stest b/stest
deleted file mode 100755
index d2d6ca3..0000000
--- a/stest
+++ /dev/null
Binary files differ