Ticket #29: screensaver-x11-1.2.diff
| File screensaver-x11-1.2.diff, 5.3 KB (added by , 21 years ago) |
|---|
-
libs/libmyth/util.h
54 54 bool getUptime(time_t &uptime); 55 55 bool getMemStats(int &totalMB, int &freeMB, int &totalVM, int &freeVM); 56 56 57 bool processRunning(const QString &pName); 58 57 59 #endif // UTIL_H_ -
libs/libmyth/screensaver-x11.cpp
8 8 } 9 9 10 10 #include "mythcontext.h" 11 #include "util.h" 11 12 12 13 class ScreenSaverX11Private 13 14 { … … 19 20 int preferblank; 20 21 int allowexposure; 21 22 bool dpmsdisabled; 23 bool xscreensaverRunning; 22 24 } state; 23 25 24 26 friend class ScreenSaverX11; 25 27 }; 26 28 29 ScreenSaverXSSTimer::ScreenSaverXSSTimer() 30 { 31 resetTimer = new QTimer(); 32 connect(resetTimer, SIGNAL(timeout()), this, SLOT(resetSlot())); 33 } 34 35 ScreenSaverXSSTimer::~ScreenSaverXSSTimer() 36 { 37 delete resetTimer; 38 } 39 40 void ScreenSaverXSSTimer::resetXSS() 41 { 42 myth_system(QString("xscreensaver-command -deactivate >&- 2>&- &")); 43 } 44 45 void ScreenSaverXSSTimer::resetSlot() 46 { 47 resetXSS(); 48 } 49 27 50 ScreenSaverX11::ScreenSaverX11() 28 51 { 29 52 d = new ScreenSaverX11Private(); 53 d->state.xscreensaverRunning = processRunning("xscreensaver"); 54 if (d->state.xscreensaverRunning) 55 { 56 t = new ScreenSaverXSSTimer(); 57 t->timeoutInterval = -1; 58 VERBOSE(VB_GENERAL, QString("XScreenSaver support enabled")); 59 } 30 60 } 31 61 32 62 ScreenSaverX11::~ScreenSaverX11() 33 63 { 34 64 delete d; 65 delete t; 35 66 } 36 67 37 68 void ScreenSaverX11::Disable(void) … … 63 94 VERBOSE(VB_GENERAL, "Disable DPMS"); 64 95 } 65 96 } 97 98 if (d->state.xscreensaverRunning) 99 { 100 if (t->resetTimer) 101 { 102 t->resetTimer->stop(); 103 } 104 if (t->timeoutInterval == -1) 105 { 106 t->timeoutInterval = 107 gContext->GetNumSettingOnHost("xscreensaverInterval", 108 gContext->GetHostName(), 109 60) * 1000; 110 } 111 if (t->timeoutInterval > 0) 112 { 113 t->resetTimer->start(t->timeoutInterval, FALSE); 114 } 115 } 66 116 } 67 117 68 118 void ScreenSaverX11::Restore(void) … … 84 134 VERBOSE(VB_GENERAL, "Enable DPMS"); 85 135 } 86 136 } 137 138 if (d->state.xscreensaverRunning) 139 { 140 if (t->resetTimer) 141 { 142 t->resetTimer->stop(); 143 } 144 } 87 145 } 88 146 89 147 void ScreenSaverX11::Reset(void) 90 148 { 91 149 XResetScreenSaver(qt_xdisplay()); 150 if (d->state.xscreensaverRunning) 151 { 152 t->resetXSS(); 153 } 92 154 } 93 155 -
libs/libmyth/util.cpp
28 28 #include <qpainter.h> 29 29 #include <qpixmap.h> 30 30 #include <qfont.h> 31 #include <qdir.h> 32 #include <qfile.h> 33 #include <qregexp.h> 31 34 32 35 // Myth headers 33 36 #include "mythconfig.h" … … 1068 1071 1069 1072 return true; 1070 1073 } 1074 1075 /** \fn processRunning(QString&) 1076 * \brief Returns the running state of a process. 1077 * 1078 * \todo Add support for other platforms. 1079 * \return true if process is running, false otherwise. 1080 */ 1081 bool processRunning(const QString &pName) 1082 { 1083 #ifdef __linux__ 1084 // Parse /proc pseudo-fs for pid's 1085 QDir procDir(QString("/proc")); 1086 procDir.setFilter(QDir::Dirs | QDir::Readable); 1087 if (procDir.exists()) 1088 { 1089 QStringList processes = procDir.entryList(); 1090 for (QStringList::iterator i = processes.begin(); i != processes.end(); i++) 1091 { 1092 QString process = *i; 1093 QRegExp rx( "^\\d+$" ); 1094 if (rx.search(process) == 0) 1095 { 1096 // Get process name from stat file 1097 QFile processStatFile(QString("/proc/%1/stat").arg(process)); 1098 if (processStatFile.open(IO_ReadOnly)) 1099 { 1100 QTextStream stream(&processStatFile); 1101 QString processName; 1102 stream >> processName >> processName; 1103 processStatFile.close(); 1104 if (QString("(%1)").arg(pName) == processName) 1105 { 1106 return true; 1107 } 1108 } 1109 } 1110 } 1111 } 1112 1113 #else 1114 VERBOSE(VB_IMPORTANT, "processRunning(): Error, " 1115 "only linux supported"); 1116 #endif 1117 1118 return false; 1119 } -
libs/libmyth/screensaver-x11.h
3 3 4 4 #include "screensaver.h" 5 5 6 #include <qobject.h> 7 #include <qtimer.h> 8 9 class ScreenSaverXSSTimer : public QObject 10 { 11 Q_OBJECT 12 public: 13 ScreenSaverXSSTimer(); 14 ~ScreenSaverXSSTimer(); 15 void resetXSS(void); 16 int timeoutInterval; 17 QTimer *resetTimer; 18 19 private slots: 20 void resetSlot(); 21 22 }; 23 6 24 class ScreenSaverX11 : public ScreenSaverControl 7 25 { 8 26 public: … … 15 33 16 34 protected: 17 35 class ScreenSaverX11Private *d; 36 class ScreenSaverXSSTimer *t; 18 37 }; 19 38 20 39 #endif // MYTH_SCREENSAVER_X11_H
