Exemple #1
0
int PDC_getclipboard(char **contents, long *length)
{
#ifdef PDC_WIDE
    wchar_t *wcontents;
#endif
    int result = 0;
    int len;

    PDC_LOG(("PDC_getclipboard() - called\n"));

    XCursesInstructAndWait(CURSES_GET_SELECTION);

    if (XC_read_socket(xc_display_sock, &result, sizeof(int)) < 0)
        XCursesExitCursesProcess(5, "exiting from PDC_getclipboard");

    if (result == PDC_CLIP_SUCCESS)
    {
        if (XC_read_socket(xc_display_sock, &len, sizeof(int)) < 0)
            XCursesExitCursesProcess(5, "exiting from PDC_getclipboard");
#ifdef PDC_WIDE
        wcontents = malloc((len + 1) * sizeof(wchar_t));
        *contents = malloc(len * 3 + 1);

        if (!wcontents || !*contents)
#else
            *contents = malloc(len + 1);

        if (!*contents)
#endif
        XCursesExitCursesProcess(6, "exiting from PDC_getclipboard - "
                                    "synchronization error");

        if (len)
        {
            if (XC_read_socket(xc_display_sock,
#ifdef PDC_WIDE
                wcontents, len * sizeof(wchar_t)) < 0)
#else
                *contents, len) < 0)
#endif
                XCursesExitCursesProcess(5, "exiting from PDC_getclipboard");
        }

#ifdef PDC_WIDE
        wcontents[len] = 0;
        len = PDC_wcstombs(*contents, wcontents, len * 3);
        free(wcontents);
#endif
        (*contents)[len] = '\0';
        *length = len;
    }

    return result;
}
Exemple #2
0
int PDC_init_color(short color, short red, short green, short blue)
{
    XColor *tmp = (XColor *)(Xcurscr + XCURSCR_XCOLOR_OFF);

    tmp->pixel = color;

    tmp->red = ((double)red * 65535 / 1000) + 0.5;
    tmp->green = ((double)green * 65535 / 1000) + 0.5;
    tmp->blue = ((double)blue * 65535 / 1000) + 0.5;

    XCursesInstructAndWait(CURSES_SET_COLOR);

    return OK;
}
Exemple #3
0
int PDC_color_content(short color, short *red, short *green, short *blue)
{
    XColor *tmp = (XColor *)(Xcurscr + XCURSCR_XCOLOR_OFF);

    tmp->pixel = color;

    XCursesInstructAndWait(CURSES_GET_COLOR);

    *red = ((double)(tmp->red) * 1000 / 65535) + 0.5;
    *green = ((double)(tmp->green) * 1000 / 65535) + 0.5;
    *blue = ((double)(tmp->blue) * 1000 / 65535) + 0.5;

    return OK;
}
Exemple #4
0
int PDC_resize_screen(int nlines, int ncols)
{
    PDC_LOG(("PDC_resize_screen() - called. Lines: %d Cols: %d\n",
             nlines, ncols));

    if( !stdscr)      /* window hasn't been created yet;  we're */
    {                 /* specifying its size before doing so    */
        XCursesLINES = nlines;
        XCursesCOLS = ncols;
        return OK;
    }

    if (nlines || ncols || !SP->resized)
        return ERR;

    shmdt((char *)Xcurscr);
    XCursesInstructAndWait(CURSES_RESIZE);

    if ((shmid_Xcurscr = shmget(shmkey_Xcurscr,
        SP->XcurscrSize + XCURSESSHMMIN, 0700)) < 0)
    {
        perror("Cannot allocate shared memory for curscr");
        kill(xc_otherpid, SIGKILL);
        return ERR;
    }

    XCursesLINES = SP->lines;
    XCursesCOLS = SP->cols;

    PDC_LOG(("%s:shmid_Xcurscr %d shmkey_Xcurscr %d SP->lines %d "
             "SP->cols %d\n", XCLOGMSG, shmid_Xcurscr,
             shmkey_Xcurscr, SP->lines, SP->cols));

    Xcurscr = (unsigned char*)shmat(shmid_Xcurscr, 0, 0);
    xc_atrtab = (short *)(Xcurscr + XCURSCR_ATRTAB_OFF);

    SP->resized = FALSE;

    return OK;
}