Skip to content

Commit

Permalink
Add mouse feature to print path of node
Browse files Browse the repository at this point in the history
  • Loading branch information
niclas committed Aug 15, 2018
1 parent 13a564e commit a374120
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
25 changes: 25 additions & 0 deletions xdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -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 = &top;
Expand Down
16 changes: 15 additions & 1 deletion xwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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},
Expand Down Expand Up @@ -181,7 +184,8 @@ static char defaultTranslations[] = "\
<Key>9: ncol(9)\n\
<Key>0: ncol(10)\n\
<Btn1Down>: goto()\n\
<Btn2Down>: reset()\n\
<Btn2Down>: printpath()\n\
<Btn3Down>: reset()\n\
";

#define UNUSED1(x) (void)(x)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a374120

Please sign in to comment.