Feed button events through compositor.

This also generalizes the code to send events to a surface a bit.
This commit is contained in:
Kristian Høgsberg 2008-12-10 13:16:50 -05:00
parent 715a081cf4
commit 5a75c90d01
4 changed files with 42 additions and 36 deletions

View File

@ -758,8 +758,8 @@ notify_pointer_motion(struct wl_compositor *compositor,
if (es) { if (es) {
sx = (x - es->map.x) * es->width / es->map.width; sx = (x - es->map.x) * es->width / es->map.width;
sy = (y - es->map.y) * es->height / es->map.height; sy = (y - es->map.y) * es->height / es->map.height;
wl_display_post_surface_motion(ec->wl_display, es->wl_surface, wl_surface_post_event(es->wl_surface, source,
source, x, y, sx, sy); WL_INPUT_MOTION, x, y, sx, sy);
} }
ec->pointer->map.x = x - hotspot_x; ec->pointer->map.x = x - hotspot_x;
@ -784,6 +784,10 @@ notify_pointer_button(struct wl_compositor *compositor,
if (es) { if (es) {
wl_list_remove(&es->link); wl_list_remove(&es->link);
wl_list_insert(ec->surface_list.prev, &es->link); wl_list_insert(ec->surface_list.prev, &es->link);
/* FIXME: Swallow click on raise? */
wl_surface_post_event(es->wl_surface, source,
WL_INPUT_BUTTON, button, state);
} }
schedule_repaint(ec); schedule_repaint(ec);

View File

@ -42,10 +42,18 @@ struct wl_input_device {
static const struct wl_method input_device_methods[] = { static const struct wl_method input_device_methods[] = {
}; };
static const struct wl_event input_device_events[] = {
{ "motion", "ii" },
{ "button", "uu" },
{ "key", "uu" },
};
static const struct wl_interface input_device_interface = { static const struct wl_interface input_device_interface = {
"input_device", 1, "input_device", 1,
ARRAY_LENGTH(input_device_methods), ARRAY_LENGTH(input_device_methods),
input_device_methods, input_device_methods,
ARRAY_LENGTH(input_device_events),
input_device_events,
}; };
static void wl_input_device_data(int fd, uint32_t mask, void *data) static void wl_input_device_data(int fd, uint32_t mask, void *data)

View File

@ -212,13 +212,12 @@ void
wl_client_destroy(struct wl_client *client); wl_client_destroy(struct wl_client *client);
static void static void
wl_client_marshal(struct wl_client *client, struct wl_object *sender, wl_client_vmarshal(struct wl_client *client, struct wl_object *sender,
uint32_t opcode, ...) uint32_t opcode, va_list ap)
{ {
const struct wl_event *event; const struct wl_event *event;
struct wl_object *object; struct wl_object *object;
uint32_t args[10], size; uint32_t args[10], size;
va_list ap;
int i, count; int i, count;
event = &sender->interface->events[opcode]; event = &sender->interface->events[opcode];
@ -226,7 +225,6 @@ wl_client_marshal(struct wl_client *client, struct wl_object *sender,
assert(count <= ARRAY_LENGTH(args)); assert(count <= ARRAY_LENGTH(args));
size = 0; size = 0;
va_start(ap, opcode);
for (i = 2; i < count; i++) { for (i = 2; i < count; i++) {
switch (event->signature[i - 2]) { switch (event->signature[i - 2]) {
case 'u': case 'u':
@ -249,7 +247,6 @@ wl_client_marshal(struct wl_client *client, struct wl_object *sender,
break; break;
} }
} }
va_end(ap);
size += 2 * sizeof args[0]; size += 2 * sizeof args[0];
args[0] = sender->id; args[0] = sender->id;
@ -257,6 +254,17 @@ wl_client_marshal(struct wl_client *client, struct wl_object *sender,
wl_connection_write(client->connection, args, size); wl_connection_write(client->connection, args, size);
} }
static void
wl_client_marshal(struct wl_client *client, struct wl_object *sender,
uint32_t opcode, ...)
{
va_list ap;
va_start(ap, opcode);
wl_client_vmarshal(client, sender, opcode, ap);
va_end(ap);
}
static void static void
wl_client_demarshal(struct wl_client *client, struct wl_object *target, wl_client_demarshal(struct wl_client *client, struct wl_object *target,
const struct wl_method *method, size_t size) const struct wl_method *method, size_t size)
@ -628,26 +636,16 @@ wl_display_send_event(struct wl_display *display, uint32_t *data, size_t size)
} }
} }
#define WL_INPUT_MOTION 0
#define WL_INPUT_BUTTON 1
#define WL_INPUT_KEY 2
WL_EXPORT void WL_EXPORT void
wl_display_post_surface_motion(struct wl_display *display, wl_surface_post_event(struct wl_surface *surface,
struct wl_surface *surface, struct wl_object *sender,
struct wl_object *source, uint32_t event, ...)
int32_t x, int32_t y, int32_t sx, int32_t sy)
{ {
uint32_t p[6]; va_list ap;
p[0] = source->id; va_start(ap, event);
p[1] = (sizeof p << 16) | WL_INPUT_MOTION; wl_client_vmarshal(surface->client, sender, event, ap);
p[2] = x; va_end(ap);
p[3] = y;
p[4] = sx;
p[5] = sy;
wl_connection_write(surface->client->connection, p, sizeof p);
} }
WL_EXPORT void WL_EXPORT void
@ -683,18 +681,10 @@ wl_display_post_button_event(struct wl_display *display,
struct wl_object *source, int button, int state) struct wl_object *source, int button, int state)
{ {
const struct wl_compositor_interface *interface; const struct wl_compositor_interface *interface;
uint32_t p[4];
interface = display->compositor->interface; interface = display->compositor->interface;
interface->notify_pointer_button(display->compositor, source, interface->notify_pointer_button(display->compositor, source,
button, state); button, state);
p[0] = source->id;
p[1] = (sizeof p << 16) | WL_INPUT_BUTTON;
p[2] = button;
p[3] = state;
wl_display_send_event(display, p, sizeof p);
} }
WL_EXPORT void WL_EXPORT void

View File

@ -135,11 +135,15 @@ wl_display_post_key_event(struct wl_display *display,
void void
wl_display_post_frame(struct wl_display *display, wl_display_post_frame(struct wl_display *display,
uint32_t frame, uint32_t msecs); uint32_t frame, uint32_t msecs);
#define WL_INPUT_MOTION 0
#define WL_INPUT_BUTTON 1
#define WL_INPUT_KEY 2
void void
wl_display_post_surface_motion(struct wl_display *display, wl_surface_post_event(struct wl_surface *surface,
struct wl_surface *surface, struct wl_object *sender,
struct wl_object *source, uint32_t event, ...);
int x, int y, int sx, int sy);
struct wl_compositor { struct wl_compositor {
const struct wl_compositor_interface *interface; const struct wl_compositor_interface *interface;