Skip to content

Commit

Permalink
[Imp] Allow DPI-awareness to be set in the Display options directly, …
Browse files Browse the repository at this point in the history
…without the need to edit hidden settings. System-DPI-aware mode is now also supported.

[Mod] The old Display.HighResUI and Display.UseGDIUpscaling settings are gone. They are not migrated.
[Mod] OpenMPT is now per-monitor DPI-aware by default.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22440 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Dec 1, 2024
1 parent 3a32192 commit 5233db9
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 50 deletions.
36 changes: 36 additions & 0 deletions mptrack/ColorConfigDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void COptionsColors::DoDataExchange(CDataExchange* pDX)
DDX_Control(pDX, IDC_COMBO1, m_ComboItem);
DDX_Control(pDX, IDC_COMBO2, m_ComboFont);
DDX_Control(pDX, IDC_COMBO3, m_ComboPreset);
DDX_Control(pDX, IDC_COMBO4, m_ComboDPIAwareness);
DDX_Control(pDX, IDC_BUTTON4, m_BtnPreview);
DDX_Control(pDX, IDC_TEXT1, m_TxtColor[0]);
DDX_Control(pDX, IDC_TEXT2, m_TxtColor[1]);
Expand Down Expand Up @@ -143,11 +144,33 @@ static CString FormatFontName(const FontSetting &font)
BOOL COptionsColors::OnInitDialog()
{
CPropertyPage::OnInitDialog();

m_pPreviewDib = LoadDib(MAKEINTRESOURCE(IDB_COLORSETUP));

m_ComboDPIAwareness.SetRedraw(FALSE);
static constexpr std::pair<const TCHAR *, DPIAwarenessMode> DPIModes[] =
{
{_T("Not DPI-Aware"), DPIAwarenessMode::NoDPIAwareness },
{_T("Not DPI-Aware; GDI upscaling"), DPIAwarenessMode::NoDPIAwarenessGDIUpscaled},
{_T("System DPI-Aware"), DPIAwarenessMode::SystemDPIAware },
{_T("Per-Monitor DPI-Aware"), DPIAwarenessMode::PerMonitorDPIAware },
};
const DPIAwarenessMode currentDPIMode = TrackerSettings::Instance().dpiAwareness;
for(const auto dpiMode : DPIModes)
{
int item = m_ComboDPIAwareness.AddString(dpiMode.first);
m_ComboDPIAwareness.SetItemData(item, static_cast<DWORD_PTR>(dpiMode.second));
if(currentDPIMode == dpiMode.second)
m_ComboDPIAwareness.SetCurSel(item);
}
m_ComboDPIAwareness.SetRedraw(TRUE);

m_ComboItem.SetRedraw(FALSE);
for (size_t i = 0; i < std::size(colorDefs); i++)
{
m_ComboItem.SetItemData(m_ComboItem.AddString(colorDefs[i].name), i);
}
m_ComboItem.SetRedraw(TRUE);
m_ComboItem.SetCurSel(0);

m_BtnColor[0].SubclassDlgItem(IDC_BUTTON1, this);
Expand All @@ -168,6 +191,7 @@ BOOL COptionsColors::OnInitDialog()
CheckRadioButton(IDC_RADIO3, IDC_RADIO5, IDC_RADIO3 + static_cast<int>(TrackerSettings::Instance().defaultRainbowChannelColors.Get()));

patternFont = TrackerSettings::Instance().patternFont;
m_ComboFont.SetRedraw(FALSE);
m_ComboFont.AddString(_T("Built-in (small)"));
m_ComboFont.AddString(_T("Built-in (large)"));
m_ComboFont.AddString(_T("Built-in (small, x2)"));
Expand All @@ -186,6 +210,7 @@ BOOL COptionsColors::OnInitDialog()
m_ComboFont.AddString(FormatFontName(patternFont));
sel = 6;
}
m_ComboFont.SetRedraw(TRUE);
m_ComboFont.SetCurSel(sel);

commentFont = TrackerSettings::Instance().commentsFont;
Expand Down Expand Up @@ -227,6 +252,17 @@ BOOL COptionsColors::OnKillActive()

