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.
This commit is contained in:
Tomas Janousek
2020-11-04 15:29:58 +00:00
parent 087076f136
commit b989655cea
6 changed files with 10 additions and 5 deletions

View File

@@ -251,6 +251,11 @@
- Export `Minimize` type constructor. - 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 ## 0.16
### Breaking Changes ### Breaking Changes

View File

@@ -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 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 ) => LayoutClass (LayoutB l1 l2 p) a where
-- | Update window locations. -- | Update window locations.

View File

@@ -78,7 +78,7 @@ layoutAll box sub =
let a = alwaysTrue (Proxy :: Proxy a) let a = alwaysTrue (Proxy :: Proxy a)
in LayoutP Nothing Nothing a box Nothing sub Nothing 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 LayoutClass (LayoutP p l1 l2) w where
-- | Update window locations. -- | Update window locations.

View File

@@ -250,7 +250,7 @@ class (Show (m a), Read (m a)) => LayoutModifier m a where
-- | The 'LayoutClass' instance for a 'ModifiedLayout' defines the -- | The 'LayoutClass' instance for a 'ModifiedLayout' defines the
-- semantics of a 'LayoutModifier' applied to an underlying layout. -- 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 = runLayout (Workspace i (ModifiedLayout m l) ms) r =
do ((ws, ml'),mm') <- modifyLayoutWithUpdate m (Workspace i l ms) r do ((ws, ml'),mm') <- modifyLayoutWithUpdate m (Workspace i l ms) r
(ws', mm'') <- redoLayout (maybe m id mm') r ms ws (ws', mm'') <- redoLayout (maybe m id mm') r ms ws

View File

@@ -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 :: (Typeable a, Eq a, Typeable b) => a -> b -> Bool
geq a b = Just a == cast b 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 description mt = currLayout mt `unEL` \l -> description l
runLayout (Workspace i mt s) r = case currLayout mt of runLayout (Workspace i mt s) r = case currLayout mt of

View File

@@ -185,7 +185,7 @@ zoomReset = ZoomTo 1
-- * LayoutClass instance -- * 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 => LayoutClass (ZoomRow f) a where
description (ZC _ Nothing) = "ZoomRow" description (ZC _ Nothing) = "ZoomRow"
description (ZC _ (Just s)) = "ZoomRow" ++ if full $ W.focus s description (ZC _ (Just s)) = "ZoomRow" ++ if full $ W.focus s