platform-osx.mm 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include <sstream>
  15. #include <util/base.h>
  16. #include "platform.hpp"
  17. #include <unistd.h>
  18. #import <AppKit/AppKit.h>
  19. using namespace std;
  20. bool GetDataFilePath(const char *data, string &output)
  21. {
  22. stringstream str;
  23. str << OBS_DATA_PATH << "/obs-studio/" << data;
  24. output = str.str();
  25. return !access(output.c_str(), R_OK);
  26. }
  27. void GetMonitors(vector<MonitorInfo> &monitors)
  28. {
  29. monitors.clear();
  30. for(NSScreen *screen : [NSScreen screens])
  31. {
  32. NSRect frame = [screen convertRectToBacking:[screen frame]];
  33. monitors.emplace_back(frame.origin.x, frame.origin.y,
  34. frame.size.width, frame.size.height);
  35. }
  36. }
  37. bool InitApplicationBundle()
  38. {
  39. #ifdef OBS_OSX_BUNDLE
  40. static bool initialized = false;
  41. if (initialized)
  42. return true;
  43. try {
  44. NSBundle *bundle = [NSBundle mainBundle];
  45. if (!bundle)
  46. throw "Could not find main bundle";
  47. NSString *exe_path = [bundle executablePath];
  48. if (!exe_path)
  49. throw "Could not find executable path";
  50. NSString *path = [exe_path stringByDeletingLastPathComponent];
  51. if (chdir([path fileSystemRepresentation]))
  52. throw "Could not change working directory to "
  53. "bundle path";
  54. } catch (const char* error) {
  55. blog(LOG_ERROR, "InitBundle: %s", error);
  56. return false;
  57. }
  58. return initialized = true;
  59. #else
  60. return true;
  61. #endif
  62. }