From ed44f37de487e0d98803998fece2f7b5be0b7080 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 14 Sep 2023 11:32:22 -0400 Subject: [PATCH] gtk-demo: Add sound to the path maze Its a game, after all. --- demos/gtk-demo/path_maze.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/demos/gtk-demo/path_maze.c b/demos/gtk-demo/path_maze.c index f81eb81e62..6d8acce3ff 100644 --- a/demos/gtk-demo/path_maze.c +++ b/demos/gtk-demo/path_maze.c @@ -8,6 +8,7 @@ * is a rather complex path. */ +#include "config.h" #include #include @@ -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)); }