[XMonad] Add class cycling

This commit is contained in:
Ivan Malison 2016-11-26 18:04:48 -08:00
parent bffe020619
commit 5101d3f8a4
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8
2 changed files with 41 additions and 3 deletions

View File

@ -26,6 +26,7 @@ executable imalison-xmonad
bytestring>=0.10.8.1, bytestring>=0.10.8.1,
containers>=0.5.7.1, containers>=0.5.7.1,
directory>=1.2.6.2, directory>=1.2.6.2,
filepath>=1.4.1.0 filepath>=1.4.1.0,
multimap>=1.2.1
hs-source-dirs: . hs-source-dirs: .
default-language: Haskell2010 default-language: Haskell2010

View File

@ -9,6 +9,7 @@ import Data.Aeson
import qualified Data.ByteString.Lazy as B import qualified Data.ByteString.Lazy as B
import Data.List import Data.List
import qualified Data.Map as M import qualified Data.Map as M
import qualified Data.MultiMap as MM
import Data.Maybe import Data.Maybe
import Graphics.X11.ExtraTypes.XF86 import Graphics.X11.ExtraTypes.XF86
import System.Directory import System.Directory
@ -100,6 +101,9 @@ toggleInMap :: Ord k => k -> M.Map k Bool -> M.Map k Bool
toggleInMap = toggleInMap' True toggleInMap = toggleInMap' True
maybeRemap k = M.findWithDefault k k maybeRemap k = M.findWithDefault k k
(<$.>) :: Functor f => (b -> c) -> (a -> f b) -> a -> f c
(<$.>) l r = fmap l . r
-- Selectors -- Selectors
@ -383,11 +387,38 @@ maybeUnminimizeAfter = (>> maybeUnminimizeFocused)
maybeUnminimizeClassAfter = (>> maximizeSameClassesInWorkspace) maybeUnminimizeClassAfter = (>> maximizeSameClassesInWorkspace)
sameClassOnly action =
action >> minimizeOtherClassesInWorkspace >> maximizeSameClassesInWorkspace
restoreAllMinimized = restoreFocus $ restoreAllMinimized = restoreFocus $
withLastMinimized $ \w -> maximizeWindow w >> restoreAllMinimized withLastMinimized $ \w -> maximizeWindow w >> restoreAllMinimized
restoreOrMinimizeOtherClasses = withLastMinimized' $ restoreOrMinimizeOtherClasses = withLastMinimized' $
maybe minimizeOtherClassesInWorkspace (`seq` restoreAllMinimized) maybe minimizeOtherClassesInWorkspace (`seq` restoreAllMinimized)
getClassPair w = flip (,) w <$> getClass w
windowClassPairs = withWindowSet $ mapM getClassPair . W.allWindows
classToWindowMap = MM.fromList <$> windowClassPairs
allClasses = sort . MM.keys <$> classToWindowMap
thisClass = withWindowSet $ sequence . (getClass <$.> W.peek)
nextClass = do
classes <- allClasses
current <- thisClass
let index = join $ elemIndex <$> current <*> pure classes
return $ fmap (\i -> cycle classes !! (i + 1)) index
classWindow c = do
m <- classToWindowMap
return $ join $ listToMaybe <$> (flip MM.lookup m <$> c)
nextClassWindow = nextClass >>= classWindow
focusNextClass' = join $ windows . maybe id greedyFocusWindow <$> nextClassWindow
focusNextClass = sameClassOnly focusNextClass'
selectClass = join $ DM.menuArgs "rofi" ["-dmenu", "-i"] <$> allClasses
-- Window switching -- Window switching
@ -438,8 +469,11 @@ myBringNextMaybe =
bindBringAndRaise :: KeyMask -> KeySym -> X () -> Query Bool -> [((KeyMask, KeySym), X ())] bindBringAndRaise :: KeyMask -> KeySym -> X () -> Query Bool -> [((KeyMask, KeySym), X ())]
bindBringAndRaise mask sym start query = bindBringAndRaise mask sym start query =
[ ((mask, sym), myRaiseNextMaybe start query) [ ((mask, sym), doRaiseNext)
, ((mask .|. controlMask, sym), myBringNextMaybe start query)] , ((mask .|. controlMask, sym), myBringNextMaybe start query)
, ((mask .|. shiftMask, sym), doRaiseNext >> minimizeOtherClassesInWorkspace)
]
where doRaiseNext = myRaiseNextMaybe start query
bindBringAndRaiseMany :: [(KeyMask, KeySym, X (), Query Bool)] -> [((KeyMask, KeySym), X())] bindBringAndRaiseMany :: [(KeyMask, KeySym, X (), Query Bool)] -> [((KeyMask, KeySym), X())]
bindBringAndRaiseMany = concatMap (\(a, b, c, d) -> bindBringAndRaise a b c d) bindBringAndRaiseMany = concatMap (\(a, b, c, d) -> bindBringAndRaise a b c d)
@ -458,6 +492,8 @@ addKeys conf@XConfig {modMask = modm} =
, ((modm .|. shiftMask, xK_p), spawn "rofi -show run") , ((modm .|. shiftMask, xK_p), spawn "rofi -show run")
, ((modm, xK_g), andDeactivateFull . maybeUnminimizeAfter $ , ((modm, xK_g), andDeactivateFull . maybeUnminimizeAfter $
actionMenu myWindowBringerConfig greedyFocusWindow) actionMenu myWindowBringerConfig greedyFocusWindow)
, ((modm .|. shiftMask, xK_g), andDeactivateFull . sameClassOnly $
actionMenu myWindowBringerConfig greedyFocusWindow)
, ((modm, xK_b), andDeactivateFull $ myBringWindow myWindowBringerConfig) , ((modm, xK_b), andDeactivateFull $ myBringWindow myWindowBringerConfig)
, ((modm .|. shiftMask, xK_b), , ((modm .|. shiftMask, xK_b),
swapMinimizeStateAfter $ actionMenu myWindowBringerConfig swapFocusedWith) swapMinimizeStateAfter $ actionMenu myWindowBringerConfig swapFocusedWith)
@ -478,6 +514,7 @@ addKeys conf@XConfig {modMask = modm} =
, ((modm, xK_j), focusDown) , ((modm, xK_j), focusDown)
, ((modm, xK_k), focusUp) , ((modm, xK_k), focusUp)
, ((modm, xK_m), focusMaster) , ((modm, xK_m), focusMaster)
, ((modm, xK_Tab), focusNextClass)
-- Hyper bindings -- Hyper bindings
, ((mod3Mask, xK_1), toggleFadingForActiveWindow) , ((mod3Mask, xK_1), toggleFadingForActiveWindow)