/* See LICENSE file for copyright and license details. */

#include "../style.h"

/* appearance */
static const unsigned int borderpx  = BORDER_PX;/* border pixel of windows */
static const unsigned int gappx     = GAP_PX;   /* gap pixel between windows */
static const unsigned int snap      = 32;       /* snap pixel */
static const int showbar            = 1;        /* 0 means no bar */
static const int topbar             = TOPBAR;   /* 0 means bottom bar */
static const char *fonts[]          = { FONT ":size=" FONTSIZE ,
                                       "FontAwesome:size=" FONTAWSMSIZE };

static const char dmenufont[]       = FONT ":size=" FONTSIZE;
static const char col_blk[]         = SC0;
static const char col_red[]         = SC1;
static const char col_grn[]         = SC2;
static const char col_ylw[]         = SC3;
static const char col_blu[]         = SC4;
static const char col_pnk[]         = SC5;
static const char col_cyn[]         = SC6;
static const char col_wht[]         = SC7;
static const char col_mid[]         = SC8;

static const char *colors[][3]      = {
	/*					fg         bg          border   */
  [SchemeNorm] = { col_wht, col_blk, col_blk},
  [SchemeSel] = { col_blk, col_mid, col_blk},
  [SchemeBlu] = { col_blu, col_blk, col_blk},
  [SchemeCyn] = { col_cyn, col_blk, col_blk},
  [SchemeGrn] = { col_grn, col_blk, col_blk},
  [SchemeYlw] = { col_ylw, col_blk, col_blk},
  [SchemePnk] = { col_pnk, col_blk, col_blk},
  [SchemeRed] = { col_red, col_blk, col_blk},
};

/* tagging */
//static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
static const char *tags[] = {
  TAGN1 ,
  TAGN2 ,
  TAGN3 ,
  TAGN4 ,
  TAGN5 ,
  TAGN6 ,
  TAGN7 ,
  TAGN8 ,
  TAGN9 ,
};

static const Rule rules[] = {
	/* xprop(1):
	 *	WM_CLASS(STRING) = instance, class
	 *	WM_NAME(STRING) = title
	 */
  /* class      instance    title       tags mask     isfloating   isterm    noswallow monitor */
//{ "Gimp",     NULL,       NULL,       0,            1,           0,        0,        -1 },
  { "waterfox", NULL,       NULL,       1 << 8,       0,           0,        0,        -1 },
	{ "st",       NULL,       NULL,       0,            0,           1,        1,        -1 },
	{ "pd",       NULL,       NULL,       0,            1,           0,        1,        -1 },
};

/* layout(s) */
static const float mfact     = 0.55; /* factor of master area size [0.05..0.95] */
static const int nmaster     = 1;    /* number of clients in master area */
static const int resizehints = 1;    /* 1 means respect size hints in tiled resizals */

static const Layout layouts[] = {
	/* symbol     arrange function */
	{ "T",      tile },
	{ "M",      monocle },
  { "D",      deck },
	{ "F",      NULL },
	{ "H",      grid },
};

/* key definitions */
#define XF86AudioLowerVolume  0x1008ff11
#define XF86AudioRaiseVolume  0x1008ff13
#define XF86AudioMute         0x1008ff12
#define XF86AudioNext         0x1008ff17
#define XF86AudioPrev         0x1008ff16
#define XF86AudioPlay         0x1008ff14
#define XF86MonBrightnessUp   0x1008ff02
#define XF86MonBrightnessDown 0x1008ff03
#define Print                 0xff61
#define MODKEY Mod4Mask
#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} },

/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }

