Ignore BadWindow errors caused by faulty __NET_ACTIVE_WINDOW events
This commit is contained in:
@ -124,6 +124,7 @@ void XInstance::flush()
|
|||||||
|
|
||||||
pid_t XInstance::getPid(Window wid)
|
pid_t XInstance::getPid(Window wid)
|
||||||
{
|
{
|
||||||
|
defaultHandler = XSetErrorHandler(ignoreErrorHandler);
|
||||||
XTextProperty xWidHostNameTextProperty;
|
XTextProperty xWidHostNameTextProperty;
|
||||||
bool ret;
|
bool ret;
|
||||||
ret = XGetTextProperty(display, wid, &xWidHostNameTextProperty, atoms.wmClientMachine);
|
ret = XGetTextProperty(display, wid, &xWidHostNameTextProperty, atoms.wmClientMachine);
|
||||||
@ -132,7 +133,11 @@ pid_t XInstance::getPid(Window wid)
|
|||||||
char errorString[1024];
|
char errorString[1024];
|
||||||
XGetErrorText(display, ret, errorString, 1024);
|
XGetErrorText(display, ret, errorString, 1024);
|
||||||
debug("XGetWMClientMachine failed! " + std::string(errorString));
|
debug("XGetWMClientMachine failed! " + std::string(errorString));
|
||||||
if(!ignoreClientMachine) return -1;
|
if(!ignoreClientMachine)
|
||||||
|
{
|
||||||
|
XSetErrorHandler(defaultHandler);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
char** xWidHostNameStringList = nullptr;
|
char** xWidHostNameStringList = nullptr;
|
||||||
int nStrings;
|
int nStrings;
|
||||||
@ -142,13 +147,21 @@ pid_t XInstance::getPid(Window wid)
|
|||||||
char errorString[1024];
|
char errorString[1024];
|
||||||
XGetErrorText(display, ret, errorString, 1024);
|
XGetErrorText(display, ret, errorString, 1024);
|
||||||
debug("XTextPropertyToStringList failed! " + std::string(errorString));
|
debug("XTextPropertyToStringList failed! " + std::string(errorString));
|
||||||
if(!ignoreClientMachine) return -1;
|
if(!ignoreClientMachine)
|
||||||
|
{
|
||||||
|
XSetErrorHandler(defaultHandler);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
char hostName[HOST_NAME_MAX+1]={0};
|
char hostName[HOST_NAME_MAX+1]={0};
|
||||||
if(gethostname(hostName, HOST_NAME_MAX) != 0)
|
if(gethostname(hostName, HOST_NAME_MAX) != 0)
|
||||||
{
|
{
|
||||||
debug("Can't get host name");
|
debug("Can't get host name");
|
||||||
if(!ignoreClientMachine) return -1;
|
if(!ignoreClientMachine)
|
||||||
|
{
|
||||||
|
XSetErrorHandler(defaultHandler);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pid_t pid = -1;
|
pid_t pid = -1;
|
||||||
if(ignoreClientMachine || strcmp(hostName, xWidHostNameStringList[0]) == 0 )
|
if(ignoreClientMachine || strcmp(hostName, xWidHostNameStringList[0]) == 0 )
|
||||||
@ -165,9 +178,17 @@ pid_t XInstance::getPid(Window wid)
|
|||||||
debug("Window "+std::to_string(wid)+" is a remote window");
|
debug("Window "+std::to_string(wid)+" is a remote window");
|
||||||
}
|
}
|
||||||
if(xWidHostNameStringList) XFreeStringList(xWidHostNameStringList);
|
if(xWidHostNameStringList) XFreeStringList(xWidHostNameStringList);
|
||||||
|
XSetErrorHandler(defaultHandler);
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int XInstance::ignoreErrorHandler(Display* display, XErrorEvent* xerror)
|
||||||
|
{
|
||||||
|
std::cerr<<"Ignoring: error code"<<xerror->error_code<<" request code "<<xerror->request_code<<'\n'
|
||||||
|
<<"this error most likely occured because of a bug in your WM\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
XInstance::~XInstance()
|
XInstance::~XInstance()
|
||||||
{
|
{
|
||||||
if(display) XCloseDisplay(display);
|
if(display) XCloseDisplay(display);
|
||||||
|
@ -34,6 +34,7 @@ class XInstance
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
inline static XErrorHandler defaultHandler;
|
||||||
static constexpr unsigned long MAX_BYTES = 1048576;
|
static constexpr unsigned long MAX_BYTES = 1048576;
|
||||||
|
|
||||||
inline static bool ignoreClientMachine = false;
|
inline static bool ignoreClientMachine = false;
|
||||||
@ -46,6 +47,7 @@ private:
|
|||||||
|
|
||||||
unsigned long readProparty(Window wid, Atom atom, unsigned char** prop, int* format);
|
unsigned long readProparty(Window wid, Atom atom, unsigned char** prop, int* format);
|
||||||
Atom getAtom(const std::string& atomName);
|
Atom getAtom(const std::string& atomName);
|
||||||
|
static int ignoreErrorHandler(Display* display, XErrorEvent* xerror);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user