Merge pull request #423 from dminuoso/fix-toenum-crash

Check for text encoding correctly and avoid bottom (#422)
This commit is contained in:
Tomáš Janoušek 2020-12-11 01:53:41 +00:00 committed by GitHub
commit 5db2589abf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -299,6 +299,9 @@
- Add the -dock argument to the dzen spawn arguments - Add the -dock argument to the dzen spawn arguments
* `XMonad.Util.DebugWindow`
Fixed a bottom in `debugWindow` when used on windows with UTF8 encoded titles.
## 0.16 ## 0.16
### Breaking Changes ### Breaking Changes

View File

@ -120,13 +120,13 @@ getDecodedStringProp w a = do
tryUTF8 :: TextProperty -> X [String] tryUTF8 :: TextProperty -> X [String]
tryUTF8 (TextProperty s enc _ _) = do tryUTF8 (TextProperty s enc _ _) = do
uTF8_STRING <- getAtom "UTF8_STRING" uTF8_STRING <- getAtom "UTF8_STRING"
when (enc == uTF8_STRING) $ error "String is not UTF8_STRING" when (enc /= uTF8_STRING) $ error "String is not UTF8_STRING"
(map decodeString . splitNul) <$> io (peekCString s) (map decodeString . splitNul) <$> io (peekCString s)
tryCompound :: TextProperty -> X [String] tryCompound :: TextProperty -> X [String]
tryCompound t@(TextProperty _ enc _ _) = do tryCompound t@(TextProperty _ enc _ _) = do
cOMPOUND_TEXT <- getAtom "COMPOUND_TEXT" cOMPOUND_TEXT <- getAtom "COMPOUND_TEXT"
when (enc == cOMPOUND_TEXT) $ error "String is not COMPOUND_TEXT" when (enc /= cOMPOUND_TEXT) $ error "String is not COMPOUND_TEXT"
withDisplay $ \d -> io $ wcTextPropertyToTextList d t withDisplay $ \d -> io $ wcTextPropertyToTextList d t
splitNul :: String -> [String] splitNul :: String -> [String]