<commit_before>{-# LANGUAGE FlexibleContexts #-}

import XMonad
import XMonad.Layout.NoBorders
import qualified XMonad.StackSet as W
import XMonad.Hooks.DynamicLog (PP, shorten, xmobarColor)
import XMonad.Hooks.EwmhDesktops (fullscreenEventHook)
import XMonad.Layout.LayoutModifier (ModifiedLayout)
import XMonad.Layout.LayoutScreens
import XMonad.Util.EZConfig (additionalKeys)
import XMonad.Hooks.ManageHelpers (isDialog)
import XMonad.Layout.ResizableTile

import Data.List

import Control.Monad
import Control.Exception
import Graphics.X11.ExtraTypes.XF86 -- For media keys.
import System.Process
import System.FilePath
import System.Directory
import System.IO.Error
import System.Info

import Sgf.Control.Lens
import Sgf.XMonad.Restartable
import Sgf.XMonad.Restartable.Firefox
import Sgf.XMonad.Restartable.Feh
import Sgf.XMonad.Restartable.XTerm
import Sgf.XMonad.Docks
import Sgf.XMonad.Docks.Xmobar
import Sgf.XMonad.Docks.Trayer
import Sgf.XMonad.VNC
import Sgf.XMonad.Util.EntryHelper
import Sgf.XMonad.Trace
import Sgf.XMonad.Focus
import Sgf.XMonad.Workspaces

import Data.Maybe

main :: IO ()
main                = withHelper $ do
    -- FIXME: Spawn process directly, not through shell.
    let xcf = handleFocus Nothing myFocusHook
                . handleDefaultWorkspaces False (`elem` ["7"])
                . handleFullscreen
                . handleDocks (Just (0, xK_b))
                . handleProgs (Just (0, xK_s)) (myDocks ++ myPrograms)
                . (additionalKeys <*> myKeys)
                $ def
                    {
                    -- Workspace "lock" is for xtrlock only and it is
                    -- inaccessible for workspace switch keys.
                    workspaces = map show [1..9] ++ ["lock"]
                    , modMask = mod4Mask
                    , focusFollowsMouse = False
                    -- Do not set terminal here: edit `xterm` value instead.
                    -- Because proper conversion from Program to String (and
                    -- back) should be done with respect to shell escaping
                    -- rules, it's simpler to just redefine 'mod+shift+enter'
                    -- to use Program value (`xterm`). I set terminal here,
                    -- though, to make it roughly match to `xterm` value and
                    -- to avoid conversion issues i just throw away all
                    -- arguments: at least it's safe..
                    , terminal = viewA progBin xterm
                    --, logHook = traceWindowSet
                    , clickJustFocuses = False
                    , manageHook = manageLockWorkspace "lock"
                    , layoutHook = myLayout
                    }
    handleVnc xcf >>= xmonad

myLayout    = tiled ||| Mirror tiled ||| Full
  where
    tiled :: ResizableTall Window
    tiled = ResizableTall nmaster delta ratio slaves
    nmaster :: Int
    nmaster = 1
    delta :: Rational
    delta   = 3/100
    ratio :: Rational
    ratio   = 1/2
    slaves :: [Rational]
    slaves  = []

-- Modify layoutHook to remove borders around floating windows covering whole
-- screen and around tiled windows in non-ambiguous cases. Also, add event
-- hook to detect windows going to fullscreen using _NET_WM_STATE protocol
-- (EWMH).
handleFullscreen :: LayoutClass l Window => XConfig l
                    -> XConfig (ModifiedLayout (ConfigurableBorder Ambiguity) l)
handleFullscreen cf = cf
    { layoutHook        = lessBorders OtherIndicated (layoutHook cf)
    , handleEventHook   = fullscreenEventHook <+> handleEventHook cf
    }

-- FocusHook-s for different programs.
myFocusHook :: [FocusHook]
myFocusHook         = sequence [gmrunFocus, firefoxPassword]
                        defaultFocusHook
  where
    -- gmrun takes focus from others *and* keeps it.
    gmrunFocus :: FocusHook -> FocusHook
    gmrunFocus      = setA newWindow (className =? "Gmrun")
                        . setA focusedWindow (className =? "Gmrun")
    -- Firefox dialog prompts (e.g. password manager prompt) keep focus
    -- (unless overwritten by e.g. gmrun).
    firefoxPassword :: FocusHook -> FocusHook
    firefoxPassword = setA focusedWindow $
                        (className =? "Iceweasel" <||> className =? "Firefox")
                        <&&> isDialog

myDocks :: LayoutClass l Window => [ProgConfig l]
myDocks     = addDock trayer : map addDock [xmobar, xmobarAlt]

myPrograms :: LayoutClass l Window =>[ProgConfig l]
myPrograms          = [ addProg feh
                      , addProg xtermUser, addProg xtermRoot
                      , addProg firefox
                      , addProg skype
                      , addProg pidgin
                      , addProg xclock
                      ]

-- Session with instant messengers.
sessionIMKey :: (ButtonMask, KeySym)<commit_msg>xmonad. Remove 'LayoutClass l Window' constraint.<commit_after>{-# LANGUAGE FlexibleContexts #-}

import XMonad
import XMonad.Layout.NoBorders
import qualified XMonad.StackSet as W
import XMonad.Hooks.DynamicLog (PP, shorten, xmobarColor)
import XMonad.Hooks.EwmhDesktops (fullscreenEventHook)
import XMonad.Layout.LayoutModifier (ModifiedLayout)
import XMonad.Layout.LayoutScreens
import XMonad.Util.EZConfig (additionalKeys)
import XMonad.Hooks.ManageHelpers (isDialog)
import XMonad.Layout.ResizableTile

import Data.List

import Control.Monad
import Control.Exception
import Graphics.X11.ExtraTypes.XF86 -- For media keys.
import System.Process
import System.FilePath
import System.Directory
import System.IO.Error
import System.Info

import Sgf.Control.Lens
import Sgf.XMonad.Restartable
import Sgf.XMonad.Restartable.Firefox
import Sgf.XMonad.Restartable.Feh
import Sgf.XMonad.Restartable.XTerm
import Sgf.XMonad.Docks
import Sgf.XMonad.Docks.Xmobar
import Sgf.XMonad.Docks.Trayer
import Sgf.XMonad.VNC
import Sgf.XMonad.Util.EntryHelper
import Sgf.XMonad.Trace
import Sgf.XMonad.Focus
import Sgf.XMonad.Workspaces

import Data.Maybe

main :: IO ()
main                = withHelper $ do
    -- FIXME: Spawn process directly, not through shell.
    let xcf = handleFocus Nothing myFocusHook
                . handleDefaultWorkspaces False (`elem` ["7"])
                . handleFullscreen
                . handleDocks (Just (0, xK_b))
                . handleProgs (Just (0, xK_s)) (myDocks ++ myPrograms)
                . (additionalKeys <*> myKeys)
                $ def
                    {
                    -- Workspace "lock" is for xtrlock only and it is
                    -- inaccessible for workspace switch keys.
                    workspaces = map show [1..9] ++ ["lock"]
                    , modMask = mod4Mask
                    , focusFollowsMouse = False
                    -- Do not set terminal here: edit `xterm` value instead.
                    -- Because proper conversion from Program to String (and
                    -- back) should be done with respect to shell escaping
                    -- rules, it's simpler to just redefine 'mod+shift+enter'
                    -- to use Program value (`xterm`). I set terminal here,
                    -- though, to make it roughly match to `xterm` value and
                    -- to avoid conversion issues i just throw away all
                    -- arguments: at least it's safe..
                    , terminal = viewA progBin xterm
                    --, logHook = traceWindowSet
                    , clickJustFocuses = False
                    , manageHook = manageLockWorkspace "lock"
                    , layoutHook = myLayout
                    }
    handleVnc xcf >>= xmonad

myLayout    = tiled ||| Mirror tiled ||| Full
  where
    tiled :: ResizableTall Window
    tiled = ResizableTall nmaster delta ratio slaves
    nmaster :: Int
    nmaster = 1
    delta :: Rational
    delta   = 3/100
    ratio :: Rational
    ratio   = 1/2
    slaves :: [Rational]
    slaves  = []

-- Modify layoutHook to remove borders around floating windows covering whole
-- screen and around tiled windows in non-ambiguous cases. Also, add event
-- hook to detect windows going to fullscreen using _NET_WM_STATE protocol
-- (EWMH).
handleFullscreen :: LayoutClass l Window => XConfig l
                    -> XConfig (ModifiedLayout (ConfigurableBorder Ambiguity) l)
handleFullscreen cf = cf
    { layoutHook        = lessBorders OtherIndicated (layoutHook cf)
    , handleEventHook   = fullscreenEventHook <+> handleEventHook cf
    }

-- FocusHook-s for different programs.
myFocusHook :: [FocusHook]
myFocusHook         = sequence [gmrunFocus, firefoxPassword]
                        defaultFocusHook
  where
    -- gmrun takes focus from others *and* keeps it.
    gmrunFocus :: FocusHook -> FocusHook
    gmrunFocus      = setA newWindow (className =? "Gmrun")
                        . setA focusedWindow (className =? "Gmrun")
    -- Firefox dialog prompts (e.g. password manager prompt) keep focus
    -- (unless overwritten by e.g. gmrun).
    firefoxPassword :: FocusHook -> FocusHook
    firefoxPassword = setA focusedWindow $
                        (className =? "Iceweasel" <||> className =? "Firefox")
                        <&&> isDialog

myDocks :: [ProgConfig l]
myDocks     = addDock trayer : map addDock [xmobar, xmobarAlt]

myPrograms :: [ProgConfig l]
myPrograms          = [ addProg feh
                      , addProg xtermUser, addProg xtermRoot
                      , addProg firefox
                      , addProg skype
                      , addProg pidgin
                      , addProg xclock
                      ]

-- Session with instant messengers.
sessionIMKey :: (ButtonMask, KeySym)
{'fraction_non_alphanumeric': 0.07927778354259625, 'fraction_numerical': 0.003528068901110304, 'mean_word_length': 2.08416, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, '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': '861227', 'n_tokens_mistral': 2810, 'n_tokens_neox': 2652, 'n_words': 808}