platform-x11.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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, string &output)
  25. {
  26. ostringstream str;
  27. str << path << data;
  28. output = str.str();
  29. printf("Attempted path: %s\n", output.c_str());
  30. return (access(output.c_str(), R_OK) == 0);
  31. }
  32. bool GetDataFilePath(const char *data, string &output)
  33. {
  34. char *data_path = getenv("OBS_DATA_PATH");
  35. if (data_path != NULL) {
  36. if (check_path(data, data_path, output))
  37. return true;
  38. }
  39. if (check_path(data, OBS_DATA_PATH "/obs-studio/", output))
  40. return true;
  41. if (check_path(data, OBS_INSTALL_PREFIX "/" OBS_DATA_PATH "/obs-studio/", output))
  42. return true;
  43. return false;
  44. }
  45. void GetMonitors(vector<MonitorInfo> &monitors)
  46. {
  47. int num_screens;
  48. XineramaScreenInfo *screens;
  49. int event_code = 0, error_code = 0;
  50. Display* display = XOpenDisplay(NULL);
  51. if (!XineramaQueryExtension(display, &event_code, &error_code)) {
  52. printf("Xinerama extension unavailable. We don't handle this yet.\n");
  53. return;
  54. }
  55. /* Do I need to make a call to XineramaQueryVersion...? */
  56. screens = XineramaQueryScreens(display, &num_screens);
  57. if (num_screens == 0 || !screens) {
  58. printf("Xinerama isn't active on this screen.\n");
  59. return;
  60. }
  61. monitors.clear();
  62. do {
  63. --num_screens;
  64. monitors.emplace_back(
  65. screens[num_screens].x_org,
  66. screens[num_screens].y_org,
  67. screens[num_screens].width,
  68. screens[num_screens].height
  69. );
  70. } while (num_screens > 0);
  71. XCloseDisplay(display);
  72. }
  73. bool InitApplicationBundle()
  74. {
  75. return true;
  76. }