kdetcompmgr.cpp
00001 /*************************************************************************** 00002 * Copyright (C) 2011-2014 Timothy Pearson <kb9vqf@pearsoncomputing.net> * 00003 * * 00004 * This program is free software; you can redistribute it and/or modify * 00005 * it under the terms of the GNU General Public License as published by * 00006 * the Free Software Foundation; either version 2 of the License, or * 00007 * (at your option) any later version. * 00008 * * 00009 * This program is distributed in the hope that it will be useful, * 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00012 * GNU General Public License for more details. * 00013 * * 00014 * You should have received a copy of the GNU General Public License * 00015 * along with this program; if not, write to the * 00016 * Free Software Foundation, Inc., * 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 00018 ***************************************************************************/ 00019 00020 #include <unistd.h> 00021 #include <stdio.h> 00022 #include <stdlib.h> 00023 00024 #include <tdeapplication.h> 00025 #include <tdeaboutdata.h> 00026 #include <tdecmdlineargs.h> 00027 #include <tdelocale.h> 00028 #include <kdebug.h> 00029 #include <tdeconfig.h> 00030 00031 #include <pwd.h> 00032 #include <signal.h> 00033 00034 static const char description[] = 00035 I18N_NOOP("TDE composition manager detection utility"); 00036 00037 static const char version[] = "0.1"; 00038 00039 static TDECmdLineOptions options[] = 00040 { 00041 TDECmdLineLastOption 00042 }; 00043 00044 int main(int argc, char **argv) 00045 { 00046 TDEAboutData about("kdetcompmgr", I18N_NOOP("kdetcompmgr"), version, description, 00047 TDEAboutData::License_GPL, "(C) 2011-2014 Timothy Pearson", 0, 0, "kb9vqf@pearsoncomputing.net"); 00048 about.addAuthor( "Timothy Pearson", 0, "kb9vqf@pearsoncomputing.net" ); 00049 TDECmdLineArgs::init(argc, argv, &about); 00050 TDECmdLineArgs::addCmdLineOptions( options ); 00051 00052 TDEApplication app; 00053 00054 TDEConfig config("twinrc", true); 00055 config.setGroup( "Notification Messages" ); 00056 if (!config.readBoolEntry("UseTranslucency",false)) { 00057 // Attempt to load the compton-tde pid file 00058 char *filename; 00059 const char *pidfile = "compton-tde.pid"; 00060 char uidstr[sizeof(uid_t)*8+1]; 00061 sprintf(uidstr, "%d", getuid()); 00062 int n = strlen(P_tmpdir)+strlen(uidstr)+strlen(pidfile)+3; 00063 filename = (char*)malloc(n*sizeof(char)+1); 00064 memset(filename,0,n); 00065 strcat(filename, P_tmpdir); 00066 strcat(filename, "/."); 00067 strcat(filename, uidstr); 00068 strcat(filename, "-"); 00069 strcat(filename, pidfile); 00070 00071 // Now that we did all that by way of introduction...read the file! 00072 FILE *pFile; 00073 char buffer[255]; 00074 pFile = fopen(filename, "r"); 00075 int kompmgrpid = 0; 00076 if (pFile) { 00077 printf("[kdetcompmgr] Using '%s' as compton-tde pidfile\n", filename); 00078 // obtain file size 00079 fseek (pFile , 0 , SEEK_END); 00080 unsigned long lSize = ftell (pFile); 00081 if (lSize > 254) 00082 lSize = 254; 00083 rewind (pFile); 00084 fclose(pFile); 00085 kompmgrpid = atoi(buffer); 00086 } 00087 00088 free(filename); 00089 filename = NULL; 00090 00091 if (kompmgrpid) { 00092 kill(kompmgrpid, SIGTERM); 00093 } 00094 } 00095 00096 if (app.detectCompositionManagerAvailable(false, false)) { // Perform a shallow check for the composite extension (a deep check would cause noticeable flicker) 00097 TDEConfig config2("twinrc", true); 00098 config2.setGroup( "Notification Messages" ); 00099 if (config2.readBoolEntry("UseTranslucency",false)) { 00100 app.detectCompositionManagerAvailable(true, true); 00101 return 2; 00102 } 00103 else { 00104 app.detectCompositionManagerAvailable(true, false); 00105 return 0; 00106 } 00107 } 00108 else { 00109 app.detectCompositionManagerAvailable(true, false); 00110 return 1; 00111 } 00112 } 00113