From d3023ec9ae9912d4ab3782b44bbf5c08f76929ad Mon Sep 17 00:00:00 2001
From: Didier Roche <didrocks@ubuntu.com>
Date: Mon, 26 Jan 2015 16:57:53 +0100
Subject: [PATCH 06/13] Add functionality to register and watch for plymouth
 keys

Each listened key can send a callback which will be used once the key is
pressed on plymouth by the user.
---
 src/shared/plymouth.c | 15 +++++++++++++++
 src/shared/plymouth.h |  2 ++
 2 files changed, 17 insertions(+)

diff --git a/src/shared/plymouth.c b/src/shared/plymouth.c
index 7927b61..51de18d 100644
--- a/src/shared/plymouth.c
+++ b/src/shared/plymouth.c
@@ -87,6 +87,21 @@ void plymouth_update(const char *message) {
         ply_boot_client_flush(plymouth_client);
 }
 
+static void plymouth_key_pressed(void *callback, const char *pressed_key, ply_boot_client_t *client) {
+        ((keypress_callback)callback)();
+}
+
+bool plymouth_watch_key(const char *keys, const char *message, keypress_callback callback) {
+        if (!plymouth_running() || !plymouth_connect())
+                return false;
+
+        ply_boot_client_tell_daemon_to_display_message (plymouth_client, message, NULL,
+                                                        plymouth_update_failed, NULL);
+        ply_boot_client_ask_daemon_to_watch_for_keystroke (plymouth_client, keys, plymouth_key_pressed,
+                                                           NULL, callback);
+        return true;
+}
+
 void plymouth_delete_message(void) {
         if (!plymouth_running() || !plymouth_client)
                 return;
diff --git a/src/shared/plymouth.h b/src/shared/plymouth.h
index c7c41bc..7811946 100644
--- a/src/shared/plymouth.h
+++ b/src/shared/plymouth.h
@@ -29,4 +29,6 @@ bool plymouth_connect(void);
 void plymouth_disconnect(void);
 void plymouth_update(const char *message);
 
+typedef void (*keypress_callback)(void);
 void plymouth_delete_message(void);
+bool plymouth_watch_key(const char *keys, const char *message, keypress_callback callback);
-- 
2.1.4

