xwayland: add simple xcb-cursor hook based on libXcursor

It's in fact based on the core of libXcursor, which doesn't bring any Xlib
dependency.

Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
Tiago Vignatti 12 years ago committed by Kristian Høgsberg
parent e89cef37eb
commit 90fada4338
  1. 2
      configure.ac
  2. 71
      src/xwayland/window-manager.c

@ -42,7 +42,7 @@ AC_ARG_ENABLE(xwayland, [ --enable-xwayland],,
enable_xwayland=yes) enable_xwayland=yes)
AM_CONDITIONAL(ENABLE_XWAYLAND, test x$enable_xwayland = xyes) AM_CONDITIONAL(ENABLE_XWAYLAND, test x$enable_xwayland = xyes)
if test x$enable_xwayland = xyes; then if test x$enable_xwayland = xyes; then
PKG_CHECK_MODULES([XWAYLAND], xcb xcb-xfixes cairo-xcb) PKG_CHECK_MODULES([XWAYLAND], xcb xcb-xfixes xcursor cairo-xcb)
AC_DEFINE([BUILD_XWAYLAND], [1], [Build the X server launcher]) AC_DEFINE([BUILD_XWAYLAND], [1], [Build the X server launcher])
AC_ARG_WITH(xserver-path, AS_HELP_STRING([--with-xserver-path=PATH], AC_ARG_WITH(xserver-path, AS_HELP_STRING([--with-xserver-path=PATH],

@ -31,6 +31,7 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include <X11/Xcursor/Xcursor.h>
#include "xwayland.h" #include "xwayland.h"
@ -140,6 +141,76 @@ get_atom_name(xcb_connection_t *c, xcb_atom_t atom)
return buffer; return buffer;
} }
static xcb_cursor_t
xcb_cursor_image_load_cursor(struct weston_wm *wm, const XcursorImage *img)
{
xcb_connection_t *c = wm->conn;
xcb_screen_iterator_t s = xcb_setup_roots_iterator(xcb_get_setup(c));
xcb_screen_t *screen = s.data;
xcb_gcontext_t gc;
xcb_pixmap_t pix;
xcb_render_picture_t pic;
xcb_cursor_t cursor;
int stride = img->width * 4;
pix = xcb_generate_id(c);
xcb_create_pixmap(c, 32, pix, screen->root, img->width, img->height);
pic = xcb_generate_id(c);
xcb_render_create_picture(c, pic, pix, wm->format_rgba.id, 0, 0);
gc = xcb_generate_id(c);
xcb_create_gc(c, gc, pix, 0, 0);
xcb_put_image(c, XCB_IMAGE_FORMAT_Z_PIXMAP, pix, gc,
img->width, img->height, 0, 0, 0, 32,
stride * img->height, (uint8_t *) img->pixels);
xcb_free_gc(c, gc);
cursor = xcb_generate_id(c);
xcb_render_create_cursor(c, cursor, pic, img->xhot, img->yhot);
xcb_render_free_picture(c, pic);
xcb_free_pixmap(c, pix);
return cursor;
}
static xcb_cursor_t
xcb_cursor_images_load_cursor(struct weston_wm *wm, const XcursorImages *images)
{
/* TODO: treat animated cursors as well */
if (images->nimage != 1)
return -1;
return xcb_cursor_image_load_cursor(wm, images->images[0]);
}
static xcb_cursor_t
xcb_cursor_library_load_cursor(struct weston_wm *wm, const char *file)
{
xcb_cursor_t cursor;
XcursorImages *images;
char *v = NULL;
int size = 0;
if (!file)
return 0;
v = getenv ("XCURSOR_SIZE");
if (v)
size = atoi(v);
if (!size)
size = 32;
images = XcursorLibraryLoadImages (file, NULL, size);
cursor = xcb_cursor_images_load_cursor (wm, images);
XcursorImagesDestroy (images);
return cursor;
}
void void
dump_property(struct weston_wm *wm, dump_property(struct weston_wm *wm,
xcb_atom_t property, xcb_get_property_reply_t *reply) xcb_atom_t property, xcb_get_property_reply_t *reply)

Loading…
Cancel
Save