Hide the mouse cursor in OS X
Wilson Saunders

I am porting a PC Allegro game to the MAC. I can't find the function that gets rid of the OS cursor. I have tried:

disable_hardware_cursor();

show_mouse(NULL);

BITMAP * hidden = create_bitmap(1,1);
set_mouse_sprite(hidden);

select_mouse_cursor(MOUSE_CURSOR_NONE);

Is there any other way to hide the mac OS X mouse? FYI I am using OS X 10.2.8 on a G4 but would like it to be compatible with the later OS X's

Matthew Leverton
Wilson Saunders

That thread let me narrow down the problem. The mouse hides perfectly in windowed mode it also hides when in regular full screen mode. However my program is running in 32 bit color depth. When the display settings are:

set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1024, 768,0,0);

on Mac OS X 10.2.8 the cursor can not be hiden.

I double checked this by setting the exmouse.c example file to render in 32bit full screen and it produced the same result.

Peter Hull

OK, I see it too. I'll have a look

Pete

Wilson Saunders

As far as I can tell no allegro routines can resolve this problem. Fortunately I found a Mac OS X function that can:

http://developer.apple.com/documentation/GraphicsImaging/Reference/Quartz_Services_Ref/Reference/reference.html#//apple_ref/c/func/CGDisplayHideCursor

The exact solution in project builder is as follows:
Project->Add Frameworks...->ApplicationServices.framework
in main.cpp:
#include <ApplicationServices/ApplicationServices.h>

int main(){
...
CGDisplayHideCursor(kCDSirectMainDisplay);
...
}

I hope this helps some one else.
Credit for solution: me :)

Peter Hull

Oh but did you see my other post - did that not help? I can't reply to two threads at once!

Pete

Wilson Saunders

Yes Peter I saw your other thread. ML referenced me to it. Unfortunately I did not find the thread on a google search for this problem. So I started my own thread.

It was helpfull in narrowing down the problem. Especially using exmouse as a test harness, instead of relying on my own somewhat faulty code.

Still I claim credit since I spent the time scouring the apple dev website :P

Peter Hull

Wilson,

Can you do me a big favour and try out the patch that I posted in the other thread?

The reason is that using CGDisplayHideCursor is fine, (indeed, it's used in the Allegro source, src/macosx/qzfull.m line 244) but it does hide the cursor completely so none of Allegro's other cursor stuff will work. So, it's not a general solution on its own.

When I looked at the relevant code, it seemed to imply that hardware cursors (as used in Windowed mode) would work in full-screen mode for all colour depths apart from 8-bit. In 8-bit mode, Allegro instead hides the cursor (guess which function it uses!) and disables the hardware cursor. That may have been true in the past but as far as I can see, hardware cursors don't work in fullscreen mode at any depth. By that, I mean that you can't set the cursor image with set_mouse_sprite. My patch just disables hardware cursors for all colour depths in fullscreen mode.

Please try it and see if it helps.

Thanks,
Peter.

Thread #592589. Printed from Allegro.cc