[PATCH weston v3 2/8] compositor: Track inhibition state in weston_surface

Bryce Harrington bryce at osg.samsung.com
Thu Apr 7 23:44:17 UTC 2016


Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
---
v3: Rename inhibit_screensaving to inhibit_idling

 desktop-shell/shell.c               |  4 +++-
 fullscreen-shell/fullscreen-shell.c | 25 +++++++++++++++-------
 ivi-shell/ivi-shell.c               |  4 +++-
 src/compositor.c                    | 42 +++++++++++++++++++++++++++++++++++++
 src/compositor.h                    | 27 +++++++++++++++++++++---
 src/input.c                         | 15 -------------
 tests/weston-test.c                 |  8 +++++--
 7 files changed, 96 insertions(+), 29 deletions(-)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 780902d..6e49076 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -5055,7 +5055,9 @@ activate(struct desktop_shell *shell, struct weston_surface *es,
 	 * Leave fullscreen surfaces on unrelated outputs alone. */
 	lower_fullscreen_layer(shell, shsurf->output);
 
-	weston_surface_activate(es, seat);
+	weston_surface_assign_keyboard(es, seat);
+	if (es != NULL)
+		weston_surface_activate(es);
 
 	state = ensure_focus_state(shell, seat);
 	if (state == NULL)
diff --git a/fullscreen-shell/fullscreen-shell.c b/fullscreen-shell/fullscreen-shell.c
index abc4e84..e1f8a63 100644
--- a/fullscreen-shell/fullscreen-shell.c
+++ b/fullscreen-shell/fullscreen-shell.c
@@ -88,8 +88,11 @@ pointer_focus_changed(struct wl_listener *listener, void *data)
 {
 	struct weston_pointer *pointer = data;
 
-	if (pointer->focus && pointer->focus->surface->resource)
-		weston_surface_activate(pointer->focus->surface, pointer->seat);
+	if (pointer->focus && pointer->focus->surface->resource) {
+		weston_surface_assign_keyboard(pointer->focus->surface, pointer->seat);
+		if (pointer->focus->surface != NULL)
+			weston_surface_activate(pointer->focus->surface);
+	}
 }
 
 static void
@@ -118,7 +121,9 @@ seat_caps_changed(struct wl_listener *l, void *data)
 	if (keyboard && keyboard->focus != NULL) {
 		wl_list_for_each(fsout, &listener->shell->output_list, link) {
 			if (fsout->surface) {
-				weston_surface_activate(fsout->surface, seat);
+				weston_surface_assign_keyboard(fsout->surface, seat);
+				if (fsout->surface != NULL)
+					weston_surface_activate(fsout->surface);
 				return;
 			}
 		}
@@ -703,8 +708,11 @@ fullscreen_shell_present_surface(struct wl_client *client,
 			struct weston_keyboard *keyboard =
 				weston_seat_get_keyboard(seat);
 
-			if (keyboard && !keyboard->focus)
-				weston_surface_activate(surface, seat);
+			if (keyboard && !keyboard->focus) {
+				weston_surface_assign_keyboard(surface, seat);
+				if (surface != NULL)
+					weston_surface_activate(surface);
+			}
 		}
 	}
 }
@@ -754,8 +762,11 @@ fullscreen_shell_present_surface_for_mode(struct wl_client *client,
 		struct weston_keyboard *keyboard =
 			weston_seat_get_keyboard(seat);
 
-		if (keyboard && !keyboard->focus)
-			weston_surface_activate(surface, seat);
+		if (keyboard && !keyboard->focus) {
+			weston_surface_assign_keyboard(surface, seat);
+			if (surface != NULL)
+				weston_surface_activate(surface);
+		}
 	}
 }
 
diff --git a/ivi-shell/ivi-shell.c b/ivi-shell/ivi-shell.c
index a767ccf..59f5656 100644
--- a/ivi-shell/ivi-shell.c
+++ b/ivi-shell/ivi-shell.c
@@ -425,7 +425,9 @@ activate_binding(struct weston_seat *seat,
 	if (get_ivi_shell_surface(main_surface) == NULL)
 		return;
 
-	weston_surface_activate(focus, seat);
+	weston_surface_assign_keyboard(focus, seat);
+	if (focus != NULL)
+		weston_surface_activate(focus);
 }
 
 static void
diff --git a/src/compositor.c b/src/compositor.c
index 83cabf7..9531a0a 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -612,6 +612,9 @@ weston_surface_create(struct weston_compositor *compositor)
 	weston_matrix_init(&surface->buffer_to_surface_matrix);
 	weston_matrix_init(&surface->surface_to_buffer_matrix);
 
+	surface->active = false;
+	surface->inhibit_idling = false;
+
 	return surface;
 }
 
