dwm-xrdb-6.2.diff 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. diff --git a/config.def.h b/config.def.h
  2. index 1c0b587..5db7d05 100644
  3. --- a/config.def.h
  4. +++ b/config.def.h
  5. @@ -7,15 +7,16 @@ static const int showbar = 1; /* 0 means no bar */
  6. static const int topbar = 1; /* 0 means bottom bar */
  7. static const char *fonts[] = { "monospace:size=10" };
  8. static const char dmenufont[] = "monospace:size=10";
  9. -static const char col_gray1[] = "#222222";
  10. -static const char col_gray2[] = "#444444";
  11. -static const char col_gray3[] = "#bbbbbb";
  12. -static const char col_gray4[] = "#eeeeee";
  13. -static const char col_cyan[] = "#005577";
  14. -static const char *colors[][3] = {
  15. - /* fg bg border */
  16. - [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
  17. - [SchemeSel] = { col_gray4, col_cyan, col_cyan },
  18. +static char normbgcolor[] = "#222222";
  19. +static char normbordercolor[] = "#444444";
  20. +static char normfgcolor[] = "#bbbbbb";
  21. +static char selfgcolor[] = "#eeeeee";
  22. +static char selbordercolor[] = "#005577";
  23. +static char selbgcolor[] = "#005577";
  24. +static char *colors[][3] = {
  25. + /* fg bg border */
  26. + [SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor },
  27. + [SchemeSel] = { selfgcolor, selbgcolor, selbordercolor },
  28. };
  29. /* tagging */
  30. @@ -56,7 +57,7 @@ static const Layout layouts[] = {
  31. /* commands */
  32. static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
  33. -static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
  34. +static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbordercolor, "-sf", selfgcolor, NULL };
  35. static const char *termcmd[] = { "st", NULL };
  36. static Key keys[] = {
  37. @@ -84,6 +85,7 @@ static Key keys[] = {
  38. { MODKEY, XK_period, focusmon, {.i = +1 } },
  39. { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
  40. { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
  41. + { MODKEY, XK_F5, xrdb, {.v = NULL } },
  42. TAGKEYS( XK_1, 0)
  43. TAGKEYS( XK_2, 1)
  44. TAGKEYS( XK_3, 2)
  45. diff --git a/drw.c b/drw.c
  46. index 8fd1ca4..e4968a0 100644
  47. --- a/drw.c
  48. +++ b/drw.c
  49. @@ -207,7 +207,7 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
  50. /* Wrapper to create color schemes. The caller has to call free(3) on the
  51. * returned color scheme when done using it. */
  52. Clr *
  53. -drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
  54. +drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount)
  55. {
  56. size_t i;
  57. Clr *ret;
  58. diff --git a/drw.h b/drw.h
  59. index 4bcd5ad..42b04ce 100644
  60. --- a/drw.h
  61. +++ b/drw.h
  62. @@ -39,7 +39,7 @@ void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned in
  63. /* Colorscheme abstraction */
  64. void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
  65. -Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
  66. +Clr *drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount);
  67. /* Cursor abstraction */
  68. Cur *drw_cur_create(Drw *drw, int shape);
  69. diff --git a/dwm.c b/dwm.c
  70. index 4465af1..7fa45c5 100644
  71. --- a/dwm.c
  72. +++ b/dwm.c
  73. @@ -35,6 +35,7 @@
  74. #include <X11/Xatom.h>
  75. #include <X11/Xlib.h>
  76. #include <X11/Xproto.h>
  77. +#include <X11/Xresource.h>
  78. #include <X11/Xutil.h>
  79. #ifdef XINERAMA
  80. #include <X11/extensions/Xinerama.h>
  81. @@ -56,6 +57,21 @@
  82. #define HEIGHT(X) ((X)->h + 2 * (X)->bw)
  83. #define TAGMASK ((1 << LENGTH(tags)) - 1)
  84. #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
  85. +#define XRDB_LOAD_COLOR(R,V) if (XrmGetResource(xrdb, R, NULL, &type, &value) == True) { \
  86. + if (value.addr != NULL && strnlen(value.addr, 8) == 7 && value.addr[0] == '#') { \
  87. + int i = 1; \
  88. + for (; i <= 6; i++) { \
  89. + if (value.addr[i] < 48) break; \
  90. + if (value.addr[i] > 57 && value.addr[i] < 65) break; \
  91. + if (value.addr[i] > 70 && value.addr[i] < 97) break; \
  92. + if (value.addr[i] > 102) break; \
  93. + } \
  94. + if (i == 7) { \
  95. + strncpy(V, value.addr, 7); \
  96. + V[7] = '\0'; \
  97. + } \
  98. + } \
  99. + }
  100. /* enums */
  101. enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
  102. @@ -177,6 +193,7 @@ static void grabkeys(void);
  103. static void incnmaster(const Arg *arg);
  104. static void keypress(XEvent *e);
  105. static void killclient(const Arg *arg);
  106. +static void loadxrdb(void);
  107. static void manage(Window w, XWindowAttributes *wa);
  108. static void mappingnotify(XEvent *e);
  109. static void maprequest(XEvent *e);
  110. @@ -232,6 +249,7 @@ static Monitor *wintomon(Window w);
  111. static int xerror(Display *dpy, XErrorEvent *ee);
  112. static int xerrordummy(Display *dpy, XErrorEvent *ee);
  113. static int xerrorstart(Display *dpy, XErrorEvent *ee);
  114. +static void xrdb(const Arg *arg);
  115. static void zoom(const Arg *arg);
  116. /* variables */
  117. @@ -1014,6 +1032,37 @@ killclient(const Arg *arg)
  118. }
  119. }
  120. +void
  121. +loadxrdb()
  122. +{
  123. + Display *display;
  124. + char * resm;
  125. + XrmDatabase xrdb;
  126. + char *type;
  127. + XrmValue value;
  128. +
  129. + display = XOpenDisplay(NULL);
  130. +
  131. + if (display != NULL) {
  132. + resm = XResourceManagerString(display);
  133. +
  134. + if (resm != NULL) {
  135. + xrdb = XrmGetStringDatabase(resm);
  136. +
  137. + if (xrdb != NULL) {
  138. + XRDB_LOAD_COLOR("dwm.normbordercolor", normbordercolor);
  139. + XRDB_LOAD_COLOR("dwm.normbgcolor", normbgcolor);
  140. + XRDB_LOAD_COLOR("dwm.normfgcolor", normfgcolor);
  141. + XRDB_LOAD_COLOR("dwm.selbordercolor", selbordercolor);
  142. + XRDB_LOAD_COLOR("dwm.selbgcolor", selbgcolor);
  143. + XRDB_LOAD_COLOR("dwm.selfgcolor", selfgcolor);
  144. + }
  145. + }
  146. + }
  147. +
  148. + XCloseDisplay(display);
  149. +}
  150. +
  151. void
  152. manage(Window w, XWindowAttributes *wa)
  153. {
  154. @@ -2110,6 +2159,17 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
  155. return -1;
  156. }
  157. +void
  158. +xrdb(const Arg *arg)
  159. +{
  160. + loadxrdb();
  161. + int i;
  162. + for (i = 0; i < LENGTH(colors); i++)
  163. + scheme[i] = drw_scm_create(drw, colors[i], 3);
  164. + focus(NULL);
  165. + arrange(NULL);
  166. +}
  167. +
  168. void
  169. zoom(const Arg *arg)
  170. {
  171. @@ -2136,6 +2196,8 @@ main(int argc, char *argv[])
  172. if (!(dpy = XOpenDisplay(NULL)))
  173. die("dwm: cannot open display");
  174. checkotherwm();
  175. + XrmInitialize();
  176. + loadxrdb();
  177. setup();
  178. #ifdef __OpenBSD__
  179. if (pledge("stdio rpath proc exec", NULL) == -1)