From 980ed179c049b40f075c24fb4fe3ea1daa726ca5 Mon Sep 17 00:00:00 2001 From: Martin Potier Date: Tue, 12 Dec 2017 21:55:08 +0200 Subject: [PATCH] Shorten config --- lib/MouseBindings.hs | 12 ++ xmonad.hs | 422 +++---------------------------------------- 2 files changed, 34 insertions(+), 400 deletions(-) create mode 100644 lib/MouseBindings.hs diff --git a/lib/MouseBindings.hs b/lib/MouseBindings.hs new file mode 100644 index 0000000..7229a2f --- /dev/null +++ b/lib/MouseBindings.hs @@ -0,0 +1,12 @@ +module MouseBindings ( + MouseBindings.modify +) where + +import XMonad +import XMonad.Actions.UpdatePointer + +modify :: XConfig l -> XConfig l +modify conf = conf + { logHook = logHook conf >> updatePointer (0.5,0.5) (0,0) + } + diff --git a/xmonad.hs b/xmonad.hs index 372ca59..10e1617 100755 --- a/xmonad.hs +++ b/xmonad.hs @@ -4,35 +4,23 @@ module Main (main) where -import Data.Ratio ((%)) import XMonad -import XMonad.Actions.UpdatePointer import XMonad.Config.Desktop import XMonad.Hooks.DynamicLog import XMonad.Hooks.ManageHelpers -import XMonad.Hooks.ManageDocks (docksEventHook) import XMonad.Layout.NoBorders (noBorders, smartBorders) import XMonad.Layout.ResizableTile (ResizableTall(..)) import XMonad.Layout.Spacing -import XMonad.Layout.ToggleLayouts (ToggleLayout(..), toggleLayouts) -import XMonad.Prompt -import XMonad.Prompt.ConfirmPrompt -import XMonad.Prompt.Shell +import XMonad.Layout.ToggleLayouts (toggleLayouts) import XMonad.Util.EZConfig -import XMonad.Util.Run (spawnPipe) import qualified Solarized as S --- Contructors imports -import XMonad.Hooks.ManageDocks (AvoidStruts) -import XMonad.Layout.LayoutModifier (ModifiedLayout) - -- Tidy modules import StatusBar as Bar (modify) import KeyBindings as Keys (modify) +import MouseBindings as Mouse (modify) -wkspcs :: [String] --------- ["●", "◕", "◑", "◔", "◯", "◐", "◒", "◓", "☦", "λ"] --------- ["α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ"] +-------- A list of my usual workspaces (with some FontAwesome & xmobar format) wkspcs = [ wrap "" "" "\xF0E0" --  email , wrap "" "" "\xF086" --  chat , wrap "" "" "\xF121" --  work @@ -45,24 +33,8 @@ wkspcs = [ wrap "" "" "\xF0E0" --  email , wrap "" "" "\xF03D" --  movie ] -lh = do - updatePointer (0.5,0.5) (0,0) - logHook desktopConfig - -myConfig = Bar.modify - $ Keys.modify - $ desktopConfig - { manageHook = myManageHook <+> manageHook desktopConfig - , layoutHook = desktopLayoutModifiers myLayouts - , logHook = lh - , terminal = "/run/current-system/sw/bin/kitty" - , workspaces = wkspcs - , normalBorderColor = S.base03 - , focusedBorderColor = S.violet - , borderWidth = 5 - } - -myLayouts = toggleLayouts fullscreen tiled +--------- toggle btw vvvvvvvvvv or vvvvv +layouts = toggleLayouts fullscreen tiled where fullscreen = (noBorders Full) tiled = smarts $ resizableTall ||| (Mirror resizableTall) @@ -71,6 +43,7 @@ myLayouts = toggleLayouts fullscreen tiled -- Use the `xprop' tool to get the info you need for these matches. -- For className, use the second value that xprop gives you. +-------------- Here be the law of windows myManageHook = composeOne [ className =? "mpv" -?> doFullFloat <+> (doShift $ last wkspcs) , className =? "Pavucontrol" -?> doShift $ wkspcs !! 7 @@ -81,371 +54,20 @@ myManageHook = composeOne , transience ] --- Finally: -main = xmonad myConfig +------------ build the full config +withConfig = + Bar.modify -- Apply statusBar config + $ Keys.modify -- Apply keybindings config + $ Mouse.modify -- Apply mouse bindings config + $ desktopConfig -- on a default desktop config + { manageHook = myManageHook <+> manageHook desktopConfig + , layoutHook = desktopLayoutModifiers layouts + , terminal = "/run/current-system/sw/bin/kitty" + , workspaces = wkspcs + , normalBorderColor = S.base03 + , focusedBorderColor = S.violet + , borderWidth = 5 + } - - ---- import qualified Data.Map as Map ---- import XMonad ---- import XMonad.Util.EZConfig ---- import XMonad.Layout.Tabbed ---- import XMonad.Hooks.ManageDocks ---- import XMonad.Hooks.DynamicLog ---- import XMonad.Layout.NoBorders ---- import XMonad.Actions.SwapWorkspaces ---- import XMonad.Prompt ---- import XMonad.Prompt.Shell ---- ---- -- Solarized colours. ---- activeBackColor = "#073642" ---- --activeForeColor = "#93A1A1" -- base1 ---- activeForeColor = "#EEE8D5" -- base2 ---- passiveForeColor = "#2AA198" ---- ---- yoTabbed = tabbed shrinkText $ def ---- { fontName = "xft:Hack:size=10" ---- , activeBorderColor = activeForeColor ---- , activeTextColor = activeForeColor ---- , activeColor = activeBackColor ---- , inactiveBorderColor = "#555555" ---- , inactiveTextColor = "#555555" ---- , inactiveColor = "#000000" ---- } ---- simpleTall = Tall 1 (1/100) (1/2) ---- yoLayouts = smartBorders $ (Mirror simpleTall ||| simpleTall ||| yoTabbed) ---- ---- yoPromptXP = def ---- { bgColor = activeBackColor ---- , borderColor = activeForeColor ---- , fgColor = activeForeColor ---- , fgHLight = "#073642" ---- , bgHLight = "#859900" ---- , promptKeymap = emacsLikeXPKeymap ---- , font = "xft:Hack:size=12" ---- } ---- ---- yoConfig = def ---- { terminal = "termite" ---- , modMask = mod4Mask ---- , focusedBorderColor = activeForeColor ---- , layoutHook = yoLayouts ---- } ---- `additionalKeysP` ---- [ ( "M-", spawn $ "emacs") ---- ---- , ("", spawn "pamixer -t") ---- , ("M-" , spawn "pamixer -d 1") ---- , ("M-" , spawn "pamixer -i 1") ---- ---- , ("M-" , spawn "xbacklight -dec 5") ---- , ("M-" , spawn "xbacklight -inc 5") ---- ---- , ("M-" , spawn "setxkbmap dvorak") ---- , ("M-", spawn "setxkbmap fr" ) ---- , ("M-", spawn "setxkbmap ru" ) ---- , ("M-", spawn "setxkbmap ro" ) ---- ---- , ("M-C-", swapTo Next) ---- , ("M-C-" , swapTo Prev) ---- ---- , ("M-r", shellPrompt yoPromptXP) ---- ] ---- `removeKeysP` ---- [ "M-q" ] ---- ---- yoXmobarPP = def ---- { ppCurrent = xmobarColor' activeForeColor . activePad ---- , ppVisible = xmobarColor' activeForeColor -- other screen ---- , ppHidden = xmobarColor' passiveForeColor -- other workspaces with windows ---- , ppHiddenNoWindows = xmobarColor' activeBackColor -- other workspaces ---- , ppSep = " " ---- , ppLayout = printLayout ---- , ppTitle = printTitle ---- } ---- where xmobarColor' fg = xmobarColor fg "#000000" ---- ---- printLayout "Tall" = "[|]" ---- printLayout "Mirror Tall" = "[—]" ---- printLayout "Tabbed Simplest" = "[□]" ---- printLayout l = "[" ++ l ++ "]" ---- ---- printTitle t = let t' = shorten 120 t ---- in xmobarColor' passiveForeColor "[ " ---- ++ xmobarColor' passiveForeColor t' ---- ++ xmobarColor' passiveForeColor " ]" ---- ---- activePad s = xmobarColor' bracketColor " >" ---- ++ s ---- ++ xmobarColor' bracketColor "< " ---- bracketColor = "#B58900" ---- ---- xmobarCmd = "xmobar /home/scolobb/.xmonad/xmobarrc" ---- ---- main = do ---- spawn "stalonetray --geometry 5x1+1000 --icon-size 20 -bg '#000000'" ---- spawn "nm-applet" ---- spawn "seafile-applet" ---- spawn "syndaemon" ---- xmonad =<< statusBar xmobarCmd yoXmobarPP hideBarsKey yoConfig ---- where hideBarsKey XConfig{modMask = modm} = (modm, xK_b) - - - ---- import Codec.Binary.UTF8.String ---- import Graphics.X11.ExtraTypes.XF86 ---- import LemonBar ---- import qualified Solarized as S ---- import qualified Data.Map as M ---- import qualified XMonad.StackSet as W ---- import System.Exit ---- import System.IO ---- import Text.Printf ---- import XMonad ---- import XMonad.Actions.CycleWS ---- import XMonad.Config.Desktop ---- import XMonad.Hooks.DynamicLog ---- import XMonad.Hooks.EwmhDesktops ---- import XMonad.Hooks.ManageDocks ---- import XMonad.Hooks.ManageHelpers ---- import XMonad.Layout.IndependentScreens ---- import XMonad.Layout.LayoutCombinators hiding ( (|||) ) ---- import XMonad.Layout.Reflect ---- import XMonad.Prompt ---- import XMonad.Prompt.Shell(shellPrompt) ---- import XMonad.Util.Font ---- import XMonad.Util.Loggers ---- -- import XMonad.Util.Run ---- ---- main = do ---- spawn bar ---- xmonad $ docks $ ewmh desktopConfig ---- { manageHook = myManageHook <+> manageDocks <+> manageHook defaultConfig ---- , layoutHook = myLayout ---- , logHook = maLogouk ---- , modMask = mod4Mask -- Rebind to Logo key ---- , workspaces = ["●", "◕", "◑", "◔", "◯", "◐", "◒", "◓", "☦"] ---- , borderWidth = 0 ---- , keys = myKeys ---- , terminal = "/run/current-system/sw/bin/kitty" ---- , handleEventHook = handleEventHook defaultConfig <+> fullscreenEventHook ---- } ---- ---- sym "Tall" = "|" ---- sym "Mirror Tall" = "-" ---- sym "Full" = "F" ---- sym _ = "◓" ---- ---- maLogouk = dynamicLogWithPP $ defaultPP ---- { ppOutput = printToFile ---- , ppCurrent = LemonBar.color S.orange S.base03 . LemonBar.underline -- . sym ---- , ppVisible = LemonBar.color S.yellow S.base03 . LemonBar.underline -- . sym ---- , ppHidden = LemonBar.color S.base2 S.base03 . LemonBar.underline -- . sym ---- , ppHiddenNoWindows = LemonBar.color S.base01 S.base03 -- . sym ---- , ppLayout = sym ---- , ppTitle = LemonBar.fColor S.violet . shorten 70 ---- , ppSep = " " ---- } ---- ---- printToFile :: String -> IO () ---- printToFile s = do ---- h <- openFile "/tmp/monitors/xmonad" WriteMode ---- hPutStrLn h $ decodeString s ---- -- xxxxxxxxxxxx ---- -- v----------------| ---- -- Hacky hack to fix the broken fix of dynamicLogWithPP ---- hClose h ---- ---- myManageHook = composeAll ---- [ className =? "float" --> doCenterFloat ---- , manageDocks ] ---- ---- ------------------------------------------------------------------------ ---- -- LogHook. Dynamically outputs logs nicely formatted for dzen2 ---- -- ---- -- myLogHook h = dynamicLogWithPP $ defaultPP { ---- -- ppCurrent = dzenColor "#cb4b16" "#eee8d5", ---- -- ppVisible = dzenColor "#657b83" "#eee8d5", ---- -- ppHiddenNoWindows = dzenColor "#93a1a1" "#eee8d5", ---- -- ppLayout = dzenColor "#6c71c4" "#eee8d5", ---- -- ppTitle = (dzenColor "#cb4b16" "") . (fixedWidth 256), ---- -- ppSep = " ", ---- -- ppWsSep = " ", ---- -- ppOutput = hPutStrLn h ---- -- } ---- -- where ---- -- fixedWidth n l = take (n+5) $ l ++ (cycle ".") ---- ---- ---- ------------------------------------------------------------------------ ---- -- StatusBar. Call lemonbar ---- bar = printf ---- "pkill lemonbar; /home/eeva/bin/mkstatus.sh | \ ---- \ lemonbar -g 1919x24+0+0 \ ---- \ -f '%s' \ ---- \ -f '%s' \ ---- \ -u %d -B '%s' -F '%s' -U '%s'" ---- --"tewi:style=Regular:antialias=false:autohint=false" ---- "Iosevka:size=10" ---- "DejaVu Sans Mono:size=10" ---- (2 :: Int) ---- S.base03 ---- S.base0 ---- S.violet ---- ---- myLayout = (avoidStruts $ tiled ||| Mirror tiled) ||| Full ---- where ---- tiled = Tall 1 (3/100) (1/2) ---- ---- -- Prompt config ---- myXPConfig = defaultXPConfig { ---- position = Top, ---- promptBorderWidth = 5, ---- font = "xft:tewi:style=Regular:antialias=false:autohint=false", ---- height = 24, ---- borderColor = S.base03, ---- bgHLight = S.base02, ---- fgHLight = S.magenta, ---- bgColor = S.base03, ---- fgColor = S.base0, ---- defaultText = "" ---- } ---- ---- ------------------------------------------------------------------------ ---- -- Key bindings. Add, modify or remove key bindings here. ---- -- ---- myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $ ---- [ ---- -- launch dmenu ---- --((modm, xK_p), spawn "dmenu_run -b -l 3") ---- -- launch prompt ---- ((modm, xK_p), shellPrompt myXPConfig) ---- ---- -- close focused window ---- , ((modm, xK_Delete), kill) ---- ---- -- Rotate through the available layout algorithms ---- , ((modm, xK_space ), sendMessage NextLayout) ---- --, ((modm .|. shiftMask xK_Tab ), sendMessage PreviousLayout) ---- ---- -- Reset the layouts on the current workspace to default ---- , ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf) ---- ---- -- Resize viewed windows to the correct size ---- , ((modm, xK_n ), refresh) ---- ---- -- Move focus to the master window ---- , ((modm, xK_m ), windows W.focusMaster ) ---- ---- -- Swap the focused window and the master window ---- , ((modm, xK_BackSpace), windows W.swapMaster) ---- ---- -- Move focus to the next window ---- , ((modm, xK_j ), windows W.focusDown) ---- , ((modm, xK_Down ), windows W.focusDown) ---- ---- -- Move focus to the previous window ---- , ((modm, xK_k ), windows W.focusUp ) ---- , ((modm, xK_Up ), windows W.focusUp) ---- ---- -- Swap the focused window with the next window ---- , ((modm .|. shiftMask, xK_j ), windows W.swapDown ) ---- , ((modm .|. shiftMask, xK_Down ), windows W.swapDown ) ---- ---- -- Swap the focused window with the previous window ---- , ((modm .|. shiftMask, xK_k ), windows W.swapUp ) ---- , ((modm .|. shiftMask, xK_Up ), windows W.swapUp ) ---- ---- -- Shrink the master area ---- , ((modm, xK_h ), sendMessage Shrink) ---- ---- -- Expand the master area ---- , ((modm, xK_l ), sendMessage Expand) ---- ---- -- Move to next Workspace ---- , ((modm, xK_Right ), nextWS) ---- ---- -- Move to previous Workspace ---- , ((modm, xK_Left ), prevWS) ---- ---- -- Move focused window to next Workspace ---- , ((modm .|. shiftMask, xK_Right ), shiftToNext >> nextWS) ---- ---- -- Move focused window to previous Workspace ---- , ((modm .|. shiftMask, xK_Left ), shiftToPrev >> prevWS) ---- ---- -- Cycle between windows ---- , ((modm , xK_Tab ), toggleWS) ---- ---- -- Push window back into tiling ---- , ((modm, xK_t ), withFocused $ windows . W.sink) ---- ---- -- Increment the number of windows in the master area ---- , ((modm , xK_comma ), sendMessage (IncMasterN 1)) ---- ---- -- Deincrement the number of windows in the master area ---- , ((modm , xK_period), sendMessage (IncMasterN (-1))) ---- ---- -- close focused window ---- , ((modm .|. shiftMask, xK_c ), kill) ---- ---- -- Swap the focused window and the master window ---- , ((modm, xK_Return), windows W.swapMaster) ---- ---- -- run my terminal ---- , ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf) ---- ---- -- lock my session ---- --, ((modm .|. shiftMask, xK_Delete), spawn "/usr/bin/sxlock -f \"-*-ubuntu mono-*-r-*-*-*-*-*-*-*-*-*-*\"") ---- , ((modm .|. shiftMask, xK_Delete), spawn "/run/current-system/sw/bin/i3lock-fancy -g -p") ---- ---- -- quit xmonad ---- , ((modm .|. shiftMask, xK_q), io (exitWith ExitSuccess)) ---- ---- -- Raise volume (XF86XK_AudioRaiseVolume) ---- , ((0 , xF86XK_AudioRaiseVolume), spawn "/home/eeva/prefix/bin/volume up") ---- ---- -- Lower volume (XF86XK_AudioLowerVolume) ---- , ((0 , xF86XK_AudioLowerVolume), spawn "/home/eeva/prefix/bin/volume down") ---- ---- -- Mute volume (xF86XK_AudioMute) ---- , ((0 , xF86XK_AudioMute), spawn "/home/eeva/prefix/bin/volume toggle") ---- ---- -- Playlist play (xK_F7) ---- , ((0 , xK_F7), spawn "/usr/bin/notify-send \"Current song\" \"$(mpc -h ~/.config/mpd/mpd.socket | head -n 1)\"") ---- ---- -- Playlist play (xK_F8) ---- , ((0 , xK_F8), spawn "/home/eeva/prefix/bin/playlist toggle") ---- ---- -- Playlist stop (xK_F9) ---- , ((0 , xK_F9), spawn "/home/eeva/prefix/bin/playlist stop") ---- ---- -- Launch App (XF86XK_Launch1) ---- , ((0 , xF86XK_Launch1), spawn "/usr/bin/firefox") ---- ---- -- Adjust Brightness up (xF86XK_MonBrightnessUp) ---- , ((0 , xF86XK_MonBrightnessUp), spawn "/run/current-system/sw/bin/xbacklight +10") ---- ---- -- Adjust Brightness down (xF86XK_MonBrightnessDown) ---- , ((0 , xF86XK_MonBrightnessDown), spawn "/run/current-system/sw/bin/xbacklight -10") ---- ] ---- ++ ---- ---- -- ---- -- mod-[1..9], Switch to workspace N ---- -- ---- -- mod-[1..9], Switch to workspace N ---- -- mod-shift-[1..9], Move client to workspace N ---- -- ---- [((m .|. modm, k), windows $ f i) ---- | (i, k) <- zip (XMonad.workspaces conf) [xK_F1 .. xK_F9] ---- , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]] ---- ++ ---- ---- -- ---- -- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3 ---- -- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3 ---- -- ---- [((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f)) ---- | (key, sc) <- zip [xK_z, xK_e, xK_r] [0..] ---- , (f, m) <- [(W.view, 0), (W.shift, shiftMask)] +------ and pass it to xmonad: +main = xmonad withConfig