Avoid getting stuck when swtiching from one window to another with the same PID

This commit is contained in:
2020-06-04 18:54:03 +02:00
parent c1a3b0af34
commit 3c7d0f49de

View File

@ -94,7 +94,7 @@ public:
atoms.wmClientMachine = getAtom("WM_CLIENT_MACHINE"); atoms.wmClientMachine = getAtom("WM_CLIENT_MACHINE");
if(atoms.netActiveWindow == 0) if(atoms.netActiveWindow == 0)
{ {
std::cerr<<"WM_CLIENT_MACHINE is required\n"; std::cerr<<" is required\n";
return false; return false;
} }
@ -177,6 +177,10 @@ public:
{ {
return pid == in.pid; return pid == in.pid;
} }
bool operator!=(const Process& in)
{
return pid != in.pid;
}
Process(){} Process(){}
Process(pid_t pidIn) Process(pid_t pidIn)
{ {
@ -266,17 +270,20 @@ int main(int argc, char* argv[])
pid_t windowPid = xinstance.getPid(wid); pid_t windowPid = xinstance.getPid(wid);
Process process(windowPid); Process process(windowPid);
for(size_t i = 0; i < applicationNames.size(); ++i) if(process != prevProcess)
{ {
if(process.name == applicationNames[i] && process.name != "" && wid != 0) for(size_t i = 0; i < applicationNames.size(); ++i)
{ {
kill(process.pid, SIGCONT); if(process.name == applicationNames[i] && process.name != "" && wid != 0)
std::cout<<"Resumeing: "<<wid<<" pid: "<<process.pid<<" name: "<<process.name<<'\n'; {
} kill(process.pid, SIGCONT);
else if(prevProcess.name == applicationNames[i] && prevWindow != 0 && process.name != "" && wid != 0) std::cout<<"Resumeing: "<<wid<<" pid: "<<process.pid<<" name: "<<process.name<<'\n';
{ }
kill(prevProcess.pid, SIGSTOP); else if(prevProcess.name == applicationNames[i] && prevWindow != 0 && prevProcess.name != "")
std::cout<<"Stoping: "<<prevWindow<<" pid: "<<prevProcess.pid<<" name: "<<prevProcess.name<<'\n'; {
kill(prevProcess.pid, SIGSTOP);
std::cout<<"Stoping: "<<prevWindow<<" pid: "<<prevProcess.pid<<" name: "<<prevProcess.name<<'\n';
}
} }
} }
prevProcess = process; prevProcess = process;