NSWindow frame message not returning correct values after moving the window
Hi,
I've noticed that if I move the window and then call [window frame], the values returned are the same as those before the window was moved. I can't seem to find any way to get the correct and up to date window position through Cocoa.
The only workaround I found was to call:
GetWindowBounds([window windowRef], kWindowContentRgn, &cont);
Is there a better way of doing this?
More importantly, do I even need to do this? The main reason I need this is to find the center of the window so I can reposition the mouse to the center to prevent the app from losing focus if the user clicks a mouse button.
And is there a graceful way to release the mouse if the user hits Cmd-Tab? Can I somehow detect this from the application to release the mouse and unhide it if it was hidden?
Thanks,
Svarog
I've noticed that if I move the window and then call [window frame], the values returned are the same as those before the window was moved. I can't seem to find any way to get the correct and up to date window position through Cocoa.
The only workaround I found was to call:
GetWindowBounds([window windowRef], kWindowContentRgn, &cont);
Is there a better way of doing this?
More importantly, do I even need to do this? The main reason I need this is to find the center of the window so I can reposition the mouse to the center to prevent the app from losing focus if the user clicks a mouse button.
And is there a graceful way to release the mouse if the user hits Cmd-Tab? Can I somehow detect this from the application to release the mouse and unhide it if it was hidden?
Thanks,
Svarog
You might be better of making a CGEventTap and dropping mouse pressed event.
Sir, e^iπ + 1 = 0, hence God exists; reply!
As discussed on IRC, the window -frame misbehavior appears to be caused by your app not having a CGS connection due to you not starting up in the usual manner -- if you can make your window activate, I'm sure -frame will start working too.
You can detect your application being made inactive in the NSApplication delegate.
You can detect your application being made inactive in the NSApplication delegate.
OneSadCookie Wrote:As discussed on IRC, the window -frame misbehavior appears to be caused by your app not having a CGS connection due to you not starting up in the usual manner -- if you can make your window activate, I'm sure -frame will start working too.
You can detect your application being made inactive in the NSApplication delegate.
I've ran into the same problem when using the Interface Builder to create a nib file. However I've finally found what the problem is. I was on a completely wrong track.
The problem lies with the nextEventMatchingMask message.
If I manually handle all the events, certain things don't get updated.
After adding [NSApp sendEvent: event] to forward the events to other objects everything worked correctly.
I did come across something else that's a bit of a pain. I can work around it but I'm curious as to why it doesn't work. Maybe I should start a new thread for that?
Basically if I spawn off a separate thread for event handling using [NSThread detachNewThreadSelector...], [NSApp nextEventMatchingMask...] always returns nil.
However if I just call [NSApp nextEventMatchingMask...] from the main thread it works fine.
I've setup the NSAutoreleasePool in the thread, is there anything else that I might be missing?
Svarog
Events are always dispatched on the main thread in Mac OS X.
OneSadCookie Wrote:Events are always dispatched on the main thread in Mac OS X.
Yes but NSApp is a global variable - I thought that the nextEventMatchingMask message would work on it all the same regardless of which thread I call it from.
Also SDL appears to create a separate thread for event handling although it's using pthreads whereas I'm was trying to use NSThread.
Svarog
To say it more clearly: you cannot handle events from any thread other than the main thread on Mac OS X.
I don't know what SDL is doing, or whether it works on Mac OS X, but I suspect that it's not doing what you think it is.
I don't know what SDL is doing, or whether it works on Mac OS X, but I suspect that it's not doing what you think it is.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Die-hard vertex-sorting function not accepting input values! | mikey | 6 | 3,249 |
Oct 31, 2009 03:36 AM Last Post: mikey |
|
| Previous frame inner to this frame (corrupt stack?) | wyrmmage | 9 | 6,449 |
Nov 29, 2006 05:14 PM Last Post: wyrmmage |
|
| Converting integer/numeric values to Strings | vnvrymdreglage | 5 | 3,193 |
Oct 23, 2006 07:18 PM Last Post: vnvrymdreglage |
|
| [NSWindow center] not centering | maaaaark | 9 | 6,471 |
Mar 13, 2005 12:34 PM Last Post: maaaaark |
|
| Adding message handlers | rove | 3 | 3,676 |
Mar 13, 2005 08:53 AM Last Post: sealfin |
|

