commit d9ce4bb
uint
·
2026-05-15 17:15:07 +0000 UTC
parent 335ed67
skip processing if pty buffer unchanged
1 files changed,
+28,
-1
+28,
-1
1@@ -2,6 +2,7 @@
2 #include <errno.h>
3 #include <fcntl.h>
4 #include <locale.h>
5+#include <poll.h>
6 #include <stdbool.h>
7 #include <stdint.h>
8 #include <stdlib.h>
9@@ -34,6 +35,7 @@ static void resize_pty(void);
10 static int resize_surface(int w, int h);
11 static void resize_terminal(int w, int h);
12 static void run(void);
13+static void wait(void);
14
15 static Fontface font;
16 static Caret car;
17@@ -341,8 +343,10 @@ static void run(void)
18 dirty = true;
19 }
20
21- if (!dirty)
22+ if (!dirty) {
23+ wait();
24 continue;
25+ }
26
27 if (redraw_all) {
28 draw_clear(pixels, winw, winh, rgba(0, 0, 0, 255));
29@@ -387,6 +391,29 @@ static void run(void)
30 }
31 }
32
33+/**
34+ * @brief wait for activity while allowing window events
35+ */
36+static void wait(void)
37+{
38+ struct pollfd pfd = {
39+ .fd = term.ptyfd,
40+ .events = POLLIN,
41+ };
42+
43+ if (term.ptyfd < 0) {
44+ RGFW_waitForEvent(16);
45+ return;
46+ }
47+
48+ for (;;) {
49+ int ret = poll(&pfd, 1, 16);
50+ if (ret < 0 && errno == EINTR)
51+ continue;
52+ break;
53+ }
54+}
55+
56 int main(int argc, char* argv[])
57 {
58 /* TODO: pledges */