diff --git a/xdu.c b/xdu.c
index a45002e..7347dea 100644
--- a/xdu.c
+++ b/xdu.c
@@ -88,12 +88,12 @@ int ncols = NCOLS;
* internal routines
*/
// char *strdup();
-void addtree();
-void parse_file();
-void parse_entry();
+static void addtree();
+static void parse_file();
+static void parse_entry();
void dumptree();
-void clearrects();
-void sorttree();
+static void clearrects();
+static void sorttree();
/*
* order to sort paths by
@@ -139,7 +139,7 @@ long nnodes = 0;
/*
* create a new node with the given name and size info
*/
-struct node*
+static struct node*
makenode(char* name, long long size)
{
struct node* np;
@@ -157,7 +157,7 @@ makenode(char* name, long long size)
* Return the node (if any) which has a draw rectangle containing
* the given x,y point.
*/
-struct node*
+static struct node*
findnode(struct node* treep, int x, int y)
{
struct node* np;
@@ -188,7 +188,7 @@ findnode(struct node* treep, int x, int y)
/*
* return a count of the number of children of a given node
*/
-int numchildren(struct node* nodep)
+static int numchildren(struct node* nodep)
{
int n;
@@ -207,7 +207,7 @@ int numchildren(struct node* nodep)
* had their sizes initialized. [DPT911113]
* * * * This function is recursive * * *
*/
-long fix_tree(struct node* top)
+static long fix_tree(struct node* top)
{
struct node* nd;
@@ -264,8 +264,8 @@ int main(int argc, char** argv)
/*
* dumptree(&top,0);
*/
- if (order != ORD_DEFAULT)
- sorttree(&top, order);
+
+ sorttree(&top, order);
topp = ⊤
/*
@@ -278,7 +278,7 @@ int main(int argc, char** argv)
exit(0);
}
-void parse_file(char* filename)
+static void parse_file(char* filename)
{
char buf[4096];
char name[4096];
@@ -317,7 +317,7 @@ void parse_file(char* filename)
/*
* bust up a path string and link it into the tree
*/
-void parse_entry(char* name, long long size)
+static void parse_entry(char* name, long long size)
{
char* path[MAXDEPTH]; /* break up path into this list */
char buf[MAXNAME]; /* temp space for path element
@@ -369,7 +369,7 @@ void parse_entry(char* name, long long size)
* 0 if it is a toss up.
* 1 if it should go after.
*/
-int compare(struct node* n1, struct node* n2, int order)
+static int compare(struct node* n1, struct node* n2, int order)
{
switch (order) {
case ORD_SIZE:
@@ -421,59 +421,10 @@ int compare(struct node* n1, struct node* n2, int order)
return 0;
}
-void insertchild(struct node* nodep, struct node* childp, int order)
-{
- struct node *np,
- *np1;
-
- if (nodep == NODE_NULL || childp == NODE_NULL)
- return;
- if (childp->peer != NODE_NULL) {
- fprintf(stderr, "xdu: can't insert child with peers\n");
- return;
- }
-
- childp->parent = nodep;
- if (nodep->child == NODE_NULL) {
- /*
- * no children, order doesn't matter
- */
- nodep->child = childp;
- return;
- }
- /*
- * nodep has at least one child already
- */
- if (compare(childp, nodep->child, order) < 0) {
- /*
- * new first child
- */
- childp->peer = nodep->child;
- nodep->child = childp;
- return;
- }
- np1 = nodep->child;
- for (np = np1->peer; np != NODE_NULL; np = np->peer) {
- if (compare(childp, np, order) < 0) {
- /*
- * insert between np1 and np
- */
- childp->peer = np;
- np1->peer = childp;
- return;
- }
- np1 = np;
- }
- /*
- * at end, link new child on
- */
- np1->peer = childp;
-}
-
/*
* add path as a child of top - recursively
*/
-void addtree(struct node* top, char* path[], long long size)
+static void addtree(struct node* top, char* path[], long long size)
{
struct node* np;
@@ -507,7 +458,9 @@ void addtree(struct node* top, char* path[], long long size)
* no child matched, add a new child
*/
np = makenode(path[0], -1);
- insertchild(top, np, order);
+ np->parent = top;
+ np->peer = top->child;
+ top->child=np;
if (path[1] == NULL) {
/*
@@ -540,7 +493,7 @@ void dumptree(struct node* np, int level)
}
}
-void sorttree(struct node* np, int order)
+static void sorttree(struct node* np, int order)
{
struct node* subnp;
struct node *np0,
@@ -588,7 +541,7 @@ void sorttree(struct node* np, int order)
* Draws all children of a node within the given rectangle.
* Recurses on children.
*/
-void drawchildren(struct node* nodep, struct rect rect)
+static void drawchildren(struct node* nodep, struct rect rect)
{
long long totalsize;
int totalheight;
@@ -665,7 +618,7 @@ void drawchildren(struct node* nodep, struct rect rect)
* Draws a node in the given rectangle, and all of its children
* to the "right" of the given rectangle.
*/
-void drawnode(struct node* nodep, struct rect rect)
+static void drawnode(struct node* nodep, struct rect rect)
{
struct rect subrect;
@@ -698,7 +651,7 @@ void drawnode(struct node* nodep, struct rect rect)
* clear the rectangle information of a given node
* and all of its decendents
*/
-void clearrects(struct node* nodep)
+static void clearrects(struct node* nodep)
{
struct node* np;
@@ -718,7 +671,7 @@ void clearrects(struct node* nodep)
}
}
-void pwd(void)
+static void pwd(void)
{
struct node* np;
struct node* stack[MAXDEPTH];
@@ -749,7 +702,7 @@ void pwd(void)
}
#ifdef NEED_STRDUP
-char* strdup(char* s)
+static char* strdup(char* s)
{
int n;
char* cp;
@@ -921,7 +874,7 @@ XDU Version %s - Keyboard Commands\n\
XDU_VERSION);
}
-void fprintpsstart(FILE* fp)
+static void fprintpsstart(FILE* fp)
{
fprintf(fp,
"%%!\n"
@@ -948,7 +901,7 @@ void fprintpsstart(FILE* fp)
"/xduorigctm matrix currentmatrix def\n\n");
}
-void fprintpsend(FILE* fp)
+static void fprintpsend(FILE* fp)
{
fprintf(fp,
"grestore\n"
@@ -961,7 +914,7 @@ void fprintpsend(FILE* fp)
"%%%%EOF\n");
}
-void fprintpsbox(FILE* fp, int x1, int y1, int x2, int y2)
+static void fprintpsbox(FILE* fp, int x1, int y1, int x2, int y2)
{
fprintf(fp,
"%%BOX\n"
@@ -979,7 +932,7 @@ void fprintpsbox(FILE* fp, int x1, int y1, int x2, int y2)
x1, y1, x2 + x1, y1, x2 + x1, y2 + y1, x1, y2 + y1);
}
-void fprintpstext(FILE* fp, int x, int y, char* s)
+static void fprintpstext(FILE* fp, int x, int y, char* s)
{
fprintf(fp,
"%%TEXT\n"
@@ -992,7 +945,7 @@ void fprintpstext(FILE* fp, int x, int y, char* s)
x, y, s);
}
-void savepschildren(FILE* fp, struct node* nodep, struct rect rect, int showsize)
+static void savepschildren(FILE* fp, struct node* nodep, struct rect rect, int showsize)
{
long long size, totalsize;
int totalheight,
@@ -1063,7 +1016,7 @@ void savepschildren(FILE* fp, struct node* nodep, struct rect rect, int showsize
}
}
-void savepsnode(FILE* fp, struct node* nodep, struct rect rect, int showsize)
+static void savepsnode(FILE* fp, struct node* nodep, struct rect rect, int showsize)
{
struct rect subrect;
char label[1024],
@@ -1128,24 +1081,24 @@ void savetops(char* fname, int showsize)
}
}
-void fprintsvgstart(FILE* fp, int width, int height)
+static void fprintsvgstart(FILE* fp, int width, int height)
{
fprintf(fp, "\n");
}
-void fprintsvgnode(FILE* fp, struct rect rect)
+static void fprintsvgnode(FILE* fp, struct rect rect)
{
fprintf(fp,
" \n",
rect.left, rect.top, rect.width, rect.height);
}
-void fprintsvgnodetext(FILE* fp, int x, int y, long long size, char* name, int showsize)
+static void fprintsvgnodetext(FILE* fp, int x, int y, long long size, char* name, int showsize)
{
char buffer[1024],
*text="n/a";
@@ -1182,7 +1135,7 @@ void fprintsvgnodetext(FILE* fp, int x, int y, long long size, char* name, int s
x, y, text);
}
-void savesvgnode(FILE* fp, struct node* nodep, int showsize, int depth)
+static void savesvgnode(FILE* fp, struct node* nodep, int showsize, int depth)
{
struct node* np;
diff --git a/xwin.c b/xwin.c
index a2a08bc..5f9751f 100644
--- a/xwin.c
+++ b/xwin.c
@@ -35,8 +35,6 @@
#include /* for exit() */
#endif
-#include
-
/*
* IMPORTS: routines that this module vectors out to
*/
@@ -61,7 +59,6 @@ extern int xsetup();
extern int xmainloop();
extern void xclear();
extern void xrepaint();
-extern void xrepaint_noclear();
extern void xdrawrect();
/*
@@ -69,11 +66,6 @@ extern void xdrawrect();
*/
static void help_popup();
static void help_popdown();
-static struct timeval last_repaint;
-static long int timediff(struct timeval* t1, struct timeval* t2)
-{
- return 1000000 * (t2->tv_sec - t1->tv_sec) + t2->tv_usec - t1->tv_usec;
-}
static String fallback_resources[] = {
"*window.width: 600",
@@ -340,26 +332,7 @@ a_removehelp(Widget w, XEvent* event, String* params, Cardinal* num_params)
/*
* callback routines
*/
-
-static void
-c_resize(Widget w, XtPointer data, XEvent* event, Boolean* continue_to_dispatch)
-{
- UNUSED(w, data, event, continue_to_dispatch);
- /*
- * printf("Resize\n");
- */
- long int diff;
- struct timeval t;
-
- gettimeofday(&t, NULL);
- diff = timediff(&last_repaint, &t);
-
- if (diff < (long int)50000)
- return;
- xrepaint();
-
- gettimeofday(&last_repaint, NULL);
-}
+static void setRepaintWhenIdle();
static void
c_repaint(Widget w, XtPointer data, XEvent* event, Boolean* continue_to_dispatch)
@@ -368,15 +341,7 @@ c_repaint(Widget w, XtPointer data, XEvent* event, Boolean* continue_to_dispatch
/*
* printf("Expose\n");
*/
- long int diff;
- struct timeval t;
-
- gettimeofday(&t, NULL);
- diff = timediff(&last_repaint, &t);
-
- if (diff < (long int)50000)
- return;
- xrepaint_noclear();
+ setRepaintWhenIdle();
}
/*
@@ -388,6 +353,31 @@ static Visual* vis;
static Window win;
static GC gc;
static XtAppContext app_con;
+static int workerRegistered=0;
+static int last_repaint_width=-1;
+static int last_repaint_height=-1;
+
+Boolean doIdleRepaint(XtPointer data) {
+ (void)data;
+ XWindowAttributes xwa;
+
+ XGetWindowAttributes(dpy, win, &xwa);
+ if (xwa.width != last_repaint_width || xwa.height != last_repaint_height) {
+ XClearWindow(dpy, win);
+ }
+ repaint(xwa.width, xwa.height);
+ last_repaint_width=xwa.width;
+ last_repaint_height=xwa.height;
+ workerRegistered=0;
+ return True;
+}
+
+static void setRepaintWhenIdle() {
+ if (!workerRegistered) {
+ (void)XtAppAddWorkProc(app_con,doIdleRepaint,NULL);
+ workerRegistered=1;
+ }
+}
static void
a_savesvg(Widget w, XEvent* e, String* params, Cardinal* num_params)
@@ -465,7 +455,6 @@ int xsetup(int* argcp, char** argv)
* events
*/
XtAddEventHandler(w, ExposureMask, False, c_repaint, NULL);
- XtAddEventHandler(w, StructureNotifyMask, False, c_resize, NULL);
XtAugmentTranslations(w, trans_table);
XtRealizeWidget(toplevel);
@@ -508,14 +497,6 @@ void xrepaint()
repaint(xwa.width, xwa.height);
}
-void xrepaint_noclear()
-{
- XWindowAttributes xwa;
-
- XGetWindowAttributes(dpy, win, &xwa);
- repaint(xwa.width, xwa.height);
-}
-
void readable_float(float number, char* number_label)
{
char number_string[1024];