From 0f67011c139348ebab63c9c01e7d8f19744d6d12 Mon Sep 17 00:00:00 2001 From: jao Date: Wed, 16 Feb 2022 17:59:03 +0000 Subject: initial contents --- .gitignore | 10 +++ cabal.project | 1 + my-xmonad.cabal | 21 ++++++ rebuild.sh | 6 ++ sendCommand.hs | 21 ++++++ xmonad | 1 + xmonad-contrib | 1 + xmonad.hs | 214 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 275 insertions(+) create mode 100644 .gitignore create mode 100644 cabal.project create mode 100644 my-xmonad.cabal create mode 100755 rebuild.sh create mode 100644 sendCommand.hs create mode 120000 xmonad create mode 120000 xmonad-contrib create mode 100644 xmonad.hs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e588e5c --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +/build-x86_64-linux/ +/.ghc.environment.x86_64-linux-8.8.4 +/cabal.project.local~ +/dist-newstyle/ +/prompt-history +/xmonad-x86_64-linux +/xmonad.errors +/xmonad.hi +/xmonad.o +/cabal.project.local diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..8a8c138 --- /dev/null +++ b/cabal.project @@ -0,0 +1 @@ +packages: ., */*.cabal diff --git a/my-xmonad.cabal b/my-xmonad.cabal new file mode 100644 index 0000000..4951fc2 --- /dev/null +++ b/my-xmonad.cabal @@ -0,0 +1,21 @@ +Name: my-xmonad +version: 0.1.0.0 +build-type: Simple +cabal-version: >=1.10 + +executable my-xmonad + main-is: xmonad.hs + other-modules: + build-depends: base + , containers + , xmonad + , xmonad-contrib + hs-source-dirs: . + default-language: Haskell2010 + ghc-options: -Wall -Werror -fno-warn-missing-signatures -threaded + +executable sendCommand + main-is: sendCommand.hs + build-depends: base, X11 + default-language: Haskell2010 + ghc-options: -Wall -Werror -fno-warn-missing-signatures -threaded diff --git a/rebuild.sh b/rebuild.sh new file mode 100755 index 0000000..dbcf849 --- /dev/null +++ b/rebuild.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +cabal update +rm -f .ghc.environment.* +cabal install --package-env=/home/jao/.xmonad --lib xmonad xmonad-contrib +cabal install --package-env=/home/jao/.xmonad xmonad diff --git a/sendCommand.hs b/sendCommand.hs new file mode 100644 index 0000000..635f729 --- /dev/null +++ b/sendCommand.hs @@ -0,0 +1,21 @@ +-- https://gist.github.com/lierdakil/216a9d2b9e934d9e1a30 + +import Graphics.X11.Xlib +import Graphics.X11.Xlib.Extras +import System.Environment + +main :: IO () +main = sendCommand "XMONAD_COMMAND" =<< getArgs + +sendCommand :: String -> [String] -> IO () +sendCommand addr (s:_) = do + d <- openDisplay "" + rw <- rootWindow d $ defaultScreen d + a <- internAtom d addr False + m <- internAtom d s False + allocaXEvent $ \e -> do + setEventType e clientMessage + setClientMessageEvent e rw a 32 m currentTime + sendEvent d rw False structureNotifyMask e + sync d False +sendCommand _ _ = return () diff --git a/xmonad b/xmonad new file mode 120000 index 0000000..4dccc4f --- /dev/null +++ b/xmonad @@ -0,0 +1 @@ +/usr/local/src/xmonad \ No newline at end of file diff --git a/xmonad-contrib b/xmonad-contrib new file mode 120000 index 0000000..cbf426b --- /dev/null +++ b/xmonad-contrib @@ -0,0 +1 @@ +/usr/local/src/xmonad-contrib \ No newline at end of file diff --git a/xmonad.hs b/xmonad.hs new file mode 100644 index 0000000..dd885e4 --- /dev/null +++ b/xmonad.hs @@ -0,0 +1,214 @@ +{-# LANGUAGE FlexibleContexts #-} + +import qualified Data.Map as M +import System.Environment (lookupEnv) + +import XMonad hiding ( (|||) ) +import XMonad.Actions.FloatKeys (keysMoveWindow, keysResizeWindow) +import XMonad.Actions.WindowGo (raise, runOrRaise) +import qualified XMonad.Actions.GridSelect as GS +import XMonad.Actions.PerWindowKeys (bindAll) +import XMonad.Hooks.ManageHelpers ((-?>)) +import qualified XMonad.Hooks.ManageDocks as MD +import qualified XMonad.Hooks.ManageHelpers as MH +import qualified XMonad.Hooks.ServerMode as SM +import qualified XMonad.Hooks.EwmhDesktops as Ewm +import qualified XMonad.Layout.NoBorders as NB +import XMonad.Layout.IM (withIM, Property(ClassName)) +import XMonad.Layout.LayoutCombinators ((|||)) +-- import XMonad.Layout.WindowNavigation +import qualified XMonad.Layout.LayoutCombinators as LJ +import qualified XMonad.Layout.Renamed as LR +import qualified XMonad.Layout.Spacing as SP +import qualified XMonad.Layout.Reflect as Refl +import qualified XMonad.Prompt as P +import qualified XMonad.Prompt.Shell as PS +import qualified XMonad.Prompt.XMonad as XmP +import qualified XMonad.StackSet as W +import qualified XMonad.Util.EZConfig as EZ +import qualified XMonad.Util.Hacks as UH +import qualified XMonad.Util.NamedScratchpad as NS +import XMonad.Util.Paste (sendKey) +import qualified XMonad.Util.WindowProperties as WP + +jaoscript scrpt = "/home/jao/etc/config/bin/" ++ scrpt + +defFace = "Hack-10" + +promptKeys = M.fromList [((controlMask, xK_a), P.startOfLine) + ,((controlMask, xK_b), P.moveCursor P.Prev) + ,((mod1Mask, xK_b), P.moveWord P.Prev) + ,((controlMask, xK_d), P.deleteString P.Next) + ,((mod1Mask, xK_d), P.killWord P.Next) + ,((controlMask, xK_e), P.endOfLine) + ,((controlMask, xK_f), P.moveCursor P.Next) + ,((mod1Mask, xK_f), P.moveWord P.Next) + ,((controlMask, xK_g), P.quit) + ,((controlMask, xK_k), P.killAfter) + ,((controlMask, xK_n), P.moveHistory W.focusUp') + ,((mod1Mask, xK_n), P.moveHistory W.focusUp') + ,((controlMask, xK_p), P.moveHistory W.focusDown') + ,((mod1Mask, xK_p), P.moveHistory W.focusDown') + ,((controlMask, xK_y), P.pasteString) + ,((mod1Mask, xK_d), P.killWord P.Next) + ] + +promptKM = M.union promptKeys P.defaultXPKeymap + +popConfig = P.def { P.font = "xft:" ++ defFace + , P.promptKeymap = promptKM + , P.position = P.Bottom + , P.height = 25 + , P.promptBorderWidth = 1 + } + +darkPopConfig = popConfig { P.fgColor = "grey60" + , P.bgColor = "grey10" + , P.fgHLight = "lightgoldenrod2" + , P.bgHLight = "grey20" + , P.borderColor = "grey30" + } + +lightPopConfig = popConfig { P.fgColor = "grey10" + , P.bgColor = "#efebe7" + , P.fgHLight = "sienna" + , P.bgHLight = "lightyellow" + , P.borderColor = "grey70" + } + +defWorkspaces = ["X"] + +isEmacs = + className =? "Emacs" <||> className =? "Pemacs" <||> className =? "Gemacs" + +isntEmacs = not `fmap` isEmacs + +raiseEmacs = raise isEmacs +runOrRaiseEmacs = do + emacs <- liftIO $ lookupEnv "emacs" + runOrRaise (case emacs of Just e -> e; _ -> "emacs") isEmacs + +runOrRaiseFirefox = runOrRaise "firefox" (className =? "Firefox") + +toggleEmacs other = do + ems <- mapM (WP.focusedHasProperty . WP.ClassName) ["Emacs", "Pemacs", "Gemacs"] + if or ems then other else runOrRaiseEmacs + +keyDefs conf = + [ ("", backlight "5%+") + , ("", backlight "5%-") + , ("", backlight "5%+") + , ("", backlight "5%-") + , ("", spawn "amixer sset Master 10%+") + , ("", spawn "amixer sset Master 10%-") + , ("", spawn "amixer sset Master toggle") + , ("", spawn "import -window root ~/screenshot.png") + , ("C-c", bindAll [(isntEmacs, raiseEmacs), (pure True, sendCtrlC)]) + , ("M-", move (10,0)) + , ("M-", move (-10,0)) + , ("M-", move (0,-10)) + , ("M-", move (0,10)) + , ("M-0", emacsAfio "scratch") + , ("M-1", emacsAfio "main") + , ("M-2", emacsAfio "mail") + , ("M-3", emacsAfio "www") + , ("M-4", emacsAfio "docs") + , ("M-5", jumpToL "F" >> raise (className =? "Firefox")) + , ("M-C-", resize (10,0) (0,0)) + , ("M-C-", resize (-10,0) (0,1)) + , ("M-C-", resize (0,-10) (0,0)) + , ("M-C-", resize (0,10) (0,0)) + , ("M-C-b", sendMessage $ MD.ToggleStruts) + , ("M-d", NS.namedScratchpadAction scratchpads "deezer") + , ("M-e", runOrRaiseEmacs) + , ("M-f", toggleEmacs runOrRaiseFirefox) + , ("M-m", raiseEmacs >> emacsclient "jao-transient-media") + , ("M-o", raiseEmacs >> emacsclient "other-window 1") + , ("M-S-o", raiseEmacs >> emacsclient "jao-transpose-windows 1") + , ("M-S-r", PS.shellPrompt $ conf {P.position = P.Top}) + , ("M-C-r", PS.shellPrompt $ conf {P.position = P.Top}) + , ("M-s", raiseEmacs >> emacsclient "jao-transient-streaming") + , ("M-S-s", withFocused $ windows . W.sink) + , ("M-t", emacsAfio "main" >> emacsclient "vterm") + , ("M-S-t", spawn (jaoscript "term")) + , ("M-w", raiseEmacs >> emacsclient "jao-transient-utils") + , ("M-x 1", emacsAfio "main") + , ("M-x k", kill) + , ("M-x M-f", withFocused float) + , ("M-x s", withFocused $ windows . W.sink) + , ("M-x g", GS.goToSelected GS.def) + , ("M-x f", jumpToL "F") + , ("M-x l", jumpToLE "L") + , ("M-x r", jumpToLE "R") + , ("M-x t", jumpToLE "T") + , ("M-x n", sendMessage NextLayout) + , ("M-S-x", XmP.xmonadPrompt $ conf {P.position = P.Top}) + , ("M-z l", xdgscr "activate") + , ("M-z u", spawn "toggle-screensaver.sh") + , ("M-z z", zzCmd "suspend") + , ("M-z h", zzCmd "hibernate") + , ("M-z b", zzCmd "hybrid") + , ("M-z l", i3lock) + ] where emacsclient x = spawn $ "emacsclient -e '(" ++ x ++ ")'" + jumpToL x = sendMessage (LJ.JumpToLayout x) >> return () + withEmacs x = jumpToL "F" >> raiseEmacs >> emacsclient x + emacsAfio f = withEmacs $ "jao-afio--goto-" ++ f + sendCtrlC = sendKey controlMask xK_c + jumpToLE x = emacsAfio "scratch-1" >> jumpToL x + backlight x = spawn $ "brightnessctl -q s " ++ x + i3lock = spawn "i3lock -e -i ~/.lockimage" + xdgscr = spawn . ("xdg-screensaver " ++) + zzCmd = spawn . ("sudo systemctl " ++) + move r = withFocused $ keysMoveWindow r + resize a b = withFocused $ keysResizeWindow a b + +spacing n = + SP.spacingRaw False (SP.Border n 0 n 0) True (SP.Border 0 n 0 n) True +namedLyt n = LR.renamed [LR.Replace n] +lytFull = namedLyt "F" $ NB.smartBorders Full +lytTall = namedLyt "T" $ spacing 1 (Tall 1 (1/100) (1/2)) +lytLeft = namedLyt "L" $ withIM (9/26) (ClassName "Emacs") Full +lytRight = namedLyt "R" $ Refl.reflectHoriz lytLeft + +scratchpads = [ + NS.NS "deezer" "deezer-desktop" (className =? "Deezer") + (centerFloat (3/4) (7/8)) + ] +scratchpad = NS.namedScratchpadManageHook scratchpads + +centerFloat width height + = NS.customFloating $ W.RationalRect marginLeft marginTop width height + where marginLeft = (1 - width) / 2 + marginTop = (1 - height) / 2 + +mHook = MD.manageDocks <+> MH.composeOne dlgs <+> composeAll cl + where + dlgs = [MH.isDialog -?> MH.doCenterFloat] + cfs = ["Display", "Gitk", "MPlayer", "Vlc", "Ekiga", "xli", "Skype", + "Gpick", "Blueman-services", "Blueman-manager", "Wicd-client.py", + "Pavumeter", "Xmessage", "XLogo", "mpv", "Mpv"] + cl = [className =? x --> MH.doCenterFloat | x <- cfs] + +main = do + scheme <- lookupEnv "JAO_COLOR_SCHEME" + let dark = Just "dark" == scheme + popCfg = if dark then darkPopConfig else lightPopConfig + defBorder = if dark then "grey10" else "grey90" + defFBorder = if dark then "grey15" else "grey50" + ehook = SM.serverModeEventHook <+> UH.trayerPaddingXmobarEventHook + lyt = lytFull ||| lytRight ||| lytLeft ||| lytTall + localStartupHook = spawn "xmobars.sh" >> runOrRaiseEmacs + xmonad $ MD.docks $ Ewm.ewmhFullscreen $ Ewm.ewmh def { + manageHook = scratchpad <+> mHook <+> manageHook def + , handleEventHook = ehook + , layoutHook = MD.avoidStruts lyt + , startupHook = localStartupHook + , modMask = mod4Mask + , borderWidth = 0 + , focusedBorderColor = defFBorder + , normalBorderColor = defBorder + , terminal = (jaoscript "term") + , workspaces = defWorkspaces + , focusFollowsMouse = False + } `EZ.removeKeysP` ["M-j", "M-n", "M-w", "M-m", "M-r", "M-"] + `EZ.additionalKeysP` (keyDefs popCfg) -- cgit v1.2.3