Mercurial > minori
comparison dep/animia/src/win/quartz.cc @ 197:c4ca035c565d
*: misc. patches
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Fri, 08 Dec 2023 11:19:54 -0500 |
| parents | 50108040d792 |
| children | bc1ae1810855 |
comparison
equal
deleted
inserted
replaced
| 196:f0ff06a45c42 | 197:c4ca035c565d |
|---|---|
| 59 | 59 |
| 60 // return [bundle_id UTF8String]; | 60 // return [bundle_id UTF8String]; |
| 61 return osx::util::StringFromCFString(bundle_id, result); | 61 return osx::util::StringFromCFString(bundle_id, result); |
| 62 } | 62 } |
| 63 | 63 |
| 64 template<typename T> | |
| 65 static bool CFDictionaryGetValue(CFDictionaryRef thedict, CFStringRef key, T& out) { | |
| 66 CFTypeRef data = nullptr; | |
| 67 if (!CFDictionaryGetValueIfPresent(thedict, key, reinterpret_cast<const void**>(&data)) || !data) | |
| 68 return false; | |
| 69 | |
| 70 if constexpr (std::is_arithmetic<T>::value) | |
| 71 osx::util::GetCFNumber(reinterpret_cast<CFNumberRef>(data), out); | |
| 72 else if constexpr (std::is_same<T, std::string>::value) | |
| 73 osx::util::StringFromCFString(reinterpret_cast<CFStringRef>(data), out); | |
| 74 else | |
| 75 return false; | |
| 76 | |
| 77 return true; | |
| 78 } | |
| 79 | |
| 64 bool QuartzWinTools::EnumerateWindows(window_proc_t window_proc) { | 80 bool QuartzWinTools::EnumerateWindows(window_proc_t window_proc) { |
| 65 if (!window_proc) | 81 if (!window_proc) |
| 66 return false; | 82 return false; |
| 67 | 83 |
| 68 const CFArrayRef windows = CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID); | 84 const CFArrayRef windows = CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID); |
| 75 if (!window) | 91 if (!window) |
| 76 continue; | 92 continue; |
| 77 | 93 |
| 78 Process proc; | 94 Process proc; |
| 79 { | 95 { |
| 80 { | 96 CFDictionaryGetValue(window, CFSTR("kCGWindowOwnerPID"), proc.pid); |
| 81 CFNumberRef num = nullptr; | 97 if (!CFDictionaryGetValue(window, CFSTR("kCGWindowOwnerName"), proc.name)) |
| 82 if (CFDictionaryGetValueIfPresent(window, CFSTR("kCGWindowOwnerPID"), reinterpret_cast<const void**>(&num)) && num) | |
| 83 osx::util::GetCFNumber(num, proc.pid); | |
| 84 } | |
| 85 { | |
| 86 CFStringRef str = nullptr; | |
| 87 if (CFDictionaryGetValueIfPresent(window, CFSTR("kCGWindowOwnerName"), reinterpret_cast<const void**>(&str)) && str) | |
| 88 osx::util::StringFromCFString(str, proc.name); | |
| 89 } | |
| 90 if (proc.name.empty()) | |
| 91 osx::util::GetProcessName(proc.pid, proc.name); | 98 osx::util::GetProcessName(proc.pid, proc.name); |
| 92 } | 99 } |
| 93 | 100 |
| 94 Window win; | 101 Window win; |
| 95 { | 102 { |
| 96 { | 103 CFDictionaryGetValue(window, CFSTR("kCGWindowNumber"), win.id); |
| 97 CFNumberRef num = nullptr; | 104 |
| 98 if (CFDictionaryGetValueIfPresent(window, CFSTR("kCGWindowNumber"), reinterpret_cast<const void**>(&num)) && num) | |
| 99 osx::util::GetCFNumber(num, win.id); | |
| 100 } | |
| 101 if (!GetProcessBundleIdentifier(proc.pid, win.class_name)) { | 105 if (!GetProcessBundleIdentifier(proc.pid, win.class_name)) { |
| 102 // Fallback to the Quartz window name, which is unlikely to be filled, but it | 106 // Fallback to the Quartz window name, which is unlikely to be filled, but it |
| 103 // *could* be. | 107 // *could* be. |
| 104 CFStringRef str = nullptr; | 108 CFDictionaryGetValue(window, CFSTR("kCGWindowName"), win.class_name); |
| 105 if (CFDictionaryGetValueIfPresent(window, CFSTR("kCGWindowName"), reinterpret_cast<const void**>(&str)) && str) | |
| 106 osx::util::StringFromCFString(str, win.class_name); | |
| 107 } | 109 } |
| 110 | |
| 108 GetWindowTitle(win.id, win.text); | 111 GetWindowTitle(win.id, win.text); |
| 109 } | 112 } |
| 110 | 113 |
| 111 if (!window_proc(proc, win)) { | 114 if (!window_proc(proc, win)) { |
| 112 CFRelease(windows); | 115 CFRelease(windows); |
