diff options
author | Jonathon Jongsma <jjongsma@redhat.com> | 2014-09-30 11:24:18 -0500 |
---|---|---|
committer | Jonathon Jongsma <jjongsma@redhat.com> | 2014-10-27 10:37:31 -0500 |
commit | 8fa5e004ec7e66ab0ca6e8443271e09425e4a1a1 (patch) | |
tree | f95a3cfb4b7dfa550039e335c2505712de440927 /src/virt-viewer-util.c | |
parent | 221d5f5cd44b73fe1fc3c28a944744bd791af631 (diff) | |
download | virt-viewer-8fa5e004ec7e66ab0ca6e8443271e09425e4a1a1.tar.gz virt-viewer-8fa5e004ec7e66ab0ca6e8443271e09425e4a1a1.tar.xz virt-viewer-8fa5e004ec7e66ab0ca6e8443271e09425e4a1a1.zip |
Shift top-left display to origin
When using a custom fullscreen display configuration, it's possible to
specify that e.g. a single screen should be fullscreen on client
monitor #4. Since we send down absolute positions and disable alignment
when all windows are in fullscreen, we can send configurations with a
very large offset to the top-left corner. This could result in the guest
trying to create a screen that was much larger than necessary. For
example when sending a configuration of 1280x1024+4240+0, the guest
would need to allocate a screen of size 5520x1024, which might fail if
video memory was too low. To avoid this issue, we shift all displays
so that the minimum X coordinate for all screens is at x=0, and the
minimum y coordinate is at y=0.
Diffstat (limited to 'src/virt-viewer-util.c')
-rw-r--r-- | src/virt-viewer-util.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/virt-viewer-util.c b/src/virt-viewer-util.c index c46d07d..aec3b77 100644 --- a/src/virt-viewer-util.c +++ b/src/virt-viewer-util.c @@ -538,6 +538,48 @@ virt_viewer_align_monitors_linear(GdkRectangle *displays, guint ndisplays) g_free(sorted_displays); } +/* Shift all displays so that the monitor origin is at (0,0). This reduces the + * size of the screen that will be required on the guest when all client + * monitors are fullscreen but do not begin at the origin. For example, instead + * of sending down the following configuration: + * 1280x1024+4240+0 + * (which implies that the guest screen must be at least 5520x1024), we'd send + * 1280x1024+0+0 + * (which implies the guest screen only needs to be 1280x1024). The first + * version might fail if the guest video memory is not large enough to handle a + * screen of that size. + */ +void +virt_viewer_shift_monitors_to_origin(GdkRectangle *displays, guint ndisplays) +{ + gint xmin = G_MAXINT; + gint ymin = G_MAXINT; + gint i; + + g_return_if_fail(ndisplays > 0); + + for (i = 0; i < ndisplays; i++) { + GdkRectangle *display = &displays[i]; + if (display->width > 0 && display->height > 0) { + xmin = MIN(xmin, display->x); + ymin = MIN(ymin, display->y); + } + } + g_return_if_fail(xmin < G_MAXINT && ymin < G_MAXINT); + + if (xmin > 0 || ymin > 0) { + g_debug("%s: Shifting all monitors by (%i, %i)", G_STRFUNC, xmin, ymin); + for (i = 0; i < ndisplays; i++) { + GdkRectangle *display = &displays[i]; + if (display->width > 0 && display->height > 0) { + display->x -= xmin; + display->y -= ymin; + } + } + } +} + + /* * Local variables: * c-indent-level: 4 |