aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Moore <moorekou@gmail.com>2015-08-21 08:57:56 -0400
committerKen Moore <moorekou@gmail.com>2015-08-21 08:57:56 -0400
commit93ab1758bb2bd9534cff9d51ec2785c94f59e6af (patch)
tree6adcb647db5080f0181c9e9b495477efc6ed2b28
parentAdd a bit more text output for the single instance framework. This makes it r... (diff)
downloadlumina-93ab1758bb2bd9534cff9d51ec2785c94f59e6af.tar.gz
lumina-93ab1758bb2bd9534cff9d51ec2785c94f59e6af.tar.bz2
lumina-93ab1758bb2bd9534cff9d51ec2785c94f59e6af.zip
Add an additional level of locking to the single-application framework: The X11 Screen number. This ensure that the same app on a different X screen does not stop the app from opening on the current screen as well.
-rw-r--r--libLumina/LuminaSingleApplication.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/libLumina/LuminaSingleApplication.cpp b/libLumina/LuminaSingleApplication.cpp
index 900e7f23..89703053 100644
--- a/libLumina/LuminaSingleApplication.cpp
+++ b/libLumina/LuminaSingleApplication.cpp
@@ -9,6 +9,7 @@
#include <QFile>
#include <QLocalSocket>
#include <QDebug>
+#include <QX11Info>
#include <unistd.h> //for getlogin()
@@ -16,15 +17,11 @@ LSingleApplication::LSingleApplication(int &argc, char **argv, QString appname)
//Load the proper translation systems
cTrans = LUtils::LoadTranslation(this, appname); //save the translator for later
//Initialize a couple convenience internal variables
- cfile = QDir::tempPath()+"/.LSingleApp-%1-%2";
+ cfile = QDir::tempPath()+"/.LSingleApp-%1-%2-%3";
QString username = QString(getlogin());
//For locking the process use the official process name - not the user input (no masking)
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 );
+ cfile = cfile.arg( username, appname, QString::number(QX11Info::appScreen()) );
lockfile = new QLockFile(cfile+"-lock");
lockfile->setStaleLockTime(0); //long-lived processes
for(int i=1; i<argc; i++){
@@ -68,8 +65,12 @@ void LSingleApplication::PerformLockChecks(){
//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();
+ 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;
bgstack15