diff --git a/xdu.c b/xdu.c index 785cfa7..7412f60 100644 --- a/xdu.c +++ b/xdu.c @@ -38,8 +38,16 @@ * - 'worksforme' Makefile * - -Wall -Werror -Wextra -pedantic * + * changed mouse actions Wed Aug 15 2018 11:25:00 PM CEST + * Niclas Hofmann, niclas@molgen.mpg.de + * - middle mouse button: print path of node that had been clicked + * - right mouse button: reset (former middle button action) + * - 'worksforme' Makefile + * - -Wall -Werror -Wextra -pedantic + * */ +#define _GNU_SOURCE #include #include #include @@ -53,6 +61,8 @@ #define MAXPATH 4096 /* max total pathname length */ #define NCOLS 5 /* default number of columns in display */ +char* root_prefix = "[root]"; + /* What we IMPORT from xwin.c */ extern int xsetup(), xmainloop(), xdrawrect(), xrepaint(); @@ -215,7 +225,7 @@ int main(argc, argv) int argc; char **argv; { - top.name = strdup("[root]"); + top.name = root_prefix; top.size = -1; xsetup(&argc, argv); @@ -684,6 +694,27 @@ void press(int x, int y) } } +void printpath(int x, int y) +{ + struct node *np; + char* path; + char* tmp_path; + + np = findnode(&top, x, y); + if (np == NULL) + return; + asprintf(&path, "%s", np->name); + while(np->parent != NULL) { + tmp_path = path; + asprintf(&path, "%s/%s", np->parent->name, path); + np = np->parent; + free(tmp_path); + } + tmp_path = path + strlen(root_prefix); + printf("%s\n", tmp_path); + free(path); +} + void reset(void) { topp = ⊤ diff --git a/xwin.c b/xwin.c index 4654084..05d3e45 100644 --- a/xwin.c +++ b/xwin.c @@ -37,6 +37,7 @@ /* IMPORTS: routines that this module vectors out to */ extern int press(); +extern int printpath(); extern int reset(); extern int uponechild(); extern int downonechild(); @@ -123,6 +124,7 @@ static XrmOptionDescRec options[] = { /* action routines */ static void a_goto(); +static void a_printpath(); static void a_reset(); static void a_quit(); static void a_reorder(); @@ -138,6 +140,7 @@ static void a_removehelp(); static XtActionsRec actionsTable[] = { {"reset", a_reset}, + {"printpath", a_printpath}, {"goto", a_goto}, {"quit", a_quit}, {"reorder", a_reorder}, @@ -181,7 +184,8 @@ static char defaultTranslations[] = "\ 9: ncol(9)\n\ 0: ncol(10)\n\ : goto()\n\ -: reset()\n\ +: printpath()\n\ +: reset()\n\ "; #define UNUSED1(x) (void)(x) @@ -220,6 +224,16 @@ Cardinal *num_params; press(event->xbutton.x, event->xbutton.y); } +static void a_printpath(w, event, params, num_params) +Widget w; +XEvent *event; +String *params; +Cardinal *num_params; +{ + UNUSED(w, params, num_params); + printpath(event->xbutton.x, event->xbutton.y); +} + static void a_reset(w, event, params, num_params) Widget w; XEvent *event;