mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-01 22:58:40 -04:00
Provide visual feedback as to whether drop is supported
Change the cursor in response to target events.
This commit is contained in:
parent
b571f5db6b
commit
e968f9c6b9
3 changed files with 103 additions and 48 deletions
142
clients/dnd.c
142
clients/dnd.c
|
|
@ -45,7 +45,8 @@ struct dnd {
|
||||||
uint32_t key;
|
uint32_t key;
|
||||||
struct item *items[16];
|
struct item *items[16];
|
||||||
|
|
||||||
struct wl_buffer *buffer;
|
struct wl_buffer *translucent_buffer;
|
||||||
|
struct wl_buffer *opaque_buffer;
|
||||||
int hotspot_x, hotspot_y;
|
int hotspot_x, hotspot_y;
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
const char *drag_type;
|
const char *drag_type;
|
||||||
|
|
@ -198,8 +199,14 @@ static struct item *
|
||||||
dnd_get_item(struct dnd *dnd, int32_t x, int32_t y)
|
dnd_get_item(struct dnd *dnd, int32_t x, int32_t y)
|
||||||
{
|
{
|
||||||
struct item *item;
|
struct item *item;
|
||||||
|
struct rectangle rectangle;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
window_get_child_rectangle(dnd->window, &rectangle);
|
||||||
|
|
||||||
|
x -= rectangle.x;
|
||||||
|
y -= rectangle.y;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_LENGTH(dnd->items); i++) {
|
for (i = 0; i < ARRAY_LENGTH(dnd->items); i++) {
|
||||||
item = dnd->items[i];
|
item = dnd->items[i];
|
||||||
if (item &&
|
if (item &&
|
||||||
|
|
@ -231,10 +238,16 @@ drag_pointer_focus(void *data,
|
||||||
|
|
||||||
fprintf(stderr, "drag pointer focus %p\n", surface);
|
fprintf(stderr, "drag pointer focus %p\n", surface);
|
||||||
|
|
||||||
if (surface) {
|
if (!surface) {
|
||||||
|
dnd->drag_type = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dnd_get_item(dnd, surface_x, surface_y)) {
|
||||||
wl_drag_accept(drag, "text/plain");
|
wl_drag_accept(drag, "text/plain");
|
||||||
dnd->drag_type = "text/plain";
|
dnd->drag_type = "text/plain";
|
||||||
} else {
|
} else {
|
||||||
|
wl_drag_accept(drag, NULL);
|
||||||
dnd->drag_type = NULL;
|
dnd->drag_type = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -258,8 +271,13 @@ drag_motion(void *data,
|
||||||
* Problem is, we don't know when we've seen that last offer
|
* Problem is, we don't know when we've seen that last offer
|
||||||
* event, and we might need to look at all of them before we
|
* event, and we might need to look at all of them before we
|
||||||
* can decide which one to go with. */
|
* can decide which one to go with. */
|
||||||
wl_drag_accept(drag, "text/plain");
|
if (!dnd_get_item(dnd, surface_x, surface_y)) {
|
||||||
dnd->drag_type = "text/plain";
|
wl_drag_accept(drag, "text/plain");
|
||||||
|
dnd->drag_type = "text/plain";
|
||||||
|
} else {
|
||||||
|
wl_drag_accept(drag, NULL);
|
||||||
|
dnd->drag_type = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -270,10 +288,15 @@ drag_target(void *data,
|
||||||
struct input *input;
|
struct input *input;
|
||||||
struct wl_input_device *device;
|
struct wl_input_device *device;
|
||||||
|
|
||||||
|
fprintf(stderr, "target %s\n", mime_type);
|
||||||
input = wl_drag_get_user_data(drag);
|
input = wl_drag_get_user_data(drag);
|
||||||
device = input_get_input_device(input);
|
device = input_get_input_device(input);
|
||||||
wl_input_device_attach(device, dnd->buffer,
|
if (mime_type)
|
||||||
dnd->hotspot_x, dnd->hotspot_y);
|
wl_input_device_attach(device, dnd->opaque_buffer,
|
||||||
|
dnd->hotspot_x, dnd->hotspot_y);
|
||||||
|
else
|
||||||
|
wl_input_device_attach(device, dnd->translucent_buffer,
|
||||||
|
dnd->hotspot_x, dnd->hotspot_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|
@ -305,6 +328,10 @@ drag_drop(void *data, struct wl_drag *drag)
|
||||||
|
|
||||||
if (!dnd->drag_type) {
|
if (!dnd->drag_type) {
|
||||||
fprintf(stderr, "got 'drop', but no target\n");
|
fprintf(stderr, "got 'drop', but no target\n");
|
||||||
|
/* FIXME: Should send response so compositor and
|
||||||
|
* source knows it's over. Can't send -1 to indicate
|
||||||
|
* 'no target' though becauses of the way fd passing
|
||||||
|
* currently works. */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -339,61 +366,82 @@ static const struct wl_drag_listener drag_listener = {
|
||||||
drag_finish
|
drag_finish
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static cairo_surface_t *
|
||||||
|
create_drag_cursor(struct dnd *dnd, struct item *item, int32_t x, int32_t y,
|
||||||
|
double opacity)
|
||||||
|
{
|
||||||
|
cairo_surface_t *surface, *pointer;
|
||||||
|
int32_t pointer_width, pointer_height, hotspot_x, hotspot_y;
|
||||||
|
struct rectangle rectangle;
|
||||||
|
cairo_pattern_t *pattern;
|
||||||
|
cairo_t *cr;
|
||||||
|
|
||||||
|
pointer = display_get_pointer_surface(dnd->display,
|
||||||
|
POINTER_DRAGGING,
|
||||||
|
&pointer_width,
|
||||||
|
&pointer_height,
|
||||||
|
&hotspot_x,
|
||||||
|
&hotspot_y);
|
||||||
|
|
||||||
|
rectangle.width = item_width + 2 * pointer_width;
|
||||||
|
rectangle.height = item_height + 2 * pointer_height;
|
||||||
|
surface = display_create_surface(dnd->display, &rectangle);
|
||||||
|
|
||||||
|
cr = cairo_create(surface);
|
||||||
|
cairo_translate(cr, pointer_width, pointer_height);
|
||||||
|
|
||||||
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
||||||
|
cairo_set_source_rgba(cr, 0, 0, 0, 0);
|
||||||
|
cairo_paint(cr);
|
||||||
|
|
||||||
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
||||||
|
cairo_set_source_surface(cr, item->surface, 0, 0);
|
||||||
|
pattern = cairo_pattern_create_rgba(0, 0, 0, opacity);
|
||||||
|
cairo_mask(cr, pattern);
|
||||||
|
cairo_pattern_destroy(pattern);
|
||||||
|
|
||||||
|
cairo_set_source_surface(cr, pointer,
|
||||||
|
x - item->x - hotspot_x,
|
||||||
|
y - item->y - hotspot_y);
|
||||||
|
cairo_surface_destroy(pointer);
|
||||||
|
cairo_paint(cr);
|
||||||
|
/* FIXME: more cairo-gl brokeness */
|
||||||
|
display_flush_cairo_device(dnd->display);
|
||||||
|
cairo_destroy(cr);
|
||||||
|
|
||||||
|
dnd->hotspot_x = pointer_width + x - item->x;
|
||||||
|
dnd->hotspot_y = pointer_height + y - item->y;
|
||||||
|
|
||||||
|
return surface;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dnd_button_handler(struct window *window,
|
dnd_button_handler(struct window *window,
|
||||||
struct input *input, uint32_t time,
|
struct input *input, uint32_t time,
|
||||||
int button, int state, void *data)
|
int button, int state, void *data)
|
||||||
{
|
{
|
||||||
struct dnd *dnd = data;
|
struct dnd *dnd = data;
|
||||||
int32_t x, y, hotspot_x, hotspot_y, pointer_width, pointer_height;
|
int32_t x, y;
|
||||||
struct rectangle rectangle;
|
|
||||||
struct item *item;
|
struct item *item;
|
||||||
cairo_surface_t *surface, *pointer;
|
cairo_surface_t *surface;
|
||||||
cairo_t *cr;
|
struct rectangle rectangle;
|
||||||
|
|
||||||
input_get_position(input, &x, &y);
|
|
||||||
window_get_child_rectangle(dnd->window, &rectangle);
|
window_get_child_rectangle(dnd->window, &rectangle);
|
||||||
|
input_get_position(input, &x, &y);
|
||||||
|
item = dnd_get_item(dnd, x, y);
|
||||||
x -= rectangle.x;
|
x -= rectangle.x;
|
||||||
y -= rectangle.y;
|
y -= rectangle.y;
|
||||||
item = dnd_get_item(dnd, x, y);
|
|
||||||
|
|
||||||
if (item && state == 1) {
|
if (item && state == 1) {
|
||||||
fprintf(stderr, "start drag, item %p\n", item);
|
fprintf(stderr, "start drag, item %p\n", item);
|
||||||
|
|
||||||
pointer = display_get_pointer_surface(dnd->display,
|
surface = create_drag_cursor(dnd, item, x, y, 1);
|
||||||
POINTER_DRAGGING,
|
dnd->opaque_buffer =
|
||||||
&pointer_width,
|
display_get_buffer_for_surface(dnd->display, surface);
|
||||||
&pointer_height,
|
|
||||||
&hotspot_x,
|
|
||||||
&hotspot_y);
|
|
||||||
|
|
||||||
rectangle.width = item_width + 2 * pointer_width;
|
surface = create_drag_cursor(dnd, item, x, y, 0.2);
|
||||||
rectangle.height = item_height + 2 * pointer_height;
|
dnd->translucent_buffer =
|
||||||
surface = display_create_surface(dnd->display, &rectangle);
|
display_get_buffer_for_surface(dnd->display, surface);
|
||||||
|
|
||||||
cr = cairo_create(surface);
|
|
||||||
cairo_translate(cr, pointer_width, pointer_height);
|
|
||||||
|
|
||||||
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
|
||||||
cairo_set_source_rgba(cr, 0, 0, 0, 0);
|
|
||||||
cairo_paint(cr);
|
|
||||||
|
|
||||||
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
|
||||||
cairo_set_source_surface(cr, item->surface, 0, 0);
|
|
||||||
cairo_paint(cr);
|
|
||||||
|
|
||||||
cairo_set_source_surface(cr, pointer,
|
|
||||||
x - item->x - hotspot_x,
|
|
||||||
y - item->y - hotspot_y);
|
|
||||||
cairo_surface_destroy(pointer);
|
|
||||||
cairo_paint(cr);
|
|
||||||
cairo_destroy(cr);
|
|
||||||
|
|
||||||
dnd->buffer = display_get_buffer_for_surface(dnd->display,
|
|
||||||
surface);
|
|
||||||
dnd->hotspot_x = pointer_width + x - item->x;
|
|
||||||
dnd->hotspot_y = pointer_height + y - item->y;
|
|
||||||
|
|
||||||
window_start_drag(window, input, time);
|
window_start_drag(window, input, time);
|
||||||
|
|
||||||
|
|
@ -410,10 +458,8 @@ dnd_motion_handler(struct window *window,
|
||||||
{
|
{
|
||||||
struct dnd *dnd = data;
|
struct dnd *dnd = data;
|
||||||
struct item *item;
|
struct item *item;
|
||||||
struct rectangle rectangle;
|
|
||||||
|
|
||||||
window_get_child_rectangle(dnd->window, &rectangle);
|
item = dnd_get_item(dnd, sx, sy);
|
||||||
item = dnd_get_item(dnd, sx - rectangle.x, sy - rectangle.y);
|
|
||||||
|
|
||||||
if (item)
|
if (item)
|
||||||
return POINTER_HAND1;
|
return POINTER_HAND1;
|
||||||
|
|
|
||||||
|
|
@ -407,6 +407,12 @@ window_draw_decorations(struct window *window)
|
||||||
cairo_device_flush (window->display->device);
|
cairo_device_flush (window->display->device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
display_flush_cairo_device(struct display *display)
|
||||||
|
{
|
||||||
|
cairo_device_flush (display->device);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
window_draw_fullscreen(struct window *window)
|
window_draw_fullscreen(struct window *window)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,9 @@ display_add_drag_listener(struct display *display,
|
||||||
const struct wl_drag_listener *drag_listener,
|
const struct wl_drag_listener *drag_listener,
|
||||||
void *data);
|
void *data);
|
||||||
|
|
||||||
|
void
|
||||||
|
display_flush_cairo_device(struct display *display);
|
||||||
|
|
||||||
void
|
void
|
||||||
display_run(struct display *d);
|
display_run(struct display *d);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue