After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 541377 - gdk cursors are only black and white on win32
gdk cursors are only black and white on win32
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Backend: Win32
2.12.x
Other All
: Normal normal
: ---
Assigned To: gtk-win32 maintainers
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2008-07-03 10:50 UTC by Steven Durrans
Modified: 2018-02-10 03:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Workaround to get gdk_cursor_new_from_pixmap to support colors on Win32. (2.61 KB, text/plain)
2009-09-10 11:55 UTC, Dirk Gerrits
Details

Description Steven Durrans 2008-07-03 10:50:04 UTC
Please describe the problem:
Essentially tge cursor example from the gdk reference manual;
http://library.gnome.org/devel/gdk/stable/gdk-Cursors.html

#include <gtk/gtk.h>

/* This data is in X bitmap format, and can be created with the 'bitmap'
 *    utility. */
#define cursor1_width 16
#define cursor1_height 16
static unsigned char cursor1_bits[] = {
  0x80, 0x01, 0x40, 0x02, 0x20, 0x04, 0x10, 0x08, 0x08, 0x10, 0x04, 0x20,
  0x82, 0x41, 0x41, 0x82, 0x41, 0x82, 0x82, 0x41, 0x04, 0x20, 0x08, 0x10,
  0x10, 0x08, 0x20, 0x04, 0x40, 0x02, 0x80, 0x01};

static unsigned char cursor1mask_bits[] = {
  0x80, 0x01, 0xc0, 0x03, 0x60, 0x06, 0x30, 0x0c, 0x18, 0x18, 0x8c, 0x31,
  0xc6, 0x63, 0x63, 0xc6, 0x63, 0xc6, 0xc6, 0x63, 0x8c, 0x31, 0x18, 0x18,
  0x30, 0x0c, 0x60, 0x06, 0xc0, 0x03, 0x80, 0x01};

GdkCursor *cursor;

static gint expose_cb( GtkWidget *pWidget, GdkEventExpose *pEvent, gpointer pData )
{
    gdk_window_set_cursor (pWidget->window, cursor);
}

int main ( int argc, char **argv )
{
    GtkWindow *lWindow;
    GdkPixmap *source, *mask;
    GdkColor fg = { 0, 65535, 0, 0 }; /* Red. */
    GdkColor bg = { 0, 0, 0, 65535 }; /* Blue. */

    gtk_init (&argc, &argv);

    lWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL );
    gtk_widget_set_size_request( lWindow, 400, 400 );

    source = gdk_bitmap_create_from_data (NULL, cursor1_bits,
                                       cursor1_width, cursor1_height);
    mask = gdk_bitmap_create_from_data (NULL, cursor1mask_bits,
                                     cursor1_width, cursor1_height);
    cursor = gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, 8, 8);

    g_signal_connect( lWindow, "expose_event", G_CALLBACK( expose_cb ), NULL );

    gtk_widget_show_all( lWindow );

    gtk_main();

}


Steps to reproduce:
1. build above on linux
2. cursor is red and blue as expected
3. build on win32 and the cursor is only black and white



Actual results:
Cursor is black and white

Expected results:
Cursor should be red and blue

Does this happen every time?
yes

Other information:
A fix would be greatly appreciated.
Comment 1 Tor Lillqvist 2008-07-09 01:15:02 UTC
gdk_cursor_new_from_pixmap() in gdkcursor-win32.c contains the telltale comment:

  /* Such complex bit manipulation for this simple task, sigh.
   * The X cursor and Windows cursor concepts are quite different.
   * We assume here that we are always called with fg == black and
   * bg == white, *or* the other way around. Random colours won't work.
   * (Well, you will get a cursor, but not in those colours.)
   */

http://www.codeproject.com/KB/graphics/ColorCursorFromBmp.aspx seems to have sample code describing how to create coloured cursors. Need to investigate...
Comment 2 Dirk Gerrits 2009-09-10 11:55:42 UTC
Created attachment 142904 [details]
Workaround to get gdk_cursor_new_from_pixmap to support colors on Win32.
Comment 3 Dirk Gerrits 2009-09-10 11:58:55 UTC
The "proper" way to do gdk_cursor_new_from_pixmap in Win32 is probably to use CreateIconIndirect as in the link Tor posted.  However, I've created a different implementation using only GDK functionality (specifically, gdk_cursor_new_from_pixbuf).  You'll find it in the attachment above.  I'm using it to port an application using gdk_cursor_new_from_pixmap to Win32, perhaps it's useful to others as well.
Comment 4 Matthias Clasen 2018-02-10 03:41:36 UTC
We're moving to gitlab! As part of this move, we are closing bugs that haven't seen activity in more than 5 years. If this issue is still imporant to you and
still relevant with GTK+ 3.22 or master, please consider creating a gitlab issue
for it.