summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@openbsd.org>2009-11-23 15:16:52 +0000
committerMatthieu Herrb <matthieu@openbsd.org>2009-11-23 15:16:52 +0000
commit09286bc24e9ea3ac6660babd8f3e04dafd7db311 (patch)
treea9cc72edc9235c41b88c0e9f0baea5ffa97287fe
parent08bdd827e8816e19251a14c24489c3aade9863f0 (diff)
split wsProc().
-rw-r--r--src/ws.c202
1 files changed, 114 insertions, 88 deletions
diff --git a/src/ws.c b/src/ws.c
index 01f4472..0a95b24 100644
--- a/src/ws.c
+++ b/src/ws.c
@@ -62,6 +62,9 @@ static void TearDownProc(pointer);
static InputInfoPtr wsPreInit(InputDriverPtr, IDevPtr, int);
static int wsProc(DeviceIntPtr, int);
+static int wsDeviceInit(DeviceIntPtr);
+static int wsDeviceOn(DeviceIntPtr);
+static void wsDeviceOff(DeviceIntPtr);
static void wsReadInput(InputInfoPtr);
static void wsSendButtons(InputInfoPtr, int);
static int wsChangeControl(InputInfoPtr, xDeviceCtl *);
@@ -327,115 +330,138 @@ static int
wsProc(DeviceIntPtr pWS, int what)
{
InputInfoPtr pInfo = (InputInfoPtr)pWS->public.devicePrivate;
- WSDevicePtr priv = (WSDevicePtr)XI_PRIVATE(pWS);
- unsigned char map[NBUTTONS + 1];
- int i;
-#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
- Atom btn_labels[NBUTTONS] = {0};
- Atom axes_labels[NAXES] = {0};
-#endif
switch (what) {
case DEVICE_INIT:
- DBG(1, ErrorF("WS DEVICE_INIT\n"));
+ return wsDeviceInit(pWS);
- priv->screen_width =
- screenInfo.screens[priv->screen_no]->width;
- priv->screen_height =
- screenInfo.screens[priv->screen_no]->height;
+ case DEVICE_ON:
+ return wsDeviceOn(pWS);
+
+ case DEVICE_OFF:
+ wsDeviceOff(pWS);
+ break;
+
+ case DEVICE_CLOSE:
+ DBG(1, ErrorF("WS DEVICE_CLOSE\n"));
+ wsClose(pInfo);
+ break;
+
+ default:
+ xf86Msg(X_ERROR, "WS: unknown command %d\n", what);
+ return !Success;
+ } /* switch */
+ return Success;
+} /* wsProc */
- for (i = 0; i < NBUTTONS; i++)
- map[i + 1] = i + 1;
- if (!InitButtonClassDeviceStruct(pWS,
- min(priv->buttons, NBUTTONS),
+static int
+wsDeviceInit(DeviceIntPtr pWS)
+{
+ InputInfoPtr pInfo = (InputInfoPtr)pWS->public.devicePrivate;
+ WSDevicePtr priv = (WSDevicePtr)XI_PRIVATE(pWS);
+ unsigned char map[NBUTTONS + 1];
+ int i;
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
- btn_labels,
+ Atom btn_labels[NBUTTONS] = {0};
+ Atom axes_labels[NAXES] = {0};
#endif
- map))
- return !Success;
- if (!InitValuatorClassDeviceStruct(pWS,
- NAXES,
+ DBG(1, ErrorF("WS DEVICE_INIT\n"));
+
+ priv->screen_width = screenInfo.screens[priv->screen_no]->width;
+ priv->screen_height = screenInfo.screens[priv->screen_no]->height;
+
+ for (i = 0; i < NBUTTONS; i++)
+ map[i + 1] = i + 1;
+ if (!InitButtonClassDeviceStruct(pWS,
+ min(priv->buttons, NBUTTONS),
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
- axes_labels,
+ btn_labels,
+#endif
+ map))
+ return !Success;
+
+ if (!InitValuatorClassDeviceStruct(pWS,
+ NAXES,
+#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
+ axes_labels,
#endif
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
- xf86GetMotionEvents,
+ xf86GetMotionEvents,
#endif
- GetMotionHistorySize(),
- priv->type == WSMOUSE_TYPE_TPANEL ?
- Absolute : Relative))
- return !Success;
- if (!InitPtrFeedbackClassDeviceStruct(pWS, wsControlProc))
- return !Success;
-
- xf86InitValuatorAxisStruct(pWS,
+ GetMotionHistorySize(),
+ priv->type == WSMOUSE_TYPE_TPANEL ?
+ Absolute : Relative))
+ return !Success;
+ if (!InitPtrFeedbackClassDeviceStruct(pWS, wsControlProc))
+ return !Success;
+
+ xf86InitValuatorAxisStruct(pWS,
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
- axes_labels[0],
+ axes_labels[0],
#endif
- 0, 0, -1, 1, 0, 1);
- xf86InitValuatorDefaults(pWS, 0);
-
- xf86InitValuatorAxisStruct(pWS,
+ 0, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pWS, 0);
+
+ xf86InitValuatorAxisStruct(pWS,
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
- axes_labels[1],
+ axes_labels[1],
#endif
- 1, 0, -1, 1, 0, 1);
- xf86InitValuatorDefaults(pWS, 1);
- xf86MotionHistoryAllocate(pInfo);
- AssignTypeAndName(pWS, pInfo->atom, pInfo->name);
- pWS->public.on = FALSE;
- /* This should correspond to the center of the screen */
- priv->x = (priv->max_x - priv->min_x) / 2;
- priv->y = (priv->max_y - priv->min_y) / 2;
- if (wsOpen(pInfo) != Success) {
- return !Success;
- }
- break;
-
- case DEVICE_ON:
- DBG(1, ErrorF("WS DEVICE ON\n"));
- if ((pInfo->fd < 0) && (wsOpen(pInfo) != Success)) {
- xf86Msg(X_ERROR, "wsOpen failed %s\n",
- strerror(errno));
- return !Success;
- }
- priv->buffer = XisbNew(pInfo->fd,
- sizeof(struct wscons_event) * NUMEVENTS);
- if (priv->buffer == NULL) {
- xf86Msg(X_ERROR, "cannot alloc xisb buffer\n");
- wsClose(pInfo);
- return !Success;
- }
- xf86AddEnabledDevice(pInfo);
- pWS->public.on = TRUE;
-
- break;
+ 1, 0, -1, 1, 0, 1);
+ xf86InitValuatorDefaults(pWS, 1);
+ xf86MotionHistoryAllocate(pInfo);
+ AssignTypeAndName(pWS, pInfo->atom, pInfo->name);
+ pWS->public.on = FALSE;
+ /* This should correspond to the center of the screen */
+ priv->x = (priv->max_x - priv->min_x) / 2;
+ priv->y = (priv->max_y - priv->min_y) / 2;
+ if (wsOpen(pInfo) != Success) {
+ return !Success;
+ }
+ return Success;
+}
- case DEVICE_OFF:
- DBG(1, ErrorF("WS DEVICE OFF\n"));
- if (pInfo->fd >= 0) {
- xf86RemoveEnabledDevice(pInfo);
- wsClose(pInfo);
- }
- if (priv->buffer) {
- XisbFree(priv->buffer);
- priv->buffer = NULL;
- }
- pWS->public.on = FALSE;
- break;
+static int
+wsDeviceOn(DeviceIntPtr pWS)
+{
+ InputInfoPtr pInfo = (InputInfoPtr)pWS->public.devicePrivate;
+ WSDevicePtr priv = (WSDevicePtr)XI_PRIVATE(pWS);
- case DEVICE_CLOSE:
- DBG(1, ErrorF("WS DEVICE_CLOSE\n"));
+ DBG(1, ErrorF("WS DEVICE ON\n"));
+ if ((pInfo->fd < 0) && (wsOpen(pInfo) != Success)) {
+ xf86Msg(X_ERROR, "wsOpen failed %s\n",
+ strerror(errno));
+ return !Success;
+ }
+ priv->buffer = XisbNew(pInfo->fd,
+ sizeof(struct wscons_event) * NUMEVENTS);
+ if (priv->buffer == NULL) {
+ xf86Msg(X_ERROR, "cannot alloc xisb buffer\n");
wsClose(pInfo);
- break;
-
- default:
- xf86Msg(X_ERROR, "WS: unknown command %d\n", what);
return !Success;
- } /* switch */
+ }
+ xf86AddEnabledDevice(pInfo);
+ pWS->public.on = TRUE;
return Success;
-} /* wsProc */
+}
+
+static void
+wsDeviceOff(DeviceIntPtr pWS)
+{
+ InputInfoPtr pInfo = (InputInfoPtr)pWS->public.devicePrivate;
+ WSDevicePtr priv = (WSDevicePtr)XI_PRIVATE(pWS);
+
+ DBG(1, ErrorF("WS DEVICE OFF\n"));
+ if (pInfo->fd >= 0) {
+ xf86RemoveEnabledDevice(pInfo);
+ wsClose(pInfo);
+ }
+ if (priv->buffer) {
+ XisbFree(priv->buffer);
+ priv->buffer = NULL;
+ }
+ pWS->public.on = FALSE;
+}
static void
wsReadInput(InputInfoPtr pInfo)