From: bru Date: Thu, 18 Aug 2016 21:12:35 +0000 (+0000) Subject: Reset the input state completely when wsmouse is (re-)opened. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=e1975f3c13d24b4cd4bacc81d7d43eb6df1d354d;p=openbsd Reset the input state completely when wsmouse is (re-)opened. ok mpi@ --- diff --git a/sys/dev/wscons/wsmouse.c b/sys/dev/wscons/wsmouse.c index 6139deccae3..c2839bad194 100644 --- a/sys/dev/wscons/wsmouse.c +++ b/sys/dev/wscons/wsmouse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsmouse.c,v 1.33 2016/07/13 15:41:51 deraadt Exp $ */ +/* $OpenBSD: wsmouse.c,v 1.34 2016/08/18 21:12:35 bru Exp $ */ /* $NetBSD: wsmouse.c,v 1.35 2005/02/27 00:27:52 perry Exp $ */ /* @@ -379,6 +379,8 @@ wsmousedoopen(struct wsmouse_softc *sc, struct wseventvar *evp) { sc->sc_base.me_evp = evp; + wsmouse_input_reset(&sc->input); + /* enable the device, and punt if that's not possible */ return (*sc->sc_accessops->enable)(sc->sc_accesscookie); } @@ -1266,8 +1268,11 @@ wsmouse_mt_init(struct device *sc, int num_slots, int tracking) &((struct wsmouse_softc *) sc)->input; int n, size; + if (num_slots == input->mt.num_slots + && (!tracking == ((input->flags & MT_TRACKING) == 0))) + return (0); + free_mt_slots(input); - memset(&input->mt, 0, sizeof(struct mt_state)); if (tracking) input->flags |= MT_TRACKING; @@ -1365,6 +1370,27 @@ wsmouse_set_mode(struct device *sc, int mode) return (-1); } +void +wsmouse_input_reset(struct wsmouseinput *input) +{ + int num_slots, *matrix; + struct mt_slot *slots; + + memset(&input->btn, 0, sizeof(struct btn_state)); + memset(&input->motion, 0, sizeof(struct motion_state)); + memset(&input->touch, 0, sizeof(struct touch_state)); + input->touch.min_pressure = input->params.pressure_hi; + if ((num_slots = input->mt.num_slots)) { + slots = input->mt.slots; + matrix = input->mt.matrix; + memset(&input->mt, 0, sizeof(struct mt_state)); + memset(slots, 0, num_slots * sizeof(struct mt_slot)); + input->mt.num_slots = num_slots; + input->mt.slots = slots; + input->mt.matrix = matrix; + } +} + void wsmouse_input_init(struct wsmouseinput *input, struct wseventvar **evar) { diff --git a/sys/dev/wscons/wsmouseinput.h b/sys/dev/wscons/wsmouseinput.h index 0b377b405cc..50a12fe05fe 100644 --- a/sys/dev/wscons/wsmouseinput.h +++ b/sys/dev/wscons/wsmouseinput.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wsmouseinput.h,v 1.1 2016/03/30 23:34:12 bru Exp $ */ +/* $OpenBSD: wsmouseinput.h,v 1.2 2016/08/18 21:12:35 bru Exp $ */ /* * Copyright (c) 2015, 2016 Ulf Brosziewski @@ -139,6 +139,7 @@ struct evq_access { void wsmouse_evq_put(struct evq_access *, int, int); void wsmouse_init_scaling(struct wsmouseinput *); +void wsmouse_input_reset(struct wsmouseinput *); void wsmouse_input_init(struct wsmouseinput *, struct wseventvar **); void wsmouse_input_cleanup(struct wsmouseinput *);