Skip to content

Commit

Permalink
Improve App Category tree
Browse files Browse the repository at this point in the history
  • Loading branch information
MeisApps committed Oct 10, 2022
1 parent 5c98f5a commit 5494d99
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
38 changes: 37 additions & 1 deletion src/api/process/ProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ std::map<int, ProcessCPUTimes> ProcessManager::m_PidCpuTimes;
std::map<int, ProcessIOUsage> ProcessManager::m_PidIOUsages;

std::vector<std::string> g_AppBlacklist = {"gnome-shell", "plasmashell"}; // NOLINT(cert-err58-cpp)
std::vector<std::string> g_AppParentBlacklist = {"bash", "bwrap"};

inline bool is_in_app_blacklist(ProcessNode *node) {
return Utils::vectorContains(g_AppBlacklist, node->GetName());
Expand Down Expand Up @@ -95,7 +96,7 @@ std::vector<ProcessNode *> ProcessManager::GetProcessesByCategory(int categoryId
windowPids = CGUtils::GetAllPidsWithWindows();

filterFunc = [&](ProcessNode *proc) -> bool { return proc->GetUserIds().uid == getuid() && !is_in_app_blacklist(proc) && Utils::vectorContains(windowPids, proc->GetPid()); };
result = ProcessManager::GetProcessesByFilter(filterFunc, !AppSettings::Get().displayProcList);
result = ProcessManager::GetAppProcessesByFilter(filterFunc, !AppSettings::Get().displayProcList);
break;
}
case PROCESSES_VIEW_CATEGORY_WINE: {
Expand Down Expand Up @@ -154,6 +155,41 @@ std::vector<ProcessNode *> ProcessManager::GetProcessesByFilter(const std::funct
return result;
}

std::vector<ProcessNode *> ProcessManager::GetAppProcessesByFilter(const std::function<bool(ProcessNode *)>& filterFunc, bool withChildren) {
std::vector<ProcessNode *> result;
std::vector<int> pids;

auto procList = GetAllProcesses();
for(auto proc : procList) {
if(filterFunc(proc)) {
auto realProc = proc;
auto minDepth = INT32_MAX;
for(auto child : proc->FlatTree()) {
if(Utils::vectorContains(g_AppParentBlacklist, child->GetName()))
continue;

auto childDepth = child->GetDepth();
if(childDepth < minDepth) {
realProc = child;
minDepth = childDepth;
}
}

for(auto child : realProc->FlatTree()) {
if(Utils::vectorContains(pids, child->GetPid()))
continue;
if(!withChildren && realProc->GetName() != child->GetName())
continue;

result.push_back(child->Copy());
pids.push_back(child->GetPid());
}
}
}

return result;
}

std::vector<ProcessNode *> ProcessManager::GetAllProcesses() {
if(!m_AllProcessesCache.empty())
return m_AllProcessesCache;
Expand Down
1 change: 1 addition & 0 deletions src/api/process/ProcessManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ProcessManager {
private:
static std::vector<ProcessNode *> GetProcessesByCategory(int categoryId);
static std::vector<ProcessNode *> GetProcessesByFilter(const std::function<bool(ProcessNode *)>& filterFunc, bool withChildren = true);
static std::vector<ProcessNode *> GetAppProcessesByFilter(const std::function<bool(ProcessNode *)>& filterFunc, bool withChildren = true);
static std::vector<ProcessNode *> GetAllProcesses();

static double GetCPUUsageForProc(const ProcessInfo& proc, CPUTimes cpuTimes);
Expand Down
8 changes: 3 additions & 5 deletions src/api/process/ProcessNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ std::vector<ProcessNode *> ProcessNode::GetChildren() {
}

int ProcessNode::GetDepth() {
int depth = 0;
for(auto child : m_Children) {
depth += child->GetDepth();
}
if(m_ParentPid == -1 || m_Parent == nullptr)
return 0;

return depth;
return m_Parent->GetDepth() + 1;
}

int ProcessNode::GetPid() const {
Expand Down

0 comments on commit 5494d99

Please sign in to comment.