diff mbox series

[2/2] ui: fix incorrect pointer position on highdpi with gtk

Message ID 20211121065504.29101-3-orzechowski.alexander@gmail.com
State New
Headers show
Series Fix trivial errors with highdpi/wayland | expand

Commit Message

Alexander Orzechowski Nov. 21, 2021, 6:55 a.m. UTC
Signed-off-by: Alexander Orzechowski <orzechowski.alexander@gmail.com>
---
 ui/gtk.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Philippe Mathieu-Daudé Nov. 22, 2021, 12:15 p.m. UTC | #1
On 11/21/21 07:55, Alexander Orzechowski wrote:
> Signed-off-by: Alexander Orzechowski <orzechowski.alexander@gmail.com>
> ---
>  ui/gtk.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/ui/gtk.c b/ui/gtk.c
> index d2892ea6b4..b2670142b5 100644
> --- a/ui/gtk.c
> +++ b/ui/gtk.c
> @@ -838,10 +838,11 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
>  {
>      VirtualConsole *vc = opaque;
>      GtkDisplayState *s = vc->s;
> +    GdkWindow *window;
>      int x, y;
>      int mx, my;
>      int fbh, fbw;
> -    int ww, wh;
> +    int ww, wh, ws;
>  
>      if (!vc->gfx.ds) {
>          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;
>      fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
>  
> -    ww = gdk_window_get_width(gtk_widget_get_window(vc->gfx.drawing_area));
> -    wh = gdk_window_get_height(gtk_widget_get_window(vc->gfx.drawing_area));
> +    window = 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);

Please follow the coding style and remove the extra space.

Otherwise LGTM.
diff mbox series

Patch

diff --git a/ui/gtk.c b/ui/gtk.c
index d2892ea6b4..b2670142b5 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -838,10 +838,11 @@  static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
 {
     VirtualConsole *vc = opaque;
     GtkDisplayState *s = vc->s;
+    GdkWindow *window;
     int x, y;
     int mx, my;
     int fbh, fbw;
-    int ww, wh;
+    int ww, wh, ws;
 
     if (!vc->gfx.ds) {
         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;
     fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
 
-    ww = gdk_window_get_width(gtk_widget_get_window(vc->gfx.drawing_area));
-    wh = gdk_window_get_height(gtk_widget_get_window(vc->gfx.drawing_area));
+    window = 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;
     if (ww > fbw) {
@@ -861,8 +864,8 @@  static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
         my = (wh - fbh) / 2;
     }
 
-    x = (motion->x - mx) / vc->gfx.scale_x;
-    y = (motion->y - my) / vc->gfx.scale_y;
+    x = (motion->x - mx) / vc->gfx.scale_x * ws;
+    y = (motion->y - my) / vc->gfx.scale_y * ws;
 
     if (qemu_input_is_absolute()) {
         if (x < 0 || y < 0 ||