ref: ee4ceb2e711a4198fb8e831d078e21d6b7cd8bd1
parent: 8bc07106249a28dec80e91228b945814efc60d70
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Jan 2 14:39:30 EST 2020
alt: blocking mode, propagate mouse/key events by processing twice
--- a/demo/plan9.c
+++ b/demo/plan9.c
@@ -19,9 +19,9 @@
{ nil, &m, CHANRCV },
{ nil, nil, CHANRCV },
{ nil, &key, CHANRCV },
- { nil, nil, CHANNOBLK},
+ { nil, nil, CHANEND},
};
- int oldbuttons, b, nkey;
+ int oldbuttons, b, nkey, gotevent;
char text[5], *s;
mu_Command *cmd;
mu_Context *ctx;
@@ -51,15 +51,14 @@
ctx->text_width = r_get_text_width;
ctx->text_height = r_get_text_height;
ctx->style->font = display->defaultfont;
+ process_frame(ctx);
oldbuttons = 0;
for (;;) {
- /* process frame */
process_frame(ctx);
- /* render */
- r_clear(mu_color(bg[0], bg[1], bg[2], 255));
cmd = nil;
+ r_clear(mu_color(bg[0], bg[1], bg[2], 255));
while (mu_next_command(ctx, &cmd)) {
switch (cmd->type) {
case MU_COMMAND_TEXT: r_draw_text(ctx->style->font, cmd->text.str, cmd->text.pos, cmd->text.color); break;
@@ -70,6 +69,7 @@
}
r_present();
+ gotevent = 1;
switch (alt(a)) {
case 0: /* mouse */
m.xy.x -= screen->r.min.x;
@@ -114,9 +114,15 @@
mu_input_keydown(ctx, nkey);
mu_input_keyup(ctx, nkey);
}
+ break;
+
+ default:
+ gotevent = 0;
+ break;
}
- a[nelem(a)-1].op = a[nelem(a)-1].op == CHANNOBLK ? CHANEND : CHANNOBLK;
+ if (gotevent)
+ process_frame(ctx);
}
end: