kdetcompmgr.cpp
00001 /*************************************************************************** 00002 * Copyright (C) 2011 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 <kapplication.h> 00025 #include <kaboutdata.h> 00026 #include <kcmdlineargs.h> 00027 #include <klocale.h> 00028 #include <kdebug.h> 00029 #include <kconfig.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 KCmdLineOptions options[] = 00040 { 00041 KCmdLineLastOption 00042 }; 00043 00044 int main(int argc, char **argv) 00045 { 00046 KAboutData about("kdetcompmgr", I18N_NOOP("kdetcompmgr"), version, description, 00047 KAboutData::License_GPL, "(C) 2011 Timothy Pearson", 0, 0, "kb9vqf@pearsoncomputing.net"); 00048 about.addAuthor( "Timothy Pearson", 0, "kb9vqf@pearsoncomputing.net" ); 00049 KCmdLineArgs::init(argc, argv, &about); 00050 KCmdLineArgs::addCmdLineOptions( options ); 00051 00052 KApplication app; 00053 00054 KConfig config("kwinrc", true); 00055 config.setGroup( "Notification Messages" ); 00056 if (!config.readBoolEntry("UseTranslucency",false)) { 00057 // Attempt to load the kompmgr pid file 00058 const char *home; 00059 struct passwd *p; 00060 p = getpwuid(getuid()); 00061 if (p) 00062 home = p->pw_dir; 00063 else 00064 home = getenv("HOME"); 00065 char *filename; 00066 const char *configfile = "/.kompmgr.pid"; 00067 int n = strlen(home)+strlen(configfile)+1; 00068 filename = (char*)malloc(n*sizeof(char)); 00069 memset(filename,0,n); 00070 strcat(filename, home); 00071 strcat(filename, configfile); 00072 00073 // Now that we did all that by way of introduction...read the file! 00074 FILE *pFile; 00075 char buffer[255]; 00076 pFile = fopen(filename, "r"); 00077 int kompmgrpid = 0; 00078 if (pFile) { 00079 printf("[kdetcompmgr] Using '%s' as kompmgr pidfile\n", filename); 00080 // obtain file size 00081 fseek (pFile , 0 , SEEK_END); 00082 unsigned long lSize = ftell (pFile); 00083 if (lSize > 254) 00084 lSize = 254; 00085 rewind (pFile); 00086 fclose(pFile); 00087 kompmgrpid = atoi(buffer); 00088 } 00089 00090 free(filename); 00091 filename = NULL; 00092 00093 if (kompmgrpid) { 00094 kill(kompmgrpid, SIGTERM); 00095 } 00096 } 00097 00098 if (app.detectCompositionManagerAvailable(false, false)) { // Perform a shallow check for the composite extension (a deep check would cause noticeable flicker) 00099 KConfig config2("kwinrc", true); 00100 config2.setGroup( "Notification Messages" ); 00101 if (config2.readBoolEntry("UseTranslucency",false)) { 00102 app.detectCompositionManagerAvailable(true, true); 00103 return 2; 00104 } 00105 else { 00106 app.detectCompositionManagerAvailable(true, false); 00107 return 0; 00108 } 00109 } 00110 else { 00111 app.detectCompositionManagerAvailable(true, false); 00112 return 1; 00113 } 00114 } 00115