From b989655cea7bc92d6d0ba4dcc995eb9851986bb6 Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Wed, 4 Nov 2020 15:29:58 +0000 Subject: [PATCH] Add Typeable constraint to a few LayoutClass instances This enables adding the Typeable constraint to LayoutClass itself (https://github.com/xmonad/xmonad/pull/242) which in turn enables querying the current layout state. That might be useful to e.g. show the current X.L.WorkspaceDir in xmobar. This is a preparation commit that fixes the compile failures that would result in merging that change to xmonad. For this to be generally useful we first need to merge (and ideally also release) that xmonad change, and then we'll need some documentation and perhaps a type class to help find the right LayoutModifier in the tree of ModifiedLayouts and Choices. That will come later. --- CHANGES.md | 5 +++++ XMonad/Layout/LayoutBuilder.hs | 2 +- XMonad/Layout/LayoutBuilderP.hs | 2 +- XMonad/Layout/LayoutModifier.hs | 2 +- XMonad/Layout/MultiToggle.hs | 2 +- XMonad/Layout/ZoomRow.hs | 2 +- 6 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cac2914f..b23153e4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -251,6 +251,11 @@ - Export `Minimize` type constructor. + * Several `LayoutClass` instances now have an additional `Typeable` + constraint which may break some advanced configs. The upside is that we + can now add `Typeable` to `LayoutClass` in `XMonad.Core` and make it + possible to introspect the current layout and its modifiers. + ## 0.16 ### Breaking Changes diff --git a/XMonad/Layout/LayoutBuilder.hs b/XMonad/Layout/LayoutBuilder.hs index 9f59450b..a2ada603 100644 --- a/XMonad/Layout/LayoutBuilder.hs +++ b/XMonad/Layout/LayoutBuilder.hs @@ -259,7 +259,7 @@ relBox x y w h = SubBox (Rel x) (Rel y) (Rel w) (Rel h) -------------------------------------------------------------------------------- instance ( LayoutClass l1 a, LayoutClass l2 a - , Read a, Show a, Show p, Eq a, Typeable a, Predicate p a + , Read a, Show a, Show p, Typeable p, Eq a, Typeable a, Predicate p a ) => LayoutClass (LayoutB l1 l2 p) a where -- | Update window locations. diff --git a/XMonad/Layout/LayoutBuilderP.hs b/XMonad/Layout/LayoutBuilderP.hs index 2c200c3d..e74368c1 100644 --- a/XMonad/Layout/LayoutBuilderP.hs +++ b/XMonad/Layout/LayoutBuilderP.hs @@ -78,7 +78,7 @@ layoutAll box sub = let a = alwaysTrue (Proxy :: Proxy a) in LayoutP Nothing Nothing a box Nothing sub Nothing -instance (LayoutClass l1 w, LayoutClass l2 w, Predicate p w, Show w, Read w, Eq w, Typeable w, Show p) => +instance (LayoutClass l1 w, LayoutClass l2 w, Predicate p w, Show w, Read w, Eq w, Typeable w, Show p, Typeable p) => LayoutClass (LayoutP p l1 l2) w where -- | Update window locations. diff --git a/XMonad/Layout/LayoutModifier.hs b/XMonad/Layout/LayoutModifier.hs index 69f8a256..a0157801 100644 --- a/XMonad/Layout/LayoutModifier.hs +++ b/XMonad/Layout/LayoutModifier.hs @@ -250,7 +250,7 @@ class (Show (m a), Read (m a)) => LayoutModifier m a where -- | The 'LayoutClass' instance for a 'ModifiedLayout' defines the -- semantics of a 'LayoutModifier' applied to an underlying layout. -instance (LayoutModifier m a, LayoutClass l a) => LayoutClass (ModifiedLayout m l) a where +instance (LayoutModifier m a, LayoutClass l a, Typeable m) => LayoutClass (ModifiedLayout m l) a where runLayout (Workspace i (ModifiedLayout m l) ms) r = do ((ws, ml'),mm') <- modifyLayoutWithUpdate m (Workspace i l ms) r (ws', mm'') <- redoLayout (maybe m id mm') r ms ws diff --git a/XMonad/Layout/MultiToggle.hs b/XMonad/Layout/MultiToggle.hs index 2f9d8d9e..f7b28c62 100644 --- a/XMonad/Layout/MultiToggle.hs +++ b/XMonad/Layout/MultiToggle.hs @@ -188,7 +188,7 @@ instance (Transformer a w, HList b w) => HList (HCons a b) w where geq :: (Typeable a, Eq a, Typeable b) => a -> b -> Bool geq a b = Just a == cast b -instance (Typeable a, Show ts, HList ts a, LayoutClass l a) => LayoutClass (MultiToggle ts l) a where +instance (Typeable a, Show ts, Typeable ts, HList ts a, LayoutClass l a) => LayoutClass (MultiToggle ts l) a where description mt = currLayout mt `unEL` \l -> description l runLayout (Workspace i mt s) r = case currLayout mt of diff --git a/XMonad/Layout/ZoomRow.hs b/XMonad/Layout/ZoomRow.hs index 6f86726c..816e64c0 100644 --- a/XMonad/Layout/ZoomRow.hs +++ b/XMonad/Layout/ZoomRow.hs @@ -185,7 +185,7 @@ zoomReset = ZoomTo 1 -- * LayoutClass instance -instance (EQF f a, Show a, Read a, Show (f a), Read (f a)) +instance (EQF f a, Show a, Read a, Show (f a), Read (f a), Typeable f) => LayoutClass (ZoomRow f) a where description (ZC _ Nothing) = "ZoomRow" description (ZC _ (Just s)) = "ZoomRow" ++ if full $ W.focus s