fix EWMH titles

I have no idea what I was thinking when I wrote that code.
While at it, just reused the code for ICCCM title which already
assumes the client may have broken the rules (I think we have
seen a case of `WM_NAME` being `UTF8_STRING`).
This commit is contained in:
brandon s allbery kf8nh 2022-12-12 13:30:42 -05:00
parent 04c0ddd3e0
commit 4998e946cc
No known key found for this signature in database
GPG Key ID: 227EE1942B0BDB95

View File

@ -107,8 +107,7 @@ debugWindow w = do
getEWMHTitle :: String -> Window -> X String getEWMHTitle :: String -> Window -> X String
getEWMHTitle sub w = do getEWMHTitle sub w = do
a <- getAtom $ "_NET_WM_" ++ (if null sub then "" else '_':sub) ++ "_NAME" a <- getAtom $ "_NET_WM_" ++ (if null sub then "" else '_':sub) ++ "_NAME"
(Just t) <- withDisplay $ \d -> io $ getWindowProperty32 d a w getDecodedStringProp w a -- should always be UTF8_STRING but rules are made to be broken
return $ map (toEnum . fromEnum) t
getICCCMTitle :: Window -> X String getICCCMTitle :: Window -> X String
getICCCMTitle w = getDecodedStringProp w wM_NAME getICCCMTitle w = getDecodedStringProp w wM_NAME
@ -116,7 +115,7 @@ getICCCMTitle w = getDecodedStringProp w wM_NAME
getDecodedStringProp :: Window -> Atom -> X String getDecodedStringProp :: Window -> Atom -> X String
getDecodedStringProp w a = do getDecodedStringProp w a = do
t@(TextProperty t' _ 8 _) <- withDisplay $ \d -> io $ getTextProperty d w a t@(TextProperty t' _ 8 _) <- withDisplay $ \d -> io $ getTextProperty d w a
[s] <- catchX' (tryUTF8 t) $ [s] <- catchX' (tryUTF8 t) $ -- shouldn't happen but some apps do it
catchX' (tryCompound t) $ catchX' (tryCompound t) $
io ((:[]) <$> peekCString t') io ((:[]) <$> peekCString t')
return s return s