Skip to content

Commit

Permalink
Commit a checkpoint on the conversion of Lumina to Qt5.
Browse files Browse the repository at this point in the history
It is functional at the moment, but still has a few rough edges with regards to the X11 background interface (due to the move from XLib to XCB in Qt5). This reulst in some of the window manager interactions not behaving properly (such as sticky status on panels).
  • Loading branch information
Ken Moore committed Dec 18, 2014
1 parent d9d958c commit 71c2fda
Show file tree
Hide file tree
Showing 48 changed files with 783 additions and 242 deletions.
22 changes: 21 additions & 1 deletion DEPENDENCIES
Expand Up @@ -20,6 +20,7 @@ xbrightness (x11/xbrightness) (Screen Brightness Control)


Build time dependencies:
== (Version 0.7.2) ==
Qt 4.8+
qt4-core (devel/qt4-corelib))
qt4-gui (x11-toolkits/qt4-gui)
Expand All @@ -31,11 +32,30 @@ Qt 4.8+
qt4-moc (devel/qt4-moc)
qt4-rcc (devel/qt4-rcc)
devel/qt4-qtsolutions-singleapplication

X.org and XLib with extensions:
Xrender (x11/libXrender)
Xcomposite (x11/libXcomposite)
Xdamage (x11/libXdamage)

== (Version 0.8.0+) ==
Qt 5.2+
qt5-core
qt5-buildtools
qt5-gui
qt5-widgets
qt5-multimedia
qt5-network
qt5-qmake
qt5-svg
qt5-x11extras

X.org and XCB extensions (possibly the XLib libraries above during the transition phase):
libxcb
xcb-util-wm (window manager framework)
xcb-damage (included in base XCB lib?)
xcb-composite (included in base XCB lib?)
xcb-render (included in base XCB lib?)



Expand Down
1 change: 1 addition & 0 deletions libLumina/LuminaOS.h
Expand Up @@ -16,6 +16,7 @@
#include <QStringList>
#include <QProcess>
#include <QDir>
#include <QObject>

#include "LuminaUtils.h"

Expand Down
107 changes: 107 additions & 0 deletions libLumina/LuminaSingleApplication.cpp
@@ -0,0 +1,107 @@
//===========================================
// Lumina-DE source code
// Copyright (c) 2014, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
#include "LuminaSingleApplication.h"
#include <QDir>
#include <QFile>
#include <QLocalSocket>
#include <QDebug>

#include <unistd.h> //for getlogin()

LSingleApplication::LSingleApplication(int &argc, char **argv) : QApplication(argc, argv){
//Initialize a couple convenience internal variables
cfile = QDir::tempPath()+"/.LSingleApp-%1-%2";
QString username = QString(getlogin());
QString appname = this->applicationName();
//Obscure the user/app in the filename (TO DO)
//qDebug() << username << appname;
//bool junk;
//qDebug() << QString::number( username.toInt(&junk,16) );
cfile = cfile.arg( username, appname );
lockfile = new QLockFile(cfile+"-lock");
lockfile->setStaleLockTime(0); //long-lived processes
for(int i=1; i<argc; i++){ inputlist << QString(argv[i]); }
isActive = false;
lserver = 0;
PerformLockChecks();
}

LSingleApplication::~LSingleApplication(){
if(lserver != 0 && lockfile->isLocked() ){
//currently locked instance: remove the lock now
lserver->close();
QLocalServer::removeServer(cfile);
lockfile->unlock();
}
}

bool LSingleApplication::isPrimaryProcess(){
return isActive;
}

