[PATCH weston v2 09/21] compositor: Keep track of what views were activated by clicking

Jonas Ådahl jadahl at gmail.com
Wed May 13 03:26:30 PDT 2015


Adds a weston_view_activate() that can be passed an additional active
flag WESTON_ACTIVATE_CLICKED, that the shell passes when a view was
activated by clicking.

This allows shell independent components implement heuristics depending
on how a view was activated.

Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
---
 desktop-shell/shell.c |  3 ++-
 src/compositor.c      |  2 ++
 src/compositor.h      | 11 +++++++++++
 src/input.c           | 30 ++++++++++++++++++++++++++++++
 4 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index cbd7d88..0169414 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -5111,7 +5111,7 @@ activate(struct desktop_shell *shell, struct weston_view *view,
 
 	main_surface = weston_surface_get_main_surface(es);
 
-	weston_surface_activate(es, seat);
+	weston_view_activate(view, seat, flags);
 
 	state = ensure_focus_state(shell, seat);
 	if (state == NULL)
@@ -5191,6 +5191,7 @@ click_to_activate_binding(struct weston_seat *seat,
 		return;
 
 	activate_binding(seat, data, seat->pointer->focus,
+			 WESTON_ACTIVATE_FLAG_CLICKED |
 			 WESTON_ACTIVATE_FLAG_CONFIGURE);
 }
 
diff --git a/src/compositor.c b/src/compositor.c
index 8f02b4d..5594d30 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -4527,6 +4527,8 @@ weston_compositor_init(struct weston_compositor *ec,
 
 	ec->output_id_pool = 0;
 
+	ec->activate_serial = 1;
+
 	if (!wl_global_create(display, &wl_compositor_interface, 3,
 			      ec, compositor_bind))
 		return -1;
diff --git a/src/compositor.h b/src/compositor.h
index dd554bb..79b232e 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -716,6 +716,8 @@ struct weston_compositor {
 	int32_t repaint_msec;
 
 	int exit_code;
+
+	unsigned int activate_serial;
 };
 
 struct weston_buffer {
@@ -810,6 +812,8 @@ struct weston_view {
 	/* For weston_layer inheritance from another view */
 	struct weston_view *parent_view;
 
+	unsigned int click_to_activate_serial;
+
 	pixman_region32_t clip;          /* See weston_view_damage_below() */
 	float alpha;                     /* part of geometry, see below */
 
@@ -1029,6 +1033,7 @@ enum weston_key_state_update {
 enum weston_activate_flag {
 	WESTON_ACTIVATE_FLAG_NONE = 0,
 	WESTON_ACTIVATE_FLAG_CONFIGURE = 1 << 0,
+	WESTON_ACTIVATE_FLAG_CLICKED = 1 << 1,
 };
 
 void
@@ -1085,6 +1090,12 @@ weston_spring_done(struct weston_spring *spring);
 void
 weston_surface_activate(struct weston_surface *surface,
 			struct weston_seat *seat);
+
+void
+weston_view_activate(struct weston_view *view,
+		     struct weston_seat *seat,
+		     enum weston_activate_flag flags);
+
 void
 notify_motion(struct weston_seat *seat, uint32_t time,
 	      struct weston_pointer_motion_event *event);
diff --git a/src/input.c b/src/input.c
index a7d8daa..cd24067 100644
--- a/src/input.c
+++ b/src/input.c
@@ -1054,12 +1054,28 @@ notify_motion_absolute(struct weston_seat *seat,
 	pointer->grab->interface->motion(pointer->grab, time, &event);
 }
 
+static unsigned int
+peek_next_activate_serial(struct weston_compositor *c)
+{
+	unsigned serial = c->activate_serial + 1;
+
+	return serial == 0 ? 1 : serial;
+}
+
+static void
+inc_activate_serial(struct weston_compositor *c)
+{
+	c->activate_serial = peek_next_activate_serial (c);
+}
+
 WL_EXPORT void
 weston_surface_activate(struct weston_surface *surface,
 			struct weston_seat *seat)
 {
 	struct weston_compositor *compositor = seat->compositor;
 
+	inc_activate_serial(compositor);
+
 	if (seat->keyboard) {
 		weston_keyboard_set_focus(seat->keyboard, surface);
 		wl_data_device_set_keyboard_focus(seat);
@@ -1069,6 +1085,20 @@ weston_surface_activate(struct weston_surface *surface,
 }
 
 WL_EXPORT void
+weston_view_activate(struct weston_view *view,
+		     struct weston_seat *seat,
+		     uint32_t flags)
+{
+	struct weston_compositor *compositor = seat->compositor;
+
+	if (flags & WESTON_ACTIVATE_FLAG_CLICKED) {
+		view->click_to_activate_serial =
+			peek_next_activate_serial(compositor);
+	}
+	weston_surface_activate(view->surface, seat);
+}
+
+WL_EXPORT void
 notify_button(struct weston_seat *seat, uint32_t time, int32_t button,
 	      enum wl_pointer_button_state state)
 {
-- 
2.1.4



More information about the wayland-devel mailing list