From cfbc283c3a9f3c3b9db6f1d2a75e9c875e630f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Tue, 19 Jul 2022 20:31:26 +0200 Subject: [PATCH] implement dynamic changing of working directory --- src/XMonad/Custom/TopicSpace.hs | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/XMonad/Custom/TopicSpace.hs b/src/XMonad/Custom/TopicSpace.hs index 345d336..3cd1b60 100644 --- a/src/XMonad/Custom/TopicSpace.hs +++ b/src/XMonad/Custom/TopicSpace.hs @@ -6,6 +6,8 @@ module XMonad.Custom.TopicSpace ( , currentTopicConfig , goto , spawnInTopicDir + , setTopicDir + , promptSetTopicDir ) where @@ -43,12 +45,14 @@ module XMonad.Custom.TopicSpace ( -- -- --- import qualified Data.Map.Strict as M +import Data.Map import qualified XMonad.Util.ExtensibleState as XS --- import qualified XMonad.StackSet as W +import qualified XMonad.StackSet as W import XMonad import XMonad.Actions.TopicSpace +import XMonad.Prompt +import XMonad.Prompt.Workspace -- | An alias for topicNames. @@ -84,15 +88,19 @@ instance ExtensionClass StoreTopicConfig where topicConfig :: StoreTopicConfig -> TopicConfig topicConfig (StoreTopicConfig tc) = tc --- | Put initial topic Config into X state at startup --- Add this to the XConfig startupHook -topicStartupHook :: TopicConfig -> X () -topicStartupHook = XS.put . StoreTopicConfig +-- | Update the value of the topic config in the X state +updateTopicConfig :: TopicConfig -> X () +updateTopicConfig = XS.put . StoreTopicConfig -- | Retrieve the current topic config from the X state currentTopicConfig :: X TopicConfig currentTopicConfig = fmap topicConfig XS.get +-- | Put initial topic Config into X state at startup +-- Add this to the XConfig startupHook +topicStartupHook :: TopicConfig -> X () +topicStartupHook = updateTopicConfig + ------------------------------------------- -- | These are the real utilities that we aimed for @@ -112,3 +120,16 @@ spawnInTopicDir cmd = do tc <- currentTopicConfig dir <- currentTopicDir tc spawn $ "cd " ++ dir ++ "; " ++ cmd + +-- | Set the working directory of the current topic +setTopicDir :: Dir -> X () +setTopicDir dir = do + ws <- gets (W.currentTag . windowset) + tc <- currentTopicConfig + updateTopicConfig tc { + topicDirs = insert ws dir $ topicDirs tc + } + +-- | Prompt for the new working directory +promptSetTopicDir :: XPConfig -> X () +promptSetTopicDir xpc = workspacePrompt xpc setTopicDir