[gpm] [PATCH 3/18] separate-repeater-handling.patch

Dmitry Torokhov dtor_core@ameritech.net
Tue Aug 10 08:51:34 CEST 2004


===================================================================


ChangeSet@1.7, 2004-08-10 00:52:42-05:00, dtor_core@ameritech.net
  Split repeater-handling code into separate data structures
  and functions.


 gpm.c            |   59 +++++++++++++++++++++++++++++--------------------------
 gpn.c            |   27 ++++++++++++++++++-------
 headers/gpmInt.h |   12 ++++++-----
 startup.c        |   25 +++--------------------
 4 files changed, 63 insertions(+), 60 deletions(-)


===================================================================



diff -Nru a/src/gpm.c b/src/gpm.c
--- a/src/gpm.c	2004-08-10 01:17:58 -05:00
+++ b/src/gpm.c	2004-08-10 01:17:58 -05:00
@@ -77,11 +77,10 @@
 int opt_test=DEF_TEST;
 int opt_double=0;
 char *opt_special=NULL; /* special commands, like reboot or such */
-int opt_rawrep=0;
-Gpm_Type *repeated_type=0;
 
 static int opt_resize=0; /* not really an option */
-int fifofd=-1;
+
+struct repeater repeater;
 
 int eventFlag=0;
 Gpm_Cinfo *cinfo[MAX_VC+1];
@@ -183,8 +182,8 @@
       return NULL;
    }
 
-   if (!text_mode && fifofd != -1 && opt_rawrep)
-      write(fifofd, data, howmany);
+   if (!text_mode && repeater.fd != -1 && repeater.raw)
+      write(repeater.fd, data, howmany);
 
    if ((data[0]&(m_type->proto)[0]) != (m_type->proto)[1]) {
       if (m_type->getextra == 1) {
@@ -206,8 +205,8 @@
    if((i=m_type->packetlen-howmany)) /* still to get */
       do {
          j = read(fd,edata-i,i); /* edata is pointer just after data */
-         if (!text_mode && fifofd != -1 && opt_rawrep && j > 0)
-            write(fifofd, edata-i, j);
+         if (!text_mode && repeater.fd != -1 && repeater.raw && j > 0)
+            write(repeater.fd, edata - i, j);
          i -= j;
       } while (i && j);
 
@@ -256,6 +255,28 @@
    }
 }
 
+static void handle_repeater(Gpm_Event *new_event, Gpm_Event *event)
+{
+   static struct timeval last;
+   struct timeval now;
+
+   if (m_type->absolute) {
+      /* prepare the values from a absolute device for repeater mode */
+      gettimeofday(&now, (struct timezone *)NULL);
+      if (((now.tv_sec - last.tv_sec) * 1000 +
+               (now.tv_usec - last.tv_usec) / 1000) > 250) {
+         event->dx = 0;
+         event->dy = 0;
+      }
+      last = now;
+
+      event->dy = event->dy * ((console.max_x / console.max_y) + 1);
+      event->x = new_event->x;
+      event->y = new_event->y;
+   }
+   repeater.type->repeat_fun(event, repeater.fd);
+}
+
 /*-------------------------------------------------------------------
  * call getMouseData to get hardware device data, call mouse device's fun() 
  * to retrieve the hardware independent event data, then optionally repeat
@@ -349,26 +370,10 @@
 /*....................................... we're a repeater, aren't we? */
 
    if (!text_mode) {
-      if (fifofd != -1 && ! opt_rawrep) {
-         if (m_type->absolute) { /* hof Wed Feb  3 21:43:28 MET 1999 */ 
-            /* prepare the values from a absolute device for repeater mode */
-            static struct timeval rept1,rept2;
-            gettimeofday(&rept2, (struct timezone *)NULL);
-            if (((rept2.tv_sec -rept1.tv_sec)
-                  *1000+(rept2.tv_usec-rept1.tv_usec)/1000)>250) {
-               event->dx=0;
-               event->dy=0;
-            }
-            rept1=rept2;
-              
-            event->dy = event->dy * ((console.max_x / console.max_y) + 1);
-            event->x=nEvent.x; 
-            event->y=nEvent.y;
-         }
-         repeated_type->repeat_fun(event, fifofd); /* itz Jan 11 1999 */
-      }
+      if (repeater.fd != -1 && !repeater.raw)
+         handle_repeater(&nEvent, event);
       return 0; /* no events nor information for clients */
-   } /* first if of these three */
+   }
 
 /*....................................... no, we arent a repeater, go on */
 
@@ -839,7 +844,7 @@
       * but actually it only matters if you have events.
       */
       text_mode = is_text_console();
