testdmabuf: Add another shortcut

Make the picture not expand, and add Ctrl-S to toggle the
horizontal alignment between start and center. This makes the
offloaded picture move under the overlaid controls, or out
from under them, triggering some offloading transitions.
This commit is contained in:
Matthias Clasen 2024-02-11 20:43:16 -05:00
parent a9949a102b
commit df7889d7f3

View File

@ -725,6 +725,21 @@ toggle_flip (GtkWidget *widget,
return TRUE;
}
static gboolean
toggle_start (GtkWidget *widget,
GVariant *args,
gpointer data)
{
GtkWidget *offload = data;
if (gtk_widget_get_halign (offload) == GTK_ALIGN_CENTER)
gtk_widget_set_halign (offload, GTK_ALIGN_START);
else
gtk_widget_set_halign (offload, GTK_ALIGN_CENTER);
return TRUE;
}
int
main (int argc, char *argv[])
{
@ -791,6 +806,8 @@ main (int argc, char *argv[])
picture = gtk_picture_new_for_paintable (GDK_PAINTABLE (texture));
offload = gtk_graphics_offload_new (picture);
gtk_widget_set_halign (offload, GTK_ALIGN_CENTER);
gtk_widget_set_valign (offload, GTK_ALIGN_CENTER);
overlay = gtk_overlay_new ();
gtk_overlay_set_child (GTK_OVERLAY (overlay), offload);
@ -813,6 +830,11 @@ main (int argc, char *argv[])
shortcut = gtk_shortcut_new (trigger, action);
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
trigger = gtk_keyval_trigger_new (GDK_KEY_S, GDK_CONTROL_MASK);
action = gtk_callback_action_new (toggle_start, offload, NULL);
shortcut = gtk_shortcut_new (trigger, action);
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
gtk_widget_add_controller (window, controller);
gtk_window_present (GTK_WINDOW (window));