From 2fde742e7a632f2f982cb03417abb6f0d2039f8d Mon Sep 17 00:00:00 2001 From: Yclept Nemo Date: Thu, 14 Jun 2018 13:00:27 -0400 Subject: [PATCH 1/2] 'XMonad.Layout.Spacing': compatibility tweaks * All the backwards-compatibility functions now accept `Int` rather than `Integer`: `spacing`, `spacingWithEdge`, `smartSpacing`, `smartSpacingWithEdge`, `setSpacing`, and `incSpacing`. Work done by @LSLeary. * Introduce the new functions `setScreenWindowSpacing`, `incScreenWindowSpacing`, `decScreenWindowSpacing`. Unlike their original `setSpacing`, `incSpacing` counterparts, these refresh no more than once. Requires `sendMessages` from my PR of `XMonad.Actions.MessageFeedback`. Suggestion by @LSLeary and implemented so any combination of messages can be sent without triggering unnecessary refreshes. --- XMonad/Layout/Spacing.hs | 66 +++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/XMonad/Layout/Spacing.hs b/XMonad/Layout/Spacing.hs index fe44cecc..b4e8078f 100644 --- a/XMonad/Layout/Spacing.hs +++ b/XMonad/Layout/Spacing.hs @@ -29,8 +29,10 @@ module XMonad.Layout.Spacing , toggleSmartSpacing , toggleScreenSpacingEnabled , toggleWindowSpacingEnabled + , setScreenWindowSpacing , incWindowSpacing, incScreenSpacing , decWindowSpacing, decScreenSpacing + , incScreenWindowSpacing, decScreenWindowSpacing , borderIncrementBy -- * Backwards Compatibility -- $backwardsCompatibility @@ -40,9 +42,10 @@ module XMonad.Layout.Spacing ) where import XMonad -import XMonad.StackSet as W +import XMonad.StackSet as W +import qualified XMonad.Util.Rectangle as R import XMonad.Layout.LayoutModifier -import qualified XMonad.Util.Rectangle as R +import XMonad.Actions.MessageFeedback -- $usage @@ -235,6 +238,12 @@ toggleScreenSpacingEnabled = sendMessage $ ModifyScreenBorderEnabled not toggleWindowSpacingEnabled :: X () 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 -- preserves border ratios during clamping. incWindowSpacing :: Integer -> X () @@ -252,6 +261,20 @@ decWindowSpacing = incWindowSpacing . negate decScreenSpacing :: Integer -> X () 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. borderMap :: (Integer -> Integer) -> Border -> Border borderMap f (Border t b r l) = Border (f t) (f b) (f r) (f l) @@ -300,8 +323,8 @@ orderSelect o (lt,eq,gt) = case o of -- Backwards Compatibility: ----------------------------------------------------------------------------- {-# DEPRECATED spacing, spacingWithEdge, smartSpacing, smartSpacingWithEdge "Use spacingRaw instead." #-} -{-# DEPRECATED setSpacing "Use setWindowSpacing/setScreenSpacing instead." #-} -{-# DEPRECATED incSpacing "Use incWindowSpacing/incScreenSpacing instead." #-} +{-# DEPRECATED setSpacing "Use setScreenWindowSpacing instead." #-} +{-# DEPRECATED incSpacing "Use incScreenWindowSpacing instead." #-} -- $backwardsCompatibility -- The following functions exist solely for compatibility with pre-0.14 @@ -309,33 +332,34 @@ orderSelect o (lt,eq,gt) = case o of -- | Surround all windows by a certain number of pixels of blank space. See -- 'spacingRaw'. -spacing :: Integer -> l a -> ModifiedLayout Spacing l a -spacing i = spacingRaw False (Border 0 0 0 0) False (Border i i i i) True +spacing :: Int -> l a -> ModifiedLayout Spacing l a +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 -- additionally adds the same amount of spacing around the edge of the screen. -- See 'spacingRaw'. -spacingWithEdge :: Integer -> l a -> ModifiedLayout Spacing l a -spacingWithEdge i = spacingRaw False (Border i i i i) True (Border i i i i) True +spacingWithEdge :: Int -> l a -> ModifiedLayout Spacing l a +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 -- visible window on the current workspace. See 'spacingRaw'. -smartSpacing :: Integer -> l a -> ModifiedLayout Spacing l a -smartSpacing i = spacingRaw True (Border 0 0 0 0) False (Border i i i i) True +smartSpacing :: Int -> l a -> ModifiedLayout Spacing l a +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 -- spacing around the edge of the screen, except when the window is the only -- visible window on the current workspace. See 'spacingRaw'. -smartSpacingWithEdge :: Integer -> l a -> ModifiedLayout Spacing l a -smartSpacingWithEdge i = spacingRaw True (Border i i i i) True (Border i i i i) True +smartSpacingWithEdge :: Int -> l a -> ModifiedLayout Spacing l a +smartSpacingWithEdge i = spacingRaw True (uniformBorder i') True (uniformBorder i') True + where i' = fromIntegral i --- | Set all borders to a uniform size; see 'setWindowSpacing' and --- 'setScreenSpacing'. -setSpacing :: Integer -> X () -setSpacing i = setWindowSpacing b >> setScreenSpacing b - where b = Border i i i i +-- | See 'setScreenWindowSpacing'. +setSpacing :: Int -> X () +setSpacing = setScreenWindowSpacing . fromIntegral --- | Increment both screen and window borders; see 'incWindowSpacing' and --- 'incScreenSpacing'. -incSpacing :: Integer -> X () -incSpacing i = incWindowSpacing i >> incScreenSpacing i +-- | See 'incScreenWindowSpacing'. +incSpacing :: Int -> X () +incSpacing = incScreenWindowSpacing . fromIntegral From 3e680363602c836e6b34236f6d017eb315d411e8 Mon Sep 17 00:00:00 2001 From: Yclept Nemo Date: Thu, 19 Jul 2018 14:41:00 -0400 Subject: [PATCH 2/2] XMonad.Layout.Spacing: extreme compatibility * Reintroduce the original 'ModifySpacing' type and constructor as deprecated; the new 'ModifySpacing' type was renamed to 'SpacingModifier'. Suggested by @LSLeary. * Types 'SpacingWithEdge', 'SmartSpacing', and 'SmartSpacingWithEdge' have been reintroduced as deprecated type synonyms of 'Spacing'. Work by @LSLeary. Also 'borderMap' is now exported; it might be useful. --- XMonad/Layout/Spacing.hs | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/XMonad/Layout/Spacing.hs b/XMonad/Layout/Spacing.hs index b4e8078f..c103c356 100644 --- a/XMonad/Layout/Spacing.hs +++ b/XMonad/Layout/Spacing.hs @@ -21,7 +21,7 @@ module XMonad.Layout.Spacing -- $usage Border (..) , Spacing (..) - , ModifySpacing (..) + , SpacingModifier (..) , spacingRaw , setSmartSpacing , setScreenSpacing, setScreenSpacingEnabled @@ -33,9 +33,12 @@ module XMonad.Layout.Spacing , incWindowSpacing, incScreenSpacing , decWindowSpacing, decScreenSpacing , incScreenWindowSpacing, decScreenWindowSpacing - , borderIncrementBy + , borderMap, borderIncrementBy -- * Backwards Compatibility -- $backwardsCompatibility + , SpacingWithEdge + , SmartSpacing, SmartSpacingWithEdge + , ModifySpacing (..) , spacing, spacingWithEdge , smartSpacing, smartSpacingWithEdge , setSpacing, incSpacing @@ -178,6 +181,9 @@ instance Eq a => LayoutModifier Spacing a where = Just $ s { windowBorder = f wb } | Just (ModifyWindowBorderEnabled f) <- fromMessage m = 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 = Nothing @@ -196,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 -- arguments. -data ModifySpacing +data SpacingModifier = ModifySmartBorder (Bool -> Bool) | ModifyScreenBorder (Border -> Border) | ModifyScreenBorderEnabled (Bool -> Bool) @@ -204,7 +210,7 @@ data ModifySpacing | ModifyWindowBorderEnabled (Bool -> Bool) deriving (Typeable) -instance Message ModifySpacing +instance Message SpacingModifier -- | Set 'smartBorder' to the given 'Bool'. setSmartSpacing :: Bool -> X () @@ -322,13 +328,30 @@ orderSelect o (lt,eq,gt) = case o of ----------------------------------------------------------------------------- -- 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 setSpacing "Use setScreenWindowSpacing instead." #-} {-# DEPRECATED incSpacing "Use incScreenWindowSpacing instead." #-} -- $backwardsCompatibility --- The following functions exist solely for compatibility with pre-0.14 --- releases. +-- The following functions and types exist solely for compatibility with +-- 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 -- 'spacingRaw'.