示例#1
0
文件: EventLoop.c 项目: yixuan/Layer
void
R_gtk_setEventHandler()
{
#ifndef WIN32
  static InputHandler *h = NULL;
  if(!h)
    {
      if (!GDK_DISPLAY())
        error("GDK display not found - please make sure X11 is running");
      h = addInputHandler(R_InputHandlers, ConnectionNumber(GDK_DISPLAY()),
                          R_gtk_eventHandler, -1);
    }
#else
  /* Create a dummy window for receiving messages */
  LPCTSTR class = "cairoDevice";
  HINSTANCE instance = GetModuleHandle(NULL);
  WNDCLASS wndclass = { 0, DefWindowProc, 0, 0, instance, NULL, 0, 0, NULL,
                        class };
  RegisterClass(&wndclass);
  HWND win = CreateWindow(class, NULL, 0, 1, 1, 1, 1, HWND_MESSAGE,
                          NULL, instance, NULL);

  SetTimer(win, CD_TIMER_ID, CD_TIMER_DELAY, (TIMERPROC)R_gtk_timer_proc);
#endif
}
示例#2
0
pointer
xf86AddGeneralHandler(int fd, InputHandlerProc proc, pointer data)
{
    IHPtr ih = addInputHandler(fd, proc, data);

    if (ih)
        AddGeneralSocket(fd);
    return ih;
}
示例#3
0
pointer
xf86AddInputHandler(int fd, InputHandlerProc proc, pointer data)
{
    IHPtr ih = addInputHandler(fd, proc, data);

    if (ih)
        AddEnabledDevice(fd);
    return ih;
}
示例#4
0
文件: sys-std.c 项目: lovmoy/r-source
/*
  Initialize the input source handlers used to check for input on the
  different file descriptors.
 */
