shithub: orca

Download patch

ref: dee1549232dd102cc9253a2f3267e1330fdf7cde
parent: 285196d28e5d81cf6279892db482e4cf75746632
author: cancel <cancel@cancel.fm>
date: Mon Jan 27 02:14:36 EST 2020

Factor out qnav drawing

--- a/term_util.c
+++ b/term_util.c
@@ -115,7 +115,7 @@
   qb->content_window = subpad(qb->outer_window, height, width, 1, 1);
   qb->y = top;
   qb->x = left;
-  qnav_stack.stack_changed = true;
+  qnav_stack.occlusion_dirty = true;
 }
 
 Qblock *qnav_top_block() {
@@ -164,7 +164,49 @@
   delwin(outer_window);
   --qnav_stack.count;
   qnav_stack.blocks[qnav_stack.count] = NULL;
-  qnav_stack.stack_changed = true;
+  qnav_stack.occlusion_dirty = true;
+}
+
+bool qnav_draw(void) {
+  bool drew_any = false;
+  if (qnav_stack.count < 1)
+    goto done;
+  int term_h, term_w;
+  getmaxyx(stdscr, term_h, term_w);
+  for (Usz i = 0; i < qnav_stack.count; ++i) {
+    Qblock *qb = qnav_stack.blocks[i];
+    if (qnav_stack.occlusion_dirty) {
+      bool is_frontmost = i == qnav_stack.count - 1;
+      qblock_print_frame(qb, is_frontmost);
+      switch (qb->tag) {
+      case Qblock_type_qmsg:
+        break;
+      case Qblock_type_qmenu:
+        qmenu_set_displayed_active(qmenu_of(qb), is_frontmost);
+        break;
+      case Qblock_type_qform:
+        break;
+      }
+    }
+    touchwin(qb->outer_window); // here? or after continue?
+    if (term_h < 1 || term_w < 1)
+      continue;
+    int qbwin_h, qbwin_w;
+    getmaxyx(qb->outer_window, qbwin_h, qbwin_w);
+    int qbwin_endy = qb->y + qbwin_h;
+    int qbwin_endx = qb->x + qbwin_w;
+    if (qbwin_endy >= term_h)
+      qbwin_endy = term_h - 1;
+    if (qbwin_endx >= term_w)
+      qbwin_endx = term_w - 1;
+    if (qb->y >= qbwin_endy || qb->x >= qbwin_endx)
+      continue;
+    pnoutrefresh(qb->outer_window, 0, 0, qb->y, qb->x, qbwin_endy, qbwin_endx);
+    drew_any = true;
+  }
+done:
+  qnav_stack.occlusion_dirty = false;
+  return drew_any;
 }
 
 void qblock_print_border(Qblock *qb, unsigned int attr) {
--- a/term_util.h
+++ b/term_util.h
@@ -66,7 +66,7 @@
 typedef struct {
   Qblock *blocks[16];
   Usz count;
-  bool stack_changed;
+  bool occlusion_dirty;
 } Qnav_stack;
 
 typedef struct Qmsg Qmsg;
@@ -119,6 +119,7 @@
 void qnav_deinit(void);
 Qblock *qnav_top_block(void);
 void qnav_stack_pop(void);
+bool qnav_draw(void); // also clear qnav_stack.occlusion_dirty
 
 void qblock_print_frame(Qblock *qb, bool active);
 void qblock_set_title(Qblock *qb, char const *title);
--- a/tui_main.c
+++ b/tui_main.c
@@ -3524,9 +3524,7 @@
   case ERR: { // ERR indicates no more events.
     ged_do_stuff(&t.ged);
     bool drew_any = false;
-    if (qnav_stack.stack_changed)
-      drew_any = true;
-    if (ged_is_draw_dirty(&t.ged) || drew_any) {
+    if (ged_is_draw_dirty(&t.ged) || qnav_stack.occlusion_dirty) {
       werase(cont_window);
       ged_draw(&t.ged, cont_window, osoc(t.file_name), t.fancy_grid_dots,
                t.fancy_grid_rulers);
@@ -3533,44 +3531,7 @@
       wnoutrefresh(cont_window);
       drew_any = true;
     }
-    if (qnav_stack.count < 1)
-      goto done_qnav_stack_update;
-    int term_h, term_w;
-    getmaxyx(stdscr, term_h, term_w);
-    for (Usz i = 0; i < qnav_stack.count; ++i) {
-      Qblock *qb = qnav_stack.blocks[i];
-      if (qnav_stack.stack_changed) {
-        bool is_frontmost = i == qnav_stack.count - 1;
-        qblock_print_frame(qb, is_frontmost);
-        switch (qb->tag) {
-        case Qblock_type_qmsg:
-          break;
-        case Qblock_type_qmenu:
-          qmenu_set_displayed_active(qmenu_of(qb), is_frontmost);
-          break;
-        case Qblock_type_qform:
-          break;
-        }
-      }
-      touchwin(qb->outer_window); // here? or after continue?
-      if (term_h < 1 || term_w < 1)
-        continue;
-      int qbwin_h, qbwin_w;
-      getmaxyx(qb->outer_window, qbwin_h, qbwin_w);
-      int qbwin_endy = qb->y + qbwin_h;
-      int qbwin_endx = qb->x + qbwin_w;
-      if (qbwin_endy >= term_h)
-        qbwin_endy = term_h - 1;
-      if (qbwin_endx >= term_w)
-        qbwin_endx = term_w - 1;
-      if (qb->y >= qbwin_endy || qb->x >= qbwin_endx)
-        continue;
-      pnoutrefresh(qb->outer_window, 0, 0, qb->y, qb->x, qbwin_endy,
-                   qbwin_endx);
-      drew_any = true;
-    }
-  done_qnav_stack_update:
-    qnav_stack.stack_changed = false;
+    drew_any |= qnav_draw(); // clears qnav_stack.occlusion_dirty
     if (drew_any)
       doupdate();
     double secs_to_d = ged_secs_to_deadline(&t.ged);