[Spice-devel] [PATCH linux vdagent v2 3/9] Look up and store xrandr output in display map
Jonathon Jongsma
jjongsma at redhat.com
Thu Jan 3 22:45:42 UTC 2019
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 | 47 +++++++++++++++++++----------------------
src/vdagent/x11.c | 20 ++++++------------
3 files changed, 30 insertions(+), 39 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 4a5c7e4..b1c1b9d 100644
--- a/src/vdagent/x11-randr.c
+++ b/src/vdagent/x11-randr.c
@@ -727,11 +727,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)
@@ -752,31 +747,33 @@ void vdagent_x11_handle_graphics_device_info(struct vdagent_x11 *x11, uint8_t *d
break;
}
- GraphicsDisplayInfo *value = g_malloc(sizeof(GraphicsDisplayInfo));
-
- size_t device_address_len = device_display_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);
- }
+ // make sure the string is terminated:
+ device_display_info->device_address[device_display_info->device_address_len] = '\0';
- strncpy(value->device_address,
- (char*) device_display_info->device_address,
- device_address_len);
- value->device_address[device_address_len] = '\0'; // make sure the string is terminated
- value->device_display_id = device_display_info->device_display_id;
+ RROutput x_output;
+ if (lookup_xrandr_output_for_device_info(device_display_info, x11->randr.res, &x_output)) {
+ gint64 *value = g_new(gint64, 1);
+ *value = x_output;
- syslog(LOG_INFO, " channel_id: %u monitor_id: %u device_address: %s, "
- "device_display_id: %u",
- device_display_info->channel_id,
- device_display_info->monitor_id,
- value->device_address,
- value->device_display_id);
+ syslog(LOG_INFO, " channel_id: %u monitor_id: %u device_address: %s, "
+ "device_display_id: %u xrandr output ID: %lu",
+ device_display_info->channel_id,
+ device_display_info->monitor_id,
+ device_display_info->device_address,
+ device_display_info->device_display_id,
+ x_output);
- g_hash_table_insert(x11->graphics_display_infos,
+ g_hash_table_insert(x11->guest_output_map,
GUINT_TO_POINTER(device_display_info->channel_id + device_display_info->monitor_id),
value);
+ } else {
+ syslog(LOG_INFO, " channel_id: %u monitor_id: %u device_address: %s, "
+ "device_display_id: %u xrandr output ID NOT FOUND",
+ device_display_info->channel_id,
+ device_display_info->monitor_id,
+ device_display_info->device_address,
+ device_display_info->device_display_id);
+ }
device_display_info = (VDAgentDeviceDisplayInfo*) ((char*) device_display_info +
sizeof(VDAgentDeviceDisplayInfo) + device_display_info->device_address_len);
diff --git a/src/vdagent/x11.c b/src/vdagent/x11.c
index 9d979fc..7638085 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)
{
@@ -220,6 +214,12 @@ struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
x11->vdagentd = vdagentd;
x11->debug = debug;
+ x11->guest_output_map = g_hash_table_new_full(&g_direct_hash,
+ &g_direct_equal,
+ NULL,
+ &g_free);
+
+
x11->display = XOpenDisplay(NULL);
if (!x11->display) {
syslog(LOG_ERR, "could not connect to X-server");
@@ -324,12 +324,6 @@ 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,
- &g_direct_equal,
- NULL,
- &graphics_display_info_destroy);
-
-
/* Flush output buffers and consume any pending events */
vdagent_x11_do_read(x11);
@@ -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
More information about the Spice-devel
mailing list