Changeset 10340
- Timestamp:
- 06/12/09 12:00:08 (4 years ago)
- Location:
- OpenSceneGraph/trunk/src/osgViewer
- Files:
-
- 2 modified
-
DarwinUtils.mm (modified) (3 diffs)
-
GraphicsWindowCocoa.mm (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgViewer/DarwinUtils.mm
r10208 r10340 13 13 #include <Cocoa/Cocoa.h> 14 14 15 @interface MenubarToggler : NSObject { 16 17 } 18 19 -(void) show: (ID) data; 20 -(void) hide: (ID) data; 21 22 @end 23 24 @implementation MenubarToggler 25 26 27 28 -(void) hide:(ID) data 29 { 30 OSErr error = SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); 31 if (error) { 32 osg::notify(osg::DEBUG_INFO) << "MenubarToggler::hide failed with " << error << std::endl; 33 } 34 } 35 36 37 -(void) show:(ID) data 38 { 39 OSErr error = SetSystemUIMode(kUIModeNormal, 0); 40 if (error) { 41 osg::notify(osg::DEBUG_INFO) << "MenubarToggler::show failed with " << error << std::endl; 42 } 43 } 44 45 46 @end 47 15 48 namespace osgDarwin { 16 49 … … 84 117 // iterate through all open windows and check, if they intersect the area occupied by the menubar/dock, and if so, hide the menubar/dock 85 118 119 86 120 void MenubarController::update() 87 121 { 88 OSErr error(noErr);89 122 unsigned int windowsCoveringMenubarArea = 0; 90 123 unsigned int windowsIntersectingMainScreen = 0; … … 116 149 } 117 150 118 // see http://developer.apple.com/technotes/tn2002/tn2062.html for hiding the dock+menubar 119 120 if (windowsCoveringMenubarArea && _menubarShown) 121 error = SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); 122 123 if (!windowsCoveringMenubarArea && !_menubarShown) 124 error = SetSystemUIMode(kUIModeNormal, 0); 125 _menubarShown = !windowsCoveringMenubarArea; 126 127 // osg::notify(osg::DEBUG_INFO) << "MenubarController:: " << windowsCoveringMenubarArea << " windows covering the menubar/dock area, " << windowsIntersectingMainScreen << " intersecting mainscreen" << std::endl; 151 // if we use the cocoa implementation then we have a NSRunLoop in place, and so we can use the deferred menubar-toggling which is thread safe 152 153 #ifdef USE_DARWIN_COCOA_IMPLEMENTATION 154 155 // SetSystemUIMode is not threadsafe, you'll get crashes if you call this method from other threads 156 // so use a small NSObject to switch the menubar on the main thread via performSelectorOnMainThread 157 158 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 159 if (windowsCoveringMenubarArea && _menubarShown) 160 { 161 162 //error = SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); 163 MenubarToggler* toggler = [[MenubarToggler alloc] init]; 164 [toggler performSelectorOnMainThread: @selector(hide:) withObject:NULL waitUntilDone: YES]; 165 [toggler autorelease]; 166 } 167 if (!windowsCoveringMenubarArea && !_menubarShown) 168 { 169 //error = SetSystemUIMode(kUIModeNormal, 0); 170 MenubarToggler* toggler = [[MenubarToggler alloc] init]; 171 [toggler performSelectorOnMainThread: @selector(show:) withObject:NULL waitUntilDone: YES]; 172 [toggler autorelease]; 173 } 174 [pool release]; 175 176 #else 177 178 OSErr error; 179 180 // see http://developer.apple.com/technotes/tn2002/tn2062.html for hiding the dock+menubar 181 if (windowsCoveringMenubarArea && _menubarShown) 182 { 183 error = SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); 184 } 185 else 186 { 187 error = SetSystemUIMode(kUIModeNormal, 0); 188 } 189 #endif 190 191 _menubarShown = !windowsCoveringMenubarArea; 128 192 } 129 193 -
OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowCocoa.mm
r10285 r10340 20 20 #include "DarwinUtils.h" 21 21 22 //#define DEBUG_OUT(s) std::cout << "GraphicsWindowCocoa :: " << s << std::endl;23 24 #define DEBUG_OUT(s) ;22 #define DEBUG_OUT(s) std::cout << "GraphicsWindowCocoa :: " << s << std::endl; 23 24 //#define DEBUG_OUT(s) ; 25 25 26 26 static bool s_quit_requested = false; … … 389 389 - (void) mouseMoved:(NSEvent*)theEvent 390 390 { 391 DEBUG_OUT("Mouse moved");392 391 NSPoint converted_point = [self getLocalPoint: theEvent]; 392 DEBUG_OUT("Mouse moved" << converted_point.x << "/" << converted_point.y); 393 393 _win->getEventQueue()->mouseMotion(converted_point.x, converted_point.y); 394 394 } … … 606 606 if (!_win) return; 607 607 608 DEBUG_OUT("middleMouseDown "); 609 608 610 NSPoint converted_point = [self getLocalPoint: theEvent]; 609 611 … … 621 623 { 622 624 if (!_win) return; 625 626 DEBUG_OUT("extraMouseDown btn: " << button_number); 623 627 624 628 NSPoint converted_point = [self getLocalPoint: theEvent]; … … 1037 1041 if (mbc) mbc->detachWindow(this); 1038 1042 1039 if (_window) {1040 [_window close];1041 [_window release];1042 }1043 1044 1043 if (_view) { 1045 1044 [_view setGraphicsWindowCocoa: NULL]; 1046 1045 } 1046 1047 if (_window) { 1048 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 1049 1050 // we have to close + release the window in the main-thread 1051 1052 [_window performSelectorOnMainThread: @selector(close) withObject:NULL waitUntilDone: YES]; 1053 [_window performSelectorOnMainThread: @selector(release) withObject:NULL waitUntilDone: YES]; 1054 [pool release]; 1055 } 1047 1056 1048 1057 _window = NULL; 1049 _view = NULL; 1050 1058 _view = NULL; 1051 1059 } 1052 1060
