Skip to content

Commit

Permalink
Assume locale is utf8 for spawn.
Browse files Browse the repository at this point in the history
This adds the utf8-string dependency so that users no longer need to encode
strings they (possibly indirectly) pass to spawn. This is the expected
behavior, since each Char in String should be an actual character.

For systems that do not use utf8 this does not help. Fixing this by using iconv
or similar libraries may be done later.
  • Loading branch information
aavogt committed Nov 18, 2011
1 parent 75889ab commit 4be3b39
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion XMonad/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module XMonad.Core (
import XMonad.StackSet hiding (modify)

import Prelude hiding ( catch )
import Codec.Binary.UTF8.String (encodeString)
import Control.Exception.Extensible (catch, fromException, try, bracket, throw, finally, SomeException(..))
import Control.Applicative
import Control.Monad.State
Expand Down Expand Up @@ -384,12 +385,14 @@ catchIO f = io (f `catch` \(SomeException e) -> hPrint stderr e >> hFlush stderr

-- | spawn. Launch an external application. Specifically, it double-forks and
-- runs the 'String' you pass as a command to \/bin\/sh.
--
-- Note this function assumes your locale uses utf8.
spawn :: MonadIO m => String -> m ()
spawn x = spawnPID x >> return ()

-- | Like 'spawn', but returns the 'ProcessID' of the launched application
spawnPID :: MonadIO m => String -> m ProcessID
spawnPID x = xfork $ executeFile "/bin/sh" False ["-c", x] Nothing
spawnPID x = xfork $ executeFile "/bin/sh" False ["-c", encodeString x] Nothing

-- | A replacement for 'forkProcess' which resets default signal handlers.
xfork :: MonadIO m => IO () -> m ProcessID
Expand Down
3 changes: 2 additions & 1 deletion xmonad.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ library
build-depends: base < 5 && >=3, containers, directory, process, filepath, extensible-exceptions
else
build-depends: base < 3
build-depends: X11>=1.5.0.0 && < 1.6, mtl, unix
build-depends: X11>=1.5.0.0 && < 1.6, mtl, unix,
utf8-string >= 0.3 && < 0.4

if true
ghc-options: -funbox-strict-fields -Wall
Expand Down

0 comments on commit 4be3b39

Please sign in to comment.