summaryrefslogtreecommitdiff
authorSam Spilsbury <smspillaz@gmail.com>2010-02-07 11:34:41 (GMT)
committer Sam Spilsbury <smspillaz@gmail.com>2010-02-07 11:34:41 (GMT)
commita8255c85207f5dd150162c0df6fe20bef3caee6c (patch) (side-by-side diff)
tree5a4eb72b7e932a90dfb96eb79376cdc5762bdf05
parenta89f2bb3876f5afaaa5e9b2614263439b56f1c19 (diff)
downloadgroup-a8255c85207f5dd150162c0df6fe20bef3caee6c.tar.gz
group-a8255c85207f5dd150162c0df6fe20bef3caee6c.tar.bz2
Cleanup and fix crashes
-rw-r--r--src/cairo.cpp40
-rw-r--r--src/group.cpp3
-rw-r--r--src/group.h7
-rw-r--r--src/init.cpp12
-rw-r--r--src/window.cpp2
5 files changed, 46 insertions, 18 deletions
diff --git a/src/cairo.cpp b/src/cairo.cpp
index 8666adf..7109071 100644
--- a/src/cairo.cpp
+++ b/src/cairo.cpp
@@ -40,7 +40,7 @@ TextLayer::~TextLayer ()
* groupRebuildCairoLayer
*
*/
-void
+bool
CairoLayer::rebuild (int width,
int height)
{
@@ -49,7 +49,7 @@ CairoLayer::rebuild (int width,
texture.clear ();
- reinit (width, height);
+ return reinit (width, height);
}
/*
@@ -83,22 +83,33 @@ void
CairoHelper::destroy ()
{
if (cairo)
+ {
cairo_destroy (cairo);
+ cairo = NULL;
+ }
if (surface)
+ {
cairo_surface_destroy (surface);
+ surface = NULL;
+ }
if (buffer)
- free (buffer);
+ {
+ delete[] buffer;
+ buffer = NULL;
+ }
}
bool
CairoHelper::init (int width, int height)
{
- buffer = (unsigned char *)
- calloc (4 * width * height, sizeof (unsigned char));
- if (!buffer)
+ try
+ {
+ buffer = new unsigned char[4 * width * height];
+ }
+ catch (std::bad_alloc)
{
compLogMessage ("group", CompLogLevelError,
"Failed to allocate cairo layer buffer.");
@@ -113,7 +124,10 @@ CairoHelper::init (int width, int height)
{
compLogMessage ("group", CompLogLevelError,
"Failed to create cairo layer surface.");
- free (buffer);
+ delete[] buffer;
+ buffer = NULL;
+ cairo_surface_destroy (surface);
+ surface = NULL;
return false;
}
@@ -122,8 +136,12 @@ CairoHelper::init (int width, int height)
{
compLogMessage ("group", CompLogLevelError,
"Failed to create cairo layer context.");
- free (buffer);
+ delete [] buffer;
+ buffer = NULL;
cairo_surface_destroy (surface);
+ surface = NULL;
+ cairo_destroy (cairo);
+ cairo = NULL;
return false;
}
@@ -190,7 +208,8 @@ CairoLayer::renderTopTabHighlight (TabBar *tb)
height = tb->topTab->region.boundingRect ().y2 () -
tb->topTab->region.boundingRect ().y1 ();
- rebuild (width, height);
+ if (!rebuild (width, height))
+ return;
cairo_t *&cr = cairo;
@@ -248,7 +267,8 @@ CairoLayer::renderTabBarBackground (TabBar *tb)
if (radius > width / 2)
radius = width / 2;
- rebuild (width, height);
+ if (!rebuild (width, height))
+ return;
cr = cairo;
diff --git a/src/group.cpp b/src/group.cpp
index c38b121..c7c9d63 100644
--- a/src/group.cpp
+++ b/src/group.cpp
@@ -199,7 +199,8 @@ Group::destroy (bool immediate)
gw->window->updateWindowOutputExtents ();
gw->updateProperty ();
- if (gs->optionGetAutotabCreate () && gw->isGroupable ())
+ if (gs->optionGetAutotabCreate () && gw->isGroupable () &&
+ !immediate)
{
Selection sel;
Group *group;
diff --git a/src/group.h b/src/group.h
index d42c232..7ca6ff1 100644
--- a/src/group.h
+++ b/src/group.h
@@ -78,9 +78,10 @@
#define PREV_TOP_TAB(g) ((g)->tabBar->prevTopTab->window)
#define NEXT_TOP_TAB(g) ((g)->tabBar->nextTopTab->window)
-#define HAS_TOP_WIN(group) (((group)->tabBar->topTab) && \
+#define HAS_TOP_WIN(group) (group->tabBar && ((group)->tabBar->topTab) && \
((group)->tabBar->topTab->window))
-#define HAS_PREV_TOP_WIN(group) (((group)->tabBar->prevTopTab) && \
+#define HAS_PREV_TOP_WIN(group) (group->tabBar && \
+ ((group)->tabBar->prevTopTab) && \
((group)->tabBar->prevTopTab->window))
#define IS_TOP_TAB(w, group) (HAS_TOP_WIN (group) && \
@@ -179,7 +180,7 @@ class CairoLayer :
void
renderTabBarBackground (TabBar *);
- void
+ bool
rebuild (int width,
int height);
diff --git a/src/init.cpp b/src/init.cpp
index 8d493c9..3bcfb64 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -313,15 +313,19 @@ GroupScreen::GroupScreen (CompScreen *screen) :
GroupScreen::~GroupScreen ()
{
- while (!groups.empty ())
+ std::list <Group *>::iterator it = groups.begin ();
+
+ while (it != groups.end ())
{
- Group *group = groups.back ();
+ Group *group = *it;
+
+ it++;
group->destroy (true);
}
- /*if (grabIndex)
- grabScreen (ScreenGrabNone);*/
+ if (grabIndex)
+ grabScreen (ScreenGrabNone);
if (dragHoverTimeoutHandle.active ())
dragHoverTimeoutHandle.stop ();
diff --git a/src/window.cpp b/src/window.cpp
index f754d48..46a79cf 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -55,6 +55,7 @@ GroupWindow::checkProperty (long int &id,
if (type == XA_CARDINAL && fmt == 32 && nitems == 5)
{
id = data[0];
+
tabbed = (bool) data[1];
color[0] = (GLushort) data[2];
color[1] = (GLushort) data[3];
@@ -75,6 +76,7 @@ GroupWindow::checkProperty (long int &id,
*
* On color change / group change / tabbing - update the X Window property
*
+ * FIXME: broken
*/
void
GroupWindow::updateProperty ()