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

#include <X11/XF86keysym.h>

/* appearance */
static  unsigned int borderpx       = 2; /* border pixel of windows */
static  unsigned int snap           = 32; /* snap pixel */
static  unsigned int systraypinning = 0; /* 0: sloppy systray follows selected monitor, >0: pin systray to monitor X */
static  unsigned int systrayspacing = 2; /* systray spacing */
static  int systraypinningfailfirst = 1; /* 1: if pinning fails, display systray on the first monitor, False: display systray on the last monitor*/
static  int          showsystray    = 1; /* 0 means no systray */
static  unsigned int gappih         = 10; /* horiz inner gap between windows */
static  unsigned int gappiv         = 10; /* vert inner gap between windows */
static  unsigned int gappoh         = 10; /* horiz outer gap between windows and screen edge */
static  unsigned int gappov         = 10; /* vert outer gap between windows and screen edge */
static  int          smartgaps      = 1; /* 1 means no outer gap when there is only one window */
static  int          showbar        = 1; /* 0 means no bar */
static  int          topbar         = 1; /* 0 means bottom bar */
static  char *fonts[]               = { "FantasqueSansMono Nerd Font:style=Regular:size=11" };
static  char dmenufont[]            = "monospace:size=10";
static  char normbgcolor[]          = "#fbf1c7";
static  char normbordercolor[]      = "#d5c4a1";
static  char normfgcolor[]          = "#3c3836";
static  char selfgcolor[]           = "#fbf1c7";
static  char selbordercolor[]       = "#b16286";
static  char selbgcolor[]           = "#8f3f71";
static  char statusbgcolor[]        = "#ebdbb2";
static  char statusfgcolor[]        = "#7c6f64";
static  char *colors[][3]           = {
  /*               fg         bg         border   */
  [SchemeNorm]     = { normfgcolor, normbgcolor, normbordercolor },
  [SchemeSel]      = { selfgcolor,  selbgcolor,  selbordercolor  },
  [SchemeStatus]   = { statusfgcolor, statusbgcolor, normbordercolor }, // Statusbar right {text,background,not used but cannot be empty}
  [SchemeTagsSel]  = { selfgcolor, selbgcolor, selbordercolor }, // Tagbar left selected {text,background,not used but cannot be empty}
  [SchemeTagsNorm] = { normfgcolor, normbgcolor, normbordercolor }, // Tagbar left unselected {text,background,not used but cannot be empty}
  [SchemeInfoSel]  = { selbgcolor, normbgcolor, selbordercolor }, // infobar middle  selected {text,background,not used but cannot be empty}
  [SchemeInfoNorm] = { normfgcolor, normbgcolor, normbordercolor }, // infobar middle  unselected {text,background,not used but cannot be empty}
};

/* tagging */
// static const char *tags[]    = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; // for non glyph tag name
/*                                 file      editor    term     image     video     record      misc      misc     browser  */
static const char *tags[]    = { "\ue5ff", "\uf44f", "\uf120", "\uf7e8", "\uf03d", "\uf86b", "\uf8b5", "\uf8b8", "\ufa9e" }; // nerd fot based glyph
static const char *tagsalt[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };

static const Rule rules[] = {
  /* xprop(1):
   *	WM_CLASS(STRING) = instance, class
   *	WM_NAME(STRING) = title
   */
  /* class          instance    title       tags mask     isfloating   monitor */
  { "Gimp",         NULL,       NULL,       1 << 3,       0,           -1 },
  { "zoom ",        NULL,       NULL,    1 << 4,       1,           -1 },
  { "firefox",      NULL,       NULL,       1 << 8,       0,           -1 },
  { "st",           NULL,       NULL,       1 << 2,       0,           -1 },
  { "kitty",        NULL,       NULL,       1 << 2,       0,           -1 },
  { "Emacs",        NULL,       NULL,       1 << 1,       0,           -1 },
  { "Pcmanfm",      NULL,       NULL,       1,            0,           -1 },
  { "Xephyr",       NULL,       NULL,       0,            1,           -1 },
  { "Chromium",     NULL,       "Zotero Item Selector",   0,     1,    -1 },
  { "Pavucontrol",  NULL,       NULL,       0,            1,           -1 },
  { "easyeffects", "easyeffects", NULL,     0,            1,           -1 },
  { "Zotero", "Toplevel",       NULL,       0,            1,           -1 },
  { "NoiseTorch",   NULL,       NULL,       0,            1,           -1 },
  { "Lxappearance", "lxappearance", NULL,   0,            1,           -1 },
};

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

