From b0ad81e7ba9407cc49b245f4f32d94495f86421c Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Fri, 20 May 2022 21:45:12 +0530 Subject: Modularised my XMonad Config --- .config/XMonad/xmonad.hs | 357 +++-------------------------------------------- 1 file changed, 18 insertions(+), 339 deletions(-) (limited to '.config/XMonad/xmonad.hs') diff --git a/.config/XMonad/xmonad.hs b/.config/XMonad/xmonad.hs index 9cc9c5b..095bc1e 100644 --- a/.config/XMonad/xmonad.hs +++ b/.config/XMonad/xmonad.hs @@ -2,6 +2,7 @@ import XMonad import qualified XMonad.StackSet as W import XMonad.ManageHook import System.Exit +import System.IO -- data import Data.Tree @@ -31,190 +32,27 @@ import XMonad.Hooks.SetWMName import XMonad.Hooks.ManageDocks import XMonad.Hooks.EwmhDesktops +import XMonad.Hooks.DynamicLog +-- DynamicLog replacement(s) +-- import XMonad.Hooks.StatusBar +-- import XMonad.Hooks.StatusBar.PP + -- utilities +import XMonad.Util.Run import XMonad.Util.SpawnOnce import XMonad.Util.EZConfig import XMonad.Util.Cursor import XMonad.Util.NamedScratchpad --- defaults -myModMask = mod4Mask -altMask = mod1Mask -myLockscreen = "notify-send 'to be set up!' 'to be set up!'" -myColorPicker = "colorpicker --short --one-shot --preview | xsel -b" -myFont = "xft:Sauce Code Pro:style=Regular:size=14" -volUp = "pamixer -i 5" -volDown = "pamixer -d 5" -volMute = "pamixer -t" -backlightUp = "brightnessctl s +5" -backlightDown = "brightnessctl s 5-" -screenshot = "flameshot screen" -fullScreenshot = "flameshot full" -customScreenshot = "flameshot gui" - -myExtraWorkspaces = [(xK_0, "十")] -- , (xK_comma, " 十一 "), (xK_period, " 十二 "), (xK_slash, " 十三 ")] -myWorkspaces = ["一", "二", "三", "四", "五", "六", "七", "八", "九"] ++ map snd myExtraWorkspaces - -myScratchpads = - [ NS "Term 0" "alacritty -t 'Term 0'" (title =? "Term 0") (customFloating $ W.RationalRect (1/16) (1/16) (7/8) (7/8)) - , NS "Term 1" "alacritty -t 'Term 1'" (title =? "Term 1") (customFloating $ W.RationalRect (1/16) (1/16) (7/8) (7/8)) - , NS "Term 2" "alacritty -t 'Term 2'" (title =? "Term 2") (customFloating $ W.RationalRect (1/16) (1/16) (7/8) (7/8)) - , NS "Term 3" "alacritty -t 'Term 3'" (title =? "Term 3") (customFloating $ W.RationalRect (1/16) (1/16) (7/8) (7/8)) - , NS "lf" "alacritty -t 'lf' -e 'lf'" (title =? "lf") (customFloating $ W.RationalRect (1/16) (1/16) (7/8) (7/8)) - , NS "arandr" "arandr" (className =? "Arandr") (customFloating $ W.RationalRect (1/4) (1/4) (1/2) (1/2)) - , NS "calc" "galculator" (className =? "Galculator") (customFloating $ W.RationalRect (5/13) (4/13) (3/13) (6/13)) - , NS "blueman" "blueman-manager" (className =? "Blueman-manager") (customFloating $ W.RationalRect (5.5/16) (4/13) (5/16) (6/13)) - , NS "pavucontrol" "pavucontrol" (className =? "Pavucontrol") (customFloating $ W.RationalRect (3/12) (1/12) (3/6) (5/6)) - , NS "wallpaper" "nitrogen" (className =? "Nitrogen") (customFloating $ W.RationalRect (3/12) (1/12) (3/6) (5/6)) - , NS "BPYTOP" "alacritty -t 'BPYTOP' -e 'bpytop'" (title =? "BPYTOP") (customFloating $ W.RationalRect (1/16) (1/16) (7/8) (7/8)) - ] - -myTabTheme = def { fontName = myFont - , activeColor = "#755999" - , inactiveColor = "#282c35" - , activeBorderColor = "#755999" - , inactiveBorderColor = "#313846" - , activeTextColor = "#FFFFFF" - , inactiveTextColor = "#d0d0d0" - , decoHeight = 20 - } - -myTSConfig = TS.TSConfig { TS.ts_hidechildren = False - , TS.ts_background = 0xdd282c34 - , TS.ts_font = myFont - , TS.ts_node = (0xffd0d0d0, 0xff1c1f24) - , TS.ts_nodealt = (0xffd0d0d0, 0xff282c34) - , TS.ts_highlight = (0xffffffff, 0xff755999) - , TS.ts_extra = 0xffd0d0d0 - , TS.ts_node_width = 220 - , TS.ts_node_height = 34 - , TS.ts_originX = 10000 - , TS.ts_originY = 100 - , TS.ts_indent = 80 - , TS.ts_navigate = TS.defaultNavigation - } - -networkingTS = - [ Node (TS.TSNode "Transmission" "" (spawn "qbittorrent")) [] - , Node (TS.TSNode "TOR" "" (spawn "torbrowser-launcher")) [] - , Node (TS.TSNode "Discord" "" (spawn "discord")) [] - , Node (TS.TSNode "Icecat" "" (spawn "icecat")) [] - , Node (TS.TSNode "Network Manager" "" (spawn "nm-connection-editor")) [] - , Node (TS.TSNode "Firefox" "" (spawn "firefox")) [] - , Node (TS.TSNode "Librewolf" "" (spawn "librewolf")) [] - , Node (TS.TSNode "Brave" "" (spawn "brave")) [] - ] -myNetworkingTS a = TS.treeselectAction a networkingTS - -screenshotTS = - [ Node (TS.TSNode "Custom Selection" "" (spawn customScreenshot)) [] - , Node (TS.TSNode "Full Screen" "" (spawn screenshot)) [] - , Node (TS.TSNode "All Screens" "" (spawn fullScreenshot)) [] - ] -myScreenshotTS a = TS.treeselectAction a screenshotTS - -powerTS = - [ Node (TS.TSNode "Shutdown" "" (return())) - [ Node (TS.TSNode "Confirm" "" (spawn "shutdown now")) [] ] - , Node (TS.TSNode "Restart" "" (return())) - [ Node (TS.TSNode "Confirm" "" (spawn "reboot")) [] ] - , Node (TS.TSNode "Lock" "" (return())) - [ Node (TS.TSNode "Confirm" "" (spawn myLockscreen)) [] ] - , Node (TS.TSNode "Logout" "" (return())) - [ Node (TS.TSNode "Confirm" "" (io exitSuccess)) [] ] - ] -myPowerTS a = TS.treeselectAction a powerTS - -mediaTS = - [ Node (TS.TSNode "VLC" "" (spawn "vlc")) [] - , Node (TS.TSNode "GIMP" "" (spawn "gimp")) [] - , Node (TS.TSNode "Kdenlive" "" (spawn "kdenlive")) [] - , Node (TS.TSNode "OBS" "" (spawn "obs")) [] - ] -myMediaTS a = TS.treeselectAction a mediaTS - -gamingTS = - [ Node (TS.TSNode "Minecraft" "" (spawn "minecraft-launcher")) [] - , Node (TS.TSNode "osu!lazer" "" (spawn "env LUTRIS_SKIP_INIT=1 lutris lutris:rungameid/3")) [] - , Node (TS.TSNode "Steam" "" (spawn "steam")) [] - , Node (TS.TSNode "Lutris" "" (spawn "lutris")) [] - ] -myGamingTS a = TS.treeselectAction a gamingTS - -scratchpadTS = - [ Node (TS.TSNode "Term 0" "" (namedScratchpadAction myScratchpads "Term 0")) [] - , Node (TS.TSNode "Term 1" "" (namedScratchpadAction myScratchpads "Term 1")) [] - , Node (TS.TSNode "Term 2" "" (namedScratchpadAction myScratchpads "Term 2")) [] - , Node (TS.TSNode "Term 3" "" (namedScratchpadAction myScratchpads "Term 3")) [] - , Node (TS.TSNode "lf" "" (namedScratchpadAction myScratchpads "lf")) [] - , Node (TS.TSNode "BPYTOP" "" (namedScratchpadAction myScratchpads "BPYTOP")) [] - , Node (TS.TSNode "Calculator" "" (namedScratchpadAction myScratchpads "calc")) [] - , Node (TS.TSNode "Arandr" "" (namedScratchpadAction myScratchpads "arandr")) [] - , Node (TS.TSNode "Blueman" "" (namedScratchpadAction myScratchpads "blueman")) [] - , Node (TS.TSNode "Pavucontrol" "" (namedScratchpadAction myScratchpads "pavucontrol")) [] - , Node (TS.TSNode "Wallpapers" "" (namedScratchpadAction myScratchpads "nitrogen")) [] - ] -myScratchpadTS a = TS.treeselectAction a scratchpadTS - -xmonadTS = - [ Node (TS.TSNode "Rotate Windows" "" (sendMessage Rotate)) [] - , Node (TS.TSNode "Sticky Window" "" (windows copyToAll)) [] - , Node (TS.TSNode "Un-sticky Window" "" (killAllOtherCopies)) [] - , Node (TS.TSNode "Swap Windows" "" (sendMessage BSP.Swap)) [] - , Node (TS.TSNode "Bring Window" "" (bringSelected defaultGSConfig)) [] - , Node (TS.TSNode "Go To Window" "" (goToSelected defaultGSConfig)) [] - , Node (TS.TSNode "Sink Window" "" (withFocused $ windows . W.sink)) [] - , Node (TS.TSNode "Un/Maximize" "" (withFocused (sendMessage . maximizeRestore))) [] - ] -myXmonadTS a = TS.treeselectAction a xmonadTS - -devTS = - [ Node (TS.TSNode "Android Studio" "" (spawn "android-studio")) [] - , Node (TS.TSNode "Doom Emacs" "" (spawn "code")) [] - , Node (TS.TSNode "VSCodium" "" (spawn "code")) [] - ] -myDevTS a = TS.treeselectAction a (devTS ++ vmTS) - -vmTS = - [ Node (TS.TSNode "Virt Manager" "" (spawn "virt-manager")) [] - , Node (TS.TSNode "VirtualBox" "" (spawn "virtualbox")) [] - ] -myVmTS a = TS.treeselectAction a vmTS - -utilTS = - [ Node (TS.TSNode "Pavucontrol" "" (spawn "pavucontrol")) [] - , Node (TS.TSNode "OBS" "" (spawn "obs")) [] - , Node (TS.TSNode "Arandr" "" (spawn "arandr")) [] - , Node (TS.TSNode "System Monitor" "" (spawn "alacritty -e bpytop")) [] - , Node (TS.TSNode "File Manager" "" (spawn "pcmanfm")) [] - , Node (TS.TSNode "Calculator" "" (spawn "galculator")) [] - , Node (TS.TSNode "Wallpapers" "" (spawn "nitrogen")) [] - , Node (TS.TSNode "Screenshot" "" (return())) screenshotTS - ] -myUtilTS a = TS.treeselectAction a utilTS - -myTreeMenu a = TS.treeselectAction a - ([Node (TS.TSNode "Utilities" "" (return())) utilTS - , Node (TS.TSNode "Networking" "" (return())) networkingTS - , Node (TS.TSNode "Development" "" (return())) devTS - , Node (TS.TSNode "Virtual Machines" "" (return())) vmTS - , Node (TS.TSNode "XMonad" "" (return())) - [ Node (TS.TSNode "Window/Layout" "" (return())) xmonadTS - , Node (TS.TSNode "Scratchpads" "" (return())) scratchpadTS - ] - , Node (TS.TSNode "Gaming" "" (return())) gamingTS - , Node (TS.TSNode "Media" "" (return())) mediaTS - , Node (TS.TSNode "Power" "" (return())) powerTS - ]) - -sGap = 4 -- screen gap -wGap = 8 -- window gap - -myGap = spacingRaw True (Border sGap sGap sGap sGap) True (Border wGap wGap wGap wGap) True -myGap' = spacingRaw False (Border sGap sGap sGap sGap) True (Border wGap wGap wGap wGap) True +-- myLibs +import Keybindings +import Defaults +import Scratchpads +import Hooks main :: IO () main = do + -- lemonBar <- spawnPipe myLemonbar xmonad $ ewmh $ docks $ fullscreenSupport def { focusFollowsMouse = True , borderWidth = 2 @@ -222,168 +60,9 @@ main = do , workspaces = myWorkspaces , normalBorderColor = "#130F23" , focusedBorderColor = "#c44cf2" - , layoutHook = avoidStruts $ maximize $ windowNavigation $ smartBorders $ myGap $ ( - emptyBSP ||| tabbed shrinkText myTabTheme ||| Grid - ) - , startupHook = do - -- spawnOnce "lxsession" - spawnOnce "xmodmap /home/zt/.Xmodmap" - -- spawnOnce "glava --force-mod radial --desktop" - spawnOnce "picom" - spawnOnce "dunst" - spawnOnce "polystart" - spawnOnce "nitrogen --restore" - spawnOnce "cbatticon" - -- spawnOnce "blueman-applet" - -- spawnOnce "nm-applet" - -- spawnOnce "flameshot" - -- spawnOnce "optimus-manager-qt" - setWMName "LG3D" - setDefaultCursor xC_left_ptr - , manageHook = namedScratchpadManageHook myScratchpads - <+> manageDocks <+> composeAll [ - className =? "discord" --> doShift ( myWorkspaces !! 9 ) - , className =? "vlc" --> doShift ( myWorkspaces !! 6 ) - ] - -} `additionalMouseBindings` [ - ((myModMask, 4), \w -> prevWS) - , ((myModMask, 5), \w -> nextWS) - ] `additionalKeys` ([ - ((myModMask, xK_Return), spawn ("open_terminal")) - , ((myModMask .|. shiftMask, xK_q), kill1) - - -- volume keys - , ((myModMask, xK_equal), spawn volUp) - , ((myModMask, xK_minus), spawn volDown) - , ((myModMask, xK_BackSpace), spawn volMute) - - -- brightness keys - , ((myModMask .|. shiftMask, xK_equal), spawn backlightUp) - , ((myModMask .|. shiftMask, xK_minus), spawn backlightDown) - - -- modify gaps on runtime - , ((myModMask, xK_F2), incWindowSpacing 1) - , ((myModMask, xK_F1), decWindowSpacing 1) - , ((myModMask .|. shiftMask, xK_F2), incScreenSpacing 1) - , ((myModMask .|. shiftMask, xK_F1), decScreenSpacing 1) - - -- view prev/next workspaces - , ((myModMask .|. shiftMask, xK_Tab), prevWS) - , ((myModMask, xK_Tab), nextWS) - , ((myModMask, xK_semicolon), prevWS) - , ((myModMask, xK_apostrophe), nextWS) - , ((altMask, xK_h), prevWS) - , ((altMask, xK_l), nextWS) - - -- move to prev/next workspaces - , ((altMask .|. shiftMask, xK_h), shiftToPrev >> prevWS) - , ((altMask .|. shiftMask, xK_l), shiftToNext >> nextWS) - , ((myModMask .|. shiftMask, xK_semicolon), shiftToPrev >> prevWS) - , ((myModMask .|. shiftMask, xK_apostrophe), shiftToNext >> nextWS) - - -- focus previous/next monitor - , ((myModMask, xK_bracketleft), prevScreen) - , ((myModMask, xK_bracketright), nextScreen) - - -- move window to previous/next monitor - , ((myModMask .|. shiftMask, xK_bracketleft), shiftPrevScreen >> prevScreen) - , ((myModMask .|. shiftMask, xK_bracketright), shiftNextScreen >> nextScreen) - - -- swap different screens - , ((myModMask .|. controlMask, xK_bracketleft), swapPrevScreen) - , ((myModMask .|. controlMask, xK_bracketright), swapNextScreen) - - , ((myModMask, xK_a), sendMessage ToggleStruts) -- toggle both bars - , ((myModMask, xK_f), withFocused (sendMessage . maximizeRestore)) -- toggle maximize - , ((myModMask .|. shiftMask, xK_f), withFocused $ windows . W.sink) -- unfloat windows - - -- cycle through windows - , ((altMask, xK_j), windows W.focusDown) - , ((altMask, xK_k), windows W.focusUp) - - -- 2D navigation - , ((myModMask, xK_l), sendMessage $ Go R) - , ((myModMask, xK_h), sendMessage $ Go L) - , ((myModMask, xK_k), sendMessage $ Go U) - , ((myModMask, xK_j), sendMessage $ Go D) - - -- swap windows - , ((myModMask .|. shiftMask, xK_l), sendMessage $ WN.Swap R) - , ((myModMask .|. shiftMask, xK_h), sendMessage $ WN.Swap L) - , ((myModMask .|. shiftMask, xK_k), sendMessage $ WN.Swap U) - , ((myModMask .|. shiftMask, xK_j), sendMessage $ WN.Swap D) - - -- resize - , ((myModMask .|. mod1Mask, xK_l ), sendMessage $ ExpandTowards R) - , ((myModMask .|. mod1Mask, xK_h ), sendMessage $ ExpandTowards L) - , ((myModMask .|. mod1Mask, xK_j ), sendMessage $ ExpandTowards D) - , ((myModMask .|. mod1Mask, xK_k ), sendMessage $ ExpandTowards U) - , ((myModMask .|. mod1Mask .|. shiftMask , xK_l ), sendMessage $ ShrinkFrom R) - , ((myModMask .|. mod1Mask .|. shiftMask , xK_h ), sendMessage $ ShrinkFrom L) - , ((myModMask .|. mod1Mask .|. shiftMask , xK_j ), sendMessage $ ShrinkFrom D) - , ((myModMask .|. mod1Mask .|. shiftMask , xK_k ), sendMessage $ ShrinkFrom U) + , layoutHook = myLayoutHook + , startupHook = myStartupHook + , manageHook = myManageHook + -- , logHook = dynamicLogWithPP myLemonbarPP { ppOutput = \x -> hPutStrLn lemonBar x} - ] ++ [ -- for extra workspace(s) - ((myModMask, key), (windows $ W.greedyView ws)) - | (key,ws) <- myExtraWorkspaces - ] ++ [ -- also for extra workspaces - ((myModMask .|. shiftMask, key), (windows $ W.shift ws)) - | (key,ws) <- myExtraWorkspaces - ] ++ [ -- to swap workspace - ((mod1Mask .|. shiftMask, k), windows $ swapWithCurrent i) - | (i, k) <- zip myWorkspaces [xK_1, xK_2, xK_3, xK_4, xK_5, xK_6, xK_7, xK_8, xK_9, xK_0] - ] ++ [ -- copy - ((m .|. myModMask, k), windows $ f i) - | (i, k) <- zip (myWorkspaces) [xK_1, xK_2, xK_3, xK_4, xK_5, xK_6, xK_7, xK_8, xK_9, xK_0] - , (f, m) <- [(copy, shiftMask .|. altMask)] - ] ++ [ -- for not swapping tags while using multihead - ((m .|. myModMask, k), windows $ f i) - | (i, k) <- zip myWorkspaces [xK_1, xK_2, xK_3, xK_4, xK_5, xK_6, xK_7, xK_8, xK_9, xK_0] - , (f, m) <- [(W.view, 0), (W.shift, shiftMask)] - ] -- ++ [ -- focus different monitors --- ((m .|. myModMask, key), screenWorkspace sc >>= flip whenJust (windows . f)) --- | (key, sc) <- zip [xK_bracketleft, xK_bracketright] [1,0] -- was [0..] *** change to match your screen order *** --- , (f, m) <- [(W.view, 0), (W.shift, shiftMask)] --- ] - ) `additionalKeysP` [ - ("M-c", spawn myColorPicker) - -- Launchers - , ("M-S-w", myDevTS myTSConfig) - , ("M-q", myXmonadTS myTSConfig) - , ("M-e", myMediaTS myTSConfig) - , ("M-S-e", myGamingTS myTSConfig) - , ("M-w", myScratchpadTS myTSConfig) - , ("M-o", myUtilTS myTSConfig) - , ("M-i", myNetworkingTS myTSConfig) - , ("M-S-", myPowerTS myTSConfig) - , ("M-p", myTreeMenu myTSConfig) - , ("M-S-p", spawn "dmenu_run") - -- scratchpads - , ("M-r", namedScratchpadAction myScratchpads "Term 0") - , ("M-t", namedScratchpadAction myScratchpads "Term 1") - , ("M-y", namedScratchpadAction myScratchpads "Term 2") - , ("M-u", namedScratchpadAction myScratchpads "Term 3") - , ("M-m", namedScratchpadAction myScratchpads "BPYTOP") - , ("M-S-m", namedScratchpadAction myScratchpads "calc") - , ("M-n", namedScratchpadAction myScratchpads "pavucontrol") - , ("M-S-n", namedScratchpadAction myScratchpads "arandr") - , ("M-b", namedScratchpadAction myScratchpads "blueman") - , ("M-S-r", namedScratchpadAction myScratchpads "wallpaper") - -- other apps - , ("M-g", spawn customScreenshot) - , ("M-S-o", spawn "pcmanfm") - , ("M-S-y", spawn "gimp") - , ("M-S-u", spawn "kdenlive") - , ("M-S-b", spawn "discord") - , ("M-S-i", spawn "librewolf") - , ("M-s", spawn "obs") - , ("M-d", spawn "emacs") - -- fn keys - , ("", spawn backlightUp) - , ("", spawn backlightDown) - , ("", spawn volUp) - , ("", spawn volDown) - , ("", spawn volMute) - ] - -- used keys: x e w o i p r t y q n b c d +} -- cgit v1.2.3