From 6dc1e319d177ac9aa6b9b6f6395077827ee7e1a3 Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Wed, 4 Nov 2020 15:09:12 +0000 Subject: [PATCH] Make layouts Typeable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes it possible to query the current layout state, which might be useful to e.g. show the current X.L.WorkspaceDir in xmobar. Example of use (assuming myLayout is the layout that is assigned to layoutHook): asMyLayout (Layout l) = (`asTypeOf` myLayout) <$> cast l … layout <- asMyLayout . W.layout . W.workspace . W.current <$> gets windowset case layout of Just (WorkspaceDir d) -> … Unfortunately this requires adding the Typeable constraint to a bunch of classes in xmonad-contrib, so we need to merge those changes there first (fortunately it doesn't need to go in lockstep, adding a Typeable constraint to those classes in xmonad-contrib is harmless). --- CHANGES.md | 4 ++++ src/XMonad/Core.hs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index cd7b88e..f0d3157 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,10 @@ causing some floating windows to be smaller/larger than the size they requested. + * Added `Typeable layout` constraint to `LayoutClass`, making it possible to + cast `Layout` back into a concrete type and extract current layout state + from it. + ## 0.15 (September 30, 2018) * Reimplement `sendMessage` to deal properly with windowset changes made diff --git a/src/XMonad/Core.hs b/src/XMonad/Core.hs index 7810522..96a9878 100644 --- a/src/XMonad/Core.hs +++ b/src/XMonad/Core.hs @@ -271,7 +271,7 @@ readsLayout (Layout l) s = [(Layout (asTypeOf x l), rs) | (x, rs) <- reads s] -- 'runLayout', 'handleMessage', and so on. This ensures that the -- proper methods will be used, regardless of the particular methods -- that any 'LayoutClass' instance chooses to define. -class Show (layout a) => LayoutClass layout a where +class (Show (layout a), Typeable layout) => LayoutClass layout a where -- | By default, 'runLayout' calls 'doLayout' if there are any -- windows to be laid out, and 'emptyLayout' otherwise. Most