Skip to content

Add mouse feature to print path of node #9

Merged
merged 3 commits into from
Aug 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion 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 All @@ -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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 = &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