#define FORCE_VSPLIT 1  /* nrowgrid layout: force two clients to always split vertically */
#include "vanitygaps.c"

static const Layout layouts[] = {
  /* symbol     arrange function */
  { ":::",      gaplessgrid },
  { "[]=",      tile },    /* first entry is default */
  { "[M]",      monocle },
  { "[@]",      spiral },
  { "[\\]",     dwindle },
  { "H[]",      deck },
  { "TTT",      bstack },
  { "===",      bstackhoriz },
  { "HHH",      grid },
  { "###",      nrowgrid },
  { "---",      horizgrid },
  { "|M|",      centeredmaster },
  { ">M>",      centeredfloatingmaster },
  { "><>",      NULL },    /* no layout function means floating behavior */
  { NULL,       NULL },
};

/* key definitions */
#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} },
#define HOLDKEY XK_Super_L // replace 0 with the keysym to activate holdbar, XK_Super_L is left super key

/* 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", normbgcolor, "-nf", normfgcolor, "-sb", selbordercolor, "-sf", selfgcolor, NULL };
static const char *launchercmd[] = { "rofi", "-show", "combi", NULL };
static const char *termcmd[]  = { "kitty", NULL };
static const char *browsercmd[] = { "firefox", NULL, NULL, NULL, "Firefox" };
static const char *filemancmd[] = { "pcmanfm", NULL, NULL, NULL, "Pcmanfm" };
static const char *lockcmd[]  = { "lockscreen", NULL};
static const char *volinccmd[]  = { "vol", "up"};
static const char *voldeccmd[]  = { "vol", "down"};
static const char *volmutecmd[]  = { "vol", "mute"};
static const char *briinccmd[]  = { "brightness", "up"};
static const char *brideccmd[]  = { "brightness", "down"};

#include "focusurgent.c"
/*
 * Xresources preferences to load at startup
 */
ResourcePref resources[] = {
  { "normbgcolor",        STRING,  &normbgcolor },
  { "normbordercolor",    STRING,  &normbordercolor },
  { "normfgcolor",        STRING,  &normfgcolor },
  { "statusfgcolor",      STRING,  &statusfgcolor },
  { "statusbgcolor",      STRING,  &statusbgcolor },
  { "selbgcolor",         STRING,  &selbgcolor },
  { "selbordercolor",     STRING,  &selbordercolor },
  { "selfgcolor",         STRING,  &selfgcolor },
  { "borderpx",           INTEGER, &borderpx },
  { "snap",               INTEGER, &snap },
  { "showbar",            INTEGER, &showbar },
  { "topbar",             INTEGER, &topbar },
  { "nmaster",            INTEGER, &nmaster },
  { "resizehints",        INTEGER, &resizehints },
  { "mfact",              FLOAT,   &mfact },
};

static Key keys[] = {
  /* modifier                     key        function        argument */
  { Mod1Mask,                     XK_space,  spawn,          {.v = launchercmd } },
  { MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
  { Mod1Mask,                     XK_Up,     spawn,          {.v = volinccmd } },
  { Mod1Mask,                     XK_Down,   spawn,          {.v = voldeccmd } },
  { 0,            XF86XK_AudioRaiseVolume,   spawn,          {.v = volinccmd } },
  { 0,            XF86XK_AudioLowerVolume,   spawn,          {.v = voldeccmd } },
  { 0,            XF86XK_MonBrightnessUp,    spawn,          {.v = briinccmd } },
  { 0,            XF86XK_MonBrightnessDown,  spawn,          {.v = brideccmd } },
  { Mod1Mask,                     XK_m,      spawn,          {.v = volmutecmd } },
  { MODKEY,                       XK_v,      runorraise,     {.v = browsercmd } },
  { MODKEY,                       XK_e,      runorraise,     {.v = filemancmd } },
  { MODKEY,                       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,                       XK_Return, zoom,           {0} },
  { MODKEY|Mod1Mask,              XK_u,      incrgaps,       {.i = +1 } },
  { MODKEY|Mod1Mask|ShiftMask,    XK_u,      incrgaps,       {.i = -1 } },
  { MODKEY|Mod1Mask,              XK_i,      incrigaps,      {.i = +1 } },
  { MODKEY|Mod1Mask|ShiftMask,    XK_i,      incrigaps,      {.i = -1 } },
  { MODKEY|Mod1Mask,              XK_o,      incrogaps,      {.i = +1 } },
  { MODKEY|Mod1Mask|ShiftMask,    XK_o,      incrogaps,      {.i = -1 } },
  { MODKEY|Mod1Mask,              XK_6,      incrihgaps,     {.i = +1 } },
  { MODKEY|Mod1Mask|ShiftMask,    XK_6,      incrihgaps,     {.i = -1 } },
  { MODKEY|Mod1Mask,              XK_7,      incrivgaps,     {.i = +1 } },
  { MODKEY|Mod1Mask|ShiftMask,    XK_7,      incrivgaps,     {.i = -1 } },
  { MODKEY|Mod1Mask,              XK_8,      incrohgaps,     {.i = +1 } },
  { MODKEY|Mod1Mask|ShiftMask,    XK_8,      incrohgaps,     {.i = -1 } },
  { MODKEY|Mod1Mask,              XK_9,      incrovgaps,     {.i = +1 } },
  { MODKEY|Mod1Mask|ShiftMask,    XK_9,      incrovgaps,     {.i = -1 } },
  { MODKEY|Mod1Mask,              XK_0,      togglegaps,     {0} },
  { MODKEY|Mod1Mask|ShiftMask,    XK_0,      defaultgaps,    {0} },
  { MODKEY,                       XK_Tab,    view,           {0} },
  { MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
  { MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
  { MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
  { MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
  { MODKEY|ControlMask,           XK_comma,  cyclelayout,    {.i = -1 } },
  { MODKEY|ControlMask,           XK_period, cyclelayout,    {.i = +1 } },
  { MODKEY,                       XK_space,  setlayout,      {0} },
  { MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
  { MODKEY,                       XK_Down,   moveresize,     {.v = "0x 25y 0w 0h" } },
  { MODKEY,                       XK_Up,     moveresize,     {.v = "0x -25y 0w 0h" } },
  { MODKEY,                       XK_Right,  moveresize,     {.v = "25x 0y 0w 0h" } },
  { MODKEY,                       XK_Left,   moveresize,     {.v = "-25x 0y 0w 0h" } },
  { MODKEY|ShiftMask,             XK_Down,   moveresize,     {.v = "0x 0y 0w 25h" } },
  { MODKEY|ShiftMask,             XK_Up,     moveresize,     {.v = "0x 0y 0w -25h" } },
  { MODKEY|ShiftMask,             XK_Right,  moveresize,     {.v = "0x 0y 25w 0h" } },
  { MODKEY|ShiftMask,             XK_Left,   moveresize,     {.v = "0x 0y -25w 0h" } },
  { MODKEY|ControlMask,           XK_Up,     moveresizeedge, {.v = "t"} },
  { MODKEY|ControlMask,           XK_Down,   moveresizeedge, {.v = "b"} },
  { MODKEY|ControlMask,           XK_Left,   moveresizeedge, {.v = "l"} },
  { MODKEY|ControlMask,           XK_Right,  moveresizeedge, {.v = "r"} },
  { MODKEY|ControlMask|ShiftMask, XK_Up,     moveresizeedge, {.v = "T"} },
  { MODKEY|ControlMask|ShiftMask, XK_Down,   moveresizeedge, {.v = "B"} },
  { MODKEY|ControlMask|ShiftMask, XK_Left,   moveresizeedge, {.v = "L"} },
  { MODKEY|ControlMask|ShiftMask, XK_Right,  moveresizeedge, {.v = "R"} },
  { MODKEY,                       XK_0,      view,           {.ui = ~0 } },
  { MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
  { MODKEY|ShiftMask,             XK_j,      pushdown,       {0} },
  { MODKEY|ShiftMask,             XK_k,      pushup,         {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,                       XK_n,      togglealttag,   {0} },
  { MODKEY|ShiftMask,             XK_q,      quit,           {1} },
  { MODKEY,                       XK_u,      focusurgent,    {0} },
  { 0,                            HOLDKEY,   holdbar,        {0} },
  { MODKEY|ControlMask|ShiftMask, XK_q,      quit,           {0} },
  { MODKEY,                       XK_q,      spawn,          {.v = lockcmd} },
  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)
};

/* 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} },
};

/* quitting */
static const int EMPTY_WINDOW_COUNT = 5;
