diff mbox series

[v1,2/2] ui/gtk: Include the position info while setting the ui info

Message ID 20221118013723.182424-3-vivek.kasireddy@intel.com (mailing list archive)
State New, archived
Headers show
Series virtio-gpu: Provide display position info (x, y) to the Guest | expand

Commit Message

Kasireddy, Vivek Nov. 18, 2022, 1:37 a.m. UTC
In situtations where the Guest uses multiple displays/outputs, this
position info is useful for aligning the Guest's outputs with that of
the Host's.

Cc: Dongwon Kim <dongwon.kim@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
---
 ui/gtk.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
diff mbox series

Patch

diff --git a/ui/gtk.c b/ui/gtk.c
index 92daaa6a6e..12b3bc6481 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -714,12 +714,31 @@  static gboolean gd_window_close(GtkWidget *widget, GdkEvent *event,
     return TRUE;
 }
 
+static void gd_set_ui_window_position(VirtualConsole *vc, QemuUIInfo *info)
+{
+    GdkDisplay *dpy = gtk_widget_get_display(vc->gfx.drawing_area);
+    GdkWindow *window;
+    GdkMonitor *monitor;
+    GdkRectangle geometry;
+
+    if (!gtk_widget_get_realized(vc->gfx.drawing_area)) {
+        return;
+    }
+
+    window = gtk_widget_get_window(vc->gfx.drawing_area);
+    monitor = gdk_display_get_monitor_at_window(dpy, window);
+    gdk_monitor_get_geometry(monitor, &geometry);
+    info->xoff = geometry.x;
+    info->yoff = geometry.y;
+}
+
 static void gd_set_ui_refresh_rate(VirtualConsole *vc, int refresh_rate)
 {
     QemuUIInfo info;
 
     info = *dpy_get_ui_info(vc->gfx.dcl.con);
     info.refresh_rate = refresh_rate;
+    gd_set_ui_window_position(vc, &info);
     dpy_set_ui_info(vc->gfx.dcl.con, &info, true);
 }
 
@@ -730,6 +749,7 @@  static void gd_set_ui_size(VirtualConsole *vc, gint width, gint height)
     info = *dpy_get_ui_info(vc->gfx.dcl.con);
     info.width = width;
     info.height = height;
+    gd_set_ui_window_position(vc, &info);
     dpy_set_ui_info(vc->gfx.dcl.con, &info, true);
 }