From: Antonio Ospite Date: Thu, 14 Jan 2010 14:23:04 +0000 (+0100) Subject: Initial import X-Git-Url: https://git.ao2.it/xicursorset.git/commitdiff_plain/464f2702f5699c240fba01e6a7af783fa96454a5 Initial import --- 464f2702f5699c240fba01e6a7af783fa96454a5 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3fff7f7 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +CFLAGS := -ansi -Wall -pedantic +CFLAGS += -ggdb + +LDFLAGS := $(shell pkg-config --cflags --libs xi xcursor) + +xicursorset: xicursorset.c + $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) + +clean: + rm -f xicursorset *.o diff --git a/README b/README new file mode 100644 index 0000000..b87be08 --- /dev/null +++ b/README @@ -0,0 +1,23 @@ +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 diff --git a/xicursorset.c b/xicursorset.c new file mode 100644 index 0000000..54c985c --- /dev/null +++ b/xicursorset.c @@ -0,0 +1,95 @@ +/* + * xicursorset - set cursor image for an XInput2 pointer + * + * Copyright (C) 2010 Antonio Ospite + * + * 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 . + */ + +#include +#include +#include +#include +#include + +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 []\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 or .\n"); + return EXIT_FAILURE; + } + + cursor = XcursorImageLoadCursor(dpy, image); + + XIDefineCursor(dpy, ptrid, win, cursor); + XFlush(dpy); + + XCloseDisplay(dpy); + return 0; +}