platform-x11.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. /* Here we use xinerama to fetch data about monitor geometry
  15. * Even if there are not multiple monitors, this should still work.
  16. */
  17. #include <X11/Xlib.h>
  18. #include <X11/extensions/Xinerama.h>
  19. #include <unistd.h>
  20. #include <sstream>
  21. #include "platform.hpp"
  22. using namespace std;
  23. static inline bool check_path(const char* data, const char *path, string &output)
  24. {
  25. ostringstream str;
  26. str << path << data;
  27. output = str.str();
  28. printf("Attempted path: %s\n", output.c_str());
  29. return (access(output.c_str(), R_OK) == 0);
  30. }
  31. bool GetDataFilePath(const char *data, string &output)
  32. {
  33. char *data_path = getenv("OBS_DATA_PATH");
  34. if (data_path != NULL) {
  35. if (check_path(data, data_path, output))
  36. return true;
  37. }
  38. if (check_path(data, "/usr/local/share/obs-studio/", output))
  39. return true;
  40. if (check_path(data, "/usr/share/obs-studio/", output))
  41. return true;
  42. return false;
  43. }
  44. void GetMonitors(vector<MonitorInfo> &monitors)
  45. {
  46. int num_screens;
  47. XineramaScreenInfo *screens;
  48. int event_code = 0, error_code = 0;
  49. Display* display = XOpenDisplay(NULL);
  50. if (!XineramaQueryExtension(display, &event_code, &error_code)) {
  51. printf("Xinerama extension unavailable. We don't handle this yet.\n");
  52. return;
  53. }
  54. /* Do I need to make a call to XineramaQueryVersion...? */
  55. screens = XineramaQueryScreens(display, &num_screens);
  56. if (num_screens == 0 || !screens) {
  57. printf("Xinerama isn't active on this screen.\n");
  58. return;
  59. }
  60. monitors.clear();
  61. do {
  62. --num_screens;
  63. monitors.emplace_back(
  64. screens[num_screens].x_org,
  65. screens[num_screens].y_org,
  66. screens[num_screens].width,
  67. screens[num_screens].height
  68. );
  69. } while (num_screens > 0);
  70. XCloseDisplay(display);
  71. }
  72. bool InitApplicationBundle()
  73. {
  74. return true;
  75. }