[PATCH 4/4] desktop-shell: add sleep event

Pekka Paalanen ppaalanen at gmail.com
Thu Nov 3 05:11:35 PDT 2011


Add sleep event to the desktop_shell interface for notifying the shell
when the compositor decides to go to sleep.

The shell could react by invoking a screen saver or locking the screen
(once such interfaces are implemented).

Signed-off-by: Pekka Paalanen <ppaalanen at gmail.com>
---
 clients/desktop-shell.c    |    9 ++++++++-
 compositor/shell.c         |   15 +++++++++++++--
 protocol/desktop-shell.xml |    3 +++
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index b915723..612c5b9 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -277,8 +277,15 @@ desktop_shell_configure(void *data,
 	}
 }
 
+static void
+desktop_shell_sleep(void *data, struct desktop_shell *desktop_shell)
+{
+	printf("Coucou! %s\n", __func__);
+}
+
 static const struct desktop_shell_listener listener = {
-	desktop_shell_configure
+	desktop_shell_configure,
+	desktop_shell_sleep
 };
 
 static void
diff --git a/compositor/shell.c b/compositor/shell.c
index 2e288d9..c7d3fd2 100644
--- a/compositor/shell.c
+++ b/compositor/shell.c
@@ -44,6 +44,7 @@ struct wl_shell {
 	struct {
 		struct wlsc_process process;
 		struct wl_client *client;
+		struct wl_resource *desktop_shell;
 	} child;
 };
 
@@ -914,8 +915,15 @@ activate(struct wlsc_shell *base, struct wlsc_surface *es,
 }
 
 static void
-go_sleep(struct wlsc_shell *shell)
+go_sleep(struct wlsc_shell *base)
 {
+	struct wl_shell *shell = container_of(base, struct wl_shell, shell);
+	struct wl_resource *desktop_shell = shell->child.desktop_shell;
+
+	if (!desktop_shell)
+		return;
+
+	wl_resource_post_event(desktop_shell, DESKTOP_SHELL_SLEEP);
 }
 
 static void
@@ -941,6 +949,7 @@ desktop_shell_sigchld(struct wlsc_process *process, int status)
 
 	shell->child.process.pid = 0;
 	shell->child.client = NULL; /* already destroyed by wayland */
+	shell->child.desktop_shell = NULL;
 }
 
 static int
@@ -1008,8 +1017,10 @@ bind_desktop_shell(struct wl_client *client,
 					&desktop_shell_implementation,
 					id, shell);
 
-	if (client == shell->child.client)
+	if (client == shell->child.client) {
+		shell->child.desktop_shell = resource;
 		return;
+	}
 
 	wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
 			       "permission to bind desktop_shell denied");
diff --git a/protocol/desktop-shell.xml b/protocol/desktop-shell.xml
index 438773d..3680c74 100644
--- a/protocol/desktop-shell.xml
+++ b/protocol/desktop-shell.xml
@@ -19,6 +19,9 @@
       <arg name="height" type="int"/>
     </event>
 
+    <!-- Compositor went to sleep after idle timeout, shell could
+         react by e.g. locking the screen. -->
+    <event name="sleep"/>
   </interface>
 
 </protocol>
-- 
1.7.3.4



More information about the wayland-devel mailing list