Skip to content

Commit

Permalink
Add puGL API to query HiDPI backing-scale factor
Browse files Browse the repository at this point in the history
This is mainly relevant for Apple's high-resolution displays,
where rendering should be upsampled.
  • Loading branch information
x42 committed Jul 30, 2022
1 parent 57473a3 commit f7e3821
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pugl/pugl.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ puglGetHandle(PuglView* view);
PUGL_API uint32_t
puglGetEventTimestamp(PuglView* view);

/**
Return the hardware backing scale
*/
PUGL_API float
puglGetHWSurfaceScale(PuglView* view);

/**
Get the currently active modifiers (PuglMod flags).
Expand Down
7 changes: 7 additions & 0 deletions pugl/pugl_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct PuglViewImpl {
bool set_window_hints;
bool ontop;
bool resize;
float ui_scale;
uint32_t event_timestamp_ms;
};

Expand All @@ -75,6 +76,12 @@ puglGetEventTimestamp(PuglView* view)
return view->event_timestamp_ms;
}

float
puglGetHWSurfaceScale(PuglView* view)
{
return view->ui_scale;;
}

int
puglGetModifiers(PuglView* view)
{
Expand Down
4 changes: 4 additions & 0 deletions pugl/pugl_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ - (void) flagsChanged:(NSEvent*)event
view->width = width;
view->height = height;
view->ontop = ontop;
view->ui_scale = 1.0;
view->user_resizable = resizable; // unused

[NSAutoreleasePool new];
Expand Down Expand Up @@ -501,6 +502,9 @@ void set_value (id) { }
} else {
p.set_value ([[NSScreen mainScreen] backingScaleFactor]);
}
if (p._f >= 1.f && p._f <= 4.f) {
view->ui_scale = p._f;
}
}
#endif
return view;
Expand Down
1 change: 1 addition & 0 deletions pugl/pugl_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ puglCreate(PuglNativeWindow parent,
view->width = width;
view->height = height;
view->ontop = ontop;
view->ui_scale = 1.0;
view->user_resizable = resizable && !parent;
view->impl->keep_aspect = min_width != width;

Expand Down
1 change: 1 addition & 0 deletions pugl/pugl_x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ puglCreate(PuglNativeWindow parent,
view->width = width;
view->height = height;
view->ontop = ontop;
view->ui_scale = 1.0;
view->set_window_hints = true;
view->user_resizable = resizable;

Expand Down

0 comments on commit f7e3821

Please sign in to comment.