void CommandInterpreter::handleCommand(TACommand command) { XTestGrabControl(display, True); printf("COMMAND: %i, %i, %i, %i, %f\n", command.type, command.touch, command.xDifference, command.yDifference, command.zoomValue); switch(command.type) { case TACommandTypeZoom: zoom(command); break; case TACommandTypePan: pan(command); break; case TACommandTypeRotate: rotate(command); break; default: break; } XSync(display, 0); XTestGrabControl(display, False); usleep(100); }
void xf_input_keyboard_event(rdpInput* input, uint16 flags, uint16 code) { #ifdef WITH_XTEST unsigned int keycode; boolean extended = false; xfPeerContext* xfp = (xfPeerContext*) input->context; xfInfo* xfi = xfp->info; if (flags & KBD_FLAGS_EXTENDED) extended = true; keycode = freerdp_keyboard_get_x11_keycode_from_rdp_scancode(code, extended); if (keycode != 0) { pthread_mutex_lock(&(xfp->mutex)); XTestGrabControl(xfi->display, True); if (flags & KBD_FLAGS_DOWN) XTestFakeKeyEvent(xfi->display, keycode, True, 0); else if (flags & KBD_FLAGS_RELEASE) XTestFakeKeyEvent(xfi->display, keycode, False, 0); XTestGrabControl(xfi->display, False); pthread_mutex_unlock(&(xfp->mutex)); } #endif }
/* Send Fake Key Event */ static void SendKey (Display * disp, KeySym keysym, KeySym modsym) { KeyCode keycode = 0, modcode = 0; keycode = XKeysymToKeycode (disp, keysym); if (keycode == 0) return; XTestGrabControl (disp, True); /* Generate modkey press */ if (modsym != 0) { modcode = XKeysymToKeycode(disp, modsym); XTestFakeKeyEvent (disp, modcode, True, 0); } /* Generate regular key press and release */ XTestFakeKeyEvent (disp, keycode, True, 0); XTestFakeKeyEvent (disp, keycode, False, 0); /* Generate modkey release */ if (modsym != 0) XTestFakeKeyEvent (disp, modcode, False, 0); XSync (disp, False); XTestGrabControl (disp, False); }
void xf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { #ifdef WITH_XTEST xfPeerContext* xfp = (xfPeerContext*) input->context; int button = 0; BOOL down = FALSE; xfInfo* xfi = xfp->info; XTestGrabControl(xfi->display, True); XTestFakeMotionEvent(xfi->display, 0, x, y, CurrentTime); if (flags & PTR_XFLAGS_BUTTON1) button = 8; else if (flags & PTR_XFLAGS_BUTTON2) button = 9; if (flags & PTR_XFLAGS_DOWN) down = TRUE; if (button != 0) XTestFakeButtonEvent(xfi->display, button, down, 0); XTestGrabControl(xfi->display, False); #endif }
void xf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) { #ifdef WITH_XTEST DWORD vkcode; DWORD keycode; BOOL extended = FALSE; xfPeerContext* xfp = (xfPeerContext*) input->context; xfInfo* xfi = xfp->info; if (flags & KBD_FLAGS_EXTENDED) extended = TRUE; if (extended) code |= KBDEXT; vkcode = GetVirtualKeyCodeFromVirtualScanCode(code, 4); keycode = GetKeycodeFromVirtualKeyCode(vkcode, KEYCODE_TYPE_EVDEV); if (keycode != 0) { XTestGrabControl(xfi->display, True); if (flags & KBD_FLAGS_DOWN) XTestFakeKeyEvent(xfi->display, keycode, True, 0); else if (flags & KBD_FLAGS_RELEASE) XTestFakeKeyEvent(xfi->display, keycode, False, 0); XTestGrabControl(xfi->display, False); } #endif }
void helper_release() { XTestGrabControl(dpy,True); XTestFakeButtonEvent(dpy,1,False,CurrentTime); XSync(dpy,False); XTestGrabControl(dpy,False); }
void x11_shadow_input_keyboard_event(x11ShadowSubsystem* subsystem, UINT16 flags, UINT16 code) { #ifdef WITH_XTEST DWORD vkcode; DWORD keycode; BOOL extended = FALSE; if (flags & KBD_FLAGS_EXTENDED) extended = TRUE; if (extended) code |= KBDEXT; vkcode = GetVirtualKeyCodeFromVirtualScanCode(code, 4); if (extended) vkcode |= KBDEXT; keycode = GetKeycodeFromVirtualKeyCode(vkcode, KEYCODE_TYPE_EVDEV); if (keycode != 0) { XTestGrabControl(subsystem->display, True); if (flags & KBD_FLAGS_DOWN) XTestFakeKeyEvent(subsystem->display, keycode, True, CurrentTime); else if (flags & KBD_FLAGS_RELEASE) XTestFakeKeyEvent(subsystem->display, keycode, False, CurrentTime); XTestGrabControl(subsystem->display, False); XFlush(subsystem->display); } #endif }
void x11_shadow_input_extended_mouse_event(x11ShadowSubsystem* subsystem, UINT16 flags, UINT16 x, UINT16 y) { #ifdef WITH_XTEST int button = 0; BOOL down = FALSE; rdpShadowServer* server; rdpShadowSurface* surface; server = subsystem->server; surface = server->surface; x += surface->x; y += surface->y; XTestGrabControl(subsystem->display, True); XTestFakeMotionEvent(subsystem->display, 0, x, y, CurrentTime); if (flags & PTR_XFLAGS_BUTTON1) button = 8; else if (flags & PTR_XFLAGS_BUTTON2) button = 9; if (flags & PTR_XFLAGS_DOWN) down = TRUE; if (button) XTestFakeButtonEvent(subsystem->display, button, down, CurrentTime); XTestGrabControl(subsystem->display, False); XFlush(subsystem->display); #endif }
void helper_mov_absxy(int x,int y) { XTestGrabControl(dpy,True); XTestFakeMotionEvent(dpy,-1,x,y,CurrentTime); XSync(dpy,False); XTestGrabControl(dpy,False); }
void helper_mov_relxy(int x,int y) { XTestGrabControl(dpy,True); XTestFakeRelativeMotionEvent(dpy,x,y,CurrentTime); XSync(dpy,False); XTestGrabControl(dpy,False); }
void x11_shadow_input_mouse_event(x11ShadowSubsystem* subsystem, UINT16 flags, UINT16 x, UINT16 y) { #ifdef WITH_XTEST int button = 0; BOOL down = FALSE; rdpShadowServer* server; rdpShadowSurface* surface; server = subsystem->server; surface = server->surface; x += surface->x; y += surface->y; if (server->shareSubRect) { x += server->subRect.left; y += server->subRect.top; } XTestGrabControl(subsystem->display, True); if (flags & PTR_FLAGS_WHEEL) { BOOL negative = FALSE; if (flags & PTR_FLAGS_WHEEL_NEGATIVE) negative = TRUE; button = (negative) ? 5 : 4; XTestFakeButtonEvent(subsystem->display, button, True, CurrentTime); XTestFakeButtonEvent(subsystem->display, button, False, CurrentTime); } else { if (flags & PTR_FLAGS_MOVE) XTestFakeMotionEvent(subsystem->display, 0, x, y, CurrentTime); if (flags & PTR_FLAGS_BUTTON1) button = 1; else if (flags & PTR_FLAGS_BUTTON2) button = 3; else if (flags & PTR_FLAGS_BUTTON3) button = 2; if (flags & PTR_FLAGS_DOWN) down = TRUE; if (button) XTestFakeButtonEvent(subsystem->display, button, down, CurrentTime); } XTestGrabControl(subsystem->display, False); XFlush(subsystem->display); #endif }
void xf_input_extended_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y) { #ifdef WITH_XTEST xfPeerContext* xfp = (xfPeerContext*) input->context; xfInfo* xfi = xfp->info; pthread_mutex_lock(&(xfp->mutex)); XTestGrabControl(xfi->display, True); XTestFakeMotionEvent(xfi->display, 0, x, y, CurrentTime); XTestGrabControl(xfi->display, False); pthread_mutex_unlock(&(xfp->mutex)); #endif }
void helper_init() { dpy=NULL; if(((int)(dpy=XOpenDisplay(NULL)))==NULL) printf("Error in opening display\n"); printf("Inside C\n"); XTestGrabControl(dpy,True); // XTestFakeButtonEvent(dpy,1,True,CurrentTime); XTestFakeMotionEvent(dpy,-1,0,0,CurrentTime); // XTestFakeButtonEvent(dpy,1,False,CurrentTime); XSync(dpy,False); XTestGrabControl(dpy,False); return; }
void keyboard(Display * disp, KeySym keysym, KeySym modsym){ KeyCode keycode = 0, modcode = 0; keycode = XKeysymToKeycode (disp, keysym); if (keycode == 0) return; XTestGrabControl (disp, True); if (modsym != 0) { modcode = XKeysymToKeycode(disp, modsym); XTestFakeKeyEvent (disp, modcode, True, 0); } XTestFakeKeyEvent (disp, keycode, True, 0); XTestFakeKeyEvent (disp, keycode, False, 0); if (modsym != 0) XTestFakeKeyEvent (disp, modcode, False, 0); XSync (disp, False); XTestGrabControl (disp, False); }
static int32_t isXTestAvailable() { int32_t major_opcode, first_event, first_error; int32_t event_basep, error_basep, majorp, minorp; int32_t isXTestAvailable; /* check if XTest is available */ isXTestAvailable = XQueryExtension(awt_display, XTestExtensionName, &major_opcode, &first_event, &first_error); DTRACE_PRINTLN3("RobotPeer: XQueryExtension(XTEST) returns major_opcode = %d, first_event = %d, first_error = %d", major_opcode, first_event, first_error); if (isXTestAvailable) { /* check if XTest version is OK */ XTestQueryExtension(awt_display, &event_basep, &error_basep, &majorp, &minorp); DTRACE_PRINTLN4("RobotPeer: XTestQueryExtension returns event_basep = %d, error_basep = %d, majorp = %d, minorp = %d", event_basep, error_basep, majorp, minorp); if (majorp < 2 || (majorp == 2 && minorp < 2)) { /* bad version*/ DTRACE_PRINTLN2("XRobotPeer: XTEST version is %d.%d \n", majorp, minorp); if (majorp == 2 && minorp == 1) { DTRACE_PRINTLN("XRobotPeer: XTEST is 2.1 - no grab is available\n"); } else { isXTestAvailable = False; } } else { /* allow XTest calls even if someone else has the grab; e.g. during * a window resize operation. Works only with XTEST2.2*/ XTestGrabControl(awt_display, True); } } else { DTRACE_PRINTLN("RobotPeer: XTEST extension is unavailable"); } return isXTestAvailable; }
void xf_input_mouse_event(rdpInput* input, uint16 flags, uint16 x, uint16 y) { #ifdef WITH_XTEST xfPeerContext* xfp = (xfPeerContext*) input->context; int button = 0; boolean down = false; xfInfo* xfi = xfp->info; pthread_mutex_lock(&(xfp->mutex)); XTestGrabControl(xfi->display, True); if (flags & PTR_FLAGS_WHEEL) { boolean negative = false; if (flags & PTR_FLAGS_WHEEL_NEGATIVE) negative = true; button = (negative) ? 5 : 4; XTestFakeButtonEvent(xfi->display, button, True, 0); XTestFakeButtonEvent(xfi->display, button, False, 0); } else { if (flags & PTR_FLAGS_MOVE) XTestFakeMotionEvent(xfi->display, 0, x, y, 0); if (flags & PTR_FLAGS_BUTTON1) button = 1; else if (flags & PTR_FLAGS_BUTTON2) button = 3; else if (flags & PTR_FLAGS_BUTTON3) button = 2; if (flags & PTR_FLAGS_DOWN) down = true; if (button != 0) XTestFakeButtonEvent(xfi->display, button, down, 0); } XTestGrabControl(xfi->display, False); pthread_mutex_unlock(&(xfp->mutex)); #endif }
void xf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { #ifdef WITH_XTEST xfPeerContext* xfp = (xfPeerContext*) input->context; int button = 0; BOOL down = FALSE; xfInfo* xfi = xfp->info; XTestGrabControl(xfi->display, True); if (flags & PTR_FLAGS_WHEEL) { BOOL negative = FALSE; if (flags & PTR_FLAGS_WHEEL_NEGATIVE) negative = TRUE; button = (negative) ? 5 : 4; XTestFakeButtonEvent(xfi->display, button, True, 0); XTestFakeButtonEvent(xfi->display, button, False, 0); } else { if (flags & PTR_FLAGS_MOVE) XTestFakeMotionEvent(xfi->display, 0, x, y, 0); if (flags & PTR_FLAGS_BUTTON1) button = 1; else if (flags & PTR_FLAGS_BUTTON2) button = 3; else if (flags & PTR_FLAGS_BUTTON3) button = 2; if (flags & PTR_FLAGS_DOWN) down = TRUE; if (button != 0) XTestFakeButtonEvent(xfi->display, button, down, 0); } XTestGrabControl(xfi->display, False); #endif }
int main (int argc, char *argv[]) { Display *display; int eventbase, errorbase, majorver, minorver; int x, y; struct timespec delay = { 0, 500000 }; if (argc != 3) { fprintf (stderr, "Usage: grabcontrol <x> <y>\n"); exit (1); } x = atoi (argv[1]); y = atoi (argv[2]); if ((display = XOpenDisplay(XDisplayName(NULL))) == NULL) { fprintf (stderr, "Can't connect to X display\n"); exit(1); } if (!XTestQueryExtension(display, &eventbase, &errorbase, &majorver, &minorver)) { fprintf (stderr, "Can't find XTest support\n"); exit(1); } XTestGrabControl(display, True); XTestFakeMotionEvent (display, DefaultScreen (display), x, y, CurrentTime); XTestFakeButtonEvent(display, 1, True, CurrentTime); nanosleep (&delay, NULL); XTestFakeButtonEvent(display, 1, False, CurrentTime); XTestGrabControl(display, False); XFlush (display); return 0; }
/* SaveFile: This function sends key commands to the FireFox save file dialog. Input: dsp: The current XWindows Display. win: The window to send the key commands to. Output: returns 0 on success and -1 on failure. */ int SaveFile(Display *dsp, Window win) { int err = 0; Window parent; Window root; Window *kids; int count; KeyCode keycode_return = XKeysymToKeycode(dsp, XK_Return); KeyCode keycode_tab = XKeysymToKeycode(dsp, XK_Tab); XRaiseWindow(dsp, win); XFlush(dsp); XSetInputFocus(dsp, win, RevertToNone, CurrentTime); XFlush(dsp); XTestGrabControl(dsp, True); printf("Sending Tab key\n"); XTestFakeKeyEvent(dsp, keycode_tab, True, 0); XFlush(dsp); XTestFakeKeyEvent(dsp, keycode_tab, False, 0); XFlush(dsp); sleep(1); printf("Finished.\n"); printf("Sending Tab key\n"); XTestFakeKeyEvent(dsp, keycode_tab, True, 0); XTestFakeKeyEvent(dsp, keycode_tab, False, 0); XFlush(dsp); sleep(1); printf("Finished.\n"); printf("Sending Tab key\n"); XTestFakeKeyEvent(dsp, keycode_tab, True, 0); XTestFakeKeyEvent(dsp, keycode_tab, False, 0); XFlush(dsp); sleep(1); printf("Finished.\n"); printf("Sending Tab key\n"); XTestFakeKeyEvent(dsp, keycode_tab, True, 0); XTestFakeKeyEvent(dsp, keycode_tab, False, 0); XFlush(dsp); sleep(1); printf("Finished.\n"); printf("Sending Tab Return\n"); XTestFakeKeyEvent(dsp, keycode_return, True, 0); XTestFakeKeyEvent(dsp, keycode_return, False, 0); XFlush(dsp); printf("Finished\n"); return err; }
/* on_key_clicked */ static void _on_key_clicked(GtkWidget * widget, gpointer data) { KeyboardLayout * layout = data; KeyboardKey * key; Display * display; KeySym keysym; KeyCode keycode; gboolean active; key = g_object_get_data(G_OBJECT(widget), "key"); keysym = keyboard_key_get_keysym(key); display = gdk_x11_get_default_xdisplay(); if((keycode = XKeysymToKeycode(display, keysym)) == NoSymbol) return; XTestGrabControl(display, True); if(keysym_is_modifier(keysym) != 0) { active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( widget)); if(keysym != XK_Num_Lock) /* XXX ugly workaround */ XTestFakeKeyEvent(display, keycode, active ? True : False, 0); else { XTestFakeKeyEvent(display, keycode, True, 0); XTestFakeKeyEvent(display, keycode, False, 0); } keyboard_layout_apply_modifier(layout, active ? keysym : 0); } else { XTestFakeKeyEvent(display, keycode, True, 0); XTestFakeKeyEvent(display, keycode, False, 0); } XTestGrabControl(display, False); }
Display * remoteDisplay (const char * DisplayName) { int Event, Error; int Major, Minor; // open the display Display * D = XOpenDisplay ( DisplayName ); // did we get it? if ( ! D ) { // nope, so show error and abort std::cerr << PROG << ": could not open display \"" << XDisplayName ( DisplayName ) << "\", aborting." << std::endl; exit ( EXIT_FAILURE ); } // does the remote display have the Xtest-extension? if ( ! XTestQueryExtension (D, &Event, &Error, &Major, &Minor ) ) { // nope, extension not supported std::cerr << PROG << ": XTest extension not supported on server \"" << DisplayString(D) << "\"" << std::endl; // close the display and go away XCloseDisplay ( D ); exit ( EXIT_FAILURE ); } // print some information std::cerr << "XTest for server \"" << DisplayString(D) << "\" is version " << Major << "." << Minor << "." << std::endl << std::endl;; // execute requests even if server is grabbed XTestGrabControl ( D, True ); // sync the server XSync ( D,True ); // return the display return D; }
void connect() { int eventnum = 0, errornum = 0, majornum = 0, minornum = 0; /* Get Display Pointer */ display = XOpenDisplay(NULL); if (display == NULL) { printf("FAIL to connect X Windows!\n"); exit(1); } if (!XTestQueryExtension(display, &eventnum, &errornum, &majornum, &minornum)) { printf("XTest is not supported on server %s!\n", "null"); } printf("connected %d.%d!\n",majornum,minornum); DefaultScreen(display); XSynchronize(display, True); XTestGrabControl(display, True); }
/* Main function, contains kernel driver event loop */ int main(int argc, char **argv) { char* devname = 0; int doDaemonize = 1; int doWait = 0; int clickMode = 2; int i; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "--debug") == 0) { doDaemonize = 0; debugMode = 1; } else if (strcmp(argv[i], "--wait") == 0) { doWait = 1; } else if (strcmp(argv[i], "--click=first") == 0) { clickMode = 0; } else if (strcmp(argv[i], "--click=second") == 0) { clickMode = 1; } else if (strcmp(argv[i], "--click=center") == 0) { clickMode = 2; } else { devname = argv[i]; } } initGestures(clickMode); if (doDaemonize) { daemonize(); } if (doWait) { /* Wait until all necessary things are loaded */ sleep(10); } /* Connect to X server */ if ((display = XOpenDisplay(NULL)) == NULL) { fprintf(stderr, "Couldn't connect to X server\n"); exit(1); } /* Read X data */ screenNum = DefaultScreen(display); root = RootWindow(display, screenNum); // realDisplayWidth = DisplayWidth(display, screenNum); // realDisplayHeight = DisplayHeight(display, screenNum); WM_CLASS = XInternAtom(display, "WM_CLASS", 0); /* Get notified about new windows */ XSelectInput(display, root, StructureNotifyMask | SubstructureNotifyMask); //TODO load blacklist and profiles from file(s) /* Device file name */ if (devname == 0) { devname = "/dev/twofingtouch"; } /* Try to read from device file */ int fileDesc; if ((fileDesc = open(devname, O_RDONLY)) < 0) { perror("twofing"); return 1; } fd_set fileDescSet; FD_ZERO(&fileDescSet); int eventQueueDesc = XConnectionNumber(display); while (1) { /* Perform initialization at beginning and after module has been re-loaded */ int rd, i; struct input_event ev[64]; char name[256] = "Unknown"; /* Read device name */ ioctl(fileDesc, EVIOCGNAME(sizeof(name)), name); printf("Input device name: \"%s\"\n", name); //TODO activate again? //XSetErrorHandler(invalidWindowHandler); int opcode, event, error; if (!XQueryExtension(display, "RANDR", &opcode, &event, &error)) { printf("X RANDR extension not available.\n"); XCloseDisplay(display); exit(1); } /* Which version of XRandR? We support 1.3 */ int major = 1, minor = 3; if (!XRRQueryVersion(display, &major, &minor)) { printf("XRandR version not available.\n"); XCloseDisplay(display); exit(1); } else if(!(major>1 || (major == 1 && minor >= 3))) { printf("XRandR 1.3 not available. Server supports %d.%d\n", major, minor); XCloseDisplay(display); exit(1); } /* XInput Extension available? */ if (!XQueryExtension(display, "XInputExtension", &opcode, &event, &error)) { printf("X Input extension not available.\n"); XCloseDisplay(display); exit(1); } /* Which version of XI2? We support 2.1 */ major = 2; minor = 1; if (XIQueryVersion(display, &major, &minor) == BadRequest) { printf("XI 2.1 not available. Server supports %d.%d\n", major, minor); XCloseDisplay(display); exit(1); } screenWidth = XDisplayWidth(display, screenNum); screenHeight = XDisplayHeight(display, screenNum); int n; XIDeviceInfo *info = XIQueryDevice(display, XIAllDevices, &n); if (!info) { printf("No XInput devices available\n"); exit(1); } /* Go through input devices and look for that with the same name as the given device */ int devindex; for (devindex = 0; devindex < n; devindex++) { if (info[devindex].use == XIMasterPointer || info[devindex].use == XIMasterKeyboard) continue; if (strcmp(info[devindex].name, name) == 0) { deviceID = info[devindex].deviceid; break; } } if (deviceID == -1) { printf("Input device not found in XInput device list.\n"); exit(1); } XIFreeDeviceInfo(info); if(debugMode) printf("XInput device id is %i.\n", deviceID); /* Prepare by reading calibration */ readCalibrationData(1); /* Receive device property change events */ XIEventMask device_mask2; unsigned char mask_data2[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; device_mask2.deviceid = deviceID; device_mask2.mask_len = sizeof(mask_data2); device_mask2.mask = mask_data2; XISetMask(device_mask2.mask, XI_PropertyEvent); XISetMask(device_mask2.mask, XI_ButtonPress); //XISetMask(device_mask2.mask, XI_TouchBegin); //XISetMask(device_mask2.mask, XI_TouchUpdate); //XISetMask(device_mask2.mask, XI_TouchEnd); XISelectEvents(display, root, &device_mask2, 1); /* Recieve events when screen size changes */ XRRSelectInput(display, root, RRScreenChangeNotifyMask); /* Receive touch events */ /* Needed for XTest to work correctly */ XTestGrabControl(display, True); /* Needed for some reason to receive events */ /* XGrabPointer(display, root, False, 0, GrabModeAsync, GrabModeAsync, None, None, CurrentTime); XUngrabPointer(display, CurrentTime);*/ grab(display, deviceID); printf("Reading input from device ... (interrupt to exit)\n"); /* We perform raw event reading here as X touch events don't seem too reliable */ int currentSlot = 0; /* If we use the legacy protocol, we collect all data of one finger into tempFingerInfo and set it to the correct slot once MT_SYNC occurs. */ FingerInfo tempFingerInfo = { .rawX=0, .rawY=0, .rawZ=0, .id = -1, .slotUsed = 0, .setThisTime = 0 }; while (1) { FD_SET(fileDesc, &fileDescSet); FD_SET(eventQueueDesc, &fileDescSet); select(MAX(fileDesc, eventQueueDesc) + 1, &fileDescSet, NULL, NULL, getEasingStepTimeVal()); checkEasingStep(); if(FD_ISSET(fileDesc, &fileDescSet)) { rd = read(fileDesc, ev, sizeof(struct input_event) * 64); if (rd < (int) sizeof(struct input_event)) { printf("Data stream stopped\n"); break; } for (i = 0; i < rd / sizeof(struct input_event); i++) { if (ev[i].type == EV_SYN) { if (0 == ev[i].code) { // Ev_Sync event end /* All finger data received, so process now. */ if(useLegacyProtocol) { /* Clear slots not set this time */ int i; for(i = 0; i < 2; i++) { if(fingerInfos[i].setThisTime) { fingerInfos[i].setThisTime = 0; } else { /* Clear slot */ fingerInfos[i].slotUsed = 0; } } tempFingerInfo.slotUsed = 0; } processFingers(); } else if (2 == ev[i].code) { // MT_Sync : Multitouch event end if(!useLegacyProtocol) { /* This messsage indicates we use legacy protocol, so switch */ useLegacyProtocol = 1; currentSlot = -1; tempFingerInfo.slotUsed = 0; if(debugMode) printf("Switch to legacy protocol.\n"); } else { if(tempFingerInfo.slotUsed) { /* Finger info for one finger collected in tempFingerInfo, so save it to fingerInfos. */ /* Look for slot to put the data into by looking at the tracking ids */ int index = -1; int i; for(i = 0; i < 2; i++) { if(fingerInfos[i].slotUsed && fingerInfos[i].id == tempFingerInfo.id) { index = i; break; } } if(index == -1) { for(i = 0; i < 2; i++) { if(!fingerInfos[i].slotUsed) { /* "Empty" slot, so we can add it. */ index = i; fingerInfos[i].id = tempFingerInfo.id; fingerInfos[i].slotUsed = 1; break; } } } if(index != -1) { /* Copy temporary data to slot */ fingerInfos[index].setThisTime = 1; fingerInfos[index].rawX = tempFingerInfo.rawX; fingerInfos[index].rawY = tempFingerInfo.rawY; fingerInfos[index].rawZ = tempFingerInfo.rawZ; } } } } } else if (ev[i].type == EV_MSC && (ev[i].code == MSC_RAW || ev[i].code == MSC_SCAN)) { } else if (ev[i].code == 47) { currentSlot = ev[i].value; if(currentSlot < 0 || currentSlot > 1) currentSlot = -1; } else { /* Set finger info values for current finger */ if (ev[i].code == 57) { /* ABS_MT_TRACKING_ID */ if(currentSlot != -1) { if(ev[i].value == -1) { fingerInfos[currentSlot].slotUsed = 0; } else { fingerInfos[currentSlot].id = ev[i].value; fingerInfos[currentSlot].slotUsed = 1; } } else if(useLegacyProtocol) { tempFingerInfo.id = ev[i].value; tempFingerInfo.slotUsed = 1; } }; if (ev[i].code == 53) { if(currentSlot != -1) { fingerInfos[currentSlot].rawX = ev[i].value; } else if(useLegacyProtocol) { tempFingerInfo.rawX = ev[i].value; } }; if (ev[i].code == 54) { if(currentSlot != -1) { fingerInfos[currentSlot].rawY = ev[i].value; } else if(useLegacyProtocol) { tempFingerInfo.rawY = ev[i].value; } }; if (ev[i].code == 58) { if(currentSlot != -1) { fingerInfos[currentSlot].rawZ = ev[i].value; } else if(useLegacyProtocol) { tempFingerInfo.rawZ = ev[i].value; } }; } } } if(FD_ISSET(eventQueueDesc, &fileDescSet)) { handleXEvent(); } } /* Stream stopped, probably because module has been unloaded */ close(fileDesc); /* Clean up */ releaseButton(); ungrab(display, deviceID); /* Wait until device file is there again */ while ((fileDesc = open(devname, O_RDONLY)) < 0) { sleep(1); } } }
static void spi_controller_register_with_devices (SpiDEController *controller) { DEControllerPrivateData *priv; int event_base, error_base, major_version, minor_version; priv = controller->priv; if (XTestQueryExtension (spi_get_display(), &event_base, &error_base, &major_version, &minor_version)) { XTestGrabControl (spi_get_display (), True); } /* calls to device-specific implementations and routines go here */ /* register with: keyboard hardware code handler */ /* register with: (translated) keystroke handler */ priv->have_xkb = XkbQueryExtension (spi_get_display (), &priv->xkb_major_extension_opcode, &priv->xkb_base_event_code, &priv->xkb_base_error_code, NULL, NULL); if (priv->have_xkb) { gint i; guint64 reserved = 0; priv->xkb_desc = XkbGetMap (spi_get_display (), XkbKeySymsMask, XkbUseCoreKbd); XkbSelectEvents (spi_get_display (), XkbUseCoreKbd, XkbStateNotifyMask, XkbStateNotifyMask); _numlock_physical_mask = XkbKeysymToModifiers (spi_get_display (), XK_Num_Lock); for (i = priv->xkb_desc->max_key_code; i >= priv->xkb_desc->min_key_code; --i) { if (priv->xkb_desc->map->key_sym_map[i].kt_index[0] == XkbOneLevelIndex) { if (XkbKeycodeToKeysym (spi_get_display (), i, 0, 0) != 0) { /* don't use this one if there's a grab client! */ /* Runtime errors are generated from these functions, * that are then quashed. Equivalent to: * try * {Blah} * except * {;} */ spi_x_error_trap (); XGrabKey (spi_get_display (), i, 0, spi_get_root_window (), TRUE, GrabModeSync, GrabModeSync); XSync (spi_get_display (), TRUE); XUngrabKey (spi_get_display (), i, 0, spi_get_root_window ()); if (!spi_x_error_release ()) { reserved = i; break; } } } } if (reserved) { priv->reserved_keycode = reserved; priv->reserved_keysym = XkbKeycodeToKeysym (spi_get_display (), reserved, 0, 0); } else { priv->reserved_keycode = XKeysymToKeycode (spi_get_display (), XK_numbersign); priv->reserved_keysym = XK_numbersign; } #ifdef SPI_RESERVED_DEBUG unsigned sym = 0; sym = XKeycodeToKeysym (spi_get_display (), reserved, 0); fprintf (stderr, "%x\n", sym); fprintf (stderr, "setting the reserved keycode to %d (%s)\n", reserved, XKeysymToString (XKeycodeToKeysym (spi_get_display (), reserved, 0))); #endif } spi_set_filter (global_filter_fn, controller); spi_set_events (KeyPressMask | KeyReleaseMask); x_default_error_handler = XSetErrorHandler (_spi_controller_device_error_handler); }
int main(int argc, char *argv[]) { char input_path[32]; get_input(input_path); int file; if ((file = open(input_path, O_RDONLY)) < 0) { perror("Couldn't open input device"); return 1; } struct input_event event[64]; size_t read_bytes; int i; display = XOpenDisplay (NULL); while(1) { read_bytes = read(file, event, sizeof(event)); if (read_bytes < (int) sizeof(struct input_event)) { perror("short read"); return 1; } for (i = 0; i < (int) (read_bytes / sizeof(struct input_event)); i++) { if(event[i].type != EV_KEY) continue; switch(event[i].value) { case 0: keys_up(); XTestGrabControl (display, True); printf("%d down\n", event[i].code); break; case 1: XSync (display, False); XTestGrabControl (display, False); switch(event[i].code) { case KEY_NEXTSONG: printf("forwards\n"); keys_down(XK_F, XK_W); break; case KEY_PREVIOUSSONG: printf("backwards\n"); break; default: perror("unknown key"); return 1; } break; case 2: printf("%d held\n", event[i].code); break; default: perror("Unknown event value"); } } } return 0; }
~AutotypeMethodXTEST() { XTestGrabControl(m_display, false); }
AutotypeMethodXTEST(Display *display, bool emulateMods): AutotypeMethodBase(display, emulateMods){ XTestGrabControl(display, true); }