[PATCH weston v4 06/20] compositor: Keep track of what views were activated by clicking

Jonas Ådahl jadahl at gmail.com
Thu Nov 19 20:10:06 PST 2015


On Thu, Nov 19, 2015 at 12:23:34PM +1000, Peter Hutterer wrote:
> On Tue, Nov 17, 2015 at 06:10:52PM +0800, Jonas Ådahl wrote:
> > 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
> 
> typo: shell-independent
> 
> 02-06 are Acked-by: Peter Hutterer <peter.hutterer at who-t.net>
> one comment at the bottom of this email:
> 
> > 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 3b34529..ab5be7a 100644
> > --- a/desktop-shell/shell.c
> > +++ b/desktop-shell/shell.c
> > @@ -5055,7 +5055,7 @@ activate(struct desktop_shell *shell, struct weston_view *view,
> >  	 * Leave fullscreen surfaces on unrelated outputs alone. */
> >  	lower_fullscreen_layer(shell, shsurf->output);
> >  
> > -	weston_surface_activate(es, seat);
> > +	weston_view_activate(view, seat, flags);
> >  
> >  	state = ensure_focus_state(shell, seat);
> >  	if (state == NULL)
> > @@ -5130,6 +5130,7 @@ click_to_activate_binding(struct weston_pointer *pointer, uint32_t time,
> >  		return;
> >  
> >  	activate_binding(pointer->seat, data, pointer->focus,
> > +			 WESTON_ACTIVATE_FLAG_CLICKED |
> >  			 WESTON_ACTIVATE_FLAG_CONFIGURE);
> >  }
> >  
> > diff --git a/src/compositor.c b/src/compositor.c
> > index f8437e8..6f8d769 100644
> > --- a/src/compositor.c
> > +++ b/src/compositor.c
> > @@ -4490,6 +4490,8 @@ weston_compositor_create(struct wl_display *display, void *user_data)
> >  	ec->output_id_pool = 0;
> >  	ec->repaint_msec = DEFAULT_REPAINT_WINDOW;
> >  
> > +	ec->activate_serial = 1;
> > +
> >  	if (!wl_global_create(ec->wl_display, &wl_compositor_interface, 3,
> >  			      ec, compositor_bind))
> >  		goto fail;
> > diff --git a/src/compositor.h b/src/compositor.h
> > index d1f7b04..032c637 100644
> > --- a/src/compositor.h
> > +++ b/src/compositor.h
> > @@ -750,6 +750,8 @@ struct weston_compositor {
> >  	clockid_t presentation_clock;
> >  	int32_t repaint_msec;
> >  
> > +	unsigned int activate_serial;
> > +
> >  	int exit_code;
> >  
> >  	void *user_data;
> > @@ -848,6 +850,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 */
> >  
> > @@ -1067,6 +1071,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
> > @@ -1123,6 +1128,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 53e84a0..0a567da 100644
> > --- a/src/input.c
> > +++ b/src/input.c
> > @@ -1102,6 +1102,20 @@ 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)
> > @@ -1109,6 +1123,8 @@ weston_surface_activate(struct weston_surface *surface,
> >  	struct weston_compositor *compositor = seat->compositor;
> >  	struct weston_keyboard *keyboard = weston_seat_get_keyboard(seat);
> >  
> > +	inc_activate_serial(compositor);
> > +
> >  	if (keyboard) {
> >  		weston_keyboard_set_focus(keyboard, surface);
> >  		wl_data_device_set_keyboard_focus(seat);
> > @@ -1118,6 +1134,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);
> > +}
> 
> I'm not overly fond of this approach tbh, the peek and disassociated
> serial increase is looking for trouble. would it make sense to simply return
> the serial from weston_surface_activate()?

The reason is that we need to have the click_to_activate_serial up to
date in the 'activate_signal' listener callbacks. We could split out
weston_surface_activate into two functions, one doing the keyboard focus
and signal emitting things taking a serial that is called by
view_activate, and an old weston_surface_activate that just calls the
above mentioned helper with a new serial.


Jonas

> 
> Cheers,
>    Peter
> 
> > +
> > +WL_EXPORT void
> >  notify_button(struct weston_seat *seat, uint32_t time, int32_t button,
> >  	      enum wl_pointer_button_state state)
> >  {
> > -- 
> > 2.4.3
> > 
> 


More information about the wayland-devel mailing list