window: Add a widget default cursor convenience helper

In a few cases, we set a motion handler just to be able to set a fixed
cursor.  This adds a default cursor helper that can be used in those cases.
In case of the 'transformed' test case, we also avoid a brief flicker
of the pointer cursor, which is set on enter when the move grab is lifted.
Kristian Høgsberg 12 years ago
parent ec07669a08
commit bf74d5242a
  1. 9
      clients/flower.c
  2. 9
      clients/transformed.c
  3. 22
      clients/window.c
  4. 2
      clients/window.h

@ -129,13 +129,6 @@ redraw_handler(struct widget *widget, void *data)
cairo_surface_destroy(surface);
}
static int
motion_handler(struct widget *widget, struct input *input,
uint32_t time, float x, float y, void *data)
{
return CURSOR_HAND1;
}
static void
button_handler(struct widget *widget,
struct input *input, uint32_t time,
@ -184,8 +177,8 @@ int main(int argc, char *argv[])
widget_set_resize_handler(flower.widget, resize_handler);
widget_set_redraw_handler(flower.widget, redraw_handler);
widget_set_motion_handler(flower.widget, motion_handler);
widget_set_button_handler(flower.widget, button_handler);
widget_set_default_cursor(flower.widget, CURSOR_HAND1);
window_schedule_resize(flower.window, flower.width, flower.height);

@ -185,13 +185,6 @@ output_handler(struct window *window, struct output *output, int enter,
window_schedule_redraw(window);
}
static int
motion_handler(struct widget *widget, struct input *input,
uint32_t time, float x, float y, void *data)
{
return CURSOR_BLANK;
}
static void
button_handler(struct widget *widget,
struct input *input, uint32_t time,
@ -237,9 +230,9 @@ int main(int argc, char *argv[])
window_set_title(transformed.window, "Transformed");
widget_set_transparent(transformed.widget, 0);
widget_set_default_cursor(transformed.widget, CURSOR_BLANK);
widget_set_redraw_handler(transformed.widget, redraw_handler);
widget_set_motion_handler(transformed.widget, motion_handler);
widget_set_button_handler(transformed.widget, button_handler);
window_set_fullscreen_handler(transformed.window, fullscreen_handler);

@ -253,6 +253,7 @@ struct widget {
void *user_data;
int opaque;
int tooltip_count;
int default_cursor;
};
struct input {
@ -1334,6 +1335,7 @@ widget_create(struct window *window, void *data)
widget->opaque = 0;
widget->tooltip = NULL;
widget->tooltip_count = 0;
widget->default_cursor = CURSOR_LEFT_PTR;
return widget;
}
@ -1378,6 +1380,12 @@ widget_destroy(struct widget *widget)
free(widget);
}
void
widget_set_default_cursor(struct widget *widget, int cursor)
{
widget->default_cursor = cursor;
}
void
widget_get_allocation(struct widget *widget, struct rectangle *allocation)
{
@ -2241,7 +2249,7 @@ input_set_focus_widget(struct input *input, struct widget *focus,
float x, float y)
{
struct widget *old, *widget;
int pointer = CURSOR_LEFT_PTR;
int cursor;
if (focus == input->focus_widget)
return;
@ -2262,10 +2270,12 @@ input_set_focus_widget(struct input *input, struct widget *focus,
widget = input->grab;
input->focus_widget = focus;
if (widget->enter_handler)
pointer = widget->enter_handler(focus, input, x, y,
widget->user_data);
cursor = widget->enter_handler(focus, input, x, y,
widget->user_data);
else
cursor = widget->default_cursor;
input_set_pointer_image(input, pointer);
input_set_pointer_image(input, cursor);
}
}
@ -2354,7 +2364,7 @@ pointer_handle_motion(void *data, struct wl_pointer *pointer,
struct input *input = data;
struct window *window = input->pointer_focus;
struct widget *widget;
int cursor = CURSOR_LEFT_PTR;
int cursor;
float sx = wl_fixed_to_double(sx_w);
float sy = wl_fixed_to_double(sy_w);
@ -2377,6 +2387,8 @@ pointer_handle_motion(void *data, struct wl_pointer *pointer,
cursor = widget->motion_handler(input->focus_widget,
input, time, sx, sy,
widget->user_data);
else
cursor = input->focus_widget->default_cursor;
input_set_pointer_image(input, cursor);
}

@ -360,6 +360,8 @@ widget_add_widget(struct widget *parent, void *data);
void
widget_destroy(struct widget *widget);
void
widget_set_default_cursor(struct widget *widget, int cursor);
void
widget_get_allocation(struct widget *widget, struct rectangle *allocation);
void

Loading…
Cancel
Save