Mouse Event Not Being Called? [XCode Project Attached]

Discussion in 'Mac Programming' started by Darkroom, Jul 29, 2008.

  1. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #1
    so here's a fun one that i've been trying to solve for a few weeks now...

    2 window objects: Main Window and Full Screen Window... when Full Screen Window is up, the mouse cursor should hide until moved, then become invisible again after 1 second if the NSCursor has not moved.

    everything work fine ONLY IF the user first clicks on the full screen window (when it's visible) to activate the process... i've tried lots: if ([FullScreenWindow isVisible]) activate the process, if it's not visible activate the process, etc, etc, etc... i've seen this done in countless apps but i just can't get it...

    the small project code is attached... if someone can take a look and let me know what i'm doing wrong this that would be great...
     

    Attached Files:

  2. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #2
    It seems like moving the call to -setAcceptsMouseMovedEvents: outside -awakeFromNib makes it work. You may want to use a delegate to set up your timer in -windowDidBecomeKey: or you can listen for NSWindowDidBecomeKeyNotification.
     
  3. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #3
    i'm not sure i follow what you mean here... you mean get rid of the awakeFromNib method and write [self setAcceptsMouseMovedEvents:YES]; in some other method?
     
  4. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #5
    it hasn't for me... what method did you use instead?
     
  5. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #6
    I tried it both at the end of your FullScreenMode: method and a quick and dirty override of -makeKeyAndOrderFront: (after calling super), which isn't recommended, but the delegate method should be roughly equivalent.
     
  6. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #7
    christ... that was WELL dumb of me... i sware i tried this and a bunch of other things before but it seems to work perfectly as you say by removing the awakeFromNib method from the FullScreenWindow class and just change the app controller to look like this:

    Code:
    - (IBAction)WindowMode:(id)sender
    	{
    	[FullScreenWindow orderOut:nil];
    	SetSystemUIMode(kUIModeNormal, 0);
    	[MainWindow makeKeyAndOrderFront:nil];
    	[COLOR="RoyalBlue"][NSCursor setHiddenUntilMouseMoves:NO][/COLOR];
    	}
    
    - (IBAction)FullScreenMode:(id)sender
    	{
    	[MainWindow orderOut:nil];
    	SetSystemUIMode(kUIModeAllHidden, 0);
    	[FullScreenWindow makeKeyAndOrderFront:nil];
    	[FullScreenWindow setFrame:[[FullScreenWindow screen] visibleFrame] display:YES];
    	SetSystemUIMode(kUIModeAllSuppressed, 0);
    [COLOR="RoyalBlue"]	[FullScreenWindow setAcceptsMouseMovedEvents:YES];
    	[NSCursor setHiddenUntilMouseMoves:YES];[/COLOR]
    	}
    
    thanks for the help :eek:
     
  7. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #8
    i've realized that while the above code alterations now work, whenever i switch back to the main window it's still timing down to the last [NSCursor setHiddenUntilMouseMoves:YES]; from the FullScreen class and will once more hide the cursor when the mode switches from full screen to window mode, even though the IBAction for the main Window has [NSCursor setHiddenUntilMouseMoves:NO]; as apart of it's method... i can't seem to override the last timer that runs when switching from full screen to main window. i don't know how to invalidate the timer from the IBAction Window Mode method in the app controller class...

    i've tried writing:
    Code:
    - (void)hideMouse:(NSTimer *)theTimer
    	{
    	if ([self isVisible]) // or if self isKeyWindow
    		{
    		[NSCursor setHiddenUntilMouseMoves:YES];
    		timer = nil;
    		}
    	}
    
    but that just seems to crash the app... ??

    finally, i'm not following really your suggestion to including NSNotification here... when i set it up it only works once, since the posting a notification with the appcontroller's FullScreen IBAction is only triggered once, which is why i have been using the mouseMoved event... unless i've misunderstood what you mean exactly - which is quite possible...
     

Share This Page