Skip to content
Merged
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
38 changes: 15 additions & 23 deletions src/_c_internal_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ mpl_xdisplay_is_valid(void)
// than dlopen().
if (getenv("DISPLAY")
&& (libX11 = dlopen("libX11.so.6", RTLD_LAZY))) {
typedef struct Display* (*XOpenDisplay_t)(char const*);
typedef int (*XCloseDisplay_t)(struct Display*);
struct Display* display = nullptr;
XOpenDisplay_t XOpenDisplay = (XOpenDisplay_t)dlsym(libX11, "XOpenDisplay");
XCloseDisplay_t XCloseDisplay = (XCloseDisplay_t)dlsym(libX11, "XCloseDisplay");
auto XOpenDisplay = (struct Display* (*)(char const*))
dlsym(libX11, "XOpenDisplay");
auto XCloseDisplay = (int (*)(struct Display*))
dlsym(libX11, "XCloseDisplay");
if (XOpenDisplay && XCloseDisplay
&& (display = XOpenDisplay(nullptr))) {
XCloseDisplay(display);
Expand Down Expand Up @@ -73,13 +73,11 @@ mpl_display_is_valid(void)
void* libwayland_client;
if (getenv("WAYLAND_DISPLAY")
&& (libwayland_client = dlopen("libwayland-client.so.0", RTLD_LAZY))) {
typedef struct wl_display* (*wl_display_connect_t)(char const*);
typedef void (*wl_display_disconnect_t)(struct wl_display*);
struct wl_display* display = nullptr;
wl_display_connect_t wl_display_connect =
(wl_display_connect_t)dlsym(libwayland_client, "wl_display_connect");
wl_display_disconnect_t wl_display_disconnect =
(wl_display_disconnect_t)dlsym(libwayland_client, "wl_display_disconnect");
auto wl_display_connect = (struct wl_display* (*)(char const*))
dlsym(libwayland_client, "wl_display_connect");
auto wl_display_disconnect = (void (*)(struct wl_display*))
dlsym(libwayland_client, "wl_display_disconnect");
if (wl_display_connect && wl_display_disconnect
&& (display = wl_display_connect(nullptr))) {
wl_display_disconnect(display);
Expand Down Expand Up @@ -162,25 +160,19 @@ mpl_SetProcessDpiAwareness_max(void)
#ifdef _DPI_AWARENESS_CONTEXTS_
// These functions and options were added in later Windows 10 updates, so
// must be loaded dynamically.
typedef BOOL (WINAPI *IsValidDpiAwarenessContext_t)(DPI_AWARENESS_CONTEXT);
typedef BOOL (WINAPI *SetProcessDpiAwarenessContext_t)(DPI_AWARENESS_CONTEXT);

HMODULE user32 = LoadLibrary("user32.dll");
IsValidDpiAwarenessContext_t IsValidDpiAwarenessContextPtr =
(IsValidDpiAwarenessContext_t)GetProcAddress(
user32, "IsValidDpiAwarenessContext");
SetProcessDpiAwarenessContext_t SetProcessDpiAwarenessContextPtr =
(SetProcessDpiAwarenessContext_t)GetProcAddress(
user32, "SetProcessDpiAwarenessContext");
auto IsValidDpiAwarenessContext = (BOOL (WINAPI *)(DPI_AWARENESS_CONTEXT))
GetProcAddress(user32, "IsValidDpiAwarenessContext");
auto SetProcessDpiAwarenessContext = (BOOL (WINAPI *)(DPI_AWARENESS_CONTEXT))
GetProcAddress(user32, "SetProcessDpiAwarenessContext");
DPI_AWARENESS_CONTEXT ctxs[3] = {
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2, // Win10 Creators Update
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE, // Win10
DPI_AWARENESS_CONTEXT_SYSTEM_AWARE}; // Win10
if (IsValidDpiAwarenessContextPtr != NULL
&& SetProcessDpiAwarenessContextPtr != NULL) {
if (IsValidDpiAwarenessContext && SetProcessDpiAwarenessContext) {
for (size_t i = 0; i < sizeof(ctxs) / sizeof(DPI_AWARENESS_CONTEXT); ++i) {
if (IsValidDpiAwarenessContextPtr(ctxs[i])) {
SetProcessDpiAwarenessContextPtr(ctxs[i]);
if (IsValidDpiAwarenessContext(ctxs[i])) {
SetProcessDpiAwarenessContext(ctxs[i]);
break;
}
}
Expand Down
Loading