Skip to content

Commit

Permalink
Finish adding logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Mar 28, 2021
1 parent ea51ab9 commit 29c9b26
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 18 deletions.
1 change: 1 addition & 0 deletions applications/system-service/dbusservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
2 changes: 1 addition & 1 deletion applications/system-service/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
35 changes: 25 additions & 10 deletions applications/system-service/notificationapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QDBusObjectPath> getAllNotifications(){
Expand Down Expand Up @@ -77,15 +78,11 @@ class NotificationAPI : public APIBase {
}
QList<Notification*> 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, [=]{
Expand All @@ -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")){
Expand Down
23 changes: 23 additions & 0 deletions applications/system-service/systemapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "appsapi.h"
#include "powerapi.h"
#include "wifiapi.h"
#include "notificationapi.h"
#include "devicesettings.h"

#ifdef DEBUG
Expand Down Expand Up @@ -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();
}
24 changes: 17 additions & 7 deletions applications/system-service/systemapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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;
Expand Down Expand Up @@ -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()){
Expand Down Expand Up @@ -208,7 +217,7 @@ public slots:
emit powerOffInhibitedChanged(false);
}
}

void toggleSwipes();
signals:
void leftAction();
void homeAction();
Expand Down Expand Up @@ -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<SwipeDirection, bool> swipeStates;

void inhibitSleep(){
inhibitors.append(Inhibitor(systemd, "sleep", qApp->applicationName(), "Handle sleep screen"));
Expand Down Expand Up @@ -472,23 +481,23 @@ 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;
}
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);
Expand All @@ -500,6 +509,7 @@ private slots:
}
if(swipeDirection == Left){
emit rightAction();

}else{
emit leftAction();
}
Expand Down

0 comments on commit 29c9b26

Please sign in to comment.