-      if (!text_mode && !option.repeater) {
+      if (!text_mode && !repeater.type && !repeater.raw) {
          close(mouse_table[i].fd);
          wait_text_console();
          /* reopen, reinit (the function is only used if we have one mouse device) */
diff -Nru a/src/gpn.c b/src/gpn.c
--- a/src/gpn.c	2004-08-10 01:17:58 -05:00
+++ b/src/gpn.c	2004-08-10 01:17:58 -05:00
@@ -128,6 +128,21 @@
    return type;
 }
 
+static void validate_repeater(char *type)
+{
+   if (strcmp(type, "raw") == 0)
+      repeater.raw = 1;
+   else {
+      repeater.raw = 0;
+
+      if (!(repeater.type = find_mouse_by_name(type)))
+         exit(M_listTypes()); /* not found */
+
+      if (!repeater.type->repeat_fun) /* unsupported translation */
+         gpm_report(GPM_PR_OOPS, GPM_MESS_NO_REPEAT, type);
+   }
+}
+
 /*****************************************************************************
  * Check the command line and / or set the appropriate variables
  * Can't believe it, today cmdline() really does what the name tries to say
@@ -159,9 +174,9 @@
          case 'l': console.charset = optarg;             break;
          case 'm': add_mouse(GPM_ADD_DEVICE,optarg);     
                    opt_dev = optarg;                     break; /* GO AWAY!*/
-         case 'M': opt_double++; option.repeater++;
-            if (option.repeater_type == 0)
-               option.repeater_type = "msc";
+         case 'M':   opt_double++;
+                     if (!repeater.type && !repeater.raw)
+                        repeater.type = find_mouse_by_name(DEF_REP_TYPE);
             which_mouse=mouse_table+2;                   break;
          case 'o': add_mouse(GPM_ADD_OPTIONS,optarg);
                    gpm_report(GPM_PR_DEBUG,"options: %s",optarg);
@@ -172,10 +187,8 @@
             opt_scale=atoi(optarg);
             if(!opt_scale || opt_scale > 100) opt_scale=100; /* the maximum */
             else opt_scale=100/opt_scale;                break;
-         case 'R':
-            option.repeater++;
-            if (optarg) option.repeater_type = optarg;
-            else        option.repeater_type = "msc";    break;
+         case 'R':   validate_repeater((optarg) ? optarg : DEF_REP_TYPE);
+                     break;
          case 's': opt_sample = atoi(optarg);            break;
          case 'S': if (optarg) opt_special = optarg;
                    else opt_special="";                  break;
diff -Nru a/src/headers/gpmInt.h b/src/headers/gpmInt.h
--- a/src/headers/gpmInt.h	2004-08-10 01:17:58 -05:00
+++ b/src/headers/gpmInt.h	2004-08-10 01:17:58 -05:00
@@ -52,6 +52,7 @@
 
 /* all the default values */
 #define DEF_TYPE          "ms"
+#define DEF_REP_TYPE     "msc"
 #define DEF_DEV           NULL     /* use the type-related one */
 #define DEF_LUT   "-a-zA-Z0-9_./\300-\326\330-\366\370-\377"
 #define DEF_SEQUENCE     "123"     /* how buttons are reordered */
@@ -188,17 +189,19 @@
 extern int opt_kill;
 extern int opt_kernel, opt_explicittype;
 extern char *opt_special;
-extern int opt_rawrep;
-extern int fifofd;
 extern int opt_double;
 
-extern Gpm_Type *repeated_type;
 extern Gpm_Type mice[];             /* where the hell are the descriptions...*/
 extern Gpm_Cinfo *cinfo[MAX_VC+1];
 
 /* new variables <CLEAN> */
 
 /* structure prototypes */
+struct repeater {
+   int      fd;
+   int      raw;
+   Gpm_Type *type;
+};
 
 /* contains all mice */
 struct micetab {
@@ -211,8 +214,6 @@
 struct options {
    int autodetect;            /* -u [aUtodetect..'A' is not available] */
    int no_mice;               /* number of mice */
-   int repeater;              /* repeat data */
-   char *repeater_type;       /* repeat data as which mouse type */
    int run_status;            /* startup/daemon/debug */
    char *progname;            /* hopefully gpm ;) */
    struct micetab *micelist;  /* mice and their options */
@@ -220,6 +221,7 @@
 
 /* global variables */
 struct options option;        /* one should be enough for us */
+extern struct repeater repeater; /* again, only one */
 
 /* new variables </CLEAN> */
 
diff -Nru a/src/startup.c b/src/startup.c
--- a/src/startup.c	2004-08-10 01:17:58 -05:00
+++ b/src/startup.c	2004-08-10 01:17:58 -05:00
@@ -72,8 +72,6 @@
    /* basic2: are not necessary for oops()ing, if not root */
    option.no_mice       = 0;                    /* counts -m + -t */
    option.micelist      = NULL;                 /* no mice found yet */
-   option.repeater      = 0;                    /* repeat data */
-   option.repeater_type = NULL;                 /* type of */
    
    console.device       = Gpm_get_console();    /* get consolename */
 
@@ -92,10 +90,10 @@
 
    console_load_lut();
 
-   if (option.repeater) {
-      if(mkfifo(GPM_NODE_FIFO,0666) && errno!=EEXIST)
-         gpm_report(GPM_PR_OOPS,GPM_MESS_CREATE_FIFO,GPM_NODE_FIFO);
-      if((fifofd=open(GPM_NODE_FIFO, O_RDWR|O_NONBLOCK)) < 0)
+   if (repeater.raw || repeater.type) {
+      if (mkfifo(GPM_NODE_FIFO, 0666) && errno != EEXIST)
+         gpm_report(GPM_PR_OOPS, GPM_MESS_CREATE_FIFO, GPM_NODE_FIFO);
+      if ((repeater.fd = open(GPM_NODE_FIFO, O_RDWR|O_NONBLOCK)) < 0)
          gpm_report(GPM_PR_OOPS, GPM_MESS_OPEN, GPM_NODE_FIFO);
    }
 
@@ -119,21 +117,6 @@
       m_type = find_mouse_by_name(opt_type);
       if (!m_type) /* not found */
          exit(M_listTypes());
-   }
-
-   /* Check repeater status */
-   if (option.repeater) {
-      if (strcmp(option.repeater_type,"raw") == 0)
-         opt_rawrep = 1;
-      else {
-         /* look for the type */
-         repeated_type = find_mouse_by_name(option.repeater_type);
-
-         if(!repeated_type) exit(M_listTypes()); /* not found */
-
-         if (!(repeated_type->repeat_fun)) /* unsupported translation */
-            gpm_report(GPM_PR_OOPS,GPM_MESS_NO_REPEAT,option.repeater_type);
-      }
    }
 
    if(option.run_status == GPM_RUN_STARTUP ) { /* else is debugging */


More information about the gpm mailing list