getNameWMClass :: Window -> X NamedWindow
getNameWMClass w =
  withDisplay $ \d
    -- TODO, this code is ugly and convoluted -- clean it up
   -> do
    let getIt = bracket getProp (xFree . tp_value) (fmap (`NW` w) . copy)
        getProp = getTextProperty d w wM_CLASS
        copy prop =
          fromMaybe "" . listToMaybe <$> wcTextPropertyToTextList d prop
    io $
      getIt `E.catch` \(SomeException _) ->
        (`NW` w) . resName <$> getClassHint d w
getNameWMClass :: Window -> X NamedWindow
getNameWMClass w =
  withDisplay $ \d
    -- TODO, this code is ugly and convoluted -- clean it up
   -> do
    let getIt = bracket getProp (xFree . tp_value) (fmap (`NW` w) . copy)
        getProp = getTextProperty d w wM_CLASS
        copy prop =
          fromMaybe "" . listToMaybe <$> wcTextPropertyToTextList d prop
    io $
      getIt `E.catch` \(SomeException _) ->
        (`NW` w) . resName <$> getClassHint d w
getNameWMClass w =
  withDisplay $ \d
    -- TODO, this code is ugly and convoluted -- clean it up
   -> do
    let getIt = bracket getProp (xFree . tp_value) (fmap (`NW` w) . copy)
        getProp = getTextProperty d w wM_CLASS
        copy prop =
          fromMaybe "" . listToMaybe <$> wcTextPropertyToTextList d prop
    io $
      getIt `E.catch` \(SomeException _) ->
        (`NW` w) . resName <$> getClassHint d w