Full screen mouse events

Member
Posts: 21
Joined: 2009.12
Post: #1
Hi all,

I'm trying to handle full-screen mouse events in my cocoa game. I've extended an NSOpenGLView which can do both windowed and full-screen rendering (using a unique pixel format for each case). I've included an override for "acceptsFirstResponder," which returns true, and added methods to handle the following events:

Code:
- (void)keyDown:(NSEvent *) theEvent;
- (void)keyUp:(NSEvent *) theEvent;
- (void)mouseDown:(NSEvent *)theEvent;
- (void)mouseUp:(NSEvent *)theEvent;
- (void)mouseDragged:(NSEvent *)theEvent;
- (void)mouseMoved:(NSEvent *)theEvent;

In windowed mode, all of these events are being handled as I would expect. However, in full screen mode, only the keyUp/keyDown events are being handled --All mouse events are ignored.

I've found a couple of workarounds for mouseMoved events. The one I'm using is as follows:

Code:
NSPoint mouseLoc = [NSEvent mouseLocation];

However, I can't think of any other way to handle mousUp/mouseDown events without resorting to Carbon. I've done this in carbon before, so I'm confident that I could get it to work in this case, but Carbon seems to be on its way out, so I'd like to avoid it, if at all possible. So is this possible?

Thanks.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #2
You can grab all the events in full screen by overriding NSApplication's sendEvent method.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
If you're using 10.5's -[NSView enterFullScreenMode:options:] ( and if you aren't, why not? Wink ) then mouse events work normally.
Quote this message in a reply
Member
Posts: 21
Joined: 2009.12
Post: #4
AnotherJake Wrote:You can grab all the events in full screen by overriding NSApplication's sendEvent method.

Thanks, that works beautifully!
Quote this message in a reply
Member
Posts: 21
Joined: 2009.12
Post: #5
OneSadCookie Wrote:If you're using 10.5's -[NSView enterFullScreenMode:options:] ( and if you aren't, why not? Wink ) then mouse events work normally.

Thanks for the reply. There's a couple of reasons: The biggest reason is that I want to support older versions of OS X. At the moment, I'm using XCode 3.2, but I plan on moving to an older version in the near future --what's the oldest version that supports universal binaries?

Secondly, I was looking at examples for defining rendering contexts programmatically (which is desirable to me for a few reasons), and those examples didn't use that method (so I never really thought about it).
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #6
I don't think I'd bother supporting anything farther back than 10.4. I've run into a whole bunch of various little compatibility issues trying to reach back any farther than that. Plus, if a potential customer ain't gonna upgrade their OS to at least Tiger, I doubt they'd be the type to buy any new software anyway.
Quote this message in a reply
Member
Posts: 21
Joined: 2009.12
Post: #7
Yeah, maybe you're right. On the other hand, PPC Macs don't support 10.6, and copies of older versions are sold out everywhere. If you're looking to upgrade an old Panther machine, you'd have to go to eBay, and even then, the extra demand has ramped up prices on used copies. There's a copy of 10.5 going for $212.50. Copies of Tiger are selling for what they originally cost new.

I wonder if there's any current stats that breaks down the Mac user base by OS version. A few years back (I think it was at a WWDC), Steve gave such stats, and I believed it showed that the majority of Mac users were at least one version behind the latest. Very impressive.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
Something like 75% of people have Leopard+ these days. I can see *considering* Tiger support, but if they haven't upgraded the most important piece of software on their machine in 2+ years, and haven't bought a machine in 2+ years, are they going to buy your software, or even know it exists?

Attempting to support older OSes introduces coding difficulties (eg. you don't have -enterFullScreenMode:options) and compatibility testing difficulties (do you have a 400MHz G3 with a Rage 128 and 128MB RAM lying around to test your app with Tiger?).
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #9
Moderator note: Mister T was stuck in approval queue for new members before OSC replied. Sorry for any confusion, Mister T. Sad The first few posts of new members have to be moderated to filter out spam.

Quote:I wonder if there's any current stats that breaks down the Mac user base by OS version.

For some interesting OS stats, check out: http://update.omnigroup.com/

[heh... being as how I got turned on to that link by OneSadCookie back in the day, I'm sure he would've added that to his post in the first place -- hijacked by moderator! Rasp]
Quote this message in a reply
Member
Posts: 21
Joined: 2009.12
Post: #10
No problem. I knew that was going to happen from the registration email. Smile

Anyhoo, that omnigroup link is really helpful. It looks like there's not much point in going back past Tiger, even. That will certainly make my life easier.

@onesadcookie, outnumbered looks fantastic!
Quote this message in a reply
Member
Posts: 177
Joined: 2002.08
Post: #11
Quote:I'm using XCode 3.2, but I plan on moving to an older version in the near future --what's the oldest version that supports universal binaries?

I would really recommend not doing this as the internals of the pbxproj file are dependent on the version of Xcode and this may break things unexpectedly. You can install the older SDKs under Xcode 3.2 and target them without having to downgrade.

Universal binaries appeared in 10.3.9 but supporting that far back would be much more trouble than it's worth.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #12
Mac OS X 10.0.0 supports fat binaries...
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2009.10
Post: #13
AnotherJake Wrote:You can grab all the events in full screen by overriding NSApplication's sendEvent method.

Why? is the way to use NSOpenGLView for both window and full screen mode?

Can you explain by giving an example NSApplication's overriding?

thank you
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #14
Ariel Wrote:Why? is the way to use NSOpenGLView for both window and full screen mode?
I don't know how it is in >=10.5 but in lower versions you don't get all the input events you might want in full screen.

Ariel Wrote:Can you explain by giving an example NSApplication's overriding?

- Make a subclass of NSApplication.
- Get info on your target. Under the Properties tab, set Principal class to whatever subclass you just made.
- Add this to your subclass:
Code:
- (void)sendEvent:(NSEvent *)event
{
    NSEventType type = [event type];
    switch (type)
    {
        case NSLeftMouseDown:
        {
            NSLog(@"left mouse down");
            break;
        }
    }
    [super sendEvent:event];
}
Quote this message in a reply
Member
Posts: 21
Joined: 2009.12
Post: #15
There's other cool things you can do from NSApplication, too. As someone new to Cocoa, most of my initial confusion stemmed from the fact that I didn't fully understand what Cocoa and Interface Builder were doing for me behind the scenes.

In fact, I would highly recommend the following links to any experienced programmer looking to get into Cocoa development.

Objective-C. What's that about?
What's going on behind the scenes, and how can I intervene?
How to load a NIB file

These three links alone, answered 90% of my questions.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Cocoa/OpenGL drawing full-screen problem ultitech 5 8,535 Jan 13, 2011 01:11 PM
Last Post: SethWillits
  Carbon events in windowed/full screen mode. Help needed. Anton Petrov 1 3,809 Dec 18, 2008 05:35 AM
Last Post: DoG
  Full Screen Event Handling kodex 4 4,858 Jun 27, 2008 08:37 PM
Last Post: OneSadCookie
  Mouse Events in NSView Chandhu 1 4,200 Feb 28, 2008 02:08 AM
Last Post: kuon_
  Full-screen without OpenGL George Marlin 2 3,123 May 11, 2007 01:38 PM
Last Post: George Marlin