/* MIT/X Consortium License */

/* appearance */
//static const char font[] = "-*-terminus-*-*-*-*-*-*-*-*-*-*-*-*";
//static const char font[]   = "-artwiz-cureextra-*-*-*-*-*-*-*-*-*-*-*-*";
static const char font[]   = "-*-terminusmod-medium-r-normal-*-*-*-*-*-*-*-*-*";
//static const char font[]   = "-*-neep-medium-r-semicondensed-*-*-*-*-*-*-*-*-";
#define BOTTOM_GAP 20
static const unsigned int gappx = 5;
#define NUMCOLORS 8 
static const char colors[NUMCOLORS][ColLast][8] = {
// border foreground background
{ "#212121", "#696969", "#121212" }, // 0 = normal
{ "#696969", "#E0E0E0", "#121212" }, // 1 = selected
{ "#212121", "#CF4F88", "#121212" }, // 2 = red
{ "#212121", "#53A6A6", "#121212" }, // 3 = green
{ "#212121", "#FBB600", "#121212" }, // 4 = yellow
{ "#212121", "#47959E", "#121212" }, // 5 = cyan
{ "#212121", "#7E62B3", "#121212" }, // 6 = magenta
{ "#212121", "#C0C0C0", "#121212" }, // 7 = white
};

static const unsigned int borderpx  = 1;        /* border pixel of windows */
static const unsigned int snap      = 4;        /* snap pixel */
static const Bool showbar           = True;     /* False means no bar */
static const Bool topbar            = True;     /* False means bottom bar */

#define TAG_MAIN        1 << 0
#define TAG_WWW         1 << 1
#define TAG_GAMES       1 << 2
#define TAG_IRC         1 << 3
#define TAG_CODE        1 << 4
#define TAG_IM          1 << 5
#define TAG_MEDIA       1 << 6
#define TAG_MISC        1 << 7
#define TAG_ETC         1 << 8
static const Rule rules[] = {
	/* class           instance             title   tags mask     isfloating   monitor */
	{ "Gimp",           NULL,                NULL,   TAG_MISC,      True,        -1 },
	{ "Vimprobable",    NULL,                NULL,   TAG_WWW,      False,        -1 },
	{ "Tabbed",         NULL,                NULL,   TAG_WWW,      False,        -1 },
	{ "Skype",          NULL,                NULL,   TAG_IM,        True,        -1 },
	{ "Filezilla",      NULL,                NULL,   TAG_MISC,      True,        -1 },
	{ "MPlayer",        NULL,                NULL,   TAG_MEDIA,     True,        -1 },
	{ "VLC",            NULL,                NULL,   TAG_MEDIA,    False,        -1 },
	{ "Smplayer",       NULL,                NULL,   TAG_MEDIA,    False,        -1 },
	{ "Truecrypt",      NULL,                NULL,   TAG_ETC,       True,        -1 },
	{ "Zenity",         NULL,                NULL,   0,             True,        -1 },
	{ "Keepassx",       NULL,                NULL,   TAG_MISC,      True,        -1 },
	{  NULL,            NULL,        "scratchpad",   0,             True,        -1 },
	{ "Pidgin",         NULL,                NULL,   TAG_IM,        True,        -1 },
	{ "Chromium",       NULL,                NULL,   TAG_WWW,       True,        -1 },
	{ "Deluge",         NULL,                NULL,   TAG_ETC,       True,        -1 },
	{ "Geeqie",         NULL,                NULL,   0,             True,        -1 },
	{ "GThumb",         NULL,                NULL,   0,             True,        -1 },
	{ "Wicd",           NULL,                NULL,   0,             True,        -1 },
	{ "Codeblocks",     NULL,                NULL,   TAG_CODE,     False,        -1 },
	{ "net-minecraft",  NULL,                NULL,   TAG_GAMES,    False,        -1 },
	{  NULL,            NULL, "cb_console_runner",   TAG_CODE,      True,        -1 },
	{  NULL,            NULL,           "weechat",   TAG_IRC,      False,        -1 },
	{ "Geany",          NULL,                NULL,   TAG_CODE,     False,        -1 },
	{ "Evince",         NULL,                NULL,   0,             True,        -1 },
};

