Skip to content

Commit

Permalink
Integrate custom render code
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Jan 22, 2024
1 parent cf70cf5 commit 92cd13a
Show file tree
Hide file tree
Showing 21 changed files with 968 additions and 106 deletions.
79 changes: 53 additions & 26 deletions applications/display-server/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <QCoreApplication>
#include <cstring>

#ifdef EPAPER
#include "guithread.h"
#endif
#include "surface.h"

Connection::Connection(QObject* parent, pid_t pid, pid_t pgid)
Expand Down Expand Up @@ -142,7 +145,7 @@ std::shared_ptr<Surface> Connection::getSurface(QString identifier){
return nullptr;
}

QStringList Connection::getSurfaces(){
QStringList Connection::getSurfaceIds(){
QStringList identifiers;
for(auto surface : qAsConst(surfaces)){
if(surface == nullptr){
Expand All @@ -153,6 +156,8 @@ QStringList Connection::getSurfaces(){
return identifiers;
}

const QList<std::shared_ptr<Surface>>& Connection::getSurfaces(){ return surfaces; }

void Connection::inputEvent(const input_event& event){
int res = -1;
while(res < 0){
Expand Down Expand Up @@ -193,6 +198,7 @@ void Connection::readSocket(){
<< ", size=" << message->header.size
<< ", socket=" << m_serverFd
);
bool do_ack = true;
unsigned int ack_size = 0;
Blight::data_t ack_data = nullptr;
std::function<void()> ack_free = NULL;
Expand All @@ -215,12 +221,27 @@ void Connection::readSocket(){
O_WARNING("Could not find surface " << repaint.identifier.c_str());
break;
}
emit surface->update(QRect(
QRect rect(
repaint.header.x,
repaint.header.y,
repaint.header.width,
repaint.header.height
));
);
#ifdef EPAPER
guiThread->enqueue(
surface,
rect,
(EPFrameBuffer::WaveformMode)repaint.header.waveform,
message->header.ackid,
false,
[message, this]{
ack(message, 0, nullptr);
}
);
do_ack = false;
#else
emit surface->update(rect);
#endif
break;
}
case Blight::MessageType::Move:{
Expand Down Expand Up @@ -282,7 +303,7 @@ void Connection::readSocket(){
case Blight::MessageType::List:{
O_DEBUG("List requested");
std::vector<std::string> list;
for(QString& surface : getSurfaces()){
for(QString& surface : getSurfaceIds()){
auto string = surface.toStdString();
ack_size += sizeof(Blight::list_item_t::identifier_len) + string.size();
list.push_back(string);
Expand Down Expand Up @@ -317,28 +338,8 @@ void Connection::readSocket(){
O_WARNING("Ack expected data, but none sent");
ack_size = 0;
}
auto ack = Blight::message_t::create_ack(message.get(), ack_size);
auto res = ::send(
m_serverFd,
reinterpret_cast<char*>(ack),
sizeof(Blight::header_t),
MSG_EOR
);
if(res < 0){
O_WARNING("Failed to write to socket:" << strerror(errno));
}else if(res != sizeof(Blight::header_t)){
O_WARNING("Failed to write to socket: Size of written bytes doesn't match!");
}else if(ack_size){
res = ::send(m_serverFd, ack_data, ack_size, MSG_EOR);
if(res < 0){
O_WARNING("Failed to write to socket:" << strerror(errno));
}else if((unsigned int)res != ack_size){
O_WARNING("Failed to write to socket: Size of written bytes doesn't match!");
}else{
O_DEBUG("Acked" << message->header.ackid);
}
}else{
O_DEBUG("Acked" << message->header.ackid);
if(do_ack){
ack(message, ack_size, ack_data);
}
if(ack_free){
ack_free();
Expand All @@ -348,4 +349,30 @@ void Connection::readSocket(){
};
m_notifier->setEnabled(true);
}

void Connection::ack(Blight::message_ptr_t message, unsigned int size, Blight::data_t data){
auto ack = Blight::message_t::create_ack(message.get(), size);
auto res = ::send(
m_serverFd,
reinterpret_cast<char*>(ack),
sizeof(Blight::header_t),
MSG_EOR
);
if(res < 0){
O_WARNING("Failed to write to socket:" << strerror(errno));
}else if(res != sizeof(Blight::header_t)){
O_WARNING("Failed to write to socket: Size of written bytes doesn't match!");
}else if(size){
res = ::send(m_serverFd, data, size, MSG_EOR);
if(res < 0){
O_WARNING("Failed to write to socket:" << strerror(errno));
}else if((unsigned int)res != size){
O_WARNING("Failed to write to socket: Size of written bytes doesn't match!");
}else{
O_DEBUG("Acked" << message->header.ackid);
}
}else{
O_DEBUG("Acked" << message->header.ackid);
}
}
#include "moc_connection.cpp"
4 changes: 3 additions & 1 deletion applications/display-server/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class Connection : public QObject {
void close();
std::shared_ptr<Surface> addSurface(int fd, QRect geometry, int stride, QImage::Format format);
std::shared_ptr<Surface> getSurface(QString identifier);
QStringList getSurfaces();
QStringList getSurfaceIds();
const QList<std::shared_ptr<Surface>>& getSurfaces();
void inputEvent(const input_event& event);

signals:
Expand All @@ -55,4 +56,5 @@ private slots:
int m_serverInputFd;
QSocketNotifier* m_notifier;
QList<std::shared_ptr<Surface>> surfaces;
void ack(Blight::message_ptr_t message, unsigned int size, Blight::data_t data);
};
47 changes: 28 additions & 19 deletions applications/display-server/dbusinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
#include <libblight/types.h>
#include <cstring>

DbusInterface* DbusInterface::singleton = nullptr;

DbusInterface::DbusInterface(QObject* parent, QQmlApplicationEngine* engine)
DbusInterface::DbusInterface(QObject* parent)
: QObject(parent),
engine(engine),
m_focused(nullptr)
{
if(singleton != nullptr){
qFatal("DbusInterface singleton already exists");
engine.load(QUrl(QStringLiteral("qrc:/Workspace.qml")));
if(engine.rootObjects().isEmpty()){
qFatal("Failed to load main layout");
}
singleton = this;
// Needed to trick QtDBus into exposing the object
setProperty("__init__", true);
#ifdef EPAPER
Expand Down Expand Up @@ -55,7 +52,7 @@ DbusInterface::DbusInterface(QObject* parent, QQmlApplicationEngine* engine)
&QDBusConnectionInterface::serviceOwnerChanged,
this,
&DbusInterface::serviceOwnerChanged
);
);
O_DEBUG("Connected service to bus");
connect(&connectionTimer, &QTimer::timeout, this, [this]{
for(auto& connection : qAsConst(connections)){
Expand All @@ -78,7 +75,7 @@ DbusInterface::DbusInterface(QObject* parent, QQmlApplicationEngine* engine)
int DbusInterface::pid(){ return qApp->applicationPid(); }

QObject* DbusInterface::loadComponent(QString url, QString identifier, QVariantMap properties){
auto object = engine->findChild<QObject*>(identifier);
auto object = engine.findChild<QObject*>(identifier);
if(object != nullptr){
for(auto i = properties.cbegin(), end = properties.cend(); i != end; ++i){
object->setProperty(i.key().toStdString().c_str(), i.value());
Expand Down Expand Up @@ -306,7 +303,7 @@ std::shared_ptr<Connection> DbusInterface::getConnection(QDBusMessage message){
}

QObject* DbusInterface::workspace(){
QListIterator<QObject*> i(engine->rootObjects());
QListIterator<QObject*> i(engine.rootObjects());
while(i.hasNext()){
auto item = i.next();
if(item->objectName() == "Workspace"){
Expand Down Expand Up @@ -357,8 +354,8 @@ std::shared_ptr<Connection> DbusInterface::createConnection(int pid){
return ptr;
}

QList<QString> DbusInterface::surfaces(){
QList<QString> surfaces;
QList<std::shared_ptr<Surface>> DbusInterface::surfaces(){
QList<std::shared_ptr<Surface>> surfaces;
for(auto& connection : connections){
for(auto& surface : connection->getSurfaces()){
surfaces.append(surface);
Expand All @@ -367,26 +364,38 @@ QList<QString> DbusInterface::surfaces(){
return surfaces;
}

void DbusInterface::sortZ(){
QList<std::shared_ptr<Surface>> DbusInterface::sortedSurfaces(){
auto sorted = surfaces().toVector();
std::sort(
sorted.begin(),
sorted.end(),
[this](const QString& identifier0, const QString& identifier1){
auto surface0 = getSurface(identifier0);
[](std::shared_ptr<Surface> surface0, std::shared_ptr<Surface> surface1){
if(surface0 == nullptr){
return false;
}
auto surface1 = getSurface(identifier1);
if(surface1 == nullptr){
return true;
}
return surface0->z() < surface1->z();
}
);
return QList<std::shared_ptr<Surface>>::fromVector(sorted);
}

QList<std::shared_ptr<Surface> > DbusInterface::visibleSurfaces(){
QList<std::shared_ptr<Surface>> surfaces;
for(auto& surface : sortedSurfaces()){
if(surface->visible()){
surfaces.append(surface);
}
}
return surfaces;
}

void DbusInterface::sortZ(){
auto sorted = sortedSurfaces();
int z = 0;
for(auto& identifier : sorted){
auto surface = getSurface(identifier);
for(auto surface : sorted){
if(surface == nullptr){
continue;
}
Expand All @@ -395,7 +404,7 @@ void DbusInterface::sortZ(){
if(m_focused != nullptr || sorted.empty()){
return;
}
auto surface = getSurface(sorted.last());
auto surface = sorted.last();
if(surface == nullptr){
return;
}
Expand Down
19 changes: 15 additions & 4 deletions applications/display-server/dbusinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,30 @@

#include "../../shared/liboxide/meta.h"

#define dbusInterface DbusInterface::singleton()

class DbusInterface : public QObject, public QDBusContext {
Q_OBJECT
Q_CLASSINFO("Version", OXIDE_INTERFACE_VERSION)
Q_CLASSINFO("D-Bus Interface", BLIGHT_INTERFACE)
Q_PROPERTY(int pid READ pid CONSTANT)

public:
static DbusInterface* singleton;
DbusInterface(QObject* parent, QQmlApplicationEngine* engine);
static DbusInterface* singleton(){
static DbusInterface* instance = nullptr;
if(instance == nullptr){
instance = new DbusInterface(qApp);
}
return instance;
}

int pid();
QObject* loadComponent(QString url, QString identifier, QVariantMap properties = QVariantMap());
std::shared_ptr<Surface> getSurface(QString identifier);
QList<std::shared_ptr<Surface>> surfaces();
QList<std::shared_ptr<Surface>> sortedSurfaces();
QList<std::shared_ptr<Surface>> visibleSurfaces();


public slots:
QDBusUnixFileDescriptor open(QDBusMessage message);
Expand All @@ -50,14 +61,14 @@ private slots:
void inputEvents(unsigned int device, const std::vector<input_event>& events);

private:
QQmlApplicationEngine* engine;
DbusInterface(QObject* parent);
QQmlApplicationEngine engine;
QList<std::shared_ptr<Connection>> connections;
std::shared_ptr<Connection> m_focused;
QTimer connectionTimer;

std::shared_ptr<Connection> getConnection(QDBusMessage message);
QObject* workspace();
std::shared_ptr<Connection> createConnection(int pid);
QList<QString> surfaces();
void sortZ();
};
Loading

0 comments on commit 92cd13a

Please sign in to comment.