From 27dac9cb0fad229c88144b432a957f1cbd067b98 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Sun, 20 Nov 2022 15:09:10 -0700 Subject: Change term "Theater" -> "Desktop" --- src/Rahm/Desktop/Desktop.hs | 60 +++++++++++++++++++++++++++++++++++++++++++++ src/Rahm/Desktop/Keys.hs | 6 ++--- src/Rahm/Desktop/Theater.hs | 60 --------------------------------------------- 3 files changed, 63 insertions(+), 63 deletions(-) create mode 100644 src/Rahm/Desktop/Desktop.hs delete mode 100644 src/Rahm/Desktop/Theater.hs (limited to 'src') diff --git a/src/Rahm/Desktop/Desktop.hs b/src/Rahm/Desktop/Desktop.hs new file mode 100644 index 0000000..053b330 --- /dev/null +++ b/src/Rahm/Desktop/Desktop.hs @@ -0,0 +1,60 @@ +module Rahm.Desktop.Desktop where + +-- A "Desktop" is a mapping from screen -> workspace. This is used to save the +-- state of the current screen -> workspace and thus restore it. + +-- import XMonad.Operations +import Data.Maybe (fromMaybe) +import Control.Monad (forM_) +import XMonad (X(..)) +import qualified XMonad.StackSet as W +import qualified XMonad as X +import Data.Map (Map) +import qualified Data.Map as Map +import Data.Default +import qualified XMonad.Util.ExtensibleState as XS + +newtype Desktop si wi = Desktop (Map si wi) + deriving (Read, Show) + +newtype Desktops = Desktops { + theaters :: Map String (Desktop X.ScreenId X.WorkspaceId) +} deriving (Read, Show) + +instance Default Desktops where + def = Desktops mempty + +instance X.ExtensionClass Desktops where + initialValue = def + extensionType = X.PersistentExtension + +saveCurrentDesktop :: String -> X () +saveCurrentDesktop name = + X.withWindowSet $ \windowSet -> + XS.modify $ \(Desktops m) -> + Desktops $ flip (Map.insert name) m $ + Desktop $ Map.fromList $ + map (\(W.Screen ws sid _) -> (sid, W.tag ws)) $ W.screens windowSet + +restoreDesktop :: String -> X () +restoreDesktop name = do + (Desktops theaters) <- XS.get + forM_ (Map.lookup name theaters) $ \(Desktop screenToWorkspace) -> + X.windows $ \ws@(W.StackSet cur vis hidden float) -> + let workspacesById = Map.fromList $ map (\ws -> (W.tag ws, ws)) (W.workspaces ws) + + newScreenWorkspace scr = + fromMaybe scr $ do + wid <- Map.lookup (W.screen scr) screenToWorkspace + workspace <- Map.lookup wid workspacesById + return $ scr { W.workspace = workspace } + + newScreens = map newScreenWorkspace (cur : vis) + newVisibleWorkspaces = map (W.tag . W.workspace) newScreens + newHiddenWorkspaces = + filter (\ws -> not (W.tag ws `elem` newVisibleWorkspaces)) $ + W.workspaces ws + + (newCur:newVisible) = newScreens + in + W.StackSet newCur newVisible newHiddenWorkspaces float diff --git a/src/Rahm/Desktop/Keys.hs b/src/Rahm/Desktop/Keys.hs index ac80561..edeb77e 100644 --- a/src/Rahm/Desktop/Keys.hs +++ b/src/Rahm/Desktop/Keys.hs @@ -64,7 +64,7 @@ import Rahm.Desktop.Submap import Rahm.Desktop.Swallow import Rahm.Desktop.SwapMaster (swapMaster) import Rahm.Desktop.Workspaces -import Rahm.Desktop.Theater +import Rahm.Desktop.Desktop import qualified Rahm.Desktop.StackSet as W import Rahm.Desktop.History @@ -287,7 +287,7 @@ keymap = runKeys $ do runMaybeT_ $ do mapNextString $ \_ str -> lift $ case str of - [ch] | isAlpha ch -> restoreTheater [ch] + [ch] | isAlpha ch -> restoreDesktop [ch] _ -> return () -- shiftMod $ @@ -427,7 +427,7 @@ keymap = runKeys $ do runMaybeT_ $ do mapNextString $ \_ str -> lift $ case str of - [ch] | isAlpha ch -> saveCurrentTheater str + [ch] | isAlpha ch -> saveCurrentDesktop str _ -> return () bind xK_plus $ do diff --git a/src/Rahm/Desktop/Theater.hs b/src/Rahm/Desktop/Theater.hs deleted file mode 100644 index b0404b7..0000000 --- a/src/Rahm/Desktop/Theater.hs +++ /dev/null @@ -1,60 +0,0 @@ -module Rahm.Desktop.Theater where - --- A "Theater" is a mapping from screen -> workspace. This is used to save the --- state of the current screen -> workspace and thus restore it. - --- import XMonad.Operations -import Data.Maybe (fromMaybe) -import Control.Monad (forM_) -import XMonad (X(..)) -import qualified XMonad.StackSet as W -import qualified XMonad as X -import Data.Map (Map) -import qualified Data.Map as Map -import Data.Default -import qualified XMonad.Util.ExtensibleState as XS - -newtype Theater si wi = Theater (Map si wi) - deriving (Read, Show) - -newtype Theaters = Theaters { - theaters :: Map String (Theater X.ScreenId X.WorkspaceId) -} deriving (Read, Show) - -instance Default Theaters where - def = Theaters mempty - -instance X.ExtensionClass Theaters where - initialValue = def - extensionType = X.PersistentExtension - -saveCurrentTheater :: String -> X () -saveCurrentTheater name = - X.withWindowSet $ \windowSet -> - XS.modify $ \(Theaters m) -> - Theaters $ flip (Map.insert name) m $ - Theater $ Map.fromList $ - map (\(W.Screen ws sid _) -> (sid, W.tag ws)) $ W.screens windowSet - -restoreTheater :: String -> X () -restoreTheater name = do - (Theaters theaters) <- XS.get - forM_ (Map.lookup name theaters) $ \(Theater screenToWorkspace) -> - X.windows $ \ws@(W.StackSet cur vis hidden float) -> - let workspacesById = Map.fromList $ map (\ws -> (W.tag ws, ws)) (W.workspaces ws) - - newScreenWorkspace scr = - fromMaybe scr $ do - wid <- Map.lookup (W.screen scr) screenToWorkspace - workspace <- Map.lookup wid workspacesById - return $ scr { W.workspace = workspace } - - newScreens = map newScreenWorkspace (cur : vis) - newVisibleWorkspaces = map (W.tag . W.workspace) newScreens - newHiddenWorkspaces = - filter (\ws -> not (W.tag ws `elem` newVisibleWorkspaces)) $ - W.workspaces ws - - (newCur:newVisible) = newScreens - in - W.StackSet newCur newVisible newHiddenWorkspaces float -- cgit