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); }
//====================================== // Implement mouse apply // Usage: // SetMouse ( // display -> display // device -> device // mousetype -> Protocol // baudrate -> Baudrate // samplerate -> Samplerate // resolution -> Resolution // buttons -> Buttons // on|off -> Emulate3Buttons // timeout -> Emulate3Timeout // on|off -> ChordMiddle // // you may set one of this flags // ----------------------------- // [ClearDTR] -> Flag // [ClearRTS] -> Flag // [ReOpen] -> apply immediatelly // ) //---------------------------------------- int SetMouse(Display *dpy, struct mouse* argv) { XF86MiscMouseSettings mseinfo; unsigned i; mseinfo.device = argv->device; mseinfo.type = -1; for (i = 1; i < sizeof(msetable)/sizeof(char *); i++) { if (!StrCaseCmp(msetable[i], argv->type)) { mseinfo.type = i - 1; } } /* some special cases... */ if (!StrCaseCmp("Xqueue", argv->type)) { mseinfo.type = MTYPE_XQUEUE; } else if (!StrCaseCmp("OSMouse", argv->type)) { mseinfo.type = MTYPE_OSMOUSE; } if (mseinfo.type == -1) { return (-1); } mseinfo.baudrate = argv->baudrate; mseinfo.samplerate = argv->samplerate; mseinfo.resolution = argv->resolution; if (argv->buttons != 0) { mseinfo.buttons = argv->buttons; } if (!StrCaseCmp(argv->emu3button, "on")) { mseinfo.emulate3buttons = 1; } else { mseinfo.emulate3buttons = 0; } mseinfo.emulate3timeout = argv->emu3timeout; if (!StrCaseCmp(argv->chordmiddle, "on")) { mseinfo.chordmiddle = 1; } else { mseinfo.chordmiddle = 0; } mseinfo.flags = 0; if (!StrCaseCmp(argv->flag, "cleardtr")) { mseinfo.flags |= MF_CLEAR_DTR; } else if (!StrCaseCmp(argv->flag, "clearrts")) { mseinfo.flags |= MF_CLEAR_RTS; } else if (!StrCaseCmp(argv->flag, "reopen")) { mseinfo.flags |= MF_REOPEN; } else { mseinfo.flags |= MF_REOPEN; } XSync (dpy, False); XF86MiscSetMouseSettings (dpy, &mseinfo); XSync (dpy, False); return (0); }
//=================================== // enableMouse... //----------------------------------- void enableMouse (Display* dpy) { XSetErrorHandler (catchErrors); XF86MiscMouseSettings mseinfo; if (!XF86MiscGetMouseSettings(dpy, &mseinfo)) { return; } mseinfo.flags |= MF_REOPEN; XF86MiscSetMouseSettings(dpy, &mseinfo); XSync(dpy, False); }
//======================================== // 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); }