From 2d33f18dec4fea5ede5e39660b8d22900c4b9deb Mon Sep 17 00:00:00 2001 From: Yecine Megdiche Date: Thu, 3 Feb 2022 15:37:22 +0100 Subject: [PATCH] XMonad.Prelude: add the `WindowScreen` type `WindowScreen` is a type synonym for the specialized `Screen` type, that results from the `WindowSet` definition in XMonad.Core. Having this type defined and exported in a central module saves extension developers from trying to reconstruct it, whenever the general `Screen i l a sid sd` is not suitable. Note: this should be moved to `XMonad.Core` in the next core release. --- CHANGES.md | 3 +++ XMonad/Actions/EasyMotion.hs | 2 +- XMonad/Actions/Navigation2D.hs | 2 +- XMonad/Layout/IndependentScreens.hs | 2 +- XMonad/Prelude.hs | 6 ++++++ XMonad/Util/Loggers.hs | 7 ++----- XMonad/Util/PureX.hs | 6 ++---- 7 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c2fa1c67..95f8ac25 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -121,6 +121,9 @@ - Added `keymaskToString` and `keyToString` to show a key mask and a key in the style of `XMonad.Util.EZConfig`. + - Added `WindowScreen`, which is a type synonym for the specialized `Screen` + type, that results from the `WindowSet` definition in `XMonad.Core`. + * `XMonad.Util.XUtils` - Added `withSimpleWindow`, `showSimpleWindow`, `WindowConfig`, and diff --git a/XMonad/Actions/EasyMotion.hs b/XMonad/Actions/EasyMotion.hs index 758e4226..8f449f6c 100644 --- a/XMonad/Actions/EasyMotion.hs +++ b/XMonad/Actions/EasyMotion.hs @@ -271,7 +271,7 @@ handleSelectWindow c = do $ M.elems $ M.mapWithKey (\sid ks -> buildOverlays ks <$> sortedOverlayWindows sid) m where - screenById :: ScreenId -> Maybe (W.Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail) + screenById :: ScreenId -> Maybe WindowScreen screenById sid = find ((== sid) . W.screen) (W.screens ws) visibleWindowsOnScreen :: ScreenId -> [Window] visibleWindowsOnScreen sid = filter (`elem` toList mappedWins) $ W.integrate' $ screenById sid >>= W.stack . W.workspace diff --git a/XMonad/Actions/Navigation2D.hs b/XMonad/Actions/Navigation2D.hs index 1af0bf22..a5b8a248 100644 --- a/XMonad/Actions/Navigation2D.hs +++ b/XMonad/Actions/Navigation2D.hs @@ -388,7 +388,7 @@ data Navigation2DConfig = Navigation2DConfig } -- | Shorthand for the tedious screen type -type Screen = W.Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail +type Screen = WindowScreen -- | Convenience function for enabling Navigation2D with typical keybindings. -- Takes a Navigation2DConfig, an (up, left, down, right) tuple, a mapping from diff --git a/XMonad/Layout/IndependentScreens.hs b/XMonad/Layout/IndependentScreens.hs index e00468ab..5bf89491 100644 --- a/XMonad/Layout/IndependentScreens.hs +++ b/XMonad/Layout/IndependentScreens.hs @@ -148,7 +148,7 @@ withWspOnScreen screenId operation ws = case workspaceOnScreen screenId ws of Nothing -> ws -- | Get the workspace that is active on a given screen. -screenOnMonitor :: ScreenId -> WindowSet -> Maybe (W.Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail) +screenOnMonitor :: ScreenId -> WindowSet -> Maybe WindowScreen screenOnMonitor screenId ws = find ((screenId ==) . W.screen) (W.current ws : W.visible ws) -- | Focus a window, switching workspace on the correct Xinerama screen if neccessary. diff --git a/XMonad/Prelude.hs b/XMonad/Prelude.hs index 18805fa2..fa20ede4 100644 --- a/XMonad/Prelude.hs +++ b/XMonad/Prelude.hs @@ -32,6 +32,7 @@ module XMonad.Prelude ( specialKeys, multimediaKeys, functionKeys, + WindowScreen, ) where import Foreign (alloca, peek) @@ -57,6 +58,7 @@ import Data.Bits import Data.List.NonEmpty (NonEmpty ((:|))) import Data.Tuple (swap) import GHC.Stack +import qualified XMonad.StackSet as W -- | Short for 'fromIntegral'. fi :: (Integral a, Num b) => a -> b @@ -415,3 +417,7 @@ multimediaKeys = filter ((/= noSymbol) . snd) . map (id &&& stringToKeysym) $ , "XF86_Prev_VMode" , "XF86Bluetooth" ] + +-- | The specialized 'W.Screen' derived from 'WindowSet'. +type WindowScreen -- FIXME move to core + = W.Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail diff --git a/XMonad/Util/Loggers.hs b/XMonad/Util/Loggers.hs index 65d172ca..ef960627 100644 --- a/XMonad/Util/Loggers.hs +++ b/XMonad/Util/Loggers.hs @@ -48,7 +48,7 @@ module XMonad.Util.Loggers ( ) where -import XMonad (liftIO, Window, gets) +import XMonad (liftIO, gets) import XMonad.Core import qualified XMonad.StackSet as W import XMonad.Hooks.StatusBar.PP @@ -56,7 +56,7 @@ import XMonad.Util.Font (Align (..)) import XMonad.Util.NamedWindows (getName) import Control.Exception as E -import XMonad.Prelude (find, fromMaybe, isPrefixOf, isSuffixOf) +import XMonad.Prelude (find, fromMaybe, isPrefixOf, isSuffixOf, WindowScreen) import Data.Time (defaultTimeLocale, formatTime, getCurrentTime) import System.Directory (getDirectoryContents) import System.IO (hGetLine) @@ -272,9 +272,6 @@ logLayoutOnScreen :: ScreenId -> Logger logLayoutOnScreen = withScreen $ logConst . description . W.layout . W.workspace --- | A shortcut to a screen -type WindowScreen = W.Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail - -- | A helper function to create screen-specific loggers. withScreen :: (WindowScreen -> Logger) -> ScreenId -> Logger withScreen f n = do diff --git a/XMonad/Util/PureX.hs b/XMonad/Util/PureX.hs index 9d4e7283..e0bdf133 100644 --- a/XMonad/Util/PureX.hs +++ b/XMonad/Util/PureX.hs @@ -53,7 +53,7 @@ module XMonad.Util.PureX ( -- xmonad import XMonad -import XMonad.Prelude (Any (..), liftA2) +import XMonad.Prelude (Any (..), liftA2, WindowScreen) import qualified XMonad.StackSet as W import qualified XMonad.Actions.FocusNth @@ -220,9 +220,7 @@ peek :: XLike m => m (Maybe Window) peek = withWindowSet' (return . W.peek) -- | Get the current screen. -curScreen - :: XLike m - => m (W.Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail) +curScreen :: XLike m => m WindowScreen curScreen = withWindowSet' (return . W.current) -- | Get the current workspace.