Skip to content

Commit 21cdb39

Browse files
committed
Lots of hidpi fixes (tested on Debian/XFCE under X11 so far)
1 parent 53890c2 commit 21cdb39

6 files changed

Lines changed: 26 additions & 15 deletions

File tree

src/ngscopeclient/FontManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/***********************************************************************************************************************
22
* *
3-
* glscopeclient *
3+
* ngscopeclient *
44
* *
5-
* Copyright (c) 2012-2022 Andrew D. Zonenberg *
5+
* Copyright (c) 2012-2025 Andrew D. Zonenberg *
66
* All rights reserved. *
77
* *
88
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *

src/ngscopeclient/MainWindow.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,17 @@ class MainWindow : public VulkanWindow
546546
FontWithSize GetFontPref(const std::string& name)
547547
{
548548
auto desc = m_session.GetPreferences().GetFont(name.c_str());
549-
return std::pair<ImFont*, float>(m_fontmgr.GetFont(desc), desc.second);
549+
return std::pair<ImFont*, float>(m_fontmgr.GetFont(desc), desc.second * GetFontScale());
550550
}
551551

552+
/**
553+
@brief Get scaling factor for fonts being drawn with ImDrawList
554+
555+
For now, normalize everything to a nominal size 13 default font
556+
*/
557+
float GetFontScale()
558+
{ return ImGui::GetFontSize() / 13; }
559+
552560
ImU32 GetColorPref(const std::string& name)
553561
{ return m_session.GetPreferences().GetColor(name); }
554562

src/ngscopeclient/VulkanWindow.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,20 @@ VulkanWindow::VulkanWindow(const string& title, shared_ptr<QueueHandle> queue)
181181
ImGui_ImplVulkan_Init(&info);
182182
}
183183

184-
// Apply DPI scaling now that glfw initialized
184+
//Apply DPI scaling now that glfw initialized
185+
//This appears to be cached by glfw at init time and is not updated for dynamic scaling changes at least on X11
186+
//TODO: can we fix this by moving to SDL?
185187
float scale = GetContentScale();
186-
187-
LogTrace("Applying ImGui style scale factor: %.2f\n", scale);
188+
LogTrace("Using ImGui style scale factor: %.2f\n", scale);
188189

189190
//WORKAROUND: handle HiDPI correctly on macOS.
191+
//This is probably wrong, per comment in imgui_impl_glfw "Apple platforms use FramebufferScale"
190192
#ifdef __APPLE__
191193
io.FontGlobalScale = 1.0f / scale;
192194
#else
193-
ImGui::GetStyle().ScaleAllSizes(scale);
195+
//ImGui::GetStyle().ScaleAllSizes(scale);
196+
//ImGui::GetStyle().FontScaleMain = scale;
197+
//Don't change any scaling for now in hidpi mode!
194198
#endif
195199

196200
//Hook a couple of backend functions with mutexing

src/ngscopeclient/WaveformArea.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ void WaveformArea::RenderProtocolWaveform(std::shared_ptr<DisplayedChannel> chan
16771677
if(ifirst > 0)
16781678
ifirst --;
16791679

1680-
float ybot = (channel->GetYButtonPos() * ImGui::GetWindowDpiScale()) + start.y;
1680+
float ybot = channel->GetYButtonPos() + start.y;
16811681
float ytop = ybot - m_channelButtonHeight;
16821682
float ymid = ybot - m_channelButtonHeight/2;
16831683

@@ -4076,7 +4076,7 @@ void WaveformArea::OnDragUpdate()
40764076
{
40774077
case DRAG_STATE_Y_AXIS:
40784078
{
4079-
float dy = ImGui::GetIO().MouseDelta.y * ImGui::GetWindowDpiScale();
4079+
float dy = ImGui::GetIO().MouseDelta.y;
40804080
m_yAxisOffset -= PixelsToYAxisUnits(dy);
40814081

40824082
for(auto chan : m_displayedChannels)

src/ngscopeclient/WaveformGroup.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ void WaveformGroup::RenderTimeline(float width, float height)
938938
if(m_dragState == DRAG_STATE_TIMELINE)
939939
{
940940
//Use relative delta, not drag delta, since we update the offset every frame
941-
float dx = mouseDelta.x * ImGui::GetWindowDpiScale();
941+
float dx = mouseDelta.x;
942942
if(dx != 0)
943943
{
944944
m_xAxisOffset -= PixelsToXAxisUnits(dx);
@@ -950,10 +950,9 @@ void WaveformGroup::RenderTimeline(float width, float height)
950950
}
951951

952952
//Dimensions for various things
953-
float dpiScale = ImGui::GetWindowDpiScale();
954-
float fineTickLength = 10 * dpiScale;
953+
float fineTickLength = 10;
955954
float coarseTickLength = height;
956-
const double min_label_grad_width = 75 * dpiScale; //Minimum distance between text labels
955+
const double min_label_grad_width = 6 * ImGui::GetFontSize(); //Minimum distance between text labels
957956
float thickLineWidth = 2;
958957
float thinLineWidth = 1;
959958
float ymid = pos.y + height/2;

src/ngscopeclient/WaveformGroup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* *
33
* ngscopeclient *
44
* *
5-
* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
5+
* Copyright (c) 2012-2025 Andrew D. Zonenberg and contributors *
66
* All rights reserved. *
77
* *
88
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
@@ -117,7 +117,7 @@ class WaveformGroup
117117
void ClearPersistence();
118118

119119
float GetYAxisWidth()
120-
{ return 6 * ImGui::GetFontSize() * ImGui::GetWindowDpiScale(); }
120+
{ return 6 * ImGui::GetFontSize(); }
121121

122122
float GetSpacing()
123123
{ return ImGui::GetFrameHeightWithSpacing() - ImGui::GetFrameHeight(); }

0 commit comments

Comments
 (0)