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.

55 lines
2.0KB

  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_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_PLUGIN_HAS_EXTERNAL_UI
  33. # include <algorithm>
  34. # include <cmath>
  35. START_NAMESPACE_DISTRHO
  36. double getDesktopScaleFactor(const uintptr_t parentWindowHandle)
  37. {
  38. // allow custom scale for testing
  39. if (const char* const scale = getenv("DPF_SCALE_FACTOR"))
  40. return std::max(1.0, std::atof(scale));
  41. if (NSView* const parentView = (NSView*)parentWindowHandle)
  42. if (NSWindow* const parentWindow = [parentView window])
  43. return [parentWindow screen].backingScaleFactor;
  44. return [NSScreen mainScreen].backingScaleFactor;
  45. }
  46. END_NAMESPACE_DISTRHO
  47. #endif