[PATCH weston 5/6] zoom: Only use a motion listener if a pointer is available

Derek Foreman derekf at osg.samsung.com
Fri Jan 9 10:45:18 PST 2015


If no pointer is available for a seat, we no longer try to install a
motion listener.

Also, we now add a motion listener when a pointer device is plugged in.

Note that a seat may have a pointer when the device to move it has been
removed - in this case we still add the listener and it will work if
a device is plugged in to control the pointer.

Signed-off-by: Derek Foreman <derekf at osg.samsung.com>
---
 src/compositor.h |  4 ++++
 src/input.c      |  4 ++++
 src/zoom.c       | 31 ++++++++++++++++++++++++++++---
 3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/src/compositor.h b/src/compositor.h
index 48e40b9..fafdf95 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -153,6 +153,7 @@ struct weston_fixed_point {
 
 struct weston_output_zoom {
 	bool active;
+	bool has_listener;
 	float increment;
 	float level;
 	float max_level;
@@ -1287,6 +1288,9 @@ void
 weston_output_activate_zoom(struct weston_output *output,
 			    struct weston_seat *seat);
 void
+weston_output_zoom_add_motion_listener(struct weston_output *output,
+				       struct weston_seat *seat);
+void
 weston_output_update_matrix(struct weston_output *output);
 void
 weston_output_move(struct weston_output *output, int x, int y);
diff --git a/src/input.c b/src/input.c
index c039af0..e832644 100644
--- a/src/input.c
+++ b/src/input.c
@@ -2189,6 +2189,7 @@ weston_seat_release_keyboard(struct weston_seat *seat)
 WL_EXPORT void
 weston_seat_init_pointer(struct weston_seat *seat)
 {
+	struct weston_output *output;
 	struct weston_pointer *pointer;
 
 	if (seat->pointer) {
@@ -2207,6 +2208,9 @@ weston_seat_init_pointer(struct weston_seat *seat)
 	pointer->seat = seat;
 
 	seat_send_updated_caps(seat);
+
+	wl_list_for_each(output, &seat->compositor->output_list, link)
+		weston_output_zoom_add_motion_listener(output, seat);
 }
 
 WL_EXPORT void
diff --git a/src/zoom.c b/src/zoom.c
index d1358a2..70afb7c 100644
--- a/src/zoom.c
+++ b/src/zoom.c
@@ -48,7 +48,10 @@ weston_zoom_frame_z(struct weston_animation *animation,
 			output->zoom.active = false;
 			output->zoom.seat = NULL;
 			output->disable_planes--;
-			wl_list_remove(&output->zoom.motion_listener.link);
+			if (output->zoom.has_listener) {
+				wl_list_remove(&output->zoom.motion_listener.link);
+				output->zoom.has_listener = false;
+			}
 		}
 		output->zoom.spring_z.current = output->zoom.level;
 		wl_list_remove(&animation->link);
@@ -197,6 +200,28 @@ motion(struct wl_listener *listener, void *data)
 	weston_output_update_zoom(output);
 }
 
+/** Add a motion listener for a zoomed output
+ *
+ * This will be called at the start of a zoom or during hotplug
+ * if there was no pointer when the zoom started.
+ *
+ * \param output Output to add listener to
+ * \param seat Seat that controls the zoom location
+ */
+WL_EXPORT void
+weston_output_zoom_add_motion_listener(struct weston_output *output,
+				       struct weston_seat *seat)
+{
+	if (!output->zoom.active ||
+	    output->zoom.seat != seat ||
+	    !seat->pointer)
+		return;
+
+	wl_signal_add(&seat->pointer->motion_signal,
+		      &output->zoom.motion_listener);
+	output->zoom.has_listener = true;
+}
+
 WL_EXPORT void
 weston_output_activate_zoom(struct weston_output *output,
 			    struct weston_seat *seat)
@@ -207,8 +232,8 @@ weston_output_activate_zoom(struct weston_output *output,
 	output->zoom.active = true;
 	output->zoom.seat = seat;
 	output->disable_planes++;
-	wl_signal_add(&seat->pointer->motion_signal,
-		      &output->zoom.motion_listener);
+
+	weston_output_zoom_add_motion_listener(output, seat);
 }
 
 WL_EXPORT void
-- 
2.1.4



More information about the wayland-devel mailing list