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

/* appearance */
static const unsigned int borderpx  = 3;        /* border pixel of windows */
static const unsigned int snap      = 32;       /* snap pixel */
static const int showbar            = 1;        /* 0 means no bar */
static const int topbar             = 1;        /* 0 means bottom bar */
static const char *fonts[]          = { "SourceCodeProSemiBold:size=10" };
static const char dmenufont[]       = "monospace:size=10";
static const char col_gray1[]       = "#222222";
static const char col_gray2[]       = "#444444";
static const char col_gray3[]       = "#bbbbbb";
static const char col_gray4[]       = "#eeeeee";
static const char col_cyan[]        = "#005577";

// solarized
static const char sol_base03[]      = "#002b36";
static const char sol_base02[]      = "#073642";
static const char sol_base01[]      = "#586e75";
static const char sol_base00[]      = "#657b83";
static const char sol_base0[]       = "#839496";
static const char sol_base1[]       = "#93a1a1";
static const char sol_base2[]       = "#eee8d5";
static const char sol_base3[]       = "#fdf6e3";
static const char sol_yellow[]      = "#b58900";
static const char sol_orange[]      = "#cb4b16";
static const char sol_red[]         = "#dc322f";
static const char sol_magenta[]     = "#d33682";
static const char sol_violet[]      = "#6c71c4";
static const char sol_blue[]        = "#268bd2";
static const char sol_cyan[]        = "#2aa198";
static const char sol_green[]       = "#859900";

static const char *colors[][3]      = {
	/*               fg           bg          border   */
	[SchemeNorm] = { sol_magenta, sol_base03, sol_base02 },
	[SchemeSel]  = { sol_base03,  sol_green,  sol_orange },
};

/* tagging */
static const char *tags[] = { "a", "r", "s", "t", "z", "x", "c", "v", };

static const Rule rules[] = {
	/* xprop(1):
	 *	WM_CLASS(STRING) = instance, class
	 *	WM_NAME(STRING) = title
	 */
	/* class          instance    title       tags mask     iscentered   isfloating   monitor */
	{ "Gimp",         NULL,       NULL,       0,            0,           1,           -1 },
	{ "Alacritty",    NULL,       NULL,       0,            1,           0,           -1 },
	{ "Firefox",      NULL,       NULL,       1 << 1,       0,           0,           -1 },
	{ "firefox",      NULL,       NULL,       1 << 1,       0,           0,           -1 },
	{ "discord",      NULL,       NULL,       1 << 2,       0,           0,           -1 },
	{ "Steam",        NULL,       NULL,       1 << 3,       0,           0,           -1 },
	{ "Lutris",       NULL,       NULL,       1 << 3,       0,           0,           -1 },
	{ "UE4Editor",    NULL,       NULL,       1 << 3,       0,           0,           -1 },
	/* zoom */
	{ "zoom",         NULL,       NULL,       0,            1,           1,           -1 },
	{ "zoom",         NULL,  "Zoom Meeting",  0,            0,           0,           -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 int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
static const int centerfirst = 1;    /* center first window if it has rule */

static const Layout layouts[] = {
	/* symbol     arrange function */
	{ "[]=",      tile },    /* first entry is default */
	{ "|M|",      centeredmaster },
	{ ">M>",      centeredfloatingmaster },
	{ "[M]",      monocle },
	{ "><>",      NULL },    /* no layout function means floating behavior */
};

/* key definitions */
#define MODKEY Mod4Mask
#define ALTKEY Mod1Mask
#define TAGKEYS(KEY,TAG) \
	{ MODKEY,                       KEY,      view,           {.ui = 1 << TAG} }, \
	{ ALTKEY,                       KEY,      toggleview,     {.ui = 1 << TAG} }, \
	{ MODKEY|ShiftMask,             KEY,      tag,            {.ui = 1 << TAG} }, \
	{ ALTKEY|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_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *roficmd[] = { "rofi", "-modi", "drun,run", "-show", "run", "-font", "SourceCodePro 12" };
static const char *termcmd[]  = { "alacritty", NULL };
static const char *filecmd[]  = { "pcmanfm", NULL };
static const char *browsercmd[]  = { "firefox", NULL };
static const char *slockcmd[]  = { "slock", NULL };

/* functions */
void focusmaster(const Arg* arg);

/* variables */
static int gamingmodmask = ALTKEY|MODKEY; /* mod keys to disable when gaming */

static Key togglegamingkey = { MODKEY, XK_g, togglegaming, {0} };

static Key keys[] = {
	/* modifier                     key        function        argument */
	//{ MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
	{ MODKEY,                       XK_space,  spawn,          {.v = roficmd } },
	{ MODKEY,                       XK_Return, spawn,          {.v = termcmd } },
	{ MODKEY,                       XK_e,      spawn,          {.v = filecmd } },
	{ MODKEY,                       XK_b,      spawn,          {.v = browsercmd } },
	{ MODKEY,                       XK_Escape, spawn,          {.v = slockcmd } },
	{ MODKEY,                       XK_q,      spawn,          SHCMD("~/.config/wm_scripts/screenshot.sh") },
	{ MODKEY|ShiftMask,             XK_q,      spawn,          SHCMD("~/.config/wm_scripts/all.sh") },
	{ MODKEY|ControlMask,           XK_b,      togglebar,      {0} },
	{ MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
	{ MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
	{ MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
	{ MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
	{ MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
	{ MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
	{ MODKEY|ControlMask,           XK_Return, zoom,           {0} },
	{ MODKEY,                       XK_Tab,    view,           {0} },
	{ MODKEY,                       XK_w,      killclient,     {0} },
	{ MODKEY,                       XK_1,      setlayout,      {.v = &layouts[0]} },
	{ MODKEY,                       XK_2,      setlayout,      {.v = &layouts[1]} },
	{ MODKEY,                       XK_3,      setlayout,      {.v = &layouts[4]} },
	{ MODKEY,                       XK_f,      togglelayout,   {.v = &layouts[3]} },
	{ MODKEY,                       XK_p,      togglecenterfirst,   {0} },
	{ MODKEY,                       XK_apostrophe,  focusmaster,{0} },
	{ MODKEY|ControlMask,           XK_space,  togglefloating, {0} },
	{ MODKEY,                       XK_0,      view,           {.ui = ~0 } },
	{ ALTKEY,                       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 } },
	TAGKEYS(                        XK_a,                      0)
	TAGKEYS(                        XK_r,                      1)
	TAGKEYS(                        XK_s,                      2)
	TAGKEYS(                        XK_t,                      3)
	TAGKEYS(                        XK_z,                      4)
	TAGKEYS(                        XK_x,                      5)
	TAGKEYS(                        XK_c,                      6)
	TAGKEYS(                        XK_v,                      7)
	{ MODKEY|ControlMask,           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} },
};

void
focusmaster(const Arg* arg)
{
	focus(NULL);
}