static void MouseApplyCallback(Widget w, XtPointer user_data, XtPointer call_data) { int i; XF86MiscMouseSettings mouse; XF86MiscGetMouseSettings(XtDisplay(w), &mouse); XtFree(mouse.device); if (mouse.baudrate == 0 || mouse.baudrate < 0 || mouse.baudrate > 9600 || mouse.baudrate % 1200) mouse.baudrate = 1200; mouse.type = MTYPE_AUTOMOUSE; for (i = 0; i < sizeof(protocols) / sizeof(protocols[0]); i++) if (strcmp(protocols[i].name, protocol) == 0) { mouse.type = protocols[i].type; break; } mouse.emulate3buttons = emulate; mouse.flags |= MF_REOPEN; mouse.device = device; XFlush(XtDisplay(w)); XF86MiscSetMouseSettings(XtDisplay(w), &mouse); }
//=================================== // enableMouse... //----------------------------------- void enableMouse (Display* dpy) { XSetErrorHandler (catchErrors); XF86MiscMouseSettings mseinfo; if (!XF86MiscGetMouseSettings(dpy, &mseinfo)) { return; } mseinfo.flags |= MF_REOPEN; XF86MiscSetMouseSettings(dpy, &mseinfo); XSync(dpy, False); }
//======================================== // GetMouse... //---------------------------------------- XF86MiscMouseSettings GetMouse(Display *dpy) { XF86MiscMouseSettings mseinfo; char tmpbuf[200] = {0}; if (!XF86MiscGetMouseSettings(dpy, &mseinfo)) { return(mseinfo); } else { char *name; if (mseinfo.type == MTYPE_XQUEUE) { name = "Xqueue"; } else if (mseinfo.type == MTYPE_OSMOUSE) { name = "OSMouse"; } else if ( (mseinfo.type < 0) || ((unsigned)mseinfo.type >= MSETABLESIZE) ) { name = "Unknown"; } else { name = msetable[mseinfo.type+1]; } snprintf ( tmpbuf, sizeof(tmpbuf), "%s %s %d %d %d %d %s %d %s", mseinfo.device==NULL? "{}": mseinfo.device, name, mseinfo.baudrate, mseinfo.samplerate, mseinfo.resolution, mseinfo.buttons, mseinfo.emulate3buttons? "on": "off", mseinfo.emulate3timeout, mseinfo.chordmiddle? "on": "off" ); if (mseinfo.flags & MF_CLEAR_DTR) { strncat(tmpbuf, " ClearDTR", sizeof(tmpbuf)-strlen(tmpbuf)-1); } if (mseinfo.flags & MF_CLEAR_RTS) { strncat(tmpbuf, " ClearRTS", sizeof(tmpbuf)-strlen(tmpbuf)-1); } if (mseinfo.device) { XFree(mseinfo.device); } printf("%s\n",tmpbuf); return(mseinfo); } }
//======================================== // main... //---------------------------------------- int main (int argc, char*argv[]) { XF86MiscMouseSettings mseinfo; Display* dpy; int c; int DEBUG = False; int show = False; int Version = False; int apply = False; int enable = False; int disable = False; int major = 0; int minor = 0; char link [256] = ""; char mydisp [256] = ""; char option [256] = ""; char left [256] = ""; struct mouse *pointer; struct devnode *dev; struct stat *linkstatus = NULL; pointer = (struct mouse*) malloc(sizeof(struct mouse)); dev = (struct devnode*) malloc(sizeof(struct devnode)); // get commandline options... //----------------------------- while (1) { int option_index = 0; static struct option long_options[] = { {"show" , 0 , 0 , 's'}, {"apply" , 1 , 0 , 'a'}, {"display" , 1 , 0 , 'd'}, {"help" , 0 , 0 , 'h'}, {"link" , 1 , 0 , 'l'}, {"enable" , 0 , 0 , 'E'}, {"disable" , 0 , 0 , 'D'}, {"version" , 0 , 0 , 'v'}, {"config" , 0 , 0 , 'c'}, {0 , 0 , 0 , 0 } }; c = getopt_long (argc, argv, "hsa:d:l:EDvc",long_options, &option_index); if (c == -1) break; switch (c) { case 0: if (DEBUG) { fprintf (stderr,"option %s", long_options[option_index].name); if (optarg) fprintf (stderr," with arg %s", optarg); fprintf (stderr,"\n"); } break; case 'h': usage(); break; case 'c': showConfig(); break; case 's': show = True; break; case 'v': Version = True; break; case 'a': if (! IsRoot()) { fprintf(stderr,"xmset: only root can do this\n"); exit(1); } apply = True; strcpy(option,optarg); break; case 'l': // no longer used because we will get the // the device name (which may be a link) from the X-Server // and check if it is realy a link to the pointer device. // If not, no symlink is created after apply // --- // strcpy(link,optarg); break; case 'd': strcpy(mydisp,optarg); break; case 'E': if (! IsRoot()) { fprintf(stderr,"xmset: only root can do this\n"); exit(1); } enable = True; break; case 'D': if (! IsRoot()) { fprintf(stderr,"xmset: only root can do this\n"); exit(1); } disable = True; break; default: exit(1); } } // ... // open display... // --- if (strcmp(mydisp,"") == 0) { strcpy(mydisp,"null"); } dpy = XOpen(mydisp); if (dpy == NULL) { if (Version) { printf("0:6\n"); } else { fprintf(stderr,"xmset: could not open display\n"); } exit(1); } if (Version) { if (XF86MiscQueryVersion(dpy,&major,&minor)) { printf("%d:%d\n",major,minor); exit (0); } } // ... // store link name if the device specification // of the current configuration is a link // --- if (!XF86MiscGetMouseSettings(dpy, &mseinfo)) { fprintf(stderr,"xmset: could not get mouse settings\n"); exit(1); } if (apply == True) { linkstatus = (struct stat*)malloc(sizeof(struct stat)); lstat (mseinfo.device,linkstatus); if (S_ISLNK (linkstatus->st_mode)) { strcpy (link,mseinfo.device); } } //================================= // enable mouse //--------------------------------- if (enable == True) { XF86MiscMouseSettings mseinfo; if (!XF86MiscGetMouseSettings(dpy, &mseinfo)) { exit(1); } mseinfo.flags |= MF_REOPEN; XSetErrorHandler (catchErrors); XF86MiscSetMouseSettings(dpy, &mseinfo); XSync(dpy, False); exit(0); } //================================= // disable mouse //--------------------------------- if (disable == True) { XF86MiscMouseSettings mseinfo; if (!XF86MiscGetMouseSettings(dpy, &mseinfo)) { exit(1); } mseinfo.flags |= MF_REOPEN; mseinfo.device = "/dev/unused"; XSetErrorHandler (catchErrors); XF86MiscSetMouseSettings(dpy, &mseinfo); XSync(dpy, False); exit(0); } //================================== // apply mouse settings //---------------------------------- if (apply == True) { XF86MiscMouseSettings mseinfo; strsplit (option,':',left,option); strcpy (pointer->device,left); strsplit (option,':',left,option); strcpy (pointer->type,left); strsplit (option,':',left,option); pointer->baudrate = atoi(left); strsplit (option,':',left,option); pointer->samplerate = atoi(left); strsplit (option,':',left,option); pointer->resolution = atoi(left); strsplit (option,':',left,option); pointer->buttons = atoi(left); strsplit (option,':',left,option); if (strcmp(left,"on") == 0) { strcpy(pointer->emu3button,"on"); } else { strcpy(pointer->emu3button,"off"); } strsplit(option,':',left,option); pointer->emu3timeout = atoi(left); strsplit(option,':',left,option); if (strcmp(left,"on") == 0) { strcpy(pointer->chordmiddle,"on"); } else { strcpy(pointer->chordmiddle,"off"); } strsplit (option,':',left,option); strcpy (pointer->flag,left); // ... // relink the /dev/sax link if the configuration // use a device link to point to the input device // --- if (S_ISLNK (linkstatus->st_mode)) { remove (link); symlink (pointer->device,link); } // ... // remove mouse from currently // accessed device // --- if (!XF86MiscGetMouseSettings(dpy, &mseinfo)) { exit(1); } mseinfo.flags |= MF_REOPEN; sprintf(mseinfo.device,"disabled"); XSetErrorHandler (catchErrors); XF86MiscSetMouseSettings(dpy, &mseinfo); XSync(dpy, False); // ... // set new mouse parameters... // --- usleep (1000); SetMouse (dpy,pointer); } //================================== // show current mouse settings //---------------------------------- if (show == True) { GetMouse(dpy); } return(0); }