From ab0d160ac877c9719dd8112e6f06312f3cd69d6c Mon Sep 17 00:00:00 2001
From: Jan Vornberger <jan.vornberger@informatik.uni-oldenburg.de>
Date: Wed, 28 Jul 2010 00:48:41 +0200
Subject: Minimize: Replaced calls to 'sendMessage' (BW.focusDown) and
 'windows' with alternative methods

Ignore-this: 67257480b7b93181967a806fedf6fbc5
Calling these functions during message handling results in the loss of layout state.
This fixes a number of bugs related to the combination of X.L.Minimize with a decoration.

darcs-hash:20100727224841-594c5-c8ddec3ae634ec96103e332433066b5173a0002a.gz
---
 XMonad/Layout/DecorationAddons.hs      |  2 +-
 XMonad/Layout/ImageButtonDecoration.hs |  2 +-
 XMonad/Layout/Minimize.hs              | 21 ++++++++++++---------
 3 files changed, 14 insertions(+), 11 deletions(-)

(limited to 'XMonad/Layout')

diff --git a/XMonad/Layout/DecorationAddons.hs b/XMonad/Layout/DecorationAddons.hs
index 9192e54..6d751ec 100644
--- a/XMonad/Layout/DecorationAddons.hs
+++ b/XMonad/Layout/DecorationAddons.hs
@@ -62,7 +62,7 @@ titleBarButtonHandler mainw distFromLeft distFromRight = do
                              then focus mainw >> sendMessage (maximizeRestore mainw) >> return True
                   else if (fi distFromRight >= minimizeButtonOffset &&
                            fi distFromRight <= minimizeButtonOffset + buttonSize)
-                             then focus mainw >> sendMessage (MinimizeWin mainw) >> return True
+                             then focus mainw >> minimizeWindow mainw >> return True
                   else return False
     action
 
diff --git a/XMonad/Layout/ImageButtonDecoration.hs b/XMonad/Layout/ImageButtonDecoration.hs
index c8d8453..23c6cc3 100644
--- a/XMonad/Layout/ImageButtonDecoration.hs
+++ b/XMonad/Layout/ImageButtonDecoration.hs
@@ -158,7 +158,7 @@ imageTitleBarButtonHandler mainw distFromLeft distFromRight = do
                              then focus mainw >> sendMessage (maximizeRestore mainw) >> return True
                   else if (fi distFromRight >= minimizeButtonOffset &&
                            fi distFromRight <= minimizeButtonOffset + buttonSize)
-                             then focus mainw >> sendMessage (MinimizeWin mainw) >> return True
+                             then focus mainw >> minimizeWindow mainw >> return True
                   else return False
     action
 
diff --git a/XMonad/Layout/Minimize.hs b/XMonad/Layout/Minimize.hs
index aced551..e206ac5 100644
--- a/XMonad/Layout/Minimize.hs
+++ b/XMonad/Layout/Minimize.hs
@@ -18,7 +18,8 @@ module XMonad.Layout.Minimize (
         -- * Usage
         -- $usage
         minimize,
-        MinimizeMsg(..)
+        minimizeWindow,
+        MinimizeMsg(RestoreMinimizedWin,RestoreNextMinimizedWin)
     ) where
 
 import XMonad
@@ -47,7 +48,7 @@ import Foreign.C.Types (CLong)
 --
 -- In the key-bindings, do something like:
 --
--- >        , ((modm,               xK_m     ), withFocused (\f -> sendMessage (MinimizeWin f)))
+-- >        , ((modm,               xK_m     ), withFocused minimizeWindow)
 -- >        , ((modm .|. shiftMask, xK_m     ), sendMessage RestoreNextMinimizedWin)
 --
 -- The first action will minimize the focused window, while the second one will restore
@@ -75,6 +76,8 @@ data MinimizeMsg = MinimizeWin Window
                     deriving (Typeable, Eq)
 instance Message MinimizeMsg
 
+minimizeWindow :: Window -> X ()
+minimizeWindow w = sendMessage (MinimizeWin w) >> BW.focusDown
 
 setMinimizedState :: Window -> Int -> (CLong -> [CLong] -> [CLong]) -> X ()
 setMinimizedState win st f = do
@@ -103,34 +106,34 @@ instance LayoutModifier Minimize Window where
 
     handleMess (Minimize minimized unfloated) m
         | Just (MinimizeWin w) <- fromMessage m, not (w `elem` minimized) = do
-                BW.focusDown
                 setMinimized w
                 ws <- gets windowset
                 case M.lookup w (W.floating ws) of
                   Nothing -> return $ Just $ Minimize (w:minimized) unfloated
                   Just r -> do
-                    (windows . W.sink) w
+                    modify (\s -> s { windowset = W.sink w ws})
                     return $ Just $ Minimize (w:minimized) (M.insert w r unfloated)
         | Just (RestoreMinimizedWin w) <- fromMessage m = do
             setNotMinimized w
             case M.lookup w unfloated of
               Nothing -> return $ Just $ Minimize (minimized \\ [w]) unfloated
               Just r -> do
-                (windows . (W.float w)) r
+                ws <- gets windowset
+                modify (\s -> s { windowset = W.float w r ws})
                 return $ Just $ Minimize (minimized \\ [w]) (M.delete w unfloated)
-        | Just RestoreNextMinimizedWin <- fromMessage m =
+        | Just RestoreNextMinimizedWin <- fromMessage m = do
+          ws <- gets windowset
           if not (null minimized)
             then case M.lookup (head minimized) unfloated of
               Nothing -> do
                 let w = head minimized
                 setNotMinimized w
-                focus w
+                modify (\s -> s { windowset = W.focusWindow w ws})
                 return $ Just $ Minimize (tail minimized) unfloated
               Just r -> do
                 let w = head minimized
                 setNotMinimized w
-                (windows . (W.float w)) r
-                focus w
+                modify (\s -> s { windowset = (W.focusWindow w . W.float w r) ws})
                 return $ Just $ Minimize (tail minimized) (M.delete w unfloated)
             else return Nothing
         | Just BW.UpdateBoring <- fromMessage m = do
-- 
cgit v1.2.3