[PATCH weston 5/5] window: Implement animated cursors (using pointer surfaces)

Ander Conselvan de Oliveira conselvan2 at gmail.com
Mon Jun 18 06:04:12 PDT 2012


On 06/15/2012 06:05 PM, Kristian Høgsberg wrote:
> On Fri, Jun 15, 2012 at 05:27:36PM +0300, Ander Conselvan de Oliveira wrote:
>> Since the introduction of pointer.set_cursor(), it is possible for a
>> client to set the surface containing the pointer image and get frame
>> callbacks on it thus allowing a clear implementation of animated
>> cursors.
>>
>> This also makes the busy cursor hack of using frame callbacks on the
>> busy surface unnecessary.
>> ---

[...]

>> diff --git a/clients/window.c b/clients/window.c
>> index 57443d9..436f862 100644
>> --- a/clients/window.c
>> +++ b/clients/window.c
>> @@ -2304,13 +2305,61 @@ input_set_pointer_image_index(struct input *input, int pointer, int index)
>>   			  image->width, image->height);
>>   }
>>
>> +static const struct wl_callback_listener pointer_surface_listener;
>> +
>> +static void
>> +pointer_surface_frame_callback(void *data, struct wl_callback *callback,
>> +			       uint32_t time)
>> +{
>> +	struct input *input = data;
>> +	struct wl_cursor *cursor =
>> +		input->display->cursors[input->current_cursor];
>> +	int i;
>> +
>> +	if (callback) {
>> +		assert(callback == input->cursor_frame_cb);
>> +		wl_callback_destroy(callback);
>> +		input->cursor_frame_cb = NULL;
>> +	}
>> +
>> +	if (input->current_cursor == CURSOR_UNSET)
>> +		return;
>> +
>> +	/* FIXME We don't have the current time on the first call so we set
>> +	 * the animation start to the time of the first frame callback. */
>
> Better to check for callback == NULL to detect first frame (0 is a
> valid timestamp).  On the other hand, does it even matter?  Just
> always pass in the timestamp, and the animation will just start from a
> random frame.  Anyway, committed the patch as is, we can tweak this
> later.

This makes things simple and starting from a random frame doesn't seem 
like a problem. (One could even argue the behavior is better, since the 
animation doesn't reset every time the pointer enters some surface.)

But to do that we need to bring back the timestamp argument to 
input_set_pointer_image(), otherwise we might have a jump in the 
animation because we don't have a valid timestamp on the first call.


Ander

>> +	if (time == 0)
>> +		input->cursor_anim_start = 0;
>> +	else if (input->cursor_anim_start == 0)
>> +		input->cursor_anim_start = time;
>> +
>> +	if (time == 0 || input->cursor_anim_start == 0)
>> +		i = 0;
>> +	else
>> +		i = wl_cursor_frame(cursor, time - input->cursor_anim_start);
>> +
>> +	input_set_pointer_image_index(input, i);
>> +
>> +	if (cursor->image_count == 1)
>> +		return;
>> +
>> +	input->cursor_frame_cb = wl_surface_frame(input->pointer_surface);
>> +	wl_callback_add_listener(input->cursor_frame_cb,
>> +				&pointer_surface_listener, input);
>> +}
>> +
>> +static const struct wl_callback_listener pointer_surface_listener = {
>> +	pointer_surface_frame_callback
>> +};
>> +
>>   void
>>   input_set_pointer_image(struct input *input, int pointer)
>>   {
>>   	if (pointer == input->current_cursor)
>>   		return;
>>
>> -	input_set_pointer_image_index(input, pointer, 0);
>> +	input->current_cursor = pointer;
>> +	if (!input->cursor_frame_cb)
>> +		pointer_surface_frame_callback(input, NULL, 0);
>>   }
>>
>>   struct wl_data_device *
>> diff --git a/clients/window.h b/clients/window.h
>> index 8b8e816..da3815b 100644
>> --- a/clients/window.h
>> +++ b/clients/window.h
>> @@ -368,9 +368,6 @@ void
>>   input_set_pointer_image(struct input *input, int pointer);
>>
>>   void
>> -input_set_pointer_image_index(struct input *input, int pointer, int index);
>> -
>> -void
>>   input_get_position(struct input *input, int32_t *x, int32_t *y);
>>
>>   #define MOD_SHIFT_MASK		0x01
>> --
>> 1.7.4.1
>>
>> _______________________________________________
>> wayland-devel mailing list
>> wayland-devel at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> _______________________________________________
> 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