summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <smspillaz@gmail.com>2009-02-02 15:29:05 +0100
committerDanny Baumann <dannybaumann@web.de>2009-02-02 15:29:05 +0100
commit0a34f7381c5f50ad2e8183a6471e99f181f72f93 (patch)
tree6b6352bef7382f350b5cc85c023310fa13a53d48
parent0bc295aaeb8482753cb801b216d72de861c16499 (diff)
downloadmousepoll-0a34f7381c5f50ad2e8183a6471e99f181f72f93.tar.gz
mousepoll-0a34f7381c5f50ad2e8183a6471e99f181f72f93.tar.bz2
Initial C++ port.
-rw-r--r--Makefile36
-rw-r--r--mousepoll.c491
-rw-r--r--mousepoll.cpp261
-rw-r--r--mousepoll.h (renamed from compiz-mousepoll.h)48
-rw-r--r--mousepoll.xml.in6
-rw-r--r--private.h85
6 files changed, 381 insertions, 546 deletions
diff --git a/Makefile b/Makefile
index d9a07cf..fb9d387 100644
--- a/Makefile
+++ b/Makefile
@@ -89,14 +89,14 @@ INSTALL = install
BCOP = `pkg-config --variable=bin bcop`
-CFLAGS = -g -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -fno-strict-aliasing `pkg-config --cflags $(PKG_DEP) compiz ` $(CFLAGS_ADD)
+CFLAGS = -g -Wall -Wpointer-arith -fno-strict-aliasing `pkg-config --cflags $(PKG_DEP) compiz ` $(CFLAGS_ADD)
LDFLAGS = `pkg-config --libs $(PKG_DEP) compiz ` $(LDFLAGS_ADD)
DEFINES = -DIMAGEDIR=\"$(IMAGEDIR)\" -DDATADIR=\"$(DATADIR)\"
POFILEDIR = $(shell if [ -n "$(PODIR)" ]; then $(ECHO) $(PODIR); else $(ECHO) ./po;fi )
-COMPIZ_HEADERS = compiz.h compiz-core.h
+COMPIZ_HEADERS = compiz.h core/core.h
COMPIZ_INC = $(shell pkg-config --variable=includedir compiz)/compiz/
is-bcop-target := $(shell if [ -e $(PLUGIN).xml.in ]; then cat $(PLUGIN).xml.in | grep "useBcop=\"true\""; \
@@ -105,7 +105,6 @@ is-bcop-target := $(shell if [ -e $(PLUGIN).xml.in ]; then cat $(PLUGIN).xml.in
trans-target := $(shell if [ -e $(PLUGIN).xml.in -o -e $(PLUGIN).xml ]; then $(ECHO) $(BUILDDIR)/$(PLUGIN).xml;fi )
bcop-target := $(shell if [ -n "$(is-bcop-target)" ]; then $(ECHO) $(BUILDDIR)/$(PLUGIN).xml; fi )
-bcop-target-src := $(shell if [ -n "$(is-bcop-target)" ]; then $(ECHO) $(BUILDDIR)/$(PLUGIN)_options.c; fi )
bcop-target-hdr := $(shell if [ -n "$(is-bcop-target)" ]; then $(ECHO) $(BUILDDIR)/$(PLUGIN)_options.h; fi )
gen-schemas := $(shell if [ \( -e $(PLUGIN).xml.in -o -e $(PLUGIN).xml \) -a -n "`pkg-config --variable=xsltdir compiz-gconf`" ]; then $(ECHO) true; fi )
@@ -119,17 +118,14 @@ endif
# find all the object files
-c-objs := $(patsubst %.c,%.lo,$(shell find -name '*.c' 2> /dev/null | grep -v "$(BUILDDIR)/" | sed -e 's/^.\///'))
-c-objs += $(patsubst %.cpp,%.lo,$(shell find -name '*.cpp' 2> /dev/null | grep -v "$(BUILDDIR)/" | sed -e 's/^.\///'))
+c-objs := $(patsubst %.cpp,%.lo,$(shell find -name '*.cpp' 2> /dev/null | grep -v "$(BUILDDIR)/" | sed -e 's/^.\///'))
c-objs += $(patsubst %.cxx,%.lo,$(shell find -name '*.cxx' 2> /dev/null | grep -v "$(BUILDDIR)/" | sed -e 's/^.\///'))
-c-objs := $(filter-out $(bcop-target-src:.c=.lo),$(c-objs))
h-files := $(shell find -name '*.h' 2> /dev/null | grep -v "$(BUILDDIR)/" | sed -e 's/^.\///')
h-files += $(bcop-target-hdr)
h-files += $(foreach file,$(COMPIZ_HEADERS) $(CHK_HEADERS),$(shell $(ECHO) -n "$(COMPIZ_INC)$(file)"))
all-c-objs := $(addprefix $(BUILDDIR)/,$(c-objs))
-all-c-objs += $(bcop-target-src:.c=.lo)
# additional files
@@ -280,28 +276,6 @@ $(BUILDDIR)/compiz-%.pc: compiz-%.pc.in
# Compiling
#
-$(BUILDDIR)/%.lo: %.c $(h-files)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5mcompiling \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "compiling $< -> $@"; \
- fi
- @$(LIBTOOL) --quiet --mode=compile $(CC) $(CFLAGS) $(DEFINES) -I$(BUILDDIR) -c -o $@ $<
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mcompiling : \033[34m$< -> $@\033[0m"; \
- fi
-
-$(BUILDDIR)/%.lo: $(BUILDDIR)/%.c $(h-files)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5mcompiling \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "compiling $< -> $@"; \
- fi
- @$(LIBTOOL) --quiet --mode=compile $(CC) $(CFLAGS) $(DEFINES) -I$(BUILDDIR) -c -o $@ $<
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mcompiling : \033[34m$< -> $@\033[0m"; \
- fi
-
$(BUILDDIR)/%.lo: %.cpp $(h-files)
@if [ '$(color)' != 'no' ]; then \
$(ECHO) -n -e "\033[0;1;5mcompiling \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
@@ -319,7 +293,7 @@ $(BUILDDIR)/%.lo: %.cxx $(h-files)
else \
$(ECHO) "compiling $< -> $@"; \
fi
- @$(LIBTOOL) --quiet --mode=compile $(CPP) $(CFLAGS) $(DEFINES) -I$(BUILDDIR) -c -o $@ $<
+ @$(LIBTOOL) --mode=compile $(CPP) $(CFLAGS) $(DEFINES) -I$(BUILDDIR) -c -o $@ $<
@if [ '$(color)' != 'no' ]; then \
$(ECHO) -e "\r\033[0mcompiling : \033[34m$< -> $@\033[0m"; \
fi
@@ -336,7 +310,7 @@ $(BUILDDIR)/lib$(PLUGIN).la: $(all-c-objs)
else \
$(ECHO) "linking : $@"; \
fi
- @$(LIBTOOL) --quiet --mode=link $(CC) $(LDFLAGS) -rpath $(DESTDIR) -o $@ $(all-c-objs)
+ @$(LIBTOOL) --quiet --mode=link $(CC) $(LDFLAGS) -rpath $(DESTDIR) -o $@ $(all-c-objs) -R `pkg-config --variable=libdir compiz`/compiz
@if [ '$(color)' != 'no' ]; then \
$(ECHO) -e "\r\033[0mlinking : \033[34m$@\033[0m"; \
fi
diff --git a/mousepoll.c b/mousepoll.c
deleted file mode 100644
index d64d641..0000000
--- a/mousepoll.c
+++ /dev/null
@@ -1,491 +0,0 @@
-/*
- *
- * Compiz mouse position polling plugin
- *
- * mousepoll.c
- *
- * Copyright : (C) 2008 by Dennis Kasprzyk
- * E-mail : onestone@opencompositing.org
- *
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
-
-#include <compiz-core.h>
-
-#include "compiz-mousepoll.h"
-
-static CompMetadata mousepollMetadata;
-
-static int displayPrivateIndex;
-static int functionsPrivateIndex;
-
-typedef struct _MousepollClient MousepollClient;
-
-struct _MousepollClient {
- MousepollClient *next;
- MousepollClient *prev;
-
- PositionPollingHandle id;
- PositionUpdateProc update;
-};
-
-typedef enum _MousepollDisplayOptions
-{
- MP_DISPLAY_OPTION_ABI,
- MP_DISPLAY_OPTION_INDEX,
- MP_DISPLAY_OPTION_MOUSE_POLL_INTERVAL,
- MP_DISPLAY_OPTION_NUM
-} MousepollDisplayOptions;
-
-typedef struct _MousepollDisplay {
- int screenPrivateIndex;
-
- CompOption opt[MP_DISPLAY_OPTION_NUM];
-} MousepollDisplay;
-
-typedef struct _MousepollScreen {
-
- MousepollClient *clients;
- PositionPollingHandle freeId;
-
- CompTimeoutHandle updateHandle;
- int posX;
- int posY;
-
-} MousepollScreen;
-
-#define GET_MOUSEPOLL_DISPLAY(d) \
- ((MousepollDisplay *) (d)->base.privates[displayPrivateIndex].ptr)
-
-#define MOUSEPOLL_DISPLAY(d) \
- MousepollDisplay *md = GET_MOUSEPOLL_DISPLAY (d)
-
-#define GET_MOUSEPOLL_SCREEN(s, md) \
- ((MousepollScreen *) (s)->base.privates[(md)->screenPrivateIndex].ptr)
-
-#define MOUSEPOLL_SCREEN(s) \
- MousepollScreen *ms = GET_MOUSEPOLL_SCREEN (s, GET_MOUSEPOLL_DISPLAY (s->display))
-
-#define NUM_OPTIONS(s) (sizeof ((s)->opt) / sizeof (CompOption))
-
-static Bool
-getMousePosition (CompScreen *s)
-{
- Window root_return;
- Window child_return;
- int rootX, rootY;
- int winX, winY;
- unsigned int maskReturn;
- Bool status;
-
- MOUSEPOLL_SCREEN (s);
-
- status = XQueryPointer (s->display->display, s->root,
- &root_return, &child_return,
- &rootX, &rootY, &winX, &winY, &maskReturn);
-
- if (!status || rootX > s->width || rootY > s->height ||
- s->root != root_return)
- return FALSE;
-
- if ((rootX != ms->posX || rootY != ms->posY))
- {
- ms->posX = rootX;
- ms->posY = rootY;
- return TRUE;
- }
- return FALSE;
-}
-
-static Bool
-updatePosition (void *c)
-{
- CompScreen *s = (CompScreen *)c;
- MousepollClient *mc;
-
- MOUSEPOLL_SCREEN (s);
-
- if (!ms->clients)
- return FALSE;
-
- if (getMousePosition (s))
- {
- MousepollClient *next;
- for (mc = ms->clients; mc; mc = next)
- {
- next = mc->next;
- if (mc->update)
- (*mc->update) (s, ms->posX, ms->posY);
- }
- }
-
- return TRUE;
-}
-
-static PositionPollingHandle
-mousepollAddPositionPolling (CompScreen *s,
- PositionUpdateProc update)
-{
- MOUSEPOLL_SCREEN (s);
- MOUSEPOLL_DISPLAY (s->display);
-
- Bool start = FALSE;
-
- MousepollClient *mc = malloc (sizeof (MousepollClient));
-
- if (!mc)
- return -1;
-
- if (!ms->clients)
- start = TRUE;
-
- mc->update = update;
- mc->id = ms->freeId;
- ms->freeId++;
-
- mc->prev = NULL;
- mc->next = ms->clients;
-
- if (ms->clients)
- ms->clients->prev = mc;
-
- ms->clients = mc;
-
- if (start)
- {
- getMousePosition (s);
- ms->updateHandle =
- compAddTimeout (
- md->opt[MP_DISPLAY_OPTION_MOUSE_POLL_INTERVAL].value.i / 2,
- md->opt[MP_DISPLAY_OPTION_MOUSE_POLL_INTERVAL].value.i,
- updatePosition, s);
- }
-
- return mc->id;
-}
-
-static void
-mousepollRemovePositionPolling (CompScreen *s,
- PositionPollingHandle id)
-{
- MOUSEPOLL_SCREEN (s);
-
- MousepollClient *mc = ms->clients;
-
- if (ms->clients && ms->clients->id == id)
- {
- ms->clients = ms->clients->next;
- if (ms->clients)
- ms->clients->prev = NULL;
-
- free (mc);
- return;
- }
-
- for (mc = ms->clients; mc; mc = mc->next)
- if (mc->id == id)
- {
- if (mc->next)
- mc->next->prev = mc->prev;
- if (mc->prev)
- mc->prev->next = mc->next;
- free (mc);
- return;
- }
-
- if (!ms->clients && ms->updateHandle)
- {
- compRemoveTimeout (ms->updateHandle);
- ms->updateHandle = 0;
- }
-}
-
-static void
-mousepollGetCurrentPosition (CompScreen *s,
- int *x,
- int *y)
-{
- MOUSEPOLL_SCREEN (s);
-
- if (!ms->clients)
- getMousePosition (s);
-
- if (x)
- *x = ms->posX;
- if (y)
- *y = ms->posY;
-}
-
-static const CompMetadataOptionInfo mousepollDisplayOptionInfo[] = {
- { "abi", "int", 0, 0, 0 },
- { "index", "int", 0, 0, 0 },
- { "mouse_poll_interval", "int", "<min>1</min><max>500</max><default>10</default>", 0, 0 }
-};
-
-static CompOption *
-mousepollGetDisplayOptions (CompPlugin *plugin,
- CompDisplay *display,
- int *count)
-{
- MOUSEPOLL_DISPLAY (display);
- *count = NUM_OPTIONS (md);
- return md->opt;
-}
-
-static Bool
-mousepollSetDisplayOption (CompPlugin *plugin,
- CompDisplay *display,
- const char *name,
- CompOptionValue *value)
-{
- CompOption *o;
- CompScreen *s;
- MousepollScreen *ms;
- int index;
- Bool status = FALSE;
- MOUSEPOLL_DISPLAY (display);
- o = compFindOption (md->opt, NUM_OPTIONS (md), name, &index);
- if (!o)
- return FALSE;
-
- switch (index) {
- case MP_DISPLAY_OPTION_ABI:
- case MP_DISPLAY_OPTION_INDEX:
- break;
- case MP_DISPLAY_OPTION_MOUSE_POLL_INTERVAL:
- status = compSetDisplayOption (display, o, value);
- for (s = display->screens; s; s = s->next)
- {
- ms = GET_MOUSEPOLL_SCREEN (s, md);
- if (ms->updateHandle)
- {
- compRemoveTimeout (ms->updateHandle);
- ms->updateHandle =
- compAddTimeout (
- md->opt[MP_DISPLAY_OPTION_MOUSE_POLL_INTERVAL].value.i
- / 2,
- md->opt[MP_DISPLAY_OPTION_MOUSE_POLL_INTERVAL].value.i,
- updatePosition, s);
- }
- }
- return status;
- break;
- default:
- return compSetDisplayOption (display, o, value);
- }
-
- return FALSE;
-}
-
-static MousePollFunc mousepollFunctions =
-{
- .addPositionPolling = mousepollAddPositionPolling,
- .removePositionPolling = mousepollRemovePositionPolling,
- .getCurrentPosition = mousepollGetCurrentPosition,
-};
-
-static Bool
-mousepollInitDisplay (CompPlugin *p,
- CompDisplay *d)
-{
- MousepollDisplay *md;
-
- if (!checkPluginABI ("core", CORE_ABIVERSION))
- return FALSE;
-
- md = malloc (sizeof (MousepollDisplay));
- if (!md)
- return FALSE;
- if (!compInitDisplayOptionsFromMetadata (d,
- &mousepollMetadata,
- mousepollDisplayOptionInfo,
- md->opt,
- MP_DISPLAY_OPTION_NUM))
- {
- free (md);
- return FALSE;
- }
-
- md->screenPrivateIndex = allocateScreenPrivateIndex (d);
- if (md->screenPrivateIndex < 0)
- {
- compFiniDisplayOptions (d, md->opt, MP_DISPLAY_OPTION_NUM);
- free (md);
- return FALSE;
- }
-
- md->opt[MP_DISPLAY_OPTION_ABI].value.i = MOUSEPOLL_ABIVERSION;
- md->opt[MP_DISPLAY_OPTION_INDEX].value.i = functionsPrivateIndex;
-
- d->base.privates[displayPrivateIndex].ptr = md;
- d->base.privates[functionsPrivateIndex].ptr = &mousepollFunctions;
- return TRUE;
-}
-
-static void
-mousepollFiniDisplay (CompPlugin *p,
- CompDisplay *d)
-{
- MOUSEPOLL_DISPLAY (d);
-
- compFiniDisplayOptions (d, md->opt, MP_DISPLAY_OPTION_NUM);
- free (md);
-}
-
-static Bool
-mousepollInitScreen (CompPlugin *p,
- CompScreen *s)
-{
- MousepollScreen *ms;
-
- MOUSEPOLL_DISPLAY (s->display);
-
- ms = malloc (sizeof (MousepollScreen));
- if (!ms)
- return FALSE;
-
- ms->posX = 0;
- ms->posY = 0;
-
- ms->clients = NULL;
- ms->freeId = 1;
-
- ms->updateHandle = 0;
-
- s->base.privates[md->screenPrivateIndex].ptr = ms;
- return TRUE;
-}
-
-static void
-mousepollFiniScreen (CompPlugin *p,
- CompScreen *s)
-{
- MOUSEPOLL_SCREEN (s);
-
- free (ms);
-}
-
-static CompBool
-mousepollInitObject (CompPlugin *p,
- CompObject *o)
-{
- static InitPluginObjectProc dispTab[] = {
- (InitPluginObjectProc) 0, /* InitCore */
- (InitPluginObjectProc) mousepollInitDisplay,
- (InitPluginObjectProc) mousepollInitScreen
- };
-
- RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o));
-}
-
-static void
-mousepollFiniObject (CompPlugin *p,
- CompObject *o)
-{
- static FiniPluginObjectProc dispTab[] = {
- (FiniPluginObjectProc) 0, /* FiniCore */
- (FiniPluginObjectProc) mousepollFiniDisplay,
- (FiniPluginObjectProc) mousepollFiniScreen
- };
-
- DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (p, o));
-}
-
-static Bool
-mousepollInit (CompPlugin *p)
-{
- if (!compInitPluginMetadataFromInfo (&mousepollMetadata,
- p->vTable->name,
- mousepollDisplayOptionInfo,
- MP_DISPLAY_OPTION_NUM,
- NULL, 0))
- return FALSE;
-
- displayPrivateIndex = allocateDisplayPrivateIndex ();
- if (displayPrivateIndex < 0)
- {
- compFiniMetadata (&mousepollMetadata);
- return FALSE;
- }
-
- functionsPrivateIndex = allocateDisplayPrivateIndex ();
- if (functionsPrivateIndex < 0)
- {
- freeDisplayPrivateIndex (displayPrivateIndex);
- compFiniMetadata (&mousepollMetadata);
- return FALSE;
- }
-
- compAddMetadataFromFile (&mousepollMetadata, p->vTable->name);
- return TRUE;
-}
-
-static CompOption *
-mousepollGetObjectOptions (CompPlugin *plugin,
- CompObject *object,
- int *count)
-{
- static GetPluginObjectOptionsProc dispTab[] = {
- (GetPluginObjectOptionsProc) 0, /* GetCoreOptions */
- (GetPluginObjectOptionsProc) mousepollGetDisplayOptions
- };
-
- RETURN_DISPATCH (object, dispTab, ARRAY_SIZE (dispTab),
- (void *) (*count = 0), (plugin, object, count));
-}
-
-static CompBool
-mousepollSetObjectOption (CompPlugin *plugin,
- CompObject *object,
- const char *name,
- CompOptionValue *value)
-{
- static SetPluginObjectOptionProc dispTab[] = {
- (SetPluginObjectOptionProc) 0, /* SetCoreOption */
- (SetPluginObjectOptionProc) mousepollSetDisplayOption
- };
-
- RETURN_DISPATCH (object, dispTab, ARRAY_SIZE (dispTab), FALSE,
- (plugin, object, name, value));
-}
-
-static void
-mousepollFini (CompPlugin *p)
-{
- freeDisplayPrivateIndex (displayPrivateIndex);
- freeDisplayPrivateIndex (functionsPrivateIndex);
- compFiniMetadata (&mousepollMetadata);
-}
-
-static CompMetadata *
-mousepollGetMetadata (CompPlugin *plugin)
-{
- return &mousepollMetadata;
-}
-
-CompPluginVTable mousepollVTable = {
- "mousepoll",
- mousepollGetMetadata,
- mousepollInit,
- mousepollFini,
- mousepollInitObject,
- mousepollFiniObject,
- mousepollGetObjectOptions,
- mousepollSetObjectOption
-};
-
-CompPluginVTable *
-getCompPluginInfo20070830 (void)
-{
- return &mousepollVTable;
-}
diff --git a/mousepoll.cpp b/mousepoll.cpp
new file mode 100644
index 0000000..ea9034a
--- /dev/null
+++ b/mousepoll.cpp
@@ -0,0 +1,261 @@
+/*
+ *
+ * Compiz mouse position polling plugin
+ *
+ * mousepoll.c
+ *
+ * Copyright : (C) 2008 by Dennis Kasprzyk
+ * E-mail : onestone@opencompositing.org
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include "private.h"
+
+COMPIZ_PLUGIN_20081216 (mousepoll, MousepollPluginVTable);
+
+bool
+MousepollScreen::getMousePosition ()
+{
+ Window root_return;
+ Window child_return;
+ int rootX, rootY;
+ int winX, winY;
+ int w = screen->width (), h = screen->height ();
+ unsigned int maskReturn;
+ bool status;
+
+ status = XQueryPointer (screen->dpy (), screen->root (),
+ &root_return, &child_return,
+ &rootX, &rootY, &winX, &winY, &maskReturn);
+
+ if (!status || rootX > w || rootY > h ||
+ screen->root () != root_return)
+ return false;
+
+ if ((rootX != posX || rootY != posY))
+ {
+ posX = rootX;
+ posY = rootY;
+ return true;
+ }
+ return false;
+}
+
+bool
+MousepollScreen::updatePosition ()
+{
+ if (pollers.empty ())
+ return false;
+
+ if (getMousePosition ())
+ {
+ std::list<MousePoller *>::iterator it;
+ for (it = pollers.begin (); it != pollers.end (); it++)
+ {
+ MousePoller *poller = *it;
+ poller->mPoint.setX(posX);
+ poller->mPoint.setY(posY);
+ poller->mCallback (posX, posY);
+ }
+ }
+
+ return true;
+}
+
+bool
+MousepollScreen::addTimer (MousePoller *poller)
+{
+ bool start = pollers.empty ();
+ std::list<MousePoller *>::iterator it;
+
+ it = std::find (pollers.begin (), pollers.end (), poller);
+
+ if (it != pollers.end ())
+ return false;
+
+ pollers.insert (it, poller);
+
+ if (start)
+ {
+ getMousePosition ();
+ timer.start ();
+ }
+
+ return true;
+}
+
+void
+MousepollScreen::removeTimer (MousePoller *poller)
+{
+ std::list<MousePoller *>::iterator it;
+
+ it = std::find (pollers.begin(), pollers.end (), poller);
+
+ if (it == pollers.end ())
+ return;
+
+ pollers.erase (it);
+
+ if (pollers.empty ())
+ {
+ timer.stop ();
+ }
+}
+
+void
+MousePoller::start ()
+{
+ MOUSEPOLL_SCREEN (screen);
+
+ if (!ms)
+ {
+ compLogMessage ("mousepoll",
+ CompLogLevelWarn,
+ "Plugin version mismatch, can't start mouse poller");
+
+ return;
+ }
+
+ ms->addTimer (this);
+
+ mActive = true;
+}
+
+void
+MousePoller::stop ()
+{
+ MOUSEPOLL_SCREEN (screen);
+
+ if (!ms)
+ {
+ compLogMessage ("mousepoll",
+ CompLogLevelWarn,
+ "Plugin version mismatch, can't start mouse poller");
+
+ return;
+ }
+
+ mActive = false;
+
+ ms->removeTimer (this);
+}
+
+CompPoint
+MousePoller::getCurrentPosition ()
+{
+ MOUSEPOLL_SCREEN (screen);
+
+ CompPoint p;
+
+ if (!ms)
+ {
+ compLogMessage ("mousepoll",
+ CompLogLevelWarn,
+ "Plugin version mismatch, can't start mouse poller");
+
+ p.setX (0);
+ p.setY (0);
+
+ return p;
+ }
+
+ ms->getMousePosition ();
+
+ p.setX (ms->posX);
+ p.setY (ms->posY);
+
+ return p;
+}
+
+CompPoint
+MousePoller::getPosition ()
+{
+ return mPoint;
+}
+
+MousePoller::MousePoller () :
+ mActive (false),
+ mPoint (0, 0)
+{
+}
+
+MousePoller::~MousePoller ()
+{
+ if (mActive)
+ stop ();
+}
+static const CompMetadata::OptionInfo mousepollOptionInfo[] = {
+ { "mouse_poll_interval", "int",
+ "<min>1</min><max>500</max>", 0, 0 }
+};
+
+CompOption::Vector &
+MousepollScreen::getOptions ()
+{
+ return opt;
+}
+
+bool
+MousepollScreen::setOption (const char *name,
+ CompOption::Value &value)
+{
+ CompOption *o;
+ bool status;
+ unsigned int index;
+
+ o = CompOption::findOption (opt, name, &index);
+ if (!o)
+ return false;
+
+ switch (index) {
+ case MP_OPTION_MOUSE_POLL_INTERVAL:
+ status = o->set (value);
+
+ if (timer.active ())
+ timer.start
+ (o->value ().i () / 2,
+ o->value ().i ());
+ return status;
+ default:
+ return CompOption::setOption (*o, value);
+ }
+
+ return false;
+}
+
+MousepollScreen::MousepollScreen (CompScreen *screen) :
+ PrivateHandler <MousepollScreen, CompScreen, COMPIZ_MOUSEPOLL_ABI> (screen),
+ opt (MP_OPTION_NUM),
+ posX (0),
+ posY (0)
+{
+ if (!mousepollVTable->getMetadata ()->initOptions (mousepollOptionInfo,
+ MP_OPTION_NUM, opt))
+ {
+ setFailed ();
+ return;
+ }
+}
+
+bool
+MousepollPluginVTable::init ()
+{
+ if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
+ return false;
+
+ getMetadata ()->addFromOptionInfo (mousepollOptionInfo, MP_OPTION_NUM);
+ getMetadata ()->addFromFile (name ());
+
+ return true;
+}
diff --git a/compiz-mousepoll.h b/mousepoll.h
index cf1b64b..ea47cf9 100644
--- a/compiz-mousepoll.h
+++ b/mousepoll.h
@@ -21,31 +21,39 @@
#ifndef _COMPIZ_MOUSEPOLL_H
#define _COMPIZ_MOUSEPOLL_H
-#define MOUSEPOLL_ABIVERSION 20080116
+#define COMPIZ_MOUSEPOLL_ABI 1
-typedef int PositionPollingHandle;
+class MousePoller
+{
+ public:
-typedef void (*PositionUpdateProc) (CompScreen *s,
- int x,
- int y);
+ typedef boost::function<void (int, int)> CallBack;
-typedef PositionPollingHandle
-(*AddPositionPollingProc) (CompScreen *s,
- PositionUpdateProc update);
+ MousePoller ();
+ ~MousePoller ();
-typedef void
-(*RemovePositionPollingProc) (CompScreen *s,
- PositionPollingHandle id);
+ void
+ setCallback (CallBack callback);
-typedef void
-(*GetCurrentPositionProc) (CompScreen *s,
- int *x,
- int *y);
+ void
+ start ();
-typedef struct _MousePollFunc {
- AddPositionPollingProc addPositionPolling;
- RemovePositionPollingProc removePositionPolling;
- GetCurrentPositionProc getCurrentPosition;
-} MousePollFunc;
+ void
+ stop ();
+
+ CompPoint
+ getPosition ();
+
+ static CompPoint
+ getCurrentPosition ();
+
+ private:
+
+ bool mActive;
+ CompPoint mPoint;
+ CallBack mCallback;
+
+ friend class MousepollScreen;
+};
#endif
diff --git a/mousepoll.xml.in b/mousepoll.xml.in
index 49070fd..c5fff21 100644
--- a/mousepoll.xml.in
+++ b/mousepoll.xml.in
@@ -4,9 +4,7 @@
<_short>Mouse position polling</_short>
<_long>Updates the mouse pointer position from the xserver</_long>
<category>Utility</category>
- <display>
- <option name="abi" type="int" read_only="true"/>
- <option name="index" type="int" read_only="true"/>
+ <screen>
<group>
<_short>Misc</_short>
<option type="int" name="mouse_poll_interval">
@@ -17,6 +15,6 @@
<max>500</max>
</option>
</group>
- </display>
+ </screen>
</plugin>
</compiz>
diff --git a/private.h b/private.h
new file mode 100644
index 0000000..b1eff46
--- /dev/null
+++ b/private.h
@@ -0,0 +1,85 @@
+/*
+ *
+ * Compiz mouse position polling plugin
+ *
+ * mousepoll.c
+ *
+ * Copyright : (C) 2008 by Dennis Kasprzyk
+ * E-mail : onestone@opencompositing.org
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <core/core.h>
+#include <core/privatehandler.h>
+#include <core/timer.h>
+
+#include "mousepoll.h"
+
+typedef enum _MousepollOptions
+{
+ MP_DISPLAY_OPTION_MOUSE_POLL_INTERVAL,
+ MP_DISPLAY_OPTION_NUM
+} MousepollDisplayOptions;
+
+#define MP_OPTION_MOUSE_POLL_INTERVAL 0
+#define MP_OPTION_NUM 1
+
+class MousepollScreen :
+ public PrivateHandler <MousepollScreen, CompScreen, COMPIZ_MOUSEPOLL_ABI>
+{
+ public:
+
+ CompOption::Vector opt;
+
+ MousepollScreen (CompScreen *screen);
+
+ std::list<MousePoller *> pollers;
+ CompTimer timer;
+
+ int posX;
+ int posY;
+
+ bool
+ updatePosition ();
+
+ bool
+ getMousePosition ();
+
+ bool
+ addTimer (MousePoller *poller);
+
+ void
+ removeTimer (MousePoller *poller);
+
+ CompOption::Vector & getOptions ();
+ bool setOption (const char *name, CompOption::Value &value);
+
+};
+
+#define MOUSEPOLL_SCREEN(s) \
+ MousepollScreen *ms = MousepollScreen::get (s)
+
+#define NUM_OPTIONS(s) (sizeof ((s)->opt) / sizeof (CompOption))
+
+class MousepollPluginVTable :
+ public CompPlugin::VTableForScreen<MousepollScreen>
+{
+ public:
+
+ bool init ();
+
+ PLUGIN_OPTION_HELPER (MousepollScreen);
+
+};
+