Merge branch 'matthiasc/for-main' into 'main'

gtk-demo: Add sound to the path maze

See merge request GNOME/gtk!6395
This commit is contained in:
Matthias Clasen 2023-09-14 18:24:09 +00:00
commit dd7d145249

View File

@ -8,6 +8,7 @@
* is a rather complex path.
*/
#include "config.h"
#include <glib/gi18n.h>
#include <gtk/gtk.h>
@ -131,6 +132,24 @@ gtk_maze_class_init (GtkMazeClass *klass)
widget_class->snapshot = gtk_maze_snapshot;
}
static void
celebrate (gboolean win)
{
char *path;
GtkMediaStream *stream;
if (win)
path = g_build_filename (GTK_DATADIR, "sounds", "freedesktop", "stereo", "complete.oga", NULL);
else
path = g_build_filename (GTK_DATADIR, "sounds", "freedesktop", "stereo", "suspend-error.oga", NULL);
stream = gtk_media_file_new_for_filename (path);
gtk_media_stream_set_volume (stream, 1.0);
gtk_media_stream_play (stream);
g_signal_connect (stream, "notify::ended", G_CALLBACK (g_object_unref), NULL);
g_free (path);
}
static void
pointer_motion (GtkEventControllerMotion *controller,
double x,
@ -153,6 +172,8 @@ pointer_motion (GtkEventControllerMotion *controller,
return;
}
celebrate (FALSE);
self->active = FALSE;
gtk_widget_queue_draw (GTK_WIDGET (self));
}