Merge branch 'bilelmoussaoui/auto-resize' into 'main'

display: Add the possibility to disable auto resizing

See merge request chergert/libmks!22
This commit is contained in:
Christian Hergert 2023-05-31 23:50:28 +00:00
commit f1a6ce1fe1
2 changed files with 71 additions and 7 deletions

View File

@ -43,12 +43,14 @@ typedef struct
MksDisplayPicture *picture; MksDisplayPicture *picture;
MksInhibitor *inhibitor; MksInhibitor *inhibitor;
GtkShortcutTrigger *ungrab_trigger; GtkShortcutTrigger *ungrab_trigger;
guint auto_resize : 1;
} MksDisplayPrivate; } MksDisplayPrivate;
enum { enum {
PROP_0, PROP_0,
PROP_SCREEN, PROP_SCREEN,
PROP_UNGRAB_TRIGGER, PROP_UNGRAB_TRIGGER,
PROP_AUTO_RESIZE,
N_PROPS N_PROPS
}; };
@ -301,12 +303,16 @@ mks_display_size_allocate (GtkWidget *widget,
mks_display_get_paintable_area (self, &area); mks_display_get_paintable_area (self, &area);
attributes = mks_screen_attributes_new (); if (priv->auto_resize)
mks_screen_attributes_set_width (attributes, width); {
mks_screen_attributes_set_height (attributes, height); attributes = mks_screen_attributes_new ();
mks_screen_attributes_set_width (attributes, width);
mks_screen_attributes_set_height (attributes, height);
mks_screen_resizer_queue_resize (priv->resizer, mks_screen_resizer_queue_resize (priv->resizer,
g_steal_pointer (&attributes)); g_steal_pointer (&attributes));
mks_screen_attributes_free (attributes);
}
gtk_widget_size_allocate (GTK_WIDGET (priv->picture), gtk_widget_size_allocate (GTK_WIDGET (priv->picture),
&(GtkAllocation) { &(GtkAllocation) {
@ -316,7 +322,6 @@ mks_display_size_allocate (GtkWidget *widget,
area.size.height area.size.height
}, },
-1); -1);
mks_screen_attributes_free (attributes);
} }
static void static void
@ -337,6 +342,10 @@ mks_display_get_property (GObject *object,
g_value_set_object (value, mks_display_get_ungrab_trigger (self)); g_value_set_object (value, mks_display_get_ungrab_trigger (self));
break; break;
case PROP_AUTO_RESIZE:
g_value_set_boolean (value, mks_display_get_auto_resize (self));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
} }
@ -360,6 +369,10 @@ mks_display_set_property (GObject *object,
mks_display_set_ungrab_trigger (self, g_value_get_object (value)); mks_display_set_ungrab_trigger (self, g_value_get_object (value));
break; break;
case PROP_AUTO_RESIZE:
mks_display_set_auto_resize (self, g_value_get_boolean (value));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
} }
@ -391,6 +404,11 @@ mks_display_class_init (MksDisplayClass *klass)
GTK_TYPE_SHORTCUT_TRIGGER, GTK_TYPE_SHORTCUT_TRIGGER,
(G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
properties [PROP_AUTO_RESIZE] =
g_param_spec_boolean ("auto-resize", NULL, NULL,
TRUE,
(G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties); g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_css_name (widget_class, "MksDisplay"); gtk_widget_class_set_css_name (widget_class, "MksDisplay");
@ -468,6 +486,48 @@ mks_display_set_screen (MksDisplay *self,
MKS_EXIT; MKS_EXIT;
} }
/**
* mks_display_get_auto_resize:
* @self: A `MksDisplay`
*
* Get whether the widget will reconfigure the VM whenever
* it gets a new size allocation.
*/
gboolean
mks_display_get_auto_resize (MksDisplay *self)
{
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
g_return_val_if_fail (MKS_IS_DISPLAY (self), FALSE);
return priv->auto_resize;
}
/**
* mks_display_set_auto_resize:
* @self: A `MksDisplay`
* @auto_resize: Whether to auto resize or not
*
* Sets whether the widget should reconfigure the VM
* with the allocated size of the widget.
*/
void
mks_display_set_auto_resize (MksDisplay *self,
gboolean auto_resize)
{
MksDisplayPrivate *priv = mks_display_get_instance_private (self);
g_return_if_fail (MKS_IS_DISPLAY (self));
auto_resize = !!auto_resize;
if (auto_resize != priv->auto_resize)
{
priv->auto_resize = auto_resize;
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_AUTO_RESIZE]);
gtk_widget_queue_allocate (GTK_WIDGET (self));
}
}
/** /**
* mks_display_get_ungrab_trigger: * mks_display_get_ungrab_trigger:
* @self: a #MksDisplay * @self: a #MksDisplay

View File

@ -52,5 +52,9 @@ MksScreen *mks_display_get_screen (MksDisplay *self);
MKS_AVAILABLE_IN_ALL MKS_AVAILABLE_IN_ALL
void mks_display_set_screen (MksDisplay *self, void mks_display_set_screen (MksDisplay *self,
MksScreen *screen); MksScreen *screen);
MKS_AVAILABLE_IN_ALL
gboolean mks_display_get_auto_resize (MksDisplay *self);
MKS_AVAILABLE_IN_ALL
void mks_display_set_auto_resize (MksDisplay *self,
gboolean auto_resize);
G_END_DECLS G_END_DECLS