Merge pull request #5465 from SamGondelman/connexionFixes

Trying to fix/clean up 3DConnexion stuff
This commit is contained in:
Andrew Meadows 2015-08-05 11:16:34 -07:00
commit 59f6988e56
10 changed files with 143 additions and 179 deletions

View file

@ -0,0 +1,38 @@
#
# Find3DConnexionClient.cmake
#
# Once done this will define
# 3DCONNEXIONCLIENT_FOUND - system found 3DConnexion
# 3DCONNEXIONCLIENT_INCLUDE_DIRS - the 3DConnexion include directory
# 3DCONNEXIONCLIENT_LIBRARY - Link this to use 3DConnexion
#
# Created on 10/06/2015 by Marcel Verhagen
# Copyright 2015 High Fidelity, Inc.
#
# Distributed under the Apache License, Version 2.0.
# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
#
include("${MACRO_DIR}/HifiLibrarySearchHints.cmake")
hifi_library_search_hints("3dconnexionclient")
if (APPLE)
find_library(3DCONNEXIONCLIENT_LIBRARIES NAMES 3DConnexionClient HINTS 3DCONNEXIONCLIENT_SEARCH_DIRS)
if(EXISTS ${3DConnexionClient})
set(3DCONNEXIONCLIENT_FOUND true)
set(3DCONNEXIONCLIENT_INCLUDE_DIRS ${3DConnexionClient})
set(3DCONNEXIONCLIENT_LIBRARY ${3DConnexionClient})
message(STATUS "Found 3DConnexion at " ${3DConnexionClient})
mark_as_advanced(3DCONNEXIONCLIENT_INCLUDE_DIR 3DCONNEXIONCLIENT_LIBRARY)
else ()
message(STATUS "Could NOT find 3DConnexionClient")
endif()
elseif (WIN32)
find_path(3DCONNEXIONCLIENT_INCLUDE_DIRS I3dMouseParams.h PATH_SUFFIXES include HINTS ${3DCONNEXIONCLIENT_SEARCH_DIRS})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(3DConnexionClient DEFAULT_MSG 3DCONNEXIONCLIENT_INCLUDE_DIRS)
mark_as_advanced(3DCONNEXIONCLIENT_INCLUDE_DIRS 3DCONNEXIONCLIENT_SEARCH_DIRS)
endif()

View file

@ -1,38 +0,0 @@
#
# FindconnexionClient.cmake
#
# Once done this will define
#
# 3DCONNEXIONCLIENT_INCLUDE_DIRS
#
# Created on 10/06/2015 by Marcel Verhagen
# Copyright 2015 High Fidelity, Inc.
#
# Distributed under the Apache License, Version 2.0.
# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
#
# setup hints for 3DCONNEXIONCLIENT search
include("${MACRO_DIR}/HifiLibrarySearchHints.cmake")
hifi_library_search_hints("connexionclient")
if (APPLE)
find_library(3DconnexionClient 3DconnexionClient)
if(EXISTS ${3DconnexionClient})
set(CONNEXIONCLIENT_FOUND true)
set(CONNEXIONCLIENT_INCLUDE_DIR ${3DconnexionClient})
set(CONNEXIONCLIENT_LIBRARY ${3DconnexionClient})
set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "-weak_framework 3DconnexionClient")
message(STATUS "Found 3Dconnexion")
mark_as_advanced(CONNEXIONCLIENT_INCLUDE_DIR CONNEXIONCLIENT_LIBRARY)
endif()
endif()
if (WIN32)
find_path(CONNEXIONCLIENT_INCLUDE_DIRS I3dMouseParams.h PATH_SUFFIXES Inc HINTS ${CONNEXIONCLIENT_SEARCH_DIRS})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(connexionClient DEFAULT_MSG CONNEXIONCLIENT_INCLUDE_DIRS)
mark_as_advanced(CONNEXIONCLIENT_INCLUDE_DIRS CONNEXIONCLIENT_SEARCH_DIRS)
endif()

View file

