DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.3KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. // A few utils declared in DistrhoUI.cpp but defined here because they use Obj-C
  17. #include "DistrhoDetails.hpp"
  18. #include "src/DistrhoPluginChecks.h"
  19. #include "src/DistrhoDefines.h"
  20. #if DISTRHO_UI_FILE_BROWSER || DISTRHO_UI_WEB_VIEW || DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  21. # import <Cocoa/Cocoa.h>
  22. #endif
  23. #if DISTRHO_UI_FILE_BROWSER
  24. # define DISTRHO_FILE_BROWSER_DIALOG_HPP_INCLUDED
  25. # define FILE_BROWSER_DIALOG_NAMESPACE DISTRHO_NAMESPACE
  26. # define FILE_BROWSER_DIALOG_DISTRHO_NAMESPACE
  27. START_NAMESPACE_DISTRHO
  28. # include "extra/FileBrowserDialogImpl.hpp"
  29. END_NAMESPACE_DISTRHO
  30. # include "extra/FileBrowserDialogImpl.cpp"
  31. #endif
  32. #if DISTRHO_UI_WEB_VIEW
  33. # define DISTRHO_WEB_VIEW_HPP_INCLUDED
  34. # define WEB_VIEW_NAMESPACE DISTRHO_NAMESPACE
  35. # define WEB_VIEW_DISTRHO_NAMESPACE
  36. START_NAMESPACE_DISTRHO
  37. # include "extra/WebViewImpl.hpp"
  38. END_NAMESPACE_DISTRHO
  39. # include "extra/WebViewImpl.cpp"
  40. #endif
  41. #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
  42. # include <algorithm>
  43. # include <cmath>
  44. START_NAMESPACE_DISTRHO
  45. double getDesktopScaleFactor(const uintptr_t parentWindowHandle)
  46. {
  47. // allow custom scale for testing
  48. if (const char* const scale = getenv("DPF_SCALE_FACTOR"))
  49. return std::max(1.0, std::atof(scale));
  50. if (NSView* const parentView = (NSView*)parentWindowHandle)
  51. if (NSWindow* const parentWindow = [parentView window])
  52. return [parentWindow screen].backingScaleFactor;
  53. return [NSScreen mainScreen].backingScaleFactor;
  54. }
  55. END_NAMESPACE_DISTRHO
  56. #endif