diff --git a/bin/win64/res/qml/UtilitiesPage.qml b/bin/win64/res/qml/UtilitiesPage.qml index 2085c5a..afb626a 100644 --- a/bin/win64/res/qml/UtilitiesPage.qml +++ b/bin/win64/res/qml/UtilitiesPage.qml @@ -214,6 +214,16 @@ MyStackViewPage { } } } + + RowLayout { + MyToggleButton { + id: alarmDontAnnoyToggle + text: "Don't Annoy me" + onCheckedChanged: { + UtilitiesTabController.setAlarmIsModal(!checked, false) + } + } + } } } @@ -223,6 +233,7 @@ MyStackViewPage { Component.onCompleted: { alarmClockToggle.checked = UtilitiesTabController.alarmEnabled + alarmDontAnnoyToggle.checked = !UtilitiesTabController.alarmIsModal setAlarmHourText(UtilitiesTabController.alarmTimeHour) setAlarmMinuteText(UtilitiesTabController.alarmTimeMinute) alarmGroupBox.visible = !OverlayController.desktopMode @@ -234,6 +245,9 @@ MyStackViewPage { onAlarmEnabledChanged: { alarmClockToggle.checked = UtilitiesTabController.alarmEnabled } + onAlarmIsModalChanged: { + alarmDontAnnoyToggle.checked = !UtilitiesTabController.alarmIsModal + } onAlarmTimeHourChanged: { setAlarmHourText(UtilitiesTabController.alarmTimeHour) } diff --git a/src/overlaycontroller.h b/src/overlaycontroller.h index b0f9bd1..841dba7 100644 --- a/src/overlaycontroller.h +++ b/src/overlaycontroller.h @@ -44,7 +44,7 @@ class OverlayController : public QObject { public: static constexpr const char* applicationKey = "matzman666.AdvancedSettings"; static constexpr const char* applicationName = "Advanced Settings"; - static constexpr const char* applicationVersionString = "v2.2"; + static constexpr const char* applicationVersionString = "v2.2.1"; private: vr::VROverlayHandle_t m_ulOverlayHandle = vr::k_ulOverlayHandleInvalid; diff --git a/src/tabcontrollers/UtilitiesTabController.cpp b/src/tabcontrollers/UtilitiesTabController.cpp index 566d696..ab5ed6f 100644 --- a/src/tabcontrollers/UtilitiesTabController.cpp +++ b/src/tabcontrollers/UtilitiesTabController.cpp @@ -12,10 +12,12 @@ namespace advsettings { auto settings = OverlayController::appSettings(); settings->beginGroup("utilitiesSettings"); auto qAlarmEnabled = settings->value("alarmEnabled", m_alarmEnabled); + auto qAlarmIsModal = settings->value("alarmIsModal", m_alarmIsModal); auto qAlarmHour = settings->value("alarmHour", 0); auto qAlarmMinute = settings->value("alarmMinute", 0); settings->endGroup(); m_alarmEnabled = qAlarmEnabled.toBool(); + m_alarmIsModal = qAlarmIsModal.toBool(); m_alarmTime = QTime(qAlarmHour.toInt(), qAlarmMinute.toInt()); } @@ -160,6 +162,10 @@ namespace advsettings { return m_alarmEnabled; } + bool UtilitiesTabController::alarmIsModal() const { + return m_alarmIsModal; + } + int UtilitiesTabController::alarmTimeHour() const { return m_alarmTime.hour(); } @@ -183,6 +189,20 @@ namespace advsettings { } } + void UtilitiesTabController::setAlarmIsModal(bool modal, bool notify) { + if (m_alarmIsModal != modal) { + m_alarmIsModal = modal; + auto settings = OverlayController::appSettings(); + settings->beginGroup("utilitiesSettings"); + settings->setValue("alarmIsModal", m_alarmIsModal); + settings->endGroup(); + settings->sync(); + if (notify) { + emit alarmIsModalChanged(m_alarmIsModal); + } + } + } + void UtilitiesTabController::setAlarmTimeHour(int hour, bool notify) { if (m_alarmTime.hour() != hour) { if (m_alarmTime.isValid()) { @@ -278,22 +298,7 @@ namespace advsettings { setAlarmEnabled(false); char alarmMessageBuffer[1024]; std::snprintf(alarmMessageBuffer, 1024, "The alarm at %02i:%02i went off.", alarmTimeHour(), alarmTimeMinute()); - vr::VRNotificationId notificationId; - vr::EVRInitError eError; - vr::IVRNotifications* vrnotification = (vr::IVRNotifications*)vr::VR_GetGenericInterface(vr::IVRNotifications_Version, &eError); - if (eError != vr::VRInitError_None) { - LOG(ERROR) << "Error while getting IVRNotifications interface" << vr::VR_GetVRInitErrorAsEnglishDescription(eError); - vrnotification = nullptr; - } else { - auto nError = vrnotification->CreateNotification( - parent->overlayThumbnailHandle(), 666, vr::EVRNotificationType_Transient_SystemWithUserValue, alarmMessageBuffer, vr::EVRNotificationStyle_Application, nullptr, ¬ificationId - ); - if (nError != vr::VRNotificationError_OK) { - LOG(ERROR) << "Error while creating notification: " << nError; - vrnotification = nullptr; - } - } - if (!vr::VROverlay()->IsDashboardVisible()) { // message overlay is not shown when the dashboard is visible (see https://github.com/ValveSoftware/openvr/issues/348) + if (m_alarmIsModal) { std::thread messageThread([](UtilitiesTabController* parent, std::string message) { auto res = vr::VROverlay()->ShowMessageOverlay(message.c_str(), "Alarm Clock", "Ok", "+15 min"); if (res == vr::VRMessageOverlayResponse_ButtonPress_1) { @@ -311,6 +316,46 @@ namespace advsettings { } }, this, std::string(alarmMessageBuffer)); messageThread.detach(); + } else { + vr::VRNotificationId notificationId; + vr::EVRInitError eError; + vr::IVRNotifications* vrnotification = (vr::IVRNotifications*)vr::VR_GetGenericInterface(vr::IVRNotifications_Version, &eError); + if (eError != vr::VRInitError_None) { + LOG(ERROR) << "Error while getting IVRNotifications interface" << vr::VR_GetVRInitErrorAsEnglishDescription(eError); + vrnotification = nullptr; + } else { + vr::NotificationBitmap_t* messageIconPtr = nullptr; + /* + // Can i even create this object on the stack, who takes ownership? + vr::NotificationBitmap_t messageIcon; + + // First get image width and height + vr::VROverlay()->GetOverlayImageData(parent->overlayThumbnailHandle(), nullptr, 0, (uint32_t*)&messageIcon.m_nWidth, (uint32_t*)&messageIcon.m_nHeight); + + messageIcon.m_nBytesPerPixel = 4; + unsigned bufferSize = messageIcon.m_nWidth*messageIcon.m_nHeight*messageIcon.m_nBytesPerPixel; + + // Can I delete this buffer after this section? Who takes ownership? + std::unique_ptr imageBuffer; + imageBuffer.reset(new char[bufferSize]); + messageIcon.m_pImageData = imageBuffer.get(); + + // Get image data + auto iconError = vr::VROverlay()->GetOverlayImageData(parent->overlayThumbnailHandle(), messageIcon.m_pImageData, bufferSize, (uint32_t*)&messageIcon.m_nWidth, (uint32_t*)&messageIcon.m_nHeight); + if (iconError != vr::VROverlayError_None) { + LOG(ERROR) << "Error while getting message overlay icon: " << vr::VROverlay()->GetOverlayErrorNameFromEnum(iconError); + } else { + messageIconPtr = &messageIcon; + } + */ + auto nError = vrnotification->CreateNotification( + parent->overlayHandle(), 666, vr::EVRNotificationType_Transient, alarmMessageBuffer, vr::EVRNotificationStyle_Application, messageIconPtr, ¬ificationId + ); + if (nError != vr::VRNotificationError_OK) { + LOG(ERROR) << "Error while creating notification: " << nError; + vrnotification = nullptr; + } + } } } m_alarmLastCheckTime = now; diff --git a/src/tabcontrollers/UtilitiesTabController.h b/src/tabcontrollers/UtilitiesTabController.h index 4213e57..9c16f8b 100644 --- a/src/tabcontrollers/UtilitiesTabController.h +++ b/src/tabcontrollers/UtilitiesTabController.h @@ -15,6 +15,7 @@ namespace advsettings { class UtilitiesTabController : public QObject { Q_OBJECT Q_PROPERTY(bool alarmEnabled READ alarmEnabled WRITE setAlarmEnabled NOTIFY alarmEnabledChanged) + Q_PROPERTY(bool alarmIsModal READ alarmIsModal WRITE setAlarmIsModal NOTIFY alarmIsModalChanged) Q_PROPERTY(int alarmTimeHour READ alarmTimeHour WRITE setAlarmTimeHour NOTIFY alarmTimeHourChanged) Q_PROPERTY(int alarmTimeMinute READ alarmTimeMinute WRITE setAlarmTimeMinute NOTIFY alarmTimeMinuteChanged) @@ -25,6 +26,7 @@ namespace advsettings { unsigned settingsUpdateCounter = 0; bool m_alarmEnabled = false; + bool m_alarmIsModal = true; QTime m_alarmTime; QTime m_alarmLastCheckTime; @@ -35,6 +37,7 @@ namespace advsettings { void eventLoopTick(); bool alarmEnabled() const; + bool alarmIsModal() const; int alarmTimeHour() const; int alarmTimeMinute() const; @@ -44,6 +47,7 @@ namespace advsettings { void sendKeyboardBackspace(int count); void setAlarmEnabled(bool enabled, bool notify = true); + void setAlarmIsModal(bool modal, bool notify = true); void setAlarmTimeHour(int hour, bool notify = true); void setAlarmTimeMinute(int min, bool notify = true); void setAlarmTimeToCurrentTime(); @@ -52,6 +56,7 @@ namespace advsettings { signals: void alarmEnabledChanged(bool enabled); + void alarmIsModalChanged(bool modal); void alarmTimeHourChanged(int hour); void alarmTimeMinuteChanged(int min); };