ui: fix incorrect pointer position on highdpi with gtk

Signed-off-by: Alexander Orzechowski <orzechowski.alexander@gmail.com>
Message-Id: <20211121065504.29101-3-orzechowski.alexander@gmail.com>

[ kraxel: codestyle fix ]

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Alexander Orzechowski 2021-11-21 01:55:04 -05:00 committed by Gerd Hoffmann
parent 4323118cad
commit f14aab420c
1 changed files with 8 additions and 5 deletions

View File

@ -838,10 +838,11 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
{ {
VirtualConsole *vc = opaque; VirtualConsole *vc = opaque;
GtkDisplayState *s = vc->s; GtkDisplayState *s = vc->s;
GdkWindow *window;
int x, y; int x, y;
int mx, my; int mx, my;
int fbh, fbw; int fbh, fbw;
int ww, wh; int ww, wh, ws;
if (!vc->gfx.ds) { if (!vc->gfx.ds) {
return TRUE; return TRUE;
@ -850,8 +851,10 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
fbw = surface_width(vc->gfx.ds) * vc->gfx.scale_x; fbw = surface_width(vc->gfx.ds) * vc->gfx.scale_x;
fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y; fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
ww = gdk_window_get_width(gtk_widget_get_window(vc->gfx.drawing_area)); window = gtk_widget_get_window(vc->gfx.drawing_area);
wh = gdk_window_get_height(gtk_widget_get_window(vc->gfx.drawing_area)); ww = gdk_window_get_width(window);
wh = gdk_window_get_height(window);
ws = gdk_window_get_scale_factor(window);
mx = my = 0; mx = my = 0;
if (ww > fbw) { if (ww > fbw) {
@ -861,8 +864,8 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
my = (wh - fbh) / 2; my = (wh - fbh) / 2;
} }
x = (motion->x - mx) / vc->gfx.scale_x; x = (motion->x - mx) / vc->gfx.scale_x * ws;
y = (motion->y - my) / vc->gfx.scale_y; y = (motion->y - my) / vc->gfx.scale_y * ws;
if (qemu_input_is_absolute()) { if (qemu_input_is_absolute()) {
if (x < 0 || y < 0 || if (x < 0 || y < 0 ||