[PATCH 14/15] Prepare ScrollData for smooth scrolling
Peter Hutterer
peter.hutterer at who-t.net
Mon Jun 13 22:38:26 PDT 2011
On Thu, Jun 09, 2011 at 08:57:35PM +0100, Daniel Stone wrote:
> Convert ScrollData from up/down/left/right members for button presses,
> to more fine-grained x and y members.
>
> Signed-off-by: Daniel Stone <daniel at fooishbar.org>
> ---
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
Cheers,
Peter
> src/synaptics.c | 119 ++++++++++++++++++++++--------------------------------
> 1 files changed, 49 insertions(+), 70 deletions(-)
>
> diff --git a/src/synaptics.c b/src/synaptics.c
> index 30b442e..36f78ae 100644
> --- a/src/synaptics.c
> +++ b/src/synaptics.c
> @@ -1984,7 +1984,7 @@ out:
> }
>
> struct ScrollData {
> - int left, right, up, down;
> + double x, y;
> };
>
> static double
> @@ -2072,7 +2072,8 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
> SynapticsParameters *para = &priv->synpara;
> int delay = 1000000000;
>
> - sd->left = sd->right = sd->up = sd->down = 0;
> + sd->x = 0;
> + sd->y = 0;
>
> if ((priv->synpara.touchpad_off == 2) || (priv->finger_state == FS_BLOCKED)) {
> stop_coasting(priv);
> @@ -2250,95 +2251,60 @@ HandleScrolling(SynapticsPrivate *priv, struct SynapticsHwState *hw,
> if (priv->vert_scroll_edge_on || priv->vert_scroll_twofinger_on) {
> /* + = down, - = up */
> int delta = para->scroll_dist_vert;
> - if (delta > 0) {
> - while (hw->y - priv->scroll_y > delta) {
> - sd->down++;
> - priv->scroll_y += delta;
> - }
> - while (hw->y - priv->scroll_y < -delta) {
> - sd->up++;
> - priv->scroll_y -= delta;
> - }
> + if (delta > 0 && hw->y != priv->scroll_y) {
> + sd->y = hw->y - priv->scroll_y;
> + priv->scroll_y = hw->y;
> }
> }
> if (priv->horiz_scroll_edge_on || priv->horiz_scroll_twofinger_on) {
> /* + = right, - = left */
> int delta = para->scroll_dist_horiz;
> - if (delta > 0) {
> - while (hw->x - priv->scroll_x > delta) {
> - sd->right++;
> - priv->scroll_x += delta;
> - }
> - while (hw->x - priv->scroll_x < -delta) {
> - sd->left++;
> - priv->scroll_x -= delta;
> - }
> + if (delta > 0 && hw->x != priv->scroll_x) {
> + sd->x = hw->x - priv->scroll_x;
> + priv->scroll_x = hw->x;
> }
> }
> if (priv->circ_scroll_on) {
> /* + = counter clockwise, - = clockwise */
> double delta = para->scroll_dist_circ;
> if (delta >= 0.005) {
> - while (diffa(priv->scroll_a, angle(priv, hw->x, hw->y)) > delta) {
> - if (priv->circ_scroll_vert)
> - sd->up++;
> - else
> - sd->right++;
> - priv->scroll_a += delta;
> - if (priv->scroll_a > M_PI)
> - priv->scroll_a -= 2 * M_PI;
> - }
> - while (diffa(priv->scroll_a, angle(priv, hw->x, hw->y)) < -delta) {
> - if (priv->circ_scroll_vert)
> - sd->down++;
> - else
> - sd->left++;
> - priv->scroll_a -= delta;
> - if (priv->scroll_a < -M_PI)
> - priv->scroll_a += 2 * M_PI;
> - }
> - }
> + double diff = diffa(priv->scroll_a, angle(priv, hw->x, hw->y));
> + if (priv->circ_scroll_vert)
> + sd->y += diff;
> + else
> + sd->x += diff;
> + }
> }
>
> if (priv->autoscroll_yspd) {
> double dtime = (hw->millis - priv->last_scroll_millis) / 1000.0;
> double ddy = para->coasting_friction * dtime;
> - priv->autoscroll_y += priv->autoscroll_yspd * dtime;
> + double movement = priv->autoscroll_yspd * dtime;
> + movement *= para->scroll_dist_vert;
> + priv->autoscroll_y += movement;
> + sd->y += movement;
> delay = MIN(delay, POLL_MS);
> - while (priv->autoscroll_y > 1.0) {
> - sd->down++;
> - priv->autoscroll_y -= 1.0;
> - }
> - while (priv->autoscroll_y < -1.0) {
> - sd->up++;
> - priv->autoscroll_y += 1.0;
> - }
> if (abs(priv->autoscroll_yspd) < ddy) {
> priv->autoscroll_yspd = 0;
> priv->scroll_packet_count = 0;
> } else {
> - priv->autoscroll_yspd += (priv->autoscroll_yspd < 0 ? ddy : -1*ddy);
> + priv->autoscroll_yspd += (priv->autoscroll_yspd < 0 ? ddy : -ddy);
> }
> }
>
> if (priv->autoscroll_xspd) {
> double dtime = (hw->millis - priv->last_scroll_millis) / 1000.0;
> double ddx = para->coasting_friction * dtime;
> - priv->autoscroll_x += priv->autoscroll_xspd * dtime;
> + double movement = priv->autoscroll_xspd * dtime;
> + movement *= para->scroll_dist_vert;
> + priv->autoscroll_x += movement;
> + sd->x += movement;
> delay = MIN(delay, POLL_MS);
> - while (priv->autoscroll_x > 1.0) {
> - sd->right++;
> - priv->autoscroll_x -= 1.0;
> - }
> - while (priv->autoscroll_x < -1.0) {
> - sd->left++;
> - priv->autoscroll_x += 1.0;
> - }
> if (abs(priv->autoscroll_xspd) < ddx) {
> priv->autoscroll_xspd = 0;
> priv->scroll_packet_count = 0;
> } else {
> - priv->autoscroll_xspd += (priv->autoscroll_xspd < 0 ? ddx : -1*ddx);
> + priv->autoscroll_xspd += (priv->autoscroll_xspd < 0 ? ddx : -ddx);
> }
> }
>
> @@ -2479,17 +2445,32 @@ post_button_click(const InputInfoPtr pInfo, const int button)
> static void
> post_scroll_events(const InputInfoPtr pInfo, struct ScrollData scroll)
> {
> - while (scroll.up-- > 0)
> + SynapticsPrivate *priv = (SynapticsPrivate *) (pInfo->private);
> + SynapticsParameters *para = &priv->synpara;
> +
> + while (para->scroll_dist_vert > 0 && scroll.y <= -para->scroll_dist_vert)
> + {
> post_button_click(pInfo, 4);
> + scroll.y += para->scroll_dist_vert;
> + }
>
> - while (scroll.down-- > 0)
> + while (para->scroll_dist_vert > 0 && scroll.y >= para->scroll_dist_vert)
> + {
> post_button_click(pInfo, 5);
> + scroll.y -= para->scroll_dist_vert;
> + }
>
> - while (scroll.left-- > 0)
> + while (para->scroll_dist_horiz > 0 && scroll.x <= -para->scroll_dist_horiz)
> + {
> post_button_click(pInfo, 6);
> + scroll.x += para->scroll_dist_horiz;
> + }
>
> - while (scroll.right-- > 0)
> + while (para->scroll_dist_horiz > 0 && scroll.x >= para->scroll_dist_horiz)
> + {
> post_button_click(pInfo, 7);
> + scroll.x -= para->scroll_dist_horiz;
> + }
> }
>
> static inline int
> @@ -2534,13 +2515,13 @@ repeat_scrollbuttons(const InputInfoPtr pInfo,
> id = ffs(change);
> change &= ~(1 << (id - 1));
> if (id == 4)
> - sd->up++;
> + sd->y -= 1.0;
> else if (id == 5)
> - sd->down++;
> + sd->y += 1.0;
> else if (id == 6)
> - sd->left++;
> + sd->x -= 1.0;
> else if (id == 7)
> - sd->right++;
> + sd->x += 1.0;
> }
>
> priv->nextRepeat = now + repeat_delay;
> @@ -2706,9 +2687,7 @@ HandleState(InputInfoPtr pInfo, struct SynapticsHwState *hw, CARD32 now,
> /* Process scroll events only if coordinates are
> * in the Synaptics Area
> */
> - if (inside_active_area &&
> - (scroll.down != 0 || scroll.up != 0 || scroll.left != 0 ||
> - scroll.right != 0)) {
> + if (inside_active_area && (scroll.x != 0 || scroll.y != 0)) {
> post_scroll_events(pInfo, scroll);
> priv->last_scroll_millis = hw->millis;
> }
> --
> 1.7.5.3
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>
More information about the xorg-devel
mailing list