@ -2,7 +2,7 @@ set(TARGET_NAME interface)
project(${TARGET_NAME}) project(${TARGET_NAME})
# set a default root dir for each of our optional externals if it was not passed # set a default root dir for each of our optional externals if it was not passed
set(OPTIONAL_EXTERNALS "Faceshift" "Sixense" "LeapMotion" "RtMidi" "SDL2" "RSSDK" "connexionClient") set(OPTIONAL_EXTERNALS "Faceshift" "Sixense" "LeapMotion" "RtMidi" "SDL2" "RSSDK" "3DConnexionClient")
foreach(EXTERNAL ${OPTIONAL_EXTERNALS}) foreach(EXTERNAL ${OPTIONAL_EXTERNALS})
string(TOUPPER ${EXTERNAL} ${EXTERNAL}_UPPERCASE) string(TOUPPER ${EXTERNAL} ${EXTERNAL}_UPPERCASE)
if (NOT ${${EXTERNAL}_UPPERCASE}_ROOT_DIR) if (NOT ${${EXTERNAL}_UPPERCASE}_ROOT_DIR)

View file

@ -0,0 +1,3 @@
The Mac version does not require any files. The 3D Connexion driver should be installed from http://www.3dconnexion.eu/service/drivers.html
For Windows the provided header file is required: include/I3dMouseParams.h

View file

@ -1,4 +0,0 @@
The mac version does not require any files here. 3D connexion should be installed from
http://www.3dconnexion.eu/service/drivers.html
For windows a header file is required Inc/I3dMouseParams.h

View file

@ -115,7 +115,7 @@
#include "devices/MIDIManager.h" #include "devices/MIDIManager.h"
#include "devices/OculusManager.h" #include "devices/OculusManager.h"
#include "devices/TV3DManager.h" #include "devices/TV3DManager.h"
#include "devices/3Dconnexion.h" #include "devices/3DConnexionClient.h"
#include "scripting/AccountScriptingInterface.h" #include "scripting/AccountScriptingInterface.h"
#include "scripting/AudioDeviceScriptingInterface.h" #include "scripting/AudioDeviceScriptingInterface.h"
@ -641,7 +641,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
applicationUpdater->checkForUpdate(); applicationUpdater->checkForUpdate();
// the 3Dconnexion device wants to be initiliazed after a window is displayed. // the 3Dconnexion device wants to be initiliazed after a window is displayed.
ConnexionClient::init(); ConnexionClient::getInstance().init();
auto& packetReceiver = nodeList->getPacketReceiver(); auto& packetReceiver = nodeList->getPacketReceiver();
packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket"); packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket");
@ -754,7 +754,7 @@ Application::~Application() {
Leapmotion::destroy(); Leapmotion::destroy();
RealSense::destroy(); RealSense::destroy();
ConnexionClient::destroy(); ConnexionClient::getInstance().destroy();
qInstallMessageHandler(NULL); // NOTE: Do this as late as possible so we continue to get our log messages qInstallMessageHandler(NULL); // NOTE: Do this as late as possible so we continue to get our log messages
} }

View file

@ -29,7 +29,7 @@
#include "devices/Faceshift.h" #include "devices/Faceshift.h"
#include "devices/RealSense.h" #include "devices/RealSense.h"
#include "devices/SixenseManager.h" #include "devices/SixenseManager.h"
#include "devices/3Dconnexion.h" #include "devices/3DConnexionClient.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "scripting/MenuScriptingInterface.h" #include "scripting/MenuScriptingInterface.h"
#if defined(Q_OS_MAC) || defined(Q_OS_WIN) #if defined(Q_OS_MAC) || defined(Q_OS_WIN)

View file

