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() << " - Cleaning stale single-instance lock:"; if(lockfile->removeStaleLockFile() ){ if(QFile::exists(cfile)){ QLocalServer::removeServer(cfile); } //also remove stale socket/server file }else{ qDebug() << " -- Could not remove lock file"; } //Now re-try to create the lock primary = lockfile->tryLock(); //qDebug() << " - Try Lock Again:" << primary; } } if(primary || !QFile::exists(cfile) ){ //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) ){ qDebug() << " - Created new single-instance lock"; lserver->setSocketOptions(QLocalServer::UserAccessOption); //qDebug() << " - Success"; isActive = true; }else{ qDebug() << " - WARNING: Could not create single-instance framework"; qDebug() << " - Falling back on standard application startup"; lockfile->unlock(); isActive = true; } }else if(!isBypass){ //forward the current inputs to the locked process for processing and exit //Check the connection to the local server first qDebug() << "Single-instance lock found"; QLocalSocket socket(this); socket.connectToServer(cfile); socket.waitForConnected(); if(!socket.isValid() || socket.state()!=QLocalSocket::ConnectedState){ //error - could not forward info for some reason qDebug() << " - Could not connect to locking process: exiting..."; exit(1); } qDebug() << " - Forwarding inputs to locking process and closing down this instance..."; socket.write( inputlist.join("::::").toLocal8Bit() ); socket.waitForDisconnected(500); //max out at 1/2 second (only hits this if no inputs) } }
void PCSingleApplication::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 } }
//#define DEBUG 0 int main(int argc, char ** argv) { qDebug() << "Starting lumina-wm..."; LTHEME::LoadCustomEnvSettings(); LSingleApplication a(argc, argv, "lumina-wm"); if(!a.isPrimaryProcess()){ return 0; } //Inputs forwarded on to the primary already LuminaThemeEngine themes(&a); //Setup the special settings prefix location QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, QDir::homePath()+"/.lumina"); //Setup the global structures LWM::SYSTEM = new LXCB(); if(argc>1 && QString::fromLocal8Bit(argv[1])=="testwin"){ //Simple override to test out the window class qDebug() << "Starting window test..."; QLabel dlg(0, Qt::Window | Qt::BypassWindowManagerHint); //this test should be ignored by the current WM dlg.setText("Sample Window"); dlg.setWindowTitle("Test"); dlg.setGeometry(100,100,200,100); dlg.setStyleSheet("background: rgba(255,255,255,100); color: black;"); dlg.show(); qDebug() << " - Loading window frame..."; LWindow win(dlg.winId()); //have it wrap around the dialog qDebug() << " - Show frame..."; win.windowChanged(LWM::Show); qDebug() << " - Start event loop..."; a.setQuitOnLastWindowClosed(true); return a.exec(); } WMSession w; w.start(); QObject::connect(&themes, SIGNAL(updateIcons()), &w, SLOT(reloadIcons()) ); QObject::connect(&a, SIGNAL(InputsAvailable(QStringList)), &w, SLOT(newInputsAvailable(QStringList)) ); int retCode = a.exec(); return retCode; }