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.
diff --git a/clients/window.c b/clients/window.c
index f24f42c..20d09d5 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -253,6 +253,7 @@
void *user_data;
int opaque;
int tooltip_count;
+ int default_cursor;
};
struct input {
@@ -1334,6 +1335,7 @@
widget->opaque = 0;
widget->tooltip = NULL;
widget->tooltip_count = 0;
+ widget->default_cursor = CURSOR_LEFT_PTR;
return widget;
}
@@ -1379,6 +1381,12 @@
}
void
+widget_set_default_cursor(struct widget *widget, int cursor)
+{
+ widget->default_cursor = cursor;
+}
+
+void
widget_get_allocation(struct widget *widget, struct rectangle *allocation)
{
*allocation = widget->allocation;
@@ -2241,7 +2249,7 @@
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 @@
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 @@
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 @@
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);
}