platform-x11.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #include <obs-config.h>
  16. #include "obs-app.hpp"
  17. #include <QGuiApplication>
  18. #include <QScreen>
  19. #include <unistd.h>
  20. #include <sstream>
  21. #include <locale.h>
  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. bool InitApplicationBundle()
  48. {
  49. return true;
  50. }
  51. string GetDefaultVideoSavePath()
  52. {
  53. return string(getenv("HOME"));
  54. }
  55. vector<string> GetPreferredLocales()
  56. {
  57. setlocale(LC_ALL, "");
  58. string messages = setlocale(LC_MESSAGES, NULL);
  59. if (!messages.size() || messages == "C" || messages == "POSIX")
  60. return {};
  61. if (messages.size() > 2)
  62. messages[2] = '-';
  63. for (auto &locale_pair : GetLocaleNames()) {
  64. auto &locale = locale_pair.first;
  65. if (locale == messages.substr(0, locale.size()))
  66. return {locale};
  67. if (locale.substr(0, 2) == messages.substr(0, 2))
  68. return {locale};
  69. }
  70. return {};
  71. }
  72. bool IsAlwaysOnTop(QWidget *window)
  73. {
  74. return (window->windowFlags() & Qt::WindowStaysOnTopHint) != 0;
  75. }
  76. void SetAlwaysOnTop(QWidget *window, bool enable)
  77. {
  78. Qt::WindowFlags flags = window->windowFlags();
  79. if (enable)
  80. flags |= Qt::WindowStaysOnTopHint;
  81. else
  82. flags &= ~Qt::WindowStaysOnTopHint;
  83. window->setWindowFlags(flags);
  84. window->show();
  85. }