swallow improvements

This commit is contained in:
Vaxry 2022-10-07 09:46:01 +01:00
parent 28a6e0ce31
commit fd379db846

View file

@ -397,67 +397,59 @@ void Events::listener_mapWindow(void* owner, void* data) {
// verify swallowing // verify swallowing
if (*PSWALLOW) { if (*PSWALLOW) {
// check parent // don't swallow ourselves
int ppid = getPPIDof(PWINDOW->getPID()); std::regex rgx(*PSWALLOWREGEX);
if (!std::regex_match(g_pXWaylandManager->getAppIDClass(PWINDOW), rgx)) {
// check parent
int ppid = getPPIDof(PWINDOW->getPID());
const auto PPPID = getPPIDof(ppid); int curppid = 0;
// why? no clue. Blame terminals. for (int i = 0; i < 5; ++i) {
if (PPPID > 2) { curppid = getPPIDof(ppid);
ppid = PPPID;
}
if (ppid) { if (curppid < 10) {
// get window by pid break;
std::vector<CWindow*> found;
CWindow* finalFound = nullptr;
for (auto& w : g_pCompositor->m_vWindows) {
if (!w->m_bIsMapped || w->m_bHidden)
continue;
if (w->getPID() == ppid) {
found.push_back(w.get());
} }
ppid = curppid;
} }
if (found.size() > 1) { if (ppid) {
for (auto& w : found) { // get window by pid
// try get the focus std::vector<CWindow*> found;
if (w == PFOCUSEDWINDOWPREV) { CWindow* finalFound = nullptr;
finalFound = w; for (auto& w : g_pCompositor->m_vWindows) {
break; if (!w->m_bIsMapped || w->m_bHidden)
continue;
if (w->getPID() == ppid) {
found.push_back(w.get());
} }
} }
if (!finalFound) { if (found.size() > 1) {
// just get the closest (ws)
for (auto& w : found) { for (auto& w : found) {
if (w->m_iWorkspaceID == g_pCompositor->m_pLastMonitor->activeWorkspace) { // try get the focus, otherwise we'll ignore to avoid swallowing incorrect windows
if (w == PFOCUSEDWINDOWPREV) {
finalFound = w; finalFound = w;
break; break;
} }
} }
} } else if (found.size() == 1) {
if (!finalFound) {
// what, just use 0
finalFound = found[0]; finalFound = found[0];
} }
} else if (found.size() == 1) { if (finalFound) {
finalFound = found[0]; // check if it's the window we want
} if (std::regex_match(g_pXWaylandManager->getAppIDClass(finalFound), rgx)) {
// swallow
PWINDOW->m_pSwallowed = finalFound;
if (finalFound) { g_pLayoutManager->getCurrentLayout()->onWindowRemoved(finalFound);
// check if it's the window we want
std::regex rgx(*PSWALLOWREGEX);
if (std::regex_match(g_pXWaylandManager->getAppIDClass(finalFound), rgx)) {
// swallow
PWINDOW->m_pSwallowed = finalFound;
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(finalFound); finalFound->m_bHidden = true;
}
finalFound->m_bHidden = true;
} }
} }
} }