src: enable remote desktop resize with VNC
GTK-VNC has native support for remote desktop resize, provided that we
always give the widget the full available allocation. This requires that
we turn off VirtViewerDisplay's code for keeping aspect ratio, and
instead enable GTK-VNC's equivalent.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Daniel P. Berrangé
3 years ago
23 | 23 | |
24 | 24 | #include <config.h> |
25 | 25 | |
26 | #include <gvnc.h> | |
27 | ||
26 | 28 | #include "virt-viewer-auth.h" |
27 | 29 | #include "virt-viewer-display-vnc.h" |
28 | 30 | #include "virt-viewer-util.h" |
29 | 31 | |
30 | 32 | #include <glib/gi18n.h> |
33 | ||
34 | #ifndef VNC_CHECK_VERSION | |
35 | # define VNC_CHECK_VERSION(a, b, c) 0 | |
36 | #endif | |
37 | #if VNC_CHECK_VERSION(1, 2, 0) | |
38 | # define HAVE_VNC_REMOTE_RESIZE | |
39 | #endif | |
31 | 40 | |
32 | 41 | struct _VirtViewerDisplayVnc { |
33 | 42 | VirtViewerDisplay parent; |
209 | 218 | vnc_display_set_grab_keys(vnc, NULL); |
210 | 219 | } |
211 | 220 | } |
221 | ||
222 | ||
223 | #ifdef HAVE_VNC_REMOTE_RESIZE | |
224 | static void | |
225 | resize_policy_changed(VirtViewerDisplayVnc *self, | |
226 | GParamSpec *pspec G_GNUC_UNUSED, | |
227 | VncDisplay *vnc) | |
228 | { | |
229 | gboolean enable = virt_viewer_display_get_auto_resize(VIRT_VIEWER_DISPLAY(self)); | |
230 | ||
231 | vnc_display_set_allow_resize(vnc, enable); | |
232 | } | |
233 | ||
234 | static void | |
235 | zoom_level_changed(VirtViewerDisplay *display, | |
236 | GParamSpec *pspec G_GNUC_UNUSED, | |
237 | VncDisplay *vnc) | |
238 | { | |
239 | guint zoom = virt_viewer_display_get_zoom_level(display); | |
240 | ||
241 | vnc_display_set_zoom(vnc, zoom); | |
242 | } | |
243 | #endif | |
212 | 244 | |
213 | 245 | |
214 | 246 | GtkWidget * |
239 | 271 | vnc_display_set_force_size(self->vnc, FALSE); |
240 | 272 | vnc_display_set_scaling(self->vnc, TRUE); |
241 | 273 | |
274 | #ifdef HAVE_VNC_REMOTE_RESIZE | |
275 | vnc_display_set_keep_aspect_ratio(self->vnc, TRUE); | |
276 | g_object_set(self, "force-aspect", FALSE, NULL); | |
277 | #endif | |
278 | ||
242 | 279 | /* When VNC desktop resizes, we have to resize the containing widget */ |
243 | 280 | g_signal_connect(self->vnc, "vnc-desktop-resize", |
244 | 281 | G_CALLBACK(virt_viewer_display_vnc_resize_desktop), self); |
259 | 296 | G_CALLBACK(enable_accel_changed), self->vnc, 0); |
260 | 297 | enable_accel_changed(app, NULL, self->vnc); |
261 | 298 | |
299 | #ifdef HAVE_VNC_REMOTE_RESIZE | |
300 | virt_viewer_signal_connect_object(self, "notify::auto-resize", | |
301 | G_CALLBACK(resize_policy_changed), self->vnc, 0); | |
302 | virt_viewer_signal_connect_object(self, "notify::zoom-level", | |
303 | G_CALLBACK(zoom_level_changed), self->vnc, 0); | |
304 | resize_policy_changed(self, NULL, self->vnc); | |
305 | #endif | |
306 | ||
262 | 307 | return GTK_WIDGET(self); |
263 | 308 | } |
264 | 309 |