+
+ /**
+ * Peek at certain application-level events, add to eventQueue, and wake
+ * up the consuming Fiber.
+ *
+ * @param events the input events to consume
+ */
+ private void metaHandleEvents(final List<TInputEvent> events) {
+
+ for (TInputEvent event: events) {
+
+ /*
+ System.err.printf(String.format("metaHandleEvents event: %s\n",
+ event)); System.err.flush();
+ */
+
+ if (quit) {
+ // Do no more processing if the application is already trying
+ // to exit.
+ return;
+ }
+
+ // DEBUG
+ if (event instanceof TKeypressEvent) {
+ TKeypressEvent keypress = (TKeypressEvent) event;
+ if (keypress.key.equals(kbAltX)) {
+ quit = true;
+ return;
+ }
+ }
+ // DEBUG
+
+ // Special application-wide events -------------------------------
+
+ // Abort everything
+ if (event instanceof TCommandEvent) {
+ TCommandEvent command = (TCommandEvent) event;
+ if (command.getCmd().equals(cmAbort)) {
+ quit = true;
+ return;
+ }
+ }
+
+ // Screen resize
+ if (event instanceof TResizeEvent) {
+ TResizeEvent resize = (TResizeEvent) event;
+ backend.getScreen().setDimensions(resize.getWidth(),
+ resize.getHeight());
+ desktopBottom = backend.getScreen().getHeight() - 1;
+ repaint = true;
+ mouseX = 0;
+ mouseY = 0;
+ continue;
+ }
+
+ // Peek at the mouse position
+ if (event instanceof TMouseEvent) {
+ TMouseEvent mouse = (TMouseEvent) event;
+ if ((mouseX != mouse.x) || (mouseY != mouse.y)) {
+ mouseX = mouse.x;
+ mouseY = mouse.y;
+ drawMouse();
+ }
+ }
+
+ /*
+
+ // Put into the main queue
+ addEvent(event);
+
+ // Have one of the two consumer Fibers peel the events off
+ // the queue.
+ if (secondaryEventFiber !is null) {
+ assert(secondaryEventFiber.state == Fiber.State.HOLD);
+
+ // Wake up the secondary handler for these events
+ secondaryEventFiber.call();
+ } else {
+ assert(primaryEventFiber.state == Fiber.State.HOLD);
+
+ // Wake up the primary handler for these events
+ primaryEventFiber.call();
+ }
+ */
+
+ } // for (TInputEvent event: events)
+
+ }
+
+ /**
+ * Do stuff when there is no user input.
+ */
+ private void doIdle() {
+ /*
+ // Now run any timers that have timed out
+ auto now = Clock.currTime;
+ TTimer [] keepTimers;
+ foreach (t; timers) {
+ if (t.nextTick < now) {
+ t.tick();
+ if (t.recurring == true) {
+ keepTimers ~= t;
+ }
+ } else {
+ keepTimers ~= t;
+ }
+ }
+ timers = keepTimers;
+
+ // Call onIdle's
+ foreach (w; windows) {
+ w.onIdle();
+ }
+ */
+ }
+
+ /**
+ * Get the amount of time I can sleep before missing a Timer tick.
+ *
+ * @param timeout = initial (maximum) timeout
+ * @return number of milliseconds between now and the next timer event
+ */
+ protected int getSleepTime(final int timeout) {
+ /*
+ auto now = Clock.currTime;
+ auto sleepTime = dur!("msecs")(timeout);
+ foreach (t; timers) {
+ if (t.nextTick < now) {
+ return 0;
+ }
+ if ((t.nextTick > now) &&
+ ((t.nextTick - now) < sleepTime)
+ ) {
+ sleepTime = t.nextTick - now;
+ }
+ }
+ assert(sleepTime.total!("msecs")() >= 0);
+ return cast(uint)sleepTime.total!("msecs")();
+ */
+ // TODO: fix timers. Until then, come back after 250 millis.
+ return 250;
+ }
+