InputHandler * initStdinHandler(void)
{
    InputHandler *inputs;

    inputs = addInputHandler(R_InputHandlers, fileno(stdin), NULL,
			     StdinActivity);
    /* Defer the X11 registration until it is loaded and actually used. */

    return(inputs);
}
示例#5
0
int RJava_init_loop() {
  int pfd[2];
  pipe(pfd);
  ipcin = pfd[0];
  ipcout = pfd[1];
  pipe(pfd);
  resin = pfd[0];
  resout = pfd[1];

  rJavaInfoBlock.ipcin = ipcin;
  rJavaInfoBlock.ipcout = ipcout;
  rJavaInfoBlock.resin = resin;
  rJavaInfoBlock.resout = resout;
  rJavaInfoBlock.has_control = &RJava_has_control;

  addInputHandler(R_InputHandlers, ipcin, RJava_ProcessEvents, RJavaActivity);
  return 0;
}
示例#6
0
void nvimcom_Start(int *vrb, int *odf, int *ols, int *anm, int *lbe, char **pth, char **vcv, char **srchls)
{
    verbose = *vrb;
    opendf = *odf;
    openls = *ols;
    allnames = *anm;
    labelerr = *lbe;

    R_PID = getpid();
    strncpy(nvimcom_version, *vcv, 31);

    if(getenv("NVIMR_TMPDIR")){
        strncpy(nvimcom_home, *pth, 1023);
        strncpy(search_list, *srchls, 1023);
        strncpy(tmpdir, getenv("NVIMR_TMPDIR"), 500);
        if(getenv("NVIMR_SECRET"))
            strncpy(nvimsecr, getenv("NVIMR_SECRET"), 127);
        else
            REprintf("nvimcom: Environment variable NVIMR_SECRET is missing.\n");
    } else {
        if(verbose)
            REprintf("nvimcom: It seems that R was not started by Neovim. The communication with Nvim-R will not work.\n");
        tmpdir[0] = 0;
        return;
    }

    snprintf(liblist, 510, "%s/liblist_%s", tmpdir, getenv("NVIMR_ID"));
    snprintf(globenv, 510, "%s/globenv_%s", tmpdir, getenv("NVIMR_ID"));

    char envstr[1024];
    envstr[0] = 0;
    if(getenv("LC_MESSAGES"))
        strcat(envstr, getenv("LC_MESSAGES"));
    if(getenv("LC_ALL"))
        strcat(envstr, getenv("LC_ALL"));
    if(getenv("LANG"))
        strcat(envstr, getenv("LANG"));
    int len = strlen(envstr);
    for(int i = 0; i < len; i++)
        envstr[i] = toupper(envstr[i]);
    if(strstr(envstr, "UTF-8") != NULL || strstr(envstr, "UTF8") != NULL){
        nvimcom_is_utf8 = 1;
        strcpy(strL, "\xe2\x94\x94\xe2\x94\x80 ");
        strcpy(strT, "\xe2\x94\x9c\xe2\x94\x80 ");
    } else {
        nvimcom_is_utf8 = 0;
        strcpy(strL, "`- ");
        strcpy(strT, "|- ");
    }

#ifndef WIN32
    *flag_eval = 0;
    int fds[2];
    if(pipe(fds) == 0){
        ifd = fds[0];
        ofd = fds[1];
        ih = addInputHandler(R_InputHandlers, ifd, &nvimcom_uih, 32);
    } else {
        REprintf("setwidth error: pipe != 0\n");
        ih = NULL;
    }
#endif

#ifdef WIN32
    tid = _beginthread(nvimcom_server_thread, 0, NULL);
#else
    pthread_create(&tid, NULL, nvimcom_server_thread, NULL);
#endif

    if(nvimcom_failure == 0){
        // Linked list sentinel
        firstList = calloc(1, sizeof(ListStatus));
        firstList->key = (char*)malloc(13 * sizeof(char));
        strcpy(firstList->key, "package:base");

        for(int i = 0; i < 64; i++){
            loadedlibs[i] = (char*)malloc(64 * sizeof(char));
            loadedlibs[i][0] = 0;
        }
        for(int i = 0; i < 64; i++){
            builtlibs[i] = (char*)malloc(64 * sizeof(char));
            builtlibs[i][0] = 0;
        }

        obbrbuf1 = (char*)calloc(obbrbufzise, sizeof(char));
        obbrbuf2 = (char*)calloc(obbrbufzise, sizeof(char));
        if(!obbrbuf1 || !obbrbuf2)
            REprintf("nvimcom: Error allocating memory.\n");

        Rf_addTaskCallback(nvimcom_task, NULL, free, "NVimComHandler", NULL);

        nvimcom_initialized = 1;
        if(verbose > 0)
            // TODO: use packageStartupMessage()
            REprintf("nvimcom %s loaded\n", nvimcom_version);
        if(verbose > 1)
            REprintf("    NVIMR_TMPDIR = %s\n    NVIMR_ID = %s\n",
                    tmpdir, getenv("NVIMR_ID"));
    }
}
示例#7
0
文件: Rgtk.c 项目: hjy1210/RGtk2
void
R_gtkInit(long *rargc, char **rargv, Rboolean *success)
{
  int argc;

  argc = (int) *rargc;
  
  if (!gdk_display_get_default()) {
    gtk_disable_setlocale();
    if (!gtk_init_check(&argc, &rargv)) {
      *success = FALSE;
      return;
    }
  }

#ifndef G_OS_WIN32
  {
    int fds[2];

    if (!GDK_DISPLAY()) {
      *success = FALSE;
      return;
    }


    addInputHandler(R_InputHandlers, ConnectionNumber(GDK_DISPLAY()),
                    R_gtk_eventHandler, -1);

    /* Experimental timer-based piping to a file descriptor */
#ifdef G_THREADS_ENABLED
#ifndef __FreeBSD__
    if (!pipe(fds)) {
      ifd = fds[0];
      ofd = fds[1];
      eventLoopInputHandler = addInputHandler(R_InputHandlers, ifd,
                                              R_gtk_timerInputHandler, 32);
      if (!g_thread_supported ()) g_thread_init (NULL);
      eventLoopThread = g_thread_create(R_gtk_timerThreadFunc, NULL, TRUE,
                                        NULL);
      R_CStackLimit = -1;
    } else g_warning("Failed to establish pipe; "
                     "disabling timer-based event handling");
#endif
#endif
  }
#else
#if R_VERSION < R_Version(2,8,0)
  R_tcldo = R_gtk_handle_events;
#else
  
  /* Create a dummy window for receiving messages */
  LPCTSTR class = "RGtk2";
  HINSTANCE instance = GetModuleHandle(NULL);
  WNDCLASS wndclass = { 0, DefWindowProc, 0, 0, instance, NULL, 0, 0, NULL,
                        class };
  RegisterClass(&wndclass);
  win = CreateWindow(class, NULL, 0, 1, 1, 1, 1, HWND_MESSAGE,
                     NULL, instance, NULL);

  SetTimer(win, RGTK2_TIMER_ID, RGTK2_TIMER_DELAY, (TIMERPROC)R_gtk_timer_proc);
#endif // R < 2.8.0
#endif // Windows

  R_GTK_TYPE_PARAM_SEXP;
  
  g_value_register_transform_func(G_TYPE_DOUBLE, G_TYPE_STRING,
                                  transformDoubleString);
  g_value_register_transform_func(G_TYPE_INT, G_TYPE_STRING,
                                  transformIntString);
  g_value_register_transform_func(G_TYPE_BOOLEAN, G_TYPE_STRING,
                                  transformBooleanString);
  
  *success = TRUE;
}

void R_gtkCleanup() {
#ifndef G_OS_WIN32
  removeInputHandler(&R_InputHandlers, eventLoopInputHandler);
  g_main_loop_quit(eventLoopMain);
  g_thread_join(eventLoopThread);
  close(ifd);
  close(ofd);
#else
  DestroyWindow(win);
#endif
}