Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit

  • Loading branch information...
commit d75dc00d35d95b1c62ba1ce63e3cf2a35f6c84ac 0 parents
@rfc2822 authored
10 LICENSE.md
@@ -0,0 +1,10 @@
+Author: Richard Hirner <hirner@bitfire.at>
+
+X.org License
+=============
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 Makefile
@@ -0,0 +1,13 @@
+
+networktablet_drv.la : networktablet.lo
+ libtool --mode=link gcc -module -o networktablet_drv.la -rpath /usr/lib/xorg/modules/input networktablet.lo
+
+networktablet.lo : networktablet.c
+ libtool --mode=compile gcc -c `pkg-config --cflags xorg-server` networktablet.c
+
+
+clean :
+ rm -r .libs *.la *.lo *.o
+
+install :
+ libtool --mode=install install -c networktablet_drv.la '/usr/lib/xorg/modules/input'
5 README.md
@@ -0,0 +1,5 @@
+
+xf86-networktablet
+==================
+
+X.org/XF86 input driver: virtual tablet (controlled by network)
251 networktablet.c
@@ -0,0 +1,251 @@
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <linux/input.h>
+#include <linux/types.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include <xorg-server.h>
+#include <xorgVersion.h>
+#include <xf86Module.h>
+#include <X11/Xatom.h>
+#include <xf86_OSproc.h>
+#include <xf86.h>
+#include <xf86Xinput.h>
+#include <exevents.h>
+#include <xserver-properties.h>
+#include <X11/extensions/XKB.h>
+#include <xkbsrv.h>
+
+
+#include "networktablet.h"
+#include "protocol.h"
+
+static char tablet_driver_name[] = "networktablet";
+
+static int TabletPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags);
+static void TabletUnInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags);
+static pointer TabletPlug(pointer module, pointer options, int *errmaj, int *errmin);
+static void TabletUnplug(pointer p);
+static int TabletControl(DeviceIntPtr device, int what);
+static int _tablet_init_buttons(DeviceIntPtr device);
+static int _tablet_init_axes(DeviceIntPtr device);
+static void _tablet_init_axes_labels(TabletDevicePtr pTablet, int natoms, Atom *atoms);
+static void TabletReadInput(InputInfoPtr pInfo);
+
+
+_X_EXPORT InputDriverRec TABLET = {
+ 1,
+ tablet_driver_name,
+ NULL,
+ TabletPreInit,
+ TabletUnInit,
+ NULL,
+ 0
+};
+
+static XF86ModuleVersionInfo TabletVersionRec =
+{
+ "networktablet",
+ MODULEVENDORSTRING,
+ MODINFOSTRING1,
+ MODINFOSTRING2,
+ XORG_VERSION_CURRENT,
+ 0, 1, 0, /* version 0.1.0 */
+ ABI_CLASS_XINPUT,
+ ABI_XINPUT_VERSION,
+ MOD_CLASS_XINPUT,
+ {0, 0, 0, 0}
+};
+
+_X_EXPORT XF86ModuleData networktabletModuleData =
+{
+ &TabletVersionRec,
+ &TabletPlug,
+ &TabletUnplug
+};
+
+
+
+int TabletPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) {
+ TabletDevicePtr pTablet;
+
+ pTablet = calloc(1, sizeof(TabletDeviceRec));
+ if (!pTablet) {
+ pInfo->private = NULL;
+ xf86DeleteInput(pInfo, 0);
+ return BadAlloc;
+ }
+ pInfo->private = pTablet;
+
+ pInfo->type_name = XI_TABLET; /* see XI.h */
+ pInfo->read_input = TabletReadInput;
+ pInfo->switch_mode = NULL;
+ pInfo->device_control = TabletControl;
+
+ xf86CollectInputOptions(pInfo, NULL);
+ xf86ProcessCommonOptions(pInfo, pInfo->options);
+
+ return Success;
+}
+
+void TabletUnInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags){
+ TabletDevicePtr pTablet = pInfo->private;
+ if (pTablet) {
+ free(pTablet);
+ pInfo->private = NULL;
+ }
+ xf86DeleteInput(pInfo, 0);
+}
+
+
+pointer TabletPlug(pointer module, pointer options, int *errmaj, int *errmin)
+{
+ xf86AddInputDriver(&TABLET, module, 0);
+ return module;
+}
+
+void TabletUnplug(pointer p)
+{
+}
+
+
+int TabletControl(DeviceIntPtr device, int what)
+{
+ InputInfoPtr pInfo = device->public.devicePrivate;
+ TabletDevicePtr pTablet = pInfo->private;
+ struct sockaddr_in addr;
+ int ret;
+
+ switch (what) {
+ case DEVICE_INIT:
+ xf86Msg(X_INFO, "%s: Init\n", pInfo->name);
+ if ((ret = _tablet_init_buttons(device)) != Success) return ret;
+ if ((ret = _tablet_init_axes(device)) != Success) return ret;
+ break;
+ case DEVICE_ON:
+ xf86Msg(X_INFO, "%s: On\n", pInfo->name);
+ if (device->public.on) break;
+
+ pInfo->fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ bzero(&addr, sizeof(struct sockaddr_in));
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(NETWORKTABLET_PORT);
+ addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ bind(pInfo->fd, (struct sockaddr *)&addr, sizeof(addr));
+
+ xf86AddEnabledDevice(pInfo);
+ device->public.on = TRUE;
+ break;
+ case DEVICE_OFF:
+ xf86Msg(X_INFO, "%s: Off\n", pInfo->name);
+ if (!device->public.on) break;
+ xf86RemoveEnabledDevice(pInfo);
+
+ close(pInfo->fd);
+ pInfo->fd = -1;
+ device->public.on = FALSE;
+ break;
+ }
+
+ return Success;
+}
+
+
+int _tablet_init_buttons(DeviceIntPtr device)
+{
+ InputInfoPtr pInfo = device->public.devicePrivate;
+ TabletDevicePtr pTablet = pInfo->private;
+ Atom *labels = calloc(1, sizeof(Atom));
+ char map[] = { 0, 1 };
+
+ if (!InitButtonClassDeviceStruct(device, 1, labels, map)) {
+ xf86Msg(X_ERROR, "%s: Failed to register buttons.\n", pInfo->name);
+ free(labels);
+ return !Success;
+ }
+
+ free(labels);
+ return Success;
+}
+
+int _tablet_init_axes(DeviceIntPtr device)
+{
+ InputInfoPtr pInfo = device->public.devicePrivate;
+ TabletDevicePtr pTablet = pInfo->private;
+ int i;
+ const int num_axes = 3;
+ Atom *labels;
+
+ // x, y
+ labels = calloc(num_axes, sizeof(Atom));
+
+ if (!InitValuatorClassDeviceStruct(device,
+ num_axes,
+ #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
+ labels,
+ #endif
+ GetMotionHistorySize(),
+ Absolute)) {
+ free(labels);
+ return BadAlloc;
+ }
+
+ // TODO: hardcoded 1280x800
+ xf86InitValuatorAxisStruct(device, 0, XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X),
+ 0, 1280,
+ 1280,
+ 0, 1280,
+ Absolute);
+ xf86InitValuatorAxisStruct(device, 1, XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y),
+ 0, 800,
+ 800,
+ 0, 800,
+ Absolute);
+
+ // pressure
+ xf86InitValuatorAxisStruct(device, 2, XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE),
+ 0, 10000,
+ 1,
+ 0, 1,
+ Absolute);
+
+ free(labels);
+
+ return Success;
+}
+
+
+void TabletReadInput(InputInfoPtr pInfo)
+{
+ TabletDevicePtr pTablet = pInfo->private;
+ EventPacket event;
+
+ while(xf86WaitForInput(pInfo->fd, 0) > 0) {
+ // each EventPacket has at least 7 bytes
+ if (recv(pInfo->fd, &event, sizeof(event), 0) >= 7) {
+ pTablet->x = ntohs(event.x);
+ pTablet->y = ntohs(event.y);
+ pTablet->pressure = ntohs(event.pressure);
+
+ switch (event.type) {
+ case EVENT_TYPE_MOTION:
+ xf86PostMotionEvent(pInfo->dev, TRUE, 0, 3, pTablet->x, pTablet->y, pTablet->pressure);
+ break;
+ case EVENT_TYPE_BUTTON:
+ xf86PostButtonEvent(pInfo->dev, TRUE, event.button, event.down, 0, 3, pTablet->x, pTablet->y, pTablet->pressure);
+ break;
+ }
+ }
+ }
+}
+
7 networktablet.h
@@ -0,0 +1,7 @@
+
+typedef struct _TabletDeviceRec
+{
+ int x, y;
+ int pressure;
+} TabletDeviceRec, *TabletDevicePtr;
+
26 protocol.h
@@ -0,0 +1,26 @@
+
+#define NETWORKTABLET_PORT 40117
+
+
+#pragma pack(push)
+#pragma pack(1)
+
+#define EVENT_TYPE_MOTION 0
+#define EVENT_TYPE_BUTTON 1
+
+typedef struct _EventPacket
+{
+ char type;
+ struct {
+ short x, y;
+ short pressure;
+ };
+ union {
+ struct {
+ char button;
+ char down;
+ };
+ };
+} EventPacket;
+
+#pragma pack(pop)
Please sign in to comment.
Something went wrong with that request. Please try again.