Tk Source Code

Artifact [23947fdd]
Login

Artifact 23947fdd3c3b672ae44049b8ecbff038a43982bf:

Attachment "xcursor.diff" to ticket [3164867f] added by egavilan 2011-01-25 22:49:12.
Index: unix/tkUnixCursor.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/unix/tkUnixCursor.c,v
retrieving revision 1.15
diff -u -r1.15 tkUnixCursor.c
--- unix/tkUnixCursor.c	5 Nov 2008 22:48:58 -0000	1.15
+++ unix/tkUnixCursor.c	25 Jan 2011 15:46:27 -0000
@@ -12,6 +12,9 @@
  */
 
 #include "tkInt.h"
+#ifdef HAVE_XCURSOR
+#include <X11/Xcursor/Xcursor.h>
+#endif
 
 /*
  * The following data structure is a superset of the TkCursor structure
@@ -325,9 +328,15 @@
 	    goto badString;
 	}
 
+#ifdef HAVE_XCURSOR
+	if (!inTkTable && (argc != 1) && (argc != 2) && (argc != 4)) {
+	    goto badString;
+	}
+#else
 	if (!inTkTable && (argc != 2) && (argc != 4)) {
 	    goto badString;
 	}
+#endif /* HAVE_XCURSOR */
 
 	cursor = CreateCursorFromTableOrFile(interp, tkwin, argc, argv,
 		tkCursorPtr);
@@ -429,6 +438,30 @@
 	source = XCreateBitmapFromData(display, drawable, data, width,height);
 	ckfree(data);
     } else {
+#ifdef HAVE_XCURSOR
+        if (argc == 1) {
+            /* Normalize the path */
+            Tcl_Obj * pathObj;
+            Tcl_Obj * normalPathObj;
+
+            pathObj = Tcl_NewStringObj(&argv[0][1], -1);
+            Tcl_IncrRefCount(pathObj);
+
+            normalPathObj = Tcl_FSGetNormalizedPath(interp, pathObj);
+            if (NULL == normalPathObj) {
+                Tcl_AppendResult(interp, "bad filename specification \"",
+                    &argv[0][1], "\"", NULL);
+            } else {
+                cursor = XcursorFilenameLoadCursor(display, Tcl_GetString(normalPathObj));
+                if (cursor == None)
+                    Tcl_AppendResult(interp, "file \"",
+                        &argv[0][1], "\" is not an Xcursor file", NULL);
+            }
+
+            Tcl_DecrRefCount(pathObj);
+            goto cleanup;
+        }
+#endif /* HAVE_XCURSOR */
 	if (TkReadBitmapFile(display, drawable, &argv[0][1],
 		(unsigned *) &width, (unsigned *) &height,
 		&source, &xHot, &yHot) != BitmapSuccess) {
Index: unix/tcl.m4
===================================================================
RCS file: /cvsroot/tktoolkit/tk/unix/tcl.m4,v
retrieving revision 1.150
diff -u -r1.150 tcl.m4
--- unix/tcl.m4	13 Dec 2010 22:37:19 -0000	1.150
+++ unix/tcl.m4	25 Jan 2011 15:46:28 -0000
@@ -2459,6 +2459,14 @@
 	AC_MSG_RESULT([could not find any!  Using -lX11.])
 	XLIBSW=-lX11
     fi
+
+
+    AC_MSG_RESULT([])
+    # check for Xcursor availability
+    AC_CHECK_LIB(Xcursor, XcursorFilenameLoadCursor, [
+        AC_DEFINE(HAVE_XCURSOR, 1, [Is Xcursor available?])
+        XLIBSW="$XLIBSW -lXcursor"
+    ])
 ])
 
 #--------------------------------------------------------------------
Index: doc/GetCursor.3
===================================================================
RCS file: /cvsroot/tktoolkit/tk/doc/GetCursor.3,v
retrieving revision 1.15
diff -u -r1.15 GetCursor.3
--- doc/GetCursor.3	5 Nov 2008 22:58:29 -0000	1.15
+++ doc/GetCursor.3	25 Jan 2011 15:46:28 -0000
@@ -132,8 +132,13 @@
 or Windows computers.
 .TP
 \fB@\fIsourceName\fR
-This form only works on Windows, and will load a Windows system
-cursor (\fB.ani\fR or \fB.cur\fR) from the file specified in
+This form works on Windows and, if the Xcursor library is available,
+on X11.
+On Windows systems, it will load a Windows system cursor
+(\fB.ani\fR or \fB.cur\fR) on from from the file specified in
+\fIsourceName\fR.
+On X11, it will load a cursor in Xcursor format from the file
+specified in
 \fIsourceName\fR.
 .PP
 \fBTk_GetCursor\fR is identical to \fBTk_AllocCursorFromObj\fR except