about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-08-09 18:44:34 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-08-09 18:44:34 -0700
commit6fef33fd0872ffcb5141a926d1dae5b0eded3071 (patch)
treedfe65c23796ab6ae7fcb6103d0335146883e96c7
parent051c47384e34b2e2e077cc3665bba7e95b1a562d (diff)
downloadmu-6fef33fd0872ffcb5141a926d1dae5b0eded3071.tar.gz
1963 - redraw if window size changes
This was important because somebody connecting on tmux would mess up the
environment.
-rw-r--r--070display.cc12
-rw-r--r--074console.mu6
-rw-r--r--edit.mu47
3 files changed, 60 insertions, 5 deletions
diff --git a/070display.cc b/070display.cc
index 976be637..ce6d657f 100644
--- a/070display.cc
+++ b/070display.cc
@@ -335,8 +335,6 @@ case CHECK_FOR_INTERACTION: {
     break;
   }
   if (event_type == TB_EVENT_MOUSE) {
-//?     tb_shutdown(); //? 1
-//?     cerr << "AAA\n"; //? 1
     products.at(0).push_back(/*touch event*/2);
     products.at(0).push_back(event.key);  // which button, etc.
     products.at(0).push_back(event.y);  // row
@@ -344,7 +342,15 @@ case CHECK_FOR_INTERACTION: {
     products.at(1).push_back(/*found*/true);
     break;
   }
-  // ignore TB_EVENT_RESIZE events for now
+  if (event_type == TB_EVENT_RESIZE) {
+    products.at(0).push_back(/*resize event*/3);
+    products.at(0).push_back(event.w);  // width
+    products.at(0).push_back(event.h);  // height
+    products.at(0).push_back(0);
+    products.at(1).push_back(/*found*/true);
+    break;
+  }
+  assert(event_type == 0);
   products.at(0).push_back(0);
   products.at(0).push_back(0);
   products.at(0).push_back(0);
diff --git a/074console.mu b/074console.mu
index b60e17cc..b6d4b4d7 100644
--- a/074console.mu
+++ b/074console.mu
@@ -5,6 +5,7 @@ exclusive-container event [
   text:character
   keycode:number  # keys on keyboard without a unicode representation
   touch:touch-event  # mouse, track ball, etc.
+  resize:resize-event
   # update the assume-console handler if you add more variants
 ]
 
@@ -14,6 +15,11 @@ container touch-event [
   column:number
 ]
 
+container resize-event [
+  width:number
+  height:number
+]
+
 container console [
   index:number
   data:address:array:event
diff --git a/edit.mu b/edit.mu
index dd6a1822..369d0089 100644
--- a/edit.mu
+++ b/edit.mu
@@ -562,7 +562,7 @@ recipe editor-event-loop [
     loop-unless found?
     break-if quit?  # only in tests
     trace [app], [next-event]
-    # 'touch' event - send to both editors
+    # 'touch' event
     t:address:touch-event <- maybe-convert e, touch:variant
     {
       break-unless t
@@ -3762,7 +3762,6 @@ recipe new-programming-environment [
   *recipes <- new-editor initial-recipe-contents, screen, 0/left, divider/right
   # sandbox editor on the right
   new-left:number <- add divider, 1
-  new-right:number <- add new-left, 5
   current-sandbox:address:address:editor-data <- get-address *result, current-sandbox:offset
   *current-sandbox <- new-editor initial-sandbox-contents, screen, new-left, width/right
   screen <- render-all screen, result
@@ -3821,6 +3820,18 @@ recipe event-loop [
       render-minimal screen, env
       loop +next-event:label
     }
+    # 'resize' event - redraw editor
+    # todo: test this after supporting resize in assume-console
+    {
+      r:address:resize-event <- maybe-convert e:event, resize:variant
+      break-unless r
+      # if more events, we're still resizing; wait until we stop
+      more-events?:boolean <- has-more-events? console
+      break-if more-events?
+      env <- resize screen, env
+      screen <- render-all screen, env
+      loop +next-event:label
+    }
     # if it's not global and not a touch event, send to appropriate editor
     {
       {
@@ -3841,6 +3852,38 @@ recipe event-loop [
   }
 ]
 
+recipe resize [
+  local-scope
+  screen:address <- next-ingredient
+  env:address:programming-environment-data <- next-ingredient
+  # hack: clear screen to update screen dimensions
+  clear-screen screen
+  width:number <- screen-width screen
+  height:number <- screen-height screen
+  # top menu
+  draw-horizontal screen, 0, 0/left, width, 32/space, 0/black, 238/grey
+  button-start:number <- subtract width, 20
+  button-on-screen?:boolean <- greater-or-equal button-start, 0
+  assert button-on-screen?, [screen too narrow for menu]
+  move-cursor screen, 0/row, button-start
+  run-button:address:array:character <- new [ run (F4) ]
+  print-string screen, run-button, 255/white, 161/reddish
+  # dotted line down the middle
+  divider:number, _ <- divide-with-remainder width, 2
+  draw-vertical screen, divider, 1/top, height, 9482/vertical-dotted
+  # update recipe editor
+  recipes:address:editor-data <- get *env, recipes:offset
+  right:address:number <- get-address *recipes, right:offset
+  *right <- subtract divider, 1
+  # update sandbox editor
+  current-sandbox:address:editor-data <- get *env, current-sandbox:offset
+  left:address:number <- get-address *current-sandbox, left:offset
+  right:address:number <- get-address *current-sandbox, right:offset
+  *left <- add divider, 1
+  *right <- subtract width, 1
+  reply env/same-as-ingredient:1
+]
+
 recipe update-cursor [
   local-scope
   screen:address <- next-ingredient