mirror of
https://gitlab.freedesktop.org/wayland/weston.git
synced 2026-01-04 23:50:19 +01:00
Implement the new dnd/selection protocol
The new protocol splits dnd/selection from wl_shell and allows us to move the implementation out of shell.c.
This commit is contained in:
parent
f02bb64d62
commit
47fe08aad5
10 changed files with 962 additions and 868 deletions
370
clients/dnd.c
370
clients/dnd.c
|
|
@ -30,7 +30,6 @@
|
|||
#include <sys/time.h>
|
||||
#include <cairo.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
||||
#include <wayland-client.h>
|
||||
|
||||
|
|
@ -54,17 +53,8 @@ struct dnd_drag {
|
|||
struct item *item;
|
||||
int x_offset, y_offset;
|
||||
const char *mime_type;
|
||||
};
|
||||
|
||||
struct dnd_offer {
|
||||
int refcount;
|
||||
struct dnd *dnd;
|
||||
struct wl_array types;
|
||||
struct task io_task;
|
||||
const char *drag_type;
|
||||
uint32_t tag;
|
||||
int x, y;
|
||||
int fd;
|
||||
struct wl_data_source *data_source;
|
||||
};
|
||||
|
||||
struct item {
|
||||
|
|
@ -183,25 +173,21 @@ dnd_draw(struct dnd *dnd)
|
|||
window_get_child_allocation(dnd->window, &allocation);
|
||||
cairo_rectangle(cr, allocation.x, allocation.y,
|
||||
allocation.width, allocation.height);
|
||||
cairo_clip(cr);
|
||||
cairo_push_group(cr);
|
||||
|
||||
cairo_translate(cr, allocation.x, allocation.y);
|
||||
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_set_source_rgba(cr, 0, 0, 0, 0.8);
|
||||
cairo_paint(cr);
|
||||
cairo_fill(cr);
|
||||
|
||||
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
||||
for (i = 0; i < ARRAY_LENGTH(dnd->items); i++) {
|
||||
if (!dnd->items[i])
|
||||
continue;
|
||||
cairo_set_source_surface(cr, dnd->items[i]->surface,
|
||||
dnd->items[i]->x, dnd->items[i]->y);
|
||||
dnd->items[i]->x + allocation.x,
|
||||
dnd->items[i]->y + allocation.y);
|
||||
cairo_paint(cr);
|
||||
}
|
||||
|
||||
cairo_pop_group_to_source(cr);
|
||||
cairo_paint(cr);
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_destroy(surface);
|
||||
window_flush(dnd->window);
|
||||
|
|
@ -224,16 +210,6 @@ keyboard_focus_handler(struct window *window,
|
|||
window_schedule_redraw(dnd->window);
|
||||
}
|
||||
|
||||
static void
|
||||
dnd_offer_destroy(struct dnd_offer *dnd_offer)
|
||||
{
|
||||
dnd_offer->refcount--;
|
||||
if (dnd_offer->refcount == 0) {
|
||||
wl_array_release(&dnd_offer->types);
|
||||
free(dnd_offer);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
dnd_add_item(struct dnd *dnd, struct item *item)
|
||||
{
|
||||
|
|
@ -272,17 +248,16 @@ dnd_get_item(struct dnd *dnd, int32_t x, int32_t y)
|
|||
}
|
||||
|
||||
static void
|
||||
drag_target(void *data,
|
||||
struct wl_drag *drag, const char *mime_type)
|
||||
data_source_target(void *data,
|
||||
struct wl_data_source *source, const char *mime_type)
|
||||
{
|
||||
struct dnd_drag *dnd_drag = data;
|
||||
struct dnd *dnd = dnd_drag->dnd;
|
||||
struct wl_input_device *device;
|
||||
cairo_surface_t *surface;
|
||||
struct wl_buffer *buffer;
|
||||
struct wl_data_device *device;
|
||||
|
||||
fprintf(stderr, "target %s\n", mime_type);
|
||||
device = input_get_input_device(dnd_drag->input);
|
||||
device = input_get_data_device(dnd_drag->input);
|
||||
dnd_drag->mime_type = mime_type;
|
||||
if (mime_type)
|
||||
surface = dnd_drag->opaque;
|
||||
|
|
@ -290,38 +265,35 @@ drag_target(void *data,
|
|||
surface = dnd_drag->translucent;
|
||||
|
||||
buffer = display_get_buffer_for_surface(dnd->display, surface);
|
||||
wl_input_device_attach(device, dnd_drag->time, buffer,
|
||||
dnd_drag->hotspot_x, dnd_drag->hotspot_y);
|
||||
wl_data_device_attach(device, dnd_drag->time, buffer,
|
||||
dnd_drag->hotspot_x, dnd_drag->hotspot_y);
|
||||
}
|
||||
|
||||
static void
|
||||
drag_finish(void *data, struct wl_drag *drag, int fd)
|
||||
data_source_send(void *data, struct wl_data_source *source,
|
||||
const char *mime_type, int32_t fd)
|
||||
{
|
||||
struct dnd_drag *dnd_drag = data;
|
||||
|
||||
if (!dnd_drag->mime_type) {
|
||||
dnd_add_item(dnd_drag->dnd, dnd_drag->item);
|
||||
window_schedule_redraw(dnd_drag->dnd->window);
|
||||
return;
|
||||
}
|
||||
|
||||
struct dnd_flower_message dnd_flower_message;
|
||||
|
||||
struct dnd_drag *dnd_drag = data;
|
||||
|
||||
dnd_flower_message.seed = dnd_drag->item->seed;
|
||||
|
||||
dnd_flower_message.x_offset = dnd_drag->x_offset;
|
||||
dnd_flower_message.y_offset = dnd_drag->y_offset;
|
||||
|
||||
fprintf(stderr, "got 'finish', fd %d, sending dnd_flower_message\n", fd);
|
||||
|
||||
write(fd, &dnd_flower_message, sizeof dnd_flower_message);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/* The 'finish' event marks the end of the session on the drag
|
||||
* source side and we need to clean up the drag object created
|
||||
* and the local state. */
|
||||
wl_drag_destroy(drag);
|
||||
static void
|
||||
data_source_cancelled(void *data, struct wl_data_source *source)
|
||||
{
|
||||
struct dnd_drag *dnd_drag = data;
|
||||
|
||||
/* The 'cancelled' event means that the source is no longer in
|
||||
* use by the drag (or current selection). We need to clean
|
||||
* up the drag object created and the local state. */
|
||||
|
||||
wl_data_source_destroy(dnd_drag->data_source);
|
||||
|
||||
/* Destroy the item that has been dragged out */
|
||||
cairo_surface_destroy(dnd_drag->item->surface);
|
||||
|
|
@ -332,178 +304,12 @@ drag_finish(void *data, struct wl_drag *drag, int fd)
|
|||
free(dnd_drag);
|
||||
}
|
||||
|
||||
static void
|
||||
drag_reject(void *data, struct wl_drag *drag)
|
||||
{
|
||||
struct dnd_drag *dnd_drag = data;
|
||||
|
||||
dnd_add_item(dnd_drag->dnd, dnd_drag->item);
|
||||
window_schedule_redraw(dnd_drag->dnd->window);
|
||||
}
|
||||
|
||||
static const struct wl_drag_listener drag_listener = {
|
||||
drag_target,
|
||||
drag_finish,
|
||||
drag_reject
|
||||
static const struct wl_data_source_listener data_source_listener = {
|
||||
data_source_target,
|
||||
data_source_send,
|
||||
data_source_cancelled
|
||||
};
|
||||
|
||||
static void
|
||||
drag_offer_offer(void *data,
|
||||
struct wl_drag_offer *offer, const char *type)
|
||||
{
|
||||
struct dnd_offer *dnd_offer = data;
|
||||
char **p;
|
||||
|
||||
p = wl_array_add(&dnd_offer->types, sizeof *p);
|
||||
if (p)
|
||||
*p = strdup(type);
|
||||
}
|
||||
|
||||
static void
|
||||
drag_offer_pointer_focus(void *data,
|
||||
struct wl_drag_offer *offer,
|
||||
uint32_t time, struct wl_surface *surface,
|
||||
int32_t x, int32_t y,
|
||||
int32_t surface_x, int32_t surface_y)
|
||||
{
|
||||
struct dnd_offer *dnd_offer = data;
|
||||
struct window *window;
|
||||
char **p, **end;
|
||||
|
||||
/* The last event in a dnd session is pointer_focus with a
|
||||
* NULL surface, whether or not we get the drop event. We
|
||||
* need to clean up the dnd_offer proxy and whatever state we
|
||||
* allocated. */
|
||||
if (!surface) {
|
||||
fprintf(stderr, "pointer focus NULL, session over\n");
|
||||
wl_drag_offer_destroy(offer);
|
||||
dnd_offer_destroy(dnd_offer);
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(stderr, "drag pointer focus %p\n", surface);
|
||||
fprintf(stderr, "offered types:\n");
|
||||
end = dnd_offer->types.data + dnd_offer->types.size;
|
||||
for (p = dnd_offer->types.data; p < end; p++)
|
||||
fprintf(stderr, "\%s\n", *p);
|
||||
|
||||
window = wl_surface_get_user_data(surface);
|
||||
dnd_offer->dnd = window_get_user_data(window);
|
||||
|
||||
if (!dnd_get_item(dnd_offer->dnd, surface_x, surface_y)) {
|
||||
wl_drag_offer_accept(offer, time, "application/x-wayland-dnd-flower");
|
||||
dnd_offer->drag_type = "application/x-wayland-dnd-flower";
|
||||
dnd_offer->x = surface_x;
|
||||
dnd_offer->y = surface_y;
|
||||
} else {
|
||||
wl_drag_offer_accept(offer, time, NULL);
|
||||
dnd_offer->drag_type = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
drag_offer_motion(void *data,
|
||||
struct wl_drag_offer *offer, uint32_t time,
|
||||
int32_t x, int32_t y, int32_t surface_x, int32_t surface_y)
|
||||
{
|
||||
struct dnd_offer *dnd_offer = data;
|
||||
|
||||
if (!dnd_get_item(dnd_offer->dnd, surface_x, surface_y)) {
|
||||
fprintf(stderr, "drag offer motion %d, %d, accepting\n",
|
||||
surface_x, surface_y);
|
||||
wl_drag_offer_accept(offer, time, "application/x-wayland-dnd-flower");
|
||||
dnd_offer->drag_type = "application/x-wayland-dnd-flower";
|
||||
dnd_offer->x = surface_x;
|
||||
dnd_offer->y = surface_y;
|
||||
} else {
|
||||
fprintf(stderr, "drag offer motion %d, %d, declining\n",
|
||||
surface_x, surface_y);
|
||||
wl_drag_offer_accept(offer, time, NULL);
|
||||
dnd_offer->drag_type = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
drop_io_func(struct task *task, uint32_t events)
|
||||
{
|
||||
struct dnd_offer *dnd_offer =
|
||||
container_of(task, struct dnd_offer, io_task);
|
||||
struct dnd *dnd = dnd_offer->dnd;
|
||||
struct dnd_flower_message dnd_flower_message;
|
||||
unsigned int len;
|
||||
struct item *item;
|
||||
|
||||
len = read(dnd_offer->fd,
|
||||
&dnd_flower_message, sizeof dnd_flower_message);
|
||||
fprintf(stderr, "read %d bytes\n", len);
|
||||
|
||||
close(dnd_offer->fd);
|
||||
|
||||
item = item_create(dnd->display,
|
||||
dnd_offer->x - dnd_flower_message.x_offset - 26,
|
||||
dnd_offer->y - dnd_flower_message.y_offset - 66,
|
||||
dnd_flower_message.seed);
|
||||
|
||||
dnd_add_item(dnd, item);
|
||||
window_schedule_redraw(dnd->window);
|
||||
|
||||
dnd_offer_destroy(dnd_offer);
|
||||
}
|
||||
|
||||
static void
|
||||
drag_offer_drop(void *data, struct wl_drag_offer *offer)
|
||||
{
|
||||
struct dnd_offer *dnd_offer = data;
|
||||
int p[2];
|
||||
|
||||
if (!dnd_offer->drag_type) {
|
||||
fprintf(stderr, "got 'drop', but no target\n");
|
||||
wl_drag_offer_reject(offer);
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(stderr, "got 'drop', sending write end of pipe\n");
|
||||
|
||||
dnd_offer->refcount++;
|
||||
pipe(p);
|
||||
wl_drag_offer_receive(offer, p[1]);
|
||||
close(p[1]);
|
||||
|
||||
dnd_offer->io_task.run = drop_io_func;
|
||||
dnd_offer->fd = p[0];
|
||||
display_watch_fd(dnd_offer->dnd->display,
|
||||
p[0], EPOLLIN, &dnd_offer->io_task);
|
||||
}
|
||||
|
||||
static const struct wl_drag_offer_listener drag_offer_listener = {
|
||||
drag_offer_offer,
|
||||
drag_offer_pointer_focus,
|
||||
drag_offer_motion,
|
||||
drag_offer_drop,
|
||||
};
|
||||
|
||||
static void
|
||||
global_handler(struct wl_display *display, uint32_t id,
|
||||
const char *interface, uint32_t version, void *data)
|
||||
{
|
||||
struct wl_drag_offer *offer;
|
||||
struct dnd_offer *dnd_offer;
|
||||
|
||||
if (strcmp(interface, "wl_drag_offer") != 0)
|
||||
return;
|
||||
|
||||
offer = wl_display_bind(display, id, &wl_drag_offer_interface);
|
||||
|
||||
dnd_offer = malloc(sizeof *dnd_offer);
|
||||
if (dnd_offer == NULL)
|
||||
return;
|
||||
|
||||
dnd_offer->refcount = 1;
|
||||
|
||||
wl_drag_offer_add_listener(offer, &drag_offer_listener, dnd_offer);
|
||||
wl_array_init(&dnd_offer->types);
|
||||
}
|
||||
|
||||
static cairo_surface_t *
|
||||
create_drag_cursor(struct dnd_drag *dnd_drag,
|
||||
struct item *item, int32_t x, int32_t y, double opacity)
|
||||
|
|
@ -564,7 +370,6 @@ dnd_button_handler(struct window *window,
|
|||
struct item *item;
|
||||
struct rectangle allocation;
|
||||
struct dnd_drag *dnd_drag;
|
||||
struct wl_drag *drag;
|
||||
int i;
|
||||
|
||||
window_get_child_allocation(dnd->window, &allocation);
|
||||
|
|
@ -574,8 +379,6 @@ dnd_button_handler(struct window *window,
|
|||
y -= allocation.y;
|
||||
|
||||
if (item && state == 1) {
|
||||
fprintf(stderr, "start drag, item %p\n", item);
|
||||
|
||||
dnd_drag = malloc(sizeof *dnd_drag);
|
||||
dnd_drag->dnd = dnd;
|
||||
dnd_drag->input = input;
|
||||
|
|
@ -591,34 +394,114 @@ dnd_button_handler(struct window *window,
|
|||
}
|
||||
}
|
||||
|
||||
dnd_drag->data_source =
|
||||
display_create_data_source(dnd->display);
|
||||
wl_data_source_add_listener(dnd_drag->data_source,
|
||||
&data_source_listener,
|
||||
dnd_drag);
|
||||
wl_data_source_offer(dnd_drag->data_source,
|
||||
"application/x-wayland-dnd-flower");
|
||||
wl_data_source_offer(dnd_drag->data_source,
|
||||
"text/plain; charset=utf-8");
|
||||
wl_data_device_start_drag(input_get_data_device(input),
|
||||
dnd_drag->data_source,
|
||||
window_get_wl_surface(window),
|
||||
time);
|
||||
|
||||
input_set_pointer_image(input, time, POINTER_DRAGGING);
|
||||
|
||||
dnd_drag->opaque =
|
||||
create_drag_cursor(dnd_drag, item, x, y, 1);
|
||||
dnd_drag->translucent =
|
||||
create_drag_cursor(dnd_drag, item, x, y, 0.2);
|
||||
|
||||
drag = window_create_drag(window);
|
||||
wl_drag_offer(drag, "application/x-wayland-dnd-flower");
|
||||
window_activate_drag(drag, window, input, time);
|
||||
wl_drag_add_listener(drag, &drag_listener, dnd_drag);
|
||||
window_schedule_redraw(dnd->window);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
lookup_cursor(struct dnd *dnd, int x, int y)
|
||||
{
|
||||
struct item *item;
|
||||
|
||||
item = dnd_get_item(dnd, x, y);
|
||||
if (item)
|
||||
return POINTER_HAND1;
|
||||
else
|
||||
return POINTER_LEFT_PTR;
|
||||
}
|
||||
|
||||
static int
|
||||
dnd_enter_handler(struct window *window,
|
||||
struct input *input, uint32_t time,
|
||||
int32_t x, int32_t y, void *data)
|
||||
{
|
||||
return lookup_cursor(data, x, y);
|
||||
}
|
||||
|
||||
static int
|
||||
dnd_motion_handler(struct window *window,
|
||||
struct input *input, uint32_t time,
|
||||
int32_t x, int32_t y,
|
||||
int32_t sx, int32_t sy, void *data)
|
||||
{
|
||||
return lookup_cursor(data, sx, sy);
|
||||
}
|
||||
|
||||
static void
|
||||
dnd_data_handler(struct window *window,
|
||||
struct input *input, uint32_t time,
|
||||
int32_t x, int32_t y, const char **types, void *data)
|
||||
{
|
||||
struct dnd *dnd = data;
|
||||
|
||||
if (!dnd_get_item(dnd, x, y)) {
|
||||
input_accept(input, time, types[0]);
|
||||
} else {
|
||||
input_accept(input, time, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dnd_receive_func(void *data, size_t len, int32_t x, int32_t y, void *user_data)
|
||||
{
|
||||
struct dnd *dnd = user_data;
|
||||
struct dnd_flower_message *message = data;
|
||||
struct item *item;
|
||||
struct rectangle allocation;
|
||||
|
||||
item = dnd_get_item(dnd, sx, sy);
|
||||
if (len == 0) {
|
||||
return;
|
||||
} else if (len != sizeof *message) {
|
||||
fprintf(stderr, "odd message length %ld, expected %ld\n",
|
||||
len, sizeof *message);
|
||||
return;
|
||||
}
|
||||
|
||||
window_get_child_allocation(dnd->window, &allocation);
|
||||
item = item_create(dnd->display,
|
||||
x - message->x_offset - allocation.x,
|
||||
y - message->y_offset - allocation.y,
|
||||
message->seed);
|
||||
|
||||
if (item)
|
||||
return POINTER_HAND1;
|
||||
else
|
||||
return POINTER_LEFT_PTR;
|
||||
dnd_add_item(dnd, item);
|
||||
window_schedule_redraw(dnd->window);
|
||||
}
|
||||
|
||||
static void
|
||||
dnd_drop_handler(struct window *window, struct input *input,
|
||||
int32_t x, int32_t y, void *data)
|
||||
{
|
||||
struct dnd *dnd = data;
|
||||
|
||||
if (dnd_get_item(dnd, x, y)) {
|
||||
fprintf(stderr, "got 'drop', but no target\n");
|
||||
return;
|
||||
}
|
||||
|
||||
input_receive_drag_data(input,
|
||||
"application/x-wayland-dnd-flower",
|
||||
dnd_receive_func, dnd);
|
||||
}
|
||||
|
||||
static struct dnd *
|
||||
|
|
@ -639,9 +522,6 @@ dnd_create(struct display *display)
|
|||
dnd->display = display;
|
||||
dnd->key = 100;
|
||||
|
||||
wl_display_add_global_listener(display_get_display(display),
|
||||
global_handler, dnd);
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(dnd->items); i++) {
|
||||
x = (i % 4) * (item_width + item_padding) + item_padding;
|
||||
y = (i / 4) * (item_height + item_padding) + item_padding;
|
||||
|
|
@ -655,11 +535,11 @@ dnd_create(struct display *display)
|
|||
window_set_redraw_handler(dnd->window, redraw_handler);
|
||||
window_set_keyboard_focus_handler(dnd->window,
|
||||
keyboard_focus_handler);
|
||||
window_set_button_handler(dnd->window,
|
||||
dnd_button_handler);
|
||||
|
||||
window_set_motion_handler(dnd->window,
|
||||
dnd_motion_handler);
|
||||
window_set_button_handler(dnd->window, dnd_button_handler);
|
||||
window_set_enter_handler(dnd->window, dnd_enter_handler);
|
||||
window_set_motion_handler(dnd->window, dnd_motion_handler);
|
||||
window_set_data_handler(dnd->window, dnd_data_handler);
|
||||
window_set_drop_handler(dnd->window, dnd_drop_handler);
|
||||
|
||||
width = 4 * (item_width + item_padding) + item_padding;
|
||||
height = 4 * (item_height + item_padding) + item_padding;
|
||||
|
|
@ -670,16 +550,12 @@ dnd_create(struct display *display)
|
|||
return dnd;
|
||||
}
|
||||
|
||||
static const GOptionEntry option_entries[] = {
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct display *d;
|
||||
|
||||
d = display_create(&argc, &argv, option_entries);
|
||||
d = display_create(&argc, &argv, NULL);
|
||||
if (d == NULL) {
|
||||
fprintf(stderr, "failed to create display: %m\n");
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -390,10 +390,8 @@ struct terminal {
|
|||
cairo_font_extents_t extents;
|
||||
cairo_scaled_font_t *font_normal, *font_bold;
|
||||
|
||||
struct wl_selection *selection;
|
||||
struct wl_selection_offer *selection_offer;
|
||||
uint32_t selection_offer_has_text;
|
||||
int32_t dragging, selection_active;
|
||||
struct wl_data_source *selection;
|
||||
int32_t dragging;
|
||||
int selection_start_x, selection_start_y;
|
||||
int selection_end_x, selection_end_y;
|
||||
};
|
||||
|
|
@ -2026,55 +2024,65 @@ terminal_data(struct terminal *terminal, const char *data, size_t length)
|
|||
}
|
||||
|
||||
static void
|
||||
selection_listener_send(void *data, struct wl_selection *selection,
|
||||
const char *mime_type, int fd)
|
||||
data_source_target(void *data,
|
||||
struct wl_data_source *source, const char *mime_type)
|
||||
{
|
||||
fprintf(stderr, "data_source_target, %s\n", mime_type);
|
||||
}
|
||||
|
||||
static void
|
||||
data_source_send(void *data,
|
||||
struct wl_data_source *source,
|
||||
const char *mime_type, int32_t fd)
|
||||
{
|
||||
struct terminal *terminal = data;
|
||||
|
||||
fprintf(stderr, "selection send, fd is %d\n", fd);
|
||||
terminal_send_selection(terminal, fd);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void
|
||||
selection_listener_cancelled(void *data, struct wl_selection *selection)
|
||||
data_source_cancelled(void *data, struct wl_data_source *source)
|
||||
{
|
||||
fprintf(stderr, "selection cancelled\n");
|
||||
wl_selection_destroy(selection);
|
||||
wl_data_source_destroy(source);
|
||||
}
|
||||
|
||||
static const struct wl_selection_listener selection_listener = {
|
||||
selection_listener_send,
|
||||
selection_listener_cancelled
|
||||
static const struct wl_data_source_listener data_source_listener = {
|
||||
data_source_target,
|
||||
data_source_send,
|
||||
data_source_cancelled
|
||||
};
|
||||
|
||||
static void selection_receive_func(void *data, size_t len,
|
||||
int32_t x, int32_t y, void *user_data)
|
||||
{
|
||||
struct terminal *terminal = user_data;
|
||||
|
||||
write(terminal->master, data, len);
|
||||
}
|
||||
|
||||
static int
|
||||
handle_bound_key(struct terminal *terminal,
|
||||
struct input *input, uint32_t sym, uint32_t time)
|
||||
{
|
||||
struct wl_shell *shell;
|
||||
|
||||
switch (sym) {
|
||||
case XK_X:
|
||||
/* Cut selection; terminal doesn't do cut, fall
|
||||
* through to copy. */
|
||||
case XK_C:
|
||||
shell = display_get_shell(terminal->display);
|
||||
terminal->selection = wl_shell_create_selection(shell);
|
||||
wl_selection_add_listener(terminal->selection,
|
||||
&selection_listener, terminal);
|
||||
wl_selection_offer(terminal->selection, "text/plain");
|
||||
wl_selection_activate(terminal->selection,
|
||||
input_get_input_device(input), time);
|
||||
|
||||
terminal->selection =
|
||||
display_create_data_source(terminal->display);
|
||||
wl_data_source_offer(terminal->selection,
|
||||
"text/plain; charset=utf-8");
|
||||
wl_data_source_add_listener(terminal->selection,
|
||||
&data_source_listener, terminal);
|
||||
input_set_selection(input, terminal->selection, time);
|
||||
return 1;
|
||||
case XK_V:
|
||||
/* Just pass the master fd of the pty to receive the
|
||||
* selection. */
|
||||
if (input_offers_mime_type(input, "text/plain"))
|
||||
input_receive_mime_type(input, "text/plain",
|
||||
terminal->master);
|
||||
input_receive_selection_data(input,
|
||||
"text/plain; charset=utf-8",
|
||||
selection_receive_func, terminal);
|
||||
return 1;
|
||||
case XK_X:
|
||||
/* cut selection; terminal doesn't do cut */
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -2092,7 +2100,7 @@ key_handler(struct window *window, struct input *input, uint32_t time,
|
|||
modifiers = input_get_modifiers(input);
|
||||
if ((modifiers & XKB_COMMON_CONTROL_MASK) &&
|
||||
(modifiers & XKB_COMMON_SHIFT_MASK) &&
|
||||
state && handle_bound_key(terminal, input, sym, 0))
|
||||
state && handle_bound_key(terminal, input, sym, time))
|
||||
return;
|
||||
|
||||
switch (sym) {
|
||||
|
|
@ -2234,7 +2242,6 @@ button_handler(struct window *window,
|
|||
case 272:
|
||||
if (state) {
|
||||
terminal->dragging = 1;
|
||||
terminal->selection_active = 0;
|
||||
input_get_position(input,
|
||||
&terminal->selection_start_x,
|
||||
&terminal->selection_start_y);
|
||||
|
|
@ -2257,7 +2264,6 @@ motion_handler(struct window *window,
|
|||
struct terminal *terminal = data;
|
||||
|
||||
if (terminal->dragging) {
|
||||
terminal->selection_active = 1;
|
||||
input_get_position(input,
|
||||
&terminal->selection_end_x,
|
||||
&terminal->selection_end_y);
|
||||
|
|
|
|||
398
clients/window.c
398
clients/window.c
|
|
@ -20,6 +20,8 @@
|
|||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include "../config.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
|
@ -61,6 +63,7 @@ struct display {
|
|||
struct wl_shell *shell;
|
||||
struct wl_shm *shm;
|
||||
struct wl_output *output;
|
||||
struct wl_data_device_manager *data_device_manager;
|
||||
struct rectangle screen_allocation;
|
||||
EGLDisplay dpy;
|
||||
EGLConfig rgb_config;
|
||||
|
|
@ -127,6 +130,8 @@ struct window {
|
|||
window_enter_handler_t enter_handler;
|
||||
window_leave_handler_t leave_handler;
|
||||
window_item_focus_handler_t item_focus_handler;
|
||||
window_data_handler_t data_handler;
|
||||
window_drop_handler_t drop_handler;
|
||||
|
||||
struct wl_list item_list;
|
||||
struct item *focus_item;
|
||||
|
|
@ -147,11 +152,14 @@ struct input {
|
|||
struct wl_input_device *input_device;
|
||||
struct window *pointer_focus;
|
||||
struct window *keyboard_focus;
|
||||
struct selection_offer *offer;
|
||||
uint32_t current_pointer_image;
|
||||
uint32_t modifiers;
|
||||
int32_t x, y, sx, sy;
|
||||
struct wl_list link;
|
||||
|
||||
struct wl_data_device *data_device;
|
||||
struct data_offer *drag_offer;
|
||||
struct data_offer *selection_offer;
|
||||
};
|
||||
|
||||
enum {
|
||||
|
|
@ -695,7 +703,6 @@ display_get_pointer_surface(struct display *display, int pointer,
|
|||
return cairo_surface_reference(surface);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
window_attach_surface(struct window *window);
|
||||
|
||||
|
|
@ -1132,8 +1139,8 @@ get_pointer_location(struct window *window, int32_t x, int32_t y)
|
|||
return location;
|
||||
}
|
||||
|
||||
static void
|
||||
set_pointer_image(struct input *input, uint32_t time, int pointer)
|
||||
void
|
||||
input_set_pointer_image(struct input *input, uint32_t time, int pointer)
|
||||
{
|
||||
struct display *display = input->display;
|
||||
struct wl_buffer *buffer;
|
||||
|
|
@ -1233,7 +1240,7 @@ window_handle_motion(void *data, struct wl_input_device *input_device,
|
|||
x, y, sx, sy,
|
||||
window->user_data);
|
||||
|
||||
set_pointer_image(input, time, pointer);
|
||||
input_set_pointer_image(input, time, pointer);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -1364,7 +1371,7 @@ window_handle_pointer_focus(void *data,
|
|||
item = window_find_item(window, x, y);
|
||||
window_set_focus_item(window, item);
|
||||
|
||||
set_pointer_image(input, time, pointer);
|
||||
input_set_pointer_image(input, time, pointer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1435,13 +1442,238 @@ input_get_modifiers(struct input *input)
|
|||
return input->modifiers;
|
||||
}
|
||||
|
||||
struct wl_drag *
|
||||
window_create_drag(struct window *window)
|
||||
{
|
||||
cairo_device_flush (window->display->rgb_device);
|
||||
cairo_device_flush (window->display->argb_device);
|
||||
struct data_offer {
|
||||
struct wl_data_offer *offer;
|
||||
struct input *input;
|
||||
struct wl_array types;
|
||||
int refcount;
|
||||
|
||||
return wl_shell_create_drag(window->display->shell);
|
||||
struct task io_task;
|
||||
int fd;
|
||||
data_func_t func;
|
||||
int32_t x, y;
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
static void
|
||||
data_offer_offer(void *data, struct wl_data_offer *wl_data_offer, const char *type)
|
||||
{
|
||||
struct data_offer *offer = data;
|
||||
char **p;
|
||||
|
||||
p = wl_array_add(&offer->types, sizeof *p);
|
||||
*p = strdup(type);
|
||||
}
|
||||
|
||||
static const struct wl_data_offer_listener data_offer_listener = {
|
||||
data_offer_offer,
|
||||
};
|
||||
|
||||
static void
|
||||
data_offer_destroy(struct data_offer *offer)
|
||||
{
|
||||
char **p;
|
||||
|
||||
offer->refcount--;
|
||||
if (offer->refcount == 0) {
|
||||
wl_data_offer_destroy(offer->offer);
|
||||
for (p = offer->types.data; *p; p++)
|
||||
free(*p);
|
||||
wl_array_release(&offer->types);
|
||||
free(offer);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
data_device_data_offer(void *data,
|
||||
struct wl_data_device *data_device, uint32_t id)
|
||||
{
|
||||
struct data_offer *offer;
|
||||
|
||||
offer = malloc(sizeof *offer);
|
||||
|
||||
wl_array_init(&offer->types);
|
||||
offer->refcount = 1;
|
||||
offer->input = data;
|
||||
|
||||
/* FIXME: Generate typesafe wrappers for this */
|
||||
offer->offer = (struct wl_data_offer *)
|
||||
wl_proxy_create_for_id((struct wl_proxy *) data_device,
|
||||
id, &wl_data_offer_interface);
|
||||
|
||||
wl_data_offer_add_listener(offer->offer,
|
||||
&data_offer_listener, offer);
|
||||
}
|
||||
|
||||
static void
|
||||
data_device_enter(void *data, struct wl_data_device *data_device,
|
||||
uint32_t time, struct wl_surface *surface,
|
||||
int32_t x, int32_t y, struct wl_data_offer *offer)
|
||||
{
|
||||
struct input *input = data;
|
||||
struct window *window;
|
||||
char **p;
|
||||
|
||||
input->drag_offer = wl_data_offer_get_user_data(offer);
|
||||
window = wl_surface_get_user_data(surface);
|
||||
input->pointer_focus = window;
|
||||
|
||||
p = wl_array_add(&input->drag_offer->types, sizeof *p);
|
||||
*p = NULL;
|
||||
|
||||
window = input->pointer_focus;
|
||||
if (window->data_handler)
|
||||
window->data_handler(window, input, time, x, y,
|
||||
input->drag_offer->types.data,
|
||||
window->user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
data_device_leave(void *data, struct wl_data_device *data_device)
|
||||
{
|
||||
struct input *input = data;
|
||||
|
||||
data_offer_destroy(input->drag_offer);
|
||||
input->drag_offer = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
data_device_motion(void *data, struct wl_data_device *data_device,
|
||||
uint32_t time, int32_t x, int32_t y)
|
||||
{
|
||||
struct input *input = data;
|
||||
struct window *window = input->pointer_focus;
|
||||
|
||||
input->sx = x;
|
||||
input->sy = y;
|
||||
|
||||
if (window->data_handler)
|
||||
window->data_handler(window, input, time, x, y,
|
||||
input->drag_offer->types.data,
|
||||
window->user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
data_device_drop(void *data, struct wl_data_device *data_device)
|
||||
{
|
||||
struct input *input = data;
|
||||
struct window *window = input->pointer_focus;
|
||||
|
||||
if (window->drop_handler)
|
||||
window->drop_handler(window, input,
|
||||
input->sx, input->sy, window->user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
data_device_selection(void *data,
|
||||
struct wl_data_device *wl_data_device,
|
||||
struct wl_data_offer *offer)
|
||||
{
|
||||
struct input *input = data;
|
||||
char **p;
|
||||
|
||||
if (input->selection_offer)
|
||||
data_offer_destroy(input->selection_offer);
|
||||
|
||||
input->selection_offer = wl_data_offer_get_user_data(offer);
|
||||
p = wl_array_add(&input->selection_offer->types, sizeof *p);
|
||||
*p = NULL;
|
||||
}
|
||||
|
||||
static const struct wl_data_device_listener data_device_listener = {
|
||||
data_device_data_offer,
|
||||
data_device_enter,
|
||||
data_device_leave,
|
||||
data_device_motion,
|
||||
data_device_drop,
|
||||
data_device_selection
|
||||
};
|
||||
|
||||
struct wl_data_device *
|
||||
input_get_data_device(struct input *input)
|
||||
{
|
||||
return input->data_device;
|
||||
}
|
||||
|
||||
void
|
||||
input_set_selection(struct input *input,
|
||||
struct wl_data_source *source, uint32_t time)
|
||||
{
|
||||
wl_data_device_set_selection(input->data_device, source, time);
|
||||
}
|
||||
|
||||
void
|
||||
input_accept(struct input *input, uint32_t time, const char *type)
|
||||
{
|
||||
wl_data_offer_accept(input->drag_offer->offer, time, type);
|
||||
}
|
||||
|
||||
static void
|
||||
offer_io_func(struct task *task, uint32_t events)
|
||||
{
|
||||
struct data_offer *offer =
|
||||
container_of(task, struct data_offer, io_task);
|
||||
unsigned int len;
|
||||
char buffer[4096];
|
||||
|
||||
len = read(offer->fd, buffer, sizeof buffer);
|
||||
offer->func(buffer, len,
|
||||
offer->x, offer->y, offer->user_data);
|
||||
|
||||
if (len == 0) {
|
||||
close(offer->fd);
|
||||
data_offer_destroy(offer);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
data_offer_receive_data(struct data_offer *offer, const char *mime_type,
|
||||
data_func_t func, void *user_data)
|
||||
{
|
||||
int p[2];
|
||||
|
||||
pipe2(p, O_CLOEXEC);
|
||||
wl_data_offer_receive(offer->offer, mime_type, p[1]);
|
||||
close(p[1]);
|
||||
|
||||
offer->io_task.run = offer_io_func;
|
||||
offer->fd = p[0];
|
||||
offer->func = func;
|
||||
offer->refcount++;
|
||||
offer->user_data = user_data;
|
||||
|
||||
display_watch_fd(offer->input->display,
|
||||
offer->fd, EPOLLIN, &offer->io_task);
|
||||
}
|
||||
|
||||
void
|
||||
input_receive_drag_data(struct input *input, const char *mime_type,
|
||||
data_func_t func, void *data)
|
||||
{
|
||||
data_offer_receive_data(input->drag_offer, mime_type, func, data);
|
||||
input->drag_offer->x = input->sx;
|
||||
input->drag_offer->y = input->sy;
|
||||
}
|
||||
|
||||
int
|
||||
input_receive_selection_data(struct input *input, const char *mime_type,
|
||||
data_func_t func, void *data)
|
||||
{
|
||||
char **p;
|
||||
|
||||
if (input->selection_offer == NULL)
|
||||
return -1;
|
||||
|
||||
for (p = input->selection_offer->types.data; *p; p++)
|
||||
if (strcmp(mime_type, *p) == 0)
|
||||
break;
|
||||
|
||||
if (*p == NULL)
|
||||
return -1;
|
||||
|
||||
data_offer_receive_data(input->selection_offer,
|
||||
mime_type, func, data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -1452,13 +1684,6 @@ window_move(struct window *window, struct input *input, uint32_t time)
|
|||
window->surface, input->input_device, time);
|
||||
}
|
||||
|
||||
void
|
||||
window_activate_drag(struct wl_drag *drag, struct window *window,
|
||||
struct input *input, uint32_t time)
|
||||
{
|
||||
wl_drag_activate(drag, window->surface, input->input_device, time);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_configure(void *data, struct wl_shell *shell,
|
||||
uint32_t time, uint32_t edges,
|
||||
|
|
@ -1665,6 +1890,18 @@ window_set_item_focus_handler(struct window *window,
|
|||
window->item_focus_handler = handler;
|
||||
}
|
||||
|
||||
void
|
||||
window_set_data_handler(struct window *window, window_data_handler_t handler)
|
||||
{
|
||||
window->data_handler = handler;
|
||||
}
|
||||
|
||||
void
|
||||
window_set_drop_handler(struct window *window, window_drop_handler_t handler)
|
||||
{
|
||||
window->drop_handler = handler;
|
||||
}
|
||||
|
||||
void
|
||||
window_set_transparent(struct window *window, int transparent)
|
||||
{
|
||||
|
|
@ -1834,113 +2071,12 @@ display_add_input(struct display *d, uint32_t id)
|
|||
wl_input_device_add_listener(input->input_device,
|
||||
&input_device_listener, input);
|
||||
wl_input_device_set_user_data(input->input_device, input);
|
||||
}
|
||||
|
||||
struct selection_offer {
|
||||
struct display *display;
|
||||
struct wl_selection_offer *offer;
|
||||
struct wl_array types;
|
||||
struct input *input;
|
||||
};
|
||||
|
||||
int
|
||||
input_offers_mime_type(struct input *input, const char *type)
|
||||
{
|
||||
struct selection_offer *offer = input->offer;
|
||||
char **p, **end;
|
||||
|
||||
if (offer == NULL)
|
||||
return 0;
|
||||
|
||||
end = offer->types.data + offer->types.size;
|
||||
for (p = offer->types.data; p < end; p++)
|
||||
if (strcmp(*p, type) == 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
input_receive_mime_type(struct input *input, const char *type, int fd)
|
||||
{
|
||||
struct selection_offer *offer = input->offer;
|
||||
|
||||
/* FIXME: A number of things can go wrong here: the object may
|
||||
* not be the current selection offer any more (which could
|
||||
* still work, but the source may have gone away or just
|
||||
* destroyed its wl_selection) or the offer may not have the
|
||||
* requested type after all (programmer/client error,
|
||||
* typically) */
|
||||
wl_selection_offer_receive(offer->offer, type, fd);
|
||||
}
|
||||
|
||||
static void
|
||||
selection_offer_offer(void *data,
|
||||
struct wl_selection_offer *selection_offer,
|
||||
const char *type)
|
||||
{
|
||||
struct selection_offer *offer = data;
|
||||
|
||||
char **p;
|
||||
|
||||
p = wl_array_add(&offer->types, sizeof *p);
|
||||
if (p)
|
||||
*p = strdup(type);
|
||||
};
|
||||
|
||||
static void
|
||||
selection_offer_keyboard_focus(void *data,
|
||||
struct wl_selection_offer *selection_offer,
|
||||
struct wl_input_device *input_device)
|
||||
{
|
||||
struct selection_offer *offer = data;
|
||||
struct input *input;
|
||||
char **p, **end;
|
||||
|
||||
if (input_device == NULL) {
|
||||
printf("selection offer retracted %p\n", selection_offer);
|
||||
input = offer->input;
|
||||
input->offer = NULL;
|
||||
wl_selection_offer_destroy(selection_offer);
|
||||
wl_array_release(&offer->types);
|
||||
free(offer);
|
||||
return;
|
||||
}
|
||||
|
||||
input = wl_input_device_get_user_data(input_device);
|
||||
printf("new selection offer %p:", selection_offer);
|
||||
|
||||
offer->input = input;
|
||||
input->offer = offer;
|
||||
end = offer->types.data + offer->types.size;
|
||||
for (p = offer->types.data; p < end; p++)
|
||||
printf(" %s", *p);
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
struct wl_selection_offer_listener selection_offer_listener = {
|
||||
selection_offer_offer,
|
||||
selection_offer_keyboard_focus
|
||||
};
|
||||
|
||||
static void
|
||||
add_selection_offer(struct display *d, uint32_t id)
|
||||
{
|
||||
struct selection_offer *offer;
|
||||
|
||||
offer = malloc(sizeof *offer);
|
||||
if (offer == NULL)
|
||||
return;
|
||||
|
||||
offer->offer =
|
||||
wl_display_bind(d->display, id, &wl_selection_offer_interface);
|
||||
offer->display = d;
|
||||
wl_array_init(&offer->types);
|
||||
offer->input = NULL;
|
||||
|
||||
wl_selection_offer_add_listener(offer->offer,
|
||||
&selection_offer_listener, offer);
|
||||
input->data_device =
|
||||
wl_data_device_manager_get_data_device(d->data_device_manager,
|
||||
input->input_device);
|
||||
wl_data_device_add_listener(input->data_device,
|
||||
&data_device_listener, input);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -1962,8 +2098,10 @@ display_handle_global(struct wl_display *display, uint32_t id,
|
|||
wl_shell_add_listener(d->shell, &shell_listener, d);
|
||||
} else if (strcmp(interface, "wl_shm") == 0) {
|
||||
d->shm = wl_display_bind(display, id, &wl_shm_interface);
|
||||
} else if (strcmp(interface, "wl_selection_offer") == 0) {
|
||||
add_selection_offer(d, id);
|
||||
} else if (strcmp(interface, "wl_data_device_manager") == 0) {
|
||||
d->data_device_manager =
|
||||
wl_display_bind(display, id,
|
||||
&wl_data_device_manager_interface);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2215,6 +2353,12 @@ display_get_egl_display(struct display *d)
|
|||
return d->dpy;
|
||||
}
|
||||
|
||||
struct wl_data_source *
|
||||
display_create_data_source(struct display *display)
|
||||
{
|
||||
return wl_data_device_manager_create_data_source(display->data_device_manager);
|
||||
}
|
||||
|
||||
EGLConfig
|
||||
display_get_rgb_egl_config(struct display *d)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -57,6 +57,9 @@ display_get_compositor(struct display *display);
|
|||
struct wl_shell *
|
||||
display_get_shell(struct display *display);
|
||||
|
||||
struct wl_data_source *
|
||||
display_create_data_source(struct display *display);
|
||||
|
||||
#ifdef EGL_NO_DISPLAY
|
||||
EGLDisplay
|
||||
display_get_egl_display(struct display *d);
|
||||
|
|
@ -99,11 +102,6 @@ display_get_pointer_surface(struct display *display, int pointer,
|
|||
int *width, int *height,
|
||||
int *hotspot_x, int *hotspot_y);
|
||||
|
||||
void
|
||||
display_add_drag_listener(struct display *display,
|
||||
const struct wl_drag_listener *drag_listener,
|
||||
void *data);
|
||||
|
||||
void
|
||||
display_defer(struct display *display, struct task *task);
|
||||
|
||||
|
|
@ -157,6 +155,16 @@ typedef int (*window_motion_handler_t)(struct window *window,
|
|||
int32_t x, int32_t y,
|
||||
int32_t sx, int32_t sy, void *data);
|
||||
|
||||
typedef void (*window_data_handler_t)(struct window *window,
|
||||
struct input *input, uint32_t time,
|
||||
int32_t x, int32_t y,
|
||||
const char **types,
|
||||
void *data);
|
||||
|
||||
typedef void (*window_drop_handler_t)(struct window *window,
|
||||
struct input *input,
|
||||
int32_t x, int32_t y, void *data);
|
||||
|
||||
typedef void (*window_item_focus_handler_t)(struct window *window,
|
||||
struct item *focus, void *data);
|
||||
|
||||
|
|
@ -174,6 +182,9 @@ window_add_item(struct window *window, void *data);
|
|||
|
||||
typedef void (*item_func_t)(struct item *item, void *data);
|
||||
|
||||
typedef void (*data_func_t)(void *data, size_t len,
|
||||
int32_t x, int32_t y, void *user_data);
|
||||
|
||||
void
|
||||
window_for_each_item(struct window *window, item_func_t func, void *data);
|
||||
|
||||
|
|
@ -285,19 +296,20 @@ void
|
|||
window_set_item_focus_handler(struct window *window,
|
||||
window_item_focus_handler_t handler);
|
||||
|
||||
void
|
||||
window_set_data_handler(struct window *window,
|
||||
window_data_handler_t handler);
|
||||
|
||||
void
|
||||
window_set_drop_handler(struct window *window,
|
||||
window_drop_handler_t handler);
|
||||
|
||||
void
|
||||
window_set_title(struct window *window, const char *title);
|
||||
|
||||
const char *
|
||||
window_get_title(struct window *window);
|
||||
|
||||
struct wl_drag *
|
||||
window_create_drag(struct window *window);
|
||||
|
||||
void
|
||||
window_activate_drag(struct wl_drag *drag, struct window *window,
|
||||
struct input *input, uint32_t time);
|
||||
|
||||
void
|
||||
item_get_allocation(struct item *item, struct rectangle *allocation);
|
||||
|
||||
|
|
@ -308,6 +320,9 @@ item_set_allocation(struct item *item,
|
|||
void *
|
||||
item_get_user_data(struct item *item);
|
||||
|
||||
void
|
||||
input_set_pointer_image(struct input *input, uint32_t time, int pointer);
|
||||
|
||||
void
|
||||
input_get_position(struct input *input, int32_t *x, int32_t *y);
|
||||
|
||||
|
|
@ -317,10 +332,24 @@ input_get_modifiers(struct input *input);
|
|||
struct wl_input_device *
|
||||
input_get_input_device(struct input *input);
|
||||
|
||||
int
|
||||
input_offers_mime_type(struct input *input, const char *type);
|
||||
struct wl_data_device *
|
||||
input_get_data_device(struct input *input);
|
||||
|
||||
void
|
||||
input_receive_mime_type(struct input *input, const char *type, int fd);
|
||||
input_set_selection(struct input *input,
|
||||
struct wl_data_source *source, uint32_t time);
|
||||
|
||||
void
|
||||
input_accept(struct input *input, uint32_t time, const char *type);
|
||||
|
||||
|
||||
void
|
||||
input_receive_drag_data(struct input *input, const char *mime_type,
|
||||
data_func_t func, void *user_data);
|
||||
|
||||
int
|
||||
input_receive_selection_data(struct input *input, const char *mime_type,
|
||||
data_func_t func, void *data);
|
||||
|
||||
enum {
|
||||
CONFIG_KEY_INTEGER,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ wayland_compositor_SOURCES = \
|
|||
compositor.c \
|
||||
compositor.h \
|
||||
image-loader.c \
|
||||
data-device.c \
|
||||
screenshooter.c \
|
||||
screenshooter-protocol.c \
|
||||
screenshooter-server-protocol.h \
|
||||
|
|
|
|||
|
|
@ -1457,17 +1457,10 @@ WL_EXPORT void
|
|||
wlsc_surface_activate(struct wlsc_surface *surface,
|
||||
struct wlsc_input_device *device, uint32_t time)
|
||||
{
|
||||
struct wlsc_shell *shell = surface->compositor->shell;
|
||||
|
||||
wlsc_surface_raise(surface);
|
||||
if (device->selection)
|
||||
shell->set_selection_focus(shell,
|
||||
device->selection,
|
||||
&surface->surface, time);
|
||||
|
||||
wl_input_device_set_keyboard_focus(&device->input_device,
|
||||
&surface->surface,
|
||||
time);
|
||||
&surface->surface, time);
|
||||
wlsc_data_device_set_keyboard_focus(device);
|
||||
}
|
||||
|
||||
struct wlsc_binding {
|
||||
|
|
@ -1719,10 +1712,12 @@ input_device_attach(struct wl_client *client,
|
|||
|
||||
if (time < device->input_device.pointer_focus_time)
|
||||
return;
|
||||
#if 0
|
||||
if (device->input_device.pointer_focus == NULL)
|
||||
return;
|
||||
if (device->input_device.pointer_focus->resource.client != client)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (buffer_resource) {
|
||||
buffer = buffer_resource->data;
|
||||
|
|
@ -1762,6 +1757,7 @@ wlsc_input_device_init(struct wlsc_input_device *device,
|
|||
struct wlsc_compositor *ec)
|
||||
{
|
||||
wl_input_device_init(&device->input_device);
|
||||
wl_list_init(&device->drag_resource_list);
|
||||
|
||||
wl_display_add_global(ec->wl_display, &wl_input_device_interface,
|
||||
device, bind_input_device);
|
||||
|
|
@ -1781,6 +1777,7 @@ wlsc_input_device_init(struct wlsc_input_device *device,
|
|||
wl_list_insert(ec->input_device_list.prev, &device->link);
|
||||
|
||||
wlsc_input_device_set_pointer_image(device, WLSC_POINTER_LEFT_PTR);
|
||||
device->selection_data_source = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -2102,6 +2099,8 @@ wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display)
|
|||
|
||||
screenshooter_create(ec);
|
||||
|
||||
wlsc_data_device_manager_init(ec);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
if (wlsc_shader_init(&ec->texture_shader,
|
||||
|
|
|
|||
|
|
@ -112,6 +112,16 @@ struct wlsc_input_device {
|
|||
struct wl_list link;
|
||||
uint32_t modifier_state;
|
||||
struct wl_selection *selection;
|
||||
|
||||
struct wl_list drag_resource_list;
|
||||
struct wlsc_data_source *drag_data_source;
|
||||
struct wl_surface *drag_focus;
|
||||
struct wl_resource *drag_focus_resource;
|
||||
struct wl_listener drag_focus_listener;
|
||||
|
||||
struct wlsc_data_source *selection_data_source;
|
||||
struct wl_listener selection_data_source_listener;
|
||||
struct wl_grab grab;
|
||||
};
|
||||
|
||||
enum wlsc_visual {
|
||||
|
|
@ -163,9 +173,6 @@ struct wlsc_shell {
|
|||
void (*configure)(struct wlsc_shell *shell,
|
||||
struct wlsc_surface *surface,
|
||||
int32_t x, int32_t y, int32_t width, int32_t height);
|
||||
void (*set_selection_focus)(struct wlsc_shell *shell,
|
||||
struct wl_selection *selection,
|
||||
struct wl_surface *surface, uint32_t time);
|
||||
};
|
||||
|
||||
enum {
|
||||
|
|
@ -410,6 +417,11 @@ struct wlsc_process {
|
|||
struct wl_list link;
|
||||
};
|
||||
|
||||
int
|
||||
wlsc_data_device_manager_init(struct wlsc_compositor *compositor);
|
||||
void
|
||||
wlsc_data_device_set_keyboard_focus(struct wlsc_input_device *device);
|
||||
|
||||
void
|
||||
wlsc_watch_process(struct wlsc_process *process);
|
||||
|
||||
|
|
|
|||
459
compositor/data-device.c
Normal file
459
compositor/data-device.c
Normal file
|
|
@ -0,0 +1,459 @@
|
|||
/*
|
||||
* Copyright © 2011 Kristian Høgsberg
|
||||
*
|
||||
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||
* documentation for any purpose is hereby granted without fee, provided that
|
||||
* the above copyright notice appear in all copies and that both that copyright
|
||||
* notice and this permission notice appear in supporting documentation, and
|
||||
* that the name of the copyright holders not be used in advertising or
|
||||
* publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission. The copyright holders make no representations
|
||||
* about the suitability of this software for any purpose. It is provided "as
|
||||
* is" without express or implied warranty.
|
||||
*
|
||||
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
||||
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
||||
* OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "compositor.h"
|
||||
|
||||
struct wlsc_data_source {
|
||||
struct wl_resource resource;
|
||||
struct wl_array mime_types;
|
||||
int refcount;
|
||||
};
|
||||
|
||||
static void
|
||||
wlsc_data_source_unref(struct wlsc_data_source *source)
|
||||
{
|
||||
source->refcount--;
|
||||
|
||||
if (source->refcount == 1 && source->resource.object.id != 0) {
|
||||
wl_resource_post_event(&source->resource,
|
||||
WL_DATA_SOURCE_CANCELLED);
|
||||
} else if (source->refcount == 0) {
|
||||
free(source);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
data_offer_accept(struct wl_client *client, struct wl_resource *resource,
|
||||
uint32_t time, const char *mime_type)
|
||||
{
|
||||
struct wlsc_data_source *source = resource->data;
|
||||
|
||||
/* FIXME: Check that client is currently focused by the input
|
||||
* device that is currently dragging this data source. Should
|
||||
* this be a wl_data_device request? */
|
||||
|
||||
wl_resource_post_event(&source->resource,
|
||||
WL_DATA_SOURCE_TARGET, mime_type);
|
||||
}
|
||||
|
||||
static void
|
||||
data_offer_receive(struct wl_client *client, struct wl_resource *resource,
|
||||
const char *mime_type, int32_t fd)
|
||||
{
|
||||
struct wlsc_data_source *source = resource->data;
|
||||
|
||||
wl_resource_post_event(&source->resource,
|
||||
WL_DATA_SOURCE_SEND, mime_type, fd);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void
|
||||
data_offer_destroy(struct wl_client *client, struct wl_resource *resource)
|
||||
{
|
||||
wl_resource_destroy(resource, wlsc_compositor_get_time());
|
||||
}
|
||||
|
||||
static void
|
||||
destroy_data_offer(struct wl_resource *resource)
|
||||
{
|
||||
struct wlsc_data_source *source = resource->data;
|
||||
|
||||
wlsc_data_source_unref(source);
|
||||
free(resource);
|
||||
}
|
||||
|
||||
static const struct wl_data_offer_interface data_offer_interface = {
|
||||
data_offer_accept,
|
||||
data_offer_receive,
|
||||
data_offer_destroy,
|
||||
};
|
||||
|
||||
static struct wl_resource *
|
||||
wlsc_data_source_send_offer(struct wlsc_data_source *source,
|
||||
struct wl_resource *target)
|
||||
{
|
||||
struct wl_resource *resource;
|
||||
char **p, **end;
|
||||
|
||||
resource = wl_client_new_object(target->client,
|
||||
&wl_data_offer_interface,
|
||||
&data_offer_interface, source);
|
||||
resource->destroy = destroy_data_offer;
|
||||
|
||||
source->refcount++;
|
||||
|
||||
wl_resource_post_event(target, WL_DATA_DEVICE_DATA_OFFER, resource);
|
||||
|
||||
end = source->mime_types.data + source->mime_types.size;
|
||||
for (p = source->mime_types.data; p < end; p++)
|
||||
wl_resource_post_event(resource, WL_DATA_OFFER_OFFER, *p);
|
||||
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
static void
|
||||
data_source_offer(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
const char *type)
|
||||
{
|
||||
struct wlsc_data_source *source = resource->data;
|
||||
char **p;
|
||||
|
||||
p = wl_array_add(&source->mime_types, sizeof *p);
|
||||
if (p)
|
||||
*p = strdup(type);
|
||||
if (!p || !*p)
|
||||
wl_resource_post_no_memory(resource);
|
||||
}
|
||||
|
||||
static void
|
||||
data_source_destroy(struct wl_client *client, struct wl_resource *resource)
|
||||
{
|
||||
wl_resource_destroy(resource, wlsc_compositor_get_time());
|
||||
}
|
||||
|
||||
static struct wl_data_source_interface data_source_interface = {
|
||||
data_source_offer,
|
||||
data_source_destroy
|
||||
};
|
||||
|
||||
static struct wl_resource *
|
||||
find_resource(struct wl_list *list, struct wl_client *client)
|
||||
{
|
||||
struct wl_resource *r;
|
||||
|
||||
wl_list_for_each(r, list, link) {
|
||||
if (r->client == client)
|
||||
return r;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
destroy_drag_focus(struct wl_listener *listener,
|
||||
struct wl_resource *resource, uint32_t time)
|
||||
{
|
||||
struct wlsc_input_device *device =
|
||||
container_of(listener, struct wlsc_input_device,
|
||||
drag_focus_listener);
|
||||
|
||||
device->drag_focus_resource = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
drag_set_focus(struct wlsc_input_device *device,
|
||||
struct wl_surface *surface, uint32_t time,
|
||||
int32_t x, int32_t y)
|
||||
{
|
||||
struct wl_resource *resource, *offer;
|
||||
|
||||
if (device->drag_focus == surface)
|
||||
return;
|
||||
|
||||
if (device->drag_focus_resource) {
|
||||
wl_resource_post_event(device->drag_focus_resource,
|
||||
WL_DATA_DEVICE_LEAVE);
|
||||
wl_list_remove(&device->drag_focus_listener.link);
|
||||
device->drag_focus_resource = NULL;
|
||||
device->drag_focus = NULL;
|
||||
}
|
||||
|
||||
if (surface)
|
||||
resource = find_resource(&device->drag_resource_list,
|
||||
surface->resource.client);
|
||||
if (surface && resource) {
|
||||
offer = wlsc_data_source_send_offer(device->drag_data_source,
|
||||
resource);
|
||||
|
||||
wl_resource_post_event(resource,
|
||||
WL_DATA_DEVICE_ENTER,
|
||||
time, surface, x, y, offer);
|
||||
|
||||
device->drag_focus = surface;
|
||||
device->drag_focus_listener.func = destroy_drag_focus;
|
||||
wl_list_insert(resource->destroy_listener_list.prev,
|
||||
&device->drag_focus_listener.link);
|
||||
device->drag_focus_resource = resource;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
drag_grab_motion(struct wl_grab *grab,
|
||||
uint32_t time, int32_t x, int32_t y)
|
||||
{
|
||||
struct wlsc_input_device *device =
|
||||
container_of(grab, struct wlsc_input_device, grab);
|
||||
struct wlsc_surface *es;
|
||||
|
||||
es = pick_surface(&device->input_device, &x, &y);
|
||||
drag_set_focus(device, &es->surface, time, x, y);
|
||||
|
||||
if (es && device->drag_focus_resource)
|
||||
wl_resource_post_event(device->drag_focus_resource,
|
||||
WL_DATA_DEVICE_MOTION, time, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
drag_grab_button(struct wl_grab *grab,
|
||||
uint32_t time, int32_t button, int32_t state)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
drag_grab_end(struct wl_grab *grab, uint32_t time)
|
||||
{
|
||||
struct wlsc_input_device *device =
|
||||
container_of(grab, struct wlsc_input_device, grab);
|
||||
|
||||
if (device->drag_focus_resource)
|
||||
wl_resource_post_event(device->drag_focus_resource,
|
||||
WL_DATA_DEVICE_DROP);
|
||||
|
||||
drag_set_focus(device, NULL, time, 0, 0);
|
||||
wlsc_data_source_unref(device->drag_data_source);
|
||||
device->drag_data_source = NULL;
|
||||
}
|
||||
|
||||
static const struct wl_grab_interface drag_grab_interface = {
|
||||
drag_grab_motion,
|
||||
drag_grab_button,
|
||||
drag_grab_end
|
||||
};
|
||||
|
||||
static void
|
||||
data_device_start_drag(struct wl_client *client, struct wl_resource *resource,
|
||||
struct wl_resource *source_resource,
|
||||
struct wl_resource *surface_resource, uint32_t time)
|
||||
{
|
||||
struct wlsc_input_device *device = resource->data;
|
||||
struct wlsc_surface *surface = surface_resource->data;
|
||||
struct wlsc_surface *target;
|
||||
int32_t sx, sy;
|
||||
|
||||
/* FIXME: Check that client has implicit grab on the surface
|
||||
* that matches the given time. */
|
||||
|
||||
/* FIXME: Check that the data source type array isn't empty. */
|
||||
|
||||
if (wl_input_device_update_grab(&device->input_device, &device->grab,
|
||||
&surface->surface, time) < 0)
|
||||
return;
|
||||
|
||||
device->grab.interface = &drag_grab_interface;
|
||||
device->drag_data_source = source_resource->data;
|
||||
device->drag_data_source->refcount++;
|
||||
|
||||
target = pick_surface(&device->input_device, &sx, &sy);
|
||||
wl_input_device_set_pointer_focus(&device->input_device,
|
||||
NULL, time, 0, 0, 0, 0);
|
||||
drag_set_focus(device, &target->surface, time, sx, sy);
|
||||
}
|
||||
|
||||
static void
|
||||
data_device_attach(struct wl_client *client, struct wl_resource *resource,
|
||||
uint32_t time,
|
||||
struct wl_resource *buffer, int32_t x, int32_t y)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
destroy_selection_data_source(struct wl_listener *listener,
|
||||
struct wl_resource *resource, uint32_t time)
|
||||
{
|
||||
struct wlsc_input_device *device =
|
||||
container_of(listener, struct wlsc_input_device,
|
||||
selection_data_source_listener);
|
||||
struct wl_resource *data_device, *focus;
|
||||
|
||||
device->selection_data_source = NULL;
|
||||
|
||||
focus = device->input_device.keyboard_focus_resource;
|
||||
if (focus) {
|
||||
data_device = find_resource(&device->drag_resource_list,
|
||||
focus->client);
|
||||
wl_resource_post_event(data_device,
|
||||
WL_DATA_DEVICE_SELECTION, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
data_device_set_selection(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
struct wl_resource *source_resource, uint32_t time)
|
||||
{
|
||||
struct wlsc_input_device *device = resource->data;
|
||||
struct wl_resource *data_device, *focus, *offer;
|
||||
|
||||
if (!source_resource)
|
||||
return;
|
||||
|
||||
if (device->selection_data_source) {
|
||||
/* FIXME: All non-active clients will probably hold a
|
||||
* reference to the selection data source, and thus it
|
||||
* won't get destroyed until every client has been
|
||||
* activated and seen the new selection event. */
|
||||
wl_list_remove(&device->selection_data_source_listener.link);
|
||||
wlsc_data_source_unref(device->selection_data_source);
|
||||
device->selection_data_source = NULL;
|
||||
}
|
||||
|
||||
device->selection_data_source = source_resource->data;
|
||||
device->selection_data_source->refcount++;
|
||||
|
||||
focus = device->input_device.keyboard_focus_resource;
|
||||
if (focus) {
|
||||
data_device = find_resource(&device->drag_resource_list,
|
||||
focus->client);
|
||||
offer = wlsc_data_source_send_offer(device->selection_data_source,
|
||||
data_device);
|
||||
wl_resource_post_event(data_device,
|
||||
WL_DATA_DEVICE_SELECTION, offer);
|
||||
}
|
||||
|
||||
device->selection_data_source_listener.func =
|
||||
destroy_selection_data_source;
|
||||
wl_list_insert(source_resource->destroy_listener_list.prev,
|
||||
&device->selection_data_source_listener.link);
|
||||
}
|
||||
|
||||
static const struct wl_data_device_interface data_device_interface = {
|
||||
data_device_start_drag,
|
||||
data_device_attach,
|
||||
data_device_set_selection,
|
||||
};
|
||||
|
||||
static void
|
||||
destroy_data_source(struct wl_resource *resource)
|
||||
{
|
||||
struct wlsc_data_source *source =
|
||||
container_of(resource, struct wlsc_data_source, resource);
|
||||
char **p, **end;
|
||||
|
||||
end = source->mime_types.data + source->mime_types.size;
|
||||
for (p = source->mime_types.data; p < end; p++)
|
||||
free(*p);
|
||||
|
||||
wl_array_release(&source->mime_types);
|
||||
|
||||
source->resource.object.id = 0;
|
||||
wlsc_data_source_unref(source);
|
||||
}
|
||||
|
||||
static void
|
||||
create_data_source(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t id)
|
||||
{
|
||||
struct wlsc_data_source *source;
|
||||
|
||||
source = malloc(sizeof *source);
|
||||
if (source == NULL) {
|
||||
wl_resource_post_no_memory(resource);
|
||||
return;
|
||||
}
|
||||
|
||||
source->resource.destroy = destroy_data_source;
|
||||
source->resource.object.id = id;
|
||||
source->resource.object.interface = &wl_data_source_interface;
|
||||
source->resource.object.implementation =
|
||||
(void (**)(void)) &data_source_interface;
|
||||
source->resource.data = source;
|
||||
source->refcount = 1;
|
||||
|
||||
wl_array_init(&source->mime_types);
|
||||
wl_client_add_resource(client, &source->resource);
|
||||
}
|
||||
|
||||
static void unbind_data_device(struct wl_resource *resource)
|
||||
{
|
||||
wl_list_remove(&resource->link);
|
||||
free(resource);
|
||||
}
|
||||
|
||||
static void
|
||||
get_data_device(struct wl_client *client,
|
||||
struct wl_resource *manager_resource,
|
||||
uint32_t id, struct wl_resource *input_device)
|
||||
{
|
||||
struct wlsc_input_device *device = input_device->data;
|
||||
struct wl_resource *resource;
|
||||
|
||||
resource =
|
||||
wl_client_add_object(client, &wl_data_device_interface,
|
||||
&data_device_interface, id, device);
|
||||
|
||||
wl_list_insert(&device->drag_resource_list, &resource->link);
|
||||
resource->destroy = unbind_data_device;
|
||||
}
|
||||
|
||||
static const struct wl_data_device_manager_interface manager_interface = {
|
||||
create_data_source,
|
||||
get_data_device
|
||||
};
|
||||
|
||||
static void
|
||||
bind_manager(struct wl_client *client,
|
||||
void *data, uint32_t version, uint32_t id)
|
||||
{
|
||||
wl_client_add_object(client, &wl_data_device_manager_interface,
|
||||
&manager_interface, id, NULL);
|
||||
}
|
||||
|
||||
WL_EXPORT void
|
||||
wlsc_data_device_set_keyboard_focus(struct wlsc_input_device *device)
|
||||
{
|
||||
struct wl_resource *data_device, *focus, *offer;
|
||||
struct wlsc_data_source *source;
|
||||
|
||||
focus = device->input_device.keyboard_focus_resource;
|
||||
if (!focus)
|
||||
return;
|
||||
|
||||
data_device = find_resource(&device->drag_resource_list,
|
||||
focus->client);
|
||||
if (!data_device)
|
||||
return;
|
||||
|
||||
source = device->selection_data_source;
|
||||
if (source) {
|
||||
offer = wlsc_data_source_send_offer(source, data_device);
|
||||
wl_resource_post_event(data_device,
|
||||
WL_DATA_DEVICE_SELECTION, offer);
|
||||
}
|
||||
}
|
||||
|
||||
WL_EXPORT int
|
||||
wlsc_data_device_manager_init(struct wlsc_compositor *compositor)
|
||||
{
|
||||
if (wl_display_add_global(compositor->wl_display,
|
||||
&wl_data_device_manager_interface,
|
||||
NULL, bind_manager) == NULL)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -402,431 +402,9 @@ shell_set_fullscreen(struct wl_client *client,
|
|||
priv->type = SHELL_SURFACE_FULLSCREEN;
|
||||
}
|
||||
|
||||
static void
|
||||
destroy_drag(struct wl_resource *resource)
|
||||
{
|
||||
struct wl_drag *drag =
|
||||
container_of(resource, struct wl_drag, resource);
|
||||
|
||||
wl_list_remove(&drag->drag_focus_listener.link);
|
||||
if (drag->grab.input_device)
|
||||
wl_input_device_end_grab(drag->grab.input_device,
|
||||
wlsc_compositor_get_time());
|
||||
|
||||
free(drag);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
wl_drag_set_pointer_focus(struct wl_drag *drag,
|
||||
struct wl_surface *surface, uint32_t time,
|
||||
int32_t x, int32_t y, int32_t sx, int32_t sy)
|
||||
{
|
||||
char **p, **end;
|
||||
|
||||
if (drag->drag_focus == surface)
|
||||
return;
|
||||
|
||||
if (drag->drag_focus &&
|
||||
(!surface ||
|
||||
drag->drag_focus->resource.client != surface->resource.client))
|
||||
wl_resource_post_event(&drag->drag_offer.resource,
|
||||
WL_DRAG_OFFER_POINTER_FOCUS,
|
||||
time, NULL, 0, 0, 0, 0);
|
||||
|
||||
if (surface &&
|
||||
(!drag->drag_focus ||
|
||||
drag->drag_focus->resource.client != surface->resource.client)) {
|
||||
|
||||
drag->drag_offer.resource.client = surface->resource.client;
|
||||
end = drag->types.data + drag->types.size;
|
||||
for (p = drag->types.data; p < end; p++)
|
||||
wl_resource_post_event(&drag->drag_offer.resource,
|
||||
WL_DRAG_OFFER_OFFER, *p);
|
||||
}
|
||||
|
||||
if (surface) {
|
||||
wl_resource_post_event(&drag->drag_offer.resource,
|
||||
WL_DRAG_OFFER_POINTER_FOCUS,
|
||||
time, surface,
|
||||
x, y, sx, sy);
|
||||
|
||||
}
|
||||
|
||||
drag->drag_focus = surface;
|
||||
drag->pointer_focus_time = time;
|
||||
drag->target = NULL;
|
||||
|
||||
wl_list_remove(&drag->drag_focus_listener.link);
|
||||
if (surface)
|
||||
wl_list_insert(surface->resource.destroy_listener_list.prev,
|
||||
&drag->drag_focus_listener.link);
|
||||
}
|
||||
|
||||
static void
|
||||
drag_offer_accept(struct wl_client *client, struct wl_resource *resource,
|
||||
uint32_t time, const char *type)
|
||||
{
|
||||
struct wl_drag_offer *offer = resource->data;
|
||||
struct wl_drag *drag = container_of(offer, struct wl_drag, drag_offer);
|
||||
char **p, **end;
|
||||
|
||||
/* If the client responds to drag pointer_focus or motion
|
||||
* events after the pointer has left the surface, we just
|
||||
* discard the accept requests. The drag source just won't
|
||||
* get the corresponding 'target' events and eventually the
|
||||
* next surface/root will start sending events. */
|
||||
if (time < drag->pointer_focus_time)
|
||||
return;
|
||||
|
||||
drag->target = client;
|
||||
drag->type = NULL;
|
||||
end = drag->types.data + drag->types.size;
|
||||
for (p = drag->types.data; p < end; p++)
|
||||
if (type && strcmp(*p, type) == 0)
|
||||
drag->type = *p;
|
||||
|
||||
wl_resource_post_event(&drag->resource, WL_DRAG_TARGET, drag->type);
|
||||
}
|
||||
|
||||
static void
|
||||
drag_offer_receive(struct wl_client *client,
|
||||
struct wl_resource *resource, int fd)
|
||||
{
|
||||
struct wl_drag_offer *offer = resource->data;
|
||||
struct wl_drag *drag = container_of(offer, struct wl_drag, drag_offer);
|
||||
|
||||
wl_resource_post_event(&drag->resource, WL_DRAG_FINISH, fd);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void
|
||||
drag_offer_reject(struct wl_client *client, struct wl_resource *resource)
|
||||
{
|
||||
struct wl_drag_offer *offer = resource->data;
|
||||
struct wl_drag *drag = container_of(offer, struct wl_drag, drag_offer);
|
||||
|
||||
wl_resource_post_event(&drag->resource, WL_DRAG_REJECT);
|
||||
}
|
||||
|
||||
static const struct wl_drag_offer_interface drag_offer_interface = {
|
||||
drag_offer_accept,
|
||||
drag_offer_receive,
|
||||
drag_offer_reject
|
||||
};
|
||||
|
||||
static void
|
||||
drag_offer(struct wl_client *client,
|
||||
struct wl_resource *resource, const char *type)
|
||||
{
|
||||
struct wl_drag *drag = resource->data;
|
||||
char **p;
|
||||
|
||||
p = wl_array_add(&drag->types, sizeof *p);
|
||||
if (p)
|
||||
*p = strdup(type);
|
||||
if (!p || !*p)
|
||||
wl_resource_post_no_memory(resource);
|
||||
}
|
||||
|
||||
static void
|
||||
drag_grab_motion(struct wl_grab *grab,
|
||||
uint32_t time, int32_t x, int32_t y)
|
||||
{
|
||||
struct wl_drag *drag = container_of(grab, struct wl_drag, grab);
|
||||
struct wlsc_surface *es;
|
||||
int32_t sx, sy;
|
||||
|
||||
es = pick_surface(grab->input_device, &sx, &sy);
|
||||
wl_drag_set_pointer_focus(drag, &es->surface, time, x, y, sx, sy);
|
||||
if (es)
|
||||
wl_resource_post_event(&drag->drag_offer.resource,
|
||||
WL_DRAG_OFFER_MOTION,
|
||||
time, x, y, sx, sy);
|
||||
}
|
||||
|
||||
static void
|
||||
drag_grab_button(struct wl_grab *grab,
|
||||
uint32_t time, int32_t button, int32_t state)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
drag_grab_end(struct wl_grab *grab, uint32_t time)
|
||||
{
|
||||
struct wl_drag *drag = container_of(grab, struct wl_drag, grab);
|
||||
|
||||
if (drag->target)
|
||||
wl_resource_post_event(&drag->drag_offer.resource,
|
||||
WL_DRAG_OFFER_DROP);
|
||||
|
||||
wl_drag_set_pointer_focus(drag, NULL, time, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
static const struct wl_grab_interface drag_grab_interface = {
|
||||
drag_grab_motion,
|
||||
drag_grab_button,
|
||||
drag_grab_end
|
||||
};
|
||||
|
||||
static void
|
||||
drag_activate(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
struct wl_resource *surface_resource,
|
||||
struct wl_resource *device_resource, uint32_t time)
|
||||
{
|
||||
struct wl_drag *drag = resource->data;
|
||||
struct wl_surface *surface = surface_resource->data;
|
||||
struct wl_input_device *device = device_resource->data;
|
||||
struct wl_display *display = wl_client_get_display (client);
|
||||
struct wlsc_surface *target;
|
||||
int32_t sx, sy;
|
||||
|
||||
if (wl_input_device_update_grab(device,
|
||||
&drag->grab, surface, time) < 0)
|
||||
return;
|
||||
|
||||
drag->grab.interface = &drag_grab_interface;
|
||||
|
||||
drag->source = surface;
|
||||
|
||||
drag->drag_offer.resource.object.interface = &wl_drag_offer_interface;
|
||||
drag->drag_offer.resource.object.implementation =
|
||||
(void (**)(void)) &drag_offer_interface;
|
||||
|
||||
wl_display_add_global(display, &wl_drag_offer_interface, drag, NULL);
|
||||
|
||||
target = pick_surface(device, &sx, &sy);
|
||||
wl_input_device_set_pointer_focus(device, NULL, time, 0, 0, 0, 0);
|
||||
wl_drag_set_pointer_focus(drag, &target->surface, time,
|
||||
device->x, device->y, sx, sy);
|
||||
}
|
||||
|
||||
static void
|
||||
drag_destroy(struct wl_client *client, struct wl_resource *resource)
|
||||
{
|
||||
wl_resource_destroy(resource, wlsc_compositor_get_time());
|
||||
}
|
||||
|
||||
static const struct wl_drag_interface drag_interface = {
|
||||
drag_offer,
|
||||
drag_activate,
|
||||
drag_destroy,
|
||||
};
|
||||
|
||||
static void
|
||||
drag_handle_surface_destroy(struct wl_listener *listener,
|
||||
struct wl_resource *resource, uint32_t time)
|
||||
{
|
||||
struct wl_drag *drag =
|
||||
container_of(listener, struct wl_drag, drag_focus_listener);
|
||||
struct wl_surface *surface = (struct wl_surface *) resource;
|
||||
|
||||
if (drag->drag_focus == surface)
|
||||
wl_drag_set_pointer_focus(drag, NULL, time, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
shell_create_drag(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t id)
|
||||
{
|
||||
struct wl_drag *drag;
|
||||
|
||||
drag = malloc(sizeof *drag);
|
||||
if (drag == NULL) {
|
||||
wl_resource_post_no_memory(resource);
|
||||
return;
|
||||
}
|
||||
|
||||
memset(drag, 0, sizeof *drag);
|
||||
drag->resource.object.id = id;
|
||||
drag->resource.object.interface = &wl_drag_interface;
|
||||
drag->resource.object.implementation =
|
||||
(void (**)(void)) &drag_interface;
|
||||
|
||||
drag->resource.data = drag;
|
||||
drag->resource.destroy = destroy_drag;
|
||||
|
||||
drag->drag_focus_listener.func = drag_handle_surface_destroy;
|
||||
wl_list_init(&drag->drag_focus_listener.link);
|
||||
|
||||
wl_client_add_resource(client, &drag->resource);
|
||||
}
|
||||
|
||||
static void
|
||||
wlsc_selection_set_focus(struct wlsc_shell *shell,
|
||||
struct wl_selection *selection,
|
||||
struct wl_surface *surface, uint32_t time)
|
||||
{
|
||||
char **p, **end;
|
||||
|
||||
if (selection->selection_focus == surface)
|
||||
return;
|
||||
|
||||
if (selection->selection_focus != NULL)
|
||||
wl_resource_post_event(&selection->selection_offer.resource,
|
||||
WL_SELECTION_OFFER_KEYBOARD_FOCUS,
|
||||
NULL);
|
||||
|
||||
if (surface) {
|
||||
|
||||
selection->selection_offer.resource.client = surface->resource.client;
|
||||
end = selection->types.data + selection->types.size;
|
||||
for (p = selection->types.data; p < end; p++)
|
||||
wl_resource_post_event(&selection->selection_offer.resource,
|
||||
WL_SELECTION_OFFER_OFFER, *p);
|
||||
|
||||
wl_list_remove(&selection->selection_focus_listener.link);
|
||||
wl_list_insert(surface->resource.destroy_listener_list.prev,
|
||||
&selection->selection_focus_listener.link);
|
||||
|
||||
wl_resource_post_event(&selection->selection_offer.resource,
|
||||
WL_SELECTION_OFFER_KEYBOARD_FOCUS,
|
||||
selection->input_device);
|
||||
}
|
||||
|
||||
selection->selection_focus = surface;
|
||||
|
||||
wl_list_remove(&selection->selection_focus_listener.link);
|
||||
if (surface)
|
||||
wl_list_insert(surface->resource.destroy_listener_list.prev,
|
||||
&selection->selection_focus_listener.link);
|
||||
}
|
||||
|
||||
static void
|
||||
selection_offer_receive(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
const char *mime_type, int fd)
|
||||
{
|
||||
struct wl_selection_offer *offer = resource->data;
|
||||
struct wl_selection *selection =
|
||||
container_of(offer, struct wl_selection, selection_offer);
|
||||
|
||||
wl_resource_post_event(&selection->resource,
|
||||
WL_SELECTION_SEND, mime_type, fd);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static const struct wl_selection_offer_interface selection_offer_interface = {
|
||||
selection_offer_receive
|
||||
};
|
||||
|
||||
static void
|
||||
selection_offer(struct wl_client *client,
|
||||
struct wl_resource *resource, const char *type)
|
||||
{
|
||||
struct wl_selection *selection = resource->data;
|
||||
char **p;
|
||||
|
||||
p = wl_array_add(&selection->types, sizeof *p);
|
||||
if (p)
|
||||
*p = strdup(type);
|
||||
if (!p || !*p)
|
||||
wl_resource_post_no_memory(resource);
|
||||
}
|
||||
|
||||
static void
|
||||
selection_activate(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
struct wl_resource *input_resource, uint32_t time)
|
||||
{
|
||||
struct wl_selection *selection = resource->data;
|
||||
struct wlsc_input_device *wd = input_resource->data;
|
||||
struct wl_display *display = wl_client_get_display (client);
|
||||
struct wlsc_compositor *compositor = wd->compositor;
|
||||
|
||||
selection->input_device = &wd->input_device;
|
||||
|
||||
selection->selection_offer.resource.object.interface =
|
||||
&wl_selection_offer_interface;
|
||||
selection->selection_offer.resource.object.implementation =
|
||||
(void (**)(void)) &selection_offer_interface;
|
||||
|
||||
wl_display_add_global(display,
|
||||
&wl_selection_offer_interface, selection, NULL);
|
||||
|
||||
if (wd->selection) {
|
||||
wl_resource_post_event(&wd->selection->resource,
|
||||
WL_SELECTION_CANCELLED);
|
||||
}
|
||||
wd->selection = selection;
|
||||
|
||||
wlsc_selection_set_focus(compositor->shell, selection,
|
||||
wd->input_device.keyboard_focus, time);
|
||||
}
|
||||
|
||||
static void
|
||||
selection_destroy(struct wl_client *client, struct wl_resource *resource)
|
||||
{
|
||||
wl_resource_destroy(resource, wlsc_compositor_get_time());
|
||||
}
|
||||
|
||||
static const struct wl_selection_interface selection_interface = {
|
||||
selection_offer,
|
||||
selection_activate,
|
||||
selection_destroy
|
||||
};
|
||||
|
||||
static void
|
||||
destroy_selection(struct wl_resource *resource)
|
||||
{
|
||||
struct wl_selection *selection =
|
||||
container_of(resource, struct wl_selection, resource);
|
||||
struct wlsc_input_device *wd =
|
||||
(struct wlsc_input_device *) selection->input_device;
|
||||
struct wlsc_compositor *compositor = wd->compositor;
|
||||
|
||||
if (wd && wd->selection == selection) {
|
||||
wd->selection = NULL;
|
||||
wlsc_selection_set_focus(compositor->shell,
|
||||
selection, NULL,
|
||||
wlsc_compositor_get_time());
|
||||
}
|
||||
|
||||
wl_list_remove(&selection->selection_focus_listener.link);
|
||||
free(selection);
|
||||
}
|
||||
|
||||
static void
|
||||
selection_handle_surface_destroy(struct wl_listener *listener,
|
||||
struct wl_resource *resource, uint32_t time)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
shell_create_selection(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t id)
|
||||
{
|
||||
struct wl_selection *selection;
|
||||
|
||||
selection = malloc(sizeof *selection);
|
||||
if (selection == NULL) {
|
||||
wl_resource_post_no_memory(resource);
|
||||
return;
|
||||
}
|
||||
|
||||
memset(selection, 0, sizeof *selection);
|
||||
selection->resource.object.id = id;
|
||||
selection->resource.object.interface = &wl_selection_interface;
|
||||
selection->resource.object.implementation =
|
||||
(void (**)(void)) &selection_interface;
|
||||
|
||||
selection->client = client;
|
||||
selection->resource.destroy = destroy_selection;
|
||||
selection->selection_focus = NULL;
|
||||
|
||||
selection->selection_focus_listener.func =
|
||||
selection_handle_surface_destroy;
|
||||
wl_list_init(&selection->selection_focus_listener.link);
|
||||
|
||||
wl_client_add_resource(client, &selection->resource);
|
||||
}
|
||||
|
||||
static const struct wl_shell_interface shell_interface = {
|
||||
shell_move,
|
||||
shell_resize,
|
||||
shell_create_drag,
|
||||
shell_create_selection,
|
||||
shell_set_toplevel,
|
||||
shell_set_transient,
|
||||
shell_set_fullscreen
|
||||
|
|
@ -1361,7 +939,6 @@ shell_init(struct wlsc_compositor *ec)
|
|||
shell->shell.unlock = unlock;
|
||||
shell->shell.map = map;
|
||||
shell->shell.configure = configure;
|
||||
shell->shell.set_selection_focus = wlsc_selection_set_focus;
|
||||
|
||||
wl_list_init(&shell->hidden_surface_list);
|
||||
wl_list_init(&shell->backgrounds);
|
||||
|
|
|
|||
|
|
@ -632,14 +632,6 @@ home_key_binding(struct wl_input_device *device, uint32_t time,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
tablet_shell_set_selection_focus(struct wlsc_shell *shell,
|
||||
struct wl_selection *selection,
|
||||
struct wl_surface *surface,
|
||||
uint32_t time)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
|
||||
{
|
||||
|
|
@ -699,8 +691,7 @@ shell_init(struct wlsc_compositor *compositor)
|
|||
shell->shell.unlock = tablet_shell_unlock;
|
||||
shell->shell.map = tablet_shell_map;
|
||||
shell->shell.configure = tablet_shell_configure;
|
||||
shell->shell.set_selection_focus =
|
||||
tablet_shell_set_selection_focus;
|
||||
|
||||
launch_ux_daemon(shell);
|
||||
|
||||
tablet_shell_set_state(shell, STATE_STARTING);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue