28 class XSyncBasedPollerHelper
31 XSyncBasedPollerHelper() : q(0) {}
32 ~XSyncBasedPollerHelper() {
42 if (!s_globalXSyncBasedPoller->q) {
46 return s_globalXSyncBasedPoller->q;
51 , m_display(QX11Info::display())
52 , m_idleCounter(
X::
None)
53 , m_resetAlarm(
X::
None)
56 Q_ASSERT(!s_globalXSyncBasedPoller->q);
57 s_globalXSyncBasedPoller->q =
this;
59 int sync_major, sync_minor;
61 XSyncSystemCounter *counters;
63 if (!XSyncQueryExtension(m_display, &m_sync_event, &m_sync_error)) {
68 if (!XSyncInitialize(m_display, &sync_major, &sync_minor)) {
73 kDebug() << sync_major << sync_minor;
75 counters = XSyncListSystemCounters(m_display, &ncounters);
77 bool idleFound =
false;
79 for (
int i = 0; i < ncounters; ++i) {
80 if (!strcmp(counters[i].
name,
"IDLETIME")) {
81 m_idleCounter = counters[i].counter;
87 XSyncFreeSystemCounterList(counters);
94 kDebug() <<
"XSync seems available and ready";
96 kDebug() <<
"XSync seems not available";
115 kDebug() <<
"XSync Inited";
119 kDebug() <<
"Supported, init completed";
135 if (m_timeoutAlarm.contains(nextTimeout)) {
142 XSyncIntToValue(&timeout, nextTimeout);
144 setAlarm(m_display, &newalarm, m_idleCounter,
145 XSyncPositiveComparison, timeout);
147 m_timeoutAlarm.insert(nextTimeout, newalarm);
155 int XSyncBasedPoller::poll()
158 XSyncQueryCounter(m_display, m_idleCounter, &idleTime);
160 return XSyncValueLow32(idleTime);
165 if (m_timeoutAlarm.contains(timeout)) {
166 XSyncAlarm a = m_timeoutAlarm[timeout];
167 XSyncDestroyAlarm(m_display, a);
168 m_timeoutAlarm.remove(timeout);
174 return m_timeoutAlarm.keys();
180 XSyncDestroyAlarm(m_display, m_resetAlarm);
189 XSyncQueryCounter(m_display, m_idleCounter, &idleTime);
200 XSyncIntToValue(&add, -1);
201 XSyncValueAdd(&plusone, idleTime, add, &overflow);
202 setAlarm(m_display, &m_resetAlarm, m_idleCounter,
203 XSyncNegativeComparison, plusone);
206 void XSyncBasedPoller::reloadAlarms()
211 XSyncIntToValue(&timeout, i.key());
213 setAlarm(m_display, &(i.value()), m_idleCounter,
214 XSyncPositiveComparison, timeout);
220 XSyncAlarmNotifyEvent *alarmEvent;
222 if (event->type != m_sync_event + XSyncAlarmNotify) {
226 alarmEvent = (XSyncAlarmNotifyEvent *)event;
228 if (alarmEvent->state == XSyncAlarmDestroyed) {
233 if (alarmEvent->alarm == i.value()) {
242 if (alarmEvent->alarm == m_resetAlarm) {
252 void XSyncBasedPoller::setAlarm(Display *dpy, XSyncAlarm *alarm, XSyncCounter counter,
253 XSyncTestType test, XSyncValue value)
255 XSyncAlarmAttributes attr;
259 XSyncIntToValue(&delta, 0);
261 attr.trigger.counter = counter;
262 attr.trigger.value_type = XSyncAbsolute;
263 attr.trigger.test_type = test;
264 attr.trigger.wait_value = value;
267 flags = XSyncCACounter | XSyncCAValueType | XSyncCATestType |
268 XSyncCAValue | XSyncCADelta;
271 XSyncChangeAlarm(dpy, *alarm, flags, &attr);
273 *alarm = XSyncCreateAlarm(dpy, flags, &attr);
279 XResetScreenSaver(QX11Info::display());
282 #include "xsyncbasedpoller.moc"
void timeoutReached(int msec)
void addTimeout(int nextTimeout)
#define K_GLOBAL_STATIC(TYPE, NAME)
const char * name(StandardAction id)
virtual ~XSyncBasedPoller()
void stopCatchingIdleEvents()
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
static KApplication * kApplication()
void removeTimeout(int nextTimeout)
XSyncBasedPoller(QWidget *parent=0)
QList< int > timeouts() const
void simulateUserActivity()
void installX11EventFilter(QWidget *filter)
no error reporting is done
bool x11Event(XEvent *event)