]> git.mdlowis.com Git - projs/tide.git/commitdiff
tweaked tfetch to use tctl to activate open windows when jumping to tag
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 13 Aug 2017 02:28:25 +0000 (22:28 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 13 Aug 2017 02:28:25 +0000 (22:28 -0400)
inc/x11.h
lib/win.c
lib/x11.c
picktag
tctl.c
tfetch.c

index dd820babf91bd31a10029a18bb376ab0f8a3336d..785524897d25fd622991b5bb16ec20e2ea02ad78 100644 (file)
--- 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;
index 2e25d3c8f245ce08883012d6b107bd111cf92013..67f9bfdf416d44140d0d116c671fd746089a7a8a 100644 (file)
--- 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;
index 3fe41ab11b2ecb9dd7591e24933a7f2af79b18a8..d37f6171af46ef34d25926230c4f40511bacb9b0 100644 (file)
--- 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 d0ba890d31a358a933e36c18d0c26ccb15f3e536..8de878776b8e2a92f9b4acd7198e0ec415181c4c 100755 (executable)
--- 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 f24e5e93fead63c513048605418fde754c2d4d8f..9c058da5bacd311f5bf0121c423acc5783bfa76e 100644 (file)
--- 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;
 }
-
index fe58a72f3ab9ae73ef312a03e039eee76652ec94..2ea6a314596d7a3d2c60b5491b547d8d6be6b1ba 100644 (file)
--- 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