How to set busy cursor

Linux specific forum
nospam
Enthusiast
Enthusiast
Posts: 130
Joined: Mon Nov 12, 2012 9:15 am

How to set busy cursor

Post by nospam »

I've looked through the help text and searched the forums but I can't see a way to set the cursor under Linux. Does anyone who knows how it's done care to share how to set the busy cursor and back to the default pointer again?

I tried doing it in GTK by translating these lines:

Code: Select all

GtkWidget* win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
GdkCursor* watchCursor = gdk_cursor_new(GDK_WATCH);

/* set watch cursor */
gdk_window_set_cursor(win->window, watchCursor);

/* set default cursor */
gdk_window_set_cursor(win->window, NULL);
I ended up with this:

Code: Select all

Define *Window.GtkWidget
Define *Cursor.GdkCursor
gtk_init_(0, 0)

*Window = gtk_window_new_(GTK_WINDOW_TOPLEVEL)
gtk_widget_show_(*Window)

Cursor = gdk_cursor_new_(GDK_WATCH)
gdk_window_set_cursor_(*Window, Cursor);

gtk_main_()

End
Unfortunately I'm new to all this so I'm stuck. The cursor doesn't change, and my app doesn't close after the window is closed. I assume I'm missing some way to get a signal from the toolkit that the window has been closed. Tips on that latter issue would be appreciated too. PB is v5 x64.

Thanks for reading.
User avatar
Shardik
Addict
Addict
Posts: 1991
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: How to set busy cursor

Post by Shardik »

You might take a look into my code example in the German forum:
http://www.purebasic.fr/german/viewtopi ... 58&start=4
nospam
Enthusiast
Enthusiast
Posts: 130
Joined: Mon Nov 12, 2012 9:15 am

Re: How to set busy cursor

Post by nospam »

Shardik wrote:You might take a look into my code example in the German forum:
http://www.purebasic.fr/german/viewtopi ... 58&start=4
AHHHHH! There's what I was missing...

Code: Select all

*Window\window
Thank you very much, Shardik. Yes, that works. I also see now that there's no need for gtk_main() if PB is managing the interactions. Once again, thank you. I'm very grateful.
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: How to set busy cursor

Post by Keya »

Shardik wrote:You might take a look into my code example in the German forum:
http://www.purebasic.fr/german/viewtopi ... 58&start=4
Shardik your demo isnt working on Linux-64 Mint (Ubuntu) Cinnamon
It's crashing at:

Code: Select all

  gdk_window_set_cursor_(*Widget\window, *Cursor)
with the error: "[WARNING] Gdk (CRITICAL): gdk_window_set_cursor: assertion 'GDK-IS-WINDOW(window)' failed"
I had a play around with it but am at a loss as to why it's not working
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: How to set busy cursor

Post by Oma »

Hello Keya, :)

the problem is again gtk3 and not x64. (*Widget\window is empty or wrong in PB5.4x on gtk3!)
Here is an update of Shardik's code for gtk2 and gtk3: http://www.chabba.de/Linux/Window/Window_SetCursor.pb
But the predefined PB cursors in the linked code are not complete!
At the moment this cursor types in the disabled enum items are predefined in PB ...

Code: Select all

