From 503786c01c0d2d29392893b25de630dd6e8c7af1 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 2 May 2017 12:13:55 -0400 Subject: [PATCH] update all apps to use new layout/update hooks and fixed some segfaults in xpick --- inc/win.h | 1 + lib/win.c | 7 ++++--- term.c | 3 +++ xedit.c | 4 +++- xpick.c | 12 ++++++++---- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/inc/win.h b/inc/win.h index 586d781..9e02cb0 100644 --- 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); diff --git a/lib/win.c b/lib/win.c index 604a3e6..6ee9edc 100644 --- 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 6dbdbf3..9c67faf 100644 --- 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 aeed285..7186c98 100644 --- 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 ee9de8a..0439319 100644 --- 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; -- 2.52.0