[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kutils
From: Dario Freddi <drf () kde ! org>
Date: 2010-04-24 12:05:27
Message-ID: 20100424120527.6C7E2AC8A2 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1118318 by dafre:
* Fix and optimize some more things in XSync, like more #ifdefs removed, a memleak \
and some slow iterations
* KUtils no longer links to XTest \o/
M +0 -3 CMakeLists.txt
M +22 -58 kidletime/xsyncbasedpoller.cpp
M +0 -8 kidletime/xsyncbasedpoller.h
--- trunk/KDE/kdelibs/kutils/CMakeLists.txt #1118317:1118318
@@ -81,9 +81,6 @@
target_link_libraries(kutils LINK_INTERFACE_LIBRARIES kdecore kdeui \
${QT_QTGUI_LIBRARY} )
if (Q_WS_X11)
- if (HAVE_XTEST)
- target_link_libraries(kutils ${X11_XTest_LIB})
- endif (HAVE_XTEST)
if (HAVE_XSCREENSAVER)
target_link_libraries(kutils ${X11_Xss_LIB})
endif (HAVE_XSCREENSAVER)
--- trunk/KDE/kdelibs/kutils/kidletime/xsyncbasedpoller.cpp #1118317:1118318
@@ -25,8 +25,6 @@
#include <fixx11h.h>
-#include <X11/Xlib.h>
-
class XSyncBasedPollerHelper
{
public:
@@ -60,6 +58,7 @@
int sync_major, sync_minor;
int ncounters;
+ XSyncSystemCounter *counters;
if (!XSyncQueryExtension(m_display, &m_sync_event, &m_sync_error)) {
m_available = false;
@@ -73,18 +72,19 @@
kDebug() << sync_major << sync_minor;
- m_counters = XSyncListSystemCounters(m_display, &ncounters);
+ counters = XSyncListSystemCounters(m_display, &ncounters);
bool idleFound = false;
for (int i = 0; i < ncounters; ++i) {
- if (!strcmp(m_counters[i].name, "IDLETIME")) {
+ if (!strcmp(counters[i].name, "IDLETIME")) {
+ m_idleCounter = counters[i].counter;
idleFound = true;
break;
}
}
- XSyncFreeSystemCounterList(m_counters);
+ XSyncFreeSystemCounterList(counters);
if (!idleFound) {
m_available = false;
@@ -108,30 +108,12 @@
bool XSyncBasedPoller::setUpPoller()
{
-
- int ncounters;
-
if (!isAvailable()) {
return false;
}
kDebug() << "XSync Inited";
- m_counters = XSyncListSystemCounters(m_display, &ncounters);
-
- bool idleFound = false;
-
- for (int i = 0; i < ncounters && !m_idleCounter; ++i) {
- if (!strcmp(m_counters[i].name, "IDLETIME")) {
- m_idleCounter = m_counters[i].counter;
- idleFound = true;
- }
- }
-
- if (!idleFound) {
- return false;
- }
-
KApplication::kApplication()->installX11EventFilter(this);
kDebug() << "Supported, init completed";
@@ -141,7 +123,6 @@
void XSyncBasedPoller::unloadPoller()
{
- //XSyncFreeSystemCounterList( m_counters );
}
void XSyncBasedPoller::addTimeout(int nextTimeout)
@@ -150,23 +131,20 @@
* requested for next timeout
*/
+ // If there's already an alarm for the requested timeout, skip
+ if (m_timeoutAlarm.contains(nextTimeout)) {
+ return;
+ }
+
XSyncValue timeout;
XSyncAlarm newalarm = X::None;
- /*XSyncValue idleTime;
- XSyncValue result;
- int overflow;*/
-// XSyncQueryCounter(m_display, m_idleCounter, &idleTime);
-
XSyncIntToValue(&timeout, nextTimeout);
-// XSyncValueAdd(&result, idleTime, timeout, &overflow);
-
setAlarm(m_display, &newalarm, m_idleCounter,
XSyncPositiveComparison, timeout);
- m_timeoutAlarm[nextTimeout] = newalarm;
-
+ m_timeoutAlarm.insert(nextTimeout, newalarm);
}
int XSyncBasedPoller::forcePollRequest()
@@ -176,25 +154,19 @@
int XSyncBasedPoller::poll()
{
-
XSyncValue idleTime;
-
XSyncQueryCounter(m_display, m_idleCounter, &idleTime);
return XSyncValueLow32(idleTime);
-
- return -1;
}
void XSyncBasedPoller::removeTimeout(int timeout)
{
-
if (m_timeoutAlarm.contains(timeout)) {
XSyncAlarm a = m_timeoutAlarm[timeout];
- m_timeoutAlarm.remove(timeout);
XSyncDestroyAlarm(m_display, a);
+ m_timeoutAlarm.remove(timeout);
}
-
}
QList<int> XSyncBasedPoller::timeouts() const
@@ -204,15 +176,12 @@
void XSyncBasedPoller::stopCatchingIdleEvents()
{
-
XSyncDestroyAlarm(m_display, m_resetAlarm);
m_resetAlarm = X::None;
-
}
void XSyncBasedPoller::catchIdleEvent()
{
-
XSyncValue idleTime;
XSyncQueryCounter(m_display, m_idleCounter, &idleTime);
@@ -230,25 +199,22 @@
XSyncValueAdd(&plusone, idleTime, add, &overflow);
setAlarm(m_display, &m_resetAlarm, m_idleCounter,
XSyncNegativeComparison, plusone);
-
-
}
void XSyncBasedPoller::reloadAlarms()
{
XSyncValue timeout;
- foreach(int nextTimeout, m_timeoutAlarm.keys()) {
- XSyncIntToValue(&timeout, nextTimeout);
+ for (QHash<int, XSyncAlarm>::iterator i = m_timeoutAlarm.begin(); i != \
m_timeoutAlarm.end(); ++i) { + XSyncIntToValue(&timeout, i.key());
- setAlarm(m_display, &(m_timeoutAlarm[nextTimeout]), m_idleCounter,
+ setAlarm(m_display, &(i.value()), m_idleCounter,
XSyncPositiveComparison, timeout);
}
}
bool XSyncBasedPoller::x11Event(XEvent *event)
{
-
XSyncAlarmNotifyEvent *alarmEvent;
if (event->type != m_sync_event + XSyncAlarmNotify) {
@@ -261,11 +227,11 @@
return false;
}
- foreach(int timeout, m_timeoutAlarm.keys()) {
- if (alarmEvent->alarm == m_timeoutAlarm[timeout]) {
+ for (QHash<int, XSyncAlarm>::const_iterator i = m_timeoutAlarm.constBegin(); i \
!= m_timeoutAlarm.constEnd(); ++i) { + if (alarmEvent->alarm == i.value()) {
/* Bling! Caught! */
- emit timeoutReached(timeout);
- // Update back the alarm to fire back if the system gets inactive for \
the same time + emit timeoutReached(i.key());
+ // Update the alarm to fire back if the system gets inactive for the \
same time catchIdleEvent();
return false;
}
@@ -279,7 +245,6 @@
}
return false;
-
}
void XSyncBasedPoller::setAlarm(Display *dpy, XSyncAlarm *alarm, XSyncCounter \
counter, @@ -300,10 +265,11 @@
flags = XSyncCACounter | XSyncCAValueType | XSyncCATestType |
XSyncCAValue | XSyncCADelta;
- if (*alarm)
+ if (*alarm) {
XSyncChangeAlarm(dpy, *alarm, flags, &attr);
- else
+ } else {
*alarm = XSyncCreateAlarm(dpy, flags, &attr);
+ }
}
void XSyncBasedPoller::simulateUserActivity()
@@ -312,5 +278,3 @@
}
#include "xsyncbasedpoller.moc"
-
-
--- trunk/KDE/kdelibs/kutils/kidletime/xsyncbasedpoller.h #1118317:1118318
@@ -26,10 +26,8 @@
#include <config-kidletime.h>
-#ifdef HAVE_XSYNC
#include <X11/Xlib.h>
#include <X11/extensions/sync.h>
-#endif
class XSyncBasedPoller : public AbstractSystemPoller
{
@@ -61,22 +59,16 @@
int poll();
void reloadAlarms();
-#ifdef HAVE_XSYNC
private:
void setAlarm(Display *dpy, XSyncAlarm *alarm, XSyncCounter counter,
XSyncTestType test, XSyncValue value);
-#endif
private:
-#ifdef HAVE_XSYNC
Display * m_display;
int m_sync_event, m_sync_error;
- XSyncSystemCounter *m_counters;
XSyncCounter m_idleCounter;
QHash<int, XSyncAlarm> m_timeoutAlarm;
XSyncAlarm m_resetAlarm;
-#endif
- QWidget * m_filterWidget;
bool m_available;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic