int pumpKeyHook(void) { if (!datadpy) return 0; sawKeyCombo = 0; XRecordProcessReplies(datadpy); return sawKeyCombo; } // pumpKeyHook
int main() { XRecordContext xrd; XRecordRange *range; XRecordClientSpec client; osd = configure_osd(NKEYS); keystack = create_keystack(NKEYS); d0 = XOpenDisplay(NULL); d1 = XOpenDisplay(NULL); XSynchronize(d0, True); if (d0 == NULL || d1 == NULL) { fprintf(stderr, "Cannot connect to X server"); exit (-1); } client=XRecordAllClients; range=XRecordAllocRange(); memset(range, 0, sizeof(XRecordRange)); range->device_events.first=KeyPress; range->device_events.last=KeyRelease; xrd = XRecordCreateContext(d0, 0, &client, 1, &range, 1); if (! xrd) { fprintf(stderr, "Error in creating context"); exit (-1); } XRecordEnableContext(d1, xrd, update_key_ring, (XPointer)osd); XRecordProcessReplies (d1); XRecordDisableContext (d0, xrd); XRecordFreeContext (d0, xrd); XCloseDisplay(d0); XCloseDisplay(d1); exit(0); }
void record_main_loop(Display * display, double idle_time) { struct xrecord_callback_results cbres; XRecordContext context; XRecordClientSpec cspec = XRecordAllClients; Display *dpy_data; XRecordRange *range; int i; dpy_data = XOpenDisplay(NULL); /* we need an additional data connection. */ range = XRecordAllocRange(); range->device_events.first = KeyPress; range->device_events.last = KeyRelease; context = XRecordCreateContext(dpy_data, 0, &cspec, 1, &range, 1); XRecordEnableContextAsync(dpy_data, context, xrecord_callback, (XPointer) & cbres); cbres.modifiers = XGetModifierMapping(display); /* clear list of modifiers */ for (i = 0; i < MAX_MODIFIERS; ++i) cbres.pressed_modifiers[i] = 0; while (1) { int fd = ConnectionNumber(dpy_data); fd_set read_fds; int ret; int disable_event = 0; int modifier_event = 0; struct timeval timeout; FD_ZERO(&read_fds); FD_SET(fd, &read_fds); ret = select(fd + 1 /* =(max descriptor in read_fds) + 1 */ , &read_fds, NULL, NULL, pad_disabled ? &timeout : NULL /* timeout only required for enabling */ ); if (FD_ISSET(fd, &read_fds)) { cbres.key_event = 0; cbres.non_modifier_event = 0; XRecordProcessReplies(dpy_data); /* If there are any events left over, they are in error. Drain them * from the connection queue so we don't get stuck. */ while (XEventsQueued(dpy_data, QueuedAlready) > 0) { XEvent event; XNextEvent(dpy_data, &event); fprintf(stderr, "bad event received, major opcode %d\n", event.type); } if (!ignore_modifier_keys && cbres.key_event) { disable_event = 1; } if (cbres.non_modifier_event) { if (ignore_modifier_combos && is_modifier_pressed(&cbres)) { modifier_event = 1; } else { disable_event = 1; } } else if (ignore_modifier_keys) { modifier_event = 1; } } if (disable_event) { /* adjust the enable_time */ timeout.tv_sec = (int) idle_time; timeout.tv_usec = (idle_time - (double) timeout.tv_sec) * 1.e6; toggle_touchpad(False); } if (modifier_event && pad_disabled) { toggle_touchpad(True); } if (ret == 0 && pad_disabled) { /* timeout => enable event */ toggle_touchpad(True); } } /* end while(1) */ XFreeModifiermap(cbres.modifiers); }
int main (int argc, char **argv) { ctrl_disp = XOpenDisplay (NULL); data_disp = XOpenDisplay (NULL); if (!ctrl_disp || !data_disp) { fprintf (stderr, "Error to open local display!\n"); exit (1); } /* * we must set the ctrl_disp to sync mode, or, when we the enalbe * context in data_disp, there will be a fatal X error !!! */ XSynchronize(ctrl_disp,True); int major, minor; if (!XRecordQueryVersion (ctrl_disp, &major, &minor)) { fprintf (stderr, "RECORD extension not supported on this X server!\n"); exit (2); } printf ("RECORD extension for local server is version is %d.%d\n", major, minor); XRecordRange *rr; XRecordClientSpec rcs; XRecordContext rc; rr = XRecordAllocRange (); if (!rr) { fprintf (stderr, "Could not alloc record range object!\n"); exit (3); } rr->device_events.first = KeyPress; rr->device_events.last = MotionNotify; rcs = XRecordAllClients; rc = XRecordCreateContext (ctrl_disp, 0, &rcs, 1, &rr, 1); if (!rc) { fprintf (stderr, "Could not create a record context!\n"); exit (4); } if (!XRecordEnableContext (data_disp, rc, event_callback, NULL)) { fprintf (stderr, "Cound not enable the record context!\n"); exit (5); } while (stop != 1) { XRecordProcessReplies (data_disp); } XRecordDisableContext (ctrl_disp, rc); XRecordFreeContext (ctrl_disp, rc); XFree (rr); XCloseDisplay (data_disp); XCloseDisplay (ctrl_disp); return 0; }