Code

Applying patch #1415498 by James Kilfiger / zeimusu - Allow color & transparency...
authorscislac <scislac@users.sourceforge.net>
Fri, 3 Feb 2006 19:45:56 +0000 (19:45 +0000)
committerscislac <scislac@users.sourceforge.net>
Fri, 3 Feb 2006 19:45:56 +0000 (19:45 +0000)
src/event-context.cpp
src/sp-cursor.cpp

index d67572e9c7cd5c07e0f3da94afe83684972b416f..8291d79a469c6f2aed64d86f80bedfb947525574 100644 (file)
@@ -174,18 +174,35 @@ sp_event_context_update_cursor(SPEventContext *ec)
     if (w->window) {
         /* fixme: */
         if (ec->cursor_shape) {
-            GdkBitmap *bitmap = NULL;
-            GdkBitmap *mask = NULL;
-            sp_cursor_bitmap_and_mask_from_xpm(&bitmap, &mask, ec->cursor_shape);
-            if ((bitmap != NULL) && (mask != NULL)) {
-                if (ec->cursor)
-                    gdk_cursor_unref (ec->cursor);
-                ec->cursor = gdk_cursor_new_from_pixmap(bitmap, mask,
-                                                        &w->style->black, 
-                                                        &w->style->white,
-                                                        ec->hot_x, ec->hot_y);
-                g_object_unref (bitmap);
-                g_object_unref (mask);
+            GdkDisplay *display=gdk_display_get_default();
+            if (
+                    gdk_display_supports_cursor_alpha(display) & 
+                    gdk_display_supports_cursor_color(display)
+               )
+            {
+                GdkPixbuf *pixbuf =NULL;
+                pixbuf=gdk_pixbuf_new_from_xpm_data((const char**)ec->cursor_shape);
+                if (pixbuf !=NULL) { 
+                ec->cursor = gdk_cursor_new_from_pixbuf(display,pixbuf,
+                        ec->hot_x,
+                        ec->hot_y); 
+                }
+            }
+            else 
+            {
+                    GdkBitmap *bitmap = NULL;
+                GdkBitmap *mask = NULL;
+                sp_cursor_bitmap_and_mask_from_xpm(&bitmap, &mask, ec->cursor_shape);
+                if ((bitmap != NULL) && (mask != NULL)) {
+                    if (ec->cursor)
+                        gdk_cursor_unref (ec->cursor);
+                    ec->cursor = gdk_cursor_new_from_pixmap(bitmap, mask,
+                            &w->style->black, 
+                            &w->style->white,
+                            ec->hot_x, ec->hot_y);
+                    g_object_unref (bitmap);
+                    g_object_unref (mask);
+                }
             }
         }
         gdk_window_set_cursor(w->window, ec->cursor);
index f59c63487083ac986e74e49b61ed4acb39d6e691..75b0affe377381e25270f1cff815e20ac82dcdaf 100644 (file)
@@ -84,22 +84,38 @@ void sp_cursor_bitmap_and_mask_from_xpm (GdkBitmap **bitmap, GdkBitmap **mask, g
 
 GdkCursor *sp_cursor_new_from_xpm (gchar **xpm, gint hot_x, gint hot_y)
 {
-    GdkColor const fg = { 0, 0, 0, 0 };
-    GdkColor const bg = { 0, 65535, 65535, 65535 };
-    
-    GdkBitmap *bitmap = NULL;
-    GdkBitmap *mask = NULL;
-
-    sp_cursor_bitmap_and_mask_from_xpm (&bitmap, &mask, xpm);
-    if ( bitmap != NULL && mask != NULL ) {
-        GdkCursor *new_cursor = gdk_cursor_new_from_pixmap (bitmap, mask,
-                                           &fg, &bg,
-                                           hot_x, hot_y);
-        g_object_unref (bitmap);
-        g_object_unref (mask);
+GdkDisplay *display=gdk_display_get_default();
+    if (
+            gdk_display_supports_cursor_alpha(display) & 
+            gdk_display_supports_cursor_color(display)
+       )
+    {
+        GdkPixbuf *pixbuf=NULL;
+        GdkCursor *new_cursor=NULL;
+        pixbuf=gdk_pixbuf_new_from_xpm_data((const char**)xpm);
+        if (pixbuf != NULL){
+            new_cursor = gdk_cursor_new_from_pixbuf(display,pixbuf,hot_x,hot_y);
+        }
         return new_cursor;
     }
-
+    else
+    {
+        GdkColor const fg = { 0, 0, 0, 0 };
+        GdkColor const bg = { 0, 65535, 65535, 65535 };
+        GdkBitmap *bitmap = NULL;
+        GdkBitmap *mask = NULL;
+
+        sp_cursor_bitmap_and_mask_from_xpm (&bitmap, &mask, xpm);
+        if ( bitmap != NULL && mask != NULL ) {
+            GdkCursor *new_cursor = gdk_cursor_new_from_pixmap (bitmap, mask,
+                    &fg, &bg,
+                    hot_x, hot_y);
+            g_object_unref (bitmap);
+            g_object_unref (mask);
+            return new_cursor;
+        }
+    }
     return NULL;
 }