--- /dev/null
+xicursorset is a tool to set the cursor image for an XInput2 pointer.
+
+The first argument to pass is a pointer id, you can get it by running
+'xinput list' and analyzing its output.
+
+You need to specify an image name supplied by the theme you are using, and you
+can optionally pass a cursor theme name to pick up the image from it.
+
+Examples of use:
+
+Get the possible pointer ids with xinput:
+$ xinput list | grep "master pointer"
+⎡ Virtual core pointer id=2 [master pointer (3)]
+⎡ Extra pointer id=13 [master pointer (14)]
+
+Set the cursor with id=13 to the 'left_ptr' image from the 'redglass' theme
+$ ./xicursorset 13 left_ptr redglass
+
+Set the cursor with id=2 to the 'right_ptr' image from the 'whiteglass' theme
+$ ./xicursorset 2 right_ptr whiteglass
+
+Set the cursor with id=2 to the 'left_ptr' image from the default theme
+$ ./xicursorset 2 left_ptr
--- /dev/null
+/*
+ * xicursorset - set cursor image for an XInput2 pointer
+ *
+ * Copyright (C) 2010 Antonio Ospite <ospite@studenti.unina.it>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include<stdio.h>
+#include<stdlib.h>
+#include<X11/Xcursor/Xcursor.h>
+#include<X11/extensions/XInput2.h>
+#include<assert.h>
+
+int main(int argc, char *argv[])
+{
+ Display* dpy;
+ int screen;
+ Window win;
+
+ int ptrid;
+ char *shape_name;
+ int shape;
+ int size;
+ char *theme;
+ XcursorImage *image;
+ Cursor cursor;
+
+ if (argc < 3 || argc > 4) {
+ printf("usage: xicursor <ptrid> <shape> [<theme>]\n");
+ return 1;
+ }
+
+ /* TODO: verify that the pointer id is sane and
+ * that it is a master pointer
+ */
+ ptrid = atoi(argv[1]);
+
+ shape_name = argv[2];
+ shape = XcursorLibraryShape(shape_name);
+ if (shape < 0) {
+ fprintf(stderr, "Invalid shape name.\n");
+ return EXIT_FAILURE;
+ }
+
+ dpy = XOpenDisplay(NULL);
+ assert(dpy != NULL);
+
+ /* TODO: check return value? */
+ screen = DefaultScreen(dpy);
+
+ /* TODO: check return value? */
+ win = RootWindow(dpy, screen);
+
+ size = XcursorGetDefaultSize(dpy);
+ if (size == 0) {
+ fprintf(stderr, "Can't get cursor size.\n");
+ return EXIT_FAILURE;
+ }
+
+
+ if (argc == 4)
+ theme = argv[3];
+ else
+ theme = XcursorGetTheme(dpy);
+ if (theme == NULL) {
+ fprintf(stderr, "Can't get cursor theme.\n");
+ return EXIT_FAILURE;
+ }
+
+ image = XcursorShapeLoadImage(shape, theme, size);
+ if (image == NULL) {
+ fprintf(stderr, "Can't get cursor image, check <shape> or <theme>.\n");
+ return EXIT_FAILURE;
+ }
+
+ cursor = XcursorImageLoadCursor(dpy, image);
+
+ XIDefineCursor(dpy, ptrid, win, cursor);
+ XFlush(dpy);
+
+ XCloseDisplay(dpy);
+ return 0;
+}