Skip to contentSkip to conversation

Fix trivial errors with highdpi/wayland

PATCH In review Alexander Orzechowski 2 participants 5 messages Nov 21, 2021 – Nov 22, 2021

lore
Share & tools
lore
#0 lore raw

cover Fix trivial errors with highdpi/wayland

Hi, this patch series is ment to fix two problems with highdpi/wayland with gtk that makes the program unusuable. As it stands currently:
The virtual machine window will only render in the bottom-left quarter of the screen (with 2x scaling) while using the gtk,gl=on and virtgl backend. This also fixes the --usbdevice tablet option as before if the pointer would click in the incorrect spot of the virtual machine then was expected.

Alexander Orzechowski (2):
ui: fix incorrect scaling on highdpi with gtk/opengl
ui: fix incorrect pointer position on highdpi with gtk

 ui/gtk-gl-area.c |  7 ++++---
 ui/gtk.c         | 13 ++++++++-----
 2 files changed, 12 insertions(+), 8 deletions(-)
Signature · 1 line
2.34.0
#1 lore raw

PATCH 1/2 ui: fix incorrect scaling on highdpi with gtk/opengl

---
 ui/gtk-gl-area.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
ui/gtk-gl-area.c +4 -3
index 461da7712f..d3565698ae 100644
@@ -41,15 +41,16 @@ void gd_gl_area_draw(VirtualConsole *vc)
 #ifdef CONFIG_GBM
     QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf;
 #endif
-    int ww, wh, y1, y2;
+    int ww, wh, ws, y1, y2;
 
     if (!vc->gfx.gls) {
         return;
     }
 
     gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
-    ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area);
-    wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area);
+    ws = gdk_window_get_scale_factor (gtk_widget_get_window(vc->gfx.drawing_area));
+    ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area) * ws;
+    wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area) * ws;
 
     if (vc->gfx.scanout_mode) {
         if (!vc->gfx.guest_fb.framebuffer) {
Signature · 1 line
2.34.0
#3 lore raw

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

In reply to Alexander Orzechowski
---
 ui/gtk.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
ui/gtk.c +8 -5
index d2892ea6b4..b2670142b5 100644
@@ -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 ||
Signature · 1 line
2.34.0
#4 lore raw

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

Quoted 23 lines · Alexander Orzechowski
---
 ui/gtk.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
ui/gtk.c +2 -1
index d2892ea6b4..b2670142b5 100644
@@ -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;

ui/gtk.c static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion, · line 857

Quoted 9 lines
ui/gtk.c +4 -2
@@ -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.