]> git.mdlowis.com Git - projs/tide.git/commitdiff
update all apps to use new layout/update hooks and fixed some segfaults in xpick
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 2 May 2017 16:13:55 +0000 (12:13 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 2 May 2017 16:13:55 +0000 (12:13 -0400)
inc/win.h
lib/win.c
term.c
xedit.c
xpick.c

index 586d781aa821c411fc56c7ef0f9fb53d4ca5fc71..9e02cb098691f02419a6f7fc4e84cd437a75f387 100644 (file)
--- a/inc/win.h
+++ b/inc/win.h
@@ -51,6 +51,7 @@ void win_setscroll(double offset, double visible);
 /* These functions must be implemented by any appliation that wishes 
    to use this module */
 void onupdate(void);
+void onlayout(void);
 void onscroll(double percent);
 void onmouseleft(WinRegion id, size_t count, size_t row, size_t col);
 void onmousemiddle(WinRegion id, size_t count, size_t row, size_t col);
index 604a3e6c516f3b65951310fe8cbc4d9903e5a5f0..6ee9edcbd03ec1b6913138f5f12ba3b848239e0e 100644 (file)
--- a/lib/win.c
+++ b/lib/win.c
@@ -81,7 +81,8 @@ void win_loop(void) {
         bool pending = x11_events_await(200 /* ms */);
         if (update_focus() || pending) {
             x11_events_take();
-            x11_flip();
+            if (x11_running())
+                x11_flip();
         }
         x11_flush();
     }
@@ -195,9 +196,9 @@ static void onredraw(int width, int height) {
     size_t fwidth  = x11_font_width(Font);
     
     /* layout and draw the three text regions */
-    onupdate(); // Let the user program update the status and such
+    onupdate(); // Let the user program update the status and other content
     layout(width, height);
-    onupdate(); // Let the user program update the status and such
+    onlayout(); // Let the user program update the scroll bar
     
     for (int i = 0; i < SCROLL; i++) {
         View* view = win_view(i);
diff --git a/term.c b/term.c
index 6dbdbf3500828aa7c49158ca674c295bb30311e9..9c67faf5919f34f39dcad494645e86c793fe5230 100644 (file)
--- a/term.c
+++ b/term.c
@@ -24,6 +24,9 @@ void onscroll(double percent) {
 void onupdate(void) {
 }
 
+void onlayout(void) {
+}
+
 #ifndef TEST
 int main(int argc, char** argv) {
     win_window("term");
diff --git a/xedit.c b/xedit.c
index aeed285acf8558cf7e5a4accfd015f52fbe9036a..7186c98bbde64ba8c4ab41dc49b1d2bec62f789e 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -541,7 +541,9 @@ void onupdate(void) {
     strncat(status, path, remlen);
     win_settext(STATUS, status_bytes);
     win_view(STATUS)->selection = (Sel){0,0,0};
-    
+}
+
+void onlayout(void) {    
     /* calculate and update scroll region */
     View* view = win_view(EDIT);
     size_t bend = buf_end(win_buf(EDIT));
diff --git a/xpick.c b/xpick.c
index ee9de8adc04fd8c2b22acec32d53f8b96b195ba5..04393191eb861914271c1f269f9824fcdd88cd31 100644 (file)
--- a/xpick.c
+++ b/xpick.c
@@ -131,14 +131,14 @@ void onupdate(void) {
     win_settext(EDIT, "");
     View* view = win_view(EDIT);
     view->selection = (Sel){0,0,0};
-
-    score();
     Sel selection = (Sel){0,0,0};
+    
+    score();
     unsigned off = (ChoiceIdx >= view->nrows ? ChoiceIdx-view->nrows+1 : 0);
     for (int i = 0; (i < vec_size(&Choices)) && (i < view->nrows); i++) {
         unsigned beg = view->selection.end;
         Choice* choice = (Choice*)vec_at(&Choices, i+off);
-        for (char* str = choice->string; *str; str++)
+        for (char* str = choice->string; str && *str; str++)
             view_insert(view, false, *str);
         view_insert(view, false, '\n');
         if (ChoiceIdx == i+off) {
@@ -147,8 +147,12 @@ void onupdate(void) {
         }
     }
     view->selection = selection;
-    
+}
+
+void onlayout(void) {
     /* update scroll bar */
+    View* view = win_view(EDIT);
+    unsigned off = (ChoiceIdx >= view->nrows ? ChoiceIdx-view->nrows+1 : 0);
     double visible = (double)(win_view(EDIT)->nrows);
     double choices = (double)vec_size(&Choices);
     double current = (double)off;