[PATCH linux vdagent 05/10] Look up and store xrandr output in display map

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Instead of storing each device address and device display ID in the hash
table, simply use the lookup_xrandr_output_for_device_info() function to
look up the ID of the xrandr output and store that in the hash table.
---
 src/vdagent/x11-priv.h  |  2 +-
 src/vdagent/x11-randr.c | 27 +++++++++------------------
 src/vdagent/x11.c       | 12 +++---------
 3 files changed, 13 insertions(+), 28 deletions(-)

diff --git a/src/vdagent/x11-priv.h b/src/vdagent/x11-priv.h
index 5b1eff3..769a64b 100644
--- a/src/vdagent/x11-priv.h
+++ b/src/vdagent/x11-priv.h
@@ -143,7 +143,7 @@ struct vdagent_x11 {
     int xrandr_minor;
     int has_xinerama;
     int dont_send_guest_xorg_res;
-    GHashTable *graphics_display_infos;
+    GHashTable *guest_output_map;
 };
 
 extern int (*vdagent_x11_prev_error_handler)(Display *, XErrorEvent *);
diff --git a/src/vdagent/x11-randr.c b/src/vdagent/x11-randr.c
index 72e43a8..2368e17 100644
--- a/src/vdagent/x11-randr.c
+++ b/src/vdagent/x11-randr.c
@@ -719,11 +719,6 @@ static void dump_monitors_config(struct vdagent_x11 *x11,
     }
 }
 
-typedef struct GraphicsDisplayInfo {
-    char device_address[256];
-    uint32_t device_display_id;
-} GraphicsDisplayInfo;
-
 // handle the device info message from the server. This will allow us to
 // maintain a mapping from spice display id to xrandr output
 void vdagent_x11_handle_graphics_device_info(struct vdagent_x11 *x11, uint8_t *data, size_t size)
@@ -751,22 +746,18 @@ void vdagent_x11_handle_graphics_device_info(struct vdagent_x11 *x11, uint8_t *d
                graphics_device_info->device_address,
                graphics_device_info->device_display_id);
 
-        GraphicsDisplayInfo *value = g_malloc(sizeof(GraphicsDisplayInfo));
-
-        size_t device_address_len = graphics_device_info->device_address_len;
-        if (device_address_len > sizeof(value->device_address)) {
-            syslog(LOG_ERR, "Received a device address longer than %lu, "
-                   "will be truncated!", device_address_len);
-            device_address_len = sizeof(value->device_address);
+        RROutput x_output;
+        if (!lookup_xrandr_output_for_device_info(graphics_device_info, &x_output)) {
+            syslog(LOG_ERR, "Unable to find the Xrandr output for device %s id %i",
+                   graphics_device_info->device_address,
+                   graphics_device_info->device_display_id);
+            continue;
         }
 
-        strncpy(value->device_address,
-                (char*) graphics_device_info->device_address,
-                device_address_len);
-        value->device_address[device_address_len] = '\0';  // make sure the string is terminated
-        value->device_display_id = graphics_device_info->device_display_id;
+        gint64 *value = g_new(gint64, 1);
+        *value = x_output;
 
-        g_hash_table_insert(x11->graphics_display_infos,
+        g_hash_table_insert(x11->guest_output_map,
                 GUINT_TO_POINTER(graphics_device_info->channel_id + graphics_device_info->monitor_id),
                 value);
 
diff --git a/src/vdagent/x11.c b/src/vdagent/x11.c
index 9d979fc..c003a36 100644
--- a/src/vdagent/x11.c
+++ b/src/vdagent/x11.c
@@ -198,12 +198,6 @@ static gchar *vdagent_x11_get_wm_name(struct vdagent_x11 *x11)
 #endif
 }
 
-static void graphics_display_info_destroy(gpointer gdi)
-{
-    g_free(gdi);
-}
-
-
 struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
     int debug, int sync)
 {
@@ -324,10 +318,10 @@ struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
                __func__, net_wm_name, vdagent_x11_has_icons_on_desktop(x11));
     g_free(net_wm_name);
 
-    x11->graphics_display_infos = g_hash_table_new_full(&g_direct_hash,
+    x11->guest_output_map = g_hash_table_new_full(&g_direct_hash,
                                                   &g_direct_equal,
                                                   NULL,
-                                                  &graphics_display_info_destroy);
+                                                  &g_free);
 
 
     /* Flush output buffers and consume any pending events */
@@ -351,7 +345,7 @@ void vdagent_x11_destroy(struct vdagent_x11 *x11, int vdagentd_disconnected)
     }
 #endif
 
-    g_hash_table_destroy(x11->graphics_display_infos);
+    g_hash_table_destroy(x11->guest_output_map);
     XCloseDisplay(x11->display);
     g_free(x11->randr.failed_conf);
     g_free(x11);
-- 
2.17.2

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]