Relatively new with Juce, currently I’m trying to work around a frustrating issue I’ve found with the automatic resizing of windows across screens.
Here visualized: 4k monitor to the left and 2k monitor to the right.
Any help / making sense of what’s going on here would be appreciated. Best I can tell, this might be dpi related, though getting dpi / scale information and playing around with scaling the widths and heights hasn’t fixed the end result, so far I’ve only succeeded in making the dialog too small, or too big and I’ve yet to have any impact on the size of the the contained AudioProcessorEditor. This same issue isn’t isolated to the DialogWindow class, the same result occurs with the AudioProcessorEditor if I do roughly the same steps. Currently the only reason I have for the wrapping class is just to allow the window to close.
Here’s the related code, inst is an AudioPluginInstance*:
class PluginWindow : public DialogWindow {
public:
PluginWindow(const String &name, Colour backgroundColour, bool escapeKeyTriggersCloseButton,
bool addToDesktop = true)
: DialogWindow(name, backgroundColour, escapeKeyTriggersCloseButton, addToDesktop)
{
setUsingNativeTitleBar(true);
}
~PluginWindow()
{
}
void closeButtonPressed()
{
setVisible(false);
}
}
...
if (!dialog)
dialog = new PluginWindow("", Colour(255, 255, 255), false, false);
dialog->setName(inst->getName());
editor = inst->createEditorIfNeeded();
if (dialog) {
juce::Point<double> mouse_point(mouse.x(), mouse.y());
if (editor) {
editor->setOpaque(true);
}
dialog->setContentNonOwned(editor, true);
if (!dialog->isOnDesktop()) {
dialog->setOpaque(true);
dialog->addToDesktop(ComponentPeer::StyleFlags::windowHasCloseButton |
ComponentPeer::StyleFlags::windowHasTitleBar |
ComponentPeer::StyleFlags::
windowHasMinimiseButton,
nullptr);
}
dialog->setVisible(editor);
if (editor) {
juce::Point<double> mouse_double = physicalToLogical(mouse_point);
juce::Point<int> logical_mouse = mouse_double.roundToInt();
logical_mouse.x -= (dialog->getWidth() / 2);
logical_mouse.y += 20;
editor->setVisible(true);
dialog->setTopLeftPosition(logical_mouse);
editor->grabKeyboardFocus();
}
}
Also confusing aspect in working through this it’s difficult to judge in the api what functions make use of / whether “logical pixels” or regular ones. I spent a decent amount of time working out that the functions expected logical pixels after noticing that all my windows were appearing way off target but in a scaled way. I’m guessing most of these functions return logical pixels because of all the ones so far they all appear to use logical pixels, eg the dialog->getWidth() / 2 only would make sense functioning if it were logical pixels because that centers the window in the exact right spot for me on the mouse, if I didn’t copy over the physicalToLogical function similar problems with positioning happen for me on the 2k screen.
Important Edit: Not on the latest 5.4.4, I’m slightly behind on 5.4.3*
Second Edit: Played around with windows dpi settings, this appears to have an impact, so I think this is related to the earlier post. I’m going to test their code and see if it helps.