/* commands */
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_blk, "-nf", col_wht, "-sb", col_mid, "-sf", col_blk, NULL };
static const char *termcmd[]  = { TERMINAL, NULL };
static const char *poff[]   = {"poff", NULL };
static const char *muusb[]  = {"muusb", NULL };
static const char *web[]    = {"sde-ctl","web",NULL };
static const char *volup[]  = {"sde-ctl","vol","up",NULL };
static const char *voldn[]  = {"sde-ctl","vol","down",NULL };
static const char *volmt[]  = {"sde-ctl","vol","mute",NULL };
static const char *lghtm[]  = {"sde-ctl","light","more",NULL };
static const char *lghtl[]  = {"sde-ctl","light","less",NULL };
static const char *munext[] = {"sde-ctl","mu","next", NULL};
static const char *muprev[] = {"sde-ctl","mu","prev", NULL};
static const char *muplay[] = {"sde-ctl","mu","play", NULL};
char *scrotshot[] = {"scrotshot", NULL};

static Key keys[] = {
	/* modifier                key        function        argument */
	{ MODKEY,                  XK_p,      spawn,          {.v = dmenucmd } },
	{ MODKEY,                  XK_Return, spawn,          {.v = termcmd } },
	{ MODKEY,                  XK_b,      togglebar,      {0} },
	{ MODKEY,                  XK_k,      focusstack,     {.i = +1 } },
	{ MODKEY,                  XK_j,      focusstack,     {.i = -1 } },
	{ MODKEY|ShiftMask,        XK_k,      incnmaster,     {.i = +1 } },
	{ MODKEY|ShiftMask,        XK_j,      incnmaster,     {.i = -1 } },
	{ MODKEY,                  XK_h,      setmfact,       {.f = -0.05} },
	{ MODKEY,                  XK_l,      setmfact,       {.f = +0.05} },
	{ MODKEY|ShiftMask,        XK_Return, zoom,           {0} },
	{ MODKEY,                  XK_Tab,    view,           {0} },
	{ MODKEY|ShiftMask,        XK_c,      killclient,     {0} },
	{ MODKEY,                  XK_t,      setlayout,      {.v = &layouts[0]} },
	{ MODKEY,                  XK_m,      setlayout,      {.v = &layouts[1]} },
	{ MODKEY,                  XK_d,      setlayout,      {.v = &layouts[2]} },
	{ MODKEY,                  XK_f,      setlayout,      {.v = &layouts[3]} },
	{ MODKEY,                  XK_g,      setlayout,      {.v = &layouts[4]} },
	{ 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 } },
  /* custom commands */
	{ MODKEY,                  XK_o,                 spawn, {.v = poff }},
	{ MODKEY,                  XK_u,                 spawn, {.v = muusb }},
	{ MODKEY,                  XK_w,	               spawn, {.v = web }},
	{ MODKEY,                  XK_i,	               spawn, {.v = scrotshot }},
	{ 0,                       Print,                spawn, {.v = scrotshot }},
	{ 0,			                 XF86MonBrightnessUp,	 spawn, {.v = lghtm }},
	{ 0,			                 XF86MonBrightnessDown,spawn, {.v = lghtl }},
	{ 0,			                 XF86AudioMute,	       spawn, {.v = volmt }},
	{ 0,			                 XF86AudioRaiseVolume, spawn, {.v = volup }},
	{ 0,			                 XF86AudioLowerVolume, spawn, {.v = voldn }},
	{ 0,			                 XF86AudioNext,        spawn, {.v = munext }},
	{ 0,			                 XF86AudioPrev,        spawn, {.v = muprev }},
	{ 0,			                 XF86AudioPlay,        spawn, {.v = muplay }},
  TAGKEYS(                   TAGS1,                0)
  TAGKEYS(                   TAGS2,                1)
  TAGKEYS(                   TAGS3,                2)
  TAGKEYS(                   TAGS4,                3)
  TAGKEYS(                   TAGS5,                4)
  TAGKEYS(                   TAGS6,                5)
  TAGKEYS(                   TAGS7,                6)
  TAGKEYS(                   TAGS8,                7)
  TAGKEYS(                   TAGS9,                8)
	{ MODKEY|ShiftMask,        XK_q,      quit,           {0} },
};

/* button definitions */
/* click can be ClkTagBar, 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,      {0} },
};