summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/compcore.h58
-rw-r--r--src/core.cpp243
-rw-r--r--src/display.cpp20
-rw-r--r--src/event.cpp37
-rw-r--r--src/privatecore.h14
-rw-r--r--src/privatedisplay.h6
-rw-r--r--src/privatescreen.h4
-rw-r--r--src/privatewindow.h2
-rw-r--r--src/screen.cpp30
-rw-r--r--src/window.cpp10
10 files changed, 251 insertions, 173 deletions
diff --git a/include/compcore.h b/include/compcore.h
index 97a38b5..e775b28 100644
--- a/include/compcore.h
+++ b/include/compcore.h
@@ -26,16 +26,6 @@ typedef struct _CompFileWatch {
CompFileWatchHandle handle;
} CompFileWatch;
-typedef struct _CompTimeout {
- int minTime;
- int maxTime;
- int minLeft;
- int maxLeft;
- CallBackProc callBack;
- void *closure;
- CompTimeoutHandle handle;
-} CompTimeout;
-
typedef struct _CompWatchFd {
int fd;
CallBackProc callBack;
@@ -89,6 +79,43 @@ class CoreInterface : public WrapableInterface<CompCore> {
class CompCore : public WrapableHandler<CoreInterface>, public CompObject {
+ public:
+ class Timer {
+
+ public:
+ Timer ();
+ ~Timer ();
+
+ bool active ();
+ unsigned int minTime ();
+ unsigned int maxTime ();
+ unsigned int minLeft ();
+ unsigned int maxLeft ();
+ void *closure ();
+
+
+ void setTimes (unsigned int min, unsigned int max = 0);
+ void setCallback (CallBackProc callback, void *closure = NULL);
+
+ void start ();
+ void start (unsigned int min, unsigned int max = 0);
+ void start (unsigned int min, unsigned int max,
+ CallBackProc callback, void *closure = NULL);
+ void stop ();
+
+ friend class CompCore;
+ friend class PrivateCore;
+
+ private:
+ bool mActive;
+ unsigned int mMinTime;
+ unsigned int mMaxTime;
+ int mMinLeft;
+ int mMaxLeft;
+ CallBackProc mCallBack;
+ void *mClosure;
+ };
+
// functions
public:
CompCore ();
@@ -119,13 +146,7 @@ class CompCore : public WrapableHandler<CoreInterface>, public CompObject {
void
removeFileWatch (CompFileWatchHandle handle);
-
- CompTimeoutHandle
- addTimeout (int minTime,
- int maxTime,
- CallBackProc callBack,
- void *closure = NULL);
-
+
CompWatchFdHandle
addWatchFd (int fd,
short int events,
@@ -135,8 +156,6 @@ class CompCore : public WrapableHandler<CoreInterface>, public CompObject {
void
removeWatchFd (CompWatchFdHandle handle);
- void *
- removeTimeout (CompTimeoutHandle handle);
static int allocPrivateIndex ();
static void freePrivateIndex (int index);
@@ -156,6 +175,7 @@ class CompCore : public WrapableHandler<CoreInterface>, public CompObject {
WRAPABLE_HND(void, sessionEvent, CompSessionEvent, CompOption *, unsigned int)
+ friend class Timer;
private:
PrivateCore *priv;
};
diff --git a/src/core.cpp b/src/core.cpp
index bf03ab9..cdb3e4c 100644
--- a/src/core.cpp
+++ b/src/core.cpp
@@ -26,6 +26,7 @@
#include <string.h>
#include <sys/poll.h>
#include <assert.h>
+#include <algorithm>
#include <compiz-core.h>
#include "privatecore.h"
@@ -169,10 +170,10 @@ CompCore::removeDisplay (CompDisplay *d)
void
CompCore::eventLoop ()
{
- struct timeval tv;
- CompDisplay *d;
- CompTimeout *t;
- int time;
+ struct timeval tv;
+ CompDisplay *d;
+ CompCore::Timer *t;
+ int time;
for (d = priv->displays; d; d = d->next)
d->setWatchFdHandle (addWatchFd (ConnectionNumber (d->dpy()),
@@ -188,24 +189,24 @@ CompCore::eventLoop ()
d->processEvents ();
}
- if (!priv->timeouts.empty())
+ if (!priv->timers.empty())
{
gettimeofday (&tv, 0);
- priv->handleTimeouts (&tv);
+ priv->handleTimers (&tv);
- if ((*priv->timeouts.begin())->minLeft > 0)
+ if ((*priv->timers.begin())->mMinLeft > 0)
{
- std::list<CompTimeout *>::iterator it = priv->timeouts.begin();
+ std::list<CompCore::Timer *>::iterator it = priv->timers.begin();
t = (*it);
- time = t->maxLeft;
- while (it != priv->timeouts.end())
+ time = t->mMaxLeft;
+ while (it != priv->timers.end())
{
t = (*it);
- if (t->minLeft <= time)
+ if (t->mMinLeft <= time)
break;
- if (t->maxLeft < time)
- time = t->maxLeft;
+ if (t->mMaxLeft < time)
+ time = t->mMaxLeft;
it++;
}
priv->doPoll (time);
@@ -271,69 +272,38 @@ CompCore::removeFileWatch (CompFileWatchHandle handle)
}
void
-PrivateCore::addTimeout (CompTimeout *timeout)
+PrivateCore::addTimer (CompCore::Timer *timer)
{
- std::list<CompTimeout *>::iterator it;
+ std::list<CompCore::Timer *>::iterator it;
- for (it = timeouts.begin(); it != timeouts.end(); it++)
+ it = std::find (timers.begin (), timers.end (), timer);
+
+ if (it != timers.end ())
+ return;
+
+ for (it = timers.begin(); it != timers.end(); it++)
{
- if (timeout->minTime < (*it)->minLeft)
+ if ((int) timer->mMinTime < (*it)->mMinLeft)
break;
}
- timeout->minLeft = timeout->minTime;
- timeout->maxLeft = timeout->maxTime;
-
- timeouts.insert (it, timeout);
-}
-
-CompTimeoutHandle
-CompCore::addTimeout (int minTime,
- int maxTime,
- CallBackProc callBack,
- void *closure)
-{
- CompTimeout *timeout = new CompTimeout();
-
- if (!timeout)
- return 0;
-
- timeout->minTime = minTime;
- timeout->maxTime = (maxTime >= minTime) ? maxTime : minTime;
- timeout->callBack = callBack;
- timeout->closure = closure;
- timeout->handle = priv->lastTimeoutHandle++;
-
- if (priv->lastTimeoutHandle == MAXSHORT)
- priv->lastTimeoutHandle = 1;
-
- priv->addTimeout (timeout);
+ timer->mMinLeft = timer->mMinTime;
+ timer->mMaxLeft = timer->mMaxTime;
- return timeout->handle;
+ timers.insert (it, timer);
}
-void *
-CompCore::removeTimeout (CompTimeoutHandle handle)
+void
+PrivateCore::removeTimer (CompCore::Timer *timer)
{
- std::list<CompTimeout *>::iterator it;
- CompTimeout *t;
- void *closure = NULL;
-
- for (it = priv->timeouts.begin(); it != priv->timeouts.end(); it++)
- if ((*it)->handle == handle)
- break;
-
- if (it == priv->timeouts.end())
- return NULL;
+ std::list<CompCore::Timer *>::iterator it;
- t = (*it);
- priv->timeouts.erase (it);
+ it = std::find (timers.begin (), timers.end (), timer);
- closure = t->closure;
-
- delete t;
+ if (it == timers.end ())
+ return;
- return closure;
+ timers.erase (it);
}
CompWatchFdHandle
@@ -430,11 +400,11 @@ PrivateCore::doPoll (int timeout)
}
void
-PrivateCore::handleTimeouts (struct timeval *tv)
+PrivateCore::handleTimers (struct timeval *tv)
{
- CompTimeout *t;
- int timeDiff;
- std::list<CompTimeout *>::iterator it;
+ CompCore::Timer *t;
+ int timeDiff;
+ std::list<CompCore::Timer *>::iterator it;
timeDiff = TIMEVALDIFF (tv, &lastTimeout);
@@ -442,26 +412,24 @@ PrivateCore::handleTimeouts (struct timeval *tv)
if (timeDiff < 0)
timeDiff = 0;
- for (it = timeouts.begin(); it != timeouts.end(); it++)
+ for (it = timers.begin(); it != timers.end(); it++)
{
t = (*it);
- t->minLeft -= timeDiff;
- t->maxLeft -= timeDiff;
+ t->mMinLeft -= timeDiff;
+ t->mMaxLeft -= timeDiff;
}
- while (timeouts.begin() != timeouts.end() &&
- (*timeouts.begin())->minLeft <= 0)
+ while (timers.begin() != timers.end() &&
+ (*timers.begin())->mMinLeft <= 0)
{
- t = (*timeouts.begin());
- timeouts.pop_front();
+ t = (*timers.begin());
+ timers.pop_front();
- if ((*t->callBack) (t->closure))
- {
- addTimeout (t);
- }
- else
+ t->mActive = false;
+ if ((*t->mCallBack) (t->mClosure))
{
- delete t;
+ addTimer (t);
+ t->mActive = true;
}
}
@@ -577,8 +545,7 @@ PrivateCore::PrivateCore (CompCore *core) :
displays (0),
fileWatch (0),
lastFileWatchHandle (1),
- timeouts (0),
- lastTimeoutHandle (1),
+ timers (0),
watchFds (0),
lastWatchFdHandle (1),
watchPollFds (0),
@@ -590,3 +557,115 @@ PrivateCore::PrivateCore (CompCore *core) :
PrivateCore::~PrivateCore ()
{
}
+
+CompCore::Timer::Timer () :
+ mActive (false),
+ mMinTime (0),
+ mMaxTime (0),
+ mMinLeft (0),
+ mMaxLeft (0),
+ mCallBack (NULL),
+ mClosure (NULL)
+{
+}
+
+CompCore::Timer::~Timer ()
+{
+ if (mActive)
+ core->priv->removeTimer (this);
+}
+
+void
+CompCore::Timer::setTimes (unsigned int min, unsigned int max)
+{
+ bool wasActive = mActive;
+ if (mActive)
+ stop ();
+ mMinTime = min;
+ mMaxTime = (min <= max)? max : min;
+
+ if (wasActive)
+ start ();
+}
+
+void
+CompCore::Timer::setCallback (CallBackProc callback, void *closure)
+{
+ bool wasActive = mActive;
+ if (mActive)
+ stop ();
+ mCallBack = callback;
+ mClosure = closure;
+
+ if (wasActive)
+ start ();
+}
+
+void
+CompCore::Timer::start ()
+{
+ stop ();
+ mActive = true;
+ core->priv->addTimer (this);
+}
+
+void
+CompCore::Timer::start (unsigned int min, unsigned int max)
+{
+ stop ();
+ setTimes (min, max);
+ start ();
+}
+
+void
+CompCore::Timer::start (unsigned int min, unsigned int max,
+ CallBackProc callback, void *closure)
+{
+ stop ();
+ setTimes (min, max);
+ setCallback (callback, closure);
+ start ();
+}
+
+void
+CompCore::Timer::stop ()
+{
+ mActive = false;
+ core->priv->removeTimer (this);
+}
+
+unsigned int
+CompCore::Timer::minTime ()
+{
+ return mMinTime;
+}
+
+unsigned int
+CompCore::Timer::maxTime ()
+{
+ return mMaxTime;
+}
+
+unsigned int
+CompCore::Timer::minLeft ()
+{
+ return (mMinLeft < 0)? 0 : mMinLeft;
+}
+
+unsigned int
+CompCore::Timer::maxLeft ()
+{
+ return (mMaxLeft < 0)? 0 : mMaxLeft;
+}
+
+void *
+CompCore::Timer::closure ()
+{
+ return mClosure;
+}
+
+bool
+CompCore::Timer::active ()
+{
+ return mActive;
+} \ No newline at end of file
diff --git a/src/display.cpp b/src/display.cpp
index 7495b54..c72f9e0 100644
--- a/src/display.cpp
+++ b/src/display.cpp
@@ -785,8 +785,6 @@ CompDisplay::~CompDisplay ()
objectFiniPlugins (this);
- core->removeTimeout (priv->pingHandle);
-
if (priv->snDisplay)
sn_display_unref (priv->snDisplay);
@@ -1022,10 +1020,9 @@ CompDisplay::init (const char *name)
priv->screens->focusDefaultWindow ();
}
- priv->pingHandle =
- core->addTimeout (priv->opt[COMP_DISPLAY_OPTION_PING_DELAY].value.i,
- priv->opt[COMP_DISPLAY_OPTION_PING_DELAY].value.i +
- 500, CompDisplay::pingTimeout, this);
+ priv->pingTimer.start (priv->opt[COMP_DISPLAY_OPTION_PING_DELAY].value.i,
+ priv->opt[COMP_DISPLAY_OPTION_PING_DELAY].value.i +
+ 500, CompDisplay::pingTimeout, this);
return true;
}
@@ -1304,12 +1301,7 @@ CompDisplay::setOption (const char *name,
case COMP_DISPLAY_OPTION_PING_DELAY:
if (compSetIntOption (o, value))
{
- if (priv->pingHandle)
- core->removeTimeout (priv->pingHandle);
-
- priv->pingHandle =
- core->addTimeout (o->value.i, o->value.i + 500,
- CompDisplay::pingTimeout, priv->dpy);
+ priv->pingTimer.setTimes (o->value.i, o->value.i + 500);
return true;
}
break;
@@ -2647,9 +2639,9 @@ PrivateDisplay::PrivateDisplay (CompDisplay *display) :
below (None),
modMap (0),
ignoredModMask (LockMask),
- autoRaiseHandle (0),
+ autoRaiseTimer (),
autoRaiseWindow (0),
- edgeDelayHandle (0),
+ edgeDelayTimer (),
dirtyPluginList (true)
{
for (int i = 0; i < CompModNum; i++)
diff --git a/src/event.cpp b/src/event.cpp
index ca6f656..f456e85 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -86,12 +86,6 @@ CompWindow::handleSyncAlarm ()
{
if (priv->syncWait)
{
- if (priv->syncWaitHandle)
- {
- core->removeTimeout (priv->syncWaitHandle);
- priv->syncWaitHandle = 0;
- }
-
priv->syncWait = FALSE;
if (resize (priv->syncGeometry))
@@ -120,7 +114,6 @@ CompWindow::handleSyncAlarm ()
}
}
- priv->syncWaitHandle = 0;
return false;
}
@@ -723,9 +716,9 @@ PrivateDisplay::triggerEdgeEnter (unsigned int edge,
for (i = 0; i < nArgument; i++)
delayedSettings->option[i] = argument[i];
- edgeDelayHandle = core->addTimeout (delay, (float) delay * 1.2,
- delayedEdgeTimeout,
- delayedSettings);
+ edgeDelayTimer.start (delay, (float) delay * 1.2,
+ delayedEdgeTimeout,
+ delayedSettings);
delayState = CompActionStateNoEdgeDelay;
if (triggerAllEdgeEnterBindings (display, state, delayState,
@@ -875,14 +868,14 @@ PrivateDisplay::handleActionEvent (XEvent *event)
if (!s)
return false;
- if (edgeDelayHandle)
+ if (edgeDelayTimer.active ())
{
- void *closure;
+ edgeDelayTimer.stop ();
+
+ if (edgeDelayTimer.closure ())
+ free (edgeDelayTimer.closure ());
- closure = core->removeTimeout (edgeDelayHandle);
- if (closure)
- free (closure);
- edgeDelayHandle = 0;
+ edgeDelayTimer.setCallback (delayedEdgeTimeout, NULL);
}
if (edgeWindow && edgeWindow != event->xcrossing.window)
@@ -1921,11 +1914,10 @@ CompDisplay::handleEvent (XEvent *event)
if (!priv->opt[COMP_DISPLAY_OPTION_CLICK_TO_FOCUS].value.b)
{
- if (priv->autoRaiseHandle &&
+ if (priv->autoRaiseTimer.active () &&
priv->autoRaiseWindow != w->id ())
{
- core->removeTimeout (priv->autoRaiseHandle);
- priv->autoRaiseHandle = 0;
+ priv->autoRaiseTimer.stop ();
}
if (w->type () & ~(CompWindowTypeDockMask |
@@ -1938,9 +1930,10 @@ CompDisplay::handleEvent (XEvent *event)
if (delay > 0)
{
priv->autoRaiseWindow = w->id ();
- priv->autoRaiseHandle =
- core->addTimeout (delay, (float) delay * 1.2,
- autoRaiseTimeout, this);
+ priv->autoRaiseTimer.start (delay,
+ (float) delay * 1.2,
+ autoRaiseTimeout,
+ this);
}
else
{
diff --git a/src/privatecore.h b/src/privatecore.h
index c6b4764..3f0ef01 100644
--- a/src/privatecore.h
+++ b/src/privatecore.h
@@ -10,9 +10,6 @@ class PrivateCore {
PrivateCore (CompCore *core);
~PrivateCore ();
- void
- addTimeout(CompTimeout *);
-
short int
watchFdEvents (CompWatchFdHandle handle);
@@ -20,7 +17,11 @@ class PrivateCore {
doPoll (int timeout);
void
- handleTimeouts (struct timeval *tv);
+ handleTimers (struct timeval *tv);
+
+ void addTimer (CompCore::Timer *timer);
+ void removeTimer (CompCore::Timer *timer);
+
public:
CompCore *core;
@@ -29,9 +30,8 @@ class PrivateCore {
std::list<CompFileWatch *> fileWatch;
CompFileWatchHandle lastFileWatchHandle;
- std::list<CompTimeout *> timeouts;
- struct timeval lastTimeout;
- CompTimeoutHandle lastTimeoutHandle;
+ std::list<CompCore::Timer *> timers;
+ struct timeval lastTimeout;
std::list<CompWatchFd *> watchFds;
CompWatchFdHandle lastWatchFdHandle;
diff --git a/src/privatedisplay.h b/src/privatedisplay.h
index 8796f04..342c080 100644
--- a/src/privatedisplay.h
+++ b/src/privatedisplay.h
@@ -105,7 +105,7 @@ class PrivateDisplay {
SnDisplay *snDisplay;
unsigned int lastPing;
- CompTimeoutHandle pingHandle;
+ CompCore::Timer pingTimer;
GLenum textureFilter;
@@ -123,10 +123,10 @@ class PrivateDisplay {
CompOption opt[COMP_DISPLAY_OPTION_NUM];
- CompTimeoutHandle autoRaiseHandle;
+ CompCore::Timer autoRaiseTimer;
Window autoRaiseWindow;
- CompTimeoutHandle edgeDelayHandle;
+ CompCore::Timer edgeDelayTimer;
CompOptionValue plugin;
bool dirtyPluginList;
diff --git a/src/privatescreen.h b/src/privatescreen.h
index f765222..4d43589 100644
--- a/src/privatescreen.h
+++ b/src/privatescreen.h
@@ -192,7 +192,7 @@ class PrivateScreen {
SnMonitorContext *snContext;
CompStartupSequence *startupSequences;
- unsigned int startupSequenceTimeoutHandle;
+ CompCore::Timer startupSequenceTimer;
int filter[3];
@@ -258,7 +258,7 @@ class PrivateScreen {
CompOption opt[COMP_SCREEN_OPTION_NUM];
- CompTimeoutHandle paintHandle;
+ CompCore::Timer paintTimer;
GLXGetProcAddressProc getProcAddress;
diff --git a/src/privatewindow.h b/src/privatewindow.h
index 6e20a32..9b77b76 100644
--- a/src/privatewindow.h
+++ b/src/privatewindow.h
@@ -231,7 +231,7 @@ class PrivateWindow {
XSyncValue syncValue;
XSyncAlarm syncAlarm;
unsigned long syncAlarmConnection;
- unsigned int syncWaitHandle;
+ CompCore::Timer syncWaitTimer;
bool syncWait;
CompWindow::Geometry syncGeometry;
diff --git a/src/screen.cpp b/src/screen.cpp
index 51730a8..a419e67 100644
--- a/src/screen.cpp
+++ b/src/screen.cpp
@@ -588,10 +588,10 @@ PrivateScreen::addSequence (SnStartupSequence *sequence)
startupSequences = s;
- if (!startupSequenceTimeoutHandle)
- core->addTimeout (1000, 1500,
- CompScreen::startupSequenceTimeout,
- this);
+ if (!startupSequenceTimer.active ())
+ startupSequenceTimer.start (1000, 1500,
+ CompScreen::startupSequenceTimeout,
+ this);
updateStartupFeedback ();
}
@@ -621,11 +621,8 @@ PrivateScreen::removeSequence (SnStartupSequence *sequence)
free (s);
- if (!startupSequences && startupSequenceTimeoutHandle)
- {
- core->removeTimeout (startupSequenceTimeoutHandle);
- startupSequenceTimeoutHandle = 0;
- }
+ if (!startupSequences && startupSequenceTimer.active ())
+ startupSequenceTimer.stop ();
updateStartupFeedback ();
}
@@ -1469,7 +1466,7 @@ PrivateScreen::PrivateScreen (CompScreen *screen) :
overlayWindowCount (0),
snContext (0),
startupSequences (0),
- startupSequenceTimeoutHandle (0),
+ startupSequenceTimer (),
groups (0),
defaultIcon (0),
canDoSaturated (false),
@@ -1499,7 +1496,7 @@ PrivateScreen::PrivateScreen (CompScreen *screen) :
desktopHintSize (0),
cursors (0),
cursorImages (0),
- paintHandle (0),
+ paintTimer (),
getProcAddress (0)
{
memset (saturateFunction, 0, sizeof (saturateFunction));
@@ -2291,14 +2288,14 @@ CompScreen::init (CompDisplay *display,
priv->filter[SCREEN_TRANS_FILTER] = COMP_TEXTURE_FILTER_GOOD;
priv->filter[WINDOW_TRANS_FILTER] = COMP_TEXTURE_FILTER_GOOD;
- priv->paintHandle = core->addTimeout (priv->optimalRedrawTime, MAXSHORT,
- PrivateScreen::paintTimeout, this);
+ priv->paintTimer.start (priv->optimalRedrawTime, MAXSHORT,
+ PrivateScreen::paintTimeout, this);
return true;
}
CompScreen::~CompScreen ()
{
- core->removeTimeout (priv->paintHandle);
+ priv->paintTimer.stop ();
while (priv->windows)
delete priv->windows;
@@ -4603,9 +4600,8 @@ CompScreen::handlePaintTimeout ()
gettimeofday (&tv, 0);
- core->addTimeout (getTimeToNextRedraw (&tv), MAXSHORT,
- PrivateScreen::paintTimeout, this);
- return false;
+ priv->paintTimer.setTimes (getTimeToNextRedraw (&tv), MAXSHORT);
+ return true;
}
int
diff --git a/src/window.cpp b/src/window.cpp
index 7c8c5c9..6a259d2 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1750,9 +1750,8 @@ CompWindow::sendSyncRequest ()
priv->syncWait = TRUE;
priv->syncGeometry = priv->serverGeometry;
- if (!priv->syncWaitHandle)
- priv->syncWaitHandle =
- core->addTimeout (1000, 1200, syncWaitTimeout, this);
+ if (!priv->syncWaitTimer.active ())
+ priv->syncWaitTimer.start (1000, 1200, syncWaitTimeout, this);
}
void
@@ -5294,7 +5293,7 @@ PrivateWindow::PrivateWindow (CompWindow *window) :
saveMask (0),
syncCounter (0),
syncAlarm (None),
- syncWaitHandle (0),
+ syncWaitTimer (),
syncWait (false),
closeRequests (false),
@@ -5339,8 +5338,7 @@ PrivateWindow::~PrivateWindow ()
if (syncAlarm)
XSyncDestroyAlarm (screen->display ()->dpy (), syncAlarm);
- if (syncWaitHandle)
- core->removeTimeout (syncWaitHandle);
+ syncWaitTimer.stop ();
destroyTexture (screen, texture);