diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2012-05-23 13:35:36 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2012-05-31 14:56:49 +1000 |
commit | bc96940d4a9b81fa51fa3e7b9d35880bbbb22056 (patch) | |
tree | eda196db76dd665f565dad821af90467dd4821df | |
parent | bab41da8731bd6096935bc978ee6ad3b1536d90d (diff) |
Move the front-end hooks into a struct
Provide a SynapticsFrontend struct and let the frontends place their hooks
in there. This means the old SynapticsMsg frontend call must take a va_list
now but we'll probably survive that.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | src/synaptics-dummy.c | 30 | ||||
-rw-r--r-- | src/synaptics-x11.c | 54 | ||||
-rw-r--r-- | src/synaptics.c | 69 | ||||
-rw-r--r-- | src/synaptics.h | 78 | ||||
-rw-r--r-- | src/synapticsstr.h | 1 |
5 files changed, 166 insertions, 66 deletions
diff --git a/src/synaptics-dummy.c b/src/synaptics-dummy.c index a0b217d..33257c4 100644 --- a/src/synaptics-dummy.c +++ b/src/synaptics-dummy.c @@ -39,36 +39,32 @@ #include "synaptics.h" void -SynapticsMsg(SynapticsPrivate *priv, enum MessageType type, const char *format, ...) +DummySynapticsMsg(SynapticsPrivate *priv, enum MessageType type, const char *format, va_list args) { - va_list args; - printf("dummydrv: "); - va_start(args, format); vprintf(format, args); - va_end(args); } void -SynapticsButtonEvent(SynapticsPrivate *priv, int button, enum ButtonEventType press) +DummySynapticsButtonEvent(SynapticsPrivate *priv, int button, enum ButtonEventType press) { SynapticsMsg(priv, MSG_INFO, "Button %d %s\n", button, press == BTN_PRESS ? "press" : "release"); } void -SynapticsMotionEvent(SynapticsPrivate *priv, int x, int y) +DummySynapticsMotionEvent(SynapticsPrivate *priv, int x, int y) { SynapticsMsg(priv, MSG_INFO, "Motion %d/%d\n", x, y); } void -SynapticsScrollEvent(SynapticsPrivate *priv, unsigned int which, double vert, double horiz) +DummySynapticsScrollEvent(SynapticsPrivate *priv, unsigned int which, double vert, double horiz) { SynapticsMsg(priv, MSG_INFO, "Scroll vert %.f horiz %.f\n", vert, horiz); } void -SynapticsTouchEvent(SynapticsPrivate *priv, unsigned int touchid, +DummySynapticsTouchEvent(SynapticsPrivate *priv, unsigned int touchid, enum TouchEventType type, VMask *mask) { SynapticsMsg(priv, MSG_INFO,"Touch <%u> %s\n", touchid, @@ -76,13 +72,13 @@ SynapticsTouchEvent(SynapticsPrivate *priv, unsigned int touchid, } void -SynapticsSetTimer(SynapticsPrivate *priv, unsigned int now, unsigned int delay) +DummySynapticsSetTimer(SynapticsPrivate *priv, unsigned int now, unsigned int delay) { /* FIXME: should probably do something here */ } unsigned int -SynapticsGetCurrentMillis(void) +DummySynapticsGetCurrentMillis(void) { struct timeval tv; @@ -97,6 +93,16 @@ void sighandler(int sig) { printf("Signal received, stopping...\n"); } +struct SynapticsFrontend dummy_frontend = { + DummySynapticsMsg, + DummySynapticsGetCurrentMillis, + DummySynapticsButtonEvent, + DummySynapticsMotionEvent, + DummySynapticsScrollEvent, + DummySynapticsTouchEvent, + DummySynapticsSetTimer, +}; + int main(int argc, char **argv) { SynapticsPrivate *priv; @@ -104,7 +110,7 @@ int main(int argc, char **argv) int fd; int rc; - priv = SynapticsInitPrivate(); + priv = SynapticsInitPrivate(&dummy_frontend); assert(priv); priv->proto_ops = SynapticsGetDeviceProtocolOps(priv, "auto-dev", NULL, &device); diff --git a/src/synaptics-x11.c b/src/synaptics-x11.c index d7168af..ab00307 100644 --- a/src/synaptics-x11.c +++ b/src/synaptics-x11.c @@ -60,14 +60,28 @@ struct SynapticsX11 { }; static void DeviceInitTouchAxes(DeviceIntPtr dev, Atom *axes_labels); +/* frontend hooks */ +static unsigned int X11SynapticsGetCurrentMillis(void); +static void X11SynapticsMsg(SynapticsPrivate *priv, enum MessageType type, + const char *format, va_list args); +static void X11SynapticsButtonEvent(SynapticsPrivate *priv, int button, + enum ButtonEventType press); +static void X11SynapticsMotionEvent(SynapticsPrivate *priv, int x, int y); +static void +X11SynapticsScrollEvent(SynapticsPrivate *priv, unsigned int which, + double vert, double horiz); +static void X11SynapticsTouchEvent(SynapticsPrivate *priv, unsigned int touchid, + enum TouchEventType type, VMask *mask); +static void X11SynapticsSetTimer(SynapticsPrivate *priv, + unsigned int now, unsigned int delay); -void -SynapticsMsg(SynapticsPrivate *priv, enum MessageType type, const char *format, ...) +static void +X11SynapticsMsg(SynapticsPrivate *priv, enum MessageType type, + const char *format, va_list args) { struct SynapticsX11 *x11 = priv->frontend_data; InputInfoPtr pInfo = x11->pInfo; int x11_type; - va_list args; switch (type) { case MSG_DEBUG: x11_type = X_INFO; break; @@ -76,13 +90,11 @@ SynapticsMsg(SynapticsPrivate *priv, enum MessageType type, const char *format, case MSG_ERROR: x11_type = X_ERROR; break; } - va_start(args, format); xf86VIDrvMsgVerb(pInfo, x11_type, 1, format, args); - va_end(args); } -unsigned int -SynapticsGetCurrentMillis(void) +static unsigned int +X11SynapticsGetCurrentMillis(void) { return GetTimeInMillis(); } @@ -110,8 +122,8 @@ X11TimerFunc(OsTimerPtr timer, CARD32 now, pointer arg) return 0; } -void -SynapticsSetTimer(SynapticsPrivate *priv, unsigned int now, unsigned int delay) +static void +X11SynapticsSetTimer(SynapticsPrivate *priv, unsigned int now, unsigned int delay) { struct SynapticsX11 *x11 = priv->frontend_data; x11->timer = TimerSet(x11->timer, 0, delay, X11TimerFunc, x11->pInfo); @@ -681,6 +693,16 @@ struct SynapticsX11 *InitX11Private(void) return x11; } +struct SynapticsFrontend x11_frontend = { + X11SynapticsMsg, + X11SynapticsGetCurrentMillis, + X11SynapticsButtonEvent, + X11SynapticsMotionEvent, + X11SynapticsScrollEvent, + X11SynapticsTouchEvent, + X11SynapticsSetTimer, +}; + static int SynapticsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) { @@ -694,7 +716,7 @@ SynapticsPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) return BadAlloc; /* allocate memory for SynapticsPrivateRec */ - priv = SynapticsInitPrivate(); + priv = SynapticsInitPrivate(&x11_frontend); if (!priv) { FreeX11Private(&x11); return BadAlloc; @@ -802,7 +824,8 @@ DeviceInitTouchAxes(DeviceIntPtr dev, Atom *axes_labels) } } -void SynapticsButtonEvent(SynapticsPrivate *priv, int button, enum ButtonEventType press) +static void +X11SynapticsButtonEvent(SynapticsPrivate *priv, int button, enum ButtonEventType press) { struct SynapticsX11 *x11 = priv->frontend_data; InputInfoPtr pInfo = x11->pInfo; @@ -810,7 +833,8 @@ void SynapticsButtonEvent(SynapticsPrivate *priv, int button, enum ButtonEventTy xf86PostButtonEvent(pInfo->dev, FALSE, button, press == BTN_PRESS, 0, 0); } -void SynapticsMotionEvent(SynapticsPrivate *priv, int x, int y) +static void +X11SynapticsMotionEvent(SynapticsPrivate *priv, int x, int y) { struct SynapticsX11 *x11 = priv->frontend_data; InputInfoPtr pInfo = x11->pInfo; @@ -818,7 +842,8 @@ void SynapticsMotionEvent(SynapticsPrivate *priv, int x, int y) xf86PostMotionEvent(pInfo->dev, FALSE, 0, 2, x, y); } -void SynapticsScrollEvent(SynapticsPrivate *priv, unsigned int which, double vert, double horiz) +static void +X11SynapticsScrollEvent(SynapticsPrivate *priv, unsigned int which, double vert, double horiz) { struct SynapticsX11 *x11 = priv->frontend_data; InputInfoPtr pInfo = x11->pInfo; @@ -836,7 +861,8 @@ void SynapticsScrollEvent(SynapticsPrivate *priv, unsigned int which, double ver xf86PostMotionEventM(pInfo->dev, FALSE, m); } -void SynapticsTouchEvent(SynapticsPrivate *priv, unsigned int touchid, +static void +X11SynapticsTouchEvent(SynapticsPrivate *priv, unsigned int touchid, enum TouchEventType type, VMask *mask) { struct SynapticsX11 *x11 = priv->frontend_data; diff --git a/src/synaptics.c b/src/synaptics.c index 0b22694..ac045ea 100644 --- a/src/synaptics.c +++ b/src/synaptics.c @@ -65,6 +65,7 @@ #include <limits.h> #include <math.h> #include <stdio.h> +#include <stdarg.h> #include "synaptics.h" @@ -507,13 +508,17 @@ SetDefaultParameters(SynapticsPrivate *priv) } SynapticsPrivate * -SynapticsInitPrivate(void) +SynapticsInitPrivate(struct SynapticsFrontend *frontend) { SynapticsPrivate *priv; priv = calloc(1, sizeof(SynapticsPrivate)); if (!priv) - return NULL; + goto error; + if (!frontend) + goto error; + + priv->frontend = frontend; priv->count_packet_finger = 0; priv->tap_state = TS_START; priv->tap_button = 0; @@ -523,6 +528,10 @@ SynapticsInitPrivate(void) priv->synpara.hyst_y = -1; return priv; +error: + if (priv) + free(priv); + return NULL; } void @@ -823,7 +832,7 @@ SynapticsReadInput(SynapticsPrivate *priv, int fd) } if (newDelay){ - unsigned int now = SynapticsGetCurrentMillis(); + unsigned int now = SynapticsGetCurrentMillis(priv); priv->timer_time = now; SynapticsSetTimer(priv, now, delay); } @@ -2274,3 +2283,57 @@ SynapticsFinishPreInit(SynapticsPrivate *priv) { CalculateScalingCoeffs(priv); } + +/* Wrappers around the frontend hooks */ +void +SynapticsMsg(SynapticsPrivate *priv, enum MessageType type, const char *format, ...) +{ + struct SynapticsFrontend *frontend = priv->frontend; + va_list args; + + va_start(args, format); + frontend->Msg(priv, type, format, args); + va_end(args); +} + +unsigned int +SynapticsGetCurrentMillis(SynapticsPrivate *priv) +{ + struct SynapticsFrontend *frontend = priv->frontend; + return frontend->GetCurrentMillis(); +} + +void +SynapticsButtonEvent(SynapticsPrivate *priv, int button, enum ButtonEventType press) +{ + struct SynapticsFrontend *frontend = priv->frontend; + return frontend->ButtonEvent(priv, button, press); +} + +void +SynapticsMotionEvent(SynapticsPrivate *priv, int x, int y) +{ + struct SynapticsFrontend *frontend = priv->frontend; + return frontend->MotionEvent(priv, x, y); +} + +void SynapticsScrollEvent(SynapticsPrivate *priv, unsigned int which, + double vert, double horiz) +{ + struct SynapticsFrontend *frontend = priv->frontend; + return frontend->ScrollEvent(priv, which, vert, horiz); +} + +void SynapticsTouchEvent(SynapticsPrivate *priv, unsigned int touchid, + enum TouchEventType type, VMask *mask) +{ + struct SynapticsFrontend *frontend = priv->frontend; + return frontend->TouchEvent(priv, touchid, type, mask); +} + +void +SynapticsSetTimer(SynapticsPrivate *priv, unsigned int now, unsigned int delay) +{ + struct SynapticsFrontend *frontend = priv->frontend; + return frontend->SetTimer(priv, now, delay); +} diff --git a/src/synaptics.h b/src/synaptics.h index 6f4e662..47971d9 100644 --- a/src/synaptics.h +++ b/src/synaptics.h @@ -24,50 +24,54 @@ #include "synproto.h" #include "synapticsstr.h" +#include <stdarg.h> -/** - * Generic messaging call. Called by the core driver to output driver log - * messages. - * Implemented by: front-end - */ -void SynapticsMsg(SynapticsPrivate *priv, enum MessageType type, const char *format, ...); -/** - * Return the current time in milliseconds. - * Implemented-by: frontend - */ -unsigned int SynapticsGetCurrentMillis(void); +struct SynapticsFrontend { + /** + * Generic messaging call. Called by the core driver to output driver log + * messages. + */ + void (*Msg)(SynapticsPrivate *priv, enum MessageType type, + const char *format, va_list args); + /** + * Return the current time in milliseconds. + */ + unsigned int (*GetCurrentMillis)(void); + /** + * Post a button event of the given type. + */ + void (*ButtonEvent)(SynapticsPrivate *priv, int button, enum ButtonEventType press); + /** + * Post a motion event. + */ + void (*MotionEvent)(SynapticsPrivate *priv, int x, int y); + /** + * Post a scroll event. + */ + void (*ScrollEvent)(SynapticsPrivate *priv, unsigned int which, + double vert, double horiz); + /** + * Post a touch event for the given touchid of the given type. + */ + void (*TouchEvent)(SynapticsPrivate *priv, unsigned int touchid, + enum TouchEventType type, VMask *mask); + /** + * Set a timer to be called delay milliseconds after now. That timer should + * call the SynapticsTimerFunc when it fires. + */ + void (*SetTimer)(SynapticsPrivate *priv, unsigned int now, unsigned int delay); +}; -/** - * Post a button event of the given type. - * Implemented-by: frontend - */ -void SynapticsButtonEvent(SynapticsPrivate *priv, int button, enum ButtonEventType press); -/** - * Post a motion event. - * Implemented-by: frontend - */ +/* Wrappers the drivers uses to call the matching frontend calls */ +void SynapticsMsg(SynapticsPrivate *priv, enum MessageType type, const char *format, ...); +unsigned int SynapticsGetCurrentMillis(SynapticsPrivate *priv); +void SynapticsButtonEvent(SynapticsPrivate *priv, int button, enum ButtonEventType press); void SynapticsMotionEvent(SynapticsPrivate *priv, int x, int y); - -/** - * Post a scroll event. - * Implemented-by: frontend - */ void SynapticsScrollEvent(SynapticsPrivate *priv, unsigned int which, double vert, double horiz); - -/** - * Post a touch event for the given touchid of the given type. - * Implemented-by: frontend - */ void SynapticsTouchEvent(SynapticsPrivate *priv, unsigned int touchid, enum TouchEventType type, VMask *mask); - -/** - * Set a timer to be called delay milliseconds after now. That timer should - * call the SynapticsTimerFunc when it fires. - * Implemented-by: frontend - */ void SynapticsSetTimer(SynapticsPrivate *priv, unsigned int now, unsigned int delay); /** @@ -76,7 +80,7 @@ void SynapticsSetTimer(SynapticsPrivate *priv, unsigned int now, unsigned int de * Implemented by: core * @see SynapticsFreePrivate */ -SynapticsPrivate * SynapticsInitPrivate(void); +SynapticsPrivate * SynapticsInitPrivate(struct SynapticsFrontend *frontend); /** * Deletes driver-associated memory regions. * Implemented by: core diff --git a/src/synapticsstr.h b/src/synapticsstr.h index d8aed14..e0b9664 100644 --- a/src/synapticsstr.h +++ b/src/synapticsstr.h @@ -208,6 +208,7 @@ struct _SynapticsPrivateRec { the X config file */ struct SynapticsProtocolOperations *proto_ops; void *proto_data; /* protocol-specific data */ + struct SynapticsFrontend *frontend; /* frontend hooks */ void *frontend_data; /* frontend-specific data */ struct SynapticsHwState *hwState; |