From cd9a67706a9ed7162af94ca168c4530bc4b1c2cf Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Sat, 22 Oct 2016 17:17:25 -0700 Subject: [PATCH] [XMonad] Add automatic workspace naming LayoutModifier Note: This requires my own custom version of xmonad-contrib. --- dotfiles/xmonad/xmonad.hs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/dotfiles/xmonad/xmonad.hs b/dotfiles/xmonad/xmonad.hs index 402aca62..ed09ed17 100644 --- a/dotfiles/xmonad/xmonad.hs +++ b/dotfiles/xmonad/xmonad.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE TypeSynonymInstances, MultiParamTypeClasses #-} import Control.Monad import Data.Aeson import qualified Data.ByteString.Lazy as B @@ -20,6 +21,7 @@ import XMonad.Hooks.ManageDocks import XMonad.Hooks.FadeInactive import XMonad.Layout.BoringWindows import XMonad.Layout.LayoutCombinators +import XMonad.Layout.LayoutModifier import XMonad.Layout.Minimize import XMonad.Layout.MultiColumns import XMonad.Layout.MultiToggle @@ -28,6 +30,7 @@ import XMonad.Layout.NoBorders import XMonad.Layout.Spacing import qualified XMonad.StackSet as W import XMonad.Util.CustomKeys +import qualified XMonad.Util.ExtensibleState as XS import XMonad.Util.NamedWindows (getName) getClass :: Window -> X String @@ -65,13 +68,13 @@ main = xmonad $ ewmh $ pagerHints def myLogHook = fadeInactiveLogHook 0.9 -setWorkspaceNameToFocusedWindow workspace = do - namedWindows <- mapM getClass $ take 2 $ W.integrate' $ W.stack workspace - workspaceToName <- getWorkspaceNames +setWorkspaceNameToFocusedWindow workspace = do + namedWindows <- mapM getClass $ W.integrate' $ W.stack workspace renamedWindows <- remapNames namedWindows - let newName = intercalate "|" namedWindows - when (workspaceToName (W.tag workspace) /= newName) $ - setWorkspaceName (W.tag workspace) (intercalate "|" renamedWindows) + WorkspaceNames namesMap <- XS.get + let newName = intercalate "|" renamedWindows + currentName = M.findWithDefault "" (W.tag workspace) namesMap + when (currentName /= newName) $ setWorkspaceName (W.tag workspace) newName remapNames namedWindows = do remap <- io getClassRemap @@ -81,12 +84,20 @@ setWorkspaceNames = do ws <- gets windowset mapM_ setWorkspaceNameToFocusedWindow (W.workspaces ws) +data WorkspaceNamesHook a = WorkspaceNamesHook deriving (Show, Read) + +instance LayoutModifier WorkspaceNamesHook Window where + hook _ = setWorkspaceNames + +workspaceNamesHook = ModifiedLayout WorkspaceNamesHook + shiftThenView i = W.greedyView i . W.shift i layouts = multiCol [1, 1] 2 0.01 (-0.5) ||| Full ||| Tall 1 (3/100) (1/2) -myLayoutHook = avoidStruts . smartSpacing 10 . noBorders . minimize - . boringWindows . mkToggle (MIRROR ?? EOT) $ layouts +myLayoutHook = avoidStruts . smartSpacing 10 . noBorders . minimize . + boringWindows . mkToggle (MIRROR ?? EOT) . workspaceNamesHook + $ layouts myStartup = spawn "systemctl --user start wm.target"