void MouseDevice::reset() { for(int i = 0; i < ButtonCount; ++i) { if(mPressedButtons[i]) releaseButton(static_cast<Button>(i)); } }
EventClient::EventClient(QObject *parent) : QObject(parent), m_socket(-1), m_cleared(0) { m_releaseTimer.setSingleShot(false); m_releaseTimer.setInterval(200); connect(&m_releaseTimer, SIGNAL(timeout()), SLOT(releaseButton())); }
void Joystick_::setButton(uint8_t button, uint8_t value) { if (value == 0) { releaseButton(button); } else { pressButton(button); } }
void touch (int fd, const unsigned char *data, int size){ switch (data[0]){ case 13: pressButton(fd, data); break; case 5: releaseButton(fd, data); break; default: /*printf("size: %2d\n",size); for (int i=0; i<size; i++){ printf("%02hhx ",data[i]); } printf("\n");*/ break; } /*for (int j=0; j<size; j++){ printf("%02hhx ", data[j]); } printf("\n");*/ }
/* 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); } } }
void matchCode() { Serial.println("matchCode"); Serial.print("freeRam:"); Serial.println(freeRam()); int status[MAX_SIGNAL]; for (int i = 0; i < MAX_SIGNAL; i++) status[i] = 0; for (uint8_t i = 0; i < currentpulse; i++) { int received_on = applyResolution(pulses[i][1]); int received_off; if (i < currentpulse - 1) received_off = applyResolution(pulses[i+1][0]); else received_off = 0; for (int j = 0; j < MAX_SIGNAL; j++) { int pos = status[j]; int recorded_on = IRsignals[j][pos*2]; int recorded_off = IRsignals[j][pos*2+1]; //tracef("comparing aon:%d bon:%d aoff:%d boff:%d\r\n", received_on, recorded_on, received_off, recorded_off); if (received_on == recorded_on && received_off == recorded_off) { if (recorded_off == 0) { tracef("MATCH: %s\r\n", names[j]); if (j != TEMP_UP && j != TEMP_DOWN) { goToAndPressButton(j); delay(300); releaseButton(); holdStartTime = -1; } else { if (holdStartTime == -1) { goToAndPressButton(j); holdStartTime = millis(); } else { releaseButton(); holdStartTime = -1; } } return; } status[j]++; //tracef("i:%d j:%d status:%d\r\n", i, j, status[j]); } else { status[j] = 0; } } } Serial.println("no match"); }
void DispatchEvent (ASEvent * event) { ASVolume *event_volume = NULL; SHOW_EVENT_TRACE(event); if( (event->eclass & ASE_POINTER_EVENTS) != 0 ) { XKeyEvent *xk = &(event->x.xkey); int pointer_root_x = xk->x_root; int pointer_root_y = xk->y_root; event_volume = position2Volume (pointer_root_x,// - (int)AppState.mainCanvas->bw, pointer_root_y);// - (int)AppState.mainCanvas->bw); LOCAL_DEBUG_OUT ("event_volume = %p, name = \"%s\"", event_volume, event_volume ? event_volume->name : "(none)"); if(is_balloon_click( &(event->x) ) ) { withdraw_balloon(NULL); return; } if (event_volume) event->context = check_astbar_point( event_volume->contents, pointer_root_x, pointer_root_y ); } event->client = NULL ; switch (event->x.type) { case ConfigureNotify: { ASFlagType changes = handle_canvas_config (AppState.mainCanvas); if( changes != 0 ) { volumeWindowMoved_AuxData aux; aux.backgroundChanged = False; set_root_clip_area( AppState.mainCanvas ); iterate_asbidirlist (AppState.volumes, volumeWindowMoved, &aux, NULL, False); } show_activity ("changes = 0x%lx", changes); } break; case KeyPress : return ; case KeyRelease : return ; case ButtonPress: pressButton (event_volume, event); return; case ButtonRelease: LOCAL_DEBUG_OUT( "state(0x%X)->state&ButtonAnyMask(0x%X)", event->x.xbutton.state, event->x.xbutton.state&ButtonAnyMask ); if( (event->x.xbutton.state&ButtonAnyMask) == (Button1Mask<<(event->x.xbutton.button-Button1)) ) releaseButton(); return ; case EnterNotify : if( event->x.xcrossing.window == Scr.Root ) withdraw_active_balloon(); return ; case LeaveNotify : case MotionNotify : { static Bool root_pointer_moved = True ; if( event->x.type == MotionNotify ) root_pointer_moved = True ; if (event_volume) { on_astbar_pointer_action (event_volume->contents, event->context, (event->x.type == LeaveNotify), root_pointer_moved); root_pointer_moved = False ; } return ; } case ClientMessage: LOCAL_DEBUG_OUT("ClientMessage(\"%s\",format = %d, data=(%8.8lX,%8.8lX,%8.8lX,%8.8lX,%8.8lX)", XGetAtomName( dpy, event->x.xclient.message_type ), event->x.xclient.format, event->x.xclient.data.l[0], event->x.xclient.data.l[1], event->x.xclient.data.l[2], event->x.xclient.data.l[3], event->x.xclient.data.l[4]); if ( event->x.xclient.format == 32 && event->x.xclient.data.l[0] == _XA_WM_DELETE_WINDOW ) { DeadPipe(0); } return ; case PropertyNotify: if( event->x.xproperty.atom == _XA_NET_WM_STATE ) { LOCAL_DEBUG_OUT( "_XA_NET_WM_STATE updated!%s",""); return; } handle_wmprop_event (Scr.wmprops, &(event->x)); if( event->x.xproperty.atom == _AS_BACKGROUND ) { volumeWindowMoved_AuxData aux; aux.backgroundChanged = True; LOCAL_DEBUG_OUT( "root background updated!%s",""); safe_asimage_destroy( Scr.RootImage ); Scr.RootImage = NULL ; iterate_asbidirlist (AppState.volumes, volumeWindowMoved, &aux, NULL, False); }else if( event->x.xproperty.atom == _AS_STYLE ) { volumeWindowMoved_AuxData aux; aux.backgroundChanged = False; LOCAL_DEBUG_OUT( "AS Styles updated!%s",""); mystyle_list_destroy_all(&(Scr.Look.styles_list)); LoadColorScheme(); SetASMountLook(); /* now we need to update everything */ redecorateVolumes (); iterate_asbidirlist (AppState.volumes, volumeWindowMoved, &aux, NULL, False); } return ; default: #ifdef XSHMIMAGE LOCAL_DEBUG_OUT( "XSHMIMAGE> EVENT : completion_type = %d, event->type = %d ", Scr.ShmCompletionEventType, event->x.type ); if( event->x.type == Scr.ShmCompletionEventType ) handle_ShmCompletion( event ); #endif /* SHAPE */ return; } /*update_pager_shape();*/ }
bool MouseDevice::buttonClick(Button button) { return (pressButton(button) && releaseButton(button)); }