0

The example code from gdkCursorNewFromPixmap causes an error on Ubuntu with R 2.14.1 and RGtk2 2.20.25

Code:

library(RGtk2)

# This data is in X bitmap format, and can be created with the 'bitmap' utility in X11
cursor1_width <- 16
cursor1_height <- 16
cursor1_bits <- c(
  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)
cursor1mask_bits <- c(
  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)
 fg <- c(65535, 0, 0) # Red.
 bg <- c(0, 0, 65535) # Blue.
 source <- gdkPixmapNew(NULL, cursor1_width, cursor1_height, 8) 
 mask <- gdkPixmapNew(NULL, cursor1_width, cursor1_height, 8) 
 cursor <- gdkCursorNewFromPixmap(source, mask, fg, bg,0,0 )

Error:

Error in checkPtrType(source, "GdkPixmap") : 
  object of class GdkBitmap, RGtkObject isn't a GdkPixmap
Calls: gdkCursorNewFromPixmap -> checkPtrType
DGB2000
  • 33
  • 1
  • 4
  • I changed the code:
    source <- gdkPixmapNew(NULL, cursor1_width, cursor1_height, 8) mask <- gdkPixmapNew(NULL, cursor1_width, cursor1_height, 8) cursor <- gdkCursorNewFromPixmap(source, mask, fg, bg,0,0 ) The last line causes a warning: 
    Warning message: In .RGtkCall("S_gdk_cursor_new_from_pixmap", source, mask, fg, bg, : X11 protocol error: BadMatch (invalid parameter attributes) And the cursor when used is still the arrow: 
    w <- gwindow() widget[["w"]]$setCursor(cursor)
    – DGB2000 Nov 01 '13 at 12:23

1 Answers1

0

It boils down to GdkPixmap not equal to GdkBitmap, use gtk_pixmap_new instead of gtk_bitmap_create_from_data (which btw is deprecated) (adapt these to the R namsing conventions)

drahnr
  • 6,782
  • 5
  • 48
  • 75
  • Thank you for your reply! I changed the code:
    source <- gdkPixmapNew(NULL, cursor1_width, cursor1_height, 8)
    mask <- gdkPixmapNew(NULL, cursor1_width, cursor1_height, 8)
    cursor <- gdkCursorNewFromPixmap(source, mask, fg, bg,0,0 )
    
    The last line causes a warning:  
    
    Warning message:
    In .RGtkCall("S_gdk_cursor_new_from_pixmap", source, mask, fg, bg,  :
      X11 protocol error: BadMatch (invalid parameter attributes)
     
    And the cursor when used is still the arrow:  
     
    
    w <- gwindow()
    widget[["w"]]$setCursor(cursor)
    – DGB2000 Oct 31 '13 at 18:31
  • Make that comment an update to your question and I will update my answer accordingly – drahnr Oct 31 '13 at 20:47
  • No you didn't, you added a comment to your own question. Edit the actual question, so code highlighting works. – drahnr Nov 01 '13 at 21:44
  • Oops! OK, I changed the code in the question. Thanks for the tip! – DGB2000 Nov 02 '13 at 06:26