Skip to content

Commit

Permalink
demos: fix cursor position on glfw high dpi
Browse files Browse the repository at this point in the history
In particular, macOS.
  • Loading branch information
haasn committed Nov 18, 2021
1 parent d01f97c commit 93d05c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion demos/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if glfw.found()
if comps.has('vulkan')
conf_demos.set('HAVE_GLFW_VULKAN', true)
apis += static_library('glfw-vk',
dependencies: [libplacebo, glfw, vulkan_headers],
dependencies: [libplacebo, libm, glfw, vulkan_headers],
sources: 'window_glfw.c',
c_args: '-DUSE_VK',
)
Expand Down
8 changes: 6 additions & 2 deletions demos/window_glfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#endif

#include <string.h>
#include <math.h>

#include "common.h"
#include "window.h"
Expand Down Expand Up @@ -377,9 +378,12 @@ static void glfw_get_cursor(const struct window *window, int *x, int *y)
{
struct priv *p = (struct priv *) window;
double dx, dy;
int fw, fh, ww, wh;
glfwGetCursorPos(p->win, &dx, &dy);
*x = dx;
*y = dy;
glfwGetFramebufferSize(p->win, &fw, &fh);
glfwGetWindowSize(p->win, &ww, &wh);
*x = floor(dx * fw / ww);
*y = floor(dy * fh / wh);
}

static bool glfw_get_button(const struct window *window, enum button btn)
Expand Down

0 comments on commit 93d05c4

Please sign in to comment.