gpm and tslib

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,
  yesterday I hacked a bit with gpm to add a new driver for tslib, a
library for reading input from touchscreen devices. I admit that using
a stylus with gpm doesn't make much sense, but what interested me most
is the translation gpm can provide from stylus input to mouse input.

Anyway, I'm attaching the patch to this message (you have to run
configure with "CFLAGS=-DHAVE_TSLIB_H" and "LDFLAGS=-lts"), not to
propose it for inclusion in the mainline, but for anyone else who should
encounter thi need. It's really a bad hack, but unfortunately gpm's
design didn't allow me much more alternatives.

BTW, if you ever plan to re-design gpm's device driver's interface,
leave all the details to the driver (opening the device, waiting and
reading input, closing) and just provide helper functions for doing the
most common tasks, instead of directly opening and managing the fd.
Please. :-)


-- 
Saluti,
    Mardy
http://interlingua.altervista.org
Index: tmp/gpm-1.20.1/src/gpm.c
===================================================================
--- tmp.orig/gpm-1.20.1/src/gpm.c	2002-12-24 23:57:16.000000000 +0100
+++ tmp/gpm-1.20.1/src/gpm.c	2005-12-02 22:58:33.000000000 +0100
@@ -338,6 +338,7 @@
 
 /*....................................... read and identify one byte */
 
+   if (howmany == 0) return "";
    if (read(fd, data, howmany)!=howmany) {
       if (opt_test) exit(0);
       gpm_report(GPM_PR_ERR,GPM_MESS_READ_FIRST, strerror(errno));
Index: tmp/gpm-1.20.1/src/mice.c
===================================================================
--- tmp.orig/gpm-1.20.1/src/mice.c	2002-12-24 23:57:16.000000000 +0100
+++ tmp/gpm-1.20.1/src/mice.c	2005-12-02 22:58:32.000000000 +0100
@@ -69,6 +69,12 @@
 #include <linux/input.h>
 #endif /* HAVE_LINUX_INPUT_H */
  
+#ifdef HAVE_TSLIB_H
+#include <linux/fb.h>
+#include "tslib.h"
+static struct tsdev *ts = 0;
+static int ts_x, ts_y;
+#endif
 
 
 #include "headers/gpmInt.h"
@@ -1207,6 +1213,36 @@
    return 0;
 }
 
+#ifdef HAVE_TSLIB_H
+static int M_tslib(Gpm_Event *state,  unsigned char *data)
+{
+   struct ts_sample samp;
+   struct winsize win;
+   static unsigned int old_pressure;
+   int err, fd_con;
+   
+   err = ts_read(ts, &samp, 1);
+   if (err < 0) return 0;
+   fd_con = open("/dev/console", O_RDONLY);
+   ioctl(fd_con, TIOCGWINSZ, &win);
+   close(fd_con);
+   if (!win.ws_col || !win.ws_row) {
+      win.ws_col=80; win.ws_row=25;
+   }
+   state->x = samp.x * win.ws_col / ts_x;
+   state->y = samp.y * win.ws_row / ts_y;
+   if (old_pressure == 0) {
+      if (samp.pressure > 0) state->type = GPM_DOWN;
+      else state->type = GPM_MOVE;
+   } else {
+      if (samp.pressure > 0) state->type = GPM_DRAG;
+      else state->type = GPM_UP;
+   }
+   state->buttons = (samp.pressure > 0) ? GPM_B_LEFT : 0;
+   return 0;
+}
+#endif
+
 static int M_mtouch(Gpm_Event *state,  unsigned char *data)
 {
    /*
@@ -1951,6 +1987,39 @@
 }
 
 
+#ifdef HAVE_TSLIB_H
+static Gpm_Type *I_tslib(int fd, unsigned short flags,
+           struct Gpm_Type *type, int argc, char **argv)
+{
+   struct fb_var_screeninfo var;
+   char *fbdevice;
+   int fb_fd;
+
+   close(fd); /* who asked you to open it??? */
+   ts = ts_open(opt_dev, 0);
+   which_mouse->fd = ts_fd(ts);
+   ts_config(ts);
+   /* let's get screen resolution */
+   if ((fbdevice = getenv ("TSLIB_FBDEVICE")) == NULL)
+      fbdevice = "/dev/fb0";
+   fb_fd = open(fbdevice, O_RDWR);
+   if (fb_fd == -1) {
+      gpm_report(GPM_PR_ERR, GPM_MESS_OPEN, fbdevice);
+      return NULL;
+   }
+   if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &var) < 0) {
+      perror("ioctl FBIOGET_VSCREENINFO");
+      close(fb_fd);
+      return NULL;
+   }
+   close(fb_fd);
+   ts_x = var.xres;
+   ts_y = var.yres;
+   return type;
+}
+#endif
+
+
 static Gpm_Type *I_summa(int fd, unsigned short flags,
           struct Gpm_Type *type, int argc, char **argv) 
 {
@@ -2309,6 +2378,11 @@
    {"synps2", "The \"Synaptics\" PS/2 TouchPad",
            "synaptics_ps2", M_synaptics_ps2, I_synps2, STD_FLG,
                                 {0x80, 0x80, 0x00, 0x00}, 6, 1, 1, 0, 0},
+#ifdef HAVE_TSLIB_H
+   {"tslib", "tslib touchscreen library",
+            "", M_tslib, I_tslib, STD_FLG,
+                        {0x00, 0x00, 0x00, 0x00} , 0, 0, 0, 1, NULL},
+#endif
    {"twid", "Twidddler keyboard",
            "", M_twid, I_twid, CS8 | STD_FLG,
                                 {0x80, 0x00, 0x80, 0x80}, 5, 1, 0, 0, 0},
_______________________________________________
gpm mailing list
gpm@xxxxxxxxxxxxxx
http://lists.linux.it/listinfo/gpm

[Index of Archives]     [Kernel Development]     [Red Hat Install]     [Red Hat Watch]     [Red Hat Development]     [Gimp]     [Yosemite News]