Enumeration GdkCursorType
; 	#GDK_X_CURSOR           = 0
; 	#GDK_ARROW              = 2
; 	#GDK_BASED_ARROW_DOWN   = 4
; 	#GDK_BASED_ARROW_UP     = 6
; 	#GDK_BOAT               = 8
; 	#GDK_BOGOSITY           = 10
; 	#GDK_BOTTOM_LEFT_CORNER = 12
; 	#GDK_BOTTOM_RIGHT_CORNER= 14
; 	#GDK_BOTTOM_SIDE        = 16
; 	#GDK_BOTTOM_TEE         = 18
; 	#GDK_BOX_SPIRAL         = 20
; 	#GDK_CENTER_PTR         = 22
; 	#GDK_CIRCLE             = 24
; 	#GDK_CLOCK              = 26
; 	#GDK_COFFEE_MUG         = 28
; 	#GDK_CROSS              = 30
; 	#GDK_CROSS_REVERSE      = 32
; 	#GDK_CROSSHAIR          = 34
; 	#GDK_DIAMOND_CROSS      = 36
; 	#GDK_DOT                = 38
; 	#GDK_DOTBOX             = 40
; 	#GDK_DOUBLE_ARROW       = 42
; 	#GDK_DRAFT_LARGE        = 44
; 	#GDK_DRAFT_SMALL        = 46
; 	#GDK_DRAPED_BOX         = 48
; 	#GDK_EXCHANGE           = 50
; 	#GDK_FLEUR              = 52
; 	#GDK_GOBBLER            = 54
; 	#GDK_GUMBY              = 56
; 	#GDK_HAND1              = 58
; 	#GDK_HAND2              = 60
; 	#GDK_HEART              = 62
; 	#GDK_ICON               = 64
; 	#GDK_IRON_CROSS         = 66
; 	#GDK_LEFT_PTR           = 68
; 	#GDK_LEFT_SIDE          = 70
; 	#GDK_LEFT_TEE           = 72
; 	#GDK_LEFTBUTTON         = 74
; 	#GDK_LL_ANGLE           = 76
; 	#GDK_LR_ANGLE           = 78
; 	#GDK_MAN                = 80
; 	#GDK_MIDDLEBUTTON       = 82
; 	#GDK_MOUSE              = 84
; 	#GDK_PENCIL             = 86
; 	#GDK_PIRATE             = 88
; 	#GDK_PLUS               = 90
; 	#GDK_QUESTION_ARROW     = 92
; 	#GDK_RIGHT_PTR          = 94
; 	#GDK_RIGHT_SIDE         = 96
; 	#GDK_RIGHT_TEE          = 98
; 	#GDK_RIGHTBUTTON        = 100
; 	#GDK_RTL_LOGO           = 102
; 	#GDK_SAILBOAT           = 104
; 	#GDK_SB_DOWN_ARROW      = 106
; 	#GDK_SB_H_DOUBLE_ARROW  = 108
; 	#GDK_SB_LEFT_ARROW      = 110
; 	#GDK_SB_RIGHT_ARROW     = 112
; 	#GDK_SB_UP_ARROW        = 114
; 	#GDK_SB_V_DOUBLE_ARROW  = 116
; 	#GDK_SHUTTLE            = 118
; 	#GDK_SIZING             = 120
; 	#GDK_SPIDER             = 122
; 	#GDK_SPRAYCAN           = 124
; 	#GDK_STAR               = 126
; 	#GDK_TARGET             = 128
; 	#GDK_TCROSS             = 130
; 	#GDK_TOP_LEFT_ARROW     = 132
; 	#GDK_TOP_LEFT_CORNER    = 134
; 	#GDK_TOP_RIGHT_CORNER   = 136
; 	#GDK_TOP_SIDE           = 138
; 	#GDK_TOP_TEE            = 140
; 	#GDK_TREK               = 142
; 	#GDK_UL_ANGLE           = 144
; 	#GDK_UMBRELLA           = 146
; 	#GDK_UR_ANGLE           = 148
; 	#GDK_WATCH              = 150
; 	#GDK_XTERM              = 152
; 	#GDK_LAST_CURSOR        = 153
	#GDK_BLANK_CURSOR         = -2
; 	#GDK_CURSOR_IS_PIXMAP   = -1
EndEnumeration
Best Regards, Charly
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: How to set busy cursor

Post by Keya »

thanks Oma! yes your demo is working fine here - sweet it works for both gtk2 and 3 :)
i'm putting together a multi-OS SetCursor(), although it seems there's only half a dozen or so cursors that match on all three OS! but really all i/most of us need is Arrow and Busy, anything else is icing on the cake. Anyway all the pieces of the puzzle are together now so i'll post it soon! thankyou to everyone who's contributed mouse cursor code
[edit] posted here - http://www.purebasic.fr/english/viewtop ... 12&t=65293
Post Reply