From 0b8f79a968ddd6fc421c73fb026635ca1474d5e0 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Thu, 29 Dec 2022 14:49:06 -0500 Subject: [PATCH] ENH use xmonad functions for spawning processes --- lib/XMonad/Internal/Command/DMenu.hs | 8 ++++---- lib/XMonad/Internal/Command/Desktop.hs | 9 ++++----- lib/XMonad/Internal/Notify.hs | 6 ++---- lib/XMonad/Internal/Shell.hs | 27 ++++++++++---------------- 4 files changed, 20 insertions(+), 30 deletions(-) diff --git a/lib/XMonad/Internal/Command/DMenu.hs b/lib/XMonad/Internal/Command/DMenu.hs index 1cec3a2..2d6de6a 100644 --- a/lib/XMonad/Internal/Command/DMenu.hs +++ b/lib/XMonad/Internal/Command/DMenu.hs @@ -17,7 +17,6 @@ module XMonad.Internal.Command.DMenu , runAutorandrMenu ) where -import qualified Data.ByteString.Char8 as BC import Data.Internal.DBus import Data.Internal.Dependency @@ -25,13 +24,13 @@ import DBus import Graphics.X11.Types -import qualified RIO.ByteString.Lazy as B import qualified RIO.Text as T import System.Directory ( XdgDirectory (..) , getXdgDirectory ) +import System.IO import XMonad.Core hiding (spawn) import XMonad.Internal.Command.Desktop @@ -201,8 +200,9 @@ showKeysDMenu = Subfeature } showKeys :: [((KeyMask, KeySym), NamedAction)] -> X () -showKeys kbs = io $ spawnStdin i cmd +showKeys kbs = do + h <- spawnPipe cmd + io $ hPutStr h $ unlines $ showKm kbs where - i = B.fromStrict $ BC.pack $ unlines $ showKm kbs cmd = fmtCmd myDmenuCmd $ ["-dmenu", "-p", "commands"] ++ themeArgs "#7f66ff" ++ myDmenuMatchingArgs diff --git a/lib/XMonad/Internal/Command/Desktop.hs b/lib/XMonad/Internal/Command/Desktop.hs index 8d3befc..6a4d00c 100644 --- a/lib/XMonad/Internal/Command/Desktop.hs +++ b/lib/XMonad/Internal/Command/Desktop.hs @@ -41,8 +41,6 @@ module XMonad.Internal.Command.Desktop , networkManagerPkgs ) where -import Control.Monad.IO.Class - import Data.Internal.DBus import Data.Internal.Dependency @@ -58,7 +56,7 @@ import System.Environment import System.Posix.User import XMonad.Actions.Volume -import XMonad.Core as XC +import XMonad.Core hiding (spawn) import XMonad.Internal.DBus.Common import XMonad.Internal.Notify import XMonad.Internal.Shell as S @@ -296,8 +294,9 @@ runRecompile :: X () runRecompile = do -- assume that the conf directory contains a valid stack project confDir <- asks (cfgDir . directories) - spawnAt confDir - $ fmtCmd "stack" ["install"] + spawn + $ fmtCmd "cd" [T.pack confDir] + #!&& fmtCmd "stack" ["install"] #!&& fmtNotifyCmd defNoteInfo { body = Just $ Text "compilation succeeded" } #!|| fmtNotifyCmd defNoteError { body = Just $ Text "compilation failed" } diff --git a/lib/XMonad/Internal/Notify.hs b/lib/XMonad/Internal/Notify.hs index 91c1c61..f4063f2 100644 --- a/lib/XMonad/Internal/Notify.hs +++ b/lib/XMonad/Internal/Notify.hs @@ -18,12 +18,10 @@ module XMonad.Internal.Notify , spawnNotify ) where -import Control.Monad.IO.Class -import Data.Maybe - import DBus.Notify -import qualified RIO.Text as T +import RIO +import qualified RIO.Text as T import XMonad.Internal.Shell diff --git a/lib/XMonad/Internal/Shell.hs b/lib/XMonad/Internal/Shell.hs index 7d06aa7..73f2546 100644 --- a/lib/XMonad/Internal/Shell.hs +++ b/lib/XMonad/Internal/Shell.hs @@ -57,8 +57,7 @@ module XMonad.Internal.Shell ( fmtCmd , spawnCmd , spawn - , spawnAt - , spawnStdin + , spawnPipe , doubleQuote , singleQuote , skip @@ -71,15 +70,13 @@ module XMonad.Internal.Shell , (#!>>) ) where -import Control.Monad.IO.Class - import RIO -import qualified RIO.ByteString.Lazy as B -import qualified RIO.Text as T +import qualified RIO.Text as T -import qualified System.Process.Typed as P +import qualified System.Process.Typed as P -import qualified XMonad.Core as X +import qualified XMonad.Core as X +import qualified XMonad.Util.Run as XR -------------------------------------------------------------------------------- -- | Opening subshell @@ -95,9 +92,6 @@ addGroupSession = P.setCreateGroup True . P.setNewSession True runProcess :: P.ProcessConfig a b c -> IO ExitCode runProcess = withDefaultSignalHandlers . P.runProcess -startProcess :: P.ProcessConfig a b c -> IO (P.Process a b c) -startProcess = withDefaultSignalHandlers . P.startProcess - shell :: T.Text -> P.ProcessConfig () () () shell = addGroupSession . P.shell . T.unpack @@ -105,14 +99,13 @@ proc :: FilePath -> [T.Text] -> P.ProcessConfig () () () proc cmd args = addGroupSession $ P.proc cmd (T.unpack <$> args) spawn :: MonadIO m => T.Text -> m () -spawn = liftIO . void . startProcess . shell +spawn = X.spawn . T.unpack -spawnAt :: MonadIO m => FilePath -> T.Text -> m () -spawnAt fp = liftIO . void . startProcess . P.setWorkingDir fp . shell +-- spawnAt :: MonadIO m => FilePath -> T.Text -> m () +-- spawnAt fp = liftIO . void . startProcess . P.setWorkingDir fp . shell -spawnStdin :: MonadIO m => B.ByteString -> T.Text -> m () -spawnStdin i = - liftIO . void . startProcess . P.setStdin (P.byteStringInput i) . shell +spawnPipe :: MonadIO m => T.Text -> m Handle +spawnPipe = XR.spawnPipe . T.unpack spawnCmd :: MonadIO m => FilePath -> [T.Text] -> m () spawnCmd cmd = spawn . fmtCmd cmd