Advertisement
Guest User

Untitled

a guest
Nov 20th, 2024
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import System.Posix.Env (getEnv)
  2. import Data.Maybe (maybe)
  3.  
  4. import XMonad
  5. import XMonad.Util.SpawnOnce
  6. import XMonad.Util.Run
  7. import XMonad.Util.XUtils
  8. import XMonad.Hooks.DynamicLog
  9. -- import XMonad.Core
  10. --import XMonad.Config.Prime
  11. import XMonad.Util.Font
  12. --import FileLogger
  13. import Control.Monad
  14. import Data.List
  15. import Data.Char (toUpper, toLower)
  16. import XMonad.Util.EZConfig
  17. import XMonad.Util.Dmenu
  18. -- import XMonad.Operations.unGrab
  19. import XMonad.Layout.Tabbed
  20. import XMonad.Layout.Grid
  21. import XMonad.Actions.NoBorders
  22. import XMonad.Layout.Accordion
  23. import XMonad.Actions.SpawnOn
  24. import XMonad.Actions.FloatSnap
  25. import XMonad.Hooks.SetWMName
  26. import XMonad.Hooks.ManageDocks
  27. import XMonad.Util.NamedScratchpad
  28. import XMonad.Hooks.StatusBar
  29. import XMonad.Hooks.StatusBar.PP
  30. import XMonad.Util.WorkspaceCompare (getSortByXineramaRule)
  31. import Foreign.C.String
  32. import Control.Monad.State.Class
  33. import Data.Maybe (isJust)
  34. import Text.Regex.PCRE ((=~))
  35. import Control.Applicative ((<$>))
  36. import Data.List (elemIndex, find)
  37. import XMonad.Util.NamedWindows (getName)
  38. import qualified Data.Map as M
  39. import qualified XMonad.StackSet as W
  40. -- import XMonad.Config.Desktop
  41. -- import XMonad.Config.Gnome
  42. -- import XMonad.Config.Kde
  43. -- import XMonad.Config.Xfce
  44.  
  45. mySB = statusBarProp "xmobar ~/.config/xmobar/xmobarrc" (pure myPP)
  46.  
  47. main :: IO ()
  48. main = xmonad
  49.          . withEasySB mySB defToggleStrutsKey
  50.          $ def
  51.   { modMask = mod4Mask
  52.    ,terminal = myTerminal
  53.    ,normalBorderColor = "#444444"
  54.    ,focusedBorderColor = "#ffffff"
  55.    ,manageHook = newManageHook
  56.    ,startupHook = myStartupHook
  57.    ,layoutHook = avoidStruts $ myLayout
  58.    ,workspaces = myWorkspaces
  59.    ,logHook = dynamicLog
  60.   }
  61.   `additionalKeysP`
  62.     [ ("M-S-l", spawn "xscreensaver-command -lock")
  63.      --,("M-C-s", unGrab *> spawn "scrot -s")
  64.      ,("M-w", spawn myBrowserCommand)
  65.      ,("M-y", spawn "/home/summer/.nix-profile/bin/xmobar /home/summer/.config/xmobar/xmobarrc 2>&1 >/home/summer/.xmonad/xmobar.errors")
  66.      ,("M-<Return>", spawn myTerminal)
  67.      ,("M-x", kill)
  68.      ,("M-<Print>", spawn "bash -c 'cd ~/Pictures/Screenshots && shotgun'")
  69.      ,("M-d", spawn "dmenu_run")
  70.      ,("M-f", withFocused toggleFloat)
  71.      ,("M-'", namedScratchpadAction scratchpads "browser")
  72.      ,("M-g", namedScratchpadAction scratchpads "graphics")
  73.      ,("<XF86MonBrightnessUp>", spawn "lux -a 10%")
  74.      ,("<XF86MonBrightnessDown>", spawn "lux -s 10%")
  75.      -- ,("M-<Minus>", namedScratchpadAction scratchpads "terminals")
  76.      ,("M-=", toggleFull)
  77.      ,("M-<Left>", withFocused $ snapMove L Nothing)
  78.      ,("M-<Right>", withFocused $ snapMove R Nothing)
  79.      ,("M-<Down>", withFocused $ snapMove D Nothing)
  80.      ,("M-<Up>", withFocused $ snapMove U Nothing)
  81.     ]
  82.   where toggleFloat w = windows (\s -> if M.member w (W.floating s)
  83.                         then W.sink w s
  84.                         else (W.float w (W.RationalRect (1/3) (1/4) (1/2) (4/5)) s))
  85.  
  86.  
  87. myPP = def
  88.   { ppLayout = const "" -- Don't show the layout name
  89.    ,ppSort = getSortByXineramaRule -- Sort left/right screens on the left, non-empty workspaces after those
  90.    ,ppTitle = const "" -- Don't show the focused window's title
  91.    ,ppTitleSanitize = const "" -- Also about window's title
  92.    ,ppVisible = wrap "(" ")" -- Non-focused (but still visible) screen
  93.   }
  94.  
  95. -- myScratchPads :: [NamedScratchpad]
  96. -- myScratchPads = [ NS "browser" spawnBrowser findBrowser manageBrowser ]
  97. --   where spawnBrowser = myBrowser
  98. --         findBrowser = className =? "google-chrome-stable"
  99. --         manageBrowser = customFloating $ W.RationalRect l t w h
  100. --           where h = 0.9
  101. --                 w = 0.9
  102. --                 t = 0.95 -h
  103. --                 l = 0.95 -w
  104.  
  105. -- toggleFull = withFocused (\windowId -> do
  106. --     { floats <- gets (W.floating . windowset);
  107. --         if windowId `M.member` floats
  108. --         then withFocused $ windows . W.sink
  109. --         else withFocused $ windows . (flip W.float $ W.RationalRect 0 0 1 1) })  
  110. --
  111. --
  112.  
  113.  
  114.  
  115. myWorkspaces = [ "1","2","3","4","5","6","7","8","9" ];
  116.  
  117. toggleFull = withFocused (\windowId -> do    
  118. {      
  119.    floats <- gets (W.floating . windowset);        
  120.    if windowId `M.member` floats        
  121.      then do
  122.        withFocused $ toggleBorder          
  123.        withFocused $ windows . W.sink        
  124.      else do
  125.        withFocused $ toggleBorder          
  126.        withFocused $  windows . (flip W.float $ W.RationalRect 0 0 1 1)    
  127. } )
  128.  
  129. scratchpads = [
  130.    NS "browser" myBrowserCommand (className =? capitalize myBrowser)
  131.      (customFloating $ W.RationalRect 0 0.5 0.5 1)
  132.      --(customFloating $ W.RationalRect (1/4) (1/4) (2/4) (2/4))
  133.   ,NS "graphics" "gimp" (className =? "Gimp")
  134.      (customFloating $ W.RationalRect 0 0 0.5 1)
  135.      -- (customFloating $ W.RationalRect (1/4) (1/4) (2/4) (2/4))
  136.   -- ,NS "terminals" myTerminal (className =? capitalize myTerminal)
  137.   --    (customFloating $ W.RationalRect (1/4) (1/4) (2/4) (2/4))
  138.   ]
  139.  
  140. -- runOrRaiseMasterShift :: String -> Query Bool -> X ()
  141. -- runOrRaiseMasterShift run query = runOrRaiseAndDo run query (\wId -> whenX (elem wId <$> visibleWindows) swapNextScreen
  142.  
  143. capitalize :: String -> String
  144. capitalize "" = ""
  145. capitalize (x:xs) = toUpper x : map toLower xs
  146.  
  147. myBrowser = "google-chrome"
  148. myBrowserCommand = "google-chrome-stable"
  149. myTerminal = "alacritty"
  150.  
  151. -- workspacesGrouped :: X [(WorkspaceId, [String])]
  152. -- workspacesGrouped = do
  153. --   ws <- gets windowset
  154. --   let x = map (W.workspace) (W.current ws : W.visible ws)
  155. --   let y = (W.hidden ws)
  156. --   sequence $ fmap (\v -> fmap ((,) $ W.tag v) (getWorkspaceWindowTitles v)) $ x ++ y
  157. -- getWorkspaceWindowTitles :: W.Workspace i l Window -> X [String]
  158. -- getWorkspaceWindowTitles w = do
  159. --   withDisplay $ \d ->
  160. --     (liftIO $ forM
  161. --       (W.integrate' $ W.stack w)
  162. --       (\z -> getWindowTitle z d)
  163. --     )
  164. -- getWindowTitle :: Window -> Display -> IO String
  165. -- getWindowTitle w d = getTextProperty d w wM_NAME >>= (peekCString . tp_value)
  166.  
  167. windowIndex :: Window -> W.StackSet i l Window s sd -> Maybe Int
  168. windowIndex w s = elemIndex w $ allWindowsInCurrentWorkspace s
  169.  
  170. allWindowsInCurrentWorkspace :: W.StackSet i l a sid sd -> [a]
  171. allWindowsInCurrentWorkspace ws =
  172.   W.integrate' . W.stack . W.workspace . W.current $ ws
  173.  
  174. findM :: Monad m => (a -> m Bool) -> [a] -> m (Maybe a)
  175. findM _ [] = return Nothing
  176. findM f (h:t) = do
  177.  r <- f h
  178.  if r
  179.    then return (Just h)
  180.    else findM f t
  181.  
  182. -- findWindowOnCurrentWorkspace :: Query Bool -> (Window -> X()) -> X() -> X()
  183. -- findWindowOnCurrentWorkspace condition actionIfFound actionIfNotFound = do
  184. --     windows <- gets (W.index . windowset)
  185. --     found <- findM (runQuery condition) windows
  186. --     case found of
  187. --         Nothing -> actionIfNotFound
  188. --         Just w -> actionIfFound w
  189.  
  190. -- findWindow :: String -> X (Maybe Window)
  191. -- findWindow regex = do
  192. --   wmap <- concat <$> (mapM mappings =<< (W.workspaces <$> gets windowset))
  193. --     :: X [(String, Window)]
  194. --   return (snd <$> find ((=~ regex) . fst) wmap)
  195. --   where mappings :: WindowSpace -> X [(String, Window)]
  196. --         mappings ws = mapM mapping $ W.integrate' (W.stack ws)
  197. --         mapping w = flip (,) w <$> show <$> getName w
  198. --
  199.  
  200. findWindow :: (Window -> Bool) -> (Window -> X()) -> X() -> X()
  201. findWindow condition actionIfFound actionIfNotFound = do
  202.     windows <- gets (W.index . windowset)
  203.     let found = find condition windows  -- found has type Maybe Window
  204.     case found of
  205.         Nothing -> actionIfNotFound
  206.         Just w -> actionIfFound w
  207.  
  208. currentWorkspaceHasWindow :: WindowSet -> Bool
  209. currentWorkspaceHasWindow = isJust . W.peek
  210.  
  211. myStartupHook :: X ()
  212. myStartupHook = composeAll $
  213.   [ setWMName "Songbird" -- Make this conditional!!! So annoying
  214.    ,spawn "/usr/bin/env xmobar ~/.config/xmobar/xmobarrc"
  215.    ,spawnOn "1" myTerminal
  216.    ,spawnOn "1" myTerminal
  217.    ,spawnOn "1" myTerminal
  218.    ,spawnOn "1" myTerminal
  219.    ,spawnOn "1" myTerminal
  220.    ,spawnOn "1" myTerminal
  221.    ,spawnOn "1" myTerminal
  222.    ,spawnOn "1" myTerminal
  223.    ,spawnOn "1" myTerminal
  224.    --,spawnOn "2" myTerminal
  225.    --,spawnOn "2" myTerminal
  226.    --,spawnOn "2" myTerminal
  227.    --,spawnOn "2" myTerminal
  228.    --,spawnOn "2" myTerminal
  229.    --,spawnOn "2" myTerminal
  230.    --,spawnOn "2" myTerminal
  231.    --,spawnOn "2" myTerminal
  232.    --,spawnOn "2" myTerminal
  233.   ]
  234. --  else []
  235. --  where checkWS = do stackset <- gets windowset
  236. --                     currentWorkspaceHasWindow stackset
  237.  
  238. myLayout = Grid
  239. myManageHook :: ManageHook
  240. myManageHook = composeAll
  241.   [ className =? (capitalize myBrowser) --> doFloat
  242.   ] <+> namedScratchpadManageHook scratchpads
  243. newManageHook = myManageHook <> manageHook def
  244.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement