<commit_before>import Data.List (intercalate, elemIndex)
import Text.Printf (printf)
import System.IO (hPutStrLn)

import XMonad
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageHelpers
import qualified XMonad.Hooks.EwmhDesktops as E
import XMonad.Layout.Renamed (renamed, Rename (Replace))
import XMonad.Layout.NoBorders (smartBorders)
import XMonad.Layout.Fullscreen (fullscreenManageHook)
import XMonad.Layout.Gaps (gaps)
import XMonad.Layout.Spacing (spacing)
import XMonad.Util.EZConfig (additionalKeys)
import Graphics.X11.ExtraTypes.XF86
    ( xF86XK_MonBrightnessUp
    , xF86XK_MonBrightnessDown
    )
import XMonad.Util.Run (safeSpawn, spawnPipe)
import XMonad.Util.Cursor (setDefaultCursor)
import XMonad.Actions.CycleWS
import XMonad.Actions.WindowBringer (gotoMenuArgs)

-- Color definitions
colorHighlight = "#a51f1c"
focusBorderColor = "green"
colorFg = "#fafafa"
colorBg = "#262729"

-- Miscellaneous settings
terminal' = "xfce4-terminal"
borderWidth' = 1
workspaces' =
    [ "one"
    , "two"
    , "three"
    , "four"
    , "five"
    , "six"
    , "seven"
    , "eight"
    , "nine"
    ]
windowSpacing = 5

-- Layouts
layouts = golden ||| half
    where goldenRatio       = (1+(toRational(sqrt(5)::Double)))/2
          renameLayout name = renamed [Replace name]
          golden            = renameLayout "G" $ Tall 1 (1/100) (1/goldenRatio)
          half              = renameLayout "H" $ Tall 1 (1/100) (1/2)

-- Explicit window management hooks
manageHooks = composeAll
    [ -- Center-floated windows
      className =? "Gmrun" --> doCenterFloat
    , className =? "ioquake3" --> doCenterFloat
    , className =? "Volumeicon" --> doCenterFloat
    , className =? "Settings" --> doCenterFloat
    , isFullscreen --> doFullFloat
    ]

