[PATCH 08/10] Define the screensaver inhibition server interface

Bryce Harrington bryce at osg.samsung.com
Sat Mar 5 00:18:45 UTC 2016


Add a routine to bind the screensaver inhibitor protocol global.

This requires the screensaver inhibit protocol capability in
wayland-protocols.

Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
---
 Makefile.am      |  4 ++-
 src/compositor.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index cbb3b57..1057ed6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -126,7 +126,9 @@ nodist_weston_SOURCES =					\
 	protocol/scaler-protocol.c			\
 	protocol/scaler-server-protocol.h		\
 	protocol/linux-dmabuf-unstable-v1-protocol.c	\
-	protocol/linux-dmabuf-unstable-v1-server-protocol.h
+	protocol/linux-dmabuf-unstable-v1-server-protocol.h	\
+	protocol/screensaver-inhibit-unstable-v1-protocol.c	\
+	protocol/screensaver-inhibit-unstable-v1-server-protocol.h
 
 BUILT_SOURCES += $(nodist_weston_SOURCES)
 
diff --git a/src/compositor.c b/src/compositor.c
index 4dfc0eb..0927e6e 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -51,6 +51,8 @@
 #include <time.h>
 #include <errno.h>
 
+#include <screensaver-inhibit-unstable-v1-server-protocol.h>
+
 #include "timeline.h"
 
 #include "compositor.h"
@@ -4632,6 +4634,91 @@ compositor_bind(struct wl_client *client,
 				       compositor, NULL);
 }
 
+struct weston_screensaver_inhibitor {
+	struct weston_surface *surface;
+};
+
+static void
+destroy_inhibitor(struct wl_resource *resource)
+{
+	struct weston_screensaver_inhibitor *inhibitor = wl_resource_get_user_data(resource);
+
+	assert(inhibitor);
+
+	inhibitor->surface = NULL;
+	free(inhibitor);
+}
+
+
+static void
+screensaver_inhibitor_inhibit_destroy(struct wl_client *client, struct wl_resource *resource)
+{
+	struct weston_screensaver_inhibitor *inhibitor = wl_resource_get_user_data(resource);
+
+	inhibitor->surface->inhibit_screensaving = false;
+}
+
+static const struct zwp_screensaver_inhibition_inhibit_v1_interface screensaver_inhibitor_inhibit_interface = {
+	screensaver_inhibitor_inhibit_destroy
+};
+
+static void
+screensaver_inhibitor_destroy(struct wl_client *client, struct wl_resource *resource)
+{
+}
+
+static void
+screensaver_inhibitor_create_inhibitor(struct wl_client *client, struct wl_resource *resource,
+				       uint32_t id, struct wl_resource *surface_resource)
+{
+	struct weston_surface *surface = wl_resource_get_user_data(surface_resource); // is this correct?
+	struct weston_screensaver_inhibitor *inhibitor;
+	struct wl_resource *cr;
+
+	cr = wl_resource_create(client, &zwp_screensaver_inhibition_inhibit_v1_interface,
+				wl_resource_get_version(resource), id);
+	if (cr == NULL) {
+		wl_client_post_no_memory(client);
+		return;
+	}
+
+	inhibitor = zalloc(sizeof *inhibitor);
+	if (inhibitor == NULL) {
+		wl_client_post_no_memory(client);
+		return;
+	}
+
+	inhibitor->surface = surface;
+	inhibitor->surface->inhibit_screensaving = true;
+
+	wl_resource_set_implementation(cr, &screensaver_inhibitor_inhibit_interface,
+				       inhibitor, destroy_inhibitor);
+}
+
+/* TODO: Maybe name this the inhibition manager?? */
+static const struct zwp_screensaver_inhibition_v1_interface screensaver_inhibitor_interface = {
+	screensaver_inhibitor_create_inhibitor,
+	screensaver_inhibitor_destroy
+};
+
+static void
+bind_screensaver_inhibitor(struct wl_client *client,
+			   void *data, uint32_t version, uint32_t id)
+{
+	struct wl_resource *resource;
+
+	resource = wl_resource_create(client, &zwp_screensaver_inhibition_v1_interface,
+				      version, id);
+	if (resource == NULL) {
+		wl_client_post_no_memory(client);
+		return;
+	}
+
+	wl_resource_set_implementation(resource, &screensaver_inhibitor_interface,
+				       NULL, NULL);
+}
+
+
 WL_EXPORT int
 weston_environment_get_fd(const char *env)
 {
@@ -4724,6 +4811,10 @@ weston_compositor_create(struct wl_display *display, void *user_data)
 			      ec, bind_presentation))
 		goto fail;
 
+	if (!wl_global_create(ec->wl_display, &zwp_screensaver_inhibition_v1_interface, 1,
+			      ec, bind_screensaver_inhibitor))
+		goto fail;
+
 	wl_list_init(&ec->view_list);
 	wl_list_init(&ec->plane_list);
 	wl_list_init(&ec->layer_list);
-- 
1.9.1



More information about the wayland-devel mailing list