3
* Compiz mouse position polling plugin
7
* Copyright : (C) 2008 by Dennis Kasprzyk
8
* E-mail : onestone@opencompositing.org
11
* This program is free software; you can redistribute it and/or
12
* modify it under the terms of the GNU General Public License
13
* as published by the Free Software Foundation; either version 2
14
* of the License, or (at your option) any later version.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
25
COMPIZ_PLUGIN_20090315 (mousepoll, MousepollPluginVTable);
28
MousepollScreen::getMousePosition ()
33
int w = screen->width (), h = screen->height ();
34
unsigned int maskReturn;
37
status = XQueryPointer (screen->dpy (), screen->root (),
38
&root, &child, &rootX, &rootY,
39
&winX, &winY, &maskReturn);
41
if (!status || rootX > w || rootY > h || screen->root () != root)
44
if (rootX != pos.x () || rootY != pos.y ())
46
pos.set (rootX, rootY);
54
MousepollScreen::updatePosition ()
57
if (getMousePosition ())
59
std::list<MousePoller *>::iterator it;
60
for (it = pollers.begin (); it != pollers.end (); )
62
MousePoller *poller = *it;
66
poller->mCallback (pos);
75
MousepollScreen::addTimer (MousePoller *poller)
77
bool start = pollers.empty ();
78
std::list<MousePoller *>::iterator it;
80
it = std::find (pollers.begin (), pollers.end (), poller);
81
if (it != pollers.end ())
84
pollers.insert (it, poller);
96
MousepollScreen::removeTimer (MousePoller *poller)
98
std::list<MousePoller *>::iterator it;
100
it = std::find (pollers.begin(), pollers.end (), poller);
101
if (it == pollers.end ())
106
if (pollers.empty ())
111
MousePoller::setCallback (MousePoller::CallBack callback)
113
bool wasActive = mActive;
118
mCallback = callback;
125
MousePoller::start ()
127
MOUSEPOLL_SCREEN (screen);
131
compLogMessage ("mousepoll", CompLogLevelWarn,
132
"Plugin version mismatch, can't start mouse poller.");
137
if (mCallback.empty ())
139
compLogMessage ("mousepoll", CompLogLevelWarn,
140
"Can't start mouse poller without callback.");
152
MOUSEPOLL_SCREEN (screen);
154
/* Prevent broken plugins from calling stop () twice */
161
compLogMessage ("mousepoll",
163
"Plugin version mismatch, can't stop mouse poller.");
170
ms->removeTimer (this);
174
MousePoller::active ()
180
MousePoller::getCurrentPosition ()
184
MOUSEPOLL_SCREEN (screen);
188
compLogMessage ("mousepoll", CompLogLevelWarn,
189
"Plugin version mismatch, can't get mouse position.");
193
ms->getMousePosition ();
201
MousePoller::getPosition ()
206
MousePoller::MousePoller () :
213
MousePoller::~MousePoller ()
220
MousepollScreen::updateTimer ()
222
float timeout = optionGetMousePollInterval ();
223
timer.setTimes (timeout, timeout * 1.5);
227
MousepollScreen::MousepollScreen (CompScreen *screen) :
228
PluginClassHandler <MousepollScreen, CompScreen, COMPIZ_MOUSEPOLL_ABI> (screen)
231
timer.setCallback (boost::bind (&MousepollScreen::updatePosition, this));
233
optionSetMousePollIntervalNotify (boost::bind (&MousepollScreen::updateTimer, this));
237
MousepollPluginVTable::init ()
239
if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
243
p.uval = COMPIZ_MOUSEPOLL_ABI;
244
screen->storeValue ("mousepoll_ABI", p);
250
MousepollPluginVTable::fini ()
252
screen->eraseValue ("mousepoll_ABI");