From 9281b6df3cafd040eef3f54c5499dea642789ba5 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sat, 12 Aug 2017 22:28:25 -0400 Subject: [PATCH] tweaked tfetch to use tctl to activate open windows when jumping to tag --- inc/x11.h | 1 + lib/win.c | 13 +++++++++++++ lib/x11.c | 4 ++++ picktag | 2 +- tctl.c | 3 ++- tfetch.c | 2 +- 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/inc/x11.h b/inc/x11.h index dd820ba..7855248 100644 --- a/inc/x11.h +++ b/inc/x11.h @@ -5,6 +5,7 @@ typedef struct { void (*set_focus)(bool focus); void (*mouse_drag)(int state, int x, int y); void (*mouse_btn)(int state, bool pressed, int x, int y); + void (*cmd_received)(char* cmd); } XConfig; typedef void* XFont; diff --git a/lib/win.c b/lib/win.c index 2e25d3c..67f9bfd 100644 --- a/lib/win.c +++ b/lib/win.c @@ -11,6 +11,7 @@ static void onmousedrag(int state, int x, int y); static void onmousebtn(int btn, bool pressed, int x, int y); static void onwheelup(WinRegion id, bool pressed, size_t row, size_t col); static void onwheeldn(WinRegion id, bool pressed, size_t row, size_t col); +static void oncommand(char* cmd); static bool update_focus(void); static void draw_line_num(bool current, size_t x, size_t y, size_t gcols, size_t num); static void draw_glyphs(size_t x, size_t y, UGlyph* glyphs, size_t rlen, size_t ncols); @@ -27,6 +28,7 @@ static XConfig Config = { .set_focus = onfocus, .mouse_drag = onmousedrag, .mouse_btn = onmousebtn, + .cmd_received = oncommand }; static WinRegion Focused = EDIT; static Region Regions[NREGIONS] = {0}; @@ -405,6 +407,17 @@ static void onwheeldn(WinRegion id, bool pressed, size_t row, size_t col) { view_scroll(win_view(id), +(config_get_int(ScrollLines))); } +static void oncommand(char* cmd) { + size_t line = strtoul(cmd, NULL, 0); + if (line) { + View* view = win_view(EDIT); + win_setregion(EDIT); + view_setln(view, line); + view_eol(view, false); + view_selctx(view); + } +} + static bool update_focus(void) { static int prev_x = 0, prev_y = 0; int ptr_x, ptr_y; diff --git a/lib/x11.c b/lib/x11.c index 3fe41ab..d37f617 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -149,6 +149,7 @@ void x11_window(char* name, int width, int height) { | ButtonMotionMask | KeyPressMask | FocusChangeMask + | PropertyChangeMask ); /* set input methods */ @@ -641,6 +642,9 @@ bool x11_sel_set(int selid, char* str) { /* Tide Server Communication and Property Handling *****************************************************************************/ static void propnotify(XEvent* evnt) { + XPropertyEvent* ev = (XPropertyEvent*)evnt; + if (ev->atom == XInternAtom(X.display, "TIDE_COMM", False)) + Config->cmd_received(x11_prop_get("TIDE_COMM")); } void x11_prop_set(char* name, char* val) { diff --git a/picktag b/picktag index d0ba890..8de8787 100755 --- a/picktag +++ b/picktag @@ -40,7 +40,7 @@ fetch(){ print "grep -Hn", matchstr, $2, "| cut -d: -f1,2" } ' "$TAGFILE" | /bin/sh | pick) - [ "" != "$file" ] && tide "$file" + [ "" != "$file" ] && tctl "$file" } export PICKTITLE="Pick CTag ($PWD)" diff --git a/tctl.c b/tctl.c index f24e5e9..9c058da 100644 --- a/tctl.c +++ b/tctl.c @@ -125,6 +125,8 @@ static void focus_window(Window w, char* addr) { long mask = SubstructureRedirectMask | SubstructureNotifyMask; XSendEvent(X.display, X.root, False, mask, &ev); XMapRaised(X.display, w); + if (addr && *addr) + prop_set(w, "TIDE_COMM", XA_STRING, 8, addr, strlen(addr)); XFlush(X.display); } @@ -136,4 +138,3 @@ void get_abspath(char* path, char** abspath, char** addr) { if (!rpath) rpath = path; *abspath = rpath, *addr = faddr; } - diff --git a/tfetch.c b/tfetch.c index fe58a72..2ea6a31 100644 --- a/tfetch.c +++ b/tfetch.c @@ -44,7 +44,7 @@ Rule* BuiltinRules[] = { { ISSET, "EDITOR", NULL }, { MATCHES, "data", "^([^:]+):([0-9]+)" }, { ISFILE, "$1", NULL }, - { LAUNCH, "$EDITOR $0", NULL }, + { LAUNCH, "tctl $0", NULL }, { COMPLETE, NULL, NULL } }, (Rule[]){ // If it's an existing text file, open it with editor -- 2.49.0