]> git.mdlowis.com Git - projs/tide.git/commitdiff
minor refactoring, added xerror handler, and fixed a bug in pick that allowed selecti...
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 9 Jan 2019 21:20:24 +0000 (16:20 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 9 Jan 2019 21:20:24 +0000 (16:20 -0500)
TODO.md
inc/x11.h
src/lib/x11.c
src/pick.c
src/tide.c

diff --git a/TODO.md b/TODO.md
index 6c02eefdceffca7db7050af2f721977c0e135c25..05821e26d4ed1d34ab031f327d859bb525f85098 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -8,7 +8,6 @@
 * registrar: group by hostname or group env var in registrar
 * registrar: should remove invalid windows from registry when detected
 * tide: gap buffer does not handle UTF-8 currently
-* pick can return null if mouse clicked on empty row
 
 ## BACKLOG
 
index cd85b1b69bb0fa9a9c87db583adee0686386223a..a89a8b1162b80527b2c73acee68cbc4119b9113b 100644 (file)
--- a/inc/x11.h
+++ b/inc/x11.h
@@ -3,7 +3,7 @@
 #include <X11/Xft/Xft.h>
 
 typedef struct XConf {
-    Bool running;
+    Bool running, error;
     int fd, screen, width, height;
     Window root;
     Display* display;
@@ -27,6 +27,9 @@ enum {
 };
 
 int x11_init(XConf* x);
+void x11_clear_error(void);
+XErrorEvent* x11_error_get(void);
+
 void x11_mkwin(XConf* x, int width, int height, int evmask);
 void x11_mkdialog(XConf* x, int width, int height, int evmask);
 void x11_event_loop(XConf* x, void (*redraw)(XConf* x));
index 69807dcbd72cde6c31713eb9309251e00b5cd584..cb36742b247f0547f72f980161fb5ed2b72c62f3 100644 (file)
@@ -4,6 +4,15 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
+static Bool Has_Error = False;
+static XErrorEvent Error = {0};
+
+static int onerror(Display* disp, XErrorEvent* ev) {
+    (void)disp;
+    Has_Error = True, Error = *ev;
+    return 0;
+}
+
 int x11_init(XConf* x) {
     signal(SIGPIPE, SIG_IGN); // Ignore the SIGPIPE signal
     setlocale(LC_CTYPE, "");
@@ -19,9 +28,19 @@ int x11_init(XConf* x) {
     x->screen   = DefaultScreen(x->display);
     x->depth    = DefaultDepth(x->display, x->screen);
     x->running = True;
+    XSetErrorHandler(onerror);
     return 0;
 }
 
+void x11_clear_error(void) {
+    Has_Error = False;
+    memset(&Error, 0, sizeof(Error));
+}
+
+XErrorEvent* x11_error_get(void) {
+    return (Has_Error ? &Error : NULL);
+}
+
 void x11_mkwin(XConf* x, int width, int height, int evmask) {
     /* create the main window */
     x->width = width, x->height = height;
index 947f3e55c1f9f5b583b0834190514419bb30bfc2..1ec7051d68152fff43d89c846302d184471fa6ef 100644 (file)
@@ -147,6 +147,8 @@ static void xbtnpress(XConf* x, XEvent* e) {
         int starty = x->font->height + 4;
         e->xbutton.y = (e->xbutton.y < starty ? starty : e->xbutton.y - starty);
         ChoiceIdx = Offset + (e->xbutton.y / x->font->height);
+        if (ChoiceIdx >= vec_size(&Choices))
+            ChoiceIdx = vec_size(&Choices)-1;
     } else if (e->xbutton.button == Button4) {
         if (Offset > 0) Offset--;
     } else if (e->xbutton.button == Button5) {
index 626a0f6a7f70fab41f05e4b73b897d618db54b30..ce1874429b51a8341dafe6ebff9b825122238c69 100644 (file)
@@ -16,7 +16,7 @@
 #include "config.h"
 
 /* predeclare some things */
-void exec(char* cmd, char* arg);
+static void exec(char* cmd, char* arg);
 void cut(char* arg);
 void paste(char* arg);
 
@@ -435,13 +435,7 @@ static void cmd_exec(char* cmd) {
         job_start(execcmd, input, len, (op != '<' ? curr : edit));
 }
 
-static void cmd_execwitharg(char* cmd, char* arg) {
-    cmd = (arg ? strmcat(cmd, " '", arg, "'", 0) : strmcat(cmd));
-    cmd_exec(cmd);
-    free(cmd);
-}
-
-void exec(char* cmd, char* arg) {
+static void exec(char* cmd, char* arg) {
     /* skip leading space */
     for (; *cmd && isspace(*cmd); cmd++);
     if (!*cmd) return;
@@ -706,7 +700,7 @@ static void open_file(char* arg) {
 }
 
 static void pick_symbol(char* symbol) {
-    cmd_execwitharg(CMD_GOTO_TAG, symbol);
+    exec(CMD_GOTO_TAG, symbol);
 }
 
 static void pick_ctag(char* arg) {
@@ -718,14 +712,14 @@ static void complete(char* arg) {
     (void)arg;
     View* view = win_view(FOCUSED);
     view_selectobj(view, risword);
-    cmd_execwitharg(CMD_COMPLETE, view_getstr(view));
+    exec(CMD_COMPLETE, view_getstr(view));
 }
 
 static void fcomplete(char* arg) {
     (void)arg;
     View* view = win_view(FOCUSED);
     view_selectobj(view, risfile);
-    cmd_execwitharg(CMD_FCOMPLETE, view_getstr(view));
+    exec(CMD_FCOMPLETE, view_getstr(view));
 }
 
 static void jump_to(char* arg) {