]> git.mdlowis.com Git - projs/tide.git/commitdiff
more refactoring
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 29 Mar 2018 02:03:58 +0000 (22:03 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 29 Mar 2018 02:03:58 +0000 (22:03 -0400)
inc/win.h
lib/x11.c
tide.c

index a9cca05150001135f9ba68d7107f50a6cf260107..89e2213c5a91eeef49c636f119d1ad99e919c977 100644 (file)
--- a/inc/win.h
+++ b/inc/win.h
@@ -49,10 +49,7 @@ void win_setscroll(double offset, double visible);
 /* These functions must be implemented by any appliation that wishes
    to use this module */
 void onshutdown(void);
-void onfocus(bool focused);
 void onupdate(void);
-void onlayout(void);
-void onscroll(double percent);
 void onmouseleft(WinRegion id, bool pressed, size_t row, size_t col);
 void onmousemiddle(WinRegion id, bool pressed, size_t row, size_t col);
 void onmouseright(WinRegion id, bool pressed, size_t row, size_t col);
index c6081b59600d14128b6242c3370b1f14c65dd434..85966ca2bbddcb667486fb711076bb86cec835ec 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -483,12 +483,21 @@ static void onredraw(int width, int height) {
     int clreditnor = (Regions[EDIT].clrnor.bg << 8 | Regions[EDIT].clrnor.fg);
     int clreditsel = (Regions[EDIT].clrsel.bg << 8 | Regions[EDIT].clrsel.fg);
     view_update(win_view(EDIT), clreditnor, clreditsel, &(Regions[EDIT].csrx), &(Regions[EDIT].csry));
-    onlayout(); // Let the user program update the scroll bar
+
+    /* calculate and update scroll region */
+    View* view = win_view(EDIT);
+    size_t bend = buf_end(win_buf(EDIT));
+    if (bend == 0) bend = 1;
+    if (!view->rows) return;
+    size_t vbeg = view->rows[0]->off;
+    size_t vend = view->rows[view->nrows-1]->off + view->rows[view->nrows-1]->rlen;
+    double scroll_vis = (double)(vend - vbeg) / (double)bend;
+    double scroll_off = ((double)vbeg / (double)bend);
+    win_setscroll(scroll_off, scroll_vis);
 
     int clr_hbor = Colors[ClrBorders].bg;
     int clr_vbor = Colors[ClrBorders].bg;
     CPair clr_scroll = Colors[ClrScrollNor];
-
     for (int i = 0; i < SCROLL; i++) {
         View* view = win_view(i);
         x11_draw_rect(Regions[i].clrnor.bg, 0, Regions[i].y - 3, width, Regions[i].height + 8);
@@ -520,31 +529,6 @@ static void onredraw(int width, int height) {
 
 }
 
-static void scroll_actions(int btn, bool pressed, int x, int y) {
-    size_t row = (y-Regions[SCROLL].y) / x11_font_height(CurrFont);
-    switch (btn) {
-        case MouseLeft:
-            if (pressed)
-                view_scroll(win_view(EDIT), -row);
-            break;
-        case MouseMiddle:
-            if (pressed)
-                onscroll((double)(y - Regions[SCROLL].y) /
-                         (double)(Regions[SCROLL].height - Regions[SCROLL].y));
-            break;
-        case MouseRight:
-            if (pressed)
-                view_scroll(win_view(EDIT), +row);
-            break;
-        case MouseWheelUp:
-            view_scroll(win_view(EDIT), -ScrollBy);
-            break;
-        case MouseWheelDn:
-            view_scroll(win_view(EDIT), +ScrollBy);
-            break;
-    }
-}
-
 static void draw_glyphs(size_t x, size_t y, UGlyph* glyphs, size_t rlen, size_t ncols) {
     XGlyphSpec specs[rlen];
     size_t i = 0;
@@ -623,7 +607,9 @@ static void xupdate(Job* job) {
 static void xfocus(XEvent* e) {
     if (X.xic)
         (e->type == FocusIn ? XSetICFocus : XUnsetICFocus)(X.xic);
-    onfocus(e->type == FocusIn);
+    Buf* buf = win_buf(EDIT);
+    if (buf->path && buf->modtime != modtime(buf->path))
+        buf->errfn("File modified externally: {SaveAs } Overwrite Reload");
 }
 
 static void xkeypress(XEvent* e) {
diff --git a/tide.c b/tide.c
index b53fabaad24a5e7fe083c03b9a645cb9d85b8361..096c305c4dfb77b20c2526b6b5ea7f2cad4284ea 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -325,14 +325,6 @@ static void quit(char* arg) {
     before = now;
 }
 
-static bool changed_externally(Buf* buf) {
-    if (!buf->path) return false;
-    bool modified = (buf->modtime != modtime(buf->path));
-    if (modified)
-        ondiagmsg("File modified externally: {SaveAs } Overwrite Reload");
-    return modified;
-}
-
 static void put(char* arg) {
     trim_whitespace(arg);
     win_save(arg);
@@ -582,31 +574,6 @@ static KeyBinding Bindings[] = {
     { 0, 0, 0 }
 };
 
-void onscroll(double percent) {
-    size_t bend = buf_end(win_buf(EDIT));
-    size_t off  = (size_t)((double)bend * percent);
-    view_scrollto(win_view(EDIT), (off >= bend ? bend : off));
-}
-
-void onfocus(bool focused) {
-    /* notify the user if the file has changed externally */
-    if (focused)
-        (void)changed_externally(win_buf(EDIT));
-}
-
-void onlayout(void) {
-    /* calculate and update scroll region */
-    View* view = win_view(EDIT);
-    size_t bend = buf_end(win_buf(EDIT));
-    if (bend == 0) bend = 1;
-    if (!view->rows) return;
-    size_t vbeg = view->rows[0]->off;
-    size_t vend = view->rows[view->nrows-1]->off + view->rows[view->nrows-1]->rlen;
-    double scroll_vis = (double)(vend - vbeg) / (double)bend;
-    double scroll_off = ((double)vbeg / (double)bend);
-    win_setscroll(scroll_off, scroll_vis);
-}
-
 void onshutdown(void) {
     quit(0);
 }