XcursorImages *XCursorTheme::xcLoadImages(const QString &image, int size) const
{
    QByteArray cursorName = QFile::encodeName(image);
    QByteArray themeName  = QFile::encodeName(name());

    return XcursorLibraryLoadImages(cursorName, themeName, size);
}
Exemple #2
0
Cursor
XcursorLibraryLoadCursor (Display *dpy, const char *file)
{
    int		    size = XcursorGetDefaultSize (dpy);
    char	    *theme = XcursorGetTheme (dpy);
    XcursorImages   *images = XcursorLibraryLoadImages (file, theme, size);
    Cursor	    cursor;

    if (!file)
        return 0;

    if (!images)
    {
	int id = XcursorLibraryShape (file);

	if (id >= 0)
	    return _XcursorCreateFontCursor (dpy, id);
	else
	    return 0;
    }
    cursor = XcursorImagesLoadCursor (dpy, images);
    XcursorImagesDestroy (images);
#if defined HAVE_XFIXES && XFIXES_MAJOR >= 2
    XFixesSetCursorName (dpy, cursor, file);
#endif
    return cursor;
}
Exemple #3
0
XcursorImages *
XcursorShapeLoadImages (unsigned int shape, const char *theme, int size)
{
    unsigned int    id = shape >> 1;

    if (id < NUM_STANDARD_NAMES)
	return XcursorLibraryLoadImages (STANDARD_NAME (id), theme, size);
    else
	return NULL;
}
Exemple #4
0
XcursorCursors *
XcursorLibraryLoadCursors (Display *dpy, const char *file)
{
    int		    size = XcursorGetDefaultSize (dpy);
    char	    *theme = XcursorGetTheme (dpy);
    XcursorImages   *images = XcursorLibraryLoadImages (file, theme, size);
    XcursorCursors  *cursors;

    if (!file)
        return NULL;

    if (!images)
    {
	int id = XcursorLibraryShape (file);

	if (id >= 0)
	{
	    cursors = XcursorCursorsCreate (dpy, 1);
	    if (cursors)
	    {
		cursors->cursors[0] = _XcursorCreateFontCursor (dpy, id);
		if (cursors->cursors[0] == None)
		{
		    XcursorCursorsDestroy (cursors);
		    cursors = NULL;
		}
		else
		    cursors->ncursor = 1;
	    }
	}
	else
	    cursors = NULL;
    }
    else
    {
	cursors = XcursorImagesLoadCursors (dpy, images);
	XcursorImagesDestroy (images);
    }
    return cursors;
}
void PreviewCursor::load(const QString &name, const QString &theme)
{
    Display *dpy = QPaintDevice::x11AppDisplay();

    if(m_pict)
        XRenderFreePicture(dpy, m_pict);
    if(m_handle)
        XFreeCursor(dpy, m_handle);
    m_pict = 0;
    m_handle = 0;
    m_width = m_height = 0;

    // Load the preview cursor image
    XcursorImage *image = XcursorLibraryLoadImage(name.latin1(), theme.latin1(), previewSize);

    // If the theme doesn't have this cursor, load the default cursor for now
    if(!image)
        image = XcursorLibraryLoadImage("left_ptr", theme.latin1(), previewSize);

    // TODO The old classic X cursors
    if(!image)
        return;

    // Auto-crop the image (some cursor themes use a fixed image size
    //   for all cursors, and doing this results in correctly centered images)
    cropCursorImage(image);

    m_pict = createPicture(image);
    m_width = image->width;
    m_height = image->height;

    // Scale the image if its height is greater than 2x the requested size
    if(m_height > previewSize * 2.0)
    {
        double factor = double(previewSize * 2.0 / m_height);
        XTransform xform = {{{XDoubleToFixed(1.0), XDoubleToFixed(0), XDoubleToFixed(0)},
                             {XDoubleToFixed(0), XDoubleToFixed(1.0), XDoubleToFixed(0)},
                             {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(factor)}}};
        XRenderSetPictureTransform(dpy, m_pict, &xform);
        m_width = int(m_width * factor);
        m_height = int(m_height * factor);
    }

    // We don't need this image anymore
    XcursorImageDestroy(image);

    // Load the actual cursor we will use
    int size = XcursorGetDefaultSize(dpy);
    XcursorImages *images = XcursorLibraryLoadImages(name.latin1(), theme.latin1(), size);

    if(images)
    {
        m_handle = XcursorImagesLoadCursor(dpy, images);
        XcursorImagesDestroy(images);
    }
    else
    {
        images = XcursorLibraryLoadImages("left_ptr", theme.latin1(), size);
        m_handle = XcursorImagesLoadCursor(dpy, images);
        XcursorImagesDestroy(images);
    }
}