Skip to content

Commit

Permalink
Start moving tarnish over to using blight
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Jan 29, 2024
1 parent e8df3f0 commit cd7427e
Show file tree
Hide file tree
Showing 25 changed files with 187 additions and 1,120 deletions.
19 changes: 19 additions & 0 deletions applications/display-server/dbusinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,25 @@ void DbusInterface::setFlags(QString identifier, const QStringList& flags, QDBus
}
}

QStringList DbusInterface::getSurfaces(QDBusMessage message){
if(message.service() != "codes.eeems.oxide1"){
sendErrorReply(QDBusError::AccessDenied, "Access denied");
return QStringList();
}
QStringList surfaces;
for(auto connection : qAsConst(connections)){
if(!connection->isRunning()){
continue;
}
for(auto& surface : connection->getSurfaces()){
if(surface != nullptr){
surfaces.append(surface->id());
}
}
}
return surfaces;
}

Connection* DbusInterface::focused(){ return m_focused; }

void DbusInterface::serviceOwnerChanged(const QString& name, const QString& oldOwner, const QString& newOwner){
Expand Down
1 change: 1 addition & 0 deletions applications/display-server/dbusinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public slots:
void repaint(QString identifier, QDBusMessage message);
QDBusUnixFileDescriptor getSurface(ushort identifier, QDBusMessage message);
void setFlags(QString identifier, const QStringList& flags, QDBusMessage message);
QStringList getSurfaces(QDBusMessage message);

signals:
void clipboardChanged(const QByteArray& data);
Expand Down
12 changes: 12 additions & 0 deletions applications/system-service/apibase.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "apibase.h"
#include "appsapi.h"

#include <liboxide/oxideqml.h>

int APIBase::hasPermission(QString permission, const char* sender){
if(getpgid(getpid()) == getSenderPgid()){
return true;
Expand Down Expand Up @@ -30,3 +32,13 @@ int APIBase::getSenderPid() {
int APIBase::getSenderPgid() { return getpgid(getSenderPid()); }

#include "moc_apibase.cpp"

QImage* getFrameBuffer(){
static auto framebuffer = Oxide::QML::getImageForWindow(getFrameBufferWindow());
return &framebuffer;
}

QWindow* getFrameBufferWindow(){
static auto window = qApp->focusWindow();
return window;
}
3 changes: 3 additions & 0 deletions applications/system-service/apibase.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusMessage>
#include <QImage>

#include <liboxide.h>
#include <unistd.h>
Expand All @@ -27,5 +28,7 @@ class APIBase : public QObject, protected QDBusContext {
int getSenderPid();
int getSenderPgid();
};
QWindow* getFrameBufferWindow();
QImage* getFrameBuffer();

#endif // APIBASE_H
91 changes: 5 additions & 86 deletions applications/system-service/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <signal.h>
#include <liboxide.h>
#include <liboxide/oxideqml.h>

#include "application.h"
#include "appsapi.h"
Expand All @@ -12,6 +13,7 @@
#include "notificationapi.h"
#include "screenapi.h"
#include "buttonhandler.h"
#include "apibase.h"

using namespace Oxide::Applications;

Expand Down Expand Up @@ -131,9 +133,6 @@ void Application::pauseNoSecurityCheck(bool startIfNone){
Q_UNUSED(t);
#endif
interruptApplication();
if(!flags().contains("nosavescreen")){
saveScreen();
}
if(startIfNone){
appsAPI->resumeIfNone();
}
Expand Down Expand Up @@ -246,9 +245,6 @@ void Application::resumeNoSecurityCheck(){
appsAPI->recordPreviousApplication();
qDebug() << "Resuming " << path();
appsAPI->pauseAll();
if(!flags().contains("nosavescreen") && (type() != Backgroundable || stateNoSecurityCheck() == Paused)){
recallScreen();
}
uninterruptApplication();
waitForResume();
emit resumed();
Expand Down Expand Up @@ -282,7 +278,6 @@ void Application::uninterruptApplication(){
case Background:
case Backgroundable:
if(stateNoSecurityCheck() == Paused){
systemAPI->clearDeviceBuffers();
kill(-m_process->processId(), SIGCONT);
}
qDebug() << "Waiting for SIGUSR1 ack";
Expand All @@ -301,7 +296,6 @@ void Application::uninterruptApplication(){
break;
case Foreground:
default:
systemAPI->clearDeviceBuffers();
kill(-m_process->processId(), SIGCONT);
startSpan("foreground", "Application is in the foreground");
}
Expand Down Expand Up @@ -337,7 +331,6 @@ void Application::stopNoSecurityCheck(){
Application* pausedApplication = nullptr;
if(state == Paused){
Oxide::Sentry::sentry_span(t, "resume", "Resume paused application", [this, &pausedApplication](){
systemAPI->clearDeviceBuffers();
auto currentApplication = appsAPI->currentApplicationNoSecurityCheck();
if(currentApplication.path() != path()){
pausedApplication = appsAPI->getApplication(currentApplication);
Expand Down Expand Up @@ -530,30 +523,6 @@ void Application::setConfig(const QVariantMap& config){
setValue("bin", oldBin);
}
}

void Application::saveScreen(){
if(m_screenCapture != nullptr){
return;
}
Oxide::Sentry::sentry_transaction("application", "saveScreen", [this](Oxide::Sentry::Transaction* t){
qDebug() << "Saving screen...";
QByteArray bytes;
Oxide::Sentry::sentry_span(t, "save", "Save the framebuffer", [&bytes]{
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
dispatchToMainThread([&buffer]{
if(!EPFrameBuffer::framebuffer()->save(&buffer, "JPG", 100)){
O_WARNING("Failed to save buffer");
}
});
});
qDebug() << "Compressing data...";
Oxide::Sentry::sentry_span(t, "compress", "Compress the framebuffer", [this, bytes]{
m_screenCapture = new QByteArray(qCompress(bytes));
});
qDebug() << "Screen saved " << m_screenCapture->size() << "bytes";
});
}
void Application::started(){
emit launched();
emit appsAPI->applicationLaunched(qPath());
Expand Down Expand Up @@ -937,7 +906,7 @@ QStringList Application::getActiveMounts(){
return activeMounts;
}
void Application::showSplashScreen(){
auto frameBuffer = EPFrameBuffer::framebuffer();
auto frameBuffer = getFrameBuffer();
qDebug() << "Waiting for other painting to finish...";
Oxide::Sentry::sentry_transaction("application", "showSplashScreen", [this, frameBuffer](Oxide::Sentry::Transaction* t){
#ifdef SENTRY
Expand All @@ -950,7 +919,7 @@ void Application::showSplashScreen(){
Oxide::Sentry::sentry_span(t, "wait", "Wait for screen to be ready", [frameBuffer](){
dispatchToMainThread([frameBuffer]{
while(frameBuffer->paintingActive()){
EPFrameBuffer::waitForLastUpdate();
// TODO - don't spinlock
}
});
});
Expand Down Expand Up @@ -983,18 +952,12 @@ void Application::showSplashScreen(){
splashSize
);
painter.drawImage(splashRect, splash, splash.rect());
EPFrameBuffer::sendUpdate(frameBuffer->rect(), EPFrameBuffer::HighQualityGrayscale, EPFrameBuffer::FullUpdate, true);
Oxide::QML::repaint(getFrameBufferWindow(), frameBuffer->rect(), Blight::HighQualityGrayscale, true);
}
painter.end();
notificationAPI->drawNotificationText("Loading " + displayName() + "...");
});
});
qDebug() << "Waitng for screen to finish...";
Oxide::Sentry::sentry_span(t, "wait", "Wait for screen finish updating", [](){
dispatchToMainThread([]{
EPFrameBuffer::waitForLastUpdate();
});
});
});
qDebug() << "Finished painting splash screen for" << name();
}
Expand Down Expand Up @@ -1025,50 +988,6 @@ void Application::startSpan(std::string operation, std::string description){
span = Oxide::Sentry::start_span(transaction, operation, description);
}

void Application::recallScreen() {
if (m_screenCapture == nullptr) {
return;
}
Oxide::Sentry::sentry_transaction(
"application", "recallScreen", [this](Oxide::Sentry::Transaction *t) {
qDebug() << "Uncompressing screen...";
QImage img;
Oxide::Sentry::sentry_span(
t, "decompress", "Decompress the framebuffer", [this, &img] {
img = QImage::fromData(screenCaptureNoSecurityCheck(), "JPG");
});
if (img.isNull()) {
qDebug() << "Screen capture was corrupt";
qDebug() << m_screenCapture->size();
delete m_screenCapture;
return;
}
qDebug() << "Recalling screen...";
Oxide::Sentry::sentry_span(
t, "recall", "Recall the screen", [this, img] {
dispatchToMainThread([img] {
auto frameBuffer = EPFrameBuffer::framebuffer();
auto size = frameBuffer->size();
QRect rect(0, 0, size.width(), size.height());

QPainter painter(frameBuffer);
painter.drawImage(rect, img);
painter.end();
EPFrameBuffer::sendUpdate(
rect,
EPFrameBuffer::HighQualityGrayscale,
EPFrameBuffer::FullUpdate,
true
);
EPFrameBuffer::waitForLastUpdate();
});
delete m_screenCapture;
m_screenCapture = nullptr;
});
qDebug() << "Screen recalled.";
});
}

void Application::waitForFinished(){
if(m_process->processId()){
m_process->waitForFinished();
Expand Down
2 changes: 0 additions & 2 deletions applications/system-service/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ class Application : public QObject{

const QVariantMap& getConfig();
void setConfig(const QVariantMap& config);
void saveScreen();
void recallScreen();
void waitForFinished();
void signal(int signal);
QVariant value(QString name, QVariant defaultValue = QVariant());
Expand Down
39 changes: 9 additions & 30 deletions applications/system-service/appsapi.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
#include <liboxide.h>
#include <liboxide/oxideqml.h>

#include "appsapi.h"
#include "notificationapi.h"
#include "systemapi.h"

#ifdef EPAPER
#include <epframebuffer.h>
#else
#define FRAMEBUFFER new QImage(200, 200, QImage::Format_ARGB32_Premultiplied)
#endif

using namespace Oxide;

AppsAPI* AppsAPI::singleton(AppsAPI* self){
Expand Down Expand Up @@ -858,41 +853,31 @@ AppsAPI::~AppsAPI() {
m_stopping = true;
writeApplications();
settings.sync();
dispatchToMainThread([this] {
#ifdef EPAPER
auto frameBuffer = EPFrameBuffer::framebuffer();
dispatchToMainThread([this]{
auto frameBuffer = getFrameBuffer();
qDebug() << "Waiting for other painting to finish...";
while (frameBuffer->paintingActive()) {
EPFrameBuffer::waitForLastUpdate();
while(frameBuffer->paintingActive()){
// TODO - don't spinlock
}
#else
auto frameBuffer = FRAMEBUFFER;
#endif
QPainter painter(frameBuffer);
auto rect = frameBuffer->rect();
auto fm = painter.fontMetrics();
qDebug() << "Clearing screen...";
painter.setPen(Qt::white);
painter.fillRect(rect, Qt::black);
#ifdef EPAPER
EPFrameBuffer::sendUpdate(rect, EPFrameBuffer::Mono, EPFrameBuffer::FullUpdate, true);
EPFrameBuffer::waitForLastUpdate();
#endif
Oxide::QML::repaint(getFrameBufferWindow(), rect, Blight::Mono, true);
painter.end();
qDebug() << "Stopping applications...";
for (auto app : applications) {
for(auto app : applications){
if (app->stateNoSecurityCheck() != Application::Inactive) {
auto text = "Stopping " + app->displayName() + "...";
qDebug() << text.toStdString().c_str();
notificationAPI->drawNotificationText(text, Qt::white, Qt::black);
#ifdef EPAPER
EPFrameBuffer::waitForLastUpdate();
#endif
}
app->stopNoSecurityCheck();
}
qDebug() << "Ensuring all applications have stopped...";
for (auto app : applications) {
for(auto app : applications){
app->waitForFinished();
app->deleteLater();
}
Expand All @@ -909,14 +894,8 @@ AppsAPI::~AppsAPI() {
painter2.translate(-x, -y);
}
painter2.drawText(rect, Qt::AlignCenter, "Goodbye!");
#ifdef EPAPER
EPFrameBuffer::waitForLastUpdate();
EPFrameBuffer::sendUpdate(rect, EPFrameBuffer::Mono, EPFrameBuffer::FullUpdate, true);
#endif
Oxide::QML::repaint(getFrameBufferWindow(), rect, Blight::Mono, true);
painter2.end();
#ifdef EPAPER
EPFrameBuffer::waitForLastUpdate();
#endif
});
}
#include "moc_appsapi.cpp"
Loading

0 comments on commit cd7427e

Please sign in to comment.