void LSingleApplication::PerformLockChecks(){
bool primary = lockfile->tryLock();
//qDebug() << "Try Lock: " << primary;
if(!primary){
//Pre-existing lock - check it for validity
QString appname, hostname;
qint64 pid;
lockfile->getLockInfo(&pid, &hostname, &appname); //PID already exists if it gets this far, ignore hostname
//qDebug() << " - Lock Info:" << pid << hostname << appname;
if( appname!=this->applicationName() || !QFile::exists(cfile) ){
//Some other process has the same PID or the server does not exist - stale lock
//qDebug() << " - Stale Lock";
lockfile->removeStaleLockFile();
//Now re-try to create the lock
primary = lockfile->tryLock();
//qDebug() << " - Try Lock Again:" << primary;
}
}
if(primary){
//Create the server socket
//qDebug() << "Create Local Server";
if(QFile::exists(cfile)){ QLocalServer::removeServer(cfile); } //stale socket/server file
lserver = new QLocalServer(this);
connect(lserver, SIGNAL(newConnection()), this, SLOT(newInputsAvailable()) );
if( lserver->listen(cfile) ){
lserver->setSocketOptions(QLocalServer::UserAccessOption);
//qDebug() << " - Success";
isActive = true;
}else{
//qDebug() << " - Failure:" << lserver->errorString();
lockfile->unlock();
}

}else{
//forward the current inputs to the locked process for processing and exit
//qDebug() << "Forward inputs to locking process:" << inputlist;
QLocalSocket socket(this);
socket.connectToServer(cfile);
socket.waitForConnected();
if(!socket.isValid()){ exit(1); } //error - could not forward info
socket.write( inputlist.join("::::").toLocal8Bit() );
socket.waitForDisconnected(500); //max out at 1/2 second (only hits this if no inputs)
}

}

//New messages detected
void LSingleApplication::newInputsAvailable(){
while(lserver->hasPendingConnections()){
QLocalSocket *sock = lserver->nextPendingConnection();
QByteArray bytes;
sock->waitForReadyRead();
while(sock->bytesAvailable() > 0){ //if(sock->waitForReadyRead()){
//qDebug() << "Info Available";
bytes.append( sock->readAll() );
}
sock->disconnectFromServer();
QStringList inputs = QString::fromLocal8Bit(bytes).split("::::");
//qDebug() << " - New Inputs Detected:" << inputs;
emit InputsAvailable(inputs);
}
}
54 changes: 54 additions & 0 deletions libLumina/LuminaSingleApplication.h
@@ -0,0 +1,54 @@
//===========================================
// Lumina-DE source code
// Copyright (c) 2014, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
// This is the general class for a single-instance application
//===========================================
//EXAMPLE USAGE in main.cpp:
//
// LSingleApplication app(argc, argv);
// if( !app.isPrimaryProcess() ){
// return 0;
// }
// QMainWindow w; //or whatever the main window class is
// connect(app, SIGNAL(InputsAvailable(QStringList)), w, SLOT(<some slot>)); //for interactive apps - optional
// app.exec();
//===========================================
#ifndef _LUMINA_LIBRARY_SINGLE_APPLICATION_H
#define _LUMINA_LIBRARY_SINGLE_APPLICATION_H

#include <QApplication>
#include <QString>
#include <QStringList>
#include <QLocalServer>
#include <QLockFile>


class LSingleApplication : public QApplication{
Q_OBJECT
public:
LSingleApplication(int &argc, char **argv);
~LSingleApplication();

bool isPrimaryProcess();

private:
bool isActive;
QLockFile *lockfile;
QLocalServer *lserver;
QString cfile;
QStringList inputlist;

void PerformLockChecks();

private slots:
void newInputsAvailable(); //internally used to detect a message from an alternate instance

signals:
void InputsAvailable(QStringList);

};

#endif
2 changes: 1 addition & 1 deletion libLumina/LuminaThemes.cpp
Expand Up @@ -11,7 +11,7 @@
#include <QIcon>
#include <QFont>
#include <QDebug>

#include <QObject>

QStringList LTHEME::availableSystemThemes(){
//returns: [name::::path] for each item
Expand Down
4 changes: 4 additions & 0 deletions libLumina/LuminaUtils.cpp
Expand Up @@ -5,6 +5,10 @@
// See the LICENSE file for full details
//===========================================
#include "LuminaUtils.h"
#include <QString>
#include <QFile>
#include <QStringList>
#include <QObject>

int LUtils::runCmd(QString cmd, QStringList args){
QProcess *proc = new QProcess;
Expand Down
1 change: 1 addition & 0 deletions libLumina/LuminaUtils.h
Expand Up @@ -16,6 +16,7 @@
#include <QStringList>
#include <QFile>
#include <QFileInfo>
#include <QObject>

class LUtils{
public:
Expand Down

0 comments on commit 71c2fda

Please sign in to comment.