summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher James Halse Rogers <chris@Burninator.(none)>2007-06-22 23:04:06 +1000
committerChristopher James Halse Rogers <chris@Burninator.(none)>2007-06-22 23:04:06 +1000
commit45cb5578fd2a5b2df6cdec8c84050329b64ed624 (patch)
tree1e518ae01b973d523a36efa4f127d75cc170a344
parent90fad7a46334e3240b932a4f762bfba9f11d1ec3 (diff)
downloadradial-switcher-45cb5578fd2a5b2df6cdec8c84050329b64ed624.tar.gz
radial-switcher-45cb5578fd2a5b2df6cdec8c84050329b64ed624.tar.bz2
Add some comments, re-indent Cairo setup function, add a WindowTree constructor
-rw-r--r--radial-switcher.c101
1 files changed, 68 insertions, 33 deletions
diff --git a/radial-switcher.c b/radial-switcher.c
index dc8b62e..622c5aa 100644
--- a/radial-switcher.c
+++ b/radial-switcher.c
@@ -69,6 +69,20 @@ typedef Bool (*WindowCmpProc)(CompWindow *a, CompWindow *b);
typedef Bool (*WindowFilterProc)(CompWindow *a);
/**
+ * WindowList constructor
+**/
+static WindowList *
+newWindowList (void)
+{
+ WindowList *ret;
+ ret = malloc (sizeof(WindowList));
+ ret.nWindows = 0;
+ ret.windowsSize = 32;
+ ret.windows = malloc (sizeof(CompWindow *) * 32);
+ return ret;
+}
+
+/**
* Add a window to the window list, reallocing if necessary
* @param l: @WindowList to add the window to.
* @param w: @CompWindow to add to the list
@@ -93,14 +107,17 @@ addWindowToList (WindowList *l,
return TRUE;
}
-static WindowList *
-createWindowList (void)
+/**
+ * WindowTree constructor
+**/
+static WindowTreeNode *
+newWindowTreeNode (void)
{
- WindowList *ret;
- ret = malloc (sizeof(WindowList));
- ret.nWindows = 0;
- ret.windowsSize = minSize;
- ret.windows = malloc (sizeof(CompWindow *) * minSize);
+ WindowTreeNode *ret;
+ ret = malloc (sizeof(WindowTreeNode));
+ ret.windows = newWindowList();
+ ret.childrenSize = 4;
+ ret.children = malloc (sizeof (WindowTreeNode *) * 4);
return ret;
}
@@ -121,17 +138,28 @@ createWindowTree (WindowList *windows,
CompWindow *w;
WindowTreeNode *root;
- root = malloc (sizeof(WindowTreeNode));
- root.windows = createWindowList();
+ root = newWindowTreeNode();
/* XXX: Most naieve possible algorithm! */
for (int i = 0; i < windows->nWindows; ++i)
{
- for (int j = 0; j < windows->nWindows; ++j)
+ if (!addWindowToTree (root, windows->w[i], isSameGroup))
{
- if (isSameGroup (windows->w[i], windows->w[j]))
+ destroyWindowTree(root);
+ return FALSE;
}
+ }
+ return TRUE;
}
+/**
+ * Add a window to the window tree
+ * @param node: The @WindowTreeNode to add the window to
+ * @param w: The window to add to the tree
+ * @param isSameGroup: Comparison function to determine whether w should be
+ * a child of an existing window.
+ *
+ * @return: True on success
+**/
static Bool
addWindowToTree (WindowTreeNode *node,
CompWindow *w,
@@ -140,7 +168,11 @@ addWindowToTree (WindowTreeNode *node,
for (int i = 0; i < node->windows->nWindows; ++i)
{
if (isSameGroup (node->windows->w[i], w))
+ {
+ if (!node->children[i])
+ node->children[i] = newWindowTreeNode();
return addWindowToTree (node->children[i], w, isSameGroup);
+ }
}
if (node->childrenSize <= node->windows->nWindows)
node->children = realloc (node->children,
@@ -150,39 +182,42 @@ addWindowToTree (WindowTreeNode *node,
return FALSE;
node->childrenSize += 32;
- return addWindowToList (node->windows, w)
+ return addWindowToList (node->windows, w);
}
-static void radialSetupCairoContext(CompScreen *s, WallCairoContext *context)
+static void
+radialSetupCairoContext(CompScreen *s, RadialCairoContext *context)
{
- XRenderPictFormat * format;
- Screen * screen;
+ XRenderPictFormat * format;
+ Screen * screen;
- screen = ScreenOfDisplay(s->display->display, s->screenNum);
+ screen = ScreenOfDisplay(s->display->display, s->screenNum);
- int width, height;
- width = context->width;
- height = context->height;
+ int width, height;
+ width = context->width;
+ height = context->height;
- initTexture(s, &context->texture);
+ initTexture(s, &context->texture);
- format = XRenderFindStandardFormat(s->display->display, PictStandardARGB32);
+ format = XRenderFindStandardFormat(s->display->display, PictStandardARGB32);
- context->pixmap = XCreatePixmap(s->display->display, s->root, width, height, 32);
+ context->pixmap = XCreatePixmap(s->display->display, s->root,
+ width, height, 32);
- if (!bindPixmapToTexture(s, &context->texture, context->pixmap, width, height, 32))
- compLogMessage (s->display, "wall", CompLogLevelError,
- "Couldn't create cairo context for switcher");
+ if (!bindPixmapToTexture(s, &context->texture, context->pixmap,
+ width, height, 32))
+ compLogMessage (s->display, "radial-switcher", CompLogLevelError,
+ "Couldn't create cairo context for switcher");
- context->surface = cairo_xlib_surface_create_with_xrender_format(s->display->display, context->pixmap, screen, format, width, height);
- context->cr = cairo_create(context->surface);
+ context->surface = cairo_xlib_surface_create_with_xrender_format(s->display->display, context->pixmap, screen, format, width, height);
+ context->cr = cairo_create(context->surface);
- cairo_t *cr = context->cr;
- cairo_save(cr);
- cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
- cairo_paint(cr);
- cairo_restore(cr);
- cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
+ cairo_t *cr = context->cr;
+ cairo_save(cr);
+ cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
+ cairo_paint(cr);
+ cairo_restore(cr);
+ cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
}
/*