[PATCH weston v4 15/20] clients/clickdot: Use pointer confinement to confine drawed line

Peter Hutterer peter.hutterer at who-t.net
Thu Nov 19 20:49:15 PST 2015


On Tue, Nov 17, 2015 at 06:11:01PM +0800, Jonas Ådahl wrote:
> Use pointer confinement to make the line drawing not go outside the
> drawing area. It is toggled with the right pointer button.
> 
> Signed-off-by: Jonas Ådahl <jadahl at gmail.com>

patch itself is Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>, but
seem my comment about shoving stuff into clickdot from patch 19.

Cheers,
   Peter

> ---
>  clients/clickdot.c | 33 +++++++++++++++++++++++++++++++--
>  1 file changed, 31 insertions(+), 2 deletions(-)
> 
> diff --git a/clients/clickdot.c b/clients/clickdot.c
> index 776f8da..1597e11 100644
> --- a/clients/clickdot.c
> +++ b/clients/clickdot.c
> @@ -25,6 +25,7 @@
>  
>  #include "config.h"
>  
> +#include <stdbool.h>
>  #include <stdint.h>
>  #include <stdio.h>
>  #include <stdlib.h>
> @@ -63,6 +64,8 @@ struct clickdot {
>  	struct input *cursor_timeout_input;
>  	int cursor_timeout_fd;
>  	struct task cursor_timeout_task;
> +
> +	bool pointer_confined;
>  };
>  
>  static void
> @@ -207,16 +210,32 @@ key_handler(struct window *window, struct input *input, uint32_t time,
>  }
>  
>  static void
> +toggle_pointer_confine(struct clickdot *clickdot, struct input *input)
> +{
> +	if (clickdot->pointer_confined) {
> +		window_unconfine_pointer(clickdot->window);
> +	} else {
> +		window_confine_pointer_to_widget(clickdot->window,
> +						 clickdot->widget,
> +						 input);
> +	}
> +
> +	clickdot->pointer_confined = !clickdot->pointer_confined;
> +}
> +
> +static void
>  button_handler(struct widget *widget,
>  	       struct input *input, uint32_t time,
>  	       uint32_t button,
>  	       enum wl_pointer_button_state state, void *data)
>  {
>  	struct clickdot *clickdot = data;
> +	bool is_pressed = state == WL_POINTER_BUTTON_STATE_PRESSED;
>  
> -	if (state == WL_POINTER_BUTTON_STATE_PRESSED && button == BTN_LEFT)
> +	if (is_pressed && button == BTN_LEFT)
>  		input_get_position(input, &clickdot->dot.x, &clickdot->dot.y);
> -
> +	else if (is_pressed && button == BTN_RIGHT)
> +		toggle_pointer_confine(clickdot, input);
>  	widget_schedule_redraw(widget);
>  }
>  
> @@ -284,6 +303,14 @@ cursor_timeout_func(struct task *task, uint32_t events)
>  				CURSOR_LEFT_PTR);
>  }
>  
> +static void
> +pointer_unconfined(struct window *window, struct input *input, void *data)
> +{
> +	struct clickdot *clickdot = data;
> +
> +	clickdot->pointer_confined = false;
> +}
> +
>  static struct clickdot *
>  clickdot_create(struct display *display)
>  {
> @@ -300,6 +327,8 @@ clickdot_create(struct display *display)
>  	window_set_user_data(clickdot->window, clickdot);
>  	window_set_keyboard_focus_handler(clickdot->window,
>  					  keyboard_focus_handler);
> +	window_set_pointer_unconfined_handler(clickdot->window,
> +					      pointer_unconfined);
>  
>  	widget_set_redraw_handler(clickdot->widget, redraw_handler);
>  	widget_set_button_handler(clickdot->widget, button_handler);
> -- 
> 2.4.3
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> 


More information about the wayland-devel mailing list