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

Bryce Harrington bryce at osg.samsung.com
Thu Mar 24 18:27:52 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>
---
v2: Update for protocol rename from screensaver-inhibition to idle-inhibit

 Makefile.am      |  4 ++-
 configure.ac     |  2 ++
 src/compositor.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 src/compositor.h |  2 +-
 4 files changed, 97 insertions(+), 4 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index cbb3b57..aa3aa1b 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/idle-inhibit-unstable-v1-protocol.c	\
+	protocol/idle-inhibit-unstable-v1-server-protocol.h
 
 BUILT_SOURCES += $(nodist_weston_SOURCES)
 
diff --git a/configure.ac b/configure.ac
index bba8050..d4817a9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4,6 +4,8 @@ m4_define([weston_micro_version], [90])
 m4_define([weston_version],
           [weston_major_version.weston_minor_version.weston_micro_version])
 
+# Note: Inhibition patchset requires inhibition protocol in wayland-protocol
+
 AC_PREREQ([2.64])
 AC_INIT([weston],
         [weston_version],
diff --git a/src/compositor.c b/src/compositor.c
index 4dfc0eb..7743c54 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -51,6 +51,8 @@
 #include <time.h>
 #include <errno.h>
 
+#include <idle-inhibit-unstable-v1-server-protocol.h>
+
 #include "timeline.h"
 
 #include "compositor.h"
@@ -613,7 +615,7 @@ weston_surface_create(struct weston_compositor *compositor)
 	weston_matrix_init(&surface->surface_to_buffer_matrix);
 
 	surface->active = false;
-	surface->inhibit_screensaving = false;
+	surface->inhibit_idling = false;
 
 	return surface;
 }
@@ -2412,7 +2414,7 @@ weston_output_inhibited_outputs(struct weston_compositor *compositor)
 			continue;
 
 		/* Does the view's surface inhibit this output? */
-		if (!view->surface->inhibit_screensaving)
+		if (!view->surface->inhibit_idling)
 			continue;
 
 		inhibited_outputs_mask |= view->output_mask;
@@ -4632,6 +4634,89 @@ compositor_bind(struct wl_client *client,
 				       compositor, NULL);
 }
 
+struct weston_idle_inhibitor {
+	struct weston_surface *surface;
+};
+
+static void
+destroy_idle_inhibitor(struct wl_resource *resource)
+{
+	struct weston_idle_inhibitor *inhibitor = wl_resource_get_user_data(resource);
+
+	inhibitor->surface = NULL;
+	free(inhibitor);
+}
+
+static void
+idle_inhibitor_destroy(struct wl_client *client, struct wl_resource *resource)
+{
+	struct weston_idle_inhibitor *inhibitor = wl_resource_get_user_data(resource);
+
+	assert(inhibitor);
+
+	inhibitor->surface->inhibit_idling = false;
+}
+
+static const struct zwp_idle_inhibitor_v1_interface idle_inhibitor_interface = {
+	idle_inhibitor_destroy
+};
+
+static void
+idle_inhibit_manager_destroy(struct wl_client *client, struct wl_resource *resource)
+{
+}
+
+static void
+idle_inhibit_manager_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);
+	struct weston_idle_inhibitor *inhibitor;
+	struct wl_resource *cr;
+
+	cr = wl_resource_create(client, &zwp_idle_inhibitor_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_idling = true;
+
+	wl_resource_set_implementation(cr, &idle_inhibitor_interface,
+				       inhibitor, destroy_idle_inhibitor);
+}
+
+static const struct zwp_idle_inhibit_manager_v1_interface idle_inhibit_manager_interface = {
+	idle_inhibit_manager_create_inhibitor,
+	idle_inhibit_manager_destroy
+};
+
+static void
+bind_idle_inhibit_manager(struct wl_client *client,
+			  void *data, uint32_t version, uint32_t id)
+{
+	struct wl_resource *resource;
+
+	resource = wl_resource_create(client, &zwp_idle_inhibit_manager_v1_interface,
+				      version, id);
+	if (resource == NULL) {
+		wl_client_post_no_memory(client);
+		return;
+	}
+
+	wl_resource_set_implementation(resource, &idle_inhibit_manager_interface,
+				       NULL, NULL);
+}
+
+
 WL_EXPORT int
 weston_environment_get_fd(const char *env)
 {
@@ -4724,6 +4809,10 @@ weston_compositor_create(struct wl_display *display, void *user_data)
 			      ec, bind_presentation))
 		goto fail;
 
+	if (!wl_global_create(ec->wl_display, &zwp_idle_inhibit_manager_v1_interface, 1,
+			      ec, bind_idle_inhibit_manager))
+		goto fail;
+
 	wl_list_init(&ec->view_list);
 	wl_list_init(&ec->plane_list);
 	wl_list_init(&ec->layer_list);
diff --git a/src/compositor.h b/src/compositor.h
index f9068c2..f361b6f 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -1050,7 +1050,7 @@ struct weston_surface {
 	 * or other automatic obscurement to kick in while the surface is
 	 * considered "active" by the shell.
 	 */
-	bool inhibit_screensaving;
+	bool inhibit_idling;
 
 };
 
-- 
1.9.1



More information about the wayland-devel mailing list