mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-09-01 20:03:46 -07:00
Prefer safe alternatives to getWindowAttributes
Whenever possible, prefer the safe wrappers withWindowAttributes or safeGetWindowAttributes to getWindowAttributes. Places where these are not applicable are limited to layouts, where there is not good "default value" to give back in case these calls fail. In these cases, we let the exception handling of the layout mechanism handle it and fall back to the Full layout. Fixes: https://github.com/xmonad/xmonad-contrib/issues/146
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE ParallelListComp, PatternGuards #-}
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
-----------------------------------------------------------------------------
|
||||
-- |
|
||||
-- Module : XMonad.Layout.LayoutHints
|
||||
@@ -32,8 +33,8 @@ import XMonad(LayoutClass(runLayout), mkAdjust, Window,
|
||||
Dimension, Position, Rectangle(Rectangle), D,
|
||||
X, refresh, Event(..), propertyNotify, wM_NORMAL_HINTS,
|
||||
(<&&>), io, applySizeHints, whenX, isClient, withDisplay,
|
||||
getWindowAttributes, getWMNormalHints, WindowAttributes(..))
|
||||
import XMonad.Prelude (All (..), fromJust, join, maximumBy, on, sortBy)
|
||||
getWMNormalHints, WindowAttributes(..))
|
||||
import XMonad.Prelude
|
||||
import qualified XMonad.StackSet as W
|
||||
|
||||
import XMonad.Layout.Decoration(isInStack)
|
||||
@@ -264,8 +265,9 @@ hintsEventHook _ = return (All True)
|
||||
|
||||
-- | True if the window's current size does not satisfy its size hints.
|
||||
hintsMismatch :: Window -> X Bool
|
||||
hintsMismatch w = withDisplay $ \d -> io $ do
|
||||
wa <- getWindowAttributes d w
|
||||
sh <- getWMNormalHints d w
|
||||
let dim = (fromIntegral $ wa_width wa, fromIntegral $ wa_height wa)
|
||||
return $ dim /= applySizeHints 0 sh dim
|
||||
hintsMismatch w = safeGetWindowAttributes w >>= \case
|
||||
Nothing -> pure False
|
||||
Just wa -> do
|
||||
sh <- withDisplay $ \d -> io (getWMNormalHints d w)
|
||||
let dim = (fromIntegral $ wa_width wa, fromIntegral $ wa_height wa)
|
||||
return $ dim /= applySizeHints 0 sh dim
|
||||
|
Reference in New Issue
Block a user