aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2021-04-13 23:52:34 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2021-04-13 23:52:34 +0200
commit6201a016fca7507db848899c71431377f7ea068b (patch)
treeb01999788ca7dcba267f26b3947eedcc51268343
parent4ec4c04efd918888c1ad222a684a6d32ae79e7a5 (diff)
parent96083e3ab7a509c1dbe04ae61bac09dfa0f8c2dd (diff)
downloadsherlock.lv2-6201a016fca7507db848899c71431377f7ea068b.tar.xz
Merge commit '96083e3ab7a509c1dbe04ae61bac09dfa0f8c2dd'
-rw-r--r--subprojects/nk_pugl/VERSION2
-rw-r--r--subprojects/nk_pugl/example/example.c8
-rw-r--r--subprojects/nk_pugl/nk_pugl/nk_pugl.h117
3 files changed, 58 insertions, 69 deletions
diff --git a/subprojects/nk_pugl/VERSION b/subprojects/nk_pugl/VERSION
index ae51b49..d3bfa59 100644
--- a/subprojects/nk_pugl/VERSION
+++ b/subprojects/nk_pugl/VERSION
@@ -1 +1 @@
-0.1.169
+0.1.173
diff --git a/subprojects/nk_pugl/example/example.c b/subprojects/nk_pugl/example/example.c
index 1c505da..c55a2ca 100644
--- a/subprojects/nk_pugl/example/example.c
+++ b/subprojects/nk_pugl/example/example.c
@@ -53,8 +53,10 @@ main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
static nk_pugl_window_t win;
nk_pugl_config_t *cfg = &win.cfg;
- cfg->width = 1280;
- cfg->height = 720;
+ const float scale = nk_pugl_get_scale();
+
+ cfg->width = 1280 * scale;
+ cfg->height = 720 * scale;
cfg->resizable = true;
cfg->parent = 0;
cfg->threads = false;
@@ -64,7 +66,7 @@ main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
cfg->expose = _expose;
cfg->data = NULL;
cfg->font.face = "./Cousine-Regular.ttf";
- cfg->font.size = 13;
+ cfg->font.size = 13 * scale;
signal(SIGTERM, _sigint);
signal(SIGINT, _sigint);
diff --git a/subprojects/nk_pugl/nk_pugl/nk_pugl.h b/subprojects/nk_pugl/nk_pugl/nk_pugl.h
index 43b124e..58fce93 100644
--- a/subprojects/nk_pugl/nk_pugl/nk_pugl.h
+++ b/subprojects/nk_pugl/nk_pugl/nk_pugl.h
@@ -107,7 +107,6 @@ struct _nk_pugl_config_t {
struct _nk_pugl_window_t {
nk_pugl_config_t cfg;
char urn [46];
- float scale;
PuglWorld *world;
PuglView *view;
@@ -134,7 +133,6 @@ struct _nk_pugl_window_t {
PuglMod state;
#if !defined(__APPLE__) && !defined(_WIN32)
atomic_flag async;
- Display *disp;
#endif
};
@@ -184,7 +182,7 @@ NK_PUGL_API const char *
nk_pugl_paste_from_clipboard(nk_pugl_window_t *win, size_t *len);
NK_PUGL_API float
-nk_pugl_get_scale(nk_pugl_window_t *win);
+nk_pugl_get_scale();
#ifdef __cplusplus
}
@@ -451,7 +449,7 @@ _nk_pugl_font_init(nk_pugl_window_t *win)
{
nk_pugl_config_t *cfg = &win->cfg;
- const int font_size = cfg->font.size * win->scale;
+ const int font_size = cfg->font.size;
// init nuklear font
struct nk_font *ttf = NULL;
@@ -969,57 +967,8 @@ nk_pugl_init(nk_pugl_window_t *win)
nk_pugl_config_t *cfg = &win->cfg;
struct nk_convert_config *conv = &win->conv;
- const char *NK_SCALE = getenv("NK_SCALE");
- const float scale = NK_SCALE ? atof(NK_SCALE) : 1.f;
- const float dpi0 = 96.f; // reference DPI we're designing for
-
-#if defined(__APPLE__)
- const float dpi1 = dpi0; //TODO implement this
-#elif defined(_WIN32)
- // GetDpiForSystem/Monitor/Window is Win10 only
- HDC screen = GetDC(NULL);
- const float dpi1 = GetDeviceCaps(screen, LOGPIXELSX);
- ReleaseDC(NULL, screen);
-#else
- win->async = (atomic_flag)ATOMIC_FLAG_INIT;
- win->disp = XOpenDisplay(0);
- // modern X actually lies here, but proprietary nvidia
- float dpi1 = XDisplayWidth(win->disp, 0) * 25.4f / XDisplayWidthMM(win->disp, 0);
-
- // read DPI from users's ~/.Xresources
- char *resource_string = XResourceManagerString(win->disp);
- XrmInitialize();
- if(resource_string)
- {
- XrmDatabase db = XrmGetStringDatabase(resource_string);
- if(db)
- {
- char *type = NULL;
- XrmValue value;
-
- XrmGetResource(db, "Xft.dpi", "String", &type, &value);
- if(value.addr)
- {
- dpi1 = atof(value.addr);
- }
-
- XrmDestroyDatabase(db);
- }
- }
-#endif
-
- win->scale = scale * dpi1 / dpi0;
- if(win->scale < 0.5)
- {
- win->scale = 0.5;
- }
win->has_left = true;
- cfg->width *= win->scale;
- cfg->height *= win->scale;
- cfg->min_width *= win->scale;
- cfg->min_height *= win->scale;
-
// init pugl
win->world = puglNewWorld(cfg->parent ? PUGL_MODULE : PUGL_PROGRAM,
cfg->threads ? PUGL_WORLD_THREADS : 0);
@@ -1166,13 +1115,6 @@ nk_pugl_shutdown(nk_pugl_window_t *win)
puglFreeWorld(win->world);
}
-
-#if !defined(__APPLE__) && !defined(_WIN32)
- if(win->disp)
- {
- XCloseDisplay(win->disp);
- }
-#endif
}
NK_PUGL_API void
@@ -1242,10 +1184,11 @@ nk_pugl_async_redisplay(nk_pugl_window_t *win)
const int status = SendNotifyMessage(widget, WM_PAINT, 0, 0);
(void)status;
#else
+ Display *disp = puglGetNativeWorld(win->world);
const Window widget = (Window)win->widget;
XExposeEvent xevent = {
.type = Expose,
- .display = win->disp,
+ .display = disp,
.window = widget
};
@@ -1254,10 +1197,10 @@ nk_pugl_async_redisplay(nk_pugl_window_t *win)
// spin
}
- const Status status = XSendEvent(win->disp, widget, false, ExposureMask,
+ const Status status = XSendEvent(disp, widget, false, ExposureMask,
(XEvent *)&xevent);
(void)status;
- XFlush(win->disp);
+ XFlush(disp);
atomic_flag_clear_explicit(&win->async, memory_order_release);
#endif
@@ -1377,9 +1320,53 @@ nk_pugl_paste_from_clipboard(nk_pugl_window_t *win, size_t *len)
}
NK_PUGL_API float
-nk_pugl_get_scale(nk_pugl_window_t *win)
+nk_pugl_get_scale()
{
- return win->scale;
+ const char *NK_SCALE = getenv("NK_SCALE");
+ const float scale = NK_SCALE ? atof(NK_SCALE) : 1.f;
+ const float dpi0 = 96.f; // reference DPI we're designing for
+ float dpi1 = dpi0;
+
+#if defined(__APPLE__)
+ // FIXME
+#elif defined(_WIN32)
+ // GetDpiForSystem/Monitor/Window is Win10 only
+ HDC screen = GetDC(NULL);
+ dpi1 = GetDeviceCaps(screen, LOGPIXELSX);
+ ReleaseDC(NULL, screen);
+#else
+ Display *disp = XOpenDisplay(0);
+ if(disp)
+ {
+ // modern X actually lies here, but proprietary nvidia
+ dpi1 = XDisplayWidth(disp, 0) * 25.4f / XDisplayWidthMM(disp, 0);
+
+ // read DPI from users's ~/.Xresources
+ char *resource_string = XResourceManagerString(disp);
+ XrmInitialize();
+ if(resource_string)
+ {
+ XrmDatabase db = XrmGetStringDatabase(resource_string);
+ if(db)
+ {
+ char *type = NULL;
+ XrmValue value;
+
+ XrmGetResource(db, "Xft.dpi", "String", &type, &value);
+ if(value.addr)
+ {
+ dpi1 = atof(value.addr);
+ }
+
+ XrmDestroyDatabase(db);
+ }
+ }
+
+ XCloseDisplay(disp);
+ }
+#endif
+
+ return scale * dpi1 / dpi0;
}
#ifdef __cplusplus