/* tags & layouts */
static const char      *tags[] = { "½ main", "Ñ www", "¾ game", "Â irc", "5-code", "Ï im", "7-media", "8-misc", "9-etc" };
static const int initlayouts[] = { 0, 0, 1, 0, 2 }; 

static const float mfact       = 0.55;  /*  factor of master area size [0.05..0.95]         */
static const Bool resizehints  = False; /*  True means respect size hints in tiled resizals */

//#include "bstack.c"
//#include "bstackhoriz.c"
//#include "pidgin-grid.c"
static const Layout  layouts[] = {
	/* symbol     arrange function   */
	{ "þ",      bstack },  /* first entry is default */
	{ "ú",      monocle },
	{ "ý",      NULL },
	{ "ÿ",      tile },
	{ "û",      bstackhoriz },
//	{ "[P}",    pidgin },
};

/*  key definitions  */
#define TAGKEYS(KEY,TAG) \
	{ MODKEY,                       KEY,      view,           {.ui = 1 << TAG} }, \
	{ MODKEY|ControlMask,           KEY,      toggleview,     {.ui = 1 << TAG} }, \
	{ MODKEY|ShiftMask,             KEY,      tag,            {.ui = 1 << TAG} }, \
	{ MODKEY|ControlMask|ShiftMask, KEY,      toggletag,      {.ui = 1 << TAG} },


/* commands */
static const char  *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", colors[0][ColBG], "-nf", colors[0][ColFG], "-sb", colors[1][ColBG], "-sf", colors[1][ColFG], NULL };
static const char   *termcmd[] = { "urxvtc", NULL };
static const char    *irccmd[] = { "urxvtc", "-e", "'tmux", "-e", "weechat-curses'", NULL };
static const char    *wwwcmd[] = { "chromium", NULL };
static const char   *tmuxcmd[] = { "urxvtc", "-title", "tmux", "-e", "tmux", NULL };
static const char    *padcmd[] = { "urxvtc", "-title", "scratchpad", "-geometry", "70x20+504+12", NULL };
static const char   *wicdcmd[] = { "urxvtc", "-title", "scratchpad", "-geometry", "70x20+504+12", "-e", "wicd-curses", NULL };

#define ZSHCMD(cmd) { .v = (const char*[]){ "/bin/zsh", "-c", cmd, NULL } }