@@ -3422,6 +3425,45 @@ weston_surface_copy_content(struct weston_surface *surface,
 					 src_x, src_y, width, height);
 }
 
+/** Sets the keyboard focus to the given surface
+ */
+WL_EXPORT void
+weston_surface_assign_keyboard(struct weston_surface *surface,
+			      struct weston_seat *seat)
+{
+        struct weston_compositor *compositor = seat->compositor;
+        struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
+
+        if (keyboard) {
+                weston_keyboard_set_focus(keyboard, surface);
+                wl_data_device_set_keyboard_focus(seat);
+        }
+
+        wl_signal_emit(&compositor->activate_signal, surface);
+}
+
+/** Set surface as considered 'active' by the shell.
+ */
+WL_EXPORT void
+weston_surface_activate(struct weston_surface *surface)
+{
+	surface->active = true;
+}
+
+/** Set surface as no longer considered 'active' by the shell.
+ */
+WL_EXPORT void
+weston_surface_deactivate(struct weston_surface *surface)
+{
+	surface->active = false;
+}
+
+WL_EXPORT bool
+weston_surface_is_active(struct weston_surface *surface)
+{
+	return surface->active;
+}
+
 static void
 subsurface_set_position(struct wl_client *client,
 			struct wl_resource *resource, int32_t x, int32_t y)
diff --git a/src/compositor.h b/src/compositor.h
index df8ef2d..d8d5368 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -1037,6 +1037,20 @@ struct weston_surface {
 	const char *role_name;
 
 	struct weston_timeline_object timeline;
+
+	/*
+	 * A shell-specific indicator that the surface is in immediate
+	 * use by the user.  For example, the surface might have keyboard
+	 * focus.
+	 */
+	bool active;
+
+	/*
+	 * Indicates the surface prefers no screenblanking, screensaving,
+	 * or other automatic obscurement to kick in while the surface is
+	 * considered "active" by the shell.
+	 */
+	bool inhibit_idling;
 };
 
 struct weston_subsurface {
@@ -1122,9 +1136,6 @@ int
 weston_spring_done(struct weston_spring *spring);
 
 void
-weston_surface_activate(struct weston_surface *surface,
-			struct weston_seat *seat);
-void
 notify_motion(struct weston_seat *seat, uint32_t time,
 	      struct weston_pointer_motion_event *event);
 void
@@ -1402,6 +1413,16 @@ weston_surface_copy_content(struct weston_surface *surface,
 			    int src_x, int src_y,
 			    int width, int height);
 
+void
+weston_surface_assign_keyboard(struct weston_surface *surface,
+			       struct weston_seat *seat);
+void
+weston_surface_activate(struct weston_surface *surface);
+void
+weston_surface_deactivate(struct weston_surface *surface);
+bool
+weston_surface_is_active(struct weston_surface *surface);
+
 struct weston_buffer *
 weston_buffer_from_resource(struct wl_resource *resource);
 
diff --git a/src/input.c b/src/input.c
index a3d982e..6e35105 100644
--- a/src/input.c
+++ b/src/input.c
@@ -1206,21 +1206,6 @@ notify_motion_absolute(struct weston_seat *seat,
 }
 
 WL_EXPORT void
-weston_surface_activate(struct weston_surface *surface,
-			struct weston_seat *seat)
-{
-	struct weston_compositor *compositor = seat->compositor;
-	struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
-
-	if (keyboard) {
-		weston_keyboard_set_focus(keyboard, surface);
-		wl_data_device_set_keyboard_focus(seat);
-	}
-
-	wl_signal_emit(&compositor->activate_signal, surface);
-}
-
-WL_EXPORT void
 notify_button(struct weston_seat *seat, uint32_t time, int32_t button,
 	      enum wl_pointer_button_state state)
 {
diff --git a/tests/weston-test.c b/tests/weston-test.c
index 03e2c54..15cd07f 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -181,13 +181,17 @@ activate_surface(struct wl_client *client, struct wl_resource *resource,
 	seat = get_seat(test);
 	keyboard = weston_seat_get_keyboard(seat);
 	if (surface) {
-		weston_surface_activate(surface, seat);
+		weston_surface_assign_keyboard(surface, seat);
+		if (surface != NULL)
+			weston_surface_activate(surface);
 		notify_keyboard_focus_in(seat, &keyboard->keys,
 					 STATE_UPDATE_AUTOMATIC);
 	}
 	else {
 		notify_keyboard_focus_out(seat);
-		weston_surface_activate(surface, seat);
+		weston_surface_assign_keyboard(surface, seat);
+		if (surface != NULL)
+			weston_surface_activate(surface);
 	}
 }
 
-- 
1.9.1



More information about the wayland-devel mailing list