-- Pretty-printer for xmobar
workspaceIndex workspaceId =
    case (workspaceId `elemIndex` workspaces') of
        Just idx -> (idx+1)
        Nothing  -> 0 -- unreachable

wsAction idx =
    wrap ("<action=`xdotool key alt+" ++ show idx ++ "`>") "</action>"

formatWSName l r name =
    let idx = workspaceIndex name
    in wsAction idx $ wrap l r name

prettyPrinter handle = defaultPP
    { ppCurrent = formatWSName (hl "[") (hl "]")
    , ppHidden = formatWSName "" ""
    , ppSep = hl " - "
    , ppTitle = shorten 75
    -- FIXME: Remove the "Spacing 5" string added when using the smartSpacing
    --        layout modifier.
    , ppLayout = id
    , ppOutput = hPutStrLn handle
    }
    where hl = xmobarColor colorHighlight ""

-- dmenu customizations (requires the `dmenu-xft-height` AUR package)
dmenuOptions =
    [ "-b"
    , "-fn"
    , "'DejaVu Sans-8'"
    , "-nb"
    , colorBg
    , "-nf"
    , colorFg
    , "-sb"
    , colorHighlight
    , "-h"
    , "30"
    ]

-- Keybindings
keybindings =
    [ ((modMask', xK_p), safeSpawn "dmenu_run" dmenuOptions)
    , ((modMask', xK_n), spawn "nemo")
    , ((smMask, xK_f), gotoMenuArgs dmenuOptions)
    , ((modMask', xK_F5), spawn "slock")
    , ((smMask, xK_h), prevWS)
    , ((smMask, xK_l), nextWS)
    , ((scmMask, xK_h), shiftToPrev)
    , ((scmMask, xK_l), shiftToNext)
    , ((modMask', xK_q), safeSpawn "xmonad" ["--replace"])
    , ((mod4Mask, xF86XK_MonBrightnessUp), raiseBrightness)<commit_msg>xmonad: reimplement spacing layout modifier<commit_after>{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}

import Control.Arrow (second)
import Data.List (intercalate, elemIndex)
import Graphics.X11 (Rectangle(..))
import Graphics.X11.ExtraTypes.XF86
    ( xF86XK_MonBrightnessUp
    , xF86XK_MonBrightnessDown
    )
import System.IO (hPutStrLn)
import Text.Printf (printf)

import XMonad
import XMonad.Actions.CycleWS
import XMonad.Actions.WindowBringer (gotoMenuArgs)
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.ManageHelpers
import qualified XMonad.Hooks.EwmhDesktops as E
import XMonad.Layout.Fullscreen (fullscreenManageHook)
import XMonad.Layout.LayoutModifier
import XMonad.Layout.Gaps (gaps)
import XMonad.Layout.NoBorders (smartBorders)
import XMonad.Layout.Renamed (renamed, Rename (Replace))
import XMonad.Util.Cursor (setDefaultCursor)
import XMonad.Util.EZConfig (additionalKeys)
import XMonad.Util.Font (fi)
import XMonad.Util.Run (safeSpawn, spawnPipe)

-- Color definitions
colorHighlight = "#a51f1c"
focusBorderColor = "green"
colorFg = "#fafafa"
colorBg = "#262729"

-- Miscellaneous settings
terminal' = "xfce4-terminal"
borderWidth' = 1
workspaces' =
    [ "one"
    , "two"
    , "three"
    , "four"
    , "five"
    , "six"
    , "seven"
    , "eight"
    , "nine"
    ]
windowSpacing = 5

-- Layout modifier `spacing` copied from XMonad.Layout.Spacing so we can
-- override the `modifierDescription` implementation.
data Spacing a = Spacing Int deriving (Show, Read)
instance LayoutModifier Spacing a where
    pureModifier (Spacing p) _ _ wrs = (map (second $ shrinkRect p) wrs, Nothing)
    modifierDescription (Spacing p) = ""

shrinkRect p (Rectangle x y w h) = Rectangle (x+fi p) (y+fi p) (w-2*fi p) (h-2*fi p)
spacing p = ModifiedLayout (Spacing p)

-- Layouts
layouts = golden ||| half
    where goldenRatio       = (1+(toRational(sqrt(5)::Double)))/2
          renameLayout name = renamed [Replace name]
          golden            = renameLayout "G" $ Tall 1 (1/100) (1/goldenRatio)
          half              = renameLayout "H" $ Tall 1 (1/100) (1/2)

-- Explicit window management hooks
manageHooks = composeAll
    [ -- Center-floated windows
      className =? "Gmrun" --> doCenterFloat
    , className =? "ioquake3" --> doCenterFloat
    , className =? "Volumeicon" --> doCenterFloat
    , className =? "Settings" --> doCenterFloat
    , isFullscreen --> doFullFloat
    ]

-- Pretty-printer for xmobar
workspaceIndex workspaceId =
    case (workspaceId `elemIndex` workspaces') of
        Just idx -> (idx+1)
        Nothing  -> 0 -- unreachable

wsAction idx =
    wrap ("<action=`xdotool key alt+" ++ show idx ++ "`>") "</action>"

formatWSName l r name =
    let idx = workspaceIndex name
    in wsAction idx $ wrap l r name

prettyPrinter handle = defaultPP
    { ppCurrent = formatWSName (hl "[") (hl "]")
    , ppHidden = formatWSName "" ""
    , ppSep = hl " - "
    , ppTitle = shorten 75
    , ppOutput = hPutStrLn handle
    }
    where hl = xmobarColor colorHighlight ""

-- dmenu customizations (requires the `dmenu-xft-height` AUR package)
dmenuOptions =
    [ "-b"
    , "-fn"
    , "'DejaVu Sans-8'"
    , "-nb"
    , colorBg
    , "-nf"
    , colorFg
    , "-sb"
    , colorHighlight
    , "-h"
    , "30"
    ]

-- Keybindings
keybindings =
    [ ((modMask', xK_p), safeSpawn "dmenu_run" dmenuOptions)
    , ((modMask', xK_n), spawn "nemo")
    , ((smMask, xK_f), gotoMenuArgs dmenuOptions)
    , ((modMask', xK_F5), spawn "slock")
    , ((smMask, xK_h), prevWS)
    , ((smMask, xK_l), nextWS)
    , ((scmMask, xK_h), shiftToPrev)
    , ((scmMask, xK_l), shiftToNext)
    , ((modMask', xK_q), safeSpawn "xmonad" ["--replace"])
    , ((mod4Mask, xF86XK_MonBrightnessUp), raiseBrightness)
{'fraction_non_alphanumeric': 0.13096417952711312, 'fraction_numerical': 0.014299872575392893, 'mean_word_length': 3.2350119904076737, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '324401', 'n_tokens_mistral': 2594, 'n_tokens_neox': 2501, 'n_words': 600}