Changeset 1285 in vbox
- Timestamp:
- Mar 7, 2007 5:34:38 AM (18 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile
r1178 r1285 128 128 src/linux/keyboard.c 129 129 endif 130 131 VirtualBox_SOURCES.darwin = \ 132 src/darwin/DarwinKeyboard.cpp 130 133 131 134 VirtualBox_DEFS = VBOX_GUI_SEPARATE_VM_PROCESS … … 175 178 endif 176 179 endif 180 VirtualBox_LDFLAGS.darwin = -framework IOKit 177 181 VirtualBox_LIBS.win = \ 178 182 $(PATH_SDK_WINPSDK_LIB)/Htmlhelp.Lib \ -
trunk/src/VBox/Frontends/VirtualBox/include/QIHotKeyEdit.h
r382 r1285 25 25 26 26 #include <qlabel.h> 27 #ifdef Q_WS_MAC 28 #include <Carbon/Carbon.h> 29 #endif 30 27 31 28 32 class QIHotKeyEdit : public QLabel … … 33 37 34 38 QIHotKeyEdit( QWidget * parent, const char * name = 0 ); 39 virtual ~QIHotKeyEdit(); 35 40 36 41 void setKey( int keyval ); … … 55 60 #elif defined(Q_WS_X11) 56 61 bool x11Event( XEvent *event ); 62 #elif defined(Q_WS_MAC) 63 static pascal OSStatus darwinEventHandlerProc( EventHandlerCallRef inHandlerCallRef, 64 EventRef inEvent, void *inUserData ); 65 bool darwinKeyboardEvent( EventRef inEvent ); 57 66 #endif 58 67 … … 71 80 QColorGroup true_acg; 72 81 82 #if defined(Q_WS_MAC) 83 /** Event handler reference. NULL if the handler isn't installed. */ 84 EventHandlerRef m_darwinEventHandlerRef; 85 /** The current modifier key mask. Used to figure out which modifier 86 * key was pressed when we get a kEventRawKeyModifiersChanged event. */ 87 UInt32 m_darwinKeyModifiers; 88 #endif 89 73 90 static const char *NoneSymbName; 74 91 }; -
trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h
r896 r1285 36 36 #include <qkeysequence.h> 37 37 38 #if defined (Q_WS_MAC) 39 # include <Carbon/Carbon.h> 40 #endif 41 38 42 class VBoxConsoleWnd; 39 43 class MousePointerChangeEvent; … … 103 107 #elif defined(Q_WS_X11) 104 108 bool x11Event (XEvent *event ); 109 #elif defined(Q_WS_MAC) 110 bool darwinKeyboardEvent (EventRef inEvent); 111 void darwinGrabKeyboardEvents (bool fGrab); 105 112 #endif 106 113 … … 116 123 117 124 void focusEvent (bool focus); 118 bool keyEvent (int key, uint8_t scan, int flags );125 bool keyEvent (int key, uint8_t scan, int flags, wchar_t *aUniKey = NULL); 119 126 bool mouseEvent (int aType, const QPoint &aPos, const QPoint &aGlobalPos, 120 127 ButtonState aButton, … … 210 217 #endif 211 218 219 #if defined(Q_WS_MAC) 220 /** Event handler reference. NULL if the handler isn't installed. */ 221 EventHandlerRef m_darwinEventHandlerRef; 222 /** The current modifier key mask. Used to figure out which modifier 223 * key was pressed when we get a kEventRawKeyModifiersChanged event. */ 224 UInt32 m_darwinKeyModifiers; 225 #endif 226 212 227 #if defined (VBOX_GUI_USE_REFRESH_TIMER) 213 228 QPixmap pm; … … 223 238 static LRESULT CALLBACK lowLevelKeyboardProc (int nCode, 224 239 WPARAM wParam, LPARAM lParam); 240 #elif defined (Q_WS_MAC) 241 static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef, 242 EventRef inEvent, void *inUserData); 225 243 #endif 226 244 -
trunk/src/VBox/Frontends/VirtualBox/src/QIHotKeyEdit.cpp
r382 r1285 62 62 #endif 63 63 64 #ifdef Q_WS_MAC 65 #include "DarwinKeyboard.h" 66 #endif 67 64 68 65 69 #ifdef Q_WS_WIN32 … … 129 133 p.setActive( p.inactive() ); 130 134 setPalette( p ); 135 136 #ifdef Q_WS_MAC 137 m_darwinKeyModifiers = GetCurrentEventKeyModifiers(); 138 139 EventTypeSpec eventTypes[4]; 140 eventTypes[0].eventClass = kEventClassKeyboard; 141 eventTypes[0].eventKind = kEventRawKeyDown; 142 eventTypes[1].eventClass = kEventClassKeyboard; 143 eventTypes[1].eventKind = kEventRawKeyUp; 144 eventTypes[2].eventClass = kEventClassKeyboard; 145 eventTypes[2].eventKind = kEventRawKeyRepeat; 146 eventTypes[3].eventClass = kEventClassKeyboard; 147 eventTypes[3].eventKind = kEventRawKeyModifiersChanged; 148 149 EventHandlerUPP eventHandler = ::NewEventHandlerUPP( QIHotKeyEdit::darwinEventHandlerProc ); 150 151 m_darwinEventHandlerRef = NULL; 152 ::InstallApplicationEventHandler( eventHandler, RT_ELEMENTS( eventTypes ), &eventTypes[0], 153 this, &m_darwinEventHandlerRef ); 154 ::DisposeEventHandlerUPP( eventHandler ); 155 ::DarwinGrabKeyboard( false /* just modifiers */ ); 156 157 #endif 158 159 } 160 161 QIHotKeyEdit::~QIHotKeyEdit() 162 { 163 #ifdef Q_WS_MAC 164 ::DarwinReleaseKeyboard(); 165 ::RemoveEventHandler( m_darwinEventHandlerRef ); 166 m_darwinEventHandlerRef = NULL; 167 #endif 131 168 } 132 169 … … 226 263 else 227 264 name = QString( "<key_%1>" ).arg( key ); 265 #elif defined(Q_WS_MAC) 266 UInt32 modMask = DarwinKeyCodeToDarwinModifierMask( key ); 267 switch ( modMask ) { 268 case shiftKey: 269 case optionKey: 270 case controlKey: 271 case cmdKey: 272 name = tr("Left "); 273 break; 274 case rightShiftKey: 275 case rightOptionKey: 276 case rightControlKey: 277 case kEventKeyModifierRightCmdKeyMask: 278 name = tr("Right "); 279 break; 280 default: 281 AssertMsgFailedReturn(( "modMask=%#x\n", modMask ), QString()); 282 } 283 switch ( modMask ) { 284 case shiftKey: 285 case rightShiftKey: 286 name += QChar( kShiftUnicode ); 287 break; 288 case optionKey: 289 case rightOptionKey: 290 name += QChar( kOptionUnicode ); 291 break; 292 case controlKey: 293 case rightControlKey: 294 name += QChar( kControlUnicode ); 295 break; 296 case cmdKey: 297 case kEventKeyModifierRightCmdKeyMask: 298 name += QChar( kCommandUnicode ); 299 break; 300 } 228 301 #else 229 302 name = QString( "<key_%1>" ).arg( key ); … … 259 332 IsMiscFunctionKey( ks ) 260 333 ); 334 #elif defined(Q_WS_MAC) 335 UInt32 modMask = ::DarwinKeyCodeToDarwinModifierMask( k ); 336 switch ( modMask ) { 337 case shiftKey: 338 case optionKey: 339 case controlKey: 340 case rightShiftKey: 341 case rightOptionKey: 342 case rightControlKey: 343 case cmdKey: 344 case kEventKeyModifierRightCmdKeyMask: 345 return true; 346 default: 347 return false; 348 } 261 349 #else 262 350 Q_UNUSED( k ); … … 367 455 } 368 456 457 #elif defined(Q_WS_MAC) 458 459 /* static */ 460 pascal OSStatus QIHotKeyEdit::darwinEventHandlerProc( EventHandlerCallRef inHandlerCallRef, 461 EventRef inEvent, void *inUserData ) 462 { 463 QIHotKeyEdit *edit = (QIHotKeyEdit *)inUserData; 464 UInt32 EventClass = ::GetEventClass( inEvent ); 465 if (EventClass == kEventClassKeyboard) 466 { 467 if (edit->darwinKeyboardEvent( inEvent )) 468 return 0; 469 } 470 return CallNextEventHandler (inHandlerCallRef, inEvent); 471 } 472 473 #ifdef DEBUG_bird 474 # include <iprt/stream.h> 475 #endif 476 477 bool QIHotKeyEdit::darwinKeyboardEvent( EventRef inEvent ) 478 { 479 UInt32 eventKind = ::GetEventKind( inEvent ); 480 switch ( eventKind ) { 481 /*case kEventRawKeyDown: 482 case kEventRawKeyUp: 483 case kEventRawKeyRepeat:*/ 484 case kEventRawKeyModifiersChanged: { 485 UInt32 modifierMask = 0; 486 ::GetEventParameter( inEvent, kEventParamKeyModifiers, typeUInt32, NULL, 487 sizeof( modifierMask ), NULL, &modifierMask ); 488 489 modifierMask = ::DarwinAdjustModifierMask(modifierMask); 490 UInt32 changed = m_darwinKeyModifiers ^ modifierMask; 491 #ifdef DEBUG_bird 492 RTPrintf("old=%04x new=%04x changed=%04x %04x %04x\n", 493 m_darwinKeyModifiers, modifierMask, changed, GetCurrentEventKeyModifiers(), GetCurrentKeyModifiers()); 494 #endif 495 m_darwinKeyModifiers = modifierMask; 496 497 // skip key releases 498 if ( changed && ( changed & modifierMask ) ) 499 break; 500 501 // convert to keycode and skip keycodes we don't care about. 502 unsigned keyCode = ::DarwinModifierMaskToDarwinKeycode( changed ); 503 RTPrintf("keyCode=%#x valid=%d\n", keyCode, isValidKey( keyCode )); 504 if ( !keyCode || keyCode == ~0U || !isValidKey( keyCode ) ) 505 break; 506 507 // update key current key. 508 keyval = keyCode; 509 symbname = QIHotKeyEdit::keyName( keyCode ); 510 updateText(); 511 break; //return true; 512 } 513 break; 514 } 515 return false; 516 } 517 518 #else 519 # warning "Port me!" 369 520 #endif 370 521 -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp
r1007 r1285 78 78 #endif 79 79 80 #if defined (Q_WS_MAC) 81 # include "DarwinKeyboard.h" 82 #endif /* defined (Q_WS_MAC) */ 83 80 84 #if defined (VBOX_GUI_USE_REFRESH_TIMER) 81 85 enum { UPDATE_FREQ = 1000 / 60 }; // a-la 60Hz … … 99 103 100 104 #endif 105 106 #if defined (Q_WS_MAC) 107 108 /** 109 * Event handler callback for Mac OS X. 110 */ 111 /* static */ 112 pascal OSStatus VBoxConsoleView::darwinEventHandlerProc(EventHandlerCallRef inHandlerCallRef, 113 EventRef inEvent, void *inUserData) 114 { 115 VBoxConsoleView *view = (VBoxConsoleView *)inUserData; 116 UInt32 EventClass = ::GetEventClass (inEvent); 117 if (EventClass == kEventClassKeyboard) 118 { 119 if ( view->darwinKeyboardEvent (inEvent) 120 && ::GetEventKind (inEvent) != kEventRawKeyModifiersChanged) 121 return 0; 122 } 123 return CallNextEventHandler (inHandlerCallRef, inEvent); 124 } 125 126 #endif /* Q_WS_MAC */ 101 127 102 128 /** Guest mouse pointer shape change event. */ … … 358 384 , mAlphaCursor (NULL) 359 385 #endif 386 #if defined(Q_WS_MAC) 387 , m_darwinEventHandlerRef (NULL) 388 , m_darwinKeyModifiers (0) 389 #endif 360 390 { 361 391 Assert (!cconsole.isNull() && … … 752 782 return true; 753 783 } 754 /// @todo (dmik) not currently used, but may become necessary later 755 // case VBoxDefs::RepaintEventType: { 756 // VBoxRepaintEvent *re = (VBoxRepaintEvent *) e; 757 // viewport()->repaint (re->x(), re->y(), re->width(), re->height(), false); 758 // cconsole.GetDisplay().UpdateCompleted(); 759 // return true; 760 // } 784 785 #ifdef Q_WS_MAC /* see VBoxQImageFrameBuffer::NotifyUpdate. */ 786 case VBoxDefs::RepaintEventType: 787 { 788 VBoxRepaintEvent *re = (VBoxRepaintEvent *) e; 789 viewport()->repaint (re->x(), re->y(), re->width(), re->height(), false); 790 /*cconsole.GetDisplay().UpdateCompleted(); - the event was acked already */ 791 return true; 792 } 793 #endif /* Q_WS_MAC */ 761 794 762 795 case VBoxDefs::MousePointerChangeEventType: … … 983 1016 break; 984 1017 } 985 #endif 1018 #endif /* defined (Q_WS_WIN32) */ 1019 #if defined (Q_WS_MAC) 1020 /* 1021 * Install/remove the keyboard event handler. 1022 */ 1023 case QEvent::WindowActivate: 1024 darwinGrabKeyboardEvents (true); 1025 break; 1026 case QEvent::WindowDeactivate: 1027 darwinGrabKeyboardEvents (false); 1028 break; 1029 #endif /* defined (Q_WS_MAC) */ 986 1030 case QEvent::Resize: 987 1031 { … … 1282 1326 } 1283 1327 1328 #elif defined (Q_WS_MAC) 1329 1330 /** 1331 * Invoked by VBoxConsoleView::darwinEventHandlerProc when it gets a raw keyboard event. 1332 * 1333 * @param inEvent The keyboard event. 1334 * 1335 * @return true if the key was processed, false if it wasn't processed and should be passed on. 1336 */ 1337 bool VBoxConsoleView::darwinKeyboardEvent (EventRef inEvent) 1338 { 1339 bool ret = false; 1340 UInt32 EventKind = ::GetEventKind (inEvent); 1341 if (EventKind != kEventRawKeyModifiersChanged) 1342 { 1343 /* convert keycode to set 1 scan code. */ 1344 UInt32 keyCode = ~0U; 1345 ::GetEventParameter (inEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(keyCode), NULL, &keyCode); 1346 unsigned scanCode = ::DarwinKeycodeToSet1Scancode (keyCode); 1347 if (scanCode) 1348 { 1349 /* calc flags. */ 1350 int flags = 0; 1351 UInt32 EventKind = ::GetEventKind (inEvent); 1352 if (EventKind == kEventRawKeyDown) 1353 flags |= KeyPressed; 1354 if (scanCode & 0x8000) /* modifiers */ 1355 { 1356 flags |= KeyPressed; 1357 scanCode &= ~0x8000; 1358 } 1359 if (scanCode & 0x80) 1360 { 1361 flags |= KeyExtended; 1362 scanCode &= ~0x80; 1363 } 1364 /** @todo KeyPause, KeyPrint. */ 1365 1366 /* get the keycode and unicode string (if present). */ 1367 UInt32 keyCode = ~0; 1368 ::GetEventParameter (inEvent, kEventParamKeyCode, typeUInt32, NULL, 1369 sizeof (keyCode), NULL, &keyCode); 1370 AssertCompileSize(wchar_t, 2); 1371 AssertCompileSize(UniChar, 2); 1372 wchar_t ucs[32]; 1373 if (::GetEventParameter (inEvent, kEventParamKeyUnicodes, typeUnicodeText, NULL, 1374 sizeof (ucs), NULL, &ucs[0]) != 0) 1375 ucs[0] = 0; 1376 1377 ret = keyEvent (keyCode, scanCode, flags, ucs[0] ? ucs : NULL); 1378 } 1379 } 1380 else 1381 { 1382 /* May contain multiple modifier changes, kind of annoying. */ 1383 UInt32 newMask = 0; 1384 ::GetEventParameter (inEvent, kEventParamKeyModifiers, typeUInt32, NULL, 1385 sizeof (newMask), NULL, &newMask); 1386 UInt32 changed = newMask ^ m_darwinKeyModifiers; 1387 if (changed) 1388 { 1389 for (Uint32 bit = 0; bit < 32; bit++) 1390 { 1391 if (!(changed & (1 << bit))) 1392 continue; 1393 unsigned scanCode = ::DarwinModifierMaskToSet1Scancode (1 << bit); 1394 if (!scanCode) 1395 continue; 1396 1397 unsigned flags = (newMask & (1 << bit)) ? KeyPressed : 0; 1398 if (scanCode & 0x80) 1399 { 1400 flags |= KeyExtended; 1401 scanCode &= ~0x80; 1402 } 1403 keyEvent (0, scanCode, flags); 1404 } 1405 } 1406 1407 m_darwinKeyModifiers = newMask; 1408 1409 /* ret is intentionally false. */ 1410 } 1411 1412 return ret; 1413 } 1414 1415 1416 /** 1417 * Installs or removes the keyboard event handler. 1418 * 1419 * @param fGrab True if we're to grab the events, false if we're not to. 1420 */ 1421 void VBoxConsoleView::darwinGrabKeyboardEvents (bool fGrab) 1422 { 1423 if (fGrab) 1424 { 1425 ::SetMouseCoalescingEnabled (false, NULL); //?? 1426 ::CGSetLocalEventsSuppressionInterval (0.0); //?? 1427 1428 EventTypeSpec eventTypes[4]; 1429 eventTypes[0].eventClass = kEventClassKeyboard; 1430 eventTypes[0].eventKind = kEventRawKeyDown; 1431 eventTypes[1].eventClass = kEventClassKeyboard; 1432 eventTypes[1].eventKind = kEventRawKeyUp; 1433 eventTypes[2].eventClass = kEventClassKeyboard; 1434 eventTypes[2].eventKind = kEventRawKeyRepeat; 1435 eventTypes[3].eventClass = kEventClassKeyboard; 1436 eventTypes[3].eventKind = kEventRawKeyModifiersChanged; 1437 1438 EventHandlerUPP eventHandler = ::NewEventHandlerUPP (VBoxConsoleView::darwinEventHandlerProc); 1439 1440 m_darwinEventHandlerRef = NULL; 1441 ::InstallApplicationEventHandler (eventHandler, RT_ELEMENTS (eventTypes), &eventTypes[0], 1442 this, &m_darwinEventHandlerRef); 1443 ::DisposeEventHandlerUPP (eventHandler); 1444 } 1445 else if (m_darwinEventHandlerRef) 1446 { 1447 ::RemoveEventHandler (m_darwinEventHandlerRef); 1448 m_darwinEventHandlerRef = NULL; 1449 } 1450 } 1451 1284 1452 #endif 1285 1453 … … 1396 1564 * @scan hardware scan code 1397 1565 * @flags flags, a combination of Key* constants 1566 * @aUniKey Unicode translation of the key. Optional. 1398 1567 * 1399 1568 * @return true to consume the event and false to pass it to Qt 1400 1569 */ 1401 bool VBoxConsoleView::keyEvent (int key, uint8_t scan, int flags )1570 bool VBoxConsoleView::keyEvent (int key, uint8_t scan, int flags, wchar_t *aUniKey/* = NULL*/) 1402 1571 { 1403 1572 // char bbbuf[256]; … … 1589 1758 } 1590 1759 } 1760 #elif defined (Q_WS_MAC) 1761 if (aUniKey && aUniKey[0] && !aUniKey[1]) 1762 processed = processHotKey (QKeySequence (UNICODE_ACCEL + 1763 QChar (aUniKey [0]).upper().unicode()), 1764 mainwnd->menuBar()); 1591 1765 #endif 1592 1766 // grab the key from Qt if processed, or pass it to Qt otherwise … … 1959 2133 * by QWidget::grabKeyboard()) because the latter causes problems under 1960 2134 * metacity 2.16 (in particular, due to a bug, a window cannot be moved 1961 * using the mouse if it is currently grabing the keyboard). */ 2135 * using the mouse if it is currently grabing the keyboard). On Mac OS X, 2136 * we use the Qt methods + disabling global hot keys + watching modifiers 2137 * (for right/left separation). */ 1962 2138 #if defined (Q_WS_WIN32) 1963 2139 /**/ … … 1970 2146 XUngrabKey (x11Display(), AnyKey, AnyModifier, 1971 2147 topLevelWidget()->winId()); 2148 #elif defined (Q_WS_MAC) 2149 if (capture) 2150 { 2151 grabKeyboard(); 2152 ::DarwinGrabKeyboard (true); 2153 } 2154 else 2155 { 2156 ::DarwinReleaseKeyboard(); 2157 releaseKeyboard(); 2158 } 1972 2159 #else 1973 2160 if (capture) -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp
r1062 r1285 999 999 /* 1000 1000 * set success to true even if we fail to discard the 1001 * current state later -- the con osle window will be1001 * current state later -- the console window will be 1002 1002 * closed anyway 1003 1003 */ -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxFrameBuffer.cpp
r470 r1285 253 253 BOOL *aFinished) 254 254 { 255 #ifdef Q_WS_MAC 256 /* we're not on the GUI thread and update() isn't thread safe on Qt 3.3.x 257 on the Mac (4.2.x is), so post the event instead. */ 258 QApplication::postEvent (mView, 259 new VBoxRepaintEvent (aX, aY, aW, aH)); 260 261 #else /* !Q_WS_MAC */ 255 262 /* we're not on the GUI thread, so update() instead of repaint()! */ 256 263 mView->viewport()->update (aX - mView->contentsX(), 257 264 aY - mView->contentsY(), 258 265 aW, aH); 266 #endif /* !Q_WS_MAC */ 259 267 /* the update has been finished, return TRUE */ 260 268 *aFinished = TRUE; -
trunk/src/VBox/Frontends/VirtualBox/src/VMGlobalSettings.cpp
r382 r1285 46 46 hostkey = 0xffe4; // XK_Control_R 47 47 // hostkey = 65514; // XK_Alt_R 48 #elif defined (Q_WS_MAC) 49 hostkey = 0x36; // QZ_RMETA 50 // hostkey = 0x3e; // QZ_RCTRL 51 // hostkey = 0x3d; // QZ_RALT 48 52 #else 53 # warning "port me!" 49 54 hostkey = 0; 50 55 #endif
Note:
See TracChangeset
for help on using the changeset viewer.