auto-scene-switcher-osx.mm 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #import <AppKit/AppKit.h>
  2. #include <util/platform.h>
  3. #include "auto-scene-switcher.hpp"
  4. using namespace std;
  5. void GetWindowList(vector<string> &windows)
  6. {
  7. windows.resize(0);
  8. @autoreleasepool {
  9. NSWorkspace *ws = [NSWorkspace sharedWorkspace];
  10. NSArray *array = [ws runningApplications];
  11. for (NSRunningApplication *app in array) {
  12. NSString *name = app.localizedName;
  13. if (!name)
  14. continue;
  15. const char *str = name.UTF8String;
  16. if (str && *str)
  17. windows.emplace_back(str);
  18. }
  19. }
  20. }
  21. void GetCurrentWindowTitle(string &title)
  22. {
  23. title.resize(0);
  24. @autoreleasepool {
  25. NSWorkspace *ws = [NSWorkspace sharedWorkspace];
  26. NSRunningApplication *app = [ws frontmostApplication];
  27. if (app) {
  28. NSString *name = app.localizedName;
  29. if (!name)
  30. return;
  31. const char *str = name.UTF8String;
  32. if (str && *str)
  33. title = str;
  34. }
  35. }
  36. }
  37. void CleanupSceneSwitcher() {}