Full screen mouse events
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:
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:
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.
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.
You can grab all the events in full screen by overriding NSApplication's sendEvent method.
If you're using 10.5's -[NSView enterFullScreenMode:options:] ( and if you aren't, why not?
) then mouse events work normally.
) then mouse events work normally.
AnotherJake Wrote:You can grab all the events in full screen by overriding NSApplication's sendEvent method.
Thanks, that works beautifully!
OneSadCookie Wrote:If you're using 10.5's -[NSView enterFullScreenMode:options:] ( and if you aren't, why not?) 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).
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.
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.
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.
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?).
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?).
Moderator note: Mister T was stuck in approval queue for new members before OSC replied. Sorry for any confusion, Mister T.
The first few posts of new members have to be moderated to filter out spam.
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!
]
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!
]
No problem. I knew that was going to happen from the registration email. 
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!

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: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.
Mac OS X 10.0.0 supports fat binaries...
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
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];
}
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.
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.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Cocoa/OpenGL drawing full-screen problem | ultitech | 5 | 7,046 |
Jan 13, 2011 01:11 PM Last Post: SethWillits |
|
| Carbon events in windowed/full screen mode. Help needed. | Anton Petrov | 1 | 3,169 |
Dec 18, 2008 05:35 AM Last Post: DoG |
|
| Full Screen Event Handling | kodex | 4 | 4,228 |
Jun 27, 2008 08:37 PM Last Post: OneSadCookie |
|
| Mouse Events in NSView | Chandhu | 1 | 3,536 |
Feb 28, 2008 02:08 AM Last Post: kuon_ |
|
| Full-screen without OpenGL | George Marlin | 2 | 2,623 |
May 11, 2007 01:38 PM Last Post: George Marlin |
|

