diff --git a/applications/system-service/dbusservice.h b/applications/system-service/dbusservice.h index a0d8d6abd..1073cf423 100644 --- a/applications/system-service/dbusservice.h +++ b/applications/system-service/dbusservice.h @@ -121,6 +121,7 @@ class DBusService : public APIBase { }); connect(systemAPI, &SystemAPI::homeAction, appsAPI, &AppsAPI::openTaskManager); connect(systemAPI, &SystemAPI::bottomAction, appsAPI, &AppsAPI::openTaskSwitcher); + connect(systemAPI, &SystemAPI::topAction, systemAPI, &SystemAPI::toggleSwipes); auto bus = QDBusConnection::systemBus(); for(auto api : apis){ diff --git a/applications/system-service/notification.h b/applications/system-service/notification.h index e031e9fc2..0c4665bbd 100644 --- a/applications/system-service/notification.h +++ b/applications/system-service/notification.h @@ -17,7 +17,7 @@ class Notification : public QObject{ Q_PROPERTY(QString text READ text WRITE setText) Q_PROPERTY(QString icon READ icon WRITE setIcon) public: - Notification(QString path, QString identifier, QString owner, QString application, QString text, QString icon, QObject* parent) + Notification(const QString& path, const QString& identifier, const QString& owner, const QString& application, const QString& text, const QString& icon, QObject* parent) : QObject(parent), m_path(path), m_identifier(identifier), diff --git a/applications/system-service/notificationapi.h b/applications/system-service/notificationapi.h index 64e721ce3..87bce61a6 100644 --- a/applications/system-service/notificationapi.h +++ b/applications/system-service/notificationapi.h @@ -46,10 +46,11 @@ class NotificationAPI : public APIBase { if(!hasPermission("notification")){ return QDBusObjectPath("/"); } - if(!m_notifications.contains(identifier)){ + auto notification = getByIdentifier(identifier); + if(notification == nullptr){ return QDBusObjectPath("/"); } - return m_notifications.value(identifier)->qPath(); + return notification->qPath(); } QList getAllNotifications(){ @@ -77,15 +78,11 @@ class NotificationAPI : public APIBase { } QList notificationDisplayQueue; -public slots: - QDBusObjectPath add(QString identifier, QString application, QString text, QString icon, QDBusMessage message){ - if(!hasPermission("notification")){ - return QDBusObjectPath("/"); - } + Notification* add(const QString& identifier, const QString& owner, const QString& application, const QString& text, const QString& icon){ if(m_notifications.contains(identifier)){ - return QDBusObjectPath("/"); + return nullptr; } - auto notification = new Notification(getPath(identifier), identifier, message.service(), application, text, icon, this); + auto notification = new Notification(getPath(identifier), identifier, owner, application, text, icon, this); m_notifications.insert(identifier, notification); auto path = notification->qPath(); connect(notification, &Notification::changed, this, [=]{ @@ -95,7 +92,25 @@ public slots: notification->registerPath(); } emit notificationAdded(path); - return path; + return notification; + } + Notification* getByIdentifier(const QString& identifier){ + if(!m_notifications.contains(identifier)){ + return nullptr; + } + return m_notifications.value(identifier); + } + +public slots: + QDBusObjectPath add(const QString& identifier, const QString& application, const QString& text, const QString& icon, QDBusMessage message){ + if(!hasPermission("notification")){ + return QDBusObjectPath("/"); + } + auto notification = add(identifier, message.service(), application, text, icon); + if(notification == nullptr){ + return QDBusObjectPath("/"); + } + return notification->qPath(); } bool take(QString identifier, QDBusMessage message){ if(!hasPermission("notification")){ diff --git a/applications/system-service/systemapi.cpp b/applications/system-service/systemapi.cpp index 7c834adde..7658f40c7 100644 --- a/applications/system-service/systemapi.cpp +++ b/applications/system-service/systemapi.cpp @@ -2,6 +2,7 @@ #include "appsapi.h" #include "powerapi.h" #include "wifiapi.h" +#include "notificationapi.h" #include "devicesettings.h" #ifdef DEBUG @@ -149,3 +150,25 @@ void SystemAPI::timeout(){ suspend(); } } +void SystemAPI::toggleSwipes(){ + bool state = !swipeStates[Up]; + setSwipeEnabled(Left, state); + setSwipeEnabled(Right, state); + setSwipeEnabled(Up, state); + QString message = state ? "Swipes Enabled" : "Swipes Disabled"; + qDebug() << message; + const QString& id = "system-swipe-toggle"; + auto notification = notificationAPI->add(id, OXIDE_SERVICE, "tarnish", message, ""); + if(notification == nullptr){ + notification = notificationAPI->getByIdentifier(id); + if(notification == nullptr){ + return; + } + }else{ + connect(notification, &Notification::clicked, [notification]{ + notification->remove(); + }); + } + notification->setText(message); + notification->display(); +} diff --git a/applications/system-service/systemapi.h b/applications/system-service/systemapi.h index 54b8e5607..d5a4a2de9 100644 --- a/applications/system-service/systemapi.h +++ b/applications/system-service/systemapi.h @@ -72,6 +72,8 @@ class SystemAPI : public APIBase { Q_PROPERTY(bool sleepInhibited READ sleepInhibited NOTIFY sleepInhibitedChanged) Q_PROPERTY(bool powerOffInhibited READ powerOffInhibited NOTIFY powerOffInhibitedChanged) public: + enum SwipeDirection { None, Right, Left, Up, Down }; + Q_ENUM(SwipeDirection) static SystemAPI* singleton(SystemAPI* self = nullptr){ static SystemAPI* instance; if(self != nullptr){ @@ -86,7 +88,11 @@ class SystemAPI : public APIBase { sleepInhibitors(), powerOffInhibitors(), mutex(), - touches(){ + touches(), + swipeStates() { + for(short i = Right; i <= Down; i++){ + swipeStates[(SwipeDirection)i] = true; + } settings.sync(); singleton(this); this->resumeApp = nullptr; @@ -150,6 +156,9 @@ class SystemAPI : public APIBase { void startSuspendTimer(); void lock(){ mutex.lock(); } void unlock() { mutex.unlock(); } + void setSwipeEnabled(SwipeDirection direction, bool enabled){ swipeStates[direction] = enabled; } + bool getSwipeEnabled(SwipeDirection direction){ return swipeStates[direction]; } + void toggleSwipeEnabled(SwipeDirection direction){ setSwipeEnabled(direction, !getSwipeEnabled(direction)); } public slots: void suspend(){ if(sleepInhibited()){ @@ -208,7 +217,7 @@ public slots: emit powerOffInhibitedChanged(false); } } - + void toggleSwipes(); signals: void leftAction(); void homeAction(); @@ -334,10 +343,10 @@ private slots: int currentSlot = 0; int m_autoSleep; bool wifiWasOn = false; - enum SwipeDirection { None, Right, Left, Up, Down }; int swipeDirection = None; QPoint location; QPoint startLocation; + QMap swipeStates; void inhibitSleep(){ inhibitors.append(Inhibitor(systemd, "sleep", qApp->applicationName(), "Handle sleep screen")); @@ -472,14 +481,14 @@ private slots: } auto touch = touches.first(); if(swipeDirection == Up){ - if(touch->y < location.y() || touch->y - startLocation.y() < GESTURE_LENGTH){ + if(!swipeStates[Up] || touch->y < location.y() || touch->y - startLocation.y() < GESTURE_LENGTH){ // Must end swiping up and having gone far enough cancelSwipe(touch); return; } emit bottomAction(); }else if(swipeDirection == Down){ - if(touch->y > location.y() || startLocation.y() - touch->y < GESTURE_LENGTH){ + if(!swipeStates[Down] || touch->y > location.y() || startLocation.y() - touch->y < GESTURE_LENGTH){ // Must end swiping down and having gone far enough cancelSwipe(touch); return; @@ -487,8 +496,8 @@ private slots: emit topAction(); }else if(swipeDirection == Right || swipeDirection == Left){ auto isRM2 = deviceSettings.getDeviceType() == DeviceSettings::RM2; - auto invalidLeft = touch->x < location.x() || touch->x - startLocation.x() < GESTURE_LENGTH; - auto invalidRight = touch->x > location.x() || startLocation.x() - touch->x < GESTURE_LENGTH; + auto invalidLeft = !swipeStates[Left] || touch->x < location.x() || touch->x - startLocation.x() < GESTURE_LENGTH; + auto invalidRight = !swipeStates[Right] || touch->x > location.x() || startLocation.x() - touch->x < GESTURE_LENGTH; if(swipeDirection == Right && (isRM2 ? invalidLeft : invalidRight)){ // Must end swiping right and having gone far enough cancelSwipe(touch); @@ -500,6 +509,7 @@ private slots: } if(swipeDirection == Left){ emit rightAction(); + }else{ emit leftAction(); }