Furthermore we should prefer _NET_WM_NAME property instead of WM_NAME property to support window title in UTF-8 encoded but should still look for WM_NAME for fallback. So the final code is like following: