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.
dev
Kristian Høgsberg 13 years ago
parent 1f37601850
commit e11bbe4cc8
  1. 13
      src/compositor-wayland.c
  2. 18
      src/compositor-x11.c
  3. 57
      src/compositor.c
  4. 6
      src/compositor.h
  5. 16
      src/evdev.c

@ -508,15 +508,14 @@ static const struct wl_output_listener output_listener = {
/* parent input interface */ /* parent input interface */
static void static void
input_handle_motion(void *data, struct wl_input_device *input_device, 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_input *input = data;
struct wayland_compositor *c = input->compositor; 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, 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 static void
@ -554,16 +553,14 @@ static void
input_handle_pointer_enter(void *data, input_handle_pointer_enter(void *data,
struct wl_input_device *input_device, struct wl_input_device *input_device,
uint32_t time, struct wl_surface *surface, 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_input *input = data;
struct wayland_output *output; struct wayland_output *output;
struct wayland_compositor *c = input->compositor; 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); 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); wl_input_device_attach(input->input_device, time, NULL, 0, 0);
} }

@ -560,6 +560,7 @@ x11_compositor_handle_event(int fd, uint32_t mask, void *data)
xcb_atom_t atom; xcb_atom_t atom;
uint32_t *k; uint32_t *k;
uint32_t i, set; uint32_t i, set;
wl_fixed_t x, y;
prev = NULL; prev = NULL;
while (x11_compositor_next_event(c, &event, mask)) { 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: case XCB_MOTION_NOTIFY:
motion_notify = (xcb_motion_notify_event_t *) event; motion_notify = (xcb_motion_notify_event_t *) event;
output = x11_compositor_find_output(c, motion_notify->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, notify_motion(c->base.input_device,
weston_compositor_get_time(), weston_compositor_get_time(), x, y);
output->base.x + motion_notify->event_x,
output->base.y + motion_notify->event_y);
break; break;
case XCB_EXPOSE: case XCB_EXPOSE:
@ -651,10 +652,11 @@ x11_compositor_handle_event(int fd, uint32_t mask, void *data)
if (enter_notify->state >= Button1Mask) if (enter_notify->state >= Button1Mask)
break; break;
output = x11_compositor_find_output(c, enter_notify->event); 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, notify_pointer_focus(c->base.input_device,
&output->base, &output->base, x, y);
output->base.x + enter_notify->event_x,
output->base.y + enter_notify->event_y);
break; break;
case XCB_LEAVE_NOTIFY: case XCB_LEAVE_NOTIFY:
@ -662,9 +664,7 @@ x11_compositor_handle_event(int fd, uint32_t mask, void *data)
if (enter_notify->state >= Button1Mask) if (enter_notify->state >= Button1Mask)
break; break;
output = x11_compositor_find_output(c, enter_notify->event); output = x11_compositor_find_output(c, enter_notify->event);
notify_pointer_focus(c->base.input_device, NULL, notify_pointer_focus(c->base.input_device, NULL, 0, 0);
output->base.x + enter_notify->event_x,
output->base.y + enter_notify->event_y);
break; break;
case XCB_CLIENT_MESSAGE: case XCB_CLIENT_MESSAGE:

