diff --git a/applications/applications.pro b/applications/applications.pro index 0e33752e9..fc748b434 100644 --- a/applications/applications.pro +++ b/applications/applications.pro @@ -10,7 +10,6 @@ SUBDIRS = \ lockscreen \ notify-send \ process-manager \ - screenshot-tool \ screenshot-viewer \ settings-manager \ system-service \ @@ -29,7 +28,6 @@ launcher.depends = system-service update-desktop-database lockscreen.depends = system-service notify-send.depends = system-service process-manager.depends = -screenshot-tool.depends = system-service screenshot-viewer.depends = system-service settings-manager.depends = system-service system-service.depends = diff --git a/applications/display-server/dbusinterface.cpp b/applications/display-server/dbusinterface.cpp index 2dec6faaa..f05866f5e 100644 --- a/applications/display-server/dbusinterface.cpp +++ b/applications/display-server/dbusinterface.cpp @@ -6,18 +6,21 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include DbusInterface::DbusInterface(QObject* parent) : QObject(parent), - m_focused(nullptr) + m_focused(nullptr), + buttonsDevNumber{QFileInfo(deviceSettings.getButtonsDevicePath()).baseName().midRef(5).toInt()} { engine.load(QUrl(QStringLiteral("qrc:/Workspace.qml"))); if(engine.rootObjects().isEmpty()){ @@ -369,7 +372,7 @@ void DbusInterface::serviceOwnerChanged(const QString& name, const QString& oldO } void DbusInterface::inputEvents(unsigned int device, const std::vector& events){ - if(m_focused != nullptr){ + if(m_focused != nullptr && device != buttonsDevNumber){ m_focused->inputEvents(device, events); } for(auto connection : qAsConst(connections)){ diff --git a/applications/display-server/dbusinterface.h b/applications/display-server/dbusinterface.h index 1b16dc17c..4a6d952eb 100644 --- a/applications/display-server/dbusinterface.h +++ b/applications/display-server/dbusinterface.h @@ -92,6 +92,7 @@ private slots: QByteArray selection; QByteArray secondary; } clipboards; + unsigned int buttonsDevNumber; Connection* getConnection(QDBusMessage message); Connection* getConnection(QString identifier); diff --git a/applications/display-server/evdevhandler.cpp b/applications/display-server/evdevhandler.cpp index d9d9fbad7..5c4819c68 100644 --- a/applications/display-server/evdevhandler.cpp +++ b/applications/display-server/evdevhandler.cpp @@ -23,7 +23,8 @@ EvDevHandler* EvDevHandler::init(){ } EvDevHandler::EvDevHandler() -: QThread() +: QThread(), + enabled{true} { setObjectName("EvDevHandler"); reloadDevices(); @@ -46,13 +47,12 @@ bool EvDevHandler::hasDevice(event_device device){ void EvDevHandler::reloadDevices(){ O_DEBUG("Reloading devices"); for(auto& device : deviceSettings.inputDevices()){ - if(device.device == deviceSettings.getButtonsDevicePath()){ - continue; - } if(!hasDevice(device) && device.fd > 0){ auto input = new EvDevDevice(this, device); connect(input, &EvDevDevice::inputEvents, this, [this, input](auto events){ - dbusInterface->inputEvents(input->number(), events); + if(enabled){ + dbusInterface->inputEvents(input->number(), events); + } }, Qt::QueuedConnection); O_DEBUG(input->name() << "added"); devices.append(input); diff --git a/applications/display-server/evdevhandler.h b/applications/display-server/evdevhandler.h index 5010dd3a6..6109aec54 100644 --- a/applications/display-server/evdevhandler.h +++ b/applications/display-server/evdevhandler.h @@ -18,9 +18,6 @@ class EvDevHandler : public QThread{ EvDevHandler(); ~EvDevHandler(); -signals: - void inputEvents(unsigned int device, const std::vector& events); - private: QList devices; bool hasDevice(event_device device); diff --git a/applications/screenshot-tool/.gitignore b/applications/screenshot-tool/.gitignore deleted file mode 100644 index fab7372d7..000000000 --- a/applications/screenshot-tool/.gitignore +++ /dev/null @@ -1,73 +0,0 @@ -# This file is used to ignore files which are generated -# ---------------------------------------------------------------------------- - -*~ -*.autosave -*.a -*.core -*.moc -*.o -*.obj -*.orig -*.rej -*.so -*.so.* -*_pch.h.cpp -*_resource.rc -*.qm -.#* -*.*# -core -!core/ -tags -.DS_Store -.directory -*.debug -Makefile* -*.prl -*.app -moc_*.cpp -ui_*.h -qrc_*.cpp -Thumbs.db -*.res -*.rc -/.qmake.cache -/.qmake.stash - -# qtcreator generated files -*.pro.user* - -# xemacs temporary files -*.flc - -# Vim temporary files -.*.swp - -# Visual Studio generated files -*.ib_pdb_index -*.idb -*.ilk -*.pdb -*.sln -*.suo -*.vcproj -*vcproj.*.*.user -*.ncb -*.sdf -*.opensdf -*.vcxproj -*vcxproj.* - -# MinGW generated files -*.Debug -*.Release - -# Python byte code -*.pyc - -# Binaries -# -------- -*.dll -*.exe - diff --git a/applications/screenshot-tool/main.cpp b/applications/screenshot-tool/main.cpp deleted file mode 100644 index afc9b9fdb..000000000 --- a/applications/screenshot-tool/main.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include -#include -#include - -#include -#include -#include - -using namespace codes::eeems::oxide1; -using namespace Oxide::Sentry; - -void unixSignalHandler(int signal){ - qDebug() << "Recieved signal" << signal; - exit(EXIT_SUCCESS); -} -void onExit(){ - qDebug() << "Exiting"; -} - -void addNotification(Notifications* notifications, QString text, QString icon = ""){ - auto guid = QUuid::createUuid().toString(); - qDebug() << "Adding notification" << guid; - QDBusObjectPath path = notifications->add(guid, "codes.eeems.fret", text, icon); - if(path.path() != "/"){ - auto notification = new Notification(OXIDE_SERVICE, path.path(), QDBusConnection::systemBus(), notifications->parent()); - qDebug() << "Displaying notification" << guid; - notification->display().waitForFinished(); - QObject::connect(notification, &Notification::clicked, [notification]{ - qDebug() << "Notification clicked" << notification->identifier(); - notification->remove(); - notification->deleteLater(); - }); - }else{ - qDebug() << "Failed to add notification"; - } -} - -int main(int argc, char *argv[]){ - QCoreApplication app(argc, argv); - sentry_init("fret", argv); - atexit(onExit); - signal(SIGTERM, unixSignalHandler); - signal(SIGSEGV, unixSignalHandler); - signal(SIGABRT, unixSignalHandler); - signal(SIGSYS, unixSignalHandler); - app.setOrganizationName("Eeems"); - app.setOrganizationDomain(OXIDE_SERVICE); - app.setApplicationName("fret"); - app.setApplicationVersion(APP_VERSION); - auto bus = QDBusConnection::systemBus(); - qDebug() << "Waiting for tarnish to start up..."; - while(!bus.interface()->registeredServiceNames().value().contains(OXIDE_SERVICE)){ - struct timespec args{ - .tv_sec = 1, - .tv_nsec = 0, - }, res; - nanosleep(&args, &res); - } - General api(OXIDE_SERVICE, OXIDE_SERVICE_PATH, bus, &app); - qDebug() << "Requesting system API..."; - QDBusObjectPath path = api.requestAPI("system"); - if(path.path() == "/"){ - qDebug() << "Unable to get system API"; - return EXIT_FAILURE; - } - System system(OXIDE_SERVICE, path.path(), bus, &app); - qDebug() << "Requesting screen API..."; - path = api.requestAPI("screen"); - if(path.path() == "/"){ - qDebug() << "Unable to get screen API"; - return EXIT_FAILURE; - } - Screen screen(OXIDE_SERVICE, path.path(), bus, &app); - qDebug() << "Requesting notification API..."; - path = api.requestAPI("notification"); - if(path.path() == "/"){ - qDebug() << "Unable to get notification API"; - return EXIT_FAILURE; - } - Notifications notifications(OXIDE_SERVICE, path.path(), bus, &app); - qDebug() << "Connecting signal listener..."; - QObject::connect(&system, &System::rightAction, [&screen, ¬ifications, bus, &app]{ - qDebug() << "Taking screenshot"; - auto reply = screen.screenshot(); - reply.waitForFinished(); - if(reply.isError()){ - qDebug() << "Failed to take screenshot"; - addNotification(¬ifications, "Screenshot failed: " + reply.error().message()); - return; - } - auto qPath = reply.value().path(); - if(qPath == "/"){ - qDebug() << "Failed to take screenshot"; - addNotification(¬ifications, "Screenshot failed: Unknown reason"); - return; - } - Screenshot screenshot(OXIDE_SERVICE, qPath, bus, &app); - if(QFile("/tmp/.screenshot").exists()){ - // Then execute the contents of /tmp/.screenshot - qDebug() << "Screenshot file exists."; - QProcess::execute("/bin/bash", QStringList() << "/tmp/.screenshot" << screenshot.path()); - } - addNotification(¬ifications, "Screenshot taken", screenshot.path()); - qDebug() << "Screenshot done."; - }); - qDebug() << "Waiting for signals..."; - return app.exec(); -} diff --git a/applications/screenshot-tool/screenshot-tool.pro b/applications/screenshot-tool/screenshot-tool.pro deleted file mode 100644 index a50d25589..000000000 --- a/applications/screenshot-tool/screenshot-tool.pro +++ /dev/null @@ -1,19 +0,0 @@ -QT -= gui -QT += dbus - -CONFIG += c++11 console -CONFIG -= app_bundle # disables all the APIs deprecated before Qt 6.0.0 - -SOURCES += \ - main.cpp - -TARGET = fret -include(../../qmake/common.pri) -target.path = /opt/bin -INSTALLS += target - -applications.files = ../../assets/opt/usr/share/applications/codes.eeems.fret.oxide -applications.path = /opt/usr/share/applications/ -INSTALLS += applications - -include(../../qmake/liboxide.pri) diff --git a/applications/system-service/application.cpp b/applications/system-service/application.cpp index b58a48454..5a23a92d7 100644 --- a/applications/system-service/application.cpp +++ b/applications/system-service/application.cpp @@ -13,7 +13,6 @@ #include "systemapi.h" #include "notificationapi.h" #include "screenapi.h" -#include "buttonhandler.h" #include "apibase.h" using namespace Oxide::Applications; diff --git a/applications/system-service/buttonhandler.cpp b/applications/system-service/buttonhandler.cpp deleted file mode 100644 index b4d701d24..000000000 --- a/applications/system-service/buttonhandler.cpp +++ /dev/null @@ -1,221 +0,0 @@ -#include "buttonhandler.h" - - -using namespace Oxide; - -void button_exit_handler(){ - // Release lock - buttons.unlock(); - buttons.close(); -} - -void flush_stream(istream* stream){ - // Skip the next event - input_event ie; - streamsize sie = static_cast(sizeof(struct input_event)); - stream->read((char*)&ie, sie); -} -void press_button(event_device& evdev, int code, istream* stream){ - O_DEBUG("inject button " << code); - evdev.unlock(); - evdev.write(EV_KEY, code, 1); - flush_stream(stream); - evdev.ev_syn(); - flush_stream(stream); - evdev.write(EV_KEY, code, 0); - flush_stream(stream); - evdev.ev_syn(); - flush_stream(stream); - evdev.lock(); -} - -ButtonHandler* ButtonHandler::init(){ - static ButtonHandler* instance; - if(instance != nullptr){ - return instance; - } - // Get event devices - if(buttons.fd == -1){ - O_WARNING("Failed to open event device: " << buttons.device.c_str()); - throw QException(); - } - if(atexit(button_exit_handler)){ - button_exit_handler(); - throw QException(); - } - instance = new ButtonHandler(); - instance->start(); - return instance; -} - -ButtonHandler::ButtonHandler() : QThread(), filebuf(buttons.fd, ios::in), stream(&filebuf), pressed(), timer(this), m_enabled(true) { - flood = build_flood(); - timer.setInterval(100); - timer.setSingleShot(false); - connect(&timer, &QTimer::timeout, this, &ButtonHandler::timeout); - timer.start(); -} - -void ButtonHandler::setEnabled(bool enabled){ - m_enabled = enabled; -} - -void ButtonHandler::clear_buffer(){ - if(buttons.fd == -1){ - return; - } - O_DEBUG("Clearing event buffer on" << buttons.device.c_str()); - ::write(buttons.fd, flood, EVENT_FLOOD_SIZE); -} - -input_event* ButtonHandler::event_flood(){ return flood; } - -void ButtonHandler::run(){ - char name[256]; - memset(name, 0, sizeof(name)); - ioctl(buttons.fd, EVIOCGNAME(sizeof(name)), name); - O_DEBUG("Reading From : " << buttons.device.c_str() << " (" << name << ")"); - buttons.lock(); - O_DEBUG("Registering exit handler..."); - // Mapping the correct button IDs. - unordered_map map; - map[105] = PressRecord("Left", Qt::Key_Left); - map[102] = PressRecord("Middle", Qt::Key_Home); - map[106] = PressRecord("Right", Qt::Key_Right); - map[116] = PressRecord("Power", Qt::Key_PowerOff); - - O_DEBUG("Listening for keypresses..."); - // Get the size of an input event in the right format! - input_event ie; - streamsize sie = static_cast(sizeof(struct input_event)); - - while(stream.read((char*)&ie, sie)){ - // TODO - Properly pass through non-button presses - // Read for non-zero event codes. - emit rawEvent(ie); - if(ie.code != 0){ - emit activity(); - // Toggle the button state. - map[ie.code].pressed = !map[ie.code].pressed; - if(!map[ie.code].pressed && map[ie.code].name == "Unknown"){ - press_button(buttons, ie.code, &stream); - }else if(map[ie.code].pressed){ - emit keyDown(map[ie.code].keyCode); - }else{ - emit keyUp(map[ie.code].keyCode); - } - }else{ - qApp->processEvents(QEventLoop::AllEvents, 100); - yieldCurrentThread(); - } - } -} - -input_event* ButtonHandler::build_flood(){ - auto n = 512 * 8; - auto num_inst = 4; - input_event* ev = (input_event *)malloc(sizeof(struct input_event) * n * num_inst); - memset(ev, 0, sizeof(input_event) * n * num_inst); - auto i = 0; - while (i < n) { - ev[i++] = createEvent(EV_ABS, ABS_DISTANCE, 1); - ev[i++] = createEvent(EV_SYN, 0, 0); - ev[i++] = createEvent(EV_ABS, ABS_DISTANCE, 2); - ev[i++] = createEvent(EV_SYN, 0, 0); - } - return ev; -} - -input_event ButtonHandler::createEvent(ushort type, ushort code, int value){ - struct input_event event; - event.type = type; - event.code = code; - event.value = value; - return event; -} -void ButtonHandler::pressKey(Qt::Key key){ - int code; - switch(key){ - case Qt::Key_Left: - code = 105; - break; - case Qt::Key_Home: - code = 102; - break; - case Qt::Key_Right: - code = 106; - break; - case Qt::Key_PowerOff: - code = 116; - break; - default: - return; - } - press_button(buttons, code, &stream); -} - -void ButtonHandler::keyDown(Qt::Key key){ - if(!m_enabled){ - return; - } - O_DEBUG("Down" << key); - if(validKeys.contains(key) && !pressed.contains(key)){ - QElapsedTimer timer; - timer.start(); - pressed.insert(key, timer); - } -} - -void ButtonHandler::keyUp(Qt::Key key){ - if(!m_enabled){ - return; - } - O_DEBUG("Up" << key); - if(!pressed.contains(key)){ - // This should never happen - return; - } - auto value = pressed.value(key); - pressed.remove(key); - if(value.hasExpired(700)){ - // Held event already fired - return; - } - if(key == Qt::Key_PowerOff){ - emit powerPress(); - return; - } - pressKey(key); -} - -void ButtonHandler::timeout(){ - if(!m_enabled){ - return; - } - for(auto key : pressed.keys()){ - // If the key has been held for a while - if(!pressed.value(key).hasExpired(700)){ - continue; - } - O_DEBUG("Key held" << key); - switch(key){ - case Qt::Key_Left: - emit leftHeld(); - break; - case Qt::Key_Home: - emit homeHeld(); - break; - case Qt::Key_Right: - emit rightHeld(); - break; - case Qt::Key_PowerOff: - emit powerHeld(); - break; - default: - continue; - } - pressed.remove(key); - } -} - -#include "moc_buttonhandler.cpp" diff --git a/applications/system-service/buttonhandler.h b/applications/system-service/buttonhandler.h deleted file mode 100644 index 8ae1b0545..000000000 --- a/applications/system-service/buttonhandler.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef BUTTONHANDLER_H -#define BUTTONHANDLER_H - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace Oxide; - -#define buttonHandler ButtonHandler::init() -#define EVENT_FLOOD_SIZE 512 * 8 * 4 * sizeof(input_event) - -struct PressRecord { - bool pressed = false; - struct timeval pressTime; - string name = "Unknown"; - Qt::Key keyCode = Qt::Key_unknown; - PressRecord (string name, Qt::Key keyCode) : name(name), keyCode(keyCode) {} - PressRecord() : PressRecord("Unknown", Qt::Key_unknown){} -}; - -static event_device buttons(deviceSettings.getButtonsDevicePath(), O_RDWR); - - -class ButtonHandler : public QThread { - Q_OBJECT - -public: - static ButtonHandler* init(); - - ButtonHandler(); - void setEnabled(bool enabled); - void clear_buffer(); - input_event* event_flood(); - -public slots: - void pressKey(Qt::Key); - -private slots: - void keyDown(Qt::Key key); - void keyUp(Qt::Key key); - void timeout(); - -signals: - void leftHeld(); - void homeHeld(); - void rightHeld(); - void powerHeld(); - void powerPress(); - void activity(); - void rawEvent(const input_event&); - -protected: - void run(); - __gnu_cxx::stdio_filebuf filebuf; - istream stream; - QMap pressed; - QTimer timer; - const QSet validKeys { Qt::Key_Left, Qt::Key_Home, Qt::Key_Right, Qt::Key_PowerOff }; - bool m_enabled; - input_event* flood; - input_event* build_flood(); - inline static input_event createEvent(ushort type, ushort code, int value); -}; - -#endif // BUTTONHANDLER_H diff --git a/applications/system-service/controller.h b/applications/system-service/controller.h index c6cefb27a..d65310bb6 100644 --- a/applications/system-service/controller.h +++ b/applications/system-service/controller.h @@ -19,48 +19,24 @@ class Controller : public QObject{ Q_PROPERTY(int downSwipeLength READ downSwipeLength NOTIFY downSwipeLengthChanged) public: - explicit Controller(QObject* parent = nullptr) : QObject(parent){ - connect(systemAPI, &SystemAPI::swipeLengthChanged, this, [this](int swipe, int length){ - switch((SystemAPI::SwipeDirection)swipe){ - case SystemAPI::Left: - emit leftSwipeLengthChanged(length); - break; - case SystemAPI::Right: - emit rightSwipeLengthChanged(length); - break; - case SystemAPI::Up: - emit upSwipeLengthChanged(length); - break; - case SystemAPI::Down: - emit downSwipeLengthChanged(length); - break; - default: - break; - } - }); - connect(systemAPI, &SystemAPI::swipeEnabledChanged, this, [this](int swipe, bool enabled){ - switch((SystemAPI::SwipeDirection)swipe){ - case SystemAPI::Left: - emit leftSwipeEnabledChanged(enabled); - break; - case SystemAPI::Right: - emit rightSwipeEnabledChanged(enabled); - break; - case SystemAPI::Up: - emit upSwipeEnabledChanged(enabled); - break; - case SystemAPI::Down: - emit downSwipeEnabledChanged(enabled); - break; - default: - break; - } - }); + static Controller* singleton(){ + static Controller* instance = new Controller(qApp); + return instance; } + bool enabled = true; // Used to disable sending input when suspending Q_INVOKABLE void screenshot(){ screenAPI->screenshot(); } Q_INVOKABLE void taskSwitcher(){ appsAPI->openTaskSwitcher(); } Q_INVOKABLE void processManager(){ appsAPI->openTaskManager(); } - Q_INVOKABLE void back(){ appsAPI->previousApplication(); } + Q_INVOKABLE void back(){ + auto currentApplication = appsAPI->getApplication(appsAPI->currentApplicationNoSecurityCheck()); + if(currentApplication != nullptr && currentApplication->path() == appsAPI->lockscreenApplication().path()){ + O_DEBUG("Back cancelled. On lockscreen"); + return; + } + if(!appsAPI->previousApplicationNoSecurityCheck()){ + appsAPI->openDefaultApplication(); + } + } Q_INVOKABLE void lock(){ appsAPI->openLockScreen(); } Q_INVOKABLE void terminal(){ appsAPI->openTerminal(); } Q_INVOKABLE void close(){ @@ -99,6 +75,8 @@ class Controller : public QObject{ int downSwipeLength(){ return systemAPI->getSwipeLength(SystemAPI::Down); } signals: + void keyPressed(int, int, const QString&); + void keyReleased(int, int, const QString&); void leftSwipeEnabledChanged(bool); void rightSwipeEnabledChanged(bool); void upSwipeEnabledChanged(bool); @@ -107,4 +85,65 @@ class Controller : public QObject{ void rightSwipeLengthChanged(int); void upSwipeLengthChanged(int); void downSwipeLengthChanged(int); + +private: + explicit Controller(QObject* parent = nullptr) : QObject(parent){ + connect(systemAPI, &SystemAPI::swipeLengthChanged, this, [this](int swipe, int length){ + switch((SystemAPI::SwipeDirection)swipe){ + case SystemAPI::Left: + emit leftSwipeLengthChanged(length); + break; + case SystemAPI::Right: + emit rightSwipeLengthChanged(length); + break; + case SystemAPI::Up: + emit upSwipeLengthChanged(length); + break; + case SystemAPI::Down: + emit downSwipeLengthChanged(length); + break; + default: + break; + } + }); + connect(systemAPI, &SystemAPI::swipeEnabledChanged, this, [this](int swipe, bool enabled){ + switch((SystemAPI::SwipeDirection)swipe){ + case SystemAPI::Left: + emit leftSwipeEnabledChanged(enabled); + break; + case SystemAPI::Right: + emit rightSwipeEnabledChanged(enabled); + break; + case SystemAPI::Up: + emit upSwipeEnabledChanged(enabled); + break; + case SystemAPI::Down: + emit downSwipeEnabledChanged(enabled); + break; + default: + break; + } + }); + eventListener->append([this](QObject* object, QEvent* event){ + if(!enabled){ + return false; + } + Q_UNUSED(object); + switch(event->type()){ + case QEvent::KeyPress:{ + auto keyEvent = static_cast(event); + emit keyPressed(keyEvent->key(), keyEvent->modifiers(), keyEvent->text()); + return true; + } + case QEvent::KeyRelease:{ + auto keyEvent = static_cast(event); + emit keyReleased(keyEvent->key(), keyEvent->modifiers(), keyEvent->text()); + return true; + } + default: + break; + } + return false; + }); + } }; diff --git a/applications/system-service/dbusservice.cpp b/applications/system-service/dbusservice.cpp index 16ff35885..53d84b5b8 100644 --- a/applications/system-service/dbusservice.cpp +++ b/applications/system-service/dbusservice.cpp @@ -5,7 +5,6 @@ #include "systemapi.h" #include "screenapi.h" #include "notificationapi.h" -#include "buttonhandler.h" DBusService* DBusService::singleton(){ static DBusService* instance; @@ -108,41 +107,8 @@ DBusService::DBusService(QObject* parent) : APIBase(parent), apis(){ }); }); }); -#ifdef SENTRY - sentry_breadcrumb("dbusservice", "Connecting button handler events", "info"); -#endif Oxide::Sentry::sentry_span(t, "connect", "Connect events", []{ - if(deviceSettings.getDeviceType() == Oxide::DeviceSettings::RM1){ - connect(buttonHandler, &ButtonHandler::leftHeld, systemAPI, &SystemAPI::leftAction); - connect(buttonHandler, &ButtonHandler::homeHeld, systemAPI, &SystemAPI::homeAction); - connect(buttonHandler, &ButtonHandler::rightHeld, systemAPI, &SystemAPI::rightAction); - } - connect(buttonHandler, &ButtonHandler::powerHeld, systemAPI, &SystemAPI::powerAction); - connect(buttonHandler, &ButtonHandler::powerPress, systemAPI, &SystemAPI::suspend); - connect(buttonHandler, &ButtonHandler::activity, systemAPI, &SystemAPI::activity); -#ifdef SENTRY - sentry_breadcrumb("dbusservice", "Connecting power events", "info"); -#endif connect(powerAPI, &PowerAPI::chargerStateChanged, systemAPI, &SystemAPI::activity); -#ifdef SENTRY - sentry_breadcrumb("dbusservice", "Connecting system events", "info"); -#endif - connect(systemAPI, &SystemAPI::leftAction, appsAPI, []{ - if(notificationAPI->locked()){ - return; - } - auto currentApplication = appsAPI->getApplication(appsAPI->currentApplicationNoSecurityCheck()); - if(currentApplication != nullptr && currentApplication->path() == appsAPI->lockscreenApplication().path()){ - O_DEBUG("Left Action cancelled. On lockscreen"); - return; - } - if(!appsAPI->previousApplicationNoSecurityCheck()){ - appsAPI->openDefaultApplication(); - } - }); - connect(systemAPI, &SystemAPI::homeAction, appsAPI, &AppsAPI::openTaskManager); - connect(systemAPI, &SystemAPI::bottomAction, appsAPI, &AppsAPI::openTaskSwitcher); - connect(systemAPI, &SystemAPI::topAction, systemAPI, &SystemAPI::toggleSwipes); }); #ifdef SENTRY sentry_breadcrumb("dbusservice", "Cleaning up", "info"); diff --git a/applications/system-service/main.cpp b/applications/system-service/main.cpp index 4775dfdaa..2c340b106 100755 --- a/applications/system-service/main.cpp +++ b/applications/system-service/main.cpp @@ -191,8 +191,7 @@ int main(int argc, char* argv[]){ QQmlApplicationEngine engine; registerQML(&engine); QQmlContext* context = engine.rootContext(); - Controller controller(&app); - context->setContextProperty("controller", &controller); + context->setContextProperty("controller", Controller::singleton()); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if(engine.rootObjects().isEmpty()){ qFatal("Failed to load main layout"); diff --git a/applications/system-service/main.qml b/applications/system-service/main.qml index ef83879a8..e382b511c 100644 --- a/applications/system-service/main.qml +++ b/applications/system-service/main.qml @@ -9,6 +9,92 @@ Window{ height: Screen.height visible: true color: "transparent" + property bool enableHeldKeys: controller.deviceName === "reMarkable 1" + + Connections{ + target: controller + property alias enableHeldKeys: window.enableHeldKeys + function onKeyPressed(key, modifiers, text){ + switch(key){ + case Qt.Key_Left: + if(enableHeldKeys){ + leftHeldTimer.start(); + } + break; + case Qt.Key_Right: + if(enableHeldKeys){ + rightHeldTimer.start(); + } + break; + case Qt.Key_Home: + if(enableHeldKeys){ + homeHeldTimer.start(); + } + break; + case Qt.Key_PowerOff: + case Qt.Key_Suspend: + powerHeldTimer.start(); + break; + } + } + function onKeyReleased(key, modifiers, text){ + switch(key){ + case Qt.Key_Left: + if(enableHeldKeys){ + leftHeldTimer.stop(); + } + break; + case Qt.Key_Right: + if(enableHeldKeys){ + rightHeldTimer.stop(); + } + break; + case Qt.Key_Home: + if(enableHeldKeys){ + homeHeldTimer.stop(); + } + break; + case Qt.Key_PowerOff: + case Qt.Key_Suspend: + if(powerHeldTimer.running){ + powerHeldTimer.stop(); + controller.suspend(); + } + break; + } + } + } + Timer{ + id: leftHeldTimer + running: false + repeat: false + interval: 700 + onTriggered: controller.back() + } + Timer{ + id: rightHeldTimer + running: false + repeat: false + interval: 700 + onTriggered: controller.screenshot() + } + Timer{ + id: homeHeldTimer + running: false + repeat: false + interval: 700 + onTriggered: controller.processManager() + } + Timer{ + id: powerHeldTimer + running: false + repeat: false + interval: 700 + onTriggered:{ + // TODO - power menu app + } + } + Item{ anchors.fill: parent MultiPointTouchArea{ @@ -105,10 +191,4 @@ Window{ context: Qt.ApplicationShortcut onActivated: controller.close() } - Shortcut{ - enabled: Oxide.deviceName != "reMarkable 2" - sequences: ["PowerOff"] - context: Qt.ApplicationShortcut - onActivated: controller.suspend() - } } diff --git a/applications/system-service/system-service.pro b/applications/system-service/system-service.pro index ab7e55d99..0ef7d08f3 100644 --- a/applications/system-service/system-service.pro +++ b/applications/system-service/system-service.pro @@ -13,7 +13,6 @@ SOURCES += \ application.cpp \ appsapi.cpp \ bss.cpp \ - buttonhandler.cpp \ dbusservice.cpp \ eventlistener.cpp \ fifohandler.cpp \ @@ -63,7 +62,6 @@ HEADERS += \ application.h \ appsapi.h \ bss.h \ - buttonhandler.h \ controller.h \ dbusservice.h \ eventlistener.h \ diff --git a/applications/system-service/systemapi.cpp b/applications/system-service/systemapi.cpp index 38d8894ae..5009b9021 100644 --- a/applications/system-service/systemapi.cpp +++ b/applications/system-service/systemapi.cpp @@ -20,9 +20,9 @@ QDebug operator<<(QDebug debug, Touch* touch){ } void SystemAPI::PrepareForSleep(bool suspending){ - auto device = deviceSettings.getDeviceType(); if(suspending){ - Oxide::Sentry::sentry_transaction("system", "suspend", [this, device](Oxide::Sentry::Transaction* t){ + Controller::singleton()->enabled = false; + Oxide::Sentry::sentry_transaction("system", "suspend", [this](Oxide::Sentry::Transaction* t){ if(autoLock()){ lockTimestamp = QDateTime::currentMSecsSinceEpoch() + lockTimer.remainingTime(); qDebug() << "Auto Lock timestamp:" << lockTimestamp; @@ -86,14 +86,10 @@ void SystemAPI::PrepareForSleep(bool suspending){ resumeApp = nullptr; } }); - Oxide::Sentry::sentry_span(t, "disable", "Disable various services", [this, device]{ - buttonHandler->setEnabled(false); - if(device == Oxide::DeviceSettings::DeviceType::RM2){ - if(wifiAPI->state() != WifiAPI::State::Off){ - wifiWasOn = true; - wifiAPI->disable(); - } - system("/sbin/rmmod brcmfmac"); + Oxide::Sentry::sentry_span(t, "disable", "Disable various services", [this]{ + if(wifiAPI->state() != WifiAPI::State::Off){ + wifiWasOn = true; + wifiAPI->disable(); } getCompositorDBus()->waitForNoRepaints().waitForFinished(); if(m_buffer != nullptr){ @@ -104,11 +100,15 @@ void SystemAPI::PrepareForSleep(bool suspending){ qDebug() << "Suspending..."; }); }else{ - Oxide::Sentry::sentry_transaction("system", "resume", [this, device](Oxide::Sentry::Transaction* t){ + Oxide::Sentry::sentry_transaction("system", "resume", [this](Oxide::Sentry::Transaction* t){ + qDebug() << "Resuming..."; Oxide::Sentry::sentry_span(t, "inhibit", "Inhibit sleep", [this]{ inhibitSleep(); }); - qDebug() << "Resuming..."; + if(m_buffer != nullptr){ + Blight::connection()->remove(m_buffer); + m_buffer = nullptr; + } Oxide::Sentry::sentry_span(t, "process", "Process events", []{ QCoreApplication::processEvents(QEventLoop::AllEvents, 100); }); @@ -141,8 +141,7 @@ void SystemAPI::PrepareForSleep(bool suspending){ qDebug() << "Unable to find an app to resume"; } }); - Oxide::Sentry::sentry_span(t, "enable", "Enable various services", [this, device]{ - buttonHandler->setEnabled(true); + Oxide::Sentry::sentry_span(t, "enable", "Enable various services", [this]{ emit deviceResuming(); if(autoSleep() && powerAPI->chargerState() != PowerAPI::ChargerConnected){ qDebug() << "Suspend timer re-enabled due to resume"; @@ -152,19 +151,13 @@ void SystemAPI::PrepareForSleep(bool suspending){ qDebug() << "Lock timer re-enabled due to resume"; lockTimer.start(autoLock() * 60 * 1000); } - if(device == Oxide::DeviceSettings::DeviceType::RM2){ - system("/sbin/modprobe brcmfmac"); - if(wifiWasOn){ - wifiAPI->enable(); - } + if(wifiWasOn){ + wifiAPI->enable(); } wifiAPI->resumeUpdating(); }); - if(m_buffer != nullptr){ - Blight::connection()->remove(m_buffer); - m_buffer = nullptr; - } }); + Controller::singleton()->enabled = true; } } SystemAPI* SystemAPI::singleton(SystemAPI* self){ @@ -294,8 +287,8 @@ SystemAPI::SystemAPI(QObject* parent) eventListener->append([this](QObject* object, QEvent* event){ Q_UNUSED(object); switch(event->type()){ - case QEvent::KeyRelease: case QEvent::KeyPress: + case QEvent::KeyRelease: case QEvent::Shortcut: case QEvent::ShortcutOverride: case QEvent::TabletPress: diff --git a/applications/system-service/systemapi.h b/applications/system-service/systemapi.h index d4a25e8dc..f5184252c 100644 --- a/applications/system-service/systemapi.h +++ b/applications/system-service/systemapi.h @@ -9,7 +9,6 @@ #include #include "apibase.h" -#include "buttonhandler.h" #include "application.h" #include "screenapi.h" #include "eventlistener.h" diff --git a/applications/system-service/wifiapi.cpp b/applications/system-service/wifiapi.cpp index 061695058..4fdc10953 100644 --- a/applications/system-service/wifiapi.cpp +++ b/applications/system-service/wifiapi.cpp @@ -209,6 +209,9 @@ bool WifiAPI::enable(){ if(!hasPermission("wifi")){ return false; } + if(deviceSettings.getDeviceType() == Oxide::DeviceSettings::DeviceType::RM2){ + system("/sbin/modprobe brcmfmac"); + } qDebug() << "Turning wifi on"; if(m_state == Off){ setState(Disconnected); @@ -245,6 +248,9 @@ void WifiAPI::disable(){ qDebug() << "Failed to disable " + wlan->iface(); } } + if(deviceSettings.getDeviceType() == Oxide::DeviceSettings::DeviceType::RM2){ + system("/sbin/rmmod brcmfmac"); + } if(system("/usr/sbin/rfkill block wifi")){ qDebug() << "Failed to disable wifi devices"; } diff --git a/package b/package index 1f1d29989..030f98cb4 100644 --- a/package +++ b/package @@ -119,9 +119,6 @@ oxide-extra() { conflicts=(fret anxiety) package() { - # Screenshot daemon - install -D -m 755 -t "$pkgdir"/opt/bin "$srcdir"/release/opt/bin/fret - install -D -m 644 -t "$pkgdir"/opt/usr/share/applications "$srcdir"/release/opt/usr/share/applications/codes.eeems.fret.oxide # Screenshot viewer install -D -m 755 -t "$pkgdir"/opt/bin "$srcdir"/release/opt/bin/anxiety install -D -m 644 -t "$pkgdir"/opt/usr/share/applications "$srcdir"/release/opt/usr/share/applications/codes.eeems.anxiety.oxide