]> git.mdlowis.com Git - projs/tide.git/commitdiff
General refactroing and cleanup
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 9 Oct 2016 15:18:02 +0000 (11:18 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 9 Oct 2016 15:18:02 +0000 (11:18 -0400)
edit.h
keyboard.c
mouse.c
tests/tests.c
xedit.c

diff --git a/edit.h b/edit.h
index 8e1752a4008eb100f16a4195a02381c0d7e72ae6..4202cd1021eeed47edd44c5e72e39892c4668718 100644 (file)
--- a/edit.h
+++ b/edit.h
@@ -216,8 +216,13 @@ enum ColorScheme {
     LIGHT = 1
 };
 
+/* Global State
+ *****************************************************************************/
 /* variable for holding the currently selected color scheme */
-enum ColorScheme ColorBase;
+extern enum ColorScheme ColorBase;
+extern Buf Buffer;
+extern unsigned CursorPos;
+extern unsigned TargetCol;
 
 /* Configuration
  *****************************************************************************/
index 3730958d828f1d137f42f00eb55ad5b67b70c9b9..801426996fb24169150c27cb15e1f2a335be13ea 100644 (file)
@@ -1,9 +1,5 @@
 #include "edit.h"
 
-extern Buf Buffer;
-extern unsigned CursorPos;
-extern unsigned TargetCol;
-
 static void special_keys(Rune key);
 static void control_keys(Rune key);
 static void vi_keys(Rune key);
diff --git a/mouse.c b/mouse.c
index cf7a37d940b5ecc3ebc0fa9655e9789483958b92..e97a2e13a4040df2f678b1acb91b860ec8eb67d1 100644 (file)
--- a/mouse.c
+++ b/mouse.c
@@ -1,14 +1,5 @@
 #include "edit.h"
 
-struct {
-    uint32_t time;
-    uint32_t count;
-} Buttons[5] = { {0,0}, {0,0}, {0,0} };
-
-extern Buf Buffer;
-extern unsigned CursorPos;
-extern unsigned TargetCol;
-
 #ifndef __MACH__
 #include <time.h>
 #else
@@ -34,12 +25,6 @@ uint32_t getmillis(void) {
 
 /*****************************************************************************/
 
-enum {
-    SINGLE_CLICK = 0,
-    DOUBLE_CLICK,
-    TRIPLE_CLICK
-};
-
 void unused(MouseEvent* mevnt) {
     (void)mevnt;
 }
@@ -67,6 +52,19 @@ void scrolldn(MouseEvent* mevnt) {
     CursorPos = buf_byline(&Buffer, CursorPos, ScrollLines);
 }
 
+/*****************************************************************************/
+
+enum {
+    SINGLE_CLICK = 0,
+    DOUBLE_CLICK,
+    TRIPLE_CLICK
+};
+
+struct {
+    uint32_t time;
+    uint32_t count;
+} Buttons[5] = { {0,0}, {0,0}, {0,0} };
+
 void (*Actions[5][3])(MouseEvent* mevnt) = {
     [MOUSE_LEFT] = {
         [SINGLE_CLICK] = move_cursor,
@@ -95,7 +93,7 @@ void (*Actions[5][3])(MouseEvent* mevnt) = {
     },
 };
 
-void handle_mouse(MouseEvent* mevnt) {
+static void handle_click(MouseEvent* mevnt) {
     if (mevnt->button >= 5) return;
     /* update the number of clicks */
     uint32_t now = getmillis();
@@ -110,3 +108,15 @@ void handle_mouse(MouseEvent* mevnt) {
     nclicks = (nclicks > 3 ? 1 : nclicks);
     Actions[mevnt->button][nclicks-1](mevnt);
 }
+
+static void handle_drag(MouseEvent* mevnt) {
+    (void)mevnt;
+}
+
+void handle_mouse(MouseEvent* mevnt) {
+    if (mevnt->type == MouseDown) {
+        handle_click(mevnt);
+    } else if (mevnt->type == MouseMove) {
+        handle_drag(mevnt);
+    }
+}
index 5914bead15a3e34ca72c25b91867568d350a62a5..428a74056a865c11eeaefca658076d7099a8d622 100644 (file)
@@ -5,12 +5,12 @@
 Buf Buffer;
 unsigned CursorPos;
 unsigned TargetCol;
+enum ColorScheme ColorBase;
 
 void die(char* m) {
     (void)m;
 }
 
-
 int main(int argc, char** argv) {
     atf_init(argc,argv);
     RUN_EXTERN_TEST_SUITE(BufferTests);
diff --git a/xedit.c b/xedit.c
index 1f86734b7c22f6e67265bd464bc508e166e02661..4cbdbd4bb2cbd1d0d7cf266e8fc03b3a41284520 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -45,7 +45,16 @@ static XftColor xftcolor(enum ColorId cid) {
     return xc;
 }
 
+static void deinit(void) {
+    if (X.pixmap != None) {
+        XftDrawDestroy(X.xft);
+        XFreePixmap(X.display, X.pixmap);
+    }
+    XCloseDisplay(X.display);
+}
+
 static int init(void) {
+    atexit(deinit);
     signal(SIGPIPE, SIG_IGN); // Ignore the SIGPIPE signal
     /* open the X display and get basic attributes */
     if (!(X.display = XOpenDisplay(0)))
@@ -96,14 +105,6 @@ static int init(void) {
     return XConnectionNumber(X.display);
 }
 
-static void deinit(void) {
-    if (X.pixmap != None) {
-        XftDrawDestroy(X.xft);
-        XFreePixmap(X.display, X.pixmap);
-    }
-    XCloseDisplay(X.display);
-}
-
 static Rune getkey(XEvent* e) {
     Rune rune = RUNE_ERR;
     size_t len = 0;