@ -1,6 +1,6 @@
// //
// 3DConnexion.cpp // 3DConnexionClient.cpp
// hifi // interface/src/devices
// //
// Created by MarcelEdward Verhagen on 09-06-15. // Created by MarcelEdward Verhagen on 09-06-15.
// Copyright 2015 High Fidelity, Inc. // Copyright 2015 High Fidelity, Inc.
@ -9,7 +9,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "3Dconnexion.h" #include "3DConnexionClient.h"
#include "UserActivityLogger.h" #include "UserActivityLogger.h"
const float MAX_AXIS = 75.0f; // max forward = 2x speed const float MAX_AXIS = 75.0f; // max forward = 2x speed
@ -28,7 +28,6 @@ ConnexionData::ConnexionData() {
} }
void ConnexionData::handleAxisEvent() { void ConnexionData::handleAxisEvent() {
//qCWarning(interfaceapp) << "pos state x = " << cc_position.x << " y = " << cc_position.y << " z = " << cc_position.z << " Rotation x = " << cc_rotation.x << " y = " << cc_rotation.y << " z = " << cc_rotation.z;
_axisStateMap[makeInput(ROTATION_AXIS_Y_POS).getChannel()] = (cc_rotation.y > 0.0f) ? cc_rotation.y / MAX_AXIS : 0.0f; _axisStateMap[makeInput(ROTATION_AXIS_Y_POS).getChannel()] = (cc_rotation.y > 0.0f) ? cc_rotation.y / MAX_AXIS : 0.0f;
_axisStateMap[makeInput(ROTATION_AXIS_Y_NEG).getChannel()] = (cc_rotation.y < 0.0f) ? -cc_rotation.y / MAX_AXIS : 0.0f; _axisStateMap[makeInput(ROTATION_AXIS_Y_NEG).getChannel()] = (cc_rotation.y < 0.0f) ? -cc_rotation.y / MAX_AXIS : 0.0f;
_axisStateMap[makeInput(POSITION_AXIS_X_POS).getChannel()] = (cc_position.x > 0.0f) ? cc_position.x / MAX_AXIS : 0.0f; _axisStateMap[makeInput(POSITION_AXIS_X_POS).getChannel()] = (cc_position.x > 0.0f) ? cc_position.x / MAX_AXIS : 0.0f;
@ -148,7 +147,7 @@ UserInputMapper::Input ConnexionData::makeInput(ConnexionData::PositionChannel a
void ConnexionData::update() { void ConnexionData::update() {
// the update is done in the ConnexionClient class. // the update is done in the ConnexionClient class.
// for windows in the nativeEventFilter the inputmapper is connected or registed or removed when an 3Dconnnexion device is attached or deteched // for windows in the nativeEventFilter the inputmapper is connected or registed or removed when an 3Dconnnexion device is attached or detached
// for osx the api will call DeviceAddedHandler or DeviceRemoveHandler when a 3Dconnexion device is attached or detached // for osx the api will call DeviceAddedHandler or DeviceRemoveHandler when a 3Dconnexion device is attached or detached
} }
@ -157,40 +156,32 @@ ConnexionClient& ConnexionClient::getInstance() {
return sharedInstance; return sharedInstance;
} }
#ifdef HAVE_CONNEXIONCLIENT #ifdef HAVE_3DCONNEXIONCLIENT
#ifdef _WIN32 #ifdef Q_OS_WIN
static ConnexionClient* gMouseInput = 0; void ConnexionClient::toggleConnexion(bool shouldEnable) {
void ConnexionClient::toggleConnexion(bool shouldEnable)
{
ConnexionData& connexiondata = ConnexionData::getInstance(); ConnexionData& connexiondata = ConnexionData::getInstance();
if (shouldEnable && connexiondata.getDeviceID() == 0) { if (shouldEnable && connexiondata.getDeviceID() == 0) {
ConnexionClient::init(); init();
} }
if (!shouldEnable && connexiondata.getDeviceID() != 0) { if (!shouldEnable && connexiondata.getDeviceID() != 0) {
ConnexionClient::destroy(); destroy();
} }
} }
void ConnexionClient::init() { void ConnexionClient::init() {
if (Menu::getInstance()->isOptionChecked(MenuOption::Connexion)) { if (Menu::getInstance()->isOptionChecked(MenuOption::Connexion)) {
ConnexionClient& cclient = ConnexionClient::getInstance(); fLast3dmouseInputTime = 0;
cclient.fLast3dmouseInputTime = 0;
cclient.InitializeRawInput(GetActiveWindow()); InitializeRawInput(GetActiveWindow());
gMouseInput = &cclient; QAbstractEventDispatcher::instance()->installNativeEventFilter(this);
QAbstractEventDispatcher::instance()->installNativeEventFilter(&cclient);
} }
} }
void ConnexionClient::destroy() { void ConnexionClient::destroy() {
ConnexionClient& cclient = ConnexionClient::getInstance(); QAbstractEventDispatcher::instance()->removeNativeEventFilter(this);
QAbstractEventDispatcher::instance()->removeNativeEventFilter(&cclient);
ConnexionData& connexiondata = ConnexionData::getInstance(); ConnexionData& connexiondata = ConnexionData::getInstance();
int deviceid = connexiondata.getDeviceID(); int deviceid = connexiondata.getDeviceID();
connexiondata.setDeviceID(0); connexiondata.setDeviceID(0);
@ -225,15 +216,15 @@ enum ConnexionPid {
// e3dmouse_virtual_key // e3dmouse_virtual_key
enum V3dk { enum V3dk {
V3DK_INVALID = 0 V3DK_INVALID = 0,
, V3DK_MENU = 1, V3DK_FIT V3DK_MENU = 1, V3DK_FIT,
, V3DK_TOP, V3DK_LEFT, V3DK_RIGHT, V3DK_FRONT, V3DK_BOTTOM, V3DK_BACK V3DK_TOP, V3DK_LEFT, V3DK_RIGHT, V3DK_FRONT, V3DK_BOTTOM, V3DK_BACK,
, V3DK_CW, V3DK_CCW V3DK_CW, V3DK_CCW,
, V3DK_ISO1, V3DK_ISO2 V3DK_ISO1, V3DK_ISO2,
, V3DK_1, V3DK_2, V3DK_3, V3DK_4, V3DK_5, V3DK_6, V3DK_7, V3DK_8, V3DK_9, V3DK_10 V3DK_1, V3DK_2, V3DK_3, V3DK_4, V3DK_5, V3DK_6, V3DK_7, V3DK_8, V3DK_9, V3DK_10,
, V3DK_ESC, V3DK_ALT, V3DK_SHIFT, V3DK_CTRL V3DK_ESC, V3DK_ALT, V3DK_SHIFT, V3DK_CTRL,
, V3DK_ROTATE, V3DK_PANZOOM, V3DK_DOMINANT V3DK_ROTATE, V3DK_PANZOOM, V3DK_DOMINANT,
, V3DK_PLUS, V3DK_MINUS V3DK_PLUS, V3DK_MINUS
}; };
struct tag_VirtualKeys { struct tag_VirtualKeys {
@ -244,33 +235,33 @@ struct tag_VirtualKeys {
// e3dmouse_virtual_key // e3dmouse_virtual_key
static const V3dk SpaceExplorerKeys[] = { static const V3dk SpaceExplorerKeys[] = {
V3DK_INVALID // there is no button 0 V3DK_INVALID, // there is no button 0
, V3DK_1, V3DK_2 V3DK_1, V3DK_2,
, V3DK_TOP, V3DK_LEFT, V3DK_RIGHT, V3DK_FRONT V3DK_TOP, V3DK_LEFT, V3DK_RIGHT, V3DK_FRONT,
, V3DK_ESC, V3DK_ALT, V3DK_SHIFT, V3DK_CTRL V3DK_ESC, V3DK_ALT, V3DK_SHIFT, V3DK_CTRL,
, V3DK_FIT, V3DK_MENU V3DK_FIT, V3DK_MENU,
, V3DK_PLUS, V3DK_MINUS V3DK_PLUS, V3DK_MINUS,
, V3DK_ROTATE V3DK_ROTATE
}; };
//e3dmouse_virtual_key //e3dmouse_virtual_key
static const V3dk SpacePilotKeys[] = { static const V3dk SpacePilotKeys[] = {
V3DK_INVALID V3DK_INVALID,
, V3DK_1, V3DK_2, V3DK_3, V3DK_4, V3DK_5, V3DK_6 V3DK_1, V3DK_2, V3DK_3, V3DK_4, V3DK_5, V3DK_6,
, V3DK_TOP, V3DK_LEFT, V3DK_RIGHT, V3DK_FRONT V3DK_TOP, V3DK_LEFT, V3DK_RIGHT, V3DK_FRONT,
, V3DK_ESC, V3DK_ALT, V3DK_SHIFT, V3DK_CTRL V3DK_ESC, V3DK_ALT, V3DK_SHIFT, V3DK_CTRL,
, V3DK_FIT, V3DK_MENU V3DK_FIT, V3DK_MENU,
, V3DK_PLUS, V3DK_MINUS V3DK_PLUS, V3DK_MINUS,
, V3DK_DOMINANT, V3DK_ROTATE V3DK_DOMINANT, V3DK_ROTATE,
}; };
static const struct tag_VirtualKeys _3dmouseVirtualKeys[] = { static const struct tag_VirtualKeys _3dmouseVirtualKeys[] = {
CONNEXIONPID_SPACEPILOT CONNEXIONPID_SPACEPILOT,
, sizeof(SpacePilotKeys) / sizeof(SpacePilotKeys[0]) sizeof(SpacePilotKeys) / sizeof(SpacePilotKeys[0]),
, const_cast<V3dk *>(SpacePilotKeys), const_cast<V3dk *>(SpacePilotKeys),
CONNEXIONPID_SPACEEXPLORER CONNEXIONPID_SPACEEXPLORER,
, sizeof(SpaceExplorerKeys) / sizeof(SpaceExplorerKeys[0]) sizeof(SpaceExplorerKeys) / sizeof(SpaceExplorerKeys[0]),
, const_cast<V3dk *>(SpaceExplorerKeys) const_cast<V3dk *>(SpaceExplorerKeys)
}; };
// Converts a hid device keycode (button identifier) of a pre-2009 3Dconnexion USB device to the standard 3d mouse virtual key definition. // Converts a hid device keycode (button identifier) of a pre-2009 3Dconnexion USB device to the standard 3d mouse virtual key definition.
@ -282,10 +273,8 @@ static const struct tag_VirtualKeys _3dmouseVirtualKeys[] = {
// to the standard 3d mouse virtual key definition. // to the standard 3d mouse virtual key definition.
unsigned short HidToVirtualKey(unsigned long pid, unsigned short hidKeyCode) { unsigned short HidToVirtualKey(unsigned long pid, unsigned short hidKeyCode) {
unsigned short virtualkey = hidKeyCode; unsigned short virtualkey = hidKeyCode;
for (size_t i = 0; i<sizeof(_3dmouseVirtualKeys) / sizeof(_3dmouseVirtualKeys[0]); ++i) for (size_t i = 0; i<sizeof(_3dmouseVirtualKeys) / sizeof(_3dmouseVirtualKeys[0]); ++i) {
{ if (pid == _3dmouseVirtualKeys[i].pid) {
if (pid == _3dmouseVirtualKeys[i].pid)
{
if (hidKeyCode < _3dmouseVirtualKeys[i].nKeys) { if (hidKeyCode < _3dmouseVirtualKeys[i].nKeys) {
virtualkey = _3dmouseVirtualKeys[i].vkeys[hidKeyCode]; virtualkey = _3dmouseVirtualKeys[i].vkeys[hidKeyCode];
} else { } else {
@ -300,17 +289,17 @@ unsigned short HidToVirtualKey(unsigned long pid, unsigned short hidKeyCode) {
bool ConnexionClient::RawInputEventFilter(void* msg, long* result) { bool ConnexionClient::RawInputEventFilter(void* msg, long* result) {
ConnexionData& connexiondata = ConnexionData::getInstance(); ConnexionData& connexiondata = ConnexionData::getInstance();
if (ConnexionClient::Is3dmouseAttached() && connexiondata.getDeviceID() == 0) { if (Is3dmouseAttached() && connexiondata.getDeviceID() == 0) {
connexiondata.registerToUserInputMapper(*Application::getUserInputMapper()); connexiondata.registerToUserInputMapper(*Application::getUserInputMapper());
connexiondata.assignDefaultInputMapping(*Application::getUserInputMapper()); connexiondata.assignDefaultInputMapping(*Application::getUserInputMapper());
UserActivityLogger::getInstance().connectedDevice("controller", "3Dconnexion"); UserActivityLogger::getInstance().connectedDevice("controller", "3Dconnexion");
} else if (!ConnexionClient::Is3dmouseAttached() && connexiondata.getDeviceID() != 0) { } else if (!Is3dmouseAttached() && connexiondata.getDeviceID() != 0) {
int deviceid = connexiondata.getDeviceID(); int deviceid = connexiondata.getDeviceID();
connexiondata.setDeviceID(0); connexiondata.setDeviceID(0);
Application::getUserInputMapper()->removeDevice(deviceid); Application::getUserInputMapper()->removeDevice(deviceid);
} }
if (!ConnexionClient::Is3dmouseAttached()) { if (!Is3dmouseAttached()) {
return false; return false;
} }
@ -318,7 +307,7 @@ bool ConnexionClient::RawInputEventFilter(void* msg, long* result) {
if (message->message == WM_INPUT) { if (message->message == WM_INPUT) {
HRAWINPUT hRawInput = reinterpret_cast<HRAWINPUT>(message->lParam); HRAWINPUT hRawInput = reinterpret_cast<HRAWINPUT>(message->lParam);
gMouseInput->OnRawInput(RIM_INPUT, hRawInput); OnRawInput(RIM_INPUT, hRawInput);
if (result != 0) { if (result != 0) {
result = 0; result = 0;
} }
@ -327,15 +316,6 @@ bool ConnexionClient::RawInputEventFilter(void* msg, long* result) {
return false; return false;
} }
ConnexionClient::ConnexionClient() {
}
ConnexionClient::~ConnexionClient() {
ConnexionClient& cclient = ConnexionClient::getInstance();
QAbstractEventDispatcher::instance()->removeNativeEventFilter(&cclient);
}
// Access the mouse parameters structure // Access the mouse parameters structure
I3dMouseParam& ConnexionClient::MouseParams() { I3dMouseParam& ConnexionClient::MouseParams() {
return f3dMouseParams; return f3dMouseParams;
@ -680,8 +660,6 @@ void ConnexionClient::OnRawInput(UINT nInputCode, HRAWINPUT hRawInput) {
bool ConnexionClient::TranslateRawInputData(UINT nInputCode, PRAWINPUT pRawInput) { bool ConnexionClient::TranslateRawInputData(UINT nInputCode, PRAWINPUT pRawInput) {
bool bIsForeground = (nInputCode == RIM_INPUT); bool bIsForeground = (nInputCode == RIM_INPUT);
//qDebug("Rawinput.header.dwType=0x%x\n", pRawInput->header.dwType);
// We are not interested in keyboard or mouse data received via raw input // We are not interested in keyboard or mouse data received via raw input
if (pRawInput->header.dwType != RIM_TYPEHID) { if (pRawInput->header.dwType != RIM_TYPEHID) {
return false; return false;
@ -691,7 +669,7 @@ bool ConnexionClient::TranslateRawInputData(UINT nInputCode, PRAWINPUT pRawInput
UINT dwSize = 0; UINT dwSize = 0;
if (::GetRawInputDeviceInfo(pRawInput->header.hDevice, RIDI_DEVICENAME, NULL, &dwSize) == 0) { if (::GetRawInputDeviceInfo(pRawInput->header.hDevice, RIDI_DEVICENAME, NULL, &dwSize) == 0) {
std::vector<wchar_t> szDeviceName(dwSize + 1); std::vector<wchar_t> szDeviceName(dwSize + 1);
if (::GetRawInputDeviceInfo(pRawInput->header.hDevice, RIDI_DEVICENAME, &szDeviceName[0], &dwSize) >0) { if (::GetRawInputDeviceInfo(pRawInput->header.hDevice, RIDI_DEVICENAME, &szDeviceName[0], &dwSize) > 0) {
qDebug("Device Name = %s\nDevice handle = 0x%x\n", &szDeviceName[0], pRawInput->header.hDevice); qDebug("Device Name = %s\nDevice handle = 0x%x\n", &szDeviceName[0], pRawInput->header.hDevice);
} }
} }
@ -806,16 +784,15 @@ bool ConnexionClient::TranslateRawInputData(UINT nInputCode, PRAWINPUT pRawInput
return false; return false;
} }
MouseParameters::MouseParameters() : fNavigation(NAVIGATION_OBJECT_MODE) MouseParameters::MouseParameters() :
, fPivot(PIVOT_AUTO) fNavigation(NAVIGATION_OBJECT_MODE),
, fPivotVisibility(PIVOT_SHOW) fPivot(PIVOT_AUTO),
, fIsLockHorizon(true) fPivotVisibility(PIVOT_SHOW),
, fIsPanZoom(true) fIsLockHorizon(true),
, fIsRotate(true) fIsPanZoom(true),
, fSpeed(SPEED_LOW) { fIsRotate(true),
} fSpeed(SPEED_LOW)
{
MouseParameters::~MouseParameters() {
} }
bool MouseParameters::IsPanZoom() const { bool MouseParameters::IsPanZoom() const {
@ -831,15 +808,15 @@ MouseParameters::Speed MouseParameters::GetSpeed() const {
} }
void MouseParameters::SetPanZoom(bool isPanZoom) { void MouseParameters::SetPanZoom(bool isPanZoom) {
fIsPanZoom=isPanZoom; fIsPanZoom = isPanZoom;
} }
void MouseParameters::SetRotate(bool isRotate) { void MouseParameters::SetRotate(bool isRotate) {
fIsRotate=isRotate; fIsRotate = isRotate;
} }
void MouseParameters::SetSpeed(Speed speed) { void MouseParameters::SetSpeed(Speed speed) {
fSpeed=speed; fSpeed = speed;
} }
MouseParameters::Navigation MouseParameters::GetNavigationMode() const { MouseParameters::Navigation MouseParameters::GetNavigationMode() const {
@ -878,13 +855,6 @@ void MouseParameters::SetPivotVisibility(PivotVisibility visibility) {
#else #else
#define WITH_SEPARATE_THREAD false // set to true or false
// Make the linker happy for the framework check (see link below for more info)
// http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html
extern int16_t SetConnexionHandlers(ConnexionMessageHandlerProc messageHandler, ConnexionAddedHandlerProc addedHandler, ConnexionRemovedHandlerProc removedHandler, bool useSeparateThread) __attribute__((weak_import));
int fConnexionClientID; int fConnexionClientID;
static ConnexionDeviceState lastState; static ConnexionDeviceState lastState;
@ -893,20 +863,18 @@ static void DeviceAddedHandler(unsigned int connection);
static void DeviceRemovedHandler(unsigned int connection); static void DeviceRemovedHandler(unsigned int connection);
static void MessageHandler(unsigned int connection, unsigned int messageType, void *messageArgument); static void MessageHandler(unsigned int connection, unsigned int messageType, void *messageArgument);
void ConnexionClient::toggleConnexion(bool shouldEnable) void ConnexionClient::toggleConnexion(bool shouldEnable) {
{ if (shouldEnable && !Is3dmouseAttached()) {
if (shouldEnable && !ConnexionClient::Is3dmouseAttached()) { init();
ConnexionClient::init();
} }
if (!shouldEnable && ConnexionClient::Is3dmouseAttached()) { if (!shouldEnable && Is3dmouseAttached()) {
ConnexionClient::destroy(); destroy();
} }
} }
void ConnexionClient::init() { void ConnexionClient::init() {
// Make sure the framework is installed // Make sure the framework is installed
if (SetConnexionHandlers != NULL && Menu::getInstance()->isOptionChecked(MenuOption::Connexion)) { if (Menu::getInstance()->isOptionChecked(MenuOption::Connexion)) {
// Install message handler and register our client // Install message handler and register our client
InstallConnexionHandlers(MessageHandler, DeviceAddedHandler, DeviceRemovedHandler); InstallConnexionHandlers(MessageHandler, DeviceAddedHandler, DeviceRemovedHandler);
// Either use this to take over in our application only... does not work // Either use this to take over in our application only... does not work
@ -923,7 +891,7 @@ void ConnexionClient::init() {
// use default switches // use default switches
ConnexionClientControl(fConnexionClientID, kConnexionCtlSetSwitches, kConnexionSwitchesDisabled, NULL); ConnexionClientControl(fConnexionClientID, kConnexionCtlSetSwitches, kConnexionSwitchesDisabled, NULL);
if (ConnexionClient::Is3dmouseAttached() && connexiondata.getDeviceID() == 0) { if (Is3dmouseAttached() && connexiondata.getDeviceID() == 0) {
connexiondata.registerToUserInputMapper(*Application::getUserInputMapper()); connexiondata.registerToUserInputMapper(*Application::getUserInputMapper());
connexiondata.assignDefaultInputMapping(*Application::getUserInputMapper()); connexiondata.assignDefaultInputMapping(*Application::getUserInputMapper());
UserActivityLogger::getInstance().connectedDevice("controller", "3Dconnexion"); UserActivityLogger::getInstance().connectedDevice("controller", "3Dconnexion");
@ -1010,4 +978,4 @@ void MessageHandler(unsigned int connection, unsigned int messageType, void *mes
#endif // __APPLE__ #endif // __APPLE__
#endif // HAVE_CONNEXIONCLIENT #endif // HAVE_3DCONNEXIONCLIENT

View file

@ -1,5 +1,5 @@
// 3DConnexion.h // 3DConnexionClient.h
// hifi // interface/src/devices
// //
// Created by Marcel Verhagen on 09-06-15. // Created by Marcel Verhagen on 09-06-15.
// Copyright 2015 High Fidelity, Inc. // Copyright 2015 High Fidelity, Inc.
@ -8,8 +8,8 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#ifndef hifi_ConnexionClient_h #ifndef hifi_3DConnexionClient_h
#define hifi_ConnexionClient_h #define hifi_3DConnexionClient_h
#include <qobject.h> #include <qobject.h>
#include <qlibrary.h> #include <qlibrary.h>
@ -18,22 +18,22 @@
#include "ui/UserInputMapper.h" #include "ui/UserInputMapper.h"
#ifndef HAVE_CONNEXIONCLIENT #ifndef HAVE_3DCONNEXIONCLIENT
class ConnexionClient : public QObject { class ConnexionClient : public QObject {
Q_OBJECT Q_OBJECT
public: public:
static ConnexionClient& getInstance(); static ConnexionClient& getInstance();
static void init() {}; void init() {};
static void destroy() {}; void destroy() {};
static bool Is3dmouseAttached() { return false; }; bool Is3dmouseAttached() { return false; };
public slots: public slots:
void toggleConnexion(bool shouldEnable) {}; void toggleConnexion(bool shouldEnable) {};
}; };
#endif // NOT_HAVE_CONNEXIONCLIENT #endif // NOT_HAVE_3DCONNEXIONCLIENT
#ifdef HAVE_CONNEXIONCLIENT #ifdef HAVE_3DCONNEXIONCLIENT
// the windows connexion rawinput // the windows connexion rawinput
#ifdef _WIN32 #ifdef Q_OS_WIN
#include "I3dMouseParams.h" #include "I3dMouseParams.h"
#include <QAbstractNativeEventFilter> #include <QAbstractNativeEventFilter>
@ -45,7 +45,6 @@ public slots:
class MouseParameters : public I3dMouseParam { class MouseParameters : public I3dMouseParam {
public: public:
MouseParameters(); MouseParameters();
~MouseParameters();
// I3dmouseSensor interface // I3dmouseSensor interface
bool IsPanZoom() const; bool IsPanZoom() const;
@ -86,16 +85,14 @@ private:
class ConnexionClient : public QObject, public QAbstractNativeEventFilter { class ConnexionClient : public QObject, public QAbstractNativeEventFilter {
Q_OBJECT Q_OBJECT
public: public:
ConnexionClient(); ConnexionClient() {};
~ConnexionClient();
static ConnexionClient& getInstance(); static ConnexionClient& getInstance();
void init();
void destroy();
bool Is3dmouseAttached();
ConnexionClient* client; ConnexionClient* client;
static void init();
static void destroy();
static bool Is3dmouseAttached();
I3dMouseParam& MouseParams(); I3dMouseParam& MouseParams();
const I3dMouseParam& MouseParams() const; const I3dMouseParam& MouseParams() const;
@ -107,7 +104,7 @@ public:
virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long* result) Q_DECL_OVERRIDE virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long* result) Q_DECL_OVERRIDE
{ {
MSG* msg = static_cast< MSG * >(message); MSG* msg = static_cast< MSG * >(message);
return ConnexionClient::RawInputEventFilter(message, result); return RawInputEventFilter(message, result);
} }
public slots: public slots:
@ -121,7 +118,7 @@ signals:
private: private:
bool InitializeRawInput(HWND hwndTarget); bool InitializeRawInput(HWND hwndTarget);
static bool RawInputEventFilter(void* msg, long* result); bool RawInputEventFilter(void* msg, long* result);
void OnRawInput(UINT nInputCode, HRAWINPUT hRawInput); void OnRawInput(UINT nInputCode, HRAWINPUT hRawInput);
UINT GetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader); UINT GetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader);
@ -166,16 +163,16 @@ class ConnexionClient : public QObject {
Q_OBJECT Q_OBJECT
public: public:
static ConnexionClient& getInstance(); static ConnexionClient& getInstance();
static bool Is3dmouseAttached(); void init();
static void init(); void destroy();
static void destroy(); bool Is3dmouseAttached();
public slots: public slots:
void toggleConnexion(bool shouldEnable); void toggleConnexion(bool shouldEnable);
}; };
#endif // __APPLE__ #endif // __APPLE__
#endif // HAVE_CONNEXIONCLIENT #endif // HAVE_3DCONNEXIONCLIENT
// connnects to the userinputmapper // connnects to the userinputmapper
@ -241,4 +238,4 @@ protected:
AxisStateMap _axisStateMap; AxisStateMap _axisStateMap;
}; };
#endif // defined(hifi_ConnexionClient_h) #endif // defined(hifi_3DConnexionClient_h)