From 9744dbfc0b8a88ec3d784b3f8e35b4829fccdafe Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 9 Oct 2006 23:47:08 +0000 Subject: [PATCH] a bit more osx keyboard/mouse support --- panda/src/osxdisplay/osxGraphicsWindow.cxx | 22 +++++++---- panda/src/putil/keyboardButton.cxx | 2 + panda/src/putil/keyboardButton.h | 1 + panda/src/tform/trackball.cxx | 44 ++++++++++++++++------ 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/panda/src/osxdisplay/osxGraphicsWindow.cxx b/panda/src/osxdisplay/osxGraphicsWindow.cxx index 34e884ea37..e3f9732fc3 100644 --- a/panda/src/osxdisplay/osxGraphicsWindow.cxx +++ b/panda/src/osxdisplay/osxGraphicsWindow.cxx @@ -1325,7 +1325,7 @@ void osxGraphicsWindow::SystemSetWindowForground(bool forground) case 121: nk = KeyboardButton::page_down(); break; case 115: nk = KeyboardButton::home(); break; case 119: nk = KeyboardButton::end(); break; - // case : nk = KeyboardButton::insert(); break; + case 114: nk = KeyboardButton::help(); break; case 117: nk = KeyboardButton::del(); break; // case 71: nk = KeyboardButton::num_lock() break; @@ -1358,13 +1358,18 @@ void osxGraphicsWindow::SystemSetWindowForground(bool forground) case 44: nk = KeyboardButton::ascii_key('/'); break; default: - // printf (" Untranslated KeyCode: %lu (0x%lX)\n", key, key); - // not sure this is right .. but no mapping for keypad and such - // this at least does a best gess.. + if (osxdisplay_cat.is_debug()) { + osxdisplay_cat.debug() + << " Untranslated KeyCode: " << key + << " (0x" << hex << key << dec << ")\n"; + } - char charCode = 0; - if(GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, nil, sizeof( charCode ), nil, &charCode ) == noErr) - nk = KeyboardButton::ascii_key(charCode); + // not sure this is right .. but no mapping for keypad and such + // this at least does a best gess.. + + char charCode = 0; + if(GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, nil, sizeof( charCode ), nil, &charCode ) == noErr) + nk = KeyboardButton::ascii_key(charCode); } return nk; } @@ -1386,6 +1391,9 @@ void osxGraphicsWindow::SystemSetWindowForground(bool forground) if ((changed & (controlKey | rightControlKey)) != 0) SendKeyEvent(KeyboardButton::control(),(newModifiers & (controlKey | rightControlKey)) != 0); + + if ((changed & cmdKey) != 0) + SendKeyEvent(KeyboardButton::meta(),(newModifiers & cmdKey) != 0); if ((changed & alphaLock) != 0) SendKeyEvent(KeyboardButton::caps_lock(),(newModifiers & alphaLock) != 0); diff --git a/panda/src/putil/keyboardButton.cxx b/panda/src/putil/keyboardButton.cxx index bcccd3b6c3..bca2e22f26 100644 --- a/panda/src/putil/keyboardButton.cxx +++ b/panda/src/putil/keyboardButton.cxx @@ -82,6 +82,7 @@ DEFINE_KEYBD_BUTTON_HANDLE(home) DEFINE_KEYBD_BUTTON_HANDLE(end) DEFINE_KEYBD_BUTTON_HANDLE(insert) DEFINE_KEYBD_BUTTON_HANDLE(del) +DEFINE_KEYBD_BUTTON_HANDLE(help) DEFINE_KEYBD_BUTTON_HANDLE(meta) DEFINE_KEYBD_BUTTON_HANDLE(caps_lock) DEFINE_KEYBD_BUTTON_HANDLE(shift_lock) @@ -142,6 +143,7 @@ init_keyboard_buttons() { ButtonRegistry::ptr()->register_button(_home, "home"); ButtonRegistry::ptr()->register_button(_end, "end"); ButtonRegistry::ptr()->register_button(_insert, "insert"); + ButtonRegistry::ptr()->register_button(_help, "help"); ButtonRegistry::ptr()->register_button(_shift, "shift"); ButtonRegistry::ptr()->register_button(_control, "control"); diff --git a/panda/src/putil/keyboardButton.h b/panda/src/putil/keyboardButton.h index 55dd598f1f..bcbd6dbe13 100644 --- a/panda/src/putil/keyboardButton.h +++ b/panda/src/putil/keyboardButton.h @@ -63,6 +63,7 @@ PUBLISHED: static ButtonHandle end(); static ButtonHandle insert(); static ButtonHandle del(); // delete is a C++ keyword. + static ButtonHandle help(); static ButtonHandle shift(); static ButtonHandle control(); diff --git a/panda/src/tform/trackball.cxx b/panda/src/tform/trackball.cxx index 884ddd8327..2d178ee974 100644 --- a/panda/src/tform/trackball.cxx +++ b/panda/src/tform/trackball.cxx @@ -25,6 +25,7 @@ #include "modifierButtons.h" #include "linmath_events.h" #include "mouseButton.h" +#include "keyboardButton.h" TypeHandle Trackball::_type_handle; @@ -32,8 +33,6 @@ TypeHandle Trackball::_type_handle; #define B1_MASK 0x01 #define B2_MASK 0x02 #define B3_MASK 0x04 -#define B4_MASK 0x08 -#define B5_MASK 0x10 //////////////////////////////////////////////////////////////////// // Function: Trackball::Constructor @@ -66,8 +65,14 @@ Trackball(const string &name) : watch_button(MouseButton::one()); watch_button(MouseButton::two()); watch_button(MouseButton::three()); - watch_button(MouseButton::four()); - watch_button(MouseButton::five()); + + // In OSX mode, we need to use the command and option key in + // conjunction with the (one) mouse button. We can go ahead and + // keep this code live in other platforms too; it doesn't do any + // harm. + watch_button(KeyboardButton::meta()); + watch_button(KeyboardButton::alt()); + watch_button(KeyboardButton::control()); } //////////////////////////////////////////////////////////////////// @@ -553,7 +558,30 @@ do_transmit_data(DataGraphTraverser *, const DataNodeTransmit &input, int this_button = 0; if (is_down(MouseButton::one())) { - this_button |= B1_MASK; + if (is_down(KeyboardButton::meta())) { + // Wait, the user is holding down the command key in + // conjunction with mouse button 1. This changes its meaning + // to either mouse 2 and/or mouse 3, according to whether the + // alt or control key is also held down. + + if (is_down(KeyboardButton::alt())) { + // Command + alt: B2 + B3. + this_button |= B2_MASK | B3_MASK; + + } else if (is_down(KeyboardButton::control())) { + // Command + control: B2. + this_button |= B2_MASK; + + } else { + // Command key by itself: B3. + this_button |= B3_MASK; + } + + } else { + // Without the command key, a mouse 1 button is a mouse 1 + // button. + this_button |= B1_MASK; + } } if (is_down(MouseButton::two())) { this_button |= B2_MASK; @@ -561,12 +589,6 @@ do_transmit_data(DataGraphTraverser *, const DataNodeTransmit &input, if (is_down(MouseButton::three())) { this_button |= B3_MASK; } - if (is_down(MouseButton::four())) { - this_button |= B4_MASK; - } - if (is_down(MouseButton::five())) { - this_button |= B5_MASK; - } float x = this_x - _lastx; float y = this_y - _lasty;