diff options
Diffstat (limited to 'src/wayland/pointer.c')
| -rw-r--r-- | src/wayland/pointer.c | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/src/wayland/pointer.c b/src/wayland/pointer.c index 89dacde..006eadd 100644 --- a/src/wayland/pointer.c +++ b/src/wayland/pointer.c @@ -25,9 +25,9 @@ struct tablet_pad { struct zwp_tablet_pad_v2 *proxy; }; -static int device_px_round(double v) +static inline int device_px_round(double v) { - return (int)(v < 0 ? v - 0.5 : v + 0.5); + return (int)lrint(v); } static struct yasl_vector2i device_from_fixed(const struct yasl_surface *w, @@ -254,12 +254,12 @@ static void press_queue_flush(struct seat *s, struct press_queue *q, continue; } if (!p.surface) continue; - if (p.release) *buttons &= ~(1ull << p.button); - else *buttons |= 1ull << p.button; + uint64_t mask = 1ull << p.button; + *buttons = (*buttons & ~mask) | ((uint64_t)(!p.release) << p.button); struct yasl_mouse_event ev = like; ev.pos = p.pos; ev.button = p.button; - ev.kind = p.release ? YASL_PTR_RELEASE : YASL_PTR_PRESS; + ev.kind = (enum yasl_pointer_kind)p.release; push_mouse(s, p.surface, ev); } q->n = kept; @@ -397,13 +397,11 @@ static void pointer_axis(void *data, struct wl_pointer *pointer, { (void)pointer; (void)time; struct seat *s = data; - if (!s->pointer_focus) return; + if (unlikely(!s->pointer_focus)) return; double v = wl_fixed_to_double(value); - if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) { - s->axis_v += v; - s->frame_v += v; - } else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) { - s->axis_h += v; + if (likely(axis < 2)) { + (&s->axis_v)[axis] += v; + s->frame_v += v * (!axis); } pointer_event_done(s); } @@ -412,21 +410,17 @@ static void pointer_axis_source(void *data, struct wl_pointer *pointer, uint32_t { (void)pointer; struct seat *s = data; - if (axis_source == WL_POINTER_AXIS_SOURCE_FINGER || - axis_source == WL_POINTER_AXIS_SOURCE_CONTINUOUS) - s->axis_smooth = true; + s->axis_smooth = (axis_source == WL_POINTER_AXIS_SOURCE_FINGER || + axis_source == WL_POINTER_AXIS_SOURCE_CONTINUOUS); } static void pointer_axis_stop(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis) { (void)pointer; (void)time; struct seat *s = data; - if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) { - s->axis_value120_v = 0; - s->axis_has_v120_v = false; - } else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) { - s->axis_value120_h = 0; - s->axis_has_v120_h = false; + if (likely(axis < 2)) { + (&s->axis_value120_v)[axis] = 0; + (&s->axis_has_v120_v)[axis] = false; } } @@ -434,23 +428,18 @@ static void pointer_axis_discrete(void *data, struct wl_pointer *pointer, uint32 { (void)pointer; struct seat *s = data; - if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) - s->axis_discrete_v += discrete; - else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) - s->axis_discrete_h += discrete; + if (likely(axis < 2)) + (&s->axis_discrete_v)[axis] += discrete; } static void pointer_axis_value120(void *data, struct wl_pointer *pointer, uint32_t axis, int32_t value120) { (void)pointer; struct seat *s = data; - if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) { - s->axis_value120_v += value120; - s->frame_v120 += value120; - s->axis_has_v120_v = true; - } else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) { - s->axis_value120_h += value120; - s->axis_has_v120_h = true; + if (likely(axis < 2)) { + (&s->axis_value120_v)[axis] += value120; + (&s->axis_has_v120_v)[axis] = true; + s->frame_v120 += value120 * (!axis); } } |
