platform-x11.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. Copyright (C) 2014 by Zachary Lund <[email protected]>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ******************************************************************************/
  15. /* Here we use xinerama to fetch data about monitor geometry
  16. * Even if there are not multiple monitors, this should still work.
  17. */
  18. #include <X11/Xlib.h>
  19. #include <X11/extensions/Xinerama.h>
  20. #include <unistd.h>
  21. #include <sstream>
  22. #include "platform.hpp"
  23. using namespace std;
  24. static inline bool check_path(const char* data, const char *path,
  25. string &output)
  26. {
  27. ostringstream str;
  28. str << path << data;
  29. output = str.str();
  30. printf("Attempted path: %s\n", output.c_str());
  31. return (access(output.c_str(), R_OK) == 0);
  32. }
  33. #define INSTALL_DATA_PATH OBS_INSTALL_PREFIX OBS_DATA_PATH "/obs-studio/"
  34. bool GetDataFilePath(const char *data, string &output)
  35. {
  36. char *data_path = getenv("OBS_DATA_PATH");
  37. if (data_path != NULL) {
  38. if (check_path(data, data_path, output))
  39. return true;
  40. }
  41. if (check_path(data, OBS_DATA_PATH "/obs-studio/", output))
  42. return true;
  43. if (check_path(data, INSTALL_DATA_PATH, output))
  44. return true;
  45. return false;
  46. }
  47. void GetMonitors(vector<MonitorInfo> &monitors)
  48. {
  49. int num_screens;
  50. XineramaScreenInfo *screens;
  51. int event_code = 0, error_code = 0;
  52. Display* display = XOpenDisplay(NULL);
  53. if (!XineramaQueryExtension(display, &event_code, &error_code)) {
  54. printf("Xinerama extension unavailable. We don't handle this "
  55. "yet.\n");
  56. return;
  57. }
  58. /* Do I need to make a call to XineramaQueryVersion...? */
  59. screens = XineramaQueryScreens(display, &num_screens);
  60. if (num_screens == 0 || !screens) {
  61. printf("Xinerama isn't active on this screen.\n");
  62. return;
  63. }
  64. monitors.clear();
  65. do {
  66. --num_screens;
  67. monitors.emplace_back(
  68. screens[num_screens].x_org,
  69. screens[num_screens].y_org,
  70. screens[num_screens].width,
  71. screens[num_screens].height
  72. );
  73. } while (num_screens > 0);
  74. XFree(screens);
  75. XCloseDisplay(display);
  76. }
  77. bool InitApplicationBundle()
  78. {
  79. return true;
  80. }
  81. string GetDefaultVideoSavePath()
  82. {
  83. return string(getenv("HOME"));
  84. }