DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

DistrhoUI_macOS.mm (2021B)


      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 
     17 // A few utils declared in DistrhoUI.cpp but defined here because they use Obj-C
     18 
     19 #include "DistrhoDetails.hpp"
     20 #include "src/DistrhoPluginChecks.h"
     21 #include "src/DistrhoDefines.h"
     22 
     23 #if DISTRHO_UI_FILE_BROWSER || DISTRHO_PLUGIN_HAS_EXTERNAL_UI
     24 # import <Cocoa/Cocoa.h>
     25 #endif
     26 
     27 #if DISTRHO_UI_FILE_BROWSER
     28 # define DISTRHO_FILE_BROWSER_DIALOG_HPP_INCLUDED
     29 # define FILE_BROWSER_DIALOG_NAMESPACE DISTRHO_NAMESPACE
     30 # define FILE_BROWSER_DIALOG_DISTRHO_NAMESPACE
     31 START_NAMESPACE_DISTRHO
     32 # include "extra/FileBrowserDialogImpl.hpp"
     33 END_NAMESPACE_DISTRHO
     34 # include "extra/FileBrowserDialogImpl.cpp"
     35 #endif
     36 
     37 #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
     38 # include <algorithm>
     39 # include <cmath>
     40 START_NAMESPACE_DISTRHO
     41 double getDesktopScaleFactor(const uintptr_t parentWindowHandle)
     42 {
     43     // allow custom scale for testing
     44     if (const char* const scale = getenv("DPF_SCALE_FACTOR"))
     45         return std::max(1.0, std::atof(scale));
     46 
     47     if (NSView* const parentView = (NSView*)parentWindowHandle)
     48         if (NSWindow* const parentWindow = [parentView window])
     49            return [parentWindow screen].backingScaleFactor;
     50 
     51     return [NSScreen mainScreen].backingScaleFactor;
     52 }
     53 END_NAMESPACE_DISTRHO
     54 #endif