Skip to content

Commit

Permalink
Start getting notifications moved over to the new window system
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Jul 20, 2023
1 parent 026e043 commit f68e30e
Show file tree
Hide file tree
Showing 17 changed files with 202 additions and 170 deletions.
17 changes: 14 additions & 3 deletions applications/settings-manager/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,22 @@ int main(int argc, char *argv[]){
#endif
api = new Gui(OXIDE_SERVICE, path, bus);
if(parser.isSet("object")){
qDebug() << "Paths are not valid for the system API";
auto object = parser.value("object");
#ifdef SENTRY
sentry_breadcrumb("error", "invalid arguments");
sentry_breadcrumb("object", object.toStdString().c_str());
#endif
return qExit(EXIT_FAILURE);
auto type = object.mid(0, object.indexOf(":"));
auto path = object.mid(object.indexOf(":") + 1);
path = OXIDE_SERVICE_PATH + QString("/" + path);
if(type == "Window"){
api = new Window(OXIDE_SERVICE, path, bus);
}else{
qDebug() << "Unknown object type" << type;
#ifdef SENTRY
sentry_breadcrumb("error", "Unknown object type");
#endif
return qExit(EXIT_FAILURE);
}
}
}else{
qDebug() << "API not initialized? Please log a bug.";
Expand Down
37 changes: 11 additions & 26 deletions applications/system-service/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,6 @@

using namespace Oxide::Applications;

static Window* __window = nullptr;
Window* Application::_window(){
if(__window == nullptr){
__window = guiAPI->_createWindow(deviceSettings.screenGeometry(), DEFAULT_IMAGE_FORMAT);
__window->disableEventPipe();
}
return __window;
}
void Application::shutdown(){
if(__window != nullptr){
__window->_close();
__window = nullptr;
}
}

const event_device touchScreen(deviceSettings.getTouchDevicePath(), O_WRONLY);

Application::Application(QDBusObjectPath path, QObject* parent) : Application(path.path(), parent) {}
Expand Down Expand Up @@ -207,7 +192,7 @@ void Application::launchNoSecurityCheck(){
m_process->start();
m_process->waitForStarted();
if(!flags().contains("nosplash")){
_window()->_lower();
AppsAPI::_window()->_setVisible(false);
}
if(type() == Background){
startSpan("background", "Application is in the background");
Expand Down Expand Up @@ -1145,10 +1130,10 @@ void Application::showSplashScreen(){
#endif
O_INFO("Displaying splashscreen for" << name());
Oxide::Sentry::sentry_span(t, "paint", "Draw splash screen", [this](){
auto image = _window()->toImage();
auto image = AppsAPI::_window()->toImage();
QPainter painter(&image);
auto fm = painter.fontMetrics();
auto geometry = _window()->_geometry();
auto geometry = AppsAPI::_window()->_geometry();
painter.fillRect(geometry, Qt::white);
QString splashPath = splash();
if(splashPath.isEmpty() || !QFile::exists(splashPath)){
Expand Down Expand Up @@ -1183,10 +1168,10 @@ void Application::showSplashScreen(){
);
painter.end();
});
if(!_window()->_isVisible()){
_window()->_raise(false);
if(!AppsAPI::_window()->_isVisible()){
AppsAPI::_window()->_setVisible(true);
}else{
_window()->_repaint(_window()->_geometry(), EPFrameBuffer::HighQualityGrayscale, 0, false);
AppsAPI::_window()->_repaint(AppsAPI::_window()->_geometry(), EPFrameBuffer::HighQualityGrayscale, 0, false);
}
});
O_INFO("Finished painting splash screen for" << name());
Expand Down Expand Up @@ -1260,15 +1245,15 @@ void Application::recallScreen(){
}

Check notice on line 1245 in applications/system-service/application.cpp

View check run for this annotation

codefactor.io / CodeFactor

applications/system-service/application.cpp#L1245

Execution with unnecessary privileges (CWE-250, CWE-22) (flawfinder7-chroot)
qDebug() << "Recalling screen...";
Oxide::Sentry::sentry_span(t, "recall", "Recall the screen", [this, img]{
auto rect = _window()->geometry();
auto image = _window()->toImage();
auto rect = AppsAPI::_window()->geometry();
auto image = AppsAPI::_window()->toImage();
QPainter painter(&image);
painter.drawImage(rect, img);
painter.end();
if(!_window()->_isVisible()){
_window()->_raise(false);
if(AppsAPI::_window()->_isVisible()){
AppsAPI::_window()->_repaint(rect, EPFrameBuffer::HighQualityGrayscale, 0, false);
}else{
_window()->_repaint(rect, EPFrameBuffer::HighQualityGrayscale, 0, false);
AppsAPI::_window()->_setVisible(true);
}
delete m_screenCapture;
m_screenCapture = nullptr;
Expand Down
3 changes: 0 additions & 3 deletions applications/system-service/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ class Application : public QObject{
Q_PROPERTY(QByteArray screenCapture READ screenCapture)

public:
static Window* _window();
static void shutdown();

Application(QDBusObjectPath path, QObject* parent);
Application(QString path, QObject* parent);
~Application();
Expand Down
20 changes: 18 additions & 2 deletions applications/system-service/appsapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@

using namespace Oxide;

static Window* __window = nullptr;
Window* AppsAPI::_window(){
if(__window == nullptr){
__window = guiAPI->_createWindow(deviceSettings.screenGeometry(), DEFAULT_IMAGE_FORMAT);
__window->setZ(std::numeric_limits<int>::max() - 1);
__window->disableEventPipe();
__window->_setVisible(false);
__window->setSystemWindow();
__window->_raise();
}
return __window;
}

AppsAPI* AppsAPI::singleton(AppsAPI* self){
static AppsAPI* instance;
if(self != nullptr){
Expand Down Expand Up @@ -169,7 +182,7 @@ void AppsAPI::startup(){
void AppsAPI::shutdown(){
O_INFO("Shutting down Apps API");
m_stopping = true;
auto window = Application::_window();
auto window = _window();
auto image = window->toImage();
auto rect = image.rect();
QPainter painter(&image);
Expand Down Expand Up @@ -230,7 +243,10 @@ void AppsAPI::shutdown(){
}else{
window->_raise(false);
}
Application::shutdown();
if(__window != nullptr){
__window->_close();
__window = nullptr;
}
O_INFO("Apps API shutdown complete");
}

Expand Down
1 change: 1 addition & 0 deletions applications/system-service/appsapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AppsAPI : public APIBase {
Q_PROPERTY(QVariantMap pausedApplications READ pausedApplications)

public:
static Window* _window();
static AppsAPI* singleton(AppsAPI* self = nullptr);
AppsAPI(QObject* parent);
~AppsAPI();
Expand Down
21 changes: 15 additions & 6 deletions applications/system-service/guiapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Window* GuiAPI::_createWindow(QRect geometry, QImage::Format format){
auto path = QString(OXIDE_SERVICE_PATH) + "/window/" + QUuid::createUuidV5(NS, id).toString(QUuid::Id128);
auto pgid = getSenderPgid();
m_windowMutex.lock();
auto window = new Window(id, path, pgid, geometry, m_windows.count(), format);
auto window = new Window(id, path, pgid, geometry, format);
m_windows.insert(path, window);
m_windowMutex.unlock();
sortWindows();
Expand Down Expand Up @@ -151,12 +151,15 @@ QDBusObjectPath GuiAPI::createWindow(int format){
}

QList<QDBusObjectPath> GuiAPI::windows(){
auto pgid = getSenderPgid();
QList<QDBusObjectPath> windows;
QMutexLocker locker(&m_windowMutex);
Q_UNUSED(locker)
for(auto window : m_windows){
if(window->pgid() == pgid){
if(!hasPermission()){
W_DENIED();
return windows;
}
W_ALLOWED();
auto pgid = getSenderPgid();
for(auto window : sortedWindows()){
if(window->pgid() == pgid || qEnvironmentVariableIsSet("OXIDE_EXPOSE_ALL_WINDOWS")){
windows.append(window->path());
}
}
Expand Down Expand Up @@ -198,6 +201,9 @@ void GuiAPI::sortWindows(){
int raisedZ = 0;
int loweredZ = -1;
for(auto window : windows){
if(window->systemWindow()){
continue;
}
switch(window->state()){
case Window::Raised:
case Window::RaisedHidden:
Expand Down Expand Up @@ -449,6 +455,9 @@ bool GuiAPI::hasPermission(){
if(DBusService::shuttingDown()){
return false;
}
if(qEnvironmentVariableIsSet("OXIDE_EXPOSE_ALL_WINDOWS")){
return true;
}
pid_t pgid = getSenderPgid();
if(dbusService->isChildGroup(pgid)){
return true;
Expand Down
34 changes: 7 additions & 27 deletions applications/system-service/notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "notificationapi.h"
#include "appsapi.h"
#include "screenapi.h"
#include "window.h"

#include <QFontDatabase>
#include <liboxide.h>
Expand Down Expand Up @@ -110,13 +111,7 @@ void Notification::display(){
notificationAPI->lock();
Oxide::dispatchToMainThread([this]{
O_INFO("Displaying notification" << identifier());
auto path = appsAPI->currentApplicationNoSecurityCheck();
Application* resumeApp = nullptr;
if(path.path() != "/"){
resumeApp = appsAPI->getApplication(path);
resumeApp->interruptApplication();
}
paintNotification(resumeApp);
paintNotification();
});
}

Expand All @@ -135,32 +130,17 @@ void Notification::click(){
emit clicked();
}

void Notification::paintNotification(Application* resumeApp){
void Notification::paintNotification(){
O_INFO("Painting notification" << identifier());
dispatchToMainThread([this]{
screenBackup = screenAPI->copy();
});
updateRect = notificationAPI->paintNotification(text(), m_icon);
notificationAPI->paintNotification(text(), m_icon);
O_INFO("Painted notification" << identifier());
emit displayed();
QTimer::singleShot(2000, [this, resumeApp]{
dispatchToMainThread([this]{
QPainter painter(EPFrameBuffer::framebuffer());
painter.drawImage(updateRect, screenBackup, updateRect);
painter.end();
EPFrameBuffer::sendUpdate(updateRect, EPFrameBuffer::Mono, EPFrameBuffer::FullUpdate, true);
O_INFO("Finished displaying notification" << identifier());
EPFrameBuffer::waitForLastUpdate();
});
QTimer::singleShot(2000, [this]{
NotificationAPI::_window()->_setVisible(false);
if(!notificationAPI->notificationDisplayQueue.isEmpty()){
Oxide::dispatchToMainThread([resumeApp] {
notificationAPI->notificationDisplayQueue.takeFirst()->paintNotification(resumeApp);
});
notificationAPI->notificationDisplayQueue.takeFirst()->paintNotification();
return;
}
if(resumeApp != nullptr){
resumeApp->uninterruptApplication();
}
notificationAPI->unlock();
});
}
Expand Down
4 changes: 1 addition & 3 deletions applications/system-service/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Notification : public QObject{
Q_INVOKABLE void display();
Q_INVOKABLE void remove();
Q_INVOKABLE void click();
void paintNotification(Application* resumeApp);
void paintNotification();

signals:
void changed(QVariantMap);
Expand All @@ -57,8 +57,6 @@ class Notification : public QObject{
QString m_application;
QString m_text;
QString m_icon;
QImage screenBackup;
QRect updateRect;

bool hasPermission(QString permission, const char* sender = __builtin_FUNCTION());
};
Expand Down
Loading

0 comments on commit f68e30e

Please sign in to comment.