Example #1
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;
}
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateCursor
  (JNIEnv *env, jclass clazz, jlong display, jint width, jint height, jint x_hotspot, jint y_hotspot, jint num_images, jobject image_buffer, jint images_offset, jobject delay_buffer, jint delays_offset)
{
	Display *disp = (Display *)(intptr_t)display;
	const int *delays = NULL;
	if (delay_buffer != NULL)
		delays = (const int *)(*env)->GetDirectBufferAddress(env, delay_buffer) + delays_offset;		
	XcursorPixel *pixels = (XcursorPixel *)(*env)->GetDirectBufferAddress(env, image_buffer) + images_offset;
	int stride = width*height;
	XcursorImages *cursor_images = XcursorImagesCreate(num_images);
	if (cursor_images == NULL) {
		throwException(env, "Could not allocate cursor.");
		return None;
	}
	cursor_images->nimage = num_images;
	int i;
	for (i = 0; i < num_images; i++) {
		XcursorImage *cursor_image = XcursorImageCreate(width, height);
		cursor_image->xhot = x_hotspot;
		cursor_image->yhot = y_hotspot;
		cursor_image->pixels = &(pixels[stride*i]);
		if (num_images > 1)
			cursor_image->delay = delays[i];		
		cursor_images->images[i] = cursor_image;
	}
	Cursor cursor = XcursorImagesLoadCursor(disp, cursor_images);
	XcursorImagesDestroy(cursor_images);
	return cursor;
}
void CHwX11Cursor::Finish()
{
	if (cimages.size()<1)
		return;

	//resize images
	for (std::vector<XcursorImage*>::iterator it = cimages.begin(); it < cimages.end(); ++it)
		resizeImage(*it, xmaxsize, ymaxsize);

	XcursorImages *cis = XcursorImagesCreate(cimages.size());
	cis->nimage = cimages.size();
	for (int i = 0; i < int(cimages.size()); ++i) {
		XcursorImage* ci = cimages[i];
		ci->xhot = (hotSpot==CMouseCursor::TopLeft) ? 0 : ci->width/2;
		ci->yhot = (hotSpot==CMouseCursor::TopLeft) ? 0 : ci->height/2;
		cis->images[i] = ci;
	}

	SDL_SysWMinfo info;
	SDL_VERSION(&info.version);
	if (!SDL_GetWMInfo(&info)) {
		XcursorImagesDestroy(cis);
		cimages.clear();
		logOutput.Print("SDL error: can't get X11 window info");
		return;
	}

	cursor = XcursorImagesLoadCursor(info.info.x11.display,cis);
	XcursorImagesDestroy(cis);
	cimages.clear();
}
Example #4
0
QCursor XCursorThemeData::loadCursor (const QString &name, int size) const {
  if (size == -1) size = XcursorGetDefaultSize(QX11Info::display());
  // Load the cursor images
  XcursorImages *images = xcLoadImages(name, size);
  if (!images) images = xcLoadImages(findAlternative(name), size);
  // Fall back to a legacy cursor
  //if (!images) return LegacyTheme::loadCursor(name);
  if (!images) return false;
  // Create the cursor
  Cursor handle = XcursorImagesLoadCursor(QX11Info::display(), images);
  QCursor cursor = QCursor(Qt::HANDLE(handle)); // QCursor takes ownership of the handle
  XcursorImagesDestroy(images);
  //setCursorName(cursor, name);
  return cursor;
}
qulonglong XCursorTheme::loadCursor(const QString &name, int size) const
{
    if (size <= 0)
        size = autodetectCursorSize();

    // Load the cursor images
    XcursorImages *images = xcLoadImages(name, size);

    if (!images)
        images = xcLoadImages(findAlternative(name), size);

    if (!images)
        return None;

    // Create the cursor
    Cursor handle = XcursorImagesLoadCursor(QX11Info::display(), images);
    XcursorImagesDestroy(images);

    setCursorName(handle, name);
    return handle;
}
Example #6
0
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);
    }
}