From e11bbe4cc8bdb726fad1cf38ba52e9a020a1c94e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Wed, 9 May 2012 12:19:04 -0400 Subject: [PATCH] compositor: Use wl_fixed_t for incoming input events This changes notify_motion, notify_pointer_focus and notify_touch to take wl_fixed_t types for input coordinates. --- src/compositor-wayland.c | 13 +++++------ src/compositor-x11.c | 18 +++++++-------- src/compositor.c | 57 ++++++++++++++++++++++++------------------------ src/compositor.h | 6 ++--- src/evdev.c | 16 ++++++++------ 5 files changed, 54 insertions(+), 56 deletions(-) diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c index 05669bc..69135a9 100644 --- a/src/compositor-wayland.c +++ b/src/compositor-wayland.c @@ -508,15 +508,14 @@ static const struct wl_output_listener output_listener = { /* parent input interface */ static void input_handle_motion(void *data, struct wl_input_device *input_device, - uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w) + uint32_t time, wl_fixed_t x, wl_fixed_t y) { struct wayland_input *input = data; struct wayland_compositor *c = input->compositor; - GLfloat sx = wl_fixed_to_double(sx_w); - GLfloat sy = wl_fixed_to_double(sy_w); notify_motion(c->base.input_device, time, - sx - c->border.left, sy - c->border.top); + x - wl_fixed_from_int(c->border.left), + y - wl_fixed_from_int(c->border.top)); } static void @@ -554,16 +553,14 @@ static void input_handle_pointer_enter(void *data, struct wl_input_device *input_device, uint32_t time, struct wl_surface *surface, - wl_fixed_t sx_w, wl_fixed_t sy_w) + wl_fixed_t x, wl_fixed_t y) { struct wayland_input *input = data; struct wayland_output *output; struct wayland_compositor *c = input->compositor; - GLfloat sx = wl_fixed_to_double(sx_w); - GLfloat sy = wl_fixed_to_double(sy_w); output = wl_surface_get_user_data(surface); - notify_pointer_focus(c->base.input_device, &output->base, sx, sy); + notify_pointer_focus(c->base.input_device, &output->base, x, y); wl_input_device_attach(input->input_device, time, NULL, 0, 0); } diff --git a/src/compositor-x11.c b/src/compositor-x11.c index 759b551..7fbcb5f 100644 --- a/src/compositor-x11.c +++ b/src/compositor-x11.c @@ -560,6 +560,7 @@ x11_compositor_handle_event(int fd, uint32_t mask, void *data) xcb_atom_t atom; uint32_t *k; uint32_t i, set; + wl_fixed_t x, y; prev = NULL; while (x11_compositor_next_event(c, &event, mask)) { @@ -633,10 +634,10 @@ x11_compositor_handle_event(int fd, uint32_t mask, void *data) case XCB_MOTION_NOTIFY: motion_notify = (xcb_motion_notify_event_t *) event; output = x11_compositor_find_output(c, motion_notify->event); + x = wl_fixed_from_int(output->base.x + motion_notify->event_x); + y = wl_fixed_from_int(output->base.y + motion_notify->event_y); notify_motion(c->base.input_device, - weston_compositor_get_time(), - output->base.x + motion_notify->event_x, - output->base.y + motion_notify->event_y); + weston_compositor_get_time(), x, y); break; case XCB_EXPOSE: @@ -651,10 +652,11 @@ x11_compositor_handle_event(int fd, uint32_t mask, void *data) if (enter_notify->state >= Button1Mask) break; output = x11_compositor_find_output(c, enter_notify->event); + x = wl_fixed_from_int(output->base.x + enter_notify->event_x); + y = wl_fixed_from_int(output->base.y + enter_notify->event_y); + notify_pointer_focus(c->base.input_device, - &output->base, - output->base.x + enter_notify->event_x, - output->base.y + enter_notify->event_y); + &output->base, x, y); break; case XCB_LEAVE_NOTIFY: @@ -662,9 +664,7 @@ x11_compositor_handle_event(int fd, uint32_t mask, void *data) if (enter_notify->state >= Button1Mask) break; output = x11_compositor_find_output(c, enter_notify->event); - notify_pointer_focus(c->base.input_device, NULL, - output->base.x + enter_notify->event_x, - output->base.y + enter_notify->event_y); + notify_pointer_focus(c->base.input_device, NULL, 0, 0); break; case XCB_CLIENT_MESSAGE: diff --git a/src/compositor.c b/src/compositor.c index f9e2499..3005b6b 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -1560,15 +1560,15 @@ weston_input_update_drag_surface(struct wl_input_device *input_device, static void clip_pointer_motion(struct weston_compositor *ec, - GLfloat *fx, GLfloat *fy) + wl_fixed_t *fx, wl_fixed_t *fy) { struct weston_output *output; int32_t x, y; int x_valid = 0, y_valid = 0; int min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN; - x = *fx; - y = *fy; + x = wl_fixed_to_int(*fx); + y = wl_fixed_to_int(*fy); wl_list_for_each(output, &ec->output_list, link) { if (output->x <= x && x < output->x + output->current->width) @@ -1602,17 +1602,19 @@ clip_pointer_motion(struct weston_compositor *ec, y = max_y; } - *fx = x; - *fy = y; + *fx = wl_fixed_from_int(x); + *fy = wl_fixed_from_int(y); } WL_EXPORT void -notify_motion(struct wl_input_device *device, uint32_t time, GLfloat x, GLfloat y) +notify_motion(struct wl_input_device *device, + uint32_t time, wl_fixed_t x, wl_fixed_t y) { const struct wl_pointer_grab_interface *interface; struct weston_input_device *wd = (struct weston_input_device *) device; struct weston_compositor *ec = wd->compositor; struct weston_output *output; + int32_t ix, iy; weston_compositor_activity(ec); @@ -1621,12 +1623,16 @@ notify_motion(struct wl_input_device *device, uint32_t time, GLfloat x, GLfloat weston_input_update_drag_surface(device, x - device->x, y - device->y); - device->x = wl_fixed_from_double(x); - device->y = wl_fixed_from_double(y); + device->x = x; + device->y = y; + + ix = wl_fixed_to_int(x); + iy = wl_fixed_to_int(y); wl_list_for_each(output, &ec->output_list, link) if (output->zoom.active && - pixman_region32_contains_point(&output->region, x, y, NULL)) + pixman_region32_contains_point(&output->region, + ix, iy, NULL)) weston_output_update_zoom(output, x, y); weston_device_repick(device); @@ -1634,13 +1640,10 @@ notify_motion(struct wl_input_device *device, uint32_t time, GLfloat x, GLfloat interface->motion(device->pointer_grab, time, device->pointer_grab->x, device->pointer_grab->y); - x = wl_fixed_to_double(device->x); - y = wl_fixed_to_double(device->y); - if (wd->sprite) { weston_surface_set_position(wd->sprite, - x - wd->hotspot_x, - y - wd->hotspot_y); + ix - wd->hotspot_x, + iy - wd->hotspot_y); weston_compositor_schedule_repaint(ec); } } @@ -1793,18 +1796,17 @@ notify_key(struct wl_input_device *device, WL_EXPORT void notify_pointer_focus(struct wl_input_device *device, - struct weston_output *output, GLfloat x, GLfloat y) + struct weston_output *output, wl_fixed_t x, wl_fixed_t y) { struct weston_input_device *wd = (struct weston_input_device *) device; struct weston_compositor *compositor = wd->compositor; if (output) { weston_input_update_drag_surface(device, - x - wl_fixed_to_double(device->x), - y - wl_fixed_to_double(device->y)); + x - device->x, y - device->y); - device->x = wl_fixed_from_double(x); - device->y = wl_fixed_from_double(y); + device->x = x; + device->y = y; compositor->focus = 1; weston_compositor_repick(compositor); } else { @@ -1942,17 +1944,14 @@ touch_set_focus(struct weston_input_device *device, */ WL_EXPORT void notify_touch(struct wl_input_device *device, uint32_t time, int touch_id, - GLfloat x, GLfloat y, int touch_type) + wl_fixed_t x, wl_fixed_t y, int touch_type) { struct weston_input_device *wd = (struct weston_input_device *) device; struct weston_compositor *ec = wd->compositor; struct weston_surface *es; - wl_fixed_t fx, fy, sx, sy; + wl_fixed_t sx, sy; uint32_t serial = 0; - fx = wl_fixed_from_double(x); - fy = wl_fixed_from_double(y); - switch (touch_type) { case WL_INPUT_DEVICE_TOUCH_DOWN: weston_compositor_idle_inhibit(ec); @@ -1963,11 +1962,11 @@ notify_touch(struct wl_input_device *device, uint32_t time, int touch_id, * to that surface for the remainder of the touch session i.e. * until all touch points are up again. */ if (wd->num_tp == 1) { - es = weston_compositor_pick_surface(ec, fx, fy, &sx, &sy); + es = weston_compositor_pick_surface(ec, x, y, &sx, &sy); touch_set_focus(wd, &es->surface); } else if (wd->touch_focus) { es = (struct weston_surface *) wd->touch_focus; - weston_surface_from_global_fixed(es, fx, fy, &sx, &sy); + weston_surface_from_global_fixed(es, x, y, &sx, &sy); } if (wd->touch_focus_resource && wd->touch_focus) @@ -1981,7 +1980,7 @@ notify_touch(struct wl_input_device *device, uint32_t time, int touch_id, if (!es) break; - weston_surface_from_global_fixed(es, fx, fy, &sx, &sy); + weston_surface_from_global_fixed(es, x, y, &sx, &sy); if (wd->touch_focus_resource) wl_input_device_send_touch_motion(wd->touch_focus_resource, time, touch_id, sx, sy); @@ -2228,8 +2227,8 @@ weston_input_update_drag_surface(struct wl_input_device *input_device, return; weston_surface_set_position(device->drag_surface, - device->drag_surface->geometry.x + dx, - device->drag_surface->geometry.y + dy); + device->drag_surface->geometry.x + wl_fixed_to_double(dx), + device->drag_surface->geometry.y + wl_fixed_to_double(dy)); } WL_EXPORT void diff --git a/src/compositor.h b/src/compositor.h index e828470..fbd3b54 100644 --- a/src/compositor.h +++ b/src/compositor.h @@ -429,7 +429,7 @@ weston_surface_draw(struct weston_surface *es, void notify_motion(struct wl_input_device *device, - uint32_t time, GLfloat x, GLfloat y); + uint32_t time, wl_fixed_t x, wl_fixed_t y); void notify_button(struct wl_input_device *device, uint32_t time, int32_t button, uint32_t state); @@ -443,14 +443,14 @@ notify_key(struct wl_input_device *device, void notify_pointer_focus(struct wl_input_device *device, struct weston_output *output, - GLfloat x, GLfloat y); + wl_fixed_t x, wl_fixed_t y); void notify_keyboard_focus(struct wl_input_device *device, struct wl_array *keys); void notify_touch(struct wl_input_device *device, uint32_t time, int touch_id, - GLfloat x, GLfloat y, int touch_type); + wl_fixed_t x, wl_fixed_t y, int touch_type); void weston_layer_init(struct weston_layer *layer, struct wl_list *below); diff --git a/src/evdev.c b/src/evdev.c index 5fa7ae6..4dbf575 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -300,8 +300,8 @@ evdev_flush_motion(struct evdev_input_device *device, uint32_t time) if (device->type & EVDEV_RELATIVE_MOTION) { notify_motion(master, time, - wl_fixed_to_int(master->x) + device->rel.dx, - wl_fixed_to_int(master->y) + device->rel.dy); + master->x + wl_fixed_from_int(device->rel.dx), + master->y + wl_fixed_from_int(device->rel.dy)); device->type &= ~EVDEV_RELATIVE_MOTION; device->rel.dx = 0; device->rel.dy = 0; @@ -309,8 +309,8 @@ evdev_flush_motion(struct evdev_input_device *device, uint32_t time) if (device->type & EVDEV_ABSOLUTE_MT_DOWN) { notify_touch(master, time, device->mt.slot, - device->mt.x[device->mt.slot], - device->mt.y[device->mt.slot], + wl_fixed_from_int(device->mt.x[device->mt.slot]), + wl_fixed_from_int(device->mt.y[device->mt.slot]), WL_INPUT_DEVICE_TOUCH_DOWN); device->type &= ~EVDEV_ABSOLUTE_MT_DOWN; device->type &= ~EVDEV_ABSOLUTE_MT_MOTION; @@ -318,8 +318,8 @@ evdev_flush_motion(struct evdev_input_device *device, uint32_t time) if (device->type & EVDEV_ABSOLUTE_MT_MOTION) { notify_touch(master, time, device->mt.slot, - device->mt.x[device->mt.slot], - device->mt.y[device->mt.slot], + wl_fixed_from_int(device->mt.x[device->mt.slot]), + wl_fixed_from_int(device->mt.y[device->mt.slot]), WL_INPUT_DEVICE_TOUCH_MOTION); device->type &= ~EVDEV_ABSOLUTE_MT_DOWN; device->type &= ~EVDEV_ABSOLUTE_MT_MOTION; @@ -330,7 +330,9 @@ evdev_flush_motion(struct evdev_input_device *device, uint32_t time) device->type &= ~EVDEV_ABSOLUTE_MT_UP; } if (device->type & EVDEV_ABSOLUTE_MOTION) { - notify_motion(master, time, device->abs.x, device->abs.y); + notify_motion(master, time, + wl_fixed_from_int(device->abs.x), + wl_fixed_from_int(device->abs.y)); device->type &= ~EVDEV_ABSOLUTE_MOTION; } } -- 2.7.4