diff --git a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp index fe867db167..0a40410114 100644 --- a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp @@ -3199,6 +3199,34 @@ void MouseInputSource::setRawMousePosition (Point newPosition) double Desktop::getDefaultMasterScale() { + // Ubuntu and derived distributions now save a per-display scale factor as a configuration + // variable. This can be changed in the Monitor system settings panel. + ChildProcess dconf; + + if (dconf.start ("dconf read /com/ubuntu/user-interface/scale-factor", ChildProcess::wantStdOut)) + { + if (dconf.waitForProcessToFinish (200)) + { + String jsonOutput = dconf.readAllProcessOutput().replaceCharacter ('\'', '"'); + + if (dconf.getExitCode() == 0 && jsonOutput.isNotEmpty()) + { + var jsonVar = JSON::parse (jsonOutput); + + if (DynamicObject* object = jsonVar.getDynamicObject()) + { + NamedValueSet& scaleFactors = object->getProperties(); + + double maxScaleFactor = 1.0; + for (int i = 0; i < scaleFactors.size(); ++i) + maxScaleFactor = jmax (maxScaleFactor, (double) (scaleFactors.getValueAt (i)) / 8.0); + + return maxScaleFactor; + } + } + } + } + return 1.0; }