Skip to content

Commit

Permalink
win32: fix windows possibly opening out of view depending on primary …
Browse files Browse the repository at this point in the history
…monitor scale
  • Loading branch information
cfillion committed Nov 17, 2022
1 parent 4fe1ac3 commit de8629c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/win32_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "platform.hpp"
#include "win32_unicode.hpp"

#include <cassert>
#include <GL/gl3w.h>
#include <GL/wglext.h>
#include <reaper_plugin_secrets.h>
Expand Down Expand Up @@ -134,10 +133,17 @@ void Win32Window::create()
if(!(m_viewport->Flags & ImGuiViewportFlags_NoDecoration))
exStyle |= WS_EX_DLGMODALFRAME;

// give a sensible window position guess (accurate if no decorations)
// so that m_dpi gets initialized to the correct value
// (would be the primary monitor's DPI otherwise, causing scalePosition to be
// given an incorrect scale and possibly moving the window out of view)
ImVec2 initialPos { m_viewport->Pos };
Platform::scalePosition(&initialPos, true);
CreateWindowEx(exStyle, CLASS_NAME, L"", m_style,
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0,
initialPos.x, initialPos.y, 0, 0,
parentHandle(), nullptr, s_instance, this);
assert(m_hwnd && "CreateWindow failed");
if(!m_hwnd)
throw backend_error { "failed to create native window" };

m_dpi = dpiForWindow(m_hwnd.get());
m_viewport->DpiScale = scaleForDpi(m_dpi);
Expand Down

0 comments on commit de8629c

Please sign in to comment.