From ca0508b9bab048da3fda53013dbc8c932494dab1 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Fri, 11 Nov 2016 12:06:03 -0800 Subject: [PATCH] [XMonad] Restore all from same class on focus --- dotfiles/xmonad/xmonad.hs | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/dotfiles/xmonad/xmonad.hs b/dotfiles/xmonad/xmonad.hs index 164709f5..543d58f6 100644 --- a/dotfiles/xmonad/xmonad.hs +++ b/dotfiles/xmonad/xmonad.hs @@ -197,24 +197,39 @@ restoreFocus action = withFocused $ \orig -> action >> windows (W.focusWindow or withWorkspace f = withWindowSet $ \ws -> maybe (return ()) f (W.stack . W.workspace . W.current $ ws) -minimizeOtherClassesInWorkspace = restoreFocus $ - withWorkspace (windowsWithUnfocusedClass >=> mapM_ minimizeWindow) +minimizeOtherClassesInWorkspace = + actOnWindowsInWorkspace minimizeWindow windowsWithUnfocusedClass +maximizeSameClassesInWorkspace = + actOnWindowsInWorkspace maybeUnminimize windowsWithFocusedClass -windowsWithUnfocusedClass ws = windowsWithOtherClasses ws (W.focus ws) +-- Type annotation is needed to resolve ambiguity +actOnWindowsInWorkspace :: (Window -> X ()) -> (W.Stack Window -> X [Window]) -> X () +actOnWindowsInWorkspace windowAction getWindowsAction = restoreFocus $ + withWorkspace (getWindowsAction >=> mapM_ windowAction) -windowsWithOtherClasses workspace window = do - windowClass <- getClass window - let predicate = (/= windowClass) +windowsWithUnfocusedClass ws = windowsWithOtherClasses (W.focus ws) ws +windowsWithFocusedClass ws = windowsWithSameClass (W.focus ws) ws +windowsWithOtherClasses = windowsMatchingPredicate (/=) +windowsWithSameClass = windowsMatchingPredicate (==) + +windowsMatchingPredicate predicate window workspace = + windowsSatisfyingPredicate workspace $ do + windowClass <- getClass window + return $ predicate windowClass + +windowsSatisfyingPredicate workspace getPredicate = do + predicate <- getPredicate filterM (\w -> predicate <$> getClass w) (W.integrate workspace) windowIsMinimized w = do minimized <- XS.gets minimizedStack return $ w `elem` minimized -maybeUnminimizeFocused = withFocused $ \w -> - windowIsMinimized w >>= flip when (maximizeWindow w) +maybeUnminimize w = windowIsMinimized w >>= flip when (maximizeWindow w) -maybeUnminimizeAfter = (>> maybeUnminimizeFocused) +maybeUnminimizeFocused = withFocused maybeUnminimize + +maybeUnminimizeAfter = (>> maximizeSameClassesInWorkspace) restoreAllMinimized = restoreFocus $ withLastMinimized $ \w -> maximizeWindow w >> restoreAllMinimized