compositor: Move device coordinate transform helper to compositor.c

This function transform input coordinates from output space to
compositor space and is useful for X input as well as touch screen input.
dev
Kristian Høgsberg 12 years ago
parent 5addaa1820
commit 98c774f1c0
  1. 67
      src/compositor-x11.c
  2. 51
      src/compositor.c
  3. 4
      src/compositor.h

@ -1058,61 +1058,6 @@ x11_compositor_deliver_button_event(struct x11_compositor *c,
WL_POINTER_BUTTON_STATE_RELEASED);
}
static void
x11_output_transform_coordinate(struct x11_output *x11_output,
wl_fixed_t *x, wl_fixed_t *y)
{
struct weston_output *output = &x11_output->base;
wl_fixed_t tx, ty;
wl_fixed_t width = wl_fixed_from_int(output->width * output->scale - 1);
wl_fixed_t height = wl_fixed_from_int(output->height * output->scale - 1);
switch(output->transform) {
case WL_OUTPUT_TRANSFORM_NORMAL:
default:
tx = *x;
ty = *y;
break;
case WL_OUTPUT_TRANSFORM_90:
tx = *y;
ty = height - *x;
break;
case WL_OUTPUT_TRANSFORM_180:
tx = width - *x;
ty = height - *y;
break;
case WL_OUTPUT_TRANSFORM_270:
tx = width - *y;
ty = *x;
break;
case WL_OUTPUT_TRANSFORM_FLIPPED:
tx = width - *x;
ty = *y;
break;
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
tx = width - *y;
ty = height - *x;
break;
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
tx = *x;
ty = height - *y;
break;
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
tx = *y;
ty = *x;
break;
}
tx /= output->scale;
ty /= output->scale;
tx += wl_fixed_from_int(output->x);
ty += wl_fixed_from_int(output->y);
*x = tx;
*y = ty;
}
static void
x11_compositor_deliver_motion_event(struct x11_compositor *c,
xcb_generic_event_t *event)
@ -1125,9 +1070,9 @@ x11_compositor_deliver_motion_event(struct x11_compositor *c,
if (!c->has_xkb)
update_xkb_state_from_core(c, motion_notify->state);
output = x11_compositor_find_output(c, motion_notify->event);
x = wl_fixed_from_int(motion_notify->event_x);
y = wl_fixed_from_int(motion_notify->event_y);
x11_output_transform_coordinate(output, &x, &y);
weston_output_transform_coordinate(&output->base,
motion_notify->event_x,
motion_notify->event_y, &x, &y);
notify_motion(&c->core_seat, weston_compositor_get_time(),
x - c->prev_x, y - c->prev_y);
@ -1150,9 +1095,9 @@ x11_compositor_deliver_enter_event(struct x11_compositor *c,
if (!c->has_xkb)
update_xkb_state_from_core(c, enter_notify->state);
output = x11_compositor_find_output(c, enter_notify->event);
x = wl_fixed_from_int(enter_notify->event_x);
y = wl_fixed_from_int(enter_notify->event_y);
x11_output_transform_coordinate(output, &x, &y);
weston_output_transform_coordinate(&output->base,
enter_notify->event_x,
enter_notify->event_y, &x, &y);
notify_pointer_focus(&c->core_seat, &output->base, x, y);

@ -2751,6 +2751,57 @@ weston_output_init(struct weston_output *output, struct weston_compositor *c,
wl_signal_emit(&c->output_created_signal, output);
}
WL_EXPORT void
weston_output_transform_coordinate(struct weston_output *output,
int device_x, int device_y,
wl_fixed_t *x, wl_fixed_t *y)
{
wl_fixed_t tx, ty;
wl_fixed_t width, height;
width = wl_fixed_from_int(output->width * output->scale - 1);
height = wl_fixed_from_int(output->height * output->scale - 1);
switch(output->transform) {
case WL_OUTPUT_TRANSFORM_NORMAL:
default:
tx = wl_fixed_from_int(device_x);
ty = wl_fixed_from_int(device_y);
break;
case WL_OUTPUT_TRANSFORM_90:
tx = wl_fixed_from_int(device_y);
ty = height - wl_fixed_from_int(device_x);
break;
case WL_OUTPUT_TRANSFORM_180:
tx = width - wl_fixed_from_int(device_x);
ty = height - wl_fixed_from_int(device_y);
break;
case WL_OUTPUT_TRANSFORM_270:
tx = width - wl_fixed_from_int(device_y);
ty = wl_fixed_from_int(device_x);
break;
case WL_OUTPUT_TRANSFORM_FLIPPED:
tx = width - wl_fixed_from_int(device_x);
ty = wl_fixed_from_int(device_y);
break;
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
tx = width - wl_fixed_from_int(device_y);
ty = height - wl_fixed_from_int(device_x);
break;
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
tx = wl_fixed_from_int(device_x);
ty = height - wl_fixed_from_int(device_y);
break;
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
tx = wl_fixed_from_int(device_y);
ty = wl_fixed_from_int(device_x);
break;
}
*x = tx / output->scale + wl_fixed_from_int(output->x);
*y = ty / output->scale + wl_fixed_from_int(output->y);
}
static void
compositor_bind(struct wl_client *client,
void *data, uint32_t version, uint32_t id)

@ -1075,6 +1075,10 @@ weston_output_init(struct weston_output *output, struct weston_compositor *c,
int x, int y, int width, int height, uint32_t transform, int32_t scale);
void
weston_output_destroy(struct weston_output *output);
void
weston_output_transform_coordinate(struct weston_output *x11_output,
int device_x, int device_y,
wl_fixed_t *x, wl_fixed_t *y);
void
weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec,

Loading…
Cancel
Save