From bf9238fd5482554cb8526ab666c8b9333186d31d Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Thu, 27 Oct 2016 17:33:35 -0700 Subject: [PATCH] [XMonad] Add virtual classes for renaming --- dotfiles/xmonad/xmonad.hs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/dotfiles/xmonad/xmonad.hs b/dotfiles/xmonad/xmonad.hs index f16fe191..7a8ce8b2 100644 --- a/dotfiles/xmonad/xmonad.hs +++ b/dotfiles/xmonad/xmonad.hs @@ -1,5 +1,6 @@ {-# LANGUAGE TypeSynonymInstances, MultiParamTypeClasses #-} import Control.Monad +import Control.Monad.Trans.Maybe import Data.Aeson import qualified Data.ByteString.Lazy as B import Data.List @@ -57,6 +58,8 @@ emacsSelector = className =? "Emacs" hangoutsSelector = className =? "google-chrome" <&&> fmap isHangoutsTitle title +virtualClasses = [(hangoutsSelector, "Hangouts")] + -- Startup myStartup = spawn "systemctl --user start wm.target" @@ -82,9 +85,20 @@ myWindowBringerConfig = WindowBringerConfig { menuCommand = "rofi" , windowTitler = myDecorateName } +findM :: (Monad m) => (a -> m (Maybe b)) -> [a] -> m (Maybe b) +findM f = runMaybeT . msum . map (MaybeT . f) + +classIfMatches window entry = do + result <- runQuery (fst entry) window + return $ if result then Just $ snd entry else Nothing + getClass w = do - classHint <- withDisplay $ \d -> io $ getClassHint d w - return $ resClass classHint + virtualClass <- findM (classIfMatches w) virtualClasses + case virtualClass of + Nothing -> do + classHint <- withDisplay $ \d -> io $ getClassHint d w + return $ resClass classHint + Just name -> return name myDecorateName ws w = do name <- show <$> getName w