How to Identify if the process in User Interface Process?

后端 未结 3 1273
执笔经年
执笔经年 2021-01-15 15:47

How can I get information from a process that it is UI(User Interface) process or non-ui?

With UI process I mean, Finder, Dock, System UI server, or any other mac a

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-15 16:33

    On the lines of darvidsOn, below is the answer to your question.

      CFArrayRef UiProcesses()
        {
            CFArrayRef  orderedwindows = CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID);
            CFIndex count = CFArrayGetCount (orderedwindows);
            CFMutableArrayRef uiProcess = CFArrayCreateMutable (kCFAllocatorDefault , count,  &kCFTypeArrayCallBacks);
            for (CFIndex i = 0; i < count; i++)
            {
                if (orderedwindows)
                {
                    CFDictionaryRef windowsdescription = (CFDictionaryRef)CFArrayGetValueAtIndex(orderedwindows, i);
                    CFNumberRef windowownerpid  = (CFNumberRef)CFDictionaryGetValue (windowsdescription, CFSTR("kCGWindowOwnerPID"));
                    CFArrayAppendValue (uiProcess, windowownerpid);
    
                }
            }
            return uiProcess;
        }
    

    Just compare the processid you have against the array items to get the desired result.

提交回复
热议问题