@ -1560,15 +1560,15 @@ weston_input_update_drag_surface(struct wl_input_device *input_device,
static void static void
clip_pointer_motion(struct weston_compositor *ec, clip_pointer_motion(struct weston_compositor *ec,
GLfloat *fx, GLfloat *fy) wl_fixed_t *fx, wl_fixed_t *fy)
{ {
struct weston_output *output; struct weston_output *output;
int32_t x, y; int32_t x, y;
int x_valid = 0, y_valid = 0; int x_valid = 0, y_valid = 0;
int min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN; int min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN;
x = *fx; x = wl_fixed_to_int(*fx);
y = *fy; y = wl_fixed_to_int(*fy);
wl_list_for_each(output, &ec->output_list, link) { wl_list_for_each(output, &ec->output_list, link) {
if (output->x <= x && x < output->x + output->current->width) if (output->x <= x && x < output->x + output->current->width)
@ -1602,17 +1602,19 @@ clip_pointer_motion(struct weston_compositor *ec,
y = max_y; y = max_y;
} }
*fx = x; *fx = wl_fixed_from_int(x);
*fy = y; *fy = wl_fixed_from_int(y);
} }
WL_EXPORT void 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; const struct wl_pointer_grab_interface *interface;
struct weston_input_device *wd = (struct weston_input_device *) device; struct weston_input_device *wd = (struct weston_input_device *) device;
struct weston_compositor *ec = wd->compositor; struct weston_compositor *ec = wd->compositor;
struct weston_output *output; struct weston_output *output;
int32_t ix, iy;
weston_compositor_activity(ec); 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, weston_input_update_drag_surface(device,
x - device->x, y - device->y); x - device->x, y - device->y);
device->x = wl_fixed_from_double(x); device->x = x;
device->y = wl_fixed_from_double(y); device->y = y;
ix = wl_fixed_to_int(x);
iy = wl_fixed_to_int(y);
wl_list_for_each(output, &ec->output_list, link) wl_list_for_each(output, &ec->output_list, link)
if (output->zoom.active && 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_output_update_zoom(output, x, y);
weston_device_repick(device); 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, interface->motion(device->pointer_grab, time,
device->pointer_grab->x, device->pointer_grab->y); 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) { if (wd->sprite) {
weston_surface_set_position(wd->sprite, weston_surface_set_position(wd->sprite,
x - wd->hotspot_x, ix - wd->hotspot_x,
y - wd->hotspot_y); iy - wd->hotspot_y);
weston_compositor_schedule_repaint(ec); weston_compositor_schedule_repaint(ec);
} }
} }
@ -1793,18 +1796,17 @@ notify_key(struct wl_input_device *device,
WL_EXPORT void WL_EXPORT void
notify_pointer_focus(struct wl_input_device *device, 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_input_device *wd = (struct weston_input_device *) device;
struct weston_compositor *compositor = wd->compositor; struct weston_compositor *compositor = wd->compositor;
if (output) { if (output) {
weston_input_update_drag_surface(device, weston_input_update_drag_surface(device,
x - wl_fixed_to_double(device->x), x - device->x, y - device->y);
y - wl_fixed_to_double(device->y));
device->x = wl_fixed_from_double(x); device->x = x;
device->y = wl_fixed_from_double(y); device->y = y;
compositor->focus = 1; compositor->focus = 1;
weston_compositor_repick(compositor); weston_compositor_repick(compositor);
} else { } else {
@ -1942,17 +1944,14 @@ touch_set_focus(struct weston_input_device *device,
*/ */
WL_EXPORT void WL_EXPORT void
notify_touch(struct wl_input_device *device, uint32_t time, int touch_id, 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_input_device *wd = (struct weston_input_device *) device;
struct weston_compositor *ec = wd->compositor; struct weston_compositor *ec = wd->compositor;
struct weston_surface *es; struct weston_surface *es;
wl_fixed_t fx, fy, sx, sy; wl_fixed_t sx, sy;
uint32_t serial = 0; uint32_t serial = 0;
fx = wl_fixed_from_double(x);
fy = wl_fixed_from_double(y);
switch (touch_type) { switch (touch_type) {
case WL_INPUT_DEVICE_TOUCH_DOWN: case WL_INPUT_DEVICE_TOUCH_DOWN:
weston_compositor_idle_inhibit(ec); 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. * to that surface for the remainder of the touch session i.e.
* until all touch points are up again. */ * until all touch points are up again. */
if (wd->num_tp == 1) { 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); touch_set_focus(wd, &es->surface);
} else if (wd->touch_focus) { } else if (wd->touch_focus) {
es = (struct weston_surface *) 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) 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) if (!es)
break; 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) if (wd->touch_focus_resource)
wl_input_device_send_touch_motion(wd->touch_focus_resource, wl_input_device_send_touch_motion(wd->touch_focus_resource,
time, touch_id, sx, sy); time, touch_id, sx, sy);
@ -2228,8 +2227,8 @@ weston_input_update_drag_surface(struct wl_input_device *input_device,
return; return;
weston_surface_set_position(device->drag_surface, weston_surface_set_position(device->drag_surface,
device->drag_surface->geometry.x + dx, device->drag_surface->geometry.x + wl_fixed_to_double(dx),
device->drag_surface->geometry.y + dy); device->drag_surface->geometry.y + wl_fixed_to_double(dy));
} }
WL_EXPORT void WL_EXPORT void

@ -429,7 +429,7 @@ weston_surface_draw(struct weston_surface *es,
void void
notify_motion(struct wl_input_device *device, 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 void
notify_button(struct wl_input_device *device, notify_button(struct wl_input_device *device,
uint32_t time, int32_t button, uint32_t state); uint32_t time, int32_t button, uint32_t state);
@ -443,14 +443,14 @@ notify_key(struct wl_input_device *device,
void void
notify_pointer_focus(struct wl_input_device *device, notify_pointer_focus(struct wl_input_device *device,
struct weston_output *output, struct weston_output *output,
GLfloat x, GLfloat y); wl_fixed_t x, wl_fixed_t y);
void void
notify_keyboard_focus(struct wl_input_device *device, struct wl_array *keys); notify_keyboard_focus(struct wl_input_device *device, struct wl_array *keys);
void void
notify_touch(struct wl_input_device *device, uint32_t time, int touch_id, 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 void
weston_layer_init(struct weston_layer *layer, struct wl_list *below); weston_layer_init(struct weston_layer *layer, struct wl_list *below);

@ -300,8 +300,8 @@ evdev_flush_motion(struct evdev_input_device *device, uint32_t time)
if (device->type & EVDEV_RELATIVE_MOTION) { if (device->type & EVDEV_RELATIVE_MOTION) {
notify_motion(master, time, notify_motion(master, time,
wl_fixed_to_int(master->x) + device->rel.dx, master->x + wl_fixed_from_int(device->rel.dx),
wl_fixed_to_int(master->y) + device->rel.dy); master->y + wl_fixed_from_int(device->rel.dy));
device->type &= ~EVDEV_RELATIVE_MOTION; device->type &= ~EVDEV_RELATIVE_MOTION;
device->rel.dx = 0; device->rel.dx = 0;
device->rel.dy = 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) { if (device->type & EVDEV_ABSOLUTE_MT_DOWN) {
notify_touch(master, time, notify_touch(master, time,
device->mt.slot, device->mt.slot,
device->mt.x[device->mt.slot], wl_fixed_from_int(device->mt.x[device->mt.slot]),
device->mt.y[device->mt.slot], wl_fixed_from_int(device->mt.y[device->mt.slot]),
WL_INPUT_DEVICE_TOUCH_DOWN); WL_INPUT_DEVICE_TOUCH_DOWN);
device->type &= ~EVDEV_ABSOLUTE_MT_DOWN; device->type &= ~EVDEV_ABSOLUTE_MT_DOWN;
device->type &= ~EVDEV_ABSOLUTE_MT_MOTION; 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) { if (device->type & EVDEV_ABSOLUTE_MT_MOTION) {
notify_touch(master, time, notify_touch(master, time,
device->mt.slot, device->mt.slot,
device->mt.x[device->mt.slot], wl_fixed_from_int(device->mt.x[device->mt.slot]),
device->mt.y[device->mt.slot], wl_fixed_from_int(device->mt.y[device->mt.slot]),
WL_INPUT_DEVICE_TOUCH_MOTION); WL_INPUT_DEVICE_TOUCH_MOTION);
device->type &= ~EVDEV_ABSOLUTE_MT_DOWN; device->type &= ~EVDEV_ABSOLUTE_MT_DOWN;
device->type &= ~EVDEV_ABSOLUTE_MT_MOTION; 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; device->type &= ~EVDEV_ABSOLUTE_MT_UP;
} }
if (device->type & EVDEV_ABSOLUTE_MOTION) { 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; device->type &= ~EVDEV_ABSOLUTE_MOTION;
} }
} }

Loading…
Cancel
Save