Fall back to WM_NAME if _NET_WM_NAME does not exist.

This commit is contained in:
Felix Geyer 2012-07-23 17:50:54 +02:00
parent ad0d120ae6
commit 4f0600421c
2 changed files with 47 additions and 19 deletions

View File

@ -28,7 +28,9 @@ AutoTypePlatformX11::AutoTypePlatformX11()
m_rootWindow = QX11Info::appRootWindow(); m_rootWindow = QX11Info::appRootWindow();
m_atomWmState = XInternAtom(m_dpy, "WM_STATE", true); m_atomWmState = XInternAtom(m_dpy, "WM_STATE", true);
m_atomWmName = XInternAtom(m_dpy, "_NET_WM_NAME", true); m_atomWmName = XInternAtom(m_dpy, "WM_NAME", true);
m_atomNetWmName = XInternAtom(m_dpy, "_NET_WM_NAME", true);
m_atomString = XInternAtom(m_dpy, "STRING", true);
m_atomUtf8String = XInternAtom(m_dpy, "UTF8_STRING", true); m_atomUtf8String = XInternAtom(m_dpy, "UTF8_STRING", true);
m_classBlacklist << "desktop_window" << "gnome-panel"; // Gnome m_classBlacklist << "desktop_window" << "gnome-panel"; // Gnome
@ -180,19 +182,44 @@ QString AutoTypePlatformX11::windowTitle(Window window, bool useBlacklist)
unsigned long after; unsigned long after;
unsigned char* data = Q_NULLPTR; unsigned char* data = Q_NULLPTR;
int retVal = XGetWindowProperty(m_dpy, window, m_atomWmName, 0, 1000, false, m_atomUtf8String, int retVal = XGetWindowProperty(m_dpy, window, m_atomNetWmName, 0, 1000, false, m_atomUtf8String,
&type, &format, &nitems, &after, &data); &type, &format, &nitems, &after, &data);
if (retVal != 0) { if (retVal != 0 && data) {
title = QString::fromUtf8(reinterpret_cast<char*>(data));
}
else {
XTextProperty textProp;
retVal = XGetTextProperty(m_dpy, window, &textProp, m_atomWmName);
if (retVal != 0 && textProp.value) {
char** textList = Q_NULLPTR;
int count;
if (textProp.encoding == m_atomUtf8String) {
title = QString::fromUtf8(reinterpret_cast<char*>(textProp.value));
}
else if (XmbTextPropertyToTextList(m_dpy, &textProp, &textList, &count) == 0 && textList && count > 0) {
title = QString::fromLocal8Bit(textList[0]);
}
else if (textProp.encoding == m_atomString) {
title = QString::fromLocal8Bit(reinterpret_cast<char*>(textProp.value));
}
if (textList) {
XFreeStringList(textList);
}
}
if (textProp.value) {
XFree(textProp.value);
}
}
if (data) { if (data) {
XFree(data); XFree(data);
} }
}
else if (data) {
title = QString::fromUtf8(reinterpret_cast<char*>(data));
XFree(data);
if (useBlacklist) { if (useBlacklist && !title.isEmpty()) {
if (window == m_rootWindow) { if (window == m_rootWindow) {
return QString(); return QString();
} }
@ -207,7 +234,6 @@ QString AutoTypePlatformX11::windowTitle(Window window, bool useBlacklist)
return QString(); return QString();
} }
} }
}
return title; return title;
} }

View File

@ -77,6 +77,8 @@ private:
Window m_rootWindow; Window m_rootWindow;
Atom m_atomWmState; Atom m_atomWmState;
Atom m_atomWmName; Atom m_atomWmName;
Atom m_atomNetWmName;
Atom m_atomString;
Atom m_atomUtf8String; Atom m_atomUtf8String;
QSet<QString> m_classBlacklist; QSet<QString> m_classBlacklist;
Qt::Key m_currentGlobalKey; Qt::Key m_currentGlobalKey;