From f8f756f19bc91de34deccdb1aa14941719fd91d3 Mon Sep 17 00:00:00 2001
From: Matei Adriel <rafaeladriel11@gmail.com>
Date: Mon, 17 Jan 2022 19:22:09 +0200
Subject: [PATCH] feat: improved xmonad config

---
 modules/applications/xmonad/.gitignore        |   1 +
 modules/applications/xmonad/Main.hs           | 102 ++++++++++++++++++
 modules/applications/xmonad/default.nix       |   2 +-
 .../applications/xmonad/xmonad-config.cabal   |  15 +++
 modules/applications/xmonad/xmonad.hs         |  72 -------------
 5 files changed, 119 insertions(+), 73 deletions(-)
 create mode 100644 modules/applications/xmonad/.gitignore
 create mode 100644 modules/applications/xmonad/Main.hs
 create mode 100644 modules/applications/xmonad/xmonad-config.cabal
 delete mode 100644 modules/applications/xmonad/xmonad.hs

diff --git a/modules/applications/xmonad/.gitignore b/modules/applications/xmonad/.gitignore
new file mode 100644
index 0000000..4c61acd
--- /dev/null
+++ b/modules/applications/xmonad/.gitignore
@@ -0,0 +1 @@
+dist-newstyle
\ No newline at end of file
diff --git a/modules/applications/xmonad/Main.hs b/modules/applications/xmonad/Main.hs
new file mode 100644
index 0000000..5639065
--- /dev/null
+++ b/modules/applications/xmonad/Main.hs
@@ -0,0 +1,102 @@
+{-# LANGUAGE BlockArguments #-}
+
+import Control.Monad (join)
+import Data.Function ((&))
+import XMonad
+import XMonad.Actions.SpawnOn
+import XMonad.Config.Kde
+import XMonad.Hooks.EwmhDesktops (ewmh, fullscreenEventHook)
+import XMonad.Hooks.ManageDocks
+import XMonad.Layout.Spacing
+import XMonad.Layout.ThreeColumns
+import XMonad.Util.EZConfig
+
+kdeOn :: Bool
+kdeOn = False
+
+startingConfig = if kdeOn then kdeConfig else defaultConfig
+
+a = 1 + []
+
+main =
+  xmonad $
+    ewmh $
+      docks $
+        startingConfig
+          { modMask = mod4Mask,
+            layoutHook = myLayoutHook,
+            startupHook = startup,
+            manageHook = manageDocks <+> myManagerHook <+> manageHook kdeConfig,
+            handleEventHook = handleEventHook kdeConfig <+> fullscreenEventHook,
+            terminal = myTerminal,
+            workspaces = myWorkspaces
+          }
+          `additionalKeysP` keymap
+  where
+    myWorkspaces =
+      ["1:dev", "2:browser", "3:chat", "4:terminal", "5", "6", "7", "8", "9", "0"]
+
+    appWorkspaceConfig =
+      [ (3, "Discord"),
+        (4, "alacritty"),
+        (2, "google-chrome-stable")
+      ]
+
+    manageWorkspaces =
+      appWorkspaceConfig
+        & fmap \(workspaceId, name) -> do
+          let workspaceName = myWorkspaces !! (workspaceId + 1)
+          className =? name --> doShift workspaceName
+
+    kdeFloats =
+      [ "yakuake",
+        "Yakuake",
+        "Kmix",
+        "kmix",
+        "plasma",
+        "Plasma",
+        "plasma-desktop",
+        "Plasma-desktop",
+        "krunner",
+        "ksplashsimple",
+        "ksplashqml",
+        "ksplashx"
+      ]
+
+    floatKdeStuff = [className =? name --> doFloat | name <- kdeFloats]
+
+    myManagerHook =
+      composeAll $
+        concat
+          [ if kdeOn then floatKdeStuff else [],
+            manageWorkspaces
+          ]
+
+    myTerminal = "alacritty"
+    myBrowser = "google-chrome-stable"
+
+    -- TODO: find a way to bind all the program-opening-keybindings to a single sub-map
+    keymap =
+      [ ("M-p", spawn "rofi -show run"),
+        ("M-g", spawn myBrowser),
+        ("M-d", spawn "Discord"),
+        ("M-s", spawn "slack"),
+        ("M-r", spawn "ksysgurad")
+      ]
+
+    uniformBorder = join $ join $ join Border
+    border = uniformBorder 4
+    spacingHook = spacingRaw True border True border True
+
+    tall = Tall 1 (3 / 100) (1 / 2)
+    threeCols = ThreeCol 1 (3 / 100) (1 / 2)
+
+    layouts = tall ||| threeCols ||| Full
+    myLayoutHook = desktopLayoutModifiers $ spacingHook layouts
+
+    startup :: X ()
+    startup = do
+      spawn "xwallpaper --zoom ./background.jpg"
+      spawn "Discord"
+      spawn "google-chrome-stable"
+      spawn "alacritty"
\ No newline at end of file
diff --git a/modules/applications/xmonad/default.nix b/modules/applications/xmonad/default.nix
index 930b847..3022ca9 100644
--- a/modules/applications/xmonad/default.nix
+++ b/modules/applications/xmonad/default.nix
@@ -3,7 +3,7 @@
     xsession.windowManager.xmonad = {
       enable = true;
       enableContribAndExtras = true;
-      config = ./xmonad.hs;
+      config = ./Main.hs;
     };
 
     home.packages = with pkgs; [ xwallpaper ];
diff --git a/modules/applications/xmonad/xmonad-config.cabal b/modules/applications/xmonad/xmonad-config.cabal
new file mode 100644
index 0000000..1b3b5f5
--- /dev/null
+++ b/modules/applications/xmonad/xmonad-config.cabal
@@ -0,0 +1,15 @@
+cabal-version:      2.4
+name:               xmonad-config
+version:            0.1.0.0
+author:             Matei Adriel
+maintainer:         rafaeladriel11@gmail.com
+-- The license under which the package is released.
+-- license:
+
+executable xmonad-config
+    main-is:          Main.hs
+    build-depends:    
+        , base
+        , xmonad
+        , X11
+    default-language: Haskell2010
diff --git a/modules/applications/xmonad/xmonad.hs b/modules/applications/xmonad/xmonad.hs
deleted file mode 100644
index 2a51dba..0000000
--- a/modules/applications/xmonad/xmonad.hs
+++ /dev/null
@@ -1,72 +0,0 @@
-import           Control.Monad                  ( join )
-import           Data.Function                  ( (&) )
-
-import           XMonad
-import           XMonad.Actions.SpawnOn
-import           XMonad.Config.Kde
-import           XMonad.Hooks.EwmhDesktops      ( fullscreenEventHook )
-import           XMonad.Hooks.EwmhDesktops      ( ewmh )
-import           XMonad.Hooks.ManageDocks
-import           XMonad.Util.EZConfig
-
-import           XMonad.Layout.Spacing
-import           XMonad.Layout.ThreeColumns
-
-main =
-  xmonad
-    $                 ewmh
-    $                 docks
-    $                 kdeConfig
-                        { modMask = mod4Mask
-                        , layoutHook = myLayoutHook
-                        , startupHook = startup
-                        , manageHook = manageDocks <+> myManagerHook <+> manageHook kdeConfig
-                        , handleEventHook = handleEventHook kdeConfig <+> fullscreenEventHook
-                        , terminal = myTerminal
-                        }
-    `additionalKeysP` keymap
- where
-  kdeFloats =
-    [ "yakuake"
-    , "Yakuake"
-    , "Kmix"
-    , "kmix"
-    , "plasma"
-    , "Plasma"
-    , "plasma-desktop"
-    , "Plasma-desktop"
-    , "krunner"
-    , "ksplashsimple"
-    , "ksplashqml"
-    , "ksplashx"
-    ]
-
-  myManagerHook =
-    composeAll [ className =? name --> doFloat | name <- kdeFloats ]
-
-  myTerminal = "alacritty"
-  myBrowser  = "google-chrome-stable"
-
-  -- TODO: find a way to bind all the program-opening-keybindings to a single sub-map
-  keymap =
-    [ ("M-p", spawn "rofi -show run")
-    , ("M-g", spawn myBrowser)
-    , ("M-d", spawn "Discord")
-    , ("M-s", spawn "slack")
-    , ("M-r", spawn "ksysgurad")
-    ]
-
-  uniformBorder = join $ join $ join Border
-  border        = uniformBorder 4
-  spacingHook   = spacingRaw True border True border True
-
-  tall          = Tall 1 (3 / 100) (1 / 2)
-  threeCols     = ThreeCol 1 (3 / 100) (1 / 2)
-
-  layouts       = tall ||| threeCols ||| Full
-  myLayoutHook  = desktopLayoutModifiers $ spacingHook layouts
-
-
-  startup :: X ()
-  startup = do
-    spawn "xwallpaper --zoom ./background.jpg"