diff options
author | Andrey Kleshchev <andreykproductengine@lindenlab.com> | 2022-12-29 19:16:15 +0200 |
---|---|---|
committer | akleshchev <117672381+akleshchev@users.noreply.github.com> | 2023-10-23 15:26:19 +0300 |
commit | 3084f864176dffbc5da19e6f958a55513f63e795 (patch) | |
tree | ad164425f7f223879b5249d77e9c7c43cd757487 /indra/newview | |
parent | 6481d36c69dbcafdb23cb27dc07aa047b3d7d64e (diff) |
SL-13610 [MAC] Manufacturer based search
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/app_settings/settings.xml | 2 | ||||
-rw-r--r-- | indra/newview/llfloaterjoystick.cpp | 17 | ||||
-rw-r--r-- | indra/newview/llfloaterjoystick.h | 2 | ||||
-rw-r--r-- | indra/newview/llviewerjoystick.cpp | 175 | ||||
-rw-r--r-- | indra/newview/llviewerjoystick.h | 6 |
5 files changed, 103 insertions, 99 deletions
diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index ff7232830b..3e17c434a3 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -3770,7 +3770,7 @@ <key>Persist</key> <integer>1</integer> <key>Type</key> - <string>String</string> + <string>LLSD</string> <key>Value</key> <string /> </map> diff --git a/indra/newview/llfloaterjoystick.cpp b/indra/newview/llfloaterjoystick.cpp index 18e5858e8d..d3add020cf 100644 --- a/indra/newview/llfloaterjoystick.cpp +++ b/indra/newview/llfloaterjoystick.cpp @@ -250,7 +250,7 @@ void LLFloaterJoystick::refresh() initFromSettings(); } -bool LLFloaterJoystick::addDeviceCallback(std::string &name, LLSD::Binary& value, void* userdata) +bool LLFloaterJoystick::addDeviceCallback(std::string &name, LLSD& value, void* userdata) { LLFloaterJoystick * floater = (LLFloaterJoystick*)userdata; floater->mJoysticksCombo->add(name, value, ADD_BOTTOM, 1); @@ -280,9 +280,9 @@ void LLFloaterJoystick::refreshListOfDevices() #elif LL_DARWIN U32 device_type = 0; #else - // MAC doesn't support device search yet - // On MAC there is an ndof_idsearch and it is possible to specify product - // and manufacturer in NDOF_Device for ndof_init_first to pick specific one + // On MAC it is possible to specify product + // and manufacturer in NDOF_Device for + // ndof_init_first to pick specific device U32 device_type = 0; #endif if (gViewerWindow->getWindow()->getInputDevices(device_type, addDeviceCallback, win_calback, this)) @@ -427,10 +427,11 @@ void LLFloaterJoystick::onCommitJoystickEnabled(LLUICtrl*, void *joy_panel) joystick->toggleFlycam(); } } - - std::string device_id = LLViewerJoystick::getInstance()->getDeviceUUIDString(); - gSavedSettings.setString("JoystickDeviceUUID", device_id); - LL_DEBUGS("Joystick") << "Selected " << device_id << " as joystick." << LL_ENDL; + + LLViewerJoystick::getInstance()->saveDeviceIdToSettings(); + + std::string device_string = LLViewerJoystick::getInstance()->getDeviceUUIDString(); + LL_DEBUGS("Joystick") << "Selected " << device_string << " as joystick." << LL_ENDL; self->refreshListOfDevices(); } diff --git a/indra/newview/llfloaterjoystick.h b/indra/newview/llfloaterjoystick.h index e7049ab906..ff889c804b 100644 --- a/indra/newview/llfloaterjoystick.h +++ b/indra/newview/llfloaterjoystick.h @@ -46,7 +46,7 @@ public: virtual void draw(); static void setSNDefaults(); - static bool addDeviceCallback(std::string &name, LLSD::Binary& value, void* userdata); + static bool addDeviceCallback(std::string &name, LLSD& value, void* userdata); void addDevice(std::string &name, LLSD& value); protected: diff --git a/indra/newview/llviewerjoystick.cpp b/indra/newview/llviewerjoystick.cpp index 95cfa5cd78..ef96ea4493 100644 --- a/indra/newview/llviewerjoystick.cpp +++ b/indra/newview/llviewerjoystick.cpp @@ -229,18 +229,11 @@ std::string string_from_guid(const GUID &guid) } #elif LL_DARWIN -bool macos_devices_callback(std::string &product_name, LLSD::Binary &data, void* userdata) +bool macos_devices_callback(std::string &product_name, LLSD &data, void* userdata) { - S32 size = sizeof(long); - long id; - memcpy(&id, &data[0], size); + std::string product = data["product"].asString(); - NDOF_Device *device = ndof_idsearch(id); - if (device) - { - return LLViewerJoystick::getInstance()->initDevice(device, data); - } - return false; + return LLViewerJoystick::getInstance()->initDevice(nullptr, product, data); } #endif @@ -384,7 +377,7 @@ void LLViewerJoystick::init(bool autoenable) { U32 device_type = 0; void* win_callback = nullptr; - std::function<bool(std::string&, LLSD::Binary&, void*)> osx_callback; + std::function<bool(std::string&, LLSD&, void*)> osx_callback; // di8_devices_callback callback is immediate and happens in scope of getInputDevices() #if LL_WINDOWS && !LL_MESA_HEADLESS // space navigator is marked as DI8DEVCLASS_GAMECTRL in ndof lib @@ -393,27 +386,24 @@ void LLViewerJoystick::init(bool autoenable) #elif LL_DARWIN osx_callback = macos_devices_callback; - if (mLastDeviceUUID.isBinary()) + if (mLastDeviceUUID.isMap()) { - S32 size = sizeof(long); - long id; - memcpy(&id, &mLastDeviceUUID[0], size); + std::string manufacturer = mLastDeviceUUID["manufacturer"].asString(); + std::string product = mLastDeviceUUID["product"].asString(); + + strncpy(mNdofDev->manufacturer, manufacturer.c_str(), sizeof(mNdofDev->manufacturer)); + strncpy(mNdofDev->product, product.c_str(), sizeof(mNdofDev->product)); - // todo: search by manufcturer instead, locid might have changed - NDOF_Device *device = ndof_idsearch(id); - if (device) + if (ndof_init_first(mNdofDev, nullptr)) { - if (ndof_init_first(device, nullptr)) - { - mDriverState = JDS_INITIALIZING; - // Saved device no longer exist - LL_WARNS() << "ndof_init_first FAILED" << LL_ENDL; - } - else - { - mNdofDev = device; - mDriverState = JDS_INITIALIZED; - } + mDriverState = JDS_INITIALIZING; + // Saved device no longer exist + // No device found + LL_WARNS() << "ndof_init_first FAILED" << LL_ENDL; + } + else + { + mDriverState = JDS_INITIALIZED; } } #endif @@ -483,7 +473,7 @@ void LLViewerJoystick::initDevice(LLSD &guid) mLastDeviceUUID = guid; U32 device_type = 0; void* win_callback = nullptr; - std::function<bool(std::string&, LLSD::Binary&, void*)> osx_callback; + std::function<bool(std::string&, LLSD&, void*)> osx_callback; mDriverState = JDS_INITIALIZING; #if LL_WINDOWS && !LL_MESA_HEADLESS @@ -492,27 +482,24 @@ void LLViewerJoystick::initDevice(LLSD &guid) win_callback = &di8_devices_callback; #elif LL_DARWIN osx_callback = macos_devices_callback; - if (mLastDeviceUUID.isBinary()) + if (mLastDeviceUUID.isMap()) { - S32 size = sizeof(long); - long id; - memcpy(&id, &mLastDeviceUUID[0], size); + std::string manufacturer = mLastDeviceUUID["manufacturer"].asString(); + std::string product = mLastDeviceUUID["product"].asString(); - NDOF_Device *device = ndof_idsearch(id); - if (device) + strncpy(mNdofDev->manufacturer, manufacturer.c_str(), sizeof(mNdofDev->manufacturer)); + strncpy(mNdofDev->product, product.c_str(), sizeof(mNdofDev->product)); + + if (ndof_init_first(mNdofDev, nullptr)) { - // todo: search by manufcturer instead, locid might have changed - if (ndof_init_first(device, nullptr)) - { - mDriverState = JDS_INITIALIZING; - // Saved device no longer exist - LL_WARNS() << "ndof_init_first FAILED" << LL_ENDL; - } - else - { - mNdofDev = device; - mDriverState = JDS_INITIALIZED; - } + mDriverState = JDS_INITIALIZING; + // Saved device no longer exist + // Np other device present + LL_WARNS() << "ndof_init_first FAILED" << LL_ENDL; + } + else + { + mDriverState = JDS_INITIALIZED; } } #endif @@ -522,7 +509,7 @@ void LLViewerJoystick::initDevice(LLSD &guid) if (!gViewerWindow->getWindow()->getInputDevices(device_type, osx_callback, win_callback, NULL)) { LL_INFOS("Joystick") << "Failed to gather input devices. Falling back to ndof's init" << LL_ENDL; - // Failed to gather devices from windows, init first suitable one + // Failed to gather devices from window, init first suitable one void *preffered_device = NULL; mLastDeviceUUID = LLSD(); initDevice(preffered_device); @@ -537,19 +524,37 @@ void LLViewerJoystick::initDevice(LLSD &guid) #endif } -void LLViewerJoystick::initDevice(void * preffered_device /*LPDIRECTINPUTDEVICE8*/, std::string &name, LLSD &guid) +bool LLViewerJoystick::initDevice(void * preffered_device /*LPDIRECTINPUTDEVICE8*/, std::string &name, LLSD &guid) { #if LIB_NDOF mLastDeviceUUID = guid; - + +#if LL_DARWIN + if (guid.isMap()) + { + std::string manufacturer = mLastDeviceUUID["manufacturer"].asString(); + std::string product = mLastDeviceUUID["product"].asString(); + + strncpy(mNdofDev->manufacturer, manufacturer.c_str(), sizeof(mNdofDev->manufacturer)); + strncpy(mNdofDev->product, product.c_str(), sizeof(mNdofDev->product)); + } + else + { + mNdofDev->product[0] = '\0'; + mNdofDev->manufacturer[0] = '\0'; + } +#else strncpy(mNdofDev->product, name.c_str(), sizeof(mNdofDev->product)); mNdofDev->manufacturer[0] = '\0'; +#endif - initDevice(preffered_device); + return initDevice(preffered_device); +#else + return false; #endif } -void LLViewerJoystick::initDevice(void * preffered_device /* LPDIRECTINPUTDEVICE8* */) +bool LLViewerJoystick::initDevice(void * preffered_device /* LPDIRECTINPUTDEVICE8* */) { #if LIB_NDOF // Different joysticks will return different ranges of raw values. @@ -579,23 +584,6 @@ void LLViewerJoystick::initDevice(void * preffered_device /* LPDIRECTINPUTDEVICE else { mDriverState = JDS_INITIALIZED; - } -#endif -} - -bool LLViewerJoystick::initDevice(NDOF_Device * ndof_device, LLSD::Binary &data) -{ - mLastDeviceUUID = data; -#if LIB_NDOF - if (ndof_init_first(ndof_device, nullptr)) - { - mDriverState = JDS_UNINITIALIZED; - LL_WARNS() << "ndof_init_first FAILED" << LL_ENDL; - } - else - { - mNdofDev = ndof_device; - mDriverState = JDS_INITIALIZED; return true; } #endif @@ -1407,6 +1395,8 @@ bool LLViewerJoystick::isDeviceUUIDSet() #if LL_WINDOWS && !LL_MESA_HEADLESS // for ease of comparison and to dial less with platform specific variables, we store id as LLSD binary return mLastDeviceUUID.isBinary(); +#elif LL_DARWIN + return mLastDeviceUUID.isMap(); #else return false; #endif @@ -1434,13 +1424,11 @@ std::string LLViewerJoystick::getDeviceUUIDString() return std::string(); } #elif LL_DARWIN - if (mLastDeviceUUID.isBinary()) + if (mLastDeviceUUID.isMap()) { - S32 size = sizeof(long); - LLSD::Binary data = mLastDeviceUUID.asBinary(); - long id; - memcpy(&id, &data[0], size); - return std::to_string(id); + std::string manufacturer = mLastDeviceUUID["manufacturer"].asString(); + std::string product = mLastDeviceUUID["product"].asString(); + return manufacturer + ":" + product; } else { @@ -1451,13 +1439,32 @@ std::string LLViewerJoystick::getDeviceUUIDString() #endif } +void LLViewerJoystick::saveDeviceIdToSettings() +{ +#if LL_WINDOWS && !LL_MESA_HEADLESS + // can't save as binary directly, + // someone editing the xml will corrupt it + // so convert to string first + std::string device_string = getDeviceUUIDString(); + gSavedSettings.setLLSD("JoystickDeviceUUID", LLSD(device_string); +#else + LLSD device_id = getDeviceUUID(); + gSavedSettings.setLLSD("JoystickDeviceUUID", device_id); +#endif +} + void LLViewerJoystick::loadDeviceIdFromSettings() { + LLSD dev_id = gSavedSettings.getLLSD("JoystickDeviceUUID"); #if LL_WINDOWS && !LL_MESA_HEADLESS // We can't save binary data to gSavedSettings, somebody editing the file will corrupt it, // so _GUID data gets converted to string (we probably can convert it to LLUUID with memcpy) // and here we need to convert it back to binary from string - std::string device_string = gSavedSettings.getString("JoystickDeviceUUID"); + std::string device_string; + if (dev_id.isString()) + { + device_string = dev_id.asString(); + } if (device_string.empty()) { mLastDeviceUUID = LLSD(); @@ -1475,21 +1482,17 @@ void LLViewerJoystick::loadDeviceIdFromSettings() mLastDeviceUUID = LLSD(data); } #elif LL_DARWIN - std::string device_string = gSavedSettings.getString("JoystickDeviceUUID"); - if (device_string.empty()) + if (!dev_id.isMap()) { mLastDeviceUUID = LLSD(); } else { - LL_DEBUGS("Joystick") << "Looking for device by id: " << device_string << LL_ENDL; - long id = std::stol(device_string); - S32 size = sizeof(long); - LLSD::Binary data; //just an std::vector - data.resize(size); - memcpy(&data[0], &id, size); + std::string manufacturer = mLastDeviceUUID["manufacturer"].asString(); + std::string product = mLastDeviceUUID["product"].asString(); + LL_DEBUGS("Joystick") << "Looking for device by manufacturer: " << manufacturer << " and product: " << product << LL_ENDL; // We store this data in LLSD since it can handle both GUID2 and long - mLastDeviceUUID = LLSD(data); + mLastDeviceUUID = dev_id; } #else mLastDeviceUUID = LLSD(); diff --git a/indra/newview/llviewerjoystick.h b/indra/newview/llviewerjoystick.h index 0e5629497d..33579f544c 100644 --- a/indra/newview/llviewerjoystick.h +++ b/indra/newview/llviewerjoystick.h @@ -55,9 +55,8 @@ class LLViewerJoystick : public LLSingleton<LLViewerJoystick> public: void init(bool autoenable); void initDevice(LLSD &guid); - void initDevice(void * preffered_device /*LPDIRECTINPUTDEVICE8*/); - void initDevice(void * preffered_device /*LPDIRECTINPUTDEVICE8*/, std::string &name, LLSD &guid); - bool initDevice(NDOF_Device * ndof_device, LLSD::Binary &guid); + bool initDevice(void * preffered_device /*LPDIRECTINPUTDEVICE8*/); + bool initDevice(void * preffered_device /*LPDIRECTINPUTDEVICE8*/, std::string &name, LLSD &guid); void terminate(); void updateStatus(); @@ -80,6 +79,7 @@ public: LLSD getDeviceUUID(); //unconverted, OS dependent value wrapped into LLSD, for comparison/search std::string getDeviceUUIDString(); // converted readable value for settings std::string getDescription(); + void saveDeviceIdToSettings(); protected: void updateEnabled(bool autoenable); |