URI:
       tmouseswap.c - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       tmouseswap.c (963B)
       ---
            1 #include <u.h>
            2 #include <libc.h>
            3 #include <draw.h>
            4 #include <memdraw.h>
            5 #include <memlayer.h>
            6 #include <mouse.h>
            7 #include <cursor.h>
            8 #include <keyboard.h>
            9 #include <drawfcall.h>
           10 #include "devdraw.h"
           11 
           12 enum
           13 {
           14         Nbutton = 10
           15 };
           16 
           17 static int debug;
           18 
           19 static struct
           20 {
           21         int b[Nbutton];
           22         int init;
           23 } map;
           24 
           25 static void
           26 initmap(void)
           27 {
           28         char *p;
           29         int i;
           30 
           31         p = getenv("mousedebug");
           32         if(p && p[0])
           33                 debug = atoi(p);
           34 
           35         for(i=0; i<Nbutton; i++)
           36                 map.b[i] = i;
           37         map.init = 1;
           38         p = getenv("mousebuttonmap");
           39         if(p)
           40                 for(i=0; i<Nbutton && p[i]; i++)
           41                         if('0' <= p[i] && p[i] <= '9')
           42                                 map.b[i] = p[i] - '1';
           43         if(debug){
           44                 fprint(2, "mousemap: ");
           45                 for(i=0; i<Nbutton; i++)
           46                         fprint(2, " %d", 1+map.b[i]);
           47                 fprint(2, "\n");
           48         }
           49 }
           50 
           51 int
           52 mouseswap(int but)
           53 {
           54         int i;
           55         int nbut;
           56 
           57         if(!map.init)
           58                 initmap();
           59 
           60         nbut = 0;
           61         for(i=0; i<Nbutton; i++)
           62                 if((but&(1<<i)) && map.b[i] >= 0)
           63                         nbut |= 1<<map.b[i];
           64         if(debug)
           65                 fprint(2, "swap %#b -> %#b\n", but, nbut);
           66         return nbut;
           67 }