[xmonad] why spawn (and safeSpawn, etc) use encodeString?

Platon Pronko platon7pronko at gmail.com
Fri Apr 17 19:08:02 UTC 2020


Hi!

I noticed that spawn mangled my unicode characters - instead of my unicode character the called program recieved garbage. Looking deeper I found out that spawn pre-processes the string with `encodeString` function.

`encodeString` first converts [Char] into [Word8], and then converts each individual Word8 back into Char. Since unicode Char will be converted into multiple Word8, the resulting string would be quite different.

Example:

Prelude> import Codec.Binary.UTF8.String
Prelude Codec.Binary.UTF8.String> encodeString "Ø"
"\195\152"
Prelude Codec.Binary.UTF8.String> putStrLn "Ø"
Ø
Prelude Codec.Binary.UTF8.String> putStrLn $ encodeString "Ø"
ÃPrelude Codec.Binary.UTF8.String>


Is there a reason why xmonad uses `encodeString` here?

I implemented a copy of the function that doesn't use `encodeString`, seems to work okay:

safeSpawnUnicode :: MonadIO m => FilePath -> [String] -> m ()
safeSpawnUnicode prog args = io $ void $ forkProcess $ do
   uninstallSignalHandlers
   _ <- createSession
   executeFile prog True args Nothing

Best regards,
Platon Pronko


More information about the xmonad mailing list