Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/mostly_harmless/gui/mostlyharmless_DisplayInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Created by Syl Morrison on 06/02/2026.
//

#ifndef GLEO_MOSTLYHARMLESS_DISPLAYINFO_H
#define GLEO_MOSTLYHARMLESS_DISPLAYINFO_H
#include <cstdint>
namespace mostly_harmless::gui::display_info {
void getScreenDimensions(std::uint32_t* width, std::uint32_t* height);
double getDevicePixelRatio();
} // namespace mostly_harmless::gui::display_info
#endif // GLEO_MOSTLYHARMLESS_DISPLAYINFO_H
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ namespace mostly_harmless::gui::helpers::macos {
* \param height A pointer to the height variable - the result will be written here.
*/
void getViewSize(void* viewHandle, std::uint32_t* width, std::uint32_t* height);

void getScreenSize(std::uint32_t* width, std::uint32_t* height);

double getDevicePixelRatio();
/**
* Adds an NSView as a subview of another NSView.
* \param parentViewHandle A void* to the NSView to add the child view to.
Expand Down
1 change: 1 addition & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set(MOSTLYHARMLESS_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/gui/mostlyharmless_WebviewEditor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gui/mostlyharmless_Cursor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gui/mostlyharmless_Colour.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gui/mostlyharmless_DisplayInfo.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utils/mostlyharmless_TaskThread.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utils/mostlyharmless_Timer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utils/mostlyharmless_OnScopeExit.cpp
Expand Down
24 changes: 24 additions & 0 deletions source/gui/mostlyharmless_DisplayInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Created by Syl Morrison on 06/02/2026.
//
#include "mostly_harmless/gui/platform/mostlyharmless_GuiHelpersMacOS.h"


#include <mostly_harmless/gui/mostlyharmless_DisplayInfo.h>
namespace mostly_harmless::gui::display_info {

#if defined(MOSTLY_HARMLESS_MACOS)
#include <mostly_harmless/gui/platform/mostlyharmless_GuiHelpersMacOS.h>
void getScreenDimensions(std::uint32_t* width, std::uint32_t* height) {
helpers::macos::getScreenSize(width, height);
}

double getDevicePixelRatio() {
return helpers::macos::getDevicePixelRatio();
}

#else

#endif

} // namespace mostly_harmless::gui::display_info
21 changes: 21 additions & 0 deletions source/gui/platform/mostlyharmless_GuiHelpersMacOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ void getViewSize(void* viewHandle, std::uint32_t* width, std::uint32_t* height)
*height = static_cast<std::uint32_t>(bounds.size.height);
}

void getScreenSize(std::uint32_t* width, std::uint32_t* height) {
auto frame = [[NSScreen mainScreen] frame];
*width = static_cast<std::uint32_t>(frame.size.width);
*height = static_cast<std::uint32_t>(frame.size.height);
}

double getDevicePixelRatio() {
auto mainDisplayId = CGMainDisplayID();
auto screenSizeMm = CGDisplayScreenSize(mainDisplayId);
const auto widthMm = screenSizeMm.width;
const auto heightMm = screenSizeMm.height;
const auto hypMm = std::sqrt((widthMm * widthMm) + (heightMm * heightMm));
std::uint32_t widthPx, heightPx;
getScreenSize(&widthPx, &heightPx);
const auto pxHyp = std::sqrt((widthPx * widthPx) + (heightPx * heightPx));
constexpr static auto mmPerInch = 25.4;
const auto ratio = pxHyp / hypMm;
const auto dpi = ratio * mmPerInch;
return 1.0;
}

void reparentView(void* hostViewHandle, void* clientViewHandle, void* childViewHandle, Colour backgroundColour) {
auto* host = static_cast<NSView*>(hostViewHandle);
auto* client = static_cast<NSView*>(clientViewHandle);
Expand Down
Loading