void COptionsColors::OnOK()
{
if(m_ComboDPIAwareness.GetCurSel() >= 0)
{
const DPIAwarenessMode currentDPIMode = TrackerSettings::Instance().dpiAwareness;
const DPIAwarenessMode newDPIMode = static_cast<DPIAwarenessMode>(m_ComboDPIAwareness.GetItemData(m_ComboDPIAwareness.GetCurSel()));
if(newDPIMode != currentDPIMode)
{
TrackerSettings::Instance().dpiAwareness = newDPIMode;
Reporting::Information(_T("You need to restart OpenMPT for the new DPI-awareness setting to take effect."));
}
}

TrackerSettings::Instance().m_dwPatternSetup &= ~(PATTERN_STDHIGHLIGHT|PATTERN_2NDHIGHLIGHT|PATTERN_EFFECTHILIGHT);
if(IsDlgButtonChecked(IDC_CHECK1)) TrackerSettings::Instance().m_dwPatternSetup |= PATTERN_STDHIGHLIGHT;
if(IsDlgButtonChecked(IDC_CHECK2)) TrackerSettings::Instance().m_dwPatternSetup |= PATTERN_EFFECTHILIGHT;
Expand Down
2 changes: 1 addition & 1 deletion mptrack/ColorConfigDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class COptionsColors : public CPropertyPage
{
protected:
std::array<COLORREF, MAX_MODCOLORS> CustomColors;
CComboBox m_ComboItem, m_ComboFont, m_ComboPreset;
CComboBox m_ComboDPIAwareness, m_ComboItem, m_ComboFont, m_ComboPreset;
ColorPickerButton m_BtnColor[3];
CButton m_BtnPreview;
CSpinButtonCtrl m_ColorSpin;
Expand Down
43 changes: 27 additions & 16 deletions mptrack/HighDPISupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ enum MPT_DPI_AWARENESS_CONTEXT : intptr_t
};


static HANDLE DPIModeToContext(HighDPISupport::Mode mode)
{
switch (mode)
{
case HighDPISupport::Mode::LowDpi: return HANDLE(MPT_DPI_AWARENESS_CONTEXT_UNAWARE);
case HighDPISupport::Mode::LowDpiUpscaled: return HANDLE(MPT_DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED);
case HighDPISupport::Mode::HighDpiSystem: return HANDLE(MPT_DPI_AWARENESS_CONTEXT_SYSTEM_AWARE);
case HighDPISupport::Mode::HighDpiPerMonitor: return HANDLE(MPT_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
}
MPT_ASSERT_NOTREACHED();
return HANDLE(MPT_DPI_AWARENESS_CONTEXT_UNAWARE);
}


static HighDPISupportData *GetHighDPISupportData()
{
static std::unique_ptr<HighDPISupportData> highDPISupportData;
Expand All @@ -70,37 +84,34 @@ static HighDPISupportData *GetHighDPISupportData()
void HighDPISupport::SetDPIAwareness(Mode mode)
{
auto instance = GetHighDPISupportData();
bool setDPI = false;
// For Windows 10, Creators Update (1703) and newer
if(instance->m_user32.IsValid())
{
using PSETPROCESSDPIAWARENESSCONTEXT = BOOL(WINAPI *)(HANDLE);
PSETPROCESSDPIAWARENESSCONTEXT SetProcessDpiAwarenessContext = nullptr;
if(instance->m_user32.Bind(SetProcessDpiAwarenessContext, "SetProcessDpiAwarenessContext"))
{
if(mode == Mode::HighDpi)
setDPI = (SetProcessDpiAwarenessContext(HANDLE(MPT_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)) == TRUE);
else if(mode == Mode::LowDpiUpscaled && SetProcessDpiAwarenessContext(HANDLE(MPT_DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED)) == TRUE)
setDPI = true;
else
setDPI = (SetProcessDpiAwarenessContext(HANDLE(MPT_DPI_AWARENESS_CONTEXT_UNAWARE)) == TRUE);
if(SetProcessDpiAwarenessContext(DPIModeToContext(mode)) == TRUE)
return;
}
}

// For Windows 8.1 and newer
if(!setDPI)
const bool highDPI = (mode == Mode::HighDpiSystem || mode == Mode::HighDpiPerMonitor);
mpt::Library shcore(mpt::LibraryPath::System(P_("SHCore")));
if(shcore.IsValid())
{
mpt::Library shcore(mpt::LibraryPath::System(P_("SHCore")));
if(shcore.IsValid())
using PSETPROCESSDPIAWARENESS = HRESULT(WINAPI *)(int);
PSETPROCESSDPIAWARENESS SetProcessDPIAwareness = nullptr;
if(shcore.Bind(SetProcessDPIAwareness, "SetProcessDpiAwareness"))
{
using PSETPROCESSDPIAWARENESS = HRESULT(WINAPI *)(int);
PSETPROCESSDPIAWARENESS SetProcessDPIAwareness = nullptr;
if(shcore.Bind(SetProcessDPIAwareness, "SetProcessDpiAwareness"))
setDPI = (SetProcessDPIAwareness(mode == Mode::HighDpi ? 2 : 0) == S_OK);
if(SetProcessDPIAwareness(highDPI ? 2 : 0) == S_OK)
return;
}
}

// For Vista and newer
if(!setDPI && mode == Mode::HighDpi && instance->m_user32.IsValid())
if(highDPI && instance->m_user32.IsValid())
{
using PSETPROCESSDPIAWARE = BOOL(WINAPI *)();
PSETPROCESSDPIAWARE SetProcessDPIAware = nullptr;
Expand Down Expand Up @@ -199,7 +210,7 @@ bool HighDPISupport::GetWindowPlacement(HWND hwnd, WINDOWPLACEMENT &wpl)
HighDPISupport::DPIAwarenessBypass::DPIAwarenessBypass(Mode forceMode)
{
if(auto instance = GetHighDPISupportData(); instance->m_SetThreadDpiAwarenessContext)
m_previous = instance->m_SetThreadDpiAwarenessContext(HANDLE((forceMode == Mode::HighDpi) ? MPT_DPI_AWARENESS_CONTEXT_SYSTEM_AWARE : MPT_DPI_AWARENESS_CONTEXT_UNAWARE));
m_previous = instance->m_SetThreadDpiAwarenessContext(DPIModeToContext(forceMode));
}


Expand Down
5 changes: 3 additions & 2 deletions mptrack/HighDPISupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace HighDPISupport
{
LowDpi,
LowDpiUpscaled,
HighDpi,
HighDpiSystem,
HighDpiPerMonitor,
};

void SetDPIAwareness(Mode mode);
Expand Down Expand Up @@ -64,7 +65,7 @@ namespace HighDPISupport
class DPIAwarenessBypass
{
public:
DPIAwarenessBypass(Mode forceMode = Mode::HighDpi);
DPIAwarenessBypass(Mode forceMode = Mode::HighDpiSystem);
~DPIAwarenessBypass();

private:
Expand Down
22 changes: 17 additions & 5 deletions mptrack/Mptrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1295,12 +1295,24 @@ BOOL CTrackApp::InitInstanceImpl(CMPTCommandLineInfo &cmdInfo)
#endif

// Dynamic DPI-awareness. Some users might want to disable DPI-awareness because of their DPI-unaware VST plugins.
if(TrackerSettings::Instance().highResUI)
HighDPISupport::SetDPIAwareness(HighDPISupport::Mode::HighDpi);
else if(TrackerSettings::Instance().useGDIUpcaling)
HighDPISupport::SetDPIAwareness(HighDPISupport::Mode::LowDpiUpscaled);
else
switch(TrackerSettings::Instance().dpiAwareness)
{
case DPIAwarenessMode::NoDPIAwareness:
HighDPISupport::SetDPIAwareness(HighDPISupport::Mode::LowDpi);
break;
case DPIAwarenessMode::NoDPIAwarenessGDIUpscaled:
HighDPISupport::SetDPIAwareness(HighDPISupport::Mode::LowDpiUpscaled);
break;
case DPIAwarenessMode::SystemDPIAware:
HighDPISupport::SetDPIAwareness(HighDPISupport::Mode::HighDpiSystem);
break;
case DPIAwarenessMode::PerMonitorDPIAware:
HighDPISupport::SetDPIAwareness(HighDPISupport::Mode::HighDpiPerMonitor);
break;
default:
MPT_ASSERT_NOTREACHED();
break;
}

// create main MDI Frame window
CMainFrame *pMainFrame = new CMainFrame();
Expand Down
3 changes: 1 addition & 2 deletions mptrack/TrackerSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ TrackerSettings::TrackerSettings(SettingsContainer &conf)
// Display
, m_ShowSplashScreen(conf, UL_("Display"), UL_("ShowSplashScreen"), true)
, gbMdiMaximize(conf, UL_("Display"), UL_("MDIMaximize"), true)
, highResUI(conf, UL_("Display"), UL_("HighResUI"), false)
, useGDIUpcaling(conf, UL_("Display"), UL_("UseGDIUpscaling"), true)
, dpiAwareness(conf, UL_("Display"), UL_("DPIAwareness"), DPIAwarenessMode::PerMonitorDPIAware)
, glTreeSplitRatio(conf, UL_("Display"), UL_("MDITreeRatio"), 128)
, glTreeWindowWidth(conf, UL_("Display"), UL_("MDITreeWidth"), 160)
, glGeneralWindowHeight(conf, UL_("Display"), UL_("MDIGeneralHeight"), 222)
Expand Down
13 changes: 11 additions & 2 deletions mptrack/TrackerSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ enum class DefaultChannelColors
Random,
};

enum class DPIAwarenessMode
{
NoDPIAwareness = 0,
NoDPIAwarenessGDIUpscaled,
SystemDPIAware,
PerMonitorDPIAware,
};

class SampleUndoBufferSize
{
Expand Down Expand Up @@ -323,6 +330,9 @@ template<> inline TimelineFormat FromSettingValue(const SettingValue &val) { ret
template<> inline SettingValue ToSettingValue(const DefaultChannelColors & val) { return SettingValue(int32(val)); }
template<> inline DefaultChannelColors FromSettingValue(const SettingValue& val) { return DefaultChannelColors(val.as<int32>()); }

template<> inline SettingValue ToSettingValue(const DPIAwarenessMode &val) { return SettingValue(int32(val)); }
template<> inline DPIAwarenessMode FromSettingValue(const SettingValue &val) { return DPIAwarenessMode(val.as<int32>()); }

template<> inline SettingValue ToSettingValue(const MODTYPE &val) { return SettingValue(SettingsModTypeToString(val), "MODTYPE"); }
template<> inline MODTYPE FromSettingValue(const SettingValue &val) { ASSERT(val.GetTypeTag() == "MODTYPE"); return SettingsStringToModType(val.as<mpt::ustring>()); }

Expand Down Expand Up @@ -684,8 +694,7 @@ class TrackerSettings

Setting<bool> m_ShowSplashScreen;
Setting<bool> gbMdiMaximize;
Setting<bool> highResUI;
Setting<bool> useGDIUpcaling;
Setting<DPIAwarenessMode> dpiAwareness;
Setting<LONG> glTreeSplitRatio;
Setting<LONG> glTreeWindowWidth;
Setting<LONG> glGeneralWindowHeight;
Expand Down
46 changes: 24 additions & 22 deletions mptrack/mptrack.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1308,29 +1308,31 @@ CAPTION "Display"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
GROUPBOX "",IDC_STATIC,6,6,312,192
LTEXT "Pattern &Font:",IDC_STATIC,18,20,54,8
COMBOBOX IDC_COMBO2,72,18,180,66,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "&Custom...",IDC_BUTTON9,258,18,50,12
LTEXT "Comments f&ont:",IDC_STATIC,18,38,52,8
PUSHBUTTON "Font",IDC_BUTTON10,72,36,180,12
LTEXT "Display accidentals as:",IDC_STATIC,18,53,78,12,SS_CENTERIMAGE
CONTROL "&Sharps (#)",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON,102,54,66,12
CONTROL "Flats (&b)",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON,168,54,108,12
LTEXT "Default channel colours:",IDC_STATIC,18,67,78,12,SS_CENTERIMAGE
CONTROL "&No Colours",IDC_RADIO3,"Button",BS_AUTORADIOBUTTON,102,67,66,12
CONTROL "&Rainbow",IDC_RADIO4,"Button",BS_AUTORADIOBUTTON,168,67,60,12
CONTROL "Ran&dom",IDC_RADIO5,"Button",BS_AUTORADIOBUTTON,228,67,48,12
CONTROL "&Enable effect highlighting",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,84,114,10
LTEXT "DPI Awareness:",IDC_STATIC,18,20,54,8
COMBOBOX IDC_COMBO4,78,18,174,66,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Pattern &Font:",IDC_STATIC,18,39,54,8
COMBOBOX IDC_COMBO2,78,36,174,66,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "&Custom...",IDC_BUTTON9,258,36,50,12
LTEXT "Comments f&ont:",IDC_STATIC,18,57,54,8
PUSHBUTTON "Font",IDC_BUTTON10,78,55,174,12
LTEXT "Display accidentals as:",IDC_STATIC,18,71,84,12,SS_CENTERIMAGE
CONTROL "&Sharps (#)",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON,108,72,66,12
CONTROL "Flats (&b)",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON,174,72,108,12
LTEXT "Default channel colours:",IDC_STATIC,18,86,84,12,SS_CENTERIMAGE
CONTROL "&No Colours",IDC_RADIO3,"Button",BS_AUTORADIOBUTTON,108,85,66,12
CONTROL "&Rainbow",IDC_RADIO4,"Button",BS_AUTORADIOBUTTON,174,85,60,12
CONTROL "Ran&dom",IDC_RADIO5,"Button",BS_AUTORADIOBUTTON,234,85,48,12
CONTROL "&Enable effect highlighting",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,103,114,10
CONTROL "Remember each song's &window positions",IDC_CHECK5,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,102,168,10
PUSHBUTTON "Clear Song Cac&he",IDC_BUTTON11,186,100,78,12
CONTROL "&Primary highlight",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,118,84,10
EDITTEXT IDC_PRIMARYHILITE,102,118,24,12,ES_AUTOHSCROLL | ES_NUMBER
LTEXT "Rows per measure (default)",IDC_STATIC,132,121,144,8
CONTROL "Secondar&y highlight",IDC_CHECK4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,137,80,10
EDITTEXT IDC_SECONDARYHILITE,102,137,24,12,ES_AUTOHSCROLL | ES_NUMBER
LTEXT "Rows per beat (default)",IDC_STATIC,132,140,144,8
LTEXT "Note: Songs' time signatures will override the default highlight values",IDC_STATIC,18,153,258,8
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,121,168,10
PUSHBUTTON "Clear Song Cac&he",IDC_BUTTON11,186,119,78,12
CONTROL "&Primary highlight",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,137,84,10
EDITTEXT IDC_PRIMARYHILITE,102,137,24,12,ES_AUTOHSCROLL | ES_NUMBER
LTEXT "Rows per measure (default)",IDC_STATIC,132,140,144,8
CONTROL "Secondar&y highlight",IDC_CHECK4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,156,80,10
EDITTEXT IDC_SECONDARYHILITE,102,156,24,12,ES_AUTOHSCROLL | ES_NUMBER
LTEXT "Rows per beat (default)",IDC_STATIC,132,159,144,8
LTEXT "Note: Songs' time signatures will override the default highlight values",IDC_STATIC,18,172,258,8
GROUPBOX "Colours",IDC_STATIC,6,204,312,102
LTEXT "Select colo&ur for:",IDC_STATIC,18,218,63,8
CONTROL "",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,84,216,11,12
Expand Down

0 comments on commit 5233db9

Please sign in to comment.