qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ui/sdl: Mouse event optimization
@ 2024-10-25  6:52 Lei Huang
  2024-10-25  9:30 ` BALATON Zoltan
  0 siblings, 1 reply; 10+ messages in thread
From: Lei Huang @ 2024-10-25  6:52 UTC (permalink / raw)
  To: marcandre.lureau
  Cc: qemu-devel, pierre-eric.pelloux-prayer, ken.xue, lei.huang,
	Lei Huang

Use a convergence factor to make the VM's input
global coordinates more closely approach the global
coordinates of DOM0.

Change-Id: I2c3f12f1fe7dfb9306d1fc40c4fd4d299937f4c6
Signed-off-by: Lei Huang <Lei.Huang@amd.com>
---
 ui/sdl2.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/ui/sdl2.c b/ui/sdl2.c
index bd4f5a9da14..8f504dd8727 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -303,6 +303,34 @@ static void sdl_mouse_mode_change(Notifier *notify, void *data)
     }
 }
 
+/*
+ *guest_x and guest_y represent the global coordinates on the VM side,
+ *while x and y represent the global coordinates on the dom0 side.
+ *The goal of this entire process is to align the global coordinates of
+ *the VM with those of dom0 using dx and dy. The current approach aims
+ *for precise calibration in once attempt; however, because guest_x
+ *and guest_y are non-zero values, they are not accurate values when
+ *they are counted out to become negative.Therefore, achieving perfect
+ *alignment in one attempt is impossible.Since the same calibration method
+ *is used each time, repeated attempts cannot achieve alignment either.
+ *By introducing a convergence factor, guest_x and guest_y can be made to
+ *approach dom0's x and y indefinitely.
+ *
+ *                   QEMU                       (dx,dy)  VM
+ *calculates dx and dy using guest_x and guest_y ---->  input driver
+ *           ^                                            |
+ *           |                                            |
+ *           |                                            V
+ *           |     update
+ *           | guest_x,guest_y              input dispatcher ---> WindowManager
+ *           |                                            |                 |
+ *           |                                            |                 |
+ *           |                 libdrm                     V                 |
+ *       virtio-gpu  <------ drmModeMoveCursor <------ compositor <-------  |
+ *                           (guest_x,guest_y)   calculates guest_x and
+ *                                               guest_y dy using dx and dy
+ */
+#define CONVERGENCE_FACTOR 3
 static void sdl_send_mouse_event(struct sdl2_console *scon, int dx, int dy,
                                  int x, int y, int state)
 {
@@ -331,8 +359,8 @@ static void sdl_send_mouse_event(struct sdl2_console *scon, int dx, int dy,
             y -= guest_y;
             guest_x += x;
             guest_y += y;
-            dx = x;
-            dy = y;
+            dx = x / CONVERGENCE_FACTOR;
+            dy = y / CONVERGENCE_FACTOR;
         }
         qemu_input_queue_rel(scon->dcl.con, INPUT_AXIS_X, dx);
         qemu_input_queue_rel(scon->dcl.con, INPUT_AXIS_Y, dy);
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-11-01  1:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-25  6:52 [PATCH] ui/sdl: Mouse event optimization Lei Huang
2024-10-25  9:30 ` BALATON Zoltan
2024-10-29  6:08   ` Lei Huang
2024-10-29 12:51     ` BALATON Zoltan
2024-10-30  3:20       ` Lei Huang
2024-10-30  3:43         ` [PATCH v2] " Lei Huang
2024-10-30 13:38           ` BALATON Zoltan
2024-10-31  8:13             ` Lei Huang
2024-10-31 12:50               ` BALATON Zoltan
2024-11-01  1:24                 ` Lei Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).