mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-07-26 09:41:52 -07:00
Merge pull request #273 from orbisvicis/reSpaced
reSpaced: Compatibility v2
This commit is contained in:
@@ -21,7 +21,7 @@ module XMonad.Layout.Spacing
|
|||||||
-- $usage
|
-- $usage
|
||||||
Border (..)
|
Border (..)
|
||||||
, Spacing (..)
|
, Spacing (..)
|
||||||
, ModifySpacing (..)
|
, SpacingModifier (..)
|
||||||
, spacingRaw
|
, spacingRaw
|
||||||
, setSmartSpacing
|
, setSmartSpacing
|
||||||
, setScreenSpacing, setScreenSpacingEnabled
|
, setScreenSpacing, setScreenSpacingEnabled
|
||||||
@@ -29,20 +29,26 @@ module XMonad.Layout.Spacing
|
|||||||
, toggleSmartSpacing
|
, toggleSmartSpacing
|
||||||
, toggleScreenSpacingEnabled
|
, toggleScreenSpacingEnabled
|
||||||
, toggleWindowSpacingEnabled
|
, toggleWindowSpacingEnabled
|
||||||
|
, setScreenWindowSpacing
|
||||||
, incWindowSpacing, incScreenSpacing
|
, incWindowSpacing, incScreenSpacing
|
||||||
, decWindowSpacing, decScreenSpacing
|
, decWindowSpacing, decScreenSpacing
|
||||||
, borderIncrementBy
|
, incScreenWindowSpacing, decScreenWindowSpacing
|
||||||
|
, borderMap, borderIncrementBy
|
||||||
-- * Backwards Compatibility
|
-- * Backwards Compatibility
|
||||||
-- $backwardsCompatibility
|
-- $backwardsCompatibility
|
||||||
|
, SpacingWithEdge
|
||||||
|
, SmartSpacing, SmartSpacingWithEdge
|
||||||
|
, ModifySpacing (..)
|
||||||
, spacing, spacingWithEdge
|
, spacing, spacingWithEdge
|
||||||
, smartSpacing, smartSpacingWithEdge
|
, smartSpacing, smartSpacingWithEdge
|
||||||
, setSpacing, incSpacing
|
, setSpacing, incSpacing
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import XMonad
|
import XMonad
|
||||||
import XMonad.StackSet as W
|
import XMonad.StackSet as W
|
||||||
|
import qualified XMonad.Util.Rectangle as R
|
||||||
import XMonad.Layout.LayoutModifier
|
import XMonad.Layout.LayoutModifier
|
||||||
import qualified XMonad.Util.Rectangle as R
|
import XMonad.Actions.MessageFeedback
|
||||||
|
|
||||||
|
|
||||||
-- $usage
|
-- $usage
|
||||||
@@ -175,6 +181,9 @@ instance Eq a => LayoutModifier Spacing a where
|
|||||||
= Just $ s { windowBorder = f wb }
|
= Just $ s { windowBorder = f wb }
|
||||||
| Just (ModifyWindowBorderEnabled f) <- fromMessage m
|
| Just (ModifyWindowBorderEnabled f) <- fromMessage m
|
||||||
= Just $ s { windowBorderEnabled = f wbe }
|
= Just $ s { windowBorderEnabled = f wbe }
|
||||||
|
| Just (ModifySpacing f) <- fromMessage m
|
||||||
|
= Just $ let f' = borderMap (fromIntegral . f . fromIntegral)
|
||||||
|
in s { screenBorder = f' sb, windowBorder = f' wb }
|
||||||
| otherwise
|
| otherwise
|
||||||
= Nothing
|
= Nothing
|
||||||
|
|
||||||
@@ -193,7 +202,7 @@ spacingRaw b sb sbe wb wbe = ModifiedLayout (Spacing b sb sbe wb wbe)
|
|||||||
|
|
||||||
-- | Messages to alter the state of 'Spacing' using the endomorphic function
|
-- | Messages to alter the state of 'Spacing' using the endomorphic function
|
||||||
-- arguments.
|
-- arguments.
|
||||||
data ModifySpacing
|
data SpacingModifier
|
||||||
= ModifySmartBorder (Bool -> Bool)
|
= ModifySmartBorder (Bool -> Bool)
|
||||||
| ModifyScreenBorder (Border -> Border)
|
| ModifyScreenBorder (Border -> Border)
|
||||||
| ModifyScreenBorderEnabled (Bool -> Bool)
|
| ModifyScreenBorderEnabled (Bool -> Bool)
|
||||||
@@ -201,7 +210,7 @@ data ModifySpacing
|
|||||||
| ModifyWindowBorderEnabled (Bool -> Bool)
|
| ModifyWindowBorderEnabled (Bool -> Bool)
|
||||||
deriving (Typeable)
|
deriving (Typeable)
|
||||||
|
|
||||||
instance Message ModifySpacing
|
instance Message SpacingModifier
|
||||||
|
|
||||||
-- | Set 'smartBorder' to the given 'Bool'.
|
-- | Set 'smartBorder' to the given 'Bool'.
|
||||||
setSmartSpacing :: Bool -> X ()
|
setSmartSpacing :: Bool -> X ()
|
||||||
@@ -235,6 +244,12 @@ toggleScreenSpacingEnabled = sendMessage $ ModifyScreenBorderEnabled not
|
|||||||
toggleWindowSpacingEnabled :: X ()
|
toggleWindowSpacingEnabled :: X ()
|
||||||
toggleWindowSpacingEnabled = sendMessage $ ModifyWindowBorderEnabled not
|
toggleWindowSpacingEnabled = sendMessage $ ModifyWindowBorderEnabled not
|
||||||
|
|
||||||
|
-- | Set all borders to a uniform size; see 'setWindowSpacing' and
|
||||||
|
-- 'setScreenSpacing'.
|
||||||
|
setScreenWindowSpacing :: Integer -> X ()
|
||||||
|
setScreenWindowSpacing = sendMessages . flip map [ModifyWindowBorder,ModifyScreenBorder]
|
||||||
|
. flip id . const . uniformBorder
|
||||||
|
|
||||||
-- | Increment the borders of 'windowBorder' using 'borderIncrementBy', which
|
-- | Increment the borders of 'windowBorder' using 'borderIncrementBy', which
|
||||||
-- preserves border ratios during clamping.
|
-- preserves border ratios during clamping.
|
||||||
incWindowSpacing :: Integer -> X ()
|
incWindowSpacing :: Integer -> X ()
|
||||||
@@ -252,6 +267,20 @@ decWindowSpacing = incWindowSpacing . negate
|
|||||||
decScreenSpacing :: Integer -> X ()
|
decScreenSpacing :: Integer -> X ()
|
||||||
decScreenSpacing = incScreenSpacing . negate
|
decScreenSpacing = incScreenSpacing . negate
|
||||||
|
|
||||||
|
-- | Increment both screen and window borders; see 'incWindowSpacing' and
|
||||||
|
-- 'incScreenSpacing'.
|
||||||
|
incScreenWindowSpacing :: Integer -> X ()
|
||||||
|
incScreenWindowSpacing = sendMessages . flip map [ModifyWindowBorder,ModifyScreenBorder]
|
||||||
|
. flip id . borderIncrementBy
|
||||||
|
|
||||||
|
-- | Inverse of 'incScreenWindowSpacing'.
|
||||||
|
decScreenWindowSpacing :: Integer -> X ()
|
||||||
|
decScreenWindowSpacing = incScreenWindowSpacing . negate
|
||||||
|
|
||||||
|
-- | Construct a uniform 'Border'. That is, having equal individual borders.
|
||||||
|
uniformBorder :: Integer -> Border
|
||||||
|
uniformBorder i = Border i i i i
|
||||||
|
|
||||||
-- | Map a function over a 'Border'. That is, over the four individual borders.
|
-- | Map a function over a 'Border'. That is, over the four individual borders.
|
||||||
borderMap :: (Integer -> Integer) -> Border -> Border
|
borderMap :: (Integer -> Integer) -> Border -> Border
|
||||||
borderMap f (Border t b r l) = Border (f t) (f b) (f r) (f l)
|
borderMap f (Border t b r l) = Border (f t) (f b) (f r) (f l)
|
||||||
@@ -299,43 +328,61 @@ orderSelect o (lt,eq,gt) = case o of
|
|||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
-- Backwards Compatibility:
|
-- Backwards Compatibility:
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
{-# DEPRECATED SpacingWithEdge, SmartSpacing, SmartSpacingWithEdge "Use Spacing instead." #-}
|
||||||
|
{-# DEPRECATED ModifySpacing "Use SpacingModifier instead, perhaps with sendMessages." #-}
|
||||||
{-# DEPRECATED spacing, spacingWithEdge, smartSpacing, smartSpacingWithEdge "Use spacingRaw instead." #-}
|
{-# DEPRECATED spacing, spacingWithEdge, smartSpacing, smartSpacingWithEdge "Use spacingRaw instead." #-}
|
||||||
{-# DEPRECATED setSpacing "Use setWindowSpacing/setScreenSpacing instead." #-}
|
{-# DEPRECATED setSpacing "Use setScreenWindowSpacing instead." #-}
|
||||||
{-# DEPRECATED incSpacing "Use incWindowSpacing/incScreenSpacing instead." #-}
|
{-# DEPRECATED incSpacing "Use incScreenWindowSpacing instead." #-}
|
||||||
|
|
||||||
-- $backwardsCompatibility
|
-- $backwardsCompatibility
|
||||||
-- The following functions exist solely for compatibility with pre-0.14
|
-- The following functions and types exist solely for compatibility with
|
||||||
-- releases.
|
-- pre-0.14 releases.
|
||||||
|
|
||||||
|
-- | A type synonym for the 'Spacing' 'LayoutModifier'.
|
||||||
|
type SpacingWithEdge = Spacing
|
||||||
|
|
||||||
|
-- | A type synonym for the 'Spacing' 'LayoutModifier'.
|
||||||
|
type SmartSpacing = Spacing
|
||||||
|
|
||||||
|
-- | A type synonym for the 'Spacing' 'LayoutModifier'.
|
||||||
|
type SmartSpacingWithEdge = Spacing
|
||||||
|
|
||||||
|
-- | Message to dynamically modify (e.g. increase\/decrease\/set) the size of
|
||||||
|
-- the screen spacing and window spacing. See 'SpacingModifier'.
|
||||||
|
data ModifySpacing = ModifySpacing (Int -> Int) deriving (Typeable)
|
||||||
|
|
||||||
|
instance Message ModifySpacing
|
||||||
|
|
||||||
-- | Surround all windows by a certain number of pixels of blank space. See
|
-- | Surround all windows by a certain number of pixels of blank space. See
|
||||||
-- 'spacingRaw'.
|
-- 'spacingRaw'.
|
||||||
spacing :: Integer -> l a -> ModifiedLayout Spacing l a
|
spacing :: Int -> l a -> ModifiedLayout Spacing l a
|
||||||
spacing i = spacingRaw False (Border 0 0 0 0) False (Border i i i i) True
|
spacing i = spacingRaw False (uniformBorder 0) False (uniformBorder i') True
|
||||||
|
where i' = fromIntegral i
|
||||||
|
|
||||||
-- | Surround all windows by a certain number of pixels of blank space, and
|
-- | Surround all windows by a certain number of pixels of blank space, and
|
||||||
-- additionally adds the same amount of spacing around the edge of the screen.
|
-- additionally adds the same amount of spacing around the edge of the screen.
|
||||||
-- See 'spacingRaw'.
|
-- See 'spacingRaw'.
|
||||||
spacingWithEdge :: Integer -> l a -> ModifiedLayout Spacing l a
|
spacingWithEdge :: Int -> l a -> ModifiedLayout Spacing l a
|
||||||
spacingWithEdge i = spacingRaw False (Border i i i i) True (Border i i i i) True
|
spacingWithEdge i = spacingRaw False (uniformBorder i') True (uniformBorder i') True
|
||||||
|
where i' = fromIntegral i
|
||||||
|
|
||||||
-- | Surrounds all windows with blank space, except when the window is the only
|
-- | Surrounds all windows with blank space, except when the window is the only
|
||||||
-- visible window on the current workspace. See 'spacingRaw'.
|
-- visible window on the current workspace. See 'spacingRaw'.
|
||||||
smartSpacing :: Integer -> l a -> ModifiedLayout Spacing l a
|
smartSpacing :: Int -> l a -> ModifiedLayout Spacing l a
|
||||||
smartSpacing i = spacingRaw True (Border 0 0 0 0) False (Border i i i i) True
|
smartSpacing i = spacingRaw True (uniformBorder 0) False (uniformBorder i') True
|
||||||
|
where i' = fromIntegral i
|
||||||
|
|
||||||
-- | Surrounds all windows with blank space, and adds the same amount of
|
-- | Surrounds all windows with blank space, and adds the same amount of
|
||||||
-- spacing around the edge of the screen, except when the window is the only
|
-- spacing around the edge of the screen, except when the window is the only
|
||||||
-- visible window on the current workspace. See 'spacingRaw'.
|
-- visible window on the current workspace. See 'spacingRaw'.
|
||||||
smartSpacingWithEdge :: Integer -> l a -> ModifiedLayout Spacing l a
|
smartSpacingWithEdge :: Int -> l a -> ModifiedLayout Spacing l a
|
||||||
smartSpacingWithEdge i = spacingRaw True (Border i i i i) True (Border i i i i) True
|
smartSpacingWithEdge i = spacingRaw True (uniformBorder i') True (uniformBorder i') True
|
||||||
|
where i' = fromIntegral i
|
||||||
|
|
||||||
-- | Set all borders to a uniform size; see 'setWindowSpacing' and
|
-- | See 'setScreenWindowSpacing'.
|
||||||
-- 'setScreenSpacing'.
|
setSpacing :: Int -> X ()
|
||||||
setSpacing :: Integer -> X ()
|
setSpacing = setScreenWindowSpacing . fromIntegral
|
||||||
setSpacing i = setWindowSpacing b >> setScreenSpacing b
|
|
||||||
where b = Border i i i i
|
|
||||||
|
|
||||||
-- | Increment both screen and window borders; see 'incWindowSpacing' and
|
-- | See 'incScreenWindowSpacing'.
|
||||||
-- 'incScreenSpacing'.
|
incSpacing :: Int -> X ()
|
||||||
incSpacing :: Integer -> X ()
|
incSpacing = incScreenWindowSpacing . fromIntegral
|
||||||
incSpacing i = incWindowSpacing i >> incScreenSpacing i
|
|
||||||
|
Reference in New Issue
Block a user