Codebase list virt-viewer / 20f5b18
src: add prop to control forced aspect ratio When the VirtViewerDisplay class resizes the child display widget, it attempts to preserve the remote desktop aspect ratio. This is useful in general, if the display widget can't do this itself. The implication, however, is that VirtViewerDisplay also has to take ownership of the remote framebuffer resize functionality. It is thus useful to disable VirtViewerDisplay's aspect ratio preservation when the display widget can do this natively, as it can then also do desktop resizes natively. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Daniel P. Berrangé 3 years ago
1 changed file(s) with 30 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
4242 VirtViewerSession *session;
4343 gboolean fullscreen;
4444 gboolean auto_resize;
45 gboolean force_aspect;
4546 };
4647
4748 static void virt_viewer_display_get_preferred_width(GtkWidget *widget,
7778 PROP_SELECTABLE,
7879 PROP_MONITOR,
7980 PROP_AUTO_RESIZE,
81 PROP_FORCE_ASPECT,
8082 };
8183
8284 static void
188190 G_PARAM_READABLE |
189191 G_PARAM_WRITABLE));
190192
193 g_object_class_install_property(object_class,
194 PROP_FORCE_ASPECT,
195 g_param_spec_boolean("force-aspect",
196 "Force aspect",
197 "Force aspect ratio for widget",
198 TRUE,
199 G_PARAM_READABLE |
200 G_PARAM_WRITABLE));
201
191202 g_signal_new("display-pointer-grab",
192203 G_OBJECT_CLASS_TYPE(object_class),
193204 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS,
259270 priv->desktopWidth = MIN_DISPLAY_WIDTH;
260271 priv->desktopHeight = MIN_DISPLAY_HEIGHT;
261272 priv->zoom_level = NORMAL_ZOOM_LEVEL;
273 priv->force_aspect = TRUE;
262274 }
263275
264276 GtkWidget*
296308 case PROP_AUTO_RESIZE:
297309 priv->auto_resize = g_value_get_boolean(value);
298310 break;
311 case PROP_FORCE_ASPECT:
312 priv->force_aspect = g_value_get_boolean(value);
313 break;
299314
300315 default:
301316 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
339354 break;
340355 case PROP_AUTO_RESIZE:
341356 g_value_set_boolean(value, virt_viewer_display_get_auto_resize(display));
357 break;
358 case PROP_FORCE_ASPECT:
359 g_value_set_boolean(value, priv->force_aspect);
342360 break;
343361
344362 default:
417435 GtkAllocation child_allocation;
418436 gint width, height;
419437 gint border_width;
420 double desktopAspect;
421 double actualAspect;
422438 GtkWidget *child = gtk_bin_get_child(bin);
423439
424440 g_debug("Allocated %dx%d", allocation->width, allocation->height);
433449 width = MAX(MIN_DISPLAY_WIDTH, allocation->width - 2 * border_width);
434450 height = MAX(MIN_DISPLAY_HEIGHT, allocation->height - 2 * border_width);
435451
436 desktopAspect = (double) priv->desktopWidth / (double) priv->desktopHeight;
437 actualAspect = (double) width / (double) height;
438
439 if (actualAspect > desktopAspect) {
440 child_allocation.width = round(height * desktopAspect);
441 child_allocation.height = height;
452 if (priv->force_aspect) {
453 double desktopAspect = (double) priv->desktopWidth / (double) priv->desktopHeight;
454 double actualAspect = (double) width / (double) height;
455
456 if (actualAspect > desktopAspect) {
457 child_allocation.width = round(height * desktopAspect);
458 child_allocation.height = height;
459 } else {
460 child_allocation.width = width;
461 child_allocation.height = round(width / desktopAspect);
462 }
442463 } else {
443464 child_allocation.width = width;
444 child_allocation.height = round(width / desktopAspect);
465 child_allocation.height = height;
445466 }
446467
447468 child_allocation.x = 0.5 * (width - child_allocation.width) + allocation->x + border_width;