summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/core/rect.h2
-rw-r--r--include/core/region.h66
-rw-r--r--src/Makefile.am1
-rw-r--r--src/privateregion.h19
-rw-r--r--src/rect.cpp6
-rw-r--r--src/region.cpp339
6 files changed, 429 insertions, 4 deletions
diff --git a/include/core/rect.h b/include/core/rect.h
index c31eb92..43399ab 100644
--- a/include/core/rect.h
+++ b/include/core/rect.h
@@ -18,7 +18,7 @@ class CompRect {
unsigned int width () const;
unsigned int height () const;
- Region region ();
+ const Region region () const;
void setGeometry (int, int, int, int);
diff --git a/include/core/region.h b/include/core/region.h
new file mode 100644
index 0000000..918d231
--- /dev/null
+++ b/include/core/region.h
@@ -0,0 +1,66 @@
+#ifndef _COMPREGION_H
+#define _COMPREGION_H
+
+#include <X11/Xutil.h>
+#include <X11/Xregion.h>
+
+#include <core/rect.h>
+#include <core/point.h>
+
+class PrivateRegion;
+
+class CompRegion {
+ public:
+ CompRegion ();
+ CompRegion (const CompRegion &);
+ CompRegion (int x, int y, int w, int h);
+ CompRegion (const CompRect &);
+ ~CompRegion ();
+
+ CompRect boundingRect () const;
+
+ bool isEmpty () const;
+ int numRects () const;
+ CompRect::vector rects () const;
+ const Region handle () const;
+
+ bool contains (const CompPoint &) const;
+ bool contains (const CompRect &) const;
+
+ CompRegion intersected (const CompRegion &) const;
+ CompRegion intersected (const CompRect &) const;
+ bool intersects (const CompRegion &) const;
+ bool intersects (const CompRect &) const;
+ CompRegion subtracted (const CompRegion &) const;
+ void translate (int, int);
+ void translate (const CompPoint &);
+ CompRegion translated (int, int) const;
+ CompRegion translated (const CompPoint &) const;
+ CompRegion united (const CompRegion &) const;
+ CompRegion united (const CompRect &) const;
+ CompRegion xored (const CompRegion &) const;
+
+ bool operator== (const CompRegion &) const;
+ bool operator!= (const CompRegion &) const;
+ const CompRegion operator& (const CompRegion &) const;
+ const CompRegion operator& (const CompRect &) const;
+ CompRegion & operator&= (const CompRegion &);
+ CompRegion & operator&= (const CompRect &);
+ const CompRegion operator+ (const CompRegion &) const;
+ const CompRegion operator+ (const CompRect &) const;
+ CompRegion & operator+= (const CompRegion &);
+ CompRegion & operator+= (const CompRect &);
+ const CompRegion operator- (const CompRegion &) const;
+ CompRegion & operator-= (const CompRegion &);
+ CompRegion & operator= (const CompRegion &);
+
+ const CompRegion operator^ (const CompRegion &) const;
+ CompRegion & operator^= (const CompRegion &);
+ const CompRegion operator| (const CompRegion &) const;
+ CompRegion & operator|= (const CompRegion &);
+
+ private:
+ PrivateRegion *priv;
+};
+
+#endif \ No newline at end of file
diff --git a/src/Makefile.am b/src/Makefile.am
index 1bcfe44..e585586 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,6 +12,7 @@ bin_PROGRAMS = compiz
compiz_LDADD = @COMPIZ_LIBS@ @GL_LIBS@ -lm
compiz_LDFLAGS = -export-dynamic
compiz_SOURCES = \
+ region.cpp \
atoms.cpp \
timer.cpp \
main.cpp \
diff --git a/src/privateregion.h b/src/privateregion.h
new file mode 100644
index 0000000..f511d6e
--- /dev/null
+++ b/src/privateregion.h
@@ -0,0 +1,19 @@
+#ifndef _PRIVATEREGION_H
+#define _PRIVATEREGION_H
+
+#include <core/rect.h>
+#include <core/region.h>
+
+class PrivateRegion {
+ public:
+ PrivateRegion ();
+ ~PrivateRegion ();
+
+ void makeReal ();
+
+ public:
+ Region region;
+ REGION box;
+};
+
+#endif
diff --git a/src/rect.cpp b/src/rect.cpp
index 1b391ce..209e14f 100644
--- a/src/rect.cpp
+++ b/src/rect.cpp
@@ -27,10 +27,10 @@ CompRect::CompRect (const CompRect& r)
mRegion.rects = &mRegion.extents;
}
-Region
-CompRect::region ()
+const Region
+CompRect::region () const
{
- return &mRegion;
+ return const_cast<const Region> (&mRegion);
}
void
diff --git a/src/region.cpp b/src/region.cpp
new file mode 100644
index 0000000..350aeb6
--- /dev/null
+++ b/src/region.cpp
@@ -0,0 +1,339 @@
+#include <stdio.h>
+
+#include <X11/Xlib-xcb.h>
+#include <X11/Xutil.h>
+#include <X11/Xregion.h>
+
+#include <core/core.h>
+
+#include "privateregion.h"
+
+CompRegion::CompRegion ()
+{
+ priv = new PrivateRegion ();
+}
+
+CompRegion::CompRegion (const CompRegion &c)
+{
+ priv = new PrivateRegion ();
+ priv->box = c.priv->box;
+ if (priv->box.rects)
+ priv->box.rects = &priv->box.extents;
+ if (c.priv->region)
+ {
+ priv->region = XCreateRegion ();
+ XUnionRegion (&emptyRegion, c.priv->region, priv->region);
+ }
+}
+
+CompRegion::CompRegion ( int x, int y, int w, int h)
+{
+ priv = new PrivateRegion ();
+ priv->box.extents = CompRect (x, x + w, y, y + h).region ()->extents;
+ priv->box.numRects = 1;
+ priv->box.rects = &priv->box.extents;
+}
+
+CompRegion::CompRegion (const CompRect &r)
+{
+ priv = new PrivateRegion ();
+ priv->box.extents = r.region ()->extents;
+ priv->box.numRects = 1;
+ priv->box.rects = &priv->box.extents;
+}
+
+CompRegion::~CompRegion ()
+{
+ delete priv;
+}
+
+const Region
+CompRegion::handle () const
+{
+ return (priv->region)? priv->region : &priv->box;
+}
+
+CompRegion &
+CompRegion::operator= (const CompRegion &c)
+{
+ priv->box = c.priv->box;
+ if (priv->box.rects)
+ priv->box.rects = &priv->box.extents;
+ if (c.priv->region)
+ {
+ if (!priv->region)
+ priv->region = XCreateRegion ();
+ XUnionRegion (&emptyRegion, c.priv->region, priv->region);
+ }
+ return *this;
+}
+
+bool
+CompRegion::operator== (const CompRegion &c) const
+{
+ return XEqualRegion(handle (), c.handle ());
+}
+
+bool
+CompRegion::operator!= (const CompRegion &c) const
+{
+ return *this == c;
+}
+
+CompRect
+CompRegion::boundingRect () const
+{
+ BOX b = handle ()->extents;
+ return CompRect (b.x1, b.x2, b.y1, b.y2);
+}
+
+bool
+CompRegion::contains (const CompPoint &p) const
+{
+ return XPointInRegion (handle (), p.x (), p.y ());
+}
+
+bool
+CompRegion::contains (const CompRect &r) const
+{
+ return XRectInRegion (handle (), r.x (), r.y (), r.width (), r.height ())
+ != RectangleOut;
+}
+
+CompRegion
+CompRegion::intersected (const CompRegion &r) const
+{
+ CompRegion reg (r);
+ reg.priv->makeReal ();
+ XIntersectRegion (reg.handle (), handle (), reg.handle ());
+ return reg;
+}
+
+CompRegion
+CompRegion::intersected (const CompRect &r) const
+{
+ CompRegion reg (r);
+ reg.priv->makeReal ();
+ XIntersectRegion (reg.handle (), handle (), reg.handle ());
+ return reg;
+}
+
+bool
+CompRegion::intersects (const CompRegion &r) const
+{
+ return !intersected (r).isEmpty ();
+}
+
+bool
+CompRegion::intersects (const CompRect &r) const
+{
+ return !intersected (r).isEmpty ();
+}
+
+bool
+CompRegion::isEmpty () const
+{
+ return XEmptyRegion (handle ());
+}
+
+int
+CompRegion::numRects () const
+{
+ return handle ()->numRects;
+}
+
+CompRect::vector
+CompRegion::rects () const
+{
+ CompRect::vector rv;
+ if (!numRects ())
+ return rv;
+ if (!priv->region)
+ {
+ rv.push_back (CompRect (priv->box.extents.x1, priv->box.extents.x2,
+ priv->box.extents.y1, priv->box.extents.y2));
+ return rv;
+ }
+
+ BOX b;
+ for (int i = 0; i < priv->region->numRects; i++)
+ {
+ b = priv->region->rects[i];
+ rv.push_back (CompRect (b.x1, b.x2, b.y1, b.y2));
+ }
+ return rv;
+}
+
+CompRegion
+CompRegion::subtracted (const CompRegion &r) const
+{
+ CompRegion rv;
+ rv.priv->makeReal ();
+ XSubtractRegion (handle (), r.handle (), rv.handle ());
+ return rv;
+}
+
+void
+CompRegion::translate (int dx, int dy)
+{
+ priv->makeReal ();
+ XOffsetRegion (handle (), dx, dy);
+}
+
+void
+CompRegion::translate (const CompPoint &p)
+{
+ translate (p.x (), p.y ());
+}
+
+CompRegion
+CompRegion::translated (int dx, int dy) const
+{
+ CompRegion rv (*this);
+ rv.translate (dx, dy);
+ return rv;
+}
+
+CompRegion
+CompRegion::translated (const CompPoint &p) const
+{
+ CompRegion rv (*this);
+ rv.translate (p);
+ return rv;
+}
+
+CompRegion
+CompRegion::united (const CompRegion &r) const
+{
+ CompRegion rv;
+ rv.priv->makeReal ();
+ XUnionRegion (handle (), r.handle (), rv.handle ());
+ return rv;
+}
+
+CompRegion
+CompRegion::united (const CompRect &r) const
+{
+ CompRegion rv;
+ rv.priv->makeReal ();
+ XUnionRegion (handle (), r.region (), rv.handle ());
+ return rv;
+}
+
+CompRegion
+CompRegion::xored (const CompRegion &r) const
+{
+ CompRegion rv;
+ rv.priv->makeReal ();
+ XXorRegion (handle (), r.handle (), rv.handle ());
+ return rv;
+}
+
+
+const CompRegion
+CompRegion::operator& (const CompRegion &r) const
+{
+ return intersected (r);
+}
+
+const CompRegion
+CompRegion::operator& (const CompRect &r) const
+{
+ return intersected (r);
+}
+
+CompRegion &
+CompRegion::operator&= (const CompRegion &r)
+{
+ return *this = *this & r;
+}
+
+CompRegion &
+CompRegion::operator&= (const CompRect &r)
+{
+ return *this = *this & r;
+}
+
+const CompRegion
+CompRegion::operator+ (const CompRegion &r) const
+{
+ return united (r);
+}
+
+const CompRegion
+CompRegion::operator+ (const CompRect &r) const
+{
+ return united (r);
+}
+
+CompRegion &
+CompRegion::operator+= (const CompRegion &r)
+{
+ return *this = *this + r;
+}
+
+CompRegion &
+CompRegion::operator+= (const CompRect &r)
+{
+ return *this = *this + r;
+}
+
+const CompRegion
+CompRegion::operator- (const CompRegion &r) const
+{
+ return subtracted (r);
+}
+
+CompRegion &
+CompRegion::operator-= (const CompRegion &r)
+{
+ return *this = *this - r;
+}
+
+const CompRegion
+CompRegion::operator^ (const CompRegion &r) const
+{
+ return xored (r);
+}
+
+CompRegion &
+CompRegion::operator^= (const CompRegion &r)
+{
+ return *this = *this ^ r;
+}
+
+const CompRegion
+CompRegion::operator| (const CompRegion &r) const
+{
+ united (r);
+}
+
+CompRegion &
+CompRegion::operator|= (const CompRegion &r)
+{
+ return *this = *this | r;
+}
+
+
+PrivateRegion::PrivateRegion ()
+{
+ region = NULL;
+ box = emptyRegion;
+}
+
+PrivateRegion::~PrivateRegion ()
+{
+ if (region)
+ XDestroyRegion (region);
+}
+
+void
+PrivateRegion::makeReal ()
+{
+ if (region)
+ return;
+ region = XCreateRegion ();
+ if (box.numRects)
+ XUnionRegion (&emptyRegion, &box, region);
+}
+