sites

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

dwm-xrdb-6.2.diff (7033B)


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