about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-06-11 22:08:27 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-06-11 22:08:27 -0700
commitfbf5626f7df6d23f68d5497fa4cf652b8f3cae39 (patch)
tree7206f71ec3d048e5e3fdaa3cd8982bfe9f9cedda
parent55ca145e619fb9efafc021c3047f9ed5cb6fecf8 (diff)
downloadmu-fbf5626f7df6d23f68d5497fa4cf652b8f3cae39.tar.gz
1552 - mouse support
-rw-r--r--079input.cc33
-rw-r--r--mouse.mu11
2 files changed, 44 insertions, 0 deletions
diff --git a/079input.cc b/079input.cc
new file mode 100644
index 00000000..e458574a
--- /dev/null
+++ b/079input.cc
@@ -0,0 +1,33 @@
+:(before "End Primitive Recipe Declarations")
+READ_KEYBOARD_OR_MOUSE_EVENT,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["read-keyboard-or-mouse-event"] = READ_KEYBOARD_OR_MOUSE_EVENT;
+:(before "End Primitive Recipe Implementations")
+case READ_KEYBOARD_OR_MOUSE_EVENT: {
+  products.resize(2);  // result and status
+  tb_event event;
+  int event_type = tb_peek_event(&event, 5/*ms*/);
+  if (event_type == TB_EVENT_KEY) {
+    products.at(0).push_back(/*keyboard event*/0);
+    long long key = event.key ? event.key : event.ch;
+    if (key == TB_KEY_CTRL_C) tb_shutdown(), exit(1);
+    if (key == TB_KEY_BACKSPACE2) key = TB_KEY_BACKSPACE;
+    if (key == TB_KEY_CARRIAGE_RETURN) key = TB_KEY_NEWLINE;
+    products.at(0).push_back(key);
+    products.at(1).push_back(/*found*/true);
+    break;
+  }
+  if (event_type == TB_EVENT_MOUSE) {
+    products.at(0).push_back(/*mouse event*/1);
+//?     tb_shutdown(); //? 1
+//?     cerr << event_type << ' ' << event.key << ' ' << event.y << ' ' << event.x << '\n'; //? 1
+//?     exit(0); //? 1
+    products.at(0).push_back(event.key);  // which button, etc.
+    products.at(0).push_back(event.y);  // row
+    products.at(0).push_back(event.x);  // column
+    products.at(1).push_back(/*found*/true);
+    break;
+  }
+  products.at(1).push_back(/*found*/false);
+  break;
+}
diff --git a/mouse.mu b/mouse.mu
new file mode 100644
index 00000000..0621b306
--- /dev/null
+++ b/mouse.mu
@@ -0,0 +1,11 @@
+# example program: managing the display
+
+recipe main [
+  switch-to-display
+  {
+    _, found?:boolean <- read-keyboard-or-mouse-event
+    break-if found?:boolean
+    loop
+  }
+  return-to-console
+]