From a3741201eeaed08b857fb502d29bb1feb4132656 Mon Sep 17 00:00:00 2001 From: Niclas Hofmann Date: Wed, 15 Aug 2018 11:29:35 +0200 Subject: [PATCH] Add mouse feature to print path of node --- xdu.c | 25 +++++++++++++++++++++++++ xwin.c | 16 +++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/xdu.c b/xdu.c index 785cfa7..f8e6a12 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 @@ -684,6 +692,23 @@ void press(int x, int y) } } +void printpath(int x, int y) +{ + struct node *np; + char* path; + + np = findnode(&top, x, y); + if (np == NULL) + return; + path = np->name; + while(np->parent != NULL) { + asprintf(&path, "%s/%s", np->parent->name, path); + np = np->parent; + } + path += 6; + printf("%s\n", 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;