Пример #1
0
void key_pressed_cb(XPointer arg, XRecordInterceptData *d) {
  if (stop_thread) {
    if (!XRecordDisableContext(dpy, rc)) {
      fprintf(stderr, "XRecordDisableContext error\n");
      exit(1);
    }
    if (!XRecordFreeContext(dpy, rc)) {
      fprintf(stderr, "XRecordFreeContext error\n");
      exit(1);
    }
    pthread_exit(0);
  }

  if (d->category != XRecordFromServer) return;
  unsigned char type = ((unsigned char*)d->data)[0] & 0x7F;
  unsigned char detail = ((unsigned char*)d->data)[1];
  if (type == KeyPress) {
    switch (detail) {
      case 36:
        uri = 1;
        break;
      case 65:
        uri = 2;
        break;
      case 22:
        uri = 3;
        break;
      default:
        uri = 0;
    }
    g_signal_emit_by_name(arg, "activate");
  }
}
Пример #2
0
 void stop(){
   printf("DEBUG: Stop Recording ...\n");
   if(!XRecordDisableContext(disp, xrctx)){ // FAIL
     printf("DEBUG: Stop Recording FAIL\n");
   }
   XRecordFreeContext(disp, xrctx);
   XCloseDisplay(disp);
   // XCloseDisplay(udisp);  // will cause fatal
 }
Пример #3
0
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);
}
Пример #4
0
void deinitKeyHook(void)
{
    if (ctrldpy)
    {
        if (xrc)
        {
            XRecordDisableContext(ctrldpy, xrc);
            XRecordFreeContext(ctrldpy, xrc);
        } // if
        XCloseDisplay(ctrldpy);
    } // if

    if (datadpy)
        XCloseDisplay(datadpy);

    ctrldpy = NULL;
    datadpy = NULL;
    xrc = 0;
    sawKeyCombo = 0;
    keyPressFlags = 0;
} // deinitKeyHook
Пример #5
0
void
grab_xrecord_finalize ()
{
    if (key_table) {
        g_hash_table_remove_all (key_table);
        key_table = NULL;
    }

    if (!grab_info) {
        return;
    }

    if (grab_info->context) {
        XRecordDisableContext(grab_info->data_disp, grab_info->context);
        XRecordFreeContext(grab_info->data_disp, grab_info->context);
    }

    if (grab_info->range) {
        XFree(grab_info->range);
        grab_info->range = NULL;
    }

    if (grab_info->ctrl_disp) {
        XCloseDisplay (grab_info->ctrl_disp);
        grab_info->ctrl_disp = NULL;
    }

    if (grab_info->data_disp) {
        XCloseDisplay (grab_info->data_disp);
        grab_info->data_disp = NULL;
    }

    if (grab_info) {
        g_free (grab_info);
        grab_info = NULL;
    }
}
Пример #6
0
/************************************************************************
 * Internal functions
 ***********************************************************************/
void *sig_handler(void *user_data) {
	XCape_t *self = (XCape_t*) user_data;
	int sig;

	if (self->debug)
		fprintf(stdout, "sig_handler running...\n");

	sigwait(&self->sigset, &sig);

	if (self->debug)
		fprintf(stdout, "Caught signal %d!\n", sig);

	if (!XRecordDisableContext(self->ctrl_conn, self->record_ctx)) {
		fprintf(stderr, "Failed to disable xrecord context\n");
		exit(EXIT_FAILURE);
	}

	XSync(self->ctrl_conn, False);

	if (self->debug)
		fprintf(stdout, "sig_handler exiting...\n");

	return NULL;
}
Пример #7
0
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;
}