Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
the following code will hide the mouse pointer once until the mouse is moved... the problem is that once it's moved, it doesn't disappear again if the view is the same... what method should i call to make it disappear again after say 2 seconds if the view hasn't changed?

Code:
-(void)hideMouseOnFullScreenView
	{
	if ([FullScreenView isVisible])
		{
		[NSCursor setHiddenUntilMouseMoves:YES];
		}
	}
 
How about just listen for mouseMoved events in your view. Every time the mouse is moved, reset a timer to 2 seconds and make the timer call your -hideMouse... method upon firing.
 
there's something wrong with my code... totally doing something dumb for sure... coffee is on, but my logic hasn't kicked in yet... so, in my view class i've got this.

Code:
- (void)awakeFromNib
	{
	[self setAcceptsMouseMovedEvents:YES];
	}

-(void)mouseMoved:(NSEvent *)event
	{
	if (timer == nil)
		{
		NSLog(@"Timer Started / Mouse Moved");
		timer = [[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(hideMouse:) userInfo:nil repeats:NO] retain];
		}
		else
		{
		NSLog(@"Timer Ended");
		[timer invalidate];
		[timer release];
		timer = nil;
		}
        }

-(void)hideMouse:(NSTimer *)timer
	{
	[NSCursor setHiddenUntilMouseMoves:YES];
	}
 
Your timer is never being allowed to fire. On every mouse move you are reseting it back to 2.0 seconds. Take another look at your timer setting if statement in mouseMoved:
 
this seems to work:

Code:
- (void)awakeFromNib
	{
	[self setAcceptsMouseMovedEvents:YES];
	}

-(void)mouseMoved:(NSEvent *)theEvent
	{
	NSLog (@"Timer Reset");
	[timer invalidate];
	
	NSLog(@"Timer Started");
	timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(hideMouse:) userInfo:nil repeats:NO];
	}

-(void)hideMouse:(NSTimer *)theTimer
	{
	[NSCursor setHiddenUntilMouseMoves:YES];
	timer = nil;
	}

hope my new code isn't dangerous, although i believe it's fine... if anyone can comment on it's safety that would be great...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.