#define MODKEY Mod4Mask
#define ALT    Mod1Mask
static Key keys[] = {
	/*   modifier                   key        function        argument                */
	{ 0,                            XK_Menu,   spawn,          {.v = dmenucmd }        },
	{ MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd }         },
	{ MODKEY|ShiftMask,             XK_i,      spawn,          {.v = irccmd }          },
	{ MODKEY,                       XK_w,      spawn,          {.v = wicdcmd }         }, 
	{ ControlMask|ALT,              XK_t,      spawn,          {.v = tmuxcmd }         },
  	{ ControlMask|MODKEY,           XK_p,      spawn,          {.v = padcmd }          },
        { ControlMask|ALT,              XK_q,      spawn,          ZSHCMD("oblogout")      },
	{ MODKEY,                       XK_b,      togglebar,      {0}                     },
	{ MODKEY,                       XK_j,      focusstack,     {.i = +1 }              },
	{ MODKEY,                       XK_k,      focusstack,     {.i = -1 }              },
        { MODKEY,                       XK_s,      swapfocus,      {0}                     },
	{ MODKEY|ControlMask,           XK_j,      pushdown,       {0}                     },
	{ MODKEY|ControlMask,           XK_k,      pushup,         {0}                     },
	{ MODKEY,                       XK_h,      setmfact,       {.f = -0.05}            },
	{ MODKEY,                       XK_l,      setmfact,       {.f = +0.05}            },
	{ MODKEY,                       XK_Return, zoom,           {0}                     },
	{ MODKEY,                       XK_Tab,    view,           {0}                     },
	{ MODKEY|ShiftMask,             XK_c,      killclient,     {0}                     },
	{ MODKEY,                       XK_m,      setlayout,      {.v = &layouts[1]}      },
	{ MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]}      },
        { MODKEY|ShiftMask,             XK_t,      setlayout,      {.v = &layouts[3]}      },
	{ MODKEY,                       XK_f,      setlayout,      {.v = &layouts[2]}      },
 	{ MODKEY,                       XK_space,  setlayout,      {0}                     },
	{ MODKEY|ShiftMask,             XK_space,  togglefloating, {0}                     },
	{ MODKEY,                       XK_0,      view,           {.ui = ~0 }             },
	{ MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 }             },
	{ MODKEY,                       XK_comma,  focusmon,       {.i = -1 }              },
	{ MODKEY,                       XK_period, focusmon,       {.i = +1 }              },
	{ MODKEY|ShiftMask,             XK_comma,  tagmon,         {.i = -1 }              },
	{ MODKEY|ShiftMask,             XK_period, tagmon,         {.i = +1 }              },
  	{ MODKEY|ControlMask,           XK_Left,   tagcycle,       {.i = -1 }              },
	{ MODKEY|ControlMask,           XK_Right,  tagcycle,       {.i = +1 }              },
	{ 0,                            XF86XK_HomePage,          spawn,     ZSHCMD("chromium") },
	{ 0,                            XF86XK_AudioPlay,         spawn,     ZSHCMD("mpc toggle") },
	{ 0,                            XF86XK_AudioPrev,         spawn,     ZSHCMD("mpc prev") },
	{ 0,                            XF86XK_AudioNext,         spawn,     ZSHCMD("mpc next") },
	{ 0,                            XF86XK_AudioStop,         spawn,     ZSHCMD("mpc stop") },
	{ 0,                            XF86XK_AudioLowerVolume,  spawn,     ZSHCMD("amixer -c 1 set PCM 1dB-") },
	{ 0,                            XF86XK_AudioRaiseVolume,  spawn,     ZSHCMD("amixer -c 1 set PCM 1dB+") },
	{ 0,                            XF86XK_AudioMute,         spawn,     ZSHCMD("amixer -c 1 set PCM toggle") },
	{ 0,                            XF86XK_Sleep,             spawn,     ZSHCMD("slimlock") },
	{ 0,                            XK_Print,                 spawn,     ZSHCMD("scrot -cd 5 'dwm-%H:%M-%d-%m-%Y.png' -e 'mv $f /home/derp/scrots && mirage  ~/scrots/$n'") },
	{ MODKEY,                       XK_Print,                 spawn,     ZSHCMD("import $HOME/scrots/dwm-$(date%H:%M-%d-%m-%Y.png) ") },
	  TAGKEYS(                        XK_1,                      0)
	  TAGKEYS(                        XK_2,                      1)
	  TAGKEYS(                        XK_3,                      2)
	  TAGKEYS(                        XK_4,                      3)
	  TAGKEYS(                        XK_5,                      4)
	  TAGKEYS(                        XK_6,                      5)
	  TAGKEYS(                        XK_7,                      6)
	  TAGKEYS(                        XK_8,                      7)
	  TAGKEYS(                        XK_9,                      8)
	{ MODKEY|ShiftMask,             XK_q,      quit,           {0} },
};

/* button definitions */
/* click can be ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
static Button buttons[] = {
	/* click                event mask      button          function        argument */
	{ ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
	{ ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
	{ ClkWinTitle,          0,              Button2,        zoom,           {0} },
	{ ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
	{ ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
	{ ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
	{ ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
	{ ClkTagBar,            0,              Button1,        view,           {0} },
	{ ClkTagBar,            0,              Button3,        toggleview,     {0} },
	{ ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
	{ ClkTagBar,            MODKEY,         Button3,        toggletag,