Skip to content

Commit

Permalink
Get things somewhat ported over
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Jan 29, 2024
1 parent 6f4cd9b commit 98d03bc
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 72 deletions.
9 changes: 7 additions & 2 deletions applications/display-server/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,14 @@ void Connection::readSocket(){
auto repaint = Blight::repaint_t::from_message(message.get());
O_DEBUG(
"Repaint requested:"
<< QString("%6 (%1,%2) %3x%4 %5")
<< QString("%6 (%1,%2) %3x%4 %5 %7")
.arg(repaint.x)
.arg(repaint.y)
.arg(repaint.width)
.arg(repaint.height)
.arg(repaint.waveform)
.arg(repaint.identifier)
.arg(repaint.marker)
.toStdString()
.c_str()
);
Expand All @@ -312,7 +313,7 @@ void Connection::readSocket(){
surface,
rect,
(EPFrameBuffer::WaveformMode)repaint.waveform,
message->header.ackid,
repaint.marker,
false,
[message, this]{ ack(message, 0, nullptr); }
);
Expand Down Expand Up @@ -471,13 +472,17 @@ void Connection::readSocket(){
break;
}
case Blight::MessageType::Ping:{
#ifdef ACK_DEBUG
O_DEBUG("Pong" << message->header.ackid);
#endif
break;
}
case Blight::MessageType::Ack:
do_ack = false;
if(message->header.ackid == pingId){
#ifdef ACK_DEBUG
O_DEBUG("Pong recieved" << message->header.ackid);
#endif
m_notRespondingTimer.stop();
m_pingTimer.stop();
m_pingTimer.start();
Expand Down
8 changes: 8 additions & 0 deletions applications/display-server/dbusinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@ QStringList DbusInterface::getSurfaces(QDBusMessage message){
return surfaces;
}

QDBusUnixFileDescriptor DbusInterface::frameBuffer(QDBusMessage message){
if(message.service() != "codes.eeems.oxide1"){
sendErrorReply(QDBusError::AccessDenied, "Access denied");
return QDBusUnixFileDescriptor();
}
return QDBusUnixFileDescriptor(::open("/dev/fb0", O_RDWR));
}

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 @@ -66,6 +66,7 @@ public slots:
QDBusUnixFileDescriptor getSurface(ushort identifier, QDBusMessage message);
void setFlags(QString identifier, const QStringList& flags, QDBusMessage message);
QStringList getSurfaces(QDBusMessage message);
QDBusUnixFileDescriptor frameBuffer(QDBusMessage message);

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

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

int APIBase::hasPermission(QString permission, const char* sender){
Expand Down Expand Up @@ -31,14 +32,14 @@ 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;
}

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

#include "moc_apibase.cpp"
2 changes: 1 addition & 1 deletion applications/system-service/apibase.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ class APIBase : public QObject, protected QDBusContext {
int getSenderPgid();
};
QWindow* getFrameBufferWindow();
QImage* getFrameBuffer();
QImage getFrameBuffer();

#endif // APIBASE_H
28 changes: 11 additions & 17 deletions applications/system-service/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,29 +904,23 @@ QStringList Application::getActiveMounts(){
return activeMounts;
}
void Application::showSplashScreen(){
auto frameBuffer = getFrameBuffer();
return;
qDebug() << "Waiting for other painting to finish...";
Oxide::Sentry::sentry_transaction("application", "showSplashScreen", [this, frameBuffer](Oxide::Sentry::Transaction* t){
Oxide::Sentry::sentry_transaction("application", "showSplashScreen", [this](Oxide::Sentry::Transaction* t){
#ifdef SENTRY
if(t != nullptr){
sentry_transaction_set_tag(t->inner, "application", name().toStdString().c_str());
}
#else
Q_UNUSED(t);
#endif
Oxide::Sentry::sentry_span(t, "wait", "Wait for screen to be ready", [frameBuffer](){
dispatchToMainThread([frameBuffer]{
while(frameBuffer->paintingActive()){
// TODO - don't spinlock
}
});
});
qDebug() << "Displaying splashscreen for" << name();
Oxide::Sentry::sentry_span(t, "paint", "Draw splash screen", [this, frameBuffer](){
dispatchToMainThread([this, frameBuffer]{
QPainter painter(frameBuffer);
auto size = frameBuffer->size();
auto rect = frameBuffer->rect();
Oxide::Sentry::sentry_span(t, "paint", "Draw splash screen", [this](){
dispatchToMainThread([this]{
auto frameBuffer = getFrameBuffer();
QPainter painter(&frameBuffer);
auto size = frameBuffer.size();
auto rect = frameBuffer.rect();
auto fm = painter.fontMetrics();
painter.fillRect(rect, Qt::white);
QString splashPath = splash();
Expand All @@ -946,11 +940,11 @@ void Application::showSplashScreen(){
QPoint(
(size.width() / 2) - (splashWidth / 2),
(size.height() / 2) - (splashWidth / 2)
),
),
splashSize
);
);
painter.drawImage(splashRect, splash, splash.rect());
Oxide::QML::repaint(getFrameBufferWindow(), frameBuffer->rect(), Blight::HighQualityGrayscale, true);
Oxide::QML::repaint(getFrameBufferWindow(), frameBuffer.rect(), Blight::HighQualityGrayscale/*, true*/);
}
painter.end();
notificationAPI->drawNotificationText("Loading " + displayName() + "...");
Expand Down
14 changes: 5 additions & 9 deletions applications/system-service/appsapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,17 +855,13 @@ AppsAPI::~AppsAPI() {
settings.sync();
dispatchToMainThread([this]{
auto frameBuffer = getFrameBuffer();
qDebug() << "Waiting for other painting to finish...";
while(frameBuffer->paintingActive()){
// TODO - don't spinlock
}
QPainter painter(frameBuffer);
auto rect = frameBuffer->rect();
QPainter painter(&frameBuffer);
auto rect = frameBuffer.rect();
auto fm = painter.fontMetrics();
qDebug() << "Clearing screen...";
painter.setPen(Qt::white);
painter.fillRect(rect, Qt::black);
Oxide::QML::repaint(getFrameBufferWindow(), rect, Blight::Mono, true);
Oxide::QML::repaint(getFrameBufferWindow(), rect, Blight::Mono/*, true*/);
painter.end();
qDebug() << "Stopping applications...";
for(auto app : applications){
Expand All @@ -882,7 +878,7 @@ AppsAPI::~AppsAPI() {
app->deleteLater();
}
applications.clear();
QPainter painter2(frameBuffer);
QPainter painter2(&frameBuffer);
qDebug() << "Displaying final quit message...";
painter2.fillRect(rect, Qt::black);
painter2.setPen(Qt::white);
Expand All @@ -894,7 +890,7 @@ AppsAPI::~AppsAPI() {
painter2.translate(-x, -y);
}
painter2.drawText(rect, Qt::AlignCenter, "Goodbye!");
Oxide::QML::repaint(getFrameBufferWindow(), rect, Blight::Mono, true);
Oxide::QML::repaint(getFrameBufferWindow(), rect, Blight::Mono/*, true*/);
painter2.end();
});
}
Expand Down
7 changes: 7 additions & 0 deletions applications/system-service/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <liboxide.h>
#include <liboxide/oxideqml.h>
#include <libblight.h>
#include <libblight/connection.h>

#include "dbusservice.h"
#include "controller.h"
Expand Down Expand Up @@ -65,6 +66,12 @@ int main(int argc, char* argv[]){
}
return QProcess::execute("/usr/bin/xochitl", QStringList());
}
Blight::connection()->onDisconnect([](int res){
// TODO - attempt to reconnect
if(res){
qApp->exit(res);
}
});
qputenv("XDG_CURRENT_DESKTOP", "OXIDE");
QThread::currentThread()->setObjectName("main");
qputenv("QMLSCENE_DEVICE", "software");
Expand Down
7 changes: 4 additions & 3 deletions applications/system-service/notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ void Notification::setOwner(QString owner){

bool Notification::hasPermission(QString permission, const char* sender){ return notificationAPI->hasPermission(permission, sender); }

void Notification::paintNotification(Application *resumeApp) {
void Notification::paintNotification(Application *resumeApp){
return;
qDebug() << "Painting notification" << identifier();
dispatchToMainThread([this] { screenBackup = screenAPI->copy(); });
updateRect = notificationAPI->paintNotification(text(), m_icon);
Expand All @@ -184,11 +185,11 @@ void Notification::paintNotification(Application *resumeApp) {
QTimer::singleShot(2000, [this, resumeApp] {
dispatchToMainThread([this]{
auto frameBuffer = getFrameBuffer();
QPainter painter(frameBuffer);
QPainter painter(&frameBuffer);
painter.drawImage(updateRect, screenBackup, updateRect);
painter.end();
qDebug() << "Finished displaying notification" << identifier();
Oxide::QML::repaint(getFrameBufferWindow(), updateRect, Blight::Mono, true);
Oxide::QML::repaint(getFrameBufferWindow(), updateRect, Blight::Mono/*, true*/);
});
if (!notificationAPI->notificationDisplayQueue.isEmpty()) {
Oxide::dispatchToMainThread([resumeApp] {
Expand Down
30 changes: 13 additions & 17 deletions applications/system-service/notificationapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,42 +108,38 @@ QRect NotificationAPI::paintNotification(const QString &text, const QString &ico
return dispatchToMainThread<QRect>([&notification]{
qDebug() << "Painting to framebuffer...";
auto frameBuffer = getFrameBuffer();
QPainter painter(frameBuffer);
QPoint pos(0, frameBuffer->height() - notification.height());
QPainter painter(&frameBuffer);
QPoint pos(0, frameBuffer.height() - notification.height());
if(systemAPI->landscape()){
notification = notification.transformed(QTransform().rotate(90.0));
pos.setX(0);
pos.setY(frameBuffer->height() - notification.height());
pos.setY(frameBuffer.height() - notification.height());
}
auto updateRect = notification.rect().translated(pos);
painter.drawImage(updateRect, notification);
painter.end();
qDebug() << "Updating screen " << updateRect << "...";
Oxide::QML::repaint(getFrameBufferWindow(), frameBuffer->rect(), Blight::Grayscale, true);
Oxide::QML::repaint(getFrameBufferWindow(), frameBuffer.rect(), Blight::Grayscale/*, true*/);
return updateRect;
});
}
void NotificationAPI::errorNotification(const QString &text) {
dispatchToMainThread([] {
auto frameBuffer = getFrameBuffer();
qDebug() << "Waiting for other painting to finish...";
while (frameBuffer->paintingActive()) {
// TODO - don't spinlock
}
qDebug() << "Displaying error text";
QPainter painter(frameBuffer);
painter.fillRect(frameBuffer->rect(), Qt::white);
QPainter painter(&frameBuffer);
painter.fillRect(frameBuffer.rect(), Qt::white);
painter.end();
Oxide::QML::repaint(getFrameBufferWindow(), frameBuffer->rect(), Blight::Mono, true);
Oxide::QML::repaint(getFrameBufferWindow(), frameBuffer.rect(), Blight::Mono/*, true*/);
});
notificationAPI->paintNotification(text, "");
}
QImage NotificationAPI::notificationImage(const QString& text, const QString& iconPath){
auto padding = 10;
auto radius = 10;
auto frameBuffer = getFrameBuffer();
auto size = frameBuffer->size();
auto boundingRect = QPainter(frameBuffer).fontMetrics().boundingRect(
auto size = frameBuffer.size();
auto boundingRect = QPainter(&frameBuffer).fontMetrics().boundingRect(
QRect(0, 0, size.width() / 2, size.height() / 8),
Qt::AlignCenter | Qt::TextWordWrap, text
);
Expand Down Expand Up @@ -184,11 +180,11 @@ QImage NotificationAPI::notificationImage(const QString& text, const QString& ic
}

void NotificationAPI::drawNotificationText(const QString& text, QColor color, QColor background){
auto frameBuffer = getFrameBuffer();
dispatchToMainThread([frameBuffer, text, color, background]{
QPainter painter(frameBuffer);
dispatchToMainThread([text, color, background]{
auto frameBuffer = getFrameBuffer();
QPainter painter(&frameBuffer);
int padding = 10;
auto size = frameBuffer->size();
auto size = frameBuffer.size();
auto fm = painter.fontMetrics();
int textHeight = fm.height() + padding;
QImage textImage(
Expand Down
20 changes: 5 additions & 15 deletions applications/system-service/screenapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ QDBusObjectPath ScreenAPI::screenshot(){
return dispatchToMainThread<QDBusObjectPath>([this, filePath]{
QImage screen = copy();
QRect rect = notificationAPI->paintNotification("Taking Screenshot...", "");
Oxide::QML::repaint(getFrameBufferWindow(), rect, Blight::Mono, true);
Oxide::QML::repaint(getFrameBufferWindow(), rect, Blight::Mono/*, true*/);
QDBusObjectPath path("/");
bool saved = (
systemAPI->landscape()
Expand All @@ -29,11 +29,6 @@ QDBusObjectPath ScreenAPI::screenshot(){
}else{
path = addScreenshot(filePath)->qPath();
}
auto frameBuffer = getFrameBuffer();
QPainter painter(frameBuffer);
painter.drawImage(rect, screen, rect);
painter.end();
Oxide::QML::repaint(getFrameBufferWindow(), rect, Blight::HighQualityGrayscale, true);
notificationAPI->add(
QUuid::createUuid().toString(),
"codes.eeems.tarnish",
Expand All @@ -47,12 +42,7 @@ QDBusObjectPath ScreenAPI::screenshot(){

QImage ScreenAPI::copy(){
return Oxide::dispatchToMainThread<QImage>([]{
auto frameBuffer = getFrameBuffer();
qDebug() << "Waiting for other painting to finish...";
while(frameBuffer->paintingActive()){
// TODO - don't spin lock
}
return frameBuffer->copy();
return getFrameBuffer().copy();
});
}

Expand Down Expand Up @@ -210,8 +200,8 @@ bool ScreenAPI::drawFullscreenImage(QString path, double rotate){
Q_UNUSED(t);
Oxide::dispatchToMainThread([img]{
auto frameBuffer = getFrameBuffer();
QRect rect = frameBuffer->rect();
QPainter painter(frameBuffer);
QRect rect = frameBuffer.rect();
QPainter painter(&frameBuffer);
painter.fillRect(rect, Qt::white);
painter.setRenderHints(
QPainter::Antialiasing | QPainter::SmoothPixmapTransform,
Expand All @@ -227,7 +217,7 @@ bool ScreenAPI::drawFullscreenImage(QString path, double rotate){
painter.translate(0 - img.width() / 2, 0 - img.height() / 2);
painter.drawPixmap(img.rect(), QPixmap::fromImage(img));
painter.end();
Oxide::QML::repaint(getFrameBufferWindow(), frameBuffer->rect(), Blight::HighQualityGrayscale, true);
Oxide::QML::repaint(getFrameBufferWindow(), frameBuffer.rect(), Blight::HighQualityGrayscale/*, true*/);
});
});
return true;
Expand Down
3 changes: 3 additions & 0 deletions interfaces/blight.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@
<method name="getSurfaces">
<arg type="as" direction="out"/>
</method>
<method name="frameBuffer">
<arg type="h" direction="out"/>
</method>
</interface>
</node>
2 changes: 1 addition & 1 deletion shared/liboxide/oxideqml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace Oxide {

void repaint(QWindow* window, QRectF rect, Blight::WaveformMode waveform, bool sync){
auto buf = getSurfaceForWindow(window);
auto _marker = 0;
unsigned int _marker = 0;
if(sync){
_marker = ++marker;
}
Expand Down

0 comments on commit 98d03bc

Please sign in to comment.